[Bf-blender-cvs] [5b22112] wiggly-widgets: Initial steps for a connected bone and face map selection

Julian Eisel noreply at git.blender.org
Mon Nov 9 00:06:42 CET 2015


Commit: 5b2211214574ba92cfc35717c0dc67f91b00ae9f
Author: Julian Eisel
Date:   Sun Nov 8 23:58:37 2015 +0100
Branches: wiggly-widgets
https://developer.blender.org/rB5b2211214574ba92cfc35717c0dc67f91b00ae9f

Initial steps for a connected bone and face map selection

Now, when a face map is selected, all bones it is assigned to are selected as well. If this will stay in final design is not sure yet, but the logic added will be needed anyway (likely).

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

M	source/blender/editors/space_view3d/space_view3d.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_generic_widgets.c
M	source/blender/windowmanager/intern/wm_widgets.c
M	source/blender/windowmanager/wm.h

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

diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index f2fa1dd..4fcd1ca 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -60,6 +60,7 @@
 #include "BKE_scene.h"
 #include "BKE_screen.h"
 
+#include "ED_armature.h"
 #include "ED_space_api.h"
 #include "ED_screen.h"
 #include "ED_transform.h"
@@ -941,6 +942,24 @@ static int WIDGETGROUP_armature_facemap_poll(const struct bContext *C, struct wm
 	return false;
 }
 
