[Bf-blender-cvs] [053e0c0af37] master: UI: Add shortcuts for shader effect panels

Hans Goudey noreply at git.blender.org
Mon Jul 6 21:35:42 CEST 2020


Commit: 053e0c0af377133f046f33304a43497a7f8a22c8
Author: Hans Goudey
Date:   Mon Jul 6 15:35:21 2020 -0400
Branches: master
https://developer.blender.org/rB053e0c0af377133f046f33304a43497a7f8a22c8

UI: Add shortcuts for shader effect panels

Only the delete shortcut applies here, although the move up and down
operators can optionally be assigned in the keymap.

See rB1fa40c9f8a81 for more details and rB5d2005cbb54b for the
grease pencil modifier panel implementation, which is the same.

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

M	release/scripts/presets/keyconfig/keymap_data/blender_default.py
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/object/object_shader_fx.c

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

diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index 93a95d324da..2bfb57f2890 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -738,6 +738,9 @@ def km_property_editor(_params):
         ("object.gpencil_modifier_remove", {"type": 'DEL', "value": 'PRESS'}, {"properties": [("report", True)]}),
         ("object.gpencil_modifier_copy", {"type": 'D', "value": 'PRESS', "shift": True}, None),
         ("object.gpencil_modifier_apply", {"type": 'A', "value": 'PRESS', "ctrl": True}, {"properties": [("report", True)]}),
+        # ShaderFX panels
+        ("object.shaderfx_remove", {"type": 'X', "value": 'PRESS'}, {"properties": [("report", True)]}),
+        ("object.shaderfx_remove", {"type": 'DEL', "value": 'PRESS'}, {"properties": [("report", True)]}),
     ])
 
     return keymap
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 19dfd6fedd6..402d345b99a 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -2187,8 +2187,13 @@ void uiTemplateShaderFx(uiLayout *UNUSED(layout), bContext *C)
       char panel_idname[MAX_NAME];
       shaderfx_panel_id(fx, panel_idname);
 
+      /* Create custom data RNA pointer. */
+      PointerRNA *fx_ptr = MEM_mallocN(sizeof(PointerRNA), "panel customdata");
+      RNA_pointer_create(&ob->id, &RNA_ShaderFx, fx, fx_ptr);
+
       Panel *new_panel = UI_panel_add_instanced(
-          sa, region, &region->panels, panel_idname, i, NULL);
+          sa, region, &region->panels, panel_idname, i, fx_ptr);
+
       if (new_panel != NULL) {
         UI_panel_set_expand_from_list_data(C, new_panel);
       }
@@ -2201,6 +2206,27 @@ void uiTemplateShaderFx(uiLayout *UNUSED(layout), bContext *C)
         UI_panel_set_expand_from_list_data(C, panel);
       }
     }
+
+    /* Assuming there's only one group of instanced panels, update the custom data pointers. */
+    Panel *panel = region->panels.first;
+    LISTBASE_FOREACH (ShaderFxData *, fx, shaderfx) {
+      const ShaderFxTypeInfo *fxi = BKE_shaderfx_get_info(fx->type);
+      if (fxi->panelRegister == NULL) {
+        continue;
+      }
+
+      /* Move to the next instanced panel corresponding to the next modifier. */
+      while ((panel->type == NULL) || !(panel->type->flag & PNL_INSTANCED)) {
+        panel = panel->next;
+        BLI_assert(panel != NULL); /* There shouldn't be fewer panels than modifiers with UIs. */
+      }
+
+      PointerRNA *fx_ptr = MEM_mallocN(sizeof(PointerRNA), "panel customdata");
+      RNA_pointer_create(&ob->id, &RNA_ShaderFx, fx, fx_ptr);
+      UI_panel_custom_data_set(panel, fx_ptr);
+
+      panel = panel->next;
+    }
   }
 }
 
diff --git a/source/blender/editors/object/object_shader_fx.c b/source/blender/editors/object/object_shader_fx.c
index e5e3c204227..977d4abd4d4 100644
--- a/source/blender/editors/object/object_shader_fx.c
+++ b/source/blender/editors/object/object_shader_fx.c
@@ -24,6 +24,7 @@
 #include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "MEM_guardedalloc.h"
 
@@ -55,6 +56,8 @@
 #include "ED_object.h"
 #include "ED_screen.h"
 
+#include "UI_interface.h"
+
 #include "WM_api.h"
 #include "WM_types.h"
 
@@ -360,21 +363,57 @@ static void edit_shaderfx_properties(wmOperatorType *ot)
   RNA_def_property_flag(prop, PROP_HIDDEN);
 }
 
-static int edit_shaderfx_invoke_properties(bContext *C, wmOperator *op)
+static void edit_shaderfx_report_property(wmOperatorType *ot)
 {
-  ShaderFxData *fx;
+  PropertyRNA *prop = RNA_def_boolean(
+      ot->srna, "report", false, "Report", "Create a notification after the operation");
+  RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
+}
 
