diff options
Diffstat (limited to 'source/blender/editors/interface/interface_regions.c')
-rw-r--r-- | source/blender/editors/interface/interface_regions.c | 887 |
1 files changed, 499 insertions, 388 deletions
diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 9b450b8fdf4..0b586dd9fca 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -27,8 +27,6 @@ * \ingroup edinterface */ - - #include <stdarg.h> #include <stdlib.h> #include <string.h> @@ -54,7 +52,6 @@ #include "WM_types.h" #include "wm_draw.h" #include "wm_subwindow.h" -#include "wm_window.h" #include "RNA_access.h" @@ -65,7 +62,7 @@ #include "UI_view2d.h" #include "BLF_api.h" -#include "BLF_translation.h" +#include "BLT_translation.h" #include "ED_screen.h" @@ -73,8 +70,9 @@ #include "interface_intern.h" -#define MENU_TOP 8 +#define MENU_TOP (int)(8 * UI_DPI_FAC) #define MENU_PADDING (int)(0.2f * UI_UNIT_Y) +#define MENU_BORDER (int)(0.3f * U.widget_unit) static int rna_property_enum_step(const bContext *C, PointerRNA *ptr, PropertyRNA *prop, int direction) { @@ -109,20 +107,27 @@ static int rna_property_enum_step(const bContext *C, PointerRNA *ptr, PropertyRN return value; } -int ui_step_name_menu(uiBut *but, int direction) +bool ui_but_menu_step_poll(const uiBut *but) { + BLI_assert(but->type == UI_BTYPE_MENU); + /* currenly only RNA buttons */ - if ((but->rnaprop == NULL) || (RNA_property_type(but->rnaprop) != PROP_ENUM)) { - printf("%s: cannot cycle button '%s'", __func__, but->str); - return 0; + return (but->rnaprop && RNA_property_type(but->rnaprop) == PROP_ENUM); +} + +int ui_but_menu_step(uiBut *but, int direction) +{ + if (ui_but_menu_step_poll(but)) { + return rna_property_enum_step(but->block->evil_C, &but->rnapoin, but->rnaprop, direction); } - return rna_property_enum_step(but->block->evil_C, &but->rnapoin, but->rnaprop, direction); + printf("%s: cannot cycle button '%s'\n", __func__, but->str); + return 0; } /******************** Creating Temporary regions ******************/ -static ARegion *ui_add_temporary_region(bScreen *sc) +static ARegion *ui_region_temp_add(bScreen *sc) { ARegion *ar; @@ -135,7 +140,7 @@ static ARegion *ui_add_temporary_region(bScreen *sc) return ar; } -static void ui_remove_temporary_region(bContext *C, bScreen *sc, ARegion *ar) +static void ui_region_temp_remove(bContext *C, bScreen *sc, ARegion *ar) { wmWindow *win = CTX_wm_window(C); if (win) @@ -150,13 +155,14 @@ static void ui_remove_temporary_region(bContext *C, bScreen *sc, ARegion *ar) #define UI_TIP_PAD_FAC 1.3f #define UI_TIP_PADDING (int)(UI_TIP_PAD_FAC * UI_UNIT_Y) +#define UI_TIP_MAXWIDTH 600 #define MAX_TOOLTIP_LINES 8 typedef struct uiTooltipData { rcti bbox; uiFontStyle fstyle; - char lines[MAX_TOOLTIP_LINES][512]; - char header[512], active_info[512]; + char lines[MAX_TOOLTIP_LINES][2048]; + char header[2048], active_info[2048]; struct { enum { UI_TIP_STYLE_NORMAL = 0, @@ -173,6 +179,14 @@ typedef struct uiTooltipData { } color_id : 4; int is_pad : 1; } format[MAX_TOOLTIP_LINES]; + + struct { + unsigned int x_pos; /* x cursor position at the end of the last line */ + unsigned int lines; /* number of lines, 1 or more with word-wrap */ + } line_geom[MAX_TOOLTIP_LINES]; + + int wrap_width; + int totline; int toth, lineh; } uiTooltipData; @@ -182,9 +196,10 @@ typedef struct uiTooltipData { BLI_STATIC_ASSERT(UI_TIP_LC_MAX == UI_TIP_LC_ALERT + 1, "invalid lc-max"); BLI_STATIC_ASSERT(sizeof(((uiTooltipData *)NULL)->format[0]) <= sizeof(int), "oversize"); -static void rgb_tint(float col[3], - float h, float h_strength, - float v, float v_strength) +static void rgb_tint( + float col[3], + float h, float h_strength, + float v, float v_strength) { float col_hsv_from[3]; float col_hsv_to[3]; @@ -225,7 +240,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *ar) wmOrtho2_region_ui(ar); /* draw background */ - ui_draw_tooltip_background(UI_GetStyle(), NULL, &bbox); + ui_draw_tooltip_background(UI_style_get(), NULL, &bbox); /* set background_color */ rgb_uchar_to_float(background_color, (const unsigned char *)theme->inner); @@ -244,69 +259,83 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *ar) /* tone_fg = rgb_to_grayscale(main_color); */ /* mix the colors */ - rgb_tint(value_color, 0.0f, 0.0f, tone_bg, 0.2f); /* light grey */ + rgb_tint(value_color, 0.0f, 0.0f, tone_bg, 0.2f); /* light gray */ rgb_tint(active_color, 0.6f, 0.2f, tone_bg, 0.2f); /* light blue */ - rgb_tint(normal_color, 0.0f, 0.0f, tone_bg, 0.4f); /* grey */ - rgb_tint(python_color, 0.0f, 0.0f, tone_bg, 0.5f); /* dark grey */ + rgb_tint(normal_color, 0.0f, 0.0f, tone_bg, 0.4f); /* gray */ + rgb_tint(python_color, 0.0f, 0.0f, tone_bg, 0.5f); /* dark gray */ rgb_tint(alert_color, 0.0f, 0.8f, tone_bg, 0.1f); /* red */ /* draw text */ + BLF_wordwrap(data->fstyle.uifont_id, data->wrap_width); + BLF_wordwrap(blf_mono_font, data->wrap_width); bbox.xmin += 0.5f * pad_px; /* add padding to the text */ - bbox.ymax -= 0.5f * (BLI_rcti_size_y(&bbox) - data->toth); - bbox.ymin = bbox.ymax - data->lineh; + bbox.ymax -= 0.25f * pad_px; for (i = 0; i < data->totline; i++) { + bbox.ymin = bbox.ymax - (data->lineh * data->line_geom[i].lines); if (data->format[i].style == UI_TIP_STYLE_HEADER) { /* draw header and active data (is done here to be able to change color) */ uiFontStyle fstyle_header = data->fstyle; - float xofs; + float xofs, yofs; /* override text-style */ fstyle_header.shadow = 1; - fstyle_header.shadowcolor = rgb_to_luma(tip_colors[UI_TIP_LC_MAIN]); + fstyle_header.shadowcolor = rgb_to_grayscale(tip_colors[UI_TIP_LC_MAIN]); fstyle_header.shadx = fstyle_header.shady = 0; fstyle_header.shadowalpha = 1.0f; + fstyle_header.word_wrap = true; - uiStyleFontSet(&fstyle_header); + UI_fontstyle_set(&fstyle_header); glColor3fv(tip_colors[UI_TIP_LC_MAIN]); - uiStyleFontDraw(&fstyle_header, &bbox, data->header); + UI_fontstyle_draw(&fstyle_header, &bbox, data->header); - xofs = BLF_width(fstyle_header.uifont_id, data->header, sizeof(data->header)); + /* offset to the end of the last line */ + xofs = data->line_geom[i].x_pos; + yofs = data->lineh * (data->line_geom[i].lines - 1); bbox.xmin += xofs; + bbox.ymax -= yofs; glColor3fv(tip_colors[UI_TIP_LC_ACTIVE]); - uiStyleFontDraw(&data->fstyle, &bbox, data->active_info); + fstyle_header.shadow = 0; + UI_fontstyle_draw(&fstyle_header, &bbox, data->active_info); + /* undo offset */ bbox.xmin -= xofs; + bbox.ymax += yofs; } else if (data->format[i].style == UI_TIP_STYLE_MONO) { uiFontStyle fstyle_mono = data->fstyle; fstyle_mono.uifont_id = blf_mono_font; + fstyle_mono.word_wrap = true; - uiStyleFontSet(&fstyle_mono); + UI_fontstyle_set(&fstyle_mono); /* XXX, needed because we dont have mono in 'U.uifonts' */ BLF_size(fstyle_mono.uifont_id, fstyle_mono.points * U.pixelsize, U.dpi); glColor3fv(tip_colors[data->format[i].color_id]); - uiStyleFontDraw(&fstyle_mono, &bbox, data->lines[i]); + UI_fontstyle_draw(&fstyle_mono, &bbox, data->lines[i]); } else { + uiFontStyle fstyle_normal = data->fstyle; BLI_assert(data->format[i].style == UI_TIP_STYLE_NORMAL); + fstyle_normal.word_wrap = true; + /* draw remaining data */ - uiStyleFontSet(&data->fstyle); + UI_fontstyle_set(&fstyle_normal); glColor3fv(tip_colors[data->format[i].color_id]); - uiStyleFontDraw(&data->fstyle, &bbox, data->lines[i]); + UI_fontstyle_draw(&fstyle_normal, &bbox, data->lines[i]); } + + bbox.ymax -= data->lineh * data->line_geom[i].lines; + if ((i + 1 != data->totline) && data->format[i + 1].is_pad) { - bbox.ymax -= data->lineh * UI_TIP_PAD_FAC; - bbox.ymin -= data->lineh * UI_TIP_PAD_FAC; - } - else { - bbox.ymax -= data->lineh; - bbox.ymin -= data->lineh; + bbox.ymax -= data->lineh * (UI_TIP_PAD_FAC - 1); } } + BLF_disable(data->fstyle.uifont_id, BLF_WORD_WRAP); + BLF_disable(blf_mono_font, BLF_WORD_WRAP); + if (multisample_enabled) glEnable(GL_MULTISAMPLE_ARB); } @@ -324,7 +353,7 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but) { const float pad_px = UI_TIP_PADDING; wmWindow *win = CTX_wm_window(C); - uiStyle *style = UI_GetStyle(); + uiStyle *style = UI_style_get(); static ARegionType type; ARegion *ar; uiTooltipData *data; @@ -332,10 +361,11 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but) char buf[512]; /* aspect values that shrink text are likely unreadable */ const float aspect = min_ff(1.0f, but->block->aspect); - float fonth, fontw; - int winx, ofsx, ofsy, w = 0, h, i; + int fonth, fontw; + int winx, ofsx, ofsy, h, i; rctf rect_fl; rcti rect_i; + int font_flag = 0; uiStringInfo but_tip = {BUT_GET_TIP, NULL}; uiStringInfo enum_label = {BUT_GET_RNAENUM_LABEL, NULL}; @@ -351,7 +381,7 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but) /* create tooltip data */ data = MEM_callocN(sizeof(uiTooltipData), "uiTooltipData"); - uiButGetStrInfo(C, but, &but_tip, &enum_label, &enum_tip, &op_keymap, &prop_keymap, &rna_struct, &rna_prop, NULL); + UI_but_string_info_get(C, but, &but_tip, &enum_label, &enum_tip, &op_keymap, &prop_keymap, &rna_struct, &rna_prop, NULL); /* Tip */ if (but_tip.strinfo) { @@ -364,8 +394,9 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but) data->totline++; /* special case enum rna buttons */ - if ((but->type & ROW) && but->rnaprop && RNA_property_flag(but->rnaprop) & PROP_ENUM_FLAG) { - BLI_strncpy(data->lines[data->totline], IFACE_("(Shift-click to select multiple)"), sizeof(data->lines[0])); + if ((but->type & UI_BTYPE_ROW) && but->rnaprop && RNA_property_flag(but->rnaprop) & PROP_ENUM_FLAG) { + BLI_strncpy(data->lines[data->totline], IFACE_("(Shift-Click/Drag to select multiple)"), + sizeof(data->lines[0])); data->format[data->totline].color_id = UI_TIP_LC_NORMAL; data->totline++; @@ -396,11 +427,11 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but) data->totline++; } - if (ELEM(but->type, TEX, SEARCH_MENU, SEARCH_MENU_UNLINK)) { + if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU)) { /* better not show the value of a password */ if ((but->rnaprop && (RNA_property_subtype(but->rnaprop) == PROP_PASSWORD)) == 0) { /* full string */ - ui_get_but_string(but, buf, sizeof(buf)); + ui_but_string_get(but, buf, sizeof(buf)); if (buf[0]) { BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), TIP_("Value: %s"), buf); data->format[data->totline].is_pad = true; @@ -411,7 +442,7 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but) } if (but->rnaprop) { - int unit_type = uiButGetUnitType(but); + int unit_type = UI_but_unit_type_get(but); if (unit_type == PROP_UNIT_ROTATION) { if (RNA_property_type(but->rnaprop) == PROP_FLOAT) { @@ -445,7 +476,7 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but) else if (but->optype) { PointerRNA *opptr; char *str; - opptr = uiButGetOperatorPtrRNA(but); /* allocated when needed, the button owns it */ + opptr = UI_but_operator_ptr_get(but); /* allocated when needed, the button owns it */ /* so the context is passed to itemf functions (some py itemf functions use it) */ WM_operator_properties_sanitize(opptr, false); @@ -513,9 +544,10 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but) } if (data_path) { + const char *data_delim = (data_path[0] == '[') ? "" : "."; BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), - "%s.%s", /* no need to translate */ - id_path, data_path); + "%s%s%s", /* no need to translate */ + id_path, data_delim, data_path); MEM_freeN(data_path); } else if (prop) { @@ -556,7 +588,7 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but) } /* create area region */ - ar = ui_add_temporary_region(CTX_wm_screen(C)); + ar = ui_region_temp_add(CTX_wm_screen(C)); memset(&type, 0, sizeof(ARegionType)); type.draw = ui_tooltip_region_draw_cb; @@ -568,7 +600,18 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but) data->fstyle = style->widget; /* copy struct */ ui_fontscale(&data->fstyle.points, aspect); - uiStyleFontSet(&data->fstyle); + UI_fontstyle_set(&data->fstyle); + + data->wrap_width = min_ii(UI_TIP_MAXWIDTH * U.pixelsize / aspect, WM_window_pixels_x(win) - (UI_TIP_PADDING * 2)); + + font_flag |= BLF_WORD_WRAP; + if (data->fstyle.kerning == 1) { + font_flag |= BLF_KERNING_DEFAULT; + } + BLF_enable(data->fstyle.uifont_id, font_flag); + BLF_enable(blf_mono_font, font_flag); + BLF_wordwrap(data->fstyle.uifont_id, data->wrap_width); + BLF_wordwrap(blf_mono_font, data->wrap_width); /* these defines tweaked depending on font */ #define TIP_BORDER_X (16.0f / aspect) @@ -577,33 +620,43 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but) h = BLF_height_max(data->fstyle.uifont_id); for (i = 0, fontw = 0, fonth = 0; i < data->totline; i++) { + struct ResultBLF info; + int w, x_pos = 0; + if (data->format[i].style == UI_TIP_STYLE_HEADER) { - w = BLF_width(data->fstyle.uifont_id, data->header, sizeof(data->header)); - if (enum_label.strinfo) - w += BLF_width(data->fstyle.uifont_id, data->active_info, sizeof(data->active_info)); + w = BLF_width_ex(data->fstyle.uifont_id, data->header, sizeof(data->header), &info); + if (enum_label.strinfo) { + x_pos = info.width + (U.widget_unit / 2); + w = max_ii(w, x_pos + BLF_width(data->fstyle.uifont_id, data->active_info, sizeof(data->active_info))); + } } else if (data->format[i].style == UI_TIP_STYLE_MONO) { BLF_size(blf_mono_font, data->fstyle.points * U.pixelsize, U.dpi); - w = BLF_width(blf_mono_font, data->lines[i], sizeof(data->lines[i])); + w = BLF_width_ex(blf_mono_font, data->lines[i], sizeof(data->lines[i]), &info); } else { BLI_assert(data->format[i].style == UI_TIP_STYLE_NORMAL); - w = BLF_width(data->fstyle.uifont_id, data->lines[i], sizeof(data->lines[i])); + + w = BLF_width_ex(data->fstyle.uifont_id, data->lines[i], sizeof(data->lines[i]), &info); } - fontw = max_ff(fontw, (float)w); + fontw = max_ii(fontw, w); + fonth += h * info.lines; if ((i + 1 != data->totline) && data->format[i + 1].is_pad) { - fonth += h * UI_TIP_PAD_FAC; - } - else { - fonth += h; + fonth += h * (UI_TIP_PAD_FAC - 1); } + + data->line_geom[i].lines = info.lines; + data->line_geom[i].x_pos = x_pos; } //fontw *= aspect; + BLF_disable(data->fstyle.uifont_id, font_flag); + BLF_disable(blf_mono_font, font_flag); + ar->regiondata = data; data->toth = fonth; @@ -668,18 +721,18 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but) /* widget rect, in region coords */ { - int width = UI_ThemeMenuShadowWidth(); + const int margin = UI_POPUP_MARGIN; - data->bbox.xmin = width; - data->bbox.xmax = BLI_rcti_size_x(&rect_i) - width; - data->bbox.ymin = width; + data->bbox.xmin = margin; + data->bbox.xmax = BLI_rcti_size_x(&rect_i) - margin; + data->bbox.ymin = margin; data->bbox.ymax = BLI_rcti_size_y(&rect_i); /* region bigger for shadow */ - ar->winrct.xmin = rect_i.xmin - width; - ar->winrct.xmax = rect_i.xmax + width; - ar->winrct.ymin = rect_i.ymin - width; - ar->winrct.ymax = rect_i.ymax + width; + ar->winrct.xmin = rect_i.xmin - margin; + ar->winrct.xmax = rect_i.xmax + margin; + ar->winrct.ymin = rect_i.ymin - margin; + ar->winrct.ymax = rect_i.ymax + margin; } /* adds subwindow */ @@ -693,7 +746,7 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but) void ui_tooltip_free(bContext *C, ARegion *ar) { - ui_remove_temporary_region(C, CTX_wm_screen(C), ar); + ui_region_temp_remove(C, CTX_wm_screen(C), ar); } @@ -728,11 +781,11 @@ typedef struct uiSearchboxData { /* exported for use by search callbacks */ /* returns zero if nothing to add */ -bool uiSearchItemAdd(uiSearchItems *items, const char *name, void *poin, int iconid) +bool UI_search_item_add(uiSearchItems *items, const char *name, void *poin, int iconid) { /* hijack for autocomplete */ if (items->autocpl) { - autocomplete_do_name(items->autocpl, name); + UI_autocomplete_update_name(items->autocpl, name); return true; } @@ -767,17 +820,17 @@ bool uiSearchItemAdd(uiSearchItems *items, const char *name, void *poin, int ico return true; } -int uiSearchBoxHeight(void) +int UI_searchbox_size_y(void) { return SEARCH_ITEMS * UI_UNIT_Y + 2 * MENU_TOP; } -int uiSearchBoxWidth(void) +int UI_searchbox_size_x(void) { return 12 * UI_UNIT_X; } -int uiSearchItemFindIndex(uiSearchItems *items, const char *name) +int UI_search_items_find_index(uiSearchItems *items, const char *name) { int i; for (i = 0; i < items->totitem; i++) { @@ -817,7 +870,7 @@ static void ui_searchbox_select(bContext *C, ARegion *ar, uiBut *but, int step) } else { /* only let users step into an 'unset' state for unlink buttons */ - data->active = (but->type == SEARCH_MENU_UNLINK) ? -1 : 0; + data->active = (but->flag & UI_BUT_SEARCH_UNLINK) ? -1 : 0; } } @@ -828,8 +881,8 @@ static void ui_searchbox_butrect(rcti *r_rect, uiSearchboxData *data, int itemnr { /* thumbnail preview */ if (data->preview) { - int butw = BLI_rcti_size_x(&data->bbox) / data->prv_cols; - int buth = (BLI_rcti_size_y(&data->bbox) - 2 * MENU_TOP) / data->prv_rows; + int butw = (BLI_rcti_size_x(&data->bbox) - 2 * MENU_BORDER) / data->prv_cols; + int buth = (BLI_rcti_size_y(&data->bbox) - 2 * MENU_BORDER) / data->prv_rows; int row, col; *r_rect = data->bbox; @@ -837,10 +890,10 @@ static void ui_searchbox_butrect(rcti *r_rect, uiSearchboxData *data, int itemnr col = itemnr % data->prv_cols; row = itemnr / data->prv_cols; - r_rect->xmin += col * butw; + r_rect->xmin += MENU_BORDER + (col * butw); r_rect->xmax = r_rect->xmin + butw; - r_rect->ymax = data->bbox.ymax - MENU_TOP - (row * buth); + r_rect->ymax -= MENU_BORDER + (row * buth); r_rect->ymin = r_rect->ymax - buth; } /* list view */ @@ -860,7 +913,7 @@ static void ui_searchbox_butrect(rcti *r_rect, uiSearchboxData *data, int itemnr int ui_searchbox_find_index(ARegion *ar, const char *name) { uiSearchboxData *data = ar->regiondata; - return uiSearchItemFindIndex(&data->items, name); + return UI_search_items_find_index(&data->items, name); } /* x and y in screencoords */ @@ -888,7 +941,7 @@ bool ui_searchbox_apply(uiBut *but, ARegion *ar) return true; } - else if (but->type == SEARCH_MENU_UNLINK) { + else if (but->flag & UI_BUT_SEARCH_UNLINK) { /* It is valid for _UNLINK flavor to have no active element (it's a valid way to unlink). */ but->editstr[0] = '\0'; @@ -1014,11 +1067,11 @@ int ui_searchbox_autocomplete(bContext *C, ARegion *ar, uiBut *but, char *str) int match = AUTOCOMPLETE_NO_MATCH; if (str[0]) { - data->items.autocpl = autocomplete_begin(str, ui_get_but_string_max_length(but)); + data->items.autocpl = UI_autocomplete_begin(str, ui_but_string_get_max_length(but)); but->search_func(C, but->search_arg, but->editstr, &data->items); - match = autocomplete_end(data->items.autocpl, str); + match = UI_autocomplete_end(data->items.autocpl, str); data->items.autocpl = NULL; } @@ -1046,14 +1099,8 @@ static void ui_searchbox_region_draw_cb(const bContext *UNUSED(C), ARegion *ar) ui_searchbox_butrect(&rect, data, a); /* widget itself */ - if (data->preview) { - ui_draw_preview_item(&data->fstyle, &rect, data->items.names[a], data->items.icons[a], - (a == data->active) ? UI_ACTIVE : 0); - } - else { - ui_draw_menu_item(&data->fstyle, &rect, data->items.names[a], data->items.icons[a], - (a == data->active) ? UI_ACTIVE : 0, data->use_sep); - } + ui_draw_preview_item(&data->fstyle, &rect, data->items.names[a], data->items.icons[a], + (a == data->active) ? UI_ACTIVE : 0); } /* indicate more */ @@ -1118,18 +1165,19 @@ static void ui_searchbox_region_free_cb(ARegion *ar) ARegion *ui_searchbox_create(bContext *C, ARegion *butregion, uiBut *but) { wmWindow *win = CTX_wm_window(C); - uiStyle *style = UI_GetStyle(); + uiStyle *style = UI_style_get(); static ARegionType type; ARegion *ar; uiSearchboxData *data; float aspect = but->block->aspect; rctf rect_fl; rcti rect_i; + const int margin = UI_POPUP_MARGIN; int winx /*, winy */, ofsx, ofsy; int i; /* create area region */ - ar = ui_add_temporary_region(CTX_wm_screen(C)); + ar = ui_region_temp_add(CTX_wm_screen(C)); memset(&type, 0, sizeof(ARegionType)); type.draw = ui_searchbox_region_draw_cb; @@ -1144,7 +1192,7 @@ ARegion *ui_searchbox_create(bContext *C, ARegion *butregion, uiBut *but) data->fstyle = style->widget; /* copy struct */ data->fstyle.align = UI_STYLE_TEXT_CENTER; ui_fontscale(&data->fstyle.points, aspect); - uiStyleFontSet(&data->fstyle); + UI_fontstyle_set(&data->fstyle); ar->regiondata = data; @@ -1166,35 +1214,33 @@ ARegion *ui_searchbox_create(bContext *C, ARegion *butregion, uiBut *but) /* compute position */ if (but->block->flag & UI_BLOCK_SEARCH_MENU) { - int width = UI_ThemeMenuShadowWidth(); + const int search_but_h = BLI_rctf_size_y(&but->rect) + 10; /* this case is search menu inside other menu */ /* we copy region size */ ar->winrct = butregion->winrct; /* widget rect, in region coords */ - data->bbox.xmin = width; - data->bbox.xmax = BLI_rcti_size_x(&ar->winrct) - width; - /* Do not use shadow width for height, gives insane margin with big shadows, and issue T41548 with small ones */ - data->bbox.ymin = 8 * UI_DPI_FAC; - data->bbox.ymax = BLI_rcti_size_y(&ar->winrct) - 8 * UI_DPI_FAC; + data->bbox.xmin = margin; + data->bbox.xmax = BLI_rcti_size_x(&ar->winrct) - margin; + data->bbox.ymin = margin; + data->bbox.ymax = BLI_rcti_size_y(&ar->winrct) - margin; /* check if button is lower half */ if (but->rect.ymax < BLI_rctf_cent_y(&but->block->rect)) { - data->bbox.ymin += BLI_rctf_size_y(&but->rect); + data->bbox.ymin += search_but_h; } else { - data->bbox.ymax -= BLI_rctf_size_y(&but->rect); + data->bbox.ymax -= search_but_h; } } else { - const int searchbox_width = uiSearchBoxWidth(); - const int shadow_width = UI_ThemeMenuShadowWidth(); + const int searchbox_width = UI_searchbox_size_x(); rect_fl.xmin = but->rect.xmin - 5; /* align text with button */ rect_fl.xmax = but->rect.xmax + 5; /* symmetrical */ rect_fl.ymax = but->rect.ymin; - rect_fl.ymin = rect_fl.ymax - uiSearchBoxHeight(); + rect_fl.ymin = rect_fl.ymax - UI_searchbox_size_y(); ofsx = (but->block->panel) ? but->block->panel->ofsx : 0; ofsy = (but->block->panel) ? but->block->panel->ofsy : 0; @@ -1244,15 +1290,15 @@ ARegion *ui_searchbox_create(bContext *C, ARegion *butregion, uiBut *but) } /* widget rect, in region coords */ - data->bbox.xmin = shadow_width; - data->bbox.xmax = BLI_rcti_size_x(&rect_i) + shadow_width; - data->bbox.ymin = shadow_width; - data->bbox.ymax = BLI_rcti_size_y(&rect_i) + shadow_width; + data->bbox.xmin = margin; + data->bbox.xmax = BLI_rcti_size_x(&rect_i) + margin; + data->bbox.ymin = margin; + data->bbox.ymax = BLI_rcti_size_y(&rect_i) + margin; /* region bigger for shadow */ - ar->winrct.xmin = rect_i.xmin - shadow_width; - ar->winrct.xmax = rect_i.xmax + shadow_width; - ar->winrct.ymin = rect_i.ymin - shadow_width; + ar->winrct.xmin = rect_i.xmin - margin; + ar->winrct.xmax = rect_i.xmax + margin; + ar->winrct.ymin = rect_i.ymin - margin; ar->winrct.ymax = rect_i.ymax; } @@ -1282,12 +1328,12 @@ ARegion *ui_searchbox_create(bContext *C, ARegion *butregion, uiBut *but) void ui_searchbox_free(bContext *C, ARegion *ar) { - ui_remove_temporary_region(C, CTX_wm_screen(C), ar); + ui_region_temp_remove(C, CTX_wm_screen(C), ar); } /* sets red alert if button holds a string it can't find */ /* XXX weak: search_func adds all partial matches... */ -void ui_but_search_test(uiBut *but) +void ui_but_search_refresh(uiBut *but) { uiSearchItems *items; int x1; @@ -1311,11 +1357,11 @@ void ui_but_search_test(uiBut *but) /* only redalert when we are sure of it, this can miss cases when >10 matches */ if (items->totitem == 0) { - uiButSetFlag(but, UI_BUT_REDALERT); + UI_but_flag_enable(but, UI_BUT_REDALERT); } else if (items->more == 0) { - if (uiSearchItemFindIndex(items, but->drawstr) == -1) { - uiButSetFlag(but, UI_BUT_REDALERT); + if (UI_search_items_find_index(items, but->drawstr) == -1) { + UI_but_flag_enable(but, UI_BUT_REDALERT); } } @@ -1343,7 +1389,7 @@ static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but, ui_block_to_window_rctf(butregion, but->block, &butrct, &but->rect); /* widget_roundbox_set has this correction too, keep in sync */ - if (but->type != PULLDOWN) { + if (but->type != UI_BTYPE_PULLDOWN) { if (but->drawflag & UI_BUT_ALIGN_TOP) butrct.ymax += U.pixelsize; if (but->drawflag & UI_BUT_ALIGN_LEFT) @@ -1377,7 +1423,7 @@ static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but, /* aspect /= (float)xsize;*/ /*UNUSED*/ { - int left = 0, right = 0, top = 0, down = 0; + bool left = 0, right = 0, top = 0, down = 0; int winx, winy; // int offscreen; @@ -1385,8 +1431,12 @@ static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but, winy = WM_window_pixels_y(window); // wm_window_get_size(window, &winx, &winy); - if (block->direction & UI_CENTER) center = ysize / 2; - else center = 0; + if (block->direction & UI_DIR_CENTER_Y) { + center = ysize / 2; + } + else { + center = 0; + } /* check if there's space at all */ if (butrct.xmin - xsize > 0.0f) left = 1; @@ -1401,69 +1451,66 @@ static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but, down = 1; } - dir1 = block->direction & UI_DIRECTION; + dir1 = (block->direction & UI_DIR_ALL); /* secundary directions */ - if (dir1 & (UI_TOP | UI_DOWN)) { - if (dir1 & UI_LEFT) dir2 = UI_LEFT; - else if (dir1 & UI_RIGHT) dir2 = UI_RIGHT; - dir1 &= (UI_TOP | UI_DOWN); + if (dir1 & (UI_DIR_UP | UI_DIR_DOWN)) { + if (dir1 & UI_DIR_LEFT) dir2 = UI_DIR_LEFT; + else if (dir1 & UI_DIR_RIGHT) dir2 = UI_DIR_RIGHT; + dir1 &= (UI_DIR_UP | UI_DIR_DOWN); } - if ((dir2 == 0) && (dir1 == UI_LEFT || dir1 == UI_RIGHT)) dir2 = UI_DOWN; - if ((dir2 == 0) && (dir1 == UI_TOP || dir1 == UI_DOWN)) dir2 = UI_LEFT; + if ((dir2 == 0) && (dir1 == UI_DIR_LEFT || dir1 == UI_DIR_RIGHT)) dir2 = UI_DIR_DOWN; + if ((dir2 == 0) && (dir1 == UI_DIR_UP || dir1 == UI_DIR_DOWN)) dir2 = UI_DIR_LEFT; /* no space at all? don't change */ if (left || right) { - if (dir1 == UI_LEFT && left == 0) dir1 = UI_RIGHT; - if (dir1 == UI_RIGHT && right == 0) dir1 = UI_LEFT; + if (dir1 == UI_DIR_LEFT && left == 0) dir1 = UI_DIR_RIGHT; + if (dir1 == UI_DIR_RIGHT && right == 0) dir1 = UI_DIR_LEFT; /* this is aligning, not append! */ - if (dir2 == UI_LEFT && right == 0) dir2 = UI_RIGHT; - if (dir2 == UI_RIGHT && left == 0) dir2 = UI_LEFT; + if (dir2 == UI_DIR_LEFT && right == 0) dir2 = UI_DIR_RIGHT; + if (dir2 == UI_DIR_RIGHT && left == 0) dir2 = UI_DIR_LEFT; } if (down || top) { - if (dir1 == UI_TOP && top == 0) dir1 = UI_DOWN; - if (dir1 == UI_DOWN && down == 0) dir1 = UI_TOP; - if (dir2 == UI_TOP && top == 0) dir2 = UI_DOWN; - if (dir2 == UI_DOWN && down == 0) dir2 = UI_TOP; + if (dir1 == UI_DIR_UP && top == 0) dir1 = UI_DIR_DOWN; + if (dir1 == UI_DIR_DOWN && down == 0) dir1 = UI_DIR_UP; + BLI_assert(dir2 != UI_DIR_UP); +// if (dir2 == UI_DIR_UP && top == 0) dir2 = UI_DIR_DOWN; + if (dir2 == UI_DIR_DOWN && down == 0) dir2 = UI_DIR_UP; } - if (dir1 == UI_LEFT) { + if (dir1 == UI_DIR_LEFT) { xof = butrct.xmin - block->rect.xmax; - if (dir2 == UI_TOP) yof = butrct.ymin - block->rect.ymin - center - MENU_PADDING; - else yof = butrct.ymax - block->rect.ymax + center + MENU_PADDING; + if (dir2 == UI_DIR_UP) yof = butrct.ymin - block->rect.ymin - center - MENU_PADDING; + else yof = butrct.ymax - block->rect.ymax + center + MENU_PADDING; } - else if (dir1 == UI_RIGHT) { + else if (dir1 == UI_DIR_RIGHT) { xof = butrct.xmax - block->rect.xmin; - if (dir2 == UI_TOP) yof = butrct.ymin - block->rect.ymin - center - MENU_PADDING; - else yof = butrct.ymax - block->rect.ymax + center + MENU_PADDING; + if (dir2 == UI_DIR_UP) yof = butrct.ymin - block->rect.ymin - center - MENU_PADDING; + else yof = butrct.ymax - block->rect.ymax + center + MENU_PADDING; } - else if (dir1 == UI_TOP) { + else if (dir1 == UI_DIR_UP) { yof = butrct.ymax - block->rect.ymin; - if (dir2 == UI_RIGHT) xof = butrct.xmax - block->rect.xmax; - else xof = butrct.xmin - block->rect.xmin; + if (dir2 == UI_DIR_RIGHT) xof = butrct.xmax - block->rect.xmax; + else xof = butrct.xmin - block->rect.xmin; /* changed direction? */ if ((dir1 & block->direction) == 0) { - if (block->direction & UI_SHIFT_FLIPPED) - xof += dir2 == UI_LEFT ? 25 : -25; - uiBlockFlipOrder(block); + UI_block_order_flip(block); } } - else if (dir1 == UI_DOWN) { + else if (dir1 == UI_DIR_DOWN) { yof = butrct.ymin - block->rect.ymax; - if (dir2 == UI_RIGHT) xof = butrct.xmax - block->rect.xmax; - else xof = butrct.xmin - block->rect.xmin; + if (dir2 == UI_DIR_RIGHT) xof = butrct.xmax - block->rect.xmax; + else xof = butrct.xmin - block->rect.xmin; /* changed direction? */ if ((dir1 & block->direction) == 0) { - if (block->direction & UI_SHIFT_FLIPPED) - xof += dir2 == UI_LEFT ? 25 : -25; - uiBlockFlipOrder(block); + UI_block_order_flip(block); } } /* and now we handle the exception; no space below or to top */ if (top == 0 && down == 0) { - if (dir1 == UI_LEFT || dir1 == UI_RIGHT) { + if (dir1 == UI_DIR_LEFT || dir1 == UI_DIR_RIGHT) { /* align with bottom of screen */ // yof = ysize; (not with menu scrolls) } @@ -1471,7 +1518,7 @@ static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but, /* or no space left or right */ if (left == 0 && right == 0) { - if (dir1 == UI_TOP || dir1 == UI_DOWN) { + if (dir1 == UI_DIR_UP || dir1 == UI_DIR_DOWN) { /* align with left size of screen */ xof = -block->rect.xmin + 5; } @@ -1493,8 +1540,8 @@ static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but, BLI_rctf_translate(&bt->rect, xof, yof); - /* ui_check_but recalculates drawstring size in pixels */ - ui_check_but(bt); + /* ui_but_update recalculates drawstring size in pixels */ + ui_but_update(bt); } BLI_rctf_translate(&block->rect, xof, yof); @@ -1522,8 +1569,8 @@ static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but, /* exception for switched pulldowns... */ if (dir1 && (dir1 & block->direction) == 0) { - if (dir2 == UI_RIGHT) block->safety.xmax = block->rect.xmax + 3; - if (dir2 == UI_LEFT) block->safety.xmin = block->rect.xmin - 3; + if (dir2 == UI_DIR_RIGHT) block->safety.xmax = block->rect.xmax + 3; + if (dir2 == UI_DIR_LEFT) block->safety.xmin = block->rect.xmin - 3; } block->direction = dir1; } @@ -1551,7 +1598,7 @@ static void ui_block_region_draw(const bContext *C, ARegion *ar) } for (block = ar->uiblocks.first; block; block = block->next) - uiDrawBlock(C, block); + UI_block_draw(C, block); } static void ui_popup_block_clip(wmWindow *window, uiBlock *block) @@ -1633,20 +1680,20 @@ void ui_popup_block_scrolltest(uiBlock *block) static void ui_popup_block_remove(bContext *C, uiPopupBlockHandle *handle) { - ui_remove_temporary_region(C, CTX_wm_screen(C), handle->region); + ui_region_temp_remove(C, CTX_wm_screen(C), handle->region); if (handle->scrolltimer) WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), handle->scrolltimer); } /** - * Called for creatign new popups and refreshing existing ones. + * Called for creating new popups and refreshing existing ones. */ uiBlock *ui_popup_block_refresh( bContext *C, uiPopupBlockHandle *handle, ARegion *butregion, uiBut *but) { - const int width = UI_ThemeMenuShadowWidth(); + const int margin = UI_POPUP_MARGIN; wmWindow *window = CTX_wm_window(C); ARegion *ar = handle->region; @@ -1667,7 +1714,7 @@ uiBlock *ui_popup_block_refresh( else block = handle_create_func(C, handle, arg); - /* callbacks _must_ leave this for us, otherwise we can't call uiBlockUpdateFromOld */ + /* callbacks _must_ leave this for us, otherwise we can't call UI_block_update_from_old */ BLI_assert(!block->endblock); /* ensure we don't use mouse coords here! */ @@ -1685,14 +1732,9 @@ uiBlock *ui_popup_block_refresh( ar->regiondata = handle; - /* set UI_BLOCK_NUMSELECT before uiEndBlock() so we get alphanumeric keys assigned */ - if (but) { - if (but->type == PULLDOWN) { - block->flag |= UI_BLOCK_NUMSELECT; - } - } - else { - block->flag |= UI_BLOCK_POPUP | UI_BLOCK_NUMSELECT; + /* set UI_BLOCK_NUMSELECT before UI_block_end() so we get alphanumeric keys assigned */ + if (but == NULL) { + block->flag |= UI_BLOCK_POPUP; } block->flag |= UI_BLOCK_LOOP; @@ -1701,7 +1743,7 @@ uiBlock *ui_popup_block_refresh( block->oldblock = NULL; if (!block->endblock) - uiEndBlock_ex(C, block, handle->popup_create_vars.event_xy); + UI_block_end_ex(C, block, handle->popup_create_vars.event_xy); /* if this is being created from a button */ if (but) { @@ -1756,7 +1798,7 @@ uiBlock *ui_popup_block_refresh( ar->winrct.ymin = 0; ar->winrct.ymax = winy; - ui_block_calculate_pie_segment(block, block->pie_data.pie_center_init); + ui_block_calc_pie_segment(block, block->pie_data.pie_center_init); /* lastly set the buttons at the center of the pie menu, ready for animation */ if (U.pie_animation_timeout > 0) { @@ -1773,9 +1815,9 @@ uiBlock *ui_popup_block_refresh( /* the block and buttons were positioned in window space as in 2.4x, now * these menu blocks are regions so we bring it back to region space. * additionally we add some padding for the menu shadow or rounded menus */ - ar->winrct.xmin = block->rect.xmin - width; - ar->winrct.xmax = block->rect.xmax + width; - ar->winrct.ymin = block->rect.ymin - width; + ar->winrct.xmin = block->rect.xmin - margin; + ar->winrct.xmax = block->rect.xmax + margin; + ar->winrct.ymin = block->rect.ymin - margin; ar->winrct.ymax = block->rect.ymax + MENU_TOP; ui_block_translate(block, -ar->winrct.xmin, -ar->winrct.ymin); @@ -1783,8 +1825,8 @@ uiBlock *ui_popup_block_refresh( if (block_old) { block->oldblock = block_old; - uiBlockUpdateFromOld(C, block); - uiFreeInactiveBlocks(C, &ar->uiblocks); + UI_block_update_from_old(C, block); + UI_blocklist_free_inactive(C, &ar->uiblocks); } /* checks which buttons are visible, sets flags to prevent draw (do after region init) */ @@ -1810,9 +1852,10 @@ uiBlock *ui_popup_block_refresh( return block; } -uiPopupBlockHandle *ui_popup_block_create(bContext *C, ARegion *butregion, uiBut *but, - uiBlockCreateFunc create_func, uiBlockHandleCreateFunc handle_create_func, - void *arg) +uiPopupBlockHandle *ui_popup_block_create( + bContext *C, ARegion *butregion, uiBut *but, + uiBlockCreateFunc create_func, uiBlockHandleCreateFunc handle_create_func, + void *arg) { wmWindow *window = CTX_wm_window(C); static ARegionType type; @@ -1835,7 +1878,7 @@ uiPopupBlockHandle *ui_popup_block_create(bContext *C, ARegion *butregion, uiBut copy_v2_v2_int(handle->popup_create_vars.event_xy, &window->eventstate->x); /* create area region */ - ar = ui_add_temporary_region(CTX_wm_screen(C)); + ar = ui_region_temp_add(CTX_wm_screen(C)); handle->region = ar; memset(&type, 0, sizeof(ARegionType)); @@ -1843,7 +1886,7 @@ uiPopupBlockHandle *ui_popup_block_create(bContext *C, ARegion *butregion, uiBut type.regionid = RGN_TYPE_TEMPORARY; ar->type = &type; - UI_add_region_handlers(&ar->handlers); + UI_region_handlers_add(&ar->handlers); block = ui_popup_block_refresh(C, handle, butregion, but); handle = block->handle; @@ -1875,21 +1918,23 @@ static void ui_warp_pointer(int x, int y) /********************* Color Button ****************/ /* for picker, while editing hsv */ -void ui_set_but_hsv(uiBut *but) +void ui_but_hsv_set(uiBut *but) { float col[3]; - const float *hsv = ui_block_hsv_get(but->block); - + ColorPicker *cpicker = but->custom_data; + float *hsv = cpicker->color_data; + ui_color_picker_to_rgb_v(hsv, col); - ui_set_but_vectorf(but, col); + ui_but_v3_set(but, col); } -/* also used by small picker, be careful with name checks below... */ -static void ui_update_block_buts_rgb(uiBlock *block, const float rgb[3], bool is_display_space) +/* Updates all buttons who share the same color picker as the one passed + * also used by small picker, be careful with name checks below... */ +static void ui_update_color_picker_buts_rgb(uiBlock *block, ColorPicker *cpicker, const float rgb[3], bool is_display_space) { uiBut *bt; - float *hsv = ui_block_hsv_get(block); + float *hsv = cpicker->color_data; struct ColorManagedDisplay *display = NULL; /* this is to keep the H and S value when V is equal to zero * and we are working in HSV mode, of course! @@ -1902,21 +1947,24 @@ static void ui_update_block_buts_rgb(uiBlock *block, const float rgb[3], bool is float rgb_display[3]; copy_v3_v3(rgb_display, rgb); - ui_block_to_display_space_v3(block, rgb_display); + ui_block_cm_to_display_space_v3(block, rgb_display); ui_rgb_to_color_picker_compat_v(rgb_display, hsv); } if (block->color_profile) - display = ui_block_display_get(block); + display = ui_block_cm_display_get(block); /* this updates button strings, is hackish... but button pointers are on stack of caller function */ for (bt = block->buttons.first; bt; bt = bt->next) { + if (bt->custom_data != cpicker) + continue; + if (bt->rnaprop) { - ui_set_but_vectorf(bt, rgb); + ui_but_v3_set(bt, rgb); } - else if (strcmp(bt->str, "Hex: ") == 0) { + else if (STREQ(bt->str, "Hex: ")) { float rgb_gamma[3]; unsigned char rgb_gamma_uchar[3]; double intpart; @@ -1942,33 +1990,33 @@ static void ui_update_block_buts_rgb(uiBlock *block, const float rgb[3], bool is } else if (bt->str[1] == ' ') { if (bt->str[0] == 'R') { - ui_set_but_val(bt, rgb[0]); + ui_but_value_set(bt, rgb[0]); } else if (bt->str[0] == 'G') { - ui_set_but_val(bt, rgb[1]); + ui_but_value_set(bt, rgb[1]); } else if (bt->str[0] == 'B') { - ui_set_but_val(bt, rgb[2]); + ui_but_value_set(bt, rgb[2]); } else if (bt->str[0] == 'H') { - ui_set_but_val(bt, hsv[0]); + ui_but_value_set(bt, hsv[0]); } else if (bt->str[0] == 'S') { - ui_set_but_val(bt, hsv[1]); + ui_but_value_set(bt, hsv[1]); } else if (bt->str[0] == 'V') { - ui_set_but_val(bt, hsv[2]); + ui_but_value_set(bt, hsv[2]); } else if (bt->str[0] == 'L') { - ui_set_but_val(bt, hsv[2]); + ui_but_value_set(bt, hsv[2]); } } - ui_check_but(bt); + ui_but_update(bt); } } -static void do_picker_rna_cb(bContext *UNUSED(C), void *bt1, void *UNUSED(arg)) +static void ui_colorpicker_rna_cb(bContext *UNUSED(C), void *bt1, void *UNUSED(arg)) { uiBut *but = (uiBut *)bt1; uiPopupBlockHandle *popup = but->block->handle; @@ -1978,38 +2026,40 @@ static void do_picker_rna_cb(bContext *UNUSED(C), void *bt1, void *UNUSED(arg)) if (prop) { RNA_property_float_get_array(&ptr, prop, rgb); - ui_update_block_buts_rgb(but->block, rgb, (RNA_property_subtype(prop) == PROP_COLOR_GAMMA)); + ui_update_color_picker_buts_rgb(but->block, but->custom_data, rgb, (RNA_property_subtype(prop) == PROP_COLOR_GAMMA)); } if (popup) popup->menuretval = UI_RETURN_UPDATE; } -static void do_color_wheel_rna_cb(bContext *UNUSED(C), void *bt1, void *UNUSED(arg)) +static void ui_color_wheel_rna_cb(bContext *UNUSED(C), void *bt1, void *UNUSED(arg)) { uiBut *but = (uiBut *)bt1; uiPopupBlockHandle *popup = but->block->handle; float rgb[3]; - const float *hsv = ui_block_hsv_get(but->block); - bool use_display_colorspace = ui_color_picker_use_display_colorspace(but); + ColorPicker *cpicker = but->custom_data; + float *hsv = cpicker->color_data; + bool use_display_colorspace = ui_but_is_colorpicker_display_space(but); ui_color_picker_to_rgb_v(hsv, rgb); /* hsv is saved in display space so convert back */ if (use_display_colorspace) { - ui_block_to_scene_linear_v3(but->block, rgb); + ui_block_cm_to_scene_linear_v3(but->block, rgb); } - ui_update_block_buts_rgb(but->block, rgb, !use_display_colorspace); + ui_update_color_picker_buts_rgb(but->block, cpicker, rgb, !use_display_colorspace); if (popup) popup->menuretval = UI_RETURN_UPDATE; } -static void do_hex_rna_cb(bContext *UNUSED(C), void *bt1, void *hexcl) +static void ui_colorpicker_hex_rna_cb(bContext *UNUSED(C), void *bt1, void *hexcl) { uiBut *but = (uiBut *)bt1; uiPopupBlockHandle *popup = but->block->handle; + ColorPicker *cpicker = but->custom_data; char *hexcol = (char *)hexcl; float rgb[3]; @@ -2018,16 +2068,16 @@ static void do_hex_rna_cb(bContext *UNUSED(C), void *bt1, void *hexcl) /* Hex code is assumed to be in sRGB space (coming from other applications, web, etc) */ if (but->block->color_profile) { /* so we need to linearise it for Blender */ - ui_block_to_scene_linear_v3(but->block, rgb); + ui_block_cm_to_scene_linear_v3(but->block, rgb); } - ui_update_block_buts_rgb(but->block, rgb, false); + ui_update_color_picker_buts_rgb(but->block, cpicker, rgb, false); if (popup) popup->menuretval = UI_RETURN_UPDATE; } -static void close_popup_cb(bContext *UNUSED(C), void *bt1, void *UNUSED(arg)) +static void ui_popup_close_cb(bContext *UNUSED(C), void *bt1, void *UNUSED(arg)) { uiBut *but = (uiBut *)bt1; uiPopupBlockHandle *popup = but->block->handle; @@ -2036,23 +2086,23 @@ static void close_popup_cb(bContext *UNUSED(C), void *bt1, void *UNUSED(arg)) popup->menuretval = UI_RETURN_OK; } -static void picker_new_hide_reveal(uiBlock *block, short colormode) +static void ui_colorpicker_hide_reveal(uiBlock *block, short colormode) { uiBut *bt; /* tag buttons */ for (bt = block->buttons.first; bt; bt = bt->next) { - if ((bt->func == do_picker_rna_cb) && bt->type == NUMSLI && bt->rnaindex != 3) { + if ((bt->func == ui_colorpicker_rna_cb) && bt->type == UI_BTYPE_NUM_SLIDER && bt->rnaindex != 3) { /* RGB sliders (color circle and alpha are always shown) */ if (colormode == 0) bt->flag &= ~UI_HIDDEN; else bt->flag |= UI_HIDDEN; } - else if (bt->func == do_color_wheel_rna_cb) { + else if (bt->func == ui_color_wheel_rna_cb) { /* HSV sliders */ if (colormode == 1) bt->flag &= ~UI_HIDDEN; else bt->flag |= UI_HIDDEN; } - else if (bt->func == do_hex_rna_cb || bt->type == LABEL) { + else if (bt->func == ui_colorpicker_hex_rna_cb || bt->type == UI_BTYPE_LABEL) { /* hex input or gamma correction status label */ if (colormode == 2) bt->flag &= ~UI_HIDDEN; else bt->flag |= UI_HIDDEN; @@ -2060,11 +2110,11 @@ static void picker_new_hide_reveal(uiBlock *block, short colormode) } } -static void do_picker_new_mode_cb(bContext *UNUSED(C), void *bt1, void *UNUSED(arg)) +static void ui_colorpicker_create_mode_cb(bContext *UNUSED(C), void *bt1, void *UNUSED(arg)) { uiBut *bt = bt1; - short colormode = ui_get_but_val(bt); - picker_new_hide_reveal(bt->block, colormode); + short colormode = ui_but_value_get(bt); + ui_colorpicker_hide_reveal(bt->block, colormode); } #define PICKER_H (7.5f * U.widget_unit) @@ -2074,43 +2124,47 @@ static void do_picker_new_mode_cb(bContext *UNUSED(C), void *bt1, void *UNUSED(a #define PICKER_TOTAL_W (PICKER_W + PICKER_SPACE + PICKER_BAR) -static void circle_picker(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop) +static void ui_colorpicker_circle(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, ColorPicker *cpicker) { uiBut *bt; /* HS circle */ - bt = uiDefButR_prop(block, HSVCIRCLE, 0, "", 0, 0, PICKER_H, PICKER_W, ptr, prop, -1, 0.0, 0.0, 0.0, 0, TIP_("Color")); - uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); + bt = uiDefButR_prop(block, UI_BTYPE_HSVCIRCLE, 0, "", 0, 0, PICKER_H, PICKER_W, ptr, prop, -1, 0.0, 0.0, 0.0, 0, TIP_("Color")); + UI_but_func_set(bt, ui_colorpicker_rna_cb, bt, NULL); + bt->custom_data = cpicker; /* value */ if (U.color_picker_type == USER_CP_CIRCLE_HSL) { - bt = uiDefButR_prop(block, HSVCUBE, 0, "", PICKER_W + PICKER_SPACE, 0, PICKER_BAR, PICKER_H, ptr, prop, -1, 0.0, 0.0, UI_GRAD_L_ALT, 0, "Lightness"); - uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); + bt = uiDefButR_prop(block, UI_BTYPE_HSVCUBE, 0, "", PICKER_W + PICKER_SPACE, 0, PICKER_BAR, PICKER_H, ptr, prop, -1, 0.0, 0.0, UI_GRAD_L_ALT, 0, "Lightness"); + UI_but_func_set(bt, ui_colorpicker_rna_cb, bt, NULL); } else { - bt = uiDefButR_prop(block, HSVCUBE, 0, "", PICKER_W + PICKER_SPACE, 0, PICKER_BAR, PICKER_H, ptr, prop, -1, 0.0, 0.0, UI_GRAD_V_ALT, 0, TIP_("Value")); - uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); + bt = uiDefButR_prop(block, UI_BTYPE_HSVCUBE, 0, "", PICKER_W + PICKER_SPACE, 0, PICKER_BAR, PICKER_H, ptr, prop, -1, 0.0, 0.0, UI_GRAD_V_ALT, 0, TIP_("Value")); + UI_but_func_set(bt, ui_colorpicker_rna_cb, bt, NULL); } + bt->custom_data = cpicker; } -static void square_picker(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int type) +static void ui_colorpicker_square(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int type, ColorPicker *cpicker) { uiBut *bt; int bartype = type + 3; /* HS square */ - bt = uiDefButR_prop(block, HSVCUBE, 0, "", 0, PICKER_BAR + PICKER_SPACE, PICKER_TOTAL_W, PICKER_H, ptr, prop, -1, 0.0, 0.0, type, 0, TIP_("Color")); - uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); + bt = uiDefButR_prop(block, UI_BTYPE_HSVCUBE, 0, "", 0, PICKER_BAR + PICKER_SPACE, PICKER_TOTAL_W, PICKER_H, ptr, prop, -1, 0.0, 0.0, type, 0, TIP_("Color")); + UI_but_func_set(bt, ui_colorpicker_rna_cb, bt, NULL); + bt->custom_data = cpicker; /* value */ - bt = uiDefButR_prop(block, HSVCUBE, 0, "", 0, 0, PICKER_TOTAL_W, PICKER_BAR, ptr, prop, -1, 0.0, 0.0, bartype, 0, TIP_("Value")); - uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); + bt = uiDefButR_prop(block, UI_BTYPE_HSVCUBE, 0, "", 0, 0, PICKER_TOTAL_W, PICKER_BAR, ptr, prop, -1, 0.0, 0.0, bartype, 0, TIP_("Value")); + UI_but_func_set(bt, ui_colorpicker_rna_cb, bt, NULL); + bt->custom_data = cpicker; } /* a HS circle, V slider, rgb/hsv/hex sliders */ -static void uiBlockPicker(uiBlock *block, float rgba[4], PointerRNA *ptr, PropertyRNA *prop, bool show_picker) +static void ui_block_colorpicker(uiBlock *block, float rgba[4], PointerRNA *ptr, PropertyRNA *prop, bool show_picker) { static short colormode = 0; /* temp? 0=rgb, 1=hsv, 2=hex */ uiBut *bt; @@ -2120,8 +2174,9 @@ static void uiBlockPicker(uiBlock *block, float rgba[4], PointerRNA *ptr, Proper float rgb_gamma[3]; unsigned char rgb_gamma_uchar[3]; float softmin, softmax, hardmin, hardmax, step, precision; - float *hsv = ui_block_hsv_get(block); int yco; + ColorPicker *cpicker = ui_block_colorpicker_create(block); + float *hsv = cpicker->color_data; width = PICKER_TOTAL_W; butwidth = width - 1.5f * UI_UNIT_X; @@ -2137,7 +2192,7 @@ static void uiBlockPicker(uiBlock *block, float rgba[4], PointerRNA *ptr, Proper /* make a display version, for Hex code */ copy_v3_v3(rgb_gamma, rgba); - ui_block_to_display_space_v3(block, rgb_gamma); + ui_block_cm_to_display_space_v3(block, rgb_gamma); } /* sneaky way to check for alpha */ @@ -2149,75 +2204,86 @@ static void uiBlockPicker(uiBlock *block, float rgba[4], PointerRNA *ptr, Proper switch (U.color_picker_type) { case USER_CP_SQUARE_SV: - square_picker(block, ptr, prop, UI_GRAD_SV); + ui_colorpicker_square(block, ptr, prop, UI_GRAD_SV, cpicker); break; case USER_CP_SQUARE_HS: - square_picker(block, ptr, prop, UI_GRAD_HS); + ui_colorpicker_square(block, ptr, prop, UI_GRAD_HS, cpicker); break; case USER_CP_SQUARE_HV: - square_picker(block, ptr, prop, UI_GRAD_HV); + ui_colorpicker_square(block, ptr, prop, UI_GRAD_HV, cpicker); break; /* user default */ case USER_CP_CIRCLE_HSV: case USER_CP_CIRCLE_HSL: default: - circle_picker(block, ptr, prop); + ui_colorpicker_circle(block, ptr, prop, cpicker); break; } /* mode */ yco = -1.5f * UI_UNIT_Y; - uiBlockBeginAlign(block); - bt = uiDefButS(block, ROW, 0, IFACE_("RGB"), 0, yco, width / 3, UI_UNIT_Y, &colormode, 0.0, 0.0, 0, 0, ""); - uiButSetFunc(bt, do_picker_new_mode_cb, bt, NULL); + UI_block_align_begin(block); + bt = uiDefButS(block, UI_BTYPE_ROW, 0, IFACE_("RGB"), 0, yco, width / 3, UI_UNIT_Y, &colormode, 0.0, 0.0, 0, 0, ""); + UI_but_func_set(bt, ui_colorpicker_create_mode_cb, bt, NULL); + bt->custom_data = cpicker; if (U.color_picker_type == USER_CP_CIRCLE_HSL) - bt = uiDefButS(block, ROW, 0, IFACE_("HSL"), width / 3, yco, width / 3, UI_UNIT_Y, &colormode, 0.0, 1.0, 0, 0, ""); + bt = uiDefButS(block, UI_BTYPE_ROW, 0, IFACE_("HSL"), width / 3, yco, width / 3, UI_UNIT_Y, &colormode, 0.0, 1.0, 0, 0, ""); else - bt = uiDefButS(block, ROW, 0, IFACE_("HSV"), width / 3, yco, width / 3, UI_UNIT_Y, &colormode, 0.0, 1.0, 0, 0, ""); - uiButSetFunc(bt, do_picker_new_mode_cb, bt, NULL); - bt = uiDefButS(block, ROW, 0, IFACE_("Hex"), 2 * width / 3, yco, width / 3, UI_UNIT_Y, &colormode, 0.0, 2.0, 0, 0, ""); - uiButSetFunc(bt, do_picker_new_mode_cb, bt, NULL); - uiBlockEndAlign(block); + bt = uiDefButS(block, UI_BTYPE_ROW, 0, IFACE_("HSV"), width / 3, yco, width / 3, UI_UNIT_Y, &colormode, 0.0, 1.0, 0, 0, ""); + UI_but_func_set(bt, ui_colorpicker_create_mode_cb, bt, NULL); + bt->custom_data = cpicker; + bt = uiDefButS(block, UI_BTYPE_ROW, 0, IFACE_("Hex"), 2 * width / 3, yco, width / 3, UI_UNIT_Y, &colormode, 0.0, 2.0, 0, 0, ""); + UI_but_func_set(bt, ui_colorpicker_create_mode_cb, bt, NULL); + bt->custom_data = cpicker; + UI_block_align_end(block); yco = -3.0f * UI_UNIT_Y; if (show_picker) { - bt = uiDefIconButO(block, BUT, "UI_OT_eyedropper_color", WM_OP_INVOKE_DEFAULT, ICON_EYEDROPPER, butwidth + 10, yco, UI_UNIT_X, UI_UNIT_Y, NULL); - uiButSetFunc(bt, close_popup_cb, bt, NULL); + bt = uiDefIconButO(block, UI_BTYPE_BUT, "UI_OT_eyedropper_color", WM_OP_INVOKE_DEFAULT, ICON_EYEDROPPER, butwidth + 10, yco, UI_UNIT_X, UI_UNIT_Y, NULL); + UI_but_func_set(bt, ui_popup_close_cb, bt, NULL); + bt->custom_data = cpicker; } /* RGB values */ - uiBlockBeginAlign(block); - bt = uiDefButR_prop(block, NUMSLI, 0, IFACE_("R:"), 0, yco, butwidth, UI_UNIT_Y, ptr, prop, 0, 0.0, 0.0, 0, 3, TIP_("Red")); - uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); - bt = uiDefButR_prop(block, NUMSLI, 0, IFACE_("G:"), 0, yco -= UI_UNIT_Y, butwidth, UI_UNIT_Y, ptr, prop, 1, 0.0, 0.0, 0, 3, TIP_("Green")); - uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); - bt = uiDefButR_prop(block, NUMSLI, 0, IFACE_("B:"), 0, yco -= UI_UNIT_Y, butwidth, UI_UNIT_Y, ptr, prop, 2, 0.0, 0.0, 0, 3, TIP_("Blue")); - uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); + UI_block_align_begin(block); + bt = uiDefButR_prop(block, UI_BTYPE_NUM_SLIDER, 0, IFACE_("R:"), 0, yco, butwidth, UI_UNIT_Y, ptr, prop, 0, 0.0, 0.0, 0, 3, TIP_("Red")); + UI_but_func_set(bt, ui_colorpicker_rna_cb, bt, NULL); + bt->custom_data = cpicker; + bt = uiDefButR_prop(block, UI_BTYPE_NUM_SLIDER, 0, IFACE_("G:"), 0, yco -= UI_UNIT_Y, butwidth, UI_UNIT_Y, ptr, prop, 1, 0.0, 0.0, 0, 3, TIP_("Green")); + UI_but_func_set(bt, ui_colorpicker_rna_cb, bt, NULL); + bt->custom_data = cpicker; + bt = uiDefButR_prop(block, UI_BTYPE_NUM_SLIDER, 0, IFACE_("B:"), 0, yco -= UI_UNIT_Y, butwidth, UI_UNIT_Y, ptr, prop, 2, 0.0, 0.0, 0, 3, TIP_("Blue")); + UI_but_func_set(bt, ui_colorpicker_rna_cb, bt, NULL); + bt->custom_data = cpicker; /* could use uiItemFullR(col, ptr, prop, -1, 0, UI_ITEM_R_EXPAND|UI_ITEM_R_SLIDER, "", ICON_NONE); - * but need to use uiButSetFunc for updating other fake buttons */ + * but need to use UI_but_func_set for updating other fake buttons */ /* HSV values */ yco = -3.0f * UI_UNIT_Y; - uiBlockBeginAlign(block); - bt = uiDefButF(block, NUMSLI, 0, IFACE_("H:"), 0, yco, butwidth, UI_UNIT_Y, hsv, 0.0, 1.0, 10, 3, TIP_("Hue")); - uiButSetFunc(bt, do_color_wheel_rna_cb, bt, hsv); - bt = uiDefButF(block, NUMSLI, 0, IFACE_("S:"), 0, yco -= UI_UNIT_Y, butwidth, UI_UNIT_Y, hsv + 1, 0.0, 1.0, 10, 3, TIP_("Saturation")); - uiButSetFunc(bt, do_color_wheel_rna_cb, bt, hsv); + UI_block_align_begin(block); + bt = uiDefButF(block, UI_BTYPE_NUM_SLIDER, 0, IFACE_("H:"), 0, yco, butwidth, UI_UNIT_Y, hsv, 0.0, 1.0, 10, 3, TIP_("Hue")); + UI_but_func_set(bt, ui_color_wheel_rna_cb, bt, hsv); + bt->custom_data = cpicker; + bt = uiDefButF(block, UI_BTYPE_NUM_SLIDER, 0, IFACE_("S:"), 0, yco -= UI_UNIT_Y, butwidth, UI_UNIT_Y, hsv + 1, 0.0, 1.0, 10, 3, TIP_("Saturation")); + UI_but_func_set(bt, ui_color_wheel_rna_cb, bt, hsv); + bt->custom_data = cpicker; if (U.color_picker_type == USER_CP_CIRCLE_HSL) - bt = uiDefButF(block, NUMSLI, 0, IFACE_("L:"), 0, yco -= UI_UNIT_Y, butwidth, UI_UNIT_Y, hsv + 2, 0.0, 1.0, 10, 3, TIP_("Lightness")); + bt = uiDefButF(block, UI_BTYPE_NUM_SLIDER, 0, IFACE_("L:"), 0, yco -= UI_UNIT_Y, butwidth, UI_UNIT_Y, hsv + 2, 0.0, 1.0, 10, 3, TIP_("Lightness")); else - bt = uiDefButF(block, NUMSLI, 0, IFACE_("V:"), 0, yco -= UI_UNIT_Y, butwidth, UI_UNIT_Y, hsv + 2, 0.0, softmax, 10, 3, TIP_("Value")); + bt = uiDefButF(block, UI_BTYPE_NUM_SLIDER, 0, IFACE_("V:"), 0, yco -= UI_UNIT_Y, butwidth, UI_UNIT_Y, hsv + 2, 0.0, softmax, 10, 3, TIP_("Value")); bt->hardmax = hardmax; /* not common but rgb may be over 1.0 */ - uiButSetFunc(bt, do_color_wheel_rna_cb, bt, hsv); + UI_but_func_set(bt, ui_color_wheel_rna_cb, bt, hsv); + bt->custom_data = cpicker; - uiBlockEndAlign(block); + UI_block_align_end(block); if (rgba[3] != FLT_MAX) { - bt = uiDefButR_prop(block, NUMSLI, 0, IFACE_("A: "), 0, yco -= UI_UNIT_Y, butwidth, UI_UNIT_Y, ptr, prop, 3, 0.0, 0.0, 0, 3, TIP_("Alpha")); - uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); + bt = uiDefButR_prop(block, UI_BTYPE_NUM_SLIDER, 0, IFACE_("A: "), 0, yco -= UI_UNIT_Y, butwidth, UI_UNIT_Y, ptr, prop, 3, 0.0, 0.0, 0, 3, TIP_("Alpha")); + UI_but_func_set(bt, ui_colorpicker_rna_cb, bt, NULL); + bt->custom_data = cpicker; } else { rgba[3] = 1.0f; @@ -2227,17 +2293,18 @@ static void uiBlockPicker(uiBlock *block, float rgba[4], PointerRNA *ptr, Proper BLI_snprintf(hexcol, sizeof(hexcol), "%02X%02X%02X", UNPACK3_EX((unsigned int), rgb_gamma_uchar, )); yco = -3.0f * UI_UNIT_Y; - bt = uiDefBut(block, TEX, 0, IFACE_("Hex: "), 0, yco, butwidth, UI_UNIT_Y, hexcol, 0, 8, 0, 0, TIP_("Hex triplet for color (#RRGGBB)")); - uiButSetFunc(bt, do_hex_rna_cb, bt, hexcol); - uiDefBut(block, LABEL, 0, IFACE_("(Gamma Corrected)"), 0, yco - UI_UNIT_Y, butwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, ""); + bt = uiDefBut(block, UI_BTYPE_TEXT, 0, IFACE_("Hex: "), 0, yco, butwidth, UI_UNIT_Y, hexcol, 0, 8, 0, 0, TIP_("Hex triplet for color (#RRGGBB)")); + UI_but_func_set(bt, ui_colorpicker_hex_rna_cb, bt, hexcol); + bt->custom_data = cpicker; + uiDefBut(block, UI_BTYPE_LABEL, 0, IFACE_("(Gamma Corrected)"), 0, yco - UI_UNIT_Y, butwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, ""); ui_rgb_to_color_picker_v(rgb_gamma, hsv); - picker_new_hide_reveal(block, colormode); + ui_colorpicker_hide_reveal(block, colormode); } -static int ui_picker_small_wheel_cb(const bContext *UNUSED(C), uiBlock *block, const wmEvent *event) +static int ui_colorpicker_small_wheel_cb(const bContext *UNUSED(C), uiBlock *block, const wmEvent *event) { float add = 0.0f; @@ -2250,16 +2317,17 @@ static int ui_picker_small_wheel_cb(const bContext *UNUSED(C), uiBlock *block, c uiBut *but; for (but = block->buttons.first; but; but = but->next) { - if (but->type == HSVCUBE && but->active == NULL) { + if (but->type == UI_BTYPE_HSVCUBE && but->active == NULL) { uiPopupBlockHandle *popup = block->handle; float rgb[3]; - float *hsv = ui_block_hsv_get(block); - bool use_display_colorspace = ui_color_picker_use_display_colorspace(but); + ColorPicker *cpicker = but->custom_data; + float *hsv = cpicker->color_data; + bool use_display_colorspace = ui_but_is_colorpicker_display_space(but); - ui_get_but_vectorf(but, rgb); + ui_but_v3_get(but, rgb); if (use_display_colorspace) - ui_block_to_display_space_v3(block, rgb); + ui_block_cm_to_display_space_v3(block, rgb); ui_rgb_to_color_picker_compat_v(rgb, hsv); @@ -2267,11 +2335,11 @@ static int ui_picker_small_wheel_cb(const bContext *UNUSED(C), uiBlock *block, c ui_color_picker_to_rgb_v(hsv, rgb); if (use_display_colorspace) - ui_block_to_scene_linear_v3(block, rgb); + ui_block_cm_to_scene_linear_v3(block, rgb); - ui_set_but_vectorf(but, rgb); + ui_but_v3_set(but, rgb); - ui_update_block_buts_rgb(block, rgb, !use_display_colorspace); + ui_update_color_picker_buts_rgb(block, cpicker, rgb, !use_display_colorspace); if (popup) popup->menuretval = UI_RETURN_UPDATE; @@ -2288,7 +2356,7 @@ uiBlock *ui_block_func_COLOR(bContext *C, uiPopupBlockHandle *handle, void *arg_ uiBlock *block; bool show_picker = true; - block = uiBeginBlock(C, handle->region, __func__, UI_EMBOSS); + block = UI_block_begin(C, handle->region, __func__, UI_EMBOSS); if (RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) { block->color_profile = false; @@ -2304,15 +2372,15 @@ uiBlock *ui_block_func_COLOR(bContext *C, uiPopupBlockHandle *handle, void *arg_ copy_v3_v3(handle->retvec, but->editvec); - uiBlockPicker(block, handle->retvec, &but->rnapoin, but->rnaprop, show_picker); + ui_block_colorpicker(block, handle->retvec, &but->rnapoin, but->rnaprop, show_picker); - block->flag = UI_BLOCK_LOOP | UI_BLOCK_REDRAW | UI_BLOCK_KEEP_OPEN | UI_BLOCK_OUT_1 | UI_BLOCK_MOVEMOUSE_QUIT; - uiBoundsBlock(block, 0.5 * UI_UNIT_X); + block->flag = UI_BLOCK_LOOP | UI_BLOCK_KEEP_OPEN | UI_BLOCK_OUT_1 | UI_BLOCK_MOVEMOUSE_QUIT; + UI_block_bounds_set_normal(block, 0.5 * UI_UNIT_X); - block->block_event_func = ui_picker_small_wheel_cb; + block->block_event_func = ui_colorpicker_small_wheel_cb; /* and lets go */ - block->direction = UI_TOP; + block->direction = UI_DIR_UP; return block; } @@ -2448,39 +2516,39 @@ static uiBlock *ui_block_func_POPUP(bContext *C, uiPopupBlockHandle *handle, voi /* allow overriding the direction from menu_func */ direction = pup->block->direction; } - else if ((pup->but->type == PULLDOWN) || - (uiButGetMenuType(pup->but) != NULL)) + else if ((pup->but->type == UI_BTYPE_PULLDOWN) || + (UI_but_menutype_get(pup->but) != NULL)) { - direction = UI_DOWN; + direction = UI_DIR_DOWN; } else { - direction = UI_TOP; + direction = UI_DIR_UP; } } else { minwidth = 50; - direction = UI_DOWN; + direction = UI_DIR_DOWN; } - flip = (direction == UI_DOWN); + flip = (direction == UI_DIR_DOWN); block = pup->block; /* in some cases we create the block before the region, * so we set it delayed here if necessary */ if (BLI_findindex(&handle->region->uiblocks, block) == -1) - uiBlockSetRegion(block, handle->region); + UI_block_region_set(block, handle->region); block->direction = direction; - uiBlockLayoutResolve(block, &width, &height); + UI_block_layout_resolve(block, &width, &height); - uiBlockSetFlag(block, UI_BLOCK_MOVEMOUSE_QUIT); + UI_block_flag_enable(block, UI_BLOCK_MOVEMOUSE_QUIT); if (pup->popup) { uiBut *but_activate = NULL; - uiBlockSetFlag(block, UI_BLOCK_LOOP | UI_BLOCK_REDRAW | UI_BLOCK_NUMSELECT); - uiBlockSetDirection(block, direction); + UI_block_flag_enable(block, UI_BLOCK_LOOP | UI_BLOCK_NUMSELECT); + UI_block_direction_set(block, direction); /* offset the mouse position, possibly based on earlier selection */ if ((block->flag & UI_BLOCK_POPUP_MEMORY) && @@ -2518,11 +2586,11 @@ static uiBlock *ui_block_func_POPUP(bContext *C, uiPopupBlockHandle *handle, voi * to be within the window bounds may move it away from the mouse, * This ensures we set an item to be active. */ if (but_activate) { - ui_button_activate_over(C, handle->region, but_activate); + ui_but_activate_over(C, handle->region, but_activate); } block->minbounds = minwidth; - uiMenuPopupBoundsBlock(block, 1, offset[0], offset[1]); + UI_block_bounds_set_menu(block, 1, offset[0], offset[1]); } else { /* for a header menu we set the direction automatic */ @@ -2531,35 +2599,36 @@ static uiBlock *ui_block_func_POPUP(bContext *C, uiPopupBlockHandle *handle, voi if (sa && sa->headertype == HEADERDOWN) { ARegion *ar = CTX_wm_region(C); if (ar && ar->regiontype == RGN_TYPE_HEADER) { - uiBlockSetDirection(block, UI_TOP); - uiBlockFlipOrder(block); + UI_block_direction_set(block, UI_DIR_UP); + UI_block_order_flip(block); } } } block->minbounds = minwidth; - uiTextBoundsBlock(block, 3.0f * UI_UNIT_X); + UI_block_bounds_set_text(block, 3.0f * UI_UNIT_X); } /* if menu slides out of other menu, override direction */ if (pup->slideout) - uiBlockSetDirection(block, UI_RIGHT); + UI_block_direction_set(block, UI_DIR_RIGHT); return pup->block; } -uiPopupBlockHandle *ui_popup_menu_create(bContext *C, ARegion *butregion, uiBut *but, - uiMenuCreateFunc menu_func, void *arg) +uiPopupBlockHandle *ui_popup_menu_create( + bContext *C, ARegion *butregion, uiBut *but, + uiMenuCreateFunc menu_func, void *arg) { wmWindow *window = CTX_wm_window(C); - uiStyle *style = UI_GetStyleDraw(); + uiStyle *style = UI_style_get_dpi(); uiPopupBlockHandle *handle; uiPopupMenu *pup; pup = MEM_callocN(sizeof(uiPopupMenu), __func__); - pup->block = uiBeginBlock(C, NULL, __func__, UI_EMBOSSP); + pup->block = UI_block_begin(C, NULL, __func__, UI_EMBOSS_PULLDOWN); pup->block->flag |= UI_BLOCK_NUMSELECT; /* default menus to numselect */ - pup->layout = uiBlockLayout(pup->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_MENU, 0, 0, 200, 0, MENU_PADDING, style); + pup->layout = UI_block_layout(pup->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_MENU, 0, 0, 200, 0, MENU_PADDING, style); pup->slideout = but ? ui_block_is_menu(but->block) : false; pup->but = but; uiLayoutSetOperatorContext(pup->layout, WM_OP_INVOKE_REGION_WIN); @@ -2596,7 +2665,7 @@ uiPopupBlockHandle *ui_popup_menu_create(bContext *C, ARegion *butregion, uiBut if (!but) { handle->popup = true; - UI_add_popup_handlers(C, &window->modalhandlers, handle, false); + UI_popup_handlers_add(C, &window->modalhandlers, handle, 0); WM_event_add_mousemove(C); } @@ -2608,16 +2677,16 @@ uiPopupBlockHandle *ui_popup_menu_create(bContext *C, ARegion *butregion, uiBut /******************** Popup Menu API with begin and end ***********************/ /* only return handler, and set optional title */ -uiPopupMenu *uiPupMenuBegin(bContext *C, const char *title, int icon) +uiPopupMenu *UI_popup_menu_begin(bContext *C, const char *title, int icon) { - uiStyle *style = UI_GetStyleDraw(); + uiStyle *style = UI_style_get_dpi(); uiPopupMenu *pup = MEM_callocN(sizeof(uiPopupMenu), "popup menu"); uiBut *but; - pup->block = uiBeginBlock(C, NULL, __func__, UI_EMBOSSP); - pup->block->flag |= UI_BLOCK_POPUP_MEMORY; + pup->block = UI_block_begin(C, NULL, __func__, UI_EMBOSS_PULLDOWN); + pup->block->flag |= UI_BLOCK_POPUP_MEMORY | UI_BLOCK_IS_FLIP; pup->block->puphash = ui_popup_menu_hash(title); - pup->layout = uiBlockLayout(pup->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_MENU, 0, 0, 200, 0, MENU_PADDING, style); + pup->layout = UI_block_layout(pup->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_MENU, 0, 0, 200, 0, MENU_PADDING, style); /* note, this intentionally differs from the menu & submenu default because many operators * use popups like this to select one of their options - where having invoke doesn't make sense */ @@ -2632,10 +2701,10 @@ uiPopupMenu *uiPupMenuBegin(bContext *C, const char *title, int icon) if (icon) { BLI_snprintf(titlestr, sizeof(titlestr), " %s", title); - uiDefIconTextBut(pup->block, LABEL, 0, icon, titlestr, 0, 0, 200, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, ""); + uiDefIconTextBut(pup->block, UI_BTYPE_LABEL, 0, icon, titlestr, 0, 0, 200, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, ""); } else { - but = uiDefBut(pup->block, LABEL, 0, title, 0, 0, 200, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, ""); + but = uiDefBut(pup->block, UI_BTYPE_LABEL, 0, title, 0, 0, 200, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, ""); but->drawflag = UI_BUT_TEXT_LEFT; } @@ -2646,7 +2715,7 @@ uiPopupMenu *uiPupMenuBegin(bContext *C, const char *title, int icon) } /* set the whole structure to work */ -void uiPupMenuEnd(bContext *C, uiPopupMenu *pup) +void UI_popup_menu_end(bContext *C, uiPopupMenu *pup) { wmWindow *window = CTX_wm_window(C); uiPopupBlockHandle *menu; @@ -2658,13 +2727,13 @@ void uiPupMenuEnd(bContext *C, uiPopupMenu *pup) menu = ui_popup_block_create(C, NULL, NULL, NULL, ui_block_func_POPUP, pup); menu->popup = true; - UI_add_popup_handlers(C, &window->modalhandlers, menu, false); + UI_popup_handlers_add(C, &window->modalhandlers, menu, 0); WM_event_add_mousemove(C); MEM_freeN(pup); } -uiLayout *uiPupMenuLayout(uiPopupMenu *pup) +uiLayout *UI_popup_menu_layout(uiPopupMenu *pup) { return pup->layout; } @@ -2683,11 +2752,11 @@ static uiBlock *ui_block_func_PIE(bContext *UNUSED(C), uiPopupBlockHandle *handl /* in some cases we create the block before the region, * so we set it delayed here if necessary */ if (BLI_findindex(&handle->region->uiblocks, block) == -1) - uiBlockSetRegion(block, handle->region); + UI_block_region_set(block, handle->region); - uiBlockLayoutResolve(block, &width, &height); + UI_block_layout_resolve(block, &width, &height); - uiBlockSetFlag(block, UI_BLOCK_LOOP | UI_BLOCK_REDRAW | UI_BLOCK_NUMSELECT); + UI_block_flag_enable(block, UI_BLOCK_LOOP | UI_BLOCK_NUMSELECT); block->minbounds = minwidth; block->bounds = 1; @@ -2701,26 +2770,56 @@ static uiBlock *ui_block_func_PIE(bContext *UNUSED(C), uiPopupBlockHandle *handl return pie->block_radial; } -static float uiPieTitleWidth(const char *name, int icon) +static float ui_pie_menu_title_width(const char *name, int icon) { - return (UI_GetStringWidth(name) + + const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; + return (UI_fontstyle_string_width(fstyle, name) + (UI_UNIT_X * (1.50f + (icon ? 0.25f : 0.0f)))); } -uiPieMenu *uiPieMenuBegin(struct bContext *C, const char *title, int icon, const wmEvent *event) +uiPieMenu *UI_pie_menu_begin(struct bContext *C, const char *title, int icon, const wmEvent *event) { - uiStyle *style = UI_GetStyleDraw(); - uiPieMenu *pie = MEM_callocN(sizeof(uiPopupMenu), "pie menu"); + uiStyle *style; + uiPieMenu *pie; + short event_type; - pie->block_radial = uiBeginBlock(C, NULL, __func__, UI_EMBOSS); + wmWindow *win = CTX_wm_window(C); + + style = UI_style_get_dpi(); + pie = MEM_callocN(sizeof(uiPopupMenu), "pie menu"); + + pie->block_radial = UI_block_begin(C, NULL, __func__, UI_EMBOSS); /* may be useful later to allow spawning pies * from old positions */ /* pie->block_radial->flag |= UI_BLOCK_POPUP_MEMORY; */ pie->block_radial->puphash = ui_popup_menu_hash(title); pie->block_radial->flag |= UI_BLOCK_RADIAL; - pie->block_radial->pie_data.event = event->type; - pie->layout = uiBlockLayout(pie->block_radial, UI_LAYOUT_VERTICAL, UI_LAYOUT_PIEMENU, 0, 0, 200, 0, 0, style); + /* if pie is spawned by a left click, it is always assumed to be click style */ + if (event->type == LEFTMOUSE) { + pie->block_radial->pie_data.flags |= UI_PIE_CLICK_STYLE; + pie->block_radial->pie_data.event = EVENT_NONE; + win->lock_pie_event = EVENT_NONE; + } + else { + if (win->last_pie_event != EVENT_NONE) { + /* original pie key has been released, so don't propagate the event */ + if (win->lock_pie_event == EVENT_NONE) { + event_type = EVENT_NONE; + pie->block_radial->pie_data.flags |= UI_PIE_CLICK_STYLE; + } + else + event_type = win->last_pie_event; + } + else { + event_type = event->type; + } + + pie->block_radial->pie_data.event = event_type; + win->lock_pie_event = event_type; + } + + pie->layout = UI_block_layout(pie->block_radial, UI_LAYOUT_VERTICAL, UI_LAYOUT_PIEMENU, 0, 0, 200, 0, 0, style); pie->mx = event->x; pie->my = event->y; @@ -2731,12 +2830,12 @@ uiPieMenu *uiPieMenuBegin(struct bContext *C, const char *title, int icon, const int w; if (icon) { BLI_snprintf(titlestr, sizeof(titlestr), " %s", title); - w = uiPieTitleWidth(titlestr, icon); - but = uiDefIconTextBut(pie->block_radial, LABEL, 0, icon, titlestr, 0, 0, w, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, ""); + w = ui_pie_menu_title_width(titlestr, icon); + but = uiDefIconTextBut(pie->block_radial, UI_BTYPE_LABEL, 0, icon, titlestr, 0, 0, w, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, ""); } else { - w = uiPieTitleWidth(title, 0); - but = uiDefBut(pie->block_radial, LABEL, 0, title, 0, 0, w, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, ""); + w = ui_pie_menu_title_width(title, 0); + but = uiDefBut(pie->block_radial, UI_BTYPE_LABEL, 0, title, 0, 0, w, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, ""); } /* do not align left */ but->drawflag &= ~UI_BUT_TEXT_LEFT; @@ -2745,7 +2844,7 @@ uiPieMenu *uiPieMenuBegin(struct bContext *C, const char *title, int icon, const return pie; } -void uiPieMenuEnd(bContext *C, uiPieMenu *pie) +void UI_pie_menu_end(bContext *C, uiPieMenu *pie) { wmWindow *window = CTX_wm_window(C); uiPopupBlockHandle *menu; @@ -2754,18 +2853,20 @@ void uiPieMenuEnd(bContext *C, uiPieMenu *pie) menu->popup = true; menu->towardstime = PIL_check_seconds_timer(); - UI_add_popup_handlers(C, &window->modalhandlers, menu, true); + UI_popup_handlers_add( + C, &window->modalhandlers, + menu, WM_HANDLER_ACCEPT_DBL_CLICK); WM_event_add_mousemove(C); MEM_freeN(pie); } -uiLayout *uiPieMenuLayout(uiPieMenu *pie) +uiLayout *UI_pie_menu_layout(uiPieMenu *pie) { return pie->layout; } -void uiPieMenuInvoke(struct bContext *C, const char *idname, const wmEvent *event) +int UI_pie_menu_invoke(struct bContext *C, const char *idname, const wmEvent *event) { uiPieMenu *pie; uiLayout *layout; @@ -2774,14 +2875,14 @@ void uiPieMenuInvoke(struct bContext *C, const char *idname, const wmEvent *even if (mt == NULL) { printf("%s: named menu \"%s\" not found\n", __func__, idname); - return; + return OPERATOR_CANCELLED; } if (mt->poll && mt->poll(C, mt) == 0) - return; + return OPERATOR_CANCELLED; - pie = uiPieMenuBegin(C, IFACE_(mt->label), ICON_NONE, event); - layout = uiPieMenuLayout(pie); + pie = UI_pie_menu_begin(C, IFACE_(mt->label), ICON_NONE, event); + layout = UI_pie_menu_layout(pie); menu.layout = layout; menu.type = mt; @@ -2792,26 +2893,32 @@ void uiPieMenuInvoke(struct bContext *C, const char *idname, const wmEvent *even mt->draw(C, &menu); - uiPieMenuEnd(C, pie); + UI_pie_menu_end(C, pie); + + return OPERATOR_INTERFACE; } -void uiPieOperatorEnumInvoke(struct bContext *C, const char *title, const char *opname, - const char *propname, const wmEvent *event) +int UI_pie_menu_invoke_from_operator_enum( + struct bContext *C, const char *title, const char *opname, + const char *propname, const wmEvent *event) { uiPieMenu *pie; uiLayout *layout; - pie = uiPieMenuBegin(C, IFACE_(title), ICON_NONE, event); - layout = uiPieMenuLayout(pie); + pie = UI_pie_menu_begin(C, IFACE_(title), ICON_NONE, event); + layout = UI_pie_menu_layout(pie); layout = uiLayoutRadial(layout); uiItemsEnumO(layout, opname, propname); - uiPieMenuEnd(C, pie); + UI_pie_menu_end(C, pie); + + return OPERATOR_INTERFACE; } -void uiPieEnumInvoke(struct bContext *C, const char *title, const char *path, - const wmEvent *event) +int UI_pie_menu_invoke_from_rna_enum( + struct bContext *C, const char *title, const char *path, + const wmEvent *event) { PointerRNA ctx_ptr; PointerRNA r_ptr; @@ -2822,28 +2929,31 @@ void uiPieEnumInvoke(struct bContext *C, const char *title, const char *path, RNA_pointer_create(NULL, &RNA_Context, C, &ctx_ptr); if (!RNA_path_resolve(&ctx_ptr, path, &r_ptr, &r_prop)) { - return; + return OPERATOR_CANCELLED; } /* invalid property, only accept enums */ if (RNA_property_type(r_prop) != PROP_ENUM) { BLI_assert(0); - return; + return OPERATOR_CANCELLED; } - pie = uiPieMenuBegin(C, IFACE_(title), ICON_NONE, event); - layout = uiPieMenuLayout(pie); + pie = UI_pie_menu_begin(C, IFACE_(title), ICON_NONE, event); + + layout = UI_pie_menu_layout(pie); layout = uiLayoutRadial(layout); uiItemFullR(layout, &r_ptr, r_prop, RNA_NO_INDEX, 0, UI_ITEM_R_EXPAND, NULL, 0); - uiPieMenuEnd(C, pie); + UI_pie_menu_end(C, pie); + + return OPERATOR_INTERFACE; } /*************************** Standard Popup Menus ****************************/ -void uiPupMenuReports(bContext *C, ReportList *reports) +void UI_popup_menu_reports(bContext *C, ReportList *reports) { Report *report; @@ -2864,8 +2974,8 @@ void uiPupMenuReports(bContext *C, ReportList *reports) if (pup == NULL) { char title[UI_MAX_DRAW_STR]; BLI_snprintf(title, sizeof(title), "%s: %s", IFACE_("Report"), report->typestr); - pup = uiPupMenuBegin(C, title, ICON_NONE); - layout = uiPupMenuLayout(pup); + pup = UI_popup_menu_begin(C, title, ICON_NONE); + layout = UI_popup_menu_layout(pup); } else { uiItemS(layout); @@ -2873,7 +2983,7 @@ void uiPupMenuReports(bContext *C, ReportList *reports) /* split each newline into a label */ msg = report->message; - icon = uiIconFromReportType(report->type); + icon = UI_icon_from_report_type(report->type); do { char buf[UI_MAX_DRAW_STR]; msg_next = strchr(msg, '\n'); @@ -2888,11 +2998,11 @@ void uiPupMenuReports(bContext *C, ReportList *reports) } if (pup) { - uiPupMenuEnd(C, pup); + UI_popup_menu_end(C, pup); } } -bool uiPupMenuInvoke(bContext *C, const char *idname, ReportList *reports) +int UI_popup_menu_invoke(bContext *C, const char *idname, ReportList *reports) { uiPopupMenu *pup; uiLayout *layout; @@ -2901,14 +3011,14 @@ bool uiPupMenuInvoke(bContext *C, const char *idname, ReportList *reports) if (mt == NULL) { BKE_reportf(reports, RPT_ERROR, "Menu \"%s\" not found", idname); - return false; + return OPERATOR_CANCELLED; } if (mt->poll && mt->poll(C, mt) == 0) - return false; + return OPERATOR_CANCELLED; - pup = uiPupMenuBegin(C, IFACE_(mt->label), ICON_NONE); - layout = uiPupMenuLayout(pup); + pup = UI_popup_menu_begin(C, IFACE_(mt->label), ICON_NONE); + layout = UI_popup_menu_layout(pup); menu.layout = layout; menu.type = mt; @@ -2919,15 +3029,15 @@ bool uiPupMenuInvoke(bContext *C, const char *idname, ReportList *reports) mt->draw(C, &menu); - uiPupMenuEnd(C, pup); + UI_popup_menu_end(C, pup); - return true; + return OPERATOR_INTERFACE; } /*************************** Popup Block API **************************/ -void uiPupBlockO(bContext *C, uiBlockCreateFunc func, void *arg, const char *opname, int opcontext) +void UI_popup_block_invoke_ex(bContext *C, uiBlockCreateFunc func, void *arg, const char *opname, int opcontext) { wmWindow *window = CTX_wm_window(C); uiPopupBlockHandle *handle; @@ -2937,16 +3047,16 @@ void uiPupBlockO(bContext *C, uiBlockCreateFunc func, void *arg, const char *opn handle->optype = (opname) ? WM_operatortype_find(opname, 0) : NULL; handle->opcontext = opcontext; - UI_add_popup_handlers(C, &window->modalhandlers, handle, false); + UI_popup_handlers_add(C, &window->modalhandlers, handle, 0); WM_event_add_mousemove(C); } -void uiPupBlock(bContext *C, uiBlockCreateFunc func, void *arg) +void UI_popup_block_invoke(bContext *C, uiBlockCreateFunc func, void *arg) { - uiPupBlockO(C, func, arg, NULL, WM_OP_INVOKE_DEFAULT); + UI_popup_block_invoke_ex(C, func, arg, NULL, WM_OP_INVOKE_DEFAULT); } -void uiPupBlockEx(bContext *C, uiBlockCreateFunc func, uiBlockHandleFunc popup_func, uiBlockCancelFunc cancel_func, void *arg) +void UI_popup_block_ex(bContext *C, uiBlockCreateFunc func, uiBlockHandleFunc popup_func, uiBlockCancelFunc cancel_func, void *arg) { wmWindow *window = CTX_wm_window(C); uiPopupBlockHandle *handle; @@ -2960,7 +3070,7 @@ void uiPupBlockEx(bContext *C, uiBlockCreateFunc func, uiBlockHandleFunc popup_f handle->cancel_func = cancel_func; // handle->opcontext = opcontext; - UI_add_popup_handlers(C, &window->modalhandlers, handle, false); + UI_popup_handlers_add(C, &window->modalhandlers, handle, 0); WM_event_add_mousemove(C); } @@ -2979,27 +3089,28 @@ void uiPupBlockOperator(bContext *C, uiBlockCreateFunc func, wmOperator *op, int handle->cancel_func = confirm_cancel_operator; handle->opcontext = opcontext; - UI_add_popup_handlers(C, &window->modalhandlers, handle); + UI_popup_handlers_add(C, &window->modalhandlers, handle, 0); WM_event_add_mousemove(C); } #endif -void uiPupBlockClose(bContext *C, uiBlock *block) +void UI_popup_block_close(bContext *C, wmWindow *win, uiBlock *block) { + /* if loading new .blend while popup is open, window will be NULL */ if (block->handle) { - wmWindow *win = CTX_wm_window(C); - - /* if loading new .blend while popup is open, window will be NULL */ if (win) { - UI_remove_popup_handlers(&win->modalhandlers, block->handle); + UI_popup_handlers_remove(&win->modalhandlers, block->handle); ui_popup_block_free(C, block->handle); } } } -float *ui_block_hsv_get(uiBlock *block) +ColorPicker *ui_block_colorpicker_create(struct uiBlock *block) { - return block->_hsv; + ColorPicker *cpicker = MEM_callocN(sizeof(ColorPicker), "color_picker"); + BLI_addhead(&block->color_pickers.list, cpicker); + + return cpicker; } void ui_rgb_to_color_picker_compat_v(const float rgb[3], float r_cp[3]) |