[Bf-blender-cvs] [c56b812] wiggly-widgets: WIP commit, basically introducing a few things here:

Antony Riakiotakis noreply at git.blender.org
Wed Oct 15 19:16:21 CEST 2014


Commit: c56b812f765dd4bf4cf3d71ce936814999fd1d8c
Author: Antony Riakiotakis
Date:   Wed Oct 15 19:16:09 2014 +0200
Branches: wiggly-widgets
https://developer.blender.org/rBc56b812f765dd4bf4cf3d71ce936814999fd1d8c

WIP commit, basically introducing a few things here:

* highlighted vs active widget.

Active widget takes all input and basically highjacks drawing of all
other widgets in the widgetmap.

* operator names for widgets. Now widgets will spawn operators based on
names that are passed on them. They will also modify a named property of
the operator and pass it on, after which operator can process it.

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

M	source/blender/editors/object/object_lamp.c
M	source/blender/windowmanager/WM_types.h
M	source/blender/windowmanager/intern/wm_event_system.c
M	source/blender/windowmanager/intern/wm_widgets.c
M	source/blender/windowmanager/wm_event_system.h

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

diff --git a/source/blender/editors/object/object_lamp.c b/source/blender/editors/object/object_lamp.c
index 8df5805..3cfc8fc 100644
--- a/source/blender/editors/object/object_lamp.c
+++ b/source/blender/editors/object/object_lamp.c
@@ -200,13 +200,16 @@ void WIDGETGROUP_lamp_update(struct wmWidgetGroup *wgroup, const struct bContext
 int WIDGET_lamp_handler(struct bContext *C, const struct wmEvent *UNUSED(event), struct wmWidget *UNUSED(widget))
 {
 
-	struct PointerRNA *ptr = NULL;			/* rna pointer to access properties */
-	struct IDProperty *properties = NULL;	/* operator properties, assigned to ptr->data and can be written to a file */
+	struct PointerRNA ptr;
+	wmOperatorType *ot = WM_operatortype_find("UI_OT_lamp_position", 0);
 
-	WM_operator_properties_alloc(&ptr, &properties, "UI_OT_lamp_position");
-	WM_operator_name_call(C, "UI_OT_lamp_position", WM_OP_INVOKE_DEFAULT, ptr);
-	WM_operator_properties_free(ptr);
-	MEM_freeN(ptr);
+	if (ot) {
+		WM_operator_properties_create_ptr(&ptr, ot);
+		WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &ptr);
 
-	return OPERATOR_FINISHED;
+		return OPERATOR_FINISHED;
+	}
+
+	printf("Widget error: operator not found");
+	return OPERATOR_CANCELLED;
 }
diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h
index 842086c..4b1235f 100644
--- a/source/blender/windowmanager/WM_types.h
+++ b/source/blender/windowmanager/WM_types.h
@@ -662,15 +662,29 @@ typedef struct wmWidget {
 	/* determine if the mouse intersects with the widget. The calculation should be done in the callback itself */
 	int  (*intersect)(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget);
 	
-	/* determines 3d intersetion by rendering the widget in a selection routine. Returns number of max selection ids that
-	 * will be used by the widget */
+	/* determines 3d intersetion by rendering the widget in a selection routine. */
 	void (*render_3d_intersection)(const struct bContext *C, struct wmWidget *widget, float scale, int selectionbase);
 	
+	/* handler used by the widget. Usually handles interaction tied to a widget type */
 	int  (*handler)(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget);
+
 	int  flag; /* flags set by drawing and interaction, such as highlighting */
 
 	/* position in space, 2d or 3d */
 	float origin[3];
+
+	/* data used during interaction */
+	void *interaction_data;
+
+	/* name of operator to spawn when activating the widget */
+	char *opname;
+	/* property name of the operator that the widget controls */
+	char *oppropname;
+	/* operator type that will be called */
+	wmOperatorType *ot;
+
+	/* operator properties, stored if widget spawns and controls an operator */
+	struct PointerRNA opptr;
 } wmWidget;
 
 /* WidgetGroups store and manage groups of widgets.
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index fcab5a8..b7edf8d 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -1972,38 +1972,45 @@ static int wm_handlers_do_intern(bContext *C, wmEvent *event, ListBase *handlers
 			}
 			else if (handler->widgetmap) {
 				struct wmWidgetMap *wmap = handler->widgetmap;
+				wmWidget *widget = wm_widgetmap_get_active_widget(wmap);
 				
 				switch (event->type) {
-
 					case MOUSEMOVE:
-						if (wm_widgetmap_is_3d(wmap)) {
-							wmWidget *widget;
-							/* similar interface to operators */
-							if ((widget = wm_widget_find_active_3D (wmap, C, event)))
-							{
-								wm_widgetmap_set_active_widget(wmap, C, widget);
-							}
-							else {
-								wm_widgetmap_set_active_widget(wmap, C, NULL);
-							}
+						if (widget) {
+							widget->handler(C, event, widget);
+							action |= WM_HANDLER_BREAK;
+						}
+						else if (wm_widgetmap_is_3d(wmap)) {
+							widget = wm_widget_find_highlighted_3D (wmap, C, event);
+							wm_widgetmap_set_highlighted_widget(wmap, C, widget);
 						}
 						else {
-							wm_widgetmap_set_active_widget(wmap, C, NULL);
+							wm_widgetmap_set_highlighted_widget(wmap, C, NULL);
 						}
