diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:17:24 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:21:24 +0300 |
commit | e12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch) | |
tree | 8cf3453d12edb177a218ef8009357518ec6cab6a /source/blender/editors/space_info | |
parent | b3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff) |
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211.
For details on usage and instructions for migrating branches
without conflicts, see:
https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'source/blender/editors/space_info')
-rw-r--r-- | source/blender/editors/space_info/CMakeLists.txt | 52 | ||||
-rw-r--r-- | source/blender/editors/space_info/info_draw.c | 314 | ||||
-rw-r--r-- | source/blender/editors/space_info/info_intern.h | 6 | ||||
-rw-r--r-- | source/blender/editors/space_info/info_ops.c | 722 | ||||
-rw-r--r-- | source/blender/editors/space_info/info_report.c | 481 | ||||
-rw-r--r-- | source/blender/editors/space_info/info_stats.c | 862 | ||||
-rw-r--r-- | source/blender/editors/space_info/space_info.c | 358 | ||||
-rw-r--r-- | source/blender/editors/space_info/textview.c | 606 | ||||
-rw-r--r-- | source/blender/editors/space_info/textview.h | 63 |
9 files changed, 1772 insertions, 1692 deletions
diff --git a/source/blender/editors/space_info/CMakeLists.txt b/source/blender/editors/space_info/CMakeLists.txt index 665d130e072..bb403751fe2 100644 --- a/source/blender/editors/space_info/CMakeLists.txt +++ b/source/blender/editors/space_info/CMakeLists.txt @@ -16,44 +16,44 @@ # ***** END GPL LICENSE BLOCK ***** set(INC - ../include - ../../blenfont - ../../blenkernel - ../../blenlib - ../../blenloader - ../../blentranslation - ../../depsgraph - ../../imbuf - ../../bmesh - ../../gpu - ../../makesdna - ../../makesrna - ../../windowmanager - ../../../../intern/guardedalloc - ../../../../intern/glew-mx + ../include + ../../blenfont + ../../blenkernel + ../../blenlib + ../../blenloader + ../../blentranslation + ../../depsgraph + ../../imbuf + ../../bmesh + ../../gpu + ../../makesdna + ../../makesrna + ../../windowmanager + ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS - ${GLEW_INCLUDE_PATH} + ${GLEW_INCLUDE_PATH} ) set(SRC - info_draw.c - info_ops.c - info_report.c - info_stats.c - space_info.c - textview.c - - info_intern.h - textview.h + info_draw.c + info_ops.c + info_report.c + info_stats.c + space_info.c + textview.c + + info_intern.h + textview.h ) set(LIB ) if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) + add_definitions(-DWITH_INTERNATIONAL) endif() add_definitions(${GL_DEFINITIONS}) diff --git a/source/blender/editors/space_info/info_draw.c b/source/blender/editors/space_info/info_draw.c index 39d255427cc..a7d6694b362 100644 --- a/source/blender/editors/space_info/info_draw.c +++ b/source/blender/editors/space_info/info_draw.c @@ -46,236 +46,246 @@ /* complicates things a bit, so leaving in old simple code */ #define USE_INFO_NEWLINE -static void info_report_color(unsigned char *fg, unsigned char *bg, Report *report, const short do_tint) +static void info_report_color(unsigned char *fg, + unsigned char *bg, + Report *report, + const short do_tint) { - int bg_id = TH_BACK, fg_id = TH_TEXT; - int shade = do_tint ? 0 : -6; - - if (report->flag & SELECT) { - bg_id = TH_INFO_SELECTED; - fg_id = TH_INFO_SELECTED_TEXT; - } - else if (report->type & RPT_ERROR_ALL) { - bg_id = TH_INFO_ERROR; - fg_id = TH_INFO_ERROR_TEXT; - } - else if (report->type & RPT_WARNING_ALL) { - bg_id = TH_INFO_WARNING; - fg_id = TH_INFO_WARNING_TEXT; - } - else if (report->type & RPT_INFO_ALL) { - bg_id = TH_INFO_INFO; - fg_id = TH_INFO_INFO_TEXT; - } - else if (report->type & RPT_DEBUG_ALL) { - bg_id = TH_INFO_DEBUG; - fg_id = TH_INFO_DEBUG_TEXT; - } - else { - bg_id = TH_BACK; - fg_id = TH_TEXT; - } - - UI_GetThemeColorShade3ubv(bg_id, shade, bg); - UI_GetThemeColor3ubv(fg_id, fg); + int bg_id = TH_BACK, fg_id = TH_TEXT; + int shade = do_tint ? 0 : -6; + + if (report->flag & SELECT) { + bg_id = TH_INFO_SELECTED; + fg_id = TH_INFO_SELECTED_TEXT; + } + else if (report->type & RPT_ERROR_ALL) { + bg_id = TH_INFO_ERROR; + fg_id = TH_INFO_ERROR_TEXT; + } + else if (report->type & RPT_WARNING_ALL) { + bg_id = TH_INFO_WARNING; + fg_id = TH_INFO_WARNING_TEXT; + } + else if (report->type & RPT_INFO_ALL) { + bg_id = TH_INFO_INFO; + fg_id = TH_INFO_INFO_TEXT; + } + else if (report->type & RPT_DEBUG_ALL) { + bg_id = TH_INFO_DEBUG; + fg_id = TH_INFO_DEBUG_TEXT; + } + else { + bg_id = TH_BACK; + fg_id = TH_TEXT; + } + + UI_GetThemeColorShade3ubv(bg_id, shade, bg); + UI_GetThemeColor3ubv(fg_id, fg); } /* reports! */ #ifdef USE_INFO_NEWLINE static void report_textview_init__internal(TextViewContext *tvc) { - Report *report = (Report *)tvc->iter; - const char *str = report->message; - const char *next_str = strchr(str + tvc->iter_char, '\n'); - - if (next_str) { - tvc->iter_char_next = (int)(next_str - str); - } - else { - tvc->iter_char_next = report->len; - } + Report *report = (Report *)tvc->iter; + const char *str = report->message; + const char *next_str = strchr(str + tvc->iter_char, '\n'); + + if (next_str) { + tvc->iter_char_next = (int)(next_str - str); + } + else { + tvc->iter_char_next = report->len; + } } static int report_textview_skip__internal(TextViewContext *tvc) { - SpaceInfo *sinfo = (SpaceInfo *)tvc->arg1; - const int report_mask = info_report_mask(sinfo); - while (tvc->iter && (((Report *)tvc->iter)->type & report_mask) == 0) { - tvc->iter = (void *)((Link *)tvc->iter)->prev; - } - return (tvc->iter != NULL); + SpaceInfo *sinfo = (SpaceInfo *)tvc->arg1; + const int report_mask = info_report_mask(sinfo); + while (tvc->iter && (((Report *)tvc->iter)->type & report_mask) == 0) { + tvc->iter = (void *)((Link *)tvc->iter)->prev; + } + return (tvc->iter != NULL); } -#endif // USE_INFO_NEWLINE +#endif // USE_INFO_NEWLINE static int report_textview_begin(TextViewContext *tvc) { - // SpaceConsole *sc = (SpaceConsole *)tvc->arg1; - ReportList *reports = (ReportList *)tvc->arg2; + // SpaceConsole *sc = (SpaceConsole *)tvc->arg1; + ReportList *reports = (ReportList *)tvc->arg2; - tvc->lheight = 14 * UI_DPI_FAC; //sc->lheight; - tvc->sel_start = 0; - tvc->sel_end = 0; + tvc->lheight = 14 * UI_DPI_FAC; //sc->lheight; + tvc->sel_start = 0; + tvc->sel_end = 0; - /* iterator */ - tvc->iter = reports->list.last; + /* iterator */ + tvc->iter = reports->list.last; - UI_ThemeClearColor(TH_BACK); - GPU_clear(GPU_COLOR_BIT); + UI_ThemeClearColor(TH_BACK); + GPU_clear(GPU_COLOR_BIT); #ifdef USE_INFO_NEWLINE - tvc->iter_tmp = 0; - if (tvc->iter && report_textview_skip__internal(tvc)) { - /* init the newline iterator */ - tvc->iter_char = 0; - report_textview_init__internal(tvc); - - return true; - } - else { - return false; - } + tvc->iter_tmp = 0; + if (tvc->iter && report_textview_skip__internal(tvc)) { + /* init the newline iterator */ + tvc->iter_char = 0; + report_textview_init__internal(tvc); + + return true; + } + else { + return false; + } #else - return (tvc->iter != NULL); + return (tvc->iter != NULL); #endif } static void report_textview_end(TextViewContext *UNUSED(tvc)) { - /* pass */ + /* pass */ } #ifdef USE_INFO_NEWLINE static int report_textview_step(TextViewContext *tvc) { - /* simple case, but no newline support */ - Report *report = (Report *)tvc->iter; - - if (report->len <= tvc->iter_char_next) { - tvc->iter = (void *)((Link *)tvc->iter)->prev; - if (tvc->iter && report_textview_skip__internal(tvc)) { - tvc->iter_tmp++; - - tvc->iter_char = 0; /* reset start */ - report_textview_init__internal(tvc); - - return true; - } - else { - return false; - } - } - else { - /* step to the next newline */ - tvc->iter_char = tvc->iter_char_next + 1; - report_textview_init__internal(tvc); - - return true; - } + /* simple case, but no newline support */ + Report *report = (Report *)tvc->iter; + + if (report->len <= tvc->iter_char_next) { + tvc->iter = (void *)((Link *)tvc->iter)->prev; + if (tvc->iter && report_textview_skip__internal(tvc)) { + tvc->iter_tmp++; + + tvc->iter_char = 0; /* reset start */ + report_textview_init__internal(tvc); + + return true; + } + else { + return false; + } + } + else { + /* step to the next newline */ + tvc->iter_char = tvc->iter_char_next + 1; + report_textview_init__internal(tvc); + + return true; + } } static int report_textview_line_get(struct TextViewContext *tvc, const char **line, int *len) { - Report *report = (Report *)tvc->iter; - *line = report->message + tvc->iter_char; - *len = tvc->iter_char_next - tvc->iter_char; - return 1; + Report *report = (Report *)tvc->iter; + *line = report->message + tvc->iter_char; + *len = tvc->iter_char_next - tvc->iter_char; + return 1; } -static int report_textview_line_color(struct TextViewContext *tvc, unsigned char fg[3], unsigned char bg[3]) +static int report_textview_line_color(struct TextViewContext *tvc, + unsigned char fg[3], + unsigned char bg[3]) { - Report *report = (Report *)tvc->iter; - info_report_color(fg, bg, report, tvc->iter_tmp % 2); - return TVC_LINE_FG | TVC_LINE_BG; + Report *report = (Report *)tvc->iter; + info_report_color(fg, bg, report, tvc->iter_tmp % 2); + return TVC_LINE_FG | TVC_LINE_BG; } - -#else // USE_INFO_NEWLINE +#else // USE_INFO_NEWLINE static int report_textview_step(TextViewContext *tvc) { - SpaceInfo *sinfo = (SpaceInfo *)tvc->arg1; - const int report_mask = info_report_mask(sinfo); - do { - tvc->iter = (void *)((Link *)tvc->iter)->prev; - } while (tvc->iter && (((Report *)tvc->iter)->type & report_mask) == 0); + SpaceInfo *sinfo = (SpaceInfo *)tvc->arg1; + const int report_mask = info_report_mask(sinfo); + do { + tvc->iter = (void *)((Link *)tvc->iter)->prev; + } while (tvc->iter && (((Report *)tvc->iter)->type & report_mask) == 0); - return (tvc->iter != NULL); + return (tvc->iter != NULL); } static int report_textview_line_get(struct TextViewContext *tvc, const char **line, int *len) { - Report *report = (Report *)tvc->iter; - *line = report->message; - *len = report->len; + Report *report = (Report *)tvc->iter; + *line = report->message; + *len = report->len; - return 1; + return 1; } -static int report_textview_line_color(struct TextViewContext *tvc, unsigned char fg[3], unsigned char bg[3]) +static int report_textview_line_color(struct TextViewContext *tvc, + unsigned char fg[3], + unsigned char bg[3]) { - Report *report = (Report *)tvc->iter; - info_report_color(fg, bg, report, tvc->iter_tmp % 2); - return TVC_LINE_FG | TVC_LINE_BG; + Report *report = (Report *)tvc->iter; + info_report_color(fg, bg, report, tvc->iter_tmp % 2); + return TVC_LINE_FG | TVC_LINE_BG; } -#endif // USE_INFO_NEWLINE +#endif // USE_INFO_NEWLINE #undef USE_INFO_NEWLINE -static int info_textview_main__internal(struct SpaceInfo *sinfo, ARegion *ar, ReportList *reports, - int draw, int mval[2], void **mouse_pick, int *pos_pick) +static int info_textview_main__internal(struct SpaceInfo *sinfo, + ARegion *ar, + ReportList *reports, + int draw, + int mval[2], + void **mouse_pick, + int *pos_pick) { - int ret = 0; + int ret = 0; - View2D *v2d = &ar->v2d; + View2D *v2d = &ar->v2d; - TextViewContext tvc = {0}; - tvc.begin = report_textview_begin; - tvc.end = report_textview_end; + TextViewContext tvc = {0}; + tvc.begin = report_textview_begin; + tvc.end = report_textview_end; - tvc.step = report_textview_step; - tvc.line_get = report_textview_line_get; - tvc.line_color = report_textview_line_color; - tvc.const_colors = NULL; + tvc.step = report_textview_step; + tvc.line_get = report_textview_line_get; + tvc.line_color = report_textview_line_color; + tvc.const_colors = NULL; - tvc.arg1 = sinfo; - tvc.arg2 = reports; + tvc.arg1 = sinfo; + tvc.arg2 = reports; - /* view */ - tvc.sel_start = 0; - tvc.sel_end = 0; - tvc.lheight = 14 * UI_DPI_FAC; //sc->lheight; - tvc.ymin = v2d->cur.ymin; - tvc.ymax = v2d->cur.ymax; - tvc.winx = ar->winx - V2D_SCROLL_WIDTH; + /* view */ + tvc.sel_start = 0; + tvc.sel_end = 0; + tvc.lheight = 14 * UI_DPI_FAC; //sc->lheight; + tvc.ymin = v2d->cur.ymin; + tvc.ymax = v2d->cur.ymax; + tvc.winx = ar->winx - V2D_SCROLL_WIDTH; - ret = textview_draw(&tvc, draw, mval, mouse_pick, pos_pick); + ret = textview_draw(&tvc, draw, mval, mouse_pick, pos_pick); - return ret; + return ret; } void *info_text_pick(struct SpaceInfo *sinfo, ARegion *ar, ReportList *reports, int mouse_y) { - void *mouse_pick = NULL; - int mval[2]; + void *mouse_pick = NULL; + int mval[2]; - mval[0] = 0; - mval[1] = mouse_y; + mval[0] = 0; + mval[1] = mouse_y; - info_textview_main__internal(sinfo, ar, reports, 0, mval, &mouse_pick, NULL); - return (void *)mouse_pick; + info_textview_main__internal(sinfo, ar, reports, 0, mval, &mouse_pick, NULL); + return (void *)mouse_pick; } - int info_textview_height(struct SpaceInfo *sinfo, ARegion *ar, ReportList *reports) { - int mval[2] = {INT_MAX, INT_MAX}; - return info_textview_main__internal(sinfo, ar, reports, 0, mval, NULL, NULL); + int mval[2] = {INT_MAX, INT_MAX}; + return info_textview_main__internal(sinfo, ar, reports, 0, mval, NULL, NULL); } void info_textview_main(struct SpaceInfo *sinfo, ARegion *ar, ReportList *reports) { - int mval[2] = {INT_MAX, INT_MAX}; - info_textview_main__internal(sinfo, ar, reports, 1, mval, NULL, NULL); + int mval[2] = {INT_MAX, INT_MAX}; + info_textview_main__internal(sinfo, ar, reports, 1, mval, NULL, NULL); } diff --git a/source/blender/editors/space_info/info_intern.h b/source/blender/editors/space_info/info_intern.h index 7903a462ce1..7d4d6e5ab90 100644 --- a/source/blender/editors/space_info/info_intern.h +++ b/source/blender/editors/space_info/info_intern.h @@ -42,11 +42,13 @@ void FILE_OT_make_paths_absolute(struct wmOperatorType *ot); void FILE_OT_report_missing_files(struct wmOperatorType *ot); 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, struct ARegion *ar, ReportList *reports, int mouse_y); +void *info_text_pick(struct SpaceInfo *sinfo, + struct ARegion *ar, + ReportList *reports, + int mouse_y); int info_textview_height(struct SpaceInfo *sinfo, struct ARegion *ar, struct ReportList *reports); void info_textview_main(struct SpaceInfo *sinfo, struct ARegion *ar, struct ReportList *reports); diff --git a/source/blender/editors/space_info/info_ops.c b/source/blender/editors/space_info/info_ops.c index 0abad05cc76..171d8505222 100644 --- a/source/blender/editors/space_info/info_ops.c +++ b/source/blender/editors/space_info/info_ops.c @@ -21,7 +21,6 @@ * \ingroup spinfo */ - #include <string.h> #include <stdio.h> @@ -47,11 +46,9 @@ #include "BKE_report.h" #include "BKE_screen.h" - #include "WM_api.h" #include "WM_types.h" - #include "UI_interface.h" #include "UI_resources.h" @@ -60,432 +57,473 @@ #include "RNA_access.h" #include "RNA_define.h" - #include "info_intern.h" /********************* pack blend file libraries operator *********************/ static int pack_libraries_exec(bContext *C, wmOperator *op) { - Main *bmain = CTX_data_main(C); + Main *bmain = CTX_data_main(C); - packLibraries(bmain, op->reports); + packLibraries(bmain, op->reports); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void FILE_OT_pack_libraries(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Pack Blender Libraries"; - ot->idname = "FILE_OT_pack_libraries"; - ot->description = "Pack all used Blender library files into the current .blend"; + /* identifiers */ + ot->name = "Pack Blender Libraries"; + ot->idname = "FILE_OT_pack_libraries"; + ot->description = "Pack all used Blender library files into the current .blend"; - /* api callbacks */ - ot->exec = pack_libraries_exec; + /* api callbacks */ + ot->exec = pack_libraries_exec; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } static int unpack_libraries_exec(bContext *C, wmOperator *op) { - Main *bmain = CTX_data_main(C); + Main *bmain = CTX_data_main(C); - unpackLibraries(bmain, op->reports); + unpackLibraries(bmain, op->reports); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } static int unpack_libraries_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - return WM_operator_confirm_message(C, op, "Unpack Blender Libraries - creates directories, all new paths should work"); + return WM_operator_confirm_message( + C, op, "Unpack Blender Libraries - creates directories, all new paths should work"); } void FILE_OT_unpack_libraries(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Unpack Blender Libraries"; - ot->idname = "FILE_OT_unpack_libraries"; - ot->description = "Unpack all used Blender library files from this .blend file"; + /* identifiers */ + ot->name = "Unpack Blender Libraries"; + ot->idname = "FILE_OT_unpack_libraries"; + ot->description = "Unpack all used Blender library files from this .blend file"; - /* api callbacks */ - ot->invoke = unpack_libraries_invoke; - ot->exec = unpack_libraries_exec; + /* api callbacks */ + ot->invoke = unpack_libraries_invoke; + ot->exec = unpack_libraries_exec; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /********************* toggle auto-pack operator *********************/ static int autopack_toggle_exec(bContext *C, wmOperator *op) { - Main *bmain = CTX_data_main(C); + Main *bmain = CTX_data_main(C); - if (G.fileflags & G_FILE_AUTOPACK) { - G.fileflags &= ~G_FILE_AUTOPACK; - } - else { - packAll(bmain, op->reports, true); - G.fileflags |= G_FILE_AUTOPACK; - } + if (G.fileflags & G_FILE_AUTOPACK) { + G.fileflags &= ~G_FILE_AUTOPACK; + } + else { + packAll(bmain, op->reports, true); + G.fileflags |= G_FILE_AUTOPACK; + } - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void FILE_OT_autopack_toggle(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Automatically Pack Into .blend"; - ot->idname = "FILE_OT_autopack_toggle"; - ot->description = "Automatically pack all external files into the .blend file"; + /* identifiers */ + ot->name = "Automatically Pack Into .blend"; + ot->idname = "FILE_OT_autopack_toggle"; + ot->description = "Automatically pack all external files into the .blend file"; - /* api callbacks */ - ot->exec = autopack_toggle_exec; + /* api callbacks */ + ot->exec = autopack_toggle_exec; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /********************* pack all operator *********************/ static int pack_all_exec(bContext *C, wmOperator *op) { - Main *bmain = CTX_data_main(C); + Main *bmain = CTX_data_main(C); - packAll(bmain, op->reports, true); + packAll(bmain, op->reports, true); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } static int pack_all_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - Main *bmain = CTX_data_main(C); - Image *ima; - ImBuf *ibuf; - - // first check for dirty images - for (ima = bmain->images.first; ima; ima = ima->id.next) { - if (BKE_image_has_loaded_ibuf(ima)) { /* XXX FIX */ - ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL); - - if (ibuf && (ibuf->userflags & IB_BITMAPDIRTY)) { - BKE_image_release_ibuf(ima, ibuf, NULL); - break; - } - - BKE_image_release_ibuf(ima, ibuf, NULL); - } - } - - if (ima) { - return WM_operator_confirm_message(C, op, "Some images are painted on. These changes will be lost. Continue?"); - } - - return pack_all_exec(C, op); + Main *bmain = CTX_data_main(C); + Image *ima; + ImBuf *ibuf; + + // first check for dirty images + for (ima = bmain->images.first; ima; ima = ima->id.next) { + if (BKE_image_has_loaded_ibuf(ima)) { /* XXX FIX */ + ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL); + + if (ibuf && (ibuf->userflags & IB_BITMAPDIRTY)) { + BKE_image_release_ibuf(ima, ibuf, NULL); + break; + } + + BKE_image_release_ibuf(ima, ibuf, NULL); + } + } + + if (ima) { + return WM_operator_confirm_message( + C, op, "Some images are painted on. These changes will be lost. Continue?"); + } + + return pack_all_exec(C, op); } void FILE_OT_pack_all(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Pack All Into .blend"; - ot->idname = "FILE_OT_pack_all"; - ot->description = "Pack all used external files into the .blend"; + /* identifiers */ + ot->name = "Pack All Into .blend"; + ot->idname = "FILE_OT_pack_all"; + ot->description = "Pack all used external files into the .blend"; - /* api callbacks */ - ot->exec = pack_all_exec; - ot->invoke = pack_all_invoke; + /* api callbacks */ + ot->exec = pack_all_exec; + ot->invoke = pack_all_invoke; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } - /********************* unpack all operator *********************/ static const EnumPropertyItem unpack_all_method_items[] = { - {PF_USE_LOCAL, "USE_LOCAL", 0, "Use files in current directory (create when necessary)", ""}, - {PF_WRITE_LOCAL, "WRITE_LOCAL", 0, "Write files to current directory (overwrite existing files)", ""}, - {PF_USE_ORIGINAL, "USE_ORIGINAL", 0, "Use files in original location (create when necessary)", ""}, - {PF_WRITE_ORIGINAL, "WRITE_ORIGINAL", 0, "Write files to original location (overwrite existing files)", ""}, - {PF_KEEP, "KEEP", 0, "Disable Auto-pack, keep all packed files", ""}, - /* {PF_ASK, "ASK", 0, "Ask for each file", ""}, */ - {0, NULL, 0, NULL, NULL}, + {PF_USE_LOCAL, "USE_LOCAL", 0, "Use files in current directory (create when necessary)", ""}, + {PF_WRITE_LOCAL, + "WRITE_LOCAL", + 0, + "Write files to current directory (overwrite existing files)", + ""}, + {PF_USE_ORIGINAL, + "USE_ORIGINAL", + 0, + "Use files in original location (create when necessary)", + ""}, + {PF_WRITE_ORIGINAL, + "WRITE_ORIGINAL", + 0, + "Write files to original location (overwrite existing files)", + ""}, + {PF_KEEP, "KEEP", 0, "Disable Auto-pack, keep all packed files", ""}, + /* {PF_ASK, "ASK", 0, "Ask for each file", ""}, */ + {0, NULL, 0, NULL, NULL}, }; static int unpack_all_exec(bContext *C, wmOperator *op) { - Main *bmain = CTX_data_main(C); - int method = RNA_enum_get(op->ptr, "method"); + Main *bmain = CTX_data_main(C); + int method = RNA_enum_get(op->ptr, "method"); - if (method != PF_KEEP) { - unpackAll(bmain, op->reports, method); /* XXX PF_ASK can't work here */ - } - G.fileflags &= ~G_FILE_AUTOPACK; + if (method != PF_KEEP) { + unpackAll(bmain, op->reports, method); /* XXX PF_ASK can't work here */ + } + G.fileflags &= ~G_FILE_AUTOPACK; - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } static int unpack_all_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - Main *bmain = CTX_data_main(C); - uiPopupMenu *pup; - uiLayout *layout; - char title[64]; - int count = 0; + Main *bmain = CTX_data_main(C); + uiPopupMenu *pup; + uiLayout *layout; + char title[64]; + int count = 0; - count = countPackedFiles(bmain); + count = countPackedFiles(bmain); - if (!count) { - BKE_report(op->reports, RPT_WARNING, "No packed files to unpack"); - G.fileflags &= ~G_FILE_AUTOPACK; - return OPERATOR_CANCELLED; - } + if (!count) { + BKE_report(op->reports, RPT_WARNING, "No packed files to unpack"); + G.fileflags &= ~G_FILE_AUTOPACK; + return OPERATOR_CANCELLED; + } - if (count == 1) { - BLI_strncpy(title, IFACE_("Unpack 1 File"), sizeof(title)); - } - else { - BLI_snprintf(title, sizeof(title), IFACE_("Unpack %d Files"), count); - } + if (count == 1) { + BLI_strncpy(title, IFACE_("Unpack 1 File"), sizeof(title)); + } + else { + BLI_snprintf(title, sizeof(title), IFACE_("Unpack %d Files"), count); + } - pup = UI_popup_menu_begin(C, title, ICON_NONE); - layout = UI_popup_menu_layout(pup); + pup = UI_popup_menu_begin(C, title, ICON_NONE); + layout = UI_popup_menu_layout(pup); - uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT); - uiItemsEnumO(layout, "FILE_OT_unpack_all", "method"); + uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT); + uiItemsEnumO(layout, "FILE_OT_unpack_all", "method"); - UI_popup_menu_end(C, pup); + UI_popup_menu_end(C, pup); - return OPERATOR_INTERFACE; + return OPERATOR_INTERFACE; } void FILE_OT_unpack_all(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Unpack All Into Files"; - ot->idname = "FILE_OT_unpack_all"; - ot->description = "Unpack all files packed into this .blend to external ones"; + /* identifiers */ + ot->name = "Unpack All Into Files"; + ot->idname = "FILE_OT_unpack_all"; + ot->description = "Unpack all files packed into this .blend to external ones"; - /* api callbacks */ - ot->exec = unpack_all_exec; - ot->invoke = unpack_all_invoke; + /* api callbacks */ + ot->exec = unpack_all_exec; + ot->invoke = unpack_all_invoke; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - /* properties */ - RNA_def_enum(ot->srna, "method", unpack_all_method_items, PF_USE_LOCAL, "Method", "How to unpack"); + /* properties */ + RNA_def_enum( + ot->srna, "method", unpack_all_method_items, PF_USE_LOCAL, "Method", "How to unpack"); } /********************* unpack single item operator *********************/ static const EnumPropertyItem unpack_item_method_items[] = { - {PF_USE_LOCAL, "USE_LOCAL", 0, "Use file from current directory (create when necessary)", ""}, - {PF_WRITE_LOCAL, "WRITE_LOCAL", 0, "Write file to current directory (overwrite existing file)", ""}, - {PF_USE_ORIGINAL, "USE_ORIGINAL", 0, "Use file in original location (create when necessary)", ""}, - {PF_WRITE_ORIGINAL, "WRITE_ORIGINAL", 0, "Write file to original location (overwrite existing file)", ""}, - /* {PF_ASK, "ASK", 0, "Ask for each file", ""}, */ - {0, NULL, 0, NULL, NULL}, + {PF_USE_LOCAL, "USE_LOCAL", 0, "Use file from current directory (create when necessary)", ""}, + {PF_WRITE_LOCAL, + "WRITE_LOCAL", + 0, + "Write file to current directory (overwrite existing file)", + ""}, + {PF_USE_ORIGINAL, + "USE_ORIGINAL", + 0, + "Use file in original location (create when necessary)", + ""}, + {PF_WRITE_ORIGINAL, + "WRITE_ORIGINAL", + 0, + "Write file to original location (overwrite existing file)", + ""}, + /* {PF_ASK, "ASK", 0, "Ask for each file", ""}, */ + {0, NULL, 0, NULL, NULL}, }; - static int unpack_item_exec(bContext *C, wmOperator *op) { - Main *bmain = CTX_data_main(C); - ID *id; - char idname[MAX_ID_NAME - 2]; - int type = RNA_int_get(op->ptr, "id_type"); - int method = RNA_enum_get(op->ptr, "method"); + Main *bmain = CTX_data_main(C); + ID *id; + char idname[MAX_ID_NAME - 2]; + int type = RNA_int_get(op->ptr, "id_type"); + int method = RNA_enum_get(op->ptr, "method"); - RNA_string_get(op->ptr, "id_name", idname); - id = BKE_libblock_find_name(bmain, type, idname); + RNA_string_get(op->ptr, "id_name", idname); + id = BKE_libblock_find_name(bmain, type, idname); - if (id == NULL) { - BKE_report(op->reports, RPT_WARNING, "No packed file"); - return OPERATOR_CANCELLED; - } + if (id == NULL) { + BKE_report(op->reports, RPT_WARNING, "No packed file"); + return OPERATOR_CANCELLED; + } - if (method != PF_KEEP) { - BKE_unpack_id(bmain, id, op->reports, method); /* XXX PF_ASK can't work here */ - } + if (method != PF_KEEP) { + BKE_unpack_id(bmain, id, op->reports, method); /* XXX PF_ASK can't work here */ + } - G.fileflags &= ~G_FILE_AUTOPACK; + G.fileflags &= ~G_FILE_AUTOPACK; - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } static int unpack_item_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - uiPopupMenu *pup; - uiLayout *layout; + uiPopupMenu *pup; + uiLayout *layout; - pup = UI_popup_menu_begin(C, IFACE_("Unpack"), ICON_NONE); - layout = UI_popup_menu_layout(pup); + pup = UI_popup_menu_begin(C, IFACE_("Unpack"), ICON_NONE); + layout = UI_popup_menu_layout(pup); - uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT); - uiItemsFullEnumO(layout, op->type->idname, "method", op->ptr->data, WM_OP_EXEC_REGION_WIN, 0); + uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT); + uiItemsFullEnumO(layout, op->type->idname, "method", op->ptr->data, WM_OP_EXEC_REGION_WIN, 0); - UI_popup_menu_end(C, pup); + UI_popup_menu_end(C, pup); - return OPERATOR_INTERFACE; + return OPERATOR_INTERFACE; } void FILE_OT_unpack_item(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Unpack Item"; - ot->idname = "FILE_OT_unpack_item"; - ot->description = "Unpack this file to an external file"; - - /* api callbacks */ - ot->exec = unpack_item_exec; - ot->invoke = unpack_item_invoke; - - /* flags */ - ot->flag = OPTYPE_UNDO; - - /* properties */ - RNA_def_enum(ot->srna, "method", unpack_item_method_items, PF_USE_LOCAL, "Method", "How to unpack"); - RNA_def_string(ot->srna, "id_name", NULL, BKE_ST_MAXNAME, "ID name", "Name of ID block to unpack"); - RNA_def_int(ot->srna, "id_type", ID_IM, 0, INT_MAX, "ID Type", "Identifier type of ID block", 0, INT_MAX); + /* identifiers */ + ot->name = "Unpack Item"; + ot->idname = "FILE_OT_unpack_item"; + ot->description = "Unpack this file to an external file"; + + /* api callbacks */ + ot->exec = unpack_item_exec; + ot->invoke = unpack_item_invoke; + + /* flags */ + ot->flag = OPTYPE_UNDO; + + /* properties */ + RNA_def_enum( + ot->srna, "method", unpack_item_method_items, PF_USE_LOCAL, "Method", "How to unpack"); + RNA_def_string( + ot->srna, "id_name", NULL, BKE_ST_MAXNAME, "ID name", "Name of ID block to unpack"); + RNA_def_int(ot->srna, + "id_type", + ID_IM, + 0, + INT_MAX, + "ID Type", + "Identifier type of ID block", + 0, + INT_MAX); } - /********************* make paths relative operator *********************/ static int make_paths_relative_exec(bContext *C, wmOperator *op) { - Main *bmain = CTX_data_main(C); + Main *bmain = CTX_data_main(C); - if (!G.relbase_valid) { - BKE_report(op->reports, RPT_WARNING, "Cannot set relative paths with an unsaved blend file"); - return OPERATOR_CANCELLED; - } + if (!G.relbase_valid) { + BKE_report(op->reports, RPT_WARNING, "Cannot set relative paths with an unsaved blend file"); + return OPERATOR_CANCELLED; + } - BKE_bpath_relative_convert(bmain, BKE_main_blendfile_path(bmain), op->reports); + BKE_bpath_relative_convert(bmain, BKE_main_blendfile_path(bmain), op->reports); - /* redraw everything so any changed paths register */ - WM_main_add_notifier(NC_WINDOW, NULL); + /* redraw everything so any changed paths register */ + WM_main_add_notifier(NC_WINDOW, NULL); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void FILE_OT_make_paths_relative(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Make All Paths Relative"; - ot->idname = "FILE_OT_make_paths_relative"; - ot->description = "Make all paths to external files relative to current .blend"; + /* identifiers */ + ot->name = "Make All Paths Relative"; + ot->idname = "FILE_OT_make_paths_relative"; + ot->description = "Make all paths to external files relative to current .blend"; - /* api callbacks */ - ot->exec = make_paths_relative_exec; + /* api callbacks */ + ot->exec = make_paths_relative_exec; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /********************* make paths absolute operator *********************/ static int make_paths_absolute_exec(bContext *C, wmOperator *op) { - Main *bmain = CTX_data_main(C); + Main *bmain = CTX_data_main(C); - if (!G.relbase_valid) { - BKE_report(op->reports, RPT_WARNING, "Cannot set absolute paths with an unsaved blend file"); - return OPERATOR_CANCELLED; - } + if (!G.relbase_valid) { + BKE_report(op->reports, RPT_WARNING, "Cannot set absolute paths with an unsaved blend file"); + return OPERATOR_CANCELLED; + } - BKE_bpath_absolute_convert(bmain, BKE_main_blendfile_path(bmain), op->reports); + BKE_bpath_absolute_convert(bmain, BKE_main_blendfile_path(bmain), op->reports); - /* redraw everything so any changed paths register */ - WM_main_add_notifier(NC_WINDOW, NULL); + /* redraw everything so any changed paths register */ + WM_main_add_notifier(NC_WINDOW, NULL); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void FILE_OT_make_paths_absolute(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Make All Paths Absolute"; - ot->idname = "FILE_OT_make_paths_absolute"; - ot->description = "Make all paths to external files absolute"; + /* identifiers */ + ot->name = "Make All Paths Absolute"; + ot->idname = "FILE_OT_make_paths_absolute"; + ot->description = "Make all paths to external files absolute"; - /* api callbacks */ - ot->exec = make_paths_absolute_exec; + /* api callbacks */ + ot->exec = make_paths_absolute_exec; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /********************* report missing files operator *********************/ static int report_missing_files_exec(bContext *C, wmOperator *op) { - Main *bmain = CTX_data_main(C); + Main *bmain = CTX_data_main(C); - /* run the missing file check */ - BKE_bpath_missing_files_check(bmain, op->reports); + /* run the missing file check */ + BKE_bpath_missing_files_check(bmain, op->reports); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void FILE_OT_report_missing_files(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Report Missing Files"; - ot->idname = "FILE_OT_report_missing_files"; - ot->description = "Report all missing external files"; + /* identifiers */ + ot->name = "Report Missing Files"; + ot->idname = "FILE_OT_report_missing_files"; + ot->description = "Report all missing external files"; - /* api callbacks */ - ot->exec = report_missing_files_exec; + /* api callbacks */ + ot->exec = report_missing_files_exec; - /* flags */ - ot->flag = 0; /* only reports so no need to undo/register */ + /* flags */ + ot->flag = 0; /* only reports so no need to undo/register */ } /********************* find missing files operator *********************/ static int find_missing_files_exec(bContext *C, wmOperator *op) { - Main *bmain = CTX_data_main(C); - const char *searchpath = RNA_string_get_alloc(op->ptr, "directory", NULL, 0); - const bool find_all = RNA_boolean_get(op->ptr, "find_all"); + Main *bmain = CTX_data_main(C); + const char *searchpath = RNA_string_get_alloc(op->ptr, "directory", NULL, 0); + const bool find_all = RNA_boolean_get(op->ptr, "find_all"); - BKE_bpath_missing_files_find(bmain, searchpath, op->reports, find_all); - MEM_freeN((void *)searchpath); + BKE_bpath_missing_files_find(bmain, searchpath, op->reports, find_all); + MEM_freeN((void *)searchpath); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } static int find_missing_files_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - /* XXX file open button text "Find Missing Files" */ - WM_event_add_fileselect(C, op); - return OPERATOR_RUNNING_MODAL; + /* XXX file open button text "Find Missing Files" */ + WM_event_add_fileselect(C, op); + return OPERATOR_RUNNING_MODAL; } void FILE_OT_find_missing_files(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Find Missing Files"; - ot->idname = "FILE_OT_find_missing_files"; - ot->description = "Try to find missing external files"; - - /* api callbacks */ - ot->exec = find_missing_files_exec; - ot->invoke = find_missing_files_invoke; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - /* properties */ - RNA_def_boolean(ot->srna, "find_all", false, "Find All", "Find all files in the search path (not just missing)"); - - WM_operator_properties_filesel( - ot, 0, FILE_SPECIAL, FILE_OPENFILE, - WM_FILESEL_DIRECTORY, FILE_DEFAULTDISPLAY, FILE_SORT_ALPHA); + /* identifiers */ + ot->name = "Find Missing Files"; + ot->idname = "FILE_OT_find_missing_files"; + ot->description = "Try to find missing external files"; + + /* api callbacks */ + ot->exec = find_missing_files_exec; + ot->invoke = find_missing_files_invoke; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + /* properties */ + RNA_def_boolean(ot->srna, + "find_all", + false, + "Find All", + "Find all files in the search path (not just missing)"); + + WM_operator_properties_filesel(ot, + 0, + FILE_SPECIAL, + FILE_OPENFILE, + WM_FILESEL_DIRECTORY, + FILE_DEFAULTDISPLAY, + FILE_SORT_ALPHA); } /********************* report box operator *********************/ @@ -497,108 +535,106 @@ void FILE_OT_find_missing_files(wmOperatorType *ot) * inactive regions, so use this for now. --matt */ -#define INFO_TIMEOUT 5.0f -#define ERROR_TIMEOUT 10.0f -#define FLASH_TIMEOUT 1.0f -#define COLLAPSE_TIMEOUT 0.25f -#define BRIGHTEN_AMOUNT 0.1f +#define INFO_TIMEOUT 5.0f +#define ERROR_TIMEOUT 10.0f +#define FLASH_TIMEOUT 1.0f +#define COLLAPSE_TIMEOUT 0.25f +#define BRIGHTEN_AMOUNT 0.1f static int update_reports_display_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event) { - wmWindowManager *wm = CTX_wm_manager(C); - ReportList *reports = CTX_wm_reports(C); - Report *report; - ReportTimerInfo *rti; - float target_col[4] = {0.0f, 0.0f, 0.0f, 0.0f}; - float progress = 0.0, flash_progress = 0.0; - float timeout = 0.0, flash_timeout = FLASH_TIMEOUT; - int send_note = 0; - - /* escape if not our timer */ - if ((reports->reporttimer == NULL) || - (reports->reporttimer != event->customdata) || - ((report = BKE_reports_last_displayable(reports)) == NULL) /* may have been deleted */ - ) - { - return OPERATOR_PASS_THROUGH; - } - - rti = (ReportTimerInfo *)reports->reporttimer->customdata; - - timeout = (report->type & RPT_ERROR_ALL) ? ERROR_TIMEOUT : INFO_TIMEOUT; - - /* clear the report display after timeout */ - if ((float)reports->reporttimer->duration > timeout) { - WM_event_remove_timer(wm, NULL, reports->reporttimer); - reports->reporttimer = NULL; - - WM_event_add_notifier(C, NC_SPACE | ND_SPACE_INFO, NULL); - - return (OPERATOR_FINISHED | OPERATOR_PASS_THROUGH); - } - - /* set target color based on report type */ - if (report->type & RPT_ERROR_ALL) { - UI_GetThemeColorType3fv(TH_INFO_ERROR, SPACE_INFO, target_col); - } - else if (report->type & RPT_WARNING_ALL) { - UI_GetThemeColorType3fv(TH_INFO_WARNING, SPACE_INFO, target_col); - } - else if (report->type & RPT_INFO_ALL) { - UI_GetThemeColorType3fv(TH_INFO_INFO, SPACE_INFO, target_col); - } - target_col[3] = 0.65f; - - if (rti->widthfac == 0.0f) { - /* initialize color to a brighter shade of the target color */ - rti->col[0] = target_col[0] + BRIGHTEN_AMOUNT; - rti->col[1] = target_col[1] + BRIGHTEN_AMOUNT; - rti->col[2] = target_col[2] + BRIGHTEN_AMOUNT; - rti->col[3] = 1.0f; - - CLAMP3(rti->col, 0.0, 1.0); - - rti->widthfac = 1.0f; - } - - progress = powf((float)reports->reporttimer->duration / timeout, 2.0f); - flash_progress = powf((float)reports->reporttimer->duration / flash_timeout, 2.0); - - /* save us from too many draws */ - if (flash_progress <= 1.0f) { - send_note = 1; - - /* flash report briefly according to progress through fade-out duration */ - interp_v4_v4v4(rti->col, rti->col, target_col, flash_progress); - } - - /* collapse report at end of timeout */ - if (progress * timeout > timeout - COLLAPSE_TIMEOUT) { - rti->widthfac = (progress * timeout - (timeout - COLLAPSE_TIMEOUT)) / COLLAPSE_TIMEOUT; - rti->widthfac = 1.0f - rti->widthfac; - send_note = 1; - } - - if (send_note) { - WM_event_add_notifier(C, NC_SPACE | ND_SPACE_INFO, NULL); - } - - return (OPERATOR_FINISHED | OPERATOR_PASS_THROUGH); + wmWindowManager *wm = CTX_wm_manager(C); + ReportList *reports = CTX_wm_reports(C); + Report *report; + ReportTimerInfo *rti; + float target_col[4] = {0.0f, 0.0f, 0.0f, 0.0f}; + float progress = 0.0, flash_progress = 0.0; + float timeout = 0.0, flash_timeout = FLASH_TIMEOUT; + int send_note = 0; + + /* escape if not our timer */ + if ((reports->reporttimer == NULL) || (reports->reporttimer != event->customdata) || + ((report = BKE_reports_last_displayable(reports)) == NULL) /* may have been deleted */ + ) { + return OPERATOR_PASS_THROUGH; + } + + rti = (ReportTimerInfo *)reports->reporttimer->customdata; + + timeout = (report->type & RPT_ERROR_ALL) ? ERROR_TIMEOUT : INFO_TIMEOUT; + + /* clear the report display after timeout */ + if ((float)reports->reporttimer->duration > timeout) { + WM_event_remove_timer(wm, NULL, reports->reporttimer); + reports->reporttimer = NULL; + + WM_event_add_notifier(C, NC_SPACE | ND_SPACE_INFO, NULL); + + return (OPERATOR_FINISHED | OPERATOR_PASS_THROUGH); + } + + /* set target color based on report type */ + if (report->type & RPT_ERROR_ALL) { + UI_GetThemeColorType3fv(TH_INFO_ERROR, SPACE_INFO, target_col); + } + else if (report->type & RPT_WARNING_ALL) { + UI_GetThemeColorType3fv(TH_INFO_WARNING, SPACE_INFO, target_col); + } + else if (report->type & RPT_INFO_ALL) { + UI_GetThemeColorType3fv(TH_INFO_INFO, SPACE_INFO, target_col); + } + target_col[3] = 0.65f; + + if (rti->widthfac == 0.0f) { + /* initialize color to a brighter shade of the target color */ + rti->col[0] = target_col[0] + BRIGHTEN_AMOUNT; + rti->col[1] = target_col[1] + BRIGHTEN_AMOUNT; + rti->col[2] = target_col[2] + BRIGHTEN_AMOUNT; + rti->col[3] = 1.0f; + + CLAMP3(rti->col, 0.0, 1.0); + + rti->widthfac = 1.0f; + } + + progress = powf((float)reports->reporttimer->duration / timeout, 2.0f); + flash_progress = powf((float)reports->reporttimer->duration / flash_timeout, 2.0); + + /* save us from too many draws */ + if (flash_progress <= 1.0f) { + send_note = 1; + + /* flash report briefly according to progress through fade-out duration */ + interp_v4_v4v4(rti->col, rti->col, target_col, flash_progress); + } + + /* collapse report at end of timeout */ + if (progress * timeout > timeout - COLLAPSE_TIMEOUT) { + rti->widthfac = (progress * timeout - (timeout - COLLAPSE_TIMEOUT)) / COLLAPSE_TIMEOUT; + rti->widthfac = 1.0f - rti->widthfac; + send_note = 1; + } + + if (send_note) { + WM_event_add_notifier(C, NC_SPACE | ND_SPACE_INFO, NULL); + } + + return (OPERATOR_FINISHED | OPERATOR_PASS_THROUGH); } void INFO_OT_reports_display_update(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Update Reports Display"; - ot->idname = "INFO_OT_reports_display_update"; - ot->description = "Update the display of reports in Blender UI (internal use)"; + /* identifiers */ + ot->name = "Update Reports Display"; + ot->idname = "INFO_OT_reports_display_update"; + ot->description = "Update the display of reports in Blender UI (internal use)"; - /* api callbacks */ - ot->invoke = update_reports_display_invoke; + /* api callbacks */ + ot->invoke = update_reports_display_invoke; - /* flags */ - ot->flag = 0; + /* flags */ + ot->flag = 0; - /* properties */ + /* properties */ } /* report operators */ diff --git a/source/blender/editors/space_info/info_report.c b/source/blender/editors/space_info/info_report.c index e4202483574..707838cf7e5 100644 --- a/source/blender/editors/space_info/info_report.c +++ b/source/blender/editors/space_info/info_report.c @@ -18,7 +18,6 @@ * \ingroup spinfo */ - #include <stdlib.h> #include <string.h> #include <limits.h> @@ -45,346 +44,344 @@ int info_report_mask(SpaceInfo *UNUSED(sinfo)) { #if 0 - int report_mask = 0; + int report_mask = 0; - if (sinfo->rpt_mask & INFO_RPT_DEBUG) report_mask |= RPT_DEBUG_ALL; - if (sinfo->rpt_mask & INFO_RPT_INFO) report_mask |= RPT_INFO_ALL; - if (sinfo->rpt_mask & INFO_RPT_OP) report_mask |= RPT_OPERATOR_ALL; - if (sinfo->rpt_mask & INFO_RPT_WARN) report_mask |= RPT_WARNING_ALL; - if (sinfo->rpt_mask & INFO_RPT_ERR) report_mask |= RPT_ERROR_ALL; + if (sinfo->rpt_mask & INFO_RPT_DEBUG) report_mask |= RPT_DEBUG_ALL; + if (sinfo->rpt_mask & INFO_RPT_INFO) report_mask |= RPT_INFO_ALL; + if (sinfo->rpt_mask & INFO_RPT_OP) report_mask |= RPT_OPERATOR_ALL; + if (sinfo->rpt_mask & INFO_RPT_WARN) report_mask |= RPT_WARNING_ALL; + if (sinfo->rpt_mask & INFO_RPT_ERR) report_mask |= RPT_ERROR_ALL; - return report_mask; + return report_mask; #endif - return RPT_DEBUG_ALL | RPT_INFO_ALL | RPT_OPERATOR_ALL | RPT_PROPERTY_ALL | RPT_WARNING_ALL | RPT_ERROR_ALL; + return RPT_DEBUG_ALL | RPT_INFO_ALL | RPT_OPERATOR_ALL | RPT_PROPERTY_ALL | RPT_WARNING_ALL | + RPT_ERROR_ALL; } // TODO, get this working again! static int report_replay_exec(bContext *C, wmOperator *UNUSED(op)) { -// SpaceInfo *sc = CTX_wm_space_info(C); -// ReportList *reports = CTX_wm_reports(C); -// int report_mask = info_report_mask(sc); -// Report *report; + // SpaceInfo *sc = CTX_wm_space_info(C); + // ReportList *reports = CTX_wm_reports(C); + // int report_mask = info_report_mask(sc); + // Report *report; #if 0 - sc->type = CONSOLE_TYPE_PYTHON; + sc->type = CONSOLE_TYPE_PYTHON; - for (report = reports->list.last; report; report = report->prev) { - if ((report->type & report_mask) && - (report->type & RPT_OPERATOR_ALL | RPT_PROPERTY_ALL) && - (report->flag & SELECT)) - { - console_history_add_str(sc, report->message, 0); - WM_operator_name_call(C, "CONSOLE_OT_execute", WM_OP_EXEC_DEFAULT, NULL); + for (report = reports->list.last; report; report = report->prev) { + if ((report->type & report_mask) && + (report->type & RPT_OPERATOR_ALL | RPT_PROPERTY_ALL) && + (report->flag & SELECT)) + { + console_history_add_str(sc, report->message, 0); + WM_operator_name_call(C, "CONSOLE_OT_execute", WM_OP_EXEC_DEFAULT, NULL); - ED_area_tag_redraw(CTX_wm_area(C)); - } - } + ED_area_tag_redraw(CTX_wm_area(C)); + } + } - sc->type = CONSOLE_TYPE_REPORT; + sc->type = CONSOLE_TYPE_REPORT; #endif - ED_area_tag_redraw(CTX_wm_area(C)); + ED_area_tag_redraw(CTX_wm_area(C)); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void INFO_OT_report_replay(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Replay Operators"; - ot->description = "Replay selected reports"; - ot->idname = "INFO_OT_report_replay"; + /* identifiers */ + ot->name = "Replay Operators"; + ot->description = "Replay selected reports"; + ot->idname = "INFO_OT_report_replay"; - /* api callbacks */ - ot->poll = ED_operator_info_active; - ot->exec = report_replay_exec; + /* api callbacks */ + ot->poll = ED_operator_info_active; + ot->exec = report_replay_exec; - /* flags */ - /* ot->flag = OPTYPE_REGISTER; */ + /* flags */ + /* ot->flag = OPTYPE_REGISTER; */ - /* properties */ + /* properties */ } static int select_report_pick_exec(bContext *C, wmOperator *op) { - int report_index = RNA_int_get(op->ptr, "report_index"); - Report *report = BLI_findlink(&CTX_wm_reports(C)->list, report_index); + int report_index = RNA_int_get(op->ptr, "report_index"); + Report *report = BLI_findlink(&CTX_wm_reports(C)->list, report_index); - if (!report) { - return OPERATOR_CANCELLED; - } + if (!report) { + return OPERATOR_CANCELLED; + } - report->flag ^= SELECT; /* toggle */ + report->flag ^= SELECT; /* toggle */ - ED_area_tag_redraw(CTX_wm_area(C)); + ED_area_tag_redraw(CTX_wm_area(C)); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } static int select_report_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - SpaceInfo *sinfo = CTX_wm_space_info(C); - ARegion *ar = CTX_wm_region(C); - ReportList *reports = CTX_wm_reports(C); - Report *report; + SpaceInfo *sinfo = CTX_wm_space_info(C); + ARegion *ar = CTX_wm_region(C); + ReportList *reports = CTX_wm_reports(C); + Report *report; - report = info_text_pick(sinfo, ar, reports, event->mval[1]); + report = info_text_pick(sinfo, ar, reports, event->mval[1]); - RNA_int_set(op->ptr, "report_index", BLI_findindex(&reports->list, report)); + RNA_int_set(op->ptr, "report_index", BLI_findindex(&reports->list, report)); - return select_report_pick_exec(C, op); + return select_report_pick_exec(C, op); } - void INFO_OT_select_pick(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Select Report"; - ot->description = "Select reports by index"; - ot->idname = "INFO_OT_select_pick"; - - /* api callbacks */ - ot->poll = ED_operator_info_active; - ot->invoke = select_report_pick_invoke; - ot->exec = select_report_pick_exec; - - /* flags */ - /* ot->flag = OPTYPE_REGISTER; */ - - /* properties */ - RNA_def_int(ot->srna, "report_index", 0, 0, INT_MAX, "Report", "Index of the report", 0, INT_MAX); + /* identifiers */ + ot->name = "Select Report"; + ot->description = "Select reports by index"; + ot->idname = "INFO_OT_select_pick"; + + /* api callbacks */ + ot->poll = ED_operator_info_active; + ot->invoke = select_report_pick_invoke; + ot->exec = select_report_pick_exec; + + /* flags */ + /* ot->flag = OPTYPE_REGISTER; */ + + /* properties */ + RNA_def_int( + ot->srna, "report_index", 0, 0, INT_MAX, "Report", "Index of the report", 0, INT_MAX); } static int report_select_all_exec(bContext *C, wmOperator *op) { - SpaceInfo *sinfo = CTX_wm_space_info(C); - ReportList *reports = CTX_wm_reports(C); - const int report_mask = info_report_mask(sinfo); - - int action = RNA_enum_get(op->ptr, "action"); - - if (action == SEL_TOGGLE) { - action = SEL_SELECT; - for (Report *report = reports->list.last; report; report = report->prev) { - if ((report->type & report_mask) && (report->flag & SELECT)) { - action = SEL_DESELECT; - break; - } - } - } - - for (Report *report = reports->list.last; report; report = report->prev) { - if (report->type & report_mask) { - switch (action) { - case SEL_SELECT: - report->flag = SELECT; - break; - case SEL_DESELECT: - report->flag = ~SELECT; - break; - case SEL_INVERT: - report->flag ^= SELECT; - break; - default: - BLI_assert(0); - } - } - } - - ED_area_tag_redraw(CTX_wm_area(C)); - - return OPERATOR_FINISHED; + SpaceInfo *sinfo = CTX_wm_space_info(C); + ReportList *reports = CTX_wm_reports(C); + const int report_mask = info_report_mask(sinfo); + + int action = RNA_enum_get(op->ptr, "action"); + + if (action == SEL_TOGGLE) { + action = SEL_SELECT; + for (Report *report = reports->list.last; report; report = report->prev) { + if ((report->type & report_mask) && (report->flag & SELECT)) { + action = SEL_DESELECT; + break; + } + } + } + + for (Report *report = reports->list.last; report; report = report->prev) { + if (report->type & report_mask) { + switch (action) { + case SEL_SELECT: + report->flag = SELECT; + break; + case SEL_DESELECT: + report->flag = ~SELECT; + break; + case SEL_INVERT: + report->flag ^= SELECT; + break; + default: + BLI_assert(0); + } + } + } + + ED_area_tag_redraw(CTX_wm_area(C)); + + return OPERATOR_FINISHED; } void INFO_OT_select_all(wmOperatorType *ot) { - /* identifiers */ - ot->name = "(De)select All"; - ot->description = "Change selection of all visible reports"; - ot->idname = "INFO_OT_select_all"; + /* identifiers */ + ot->name = "(De)select All"; + ot->description = "Change selection of all visible reports"; + ot->idname = "INFO_OT_select_all"; - /* api callbacks */ - ot->poll = ED_operator_info_active; - ot->exec = report_select_all_exec; + /* api callbacks */ + ot->poll = ED_operator_info_active; + ot->exec = report_select_all_exec; - /* properties */ - WM_operator_properties_select_action(ot, SEL_SELECT, true); + /* properties */ + WM_operator_properties_select_action(ot, SEL_SELECT, true); } /* box_select operator */ static int box_select_exec(bContext *C, wmOperator *op) { - SpaceInfo *sinfo = CTX_wm_space_info(C); - ARegion *ar = CTX_wm_region(C); - ReportList *reports = CTX_wm_reports(C); - int report_mask = info_report_mask(sinfo); - Report *report_min, *report_max; - rcti rect; - - WM_operator_properties_border_to_rcti(op, &rect); - - const eSelectOp sel_op = RNA_enum_get(op->ptr, "mode"); - const int select = (sel_op != SEL_OP_SUB); - if (SEL_OP_USE_PRE_DESELECT(sel_op)) { - for (Report *report = reports->list.first; report; report = report->next) { - if ((report->type & report_mask) == 0) { - continue; - } - report->flag &= ~SELECT; - } - } - - report_min = info_text_pick(sinfo, ar, reports, rect.ymax); - report_max = info_text_pick(sinfo, ar, reports, rect.ymin); - - /* get the first report if none found */ - if (report_min == NULL) { - // printf("find_min\n"); - for (Report *report = reports->list.first; report; report = report->next) { - if (report->type & report_mask) { - report_min = report; - break; - } - } - } - - if (report_max == NULL) { - // printf("find_max\n"); - for (Report *report = reports->list.last; report; report = report->prev) { - if (report->type & report_mask) { - report_max = report; - break; - } - } - } - - if (report_min == NULL || report_max == NULL) { - return OPERATOR_CANCELLED; - } - - for (Report *report = report_min; (report != report_max->next); report = report->next) { - if ((report->type & report_mask) == 0) { - continue; - } - SET_FLAG_FROM_TEST(report->flag, select, SELECT); - } - - ED_area_tag_redraw(CTX_wm_area(C)); - - return OPERATOR_FINISHED; + SpaceInfo *sinfo = CTX_wm_space_info(C); + ARegion *ar = CTX_wm_region(C); + ReportList *reports = CTX_wm_reports(C); + int report_mask = info_report_mask(sinfo); + Report *report_min, *report_max; + rcti rect; + + WM_operator_properties_border_to_rcti(op, &rect); + + const eSelectOp sel_op = RNA_enum_get(op->ptr, "mode"); + const int select = (sel_op != SEL_OP_SUB); + if (SEL_OP_USE_PRE_DESELECT(sel_op)) { + for (Report *report = reports->list.first; report; report = report->next) { + if ((report->type & report_mask) == 0) { + continue; + } + report->flag &= ~SELECT; + } + } + + report_min = info_text_pick(sinfo, ar, reports, rect.ymax); + report_max = info_text_pick(sinfo, ar, reports, rect.ymin); + + /* get the first report if none found */ + if (report_min == NULL) { + // printf("find_min\n"); + for (Report *report = reports->list.first; report; report = report->next) { + if (report->type & report_mask) { + report_min = report; + break; + } + } + } + + if (report_max == NULL) { + // printf("find_max\n"); + for (Report *report = reports->list.last; report; report = report->prev) { + if (report->type & report_mask) { + report_max = report; + break; + } + } + } + + if (report_min == NULL || report_max == NULL) { + return OPERATOR_CANCELLED; + } + + for (Report *report = report_min; (report != report_max->next); report = report->next) { + if ((report->type & report_mask) == 0) { + continue; + } + SET_FLAG_FROM_TEST(report->flag, select, SELECT); + } + + ED_area_tag_redraw(CTX_wm_area(C)); + + return OPERATOR_FINISHED; } - /* ****** Box Select ****** */ void INFO_OT_select_box(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Box Select"; - ot->description = "Toggle box selection"; - ot->idname = "INFO_OT_select_box"; + /* identifiers */ + ot->name = "Box Select"; + ot->description = "Toggle box selection"; + ot->idname = "INFO_OT_select_box"; - /* api callbacks */ - ot->invoke = WM_gesture_box_invoke; - ot->exec = box_select_exec; - ot->modal = WM_gesture_box_modal; - ot->cancel = WM_gesture_box_cancel; + /* api callbacks */ + ot->invoke = WM_gesture_box_invoke; + ot->exec = box_select_exec; + ot->modal = WM_gesture_box_modal; + ot->cancel = WM_gesture_box_cancel; - ot->poll = ED_operator_info_active; + ot->poll = ED_operator_info_active; - /* flags */ - /* ot->flag = OPTYPE_REGISTER; */ + /* flags */ + /* ot->flag = OPTYPE_REGISTER; */ - /* properties */ - WM_operator_properties_gesture_box(ot); - WM_operator_properties_select_operation_simple(ot); + /* properties */ + WM_operator_properties_gesture_box(ot); + WM_operator_properties_select_operation_simple(ot); } static int report_delete_exec(bContext *C, wmOperator *UNUSED(op)) { - SpaceInfo *sinfo = CTX_wm_space_info(C); - ReportList *reports = CTX_wm_reports(C); - int report_mask = info_report_mask(sinfo); + SpaceInfo *sinfo = CTX_wm_space_info(C); + ReportList *reports = CTX_wm_reports(C); + int report_mask = info_report_mask(sinfo); + Report *report, *report_next; - Report *report, *report_next; + for (report = reports->list.first; report;) { - for (report = reports->list.first; report; ) { + report_next = report->next; - report_next = report->next; + if ((report->type & report_mask) && (report->flag & SELECT)) { + BLI_remlink(&reports->list, report); + MEM_freeN((void *)report->message); + MEM_freeN(report); + } - if ((report->type & report_mask) && (report->flag & SELECT)) { - BLI_remlink(&reports->list, report); - MEM_freeN((void *)report->message); - MEM_freeN(report); - } + report = report_next; + } - report = report_next; - } + ED_area_tag_redraw(CTX_wm_area(C)); - ED_area_tag_redraw(CTX_wm_area(C)); - - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void INFO_OT_report_delete(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Delete Reports"; - ot->description = "Delete selected reports"; - ot->idname = "INFO_OT_report_delete"; + /* identifiers */ + ot->name = "Delete Reports"; + ot->description = "Delete selected reports"; + ot->idname = "INFO_OT_report_delete"; - /* api callbacks */ - ot->poll = ED_operator_info_active; - ot->exec = report_delete_exec; + /* api callbacks */ + ot->poll = ED_operator_info_active; + ot->exec = report_delete_exec; - /* flags */ - /*ot->flag = OPTYPE_REGISTER;*/ + /* flags */ + /*ot->flag = OPTYPE_REGISTER;*/ - /* properties */ + /* properties */ } - static int report_copy_exec(bContext *C, wmOperator *UNUSED(op)) { - SpaceInfo *sinfo = CTX_wm_space_info(C); - ReportList *reports = CTX_wm_reports(C); - int report_mask = info_report_mask(sinfo); + SpaceInfo *sinfo = CTX_wm_space_info(C); + ReportList *reports = CTX_wm_reports(C); + int report_mask = info_report_mask(sinfo); - Report *report; + Report *report; - DynStr *buf_dyn = BLI_dynstr_new(); - char *buf_str; + DynStr *buf_dyn = BLI_dynstr_new(); + char *buf_str; - for (report = reports->list.first; report; report = report->next) { - if ((report->type & report_mask) && (report->flag & SELECT)) { - BLI_dynstr_append(buf_dyn, report->message); - BLI_dynstr_append(buf_dyn, "\n"); - } - } + for (report = reports->list.first; report; report = report->next) { + if ((report->type & report_mask) && (report->flag & SELECT)) { + BLI_dynstr_append(buf_dyn, report->message); + BLI_dynstr_append(buf_dyn, "\n"); + } + } - buf_str = BLI_dynstr_get_cstring(buf_dyn); - BLI_dynstr_free(buf_dyn); + buf_str = BLI_dynstr_get_cstring(buf_dyn); + BLI_dynstr_free(buf_dyn); - WM_clipboard_text_set(buf_str, 0); + WM_clipboard_text_set(buf_str, 0); - MEM_freeN(buf_str); - return OPERATOR_FINISHED; + MEM_freeN(buf_str); + return OPERATOR_FINISHED; } void INFO_OT_report_copy(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Copy Reports to Clipboard"; - ot->description = "Copy selected reports to Clipboard"; - ot->idname = "INFO_OT_report_copy"; + /* identifiers */ + ot->name = "Copy Reports to Clipboard"; + ot->description = "Copy selected reports to Clipboard"; + ot->idname = "INFO_OT_report_copy"; - /* api callbacks */ - ot->poll = ED_operator_info_active; - ot->exec = report_copy_exec; + /* api callbacks */ + ot->poll = ED_operator_info_active; + ot->exec = report_copy_exec; - /* flags */ - /*ot->flag = OPTYPE_REGISTER;*/ + /* flags */ + /*ot->flag = OPTYPE_REGISTER;*/ - /* properties */ + /* properties */ } diff --git a/source/blender/editors/space_info/info_stats.c b/source/blender/editors/space_info/info_stats.c index 054e9cd0026..3ef9a12e0c9 100644 --- a/source/blender/editors/space_info/info_stats.c +++ b/source/blender/editors/space_info/info_stats.c @@ -18,7 +18,6 @@ * \ingroup spinfo */ - #include <stdio.h> #include <string.h> @@ -67,457 +66,480 @@ #define MAX_INFO_NUM_LEN 16 typedef struct SceneStats { - uint64_t totvert, totvertsel; - uint64_t totedge, totedgesel; - uint64_t totface, totfacesel; - uint64_t totbone, totbonesel; - uint64_t totobj, totobjsel; - uint64_t totlamp, totlampsel; - uint64_t tottri; - uint64_t totgplayer, totgpframe, totgpstroke, totgppoint; - - char infostr[MAX_INFO_LEN]; + uint64_t totvert, totvertsel; + uint64_t totedge, totedgesel; + uint64_t totface, totfacesel; + uint64_t totbone, totbonesel; + uint64_t totobj, totobjsel; + uint64_t totlamp, totlampsel; + uint64_t tottri; + uint64_t totgplayer, totgpframe, totgpstroke, totgppoint; + + char infostr[MAX_INFO_LEN]; } SceneStats; typedef struct SceneStatsFmt { - /* Totals */ - char totvert[MAX_INFO_NUM_LEN], totvertsel[MAX_INFO_NUM_LEN]; - char totface[MAX_INFO_NUM_LEN], totfacesel[MAX_INFO_NUM_LEN]; - char totedge[MAX_INFO_NUM_LEN], totedgesel[MAX_INFO_NUM_LEN]; - char totbone[MAX_INFO_NUM_LEN], totbonesel[MAX_INFO_NUM_LEN]; - char totobj[MAX_INFO_NUM_LEN], totobjsel[MAX_INFO_NUM_LEN]; - char totlamp[MAX_INFO_NUM_LEN], totlampsel[MAX_INFO_NUM_LEN]; - char tottri[MAX_INFO_NUM_LEN]; - char totgplayer[MAX_INFO_NUM_LEN], totgpframe[MAX_INFO_NUM_LEN]; - char totgpstroke[MAX_INFO_NUM_LEN], totgppoint[MAX_INFO_NUM_LEN]; + /* Totals */ + char totvert[MAX_INFO_NUM_LEN], totvertsel[MAX_INFO_NUM_LEN]; + char totface[MAX_INFO_NUM_LEN], totfacesel[MAX_INFO_NUM_LEN]; + char totedge[MAX_INFO_NUM_LEN], totedgesel[MAX_INFO_NUM_LEN]; + char totbone[MAX_INFO_NUM_LEN], totbonesel[MAX_INFO_NUM_LEN]; + char totobj[MAX_INFO_NUM_LEN], totobjsel[MAX_INFO_NUM_LEN]; + char totlamp[MAX_INFO_NUM_LEN], totlampsel[MAX_INFO_NUM_LEN]; + char tottri[MAX_INFO_NUM_LEN]; + char totgplayer[MAX_INFO_NUM_LEN], totgpframe[MAX_INFO_NUM_LEN]; + char totgpstroke[MAX_INFO_NUM_LEN], totgppoint[MAX_INFO_NUM_LEN]; } SceneStatsFmt; static bool stats_mesheval(Mesh *me_eval, bool is_selected, SceneStats *stats) { - if (me_eval == NULL) { - return false; - } - - int totvert, totedge, totface, totloop; - if (me_eval->runtime.subdiv_ccg != NULL) { - const SubdivCCG *subdiv_ccg = me_eval->runtime.subdiv_ccg; - BKE_subdiv_ccg_topology_counters( - subdiv_ccg, &totvert, &totedge, &totface, &totloop); - } - else { - totvert = me_eval->totvert; - totedge = me_eval->totedge; - totface = me_eval->totpoly; - totloop = me_eval->totloop; - } - - stats->totvert += totvert; - stats->totedge += totedge; - stats->totface += totface; - stats->tottri += poly_to_tri_count(totface, totloop); - - if (is_selected) { - stats->totvertsel += totvert; - stats->totfacesel += totface; - } - return true; + if (me_eval == NULL) { + return false; + } + + int totvert, totedge, totface, totloop; + if (me_eval->runtime.subdiv_ccg != NULL) { + const SubdivCCG *subdiv_ccg = me_eval->runtime.subdiv_ccg; + BKE_subdiv_ccg_topology_counters(subdiv_ccg, &totvert, &totedge, &totface, &totloop); + } + else { + totvert = me_eval->totvert; + totedge = me_eval->totedge; + totface = me_eval->totpoly; + totloop = me_eval->totloop; + } + + stats->totvert += totvert; + stats->totedge += totedge; + stats->totface += totface; + stats->tottri += poly_to_tri_count(totface, totloop); + + if (is_selected) { + stats->totvertsel += totvert; + stats->totfacesel += totface; + } + return true; } static void stats_object(Object *ob, SceneStats *stats) { - const bool is_selected = (ob->base_flag & BASE_SELECTED) != 0; - - stats->totobj++; - if (is_selected) { - stats->totobjsel++; - } - - switch (ob->type) { - case OB_MESH: - { - /* we assume evaluated mesh is already built, this strictly does stats now. */ - Mesh *me_eval = ob->runtime.mesh_eval; - stats_mesheval(me_eval, is_selected, stats); - break; - } - case OB_LAMP: - stats->totlamp++; - if (is_selected) { - stats->totlampsel++; - } - break; - case OB_SURF: - case OB_CURVE: - case OB_FONT: - { - Mesh *me_eval = ob->runtime.mesh_eval; - if (stats_mesheval(me_eval, is_selected, stats)) { - break; - } - ATTR_FALLTHROUGH; /* Falltrough to displist. */ - } - case OB_MBALL: - { - int totv = 0, totf = 0, tottri = 0; - - if (ob->runtime.curve_cache && ob->runtime.curve_cache->disp.first) { - BKE_displist_count(&ob->runtime.curve_cache->disp, &totv, &totf, &tottri); - } - - stats->totvert += totv; - stats->totface += totf; - stats->tottri += tottri; - - if (is_selected) { - stats->totvertsel += totv; - stats->totfacesel += totf; - } - break; - } - case OB_GPENCIL: - { - if (is_selected) { - bGPdata *gpd = (bGPdata *)ob->data; - /* GPXX Review if we can move to other place when object change - * maybe to depsgraph evaluation - */ - BKE_gpencil_stats_update(gpd); - - stats->totgplayer += gpd->totlayer; - stats->totgpframe += gpd->totframe; - stats->totgpstroke += gpd->totstroke; - stats->totgppoint += gpd->totpoint; - } - break; - } - } + const bool is_selected = (ob->base_flag & BASE_SELECTED) != 0; + + stats->totobj++; + if (is_selected) { + stats->totobjsel++; + } + + switch (ob->type) { + case OB_MESH: { + /* we assume evaluated mesh is already built, this strictly does stats now. */ + Mesh *me_eval = ob->runtime.mesh_eval; + stats_mesheval(me_eval, is_selected, stats); + break; + } + case OB_LAMP: + stats->totlamp++; + if (is_selected) { + stats->totlampsel++; + } + break; + case OB_SURF: + case OB_CURVE: + case OB_FONT: { + Mesh *me_eval = ob->runtime.mesh_eval; + if (stats_mesheval(me_eval, is_selected, stats)) { + break; + } + ATTR_FALLTHROUGH; /* Falltrough to displist. */ + } + case OB_MBALL: { + int totv = 0, totf = 0, tottri = 0; + + if (ob->runtime.curve_cache && ob->runtime.curve_cache->disp.first) { + BKE_displist_count(&ob->runtime.curve_cache->disp, &totv, &totf, &tottri); + } + + stats->totvert += totv; + stats->totface += totf; + stats->tottri += tottri; + + if (is_selected) { + stats->totvertsel += totv; + stats->totfacesel += totf; + } + break; + } + case OB_GPENCIL: { + if (is_selected) { + bGPdata *gpd = (bGPdata *)ob->data; + /* GPXX Review if we can move to other place when object change + * maybe to depsgraph evaluation + */ + BKE_gpencil_stats_update(gpd); + + stats->totgplayer += gpd->totlayer; + stats->totgpframe += gpd->totframe; + stats->totgpstroke += gpd->totstroke; + stats->totgppoint += gpd->totpoint; + } + break; + } + } } static void stats_object_edit(Object *obedit, SceneStats *stats) { - if (obedit->type == OB_MESH) { - BMEditMesh *em = BKE_editmesh_from_object(obedit); - - stats->totvert += em->bm->totvert; - stats->totvertsel += em->bm->totvertsel; - - stats->totedge += em->bm->totedge; - stats->totedgesel += em->bm->totedgesel; - - stats->totface += em->bm->totface; - stats->totfacesel += em->bm->totfacesel; - - stats->tottri += em->tottri; - } - else if (obedit->type == OB_ARMATURE) { - /* Armature Edit */ - bArmature *arm = obedit->data; - EditBone *ebo; - - for (ebo = arm->edbo->first; ebo; ebo = ebo->next) { - stats->totbone++; - - if ((ebo->flag & BONE_CONNECTED) && ebo->parent) { - stats->totvert--; - } - - if (ebo->flag & BONE_TIPSEL) { - stats->totvertsel++; - } - if (ebo->flag & BONE_ROOTSEL) { - stats->totvertsel++; - } - - if (ebo->flag & BONE_SELECTED) { - stats->totbonesel++; - } - - /* if this is a connected child and it's parent is being moved, remove our root */ - if ((ebo->flag & BONE_CONNECTED) && (ebo->flag & BONE_ROOTSEL) && - ebo->parent && (ebo->parent->flag & BONE_TIPSEL)) - { - stats->totvertsel--; - } - - stats->totvert += 2; - } - } - else if (ELEM(obedit->type, OB_CURVE, OB_SURF)) { /* OB_FONT has no cu->editnurb */ - /* Curve Edit */ - Curve *cu = obedit->data; - Nurb *nu; - BezTriple *bezt; - BPoint *bp; - int a; - ListBase *nurbs = BKE_curve_editNurbs_get(cu); - - for (nu = nurbs->first; nu; nu = nu->next) { - if (nu->type == CU_BEZIER) { - bezt = nu->bezt; - a = nu->pntsu; - while (a--) { - stats->totvert += 3; - if (bezt->f1 & SELECT) { - stats->totvertsel++; - } - if (bezt->f2 & SELECT) { - stats->totvertsel++; - } - if (bezt->f3 & SELECT) { - stats->totvertsel++; - } - bezt++; - } - } - else { - bp = nu->bp; - a = nu->pntsu * nu->pntsv; - while (a--) { - stats->totvert++; - if (bp->f1 & SELECT) { - stats->totvertsel++; - } - bp++; - } - } - } - } - else if (obedit->type == OB_MBALL) { - /* MetaBall Edit */ - MetaBall *mball = obedit->data; - MetaElem *ml; - - for (ml = mball->editelems->first; ml; ml = ml->next) { - stats->totvert++; - if (ml->flag & SELECT) { - stats->totvertsel++; - } - } - } - else if (obedit->type == OB_LATTICE) { - /* Lattice Edit */ - Lattice *lt = obedit->data; - Lattice *editlatt = lt->editlatt->latt; - BPoint *bp; - int a; - - bp = editlatt->def; - - a = editlatt->pntsu * editlatt->pntsv * editlatt->pntsw; - while (a--) { - stats->totvert++; - if (bp->f1 & SELECT) { - stats->totvertsel++; - } - bp++; - } - } + if (obedit->type == OB_MESH) { + BMEditMesh *em = BKE_editmesh_from_object(obedit); + + stats->totvert += em->bm->totvert; + stats->totvertsel += em->bm->totvertsel; + + stats->totedge += em->bm->totedge; + stats->totedgesel += em->bm->totedgesel; + + stats->totface += em->bm->totface; + stats->totfacesel += em->bm->totfacesel; + + stats->tottri += em->tottri; + } + else if (obedit->type == OB_ARMATURE) { + /* Armature Edit */ + bArmature *arm = obedit->data; + EditBone *ebo; + + for (ebo = arm->edbo->first; ebo; ebo = ebo->next) { + stats->totbone++; + + if ((ebo->flag & BONE_CONNECTED) && ebo->parent) { + stats->totvert--; + } + + if (ebo->flag & BONE_TIPSEL) { + stats->totvertsel++; + } + if (ebo->flag & BONE_ROOTSEL) { + stats->totvertsel++; + } + + if (ebo->flag & BONE_SELECTED) { + stats->totbonesel++; + } + + /* if this is a connected child and it's parent is being moved, remove our root */ + if ((ebo->flag & BONE_CONNECTED) && (ebo->flag & BONE_ROOTSEL) && ebo->parent && + (ebo->parent->flag & BONE_TIPSEL)) { + stats->totvertsel--; + } + + stats->totvert += 2; + } + } + else if (ELEM(obedit->type, OB_CURVE, OB_SURF)) { /* OB_FONT has no cu->editnurb */ + /* Curve Edit */ + Curve *cu = obedit->data; + Nurb *nu; + BezTriple *bezt; + BPoint *bp; + int a; + ListBase *nurbs = BKE_curve_editNurbs_get(cu); + + for (nu = nurbs->first; nu; nu = nu->next) { + if (nu->type == CU_BEZIER) { + bezt = nu->bezt; + a = nu->pntsu; + while (a--) { + stats->totvert += 3; + if (bezt->f1 & SELECT) { + stats->totvertsel++; + } + if (bezt->f2 & SELECT) { + stats->totvertsel++; + } + if (bezt->f3 & SELECT) { + stats->totvertsel++; + } + bezt++; + } + } + else { + bp = nu->bp; + a = nu->pntsu * nu->pntsv; + while (a--) { + stats->totvert++; + if (bp->f1 & SELECT) { + stats->totvertsel++; + } + bp++; + } + } + } + } + else if (obedit->type == OB_MBALL) { + /* MetaBall Edit */ + MetaBall *mball = obedit->data; + MetaElem *ml; + + for (ml = mball->editelems->first; ml; ml = ml->next) { + stats->totvert++; + if (ml->flag & SELECT) { + stats->totvertsel++; + } + } + } + else if (obedit->type == OB_LATTICE) { + /* Lattice Edit */ + Lattice *lt = obedit->data; + Lattice *editlatt = lt->editlatt->latt; + BPoint *bp; + int a; + + bp = editlatt->def; + + a = editlatt->pntsu * editlatt->pntsv * editlatt->pntsw; + while (a--) { + stats->totvert++; + if (bp->f1 & SELECT) { + stats->totvertsel++; + } + bp++; + } + } } static void stats_object_pose(Object *ob, SceneStats *stats) { - if (ob->pose) { - bArmature *arm = ob->data; - bPoseChannel *pchan; - - for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { - stats->totbone++; - if (pchan->bone && (pchan->bone->flag & BONE_SELECTED)) { - if (pchan->bone->layer & arm->layer) { - stats->totbonesel++; - } - } - } - } + if (ob->pose) { + bArmature *arm = ob->data; + bPoseChannel *pchan; + + for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { + stats->totbone++; + if (pchan->bone && (pchan->bone->flag & BONE_SELECTED)) { + if (pchan->bone->layer & arm->layer) { + stats->totbonesel++; + } + } + } + } } static void stats_object_sculpt_dynamic_topology(Object *ob, SceneStats *stats) { - stats->totvert = ob->sculpt->bm->totvert; - stats->tottri = ob->sculpt->bm->totface; + stats->totvert = ob->sculpt->bm->totvert; + stats->tottri = ob->sculpt->bm->totface; } static bool stats_is_object_dynamic_topology_sculpt(Object *ob, const eObjectMode object_mode) { - return (ob && - (object_mode & OB_MODE_SCULPT) && - ob->sculpt && ob->sculpt->bm); + return (ob && (object_mode & OB_MODE_SCULPT) && ob->sculpt && ob->sculpt->bm); } /* Statistics displayed in info header. Called regularly on scene changes. */ static void stats_update(Depsgraph *depsgraph, ViewLayer *view_layer) { - SceneStats stats = {0}; - Object *ob = OBACT(view_layer); - Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer); - - if (obedit) { - /* Edit Mode */ - FOREACH_OBJECT_IN_MODE_BEGIN(view_layer, ((View3D *)NULL), ob->type, ob->mode, ob_iter) - { - stats_object_edit(ob_iter, &stats); - } - FOREACH_OBJECT_IN_MODE_END; - } - else if (ob && (ob->mode & OB_MODE_POSE)) { - /* Pose Mode */ - stats_object_pose(ob, &stats); - } - else if (ob && stats_is_object_dynamic_topology_sculpt(ob, ob->mode)) { - /* Dynamic-topology sculpt mode */ - stats_object_sculpt_dynamic_topology(ob, &stats); - } - else { - /* Objects */ - DEG_OBJECT_ITER_FOR_RENDER_ENGINE_BEGIN(depsgraph, ob_iter) - { - stats_object(ob_iter, &stats); - } - DEG_OBJECT_ITER_FOR_RENDER_ENGINE_END; - } - - if (!view_layer->stats) { - view_layer->stats = MEM_callocN(sizeof(SceneStats), "SceneStats"); - } - - *(view_layer->stats) = stats; + SceneStats stats = {0}; + Object *ob = OBACT(view_layer); + Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer); + + if (obedit) { + /* Edit Mode */ + FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, ((View3D *)NULL), ob->type, ob->mode, ob_iter) { + stats_object_edit(ob_iter, &stats); + } + FOREACH_OBJECT_IN_MODE_END; + } + else if (ob && (ob->mode & OB_MODE_POSE)) { + /* Pose Mode */ + stats_object_pose(ob, &stats); + } + else if (ob && stats_is_object_dynamic_topology_sculpt(ob, ob->mode)) { + /* Dynamic-topology sculpt mode */ + stats_object_sculpt_dynamic_topology(ob, &stats); + } + else { + /* Objects */ + DEG_OBJECT_ITER_FOR_RENDER_ENGINE_BEGIN (depsgraph, ob_iter) { + stats_object(ob_iter, &stats); + } + DEG_OBJECT_ITER_FOR_RENDER_ENGINE_END; + } + + if (!view_layer->stats) { + view_layer->stats = MEM_callocN(sizeof(SceneStats), "SceneStats"); + } + + *(view_layer->stats) = stats; } static void stats_string(ViewLayer *view_layer) { -#define MAX_INFO_MEM_LEN 64 - SceneStats *stats = view_layer->stats; - SceneStatsFmt stats_fmt; - LayerCollection *layer_collection = view_layer->active_collection; - Object *ob = OBACT(view_layer); - Object *obedit = OBEDIT_FROM_OBACT(ob); - eObjectMode object_mode = ob ? ob->mode : OB_MODE_OBJECT; - uintptr_t mem_in_use, mmap_in_use; - char memstr[MAX_INFO_MEM_LEN]; - char gpumemstr[MAX_INFO_MEM_LEN] = ""; - char formatted_mem[15]; - char *s; - size_t ofs = 0; - - mem_in_use = MEM_get_memory_in_use(); - mmap_in_use = MEM_get_mapped_memory_in_use(); +#define MAX_INFO_MEM_LEN 64 + SceneStats *stats = view_layer->stats; + SceneStatsFmt stats_fmt; + LayerCollection *layer_collection = view_layer->active_collection; + Object *ob = OBACT(view_layer); + Object *obedit = OBEDIT_FROM_OBACT(ob); + eObjectMode object_mode = ob ? ob->mode : OB_MODE_OBJECT; + uintptr_t mem_in_use, mmap_in_use; + char memstr[MAX_INFO_MEM_LEN]; + char gpumemstr[MAX_INFO_MEM_LEN] = ""; + char formatted_mem[15]; + char *s; + size_t ofs = 0; + mem_in_use = MEM_get_memory_in_use(); + mmap_in_use = MEM_get_mapped_memory_in_use(); - /* Generate formatted numbers */ -#define SCENE_STATS_FMT_INT(_id) \ - BLI_str_format_uint64_grouped(stats_fmt._id, stats->_id) + /* Generate formatted numbers */ +#define SCENE_STATS_FMT_INT(_id) BLI_str_format_uint64_grouped(stats_fmt._id, stats->_id) - SCENE_STATS_FMT_INT(totvert); - SCENE_STATS_FMT_INT(totvertsel); + SCENE_STATS_FMT_INT(totvert); + SCENE_STATS_FMT_INT(totvertsel); - SCENE_STATS_FMT_INT(totedge); - SCENE_STATS_FMT_INT(totedgesel); + SCENE_STATS_FMT_INT(totedge); + SCENE_STATS_FMT_INT(totedgesel); - SCENE_STATS_FMT_INT(totface); - SCENE_STATS_FMT_INT(totfacesel); + SCENE_STATS_FMT_INT(totface); + SCENE_STATS_FMT_INT(totfacesel); - SCENE_STATS_FMT_INT(totbone); - SCENE_STATS_FMT_INT(totbonesel); + SCENE_STATS_FMT_INT(totbone); + SCENE_STATS_FMT_INT(totbonesel); - SCENE_STATS_FMT_INT(totobj); - SCENE_STATS_FMT_INT(totobjsel); + SCENE_STATS_FMT_INT(totobj); + SCENE_STATS_FMT_INT(totobjsel); - SCENE_STATS_FMT_INT(totlamp); - SCENE_STATS_FMT_INT(totlampsel); + SCENE_STATS_FMT_INT(totlamp); + SCENE_STATS_FMT_INT(totlampsel); - SCENE_STATS_FMT_INT(tottri); + SCENE_STATS_FMT_INT(tottri); - SCENE_STATS_FMT_INT(totgplayer); - SCENE_STATS_FMT_INT(totgpframe); - SCENE_STATS_FMT_INT(totgpstroke); - SCENE_STATS_FMT_INT(totgppoint); + SCENE_STATS_FMT_INT(totgplayer); + SCENE_STATS_FMT_INT(totgpframe); + SCENE_STATS_FMT_INT(totgpstroke); + SCENE_STATS_FMT_INT(totgppoint); #undef SCENE_STATS_FMT_INT - - /* get memory statistics */ - BLI_str_format_byte_unit(formatted_mem, mem_in_use - mmap_in_use, true); - ofs = BLI_snprintf(memstr, MAX_INFO_MEM_LEN, IFACE_(" | Mem: %s"), formatted_mem); - - if (mmap_in_use) { - BLI_str_format_byte_unit(formatted_mem, mmap_in_use, true); - BLI_snprintf(memstr + ofs, MAX_INFO_MEM_LEN - ofs, IFACE_(" (%s)"), formatted_mem); - } - - if (GPU_mem_stats_supported()) { - int gpu_free_mem, gpu_tot_memory; - - GPU_mem_stats_get(&gpu_tot_memory, &gpu_free_mem); - - BLI_str_format_byte_unit(formatted_mem, gpu_free_mem, true); - ofs = BLI_snprintf(gpumemstr, MAX_INFO_MEM_LEN, IFACE_(" | Free GPU Mem: %s"), formatted_mem); - - if (gpu_tot_memory) { - BLI_str_format_byte_unit(formatted_mem, gpu_tot_memory, true); - BLI_snprintf(gpumemstr + ofs, MAX_INFO_MEM_LEN - ofs, IFACE_("/%s"), formatted_mem); - } - } - - s = stats->infostr; - ofs = 0; - - if (object_mode == OB_MODE_OBJECT) { - ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs, "%s | ", BKE_collection_ui_name_get(layer_collection->collection)); - } - - if (ob) { - ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs, "%s | ", ob->id.name + 2); - } - - if (obedit) { - if (BKE_keyblock_from_object(obedit)) { - ofs += BLI_strncpy_rlen(s + ofs, IFACE_("(Key) "), MAX_INFO_LEN - ofs); - } - - if (obedit->type == OB_MESH) { - ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs, - IFACE_("Verts:%s/%s | Edges:%s/%s | Faces:%s/%s | Tris:%s"), - stats_fmt.totvertsel, stats_fmt.totvert, stats_fmt.totedgesel, stats_fmt.totedge, - stats_fmt.totfacesel, stats_fmt.totface, stats_fmt.tottri); - } - else if (obedit->type == OB_ARMATURE) { - ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs, IFACE_("Verts:%s/%s | Bones:%s/%s"), stats_fmt.totvertsel, - stats_fmt.totvert, stats_fmt.totbonesel, stats_fmt.totbone); - } - else { - ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs, IFACE_("Verts:%s/%s"), stats_fmt.totvertsel, - stats_fmt.totvert); - } - - ofs += BLI_strncpy_rlen(s + ofs, memstr, MAX_INFO_LEN - ofs); - ofs += BLI_strncpy_rlen(s + ofs, gpumemstr, MAX_INFO_LEN - ofs); - } - else if (ob && (object_mode & OB_MODE_POSE)) { - ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs, IFACE_("Bones:%s/%s %s%s"), - stats_fmt.totbonesel, stats_fmt.totbone, memstr, gpumemstr); - } - else if ((ob) && (ob->type == OB_GPENCIL)) { - ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs, - IFACE_("Layers:%s | Frames:%s | Strokes:%s | Points:%s | Objects:%s/%s"), - stats_fmt.totgplayer, stats_fmt.totgpframe, stats_fmt.totgpstroke, - stats_fmt.totgppoint, stats_fmt.totobjsel, stats_fmt.totobj); - - ofs += BLI_strncpy_rlen(s + ofs, memstr, MAX_INFO_LEN - ofs); - ofs += BLI_strncpy_rlen(s + ofs, gpumemstr, MAX_INFO_LEN - ofs); - } - else if (stats_is_object_dynamic_topology_sculpt(ob, object_mode)) { - ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs, IFACE_("Verts:%s | Tris:%s%s"), stats_fmt.totvert, - stats_fmt.tottri, gpumemstr); - } - else { - ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs, - IFACE_("Verts:%s | Faces:%s | Tris:%s | Objects:%s/%s%s%s"), - stats_fmt.totvert, stats_fmt.totface, - stats_fmt.tottri, stats_fmt.totobjsel, - stats_fmt.totobj, memstr, gpumemstr); - } - - ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs, " | %s", versionstr); + /* get memory statistics */ + BLI_str_format_byte_unit(formatted_mem, mem_in_use - mmap_in_use, true); + ofs = BLI_snprintf(memstr, MAX_INFO_MEM_LEN, IFACE_(" | Mem: %s"), formatted_mem); + + if (mmap_in_use) { + BLI_str_format_byte_unit(formatted_mem, mmap_in_use, true); + BLI_snprintf(memstr + ofs, MAX_INFO_MEM_LEN - ofs, IFACE_(" (%s)"), formatted_mem); + } + + if (GPU_mem_stats_supported()) { + int gpu_free_mem, gpu_tot_memory; + + GPU_mem_stats_get(&gpu_tot_memory, &gpu_free_mem); + + BLI_str_format_byte_unit(formatted_mem, gpu_free_mem, true); + ofs = BLI_snprintf(gpumemstr, MAX_INFO_MEM_LEN, IFACE_(" | Free GPU Mem: %s"), formatted_mem); + + if (gpu_tot_memory) { + BLI_str_format_byte_unit(formatted_mem, gpu_tot_memory, true); + BLI_snprintf(gpumemstr + ofs, MAX_INFO_MEM_LEN - ofs, IFACE_("/%s"), formatted_mem); + } + } + + s = stats->infostr; + ofs = 0; + + if (object_mode == OB_MODE_OBJECT) { + ofs += BLI_snprintf(s + ofs, + MAX_INFO_LEN - ofs, + "%s | ", + BKE_collection_ui_name_get(layer_collection->collection)); + } + + if (ob) { + ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs, "%s | ", ob->id.name + 2); + } + + if (obedit) { + if (BKE_keyblock_from_object(obedit)) { + ofs += BLI_strncpy_rlen(s + ofs, IFACE_("(Key) "), MAX_INFO_LEN - ofs); + } + + if (obedit->type == OB_MESH) { + ofs += BLI_snprintf(s + ofs, + MAX_INFO_LEN - ofs, + IFACE_("Verts:%s/%s | Edges:%s/%s | Faces:%s/%s | Tris:%s"), + stats_fmt.totvertsel, + stats_fmt.totvert, + stats_fmt.totedgesel, + stats_fmt.totedge, + stats_fmt.totfacesel, + stats_fmt.totface, + stats_fmt.tottri); + } + else if (obedit->type == OB_ARMATURE) { + ofs += BLI_snprintf(s + ofs, + MAX_INFO_LEN - ofs, + IFACE_("Verts:%s/%s | Bones:%s/%s"), + stats_fmt.totvertsel, + stats_fmt.totvert, + stats_fmt.totbonesel, + stats_fmt.totbone); + } + else { + ofs += BLI_snprintf(s + ofs, + MAX_INFO_LEN - ofs, + IFACE_("Verts:%s/%s"), + stats_fmt.totvertsel, + stats_fmt.totvert); + } + + ofs += BLI_strncpy_rlen(s + ofs, memstr, MAX_INFO_LEN - ofs); + ofs += BLI_strncpy_rlen(s + ofs, gpumemstr, MAX_INFO_LEN - ofs); + } + else if (ob && (object_mode & OB_MODE_POSE)) { + ofs += BLI_snprintf(s + ofs, + MAX_INFO_LEN - ofs, + IFACE_("Bones:%s/%s %s%s"), + stats_fmt.totbonesel, + stats_fmt.totbone, + memstr, + gpumemstr); + } + else if ((ob) && (ob->type == OB_GPENCIL)) { + ofs += BLI_snprintf(s + ofs, + MAX_INFO_LEN - ofs, + IFACE_("Layers:%s | Frames:%s | Strokes:%s | Points:%s | Objects:%s/%s"), + stats_fmt.totgplayer, + stats_fmt.totgpframe, + stats_fmt.totgpstroke, + stats_fmt.totgppoint, + stats_fmt.totobjsel, + stats_fmt.totobj); + + ofs += BLI_strncpy_rlen(s + ofs, memstr, MAX_INFO_LEN - ofs); + ofs += BLI_strncpy_rlen(s + ofs, gpumemstr, MAX_INFO_LEN - ofs); + } + else if (stats_is_object_dynamic_topology_sculpt(ob, object_mode)) { + ofs += BLI_snprintf(s + ofs, + MAX_INFO_LEN - ofs, + IFACE_("Verts:%s | Tris:%s%s"), + stats_fmt.totvert, + stats_fmt.tottri, + gpumemstr); + } + else { + ofs += BLI_snprintf(s + ofs, + MAX_INFO_LEN - ofs, + IFACE_("Verts:%s | Faces:%s | Tris:%s | Objects:%s/%s%s%s"), + stats_fmt.totvert, + stats_fmt.totface, + stats_fmt.tottri, + stats_fmt.totobjsel, + stats_fmt.totobj, + memstr, + gpumemstr); + } + + ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs, " | %s", versionstr); #undef MAX_INFO_MEM_LEN } @@ -525,25 +547,25 @@ static void stats_string(ViewLayer *view_layer) void ED_info_stats_clear(ViewLayer *view_layer) { - if (view_layer->stats) { - MEM_freeN(view_layer->stats); - view_layer->stats = NULL; - } + if (view_layer->stats) { + MEM_freeN(view_layer->stats); + view_layer->stats = NULL; + } } const char *ED_info_stats_string(Main *bmain, Scene *scene, ViewLayer *view_layer) { - /* Loopin through dependency graph when interface is locked in not safe. - * Thew interface is marked as locked when jobs wants to modify the - * dependency graph. */ - wmWindowManager *wm = bmain->wm.first; - if (wm->is_interface_locked) { - return ""; - } - Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene, view_layer, true); - if (!view_layer->stats) { - stats_update(depsgraph, view_layer); - } - stats_string(view_layer); - return view_layer->stats->infostr; + /* Loopin through dependency graph when interface is locked in not safe. + * Thew interface is marked as locked when jobs wants to modify the + * dependency graph. */ + wmWindowManager *wm = bmain->wm.first; + if (wm->is_interface_locked) { + return ""; + } + Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene, view_layer, true); + if (!view_layer->stats) { + stats_update(depsgraph, view_layer); + } + stats_string(view_layer); + return view_layer->stats->infostr; } diff --git a/source/blender/editors/space_info/space_info.c b/source/blender/editors/space_info/space_info.c index 997a40839ac..6ed9d80d145 100644 --- a/source/blender/editors/space_info/space_info.c +++ b/source/blender/editors/space_info/space_info.c @@ -21,7 +21,6 @@ * \ingroup spinfo */ - #include <string.h> #include <stdio.h> @@ -48,7 +47,7 @@ #include "UI_interface.h" #include "UI_view2d.h" -#include "info_intern.h" /* own include */ +#include "info_intern.h" /* own include */ #include "BLO_readfile.h" #include "GPU_framebuffer.h" @@ -56,270 +55,271 @@ static SpaceLink *info_new(const ScrArea *UNUSED(area), const Scene *UNUSED(scene)) { - ARegion *ar; - SpaceInfo *sinfo; + ARegion *ar; + SpaceInfo *sinfo; - sinfo = MEM_callocN(sizeof(SpaceInfo), "initinfo"); - sinfo->spacetype = SPACE_INFO; + sinfo = MEM_callocN(sizeof(SpaceInfo), "initinfo"); + sinfo->spacetype = SPACE_INFO; - sinfo->rpt_mask = INFO_RPT_OP; + sinfo->rpt_mask = INFO_RPT_OP; - /* header */ - ar = MEM_callocN(sizeof(ARegion), "header for info"); + /* header */ + ar = MEM_callocN(sizeof(ARegion), "header for info"); - BLI_addtail(&sinfo->regionbase, ar); - ar->regiontype = RGN_TYPE_HEADER; - ar->alignment = (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_BOTTOM : RGN_ALIGN_TOP; + BLI_addtail(&sinfo->regionbase, ar); + ar->regiontype = RGN_TYPE_HEADER; + ar->alignment = (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_BOTTOM : RGN_ALIGN_TOP; - /* main region */ - ar = MEM_callocN(sizeof(ARegion), "main region for info"); + /* main region */ + ar = MEM_callocN(sizeof(ARegion), "main region for info"); - BLI_addtail(&sinfo->regionbase, ar); - ar->regiontype = RGN_TYPE_WINDOW; + BLI_addtail(&sinfo->regionbase, ar); + ar->regiontype = RGN_TYPE_WINDOW; - /* keep in sync with console */ - ar->v2d.scroll |= (V2D_SCROLL_RIGHT); - ar->v2d.align |= V2D_ALIGN_NO_NEG_X | V2D_ALIGN_NO_NEG_Y; /* align bottom left */ - ar->v2d.keepofs |= V2D_LOCKOFS_X; - ar->v2d.keepzoom = (V2D_LOCKZOOM_X | V2D_LOCKZOOM_Y | V2D_LIMITZOOM | V2D_KEEPASPECT); - ar->v2d.keeptot = V2D_KEEPTOT_BOUNDS; - ar->v2d.minzoom = ar->v2d.maxzoom = 1.0f; + /* keep in sync with console */ + ar->v2d.scroll |= (V2D_SCROLL_RIGHT); + ar->v2d.align |= V2D_ALIGN_NO_NEG_X | V2D_ALIGN_NO_NEG_Y; /* align bottom left */ + ar->v2d.keepofs |= V2D_LOCKOFS_X; + ar->v2d.keepzoom = (V2D_LOCKZOOM_X | V2D_LOCKZOOM_Y | V2D_LIMITZOOM | V2D_KEEPASPECT); + ar->v2d.keeptot = V2D_KEEPTOT_BOUNDS; + ar->v2d.minzoom = ar->v2d.maxzoom = 1.0f; - /* for now, aspect ratio should be maintained, and zoom is clamped within sane default limits */ - //ar->v2d.keepzoom = (V2D_KEEPASPECT|V2D_LIMITZOOM); + /* for now, aspect ratio should be maintained, and zoom is clamped within sane default limits */ + //ar->v2d.keepzoom = (V2D_KEEPASPECT|V2D_LIMITZOOM); - return (SpaceLink *)sinfo; + return (SpaceLink *)sinfo; } /* not spacelink itself */ static void info_free(SpaceLink *UNUSED(sl)) { -// SpaceInfo *sinfo = (SpaceInfo *) sl; - + // SpaceInfo *sinfo = (SpaceInfo *) sl; } - /* spacetype; init callback */ static void info_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa)) { - } static SpaceLink *info_duplicate(SpaceLink *sl) { - SpaceInfo *sinfon = MEM_dupallocN(sl); + SpaceInfo *sinfon = MEM_dupallocN(sl); - /* clear or remove stuff from old */ + /* clear or remove stuff from old */ - return (SpaceLink *)sinfon; + return (SpaceLink *)sinfon; } - - /* add handlers, stuff you only do once or on area/region changes */ static void info_main_region_init(wmWindowManager *wm, ARegion *ar) { - wmKeyMap *keymap; + wmKeyMap *keymap; - /* force it on init, for old files, until it becomes config */ - ar->v2d.scroll = (V2D_SCROLL_RIGHT); + /* force it on init, for old files, until it becomes config */ + ar->v2d.scroll = (V2D_SCROLL_RIGHT); - UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy); + UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy); - /* own keymap */ - keymap = WM_keymap_ensure(wm->defaultconf, "Info", SPACE_INFO, 0); - WM_event_add_keymap_handler(&ar->handlers, keymap); + /* own keymap */ + keymap = WM_keymap_ensure(wm->defaultconf, "Info", SPACE_INFO, 0); + WM_event_add_keymap_handler(&ar->handlers, keymap); } static void info_textview_update_rect(const bContext *C, ARegion *ar) { - SpaceInfo *sinfo = CTX_wm_space_info(C); - View2D *v2d = &ar->v2d; + SpaceInfo *sinfo = CTX_wm_space_info(C); + View2D *v2d = &ar->v2d; - UI_view2d_totRect_set(v2d, ar->winx - 1, info_textview_height(sinfo, ar, CTX_wm_reports(C))); + UI_view2d_totRect_set(v2d, ar->winx - 1, info_textview_height(sinfo, ar, CTX_wm_reports(C))); } static void info_main_region_draw(const bContext *C, ARegion *ar) { - /* draw entirely, view changes should be handled here */ - SpaceInfo *sinfo = CTX_wm_space_info(C); - View2D *v2d = &ar->v2d; - View2DScrollers *scrollers; + /* draw entirely, view changes should be handled here */ + SpaceInfo *sinfo = CTX_wm_space_info(C); + View2D *v2d = &ar->v2d; + View2DScrollers *scrollers; - /* clear and setup matrix */ - UI_ThemeClearColor(TH_BACK); - GPU_clear(GPU_COLOR_BIT); + /* clear and setup matrix */ + UI_ThemeClearColor(TH_BACK); + GPU_clear(GPU_COLOR_BIT); - /* quick way to avoid drawing if not bug enough */ - if (ar->winy < 16) { - return; - } + /* quick way to avoid drawing if not bug enough */ + if (ar->winy < 16) { + return; + } - info_textview_update_rect(C, ar); + info_textview_update_rect(C, ar); - /* worlks best with no view2d matrix set */ - UI_view2d_view_ortho(v2d); + /* worlks best with no view2d matrix set */ + UI_view2d_view_ortho(v2d); - info_textview_main(sinfo, ar, CTX_wm_reports(C)); + info_textview_main(sinfo, ar, CTX_wm_reports(C)); - /* reset view matrix */ - UI_view2d_view_restore(C); + /* reset view matrix */ + UI_view2d_view_restore(C); - /* scrollers */ - scrollers = UI_view2d_scrollers_calc(C, v2d, NULL, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_GRID_CLAMP); - UI_view2d_scrollers_draw(C, v2d, scrollers); - UI_view2d_scrollers_free(scrollers); + /* scrollers */ + scrollers = UI_view2d_scrollers_calc( + C, v2d, NULL, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_GRID_CLAMP); + UI_view2d_scrollers_draw(C, v2d, scrollers); + UI_view2d_scrollers_free(scrollers); } static void info_operatortypes(void) { - WM_operatortype_append(FILE_OT_autopack_toggle); - WM_operatortype_append(FILE_OT_pack_all); - WM_operatortype_append(FILE_OT_pack_libraries); - WM_operatortype_append(FILE_OT_unpack_all); - WM_operatortype_append(FILE_OT_unpack_item); - WM_operatortype_append(FILE_OT_unpack_libraries); - - WM_operatortype_append(FILE_OT_make_paths_relative); - WM_operatortype_append(FILE_OT_make_paths_absolute); - WM_operatortype_append(FILE_OT_report_missing_files); - WM_operatortype_append(FILE_OT_find_missing_files); - WM_operatortype_append(INFO_OT_reports_display_update); - - /* info_report.c */ - WM_operatortype_append(INFO_OT_select_pick); - WM_operatortype_append(INFO_OT_select_all); - WM_operatortype_append(INFO_OT_select_box); - - WM_operatortype_append(INFO_OT_report_replay); - WM_operatortype_append(INFO_OT_report_delete); - WM_operatortype_append(INFO_OT_report_copy); + WM_operatortype_append(FILE_OT_autopack_toggle); + WM_operatortype_append(FILE_OT_pack_all); + WM_operatortype_append(FILE_OT_pack_libraries); + WM_operatortype_append(FILE_OT_unpack_all); + WM_operatortype_append(FILE_OT_unpack_item); + WM_operatortype_append(FILE_OT_unpack_libraries); + + WM_operatortype_append(FILE_OT_make_paths_relative); + WM_operatortype_append(FILE_OT_make_paths_absolute); + WM_operatortype_append(FILE_OT_report_missing_files); + WM_operatortype_append(FILE_OT_find_missing_files); + WM_operatortype_append(INFO_OT_reports_display_update); + + /* info_report.c */ + WM_operatortype_append(INFO_OT_select_pick); + WM_operatortype_append(INFO_OT_select_all); + WM_operatortype_append(INFO_OT_select_box); + + WM_operatortype_append(INFO_OT_report_replay); + WM_operatortype_append(INFO_OT_report_delete); + WM_operatortype_append(INFO_OT_report_copy); } static void info_keymap(struct wmKeyConfig *keyconf) { - WM_keymap_ensure(keyconf, "Window", 0, 0); - WM_keymap_ensure(keyconf, "Info", SPACE_INFO, 0); + WM_keymap_ensure(keyconf, "Window", 0, 0); + WM_keymap_ensure(keyconf, "Info", SPACE_INFO, 0); } /* add handlers, stuff you only do once or on area/region changes */ static void info_header_region_init(wmWindowManager *UNUSED(wm), ARegion *ar) { - ED_region_header_init(ar); + ED_region_header_init(ar); } static void info_header_region_draw(const bContext *C, ARegion *ar) { - ED_region_header(C, ar); + ED_region_header(C, ar); } -static void info_main_region_listener( - wmWindow *UNUSED(win), ScrArea *UNUSED(sa), ARegion *ar, - wmNotifier *wmn, const Scene *UNUSED(scene)) +static void info_main_region_listener(wmWindow *UNUSED(win), + ScrArea *UNUSED(sa), + ARegion *ar, + wmNotifier *wmn, + const Scene *UNUSED(scene)) { - // SpaceInfo *sinfo = sa->spacedata.first; - - /* context changes */ - switch (wmn->category) { - case NC_SPACE: - if (wmn->data == ND_SPACE_INFO_REPORT) { - /* redraw also but only for report view, could do less redraws by checking the type */ - ED_region_tag_redraw(ar); - } - break; - } + // SpaceInfo *sinfo = sa->spacedata.first; + + /* context changes */ + switch (wmn->category) { + case NC_SPACE: + if (wmn->data == ND_SPACE_INFO_REPORT) { + /* redraw also but only for report view, could do less redraws by checking the type */ + ED_region_tag_redraw(ar); + } + break; + } } -static void info_header_listener( - wmWindow *UNUSED(win), ScrArea *UNUSED(sa), ARegion *ar, - wmNotifier *wmn, const Scene *UNUSED(scene)) +static void info_header_listener(wmWindow *UNUSED(win), + ScrArea *UNUSED(sa), + ARegion *ar, + wmNotifier *wmn, + const Scene *UNUSED(scene)) { - /* context changes */ - switch (wmn->category) { - case NC_SCREEN: - if (ELEM(wmn->data, ND_LAYER, ND_ANIMPLAY)) { - ED_region_tag_redraw(ar); - } - break; - case NC_WM: - if (wmn->data == ND_JOB) { - ED_region_tag_redraw(ar); - } - break; - case NC_SCENE: - if (wmn->data == ND_RENDER_RESULT) { - ED_region_tag_redraw(ar); - } - break; - case NC_SPACE: - if (wmn->data == ND_SPACE_INFO) { - ED_region_tag_redraw(ar); - } - break; - case NC_ID: - if (wmn->action == NA_RENAME) { - ED_region_tag_redraw(ar); - } - break; - } - + /* context changes */ + switch (wmn->category) { + case NC_SCREEN: + if (ELEM(wmn->data, ND_LAYER, ND_ANIMPLAY)) { + ED_region_tag_redraw(ar); + } + break; + case NC_WM: + if (wmn->data == ND_JOB) { + ED_region_tag_redraw(ar); + } + break; + case NC_SCENE: + if (wmn->data == ND_RENDER_RESULT) { + ED_region_tag_redraw(ar); + } + break; + case NC_SPACE: + if (wmn->data == ND_SPACE_INFO) { + ED_region_tag_redraw(ar); + } + break; + case NC_ID: + if (wmn->action == NA_RENAME) { + ED_region_tag_redraw(ar); + } + break; + } } -static void info_header_region_message_subscribe( - const bContext *UNUSED(C), - WorkSpace *UNUSED(workspace), Scene *UNUSED(scene), - bScreen *UNUSED(screen), ScrArea *UNUSED(sa), ARegion *ar, - struct wmMsgBus *mbus) +static void info_header_region_message_subscribe(const bContext *UNUSED(C), + WorkSpace *UNUSED(workspace), + Scene *UNUSED(scene), + bScreen *UNUSED(screen), + ScrArea *UNUSED(sa), + ARegion *ar, + struct wmMsgBus *mbus) { - wmMsgSubscribeValue msg_sub_value_region_tag_redraw = { - .owner = ar, - .user_data = ar, - .notify = ED_region_do_msg_notify_tag_redraw, - }; - - WM_msg_subscribe_rna_anon_prop(mbus, Window, view_layer, &msg_sub_value_region_tag_redraw); - WM_msg_subscribe_rna_anon_prop(mbus, ViewLayer, name, &msg_sub_value_region_tag_redraw); + wmMsgSubscribeValue msg_sub_value_region_tag_redraw = { + .owner = ar, + .user_data = ar, + .notify = ED_region_do_msg_notify_tag_redraw, + }; + + WM_msg_subscribe_rna_anon_prop(mbus, Window, view_layer, &msg_sub_value_region_tag_redraw); + WM_msg_subscribe_rna_anon_prop(mbus, ViewLayer, name, &msg_sub_value_region_tag_redraw); } /* only called once, from space/spacetypes.c */ void ED_spacetype_info(void) { - SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype info"); - ARegionType *art; + SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype info"); + ARegionType *art; - st->spaceid = SPACE_INFO; - strncpy(st->name, "Info", BKE_ST_MAXNAME); + st->spaceid = SPACE_INFO; + strncpy(st->name, "Info", BKE_ST_MAXNAME); - st->new = info_new; - st->free = info_free; - st->init = info_init; - st->duplicate = info_duplicate; - st->operatortypes = info_operatortypes; - st->keymap = info_keymap; + st->new = info_new; + st->free = info_free; + st->init = info_init; + st->duplicate = info_duplicate; + st->operatortypes = info_operatortypes; + st->keymap = info_keymap; - /* regions: main window */ - art = MEM_callocN(sizeof(ARegionType), "spacetype info region"); - art->regionid = RGN_TYPE_WINDOW; - art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES; + /* regions: main window */ + art = MEM_callocN(sizeof(ARegionType), "spacetype info region"); + art->regionid = RGN_TYPE_WINDOW; + art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES; - art->init = info_main_region_init; - art->draw = info_main_region_draw; - art->listener = info_main_region_listener; + art->init = info_main_region_init; + art->draw = info_main_region_draw; + art->listener = info_main_region_listener; - BLI_addhead(&st->regiontypes, art); + BLI_addhead(&st->regiontypes, art); - /* regions: header */ - art = MEM_callocN(sizeof(ARegionType), "spacetype info region"); - art->regionid = RGN_TYPE_HEADER; - art->prefsizey = HEADERY; + /* regions: header */ + art = MEM_callocN(sizeof(ARegionType), "spacetype info region"); + art->regionid = RGN_TYPE_HEADER; + art->prefsizey = HEADERY; - art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_HEADER; - art->listener = info_header_listener; - art->message_subscribe = info_header_region_message_subscribe; - art->init = info_header_region_init; - art->draw = info_header_region_draw; + art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_HEADER; + art->listener = info_header_listener; + art->message_subscribe = info_header_region_message_subscribe; + art->init = info_header_region_init; + art->draw = info_header_region_draw; - BLI_addhead(&st->regiontypes, art); + BLI_addhead(&st->regiontypes, art); - BKE_spacetype_register(st); + BKE_spacetype_register(st); } diff --git a/source/blender/editors/space_info/textview.c b/source/blender/editors/space_info/textview.c index 7585cda5e19..c81e7574186 100644 --- a/source/blender/editors/space_info/textview.c +++ b/source/blender/editors/space_info/textview.c @@ -18,7 +18,6 @@ * \ingroup spinfo */ - #include <math.h> #include <string.h> #include <sys/stat.h> @@ -36,344 +35,357 @@ #include "GPU_immediate.h" #include "GPU_state.h" - #include "BKE_text.h" #include "textview.h" static void console_font_begin(const int font_id, const int lheight) { - /* 0.875 is based on: 16 pixels lines get 14 pixel text */ - BLF_size(font_id, 0.875 * lheight, 72); + /* 0.875 is based on: 16 pixels lines get 14 pixel text */ + BLF_size(font_id, 0.875 * lheight, 72); } typedef struct ConsoleDrawContext { - int font_id; - int cwidth; - int lheight; - /** text vertical offset */ - int lofs; - /** number of characters that fit into the width of the console (fixed width) */ - int console_width; - int winx; - int ymin, ymax; - int *xy; // [2] - int *sel; // [2] - /* bottom of view == 0, top of file == combine chars, end of line is lower then start. */ - int *pos_pick; - const int *mval; // [2] - int draw; + int font_id; + int cwidth; + int lheight; + /** text vertical offset */ + int lofs; + /** number of characters that fit into the width of the console (fixed width) */ + int console_width; + int winx; + int ymin, ymax; + int *xy; // [2] + int *sel; // [2] + /* bottom of view == 0, top of file == combine chars, end of line is lower then start. */ + int *pos_pick; + const int *mval; // [2] + int draw; } ConsoleDrawContext; BLI_INLINE void console_step_sel(ConsoleDrawContext *cdc, const int step) { - cdc->sel[0] += step; - cdc->sel[1] += step; + cdc->sel[0] += step; + cdc->sel[1] += step; } -static void console_draw_sel(const char *str, const int sel[2], const int xy[2], const int str_len_draw, - int cwidth, int lheight, const unsigned char bg_sel[4]) +static void console_draw_sel(const char *str, + const int sel[2], + const int xy[2], + const int str_len_draw, + int cwidth, + int lheight, + const unsigned char bg_sel[4]) { - if (sel[0] <= str_len_draw && sel[1] >= 0) { - const int sta = txt_utf8_offset_to_column(str, max_ii(sel[0], 0)); - const int end = txt_utf8_offset_to_column(str, min_ii(sel[1], str_len_draw)); + if (sel[0] <= str_len_draw && sel[1] >= 0) { + const int sta = txt_utf8_offset_to_column(str, max_ii(sel[0], 0)); + const int end = txt_utf8_offset_to_column(str, min_ii(sel[1], str_len_draw)); - GPU_blend(true); - GPU_blend_set_func_separate(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA); + GPU_blend(true); + GPU_blend_set_func_separate( + GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA); - GPUVertFormat *format = immVertexFormat(); - uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT); - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + GPUVertFormat *format = immVertexFormat(); + uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT); + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); - immUniformColor4ubv(bg_sel); - immRecti(pos, xy[0] + (cwidth * sta), xy[1] - 2 + lheight, xy[0] + (cwidth * end), xy[1] - 2); + immUniformColor4ubv(bg_sel); + immRecti(pos, xy[0] + (cwidth * sta), xy[1] - 2 + lheight, xy[0] + (cwidth * end), xy[1] - 2); - immUnbindProgram(); + immUnbindProgram(); - GPU_blend(false); - } + GPU_blend(false); + } } /* warning: allocated memory for 'offsets' must be freed by caller */ static int console_wrap_offsets(const char *str, int len, int width, int *lines, int **offsets) { - int i, end; /* column */ - int j; /* mem */ + int i, end; /* column */ + int j; /* mem */ - *lines = 1; + *lines = 1; - *offsets = MEM_callocN(sizeof(**offsets) * (len * BLI_UTF8_WIDTH_MAX / MAX2(1, width - (BLI_UTF8_WIDTH_MAX - 1)) + 1), - "console_wrap_offsets"); - (*offsets)[0] = 0; + *offsets = MEM_callocN( + sizeof(**offsets) * + (len * BLI_UTF8_WIDTH_MAX / MAX2(1, width - (BLI_UTF8_WIDTH_MAX - 1)) + 1), + "console_wrap_offsets"); + (*offsets)[0] = 0; - for (i = 0, end = width, j = 0; j < len && str[j]; j += BLI_str_utf8_size_safe(str + j)) { - int columns = BLI_str_utf8_char_width_safe(str + j); + for (i = 0, end = width, j = 0; j < len && str[j]; j += BLI_str_utf8_size_safe(str + j)) { + int columns = BLI_str_utf8_char_width_safe(str + j); - if (i + columns > end) { - (*offsets)[*lines] = j; - (*lines)++; + if (i + columns > end) { + (*offsets)[*lines] = j; + (*lines)++; - end = i + width; - } - i += columns; - } - return j; /* return actual length */ + end = i + width; + } + i += columns; + } + return j; /* return actual length */ } /* return 0 if the last line is off the screen * should be able to use this for any string type */ -static int console_draw_string(ConsoleDrawContext *cdc, const char *str, int str_len, - const unsigned char fg[3], const unsigned char bg[3], const unsigned char bg_sel[4]) +static int console_draw_string(ConsoleDrawContext *cdc, + const char *str, + int str_len, + const unsigned char fg[3], + const unsigned char bg[3], + const unsigned char bg_sel[4]) { - int tot_lines; /* total number of lines for wrapping */ - int *offsets; /* offsets of line beginnings for wrapping */ - int y_next; - - str_len = console_wrap_offsets(str, str_len, cdc->console_width, &tot_lines, &offsets); - y_next = cdc->xy[1] + cdc->lheight * tot_lines; - - /* just advance the height */ - if (cdc->draw == 0) { - if (cdc->pos_pick && cdc->mval[1] != INT_MAX && cdc->xy[1] <= cdc->mval[1]) { - if (y_next >= cdc->mval[1]) { - int ofs = 0; - - /* wrap */ - if (tot_lines > 1) { - int iofs = (int)((float)(y_next - cdc->mval[1]) / cdc->lheight); - ofs += offsets[MIN2(iofs, tot_lines - 1)]; - } - - /* last part */ - ofs += txt_utf8_column_to_offset(str + ofs, - (int)floor((float)cdc->mval[0] / cdc->cwidth)); - - CLAMP(ofs, 0, str_len); - *cdc->pos_pick += str_len - ofs; - } - else - *cdc->pos_pick += str_len + 1; - } - - cdc->xy[1] = y_next; - MEM_freeN(offsets); - return 1; - } - else if (y_next < cdc->ymin) { - /* have not reached the drawable area so don't break */ - cdc->xy[1] = y_next; - - /* adjust selection even if not drawing */ - if (cdc->sel[0] != cdc->sel[1]) { - console_step_sel(cdc, -(str_len + 1)); - } - - MEM_freeN(offsets); - return 1; - } - - if (tot_lines > 1) { /* wrap? */ - const int initial_offset = offsets[tot_lines - 1]; - size_t len = str_len - initial_offset; - const char *s = str + initial_offset; - int i; - - int sel_orig[2]; - copy_v2_v2_int(sel_orig, cdc->sel); - - /* invert and swap for wrapping */ - cdc->sel[0] = str_len - sel_orig[1]; - cdc->sel[1] = str_len - sel_orig[0]; - - if (bg) { - GPUVertFormat *format = immVertexFormat(); - uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT); - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); - - immUniformColor3ubv(bg); - immRecti(pos, 0, cdc->xy[1], cdc->winx, (cdc->xy[1] + (cdc->lheight * tot_lines))); - - immUnbindProgram(); - } - - /* last part needs no clipping */ - BLF_position(cdc->font_id, cdc->xy[0], cdc->lofs + cdc->xy[1], 0); - BLF_color3ubv(cdc->font_id, fg); - BLF_draw_mono(cdc->font_id, s, len, cdc->cwidth); - - if (cdc->sel[0] != cdc->sel[1]) { - console_step_sel(cdc, -initial_offset); - /* BLF_color3ub(cdc->font_id, 255, 0, 0); // debug */ - console_draw_sel(s, cdc->sel, cdc->xy, len, cdc->cwidth, cdc->lheight, bg_sel); - } - - cdc->xy[1] += cdc->lheight; - - for (i = tot_lines - 1; i > 0; i--) { - len = offsets[i] - offsets[i - 1]; - s = str + offsets[i - 1]; - - BLF_position(cdc->font_id, cdc->xy[0], cdc->lofs + cdc->xy[1], 0); - BLF_draw_mono(cdc->font_id, s, len, cdc->cwidth); - - if (cdc->sel[0] != cdc->sel[1]) { - console_step_sel(cdc, len); - /* BLF_color3ub(cdc->font_id, 0, 255, 0); // debug */ - console_draw_sel(s, cdc->sel, cdc->xy, len, cdc->cwidth, cdc->lheight, bg_sel); - } - - cdc->xy[1] += cdc->lheight; - - /* check if were out of view bounds */ - if (cdc->xy[1] > cdc->ymax) { - MEM_freeN(offsets); - return 0; - } - } - - copy_v2_v2_int(cdc->sel, sel_orig); - console_step_sel(cdc, -(str_len + 1)); - } - else { /* simple, no wrap */ - - if (bg) { - GPUVertFormat *format = immVertexFormat(); - uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT); - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); - - immUniformColor3ubv(bg); - immRecti(pos, 0, cdc->xy[1], cdc->winx, cdc->xy[1] + cdc->lheight); - - immUnbindProgram(); - } - - BLF_color3ubv(cdc->font_id, fg); - BLF_position(cdc->font_id, cdc->xy[0], cdc->lofs + cdc->xy[1], 0); - BLF_draw_mono(cdc->font_id, str, str_len, cdc->cwidth); - - if (cdc->sel[0] != cdc->sel[1]) { - int isel[2]; - - isel[0] = str_len - cdc->sel[1]; - isel[1] = str_len - cdc->sel[0]; - - /* BLF_color3ub(cdc->font_id, 255, 255, 0); // debug */ - console_draw_sel(str, isel, cdc->xy, str_len, cdc->cwidth, cdc->lheight, bg_sel); - console_step_sel(cdc, -(str_len + 1)); - } + int tot_lines; /* total number of lines for wrapping */ + int *offsets; /* offsets of line beginnings for wrapping */ + int y_next; + + str_len = console_wrap_offsets(str, str_len, cdc->console_width, &tot_lines, &offsets); + y_next = cdc->xy[1] + cdc->lheight * tot_lines; + + /* just advance the height */ + if (cdc->draw == 0) { + if (cdc->pos_pick && cdc->mval[1] != INT_MAX && cdc->xy[1] <= cdc->mval[1]) { + if (y_next >= cdc->mval[1]) { + int ofs = 0; + + /* wrap */ + if (tot_lines > 1) { + int iofs = (int)((float)(y_next - cdc->mval[1]) / cdc->lheight); + ofs += offsets[MIN2(iofs, tot_lines - 1)]; + } + + /* last part */ + ofs += txt_utf8_column_to_offset(str + ofs, (int)floor((float)cdc->mval[0] / cdc->cwidth)); + + CLAMP(ofs, 0, str_len); + *cdc->pos_pick += str_len - ofs; + } + else + *cdc->pos_pick += str_len + 1; + } + + cdc->xy[1] = y_next; + MEM_freeN(offsets); + return 1; + } + else if (y_next < cdc->ymin) { + /* have not reached the drawable area so don't break */ + cdc->xy[1] = y_next; + + /* adjust selection even if not drawing */ + if (cdc->sel[0] != cdc->sel[1]) { + console_step_sel(cdc, -(str_len + 1)); + } + + MEM_freeN(offsets); + return 1; + } + + if (tot_lines > 1) { /* wrap? */ + const int initial_offset = offsets[tot_lines - 1]; + size_t len = str_len - initial_offset; + const char *s = str + initial_offset; + int i; + + int sel_orig[2]; + copy_v2_v2_int(sel_orig, cdc->sel); + + /* invert and swap for wrapping */ + cdc->sel[0] = str_len - sel_orig[1]; + cdc->sel[1] = str_len - sel_orig[0]; + + if (bg) { + GPUVertFormat *format = immVertexFormat(); + uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT); + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + + immUniformColor3ubv(bg); + immRecti(pos, 0, cdc->xy[1], cdc->winx, (cdc->xy[1] + (cdc->lheight * tot_lines))); + + immUnbindProgram(); + } + + /* last part needs no clipping */ + BLF_position(cdc->font_id, cdc->xy[0], cdc->lofs + cdc->xy[1], 0); + BLF_color3ubv(cdc->font_id, fg); + BLF_draw_mono(cdc->font_id, s, len, cdc->cwidth); + + if (cdc->sel[0] != cdc->sel[1]) { + console_step_sel(cdc, -initial_offset); + /* BLF_color3ub(cdc->font_id, 255, 0, 0); // debug */ + console_draw_sel(s, cdc->sel, cdc->xy, len, cdc->cwidth, cdc->lheight, bg_sel); + } + + cdc->xy[1] += cdc->lheight; + + for (i = tot_lines - 1; i > 0; i--) { + len = offsets[i] - offsets[i - 1]; + s = str + offsets[i - 1]; + + BLF_position(cdc->font_id, cdc->xy[0], cdc->lofs + cdc->xy[1], 0); + BLF_draw_mono(cdc->font_id, s, len, cdc->cwidth); + + if (cdc->sel[0] != cdc->sel[1]) { + console_step_sel(cdc, len); + /* BLF_color3ub(cdc->font_id, 0, 255, 0); // debug */ + console_draw_sel(s, cdc->sel, cdc->xy, len, cdc->cwidth, cdc->lheight, bg_sel); + } + + cdc->xy[1] += cdc->lheight; + + /* check if were out of view bounds */ + if (cdc->xy[1] > cdc->ymax) { + MEM_freeN(offsets); + return 0; + } + } + + copy_v2_v2_int(cdc->sel, sel_orig); + console_step_sel(cdc, -(str_len + 1)); + } + else { /* simple, no wrap */ + + if (bg) { + GPUVertFormat *format = immVertexFormat(); + uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT); + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + + immUniformColor3ubv(bg); + immRecti(pos, 0, cdc->xy[1], cdc->winx, cdc->xy[1] + cdc->lheight); + + immUnbindProgram(); + } + + BLF_color3ubv(cdc->font_id, fg); + BLF_position(cdc->font_id, cdc->xy[0], cdc->lofs + cdc->xy[1], 0); + BLF_draw_mono(cdc->font_id, str, str_len, cdc->cwidth); + + if (cdc->sel[0] != cdc->sel[1]) { + int isel[2]; + + isel[0] = str_len - cdc->sel[1]; + isel[1] = str_len - cdc->sel[0]; + + /* BLF_color3ub(cdc->font_id, 255, 255, 0); // debug */ + console_draw_sel(str, isel, cdc->xy, str_len, cdc->cwidth, cdc->lheight, bg_sel); + console_step_sel(cdc, -(str_len + 1)); + } - cdc->xy[1] += cdc->lheight; - - if (cdc->xy[1] > cdc->ymax) { - MEM_freeN(offsets); - return 0; - } - } + cdc->xy[1] += cdc->lheight; + + if (cdc->xy[1] > cdc->ymax) { + MEM_freeN(offsets); + return 0; + } + } - MEM_freeN(offsets); - return 1; + MEM_freeN(offsets); + return 1; } #define CONSOLE_DRAW_MARGIN 4 -int textview_draw(TextViewContext *tvc, const int draw, int mval[2], void **mouse_pick, int *pos_pick) +int textview_draw( + TextViewContext *tvc, const int draw, int mval[2], void **mouse_pick, int *pos_pick) { - ConsoleDrawContext cdc = {0}; - - int x_orig = CONSOLE_DRAW_MARGIN, y_orig = CONSOLE_DRAW_MARGIN + tvc->lheight / 6; - int xy[2], y_prev; - int sel[2] = {-1, -1}; /* defaults disabled */ - unsigned char fg[3], bg[3]; - const int font_id = blf_mono_font; - - console_font_begin(font_id, tvc->lheight); - - xy[0] = x_orig; xy[1] = y_orig; - - if (mval[1] != INT_MAX) { - mval[1] += (tvc->ymin + CONSOLE_DRAW_MARGIN); - } - - if (pos_pick) { - *pos_pick = 0; - } - - /* constants for the sequencer context */ - cdc.font_id = font_id; - cdc.cwidth = (int)BLF_fixed_width(font_id); - assert(cdc.cwidth > 0); - cdc.lheight = tvc->lheight; - cdc.lofs = -BLF_descender(font_id); - /* note, scroll bar must be already subtracted () */ - cdc.console_width = (tvc->winx - (CONSOLE_DRAW_MARGIN * 2)) / cdc.cwidth; - /* avoid divide by zero on small windows */ - if (cdc.console_width < 1) { - cdc.console_width = 1; - } - cdc.winx = tvc->winx - CONSOLE_DRAW_MARGIN; - cdc.ymin = tvc->ymin; - cdc.ymax = tvc->ymax; - cdc.xy = xy; - cdc.sel = sel; - cdc.pos_pick = pos_pick; - cdc.mval = mval; - cdc.draw = draw; - - /* shouldnt be needed */ - tvc->cwidth = cdc.cwidth; - tvc->console_width = cdc.console_width; - tvc->iter_index = 0; - - if (tvc->sel_start != tvc->sel_end) { - sel[0] = tvc->sel_start; - sel[1] = tvc->sel_end; - } - - if (tvc->begin(tvc)) { - unsigned char bg_sel[4] = {0}; - - if (draw && tvc->const_colors) { - tvc->const_colors(tvc, bg_sel); - } - - do { - const char *ext_line; - int ext_len; - int color_flag = 0; - - y_prev = xy[1]; - - if (draw) { - color_flag = tvc->line_color(tvc, fg, bg); - } - - tvc->line_get(tvc, &ext_line, &ext_len); - - if (!console_draw_string(&cdc, ext_line, ext_len, - (color_flag & TVC_LINE_FG) ? fg : NULL, - (color_flag & TVC_LINE_BG) ? bg : NULL, - bg_sel)) - { - /* when drawing, if we pass v2d->cur.ymax, then quit */ - if (draw) { - break; /* past the y limits */ - } - } - - if ((mval[1] != INT_MAX) && (mval[1] >= y_prev && mval[1] <= xy[1])) { - *mouse_pick = (void *)tvc->iter; - break; - } - - tvc->iter_index++; - - } while (tvc->step(tvc)); - } - - tvc->end(tvc); - - xy[1] += tvc->lheight * 2; - - return xy[1] - y_orig; + ConsoleDrawContext cdc = {0}; + + int x_orig = CONSOLE_DRAW_MARGIN, y_orig = CONSOLE_DRAW_MARGIN + tvc->lheight / 6; + int xy[2], y_prev; + int sel[2] = {-1, -1}; /* defaults disabled */ + unsigned char fg[3], bg[3]; + const int font_id = blf_mono_font; + + console_font_begin(font_id, tvc->lheight); + + xy[0] = x_orig; + xy[1] = y_orig; + + if (mval[1] != INT_MAX) { + mval[1] += (tvc->ymin + CONSOLE_DRAW_MARGIN); + } + + if (pos_pick) { + *pos_pick = 0; + } + + /* constants for the sequencer context */ + cdc.font_id = font_id; + cdc.cwidth = (int)BLF_fixed_width(font_id); + assert(cdc.cwidth > 0); + cdc.lheight = tvc->lheight; + cdc.lofs = -BLF_descender(font_id); + /* note, scroll bar must be already subtracted () */ + cdc.console_width = (tvc->winx - (CONSOLE_DRAW_MARGIN * 2)) / cdc.cwidth; + /* avoid divide by zero on small windows */ + if (cdc.console_width < 1) { + cdc.console_width = 1; + } + cdc.winx = tvc->winx - CONSOLE_DRAW_MARGIN; + cdc.ymin = tvc->ymin; + cdc.ymax = tvc->ymax; + cdc.xy = xy; + cdc.sel = sel; + cdc.pos_pick = pos_pick; + cdc.mval = mval; + cdc.draw = draw; + + /* shouldnt be needed */ + tvc->cwidth = cdc.cwidth; + tvc->console_width = cdc.console_width; + tvc->iter_index = 0; + + if (tvc->sel_start != tvc->sel_end) { + sel[0] = tvc->sel_start; + sel[1] = tvc->sel_end; + } + + if (tvc->begin(tvc)) { + unsigned char bg_sel[4] = {0}; + + if (draw && tvc->const_colors) { + tvc->const_colors(tvc, bg_sel); + } + + do { + const char *ext_line; + int ext_len; + int color_flag = 0; + + y_prev = xy[1]; + + if (draw) { + color_flag = tvc->line_color(tvc, fg, bg); + } + + tvc->line_get(tvc, &ext_line, &ext_len); + + if (!console_draw_string(&cdc, + ext_line, + ext_len, + (color_flag & TVC_LINE_FG) ? fg : NULL, + (color_flag & TVC_LINE_BG) ? bg : NULL, + bg_sel)) { + /* when drawing, if we pass v2d->cur.ymax, then quit */ + if (draw) { + break; /* past the y limits */ + } + } + + if ((mval[1] != INT_MAX) && (mval[1] >= y_prev && mval[1] <= xy[1])) { + *mouse_pick = (void *)tvc->iter; + break; + } + + tvc->iter_index++; + + } while (tvc->step(tvc)); + } + + tvc->end(tvc); + + xy[1] += tvc->lheight * 2; + + return xy[1] - y_orig; } diff --git a/source/blender/editors/space_info/textview.h b/source/blender/editors/space_info/textview.h index 40478e30f37..aa0e924b461 100644 --- a/source/blender/editors/space_info/textview.h +++ b/source/blender/editors/space_info/textview.h @@ -22,39 +22,40 @@ #define __TEXTVIEW_H__ typedef struct TextViewContext { - int lheight; - int sel_start, sel_end; - - /* view settings */ - int cwidth; /* shouldnt be needed! */ - int console_width; /* shouldnt be needed! */ - - int winx; - int ymin, ymax; - - /* callbacks */ - int (*begin)(struct TextViewContext *tvc); - void (*end)(struct TextViewContext *tvc); - void *arg1; - void *arg2; - - /* iterator */ - int (*step)(struct TextViewContext *tvc); - int (*line_get)(struct TextViewContext *tvc, const char **, int *); - int (*line_color)(struct TextViewContext *tvc, unsigned char fg[3], unsigned char bg[3]); - /* constant theme colors */ - void (*const_colors)(struct TextViewContext *tvc, unsigned char bg_sel[4]); - void *iter; - int iter_index; - int iter_char; /* char intex, used for multi-line report display */ - int iter_char_next; /* same as above, next \n */ - int iter_tmp; /* internal iterator use */ + int lheight; + int sel_start, sel_end; + + /* view settings */ + int cwidth; /* shouldnt be needed! */ + int console_width; /* shouldnt be needed! */ + + int winx; + int ymin, ymax; + + /* callbacks */ + int (*begin)(struct TextViewContext *tvc); + void (*end)(struct TextViewContext *tvc); + void *arg1; + void *arg2; + + /* iterator */ + int (*step)(struct TextViewContext *tvc); + int (*line_get)(struct TextViewContext *tvc, const char **, int *); + int (*line_color)(struct TextViewContext *tvc, unsigned char fg[3], unsigned char bg[3]); + /* constant theme colors */ + void (*const_colors)(struct TextViewContext *tvc, unsigned char bg_sel[4]); + void *iter; + int iter_index; + int iter_char; /* char intex, used for multi-line report display */ + int iter_char_next; /* same as above, next \n */ + int iter_tmp; /* internal iterator use */ } TextViewContext; -int textview_draw(struct TextViewContext *tvc, const int draw, int mval[2], void **mouse_pick, int *pos_pick); +int textview_draw( + struct TextViewContext *tvc, const int draw, int mval[2], void **mouse_pick, int *pos_pick); -#define TVC_LINE_FG (1<<0) -#define TVC_LINE_BG (1<<1) +#define TVC_LINE_FG (1 << 0) +#define TVC_LINE_BG (1 << 1) -#endif /* __TEXTVIEW_H__ */ +#endif /* __TEXTVIEW_H__ */ |