Commit: d06d42a243c16eb22aa0cfa6305ab5683f7c07d2
Author: Mateusz Grzeliński
Date:   Fri Aug 14 18:10:21 2020 +0200
Branches: soc-2020-info-editor
https://developer.blender.org/rBd06d42a243c16eb22aa0cfa6305ab5683f7c07d2

TextView: add automatic tab and new line handling

Allow for multi drawing multi line text as part of framework.

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

M       source/blender/editors/include/ED_text.h
M       source/blender/editors/space_console/console_draw.c
M       source/blender/editors/space_info/info_draw.c
M       source/blender/editors/space_info/info_draw_clog.c
M       source/blender/editors/space_info/info_draw_report.c
M       source/blender/editors/space_info/info_intern.h
M       source/blender/editors/space_info/textview.c
M       source/blender/editors/space_info/textview.h
M       source/blender/editors/space_text/text_draw.c
M       source/blender/editors/space_text/text_format.h

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

diff --git a/source/blender/editors/include/ED_text.h 
b/source/blender/editors/include/ED_text.h
index d2bff38c113..45ab2fbd3a1 100644
--- a/source/blender/editors/include/ED_text.h
+++ b/source/blender/editors/include/ED_text.h
@@ -33,8 +33,9 @@ struct Text;
 struct UndoStep;
 struct UndoType;
 struct bContext;
+enum eTextFormatTag;
 
-void text_format_draw_font_color(int font_id, char formatchar);
+void text_format_draw_font_color(int font_id, enum eTextFormatTag formatchar);
 bool ED_text_region_location_from_cursor(struct SpaceText *st,
                                          struct ARegion *region,
                                          const int cursor_co[2],
diff --git a/source/blender/editors/space_console/console_draw.c 
b/source/blender/editors/space_console/console_draw.c
index 0e84f8ed92b..87c693f444c 100644
--- a/source/blender/editors/space_console/console_draw.c
+++ b/source/blender/editors/space_console/console_draw.c
@@ -137,7 +137,7 @@ static int console_textview_step(TextViewContext *tvc)
   return ((tvc->iter = (void *)(cl)->prev) != NULL);
 }
 
