[Bf-blender-cvs] [f1c994c555d] master: Cleanup: move space text vars into a runtime struct

Campbell Barton noreply at git.blender.org
Wed Nov 27 15:09:18 CET 2019


Commit: f1c994c555da7c3e27984cc26b7f226badbe670d
Author: Campbell Barton
Date:   Thu Nov 28 00:58:34 2019 +1100
Branches: master
https://developer.blender.org/rBf1c994c555da7c3e27984cc26b7f226badbe670d

Cleanup: move space text vars into a runtime struct

Also use more descriptive names.

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

M	source/blender/blenloader/intern/readfile.c
M	source/blender/editors/space_text/space_text.c
M	source/blender/editors/space_text/text_autocomplete.c
M	source/blender/editors/space_text/text_draw.c
M	source/blender/editors/space_text/text_intern.h
M	source/blender/editors/space_text/text_ops.c
M	source/blender/makesdna/DNA_space_types.h
M	source/blender/makesdna/DNA_text_types.h
M	source/blender/makesrna/intern/rna_space.c

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

diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 9c220e59017..e7a2390b2c4 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -7376,10 +7376,7 @@ static void direct_link_area(FileData *fd, ScrArea *area)
     }
     else if (sl->spacetype == SPACE_TEXT) {
       SpaceText *st = (SpaceText *)sl;
-
-      st->drawcache = NULL;
-      st->scroll_ofs_px[0] = 0;
-      st->scroll_ofs_px[1] = 0;
+      memset(&st->runtime, 0, sizeof(st->runtime));
     }
     else if (sl->spacetype == SPACE_SEQ) {
       SpaceSeq *sseq = (SpaceSeq *)sl;
diff --git a/source/blender/editors/space_text/space_text.c b/source/blender/editors/space_text/space_text.c
index ae7c3b001e7..b477e3838bd 100644
--- a/source/blender/editors/space_text/space_text.c
+++ b/source/blender/editors/space_text/space_text.c
@@ -117,7 +117,7 @@ static SpaceLink *text_duplicate(SpaceLink *sl)
 
   /* clear or remove stuff from old */
 
-  stextn->drawcache = NULL; /* space need it's own cache */
+  stextn->runtime.drawcache = NULL; /* space need it's own cache */
 
   return (SpaceLink *)stextn;
 }
@@ -314,8 +314,9 @@ static void text_cursor(wmWindow *win, ScrArea *sa, ARegion *ar)
   SpaceText *st = sa->spacedata.first;
   int wmcursor = WM_CURSOR_TEXT_EDIT;
 
-  if (st->text &&
-      BLI_rcti_isect_pt(&st->txtbar, win->eventstate->x - ar->winrct.xmin, st->txtbar.ymin)) {
+  if (st->text && BLI_rcti_isect_pt(&st->runtime.scroll_region_handle,
+                                    win->eventstate->x - ar->winrct.xmin,
+                                    st->runtime.scroll_region_handle.ymin)) {
     wmcursor = WM_CURSOR_DEFAULT;
   }
 
diff --git a/source/blender/editors/space_text/text_autocomplete.c b/source/blender/editors/space_text/text_autocomplete.c
index 9b10f9831a5..a560b8af70f 100644
--- a/source/blender/editors/space_text/text_autocomplete.c
+++ b/source/blender/editors/space_text/text_autocomplete.c
@@ -83,11 +83,11 @@ int text_do_suggest_select(SpaceText *st, ARegion *ar)
 
   text_update_character_width(st);
 
-  x = TXT_BODY_LEFT(st) + (st->cwidth * (st->text->curc - st->left));
-  y = ar->winy - st->lheight_dpi * l - 2;
+  x = TXT_BODY_LEFT(st) + (st->runtime.cwidth_px * (st->text->curc - st->left));
+  y = ar->winy - st->runtime.lheight_px * l - 2;
 
-  w = SUGG_LIST_WIDTH * st->cwidth + U.widget_unit;
-  h = SUGG_LIST_SIZE * st->lheight_dpi + 0.4f * U.widget_unit;
+  w = SUGG_LIST_WIDTH * st->runtime.cwidth_px + U.widget_unit;
+  h = SUGG_LIST_SIZE * st->runtime.lheight_px + 0.4f * U.widget_unit;
 
   // XXX getmouseco_areawin(mval);
 
@@ -101,7 +101,7 @@ int text_do_suggest_select(SpaceText *st, ARegion *ar)
   }
 
   /* Work out the target item index in the visible list */
-  tgti = (y - mval[1] - 4) / st->lheight_dpi;
+  tgti = (y - mval[1] - 4) / st->runtime.lheight_px;
   if (tgti < 0 || tgti > SUGG_LIST_SIZE) {
     return 1;
   }
diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c
index a8b141eff15..96fa9f87398 100644
--- a/source/blender/editors/space_text/text_draw.c
+++ b/source/blender/editors/space_text/text_draw.c
@@ -52,22 +52,22 @@
 
 typedef struct TextDrawContext {
   int font_id;
-  int cwidth;
-  int lheight_dpi;
+  int cwidth_px;
+  int lheight_px;
   bool syntax_highlight;
 } TextDrawContext;
 
 static void text_draw_context_init(const SpaceText *st, TextDrawContext *tdc)
 {
   tdc->font_id = blf_mono_font;
-  tdc->cwidth = 0;
-  tdc->lheight_dpi = st->lheight_dpi;
+  tdc->cwidth_px = 0;
+  tdc->lheight_px = st->runtime.lheight_px;
   tdc->syntax_highlight = st->showsyntax && ED_text_is_syntax_highlight_supported(st->text);
 }
 
 static void text_font_begin(const TextDrawContext *tdc)
 {
-  BLF_size(tdc->font_id, tdc->lheight_dpi, 72);
+  BLF_size(tdc->font_id, tdc->lheight_px, 72);
 }
 
 static void text_font_end(const TextDrawContext *UNUSED(tdc))
@@ -79,9 +79,9 @@ static int text_font_draw(const TextDrawContext *tdc, int x, int y, const char *
   int columns;
 
   BLF_position(tdc->font_id, x, y, 0);
-  columns = BLF_draw_mono(tdc->font_id, str, BLF_DRAW_STR_DUMMY_MAX, tdc->cwidth);
+  columns = BLF_draw_mono(tdc->font_id, str, BLF_DRAW_STR_DUMMY_MAX, tdc->cwidth_px);
 
-  return tdc->cwidth * columns;
+  return tdc->cwidth_px * columns;
 }
 
 static int text_font_draw_character(const TextDrawContext *tdc, int x, int y, char c)
@@ -89,7 +89,7 @@ static int text_font_draw_character(const TextDrawContext *tdc, int x, int y, ch
   BLF_position(tdc->font_id, x, y, 0);
   BLF_draw(tdc->font_id, &c, 1);
 
-  return tdc->cwidth;
+  return tdc->cwidth_px;
 }
 
 static int text_font_draw_character_utf8(const TextDrawContext *tdc, int x, int y, const char *c)
@@ -98,9 +98,9 @@ static int text_font_draw_character_utf8(const TextDrawContext *tdc, int x, int
 
   const size_t len = BLI_str_utf8_size_safe(c);
   BLF_position(tdc->font_id, x, y, 0);
-  columns = BLF_draw_mono(tdc->font_id, c, len, tdc->cwidth);
+  columns = BLF_draw_mono(tdc->font_id, c, len, tdc->cwidth_px);
 
-  return tdc->cwidth * columns;
+  return tdc->cwidth_px * columns;
 }
 
 #if 0
@@ -193,7 +193,7 @@ int wrap_width(const SpaceText *st, ARegion *ar)
   int x, max;
 
   x = TXT_BODY_LEFT(st);
-  max = st->cwidth ? (winx - x) / st->cwidth : 0;
+  max = st->runtime.cwidth_px ? (winx - x) / st->runtime.cwidth_px : 0;
   return max > 8 ? max : 8;
 }
 