+/**
+ * \param event: If this isn't NULL, the operator will also look for panels underneath
+ * the cursor with customdata set to a modifier.
+ * \param r_retval: This should be used if #event is used in order to to return
+ * #OPERATOR_PASS_THROUGH to check other operators with the same key set.
+ */
+static bool edit_shaderfx_invoke_properties(bContext *C,
+                                            wmOperator *op,
+                                            const wmEvent *event,
+                                            int *r_retval)
+{
   if (RNA_struct_property_is_set(op->ptr, "shaderfx")) {
     return true;
   }
 
-  PointerRNA ptr = CTX_data_pointer_get_type(C, "shaderfx", &RNA_ShaderFx);
-  if (ptr.data) {
-    fx = ptr.data;
+  PointerRNA ctx_ptr = CTX_data_pointer_get_type(C, "shaderfx", &RNA_ShaderFx);
+  if (ctx_ptr.data != NULL) {
+    ShaderFxData *fx = ctx_ptr.data;
     RNA_string_set(op->ptr, "shaderfx", fx->name);
     return true;
   }
 
+  /* Check the custom data of panels under the mouse for an effect. */
+  if (event != NULL) {
+    PointerRNA *panel_ptr = UI_region_panel_custom_data_under_cursor(C, event);
+
+    if (!(panel_ptr == NULL || RNA_pointer_is_null(panel_ptr))) {
+      if (RNA_struct_is_a(panel_ptr->type, &RNA_ShaderFx)) {
+        ShaderFxData *fx = panel_ptr->data;
+        RNA_string_set(op->ptr, "shaderfx", fx->name);
+        return true;
+      }
+
+      BLI_assert(r_retval != NULL); /* We need the return value in this case. */
+      if (r_retval != NULL) {
+        *r_retval = (OPERATOR_PASS_THROUGH | OPERATOR_CANCELLED);
+      }
+      return false;
+    }
+  }
+
+  if (r_retval != NULL) {
+    *r_retval = OPERATOR_CANCELLED;
+  }
   return false;
 }
 
@@ -403,21 +442,30 @@ static int shaderfx_remove_exec(bContext *C, wmOperator *op)
   Object *ob = ED_object_active_context(C);
   ShaderFxData *fx = edit_shaderfx_property_get(op, ob, 0);
 
+  /* Store name temporarily for report. */
+  char name[MAX_NAME];
+  strcpy(name, fx->name);
+
   if (!fx || !ED_object_shaderfx_remove(op->reports, bmain, ob, fx)) {
     return OPERATOR_CANCELLED;
   }
 
+  if (RNA_boolean_get(op->ptr, "report")) {
+    BKE_reportf(op->reports, RPT_INFO, "Removed effect: %s", name);
+  }
+
   WM_event_add_notifier(C, NC_OBJECT | ND_SHADERFX, ob);
 
   return OPERATOR_FINISHED;
 }
 
-static int shaderfx_remove_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+static int shaderfx_remove_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 {
-  if (edit_shaderfx_invoke_properties(C, op)) {
+  int retval;
+  if (edit_shaderfx_invoke_properties(C, op, event, &retval)) {
     return shaderfx_remove_exec(C, op);
   }
-  return OPERATOR_CANCELLED;
+  return retval;
 }
 
 void OBJECT_OT_shaderfx_remove(wmOperatorType *ot)
@@ -433,6 +481,7 @@ void OBJECT_OT_shaderfx_remove(wmOperatorType *ot)
   /* flags */
   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
   edit_shaderfx_properties(ot);
+  edit_shaderfx_report_property(ot);
 }
 
 /************************ move up shaderfx operator *********************/
@@ -452,12 +501,13 @@ static int shaderfx_move_up_exec(bContext *C, wmOperator *op)
   return OPERATOR_FINISHED;
 }
 
-static int shaderfx_move_up_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+static int shaderfx_move_up_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 {
-  if (edit_shaderfx_invoke_properties(C, op)) {
+  int retval;
+  if (edit_shaderfx_invoke_properties(C, op, event, &retval)) {
     return shaderfx_move_up_exec(C, op);
   }
-  return OPERATOR_CANCELLED;
+  return retval;
 }
 
 void OBJECT_OT_shaderfx_move_up(wmOperatorType *ot)
@@ -492,12 +542,13 @@ static int shaderfx_move_down_exec(bContext *C, wmOperator *op)
   return OPERATOR_FINISHED;
 }
 
-static int shaderfx_move_down_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+static int shaderfx_move_down_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 {
-  if (edit_shaderfx_invoke_properties(C, op)) {
+  int retval;
+  if (edit_shaderfx_invoke_properties(C, op, event, &retval)) {
     return shaderfx_move_down_exec(C, op);
   }
-  return OPERATOR_CANCELLED;
+  return retval;
 }
 
 void OBJECT_OT_shaderfx_move_down(wmOperatorType *ot)
@@ -538,12 +589,13 @@ static int shaderfx_move_to_index_exec(bContext *C, wmOperator *op)
   return OPERATOR_FINISHED;
 }
 
-static int shaderfx_move_to_index_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+static int shaderfx_move_to_index_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 {
-  if (edit_shaderfx_invoke_properties(C, op)) {
+  int retval;
+  if (edit_shaderfx_invoke_properties(C, op, event, &retval)) {
     return shaderfx_move_to_index_exec(C, op);
   }
-  return OPERATOR_CANCELLED;
+  return retval;
 }
 
 void OBJECT_OT_shaderfx_move_to_index(wmOperatorType *ot)



More information about the Bf-blender-cvs mailing list