-						action |= WM_HANDLER_BREAK;
 						break;
 
 					case LEFTMOUSE:
-						if (event->val == KM_PRESS) {
-							int ret = -1;
-							wmWidget *widget = wm_widgetmap_get_active_widget(wmap);
-
-							if (widget && widget->handler && (ret = widget->handler(C, event, widget)) == OPERATOR_FINISHED) {
+					{
+						if (widget) {
+							if (event->val == KM_RELEASE) {
+								wm_widgetmap_set_active_widget(wmap, C, NULL);
 								action |= WM_HANDLER_BREAK;
 							}
+							else {
+								widget->handler(C, event, widget);
+								action |= WM_HANDLER_BREAK;
+							}
+						}
+						else if (event->val == KM_PRESS) {
+							widget = wm_widgetmap_get_highlighted_widget(wmap);
 
+							if (widget) {
+								wm_widgetmap_set_active_widget(wmap, C, widget);
+								action |= WM_HANDLER_BREAK;
+							}
 						}
 						break;
+					}
 				}
 			}
 			else {
diff --git a/source/blender/windowmanager/intern/wm_widgets.c b/source/blender/windowmanager/intern/wm_widgets.c
index 897e968..9a22d89 100644
--- a/source/blender/windowmanager/intern/wm_widgets.c
+++ b/source/blender/windowmanager/intern/wm_widgets.c
@@ -80,7 +80,10 @@ typedef struct wmWidgetMap {
 	/* check if widgetmap does 3D drawing */
 	bool is_3d;
 	
-	/* active widget for this map. We redraw the widgetmap when this changes  */
+	/* highlighted widget for this map. We redraw the widgetmap when this changes  */
+	wmWidget *highlighted_widget;
+
+	/* active widget for this map. User has clicked and is currently this widget  */
 	wmWidget *active_widget;
 } wmWidgetMap;
 
@@ -167,7 +170,7 @@ void WM_widgets_draw(const struct bContext *C, struct ARegion *ar)
 {
 	RegionView3D *rv3d = ar->regiondata;
 	wmWidgetMap *wmap = ar->widgetmap;
-
+	wmWidget *widget = wmap->active_widget;
 	bool use_lighting = (U.tw_flag & V3D_SHADED_WIDGETS) != 0;
 
 	if (use_lighting) {
@@ -186,7 +189,17 @@ void WM_widgets_draw(const struct bContext *C, struct ARegion *ar)
 		glPopMatrix();
 	}
 
-	if (wmap->widgetgroups.first) {
+	if (widget) {
+		float scale = 1.0;
+
+		if (!(U.tw_flag & V3D_3D_WIDGETS))
+			scale = ED_view3d_pixel_size(rv3d, widget->origin) * U.tw_size;
+
+		/* 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(widget, C, scale);
+	}
+	else if (wmap->widgetgroups.first) {
 		wmWidgetGroup *wgroup;
 		
 		for (wgroup = wmap->widgetgroups.first; wgroup; wgroup = wgroup->next) {
@@ -339,7 +352,7 @@ static void widget_find_active_3D_loop(bContext *C, ListBase *visible_widgets)
 	}
 }
 
-static int wm_widget_find_active_3D_intern (ListBase *visible_widgets, bContext *C, const struct wmEvent *event, float hotspot)
+static int wm_widget_find_highlighted_3D_intern (ListBase *visible_widgets, bContext *C, const struct wmEvent *event, float hotspot)
 {
 	ScrArea *sa = CTX_wm_area(C);
 	ARegion *ar = CTX_wm_region(C);
@@ -423,7 +436,7 @@ static void wm_prepare_visible_widgets(struct wmWidgetMap *wmap, ListBase *visib
 	}
 }
 
-wmWidget *wm_widget_find_active_3D(struct wmWidgetMap *wmap, bContext *C, const struct wmEvent *event)
+wmWidget *wm_widget_find_highlighted_3D(struct wmWidgetMap *wmap, bContext *C, const struct wmEvent *event)
 {
 	int ret, retsec;
 	wmWidget *result = NULL;
@@ -435,12 +448,12 @@ wmWidget *wm_widget_find_active_3D(struct wmWidgetMap *wmap, bContext *C, const
 	/* set up view matrices */	
 	view3d_operator_needs_opengl(C);
 	
-	ret = wm_widget_find_active_3D_intern(&visible_widgets, C, event, 0.5f * (float)U.tw_hotspot);
+	ret = wm_widget_find_highlighted_3D_intern(&visible_widgets, C, event, 0.5f * (float)U.tw_hotspot);
 	
 	if (ret != -1) {
 		LinkData *link;
 		int retfinal;
-		retsec = wm_widget_find_active_3D_intern(&visible_widgets, C, event, 0.2f * (float)U.tw_hotspot);
+		retsec = wm_widget_find_highlighted_3D_intern(&visible_widgets, C, event, 0.2f * (float)U.tw_hotspot);
 		
 		if (retsec == -1)
 			retfinal = ret;
@@ -456,21 +469,58 @@ wmWidget *wm_widget_find_active_3D(struct wmWidgetMap *wmap, bContext *C, const
 	return result;
 }
 
-void wm_widgetmap_set_active_widget(struct wmWidgetMap *wmap, struct bContext *C, struct wmWidget *widget)
+void wm_widgetmap_set_highlighted_widget(struct wmWidgetMap *wmap, struct bContext *C, struct wmWidget *widget)
 {
-	ARegion *ar = CTX_wm_region(C);
-		
-	if (widget != wmap->active_widget) {
-		if (wmap->active_widget) {
-			wmap->active_widget->flag &= ~WM_WIDGET_HIGHLIGHT;
+	if (widget != wmap->highlighted_widget) {
+		ARegion *ar = CTX_wm_region(C);
+
+		if (wmap->highlighted_widget) {
+			wmap->highlighted_widget->flag &= ~WM_WIDGET_HIGHLIGHT;
 		}
-		wmap->active_widget = widget;
+		wmap->highlighted_widget = widget;
 		
 		if (widget) {
 			widget->flag |= WM_WIDGET_HIGHLIGHT;
 		}
 		
-		/* tag the region for redraw */		
+		/* tag the region for redraw */
+		ED_region_tag_redraw(ar);
+	}
+}
+
+struct wmWidget *wm_widgetmap_get_highlighted_widget(struct wmWidgetMap *wmap)
+{
+	return wmap->highlighted_widget;
+}
+
+void wm_widgetmap_set_active_widget(struct wmWidgetMap *wmap, struct bContext *C, struct wmWidget *widget)
+{
+	if (widget) {
+		if (widget->opname) {
+			wmOperatorType *ot = widget->ot = WM_operatortype_find(widget->opname, 0);
+
+			if (ot) {
+				WM_operator_properties_create_ptr(&widget->opptr, ot);
+				WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &widget->opptr);
+				wmap->active_widget = widget;
+				return;
+			}
+			else {
+				printf("Widget error: operator not found");
+				wmap->active_widget = NULL;
+				return;
+			}
+		}
+		else {
+			/* widget does nothing, pass */
+			wmap->active_widget = NULL;
+		}
+	}
+	else {
+		ARegion *ar = CTX_wm_region(C);
+		/* deactivate, widget but first take care of some stuff */
+
+		wmap->active_widget = NULL;
 		ED_region_tag_redraw(ar);
 	}
 }
diff --git a/source/blender/windowmanager/wm_event_system.h b/source/blender/windowmanager/wm_event_system.h
index 346db47..65e201d 100644
--- a/source/blender/windowmanager/wm_event_system.h
+++ b/source

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list