@@ -429,11 +429,11 @@ static int text_draw_wrapped(const SpaceText *st,
   int mi, ma, mstart, mend; /* mem */
   char fmt_prev = 0xff;
   /* don't draw lines below this */
-  const int clip_min_y = -(int)(st->lheight_dpi - 1);
+  const int clip_min_y = -(int)(st->runtime.lheight_px - 1);
 
   flatten_string(st, &fs, str);
   str = fs.buf;
-  max = w / st->cwidth;
+  max = w / st->runtime.cwidth_px;
   if (max < 8) {
     max = 8;
   }
@@ -549,7 +549,7 @@ static void text_draw(const SpaceText *st,
     return; /* String is shorter than shift or ends with a padding */
   }
 
-  x += tdc->cwidth * padding;
+  x += tdc->cwidth_px * padding;
 
   if (use_syntax) {
     int a, str_shift = 0;
@@ -579,7 +579,7 @@ typedef struct DrawCache {
   /* this is needed to check cache relevance */
   int winx, wordwrap, showlinenrs, tabnumber;
   short lheight;
-  char cwidth;
+  char cwidth_px;
   char text_id[MAX_ID_NAME];
 
   /* for partial lines recalculation */
@@ -595,7 +595,7 @@ static void text_drawcache_init(SpaceText *st)
   drawcache->nlines = BLI_listbase_count(&st->text->lines);
   drawcache->text_id[0] = '\0';
 
-  st->drawcache = drawcache;
+  st->runtime.drawcache = drawcache;
 }
 
 static void text_update_drawcache(SpaceText *st, ARegion *ar)
@@ -604,13 +604,13 @@ static void text_update_drawcache(SpaceText *st, ARegion *ar)
   int full_update = 0, nlines = 0;
   Text *txt = st->text;
 
-  if (!st->drawcache) {
+  if (st->runtime.drawcache == NULL) {
     text_drawcache_init(st);
   }
 
   text_update_character_width(st);
 
-  drawcache = (DrawCache *)st->drawcache;
+  drawcache = st->runtime.drawcache;
   nlines = drawcache->nlines;
 
   /* check if full cache update is needed */
@@ -624,9 +624,9 @@ static void text_update_drawcache(SpaceText *st, ARegion *ar)
   /* word-wrapping option was toggled */
   full_update |= drawcache->tabnumber != st->tabnumber;
   /* word-wrapping option was toggled */
-  full_update |= drawcache->lheight != st->lheight_dpi;
+  full_update |= drawcache->lheight != st->runtime.lheight_px;
   /* word-wrapping option was toggled */
-  full_update |= drawcache->cwidth != st->cwidth;
+  full_update |= drawcache->cwidth_px != st->runtime.cwidth_px;
   /* text datablock was changed */
   full_update |= !STREQLEN(drawcache->text_id, txt->id.name, MAX_ID_NAME);
 
@@ -661,7 +661,7 @@ static void text_update_drawcache(SpaceText *st, ARegion *ar)
       drawcache->total_lines = 0;
 
       if (st->showlinenrs) {
-        st->linenrs_tot = integer_digits_i(nlines);
+        st->runtime.line_number_display_digits = integer_digits_i(nlines);
       }
 
       while (line) {
@@ -696,7 +696,7 @@ static void text_update_drawcache(SpaceText *st, ARegion *ar)
       nlines = BLI_listbase_count(&txt->lines);
 
       if (st->showlinenrs) {
-        st->linenrs_tot = integer_digits_i(nlines);
+        st->runtime.line_number_display_digits = integer_digits_i(nlines);
       }
     }
 
@@ -708,8 +708,8 @@ static void text_update_drawcache(SpaceText *st, ARegion *ar)
   /* store settings */
   drawcache->winx = ar->winx;
   drawcache->wordwrap = st->wordwrap;
-  drawcache->lheight = st->lheight_dpi;
-  drawcache->cwidth = st->cwidth;
+  drawcache->lheight = st->runtime.lheight_px;
+  drawcache->cwidth_px = st->runtime.cwidth_px;
   drawcache->showlinenrs = st->showlinenrs;
   drawcache->tabnumber = st->tabnumber;
 
@@ -728,8 +728,8 @@ void text_drawcache_tag_update(SpaceText *st, int full)
     return;
   }
 
-  if (st->drawcache) {
-    DrawCache *drawcache = (DrawCache *)st->drawcache;
+  if (st->runtime.drawcache != NULL) {
+    DrawCache *drawcache = st->runtime.drawcache;
     Text *txt = st->text;
 
     if (drawcache->update_flag) {
@@ -772,7 +772,7 @@ void text_drawcache_tag_update(SpaceText *st, int full)
 
 void text_free_caches(SpaceText *st)
 {
-  DrawCache *drawcache = (DrawCache *)st->drawcache;
+  DrawCache *drawcache = st->runtime.drawcache;
 
   if (drawcache) {
     if (drawcache->line_height) {
@@ -788,7 +788,7 @@ void text_free_caches(SpaceText *st)
 /* cache should be updated in caller */
 static int text_get_visible_lines_no(const SpaceText *st, int lineno)
 {
-  const DrawCache *drawcache = st->drawcache;
+  const DrawCache *drawcache = st->runtime.drawcache;
 
   return drawcache->line_height[lineno];
 }
@@ -859,7 +859,7 @@ int text_get_total_lines(SpaceText *st, ARegion *ar)
   DrawCache *drawcache;
 
   text_update_drawcache(st, ar);
-  drawcache = st->drawcache;
+  drawcache = st->runtime.drawcache;
 
   return drawcache->total_lines;
 }
@@ -876,7 +876,7 @@ static void calc_text_rcts(SpaceText *st, ARegion *ar, rcti *scroll, rcti *back)
   pix_bottom_margin = (0.4 * U.widget_unit);
   pix_available = ar->winy - pix_top_margin - pix_bottom_mar

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list