diff options
Diffstat (limited to 'source/blender/editors/space_console/console_draw.c')
-rw-r--r-- | source/blender/editors/space_console/console_draw.c | 67 |
1 files changed, 43 insertions, 24 deletions
diff --git a/source/blender/editors/space_console/console_draw.c b/source/blender/editors/space_console/console_draw.c index a215b476094..cb191d0b15e 100644 --- a/source/blender/editors/space_console/console_draw.c +++ b/source/blender/editors/space_console/console_draw.c @@ -50,7 +50,9 @@ #include "ED_datafiles.h" #include "ED_types.h" +#include "UI_interface.h" #include "UI_resources.h" +#include "UI_view2d.h" #include "console_intern.h" @@ -79,9 +81,9 @@ typedef struct ConsoleDrawContext { int cwidth; int lheight; int console_width; - int winx; int ymin, ymax; #if 0 /* used by textview, may use later */ + int winx; int *xy; // [2] int *sel; // [2] int *pos_pick; /* bottom of view == 0, top of file == combine chars, end of line is lower then start. */ @@ -111,15 +113,12 @@ void console_scrollback_prompt_end(struct SpaceConsole *sc, ConsoleLine *cl_dumm } #define CONSOLE_DRAW_MARGIN 4 -#define CONSOLE_DRAW_SCROLL 16 - - /* console textview callbacks */ static int console_textview_begin(TextViewContext *tvc) { SpaceConsole *sc = (SpaceConsole *)tvc->arg1; - tvc->lheight = sc->lheight; + tvc->lheight = sc->lheight * UI_DPI_FAC; tvc->sel_start = sc->sel_start; tvc->sel_end = sc->sel_end; @@ -151,6 +150,26 @@ static int console_textview_line_get(struct TextViewContext *tvc, const char **l return 1; } +static void console_cursor_wrap_offset(const char *str, int width, int *row, int *column, const char *end) +{ + int col; + + for (; *str; str += BLI_str_utf8_size_safe(str)) { + col = BLI_str_utf8_char_width_safe(str); + + if (*column + col > width) { + (*row)++; + *column = 0; + } + + if (end && str >= end) + break; + + *column += col; + } + return; +} + static int console_textview_line_color(struct TextViewContext *tvc, unsigned char fg[3], unsigned char UNUSED(bg[3])) { ConsoleLine *cl_iter = (ConsoleLine *)tvc->iter; @@ -159,24 +178,18 @@ static int console_textview_line_color(struct TextViewContext *tvc, unsigned cha if (tvc->iter_index == 0) { const SpaceConsole *sc = (SpaceConsole *)tvc->arg1; const ConsoleLine *cl = (ConsoleLine *)sc->history.last; - const int prompt_len = strlen(sc->prompt); - const int cursor_loc = cl->cursor + prompt_len; - const int line_len = cl->len + prompt_len; + int offl = 0, offc = 0; int xy[2] = {CONSOLE_DRAW_MARGIN, CONSOLE_DRAW_MARGIN}; int pen[2]; xy[1] += tvc->lheight / 6; - /* account for wrapping */ - if (line_len < tvc->console_width) { - /* simple case, no wrapping */ - pen[0] = tvc->cwidth * cursor_loc; - pen[1] = -2; - } - else { - /* wrap */ - pen[0] = tvc->cwidth * (cursor_loc % tvc->console_width); - pen[1] = -2 + (((line_len / tvc->console_width) - (cursor_loc / tvc->console_width)) * tvc->lheight); - } + console_cursor_wrap_offset(sc->prompt, tvc->console_width, &offl, &offc, NULL); + console_cursor_wrap_offset(cl->line, tvc->console_width, &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->console_width, &offl, &offc, NULL); + pen[1] += tvc->lheight * offl; /* cursor */ UI_GetThemeColor3ubv(TH_CONSOLE_CURSOR, fg); @@ -194,8 +207,13 @@ static int console_textview_line_color(struct TextViewContext *tvc, unsigned cha return TVC_LINE_FG; } +static void console_textview_const_colors(TextViewContext *UNUSED(tvc), unsigned char bg_sel[4]) +{ + 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 int console_textview_main__internal(struct SpaceConsole *sc, ARegion *ar, int draw, + int mval[2], void **mouse_pick, int *pos_pick) { ConsoleLine cl_dummy = {NULL}; int ret = 0; @@ -210,6 +228,7 @@ static int console_textview_main__internal(struct SpaceConsole *sc, ARegion *ar, tvc.step = console_textview_step; tvc.line_get = console_textview_line_get; tvc.line_color = console_textview_line_color; + tvc.const_colors = console_textview_const_colors; tvc.arg1 = sc; tvc.arg2 = NULL; @@ -217,10 +236,10 @@ static int console_textview_main__internal(struct SpaceConsole *sc, ARegion *ar, /* view */ tvc.sel_start = sc->sel_start; tvc.sel_end = sc->sel_end; - tvc.lheight = sc->lheight; + tvc.lheight = sc->lheight * UI_DPI_FAC; tvc.ymin = v2d->cur.ymin; tvc.ymax = v2d->cur.ymax; - tvc.winx = ar->winx; + tvc.winx = ar->winx - V2D_SCROLL_WIDTH; console_scrollback_prompt_begin(sc, &cl_dummy); ret = textview_draw(&tvc, draw, mval, mouse_pick, pos_pick); @@ -242,13 +261,13 @@ int console_textview_height(struct SpaceConsole *sc, ARegion *ar) return console_textview_main__internal(sc, ar, 0, mval, NULL, NULL); } -int console_char_pick(struct SpaceConsole *sc, ARegion *ar, int mval[2]) +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_SCROLL + CONSOLE_DRAW_MARGIN)); + 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); console_textview_main__internal(sc, ar, 0, mval_clamp, &mouse_pick, &pos_pick); |