[Bf-blender-cvs] [2b1bdb5] wiggly-widgets: Refactor widgets to always be recreated on redraw - like buttons.

Antony Riakiotakis noreply at git.blender.org
Fri Nov 28 23:02:54 CET 2014


Commit: 2b1bdb5412ee3ab533ecb9c8c760b009d95b1494
Author: Antony Riakiotakis
Date:   Fri Nov 28 23:02:42 2014 +0100
Branches: wiggly-widgets
https://developer.blender.org/rB2b1bdb5412ee3ab533ecb9c8c760b009d95b1494

Refactor widgets to always be recreated on redraw - like buttons.

This allows us to spawn a different number of widgets per frame, which
will be needed for shapekey doritos. Also added a widgetgroup for the
shapekeys

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

M	source/blender/editors/space_view3d/space_view3d.c
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 fbcdbf6..d714a47 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -36,6 +36,7 @@
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_camera_types.h"
+#include "DNA_key_types.h"
 
 #include "MEM_guardedalloc.h"
 
@@ -46,6 +47,7 @@
 #include "BKE_context.h"
 #include "BKE_depsgraph.h"
 #include "BKE_icons.h"
+#include "BKE_key.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_object.h"
@@ -748,6 +750,64 @@ static void WIDGETGROUP_camera_create(struct wmWidgetGroup *wgroup)
 }
 
 
+static bool WIDGETGROUP_shapekey_poll(struct wmWidgetGroup *UNUSED(wgroup), const struct bContext *C)
+{
+	Object *ob = CTX_data_active_object(C);
+
+	if (ob && ob->type == OB_MESH) {
+		Key *key = BKE_key_from_object(ob);
+		KeyBlock *kb;
+	
+		if (key == NULL)
+			return false;
+		
+		kb = BLI_findlink(&key->block, ob->shapenr - 1);
+		
+		if (kb)
+			return true;
+	}
+	return false;
+}
+
+static void WIDGETGROUP_shapekey_update(struct wmWidgetGroup *wgroup, const struct bContext *C)
+{
+	Object *ob = CTX_data_active_object(C);
+	Camera *ca = ob->data;
+	wmWidget *widget = WM_widgetgroup_widgets(wgroup)->first;
+	PointerRNA *shapeptr = WM_widgetgroup_customdata(wgroup);
+	float dir[3];
+
+	RNA_pointer_create(&ca->id, &RNA_ShapeKey, ca, shapeptr);
+	WM_widget_set_origin(widget, ob->obmat[3]);
+	WM_widget_property(widget, shapeptr, "value");
+	negate_v3_v3(dir, ob->obmat[2]);
+	WIDGET_arrow_set_direction(widget, dir);
+}
+
+
+static void WIDGETGROUP_shapekey_free(struct wmWidgetGroup *wgroup)
+{
+	PointerRNA *cameraptr = WM_widgetgroup_customdata(wgroup);
+
+	MEM_freeN(cameraptr);
+}
+
+static void WIDGETGROUP_shapekey_create(struct wmWidgetGroup *wgroup)
+{
+	float color_shape[4] = {1.0f, 0.3f, 0.0f, 1.0f};
+	wmWidget *widget = NULL;
+	PointerRNA *shapeptr = MEM_callocN(sizeof(PointerRNA), "shapekeywidgetrna");
+
+	WM_widgetgroup_customdata_set(wgroup, shapeptr);
+	
+	widget = WIDGET_arrow_new(UI_ARROW_STYLE_NORMAL, NULL);
+	WM_widget_set_3d_scale(widget, false);
+	WM_widget_register(wgroup, widget);
+	WIDGET_arrow_set_color(widget, color_shape);
+}
+
+
+
 static void view3d_widgets(void)
 {
 	struct wmWidgetMapType *wmaptype = WM_widgetmaptype_find("View3D", SPACE_VIEW3D, RGN_TYPE_WINDOW, true);
@@ -767,9 +827,15 @@ static void view3d_widgets(void)
 	                                                                WIDGETGROUP_camera_update,
 	                                                                WIDGETGROUP_camera_free);
 
+	struct wmWidgetGroupType *wgroup_shapekey = WM_widgetgrouptype_new(WIDGETGROUP_shapekey_create,
+	                                                                WIDGETGROUP_shapekey_poll,
+	                                                                WIDGETGROUP_shapekey_update,
+	                                                                WIDGETGROUP_shapekey_free);
+	
 	//WM_widgetgrouptype_register(wmaptype, wgroup_manipulator);
 	WM_widgetgrouptype_register(wmaptype, wgroup_light);
 	WM_widgetgrouptype_register(wmaptype, wgroup_camera);
