diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-03-12 08:11:52 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-03-12 08:18:38 +0300 |
commit | d4d9ded09bd34e0b44abd6f1269ff04b200da3f0 (patch) | |
tree | cfd036dda49d0ed0363c7d471743682937fdd5cb /source/blender | |
parent | 6ce709dceb8db65ec6baae21100a7ce93829b1f6 (diff) |
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.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/space_console/console_draw.c | 37 | ||||
-rw-r--r-- | source/blender/editors/space_info/info_draw.c | 65 | ||||
-rw-r--r-- | source/blender/editors/space_info/info_intern.h | 14 | ||||
-rw-r--r-- | source/blender/editors/space_info/info_report.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_info/textview.h | 36 |
5 files changed, 76 insertions, 78 deletions
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 mval[2], void **r_mval_pick_item, @@ -259,9 +258,9 @@ static int info_textview_main__internal(struct SpaceInfo *sinfo, return ret; } -void *info_text_pick(struct SpaceInfo *sinfo, +void *info_text_pick(const SpaceInfo *sinfo, const ARegion *region, - ReportList *reports, + const ReportList *reports, int mval_y) { void *mval_pick_item = NULL; @@ -271,13 +270,13 @@ void *info_text_pick(struct SpaceInfo *sinfo, return (void *)mval_pick_item; } -int info_textview_height(struct SpaceInfo *sinfo, const ARegion *region, ReportList *reports) +int info_textview_height(const SpaceInfo *sinfo, const ARegion *region, const ReportList *reports) { int mval[2] = {INT_MAX, INT_MAX}; return info_textview_main__internal(sinfo, region, reports, false, mval, NULL, NULL); } -void info_textview_main(struct SpaceInfo *sinfo, const ARegion *region, ReportList *reports) +void info_textview_main(const SpaceInfo *sinfo, const ARegion *region, const ReportList *reports) { int mval[2] = {INT_MAX, INT_MAX}; info_textview_main__internal(sinfo, region, reports, true, mval, NULL, NULL); diff --git a/source/blender/editors/space_info/info_intern.h b/source/blender/editors/space_info/info_intern.h index 443a1659690..79bfb1fa047 100644 --- a/source/blender/editors/space_info/info_intern.h +++ b/source/blender/editors/space_info/info_intern.h @@ -45,19 +45,19 @@ void FILE_OT_find_missing_files(struct wmOperatorType *ot); void INFO_OT_reports_display_update(struct wmOperatorType *ot); /* info_draw.c */ -void *info_text_pick(struct SpaceInfo *sinfo, +void *info_text_pick(const struct SpaceInfo *sinfo, const struct ARegion *region, - ReportList *reports, + const struct ReportList *reports, int mouse_y); -int info_textview_height(struct SpaceInfo *sinfo, +int info_textview_height(const struct SpaceInfo *sinfo, const struct ARegion *region, - struct ReportList *reports); -void info_textview_main(struct SpaceInfo *sinfo, + const struct ReportList *reports); +void info_textview_main(const struct SpaceInfo *sinfo, const struct ARegion *region, - struct ReportList *reports); + const struct ReportList *reports); /* info_report.c */ -int info_report_mask(struct SpaceInfo *sinfo); +int info_report_mask(const struct SpaceInfo *sinfo); void INFO_OT_select_pick(struct wmOperatorType *ot); /* report selection */ void INFO_OT_select_all(struct wmOperatorType *ot); void INFO_OT_select_box(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_info/info_report.c b/source/blender/editors/space_info/info_report.c index 1b01ac95866..303e2bbaec9 100644 --- a/source/blender/editors/space_info/info_report.c +++ b/source/blender/editors/space_info/info_report.c @@ -72,7 +72,7 @@ static void reports_select_all(ReportList *reports, int report_mask, int action) } } -int info_report_mask(SpaceInfo *UNUSED(sinfo)) +int info_report_mask(const SpaceInfo *UNUSED(sinfo)) { #if 0 int report_mask = 0; diff --git a/source/blender/editors/space_info/textview.h b/source/blender/editors/space_info/textview.h index a33ed91570d..54b7c477791 100644 --- a/source/blender/editors/space_info/textview.h +++ b/source/blender/editors/space_info/textview.h @@ -21,6 +21,14 @@ #ifndef __TEXTVIEW_H__ #define __TEXTVIEW_H__ +enum eTextViewContext_LineFlag { + TVC_LINE_FG = (1 << 0), + TVC_LINE_BG = (1 << 1), + TVC_LINE_ICON = (1 << 2), + TVC_LINE_ICON_FG = (1 << 3), + TVC_LINE_ICON_BG = (1 << 4) +}; + typedef struct TextViewContext { /** Font size scaled by the interface size. */ int lheight; @@ -40,22 +48,22 @@ typedef struct TextViewContext { /* callbacks */ int (*begin)(struct TextViewContext *tvc); void (*end)(struct TextViewContext *tvc); - void *arg1; - void *arg2; + const void *arg1; + const void *arg2; /* iterator */ int (*step)(struct TextViewContext *tvc); - int (*line_get)(struct TextViewContext *tvc, const char **, int *); - int (*line_data)(struct TextViewContext *tvc, - unsigned char fg[4], - unsigned char bg[4], - int *icon, - unsigned char icon_fg[4], - unsigned char icon_bg[4]); + void (*line_get)(struct TextViewContext *tvc, const char **r_line, int *r_len); + 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]); 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; + const void *iter; int iter_index; /** Char index, used for multi-line report display. */ int iter_char; @@ -72,12 +80,4 @@ int textview_draw(struct TextViewContext *tvc, void **r_mval_pick_item, int *r_mval_pick_offset); -enum { - TVC_LINE_FG = (1 << 0), - TVC_LINE_BG = (1 << 1), - TVC_LINE_ICON = (1 << 2), - TVC_LINE_ICON_FG = (1 << 3), - TVC_LINE_ICON_BG = (1 << 4) -}; - #endif /* __TEXTVIEW_H__ */ |