[Bf-blender-cvs] [c1ffa9d] wiggly-widgets: ManipulatorGroup customdata.

Antony Riakiotakis noreply at git.blender.org
Wed Oct 8 18:13:24 CEST 2014


Commit: c1ffa9d0e0c32532ffc2fa732a1ef88ff7f3c20f
Author: Antony Riakiotakis
Date:   Wed Oct 8 18:13:12 2014 +0200
Branches: wiggly-widgets
https://developer.blender.org/rBc1ffa9d0e0c32532ffc2fa732a1ef88ff7f3c20f

ManipulatorGroup customdata.

Make WidgetGroup data private.

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

M	source/blender/editors/include/ED_transform.h
M	source/blender/editors/interface/interface_generic_widgets.c
M	source/blender/editors/space_view3d/space_view3d.c
M	source/blender/editors/transform/transform_manipulator.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/WM_types.h
M	source/blender/windowmanager/intern/wm_widgets.c

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

diff --git a/source/blender/editors/include/ED_transform.h b/source/blender/editors/include/ED_transform.h
index bda6de0..dcb9583 100644
--- a/source/blender/editors/include/ED_transform.h
+++ b/source/blender/editors/include/ED_transform.h
@@ -153,11 +153,23 @@ void Transform_Properties(struct wmOperatorType *ot, int flags);
 
 /* view3d manipulators */
 
+typedef struct ManipulatorGroup {
+	struct wmWidget *translate_x;
+	struct wmWidget *translate_y;
+	struct wmWidget *translate_z;
+
+	struct wmWidget *rotate_x;
+	struct wmWidget *rotate_y;
+	struct wmWidget *rotate_z;
+} ManipulatorGroup;
+
 int WIDGET_manipulator_handler(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget);
 void WIDGET_manipulator_render_3d_intersect(const struct bContext *C, struct wmWidget *widget, int selectionbase);
 void WIDGET_manipulator_draw(struct wmWidget *widget, const struct bContext *C);
-bool WIDGETGROUP_manipulator_poll(struct wmWidgetGroup *UNUSED(wgroup), const struct bContext *C);
-void WIDGETGROUP_manipulator_update(struct wmWidgetGroup *UNUSED(wgroup), const struct bContext *C);
+bool WIDGETGROUP_manipulator_poll(struct wmWidgetGroup *wgroup, const struct bContext *C);
+void WIDGETGROUP_manipulator_update(struct wmWidgetGroup *wgroup, const struct bContext *C);
+void WIDGETGROUP_manipulator_free(struct wmWidgetGroup *wgroup);
+
 /* Snapping */
 
 
