Blender  V2.93
info_draw.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2010 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include <limits.h>
25 #include <string.h>
26 
27 #include "BLI_utildefines.h"
28 
29 #include "DNA_screen_types.h"
30 #include "DNA_space_types.h"
31 
32 #include "BKE_report.h"
33 
34 #include "UI_interface.h"
35 #include "UI_resources.h"
36 #include "UI_view2d.h"
37 
38 #include "info_intern.h"
39 #include "textview.h"
40 
42  uchar fg[4],
43  uchar bg[4],
44  int *r_icon,
45  uchar r_icon_fg[4],
46  uchar r_icon_bg[4])
47 {
48  const Report *report = tvc->iter;
49 
50  /* Same text color no matter what type of report. */
52 
53  /* Zebra striping for background. */
54  int bg_id = (report->flag & SELECT) ? TH_INFO_SELECTED : TH_BACK;
55  int shade = (tvc->iter_tmp % 2) ? 4 : -4;
56  UI_GetThemeColorShade4ubv(bg_id, shade, bg);
57 
58  /* Don't show icon on subsequent rows of multi-row report. */
59  *r_icon = (tvc->iter_char_begin != 0) ? ICON_NONE : UI_icon_from_report_type(report->type);
60 
61  int icon_fg_id = UI_text_colorid_from_report_type(report->type);
62  int icon_bg_id = UI_icon_colorid_from_report_type(report->type);
63 
64  if (report->flag & SELECT) {
65  icon_fg_id = TH_INFO_SELECTED;
66  icon_bg_id = TH_INFO_SELECTED_TEXT;
67  }
68 
69  if (*r_icon != ICON_NONE) {
70  UI_GetThemeColor4ubv(icon_fg_id, r_icon_fg);
71  /* This theme color is RGB only, so set alpha. */
72  r_icon_fg[3] = 255;
73  UI_GetThemeColor4ubv(icon_bg_id, r_icon_bg);
75  }
76 
77  return TVC_LINE_FG | TVC_LINE_BG;
78 }
79 
80 /* reports! */
82 {
83  const Report *report = tvc->iter;
84  const char *str = report->message;
85  for (int i = tvc->iter_char_end - 1; i >= 0; i -= 1) {
86  if (str[i] == '\n') {
87  tvc->iter_char_begin = i + 1;
88  return;
89  }
90  }
91  tvc->iter_char_begin = 0;
92 }
93 
95 {
96  const SpaceInfo *sinfo = tvc->arg1;
97  const int report_mask = info_report_mask(sinfo);
98  while (tvc->iter && (((const Report *)tvc->iter)->type & report_mask) == 0) {
99  tvc->iter = (void *)((Link *)tvc->iter)->prev;
100  }
101  return (tvc->iter != NULL);
102 }
103 
105 {
106  const ReportList *reports = tvc->arg2;
107 
108  tvc->sel_start = 0;
109  tvc->sel_end = 0;
110 
111  /* iterator */
112  tvc->iter = reports->list.last;
113 
115 
116  tvc->iter_tmp = 0;
117  if (tvc->iter && report_textview_skip__internal(tvc)) {
118  /* init the newline iterator */
119  const Report *report = tvc->iter;
120  tvc->iter_char_end = report->len;
122 
123  return true;
124  }
125 
126  return false;
127 }
128 
130 {
131  /* pass */
132 }
133 
135 {
136  /* simple case, but no newline support */
137  const Report *report = tvc->iter;
138 
139  if (tvc->iter_char_begin <= 0) {
140  tvc->iter = (void *)((Link *)tvc->iter)->prev;
141  if (tvc->iter && report_textview_skip__internal(tvc)) {
142  tvc->iter_tmp++;
143 
144  report = tvc->iter;
145  tvc->iter_char_end = report->len; /* reset start */
147 
148  return true;
149  }
150  return false;
151  }
152 
153  /* step to the next newline */
154  tvc->iter_char_end = tvc->iter_char_begin - 1;
156 
157  return true;
158 }
159 
160 static void report_textview_line_get(TextViewContext *tvc, const char **r_line, int *r_len)
161 {
162  const Report *report = tvc->iter;
163  *r_line = report->message + tvc->iter_char_begin;
164  *r_len = tvc->iter_char_end - tvc->iter_char_begin;
165 }
166 
167 static void info_textview_draw_rect_calc(const ARegion *region,
168  rcti *r_draw_rect,
169  rcti *r_draw_rect_outer)
170 {
171  const int margin = 0.45f * U.widget_unit;
172  r_draw_rect->xmin = margin + UI_UNIT_X;
173  r_draw_rect->xmax = region->winx - V2D_SCROLL_WIDTH;
174  r_draw_rect->ymin = margin;
175  r_draw_rect->ymax = region->winy;
176  /* No margin at the top (allow text to scroll off the window). */
177 
178  r_draw_rect_outer->xmin = 0;
179  r_draw_rect_outer->xmax = region->winx;
180  r_draw_rect_outer->ymin = 0;
181  r_draw_rect_outer->ymax = region->winy;
182 }
183 
184 static int info_textview_main__internal(const SpaceInfo *sinfo,
185  const ARegion *region,
186  const ReportList *reports,
187  const bool do_draw,
188  const int mval[2],
189  void **r_mval_pick_item,
190  int *r_mval_pick_offset)
191 {
192  int ret = 0;
193 
194  const View2D *v2d = &region->v2d;
195 
196  TextViewContext tvc = {0};
198  tvc.end = report_textview_end;
199 
203  tvc.const_colors = NULL;
204 
205  tvc.arg1 = sinfo;
206  tvc.arg2 = reports;
207 
208  /* view */
209  tvc.sel_start = 0;
210  tvc.sel_end = 0;
211  tvc.lheight = 17 * UI_DPI_FAC;
212  tvc.row_vpadding = 0.4 * tvc.lheight;
213  tvc.scroll_ymin = v2d->cur.ymin;
214  tvc.scroll_ymax = v2d->cur.ymax;
215 
217 
218  ret = textview_draw(&tvc, do_draw, mval, r_mval_pick_item, r_mval_pick_offset);
219 
220  return ret;
221 }
222 
223 void *info_text_pick(const SpaceInfo *sinfo,
224  const ARegion *region,
225  const ReportList *reports,
226  int mouse_y)
227 {
228  void *mval_pick_item = NULL;
229  const int mval[2] = {0, mouse_y};
230 
231  info_textview_main__internal(sinfo, region, reports, false, mval, &mval_pick_item, NULL);
232  return (void *)mval_pick_item;
233 }
234 
235 int info_textview_height(const SpaceInfo *sinfo, const ARegion *region, const ReportList *reports)
236 {
237  const int mval[2] = {INT_MAX, INT_MAX};
238  return info_textview_main__internal(sinfo, region, reports, false, mval, NULL, NULL);
239 }
240 
241 void info_textview_main(const SpaceInfo *sinfo, const ARegion *region, const ReportList *reports)
242 {
243  const int mval[2] = {INT_MAX, INT_MAX};
244  info_textview_main__internal(sinfo, region, reports, true, mval, NULL, NULL);
245 }
unsigned char uchar
Definition: BLI_sys_types.h:86
#define UNUSED(x)
int UI_text_colorid_from_report_type(int type)
int UI_icon_from_report_type(int type)
int UI_icon_colorid_from_report_type(int type)
#define UI_DPI_FAC
Definition: UI_interface.h:309
#define UI_UNIT_X
@ TH_BACK
Definition: UI_resources.h:55
@ TH_INFO_SELECTED_TEXT
Definition: UI_resources.h:330
@ TH_INFO_SELECTED
Definition: UI_resources.h:329
@ TH_TEXT
Definition: UI_resources.h:58
void UI_ThemeClearColor(int colorid)
Definition: resources.c:1478
void UI_GetThemeColorShade4ubv(int colorid, int offset, unsigned char col[4])
Definition: resources.c:1268
void UI_GetThemeColor4ubv(int colorid, unsigned char col[4])
Definition: resources.c:1381
#define V2D_SCROLL_WIDTH
Definition: UI_view2d.h:68
unsigned int U
Definition: btGjkEpa3.h:78
#define SELECT
#define str(s)
static void report_textview_end(TextViewContext *UNUSED(tvc))
Definition: info_draw.c:129
void info_textview_main(const SpaceInfo *sinfo, const ARegion *region, const ReportList *reports)
Definition: info_draw.c:241
void * info_text_pick(const SpaceInfo *sinfo, const ARegion *region, const ReportList *reports, int mouse_y)
Definition: info_draw.c:223
static int info_textview_main__internal(const SpaceInfo *sinfo, const ARegion *region, const ReportList *reports, const bool do_draw, const int mval[2], void **r_mval_pick_item, int *r_mval_pick_offset)
Definition: info_draw.c:184
int info_textview_height(const SpaceInfo *sinfo, const ARegion *region, const ReportList *reports)
Definition: info_draw.c:235
static enum eTextViewContext_LineFlag report_line_data(TextViewContext *tvc, uchar fg[4], uchar bg[4], int *r_icon, uchar r_icon_fg[4], uchar r_icon_bg[4])
Definition: info_draw.c:41
static int report_textview_begin(TextViewContext *tvc)
Definition: info_draw.c:104
static void info_textview_draw_rect_calc(const ARegion *region, rcti *r_draw_rect, rcti *r_draw_rect_outer)
Definition: info_draw.c:167
static void report_textview_line_get(TextViewContext *tvc, const char **r_line, int *r_len)
Definition: info_draw.c:160
static int report_textview_step(TextViewContext *tvc)
Definition: info_draw.c:134
static void report_textview_init__internal(TextViewContext *tvc)
Definition: info_draw.c:81
static int report_textview_skip__internal(TextViewContext *tvc)
Definition: info_draw.c:94
int info_report_mask(const struct SpaceInfo *sinfo)
return ret
void * last
Definition: DNA_listBase.h:47
const char * message
const void * arg2
Definition: textview.h:51
rcti draw_rect
Definition: textview.h:40
const void * arg1
Definition: textview.h:50
void(* line_get)(struct TextViewContext *tvc, const char **r_line, int *r_len)
Definition: textview.h:55
const void * iter
Definition: textview.h:65
int iter_char_end
Definition: textview.h:70
int row_vpadding
Definition: textview.h:37
int iter_char_begin
Definition: textview.h:68
int(* begin)(struct TextViewContext *tvc)
Definition: textview.h:48
void(* const_colors)(struct TextViewContext *tvc, unsigned char bg_sel[4])
Definition: textview.h:64
enum eTextViewContext_LineFlag(* line_data)(struct TextViewContext *tvc, uchar fg[4], uchar bg[4], int *r_icon, uchar r_icon_fg[4], uchar r_icon_bg[4])
Definition: textview.h:56
void(* end)(struct TextViewContext *tvc)
Definition: textview.h:49
int(* step)(struct TextViewContext *tvc)
Definition: textview.h:54
rcti draw_rect_outer
Definition: textview.h:42
float ymax
Definition: DNA_vec_types.h:86
float ymin
Definition: DNA_vec_types.h:86
int ymin
Definition: DNA_vec_types.h:80
int ymax
Definition: DNA_vec_types.h:80
int xmin
Definition: DNA_vec_types.h:79
int xmax
Definition: DNA_vec_types.h:79
int textview_draw(TextViewContext *tvc, const bool do_draw, const int mval_init[2], void **r_mval_pick_item, int *r_mval_pick_offset)
Definition: textview.c:313
eTextViewContext_LineFlag
Definition: textview.h:23
@ TVC_LINE_ICON
Definition: textview.h:26
@ TVC_LINE_ICON_FG
Definition: textview.h:27
@ TVC_LINE_ICON_BG
Definition: textview.h:28
@ TVC_LINE_BG
Definition: textview.h:25
@ TVC_LINE_FG
Definition: textview.h:24