[Bf-blender-cvs] [d4d9ded09bd] master: Cleanup: text view API
Campbell Barton
noreply at git.blender.org
Thu Mar 12 06:21:26 CET 2020
Commit: d4d9ded09bd34e0b44abd6f1269ff04b200da3f0
Author: Campbell Barton
Date: Thu Mar 12 16:11:52 2020 +1100
Branches: master
https://developer.blender.org/rBd4d9ded09bd34e0b44abd6f1269ff04b200da3f0
Cleanup: text view API
- Use typed enum for line_data callback.
- Pass in 'const' arguments where possible.
- Use 'r_' prefix for return arguments.
- Remove unused return value from line_get callback.
- Remove redundant casts.
===================================================================
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_intern.h
M source/blender/editors/space_info/info_report.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 7e32c3d2b5f..ee1496c96bb 100644
--- a/source/blender/editors/space_console/console_draw.c
+++ b/source/blender/editors/space_console/console_draw.c
@@ -38,14 +38,14 @@
#include "../space_info/textview.h"
-static int console_line_data(struct TextViewContext *tvc,
- uchar fg[4],
- uchar UNUSED(bg[4]),
- int *UNUSED(icon),
- uchar UNUSED(icon_fg[4]),
- uchar UNUSED(icon_bg[4]))
+static enum eTextViewContext_LineFlag console_line_data(TextViewContext *tvc,
+ uchar fg[4],
+ uchar UNUSED(bg[4]),
+ int *UNUSED(icon),
+ uchar UNUSED(icon_fg[4]),
+ uchar UNUSED(icon_bg[4]))
{
- ConsoleLine *cl_iter = (ConsoleLine *)tvc->iter;
+ const ConsoleLine *cl_iter = tvc->iter;
int fg_id = TH_TEXT;
switch (cl_iter->type) {
@@ -67,7 +67,7 @@ static int console_line_data(struct TextViewContext *tvc,
return TVC_LINE_FG;
}
-void console_scrollback_prompt_begin(struct SpaceConsole *sc, ConsoleLine *cl_dummy)
+void console_scrollback_prompt_begin(SpaceConsole *sc, ConsoleLine *cl_dummy)
{
/* fake the edit line being in the scroll buffer */
ConsoleLine *cl = sc->history.last;
@@ -81,7 +81,7 @@ void console_scrollback_prompt_begin(struct SpaceConsole *sc, ConsoleLine *cl_du
memcpy(cl_dummy->line + prompt_len, cl->line, cl->len + 1);
BLI_addtail(&sc->scrollback, cl_dummy);
}
-void console_scrollback_prompt_end(struct SpaceConsole *sc, ConsoleLine *cl_dummy)
+void console_scrollback_prompt_end(SpaceConsole *sc, ConsoleLine *cl_dummy)
{
MEM_freeN(cl_dummy->line);
BLI_remlink(&sc->scrollback, cl_dummy);
@@ -112,14 +112,13 @@ static int console_textview_step(TextViewContext *tvc)
return ((tvc->iter = (void *)((Link *)tvc->iter)->prev) != NULL);
}
-static int console_textview_line_get(struct TextViewContext *tvc, const char **line, int *len)
+static void console_textview_line_get(TextViewContext *tvc, const char **r_line, int *r_len)
{
- ConsoleLine *cl = (ConsoleLine *)tvc->iter;
- *line = cl->line;
- *len = cl->len;
+ const ConsoleLine *cl = tvc->iter;
+ *r_line = cl->line;
+ *r_len = cl->len;
// printf("'%s' %d\n", *line, cl->len);
BLI_assert(cl->line[cl->len] == '\0' && (cl->len == 0 || cl->line[cl->len - 1] != '\0'));
- return 1;
}
static void console_cursor_wrap_offset(
@@ -144,7 +143,7 @@ static void console_cursor_wrap_offset(
return;
}
-static void console_textview_draw_cursor(struct TextViewContext *tvc,
+static void console_textview_draw_cursor(TextViewContext *tvc,
int cwidth,
int columns,
int descender)
@@ -201,7 +200,7 @@ static void console_textview_draw_rect_calc(const ARegion *region,
r_draw_rect_outer->ymax = region->winy;
}
-static int console_textview_main__internal(struct SpaceConsole *sc,
+static int console_textview_main__internal(SpaceConsole *sc,
const ARegion *region,
const bool do_draw,
const int mval[2],
@@ -243,19 +242,19 @@ static int console_textview_main__internal(struct SpaceConsole *sc,
return ret;
}
-void console_textview_main(struct SpaceConsole *sc, const ARegion *region)
+void console_textview_main(SpaceConsole *sc, const ARegion *region)
{
const int mval[2] = {INT_MAX, INT_MAX};
console_textview_main__internal(sc, region, true, mval, NULL, NULL);
}
-int console_textview_height(struct SpaceConsole *sc, const ARegion *region)
+int console_textview_height(SpaceConsole *sc, const ARegion *region)
{
const int mval[2] = {INT_MAX, INT_MAX};
return console_textview_main__internal(sc, region, false, mval, NULL, NULL);
}
-int console_char_pick(struct SpaceConsole *sc, const ARegion *region, const int mval[2])
+int console_char_pick(SpaceConsole *sc, const ARegion *region, const int mval[2])
{
int r_mval_pick_offset = 0;
void *mval_pick_item = NULL;
diff --git a/source/blender/editors/space_info/info_draw.c b/source/blender/editors/space_info/info_draw.c
index 4d5f59cdb7c..0a5ca81484c 100644
--- a/source/blender/editors/space_info/info_draw.c
+++ b/source/blender/editors/space_info/info_draw.c
@@ -39,14 +39,14 @@
#include "textview.h"
#include "GPU_framebuffer.h"
-static int report_line_data(struct TextViewContext *tvc,
- uchar fg[4],
- uchar bg[4],
- int *icon,
- uchar icon_fg[4],
- uchar icon_bg[4])
+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])
{
- Report *report = (Report *)tvc->iter;
+ const Report *report = tvc->iter;
/* Same text color no matter what type of report. */
UI_GetThemeColor4ubv((report->flag & SELECT) ? TH_INFO_SELECTED_TEXT : TH_TEXT, fg);
@@ -64,35 +64,35 @@ static int report_line_data(struct TextViewContext *tvc,
if (report->type & RPT_ERROR_ALL) {
icon_fg_id = TH_INFO_ERROR_TEXT;
icon_bg_id = TH_INFO_ERROR;
- *icon = ICON_CANCEL;
+ *r_icon = ICON_CANCEL;
}
else if (report->type & RPT_WARNING_ALL) {
icon_fg_id = TH_INFO_WARNING_TEXT;
icon_bg_id = TH_INFO_WARNING;
- *icon = ICON_ERROR;
+ *r_icon = ICON_ERROR;
}
else if (report->type & RPT_INFO_ALL) {
icon_fg_id = TH_INFO_INFO_TEXT;
icon_bg_id = TH_INFO_INFO;
- *icon = ICON_INFO;
+ *r_icon = ICON_INFO;
}
else if (report->type & RPT_DEBUG_ALL) {
icon_fg_id = TH_INFO_DEBUG_TEXT;
icon_bg_id = TH_INFO_DEBUG;
- *icon = ICON_SYSTEM;
+ *r_icon = ICON_SYSTEM;
}
else if (report->type & RPT_PROPERTY) {
icon_fg_id = TH_INFO_PROPERTY_TEXT;
icon_bg_id = TH_INFO_PROPERTY;
- *icon = ICON_OPTIONS;
+ *r_icon = ICON_OPTIONS;
}
else if (report->type & RPT_OPERATOR) {
icon_fg_id = TH_INFO_OPERATOR_TEXT;
icon_bg_id = TH_INFO_OPERATOR;
- *icon = ICON_CHECKMARK;
+ *r_icon = ICON_CHECKMARK;
}
else {
- *icon = ICON_NONE;
+ *r_icon = ICON_NONE;
}
if (report->flag & SELECT) {
@@ -100,9 +100,9 @@ static int report_line_data(struct TextViewContext *tvc,
icon_bg_id = TH_INFO_SELECTED_TEXT;
}
- if (*icon != ICON_NONE) {
- UI_GetThemeColor4ubv(icon_fg_id, icon_fg);
- UI_GetThemeColor4ubv(icon_bg_id, icon_bg);
+ if (*r_icon != ICON_NONE) {
+ UI_GetThemeColor4ubv(icon_fg_id, r_icon_fg);
+ UI_GetThemeColor4ubv(icon_bg_id, r_icon_bg);
return TVC_LINE_FG | TVC_LINE_BG | TVC_LINE_ICON | TVC_LINE_ICON_FG | TVC_LINE_ICON_BG;
}
else {
@@ -113,7 +113,7 @@ static int report_line_data(struct TextViewContext *tvc,
/* reports! */
static void report_textview_init__internal(TextViewContext *tvc)
{
- Report *report = (Report *)tvc->iter;
+ const Report *report = tvc->iter;
const char *str = report->message;
const char *next_str = strchr(str + tvc->iter_char, '\n');
@@ -127,9 +127,9 @@ static void report_textview_init__internal(TextViewContext *tvc)
static int report_textview_skip__internal(TextViewContext *tvc)
{
- SpaceInfo *sinfo = (SpaceInfo *)tvc->arg1;
+ const SpaceInfo *sinfo = tvc->arg1;
const int report_mask = info_report_mask(sinfo);
- while (tvc->iter && (((Report *)tvc->iter)->type & report_mask) == 0) {
+ while (tvc->iter && (((const Report *)tvc->iter)->type & report_mask) == 0) {
tvc->iter = (void *)((Link *)tvc->iter)->prev;
}
return (tvc->iter != NULL);
@@ -137,7 +137,7 @@ static int report_textview_skip__internal(TextViewContext *tvc)
static int report_textview_begin(TextViewContext *tvc)
{
- ReportList *reports = (ReportList *)tvc->arg2;
+ const ReportList *reports = tvc->arg2;
tvc->lheight = 14 * UI_DPI_FAC;
tvc->sel_start = 0;
@@ -170,7 +170,7 @@ static void report_textview_end(TextViewContext *UNUSED(tvc))
static int report_textview_step(TextViewContext *tvc)
{
/* simple case, but no newline support */
- Report *report = (Report *)tvc->iter;
+ const Report *report = tvc->iter;
if (report->len <= tvc->iter_char_next) {
tvc->iter = (void *)((Link *)tvc->iter)->prev;
@@ -195,12 +195,11 @@ static int report_textview_step(TextViewContext *tvc)
}
}
-static int report_textview_line_get(struct TextViewContext *tvc, const char **line, int *len)
+static void report_textview_line_get(TextViewContext *tvc, const char **r_line, int *r_len)
{
- Report *report = (Report *)tvc->iter;
- *line = report->message + tvc->iter_char;
- *len = tvc->iter_char_next - tvc->iter_char;
- return 1;
+ const Report *report = tvc->iter;
+ *r_line = report->message + tvc->iter_char;
+ *r_len = tvc->iter_char_next - tvc->iter_char;
}
static void info_textview_draw_rect_calc(const ARegion *region,
@@ -220,9 +219,9 @@ static void info_textview_draw_rect_calc(const ARegion *region,
r_draw_rect_outer->ymax = region->winy;
}
-static int info_textview_main__internal(struct SpaceInfo *sinfo,
+static int info_textview_main__internal(const SpaceInfo *sinfo,
const ARegion *region,
- ReportList *reports,
+ const ReportList *reports,
const bool do_draw,
const int mva
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list