-static void console_textview_line_get(TextViewContext *tvc,
+static void console_textview_text_get(TextViewContext *tvc,
                                       char **r_line,
                                       int *r_len,
                                       bool *owns_memory)
@@ -241,10 +241,11 @@ static int console_textview_main__internal(SpaceConsole 
*sc,
   tvc.end = console_textview_end;
 
   tvc.step = console_textview_step;
-  tvc.line_get = console_textview_line_get;
+  tvc.text_get = console_textview_text_get;
   tvc.line_draw_data = console_line_draw_data;
   tvc.draw_cursor = console_textview_draw_cursor;
   tvc.const_colors = console_textview_const_colors;
+  tvc.tabnumber = 4;
 
   tvc.arg1 = sc;
   tvc.arg2 = NULL;
diff --git a/source/blender/editors/space_info/info_draw.c 
b/source/blender/editors/space_info/info_draw.c
index 2d33e99cdf4..0c3410d8a70 100644
--- a/source/blender/editors/space_info/info_draw.c
+++ b/source/blender/editors/space_info/info_draw.c
@@ -72,7 +72,7 @@ static int info_textview_main__internal(const SpaceInfo 
*sinfo,
   switch (sinfo->view) {
     case INFO_VIEW_CLOG:
       tvc.begin = clog_textview_begin;
-      tvc.line_get = clog_textview_line_get;
+      tvc.text_get = clog_textview_text_get;
       tvc.line_draw_data = clog_line_draw_data;
       tvc.end = clog_textview_end;
       tvc.step = clog_textview_step;
@@ -80,7 +80,7 @@ static int info_textview_main__internal(const SpaceInfo 
*sinfo,
       break;
     case INFO_VIEW_REPORTS:
       tvc.begin = report_textview_begin;
-      tvc.line_get = report_textview_line_get;
+      tvc.text_get = report_textview_text_get;
       tvc.line_draw_data = report_line_draw_data;
       tvc.end = report_textview_end;
       tvc.step = report_textview_step;
@@ -98,6 +98,7 @@ static int info_textview_main__internal(const SpaceInfo 
*sinfo,
   tvc.row_vpadding = 0.4 * tvc.lheight;
   tvc.scroll_ymin = v2d->cur.ymin;
   tvc.scroll_ymax = v2d->cur.ymax;
+  tvc.tabnumber = 4;
 
   info_textview_draw_rect_calc(region, &tvc.draw_rect, &tvc.draw_rect_outer);
 
diff --git a/source/blender/editors/space_info/info_draw_clog.c 
b/source/blender/editors/space_info/info_draw_clog.c
index 2e0ccd9cd2c..d9143f9b5b0 100644
--- a/source/blender/editors/space_info/info_draw_clog.c
+++ b/source/blender/editors/space_info/info_draw_clog.c
@@ -63,7 +63,7 @@ enum eTextViewContext_LineDrawFlag clog_line_draw_data(struct 
TextViewContext *t
     UI_GetThemeColor4ubv(bg_id, bg);
   }
   else {
-    if (tvc->iter_tmp % 2) {
+    if (tvc->iter_index % 2) {
       UI_GetThemeColor4ubv(TH_BACK, bg);
     }
     else {
@@ -77,10 +77,7 @@ enum eTextViewContext_LineDrawFlag 
clog_line_draw_data(struct TextViewContext *t
   int icon_fg_id;
   int icon_bg_id;
 
-  if (tvc->iter_char_begin != 0) {
-    *r_icon = ICON_NONE;
-  }
-  else if (record->severity == CLG_SEVERITY_FATAL) {
+  if (record->severity == CLG_SEVERITY_FATAL) {
     icon_fg_id = TH_INFO_ERROR_TEXT;
     icon_bg_id = TH_INFO_ERROR;
     *r_icon = ICON_X;
@@ -128,7 +125,7 @@ enum eTextViewContext_LineDrawFlag 
clog_line_draw_data(struct TextViewContext *t
   return data_flag | TVC_LINE_BG;
 }
 
-static int report_textview_skip__internal(TextViewContext *tvc)
+static int clog_textview_skip__internal(TextViewContext *tvc)
 {
   const SpaceInfo *sinfo = tvc->arg1;
   while (tvc->iter && !is_clog_record_visible(tvc->iter, sinfo)) {
@@ -150,14 +147,7 @@ int clog_textview_begin(struct TextViewContext *tvc)
   UI_ThemeClearColor(TH_BACK);
   GPU_clear(GPU_COLOR_BIT);
 
-  tvc->iter_tmp = 0;
-  if (tvc->iter && report_textview_skip__internal(tvc)) {
-    /* init the newline iterator */
-    // TODO (grzelins) fix newlines
-    //    const Report *report = tvc->iter;
-    //    tvc->iter_char_end = report->len;
-    //    report_textview_init__internal(tvc);
-
+  if (tvc->iter && clog_textview_skip__internal(tvc)) {
     return true;
   }
 
@@ -173,10 +163,11 @@ int clog_textview_step(struct TextViewContext *tvc)
 {
   const CLG_LogRecord *record = tvc->iter;
   tvc->iter = record->prev;
+  // TODO (grzelins) implement skip not visible
   return (tvc->iter != NULL);
 }
 
-void clog_textview_line_get(struct TextViewContext *tvc,
+void clog_textview_text_get(struct TextViewContext *tvc,
                             char **r_line,
                             int *r_len,
                             bool *owns_memory)
diff --git a/source/blender/editors/space_info/info_draw_report.c 
b/source/blender/editors/space_info/info_draw_report.c
index cfcd9c5ca3b..27cc11149a2 100644
--- a/source/blender/editors/space_info/info_draw_report.c
+++ b/source/blender/editors/space_info/info_draw_report.c
@@ -59,7 +59,7 @@ enum eTextViewContext_LineDrawFlag 
report_line_draw_data(TextViewContext *tvc,
     UI_GetThemeColor4ubv(bg_id, bg);
   }
   else {
-    if (tvc->iter_tmp % 2) {
+    if (tvc->iter_index % 2) {
       UI_GetThemeColor4ubv(TH_BACK, bg);
     }
     else {
@@ -73,40 +73,44 @@ enum eTextViewContext_LineDrawFlag 
report_line_draw_data(TextViewContext *tvc,
   int icon_fg_id;
   int icon_bg_id;
 
-  if (tvc->iter_char_begin != 0) {
-    *r_icon = ICON_NONE;
-  }
-  else if (report->type & RPT_ERROR_ALL) {
+  if (report->type & RPT_ERROR_ALL)
+  {
     icon_fg_id = TH_INFO_ERROR_TEXT;
     icon_bg_id = TH_INFO_ERROR;
     *r_icon = ICON_CANCEL;
   }
-  else if (report->type & RPT_WARNING_ALL) {
+  else if (report->type & RPT_WARNING_ALL)
+  {
     icon_fg_id = TH_INFO_WARNING_TEXT;
     icon_bg_id = TH_INFO_WARNING;
     *r_icon = ICON_ERROR;
   }
-  else if (report->type & RPT_INFO_ALL) {
+  else if (report->type & RPT_INFO_ALL)
+  {
     icon_fg_id = TH_INFO_INFO_TEXT;
     icon_bg_id = TH_INFO_INFO;
     *r_icon = ICON_INFO;
   }
-  else if (report->type & RPT_DEBUG_ALL) {
+  else if (report->type & RPT_DEBUG_ALL)
+  {
     icon_fg_id = TH_INFO_DEBUG_TEXT;
     icon_bg_id = TH_INFO_DEBUG;
     *r_icon = ICON_SYSTEM;
   }
-  else if (report->type & RPT_PROPERTY_ALL) {
+  else if (report->type & RPT_PROPERTY_ALL)
+  {
     icon_fg_id = TH_INFO_PROPERTY_TEXT;
     icon_bg_id = TH_INFO_PROPERTY;
     *r_icon = ICON_OPTIONS;
   }
-  else if (report->type & RPT_OPERATOR_ALL) {
+  else if (report->type & RPT_OPERATOR_ALL)
+  {
     icon_fg_id = TH_INFO_OPERATOR_TEXT;
     icon_bg_id = TH_INFO_OPERATOR;
     *r_icon = ICON_CHECKMARK;
   }
-  else {
+  else
+  {
     *r_icon = ICON_NONE;
   }
 
@@ -124,19 +128,6 @@ enum eTextViewContext_LineDrawFlag 
report_line_draw_data(TextViewContext *tvc,
   return data_flag | TVC_LINE_BG;
 }
 
-static void report_textview_init__internal(TextViewContext *tvc)
-{
-  const Report *report = tvc->iter;
-  const char *str = report->message;
-  for (int i = tvc->iter_char_end - 1; i >= 0; i -= 1) {
-    if (str[i] == '\n') {
-      tvc->iter_char_begin = i + 1;
-      return;
-    }
-  }
-  tvc->iter_char_begin = 0;
-}
-
 static int report_textview_skip__internal(TextViewContext *tvc)
 {
   const SpaceInfo *sinfo = tvc->arg1;
@@ -159,13 +150,7 @@ int report_textview_begin(TextViewContext *tvc)
   UI_ThemeClearColor(TH_BACK);
   GPU_clear(GPU_COLOR_BIT);
 
-  tvc->iter_tmp = 0;
   if (tvc->iter && report_textview_skip__internal(tvc)) {
-    /* init the newline iterator */
-    const Report *report = tvc->iter;
-    tvc->iter_char_end = report->len;
-    report_textview_init__internal(tvc);
-
     return true;
   }
 
@@ -179,38 +164,20 @@ void report_textview_end(TextViewContext *UNUSED(tvc))
 
 int report_textview_step(TextViewContext *tvc)
 {
-  /* simple case, but no newline support */
-  const Report *report = tvc->iter;
-
-  if (tvc->iter_char_begin <= 0) {
-    tvc->iter = (void *)((Link *)tvc->iter)->prev;
-    if (tvc->iter && report_textview_skip__internal(tvc)) {
-      tvc->iter_tmp++;
-
-      report = tvc->iter;
-      tvc->iter_char_end = report->len; /* reset start */
-      report_textview_init__internal(tvc);
-
-      return true;
-    }
-    return false;
+  tvc->iter = (void *)((Link *)tvc->iter)->prev;
+  if (tvc->iter && report_textview_skip__internal(tvc)) {
+    return true;
   }
-
-  /* step to the next newline */
-  tvc->iter_char_end = tvc->iter_char_begin - 1;
-  report_textview_init__internal(tvc);
-
-  return true;
+  return false;
 }
 
-void report_textview_line_get(struct TextViewContext *tvc,
+void report_textview_text_get(struct TextViewContext *tvc,
                               char **r_line,
                               int *r_len,
                               bool *owns_memory)
 {
   const Report *report = tvc->iter;
-
-  *r_line = (char *)(report->message + tvc->iter_char_begin);
-  *r_len = tvc->iter_char_end - tvc->iter_char_begin;
+  *r_line = (char *)(report->message);
+  *r_len = report->len;
   *owns_memory = false;
 }
\ No newline at end of file
diff --git a/source/blender/editors/space_info/info_intern.h 
b/source/blender/editors/space_info/info_intern.h
index afb410f042f..5d159139272 100644
--- a/source/blender/editors/space_info/info_intern.h
+++ b/source/blender/editors/space_info/info_intern.h
@@ -99,7 +99,7 @@ enum eTextViewContext_LineDrawFlag 
report_line_draw_data(struct TextViewContext
 int report_text

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to