Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_regions.c
| Show First 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | static int rna_property_enum_step(const bContext *C, PointerRNA *ptr, PropertyRNA *prop, int direction) | ||||
| if (free) { | if (free) { | ||||
| MEM_freeN(item_array); | MEM_freeN(item_array); | ||||
| } | } | ||||
| return value; | return value; | ||||
| } | } | ||||
| int ui_step_name_menu(uiBut *but, int direction) | int ui_but_menu_step(uiBut *but, int direction) | ||||
| { | { | ||||
| /* currenly only RNA buttons */ | /* currenly only RNA buttons */ | ||||
| if ((but->rnaprop == NULL) || (RNA_property_type(but->rnaprop) != PROP_ENUM)) { | if ((but->rnaprop == NULL) || (RNA_property_type(but->rnaprop) != PROP_ENUM)) { | ||||
| printf("%s: cannot cycle button '%s'", __func__, but->str); | printf("%s: cannot cycle button '%s'", __func__, but->str); | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| 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); | ||||
| } | } | ||||
| /******************** Creating Temporary regions ******************/ | /******************** Creating Temporary regions ******************/ | ||||
| static ARegion *ui_add_temporary_region(bScreen *sc) | static ARegion *ui_region_temp_add(bScreen *sc) | ||||
| { | { | ||||
| ARegion *ar; | ARegion *ar; | ||||
| ar = MEM_callocN(sizeof(ARegion), "area region"); | ar = MEM_callocN(sizeof(ARegion), "area region"); | ||||
| BLI_addtail(&sc->regionbase, ar); | BLI_addtail(&sc->regionbase, ar); | ||||
| ar->regiontype = RGN_TYPE_TEMPORARY; | ar->regiontype = RGN_TYPE_TEMPORARY; | ||||
| ar->alignment = RGN_ALIGN_FLOAT; | ar->alignment = RGN_ALIGN_FLOAT; | ||||
| return ar; | 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); | wmWindow *win = CTX_wm_window(C); | ||||
| if (win) | if (win) | ||||
| wm_draw_region_clear(win, ar); | wm_draw_region_clear(win, ar); | ||||
| ED_region_exit(C, ar); | ED_region_exit(C, ar); | ||||
| BKE_area_region_free(NULL, ar); /* NULL: no spacetype */ | BKE_area_region_free(NULL, ar); /* NULL: no spacetype */ | ||||
| BLI_freelinkN(&sc->regionbase, ar); | BLI_freelinkN(&sc->regionbase, ar); | ||||
| ▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *ar) | ||||
| /* disable AA, makes widgets too blurry */ | /* disable AA, makes widgets too blurry */ | ||||
| multisample_enabled = glIsEnabled(GL_MULTISAMPLE_ARB); | multisample_enabled = glIsEnabled(GL_MULTISAMPLE_ARB); | ||||
| if (multisample_enabled) | if (multisample_enabled) | ||||
| glDisable(GL_MULTISAMPLE_ARB); | glDisable(GL_MULTISAMPLE_ARB); | ||||
| wmOrtho2_region_ui(ar); | wmOrtho2_region_ui(ar); | ||||
| /* draw background */ | /* draw background */ | ||||
| ui_draw_tooltip_background(UI_GetStyle(), NULL, &bbox); | ui_draw_tooltip_background(UI_style_get(), NULL, &bbox); | ||||
| /* set background_color */ | /* set background_color */ | ||||
| rgb_uchar_to_float(background_color, (const unsigned char *)theme->inner); | rgb_uchar_to_float(background_color, (const unsigned char *)theme->inner); | ||||
| /* calculate normal_color */ | /* calculate normal_color */ | ||||
| rgb_uchar_to_float(main_color, (const unsigned char *)theme->text); | rgb_uchar_to_float(main_color, (const unsigned char *)theme->text); | ||||
| copy_v3_v3(active_color, main_color); | copy_v3_v3(active_color, main_color); | ||||
| copy_v3_v3(normal_color, main_color); | copy_v3_v3(normal_color, main_color); | ||||
| Show All 26 Lines | if (data->format[i].style == UI_TIP_STYLE_HEADER) { | ||||
| float xofs; | float xofs; | ||||
| /* override text-style */ | /* override text-style */ | ||||
| fstyle_header.shadow = 1; | fstyle_header.shadow = 1; | ||||
| fstyle_header.shadowcolor = rgb_to_luma(tip_colors[UI_TIP_LC_MAIN]); | fstyle_header.shadowcolor = rgb_to_luma(tip_colors[UI_TIP_LC_MAIN]); | ||||
| fstyle_header.shadx = fstyle_header.shady = 0; | fstyle_header.shadx = fstyle_header.shady = 0; | ||||
| fstyle_header.shadowalpha = 1.0f; | fstyle_header.shadowalpha = 1.0f; | ||||
| uiStyleFontSet(&fstyle_header); | UI_fontstyle_set(&fstyle_header); | ||||
| glColor3fv(tip_colors[UI_TIP_LC_MAIN]); | 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)); | xofs = BLF_width(fstyle_header.uifont_id, data->header, sizeof(data->header)); | ||||
| bbox.xmin += xofs; | bbox.xmin += xofs; | ||||
| glColor3fv(tip_colors[UI_TIP_LC_ACTIVE]); | glColor3fv(tip_colors[UI_TIP_LC_ACTIVE]); | ||||
| uiStyleFontDraw(&data->fstyle, &bbox, data->active_info); | UI_fontstyle_draw(&data->fstyle, &bbox, data->active_info); | ||||
| bbox.xmin -= xofs; | bbox.xmin -= xofs; | ||||
| } | } | ||||
| else if (data->format[i].style == UI_TIP_STYLE_MONO) { | else if (data->format[i].style == UI_TIP_STYLE_MONO) { | ||||
| uiFontStyle fstyle_mono = data->fstyle; | uiFontStyle fstyle_mono = data->fstyle; | ||||
| fstyle_mono.uifont_id = blf_mono_font; | fstyle_mono.uifont_id = blf_mono_font; | ||||
| uiStyleFontSet(&fstyle_mono); | UI_fontstyle_set(&fstyle_mono); | ||||
| /* XXX, needed because we dont have mono in 'U.uifonts' */ | /* XXX, needed because we dont have mono in 'U.uifonts' */ | ||||
| BLF_size(fstyle_mono.uifont_id, fstyle_mono.points * U.pixelsize, U.dpi); | BLF_size(fstyle_mono.uifont_id, fstyle_mono.points * U.pixelsize, U.dpi); | ||||
| glColor3fv(tip_colors[data->format[i].color_id]); | 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 { | else { | ||||
| BLI_assert(data->format[i].style == UI_TIP_STYLE_NORMAL); | BLI_assert(data->format[i].style == UI_TIP_STYLE_NORMAL); | ||||
| /* draw remaining data */ | /* draw remaining data */ | ||||
| uiStyleFontSet(&data->fstyle); | UI_fontstyle_set(&data->fstyle); | ||||
| glColor3fv(tip_colors[data->format[i].color_id]); | glColor3fv(tip_colors[data->format[i].color_id]); | ||||
| uiStyleFontDraw(&data->fstyle, &bbox, data->lines[i]); | UI_fontstyle_draw(&data->fstyle, &bbox, data->lines[i]); | ||||
| } | } | ||||
| if ((i + 1 != data->totline) && data->format[i + 1].is_pad) { | if ((i + 1 != data->totline) && data->format[i + 1].is_pad) { | ||||
| bbox.ymax -= data->lineh * UI_TIP_PAD_FAC; | bbox.ymax -= data->lineh * UI_TIP_PAD_FAC; | ||||
| bbox.ymin -= data->lineh * UI_TIP_PAD_FAC; | bbox.ymin -= data->lineh * UI_TIP_PAD_FAC; | ||||
| } | } | ||||
| else { | else { | ||||
| bbox.ymax -= data->lineh; | bbox.ymax -= data->lineh; | ||||
| bbox.ymin -= data->lineh; | bbox.ymin -= data->lineh; | ||||
| Show All 12 Lines | static void ui_tooltip_region_free_cb(ARegion *ar) | ||||
| MEM_freeN(data); | MEM_freeN(data); | ||||
| ar->regiondata = NULL; | ar->regiondata = NULL; | ||||
| } | } | ||||
| ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but) | ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but) | ||||
| { | { | ||||
| const float pad_px = UI_TIP_PADDING; | const float pad_px = UI_TIP_PADDING; | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| uiStyle *style = UI_GetStyle(); | uiStyle *style = UI_style_get(); | ||||
| static ARegionType type; | static ARegionType type; | ||||
| ARegion *ar; | ARegion *ar; | ||||
| uiTooltipData *data; | uiTooltipData *data; | ||||
| /* IDProperty *prop;*/ | /* IDProperty *prop;*/ | ||||
| char buf[512]; | char buf[512]; | ||||
| /* aspect values that shrink text are likely unreadable */ | /* aspect values that shrink text are likely unreadable */ | ||||
| const float aspect = min_ff(1.0f, but->block->aspect); | const float aspect = min_ff(1.0f, but->block->aspect); | ||||
| float fonth, fontw; | float fonth, fontw; | ||||
| Show All 10 Lines | /* IDProperty *prop;*/ | ||||
| uiStringInfo rna_prop = {BUT_GET_RNAPROP_IDENTIFIER, NULL}; | uiStringInfo rna_prop = {BUT_GET_RNAPROP_IDENTIFIER, NULL}; | ||||
| if (but->drawflag & UI_BUT_NO_TOOLTIP) | if (but->drawflag & UI_BUT_NO_TOOLTIP) | ||||
| return NULL; | return NULL; | ||||
| /* create tooltip data */ | /* create tooltip data */ | ||||
| data = MEM_callocN(sizeof(uiTooltipData), "uiTooltipData"); | 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 */ | /* Tip */ | ||||
| if (but_tip.strinfo) { | if (but_tip.strinfo) { | ||||
| BLI_strncpy(data->header, but_tip.strinfo, sizeof(data->lines[0])); | BLI_strncpy(data->header, but_tip.strinfo, sizeof(data->lines[0])); | ||||
| if (enum_label.strinfo) { | if (enum_label.strinfo) { | ||||
| BLI_snprintf(data->header, sizeof(data->header), "%s: ", but_tip.strinfo); | BLI_snprintf(data->header, sizeof(data->header), "%s: ", but_tip.strinfo); | ||||
| BLI_strncpy(data->active_info, enum_label.strinfo, sizeof(data->lines[0])); | BLI_strncpy(data->active_info, enum_label.strinfo, sizeof(data->lines[0])); | ||||
| } | } | ||||
| data->format[data->totline].style = UI_TIP_STYLE_HEADER; | data->format[data->totline].style = UI_TIP_STYLE_HEADER; | ||||
| data->totline++; | data->totline++; | ||||
| /* special case enum rna buttons */ | /* special case enum rna buttons */ | ||||
| if ((but->type & ROW) && but->rnaprop && RNA_property_flag(but->rnaprop) & PROP_ENUM_FLAG) { | 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 to select multiple)"), sizeof(data->lines[0])); | BLI_strncpy(data->lines[data->totline], IFACE_("(Shift-click to select multiple)"), sizeof(data->lines[0])); | ||||
| data->format[data->totline].color_id = UI_TIP_LC_NORMAL; | data->format[data->totline].color_id = UI_TIP_LC_NORMAL; | ||||
| data->totline++; | data->totline++; | ||||
| } | } | ||||
| } | } | ||||
| /* Enum item label & tip */ | /* Enum item label & tip */ | ||||
| Show All 15 Lines | /* IDProperty *prop;*/ | ||||
| /* Property context-toggle shortcut */ | /* Property context-toggle shortcut */ | ||||
| if (prop_keymap.strinfo) { | if (prop_keymap.strinfo) { | ||||
| BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), TIP_("Shortcut: %s"), prop_keymap.strinfo); | BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), TIP_("Shortcut: %s"), prop_keymap.strinfo); | ||||
| data->format[data->totline].is_pad = true; | data->format[data->totline].is_pad = true; | ||||
| data->format[data->totline].color_id = UI_TIP_LC_VALUE; | data->format[data->totline].color_id = UI_TIP_LC_VALUE; | ||||
| data->totline++; | data->totline++; | ||||
| } | } | ||||
| if (ELEM(but->type, TEX, SEARCH_MENU, SEARCH_MENU_UNLINK)) { | if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU, UI_BTYPE_SEARCH_MENU_UNLINK)) { | ||||
| /* better not show the value of a password */ | /* better not show the value of a password */ | ||||
| if ((but->rnaprop && (RNA_property_subtype(but->rnaprop) == PROP_PASSWORD)) == 0) { | if ((but->rnaprop && (RNA_property_subtype(but->rnaprop) == PROP_PASSWORD)) == 0) { | ||||
| /* full string */ | /* full string */ | ||||
| ui_get_but_string(but, buf, sizeof(buf)); | ui_but_string_get(but, buf, sizeof(buf)); | ||||
| if (buf[0]) { | if (buf[0]) { | ||||
| BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), TIP_("Value: %s"), buf); | BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), TIP_("Value: %s"), buf); | ||||
| data->format[data->totline].is_pad = true; | data->format[data->totline].is_pad = true; | ||||
| data->format[data->totline].color_id = UI_TIP_LC_VALUE; | data->format[data->totline].color_id = UI_TIP_LC_VALUE; | ||||
| data->totline++; | data->totline++; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if (but->rnaprop) { | if (but->rnaprop) { | ||||
| int unit_type = uiButGetUnitType(but); | int unit_type = UI_but_unit_type_get(but); | ||||
| if (unit_type == PROP_UNIT_ROTATION) { | if (unit_type == PROP_UNIT_ROTATION) { | ||||
| if (RNA_property_type(but->rnaprop) == PROP_FLOAT) { | if (RNA_property_type(but->rnaprop) == PROP_FLOAT) { | ||||
| float value = RNA_property_array_check(but->rnaprop) ? | float value = RNA_property_array_check(but->rnaprop) ? | ||||
| RNA_property_float_get_index(&but->rnapoin, but->rnaprop, but->rnaindex) : | RNA_property_float_get_index(&but->rnapoin, but->rnaprop, but->rnaindex) : | ||||
| RNA_property_float_get(&but->rnapoin, but->rnaprop); | RNA_property_float_get(&but->rnapoin, but->rnaprop); | ||||
| BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), TIP_("Radians: %f"), value); | BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), TIP_("Radians: %f"), value); | ||||
| data->format[data->totline].color_id = UI_TIP_LC_NORMAL; | data->format[data->totline].color_id = UI_TIP_LC_NORMAL; | ||||
| Show All 17 Lines | if (but->rnapoin.id.data) { | ||||
| data->format[data->totline].color_id = UI_TIP_LC_NORMAL; | data->format[data->totline].color_id = UI_TIP_LC_NORMAL; | ||||
| data->totline++; | data->totline++; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else if (but->optype) { | else if (but->optype) { | ||||
| PointerRNA *opptr; | PointerRNA *opptr; | ||||
| char *str; | 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) */ | /* so the context is passed to itemf functions (some py itemf functions use it) */ | ||||
| WM_operator_properties_sanitize(opptr, false); | WM_operator_properties_sanitize(opptr, false); | ||||
| str = WM_operator_pystring_ex(C, NULL, false, false, but->optype, opptr); | str = WM_operator_pystring_ex(C, NULL, false, false, but->optype, opptr); | ||||
| /* avoid overly verbose tips (eg, arrays of 20 layers), exact limit is arbitrary */ | /* avoid overly verbose tips (eg, arrays of 20 layers), exact limit is arbitrary */ | ||||
| WM_operator_pystring_abbreviate(str, 32); | WM_operator_pystring_abbreviate(str, 32); | ||||
| ▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | /* IDProperty *prop;*/ | ||||
| BLI_assert(data->totline < MAX_TOOLTIP_LINES); | BLI_assert(data->totline < MAX_TOOLTIP_LINES); | ||||
| if (data->totline == 0) { | if (data->totline == 0) { | ||||
| MEM_freeN(data); | MEM_freeN(data); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| /* create area region */ | /* 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)); | memset(&type, 0, sizeof(ARegionType)); | ||||
| type.draw = ui_tooltip_region_draw_cb; | type.draw = ui_tooltip_region_draw_cb; | ||||
| type.free = ui_tooltip_region_free_cb; | type.free = ui_tooltip_region_free_cb; | ||||
| type.regionid = RGN_TYPE_TEMPORARY; | type.regionid = RGN_TYPE_TEMPORARY; | ||||
| ar->type = &type; | ar->type = &type; | ||||
| /* set font, get bb */ | /* set font, get bb */ | ||||
| data->fstyle = style->widget; /* copy struct */ | data->fstyle = style->widget; /* copy struct */ | ||||
| ui_fontscale(&data->fstyle.points, aspect); | ui_fontscale(&data->fstyle.points, aspect); | ||||
| uiStyleFontSet(&data->fstyle); | UI_fontstyle_set(&data->fstyle); | ||||
| /* these defines tweaked depending on font */ | /* these defines tweaked depending on font */ | ||||
| #define TIP_BORDER_X (16.0f / aspect) | #define TIP_BORDER_X (16.0f / aspect) | ||||
| #define TIP_BORDER_Y (6.0f / aspect) | #define TIP_BORDER_Y (6.0f / aspect) | ||||
| h = BLF_height_max(data->fstyle.uifont_id); | h = BLF_height_max(data->fstyle.uifont_id); | ||||
| for (i = 0, fontw = 0, fonth = 0; i < data->totline; i++) { | for (i = 0, fontw = 0, fonth = 0; i < data->totline; i++) { | ||||
| ▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | #undef TIP_BORDER_Y | ||||
| /* notify change and redraw */ | /* notify change and redraw */ | ||||
| ED_region_tag_redraw(ar); | ED_region_tag_redraw(ar); | ||||
| return ar; | return ar; | ||||
| } | } | ||||
| void ui_tooltip_free(bContext *C, ARegion *ar) | 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); | ||||
| } | } | ||||
| /************************* Creating Search Box **********************/ | /************************* Creating Search Box **********************/ | ||||
| struct uiSearchItems { | struct uiSearchItems { | ||||
| int maxitem, totitem, maxstrlen; | int maxitem, totitem, maxstrlen; | ||||
| Show All 18 Lines | typedef struct uiSearchboxData { | ||||
| bool use_sep; /* use the UI_SEP_CHAR char for splitting shortcuts (good for operators, bad for data) */ | bool use_sep; /* use the UI_SEP_CHAR char for splitting shortcuts (good for operators, bad for data) */ | ||||
| int prv_rows, prv_cols; | int prv_rows, prv_cols; | ||||
| } uiSearchboxData; | } uiSearchboxData; | ||||
| #define SEARCH_ITEMS 10 | #define SEARCH_ITEMS 10 | ||||
| /* exported for use by search callbacks */ | /* exported for use by search callbacks */ | ||||
| /* returns zero if nothing to add */ | /* 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 */ | /* hijack for autocomplete */ | ||||
| if (items->autocpl) { | if (items->autocpl) { | ||||
| autocomplete_do_name(items->autocpl, name); | UI_autocomplete_update_name(items->autocpl, name); | ||||
| return true; | return true; | ||||
| } | } | ||||
| /* hijack for finding active item */ | /* hijack for finding active item */ | ||||
| if (items->active) { | if (items->active) { | ||||
| if (poin == items->active) | if (poin == items->active) | ||||
| items->offset_i = items->totitem; | items->offset_i = items->totitem; | ||||
| items->totitem++; | items->totitem++; | ||||
| Show All 18 Lines | bool UI_search_item_add(uiSearchItems *items, const char *name, void *poin, int iconid) | ||||
| if (items->icons) | if (items->icons) | ||||
| items->icons[items->totitem] = iconid; | items->icons[items->totitem] = iconid; | ||||
| items->totitem++; | items->totitem++; | ||||
| return true; | return true; | ||||
| } | } | ||||
| int uiSearchBoxHeight(void) | int UI_searchbox_size_y(void) | ||||
| { | { | ||||
| return SEARCH_ITEMS * UI_UNIT_Y + 2 * MENU_TOP; | return SEARCH_ITEMS * UI_UNIT_Y + 2 * MENU_TOP; | ||||
| } | } | ||||
| int uiSearchBoxWidth(void) | int UI_searchbox_size_x(void) | ||||
| { | { | ||||
| return 12 * UI_UNIT_X; | 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; | int i; | ||||
| for (i = 0; i < items->totitem; i++) { | for (i = 0; i < items->totitem; i++) { | ||||
| if (STREQ(name, items->names[i])) { | if (STREQ(name, items->names[i])) { | ||||
| return i; | return i; | ||||
| } | } | ||||
| } | } | ||||
| return -1; | return -1; | ||||
| Show All 23 Lines | static void ui_searchbox_select(bContext *C, ARegion *ar, uiBut *but, int step) | ||||
| else if (data->active < 0) { | else if (data->active < 0) { | ||||
| if (data->items.offset) { | if (data->items.offset) { | ||||
| data->items.offset--; | data->items.offset--; | ||||
| data->active = 0; | data->active = 0; | ||||
| ui_searchbox_update(C, ar, but, false); | ui_searchbox_update(C, ar, but, false); | ||||
| } | } | ||||
| else { | else { | ||||
| /* only let users step into an 'unset' state for unlink buttons */ | /* only let users step into an 'unset' state for unlink buttons */ | ||||
| data->active = (but->type == SEARCH_MENU_UNLINK) ? -1 : 0; | data->active = (but->type == UI_BTYPE_SEARCH_MENU_UNLINK) ? -1 : 0; | ||||
| } | } | ||||
| } | } | ||||
| ED_region_tag_redraw(ar); | ED_region_tag_redraw(ar); | ||||
| } | } | ||||
| static void ui_searchbox_butrect(rcti *r_rect, uiSearchboxData *data, int itemnr) | static void ui_searchbox_butrect(rcti *r_rect, uiSearchboxData *data, int itemnr) | ||||
| { | { | ||||
| Show All 26 Lines | else { | ||||
| r_rect->ymin = r_rect->ymax - buth; | r_rect->ymin = r_rect->ymax - buth; | ||||
| } | } | ||||
| } | } | ||||
| int ui_searchbox_find_index(ARegion *ar, const char *name) | int ui_searchbox_find_index(ARegion *ar, const char *name) | ||||
| { | { | ||||
| uiSearchboxData *data = ar->regiondata; | uiSearchboxData *data = ar->regiondata; | ||||
| return uiSearchItemFindIndex(&data->items, name); | return UI_search_items_find_index(&data->items, name); | ||||
| } | } | ||||
| /* x and y in screencoords */ | /* x and y in screencoords */ | ||||
| bool ui_searchbox_inside(ARegion *ar, int x, int y) | bool ui_searchbox_inside(ARegion *ar, int x, int y) | ||||
| { | { | ||||
| uiSearchboxData *data = ar->regiondata; | uiSearchboxData *data = ar->regiondata; | ||||
| return BLI_rcti_isect_pt(&data->bbox, x - ar->winrct.xmin, y - ar->winrct.ymin); | return BLI_rcti_isect_pt(&data->bbox, x - ar->winrct.xmin, y - ar->winrct.ymin); | ||||
| Show All 11 Lines | if (data->active != -1) { | ||||
| const char *name_sep = data->use_sep ? strrchr(name, UI_SEP_CHAR) : NULL; | const char *name_sep = data->use_sep ? strrchr(name, UI_SEP_CHAR) : NULL; | ||||
| BLI_strncpy(but->editstr, name, name_sep ? (name_sep - name) : data->items.maxstrlen); | BLI_strncpy(but->editstr, name, name_sep ? (name_sep - name) : data->items.maxstrlen); | ||||
| but->func_arg2 = data->items.pointers[data->active]; | but->func_arg2 = data->items.pointers[data->active]; | ||||
| return true; | return true; | ||||
| } | } | ||||
| else if (but->type == SEARCH_MENU_UNLINK) { | else if (but->type == UI_BTYPE_SEARCH_MENU_UNLINK) { | ||||
| /* It is valid for _UNLINK flavor to have no active element (it's a valid way to unlink). */ | /* It is valid for _UNLINK flavor to have no active element (it's a valid way to unlink). */ | ||||
| but->editstr[0] = '\0'; | but->editstr[0] = '\0'; | ||||
| return true; | return true; | ||||
| } | } | ||||
| else { | else { | ||||
| return false; | return false; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| int ui_searchbox_autocomplete(bContext *C, ARegion *ar, uiBut *but, char *str) | int ui_searchbox_autocomplete(bContext *C, ARegion *ar, uiBut *but, char *str) | ||||
| { | { | ||||
| uiSearchboxData *data = ar->regiondata; | uiSearchboxData *data = ar->regiondata; | ||||
| int match = AUTOCOMPLETE_NO_MATCH; | int match = AUTOCOMPLETE_NO_MATCH; | ||||
| if (str[0]) { | 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); | 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; | data->items.autocpl = NULL; | ||||
| } | } | ||||
| return match; | return match; | ||||
| } | } | ||||
| static void ui_searchbox_region_draw_cb(const bContext *UNUSED(C), ARegion *ar) | static void ui_searchbox_region_draw_cb(const bContext *UNUSED(C), ARegion *ar) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | static void ui_searchbox_region_free_cb(ARegion *ar) | ||||
| MEM_freeN(data); | MEM_freeN(data); | ||||
| ar->regiondata = NULL; | ar->regiondata = NULL; | ||||
| } | } | ||||
| ARegion *ui_searchbox_create(bContext *C, ARegion *butregion, uiBut *but) | ARegion *ui_searchbox_create(bContext *C, ARegion *butregion, uiBut *but) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| uiStyle *style = UI_GetStyle(); | uiStyle *style = UI_style_get(); | ||||
| static ARegionType type; | static ARegionType type; | ||||
| ARegion *ar; | ARegion *ar; | ||||
| uiSearchboxData *data; | uiSearchboxData *data; | ||||
| float aspect = but->block->aspect; | float aspect = but->block->aspect; | ||||
| rctf rect_fl; | rctf rect_fl; | ||||
| rcti rect_i; | rcti rect_i; | ||||
| int winx /*, winy */, ofsx, ofsy; | int winx /*, winy */, ofsx, ofsy; | ||||
| int i; | int i; | ||||
| /* create area region */ | /* 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)); | memset(&type, 0, sizeof(ARegionType)); | ||||
| type.draw = ui_searchbox_region_draw_cb; | type.draw = ui_searchbox_region_draw_cb; | ||||
| type.free = ui_searchbox_region_free_cb; | type.free = ui_searchbox_region_free_cb; | ||||
| type.regionid = RGN_TYPE_TEMPORARY; | type.regionid = RGN_TYPE_TEMPORARY; | ||||
| ar->type = &type; | ar->type = &type; | ||||
| /* create searchbox data */ | /* create searchbox data */ | ||||
| data = MEM_callocN(sizeof(uiSearchboxData), "uiSearchboxData"); | data = MEM_callocN(sizeof(uiSearchboxData), "uiSearchboxData"); | ||||
| /* set font, get bb */ | /* set font, get bb */ | ||||
| data->fstyle = style->widget; /* copy struct */ | data->fstyle = style->widget; /* copy struct */ | ||||
| data->fstyle.align = UI_STYLE_TEXT_CENTER; | data->fstyle.align = UI_STYLE_TEXT_CENTER; | ||||
| ui_fontscale(&data->fstyle.points, aspect); | ui_fontscale(&data->fstyle.points, aspect); | ||||
| uiStyleFontSet(&data->fstyle); | UI_fontstyle_set(&data->fstyle); | ||||
| ar->regiondata = data; | ar->regiondata = data; | ||||
| /* special case, hardcoded feature, not draw backdrop when called from menus, | /* special case, hardcoded feature, not draw backdrop when called from menus, | ||||
| * assume for design that popup already added it */ | * assume for design that popup already added it */ | ||||
| if (but->block->flag & UI_BLOCK_SEARCH_MENU) | if (but->block->flag & UI_BLOCK_SEARCH_MENU) | ||||
| data->noback = true; | data->noback = true; | ||||
| Show All 27 Lines | if (but->block->flag & UI_BLOCK_SEARCH_MENU) { | ||||
| if (but->rect.ymax < BLI_rctf_cent_y(&but->block->rect)) { | if (but->rect.ymax < BLI_rctf_cent_y(&but->block->rect)) { | ||||
| data->bbox.ymin += BLI_rctf_size_y(&but->rect); | data->bbox.ymin += BLI_rctf_size_y(&but->rect); | ||||
| } | } | ||||
| else { | else { | ||||
| data->bbox.ymax -= BLI_rctf_size_y(&but->rect); | data->bbox.ymax -= BLI_rctf_size_y(&but->rect); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| const int searchbox_width = uiSearchBoxWidth(); | const int searchbox_width = UI_searchbox_size_x(); | ||||
| const int shadow_width = UI_ThemeMenuShadowWidth(); | const int shadow_width = UI_ThemeMenuShadowWidth(); | ||||
| rect_fl.xmin = but->rect.xmin - 5; /* align text with button */ | rect_fl.xmin = but->rect.xmin - 5; /* align text with button */ | ||||
| rect_fl.xmax = but->rect.xmax + 5; /* symmetrical */ | rect_fl.xmax = but->rect.xmax + 5; /* symmetrical */ | ||||
| rect_fl.ymax = but->rect.ymin; | 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; | ofsx = (but->block->panel) ? but->block->panel->ofsx : 0; | ||||
| ofsy = (but->block->panel) ? but->block->panel->ofsy : 0; | ofsy = (but->block->panel) ? but->block->panel->ofsy : 0; | ||||
| BLI_rctf_translate(&rect_fl, ofsx, ofsy); | BLI_rctf_translate(&rect_fl, ofsx, ofsy); | ||||
| /* minimal width */ | /* minimal width */ | ||||
| if (BLI_rctf_size_x(&rect_fl) < searchbox_width) { | if (BLI_rctf_size_x(&rect_fl) < searchbox_width) { | ||||
| ▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | ARegion *ui_searchbox_create(bContext *C, ARegion *butregion, uiBut *but) | ||||
| for (i = 0; i < data->items.maxitem; i++) | for (i = 0; i < data->items.maxitem; i++) | ||||
| data->items.names[i] = MEM_callocN(but->hardmax + 1, "search pointers"); | data->items.names[i] = MEM_callocN(but->hardmax + 1, "search pointers"); | ||||
| return ar; | return ar; | ||||
| } | } | ||||
| void ui_searchbox_free(bContext *C, ARegion *ar) | 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 */ | /* sets red alert if button holds a string it can't find */ | ||||
| /* XXX weak: search_func adds all partial matches... */ | /* XXX weak: search_func adds all partial matches... */ | ||||
| void ui_but_search_test(uiBut *but) | void ui_but_search_refresh(uiBut *but) | ||||
| { | { | ||||
| uiSearchItems *items; | uiSearchItems *items; | ||||
| int x1; | int x1; | ||||
| /* possibly very large lists (such as ID datablocks) only | /* possibly very large lists (such as ID datablocks) only | ||||
| * only validate string RNA buts (not pointers) */ | * only validate string RNA buts (not pointers) */ | ||||
| if (but->rnaprop && RNA_property_type(but->rnaprop) != PROP_STRING) { | if (but->rnaprop && RNA_property_type(but->rnaprop) != PROP_STRING) { | ||||
| return; | return; | ||||
| } | } | ||||
| items = MEM_callocN(sizeof(uiSearchItems), "search items"); | items = MEM_callocN(sizeof(uiSearchItems), "search items"); | ||||
| /* setup search struct */ | /* setup search struct */ | ||||
| items->maxitem = 10; | items->maxitem = 10; | ||||
| items->maxstrlen = 256; | items->maxstrlen = 256; | ||||
| items->names = MEM_callocN(items->maxitem * sizeof(void *), "search names"); | items->names = MEM_callocN(items->maxitem * sizeof(void *), "search names"); | ||||
| for (x1 = 0; x1 < items->maxitem; x1++) | for (x1 = 0; x1 < items->maxitem; x1++) | ||||
| items->names[x1] = MEM_callocN(but->hardmax + 1, "search names"); | items->names[x1] = MEM_callocN(but->hardmax + 1, "search names"); | ||||
| but->search_func(but->block->evil_C, but->search_arg, but->drawstr, items); | but->search_func(but->block->evil_C, but->search_arg, but->drawstr, items); | ||||
| /* only redalert when we are sure of it, this can miss cases when >10 matches */ | /* only redalert when we are sure of it, this can miss cases when >10 matches */ | ||||
| if (items->totitem == 0) { | if (items->totitem == 0) { | ||||
| uiButSetFlag(but, UI_BUT_REDALERT); | UI_but_flag_enable(but, UI_BUT_REDALERT); | ||||
| } | } | ||||
| else if (items->more == 0) { | else if (items->more == 0) { | ||||
| if (uiSearchItemFindIndex(items, but->drawstr) == -1) { | if (UI_search_items_find_index(items, but->drawstr) == -1) { | ||||
| uiButSetFlag(but, UI_BUT_REDALERT); | UI_but_flag_enable(but, UI_BUT_REDALERT); | ||||
| } | } | ||||
| } | } | ||||
| for (x1 = 0; x1 < items->maxitem; x1++) { | for (x1 = 0; x1 < items->maxitem; x1++) { | ||||
| MEM_freeN(items->names[x1]); | MEM_freeN(items->names[x1]); | ||||
| } | } | ||||
| MEM_freeN(items->names); | MEM_freeN(items->names); | ||||
| MEM_freeN(items); | MEM_freeN(items); | ||||
| Show All 11 Lines | static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but, uiBlock *block) | ||||
| /*float aspect;*/ /*UNUSED*/ | /*float aspect;*/ /*UNUSED*/ | ||||
| int xsize, ysize, xof = 0, yof = 0, center; | int xsize, ysize, xof = 0, yof = 0, center; | ||||
| short dir1 = 0, dir2 = 0; | short dir1 = 0, dir2 = 0; | ||||
| /* transform to window coordinates, using the source button region/block */ | /* transform to window coordinates, using the source button region/block */ | ||||
| ui_block_to_window_rctf(butregion, but->block, &butrct, &but->rect); | ui_block_to_window_rctf(butregion, but->block, &butrct, &but->rect); | ||||
| /* widget_roundbox_set has this correction too, keep in sync */ | /* 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) | if (but->drawflag & UI_BUT_ALIGN_TOP) | ||||
| butrct.ymax += U.pixelsize; | butrct.ymax += U.pixelsize; | ||||
| if (but->drawflag & UI_BUT_ALIGN_LEFT) | if (but->drawflag & UI_BUT_ALIGN_LEFT) | ||||
| butrct.xmin -= U.pixelsize; | butrct.xmin -= U.pixelsize; | ||||
| } | } | ||||
| /* calc block rect */ | /* calc block rect */ | ||||
| if (block->rect.xmin == 0.0f && block->rect.xmax == 0.0f) { | if (block->rect.xmin == 0.0f && block->rect.xmax == 0.0f) { | ||||
| Show All 25 Lines | /* aspect /= (float)xsize;*/ /*UNUSED*/ | ||||
| bool left = 0, right = 0, top = 0, down = 0; | bool left = 0, right = 0, top = 0, down = 0; | ||||
| int winx, winy; | int winx, winy; | ||||
| // int offscreen; | // int offscreen; | ||||
| winx = WM_window_pixels_x(window); | winx = WM_window_pixels_x(window); | ||||
| winy = WM_window_pixels_y(window); | winy = WM_window_pixels_y(window); | ||||
| // wm_window_get_size(window, &winx, &winy); | // wm_window_get_size(window, &winx, &winy); | ||||
| if (block->direction & UI_CENTER) center = ysize / 2; | if (block->direction & UI_DIR_CENTER_Y) { | ||||
| else center = 0; | center = ysize / 2; | ||||
| } | |||||
| else { | |||||
| center = 0; | |||||
| } | |||||
| /* check if there's space at all */ | /* check if there's space at all */ | ||||
| if (butrct.xmin - xsize > 0.0f) left = 1; | if (butrct.xmin - xsize > 0.0f) left = 1; | ||||
| if (butrct.xmax + xsize < winx) right = 1; | if (butrct.xmax + xsize < winx) right = 1; | ||||
| if (butrct.ymin - ysize + center > 0.0f) down = 1; | if (butrct.ymin - ysize + center > 0.0f) down = 1; | ||||
| if (butrct.ymax + ysize - center < winy) top = 1; | if (butrct.ymax + ysize - center < winy) top = 1; | ||||
| if (top == 0 && down == 0) { | if (top == 0 && down == 0) { | ||||
| if (butrct.ymin - ysize < winy - butrct.ymax - ysize) | if (butrct.ymin - ysize < winy - butrct.ymax - ysize) | ||||
| top = 1; | top = 1; | ||||
| else | else | ||||
| down = 1; | down = 1; | ||||
| } | } | ||||
| dir1 = block->direction & UI_DIRECTION; | dir1 = (block->direction & UI_DIR_ALL); | ||||
| /* secundary directions */ | /* secundary directions */ | ||||
| if (dir1 & (UI_TOP | UI_DOWN)) { | if (dir1 & (UI_DIR_UP | UI_DIR_DOWN)) { | ||||
| if (dir1 & UI_LEFT) dir2 = UI_LEFT; | if (dir1 & UI_DIR_LEFT) dir2 = UI_DIR_LEFT; | ||||
| else if (dir1 & UI_RIGHT) dir2 = UI_RIGHT; | else if (dir1 & UI_DIR_RIGHT) dir2 = UI_DIR_RIGHT; | ||||
| dir1 &= (UI_TOP | UI_DOWN); | dir1 &= (UI_DIR_UP | UI_DIR_DOWN); | ||||
| } | } | ||||
| if ((dir2 == 0) && (dir1 == UI_LEFT || dir1 == UI_RIGHT)) dir2 = UI_DOWN; | if ((dir2 == 0) && (dir1 == UI_DIR_LEFT || dir1 == UI_DIR_RIGHT)) dir2 = UI_DIR_DOWN; | ||||
| if ((dir2 == 0) && (dir1 == UI_TOP || dir1 == UI_DOWN)) dir2 = UI_LEFT; | if ((dir2 == 0) && (dir1 == UI_DIR_UP || dir1 == UI_DIR_DOWN)) dir2 = UI_DIR_LEFT; | ||||
| /* no space at all? don't change */ | /* no space at all? don't change */ | ||||
| if (left || right) { | if (left || right) { | ||||
| if (dir1 == UI_LEFT && left == 0) dir1 = UI_RIGHT; | if (dir1 == UI_DIR_LEFT && left == 0) dir1 = UI_DIR_RIGHT; | ||||
| if (dir1 == UI_RIGHT && right == 0) dir1 = UI_LEFT; | if (dir1 == UI_DIR_RIGHT && right == 0) dir1 = UI_DIR_LEFT; | ||||
| /* this is aligning, not append! */ | /* this is aligning, not append! */ | ||||
| if (dir2 == UI_LEFT && right == 0) dir2 = UI_RIGHT; | if (dir2 == UI_DIR_LEFT && right == 0) dir2 = UI_DIR_RIGHT; | ||||
| if (dir2 == UI_RIGHT && left == 0) dir2 = UI_LEFT; | if (dir2 == UI_DIR_RIGHT && left == 0) dir2 = UI_DIR_LEFT; | ||||
| } | } | ||||
| if (down || top) { | if (down || top) { | ||||
| if (dir1 == UI_TOP && top == 0) dir1 = UI_DOWN; | if (dir1 == UI_DIR_UP && top == 0) dir1 = UI_DIR_DOWN; | ||||
| if (dir1 == UI_DOWN && down == 0) dir1 = UI_TOP; | if (dir1 == UI_DIR_DOWN && down == 0) dir1 = UI_DIR_UP; | ||||
| if (dir2 == UI_TOP && top == 0) dir2 = UI_DOWN; | if (dir2 == UI_DIR_UP && top == 0) dir2 = UI_DIR_DOWN; | ||||
| if (dir2 == UI_DOWN && down == 0) dir2 = UI_TOP; | 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; | xof = butrct.xmin - block->rect.xmax; | ||||
| if (dir2 == UI_TOP) yof = butrct.ymin - block->rect.ymin - 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 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; | xof = butrct.xmax - block->rect.xmin; | ||||
| if (dir2 == UI_TOP) yof = butrct.ymin - block->rect.ymin - 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 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; | yof = butrct.ymax - block->rect.ymin; | ||||
| if (dir2 == UI_RIGHT) xof = butrct.xmax - block->rect.xmax; | if (dir2 == UI_DIR_RIGHT) xof = butrct.xmax - block->rect.xmax; | ||||
| else xof = butrct.xmin - block->rect.xmin; | else xof = butrct.xmin - block->rect.xmin; | ||||
| /* changed direction? */ | /* changed direction? */ | ||||
| if ((dir1 & block->direction) == 0) { | if ((dir1 & block->direction) == 0) { | ||||
| uiBlockFlipOrder(block); | UI_block_order_flip(block); | ||||
| } | } | ||||
| } | } | ||||
| else if (dir1 == UI_DOWN) { | else if (dir1 == UI_DIR_DOWN) { | ||||
| yof = butrct.ymin - block->rect.ymax; | yof = butrct.ymin - block->rect.ymax; | ||||
| if (dir2 == UI_RIGHT) xof = butrct.xmax - block->rect.xmax; | if (dir2 == UI_DIR_RIGHT) xof = butrct.xmax - block->rect.xmax; | ||||
| else xof = butrct.xmin - block->rect.xmin; | else xof = butrct.xmin - block->rect.xmin; | ||||
| /* changed direction? */ | /* changed direction? */ | ||||
| if ((dir1 & block->direction) == 0) { | if ((dir1 & block->direction) == 0) { | ||||
| uiBlockFlipOrder(block); | UI_block_order_flip(block); | ||||
| } | } | ||||
| } | } | ||||
| /* and now we handle the exception; no space below or to top */ | /* and now we handle the exception; no space below or to top */ | ||||
| if (top == 0 && down == 0) { | 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 */ | /* align with bottom of screen */ | ||||
| // yof = ysize; (not with menu scrolls) | // yof = ysize; (not with menu scrolls) | ||||
| } | } | ||||
| } | } | ||||
| /* or no space left or right */ | /* or no space left or right */ | ||||
| if (left == 0 && right == 0) { | 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 */ | /* align with left size of screen */ | ||||
| xof = -block->rect.xmin + 5; | xof = -block->rect.xmin + 5; | ||||
| } | } | ||||
| } | } | ||||
| #if 0 | #if 0 | ||||
| /* clamp to window bounds, could be made into an option if its ever annoying */ | /* clamp to window bounds, could be made into an option if its ever annoying */ | ||||
| if ( (offscreen = (block->rect.ymin + yof)) < 0) yof -= offscreen; /* bottom */ | if ( (offscreen = (block->rect.ymin + yof)) < 0) yof -= offscreen; /* bottom */ | ||||
| else if ((offscreen = (block->rect.ymax + yof) - winy) > 0) yof -= offscreen; /* top */ | else if ((offscreen = (block->rect.ymax + yof) - winy) > 0) yof -= offscreen; /* top */ | ||||
| if ( (offscreen = (block->rect.xmin + xof)) < 0) xof -= offscreen; /* left */ | if ( (offscreen = (block->rect.xmin + xof)) < 0) xof -= offscreen; /* left */ | ||||
| else if ((offscreen = (block->rect.xmax + xof) - winx) > 0) xof -= offscreen; /* right */ | else if ((offscreen = (block->rect.xmax + xof) - winx) > 0) xof -= offscreen; /* right */ | ||||
| #endif | #endif | ||||
| } | } | ||||
| /* apply offset, buttons in window coords */ | /* apply offset, buttons in window coords */ | ||||
| for (bt = block->buttons.first; bt; bt = bt->next) { | for (bt = block->buttons.first; bt; bt = bt->next) { | ||||
| ui_block_to_window_rctf(butregion, but->block, &bt->rect, &bt->rect); | ui_block_to_window_rctf(butregion, but->block, &bt->rect, &bt->rect); | ||||
| BLI_rctf_translate(&bt->rect, xof, yof); | BLI_rctf_translate(&bt->rect, xof, yof); | ||||
| /* ui_check_but recalculates drawstring size in pixels */ | /* ui_but_update recalculates drawstring size in pixels */ | ||||
| ui_check_but(bt); | ui_but_update(bt); | ||||
| } | } | ||||
| BLI_rctf_translate(&block->rect, xof, yof); | BLI_rctf_translate(&block->rect, xof, yof); | ||||
| /* safety calculus */ | /* safety calculus */ | ||||
| { | { | ||||
| const float midx = BLI_rctf_cent_x(&butrct); | const float midx = BLI_rctf_cent_x(&butrct); | ||||
| const float midy = BLI_rctf_cent_y(&butrct); | const float midy = BLI_rctf_cent_y(&butrct); | ||||
| Show All 11 Lines | /* safety calculus */ | ||||
| if (midy < block->rect.ymin) block->safety.ymin = block->rect.ymin - 3; | if (midy < block->rect.ymin) block->safety.ymin = block->rect.ymin - 3; | ||||
| else block->safety.ymin = block->rect.ymin - 40; | else block->safety.ymin = block->rect.ymin - 40; | ||||
| /* parent button on top */ | /* parent button on top */ | ||||
| if (midy > block->rect.ymax) block->safety.ymax = block->rect.ymax + 3; | if (midy > block->rect.ymax) block->safety.ymax = block->rect.ymax + 3; | ||||
| else block->safety.ymax = block->rect.ymax + 40; | else block->safety.ymax = block->rect.ymax + 40; | ||||
| /* exception for switched pulldowns... */ | /* exception for switched pulldowns... */ | ||||
| if (dir1 && (dir1 & block->direction) == 0) { | if (dir1 && (dir1 & block->direction) == 0) { | ||||
| if (dir2 == UI_RIGHT) block->safety.xmax = block->rect.xmax + 3; | if (dir2 == UI_DIR_RIGHT) block->safety.xmax = block->rect.xmax + 3; | ||||
| if (dir2 == UI_LEFT) block->safety.xmin = block->rect.xmin - 3; | if (dir2 == UI_DIR_LEFT) block->safety.xmin = block->rect.xmin - 3; | ||||
| } | } | ||||
| block->direction = dir1; | block->direction = dir1; | ||||
| } | } | ||||
| /* keep a list of these, needed for pulldown menus */ | /* keep a list of these, needed for pulldown menus */ | ||||
| saferct = MEM_callocN(sizeof(uiSafetyRct), "uiSafetyRct"); | saferct = MEM_callocN(sizeof(uiSafetyRct), "uiSafetyRct"); | ||||
| saferct->parent = butrct; | saferct->parent = butrct; | ||||
| saferct->safety = block->safety; | saferct->safety = block->safety; | ||||
| Show All 11 Lines | if (ar->do_draw & RGN_DRAW_REFRESH_UI) { | ||||
| ar->do_draw &= ~RGN_DRAW_REFRESH_UI; | ar->do_draw &= ~RGN_DRAW_REFRESH_UI; | ||||
| for (block = ar->uiblocks.first; block; block = block_next) { | for (block = ar->uiblocks.first; block; block = block_next) { | ||||
| block_next = block->next; | block_next = block->next; | ||||
| ui_popup_block_refresh((bContext *)C, block->handle, NULL, NULL); | ui_popup_block_refresh((bContext *)C, block->handle, NULL, NULL); | ||||
| } | } | ||||
| } | } | ||||
| for (block = ar->uiblocks.first; block; block = block->next) | 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) | static void ui_popup_block_clip(wmWindow *window, uiBlock *block) | ||||
| { | { | ||||
| uiBut *bt; | uiBut *bt; | ||||
| float xofs = 0.0f; | float xofs = 0.0f; | ||||
| int width = UI_SCREEN_MARGIN; | int width = UI_SCREEN_MARGIN; | ||||
| int winx, winy; | int winx, winy; | ||||
| ▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | if (block->flag & UI_BLOCK_CLIPTOP) { | ||||
| if (bt->rect.ymax > block->rect.ymax - UI_MENU_SCROLL_ARROW) | if (bt->rect.ymax > block->rect.ymax - UI_MENU_SCROLL_ARROW) | ||||
| bt->flag |= UI_SCROLLED; | bt->flag |= UI_SCROLLED; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void ui_popup_block_remove(bContext *C, uiPopupBlockHandle *handle) | 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) | if (handle->scrolltimer) | ||||
| WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), 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 creatign new popups and refreshing existing ones. | ||||
| */ | */ | ||||
| Show All 17 Lines | |||||
| #endif | #endif | ||||
| /* create ui block */ | /* create ui block */ | ||||
| if (create_func) | if (create_func) | ||||
| block = create_func(C, ar, arg); | block = create_func(C, ar, arg); | ||||
| else | else | ||||
| block = handle_create_func(C, handle, arg); | 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); | BLI_assert(!block->endblock); | ||||
| /* ensure we don't use mouse coords here! */ | /* ensure we don't use mouse coords here! */ | ||||
| #ifdef DEBUG | #ifdef DEBUG | ||||
| window->eventstate = NULL; | window->eventstate = NULL; | ||||
| #endif | #endif | ||||
| if (block->handle) { | if (block->handle) { | ||||
| memcpy(block->handle, handle, sizeof(uiPopupBlockHandle)); | memcpy(block->handle, handle, sizeof(uiPopupBlockHandle)); | ||||
| MEM_freeN(handle); | MEM_freeN(handle); | ||||
| handle = block->handle; | handle = block->handle; | ||||
| } | } | ||||
| else | else | ||||
| block->handle = handle; | block->handle = handle; | ||||
| ar->regiondata = handle; | ar->regiondata = handle; | ||||
| /* set UI_BLOCK_NUMSELECT before uiEndBlock() so we get alphanumeric keys assigned */ | /* set UI_BLOCK_NUMSELECT before UI_block_end() so we get alphanumeric keys assigned */ | ||||
| if (but) { | if (but) { | ||||
| if (but->type == PULLDOWN) { | if (but->type == UI_BTYPE_PULLDOWN) { | ||||
| block->flag |= UI_BLOCK_NUMSELECT; | block->flag |= UI_BLOCK_NUMSELECT; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| block->flag |= UI_BLOCK_POPUP | UI_BLOCK_NUMSELECT; | block->flag |= UI_BLOCK_POPUP | UI_BLOCK_NUMSELECT; | ||||
| } | } | ||||
| block->flag |= UI_BLOCK_LOOP; | block->flag |= UI_BLOCK_LOOP; | ||||
| /* defer this until blocks are translated (below) */ | /* defer this until blocks are translated (below) */ | ||||
| block->oldblock = NULL; | block->oldblock = NULL; | ||||
| if (!block->endblock) | 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 this is being created from a button */ | ||||
| if (but) { | if (but) { | ||||
| block->aspect = but->block->aspect; | block->aspect = but->block->aspect; | ||||
| ui_block_position(window, butregion, but, block); | ui_block_position(window, butregion, but, block); | ||||
| handle->direction = block->direction; | handle->direction = block->direction; | ||||
| } | } | ||||
| else { | else { | ||||
| Show All 38 Lines | if ((x_offset != 0) || (y_offset != 0)) { | ||||
| block->pie_data.flags |= UI_PIE_INITIAL_DIRECTION; | block->pie_data.flags |= UI_PIE_INITIAL_DIRECTION; | ||||
| } | } | ||||
| ar->winrct.xmin = 0; | ar->winrct.xmin = 0; | ||||
| ar->winrct.xmax = winx; | ar->winrct.xmax = winx; | ||||
| ar->winrct.ymin = 0; | ar->winrct.ymin = 0; | ||||
| ar->winrct.ymax = winy; | 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 */ | /* lastly set the buttons at the center of the pie menu, ready for animation */ | ||||
| if (U.pie_animation_timeout > 0) { | if (U.pie_animation_timeout > 0) { | ||||
| for (but = block->buttons.first; but; but = but->next) { | for (but = block->buttons.first; but; but = but->next) { | ||||
| if (but->pie_dir != UI_RADIAL_NONE) { | if (but->pie_dir != UI_RADIAL_NONE) { | ||||
| BLI_rctf_recenter(&but->rect, UNPACK2(block->pie_data.pie_center_spawned)); | BLI_rctf_recenter(&but->rect, UNPACK2(block->pie_data.pie_center_spawned)); | ||||
| } | } | ||||
| } | } | ||||
| Show All 10 Lines | else { | ||||
| ar->winrct.ymin = block->rect.ymin - width; | ar->winrct.ymin = block->rect.ymin - width; | ||||
| ar->winrct.ymax = block->rect.ymax + MENU_TOP; | ar->winrct.ymax = block->rect.ymax + MENU_TOP; | ||||
| ui_block_translate(block, -ar->winrct.xmin, -ar->winrct.ymin); | ui_block_translate(block, -ar->winrct.xmin, -ar->winrct.ymin); | ||||
| } | } | ||||
| if (block_old) { | if (block_old) { | ||||
| block->oldblock = block_old; | block->oldblock = block_old; | ||||
| uiBlockUpdateFromOld(C, block); | UI_block_update_from_old(C, block); | ||||
| uiFreeInactiveBlocks(C, &ar->uiblocks); | UI_blocklist_free_inactive(C, &ar->uiblocks); | ||||
| } | } | ||||
| /* checks which buttons are visible, sets flags to prevent draw (do after region init) */ | /* checks which buttons are visible, sets flags to prevent draw (do after region init) */ | ||||
| ui_popup_block_scrolltest(block); | ui_popup_block_scrolltest(block); | ||||
| /* adds subwindow */ | /* adds subwindow */ | ||||
| ED_region_init(C, ar); | ED_region_init(C, ar); | ||||
| Show All 34 Lines | uiPopupBlockHandle *ui_popup_block_create(bContext *C, ARegion *butregion, uiBut *but, | ||||
| /* store vars to refresh popup (RGN_DRAW_REFRESH_UI) */ | /* store vars to refresh popup (RGN_DRAW_REFRESH_UI) */ | ||||
| handle->popup_create_vars.create_func = create_func; | handle->popup_create_vars.create_func = create_func; | ||||
| handle->popup_create_vars.handle_create_func = handle_create_func; | handle->popup_create_vars.handle_create_func = handle_create_func; | ||||
| handle->popup_create_vars.arg = arg; | handle->popup_create_vars.arg = arg; | ||||
| handle->popup_create_vars.butregion = but ? butregion : NULL; | handle->popup_create_vars.butregion = but ? butregion : NULL; | ||||
| copy_v2_v2_int(handle->popup_create_vars.event_xy, &window->eventstate->x); | copy_v2_v2_int(handle->popup_create_vars.event_xy, &window->eventstate->x); | ||||
| /* create area region */ | /* create area region */ | ||||
| ar = ui_add_temporary_region(CTX_wm_screen(C)); | ar = ui_region_temp_add(CTX_wm_screen(C)); | ||||
| handle->region = ar; | handle->region = ar; | ||||
| memset(&type, 0, sizeof(ARegionType)); | memset(&type, 0, sizeof(ARegionType)); | ||||
| type.draw = ui_block_region_draw; | type.draw = ui_block_region_draw; | ||||
| type.regionid = RGN_TYPE_TEMPORARY; | type.regionid = RGN_TYPE_TEMPORARY; | ||||
| ar->type = &type; | ar->type = &type; | ||||
| UI_add_region_handlers(&ar->handlers); | UI_region_handlers_add(&ar->handlers); | ||||
| block = ui_popup_block_refresh(C, handle, butregion, but); | block = ui_popup_block_refresh(C, handle, butregion, but); | ||||
| handle = block->handle; | handle = block->handle; | ||||
| return handle; | return handle; | ||||
| } | } | ||||
| void ui_popup_block_free(bContext *C, uiPopupBlockHandle *handle) | void ui_popup_block_free(bContext *C, uiPopupBlockHandle *handle) | ||||
| Show All 15 Lines | # ifndef __APPLE__ | ||||
| warp_pointer(x, y); | warp_pointer(x, y); | ||||
| # endif | # endif | ||||
| } | } | ||||
| #endif | #endif | ||||
| /********************* Color Button ****************/ | /********************* Color Button ****************/ | ||||
| /* for picker, while editing hsv */ | /* for picker, while editing hsv */ | ||||
| void ui_set_but_hsv(uiBut *but) | void ui_but_hsv_set(uiBut *but) | ||||
| { | { | ||||
| float col[3]; | float col[3]; | ||||
| ColorPicker *cpicker = but->custom_data; | ColorPicker *cpicker = but->custom_data; | ||||
| float *hsv = cpicker->color_data; | float *hsv = cpicker->color_data; | ||||
| ui_color_picker_to_rgb_v(hsv, col); | ui_color_picker_to_rgb_v(hsv, col); | ||||
| ui_set_but_vectorf(but, col); | ui_but_v3_set(but, col); | ||||
| } | } | ||||
| /* Updates all buttons who share the same color picker as the one passed | /* Updates all buttons who share the same color picker as the one passed | ||||
| * also used by small picker, be careful with name checks below... */ | * 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) | static void ui_update_color_picker_buts_rgb(uiBlock *block, ColorPicker *cpicker, const float rgb[3], bool is_display_space) | ||||
| { | { | ||||
| uiBut *bt; | uiBut *bt; | ||||
| float *hsv = cpicker->color_data; | float *hsv = cpicker->color_data; | ||||
| struct ColorManagedDisplay *display = NULL; | struct ColorManagedDisplay *display = NULL; | ||||
| /* this is to keep the H and S value when V is equal to zero | /* this is to keep the H and S value when V is equal to zero | ||||
| * and we are working in HSV mode, of course! | * and we are working in HSV mode, of course! | ||||
| */ | */ | ||||
| if (is_display_space) { | if (is_display_space) { | ||||
| ui_rgb_to_color_picker_compat_v(rgb, hsv); | ui_rgb_to_color_picker_compat_v(rgb, hsv); | ||||
| } | } | ||||
| else { | else { | ||||
| /* we need to convert to display space to use hsv, because hsv is stored in display space */ | /* we need to convert to display space to use hsv, because hsv is stored in display space */ | ||||
| float rgb_display[3]; | float rgb_display[3]; | ||||
| copy_v3_v3(rgb_display, rgb); | 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); | ui_rgb_to_color_picker_compat_v(rgb_display, hsv); | ||||
| } | } | ||||
| if (block->color_profile) | 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 */ | /* this updates button strings, is hackish... but button pointers are on stack of caller function */ | ||||
| for (bt = block->buttons.first; bt; bt = bt->next) { | for (bt = block->buttons.first; bt; bt = bt->next) { | ||||
| if (bt->custom_data != cpicker) | if (bt->custom_data != cpicker) | ||||
| continue; | continue; | ||||
| if (bt->rnaprop) { | if (bt->rnaprop) { | ||||
| ui_set_but_vectorf(bt, rgb); | ui_but_v3_set(bt, rgb); | ||||
| } | } | ||||
| else if (strcmp(bt->str, "Hex: ") == 0) { | else if (strcmp(bt->str, "Hex: ") == 0) { | ||||
| float rgb_gamma[3]; | float rgb_gamma[3]; | ||||
| unsigned char rgb_gamma_uchar[3]; | unsigned char rgb_gamma_uchar[3]; | ||||
| double intpart; | double intpart; | ||||
| char col[16]; | char col[16]; | ||||
| Show All 12 Lines | else if (strcmp(bt->str, "Hex: ") == 0) { | ||||
| rgb_float_to_uchar(rgb_gamma_uchar, rgb_gamma); | rgb_float_to_uchar(rgb_gamma_uchar, rgb_gamma); | ||||
| BLI_snprintf(col, sizeof(col), "%02X%02X%02X", UNPACK3_EX((unsigned int), rgb_gamma_uchar, )); | BLI_snprintf(col, sizeof(col), "%02X%02X%02X", UNPACK3_EX((unsigned int), rgb_gamma_uchar, )); | ||||
| strcpy(bt->poin, col); | strcpy(bt->poin, col); | ||||
| } | } | ||||
| else if (bt->str[1] == ' ') { | else if (bt->str[1] == ' ') { | ||||
| if (bt->str[0] == 'R') { | 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') { | 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') { | 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') { | 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') { | 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') { | 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') { | 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; | uiBut *but = (uiBut *)bt1; | ||||
| uiPopupBlockHandle *popup = but->block->handle; | uiPopupBlockHandle *popup = but->block->handle; | ||||
| PropertyRNA *prop = but->rnaprop; | PropertyRNA *prop = but->rnaprop; | ||||
| PointerRNA ptr = but->rnapoin; | PointerRNA ptr = but->rnapoin; | ||||
| float rgb[4]; | float rgb[4]; | ||||
| if (prop) { | if (prop) { | ||||
| RNA_property_float_get_array(&ptr, prop, rgb); | RNA_property_float_get_array(&ptr, prop, rgb); | ||||
| ui_update_color_picker_buts_rgb(but->block, but->custom_data, 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) | if (popup) | ||||
| popup->menuretval = UI_RETURN_UPDATE; | 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; | uiBut *but = (uiBut *)bt1; | ||||
| uiPopupBlockHandle *popup = but->block->handle; | uiPopupBlockHandle *popup = but->block->handle; | ||||
| float rgb[3]; | float rgb[3]; | ||||
| ColorPicker *cpicker = but->custom_data; | ColorPicker *cpicker = but->custom_data; | ||||
| float *hsv = cpicker->color_data; | float *hsv = cpicker->color_data; | ||||
| bool use_display_colorspace = ui_color_picker_use_display_colorspace(but); | bool use_display_colorspace = ui_but_is_colorpicker_display_space(but); | ||||
| ui_color_picker_to_rgb_v(hsv, rgb); | ui_color_picker_to_rgb_v(hsv, rgb); | ||||
| /* hsv is saved in display space so convert back */ | /* hsv is saved in display space so convert back */ | ||||
| if (use_display_colorspace) { | 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_color_picker_buts_rgb(but->block, cpicker, rgb, !use_display_colorspace); | ui_update_color_picker_buts_rgb(but->block, cpicker, rgb, !use_display_colorspace); | ||||
| if (popup) | if (popup) | ||||
| popup->menuretval = UI_RETURN_UPDATE; | 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; | uiBut *but = (uiBut *)bt1; | ||||
| uiPopupBlockHandle *popup = but->block->handle; | uiPopupBlockHandle *popup = but->block->handle; | ||||
| ColorPicker *cpicker = but->custom_data; | ColorPicker *cpicker = but->custom_data; | ||||
| char *hexcol = (char *)hexcl; | char *hexcol = (char *)hexcl; | ||||
| float rgb[3]; | float rgb[3]; | ||||
| hex_to_rgb(hexcol, rgb, rgb + 1, rgb + 2); | hex_to_rgb(hexcol, rgb, rgb + 1, rgb + 2); | ||||
| /* Hex code is assumed to be in sRGB space (coming from other applications, web, etc) */ | /* Hex code is assumed to be in sRGB space (coming from other applications, web, etc) */ | ||||
| if (but->block->color_profile) { | if (but->block->color_profile) { | ||||
| /* so we need to linearise it for Blender */ | /* 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_color_picker_buts_rgb(but->block, cpicker, rgb, false); | ui_update_color_picker_buts_rgb(but->block, cpicker, rgb, false); | ||||
| if (popup) | if (popup) | ||||
| popup->menuretval = UI_RETURN_UPDATE; | 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; | uiBut *but = (uiBut *)bt1; | ||||
| uiPopupBlockHandle *popup = but->block->handle; | uiPopupBlockHandle *popup = but->block->handle; | ||||
| if (popup) | if (popup) | ||||
| popup->menuretval = UI_RETURN_OK; | 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; | uiBut *bt; | ||||
| /* tag buttons */ | /* tag buttons */ | ||||
| for (bt = block->buttons.first; bt; bt = bt->next) { | 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) */ | /* RGB sliders (color circle and alpha are always shown) */ | ||||
| if (colormode == 0) bt->flag &= ~UI_HIDDEN; | if (colormode == 0) bt->flag &= ~UI_HIDDEN; | ||||
| else 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 */ | /* HSV sliders */ | ||||
| if (colormode == 1) bt->flag &= ~UI_HIDDEN; | if (colormode == 1) bt->flag &= ~UI_HIDDEN; | ||||
| else 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 */ | /* hex input or gamma correction status label */ | ||||
| if (colormode == 2) bt->flag &= ~UI_HIDDEN; | if (colormode == 2) bt->flag &= ~UI_HIDDEN; | ||||
| else bt->flag |= UI_HIDDEN; | else bt->flag |= UI_HIDDEN; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| 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; | uiBut *bt = bt1; | ||||
| short colormode = ui_get_but_val(bt); | short colormode = ui_but_value_get(bt); | ||||
| picker_new_hide_reveal(bt->block, colormode); | ui_colorpicker_hide_reveal(bt->block, colormode); | ||||
| } | } | ||||
| #define PICKER_H (7.5f * U.widget_unit) | #define PICKER_H (7.5f * U.widget_unit) | ||||
| #define PICKER_W (7.5f * U.widget_unit) | #define PICKER_W (7.5f * U.widget_unit) | ||||
| #define PICKER_SPACE (0.3f * U.widget_unit) | #define PICKER_SPACE (0.3f * U.widget_unit) | ||||
| #define PICKER_BAR (0.7f * U.widget_unit) | #define PICKER_BAR (0.7f * U.widget_unit) | ||||
| #define PICKER_TOTAL_W (PICKER_W + PICKER_SPACE + PICKER_BAR) | #define PICKER_TOTAL_W (PICKER_W + PICKER_SPACE + PICKER_BAR) | ||||
| static void circle_picker(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, ColorPicker *cpicker) | static void ui_colorpicker_circle(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, ColorPicker *cpicker) | ||||
| { | { | ||||
| uiBut *bt; | uiBut *bt; | ||||
| /* HS circle */ | /* 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")); | 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")); | ||||
| uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); | UI_but_func_set(bt, ui_colorpicker_rna_cb, bt, NULL); | ||||
| bt->custom_data = cpicker; | bt->custom_data = cpicker; | ||||
| /* value */ | /* value */ | ||||
| if (U.color_picker_type == USER_CP_CIRCLE_HSL) { | 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"); | 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"); | ||||
| uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); | UI_but_func_set(bt, ui_colorpicker_rna_cb, bt, NULL); | ||||
| } | } | ||||
| else { | 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")); | 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")); | ||||
| uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); | UI_but_func_set(bt, ui_colorpicker_rna_cb, bt, NULL); | ||||
| } | } | ||||
| bt->custom_data = cpicker; | bt->custom_data = cpicker; | ||||
| } | } | ||||
| static void square_picker(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int type, ColorPicker *cpicker) | static void ui_colorpicker_square(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int type, ColorPicker *cpicker) | ||||
| { | { | ||||
| uiBut *bt; | uiBut *bt; | ||||
| int bartype = type + 3; | int bartype = type + 3; | ||||
| /* HS square */ | /* 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")); | 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")); | ||||
| uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); | UI_but_func_set(bt, ui_colorpicker_rna_cb, bt, NULL); | ||||
| bt->custom_data = cpicker; | bt->custom_data = cpicker; | ||||
| /* value */ | /* 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")); | 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")); | ||||
| uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); | UI_but_func_set(bt, ui_colorpicker_rna_cb, bt, NULL); | ||||
| bt->custom_data = cpicker; | bt->custom_data = cpicker; | ||||
| } | } | ||||
| /* a HS circle, V slider, rgb/hsv/hex sliders */ | /* 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 */ | static short colormode = 0; /* temp? 0=rgb, 1=hsv, 2=hex */ | ||||
| uiBut *bt; | uiBut *bt; | ||||
| int width, butwidth; | int width, butwidth; | ||||
| static char tip[50]; | static char tip[50]; | ||||
| static char hexcol[128]; | static char hexcol[128]; | ||||
| float rgb_gamma[3]; | float rgb_gamma[3]; | ||||
| unsigned char rgb_gamma_uchar[3]; | unsigned char rgb_gamma_uchar[3]; | ||||
| float softmin, softmax, hardmin, hardmax, step, precision; | float softmin, softmax, hardmin, hardmax, step, precision; | ||||
| int yco; | int yco; | ||||
| ColorPicker *cpicker = ui_block_picker_new(block); | ColorPicker *cpicker = ui_block_colorpicker_create(block); | ||||
| float *hsv = cpicker->color_data; | float *hsv = cpicker->color_data; | ||||
| width = PICKER_TOTAL_W; | width = PICKER_TOTAL_W; | ||||
| butwidth = width - 1.5f * UI_UNIT_X; | butwidth = width - 1.5f * UI_UNIT_X; | ||||
| /* existence of profile means storage is in linear color space, with display correction */ | /* existence of profile means storage is in linear color space, with display correction */ | ||||
| /* XXX That tip message is not use anywhere! */ | /* XXX That tip message is not use anywhere! */ | ||||
| if (!block->color_profile) { | if (!block->color_profile) { | ||||
| BLI_strncpy(tip, N_("Value in Display Color Space"), sizeof(tip)); | BLI_strncpy(tip, N_("Value in Display Color Space"), sizeof(tip)); | ||||
| copy_v3_v3(rgb_gamma, rgba); | copy_v3_v3(rgb_gamma, rgba); | ||||
| } | } | ||||
| else { | else { | ||||
| BLI_strncpy(tip, N_("Value in Linear RGB Color Space"), sizeof(tip)); | BLI_strncpy(tip, N_("Value in Linear RGB Color Space"), sizeof(tip)); | ||||
| /* make a display version, for Hex code */ | /* make a display version, for Hex code */ | ||||
| copy_v3_v3(rgb_gamma, rgba); | 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 */ | /* sneaky way to check for alpha */ | ||||
| rgba[3] = FLT_MAX; | rgba[3] = FLT_MAX; | ||||
| RNA_property_float_ui_range(ptr, prop, &softmin, &softmax, &step, &precision); | RNA_property_float_ui_range(ptr, prop, &softmin, &softmax, &step, &precision); | ||||
| RNA_property_float_range(ptr, prop, &hardmin, &hardmax); | RNA_property_float_range(ptr, prop, &hardmin, &hardmax); | ||||
| RNA_property_float_get_array(ptr, prop, rgba); | RNA_property_float_get_array(ptr, prop, rgba); | ||||
| switch (U.color_picker_type) { | switch (U.color_picker_type) { | ||||
| case USER_CP_SQUARE_SV: | case USER_CP_SQUARE_SV: | ||||
| square_picker(block, ptr, prop, UI_GRAD_SV, cpicker); | ui_colorpicker_square(block, ptr, prop, UI_GRAD_SV, cpicker); | ||||
| break; | break; | ||||
| case USER_CP_SQUARE_HS: | case USER_CP_SQUARE_HS: | ||||
| square_picker(block, ptr, prop, UI_GRAD_HS, cpicker); | ui_colorpicker_square(block, ptr, prop, UI_GRAD_HS, cpicker); | ||||
| break; | break; | ||||
| case USER_CP_SQUARE_HV: | case USER_CP_SQUARE_HV: | ||||
| square_picker(block, ptr, prop, UI_GRAD_HV, cpicker); | ui_colorpicker_square(block, ptr, prop, UI_GRAD_HV, cpicker); | ||||
| break; | break; | ||||
| /* user default */ | /* user default */ | ||||
| case USER_CP_CIRCLE_HSV: | case USER_CP_CIRCLE_HSV: | ||||
| case USER_CP_CIRCLE_HSL: | case USER_CP_CIRCLE_HSL: | ||||
| default: | default: | ||||
| circle_picker(block, ptr, prop, cpicker); | ui_colorpicker_circle(block, ptr, prop, cpicker); | ||||
| break; | break; | ||||
| } | } | ||||
| /* mode */ | /* mode */ | ||||
| yco = -1.5f * UI_UNIT_Y; | yco = -1.5f * UI_UNIT_Y; | ||||
| uiBlockBeginAlign(block); | UI_block_align_begin(block); | ||||
| bt = uiDefButS(block, ROW, 0, IFACE_("RGB"), 0, yco, width / 3, UI_UNIT_Y, &colormode, 0.0, 0.0, 0, 0, ""); | bt = uiDefButS(block, UI_BTYPE_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_but_func_set(bt, ui_colorpicker_create_mode_cb, bt, NULL); | ||||
| bt->custom_data = cpicker; | bt->custom_data = cpicker; | ||||
| if (U.color_picker_type == USER_CP_CIRCLE_HSL) | 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 | else | ||||
| bt = uiDefButS(block, ROW, 0, IFACE_("HSV"), width / 3, yco, width / 3, UI_UNIT_Y, &colormode, 0.0, 1.0, 0, 0, ""); | bt = uiDefButS(block, UI_BTYPE_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); | UI_but_func_set(bt, ui_colorpicker_create_mode_cb, bt, NULL); | ||||
| bt->custom_data = cpicker; | bt->custom_data = cpicker; | ||||
| bt = uiDefButS(block, ROW, 0, IFACE_("Hex"), 2 * width / 3, yco, width / 3, UI_UNIT_Y, &colormode, 0.0, 2.0, 0, 0, ""); | 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, ""); | ||||
| uiButSetFunc(bt, do_picker_new_mode_cb, bt, NULL); | UI_but_func_set(bt, ui_colorpicker_create_mode_cb, bt, NULL); | ||||
| bt->custom_data = cpicker; | bt->custom_data = cpicker; | ||||
| uiBlockEndAlign(block); | UI_block_align_end(block); | ||||
| yco = -3.0f * UI_UNIT_Y; | yco = -3.0f * UI_UNIT_Y; | ||||
| if (show_picker) { | 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); | 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); | ||||
| uiButSetFunc(bt, close_popup_cb, bt, NULL); | UI_but_func_set(bt, ui_popup_close_cb, bt, NULL); | ||||
| bt->custom_data = cpicker; | bt->custom_data = cpicker; | ||||
| } | } | ||||
| /* RGB values */ | /* RGB values */ | ||||
| uiBlockBeginAlign(block); | UI_block_align_begin(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")); | 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")); | ||||
| uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); | UI_but_func_set(bt, ui_colorpicker_rna_cb, bt, NULL); | ||||
| bt->custom_data = cpicker; | bt->custom_data = cpicker; | ||||
| 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")); | 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")); | ||||
| uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); | UI_but_func_set(bt, ui_colorpicker_rna_cb, bt, NULL); | ||||
| bt->custom_data = cpicker; | bt->custom_data = cpicker; | ||||
| 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")); | 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")); | ||||
| uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); | UI_but_func_set(bt, ui_colorpicker_rna_cb, bt, NULL); | ||||
| bt->custom_data = cpicker; | bt->custom_data = cpicker; | ||||
| /* could use uiItemFullR(col, ptr, prop, -1, 0, UI_ITEM_R_EXPAND|UI_ITEM_R_SLIDER, "", ICON_NONE); | /* 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 */ | /* HSV values */ | ||||
| yco = -3.0f * UI_UNIT_Y; | yco = -3.0f * UI_UNIT_Y; | ||||
| uiBlockBeginAlign(block); | UI_block_align_begin(block); | ||||
| bt = uiDefButF(block, NUMSLI, 0, IFACE_("H:"), 0, yco, butwidth, UI_UNIT_Y, hsv, 0.0, 1.0, 10, 3, TIP_("Hue")); | 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")); | ||||
| 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; | bt->custom_data = cpicker; | ||||
| 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")); | 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")); | ||||
| 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; | bt->custom_data = cpicker; | ||||
| if (U.color_picker_type == USER_CP_CIRCLE_HSL) | 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 | 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 */ | 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; | bt->custom_data = cpicker; | ||||
| uiBlockEndAlign(block); | UI_block_align_end(block); | ||||
| if (rgba[3] != FLT_MAX) { | 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")); | 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")); | ||||
| uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); | UI_but_func_set(bt, ui_colorpicker_rna_cb, bt, NULL); | ||||
| bt->custom_data = cpicker; | bt->custom_data = cpicker; | ||||
| } | } | ||||
| else { | else { | ||||
| rgba[3] = 1.0f; | rgba[3] = 1.0f; | ||||
| } | } | ||||
| rgb_float_to_uchar(rgb_gamma_uchar, rgb_gamma); | rgb_float_to_uchar(rgb_gamma_uchar, rgb_gamma); | ||||
| BLI_snprintf(hexcol, sizeof(hexcol), "%02X%02X%02X", UNPACK3_EX((unsigned int), rgb_gamma_uchar, )); | BLI_snprintf(hexcol, sizeof(hexcol), "%02X%02X%02X", UNPACK3_EX((unsigned int), rgb_gamma_uchar, )); | ||||
| yco = -3.0f * UI_UNIT_Y; | 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)")); | 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)")); | ||||
| uiButSetFunc(bt, do_hex_rna_cb, bt, hexcol); | UI_but_func_set(bt, ui_colorpicker_hex_rna_cb, bt, hexcol); | ||||
| bt->custom_data = cpicker; | bt->custom_data = cpicker; | ||||
| uiDefBut(block, LABEL, 0, IFACE_("(Gamma Corrected)"), 0, yco - UI_UNIT_Y, butwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, ""); | 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); | 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; | float add = 0.0f; | ||||
| if (event->type == WHEELUPMOUSE) | if (event->type == WHEELUPMOUSE) | ||||
| add = 0.05f; | add = 0.05f; | ||||
| else if (event->type == WHEELDOWNMOUSE) | else if (event->type == WHEELDOWNMOUSE) | ||||
| add = -0.05f; | add = -0.05f; | ||||
| if (add != 0.0f) { | if (add != 0.0f) { | ||||
| uiBut *but; | uiBut *but; | ||||
| for (but = block->buttons.first; but; but = but->next) { | 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; | uiPopupBlockHandle *popup = block->handle; | ||||
| float rgb[3]; | float rgb[3]; | ||||
| ColorPicker *cpicker = but->custom_data; | ColorPicker *cpicker = but->custom_data; | ||||
| float *hsv = cpicker->color_data; | float *hsv = cpicker->color_data; | ||||
| bool use_display_colorspace = ui_color_picker_use_display_colorspace(but); | 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) | 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); | ui_rgb_to_color_picker_compat_v(rgb, hsv); | ||||
| hsv[2] = CLAMPIS(hsv[2] + add, 0.0f, 1.0f); | hsv[2] = CLAMPIS(hsv[2] + add, 0.0f, 1.0f); | ||||
| ui_color_picker_to_rgb_v(hsv, rgb); | ui_color_picker_to_rgb_v(hsv, rgb); | ||||
| if (use_display_colorspace) | 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_color_picker_buts_rgb(block, cpicker, rgb, !use_display_colorspace); | ui_update_color_picker_buts_rgb(block, cpicker, rgb, !use_display_colorspace); | ||||
| if (popup) | if (popup) | ||||
| popup->menuretval = UI_RETURN_UPDATE; | popup->menuretval = UI_RETURN_UPDATE; | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| uiBlock *ui_block_func_COLOR(bContext *C, uiPopupBlockHandle *handle, void *arg_but) | uiBlock *ui_block_func_COLOR(bContext *C, uiPopupBlockHandle *handle, void *arg_but) | ||||
| { | { | ||||
| uiBut *but = arg_but; | uiBut *but = arg_but; | ||||
| uiBlock *block; | uiBlock *block; | ||||
| bool show_picker = true; | 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) { | if (RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) { | ||||
| block->color_profile = false; | block->color_profile = false; | ||||
| } | } | ||||
| if (but->block) { | if (but->block) { | ||||
| /* if color block is invoked from a popup we wouldn't be able to set color properly | /* if color block is invoked from a popup we wouldn't be able to set color properly | ||||
| * this is because color picker will close popups first and then will try to figure | * this is because color picker will close popups first and then will try to figure | ||||
| * out active button RNA, and of course it'll fail | * out active button RNA, and of course it'll fail | ||||
| */ | */ | ||||
| show_picker = (but->block->flag & UI_BLOCK_POPUP) == 0; | show_picker = (but->block->flag & UI_BLOCK_POPUP) == 0; | ||||
| } | } | ||||
| copy_v3_v3(handle->retvec, but->editvec); | 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; | 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); | 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 */ | /* and lets go */ | ||||
| block->direction = UI_TOP; | block->direction = UI_DIR_UP; | ||||
| return block; | return block; | ||||
| } | } | ||||
| /************************ Popup Menu Memory ****************************/ | /************************ Popup Menu Memory ****************************/ | ||||
| static unsigned int ui_popup_string_hash(const char *str) | static unsigned int ui_popup_string_hash(const char *str) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | if (pup->but) { | ||||
| minwidth = BLI_rctf_size_x(&pup->but->rect); | minwidth = BLI_rctf_size_x(&pup->but->rect); | ||||
| /* settings (typically rna-enum-popups) show above the button, | /* settings (typically rna-enum-popups) show above the button, | ||||
| * menu's like file-menu, show below */ | * menu's like file-menu, show below */ | ||||
| if (pup->block->direction != 0) { | if (pup->block->direction != 0) { | ||||
| /* allow overriding the direction from menu_func */ | /* allow overriding the direction from menu_func */ | ||||
| direction = pup->block->direction; | direction = pup->block->direction; | ||||
| } | } | ||||
| else if ((pup->but->type == PULLDOWN) || | else if ((pup->but->type == UI_BTYPE_PULLDOWN) || | ||||
| (uiButGetMenuType(pup->but) != NULL)) | (UI_but_menutype_get(pup->but) != NULL)) | ||||
| { | { | ||||
| direction = UI_DOWN; | direction = UI_DIR_DOWN; | ||||
| } | } | ||||
| else { | else { | ||||
| direction = UI_TOP; | direction = UI_DIR_UP; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| minwidth = 50; | minwidth = 50; | ||||
| direction = UI_DOWN; | direction = UI_DIR_DOWN; | ||||
| } | } | ||||
| flip = (direction == UI_DOWN); | flip = (direction == UI_DIR_DOWN); | ||||
| block = pup->block; | block = pup->block; | ||||
| /* in some cases we create the block before the region, | /* in some cases we create the block before the region, | ||||
| * so we set it delayed here if necessary */ | * so we set it delayed here if necessary */ | ||||
| if (BLI_findindex(&handle->region->uiblocks, block) == -1) | if (BLI_findindex(&handle->region->uiblocks, block) == -1) | ||||
| uiBlockSetRegion(block, handle->region); | UI_block_region_set(block, handle->region); | ||||
| block->direction = direction; | 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) { | if (pup->popup) { | ||||
| uiBut *but_activate = NULL; | uiBut *but_activate = NULL; | ||||
| uiBlockSetFlag(block, UI_BLOCK_LOOP | UI_BLOCK_REDRAW | UI_BLOCK_NUMSELECT); | UI_block_flag_enable(block, UI_BLOCK_LOOP | UI_BLOCK_REDRAW | UI_BLOCK_NUMSELECT); | ||||
| uiBlockSetDirection(block, direction); | UI_block_direction_set(block, direction); | ||||
| /* offset the mouse position, possibly based on earlier selection */ | /* offset the mouse position, possibly based on earlier selection */ | ||||
| if ((block->flag & UI_BLOCK_POPUP_MEMORY) && | if ((block->flag & UI_BLOCK_POPUP_MEMORY) && | ||||
| (bt = ui_popup_menu_memory_get(block))) | (bt = ui_popup_menu_memory_get(block))) | ||||
| { | { | ||||
| /* position mouse on last clicked item, at 0.8*width of the | /* position mouse on last clicked item, at 0.8*width of the | ||||
| * button, so it doesn't overlap the text too much, also note | * button, so it doesn't overlap the text too much, also note | ||||
| * the offset is negative because we are inverse moving the | * the offset is negative because we are inverse moving the | ||||
| Show All 21 Lines | else { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* in rare cases this is needed since moving the popup | /* in rare cases this is needed since moving the popup | ||||
| * to be within the window bounds may move it away from the mouse, | * to be within the window bounds may move it away from the mouse, | ||||
| * This ensures we set an item to be active. */ | * This ensures we set an item to be active. */ | ||||
| if (but_activate) { | if (but_activate) { | ||||
| ui_button_activate_over(C, handle->region, but_activate); | ui_but_activate_over(C, handle->region, but_activate); | ||||
| } | } | ||||
| block->minbounds = minwidth; | block->minbounds = minwidth; | ||||
| uiMenuPopupBoundsBlock(block, 1, offset[0], offset[1]); | UI_block_bounds_set_menu(block, 1, offset[0], offset[1]); | ||||
| } | } | ||||
| else { | else { | ||||
| /* for a header menu we set the direction automatic */ | /* for a header menu we set the direction automatic */ | ||||
| if (!pup->slideout && flip) { | if (!pup->slideout && flip) { | ||||
| ScrArea *sa = CTX_wm_area(C); | ScrArea *sa = CTX_wm_area(C); | ||||
| if (sa && sa->headertype == HEADERDOWN) { | if (sa && sa->headertype == HEADERDOWN) { | ||||
| ARegion *ar = CTX_wm_region(C); | ARegion *ar = CTX_wm_region(C); | ||||
| if (ar && ar->regiontype == RGN_TYPE_HEADER) { | if (ar && ar->regiontype == RGN_TYPE_HEADER) { | ||||
| uiBlockSetDirection(block, UI_TOP); | UI_block_direction_set(block, UI_DIR_UP); | ||||
| uiBlockFlipOrder(block); | UI_block_order_flip(block); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| block->minbounds = minwidth; | 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 menu slides out of other menu, override direction */ | ||||
| if (pup->slideout) | if (pup->slideout) | ||||
| uiBlockSetDirection(block, UI_RIGHT); | UI_block_direction_set(block, UI_DIR_RIGHT); | ||||
| return pup->block; | return pup->block; | ||||
| } | } | ||||
| uiPopupBlockHandle *ui_popup_menu_create(bContext *C, ARegion *butregion, uiBut *but, | uiPopupBlockHandle *ui_popup_menu_create(bContext *C, ARegion *butregion, uiBut *but, | ||||
| uiMenuCreateFunc menu_func, void *arg) | uiMenuCreateFunc menu_func, void *arg) | ||||
| { | { | ||||
| wmWindow *window = CTX_wm_window(C); | wmWindow *window = CTX_wm_window(C); | ||||
| uiStyle *style = UI_GetStyleDraw(); | uiStyle *style = UI_style_get_dpi(); | ||||
| uiPopupBlockHandle *handle; | uiPopupBlockHandle *handle; | ||||
| uiPopupMenu *pup; | uiPopupMenu *pup; | ||||
| pup = MEM_callocN(sizeof(uiPopupMenu), __func__); | 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->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->slideout = but ? ui_block_is_menu(but->block) : false; | ||||
| pup->but = but; | pup->but = but; | ||||
| uiLayoutSetOperatorContext(pup->layout, WM_OP_INVOKE_REGION_WIN); | uiLayoutSetOperatorContext(pup->layout, WM_OP_INVOKE_REGION_WIN); | ||||
| if (!but) { | if (!but) { | ||||
| /* no button to start from, means we are a popup */ | /* no button to start from, means we are a popup */ | ||||
| pup->mx = window->eventstate->x; | pup->mx = window->eventstate->x; | ||||
| pup->my = window->eventstate->y; | pup->my = window->eventstate->y; | ||||
| Show All 20 Lines | #endif | ||||
| pup->menu_func = menu_func; | pup->menu_func = menu_func; | ||||
| pup->menu_arg = arg; | pup->menu_arg = arg; | ||||
| handle = ui_popup_block_create(C, butregion, but, NULL, ui_block_func_POPUP, pup); | handle = ui_popup_block_create(C, butregion, but, NULL, ui_block_func_POPUP, pup); | ||||
| if (!but) { | if (!but) { | ||||
| handle->popup = true; | handle->popup = true; | ||||
| UI_add_popup_handlers(C, &window->modalhandlers, handle, false); | UI_popup_handlers_add(C, &window->modalhandlers, handle, false); | ||||
| WM_event_add_mousemove(C); | WM_event_add_mousemove(C); | ||||
| } | } | ||||
| MEM_freeN(pup); | MEM_freeN(pup); | ||||
| return handle; | return handle; | ||||
| } | } | ||||
| /******************** Popup Menu API with begin and end ***********************/ | /******************** Popup Menu API with begin and end ***********************/ | ||||
| /* only return handler, and set optional title */ | /* 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"); | uiPopupMenu *pup = MEM_callocN(sizeof(uiPopupMenu), "popup menu"); | ||||
| uiBut *but; | uiBut *but; | ||||
| pup->block = uiBeginBlock(C, NULL, __func__, UI_EMBOSSP); | pup->block = UI_block_begin(C, NULL, __func__, UI_EMBOSS_PULLDOWN); | ||||
| pup->block->flag |= UI_BLOCK_POPUP_MEMORY; | pup->block->flag |= UI_BLOCK_POPUP_MEMORY; | ||||
| pup->block->puphash = ui_popup_menu_hash(title); | 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 | /* 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 */ | * use popups like this to select one of their options - where having invoke doesn't make sense */ | ||||
| uiLayoutSetOperatorContext(pup->layout, WM_OP_EXEC_REGION_WIN); | uiLayoutSetOperatorContext(pup->layout, WM_OP_EXEC_REGION_WIN); | ||||
| /* create in advance so we can let buttons point to retval already */ | /* create in advance so we can let buttons point to retval already */ | ||||
| pup->block->handle = MEM_callocN(sizeof(uiPopupBlockHandle), "uiPopupBlockHandle"); | pup->block->handle = MEM_callocN(sizeof(uiPopupBlockHandle), "uiPopupBlockHandle"); | ||||
| /* create title button */ | /* create title button */ | ||||
| if (title[0]) { | if (title[0]) { | ||||
| char titlestr[256]; | char titlestr[256]; | ||||
| if (icon) { | if (icon) { | ||||
| BLI_snprintf(titlestr, sizeof(titlestr), " %s", title); | 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 { | 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; | but->drawflag = UI_BUT_TEXT_LEFT; | ||||
| } | } | ||||
| uiItemS(pup->layout); | uiItemS(pup->layout); | ||||
| } | } | ||||
| return pup; | return pup; | ||||
| } | } | ||||
| /* set the whole structure to work */ | /* 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); | wmWindow *window = CTX_wm_window(C); | ||||
| uiPopupBlockHandle *menu; | uiPopupBlockHandle *menu; | ||||
| pup->popup = true; | pup->popup = true; | ||||
| pup->mx = window->eventstate->x; | pup->mx = window->eventstate->x; | ||||
| pup->my = window->eventstate->y; | pup->my = window->eventstate->y; | ||||
| menu = ui_popup_block_create(C, NULL, NULL, NULL, ui_block_func_POPUP, pup); | menu = ui_popup_block_create(C, NULL, NULL, NULL, ui_block_func_POPUP, pup); | ||||
| menu->popup = true; | menu->popup = true; | ||||
| UI_add_popup_handlers(C, &window->modalhandlers, menu, false); | UI_popup_handlers_add(C, &window->modalhandlers, menu, false); | ||||
| WM_event_add_mousemove(C); | WM_event_add_mousemove(C); | ||||
| MEM_freeN(pup); | MEM_freeN(pup); | ||||
| } | } | ||||
| uiLayout *uiPupMenuLayout(uiPopupMenu *pup) | uiLayout *UI_popup_menu_layout(uiPopupMenu *pup) | ||||
| { | { | ||||
| return pup->layout; | return pup->layout; | ||||
| } | } | ||||
| /*************************** Pie Menus ***************************************/ | /*************************** Pie Menus ***************************************/ | ||||
| static uiBlock *ui_block_func_PIE(bContext *UNUSED(C), uiPopupBlockHandle *handle, void *arg_pie) | static uiBlock *ui_block_func_PIE(bContext *UNUSED(C), uiPopupBlockHandle *handle, void *arg_pie) | ||||
| { | { | ||||
| uiBlock *block; | uiBlock *block; | ||||
| uiPieMenu *pie = arg_pie; | uiPieMenu *pie = arg_pie; | ||||
| int minwidth, width, height; | int minwidth, width, height; | ||||
| minwidth = 50; | minwidth = 50; | ||||
| block = pie->block_radial; | block = pie->block_radial; | ||||
| /* in some cases we create the block before the region, | /* in some cases we create the block before the region, | ||||
| * so we set it delayed here if necessary */ | * so we set it delayed here if necessary */ | ||||
| if (BLI_findindex(&handle->region->uiblocks, block) == -1) | 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_REDRAW | UI_BLOCK_NUMSELECT); | ||||
| block->minbounds = minwidth; | block->minbounds = minwidth; | ||||
| block->bounds = 1; | block->bounds = 1; | ||||
| block->mx = 0; | block->mx = 0; | ||||
| block->my = 0; | block->my = 0; | ||||
| block->bounds_type = UI_BLOCK_BOUNDS_PIE_CENTER; | block->bounds_type = UI_BLOCK_BOUNDS_PIE_CENTER; | ||||
| block->pie_data.pie_center_spawned[0] = pie->mx; | block->pie_data.pie_center_spawned[0] = pie->mx; | ||||
| block->pie_data.pie_center_spawned[1] = pie->my; | block->pie_data.pie_center_spawned[1] = pie->my; | ||||
| return pie->block_radial; | 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) + | return (UI_fontstyle_string_width(name) + | ||||
| (UI_UNIT_X * (1.50f + (icon ? 0.25f : 0.0f)))); | (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; | uiStyle *style; | ||||
| uiPieMenu *pie; | uiPieMenu *pie; | ||||
| short event_type; | short event_type; | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| style = UI_GetStyleDraw(); | style = UI_style_get_dpi(); | ||||
| pie = MEM_callocN(sizeof(uiPopupMenu), "pie menu"); | pie = MEM_callocN(sizeof(uiPopupMenu), "pie menu"); | ||||
| pie->block_radial = uiBeginBlock(C, NULL, __func__, UI_EMBOSS); | pie->block_radial = UI_block_begin(C, NULL, __func__, UI_EMBOSS); | ||||
| /* may be useful later to allow spawning pies | /* may be useful later to allow spawning pies | ||||
| * from old positions */ | * from old positions */ | ||||
| /* pie->block_radial->flag |= UI_BLOCK_POPUP_MEMORY; */ | /* pie->block_radial->flag |= UI_BLOCK_POPUP_MEMORY; */ | ||||
| pie->block_radial->puphash = ui_popup_menu_hash(title); | pie->block_radial->puphash = ui_popup_menu_hash(title); | ||||
| pie->block_radial->flag |= UI_BLOCK_RADIAL; | pie->block_radial->flag |= UI_BLOCK_RADIAL; | ||||
| /* if pie is spawned by a left click, it is always assumed to be click style */ | /* if pie is spawned by a left click, it is always assumed to be click style */ | ||||
| if (event->type == LEFTMOUSE) { | if (event->type == LEFTMOUSE) { | ||||
| Show All 14 Lines | else { | ||||
| else { | else { | ||||
| event_type = event->type; | event_type = event->type; | ||||
| } | } | ||||
| pie->block_radial->pie_data.event = event_type; | pie->block_radial->pie_data.event = event_type; | ||||
| win->lock_pie_event = event_type; | win->lock_pie_event = event_type; | ||||
| } | } | ||||
| pie->layout = uiBlockLayout(pie->block_radial, UI_LAYOUT_VERTICAL, UI_LAYOUT_PIEMENU, 0, 0, 200, 0, 0, style); | 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->mx = event->x; | ||||
| pie->my = event->y; | pie->my = event->y; | ||||
| /* create title button */ | /* create title button */ | ||||
| if (title[0]) { | if (title[0]) { | ||||
| uiBut *but; | uiBut *but; | ||||
| char titlestr[256]; | char titlestr[256]; | ||||
| int w; | int w; | ||||
| if (icon) { | if (icon) { | ||||
| BLI_snprintf(titlestr, sizeof(titlestr), " %s", title); | BLI_snprintf(titlestr, sizeof(titlestr), " %s", title); | ||||
| w = uiPieTitleWidth(titlestr, icon); | w = ui_pie_menu_title_width(titlestr, icon); | ||||
| but = uiDefIconTextBut(pie->block_radial, LABEL, 0, icon, titlestr, 0, 0, w, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, ""); | 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 { | else { | ||||
| w = uiPieTitleWidth(title, 0); | w = ui_pie_menu_title_width(title, 0); | ||||
| but = uiDefBut(pie->block_radial, LABEL, 0, title, 0, 0, w, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 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 */ | /* do not align left */ | ||||
| but->drawflag &= ~UI_BUT_TEXT_LEFT; | but->drawflag &= ~UI_BUT_TEXT_LEFT; | ||||
| } | } | ||||
| return pie; | return pie; | ||||
| } | } | ||||
| void uiPieMenuEnd(bContext *C, uiPieMenu *pie) | void UI_pie_menu_end(bContext *C, uiPieMenu *pie) | ||||
| { | { | ||||
| wmWindow *window = CTX_wm_window(C); | wmWindow *window = CTX_wm_window(C); | ||||
| uiPopupBlockHandle *menu; | uiPopupBlockHandle *menu; | ||||
| menu = ui_popup_block_create(C, NULL, NULL, NULL, ui_block_func_PIE, pie); | menu = ui_popup_block_create(C, NULL, NULL, NULL, ui_block_func_PIE, pie); | ||||
| menu->popup = true; | menu->popup = true; | ||||
| menu->towardstime = PIL_check_seconds_timer(); | menu->towardstime = PIL_check_seconds_timer(); | ||||
| UI_add_popup_handlers(C, &window->modalhandlers, menu, true); | UI_popup_handlers_add(C, &window->modalhandlers, menu, true); | ||||
| WM_event_add_mousemove(C); | WM_event_add_mousemove(C); | ||||
| MEM_freeN(pie); | MEM_freeN(pie); | ||||
| } | } | ||||
| uiLayout *uiPieMenuLayout(uiPieMenu *pie) | uiLayout *UI_pie_menu_layout(uiPieMenu *pie) | ||||
| { | { | ||||
| return pie->layout; | return pie->layout; | ||||
| } | } | ||||
| int 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; | uiPieMenu *pie; | ||||
| uiLayout *layout; | uiLayout *layout; | ||||
| Menu menu; | Menu menu; | ||||
| MenuType *mt = WM_menutype_find(idname, true); | MenuType *mt = WM_menutype_find(idname, true); | ||||
| if (mt == NULL) { | if (mt == NULL) { | ||||
| printf("%s: named menu \"%s\" not found\n", __func__, idname); | printf("%s: named menu \"%s\" not found\n", __func__, idname); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| if (mt->poll && mt->poll(C, mt) == 0) | if (mt->poll && mt->poll(C, mt) == 0) | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| pie = uiPieMenuBegin(C, IFACE_(mt->label), ICON_NONE, event); | pie = UI_pie_menu_begin(C, IFACE_(mt->label), ICON_NONE, event); | ||||
| layout = uiPieMenuLayout(pie); | layout = UI_pie_menu_layout(pie); | ||||
| menu.layout = layout; | menu.layout = layout; | ||||
| menu.type = mt; | menu.type = mt; | ||||
| if (G.debug & G_DEBUG_WM) { | if (G.debug & G_DEBUG_WM) { | ||||
| printf("%s: opening menu \"%s\"\n", __func__, idname); | printf("%s: opening menu \"%s\"\n", __func__, idname); | ||||
| } | } | ||||
| mt->draw(C, &menu); | mt->draw(C, &menu); | ||||
| uiPieMenuEnd(C, pie); | UI_pie_menu_end(C, pie); | ||||
| return OPERATOR_INTERFACE; | return OPERATOR_INTERFACE; | ||||
| } | } | ||||
| int uiPieOperatorEnumInvoke(struct bContext *C, const char *title, const char *opname, | int UI_pie_menu_invoke_from_operator_enum(struct bContext *C, const char *title, const char *opname, | ||||
| const char *propname, const wmEvent *event) | const char *propname, const wmEvent *event) | ||||
| { | { | ||||
| uiPieMenu *pie; | uiPieMenu *pie; | ||||
| uiLayout *layout; | uiLayout *layout; | ||||
| pie = uiPieMenuBegin(C, IFACE_(title), ICON_NONE, event); | pie = UI_pie_menu_begin(C, IFACE_(title), ICON_NONE, event); | ||||
| layout = uiPieMenuLayout(pie); | layout = UI_pie_menu_layout(pie); | ||||
| layout = uiLayoutRadial(layout); | layout = uiLayoutRadial(layout); | ||||
| uiItemsEnumO(layout, opname, propname); | uiItemsEnumO(layout, opname, propname); | ||||
| uiPieMenuEnd(C, pie); | UI_pie_menu_end(C, pie); | ||||
| return OPERATOR_INTERFACE; | return OPERATOR_INTERFACE; | ||||
| } | } | ||||
| int uiPieEnumInvoke(struct bContext *C, const char *title, const char *path, | int UI_pie_menu_invoke_from_rna_enum(struct bContext *C, const char *title, const char *path, | ||||
| const wmEvent *event) | const wmEvent *event) | ||||
| { | { | ||||
| PointerRNA ctx_ptr; | PointerRNA ctx_ptr; | ||||
| PointerRNA r_ptr; | PointerRNA r_ptr; | ||||
| PropertyRNA *r_prop; | PropertyRNA *r_prop; | ||||
| uiPieMenu *pie; | uiPieMenu *pie; | ||||
| uiLayout *layout; | uiLayout *layout; | ||||
| RNA_pointer_create(NULL, &RNA_Context, C, &ctx_ptr); | RNA_pointer_create(NULL, &RNA_Context, C, &ctx_ptr); | ||||
| if (!RNA_path_resolve(&ctx_ptr, path, &r_ptr, &r_prop)) { | if (!RNA_path_resolve(&ctx_ptr, path, &r_ptr, &r_prop)) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| /* invalid property, only accept enums */ | /* invalid property, only accept enums */ | ||||
| if (RNA_property_type(r_prop) != PROP_ENUM) { | if (RNA_property_type(r_prop) != PROP_ENUM) { | ||||
| BLI_assert(0); | BLI_assert(0); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| pie = uiPieMenuBegin(C, IFACE_(title), ICON_NONE, event); | pie = UI_pie_menu_begin(C, IFACE_(title), ICON_NONE, event); | ||||
| layout = uiPieMenuLayout(pie); | layout = UI_pie_menu_layout(pie); | ||||
| layout = uiLayoutRadial(layout); | layout = uiLayoutRadial(layout); | ||||
| uiItemFullR(layout, &r_ptr, r_prop, RNA_NO_INDEX, 0, UI_ITEM_R_EXPAND, NULL, 0); | 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; | return OPERATOR_INTERFACE; | ||||
| } | } | ||||
| /*************************** Standard Popup Menus ****************************/ | /*************************** Standard Popup Menus ****************************/ | ||||
| void uiPupMenuReports(bContext *C, ReportList *reports) | void UI_popup_menu_reports(bContext *C, ReportList *reports) | ||||
| { | { | ||||
| Report *report; | Report *report; | ||||
| uiPopupMenu *pup = NULL; | uiPopupMenu *pup = NULL; | ||||
| uiLayout *layout; | uiLayout *layout; | ||||
| if (!CTX_wm_window(C)) | if (!CTX_wm_window(C)) | ||||
| return; | return; | ||||
| for (report = reports->list.first; report; report = report->next) { | for (report = reports->list.first; report; report = report->next) { | ||||
| int icon; | int icon; | ||||
| const char *msg, *msg_next; | const char *msg, *msg_next; | ||||
| if (report->type < reports->printlevel) { | if (report->type < reports->printlevel) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (pup == NULL) { | if (pup == NULL) { | ||||
| char title[UI_MAX_DRAW_STR]; | char title[UI_MAX_DRAW_STR]; | ||||
| BLI_snprintf(title, sizeof(title), "%s: %s", IFACE_("Report"), report->typestr); | BLI_snprintf(title, sizeof(title), "%s: %s", IFACE_("Report"), report->typestr); | ||||
| pup = uiPupMenuBegin(C, title, ICON_NONE); | pup = UI_popup_menu_begin(C, title, ICON_NONE); | ||||
| layout = uiPupMenuLayout(pup); | layout = UI_popup_menu_layout(pup); | ||||
| } | } | ||||
| else { | else { | ||||
| uiItemS(layout); | uiItemS(layout); | ||||
| } | } | ||||
| /* split each newline into a label */ | /* split each newline into a label */ | ||||
| msg = report->message; | msg = report->message; | ||||
| icon = uiIconFromReportType(report->type); | icon = UI_icon_from_report_type(report->type); | ||||
| do { | do { | ||||
| char buf[UI_MAX_DRAW_STR]; | char buf[UI_MAX_DRAW_STR]; | ||||
| msg_next = strchr(msg, '\n'); | msg_next = strchr(msg, '\n'); | ||||
| if (msg_next) { | if (msg_next) { | ||||
| msg_next++; | msg_next++; | ||||
| BLI_strncpy(buf, msg, MIN2(sizeof(buf), msg_next - msg)); | BLI_strncpy(buf, msg, MIN2(sizeof(buf), msg_next - msg)); | ||||
| msg = buf; | msg = buf; | ||||
| } | } | ||||
| uiItemL(layout, msg, icon); | uiItemL(layout, msg, icon); | ||||
| icon = ICON_NONE; | icon = ICON_NONE; | ||||
| } while ((msg = msg_next) && *msg); | } while ((msg = msg_next) && *msg); | ||||
| } | } | ||||
| if (pup) { | if (pup) { | ||||
| uiPupMenuEnd(C, pup); | UI_popup_menu_end(C, pup); | ||||
| } | } | ||||
| } | } | ||||
| int uiPupMenuInvoke(bContext *C, const char *idname, ReportList *reports) | int UI_popup_menu_invoke(bContext *C, const char *idname, ReportList *reports) | ||||
| { | { | ||||
| uiPopupMenu *pup; | uiPopupMenu *pup; | ||||
| uiLayout *layout; | uiLayout *layout; | ||||
| Menu menu; | Menu menu; | ||||
| MenuType *mt = WM_menutype_find(idname, true); | MenuType *mt = WM_menutype_find(idname, true); | ||||
| if (mt == NULL) { | if (mt == NULL) { | ||||
| BKE_reportf(reports, RPT_ERROR, "Menu \"%s\" not found", idname); | BKE_reportf(reports, RPT_ERROR, "Menu \"%s\" not found", idname); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| if (mt->poll && mt->poll(C, mt) == 0) | if (mt->poll && mt->poll(C, mt) == 0) | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| pup = uiPupMenuBegin(C, IFACE_(mt->label), ICON_NONE); | pup = UI_popup_menu_begin(C, IFACE_(mt->label), ICON_NONE); | ||||
| layout = uiPupMenuLayout(pup); | layout = UI_popup_menu_layout(pup); | ||||
| menu.layout = layout; | menu.layout = layout; | ||||
| menu.type = mt; | menu.type = mt; | ||||
| if (G.debug & G_DEBUG_WM) { | if (G.debug & G_DEBUG_WM) { | ||||
| printf("%s: opening menu \"%s\"\n", __func__, idname); | printf("%s: opening menu \"%s\"\n", __func__, idname); | ||||
| } | } | ||||
| mt->draw(C, &menu); | mt->draw(C, &menu); | ||||
| uiPupMenuEnd(C, pup); | UI_popup_menu_end(C, pup); | ||||
| return OPERATOR_INTERFACE; | return OPERATOR_INTERFACE; | ||||
| } | } | ||||
| /*************************** Popup Block API **************************/ | /*************************** 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); | wmWindow *window = CTX_wm_window(C); | ||||
| uiPopupBlockHandle *handle; | uiPopupBlockHandle *handle; | ||||
| handle = ui_popup_block_create(C, NULL, NULL, func, NULL, arg); | handle = ui_popup_block_create(C, NULL, NULL, func, NULL, arg); | ||||
| handle->popup = true; | handle->popup = true; | ||||
| handle->optype = (opname) ? WM_operatortype_find(opname, 0) : NULL; | handle->optype = (opname) ? WM_operatortype_find(opname, 0) : NULL; | ||||
| handle->opcontext = opcontext; | handle->opcontext = opcontext; | ||||
| UI_add_popup_handlers(C, &window->modalhandlers, handle, false); | UI_popup_handlers_add(C, &window->modalhandlers, handle, false); | ||||
| WM_event_add_mousemove(C); | 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); | wmWindow *window = CTX_wm_window(C); | ||||
| uiPopupBlockHandle *handle; | uiPopupBlockHandle *handle; | ||||
| handle = ui_popup_block_create(C, NULL, NULL, func, NULL, arg); | handle = ui_popup_block_create(C, NULL, NULL, func, NULL, arg); | ||||
| handle->popup = true; | handle->popup = true; | ||||
| handle->retvalue = 1; | handle->retvalue = 1; | ||||
| handle->popup_arg = arg; | handle->popup_arg = arg; | ||||
| handle->popup_func = popup_func; | handle->popup_func = popup_func; | ||||
| handle->cancel_func = cancel_func; | handle->cancel_func = cancel_func; | ||||
| // handle->opcontext = opcontext; | // handle->opcontext = opcontext; | ||||
| UI_add_popup_handlers(C, &window->modalhandlers, handle, false); | UI_popup_handlers_add(C, &window->modalhandlers, handle, false); | ||||
| WM_event_add_mousemove(C); | WM_event_add_mousemove(C); | ||||
| } | } | ||||
| #if 0 /* UNUSED */ | #if 0 /* UNUSED */ | ||||
| void uiPupBlockOperator(bContext *C, uiBlockCreateFunc func, wmOperator *op, int opcontext) | void uiPupBlockOperator(bContext *C, uiBlockCreateFunc func, wmOperator *op, int opcontext) | ||||
| { | { | ||||
| wmWindow *window = CTX_wm_window(C); | wmWindow *window = CTX_wm_window(C); | ||||
| uiPopupBlockHandle *handle; | uiPopupBlockHandle *handle; | ||||
| handle = ui_popup_block_create(C, NULL, NULL, func, NULL, op); | handle = ui_popup_block_create(C, NULL, NULL, func, NULL, op); | ||||
| handle->popup = 1; | handle->popup = 1; | ||||
| handle->retvalue = 1; | handle->retvalue = 1; | ||||
| handle->popup_arg = op; | handle->popup_arg = op; | ||||
| handle->popup_func = operator_cb; | handle->popup_func = operator_cb; | ||||
| handle->cancel_func = confirm_cancel_operator; | handle->cancel_func = confirm_cancel_operator; | ||||
| handle->opcontext = opcontext; | handle->opcontext = opcontext; | ||||
| UI_add_popup_handlers(C, &window->modalhandlers, handle); | UI_popup_handlers_add(C, &window->modalhandlers, handle); | ||||
| WM_event_add_mousemove(C); | WM_event_add_mousemove(C); | ||||
| } | } | ||||
| #endif | #endif | ||||
| void uiPupBlockClose(bContext *C, uiBlock *block) | void UI_popup_block_close(bContext *C, uiBlock *block) | ||||
| { | { | ||||
| if (block->handle) { | if (block->handle) { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| /* if loading new .blend while popup is open, window will be NULL */ | /* if loading new .blend while popup is open, window will be NULL */ | ||||
| if (win) { | 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); | ui_popup_block_free(C, block->handle); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| ColorPicker *ui_block_picker_new(struct uiBlock *block) | ColorPicker *ui_block_colorpicker_create(struct uiBlock *block) | ||||
| { | { | ||||
| ColorPicker *cpicker = MEM_callocN(sizeof(ColorPicker), "color_picker"); | ColorPicker *cpicker = MEM_callocN(sizeof(ColorPicker), "color_picker"); | ||||
| BLI_addhead(&block->color_pickers.list, cpicker); | BLI_addhead(&block->color_pickers.list, cpicker); | ||||
| return cpicker; | return cpicker; | ||||
| } | } | ||||
| void ui_rgb_to_color_picker_compat_v(const float rgb[3], float r_cp[3]) | void ui_rgb_to_color_picker_compat_v(const float rgb[3], float r_cp[3]) | ||||
| ▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines | |||||