From 69be8039e80f55760ddc652bf79240d9d5ab38bc Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 14 Feb 2020 13:38:47 +1100 Subject: Fix T73784: Python console: incorrect wrapped line cursor position Regression in aa919f3e82020 Remove character margins, it complicated drawing & picking to have one margin in pixels and a second margin in characters. Replace this with an outer pixel-margin for drawing background colors. --- source/blender/editors/space_info/info_draw.c | 23 +++++++++++------ source/blender/editors/space_info/textview.c | 37 ++++++++++----------------- source/blender/editors/space_info/textview.h | 6 ++--- 3 files changed, 31 insertions(+), 35 deletions(-) (limited to 'source/blender/editors/space_info') diff --git a/source/blender/editors/space_info/info_draw.c b/source/blender/editors/space_info/info_draw.c index 03ff680a93d..d0ff9495a74 100644 --- a/source/blender/editors/space_info/info_draw.c +++ b/source/blender/editors/space_info/info_draw.c @@ -206,12 +206,21 @@ static int report_textview_line_get(struct TextViewContext *tvc, const char **li return 1; } -static void info_textview_draw_rect_calc(const ARegion *ar, rcti *draw_rect) +static void info_textview_draw_rect_calc(const ARegion *ar, + rcti *r_draw_rect, + rcti *r_draw_rect_outer) { - draw_rect->xmin = 0; - draw_rect->xmax = ar->winx; - draw_rect->ymin = 0; - draw_rect->ymax = ar->winy; + const int margin = 0.45f * U.widget_unit; + r_draw_rect->xmin = margin + UI_UNIT_X; + r_draw_rect->xmax = ar->winx - V2D_SCROLL_WIDTH; + r_draw_rect->ymin = margin; + r_draw_rect->ymax = ar->winy; + /* No margin at the top (allow text to scroll off the window). */ + + r_draw_rect_outer->xmin = 0; + r_draw_rect_outer->xmax = ar->winx; + r_draw_rect_outer->ymin = 0; + r_draw_rect_outer->ymax = ar->winy; } static int info_textview_main__internal(struct SpaceInfo *sinfo, @@ -243,12 +252,10 @@ static int info_textview_main__internal(struct SpaceInfo *sinfo, tvc.sel_end = 0; tvc.lheight = 17 * UI_DPI_FAC; tvc.row_vpadding = 0.4 * tvc.lheight; - tvc.margin_left_chars = 5; - tvc.margin_right_chars = 2; tvc.scroll_ymin = v2d->cur.ymin; tvc.scroll_ymax = v2d->cur.ymax; - info_textview_draw_rect_calc(ar, &tvc.draw_rect); + info_textview_draw_rect_calc(ar, &tvc.draw_rect, &tvc.draw_rect_outer); ret = textview_draw(&tvc, do_draw, mval, r_mval_pick_item, r_mval_pick_offset); diff --git a/source/blender/editors/space_info/textview.c b/source/blender/editors/space_info/textview.c index c145f5d333f..aeec1e30e34 100644 --- a/source/blender/editors/space_info/textview.c +++ b/source/blender/editors/space_info/textview.c @@ -53,12 +53,13 @@ typedef struct TextViewDrawState { int lheight; /** Text vertical offset per line. */ int lofs; - int margin_left_chars; - int margin_right_chars; int row_vpadding; /** Number of characters that fit into the width of the console (fixed width). */ int columns; + /** For drawing text. */ const rcti *draw_rect; + /** For drawing backgrounds colors which may extend beyond text. */ + const rcti *draw_rect_outer; int scroll_ymin, scroll_ymax; int *xy; // [2] int *sel; // [2] @@ -85,9 +86,8 @@ static void console_draw_sel(const char *str, const int lheight = tds->lheight; if (sel[0] <= str_len_draw && sel[1] >= 0) { - const int sta = BLI_str_utf8_offset_to_column(str, max_ii(sel[0], 0)) + tds->margin_left_chars; - const int end = BLI_str_utf8_offset_to_column(str, min_ii(sel[1], str_len_draw)) + - tds->margin_left_chars; + const int sta = BLI_str_utf8_offset_to_column(str, max_ii(sel[0], 0)); + const int end = BLI_str_utf8_offset_to_column(str, min_ii(sel[1], str_len_draw)); GPU_blend(true); GPU_blend_set_func_separate( @@ -154,11 +154,7 @@ static bool console_draw_string(TextViewDrawState *tds, int tot_lines; /* Total number of lines for wrapping. */ int *offsets; /* Offsets of line beginnings for wrapping. */ - str_len = console_wrap_offsets(str, - str_len, - tds->columns - (tds->margin_left_chars + tds->margin_right_chars), - &tot_lines, - &offsets); + str_len = console_wrap_offsets(str, str_len, tds->columns, &tot_lines, &offsets); int line_height = (tot_lines * tds->lheight) + (tds->row_vpadding * 2); int line_bottom = tds->xy[1]; @@ -223,15 +219,15 @@ static bool console_draw_string(TextViewDrawState *tds, uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT); immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); immUniformColor4ubv(bg); - immRecti(pos, 0, line_bottom, tds->draw_rect->xmax, line_top); + immRecti(pos, tds->draw_rect_outer->xmin, line_bottom, tds->draw_rect_outer->xmax, line_top); immUnbindProgram(); } if (icon_bg) { float col[4]; - int bg_size = 20 * UI_DPI_FAC; + int bg_size = UI_DPI_ICON_SIZE * 1.2; float vpadding = (tds->lheight + (tds->row_vpadding * 2) - bg_size) / 2; - float hpadding = ((tds->margin_left_chars * tds->cwidth) - bg_size) / 2; + float hpadding = tds->draw_rect->xmin - (bg_size * 1.2f); rgba_uchar_to_float(col, icon_bg); UI_draw_roundbox_corner_set(UI_CNR_ALL); @@ -246,7 +242,7 @@ static bool console_draw_string(TextViewDrawState *tds, if (icon) { int vpadding = (tds->lheight + (tds->row_vpadding * 2) - UI_DPI_ICON_SIZE) / 2; - int hpadding = ((tds->margin_left_chars * tds->cwidth) - UI_DPI_ICON_SIZE) / 2; + int hpadding = tds->draw_rect->xmin - (UI_DPI_ICON_SIZE * 1.3f); GPU_blend(true); UI_icon_draw_ex(hpadding, @@ -266,10 +262,7 @@ static bool console_draw_string(TextViewDrawState *tds, const int final_offset = offsets[tot_lines - 1]; len = str_len - final_offset; s = str + final_offset; - BLF_position(tds->font_id, - tds->xy[0] + (tds->margin_left_chars * tds->cwidth), - tds->lofs + line_bottom + tds->row_vpadding, - 0); + BLF_position(tds->font_id, tds->xy[0], tds->lofs + line_bottom + tds->row_vpadding, 0); BLF_color4ubv(tds->font_id, fg); BLF_draw_mono(tds->font_id, s, len, tds->cwidth); @@ -287,10 +280,7 @@ static bool console_draw_string(TextViewDrawState *tds, len = offsets[i] - offsets[i - 1]; s = str + offsets[i - 1]; - BLF_position(tds->font_id, - tds->xy[0] + (tds->margin_left_chars * tds->cwidth), - tds->lofs + tds->xy[1], - 0); + BLF_position(tds->font_id, tds->xy[0], tds->lofs + tds->xy[1], 0); BLF_draw_mono(tds->font_id, s, len, tds->cwidth); if (tds->sel[0] != tds->sel[1]) { @@ -364,8 +354,6 @@ int textview_draw(TextViewContext *tvc, tds.cwidth = (int)BLF_fixed_width(font_id); BLI_assert(tds.cwidth > 0); tds.lheight = tvc->lheight; - tds.margin_left_chars = tvc->margin_left_chars; - tds.margin_right_chars = tvc->margin_right_chars; tds.row_vpadding = tvc->row_vpadding; tds.lofs = -BLF_descender(font_id); /* Note, scroll bar must be already subtracted. */ @@ -375,6 +363,7 @@ int textview_draw(TextViewContext *tvc, tds.columns = 1; } tds.draw_rect = &tvc->draw_rect; + tds.draw_rect_outer = &tvc->draw_rect_outer; tds.scroll_ymin = tvc->scroll_ymin; tds.scroll_ymax = tvc->scroll_ymax; tds.xy = xy; diff --git a/source/blender/editors/space_info/textview.h b/source/blender/editors/space_info/textview.h index 3f7ba9739c4..6fcd9d30abe 100644 --- a/source/blender/editors/space_info/textview.h +++ b/source/blender/editors/space_info/textview.h @@ -32,11 +32,11 @@ typedef struct TextViewContext { int columns; /* shouldnt be needed! */ int row_vpadding; - int margin_left_chars; - int margin_right_chars; - /** Area to draw: (0, 0, winx, winy) with a margin applied and scroll-bar subtracted. */ + /** Area to draw text: (0, 0, winx, winy) with a margin applied and scroll-bar subtracted. */ rcti draw_rect; + /** Area to draw text background colors (extending beyond text in some cases). */ + rcti draw_rect_outer; /** Scroll offset in pixels. */ int scroll_ymin, scroll_ymax; -- cgit v1.2.3