Commit: 1fdea43c29a7a0ffb65ec8049da574d4198d22af Author: Campbell Barton Date: Tue Dec 3 19:37:51 2019 +1100 Branches: master https://developer.blender.org/rB1fdea43c29a7a0ffb65ec8049da574d4198d22af
Fix minor errors with text view margins for console/info editor - Margins used duplicate define between files. - Cursor selection ignored margins. - Cursor wasn't scaling with DPI. Add a 'draw_rect' member which is the region rect with margins applied to make these checks clearer. This resolves issue pointed out in D6300, which complicated further refactoring. =================================================================== M source/blender/editors/space_console/console_draw.c M source/blender/editors/space_info/info_draw.c M source/blender/editors/space_info/textview.c M source/blender/editors/space_info/textview.h =================================================================== diff --git a/source/blender/editors/space_console/console_draw.c b/source/blender/editors/space_console/console_draw.c index 4d6b05df609..02278934c20 100644 --- a/source/blender/editors/space_console/console_draw.c +++ b/source/blender/editors/space_console/console_draw.c @@ -80,8 +80,6 @@ void console_scrollback_prompt_end(struct SpaceConsole *sc, ConsoleLine *cl_dumm BLI_remlink(&sc->scrollback, cl_dummy); } -#define CONSOLE_DRAW_MARGIN 4 - /* console textview callbacks */ static int console_textview_begin(TextViewContext *tvc) { @@ -150,7 +148,7 @@ static int console_textview_line_color(struct TextViewContext *tvc, const SpaceConsole *sc = (SpaceConsole *)tvc->arg1; const ConsoleLine *cl = (ConsoleLine *)sc->history.last; int offl = 0, offc = 0; - int xy[2] = {CONSOLE_DRAW_MARGIN, CONSOLE_DRAW_MARGIN}; + int xy[2] = {tvc->draw_rect.xmin, tvc->draw_rect.ymin}; int pen[2]; GPUVertFormat *format = immVertexFormat(); uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); @@ -169,9 +167,9 @@ static int console_textview_line_color(struct TextViewContext *tvc, immUniformThemeColor(TH_CONSOLE_CURSOR); immRectf(pos, - (xy[0] + pen[0]) - 1, + (xy[0] + pen[0]) - U.pixelsize, (xy[1] + pen[1]), - (xy[0] + pen[0]) + 1, + (xy[0] + pen[0]) + U.pixelsize, (xy[1] + pen[1] + tvc->lheight)); immUnbindProgram(); @@ -187,8 +185,22 @@ static void console_textview_const_colors(TextViewContext *UNUSED(tvc), unsigned UI_GetThemeColor4ubv(TH_CONSOLE_SELECT, bg_sel); } -static int console_textview_main__internal( - struct SpaceConsole *sc, ARegion *ar, int draw, int mval[2], void **mouse_pick, int *pos_pick) +static void console_textview_draw_rect_calc(const ARegion *ar, rcti *draw_rect) +{ + const int margin = 4 * UI_DPI_FAC; + draw_rect->xmin = margin; + draw_rect->xmax = ar->winx - (margin + V2D_SCROLL_WIDTH); + draw_rect->ymin = margin; + /* No margin at the top (allow text to scroll off the window). */ + draw_rect->ymax = ar->winy; +} + +static int console_textview_main__internal(struct SpaceConsole *sc, + ARegion *ar, + int draw, + const int mval[2], + void **mouse_pick, + int *pos_pick) { ConsoleLine cl_dummy = {NULL}; int ret = 0; @@ -214,7 +226,8 @@ static int console_textview_main__internal( tvc.lheight = sc->lheight * UI_DPI_FAC; tvc.ymin = v2d->cur.ymin; tvc.ymax = v2d->cur.ymax; - tvc.winx = ar->winx - V2D_SCROLL_WIDTH; + + console_textview_draw_rect_calc(ar, &tvc.draw_rect); console_scrollback_prompt_begin(sc, &cl_dummy); ret = textview_draw(&tvc, draw, mval, mouse_pick, pos_pick); @@ -225,13 +238,13 @@ static int console_textview_main__internal( void console_textview_main(struct SpaceConsole *sc, ARegion *ar) { - int mval[2] = {INT_MAX, INT_MAX}; + const int mval[2] = {INT_MAX, INT_MAX}; console_textview_main__internal(sc, ar, 1, mval, NULL, NULL); } int console_textview_height(struct SpaceConsole *sc, ARegion *ar) { - int mval[2] = {INT_MAX, INT_MAX}; + const int mval[2] = {INT_MAX, INT_MAX}; return console_textview_main__internal(sc, ar, 0, mval, NULL, NULL); } @@ -239,11 +252,10 @@ int console_char_pick(struct SpaceConsole *sc, ARegion *ar, const int mval[2]) { int pos_pick = 0; void *mouse_pick = NULL; - int mval_clamp[2]; - mval_clamp[0] = CLAMPIS(mval[0], CONSOLE_DRAW_MARGIN, ar->winx - CONSOLE_DRAW_MARGIN); - mval_clamp[1] = CLAMPIS(mval[1], CONSOLE_DRAW_MARGIN, ar->winy - CONSOLE_DRAW_MARGIN); + rcti draw_rect; + console_textview_draw_rect_calc(ar, &draw_rect); - console_textview_main__internal(sc, ar, 0, mval_clamp, &mouse_pick, &pos_pick); + console_textview_main__internal(sc, ar, 0, mval, &mouse_pick, &pos_pick); return pos_pick; } diff --git a/source/blender/editors/space_info/info_draw.c b/source/blender/editors/space_info/info_draw.c index 734515e1f79..a22983c15a8 100644 --- a/source/blender/editors/space_info/info_draw.c +++ b/source/blender/editors/space_info/info_draw.c @@ -228,6 +228,16 @@ static int report_textview_line_color(struct TextViewContext *tvc, #undef USE_INFO_NEWLINE +static void info_textview_draw_rect_calc(ARegion *ar, rcti *draw_rect) +{ + const int margin = 4 * UI_DPI_FAC; + draw_rect->xmin = margin; + draw_rect->xmax = ar->winx - (V2D_SCROLL_WIDTH + margin); + draw_rect->ymin = margin; + /* No margin at the top (allow text to scroll off the window). */ + draw_rect->ymax = ar->winy; +} + static int info_textview_main__internal(struct SpaceInfo *sinfo, ARegion *ar, ReportList *reports, @@ -258,7 +268,8 @@ static int info_textview_main__internal(struct SpaceInfo *sinfo, tvc.lheight = 14 * UI_DPI_FAC; // sc->lheight; tvc.ymin = v2d->cur.ymin; tvc.ymax = v2d->cur.ymax; - tvc.winx = ar->winx - V2D_SCROLL_WIDTH; + + info_textview_draw_rect_calc(ar, &tvc.draw_rect); ret = textview_draw(&tvc, draw, mval, mouse_pick, pos_pick); diff --git a/source/blender/editors/space_info/textview.c b/source/blender/editors/space_info/textview.c index 97d5faa9c13..0ebd8bdc065 100644 --- a/source/blender/editors/space_info/textview.c +++ b/source/blender/editors/space_info/textview.c @@ -51,7 +51,7 @@ typedef struct ConsoleDrawContext { int lofs; /** number of characters that fit into the width of the console (fixed width) */ int console_width; - int winx; + const rcti *draw_rect; int ymin, ymax; int *xy; // [2] int *sel; // [2] @@ -201,7 +201,8 @@ static int console_draw_string(ConsoleDrawContext *cdc, immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); immUniformColor3ubv(bg); - immRecti(pos, 0, cdc->xy[1], cdc->winx, (cdc->xy[1] + (cdc->lheight * tot_lines))); + immRecti( + pos, 0, cdc->xy[1], cdc->draw_rect->xmax, (cdc->xy[1] + (cdc->lheight * tot_lines))); immUnbindProgram(); } @@ -252,7 +253,7 @@ static int console_draw_string(ConsoleDrawContext *cdc, immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); immUniformColor3ubv(bg); - immRecti(pos, 0, cdc->xy[1], cdc->winx, cdc->xy[1] + cdc->lheight); + immRecti(pos, 0, cdc->xy[1], cdc->draw_rect->xmax, cdc->xy[1] + cdc->lheight); immUnbindProgram(); } @@ -284,15 +285,13 @@ static int console_draw_string(ConsoleDrawContext *cdc, return 1; } -#define CONSOLE_DRAW_MARGIN 4 - int textview_draw( - TextViewContext *tvc, const int draw, int mval[2], void **mouse_pick, int *pos_pick) + TextViewContext *tvc, const int draw, const int mval_init[2], void **mouse_pick, int *pos_pick) { ConsoleDrawContext cdc = {0}; - int x_orig = CONSOLE_DRAW_MARGIN, y_orig = CONSOLE_DRAW_MARGIN + tvc->lheight / 6; - int xy[2], y_prev; + int x_orig = tvc->draw_rect.xmin, y_orig = tvc->draw_rect.ymin + tvc->lheight / 6; + int xy[2]; int sel[2] = {-1, -1}; /* defaults disabled */ unsigned char fg[3], bg[3]; const int font_id = blf_mono_font; @@ -302,9 +301,16 @@ int textview_draw( xy[0] = x_orig; xy[1] = y_orig; - if (mval[1] != INT_MAX) { - mval[1] += (tvc->ymin + CONSOLE_DRAW_MARGIN); - } + /* Offset and clamp the results, + * clamping so moving the cursor out of the bounds doesn't weap onto the other lines. */ + const int mval[2] = { + (mval_init[0] == INT_MAX) ? + INT_MAX : + CLAMPIS(mval_init[0], tvc->draw_rect.xmin, tvc->draw_rect.xmax) - tvc->draw_rect.xmin, + (mval_init[1] == INT_MAX) ? + INT_MAX : + CLAMPIS(mval_init[1], tvc->draw_rect.ymin, tvc->draw_rect.ymax) + tvc->ymin, + }; if (pos_pick) { *pos_pick = 0; @@ -317,12 +323,12 @@ int textview_draw( cdc.lheight = tvc->lheight; cdc.lofs = -BLF_descender(font_id); /* note, scroll bar must be already subtracted () */ - cdc.console_width = (tvc->winx - (CONSOLE_DRAW_MARGIN * 2)) / cdc.cwidth; + cdc.console_width = (tvc->draw_rect.xmax - tvc->draw_rect.xmin) / cdc.cwidth; /* avoid divide by zero on small windows */ if (cdc.console_width < 1) { cdc.console_width = 1; } - cdc.winx = tvc->winx - CONSOLE_DRAW_MARGIN; + cdc.draw_rect = &tvc->draw_rect; cdc.ymin = tvc->ymin; cdc.ymax = tvc->ymax; cdc.xy = xy; @@ -353,7 +359,7 @@ int textview_draw( int ext_len; int color_flag = 0; - y_prev = xy[1]; + const int y_prev = xy[1]; if (draw) { color_flag = tvc->line_color(tvc, fg, bg); diff --git a/source/blender/editors/space_info/textview.h b/source/blender/editors/space_info/textview.h index aa0e924b461..ca5744dbe90 100644 --- a/source/blender/editors/space_info/textview.h +++ b/source/blender/editors/space_info/textview.h @@ -29,7 +29,9 @@ typedef struct TextViewContext { int cwidth; /* shouldnt be needed! */ int console_width; /* shouldnt be needed! */ - int winx; + /** Area to draw: (0, 0, winx, winy) with a margin applied and scroll-bar subtracted. */ + rcti draw_rect; + int ymin, ymax; /* callbacks */ @@ -52,8 +54,11 @@ typedef struct TextViewContext { } TextViewContext; -int textview_draw( - struct TextViewContext *tvc, const int draw, int mval[2], void **mouse_pick, int *pos_pick); +int textview_draw(struct TextViewContext *tvc, + const int draw, + const int mval_init[2], + void **mouse_pick, + int *pos_pick); #define TVC_LINE_FG (1 << 0) #define TVC_LINE_BG (1 << 1) _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs