[Bf-blender-cvs] [6411d72] temp_widgets_files_refactor: Move wmWidgetGroup(Type) functions into own file

Julian Eisel noreply at git.blender.org
Mon Feb 8 18:04:31 CET 2016


Commit: 6411d72441f2fc7052bc15fcaed1b635e4f68f78
Author: Julian Eisel
Date:   Mon Feb 8 17:58:57 2016 +0100
Branches: temp_widgets_files_refactor
https://developer.blender.org/rB6411d72441f2fc7052bc15fcaed1b635e4f68f78

Move wmWidgetGroup(Type) functions into own file

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

M	source/blender/windowmanager/CMakeLists.txt
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_widgets.c
M	source/blender/windowmanager/widgets/WM_widgets_api.h
A	source/blender/windowmanager/widgets/wm_widgetgroup.c
M	source/blender/windowmanager/widgets/wm_widgetmap.c
M	source/blender/windowmanager/widgets/wm_widgets.h
M	source/blender/windowmanager/widgets/wm_widgets_intern.h

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

diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt
index 2ed63c0..7167eba 100644
--- a/source/blender/windowmanager/CMakeLists.txt
+++ b/source/blender/windowmanager/CMakeLists.txt
@@ -69,6 +69,7 @@ set(SRC
 	intern/wm_stereo.c
 	intern/wm_widgets.c
 	widgets/wm_widget.c
+	widgets/wm_widgetgroup.c
 	widgets/wm_widgetmap.c
 	widgets/widget_library/arrow_widget.c
 	widgets/widget_library/cage_widget.c
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 10b12e9..5f4f31f 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -551,28 +551,6 @@ void WM_widget_set_scale(struct wmWidget *widget, float scale);
 void WM_widget_set_line_width(struct wmWidget *widget, const float line_width);
 void WM_widget_set_colors(struct wmWidget *widget, const float col[4], const float col_hi[4]);
 
-wmKeyMap *WM_widgetgroup_keymap_common(const struct wmWidgetGroupType *wgrouptype, wmKeyConfig *config);
-
-struct wmWidgetGroupType *WM_widgetgrouptype_register_ptr(
-        const struct Main *bmain, struct wmWidgetMapType *wmaptype,
-        int (*poll)(const struct bContext *, struct wmWidgetGroupType *),
-        void (*create)(const struct bContext *, struct wmWidgetGroup *),
-        wmKeyMap *(*keymap_init)(const struct wmWidgetGroupType *wgrouptype, struct wmKeyConfig *config),
-        const char *name);
-
-struct wmWidgetGroupType *WM_widgetgrouptype_register(
-        const struct Main *bmain, const struct wmWidgetMapType_Params *wmap_params,
-        int (*poll)(const struct bContext *, struct wmWidgetGroupType *),
-        void (*create)(const struct bContext *, struct wmWidgetGroup *),
-        wmKeyMap *(*keymap_init)(const struct wmWidgetGroupType *wgrouptype, struct wmKeyConfig *config),
-        const char *name);
-
-void WM_widgetgrouptype_init_runtime(
-        const struct Main *bmain, struct wmWidgetMapType *wmaptype,
-        struct wmWidgetGroupType *wgrouptype);
-
-void WM_widgetgrouptype_unregister(struct bContext *C, struct Main *bmain, struct wmWidgetGroupType *wgroup);
-
 
 #ifdef WITH_INPUT_IME
 bool        WM_event_is_ime_switch(const struct wmEvent *event);
diff --git a/source/blender/windowmanager/intern/wm_widgets.c b/source/blender/windowmanager/intern/wm_widgets.c
index a524af6..73b449e 100644
--- a/source/blender/windowmanager/intern/wm_widgets.c
+++ b/source/blender/windowmanager/intern/wm_widgets.c
@@ -75,92 +75,6 @@
 #include "BPY_extern.h"
 
 
-/**
- * A varsion of #WM_widgetgrouptype_register when theres no need to search for the \a wmaptype.
- */
-wmWidgetGroupType *WM_widgetgrouptype_register_ptr(
-        const Main *bmain, wmWidgetMapType *wmaptype,
-        int (*poll)(const bContext *C, wmWidgetGroupType *),
-        void (*create)(const bContext *, wmWidgetGroup *),
-        wmKeyMap *(*keymap_init)(const wmWidgetGroupType *wgrouptype, wmKeyConfig *config),
-        const char *name)
-{
-
-	wmWidgetGroupType *wgrouptype = MEM_callocN(sizeof(wmWidgetGroupType), "widgetgroup");
-
-	wgrouptype->poll = poll;
-	wgrouptype->create = create;
-	wgrouptype->keymap_init = keymap_init;
-	wgrouptype->spaceid = wmaptype->spaceid;
-	wgrouptype->regionid = wmaptype->regionid;
-	wgrouptype->flag = wmaptype->flag;
-	BLI_strncpy(wgrouptype->name, name, MAX_NAME);
-	BLI_strncpy(wgrouptype->mapidname, wmaptype->idname, MAX_NAME);
-
-	/* add the type for future created areas of the same type  */
-	BLI_addtail(&wmaptype->widgetgrouptypes, wgrouptype);
-
-	/* Main is missing on startup when we create new areas.
-	 * So this is only called for widgets initialized on runtime */
-	if (bmain) {
-		WM_widgetgrouptype_init_runtime(bmain, wmaptype, wgrouptype);
-	}
-
-	return wgrouptype;
-}
-
-wmWidgetGroupType *WM_widgetgrouptype_register(
-        const Main *bmain, const struct wmWidgetMapType_Params *wmap_params,
-        int (*poll)(const bContext *C, wmWidgetGroupType *),
-        void (*create)(const bContext *, wmWidgetGroup *),
-        wmKeyMap *(*keymap_init)(const wmWidgetGroupType *wgrouptype, wmKeyConfig *config),
-        const char *name)
-{
-	wmWidgetMapType *wmaptype = WM_widgetmaptype_find(wmap_params);
-
-	if (!wmaptype) {
-		fprintf(stderr, "widgetgrouptype creation: widgetmap type does not exist");
-		return NULL;
-	}
-
-	return WM_widgetgrouptype_register_ptr(
-	        bmain, wmaptype,
-	        poll, create, keymap_init,
-	        name);
-}
-
-void WM_widgetgrouptype_init_runtime(
-        const Main *bmain, wmWidgetMapType *wmaptype,
-        wmWidgetGroupType *wgrouptype)
-{
-
-	/* init keymap - on startup there's an extra call to init keymaps for 'permanent' widget-groups */
-	wm_widgetgrouptype_keymap_init(wgrouptype, ((wmWindowManager *)bmain->wm.first)->defaultconf);
-
-	/* now create a widget for all existing areas */
-	for (bScreen *sc = bmain->screen.first; sc; sc = sc->id.next) {
-		for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) {
-			for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
-				ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
-				for (ARegion *ar = lb->first; ar; ar = ar->next) {
-					for (wmWidgetMap *wmap = ar->widgetmaps.first; wmap; wmap = wmap->next) {
-						if (wmap->type == wmaptype) {
-							wmWidgetGroup *wgroup = MEM_callocN(sizeof(wmWidgetGroup), "widgetgroup");
-
-							wgroup->type = wgrouptype;
-
-							/* just add here, drawing will occur on next update */
-							BLI_addtail(&wmap->widgetgroups, wgroup);
-							wm_widgetmap_set_highlighted_widget(wmap, NULL, NULL, 0);
-							ED_region_tag_redraw(ar);
-						}
-					}
-				}
-			}
-		}
-	}
-}
-
 void WM_event_add_area_widgetmap_handlers(ARegion *ar)
 {
 	for (wmWidgetMap *wmap = ar->widgetmaps.first; wmap; wmap = wmap->next) {
@@ -272,13 +186,6 @@ typedef struct WidgetTweakData {
 	int flag;       /* tweak flags */
 } WidgetTweakData;
 
-enum {
-	TWEAK_MODAL_CANCEL = 1,
-	TWEAK_MODAL_CONFIRM,
-	TWEAK_MODAL_PRECISION_ON,
-	TWEAK_MODAL_PRECISION_OFF,
-};
-
 static void widget_tweak_finish(bContext *C, wmOperator *op, const bool cancel)
 {
 	WidgetTweakData *wtweak = op->customdata;
@@ -427,139 +334,3 @@ void wm_widget_handler_modal_update(bContext *C, wmEvent *event, wmEventHandler
 	}
 }
 
-static void wm_widgetgroup_free(bContext *C, wmWidgetMap *wmap, wmWidgetGroup *wgroup)
-{
-	for (wmWidget *widget = wgroup->widgets.first; widget;) {
-		wmWidget *widget_next = widget->next;
-		if (widget->flag & WM_WIDGET_HIGHLIGHT) {
-			wm_widgetmap_set_highlighted_widget(wmap, C, NULL, 0);
-		}
-		if (widget->flag & WM_WIDGET_ACTIVE) {
-			wm_widgetmap_set_active_widget(wmap, C, NULL, NULL);
-		}
-		wm_widget_delete(&wgroup->widgets, widget);
-		widget = widget_next;
-	}
-
-#ifdef WITH_PYTHON
-	if (wgroup->py_instance) {
-		/* do this first in case there are any __del__ functions or
-		 * similar that use properties */
-		BPY_DECREF_RNA_INVALIDATE(wgroup->py_instance);
-	}
-#endif
-
-	if (wgroup->reports && (wgroup->reports->flag & RPT_FREE)) {
-		BKE_reports_clear(wgroup->reports);
-		MEM_freeN(wgroup->reports);
-	}
-
-	BLI_remlink(&wmap->widgetgroups, wgroup);
-	MEM_freeN(wgroup);
-}
-
-static wmKeyMap *widgetgroup_tweak_modal_keymap(wmKeyConfig *keyconf, const char *wgroupname)
-{
-	wmKeyMap *keymap;
-	char name[MAX_NAME];
-
-	static EnumPropertyItem modal_items[] = {
-		{TWEAK_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
-		{TWEAK_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
-		{TWEAK_MODAL_PRECISION_ON, "PRECISION_ON", 0, "Enable Precision", ""},
-		{TWEAK_MODAL_PRECISION_OFF, "PRECISION_OFF", 0, "Disable Precision", ""},
-		{0, NULL, 0, NULL, NULL}
-	};
-
-
-	BLI_snprintf(name, sizeof(name), "%s Tweak Modal Map", wgroupname);
-	keymap = WM_modalkeymap_get(keyconf, name);
-
-	/* this function is called for each spacetype, only needs to add map once */
-	if (keymap && keymap->modal_items)
-		return NULL;
-
-	keymap = WM_modalkeymap_add(keyconf, name, modal_items);
-
-
-	/* items for modal map */
-	WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_CANCEL);
-	WM_modalkeymap_add_item(keymap, RIGHTMOUSE, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_CANCEL);
-
-	WM_modalkeymap_add_item(keymap, RETKEY, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_CONFIRM);
-	WM_modalkeymap_add_item(keymap, PADENTER, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_CONFIRM);
-
-	WM_modalkeymap_add_item(keymap, RIGHTSHIFTKEY, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_PRECISION_ON);
-	WM_modalkeymap_add_item(keymap, RIGHTSHIFTKEY, KM_RELEASE, KM_ANY, 0, TWEAK_MODAL_PRECISION_OFF);
-	WM_modalkeymap_add_item(keymap, LEFTSHIFTKEY, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_PRECISION_ON);
-	WM_modalkeymap_add_item(keymap, LEFTSHIFTKEY, KM_RELEASE, KM_ANY, 0, TWEAK_MODAL_PRECISION_OFF);
-
-
-	WM_modalkeymap_assign(keymap, "WIDGETGROUP_OT_widget_tweak");
-
-	return keymap;
-}
-
-/**
- * Common default keymap for widget groups
- */
-wmKeyMap *WM_widgetgroup_keymap_common(const struct wmWidgetGroupType *wgrouptype, wmKeyConfig *config)
-{
-	const char *wgroupname = wgrouptype->name;
-	wmKeyMap *km = WM_keymap_find(config, wgroupname, 0, 0);
-	wmKeyMapItem *kmi;
-
-	WM_keymap_add_item(km, "WIDGETGROUP_OT_widget_tweak", ACTIONMOUSE, KM_PRESS, KM_ANY, 0);
-
-	widgetgroup_tweak_modal_keymap(config, wgroupname);
-
-	kmi = WM_keymap_add_item(km, "WIDGETGROUP_OT_widget_select", SELECTMOUSE, KM_PRESS, 0, 0);
-	RNA_boolean_set(kmi->ptr, "extend", false);
-	RNA_boolean_set(kmi->ptr, "deselect", false);
-	RNA_boolean_set(kmi->ptr, "toggle", false);
-	kmi = WM_keymap_add_item(km, "WIDGETGROUP_OT_widget_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
-	RNA_boolean_set(kmi->ptr, "extend", false);
-	RNA_boolean_set(kmi->ptr, "deselect", false);
-	RNA_boolean_set(kmi->ptr, "toggle", true);
-
-	return km;
-}
-
-void wm_widgetgrouptype_keymap_init(wmWidgetGroupType *wgrouptype, wmKeyConfig *keyconf)
-{
-	wgrouptype->keymap = wgrouptype->keymap_init(wgrouptype, keyconf);
-}
-
-void WM_widgetgrouptype_unregister(bContext *C, Main *bmain, wmWidgetGroupType *wgrouptype)
-{
-	for (bScreen *sc = bmain->screen.first; sc; sc = sc->id.next) {
-		for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) {
-			for (SpaceLink *sl = sa->spacedata.first;

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list