[Bf-blender-cvs] [b749e43cd3e] master: Fix color ramp eyedropper menu item

Campbell Barton noreply at git.blender.org
Mon Mar 18 07:51:01 CET 2019


Commit: b749e43cd3e2a76a58f3fb7b47959b684061ea9b
Author: Campbell Barton
Date:   Mon Mar 18 17:41:37 2019 +1100
Branches: master
https://developer.blender.org/rBb749e43cd3e2a76a58f3fb7b47959b684061ea9b

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

===================================================================

M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface_eyedropper_colorband.c
M	source/blender/editors/interface/interface_intern.h
M	source/blender/editors/interface/interface_region_menu_popup.c
M	source/blender/editors/interface/interface_region_popover.c
M	source/blender/editors/interface/interface_region_popup.c
M	source/blender/editors/interface/interface_regions_intern.h
M	source/blender/editors/interface/interface_templates.c

===================================================================

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index ec8c2e0d299..7d28c538780 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -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(
diff --git a/source/blender/editors/interface/interface_eyedropper_colorband.c b/source/blender/editors/interface/interface_eyedropper_colorband.c
index 98dbb31d049..8e588352b56 100644
--- a/source/blender/editors/interface/interface_eyedropper_colorband.c
+++ b/source/blender/editors/interface/interface_eyedropper_colorband.c
@@ -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;
 }
 
 
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index b0eb63712e2..4b35978a9de 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -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)
diff --git a/source/blender/editors/interface/interface_region_menu_popup.c b/source/blender/editors/interface/interface_region_menu_popup.c
index 3ec2fd26d36..bd8f62e2abd 100644
--- a/source/blender/editors/interface/interface_region_menu_popup.c
+++ b/source/blender/editors/interface/interface_region_menu_popup.c
@@ -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 -
diff --git a/source/blender/editors/interface/interface_region_popover.c b/source/blender/editors/interface/interface_region_popover.c
index 5710b7c3568..9fcf2a51652 100644
--- a/source/blender/editors/interface/interface_region_popover.c
+++ b/source/blender/editors/interface/interface_region_popover.c
@@ -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);
 
diff --git a/source/blender/editors/interface/interface_region_popup.c b/source/blender/editors/interface/interface_region_popup.c
index 91020cea371..2275ee9ebf5 100644
--- a/source/blender/editors/interface/interface_region_popup.c
+++ b/source/blender/editors/interface/interface_region_popup.c
@@ -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;
diff --git a/source/blender/editors/interface/interface_regions_intern.h b/source/blender/editors/interface/interface_regions_intern.h
index 0d24b310817..fb71cbd788b 100644
--- a/source/blender/editors/interface/interface_regions_intern.h
+++ b/source/blender/editors/interface/interface_regions_intern.h
@@ -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);
 
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 7bbf4d1307e..cc28d712ffa 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -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, "");



More information about the Bf-blender-cvs mailing list