+	WM_widgetgrouptype_register(wmaptype, wgroup_shapekey);
 }
 
 
diff --git a/source/blender/windowmanager/intern/wm_generic_widgets.c b/source/blender/windowmanager/intern/wm_generic_widgets.c
index 99676ee..7b518b8 100644
--- a/source/blender/windowmanager/intern/wm_generic_widgets.c
+++ b/source/blender/windowmanager/intern/wm_generic_widgets.c
@@ -351,18 +351,18 @@ static int widget_arrow_handler(struct bContext *C, const struct wmEvent *event,
 				value = arrow->min + (value * arrow->range / ARROW_RANGE);
 		}
 
-		RNA_property_float_set(widget->ptr, widget->prop, value);
-		RNA_property_update(C, widget->ptr, widget->prop);
+		RNA_property_float_set(&widget->ptr, widget->prop, value);
+		RNA_property_update(C, &widget->ptr, widget->prop);
 
 		/* accounts for clamping properly */
 		if (arrow->style & UI_ARROW_STYLE_CONSTRAINED) {
 			if (arrow->style & UI_ARROW_STYLE_INVERTED)
-				arrow->offset = ARROW_RANGE * (arrow->min + arrow->range - (RNA_property_float_get(widget->ptr, widget->prop))) / arrow->range;
+				arrow->offset = ARROW_RANGE * (arrow->min + arrow->range - (RNA_property_float_get(&widget->ptr, widget->prop))) / arrow->range;
 			else
-				arrow->offset = ARROW_RANGE * ((RNA_property_float_get(widget->ptr, widget->prop) - arrow->min) / arrow->range);
+				arrow->offset = ARROW_RANGE * ((RNA_property_float_get(&widget->ptr, widget->prop) - arrow->min) / arrow->range);
 		}
 		else
-			arrow->offset = RNA_property_float_get(widget->ptr, widget->prop);
+			arrow->offset = RNA_property_float_get(&widget->ptr, widget->prop);
 	}
 	else if (op && widget->propname) {
 
@@ -412,17 +412,17 @@ static void widget_arrow_bind_to_prop(struct wmWidget *widget)
 		if (arrow->style & UI_ARROW_STYLE_CONSTRAINED) {
 			float min, max, step, precision;
 
-			RNA_property_float_ui_range(widget->ptr, widget->prop, &min, &max, &step, &precision);
+			RNA_property_float_ui_range(&widget->ptr, widget->prop, &min, &max, &step, &precision);
 			arrow->range = max - min;
 			arrow->min = min;
 			if (arrow->style & UI_ARROW_STYLE_INVERTED)
-				arrow->offset = ARROW_RANGE * (max - (RNA_property_float_get(widget->ptr, widget->prop))) / arrow->range;
+				arrow->offset = ARROW_RANGE * (max - (RNA_property_float_get(&widget->ptr, widget->prop))) / arrow->range;
 			else
-				arrow->offset = ARROW_RANGE * ((RNA_property_float_get(widget->ptr, widget->prop) - arrow->min) / arrow->range);
+				arrow->offset = ARROW_RANGE * ((RNA_property_float_get(&widget->ptr, widget->prop) - arrow->min) / arrow->range);
 		}
 		else {
 			/* we'd need to check the property type here but for now assume always float */
-			arrow->offset = RNA_property_float_get(widget->ptr, widget->prop);
+			arrow->offset = RNA_property_float_get(&widget->ptr, widget->prop);
 		}
 	}
 	else
@@ -752,8 +752,8 @@ static int widget_cage_handler(struct bContext *C, const struct wmEvent *event,
 		
 		value = data->orig_offset + (event->mval[0] - data->orig_mouse[0]);
 		
-		RNA_property_float_set(widget->ptr, widget->prop, value);
-		RNA_property_update(C, widget->ptr, widget->prop);
+		RNA_property_float_set(&widget->ptr, widget->prop, value);
+		RNA_property_update(C, &widget->ptr, widget->prop);
 		
 		widget->origin[0] = data->orig_origin[0] + (event->mval[0] - data->orig_mouse[0]);
 	}
