[Bf-blender-cvs] [f0cf10b] wiggly-widgets: Widgets API.

Antony Riakiotakis noreply at git.blender.org
Fri Sep 19 13:07:26 CEST 2014


Commit: f0cf10b3b95c3f3858ce785c5839dc2b389a413a
Author: Antony Riakiotakis
Date:   Wed Sep 17 16:51:16 2014 +0200
Branches: wiggly-widgets
https://developer.blender.org/rBf0cf10b3b95c3f3858ce785c5839dc2b389a413a

Widgets API.

This commit has first WIP code for widgets API.
Generally widgets should be registered similar to dropboxes, that is,
any code can query for a widgetmap for a certain space and area type
and the window manager will take care of initializing the handlers
automatically.

The owner will be able remove and readd widgets to a certain widgetmap
dynamically. Generally owners should cleanup their widgets though initial code
cleans up leftover widgets automatically.

All this is the theory still, some parts are in that commit, more to come
later, but it's a solid base to build from for an initial commit.

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

M	source/blender/editors/space_view3d/space_view3d.c
M	source/blender/editors/space_view3d/view3d_draw.c
M	source/blender/editors/transform/transform_manipulator.c
M	source/blender/makesdna/DNA_screen_types.h
M	source/blender/makesdna/DNA_view3d_types.h
M	source/blender/makesdna/DNA_windowmanager_types.h
M	source/blender/windowmanager/CMakeLists.txt
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/WM_types.h
M	source/blender/windowmanager/intern/wm_event_system.c
M	source/blender/windowmanager/intern/wm_init_exit.c
A	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/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index 8b76ec3..d3b5ed6 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -343,6 +343,9 @@ static SpaceLink *view3d_new(const bContext *C)
 	
 	v3d->bundle_size = 0.2f;
 	v3d->bundle_drawtype = OB_PLAINAXES;
+
+	/* add the generic manipulator widget here */
+	v3d->manipulator_widget = WM_widget_new(NULL, NULL, NULL, NULL, NULL, NULL, 0, 0);
 	
 	/* header */
 	ar = MEM_callocN(sizeof(ARegion), "header for view3d");
@@ -470,7 +473,7 @@ static void view3d_main_area_init(wmWindowManager *wm, ARegion *ar)
 {
 	ListBase *lb;
 	wmKeyMap *keymap;
-
+	
 	/* object ops. */
 	
 	/* important to be before Pose keymap since they can both be enabled at once */
@@ -548,7 +551,8 @@ static void view3d_main_area_init(wmWindowManager *wm, ARegion *ar)
 	lb = WM_dropboxmap_find("View3D", SPACE_VIEW3D, RGN_TYPE_WINDOW);
 	
 	WM_event_add_dropbox_handler(&ar->handlers, lb);
-	
+
+	WM_widget_handler_register(ar);
 }
 
 static void view3d_main_area_exit(wmWindowManager *wm, ARegion *ar)
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 004b3e1..718e89d 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -2753,6 +2753,7 @@ static void view3d_draw_objects(
 	}
 
 	if (!draw_offscreen) {
+		WM_widgets_draw(C, ar);		
 		BIF_draw_manipulator(C);
 	}
 
diff --git a/source/blender/editors/transform/transform_manipulator.c b/source/blender/editors/transform/transform_manipulator.c
index 2161e52..9cfae51 100644
--- a/source/blender/editors/transform/transform_manipulator.c
+++ b/source/blender/editors/transform/transform_manipulator.c
@@ -1919,5 +1919,4 @@ int BIF_do_manipulator(bContext *C, const struct wmEvent *event, wmOperator *op)
 	drawflags = 0xFFFF;
 
 	return val;