+static void WIDGET_armature_facemap_select(bContext *C, wmWidget *widget, const int action)
+{
+	Object *ob = CTX_data_active_object(C);
+	bPoseChannel *pchan;
+
+	switch (action) {
+		case SEL_SELECT:
+			for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
+				if (pchan->fmap == WIDGET_facemap_get_fmap(widget)) {
+					ED_pose_bone_select(ob, pchan, true);
+				}
+			}
+			break;
+		default:
+			BLI_assert(0);
+	}
+}
+
 static void WIDGETGROUP_armature_facemap_create(const struct bContext *C, struct wmWidgetGroup *wgroup)
 {
 	Object *ob = CTX_data_active_object(C);
@@ -966,6 +985,7 @@ static void WIDGETGROUP_armature_facemap_create(const struct bContext *C, struct
 			WM_widget_set_property(widget, FACEMAP_SLOT_FACEMAP, &famapptr, "name");
 			WM_widget_set_colors(widget, color_shape, color_shape);
 			WM_widget_set_flag(widget, WM_WIDGET_DRAW_HOVER, true);
+			WM_widget_set_func_select(widget, WIDGET_armature_facemap_select);
 			opptr = WM_widget_set_operator(widget, "TRANSFORM_OT_translate");
 			if ((prop = RNA_struct_find_property(opptr, "release_confirm"))) {
 				RNA_property_boolean_set(opptr, prop, true);
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index cdc6503..4b3fc81 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -532,6 +532,9 @@ enum widgetflags {
 
 void WM_widget_set_property(struct wmWidget *, int slot, struct PointerRNA *ptr, const char *propname);
 struct PointerRNA *WM_widget_set_operator(struct wmWidget *, const char *opname);
+void WM_widget_set_func_select(
+        struct wmWidget *widget,
+        void (*select)(struct bContext *, struct wmWidget *, const int action));
 void WM_widget_set_origin(struct wmWidget *widget, const float origin[3]);
 void WM_widget_set_offset(struct wmWidget *widget, const float offset[3]);
 void WM_widget_set_flag(struct wmWidget *widget, const int flag, const bool enable);
@@ -618,6 +621,7 @@ struct wmWidget *WIDGET_rect_transform_new(
 struct wmWidget *WIDGET_facemap_new(
         struct wmWidgetGroup *wgroup, const char *name, const int style,
         struct Object *ob, const int facemap);
+struct bFaceMap *WIDGET_facemap_get_fmap(struct wmWidget *widget);
 
 
 #ifdef WITH_INPUT_IME
diff --git a/source/blender/windowmanager/intern/wm_generic_widgets.c b/source/blender/windowmanager/intern/wm_generic_widgets.c
index 6615168..bd126d8 100644
--- a/source/blender/windowmanager/intern/wm_generic_widgets.c
+++ b/source/blender/windowmanager/intern/wm_generic_widgets.c
@@ -42,6 +42,7 @@
 #include "DNA_userdef_types.h"
 #include "DNA_widget_types.h"
 
+#include "BLI_listbase.h"
 #include "BLI_utildefines.h"
 #include "BLI_math_matrix.h"
 #include "BLI_math.h"
@@ -1604,7 +1605,6 @@ wmWidget *WIDGET_facemap_new(
 //	fmap_widget->widget.bind_to_prop = NULL;
 //	fmap_widget->widget.handler = widget_facemap_handler;
 	fmap_widget->widget.render_3d_intersection = widget_facemap_render_3d_intersect;
-	fmap_widget->widget.flag |= WM_WIDGET_SELECTABLE;
 	fmap_widget->ob = ob;
 	fmap_widget->facemap = facemap;
 	fmap_widget->style = style;
@@ -1614,6 +1614,12 @@ wmWidget *WIDGET_facemap_new(
 	return (wmWidget *)fmap_widget;
 }
 
+bFaceMap *WIDGET_facemap_get_fmap(wmWidget *widget)
+{
+	FacemapWidget *fmap_widget = (FacemapWidget *)widget;
+	return BLI_findlink(&fmap_widget->ob->fmaps, fmap_widget->facemap);
+}
+
 /** \} */ // Facemap Widget API
 /** \} */ // Facemap Widget
 
diff --git a/source/blender/windowmanager/intern/wm_widgets.c b/source/blender/windowmanager/intern/wm_widgets.c
index 613d20c..e9f12bf 100644
--- a/source/blender/windowmanager/intern/wm_widgets.c
+++ b/source/blender/windowmanager/intern/wm_widgets.c
@@ -312,6 +312,11 @@ void WM_widgets_update(const bContext *C, wmWidgetMap *wmap)
 	}
 }
 
+BLI_INLINE bool widgetgroup_poll_check(const bContext *C, const wmWidgetGroup *wgroup)
+{
+	return (!wgroup->type->poll || wgroup->type->poll(C, wgroup->type));
+}
+
 void WM_widgets_draw(const bContext *C, const wmWidgetMap *wmap, const bool in_scene)
 {
 	wmWidget *widget;
@@ -351,7 +356,7 @@ void WM_widgets_draw(const bContext *C, const wmWidgetMap *wmap, const bool in_s
 		wmWidgetGroup *wgroup;
 
 		for (wgroup = wmap->widgetgroups.first; wgroup; wgroup = wgroup->next) {
-			if (!wgroup->type->poll || wgroup->type->poll(C, wgroup->type)) {
+			if (widgetgroup_poll_check(C, wgroup)) {
 				for (widget = wgroup->widgets.first; widget; widget = widget->next) {
 					if ((widget->flag & WM_WIDGET_HIDDEN) == 0 &&
 					    (!(widget->flag & WM_WIDGET_DRAW_HOVER) || (widget->flag & WM_WIDGET_HIGHLIGHT)) &&
@@ -366,9 +371,11 @@ void WM_widgets_draw(const bContext *C, const wmWidgetMap *wmap, const bool in_s
 
 	/* draw selected widgets last */
 	if ((widget = wmap->selected_widget) && in_scene == ((widget->flag & WM_WIDGET_SCENE_DEPTH) != 0)) {
-		/* notice that we don't update the widgetgroup, widget is now on
-		 * its own, it should have all relevant data to update itself */
-		widget->draw(C, widget);
+		if (widgetgroup_poll_check(C, widget->wgroup)) {
+			/* notice that we don't update the widgetgroup, widget is now on
+			 * its own, it should have all relevant data to update itself */
+			widget->draw(C, widget);
+		}
 	}
 
 	if (use_lighting)
@@ -507,6 +514,17 @@ PointerRNA *WM_widget_set_operator(wmWidget *widget, const char *opname)
 	return NULL;
 }
 
+/**
+ * \brief Set widget select callback
+ *
+ * Callback is called when widget gets selected/deselected
+ */
+void WM_widget_set_func_select(wmWidget *widget, void (*select)(bContext *, wmWidget *, const int action))
+{
+	widget->flag |= WM_WIDGET_SELECTABLE;
+	widget->select = select;
+}
+
 void WM_widget_set_origin(wmWidget *widget, const float origin[3])
 {
 	copy_v3_v3(widget->origin, origin);
@@ -1031,9 +1049,14 @@ wmWidget *wm_widgetmap_get_selected_widget(wmWidgetMap *wmap)
 
 void wm_widgetmap_set_selected_widget(bContext *C, wmWidgetMap *wmap, wmWidget *widget)
 {
+	const int action = SEL_SELECT; /* TODO currently SEL_SELECT only */
+
 	if (widget) {
 		wmap->selected_widget = widget;
 		widget->flag |= WM_WIDGET_SELECTED;
+		if (widget->select) {
+			widget->select(C, widget, action);
+		}
 		wm_widgetmap_set_highlighted_widget(wmap, C, NULL, wmap->highlighted_widget->highlighted_part);
 	}
 	else {
diff --git a/source/blender/windowmanager/wm.h b/source/blender/windowmanager/wm.h
index f2bed99..f156829 100644
--- a/source/blender/windowmanager/wm.h
+++ b/source/blender/windowmanager/wm.h
@@ -84,6 +84,9 @@ typedef struct wmWidget {
 
 	int (*get_cursor)(struct wmWidget *widget);
 
+	/* called when widget selection state changes */
+	void (*select)(struct bContext *C, struct wmWidget *widget, const int action);
+
 	int flag; /* flags set by drawing and interaction, such as highlighting */
 
 	unsigned char highlighted_part;




More information about the Bf-blender-cvs mailing list