@@ -768,7 +768,7 @@ static int widget_cage_handler(struct bContext *C, const struct wmEvent *event,
 static void widget_cage_bind_to_prop(struct wmWidget *widget)
 {
 	CageWidget *cage = (CageWidget *) widget;
-	cage->offset = RNA_property_float_get(widget->ptr, widget->prop);
+	cage->offset = RNA_property_float_get(&widget->ptr, widget->prop);
 }
 
 struct wmWidget *WIDGET_cage_new(int style, void *customdata)
diff --git a/source/blender/windowmanager/intern/wm_widgets.c b/source/blender/windowmanager/intern/wm_widgets.c
index 6c4eb8b..7a05f7c 100644
--- a/source/blender/windowmanager/intern/wm_widgets.c
+++ b/source/blender/windowmanager/intern/wm_widgets.c
@@ -188,7 +188,7 @@ void WM_widget_property(struct wmWidget *widget, struct PointerRNA *ptr, const c
 {
 	/* if widget evokes an operator we cannot use it for property manipulation */
 	widget->opname = NULL;
-	widget->ptr = ptr;
+	widget->ptr = *ptr;
 	widget->propname = propname;
 	widget->prop = RNA_struct_find_property(ptr, propname);
 
@@ -280,10 +280,55 @@ void WM_widgets_draw(const bContext *C, struct ARegion *ar)
 			if (!wgroup->type->poll || wgroup->type->poll(wgroup, C))
 			{
 				wmWidget *widget_iter;
-
+				wmWidget *highlighted = NULL;
+				
+				/* first delete and recreate the widgets */
+				for (widget_iter = wgroup->widgets.first; widget_iter;) {
+					wmWidget *widget_next = widget_iter->next;
+					
+					/* do not delete the highlighted widget, instead keep it to compare with the new one */
+					if (widget_iter->flag & WM_WIDGET_HIGHLIGHT) {
+						highlighted = widget_iter;
+						BLI_remlink(&wgroup->widgets, widget_iter);
+					}
+					else {
+						wm_widgets_delete(&wgroup->widgets, widget_iter);
+					}
+					widget_iter = widget_next;
+				}
+				
+				if (wgroup->type->free)
+					wgroup->type->free(wgroup);
+				
+				wgroup->type->create(wgroup);
+				
 				if (wgroup->type->update) {
 					wgroup->type->update(wgroup, C);
 				}
+				
+				if (highlighted) {
+					for (widget_iter = wgroup->widgets.first; widget_iter; widget_iter = widget_iter->next) {
+						if (widget_iter->ptr.data == highlighted->ptr.data &&
+						    widget_iter->opptr.data == highlighted->opptr.data &&
+						    widget_iter->prop == highlighted->prop) 
+						{
+							widget_iter->flag |= WM_WIDGET_HIGHLIGHT;
+							wmap->highlighted_widget = widget_iter;
+							wm_widgets_delete(&wgroup->widgets, highlighted);
+							highlighted = NULL;
+						}
+					}
+				}
+				
+				/* if we don't find a highlighted widget, delete the old one here */
+				if (highlighted) {
+					if (highlighted->flag & WM_WIDGET_FREE_DATA)
+						MEM_freeN(highlighted->customdata);
+					MEM_freeN(highlighted);
+					highlighted = NULL;
+					wmap->highlighted_widget = NULL;
+				}
+				
 
 				for (widget_iter = wgroup->widgets.first; widget_iter; widget_iter = widget_iter->next) {
 					if (!(widget_iter->flag & WM_WIDGET_SKIP_DRAW) &&
@@ -620,7 +665,7 @@ void wm_widgetmap_set_active_widget(struct wmWidgetMap *wmap, struct bContext *C
 			/* widget does nothing, pass */
 			wmap->active_widget = NULL;
 		}
-		else if (widget->opname || widget->ptr) {
+		else if (widget->opname || widget->ptr.data) {
 			wmOperatorType *ot;
 			const char *opname = (widget->opname) ? widget->opname : "WM_OT_widget_tweak";
 			
@@ -633,15 +678,15 @@ void wm_widgetmap_set_active_widget(struct wmWidgetMap *wmap, struct bContext *C
 					widget->activate_state(C, event, widget, WIDGET_ACTIVATE);
 				}
 
-				WM_operator_properties_alloc(&widget->opptr, &widget->properties, opname);
+				WM_operator_properties_create_ptr(&widget->opptr, ot);
 
 				/* time to initialize those properties now */
 				if

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list