diff options
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/include/UI_resources.h | 4 | ||||
-rw-r--r-- | source/blender/editors/interface/resources.c | 12 | ||||
-rw-r--r-- | source/blender/editors/space_console/console_draw.c | 107 | ||||
-rw-r--r-- | source/blender/editors/space_info/info_draw.c | 153 | ||||
-rw-r--r-- | source/blender/editors/space_info/textview.c | 229 | ||||
-rw-r--r-- | source/blender/editors/space_info/textview.h | 21 |
6 files changed, 288 insertions, 238 deletions
diff --git a/source/blender/editors/include/UI_resources.h b/source/blender/editors/include/UI_resources.h index 66662c8c27d..1e6e46cbe71 100644 --- a/source/blender/editors/include/UI_resources.h +++ b/source/blender/editors/include/UI_resources.h @@ -321,6 +321,10 @@ typedef enum ThemeColorID { TH_INFO_INFO_TEXT, TH_INFO_DEBUG, TH_INFO_DEBUG_TEXT, + TH_INFO_PROPERTY, + TH_INFO_PROPERTY_TEXT, + TH_INFO_OPERATOR, + TH_INFO_OPERATOR_TEXT, TH_VIEW_OVERLAY, TH_V3D_CLIPPING_BORDER, diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c index 37921b48401..3aede744115 100644 --- a/source/blender/editors/interface/resources.c +++ b/source/blender/editors/interface/resources.c @@ -972,6 +972,18 @@ const uchar *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid) case TH_INFO_DEBUG_TEXT: cp = ts->info_debug_text; break; + case TH_INFO_PROPERTY: + cp = ts->info_property; + break; + case TH_INFO_PROPERTY_TEXT: + cp = ts->info_property_text; + break; + case TH_INFO_OPERATOR: + cp = ts->info_operator; + break; + case TH_INFO_OPERATOR_TEXT: + cp = ts->info_operator_text; + break; case TH_V3D_CLIPPING_BORDER: cp = ts->clipping_border_3d; break; diff --git a/source/blender/editors/space_console/console_draw.c b/source/blender/editors/space_console/console_draw.c index bf6683ffc33..c9dde11cbeb 100644 --- a/source/blender/editors/space_console/console_draw.c +++ b/source/blender/editors/space_console/console_draw.c @@ -42,22 +42,33 @@ #include "../space_info/textview.h" -static void console_line_color(unsigned char fg[3], int type) +static int console_line_data(struct TextViewContext *tvc, + unsigned char fg[4], + unsigned char UNUSED(bg[4]), + int *UNUSED(icon), + unsigned char UNUSED(icon_fg[4]), + unsigned char UNUSED(icon_bg[4])) { - switch (type) { + ConsoleLine *cl_iter = (ConsoleLine *)tvc->iter; + int fg_id = TH_TEXT; + + switch (cl_iter->type) { case CONSOLE_LINE_OUTPUT: - UI_GetThemeColor3ubv(TH_CONSOLE_OUTPUT, fg); + fg_id = TH_CONSOLE_OUTPUT; break; case CONSOLE_LINE_INPUT: - UI_GetThemeColor3ubv(TH_CONSOLE_INPUT, fg); + fg_id = TH_CONSOLE_INPUT; break; case CONSOLE_LINE_INFO: - UI_GetThemeColor3ubv(TH_CONSOLE_INFO, fg); + fg_id = TH_CONSOLE_INFO; break; case CONSOLE_LINE_ERROR: - UI_GetThemeColor3ubv(TH_CONSOLE_ERROR, fg); + fg_id = TH_CONSOLE_ERROR; break; } + + UI_GetThemeColor4ubv(fg_id, fg); + return TVC_LINE_FG; } void console_scrollback_prompt_begin(struct SpaceConsole *sc, ConsoleLine *cl_dummy) @@ -137,47 +148,36 @@ static void console_cursor_wrap_offset( return; } -static int console_textview_line_color(struct TextViewContext *tvc, - unsigned char fg[3], - unsigned char UNUSED(bg[3])) +static void console_textview_draw_cursor(struct TextViewContext *tvc) { - ConsoleLine *cl_iter = (ConsoleLine *)tvc->iter; - - /* annoying hack, to draw the prompt */ - if (tvc->iter_index == 0) { - const SpaceConsole *sc = (SpaceConsole *)tvc->arg1; - const ConsoleLine *cl = (ConsoleLine *)sc->history.last; - int offl = 0, offc = 0; - 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); - xy[1] += tvc->lheight / 6; - - console_cursor_wrap_offset(sc->prompt, tvc->columns, &offl, &offc, NULL); - console_cursor_wrap_offset(cl->line, tvc->columns, &offl, &offc, cl->line + cl->cursor); - pen[0] = tvc->cwidth * offc; - pen[1] = -2 - tvc->lheight * offl; - - console_cursor_wrap_offset(cl->line + cl->cursor, tvc->columns, &offl, &offc, NULL); - pen[1] += tvc->lheight * offl; - - /* cursor */ - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); - immUniformThemeColor(TH_CONSOLE_CURSOR); - - immRectf(pos, - (xy[0] + pen[0]) - U.pixelsize, - (xy[1] + pen[1]), - (xy[0] + pen[0]) + U.pixelsize, - (xy[1] + pen[1] + tvc->lheight)); - - immUnbindProgram(); - } - - console_line_color(fg, cl_iter->type); - - return TVC_LINE_FG; + const SpaceConsole *sc = (SpaceConsole *)tvc->arg1; + const ConsoleLine *cl = (ConsoleLine *)sc->history.last; + int offl = 0, offc = 0; + 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); + xy[1] += tvc->lheight * 0.35f; + + console_cursor_wrap_offset(sc->prompt, tvc->columns, &offl, &offc, NULL); + console_cursor_wrap_offset(cl->line, tvc->columns, &offl, &offc, cl->line + cl->cursor); + pen[0] = tvc->cwidth * (offc + tvc->margin_left_chars); + pen[1] = -2 - tvc->lheight * offl; + + console_cursor_wrap_offset(cl->line + cl->cursor, tvc->columns, &offl, &offc, NULL); + pen[1] += tvc->lheight * offl; + + /* cursor */ + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + immUniformThemeColor(TH_CONSOLE_CURSOR); + + immRectf(pos, + (xy[0] + pen[0]) - U.pixelsize, + (xy[1] + pen[1]), + (xy[0] + pen[0]) + U.pixelsize, + (xy[1] + pen[1] + tvc->lheight)); + + immUnbindProgram(); } static void console_textview_const_colors(TextViewContext *UNUSED(tvc), unsigned char bg_sel[4]) @@ -187,11 +187,9 @@ static void console_textview_const_colors(TextViewContext *UNUSED(tvc), unsigned 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->xmin = 0; + draw_rect->xmax = ar->winx; + draw_rect->ymin = 0; draw_rect->ymax = ar->winy; } @@ -214,7 +212,8 @@ static int console_textview_main__internal(struct SpaceConsole *sc, tvc.step = console_textview_step; tvc.line_get = console_textview_line_get; - tvc.line_color = console_textview_line_color; + tvc.line_data = console_line_data; + tvc.draw_cursor = console_textview_draw_cursor; tvc.const_colors = console_textview_const_colors; tvc.arg1 = sc; @@ -223,7 +222,9 @@ static int console_textview_main__internal(struct SpaceConsole *sc, /* view */ tvc.sel_start = sc->sel_start; tvc.sel_end = sc->sel_end; - tvc.lheight = sc->lheight * UI_DPI_FAC; + tvc.lheight = sc->lheight * 1.2f * UI_DPI_FAC; + tvc.margin_left_chars = 1; + tvc.margin_right_chars = 2; tvc.scroll_ymin = v2d->cur.ymin; tvc.scroll_ymax = v2d->cur.ymax; diff --git a/source/blender/editors/space_info/info_draw.c b/source/blender/editors/space_info/info_draw.c index 64570459532..d86e0e2af97 100644 --- a/source/blender/editors/space_info/info_draw.c +++ b/source/blender/editors/space_info/info_draw.c @@ -42,48 +42,78 @@ #include "textview.h" #include "GPU_framebuffer.h" -/* complicates things a bit, so leaving in old simple code */ -#define USE_INFO_NEWLINE - -static void info_report_color(unsigned char *fg, - unsigned char *bg, - Report *report, - const short do_tint) +static int report_line_data(struct TextViewContext *tvc, + unsigned char fg[4], + unsigned char bg[4], + int *icon, + unsigned char icon_fg[4], + unsigned char icon_bg[4]) { - int bg_id = TH_BACK, fg_id = TH_TEXT; - int shade = do_tint ? 0 : -6; + Report *report = (Report *)tvc->iter; - if (report->flag & SELECT) { - bg_id = TH_INFO_SELECTED; - fg_id = TH_INFO_SELECTED_TEXT; - } - else if (report->type & RPT_ERROR_ALL) { - bg_id = TH_INFO_ERROR; - fg_id = TH_INFO_ERROR_TEXT; + /* Same text color no matter what type of report. */ + UI_GetThemeColor4ubv((report->flag & SELECT) ? TH_INFO_SELECTED_TEXT : TH_TEXT, fg); + + /* Zebra striping for background. */ + int bg_id = (report->flag & SELECT) ? TH_INFO_SELECTED : TH_BACK; + int shade = tvc->iter_tmp % 2 ? 4 : -4; + UI_GetThemeColorShade4ubv(bg_id, shade, bg); + + /* Icon color and backgound depend of report type. */ + + int icon_fg_id; + int icon_bg_id; + + if (report->type & RPT_ERROR_ALL) { + icon_fg_id = TH_INFO_ERROR_TEXT; + icon_bg_id = TH_INFO_ERROR; + *icon = ICON_CANCEL; } else if (report->type & RPT_WARNING_ALL) { - bg_id = TH_INFO_WARNING; - fg_id = TH_INFO_WARNING_TEXT; + icon_fg_id = TH_INFO_WARNING_TEXT; + icon_bg_id = TH_INFO_WARNING; + *icon = ICON_ERROR; } else if (report->type & RPT_INFO_ALL) { - bg_id = TH_INFO_INFO; - fg_id = TH_INFO_INFO_TEXT; + icon_fg_id = TH_INFO_INFO_TEXT; + icon_bg_id = TH_INFO_INFO; + *icon = ICON_INFO; } else if (report->type & RPT_DEBUG_ALL) { - bg_id = TH_INFO_DEBUG; - fg_id = TH_INFO_DEBUG_TEXT; + icon_fg_id = TH_INFO_DEBUG_TEXT; + icon_bg_id = TH_INFO_DEBUG; + *icon = ICON_SYSTEM; + } + else if (report->type & RPT_PROPERTY) { + icon_fg_id = TH_INFO_PROPERTY_TEXT; + icon_bg_id = TH_INFO_PROPERTY; + *icon = ICON_OPTIONS; + } + else if (report->type & RPT_OPERATOR) { + icon_fg_id = TH_INFO_OPERATOR_TEXT; + icon_bg_id = TH_INFO_OPERATOR; + *icon = ICON_CHECKMARK; } else { - bg_id = TH_BACK; - fg_id = TH_TEXT; + *icon = ICON_NONE; } - UI_GetThemeColorShade3ubv(bg_id, shade, bg); - UI_GetThemeColor3ubv(fg_id, fg); + if (report->flag & SELECT) { + icon_fg_id = TH_INFO_SELECTED; + icon_bg_id = TH_INFO_SELECTED_TEXT; + } + + if (*icon != ICON_NONE) { + UI_GetThemeColor4ubv(icon_fg_id, icon_fg); + UI_GetThemeColor4ubv(icon_bg_id, icon_bg); + return TVC_LINE_FG | TVC_LINE_BG | TVC_LINE_ICON | TVC_LINE_ICON_FG | TVC_LINE_ICON_BG; + } + else { + return TVC_LINE_FG | TVC_LINE_BG; + } } /* reports! */ -#ifdef USE_INFO_NEWLINE static void report_textview_init__internal(TextViewContext *tvc) { Report *report = (Report *)tvc->iter; @@ -108,14 +138,11 @@ static int report_textview_skip__internal(TextViewContext *tvc) return (tvc->iter != NULL); } -#endif // USE_INFO_NEWLINE - static int report_textview_begin(TextViewContext *tvc) { - // SpaceConsole *sc = (SpaceConsole *)tvc->arg1; ReportList *reports = (ReportList *)tvc->arg2; - tvc->lheight = 14 * UI_DPI_FAC; // sc->lheight; + tvc->lheight = 14 * UI_DPI_FAC; tvc->sel_start = 0; tvc->sel_end = 0; @@ -125,7 +152,6 @@ static int report_textview_begin(TextViewContext *tvc) UI_ThemeClearColor(TH_BACK); GPU_clear(GPU_COLOR_BIT); -#ifdef USE_INFO_NEWLINE tvc->iter_tmp = 0; if (tvc->iter && report_textview_skip__internal(tvc)) { /* init the newline iterator */ @@ -137,9 +163,6 @@ static int report_textview_begin(TextViewContext *tvc) else { return false; } -#else - return (tvc->iter != NULL); -#endif } static void report_textview_end(TextViewContext *UNUSED(tvc)) @@ -147,7 +170,6 @@ static void report_textview_end(TextViewContext *UNUSED(tvc)) /* pass */ } -#ifdef USE_INFO_NEWLINE static int report_textview_step(TextViewContext *tvc) { /* simple case, but no newline support */ @@ -184,57 +206,11 @@ static int report_textview_line_get(struct TextViewContext *tvc, const char **li return 1; } -static int report_textview_line_color(struct TextViewContext *tvc, - unsigned char fg[3], - unsigned char bg[3]) -{ - Report *report = (Report *)tvc->iter; - info_report_color(fg, bg, report, tvc->iter_tmp % 2); - return TVC_LINE_FG | TVC_LINE_BG; -} - -#else // USE_INFO_NEWLINE - -static int report_textview_step(TextViewContext *tvc) -{ - SpaceInfo *sinfo = (SpaceInfo *)tvc->arg1; - const int report_mask = info_report_mask(sinfo); - do { - tvc->iter = (void *)((Link *)tvc->iter)->prev; - } while (tvc->iter && (((Report *)tvc->iter)->type & report_mask) == 0); - - return (tvc->iter != NULL); -} - -static int report_textview_line_get(struct TextViewContext *tvc, const char **line, int *len) -{ - Report *report = (Report *)tvc->iter; - *line = report->message; - *len = report->len; - - return 1; -} - -static int report_textview_line_color(struct TextViewContext *tvc, - unsigned char fg[3], - unsigned char bg[3]) -{ - Report *report = (Report *)tvc->iter; - info_report_color(fg, bg, report, tvc->iter_tmp % 2); - return TVC_LINE_FG | TVC_LINE_BG; -} - -#endif // USE_INFO_NEWLINE - -#undef USE_INFO_NEWLINE - static void info_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 - (V2D_SCROLL_WIDTH + margin); - draw_rect->ymin = margin; - /* No margin at the top (allow text to scroll off the window). */ + draw_rect->xmin = 0; + draw_rect->xmax = ar->winx; + draw_rect->ymin = 0; draw_rect->ymax = ar->winy; } @@ -256,7 +232,7 @@ static int info_textview_main__internal(struct SpaceInfo *sinfo, tvc.step = report_textview_step; tvc.line_get = report_textview_line_get; - tvc.line_color = report_textview_line_color; + tvc.line_data = report_line_data; tvc.const_colors = NULL; tvc.arg1 = sinfo; @@ -265,7 +241,10 @@ static int info_textview_main__internal(struct SpaceInfo *sinfo, /* view */ tvc.sel_start = 0; tvc.sel_end = 0; - tvc.lheight = 14 * UI_DPI_FAC; // sc->lheight; + 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; diff --git a/source/blender/editors/space_info/textview.c b/source/blender/editors/space_info/textview.c index 1bc583461a5..9828034aaac 100644 --- a/source/blender/editors/space_info/textview.c +++ b/source/blender/editors/space_info/textview.c @@ -35,12 +35,16 @@ #include "GPU_immediate.h" #include "GPU_state.h" +#include "BKE_report.h" +#include "UI_interface.h" +#include "UI_interface_icons.h" + #include "textview.h" static void console_font_begin(const int font_id, const int lheight) { - /* 0.875 is based on: 16 pixels lines get 14 pixel text. */ - BLF_size(font_id, 0.875 * lheight, 72); + /* Font size in relation to line height. */ + BLF_size(font_id, 0.8f * lheight, 72); } typedef struct TextViewDrawState { @@ -49,6 +53,9 @@ 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; const rcti *draw_rect; @@ -68,16 +75,19 @@ BLI_INLINE void console_step_sel(TextViewDrawState *tds, const int step) } static void console_draw_sel(const char *str, - const int sel[2], const int xy[2], const int str_len_draw, - const int cwidth, - const int lheight, + TextViewDrawState *tds, const unsigned char bg_sel[4]) { + const int sel[2] = {tds->sel[0], tds->sel[1]}; + const int cwidth = tds->cwidth; + 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)); - const int end = BLI_str_utf8_offset_to_column(str, min_ii(sel[1], str_len_draw)); + 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; GPU_blend(true); GPU_blend_set_func_separate( @@ -134,20 +144,32 @@ static int console_wrap_offsets(const char *str, int len, int width, int *lines, static bool console_draw_string(TextViewDrawState *tds, const char *str, int str_len, - const unsigned char fg[3], - const unsigned char bg[3], + const unsigned char fg[4], + const unsigned char bg[4], + int icon, + const unsigned char icon_fg[4], + const unsigned char icon_bg[4], const unsigned char bg_sel[4]) { int tot_lines; /* Total number of lines for wrapping. */ int *offsets; /* Offsets of line beginnings for wrapping. */ - int y_next; - str_len = console_wrap_offsets(str, str_len, tds->columns, &tot_lines, &offsets); - y_next = tds->xy[1] + tds->lheight * tot_lines; + str_len = console_wrap_offsets(str, + str_len, + tds->columns - (tds->margin_left_chars + tds->margin_right_chars), + &tot_lines, + &offsets); + + + int line_height = (tot_lines * tds->lheight) + (tds->row_vpadding * 2); + int line_bottom = tds->xy[1]; + int line_top = line_bottom + line_height; + + int y_next = line_top; /* Just advance the height. */ if (tds->do_draw == false) { - if (tds->mval_pick_offset && tds->mval[1] != INT_MAX && tds->xy[1] <= tds->mval[1]) { + if (tds->mval_pick_offset && tds->mval[1] != INT_MAX && line_bottom <= tds->mval[1]) { if (y_next >= tds->mval[1]) { int ofs = 0; @@ -186,107 +208,111 @@ static bool console_draw_string(TextViewDrawState *tds, return true; } - /* Check if we need to wrap lines. */ - if (tot_lines > 1) { - const int initial_offset = offsets[tot_lines - 1]; - size_t len = str_len - initial_offset; - const char *s = str + initial_offset; - int i; - - int sel_orig[2]; - copy_v2_v2_int(sel_orig, tds->sel); - - /* Invert and swap for wrapping. */ - tds->sel[0] = str_len - sel_orig[1]; - tds->sel[1] = str_len - sel_orig[0]; - - if (bg) { - GPUVertFormat *format = immVertexFormat(); - uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT); - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); - - immUniformColor3ubv(bg); - immRecti( - pos, 0, tds->xy[1], tds->draw_rect->xmax, (tds->xy[1] + (tds->lheight * tot_lines))); - - immUnbindProgram(); - } - - /* Last part needs no clipping. */ - BLF_position(tds->font_id, tds->xy[0], tds->lofs + tds->xy[1], 0); - BLF_color3ubv(tds->font_id, fg); - BLF_draw_mono(tds->font_id, s, len, tds->cwidth); - - if (tds->sel[0] != tds->sel[1]) { - console_step_sel(tds, -initial_offset); - /* BLF_color3ub(tds->font_id, 255, 0, 0); // debug */ - console_draw_sel(s, tds->sel, tds->xy, len, tds->cwidth, tds->lheight, bg_sel); - } + size_t len; + const char *s; + int i; - tds->xy[1] += tds->lheight; + int sel_orig[2]; + copy_v2_v2_int(sel_orig, tds->sel); - for (i = tot_lines - 1; i > 0; i--) { - len = offsets[i] - offsets[i - 1]; - s = str + offsets[i - 1]; + /* Invert and swap for wrapping. */ + tds->sel[0] = str_len - sel_orig[1]; + tds->sel[1] = str_len - sel_orig[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 (bg) { + GPUVertFormat *format = immVertexFormat(); + 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); + immUnbindProgram(); + } - if (tds->sel[0] != tds->sel[1]) { - console_step_sel(tds, len); - /* BLF_color3ub(tds->font_id, 0, 255, 0); // debug */ - console_draw_sel(s, tds->sel, tds->xy, len, tds->cwidth, tds->lheight, bg_sel); - } + if (icon_bg) { + float col[4]; + int bg_size = 20 * UI_DPI_FAC; + float vpadding = (tds->lheight + (tds->row_vpadding * 2) - bg_size) / 2; + float hpadding = ((tds->margin_left_chars * tds->cwidth) - bg_size) / 2; + + rgba_uchar_to_float(col, icon_bg); + UI_draw_roundbox_corner_set(UI_CNR_ALL); + UI_draw_roundbox_aa(true, + hpadding, + line_top - bg_size - vpadding, + bg_size + hpadding, + line_top - vpadding, + 4 * UI_DPI_FAC, + col); + } - tds->xy[1] += tds->lheight; + 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; - /* Check if were out of view bounds. */ - if (tds->xy[1] > tds->scroll_ymax) { - MEM_freeN(offsets); - return false; - } - } + GPU_blend(true); + UI_icon_draw_ex(hpadding, + line_top - UI_DPI_ICON_SIZE - vpadding, + icon, + (16 / UI_DPI_ICON_SIZE), + 1.0f, + 0.0f, + icon_fg, + false); + GPU_blend(false); + } - copy_v2_v2_int(tds->sel, sel_orig); - console_step_sel(tds, -(str_len + 1)); + tds->xy[1] += tds->row_vpadding; + + /* Last part needs no clipping. */ + 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_color4ubv(tds->font_id, fg); + BLF_draw_mono(tds->font_id, s, len, tds->cwidth); + + if (tds->sel[0] != tds->sel[1]) { + console_step_sel(tds, -final_offset); + int pos[2] = {tds->xy[0], line_bottom}; + console_draw_sel(s, pos, len, tds, bg_sel); } - else { - /* Simple, no wrap. */ - if (bg) { - GPUVertFormat *format = immVertexFormat(); - uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT); - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + tds->xy[1] += tds->lheight; - immUniformColor3ubv(bg); - immRecti(pos, 0, tds->xy[1], tds->draw_rect->xmax, tds->xy[1] + tds->lheight); + BLF_color4ubv(tds->font_id, fg); - immUnbindProgram(); - } + for (i = tot_lines - 1; i > 0; i--) { + len = offsets[i] - offsets[i - 1]; + s = str + offsets[i - 1]; - BLF_color3ubv(tds->font_id, fg); - BLF_position(tds->font_id, tds->xy[0], tds->lofs + tds->xy[1], 0); - BLF_draw_mono(tds->font_id, str, str_len, tds->cwidth); + BLF_position(tds->font_id, + tds->xy[0] + (tds->margin_left_chars * tds->cwidth), + tds->lofs + tds->xy[1], + 0); + BLF_draw_mono(tds->font_id, s, len, tds->cwidth); if (tds->sel[0] != tds->sel[1]) { - int isel[2]; - - isel[0] = str_len - tds->sel[1]; - isel[1] = str_len - tds->sel[0]; - - /* BLF_color3ub(tds->font_id, 255, 255, 0); // debug */ - console_draw_sel(str, isel, tds->xy, str_len, tds->cwidth, tds->lheight, bg_sel); - console_step_sel(tds, -(str_len + 1)); + console_step_sel(tds, len); + console_draw_sel(s, tds->xy, len, tds, bg_sel); } tds->xy[1] += tds->lheight; + /* Check if were out of view bounds. */ if (tds->xy[1] > tds->scroll_ymax) { MEM_freeN(offsets); return false; } } + tds->xy[1] = y_next; + + copy_v2_v2_int(tds->sel, sel_orig); + console_step_sel(tds, -(str_len + 1)); + MEM_freeN(offsets); return true; } @@ -310,7 +336,8 @@ int textview_draw(TextViewContext *tvc, int xy[2]; /* Disable selection by. */ int sel[2] = {-1, -1}; - unsigned char fg[3], bg[3]; + unsigned char fg[4], bg[4], icon_fg[4], icon_bg[4]; + int icon = 0; const int font_id = blf_mono_font; console_font_begin(font_id, tvc->lheight); @@ -338,6 +365,9 @@ 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. */ tds.columns = (tvc->draw_rect.xmax - tvc->draw_rect.xmin) / tds.cwidth; @@ -374,12 +404,12 @@ int textview_draw(TextViewContext *tvc, do { const char *ext_line; int ext_len; - int color_flag = 0; + int data_flag = 0; const int y_prev = xy[1]; if (do_draw) { - color_flag = tvc->line_color(tvc, fg, bg); + data_flag = tvc->line_data(tvc, fg, bg, &icon, icon_fg, icon_bg); } tvc->line_get(tvc, &ext_line, &ext_len); @@ -387,8 +417,11 @@ int textview_draw(TextViewContext *tvc, if (!console_draw_string(&tds, ext_line, ext_len, - (color_flag & TVC_LINE_FG) ? fg : NULL, - (color_flag & TVC_LINE_BG) ? bg : NULL, + (data_flag & TVC_LINE_FG) ? fg : NULL, + (data_flag & TVC_LINE_BG) ? bg : NULL, + (data_flag & TVC_LINE_ICON) ? icon : 0, + (data_flag & TVC_LINE_ICON_FG) ? icon_fg : NULL, + (data_flag & TVC_LINE_ICON_BG) ? icon_bg : NULL, bg_sel)) { /* When drawing, if we pass v2d->cur.ymax, then quit. */ if (do_draw) { @@ -397,6 +430,12 @@ int textview_draw(TextViewContext *tvc, } } + if (do_draw) { + if (tvc->draw_cursor && tvc->iter_index == 0) { + tvc->draw_cursor(tvc); + } + } + if ((mval[1] != INT_MAX) && (mval[1] >= y_prev && mval[1] <= xy[1])) { *r_mval_pick_item = (void *)tvc->iter; break; diff --git a/source/blender/editors/space_info/textview.h b/source/blender/editors/space_info/textview.h index 578236bbd13..3f7ba9739c4 100644 --- a/source/blender/editors/space_info/textview.h +++ b/source/blender/editors/space_info/textview.h @@ -31,6 +31,10 @@ typedef struct TextViewContext { int cwidth; /* shouldnt be needed! */ 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. */ rcti draw_rect; @@ -46,7 +50,13 @@ typedef struct TextViewContext { /* iterator */ int (*step)(struct TextViewContext *tvc); int (*line_get)(struct TextViewContext *tvc, const char **, int *); - int (*line_color)(struct TextViewContext *tvc, unsigned char fg[3], unsigned char bg[3]); + int (*line_data)(struct TextViewContext *tvc, + unsigned char fg[4], + unsigned char bg[4], + int *icon, + unsigned char icon_fg[4], + unsigned char icon_bg[4]); + void (*draw_cursor)(struct TextViewContext *tvc); /* constant theme colors */ void (*const_colors)(struct TextViewContext *tvc, unsigned char bg_sel[4]); void *iter; @@ -66,7 +76,12 @@ int textview_draw(struct TextViewContext *tvc, void **r_mval_pick_item, int *r_mval_pick_offset); -#define TVC_LINE_FG (1 << 0) -#define TVC_LINE_BG (1 << 1) +enum { + TVC_LINE_FG = (1 << 0), + TVC_LINE_BG = (1 << 1), + TVC_LINE_ICON = (1 << 2), + TVC_LINE_ICON_FG = (1 << 3), + TVC_LINE_ICON_BG = (1 << 4) +}; #endif /* __TEXTVIEW_H__ */ |