[Bf-blender-cvs] [4b07a7d] wiggly-widgets: Move struct member 'is_3d' to a flag

Campbell Barton noreply at git.blender.org
Tue Jan 5 07:51:52 CET 2016


Commit: 4b07a7ddfd86b6523c1a1d21c99e0f58ac1d402e
Author: Campbell Barton
Date:   Tue Jan 5 17:20:26 2016 +1100
Branches: wiggly-widgets
https://developer.blender.org/rB4b07a7ddfd86b6523c1a1d21c99e0f58ac1d402e

Move struct member 'is_3d' to a flag

Means we don't have to add new args for each type-option and
makes is useful for RNA-subclassing.

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

M	source/blender/makesrna/intern/rna_wm.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/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c
index f0fc84a..dcdd292 100644
--- a/source/blender/makesrna/intern/rna_wm.c
+++ b/source/blender/makesrna/intern/rna_wm.c
@@ -1547,7 +1547,7 @@ static StructRNA *rna_WidgetGroup_register(Main *bmain, ReportList *reports, voi
 	}
 	
 	/* check if the area supports widgets */
-	if (!WM_widgetmaptype_find(dummywgt.mapidname ,dummywgt.spaceid, dummywgt.regionid, dummywgt.is_3d, false)) {
+	if (!WM_widgetmaptype_find(dummywgt.mapidname ,dummywgt.spaceid, dummywgt.regionid, dummywgt.flag, false)) {
 		BKE_reportf(reports, RPT_ERROR, "Area type does not support widgets");
 		return NULL;
 	}
@@ -1574,7 +1574,9 @@ static StructRNA *rna_WidgetGroup_register(Main *bmain, ReportList *reports, voi
 	dummywgt.poll = (have_function[0]) ? widgetgroup_poll : NULL;
 	dummywgt.create = (have_function[1]) ? widgetgroup_draw : NULL;
 
-	wgrouptype = WM_widgetgrouptype_new(dummywgt.poll, dummywgt.create, NULL, bmain, dummywgt.mapidname, NULL, dummywgt.spaceid, dummywgt.regionid, dummywgt.is_3d);
+	wgrouptype = WM_widgetgrouptype_new(
+	        dummywgt.poll, dummywgt.create, NULL,
+	        bmain, dummywgt.mapidname, NULL, dummywgt.spaceid, dummywgt.regionid, dummywgt.flag);
 	memcpy(wgrouptype, &dummywgt, sizeof(dummywgt));
 	
 	/* update while blender is running */
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 2984603..be76638 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -532,7 +532,7 @@ void  WM_modal_handler_attach_widgetgroup(struct bContext *C, struct wmEventHand
                                           struct wmWidgetGroupType *wgrouptype, struct wmOperator *op);
 
 /* wmWidget->flag */
-enum widgetflags {
+enum eWidgetFlag {
 	/* states */
 	WM_WIDGET_HIGHLIGHT   = (1 << 0),
 	WM_WIDGET_ACTIVE      = (1 << 1),
@@ -546,6 +546,16 @@ enum widgetflags {
 	WM_WIDGET_SELECTABLE  = (1 << 8),
 };
 
+/* wmWidgetType->flag */
+enum eWidgetTypeFlag {
+	/**
+	 * Check if widgetmap does 3D drawing
+	 * (uses a different kind of interaction),
+	 * - 3d: use glSelect buffer.
+	 * - 2d: use simple cursor position intersection test. */
+	WM_WIDGET_TYPE_3D           = (1 << 0),
+};
+
 /**
  * \brief Widget tweak flag.
  * Bitflag passed to widget while tweaking.
@@ -570,8 +580,9 @@ void WM_widget_set_colors(struct wmWidget *widget, const float col[4], const flo
 
 wmKeyMap *WM_widgetgroup_keymap_common(wmKeyConfig *config, const char *wgroupname);
 
-struct wmWidgetMapType *WM_widgetmaptype_find(const char *idname, const int spaceid, const int regionid,
-                                              const bool is_3d, const bool create);
+struct wmWidgetMapType *WM_widgetmaptype_find(
+        const char *idname, const int spaceid, const int regionid,
+        const int flag, const bool create);
 bool WM_widgetmap_select_all(struct bContext *C, struct wmWidgetMap *wmap, const int action);
 
 struct wmWidgetGroupType *WM_widgetgrouptype_new(
@@ -579,7 +590,7 @@ struct wmWidgetGroupType *WM_widgetgrouptype_new(
         void (*create)(const struct bContext *, struct wmWidgetGroup *),
         wmKeyMap *(*keymap_init)(wmKeyConfig *, const char *),
         const struct Main *bmain, const char *mapidname, const char *name,
-        const short spaceid, const short regionid, const bool is_3d);
+        const short spaceid, const short regionid, const int flag);
 void WM_widgetgrouptype_unregister(struct bContext *C, struct Main *bmain, struct wmWidgetGroupType *wgroup);
 
 /* creates a widgetmap with all registered widgets for that type */
diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h
index fd975e9..1be2434 100644
--- a/source/blender/windowmanager/WM_types.h
+++ b/source/blender/windowmanager/WM_types.h
@@ -704,7 +704,7 @@ typedef struct wmWidgetGroupType {
 	/* RNA integration */
 	ExtensionRNA ext;
 
-	/* general flag */
+	/* widgetTypeflags (copy of wmWidgetMapType.flag - used for comparisons) */
 	int flag;
 	
 	/* if type is spawned from operator this is set here */
@@ -713,7 +713,6 @@ typedef struct wmWidgetGroupType {
 	/* same as widgetmaps, so registering/unregistering goes to the correct region */
 	short spaceid, regionid;
 	char mapidname[64];
-	bool is_3d;
 } wmWidgetGroupType;
 
 typedef struct wmWidgetMap {
diff --git a/source/blender/windowmanager/intern/wm_widgets.c b/source/blender/windowmanager/intern/wm_widgets.c
index 43b358d..2a17911 100644
--- a/source/blender/windowmanager/intern/wm_widgets.c
+++ b/source/blender/windowmanager/intern/wm_widgets.c
@@ -83,12 +83,8 @@ typedef struct wmWidgetMapType {
 	wmWidgetMapType *next, *prev;
 	char idname[64];
 	short spaceid, regionid;
-	/**
-	 * Check if widgetmap does 3D drawing
-	 * (uses a different kind of interaction),
-	 * - 3d: use glSelect buffer.
-	 * - 2d: use simple cursor position intersection test. */
-	bool is_3d;
+	/* widgetTypeflags */
+	int flag;
 	/* types of widgetgroups for this widgetmap type */
 	ListBase widgetgrouptypes;
 } wmWidgetMapType;
@@ -110,9 +106,9 @@ wmWidgetGroupType *WM_widgetgrouptype_new(
         void (*create)(const bContext *, wmWidgetGroup *),
         wmKeyMap *(*keymap_init)(wmKeyConfig *, const char *),
         const Main *bmain, const char *mapidname, const char *name,
-        const short spaceid, const short regionid, const bool is_3d)
+        const short spaceid, const short regionid, const int flag)
 {
-	wmWidgetMapType *wmaptype = WM_widgetmaptype_find(mapidname, spaceid, regionid, is_3d, false);
+	wmWidgetMapType *wmaptype = WM_widgetmaptype_find(mapidname, spaceid, regionid, flag, false);
 
 	if (!wmaptype) {
 		fprintf(stderr, "widgetgrouptype creation: widgetmap type does not exist");
@@ -126,7 +122,7 @@ wmWidgetGroupType *WM_widgetgrouptype_new(
 	wgrouptype->keymap_init = keymap_init;
 	wgrouptype->spaceid = spaceid;
 	wgrouptype->regionid = regionid;
-	wgrouptype->is_3d = is_3d;
+	wgrouptype->flag = flag;
 	BLI_strncpy(wgrouptype->name, name, MAX_NAME);
 	BLI_strncpy(wgrouptype->mapidname, mapidname, MAX_NAME);
 
@@ -1017,14 +1013,17 @@ void WIDGETGROUP_OT_widget_tweak(wmOperatorType *ot)
 
 
 wmWidgetMapType *WM_widgetmaptype_find(
-        const char *idname, const int spaceid, const int regionid, const bool is_3d, const bool create)
+        const char *idname, const int spaceid, const int regionid, const int flag, const bool create)
 {
 	wmWidgetMapType *wmaptype;
+	/* flags which differentiates widget groups */
+	const int flag_cmp = WM_WIDGET_TYPE_3D;
+	const int flag_test = flag & flag_cmp;
 
 	for (wmaptype = widgetmaptypes.first; wmaptype; wmaptype = wmaptype->next) {
 		if (wmaptype->spaceid == spaceid &&
 		    wmaptype->regionid == regionid &&
-		    wmaptype->is_3d == is_3d &&
+		    ((wmaptype->flag & flag_cmp) == flag_test) &&
 		    STREQ(wmaptype->idname, idname))
 		{
 			return wmaptype;
@@ -1036,7 +1035,7 @@ wmWidgetMapType *WM_widgetmaptype_find(
 	wmaptype = MEM_callocN(sizeof(wmWidgetMapType), "widgettype list");
 	wmaptype->spaceid = spaceid;
 	wmaptype->regionid = regionid;
-	wmaptype->is_3d = is_3d;
+	wmaptype->flag = flag;
 	BLI_strncpy(wmaptype->idname, idname, 64);
 	BLI_addhead(&widgetmaptypes, wmaptype);
 
@@ -1055,7 +1054,7 @@ void WM_widgetmaptypes_free(void)
 
 bool wm_widgetmap_is_3d(const wmWidgetMap *wmap)
 {
-	return wmap->type->is_3d;
+	return (wmap->type->flag & WM_WIDGET_TYPE_3D) != 0;
 }
 
 static void widget_find_active_3D_loop(const bContext *C, ListBase *visible_widgets)
@@ -1561,8 +1560,9 @@ void WM_widgetgrouptype_unregister(bContext *C, Main *bmain, wmWidgetGroupType *
 		}
 	}
 
-	wmWidgetMapType *wmaptype = WM_widgetmaptype_find(wgrouptype->mapidname, wgrouptype->spaceid,
-	                                                  wgrouptype->regionid, wgrouptype->is_3d, false);
+	wmWidgetMapType *wmaptype = WM_widgetmaptype_find(
+	        wgrouptype->mapidname, wgrouptype->spaceid,
+	        wgrouptype->regionid, wgrouptype->flag, false);
 
 	BLI_remlink(&wmaptype->widgetgrouptypes, wgrouptype);
 	wgrouptype->prev = wgrouptype->next = NULL;




More information about the Bf-blender-cvs mailing list