[Bf-blender-cvs] [7dd24427ef6] custom-manipulators: Move manipulator type API into its own file
Campbell Barton
noreply at git.blender.org
Tue Jun 13 16:09:36 CEST 2017
Commit: 7dd24427ef612525a44ebcbf32cf8e210c817f9d
Author: Campbell Barton
Date: Tue Jun 13 17:47:45 2017 +1000
Branches: custom-manipulators
https://developer.blender.org/rB7dd24427ef612525a44ebcbf32cf8e210c817f9d
Move manipulator type API into its own file
===================================================================
M source/blender/windowmanager/CMakeLists.txt
M source/blender/windowmanager/manipulators/WM_manipulator_api.h
M source/blender/windowmanager/manipulators/intern/wm_manipulator.c
A source/blender/windowmanager/manipulators/intern/wm_manipulator_type.c
===================================================================
diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt
index a0efe7502c4..2cd66ac0ea1 100644
--- a/source/blender/windowmanager/CMakeLists.txt
+++ b/source/blender/windowmanager/CMakeLists.txt
@@ -72,6 +72,7 @@ set(SRC
intern/wm_window.c
intern/wm_stereo.c
manipulators/intern/wm_manipulator.c
+ manipulators/intern/wm_manipulator_type.c
manipulators/intern/wm_manipulatorgroup.c
manipulators/intern/wm_manipulatormap.c
diff --git a/source/blender/windowmanager/manipulators/WM_manipulator_api.h b/source/blender/windowmanager/manipulators/WM_manipulator_api.h
index ab7c35407da..03a524f36b1 100644
--- a/source/blender/windowmanager/manipulators/WM_manipulator_api.h
+++ b/source/blender/windowmanager/manipulators/WM_manipulator_api.h
@@ -87,7 +87,7 @@ void WM_manipulator_set_color(struct wmManipulator *mpr, const float col[4]);
void WM_manipulator_get_color_highlight(const struct wmManipulator *mpr, float col_hi[4]);
void WM_manipulator_set_color_highlight(struct wmManipulator *mpr, const float col[4]);
-/* wm_manipulator.c */
+/* wm_manipulator_type.c */
const struct wmManipulatorType *WM_manipulatortype_find(const char *idname, bool quiet);
void WM_manipulatortype_append(void (*wtfunc)(struct wmManipulatorType *));
void WM_manipulatortype_append_ptr(void (*mnpfunc)(struct wmManipulatorType *, void *), void *userdata);
diff --git a/source/blender/windowmanager/manipulators/intern/wm_manipulator.c b/source/blender/windowmanager/manipulators/intern/wm_manipulator.c
index 3dba5ab55e2..97c03545470 100644
--- a/source/blender/windowmanager/manipulators/intern/wm_manipulator.c
+++ b/source/blender/windowmanager/manipulators/intern/wm_manipulator.c
@@ -30,7 +30,6 @@
#include "BKE_context.h"
#include "BLI_listbase.h"
-#include "BLI_ghash.h"
#include "BLI_math.h"
#include "BLI_string.h"
#include "BLI_string_utils.h"
@@ -65,118 +64,6 @@
static void wm_manipulator_register(
wmManipulatorGroup *mgroup, wmManipulator *mpr, const char *name);
-/** \name Manipulator Type Append
- *
- * \note This follows conventions from #WM_operatortype_find #WM_operatortype_append & friends.
- * \{ */
-
-static GHash *global_manipulatortype_hash = NULL;
-
-const wmManipulatorType *WM_manipulatortype_find(const char *idname, bool quiet)
-{
- if (idname[0]) {
- wmManipulatorType *wt;
-
- wt = BLI_ghash_lookup(global_manipulatortype_hash, idname);
- if (wt) {
- return wt;
- }
-
- if (!quiet) {
- printf("search for unknown manipulator '%s'\n", idname);
- }
- }
- else {
- if (!quiet) {
- printf("search for empty manipulator\n");
- }
- }
-
- return NULL;
-}
-
-/* caller must free */
-void WM_manipulatortype_iter(GHashIterator *ghi)
-{
- BLI_ghashIterator_init(ghi, global_manipulatortype_hash);
-}
-
-static wmManipulatorType *wm_manipulatortype_append__begin(void)
-{
- wmManipulatorType *wt = MEM_callocN(sizeof(wmManipulatorType), "manipulatortype");
- return wt;
-}
-static void wm_manipulatortype_append__end(wmManipulatorType *wt)
-{
- BLI_assert(wt->struct_size >= sizeof(wmManipulator));
-
- BLI_ghash_insert(global_manipulatortype_hash, (void *)wt->idname, wt);
-}
-
-void WM_manipulatortype_append(void (*wtfunc)(struct wmManipulatorType *))
-{
- wmManipulatorType *wt = wm_manipulatortype_append__begin();
- wtfunc(wt);
- wm_manipulatortype_append__end(wt);
-}
-
-void WM_manipulatortype_append_ptr(void (*wtfunc)(struct wmManipulatorType *, void *), void *userdata)
-{
- wmManipulatorType *mt = wm_manipulatortype_append__begin();
- wtfunc(mt, userdata);
- wm_manipulatortype_append__end(mt);
-}
-
-/**
- * Free but don't remove from ghash.
- */
-static void manipulatortype_free(wmManipulatorType *wt)
-{
- MEM_freeN(wt);
-}
-
-void WM_manipulatortype_remove_ptr(wmManipulatorType *wt)
-{
- BLI_assert(wt == WM_manipulatortype_find(wt->idname, false));
-
- BLI_ghash_remove(global_manipulatortype_hash, wt->idname, NULL, NULL);
-
- manipulatortype_free(wt);
-}
-
-bool WM_manipulatortype_remove(const char *idname)
-{
- wmManipulatorType *wt = BLI_ghash_lookup(global_manipulatortype_hash, idname);
-
- if (wt == NULL) {
- return false;
- }
-
- WM_manipulatortype_remove_ptr(wt);
-
- return true;
-}
-
-static void wm_manipulatortype_ghash_free_cb(wmManipulatorType *mt)
-{
- manipulatortype_free(mt);
-}
-
-void wm_manipulatortype_free(void)
-{
- BLI_ghash_free(global_manipulatortype_hash, NULL, (GHashValFreeFP)wm_manipulatortype_ghash_free_cb);
- global_manipulatortype_hash = NULL;
-}
-
-/* called on initialize WM_init() */
-void wm_manipulatortype_init(void)
-{
- /* reserve size is set based on blender default setup */
- global_manipulatortype_hash = BLI_ghash_str_new_ex("wm_manipulatortype_init gh", 128);
-}
-
-/** \} */
-
/**
* \note Follow #wm_operator_create convention.
*/
diff --git a/source/blender/windowmanager/manipulators/intern/wm_manipulator_type.c b/source/blender/windowmanager/manipulators/intern/wm_manipulator_type.c
new file mode 100644
index 00000000000..14c3fec324d
--- /dev/null
+++ b/source/blender/windowmanager/manipulators/intern/wm_manipulator_type.c
@@ -0,0 +1,158 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/windowmanager/manipulators/intern/wm_manipulator_type.c
+ * \ingroup wm
+ */
+
+#include "BKE_context.h"
+
+#include "BLI_ghash.h"
+#include "BLI_string.h"
+#include "BLI_string_utils.h"
+
+#include "DNA_manipulator_types.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "RNA_access.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+/* only for own init/exit calls (wm_manipulatortype_init/wm_manipulatortype_free) */
+#include "wm.h"
+
+/* own includes */
+#include "wm_manipulator_wmapi.h"
+#include "wm_manipulator_intern.h"
+
+
+/** \name Manipulator Type Append
+ *
+ * \note This follows conventions from #WM_operatortype_find #WM_operatortype_append & friends.
+ * \{ */
+
+static GHash *global_manipulatortype_hash = NULL;
+
+const wmManipulatorType *WM_manipulatortype_find(const char *idname, bool quiet)
+{
+ if (idname[0]) {
+ wmManipulatorType *wt;
+
+ wt = BLI_ghash_lookup(global_manipulatortype_hash, idname);
+ if (wt) {
+ return wt;
+ }
+
+ if (!quiet) {
+ printf("search for unknown manipulator '%s'\n", idname);
+ }
+ }
+ else {
+ if (!quiet) {
+ printf("search for empty manipulator\n");
+ }
+ }
+
+ return NULL;
+}
+
+/* caller must free */
+void WM_manipulatortype_iter(GHashIterator *ghi)
+{
+ BLI_ghashIterator_init(ghi, global_manipulatortype_hash);
+}
+
+static wmManipulatorType *wm_manipulatortype_append__begin(void)
+{
+ wmManipulatorType *wt = MEM_callocN(sizeof(wmManipulatorType), "manipulatortype");
+ return wt;
+}
+static void wm_manipulatortype_append__end(wmManipulatorType *wt)
+{
+ BLI_assert(wt->struct_size >= sizeof(wmManipulator));
+
+ BLI_ghash_insert(global_manipulatortype_hash, (void *)wt->idname, wt);
+}
+
+void WM_manipulatortype_append(void (*wtfunc)(struct wmManipulatorType *))
+{
+ wmManipulatorType *wt = wm_manipulatortype_append__begin();
+ wtfunc(wt);
+ wm_manipulatortype_append__end(wt);
+}
+
+void WM_manipulatortype_append_ptr(void (*wtfunc)(struct wmManipulatorType *, void *), void *userdata)
+{
+ wmManipulatorType *mt = wm_manipulatortype_append__begin();
+ wtfunc(mt, userdata);
+ wm_manipulatortype_append__end(mt);
+}
+
+/**
+ * Free but don't remove from ghash.
+ */
+static void manipulatortype_free(wmManipulatorType *wt)
+{
+ MEM_freeN(wt);
+}
+
+void WM_manipulatortype_remove_ptr(wmManipulatorType *wt)
+{
+ BLI_assert(wt == WM_manipulatortype_find(wt->idname, false));
+
+ BLI_ghash_remove(global_manipulatortype_hash, wt->idname, NULL, NULL);
+
+ manipulatortype_free(wt);
+}
+
+bool WM_manipulatortype_remove(const char *idname)
+{
+ wmManipulatorType *wt = BLI_ghash_lookup(global_manipulatortype_hash, idname);
+
+ if (wt == NULL) {
+ return false;
+ }
+
+ WM_manipulatortype_remove_ptr(wt);
+
+ return true;
+}
+
+static void wm_manipulatortype_ghash_free_cb(wmManipulatorType *mt)
+{
+ manipulatortype_free(mt);
+}
+
+void wm_manipulatortype_free(void)
+{
+ BLI_ghash_free(global_manipulatortype_hash, NULL, (GHashValFreeFP)wm_manipulatortype_ghash_free_cb);
+ global_manipulatortype_hash = NULL;
+}
+
+/* called on initialize WM_init() */
+void wm_manipulatortype_init(void)
+{
+ /* reserve size is set based on blender default setup */
+ global_manipulatortype_hash = BLI_ghash_str_new_ex("wm_manipulatortype_init gh", 128);
+}
+
+/** \} */
\ No newline at end of file
More information about the Bf-blender-cvs
mailing list