-}
-
+}
\ No newline at end of file
diff --git a/source/blender/makesdna/DNA_screen_types.h b/source/blender/makesdna/DNA_screen_types.h
index 8a900c3..801a9bf 100644
--- a/source/blender/makesdna/DNA_screen_types.h
+++ b/source/blender/makesdna/DNA_screen_types.h
@@ -257,6 +257,7 @@ typedef struct ARegion {
 	ListBase ui_lists;			/* uiList */
 	ListBase ui_previews;		/* uiPreview */
 	ListBase handlers;			/* wmEventHandler */
+	ListBase widgets;			/* widgets for drawing */
 	ListBase panels_category;	/* Panel categories runtime */
 	
 	struct wmTimer *regiontimer; /* blend in/out */
diff --git a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h
index 98c12e9..db3d9ef 100644
--- a/source/blender/makesdna/DNA_view3d_types.h
+++ b/source/blender/makesdna/DNA_view3d_types.h
@@ -146,7 +146,6 @@ typedef struct RegionView3D {
 	/* active rotation from NDOF or elsewhere */
 	float rot_angle;
 	float rot_axis[3];
-
 } RegionView3D;
 
 /* 3D ViewPort Struct */
@@ -220,6 +219,8 @@ typedef struct View3D {
 	/* XXX deprecated? */
 	struct bGPdata *gpd  DNA_DEPRECATED;		/* Grease-Pencil Data (annotation layers) */
 
+	
+	void *manipulator_widget;	
 } View3D;
 
 
diff --git a/source/blender/makesdna/DNA_windowmanager_types.h b/source/blender/makesdna/DNA_windowmanager_types.h
index a17e416..21ff3fb 100644
--- a/source/blender/makesdna/DNA_windowmanager_types.h
+++ b/source/blender/makesdna/DNA_windowmanager_types.h
@@ -156,7 +156,8 @@ typedef struct wmWindowManager {
 	struct wmTimer *autosavetimer;    /* timer for auto save */
 
 	char is_interface_locked;		/* indicates whether interface is locked for user interaction */
-	char par[7];
+	char par[3];
+	int num_ogl_widgets; /* widgets requiring an OpenGL pass to detect */
 } wmWindowManager;
 
 /* wmWindowManager.initialized */
diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt
index 5f99329..b297a9e 100644
--- a/source/blender/windowmanager/CMakeLists.txt
+++ b/source/blender/windowmanager/CMakeLists.txt
@@ -64,6 +64,7 @@ set(SRC
 	intern/wm_operators.c
 	intern/wm_subwindow.c
 	intern/wm_window.c
+        intern/wm_widgets.c
 
 	WM_api.h
 	WM_keymap.h
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index e1cd334..3b0ed36 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -55,6 +55,7 @@ struct wmJob;
 struct wmNotifier;
 struct wmOperatorType;
 struct wmOperator;
+struct wmWidget;
 struct rcti;
 struct PointerRNA;
 struct PropertyRNA;
@@ -458,6 +459,23 @@ void        WM_event_ndof_to_quat(const struct wmNDOFMotionData *ndof, float q[4
 float       WM_event_tablet_data(const struct wmEvent *event, int *pen_flip, float tilt[2]);
 bool        WM_event_is_tablet(const struct wmEvent *event);
 
+
+/* widget API */
+struct wmWidget *WM_widget_new(int (*poll)(const struct bContext *C, void *customdata),
+						void (*draw)(const struct bContext *C, void *customdata),
+						void (*draw_highlighted)(const struct bContext *C, void *customdata),
+						void (*interact)(struct bContext *C, struct wmEvent *event, void *customdata),
+						void (*handler)(struct bContext *C, struct wmEvent *event, void *customdata),
+						void *customdata, bool free_data, bool requires_ogl);
+
+void WM_widgets_delete(struct wmWidget *widget);
+void WM_widgets_draw(const struct bContext *C, struct ARegion *ar);
+void WM_widget_handler_register(struct ARegion *ar);
+
+void WM_widget_register(struct ARegion *ar, struct wmWidget *widget);
+void WM_widget_unregister(struct ARegion *ar, struct wmWidget *widget);
+struct ListBase *WM_widgetmap_find(const char *idname, int spaceid, int regionid);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h
index ff252f0..2e0d510 100644
--- a/source/blender/windowmanager/WM_types.h
+++ b/source/blender/windowmanager/WM_types.h
@@ -505,6 +505,12 @@ typedef struct wmTimer {
 	int sleep;				/* internal, put timers to sleep when needed */
 } wmTimer;
 
+#define WM_WIDGET_HIGHLIGHT    (1 << 0)
+#define WM_WIDGET_FREE_DATA    (1 << 1)
+#define WM_WIDGET_REQUIRES_OGL (1 << 2)
+
+typedef struct wmWidget wmWidget;
+
 typedef struct wmOperatorType {
 	const char *name;		/* text for ui, undo */
 	const char *idname;		/* unique identifier */
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index 2f8ee1c..d536773 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -1970,6 +1970,9 @@ static int wm_handlers_do_intern(bContext *C, wmEvent *event, ListBase *handlers
 					}
 				}
 			}
+			else if (handler->widgets) {
+				
+			}
 			else {
 				/* modal, swallows all */
 				action |= wm_handler_operator_call(C, handlers, handler, event, NULL);
@@ -3415,6 +3418,7 @@ void WM_event_ndof_to_quat(const struct wmNDOFMotionData *ndof, float q[4])
 	angle = WM_event_ndof_to_axis_angle(ndof, axis);
 	axis_angle_to_quat(q, axis, angle);
 }
+/** \} */
 
 /* if this is a tablet event, return tablet pressure and set *pen_flip
  * to 1 if the eraser tool is being used, 0 otherwise */
@@ -3449,6 +3453,3 @@ bool WM_event_is_tablet(const struct wmEvent *event)
 {
 	return (event->tablet_data) ? true : false;
 }
-
-
-/** \} */
diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c
index b1f6935..8edd805 100644
--- a/source/blender/windowmanager/intern/wm_init_exit.c
+++ b/source/blender/windowmanager/intern/wm_init_exit.c
@@ -429,6 +429,7 @@ void WM_exit_ext(bContext *C, const bool do_python)
 	BKE_addon_pref_type_free();
 	wm_operatortype_free();
 	wm_dropbox_free();
+	wm_widgetmap_free();
 	WM_menutype_free();
 	WM_uilisttype_free();
 	
diff --git a/source/blender/windowmanager/intern/wm_widgets.c b/source/blender/windowmanager/intern/wm_widgets.c
new file mode 100644
index 0000000..399702f
--- /dev/null
+++ b/source/blender/windowmanager/intern/wm_widgets.c
@@ -0,0 +1,226 @@
+/*
+ * ***** 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.
+ *
+ * The Original Code is Copyright (C) 2007 Blender Foundation but based 
+ * on ghostwinlay.c (C) 2001-2002 by NaN Holding BV
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation, 2008
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/windowmanager/intern/wm_widgets.c
+ *  \ingroup wm
+ *
+ * Window management, widget API.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "DNA_screen_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_windowmanager_types.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_listbase.h"
+#include "BLI_string.h"
+
+#include "BKE_context.h"
+#include "BKE_idprop.h"
+#include "BKE_global.h"
+#include "BKE_main.h"
+#include "BKE_report.h"
+#include "BKE_scene.h"
+#include "BKE_screen.h"
+
+
+#include "WM_api.h"
+#include "WM_types.h"
+#include "wm.h"
+#include "wm_window.h"
+#include "wm_event_system.h"
+#include "wm_event_types.h"
+#include "wm_draw.h"
+
+#ifndef NDEBUG
+#  include "RNA_enum_types.h"
+#endif
+
+typedef struct wmWidget {
+	struct wmWidget *next, *prev;
+
+	void *customdata;
+	
+	/* poll if widget should be active */
+	int (*poll)(const struct bContext *C, void *customdata);
+	/* draw widget in screen space */
+	void (*draw)(const struct bContext *C, void *customdata);
+	/* draw w

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list