Fix color ramp eyedropper menu item

This couldn't be accessed because the poll function was checking the
active button.

Add a "color_ramp" context pointer which is set by the menu.

Alternative fix to D3984
This commit is contained in:
Campbell Barton 2019-03-18 17:41:37 +11:00
parent 8f5ba8e1a1
commit b749e43cd3
Notes: blender-bot 2023-02-14 01:57:16 +01:00
Referenced by issue #66524, CRASH Eyedropper operator crash blender
8 changed files with 42 additions and 17 deletions

View File

@ -1186,6 +1186,8 @@ void uiTemplateComponentMenu(uiLayout *layout, struct PointerRNA *ptr, const cha
void uiTemplateNodeSocket(uiLayout *layout, struct bContext *C, float *color);
void uiTemplateCacheFile(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, const char *propname);
struct ColorBand *UI_block_get_colorband_from_template_menu(struct uiBlock *block);
/* Default UIList class name, keep in sync with its declaration in bl_ui/__init__.py */
#define UI_UL_DEFAULT_CLASS_NAME "UI_UL_list"
void uiTemplateList(

View File

@ -96,6 +96,13 @@ static bool eyedropper_colorband_init(bContext *C, wmOperator *op)
band = (ColorBand *)but->custom_data;
}
if (!band) {
PointerRNA ptr = CTX_data_pointer_get_type(C, "color_ramp", &RNA_ColorRamp);
if (ptr.data != NULL) {
band = ptr.data;
}
}
if (!band) {
return false;
}
@ -300,7 +307,14 @@ static int eyedropper_colorband_exec(bContext *C, wmOperator *op)
static bool eyedropper_colorband_poll(bContext *C)
{
uiBut *but = UI_context_active_but_get(C);
return (but && but->type == UI_BTYPE_COLORBAND);
if (but && but->type == UI_BTYPE_COLORBAND) {
return true;
}
PointerRNA ptr = CTX_data_pointer_get_type(C, "color_ramp", &RNA_ColorRamp);
if (ptr.data != NULL) {
return true;
}
return false;
}

View File

@ -97,6 +97,8 @@ typedef enum {
UI_WTYPE_PROGRESSBAR,
} uiWidgetTypeEnum;
#define UI_MENU_PADDING (int)(0.2f * UI_UNIT_Y)
#define UI_MENU_WIDTH_MIN (UI_UNIT_Y * 9)
/* some extra padding added to menus containing submenu icons */
#define UI_MENU_SUBMENU_PADDING (6 * UI_DPI_FAC)

View File

@ -311,7 +311,7 @@ uiPopupBlockHandle *ui_popup_menu_create(
pup = MEM_callocN(sizeof(uiPopupMenu), __func__);
pup->block = UI_block_begin(C, NULL, __func__, UI_EMBOSS_PULLDOWN);
pup->block->flag |= UI_BLOCK_NUMSELECT; /* default menus to numselect */
pup->layout = UI_block_layout(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, UI_MENU_PADDING, style);
pup->slideout = but ? ui_block_is_menu(but->block) : false;
pup->but = but;
uiLayoutSetOperatorContext(pup->layout, WM_OP_INVOKE_REGION_WIN);
@ -377,7 +377,7 @@ uiPopupMenu *UI_popup_menu_begin_ex(bContext *C, const char *title, const char *
pup->block = UI_block_begin(C, NULL, block_name, UI_EMBOSS_PULLDOWN);
pup->block->flag |= UI_BLOCK_POPUP_MEMORY | UI_BLOCK_IS_FLIP;
pup->block->puphash = ui_popup_menu_hash(title);
pup->layout = UI_block_layout(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, UI_MENU_PADDING, style);
/* note, this intentionally differs from the menu & submenu default because many operators
* use popups like this to select one of their options -

View File

@ -106,7 +106,7 @@ static void ui_popover_create_block(bContext *C, uiPopover *pup, int opcontext)
pup->layout = UI_block_layout(
pup->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0,
pup->ui_size_x, 0, MENU_PADDING, style);
pup->ui_size_x, 0, UI_MENU_PADDING, style);
uiLayoutSetOperatorContext(pup->layout, opcontext);

View File

@ -203,13 +203,13 @@ static void ui_popup_block_position(wmWindow *window, ARegion *butregion, uiBut
if (dir1 == UI_DIR_LEFT) {
offset_x = butrct.xmin - block->rect.xmax;
if (dir2 == UI_DIR_UP) offset_y = butrct.ymin - block->rect.ymin - center_y - MENU_PADDING;
else offset_y = butrct.ymax - block->rect.ymax + center_y + MENU_PADDING;
if (dir2 == UI_DIR_UP) offset_y = butrct.ymin - block->rect.ymin - center_y - UI_MENU_PADDING;
else offset_y = butrct.ymax - block->rect.ymax + center_y + UI_MENU_PADDING;
}
else if (dir1 == UI_DIR_RIGHT) {
offset_x = butrct.xmax - block->rect.xmin;
if (dir2 == UI_DIR_UP) offset_y = butrct.ymin - block->rect.ymin - center_y - MENU_PADDING;
else offset_y = butrct.ymax - block->rect.ymax + center_y + MENU_PADDING;
if (dir2 == UI_DIR_UP) offset_y = butrct.ymin - block->rect.ymin - center_y - UI_MENU_PADDING;
else offset_y = butrct.ymax - block->rect.ymax + center_y + UI_MENU_PADDING;
}
else if (dir1 == UI_DIR_UP) {
offset_y = butrct.ymax - block->rect.ymin;

View File

@ -23,8 +23,6 @@
#ifndef __INTERFACE_REGIONS_INTERN_H__
#define __INTERFACE_REGIONS_INTERN_H__
#define MENU_PADDING (int)(0.2f * UI_UNIT_Y)
/* interface_region_menu_popup.c */
uint ui_popup_menu_hash(const char *str);

View File

@ -2378,15 +2378,26 @@ static void colorband_tools_dofunc(bContext *C, void *coba_v, int event)
static uiBlock *colorband_tools_func(
bContext *C, ARegion *ar, void *coba_v)
{
uiStyle *style = UI_style_get_dpi();
ColorBand *coba = coba_v;
uiBlock *block;
short yco = 0, menuwidth = 10 * UI_UNIT_X;
block = UI_block_begin(C, ar, __func__, UI_EMBOSS);
block = UI_block_begin(C, ar, __func__, UI_EMBOSS_PULLDOWN);
UI_block_func_butmenu_set(block, colorband_tools_dofunc, coba);
uiLayout *layout = UI_block_layout(
block, UI_LAYOUT_VERTICAL, UI_LAYOUT_MENU, 0, 0, UI_MENU_WIDTH_MIN, 0, UI_MENU_PADDING, style);
UI_block_layout_set_current(block, layout);
{
PointerRNA coba_ptr;
RNA_pointer_create(NULL, &RNA_ColorRamp, coba, &coba_ptr);
uiLayoutSetContextPointer(layout, "color_ramp", &coba_ptr);
}
/* We could move these to operators,
* although this isn't important unless we want to assign key shortcuts to them. */
{
uiBut *but;
uiDefIconTextBut(
block, UI_BTYPE_BUT_MENU, 1, ICON_BLANK1,
IFACE_("Flip Color Ramp"), 0, yco -= UI_UNIT_Y, menuwidth, UI_UNIT_Y,
@ -2399,11 +2410,9 @@ static uiBlock *colorband_tools_func(
block, UI_BTYPE_BUT_MENU, 1, ICON_BLANK1,
IFACE_("Distribute Stops Evenly"), 0, yco -= UI_UNIT_Y, menuwidth, UI_UNIT_Y,
NULL, 0.0, 0.0, 0, CB_FUNC_DISTRIBUTE_EVENLY, "");
but = uiDefIconTextButO(
block, UI_BTYPE_BUT_MENU, "UI_OT_eyedropper_colorband", WM_OP_INVOKE_DEFAULT, ICON_EYEDROPPER,
IFACE_("Eyedropper"), 0, yco -= UI_UNIT_Y, menuwidth, UI_UNIT_Y,
"");
but->custom_data = coba;
uiItemO(layout, IFACE_("Eyedropper"), ICON_EYEDROPPER, "UI_OT_eyedropper_colorband");
uiDefIconTextBut(
block, UI_BTYPE_BUT_MENU, 1, ICON_BLANK1, IFACE_("Reset Color Ramp"),
0, yco -= UI_UNIT_Y, menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, CB_FUNC_RESET, "");