diff --git a/source/blender/editors/interface/interface_generic_widgets.c b/source/blender/editors/interface/interface_generic_widgets.c
index 3c3479e..86bca1a 100644
--- a/source/blender/editors/interface/interface_generic_widgets.c
+++ b/source/blender/editors/interface/interface_generic_widgets.c
@@ -335,7 +335,7 @@ typedef struct ArrowWidget {
 	int style;
 	float origin[3];
 	float direction[3];
-	float color[3];
+	float color[4];
 } ArrowWidget;
 
 static void widget_draw_intern(ArrowWidget *widget, bool select, bool highlight)
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index ee8c2fa..6d3be4c 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -695,10 +695,12 @@ static void view3d_widgets(void)
 {
 	float color_green[4] = {0.0f, 1.0f, 0.0f, 1.0f};
 	wmWidget *widget = NULL;
+	ManipulatorGroup *manipulator = MEM_callocN(sizeof(ManipulatorGroup), "manipulator_data");
 	struct wmWidgetMap *wmap = WM_widgetmap_find("View3D", SPACE_VIEW3D, RGN_TYPE_WINDOW, true);
 	struct wmWidgetGroup *wgroup_manipulator = WM_widgetgroup_new(WIDGETGROUP_manipulator_poll, 
-	                                                              WIDGETGROUP_manipulator_update);
-	struct wmWidgetGroup *wgroup_light = WM_widgetgroup_new(WIDGETGROUP_lamp_poll, NULL);
+	                                                              WIDGETGROUP_manipulator_update,
+	                                                              WIDGETGROUP_manipulator_free, manipulator);
+	struct wmWidgetGroup *wgroup_light = WM_widgetgroup_new(WIDGETGROUP_lamp_poll, NULL, NULL, NULL);
 	
 	widget = WM_widget_new(WIDGET_manipulator_draw, 
 	                       WIDGET_manipulator_render_3d_intersect, 
@@ -707,9 +709,8 @@ static void view3d_widgets(void)
 	
 	WM_widget_register(wgroup_manipulator, widget);
 
-	widget = WIDGET_arrow_new(0, NULL);
-	WIDGET_arrow_set_color(widget, color_green);
-	WM_widget_register(wgroup_manipulator, widget);
+	manipulator->translate_y = WIDGET_arrow_new(0, NULL);
+	WIDGET_arrow_set_color(manipulator->translate_y, color_green);
 	
 	widget = WM_widget_new(WIDGET_lamp_draw,
 	                       WIDGET_lamp_render_3d_intersect, 
diff --git a/source/blender/editors/transform/transform_manipulator.c b/source/blender/editors/transform/transform_manipulator.c
index 660cf42..0729e36 100644
--- a/source/blender/editors/transform/transform_manipulator.c
+++ b/source/blender/editors/transform/transform_manipulator.c
@@ -45,6 +45,7 @@
 
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
+#include "BLI_listbase.h"
 
 #include "RNA_access.h"
 
@@ -1904,3 +1905,20 @@ int WIDGET_manipulator_handler(bContext *C, const struct wmEvent *event, wmWidge
 
 	return (val) ? OPERATOR_FINISHED : OPERATOR_PASS_THROUGH;
 }
+
+
+void WIDGETGROUP_manipulator_free(struct wmWidgetGroup *wgroup)
+{
+	ManipulatorGroup *manipulator = WM_widgetgroup_customdata(wgroup);
+
+	/* register all widgets for destruction */
+	WM_widget_register(wgroup, manipulator->translate_x);
+	WM_widget_register(wgroup, manipulator->translate_y);
+	WM_widget_register(wgroup, manipulator->translate_z);
+
+	WM_widget_register(wgroup, manipulator->translate_x);
+	WM_widget_register(wgroup, manipulator->translate_y);
+	WM_widget_register(wgroup, manipulator->translate_z);
+	
+	MEM_freeN(manipulator);
+}
\ No newline at end of file
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index a5fcf9e..7a8cb00 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -464,7 +464,9 @@ bool        WM_event_is_tablet(const struct wmEvent *event);
 
 /* widget API */
 struct wmWidgetGroup *WM_widgetgroup_new(bool (*poll)(struct wmWidgetGroup *, const struct bContext *),
-                                         void (*update)(struct wmWidgetGroup *, const struct bContext *));
+                                         void (*update)(struct wmWidgetGroup *, const struct bContext *),
+                                         void (*free)(struct wmWidgetGroup *),
+                                         void *customdata);
 
 struct wmWidget *WM_widget_new(void (*draw)(struct wmWidget *, const struct bContext *),
 							   void (*render_3d_intersection)(const struct bContext *, struct wmWidget *, int),
@@ -478,6 +480,8 @@ void WM_event_add_widget_handler(struct ARegion *ar);
 bool WM_widget_register(struct wmWidgetGroup *wgroup, struct wmWidget *widget);
 void WM_widget_unregister(struct wmWidgetGroup *wgroup, struct wmWidget *widget);
 
+void *WM_widgetgroup_customdata(struct wmWidgetGroup *wgroup);
+
 bool WM_widgetgroup_register(struct wmWidgetMap *wmap, struct wmWidgetGroup *wgroup);
 void WM_widgetgroup_unregister(struct wmWidgetMap *wmap, struct wmWidgetGroup *wgroup);
 
diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h
index 1645b1e..21bfe63 100644
--- a/source/blender/windowmanager/WM_types.h
+++ b/source/blender/windowmanager/WM_types.h
@@ -673,19 +673,7 @@ typedef struct wmWidget {
 /* WidgetGroups store and manage groups of widgets.
  * They are responsible for drawing necessary widgets and updating their state and position. 
  * Also they */
-typedef struct wmWidgetGroup {
-	struct wmWidgetGroup *next, *prev;
-	ListBase widgets;
-		
-	void *customdata;
-	
-	/* poll if widgetmap should be active */
-	bool (*poll)(struct wmWidgetGroup *widget, const struct bContext *C);
-
-	/* update widgets, called right before drawing */
-	void (*update)(struct wmWidgetGroup *widget, const struct bContext *C);
-} wmWidgetGroup;
-
+typedef struct wmWidgetGroup wmWidgetGroup;
 
 /* *************** migrated stuff, clean later? ************** */
 
diff --git a/source/blender/windowmanager/intern/wm_widgets.c b/source/blender/windowmanager/intern/wm_widgets.c
index 16ed971..f8e793e 100644
--- a/source/blender/windowmanager/intern/wm_widgets.c
+++ b/source/blender/windowmanager/intern/wm_widgets.c
@@ -84,12 +84,31 @@ typedef struct wmWidgetMap {
 	wmWidget *active_widget;
 } wmWidgetMap;
 
+
+struct wmWidgetGroup {
+	struct wmWidgetGroup *next, *prev;
+	ListBase widgets;
+		
+	void *customdata;
+
+	/* free the widgetmap. Should take care of any customdata too */
+	void (*free)(struct wmWidgetGroup *wgroup);
+	
+	/* poll if widgetmap should be active */
+	bool (*poll)(struct wmWidgetGroup *wgroup, const struct bContext *C);
+
+	/* update widgets, called right before drawing */
+	void (*update)(struct wmWidgetGroup *wgroup, const struct bContext *C);
+};
+
+
 /* store all widgetboxmaps here. Anyone who wants to register a widget for a certain 
  * area type can query the widgetbox to do so */
 static ListBase widgetmaps = {NULL, NULL};
 
 struct wmWidgetGroup *WM_widgetgroup_new(bool (*poll)(struct wmWidgetGroup *, const struct bContext *C),
-                                         void (*update)(struct wmWidgetGroup *, const struct bContext *))
+                                         void (*update)(struct wmWidgetGroup *, const struct bContext *),
+                                         void (*free)(struct wmWidgetGroup *wgroup), void *customdata)
 {
 	wmWidgetGroup *wgroup;
 	
@@ -97,10 +116,17 @@ struct wmWidgetGroup *WM_widgetgroup_new(bool (*poll)(struct wmWidgetGroup *, co
 	
 	wgroup->poll = poll;
 	wgroup->update = update;
+	wgroup->free = free;
+	wgroup->customdata = customdata;
 	
 	return wgroup;
 }
 
+void *WM_widgetgroup_customdata(struct wmWidgetGroup *wgroup)
+{
+	return wgroup->customdata;
+}
+
 
 wmWidget *WM_widget_new(void (*draw)(struct wmWidget *customdata, const struct bContext *C),
                         void (*render_3d_intersection)(const struct bContext *C, struct wmWidget *customdata, int selectionbase),
@@ -124,7 +150,7 @@ wmWidget *WM_widget_new(void (*draw)(struct wmWidget *customdata, const struct b
 	return widget;
 }
 
-static void WM_widgets_delete(ListBase *widgetlist, wmWidget *widget)
+static void wm_widgets_delete(ListBase *widgetlist, wmWidget *widget)
 {
 	if (widget->flag & WM_WIDGET_FREE_DATA)
 		MEM_freeN(widget->customdata);
@@ -175,6 +201,7 @@ void WM_event_add_widget_handler(ARegion *ar)
 bool WM_widget_register(struct wmWidgetGroup *wgroup, wmWidget *widget)
 {
 	wmWidget *widget_iter;
+	
 	/* search list, might already be registered */	
 	for (widget_iter = wgroup->widgets.first; widget_iter; widget_iter = widget_iter->next) {
 		if (widget_iter == widget)
@@ -237,9 +264,12 @@ void WM_widgetmaps_free(void)
 		for (wgroup = wmap->widgetgroups.first; wgroup; wgroup = wgroup->next) {
 			wmWidget *widget;
 			
+			if (wgroup->free)
+				wgroup->free(wgroup);
+			
 			for (widget = wgroup->widgets.first; widget;) {
 				wmWidget *widget_next = widget->next;
-				WM_widg

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list