[Bf-blender-cvs] [0161686] wiggly-widgets: Allow separate widget data per editor.

Antony Riakiotakis noreply at git.blender.org
Fri Nov 7 18:13:08 CET 2014


Commit: 016168652fbfb1993247736bbd3398a0a61217f1
Author: Antony Riakiotakis
Date:   Fri Nov 7 18:12:32 2014 +0100
Branches: wiggly-widgets
https://developer.blender.org/rB016168652fbfb1993247736bbd3398a0a61217f1

Allow separate widget data per editor.

To make this work, we need separate type/instance for the widgets. This
is a bit ugly but it is necessary if we want widgets on each editor to
depend of per editor-options or visibility state.

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

M	source/blender/blenkernel/intern/blender.c
M	source/blender/blenkernel/intern/screen.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/editors/screen/screen_edit.c
M	source/blender/editors/screen/screen_ops.c
M	source/blender/editors/space_view3d/space_view3d.c
M	source/blender/makesdna/DNA_screen_types.h
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_init_exit.c
M	source/blender/windowmanager/intern/wm_widgets.c

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

diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c
index af641460..adfe43c 100644
--- a/source/blender/blenkernel/intern/blender.c
+++ b/source/blender/blenkernel/intern/blender.c
@@ -616,9 +616,6 @@ static int read_undosave(bContext *C, UndoElem *uel)
 	else
 		success = BKE_read_file_from_memfile(C, &uel->memfile, NULL);
 
-	/* when reading from memory all references get invalidated so invalidate all widgets */
-	WM_widgetgroups_invalidate();
-
 	/* restore */
 	BLI_strncpy(G.main->name, mainstr, sizeof(G.main->name)); /* restore */
 	G.fileflags = fileflags;
diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c
index b229615..8aab931 100644
--- a/source/blender/blenkernel/intern/screen.c
+++ b/source/blender/blenkernel/intern/screen.c
@@ -177,6 +177,7 @@ ARegion *BKE_area_region_copy(SpaceType *st, ARegion *ar)
 	BLI_listbase_clear(&newar->panels_category_active);
 	BLI_listbase_clear(&newar->ui_lists);
 	newar->swinid = 0;
