[Bf-blender-cvs] [f621f03e4b2] master: Fix console cursor offset

Campbell Barton noreply at git.blender.org
Fri Feb 14 06:16:23 CET 2020


Commit: f621f03e4b252d5ef1d86b9306a22628da3160ce
Author: Campbell Barton
Date:   Fri Feb 14 16:11:01 2020 +1100
Branches: master
https://developer.blender.org/rBf621f03e4b252d5ef1d86b9306a22628da3160ce

Fix console cursor offset

Also remove hard coded offsets.

===================================================================

M	source/blender/editors/space_console/console_draw.c
M	source/blender/editors/space_info/textview.c
M	source/blender/editors/space_info/textview.h

===================================================================

diff --git a/source/blender/editors/space_console/console_draw.c b/source/blender/editors/space_console/console_draw.c
index af01ec72ec2..3ba355b3730 100644
--- a/source/blender/editors/space_console/console_draw.c
+++ b/source/blender/editors/space_console/console_draw.c
@@ -144,34 +144,37 @@ static void console_cursor_wrap_offset(
   return;
 }
 
-static void console_textview_draw_cursor(struct TextViewContext *tvc)
+static void console_textview_draw_cursor(struct TextViewContext *tvc,
+                                         int cwidth,
+                                         int columns,
+                                         int descender)
 {
-  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;
+  {
+    const SpaceConsole *sc = (SpaceConsole *)tvc->arg1;
+    const ConsoleLine *cl = (ConsoleLine *)sc->history.last;
+    int offl = 0, offc = 0;
+
+    console_cursor_wrap_offset(sc->prompt, columns, &offl, &offc, NULL);
+    console_cursor_wrap_offset(cl->line, columns, &offl, &offc, cl->line + cl->cursor);
+    pen[0] = cwidth * offc;
+    pen[1] = -2 - (tvc->lheight + descender) * offl;
 
-  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, columns, &offl, &offc, NULL);
+    pen[1] += (tvc->lheight + descender) * offl;
 
-  console_cursor_wrap_offset(cl->line + cl->cursor, tvc->columns, &offl, &offc, NULL);
-  pen[1] += tvc->lheight * offl;
+    pen[0] += tvc->draw_rect.xmin;
+    pen[1] += tvc->draw_rect.ymin;
+  }
 
   /* cursor */
+  GPUVertFormat *format = immVertexFormat();
+  uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
   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));
+  immRectf(
+      pos, pen[0] - U.pixelsize, pen[1], pen[0] + U.pixelsize, pen[1] + tvc->lheight + descender);
 
   immUnbindProgram();
 }
diff --git a/source/blender/editors/space_info/textview.c b/source/blender/editors/space_info/textview.c
index 6678ac2b659..d7f2cb9ce1f 100644
--- a/source/blender/editors/space_info/textview.c
+++ b/source/blender/editors/space_info/textview.c
@@ -93,7 +93,7 @@ static void textview_draw_sel(const char *str,
     immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
 
     immUniformColor4ubv(bg_sel);
-    immRecti(pos, xy[0] + (cwidth * sta), xy[1] - 2 + lheight, xy[0] + (cwidth * end), xy[1] - 2);
+    immRecti(pos, xy[0] + (cwidth * sta), xy[1] + lheight, xy[0] + (cwidth * end), xy[1]);
 
     immUnbindProgram();
 
@@ -316,7 +316,7 @@ int textview_draw(TextViewContext *tvc,
 {
   TextViewDrawState tds = {0};
 
-  int x_orig = tvc->draw_rect.xmin, y_orig = tvc->draw_rect.ymin + tvc->lheight / 6;
+  const int x_orig = tvc->draw_rect.xmin, y_orig = tvc->draw_rect.ymin;
   int xy[2];
   /* Disable selection by. */
   int sel[2] = {-1, -1};
@@ -367,11 +367,6 @@ int textview_draw(TextViewContext *tvc,
   tds.mval = mval;
   tds.do_draw = do_draw;
 
-  /* Shouldnt be needed. */
-  tvc->cwidth = tds.cwidth;
-  tvc->columns = tds.columns;
-  tvc->iter_index = 0;
-
   if (tvc->sel_start != tvc->sel_end) {
     sel[0] = tvc->sel_start;
     sel[1] = tvc->sel_end;
@@ -384,6 +379,7 @@ int textview_draw(TextViewContext *tvc,
       tvc->const_colors(tvc, bg_sel);
     }
 
+    int iter_index = 0;
     do {
       const char *ext_line;
       int ext_len;
@@ -414,8 +410,8 @@ int textview_draw(TextViewContext *tvc,
       }
 
       if (do_draw) {
-        if (tvc->draw_cursor && tvc->iter_index == 0) {
-          tvc->draw_cursor(tvc);
+        if (tvc->draw_cursor && iter_index == 0) {
+          tvc->draw_cursor(tvc, tds.cwidth, tds.columns, tds.lofs);
         }
       }
 
@@ -424,7 +420,7 @@ int textview_draw(TextViewContext *tvc,
         break;
       }
 
-      tvc->iter_index++;
+      iter_index++;
 
     } while (tvc->step(tvc));
   }
diff --git a/source/blender/editors/space_info/textview.h b/source/blender/editors/space_info/textview.h
index 6fcd9d30abe..a33ed91570d 100644
--- a/source/blender/editors/space_info/textview.h
+++ b/source/blender/editors/space_info/textview.h
@@ -27,10 +27,6 @@ typedef struct TextViewContext {
   /** Text selection, when a selection range is in use. */
   int sel_start, sel_end;
 
-  /* view settings */
-  int cwidth;  /* shouldnt be needed! */
-  int columns; /* shouldnt be needed! */
-
   int row_vpadding;
 
   /** Area to draw text: (0, 0, winx, winy) with a margin applied and scroll-bar subtracted. */
@@ -56,7 +52,7 @@ typedef struct TextViewContext {
                    int *icon,
                    unsigned char icon_fg[4],
                    unsigned char icon_bg[4]);
-  void (*draw_cursor)(struct TextViewContext *tvc);
+  void (*draw_cursor)(struct TextViewContext *tvc, int cwidth, int columns, int descender);
   /* constant theme colors */
   void (*const_colors)(struct TextViewContext *tvc, unsigned char bg_sel[4]);
   void *iter;



More information about the Bf-blender-cvs mailing list