Cleanup: text editor variable names
This commit is contained in:
@@ -2512,20 +2512,21 @@ static void txt_screen_skip(SpaceText *st, ARegion *ar, int lines)
|
||||
}
|
||||
|
||||
/* quick enum for tsc->zone (scroller handles) */
|
||||
enum {
|
||||
enum eScrollZone {
|
||||
SCROLLHANDLE_INVALID_OUTSIDE = -1,
|
||||
SCROLLHANDLE_BAR,
|
||||
SCROLLHANDLE_MIN_OUTSIDE,
|
||||
SCROLLHANDLE_MAX_OUTSIDE,
|
||||
};
|
||||
|
||||
typedef struct TextScroll {
|
||||
int old[2];
|
||||
int delta[2];
|
||||
int mval_prev[2];
|
||||
int mval_delta[2];
|
||||
|
||||
int first;
|
||||
int scrollbar;
|
||||
bool is_first;
|
||||
bool is_scrollbar;
|
||||
|
||||
int zone;
|
||||
enum eScrollZone zone;
|
||||
|
||||
/* Store the state of the display, cache some constant vars. */
|
||||
struct {
|
||||
@@ -2583,25 +2584,25 @@ static void text_scroll_apply(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
text_update_character_width(st);
|
||||
|
||||
/* compute mouse move distance */
|
||||
if (tsc->first) {
|
||||
tsc->old[0] = mval[0];
|
||||
tsc->old[1] = mval[1];
|
||||
tsc->first = 0;
|
||||
if (tsc->is_first) {
|
||||
tsc->mval_prev[0] = mval[0];
|
||||
tsc->mval_prev[1] = mval[1];
|
||||
tsc->is_first = false;
|
||||
}
|
||||
|
||||
if (event->type != MOUSEPAN) {
|
||||
tsc->delta[0] = mval[0] - tsc->old[0];
|
||||
tsc->delta[1] = mval[1] - tsc->old[1];
|
||||
tsc->mval_delta[0] = mval[0] - tsc->mval_prev[0];
|
||||
tsc->mval_delta[1] = mval[1] - tsc->mval_prev[1];
|
||||
}
|
||||
|
||||
/* accumulate scroll, in float values for events that give less than one
|
||||
* line offset but taken together should still scroll */
|
||||
if (!tsc->scrollbar) {
|
||||
tsc->ofs_delta_px[0] -= tsc->delta[0];
|
||||
tsc->ofs_delta_px[1] += tsc->delta[1];
|
||||
if (!tsc->is_scrollbar) {
|
||||
tsc->ofs_delta_px[0] -= tsc->mval_delta[0];
|
||||
tsc->ofs_delta_px[1] += tsc->mval_delta[1];
|
||||
}
|
||||
else {
|
||||
tsc->ofs_delta_px[1] -= (tsc->delta[1] * st->pix_per_line) * tsc->state.size_px[1];
|
||||
tsc->ofs_delta_px[1] -= (tsc->mval_delta[1] * st->pix_per_line) * tsc->state.size_px[1];
|
||||
}
|
||||
|
||||
for (int i = 0; i < 2; i += 1) {
|
||||
@@ -2612,7 +2613,7 @@ static void text_scroll_apply(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
|
||||
/* The final values need to be calculated from the inputs,
|
||||
* so clamping and ensuring an unsigned pixel offset doesn't conflict with
|
||||
* updating the cursor delta. */
|
||||
* updating the cursor mval_delta. */
|
||||
int scroll_ofs_new[2] = {
|
||||
tsc->state.ofs_init[0] + tsc->ofs_delta[0],
|
||||
tsc->state.ofs_init[1] + tsc->ofs_delta[1],
|
||||
@@ -2659,8 +2660,8 @@ static void text_scroll_apply(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
ED_area_tag_redraw(CTX_wm_area(C));
|
||||
}
|
||||
|
||||
tsc->old[0] = mval[0];
|
||||
tsc->old[1] = mval[1];
|
||||
tsc->mval_prev[0] = mval[0];
|
||||
tsc->mval_prev[1] = mval[1];
|
||||
}
|
||||
|
||||
static void scroll_exit(bContext *C, wmOperator *op)
|
||||
@@ -2728,7 +2729,7 @@ static int text_scroll_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
}
|
||||
|
||||
tsc = MEM_callocN(sizeof(TextScroll), "TextScroll");
|
||||
tsc->first = 1;
|
||||
tsc->is_first = true;
|
||||
tsc->zone = SCROLLHANDLE_BAR;
|
||||
|
||||
text_scroll_state_init(tsc, st, ar);
|
||||
@@ -2740,13 +2741,13 @@ static int text_scroll_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
if (event->type == MOUSEPAN) {
|
||||
text_update_character_width(st);
|
||||
|
||||
tsc->old[0] = event->x;
|
||||
tsc->old[1] = event->y;
|
||||
tsc->mval_prev[0] = event->x;
|
||||
tsc->mval_prev[1] = event->y;
|
||||
/* Sensitivity of scroll set to 4pix per line/char */
|
||||
tsc->delta[0] = (event->x - event->prevx) * st->cwidth / 4;
|
||||
tsc->delta[1] = (event->y - event->prevy) * st->lheight_dpi / 4;
|
||||
tsc->first = 0;
|
||||
tsc->scrollbar = 0;
|
||||
tsc->mval_delta[0] = (event->x - event->prevx) * st->cwidth / 4;
|
||||
tsc->mval_delta[1] = (event->y - event->prevy) * st->lheight_dpi / 4;
|
||||
tsc->is_first = false;
|
||||
tsc->is_scrollbar = false;
|
||||
text_scroll_apply(C, op, event);
|
||||
scroll_exit(C, op);
|
||||
return OPERATOR_FINISHED;
|
||||
@@ -2811,7 +2812,7 @@ static int text_scroll_bar_invoke(bContext *C, wmOperator *op, const wmEvent *ev
|
||||
ARegion *ar = CTX_wm_region(C);
|
||||
TextScroll *tsc;
|
||||
const int *mval = event->mval;
|
||||
int zone = -1;
|
||||
enum eScrollZone zone = SCROLLHANDLE_INVALID_OUTSIDE;
|
||||
|
||||
if (RNA_struct_property_is_set(op->ptr, "lines")) {
|
||||
return text_scroll_exec(C, op);
|
||||
@@ -2833,14 +2834,14 @@ static int text_scroll_bar_invoke(bContext *C, wmOperator *op, const wmEvent *ev
|
||||
}
|
||||
}
|
||||
|
||||
if (zone == -1) {
|
||||
if (zone == SCROLLHANDLE_INVALID_OUTSIDE) {
|
||||
/* we are outside slider - nothing to do */
|
||||
return OPERATOR_PASS_THROUGH;
|
||||
}
|
||||
|
||||
tsc = MEM_callocN(sizeof(TextScroll), "TextScroll");
|
||||
tsc->first = 1;
|
||||
tsc->scrollbar = 1;
|
||||
tsc->is_first = true;
|
||||
tsc->is_scrollbar = true;
|
||||
tsc->zone = zone;
|
||||
op->customdata = tsc;
|
||||
st->flags |= ST_SCROLL_SELECT;
|
||||
@@ -2849,10 +2850,10 @@ static int text_scroll_bar_invoke(bContext *C, wmOperator *op, const wmEvent *ev
|
||||
|
||||
/* jump scroll, works in v2d but needs to be added here too :S */
|
||||
if (event->type == MIDDLEMOUSE) {
|
||||
tsc->old[0] = ar->winrct.xmin + BLI_rcti_cent_x(&st->txtbar);
|
||||
tsc->old[1] = ar->winrct.ymin + BLI_rcti_cent_y(&st->txtbar);
|
||||
tsc->mval_prev[0] = ar->winrct.xmin + BLI_rcti_cent_x(&st->txtbar);
|
||||
tsc->mval_prev[1] = ar->winrct.ymin + BLI_rcti_cent_y(&st->txtbar);
|
||||
|
||||
tsc->first = 0;
|
||||
tsc->is_first = false;
|
||||
tsc->zone = SCROLLHANDLE_BAR;
|
||||
text_scroll_apply(C, op, event);
|
||||
}
|
||||
@@ -2885,12 +2886,16 @@ void TEXT_OT_scroll_bar(wmOperatorType *ot)
|
||||
ot->srna, "lines", 1, INT_MIN, INT_MAX, "Lines", "Number of lines to scroll", -100, 100);
|
||||
}
|
||||
|
||||
/******************* set selection operator **********************/
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Set Selection Operator
|
||||
* \{ */
|
||||
|
||||
typedef struct SetSelection {
|
||||
int selecting;
|
||||
int selc, sell;
|
||||
short old[2];
|
||||
short mval_prev[2];
|
||||
wmTimer *timer; /* needed for scrolling when mouse at region bounds */
|
||||
} SetSelection;
|
||||
|
||||
@@ -3192,8 +3197,8 @@ static void text_cursor_set_apply(bContext *C, wmOperator *op, const wmEvent *ev
|
||||
text_scroll_to_cursor(st, ar, false);
|
||||
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
|
||||
|
||||
ssel->old[0] = event->mval[0];
|
||||
ssel->old[1] = event->mval[1];
|
||||
ssel->mval_prev[0] = event->mval[0];
|
||||
ssel->mval_prev[1] = event->mval[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3218,7 +3223,7 @@ static void text_cursor_set_exit(bContext *C, wmOperator *op)
|
||||
MEM_freeN(ssel);
|
||||
}
|
||||
|
||||
static int text_set_selection_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
static int text_selection_set_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
{
|
||||
SpaceText *st = CTX_wm_space_text(C);
|
||||
SetSelection *ssel;
|
||||
@@ -3231,8 +3236,8 @@ static int text_set_selection_invoke(bContext *C, wmOperator *op, const wmEvent
|
||||
ssel = op->customdata;
|
||||
ssel->selecting = RNA_boolean_get(op->ptr, "select");
|
||||
|
||||
ssel->old[0] = event->mval[0];
|
||||
ssel->old[1] = event->mval[1];
|
||||
ssel->mval_prev[0] = event->mval[0];
|
||||
ssel->mval_prev[1] = event->mval[1];
|
||||
|
||||
ssel->sell = txt_get_span(st->text->lines.first, st->text->sell);
|
||||
ssel->selc = st->text->selc;
|
||||
@@ -3244,7 +3249,7 @@ static int text_set_selection_invoke(bContext *C, wmOperator *op, const wmEvent
|
||||
return OPERATOR_RUNNING_MODAL;
|
||||
}
|
||||
|
||||
static int text_set_selection_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
static int text_selection_set_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
{
|
||||
switch (event->type) {
|
||||
case LEFTMOUSE:
|
||||
@@ -3261,7 +3266,7 @@ static int text_set_selection_modal(bContext *C, wmOperator *op, const wmEvent *
|
||||
return OPERATOR_RUNNING_MODAL;
|
||||
}
|
||||
|
||||
static void text_set_selection_cancel(bContext *C, wmOperator *op)
|
||||
static void text_selection_set_cancel(bContext *C, wmOperator *op)
|
||||
{
|
||||
text_cursor_set_exit(C, op);
|
||||
}
|
||||
@@ -3274,9 +3279,9 @@ void TEXT_OT_selection_set(wmOperatorType *ot)
|
||||
ot->description = "Set cursor selection";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke = text_set_selection_invoke;
|
||||
ot->modal = text_set_selection_modal;
|
||||
ot->cancel = text_set_selection_cancel;
|
||||
ot->invoke = text_selection_set_invoke;
|
||||
ot->modal = text_selection_set_modal;
|
||||
ot->cancel = text_selection_set_cancel;
|
||||
ot->poll = text_region_edit_poll;
|
||||
|
||||
/* properties */
|
||||
|
||||
Reference in New Issue
Block a user