+	newar->widgetmap = NULL;
 	
 	/* use optional regiondata callback */
 	if (ar->regiondata) {
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index d99500d..b0aff3e 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -6258,6 +6258,7 @@ static void direct_link_region(FileData *fd, ARegion *ar, int spacetype)
 	BLI_listbase_clear(&ar->panels_category);
 	BLI_listbase_clear(&ar->handlers);
 	BLI_listbase_clear(&ar->uiblocks);
+	ar->widgetmap = NULL;
 	ar->headerstr = NULL;
 	ar->swinid = 0;
 	ar->type = NULL;
diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c
index 9463a70..fe9d0bb 100644
--- a/source/blender/editors/screen/screen_edit.c
+++ b/source/blender/editors/screen/screen_edit.c
@@ -1270,6 +1270,7 @@ void ED_region_exit(bContext *C, ARegion *ar)
 
 	CTX_wm_region_set(C, ar);
 	WM_event_remove_handlers(C, &ar->handlers);
+	WM_widgetmap_delete(ar->widgetmap);
 	if (ar->swinid)
 		wm_subwindow_close(CTX_wm_window(C), ar->swinid);
 	ar->swinid = 0;
diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c
index ac06175..76ab627 100644
--- a/source/blender/editors/screen/screen_ops.c
+++ b/source/blender/editors/screen/screen_ops.c
@@ -3977,8 +3977,10 @@ void region_blend_start(bContext *C, ScrArea *sa, ARegion *ar)
 	/* blend in, reinitialize regions because it got unhidden */
 	if (rgi->hidden == 0)
 		ED_area_initialize(wm, win, sa);
-	else
+	else {
 		WM_event_remove_handlers(C, &ar->handlers);
+		WM_widgetmap_delete(ar->widgetmap);
+	}
 
 	if (ar->next) {
 		if (ar->next->alignment & RGN_SPLIT_PREV) {
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index 925bbe2..6bea2ed 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -385,6 +385,7 @@ static SpaceLink *view3d_new(const bContext *C)
 	ar->regiontype = RGN_TYPE_WINDOW;
 	
 	ar->regiondata = MEM_callocN(sizeof(RegionView3D), "region view3d");
+
 	rv3d = ar->regiondata;
 	rv3d->viewquat[0] = 1.0f;
 	rv3d->persp = RV3D_PERSP;
@@ -549,8 +550,8 @@ static void view3d_main_area_init(wmWindowManager *wm, ARegion *ar)
 	
 	WM_event_add_dropbox_handler(&ar->handlers, lb);
 
-	ar->widgetmap = WM_widgetmap_find("View3D", SPACE_VIEW3D, RGN_TYPE_WINDOW, true);
-	
+	ar->widgetmap = WM_widgetmap_from_type("View3D", SPACE_VIEW3D, RGN_TYPE_WINDOW, true);
+
 	WM_event_add_widget_handler(ar);
 }
 
@@ -690,63 +691,81 @@ static void view3d_dropboxes(void)
 	WM_dropbox_add(lb, "OBJECT_OT_group_instance_add", view3d_group_drop_poll, view3d_group_drop_copy);	
 }
 
-static void view3d_widgets(void)
+static void WIDGETGROUP_manipulator_create(struct wmWidgetGroup *wgroup)
 {
 	float color_green[4] = {0.0f, 1.0f, 0.0f, 1.0f};
 	float color_red[4] = {1.0f, 0.0f, 0.0f, 1.0f};
 	float color_blue[4] = {0.0f, 0.0f, 1.0f, 1.0f};
 
-	float color_lamp[4] = {0.5f, 0.5f, 1.0f, 1.0f};
-
 	wmWidget *widget = NULL;
-	ManipulatorGroup *manipulator = MEM_callocN(sizeof(ManipulatorGroup), "manipulator_data");
-	WidgetGroupLamp *lampgroup = MEM_callocN(sizeof(ManipulatorGroup), "lamp_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,
-	                                                              WIDGETGROUP_manipulator_free, manipulator);
-	struct wmWidgetGroup *wgroup_light = WM_widgetgroup_new(WIDGETGROUP_lamp_poll, WIDGETGROUP_lamp_update, WIDGETGROUP_lamp_free, lampgroup);
 
-	lampgroup->lamp = MEM_callocN(sizeof(PointerRNA), "lampwidgetptr");
+	ManipulatorGroup *manipulator = MEM_callocN(sizeof(ManipulatorGroup), "manipulator_data");
 
-	widget = WM_widget_new(WIDGET_manipulator_draw, 
+	widget = WM_widget_new(WIDGET_manipulator_draw,
 	                       WIDGET_manipulator_render_3d_intersect,
 	                       NULL,
 	                       WIDGET_manipulator_handler,
 	                       NULL, NULL, false, NULL, NULL);
-	
-	WM_widget_register(wgroup_manipulator, widget);
+
+	WM_widget_register(wgroup, widget);
 
 	manipulator->translate_x = WIDGET_arrow_new(0, WIDGET_manipulator_handler_trans, "TRANSFORM_OT_translate", NULL, NULL);
 	WIDGET_arrow_set_color(manipulator->translate_x, color_red);
-	WM_widget_register(wgroup_manipulator, manipulator->translate_x);
+	WM_widget_register(wgroup, manipulator->translate_x);
 
 	manipulator->translate_y = WIDGET_arrow_new(0, WIDGET_manipulator_handler_trans, "TRANSFORM_OT_translate", NULL, SET_INT_IN_POINTER(1));
 	WIDGET_arrow_set_color(manipulator->translate_y, color_green);
-	WM_widget_register(wgroup_manipulator, manipulator->translate_y);
+	WM_widget_register(wgroup, manipulator->translate_y);
 
 	manipulator->translate_z = WIDGET_arrow_new(0, WIDGET_manipulator_handler_trans, "TRANSFORM_OT_translate", NULL, SET_INT_IN_POINTER(2));
 	WIDGET_arrow_set_color(manipulator->translate_z, color_blue);
-	WM_widget_register(wgroup_manipulator, manipulator->translate_z);
+	WM_widget_register(wgroup, manipulator->translate_z);
 
 	manipulator->rotate_x = WIDGET_dial_new(UI_DIAL_STYLE_RING_CLIPPED, WIDGET_manipulator_handler_rot, "TRANSFORM_OT_rotate", NULL, NULL);
 	WIDGET_dial_set_color(manipulator->rotate_x, color_red);
-	WM_widget_register(wgroup_manipulator, manipulator->rotate_x);
+	WM_widget_register(wgroup, manipulator->rotate_x);
 
 	manipulator->rotate_y = WIDGET_dial_new(UI_DIAL_STYLE_RING_CLIPPED, WIDGET_manipulator_handler_rot, "TRANSFORM_OT_rotate", NULL, SET_INT_IN_POINTER(1));
 	WIDGET_dial_set_color(manipulator->rotate_y, color_green);
-	WM_widget_register(wgroup_manipulator, manipulator->rotate_y);
+	WM_widget_register(wgroup, manipulator->rotate_y);
 
 	manipulator->rotate_z = WIDGET_dial_new(UI_DIAL_STYLE_RING_CLIPPED, WIDGET_manipulator_handler_rot, "TRANSFORM_OT_rotate", NULL, SET_INT_IN_POINTER(2));
 	WIDGET_dial_set_color(manipulator->rotate_z, color_blue);
-	WM_widget_register(wgroup_manipulator, manipulator->rotate_z);
+	WM_widget_register(wgroup, manipulator->rotate_z);
+
+	WM_widgetgroup_customdata_set(wgroup, manipulator);
+}
+
+static void WIDGETGROUP_lamp_create(struct wmWidgetGroup *wgroup)
+{
+	float color_lamp[4] = {0.5f, 0.5f, 1.0f, 1.0f};
+	wmWidget *widget = NULL;
+	WidgetGroupLamp *lampgroup = MEM_callocN(sizeof(WidgetGroupLamp), "lamp_manipulator_data");
+
+	lampgroup->lamp = MEM_callocN(sizeof(PointerRNA), "lampwidgetptr");
 
 	widget = WIDGET_arrow_new(UI_ARROW_STYLE_INVERTED, NULL, NULL, NULL, NULL);
-	WM_widget_register(wgroup_light,  widget);
+	WM_widget_register(wgroup, widget);
 	WIDGET_arrow_set_color(widget, color_lamp);
 
-	WM_widgetgroup_register(wmap, wgroup_manipulator);
-	WM_widgetgroup_register(wmap, wgroup_light);
+	WM_widgetgroup_customdata_set(wgroup, lampgroup);
+}
+
+
+static void view3d_widgets(void)
+{
+	struct wmWidgetMapType *wmaptype = WM_widgetmaptype_find("View3D", SPACE_VIEW3D, RGN_TYPE_WINDOW, true);
+	struct wmWidgetGroupType *wgroup_manipulator = WM_widgetgrouptype_new(WIDGETGROUP_manipulator_create,
+	                                                                      WIDGETGROUP_manipulator_poll,
+	                                                                      WIDGETGROUP_manipulator_update,
+	                                                                      WIDGETGROUP_manipulator_free);
+	struct wmWidgetGroupType *wgroup_light = WM_widgetgrouptype_new(WIDGETGROUP_lamp_create,
+	                                                                WIDGETGROUP_lamp_poll,
+	                                                                WIDGETGROUP_lamp_update,
+	                                                                WIDGETGROUP_lamp_free);
+
+	WM_widgetgrouptype_register(wmaptype, wgroup_manipulator);
+	WM_widgetgrouptype_register(wmaptype, wgroup_light);
 }
 
 
diff --git a/source/blender/makesdna/DNA_screen_types.h b/source/blender/makesdna/DNA_screen_types.h
index e75bdcd..0cf8538 100644
--- a/source/blender/makesdna/DNA_screen_types.h
+++ b/source/blender/makesdna/DNA_screen_types.h
@@ -259,7 +259,7 @@ typedef struct ARegion {
 	ListBase ui_lists;			/* uiList */
 	ListBase ui_previews;		/* uiPreview */
 	ListBase handlers;			/* wmEventHandler */
-	struct wmWidgetMap *widgetmap;			/* widgets for drawing */
+	struct wmWidgetMap *widgetmap;	/* widgets for drawing */
 	ListBase panels_category;	/* Panel categories runtime */
 	
 	struct wmTimer *regiontimer; /* blend in/out */
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 6a8f2d3..45508f5 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -60,6 +60,8 @@ struct wmOperator;
 struct wmWidget;
 struct wmWidgetGroup;
 struct wmWidgetMap;
+struct wmWidgetGroupType;
+struct wmWidgetMapType;
 struct rcti;
 struct PointerRNA;
 struct Property

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list