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
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')
-rw-r--r--source/blender/editors/space_info/info_draw.c13
-rw-r--r--source/blender/editors/space_info/textview.c34
-rw-r--r--source/blender/editors/space_info/textview.h11
3 files changed, 40 insertions, 18 deletions
diff --git a/source/blender/editors/space_info/info_draw.c b/source/blender/editors/space_info/info_draw.c
index 734515e1f79..a22983c15a8 100644
--- a/source/blender/editors/space_info/info_draw.c
+++ b/source/blender/editors/space_info/info_draw.c
@@ -228,6 +228,16 @@ static int report_textview_line_color(struct TextViewContext *tvc,
#undef USE_INFO_NEWLINE
+static void info_textview_draw_rect_calc(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->ymax = ar->winy;
+}
+
static int info_textview_main__internal(struct SpaceInfo *sinfo,
ARegion *ar,
ReportList *reports,
@@ -258,7 +268,8 @@ static int info_textview_main__internal(struct SpaceInfo *sinfo,
tvc.lheight = 14 * UI_DPI_FAC; // sc->lheight;
tvc.ymin = v2d->cur.ymin;
tvc.ymax = v2d->cur.ymax;
- tvc.winx = ar->winx - V2D_SCROLL_WIDTH;
+
+ info_textview_draw_rect_calc(ar, &tvc.draw_rect);
ret = textview_draw(&tvc, draw, mval, mouse_pick, pos_pick);
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);
diff --git a/source/blender/editors/space_info/textview.h b/source/blender/editors/space_info/textview.h
index aa0e924b461..ca5744dbe90 100644
--- a/source/blender/editors/space_info/textview.h
+++ b/source/blender/editors/space_info/textview.h
@@ -29,7 +29,9 @@ typedef struct TextViewContext {
int cwidth; /* shouldnt be needed! */
int console_width; /* shouldnt be needed! */
- int winx;
+ /** Area to draw: (0, 0, winx, winy) with a margin applied and scroll-bar subtracted. */
+ rcti draw_rect;
+
int ymin, ymax;
/* callbacks */
@@ -52,8 +54,11 @@ typedef struct TextViewContext {
} TextViewContext;
-int textview_draw(
- struct TextViewContext *tvc, const int draw, int mval[2], void **mouse_pick, int *pos_pick);
+int textview_draw(struct TextViewContext *tvc,
+ const int draw,
+ const int mval_init[2],
+ void **mouse_pick,
+ int *pos_pick);
#define TVC_LINE_FG (1 << 0)
#define TVC_LINE_BG (1 << 1)