Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-12-03 11:37:51 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-12-03 11:53:40 +0300
commit1fdea43c29a7a0ffb65ec8049da574d4198d22af (patch)
treeb910b6604d60c6710570d4c133893ed2ce73abe1 /source/blender/editors/space_info/textview.c
parenta81fdefddebc0eec3e324cf6a9d8c51050d3e749 (diff)
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.
Diffstat (limited to 'source/blender/editors/space_info/textview.c')
-rw-r--r--source/blender/editors/space_info/textview.c34
1 files changed, 20 insertions, 14 deletions
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);