[Bf-blender-cvs] [787743b] wiggly-widgets: Add back an extra paramater to the intersection function to determine the highlighted part of the widget.

Antony Riakiotakis noreply at git.blender.org
Fri Dec 5 16:43:13 CET 2014


Commit: 787743b1edd1b8ee4cca5f394fc32a946249a318
Author: Antony Riakiotakis
Date:   Fri Dec 5 16:42:39 2014 +0100
Branches: wiggly-widgets
https://developer.blender.org/rB787743b1edd1b8ee4cca5f394fc32a946249a318

Add back an extra paramater to the intersection function to determine
the highlighted part of the widget.

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

M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_event_system.c
M	source/blender/windowmanager/intern/wm_widgets.c
M	source/blender/windowmanager/wm.h
M	source/blender/windowmanager/wm_event_system.h

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

diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index c637868..b3aba29 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -482,7 +482,6 @@ struct wmWidget *WM_widget_new(void (*draw)(struct wmWidget *, const struct bCon
 
 void WM_widget_property(struct wmWidget *, struct PointerRNA *ptr, const char *propname);
 void WM_widget_operator(struct wmWidget *,
-                        int  (*initialize_op)(struct bContext *, const struct wmEvent *, struct wmWidget *, struct PointerRNA *),
                         const char *opname,
                         const char *propname);
 void WM_widgets_draw(const struct bContext *C, struct ARegion *ar);
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index fc216b8..a33f0ef 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -2005,6 +2005,7 @@ static int wm_handlers_do_intern(bContext *C, wmEvent *event, ListBase *handlers
 			}
 			else if (handler->widgetmap) {
 				struct wmWidgetMap *wmap = handler->widgetmap;
+				unsigned char part;
 				wmWidget *widget = wm_widgetmap_get_active_widget(wmap);
 				
 				switch (event->type) {
@@ -2014,12 +2015,12 @@ static int wm_handlers_do_intern(bContext *C, wmEvent *event, ListBase *handlers
 							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);
+							widget = wm_widget_find_highlighted_3D(wmap, C, event, &part);
+							wm_widgetmap_set_highlighted_widget(wmap, C, widget, part);
 						}
 						else {
-							widget = wm_widget_find_highlighted(wmap, C, event);
-							wm_widgetmap_set_highlighted_widget(wmap, C, widget);
+							widget = wm_widget_find_highlighted(wmap, C, event, &part);
+							wm_widgetmap_set_highlighted_widget(wmap, C, widget, part);
 						}
 						break;
 
diff --git a/source/blender/windowmanager/intern/wm_widgets.c b/source/blender/windowmanager/intern/wm_widgets.c
index e7bd4e4..613b753 100644
--- a/source/blender/windowmanager/intern/wm_widgets.c
+++ b/source/blender/windowmanager/intern/wm_widgets.c
@@ -78,7 +78,6 @@ typedef struct wmWidgetMap {
 	
 	/* 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;
@@ -181,24 +180,32 @@ void WM_widget_property(struct wmWidget *widget, struct PointerRNA *ptr, const c
 }
 
 void WM_widget_operator(struct wmWidget *widget,
-                        int  (*initialize_op)(struct bContext *, const struct wmEvent *, struct wmWidget *, struct PointerRNA *),
                         const char *opname,
                         const char *propname)
 {
-	widget->initialize_op = initialize_op;
-	widget->opname = opname;
-	widget->propname = propname;
-
-	if (widget->bind_to_prop)
-		widget->bind_to_prop(widget);
+	wmOperatorType *ot = WM_operatortype_find(opname, 0);
+	
+	if (ot) {
+		widget->opname = opname;
+		widget->propname = propname;
+		
+		WM_operator_properties_create_ptr(&widget->opptr, ot);
+		
+		if (widget->bind_to_prop)
+			widget->bind_to_prop(widget);
+	}
 }
 
 
-static void wm_widgets_delete(ListBase *widgetlist, wmWidget *widget)
+static void wm_widget_delete(ListBase *widgetlist, wmWidget *widget)
 {
 	if (widget->flag & WM_WIDGET_FREE_DATA)
 		MEM_freeN(widget->customdata);
 	
+	if (widget->opptr.data) {
+		WM_operator_properties_free(&widget->opptr);
+	}
+	
 	BLI_freelinkN(widgetlist, widget);
 }
 
@@ -276,7 +283,7 @@ void WM_widgets_draw(const bContext *C, struct ARegion *ar)
 						BLI_remlink(&wgroup->widgets, widget_iter);
 					}
 					else {
-						wm_widgets_delete(&wgroup->widgets, widget_iter);
+						wm_widget_delete(&wgroup->widgets, widget_iter);
 					}
 					widget_iter = widget_next;
 				}
@@ -293,7 +300,7 @@ void WM_widgets_draw(const bContext *C, struct ARegion *ar)
 						{
 							widget_iter->flag |= WM_WIDGET_HIGHLIGHT;
 							wmap->highlighted_widget = widget_iter;
-							wm_widgets_delete(&wgroup->widgets, highlighted);
+							wm_widget_delete(&wgroup->widgets, highlighted);
 							highlighted = NULL;
 						}
 					}
@@ -458,7 +465,8 @@ static void widget_find_active_3D_loop(bContext *C, ListBase *visible_widgets)
 
 	for (link = visible_widgets->first; link; link = link->next) {
 		widget = link->data;
-		widget->render_3d_intersection(C, widget, selectionbase);
+		/* pass the selection id shifted by 8 bits. Last 8 bits are used for selected widget part id */
+		widget->render_3d_intersection(C, widget, selectionbase << 8);
 
 		selectionbase++;
 	}
@@ -548,7 +556,7 @@ static void wm_prepare_visible_widgets_3D(struct wmWidgetMap *wmap, ListBase *vi
 	}
 }
 
-wmWidget *wm_widget_find_highlighted_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, unsigned char *part)
 {
 	int ret;
 	wmWidget *result = NULL;
@@ -557,6 +565,7 @@ wmWidget *wm_widget_find_highlighted_3D(struct wmWidgetMap *wmap, bContext *C, c
 
 	wm_prepare_visible_widgets_3D(wmap, &visible_widgets, C);
 
+	*part = 0;
 	/* set up view matrices */	
 	view3d_operator_needs_opengl(C);
 	
@@ -564,15 +573,14 @@ wmWidget *wm_widget_find_highlighted_3D(struct wmWidgetMap *wmap, bContext *C, c
 	
 	if (ret != -1) {
 		LinkData *link;
-		int retfinal, retsec;
+		int retsec;
 		retsec = wm_widget_find_highlighted_3D_intern(&visible_widgets, C, event, 0.2f * (float)U.tw_hotspot);
 		
-		if (retsec == -1)
-			retfinal = ret;
-		else
-			retfinal = retsec;
+		if (retsec != -1)
+			ret = retsec;
 		
-		link = BLI_findlink(&visible_widgets, retfinal);
+		link = BLI_findlink(&visible_widgets, ret >> 8);
+		*part = ret & 255;
 		result = link->data;
 	}
 
@@ -581,7 +589,7 @@ wmWidget *wm_widget_find_highlighted_3D(struct wmWidgetMap *wmap, bContext *C, c
 	return result;
 }
 
-wmWidget *wm_widget_find_highlighted(struct wmWidgetMap *wmap, bContext *C, const struct wmEvent *event)
+wmWidget *wm_widget_find_highlighted(struct wmWidgetMap *wmap, bContext *C, const struct wmEvent *event, unsigned char *part)
 {
 	wmWidget *widget;
 	wmWidgetGroup *wgroup;
@@ -590,7 +598,7 @@ wmWidget *wm_widget_find_highlighted(struct wmWidgetMap *wmap, bContext *C, cons
 		if (!wgroup->type->poll || wgroup->type->poll(wgroup, C)) {
 			for (widget = wgroup->widgets.first; widget; widget = widget->next) {
 				if (widget->intersect) {
-					if (widget->intersect(C, event, widget))
+					if ((*part = widget->intersect(C, event, widget)))
 						return widget;
 				}
 			}
@@ -601,18 +609,21 @@ wmWidget *wm_widget_find_highlighted(struct wmWidgetMap *wmap, bContext *C, cons
 }
 
 
-void wm_widgetmap_set_highlighted_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, unsigned char part)
 {
 	if (widget != wmap->highlighted_widget) {
 		ARegion *ar = CTX_wm_region(C);
 
 		if (wmap->highlighted_widget) {
 			wmap->highlighted_widget->flag &= ~WM_WIDGET_HIGHLIGHT;
+			wmap->highlighted_widget->highlighted_part = 0;
 		}
+		
 		wmap->highlighted_widget = widget;
 		
 		if (widget) {
 			widget->flag |= WM_WIDGET_HIGHLIGHT;
+			widget->highlighted_part = part;
 		}
 		
 		/* tag the region for redraw */
@@ -632,7 +643,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.data) {
+		else if (widget->opptr.data || widget->ptr.data) {
 			wmOperatorType *ot;
 			const char *opname = (widget->opname) ? widget->opname : "WM_OT_widget_tweak";
 			
@@ -645,13 +656,6 @@ void wm_widgetmap_set_active_widget(struct wmWidgetMap *wmap, struct bContext *C
 					widget->activate_state(C, event, widget, WIDGET_ACTIVATE);
 				}
 
-				WM_operator_properties_create_ptr(&widget->opptr, ot);
-
-				/* time to initialize those properties now */
-				if (widget->initialize_op) {
-					widget->initialize_op(C, event, widget, &widget->opptr);
-				}
-
 				CTX_wm_widget_set(C, widget);
 				WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &widget->opptr);
 				wmap->active_widget = widget;
@@ -679,10 +683,6 @@ void wm_widgetmap_set_active_widget(struct wmWidgetMap *wmap, struct bContext *C
 			if (widget->activate_state) {
 				widget->activate_state(C, event, widget, WIDGET_DEACTIVATE);
 			}
-
-			if (widget->opptr.data) {
-				WM_operator_properties_free(&widget->opptr);
-			}
 		}
 
 		CTX_wm_widget_set(C, NULL);
@@ -734,7 +734,7 @@ void WM_widgetmap_delete(struct wmWidgetMap *wmap)
 		
 		for (widget = wgroup->widgets.first; widget;) {
 			wmWidget *widget_next = widget->next;
-			wm_widgets_delete(&wgroup->widgets, widget);
+			wm_widget_delete(&wgroup->widgets, widget);
 			widget = widget_next;
 		}
 	}
diff --git a/source/blender/windowmanager/wm.h b/source/blender/windowmanager/wm.h
index d0bf5a7..72d6dbc 100644
--- a/source/blender/windowmanager/wm.h
+++ b/source/blender/windowmanager/wm.h
@@ -63,9 +63,6 @@ typedef struct wmWidget {
 	/* determines 3d intersection by rendering the widget in a selection routine. */
 	void (*render_3d_intersection)(const struct bContext *C, struct wmWidget *widget, int selectionbase);
 
-	/* initialize the operator properties when the user clicks the widget */
-	int (*initialize_op)(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget, struct PointerRNA *ptr);
-
 	/* 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, struct wmOperator *op);
 
@@ -76,10 +73,12 @@ typedef struct wmWidget {
 	 * used in calculations of scale */
 	void (*get_final_position)(struct wmWidget *widget, float ve

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list