Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_info/textview.c
| Show First 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | typedef struct ConsoleDrawContext { | ||||
| int font_id; | int font_id; | ||||
| int cwidth; | int cwidth; | ||||
| int lheight; | int lheight; | ||||
| int lofs; /* text vertical offset */ | int lofs; /* text vertical offset */ | ||||
| int console_width; /* number of characters that fit into the width of the console (fixed width) */ | int console_width; /* number of characters that fit into the width of the console (fixed width) */ | ||||
| int winx; | int winx; | ||||
| int ymin, ymax; | int ymin, ymax; | ||||
| int *xy; // [2] | int *xy; // [2] | ||||
| int *cursor_xy; // [2] | |||||
| int *sel; // [2] | int *sel; // [2] | ||||
| int *pos_pick; // bottom of view == 0, top of file == combine chars, end of line is lower then start. | int *pos_pick; // bottom of view == 0, top of file == combine chars, end of line is lower then start. | ||||
| const int *mval; // [2] | const int *mval; // [2] | ||||
| int draw; | int draw; | ||||
| } ConsoleDrawContext; | } ConsoleDrawContext; | ||||
| BLI_INLINE void console_step_sel(ConsoleDrawContext *cdc, const int step) | BLI_INLINE void console_step_sel(ConsoleDrawContext *cdc, const int step) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | for (i = 0, end = width, j = 0; j < len && str[j]; j += BLI_str_utf8_size_safe(str + j)) { | ||||
| i += columns; | i += columns; | ||||
| } | } | ||||
| return j; /* return actual length */ | return j; /* return actual length */ | ||||
| } | } | ||||
| /* return 0 if the last line is off the screen | /* return 0 if the last line is off the screen | ||||
| * should be able to use this for any string type */ | * should be able to use this for any string type */ | ||||
| static int console_draw_string(ConsoleDrawContext *cdc, const char *str, int str_len, | static int console_draw_string( | ||||
| const unsigned char fg[3], const unsigned char bg[3], const unsigned char bg_sel[4]) | ConsoleDrawContext *cdc, const char *str, int str_len, | ||||
| const unsigned char fg[3], const unsigned char bg[3], | |||||
| const unsigned char cursor[3], const unsigned char bg_sel[4]) | |||||
| { | { | ||||
| int tot_lines; /* total number of lines for wrapping */ | int tot_lines; /* total number of lines for wrapping */ | ||||
| int *offsets; /* offsets of line beginnings for wrapping */ | int *offsets; /* offsets of line beginnings for wrapping */ | ||||
| int y_next; | int y_next; | ||||
| str_len = console_wrap_offsets(str, str_len, cdc->console_width, &tot_lines, &offsets); | str_len = console_wrap_offsets(str, str_len, cdc->console_width, &tot_lines, &offsets); | ||||
| y_next = cdc->xy[1] + cdc->lheight * tot_lines; | y_next = cdc->xy[1] + cdc->lheight * tot_lines; | ||||
| ▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | if (bg) { | ||||
| immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); | immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); | ||||
| immUniformColor3ubv(bg); | immUniformColor3ubv(bg); | ||||
| immRecti(pos, 0, cdc->xy[1], cdc->winx, (cdc->xy[1] + (cdc->lheight * tot_lines))); | immRecti(pos, 0, cdc->xy[1], cdc->winx, (cdc->xy[1] + (cdc->lheight * tot_lines))); | ||||
| immUnbindProgram(); | immUnbindProgram(); | ||||
| } | } | ||||
| if (cursor) { | |||||
| GPUVertFormat *format = immVertexFormat(); | |||||
| unsigned int pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | |||||
| immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); | |||||
| immUniformColor3ubv(cursor); | |||||
| immRectf(pos, | |||||
| cdc->cursor_xy[0] - 1, | |||||
| cdc->cursor_xy[1], | |||||
| cdc->cursor_xy[0] + 1, | |||||
| cdc->cursor_xy[1] + cdc->lheight | |||||
| ); | |||||
| immUnbindProgram(); | |||||
| } | |||||
| /* last part needs no clipping */ | /* last part needs no clipping */ | ||||
| BLF_position(cdc->font_id, cdc->xy[0], cdc->lofs + cdc->xy[1], 0); | BLF_position(cdc->font_id, cdc->xy[0], cdc->lofs + cdc->xy[1], 0); | ||||
| BLF_color3ubv(cdc->font_id, fg); | BLF_color3ubv(cdc->font_id, fg); | ||||
| BLF_draw_mono(cdc->font_id, s, len, cdc->cwidth); | BLF_draw_mono(cdc->font_id, s, len, cdc->cwidth); | ||||
| if (cdc->sel[0] != cdc->sel[1]) { | if (cdc->sel[0] != cdc->sel[1]) { | ||||
| console_step_sel(cdc, -initial_offset); | console_step_sel(cdc, -initial_offset); | ||||
| /* BLF_color3ub(cdc->font_id, 255, 0, 0); // debug */ | /* BLF_color3ub(cdc->font_id, 255, 0, 0); // debug */ | ||||
| Show All 35 Lines | if (bg) { | ||||
| immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); | immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); | ||||
| immUniformColor3ubv(bg); | immUniformColor3ubv(bg); | ||||
| immRecti(pos, 0, cdc->xy[1], cdc->winx, cdc->xy[1] + cdc->lheight); | immRecti(pos, 0, cdc->xy[1], cdc->winx, cdc->xy[1] + cdc->lheight); | ||||
| immUnbindProgram(); | immUnbindProgram(); | ||||
| } | } | ||||
| if (cursor) { | |||||
| GPUVertFormat *format = immVertexFormat(); | |||||
| unsigned int pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | |||||
| immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); | |||||
| immUniformColor3ubv(cursor); | |||||
| immRectf(pos, | |||||
| cdc->cursor_xy[0] - 1, | |||||
| cdc->cursor_xy[1], | |||||
| cdc->cursor_xy[0] + 1, | |||||
| cdc->cursor_xy[1] + cdc->lheight | |||||
| ); | |||||
| immUnbindProgram(); | |||||
| } | |||||
| BLF_color3ubv(cdc->font_id, fg); | BLF_color3ubv(cdc->font_id, fg); | ||||
| BLF_position(cdc->font_id, cdc->xy[0], cdc->lofs + cdc->xy[1], 0); | BLF_position(cdc->font_id, cdc->xy[0], cdc->lofs + cdc->xy[1], 0); | ||||
| BLF_draw_mono(cdc->font_id, str, str_len, cdc->cwidth); | BLF_draw_mono(cdc->font_id, str, str_len, cdc->cwidth); | ||||
| if (cdc->sel[0] != cdc->sel[1]) { | if (cdc->sel[0] != cdc->sel[1]) { | ||||
| int isel[2]; | int isel[2]; | ||||
| isel[0] = str_len - cdc->sel[1]; | isel[0] = str_len - cdc->sel[1]; | ||||
| Show All 20 Lines | |||||
| int textview_draw(TextViewContext *tvc, const int draw, int mval[2], void **mouse_pick, int *pos_pick) | int textview_draw(TextViewContext *tvc, const int draw, int mval[2], void **mouse_pick, int *pos_pick) | ||||
| { | { | ||||
| ConsoleDrawContext cdc = {0}; | ConsoleDrawContext cdc = {0}; | ||||
| int x_orig = CONSOLE_DRAW_MARGIN, y_orig = CONSOLE_DRAW_MARGIN + tvc->lheight / 6; | int x_orig = CONSOLE_DRAW_MARGIN, y_orig = CONSOLE_DRAW_MARGIN + tvc->lheight / 6; | ||||
| int xy[2], y_prev; | int xy[2], y_prev; | ||||
| int sel[2] = {-1, -1}; /* defaults disabled */ | int sel[2] = {-1, -1}; /* defaults disabled */ | ||||
| int cursor_xy[2] = {-1, -1}; /* defaults disabled */ | |||||
| unsigned char fg[3], bg[3]; | unsigned char fg[3], bg[3]; | ||||
| const int font_id = blf_mono_font; | const int font_id = blf_mono_font; | ||||
| console_font_begin(font_id, tvc->lheight); | console_font_begin(font_id, tvc->lheight); | ||||
| xy[0] = x_orig; xy[1] = y_orig; | xy[0] = x_orig; xy[1] = y_orig; | ||||
| if (mval[1] != INT_MAX) | if (mval[1] != INT_MAX) | ||||
| Show All 12 Lines | int textview_draw(TextViewContext *tvc, const int draw, int mval[2], void **mouse_pick, int *pos_pick) | ||||
| cdc.console_width = (tvc->winx - (CONSOLE_DRAW_MARGIN * 2)) / cdc.cwidth; | cdc.console_width = (tvc->winx - (CONSOLE_DRAW_MARGIN * 2)) / cdc.cwidth; | ||||
| /* avoid divide by zero on small windows */ | /* avoid divide by zero on small windows */ | ||||
| if (cdc.console_width < 1) | if (cdc.console_width < 1) | ||||
| cdc.console_width = 1; | cdc.console_width = 1; | ||||
| cdc.winx = tvc->winx - CONSOLE_DRAW_MARGIN; | cdc.winx = tvc->winx - CONSOLE_DRAW_MARGIN; | ||||
| cdc.ymin = tvc->ymin; | cdc.ymin = tvc->ymin; | ||||
| cdc.ymax = tvc->ymax; | cdc.ymax = tvc->ymax; | ||||
| cdc.xy = xy; | cdc.xy = xy; | ||||
| cdc.cursor_xy = cursor_xy; | |||||
| cdc.sel = sel; | cdc.sel = sel; | ||||
| cdc.pos_pick = pos_pick; | cdc.pos_pick = pos_pick; | ||||
| cdc.mval = mval; | cdc.mval = mval; | ||||
| cdc.draw = draw; | cdc.draw = draw; | ||||
| /* shouldnt be needed */ | /* shouldnt be needed */ | ||||
| tvc->cwidth = cdc.cwidth; | tvc->cwidth = cdc.cwidth; | ||||
| tvc->console_width = cdc.console_width; | tvc->console_width = cdc.console_width; | ||||
| tvc->iter_index = 0; | tvc->iter_index = 0; | ||||
| if (tvc->sel_start != tvc->sel_end) { | if (tvc->sel_start != tvc->sel_end) { | ||||
| sel[0] = tvc->sel_start; | sel[0] = tvc->sel_start; | ||||
| sel[1] = tvc->sel_end; | sel[1] = tvc->sel_end; | ||||
| } | } | ||||
| if (tvc->begin(tvc)) { | if (tvc->begin(tvc)) { | ||||
| unsigned char bg_sel[4] = {0}; | unsigned char bg_sel[4] = {0}; | ||||
| unsigned char cursor[3] = {0}; | |||||
| if (draw && tvc->const_colors) { | if (draw && tvc->const_colors) { | ||||
| tvc->const_colors(tvc, bg_sel); | tvc->const_colors(tvc, bg_sel, cursor); | ||||
| } | } | ||||
| do { | do { | ||||
| const char *ext_line; | const char *ext_line; | ||||
| int ext_len; | int ext_len; | ||||
| int color_flag = 0; | int color_flag = 0; | ||||
| y_prev = xy[1]; | y_prev = xy[1]; | ||||
| if (draw) | if (draw) { | ||||
| color_flag = tvc->line_color(tvc, fg, bg); | color_flag = tvc->line_color(tvc, fg, bg); | ||||
| if (tvc->cursor_coords) | |||||
| tvc->cursor_coords(tvc, cursor_xy); | |||||
| } | |||||
| tvc->line_get(tvc, &ext_line, &ext_len); | tvc->line_get(tvc, &ext_line, &ext_len); | ||||
| if (!console_draw_string(&cdc, ext_line, ext_len, | if (!console_draw_string(&cdc, ext_line, ext_len, | ||||
| (color_flag & TVC_LINE_FG) ? fg : NULL, | (color_flag & TVC_LINE_FG) ? fg : NULL, | ||||
| (color_flag & TVC_LINE_BG) ? bg : NULL, | (color_flag & TVC_LINE_BG) ? bg : NULL, | ||||
| (cursor_xy[0] >= 0) ? cursor : NULL, | |||||
| bg_sel)) | bg_sel)) | ||||
| { | { | ||||
| /* when drawing, if we pass v2d->cur.ymax, then quit */ | /* when drawing, if we pass v2d->cur.ymax, then quit */ | ||||
| if (draw) { | if (draw) { | ||||
| break; /* past the y limits */ | break; /* past the y limits */ | ||||
| } | } | ||||
| } | } | ||||
| Show All 16 Lines | |||||