[Bf-blender-cvs] [e806227] temp_widgets_files_refactor: Move wmWidget functions into own file

Julian Eisel noreply at git.blender.org
Mon Feb 8 16:42:30 CET 2016


Commit: e806227373ffd164fa9830d3ac7c8f8a14ddb275
Author: Julian Eisel
Date:   Mon Feb 8 16:34:49 2016 +0100
Branches: temp_widgets_files_refactor
https://developer.blender.org/rBe806227373ffd164fa9830d3ac7c8f8a14ddb275

Move wmWidget functions into own file

Moved widget functions from windowmanager/intern/wm_widgets.c to windowmanager/widgets/wm_widget.c. Added WM_widgets_api.h for external widgets API and wm_widgets.h for window manager API.

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

M	source/blender/windowmanager/CMakeLists.txt
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_widgets.c
A	source/blender/windowmanager/widgets/WM_widgets_api.h
M	source/blender/windowmanager/widgets/widget_library/cage_widget.c
M	source/blender/windowmanager/widgets/widget_library/facemap_widget.c
M	source/blender/windowmanager/widgets/widget_library/plane_widget.c
M	source/blender/windowmanager/widgets/widget_library/widget_library.h
M	source/blender/windowmanager/widgets/wm_widget.c
A	source/blender/windowmanager/widgets/wm_widgets.h
M	source/blender/windowmanager/widgets/wm_widgets_intern.h
M	source/blender/windowmanager/wm.h
M	source/blender/windowmanager/wm_event_system.h

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

diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt
index c4c04c6..8907546 100644
--- a/source/blender/windowmanager/CMakeLists.txt
+++ b/source/blender/windowmanager/CMakeLists.txt
@@ -89,6 +89,8 @@ set(SRC
 	wm_files.h
 	wm_subwindow.h
 	wm_window.h
+	widgets/WM_widgets_api.h
+	widgets/wm_widgets.h
 	widgets/wm_widgets_intern.h
 	widgets/widget_library/widget_geometry.h
 	widgets/widget_library/widget_library.h
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 4f9312d..b83c42b 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -41,9 +41,10 @@
 #include "DNA_windowmanager_types.h"
 #include "DNA_listBase.h"
 #include "WM_keymap.h"
-#include "widgets/widget_library/widget_library.h"
 #include "BLI_compiler_attrs.h"
 
+#include "widgets/WM_widgets_api.h" /* widgets API */
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -524,11 +525,6 @@ bool        WM_event_is_tablet(const struct wmEvent *event);
  * TODO getting a bit crowded here - maybe move into own .h file?
  */
 
-struct wmWidget *WM_widget_new(void (*draw)(const struct bContext *, struct wmWidget *),
-                               void (*render_3d_intersection)(const struct bContext *, struct wmWidget *, int),
-                               int  (*intersect)(struct bContext *, const struct wmEvent *, struct wmWidget *),
-                               int  (*handler)(struct bContext *, const struct wmEvent *, struct wmWidget *, const int));
-
 void  WM_widgetmap_widgets_update(const struct bContext *C, struct wmWidgetMap *wmap);
 void  WM_widgetmap_widgets_draw(const struct bContext *C, const struct wmWidgetMap *wmap,
                       const bool in_scene, const bool free_drawwidgets);
diff --git a/source/blender/windowmanager/intern/wm_widgets.c b/source/blender/windowmanager/intern/wm_widgets.c
index e74b0d1..8e284c3 100644
--- a/source/blender/windowmanager/intern/wm_widgets.c
+++ b/source/blender/windowmanager/intern/wm_widgets.c
@@ -65,6 +65,7 @@
 #include "wm_event_system.h"
 #include "wm_event_types.h"
 #include "wm_draw.h"
+#include "../widgets/wm_widgets_intern.h" /* XXX tmp */
 
 #include "GL/glew.h"
 #include "GPU_select.h"
@@ -216,75 +217,6 @@ static GHash *wm_widgetmap_widget_hash_new(
 	return hash;
 }
 
-/* Still unused */
-wmWidget *WM_widget_new(void (*draw)(const bContext *C, wmWidget *customdata),
-                        void (*render_3d_intersection)(const bContext *C, wmWidget *customdata, int selectionbase),
-                        int  (*intersect)(bContext *C, const wmEvent *event, wmWidget *widget),
-                        int  (*handler)(bContext *C, const wmEvent *event, wmWidget *widget, const int flag))
-{
-	wmWidget *widget = MEM_callocN(sizeof(wmWidget), "widget");
-
-	widget->draw = draw;
-	widget->handler = handler;
-	widget->intersect = intersect;
-	widget->render_3d_intersection = render_3d_intersection;
-
-	/* XXX */
-	fix_linking_widget_arrow();
-	fix_linking_widget_cage();
-	fix_linking_widget_dial();
-	fix_linking_widget_facemap();
-	fix_linking_widget_plane();
-
-	return widget;
-}
-
-/**
- * Free widget data, not widget itself.
- */
-static void wm_widget_data_free(wmWidget *widget)
-{
-	if (widget->opptr.data) {
-		WM_operator_properties_free(&widget->opptr);
-	}
-
-	MEM_freeN(widget->props);
-	MEM_freeN(widget->ptr);
-}
-
-/**
- * Free and NULL \a widget.
- * \a widgetlist is allowed to be NULL.
- */
-static void wm_widget_delete(ListBase *widgetlist, wmWidget *widget)
-{
-	wm_widget_data_free(widget);
-	if (widgetlist)
-		BLI_remlink(widgetlist, widget);
-	MEM_freeN(widget);
-}
-
-
-static void widget_calculate_scale(wmWidget *widget, const bContext *C)
-{
-	const RegionView3D *rv3d = CTX_wm_region_view3d(C);
-	float scale = 1.0f;
-
-	if (rv3d && (U.tw_flag & V3D_3D_WIDGETS) == 0 && (widget->flag & WM_WIDGET_SCALE_3D)) {
-		if (widget->get_final_position) {
-			float position[3];
-
-			widget->get_final_position(widget, position);
-			scale = ED_view3d_pixel_size(rv3d, position) * (float)U.tw_size;
-		}
-		else {
-			scale = ED_view3d_pixel_size(rv3d, widget->origin) * (float)U.tw_size;
-		}
-	}
-
-	widget->scale = scale * widget->user_scale;
-}
-
 /**
  * Initialize keymaps for all existing widget-groups
  */
@@ -300,11 +232,6 @@ void wm_widgets_keymap(wmKeyConfig *keyconf)
 	}
 }
 
-BLI_INLINE bool widget_compare(const wmWidget *a, const wmWidget *b)
-{
-	return STREQ(a->idname, b->idname);
-}
-
 static void widget_highlight_update(wmWidgetMap *wmap, const wmWidget *old_, wmWidget *new_)
 {
 	new_->flag |= WM_WIDGET_HIGHLIGHT;
@@ -325,7 +252,7 @@ void WM_widgetmap_widgets_update(const bContext *C, wmWidgetMap *wmap)
 
 	if (widget) {
 		if ((widget->flag & WM_WIDGET_HIDDEN) == 0) {
-			widget_calculate_scale(widget, C);
+			wm_widget_calculate_scale(widget, C);
 			BLI_ghash_reinsert(draw_widgets, widget->idname, widget, NULL, NULL);
 		}
 	}
@@ -363,7 +290,7 @@ void WM_widgetmap_widgets_update(const bContext *C, wmWidgetMap *wmap)
 					if (widget->flag & WM_WIDGET_HIDDEN)
 						continue;
 
-					widget_calculate_scale(widget, C);
+					wm_widget_calculate_scale(widget, C);
 					/* insert newly created widget into hash table */
 					BLI_ghash_reinsert(draw_widgets, widget->idname, widget, NULL, NULL);
 				}
@@ -376,7 +303,7 @@ void WM_widgetmap_widgets_update(const bContext *C, wmWidgetMap *wmap)
 		if (highlighted_old) {
 			wmWidget *highlighted_new = BLI_ghash_lookup(draw_widgets, highlighted_old->idname);
 			if (highlighted_new) {
-				BLI_assert(widget_compare(highlighted_old, highlighted_new));
+				BLI_assert(wm_widget_compare(highlighted_old, highlighted_new));
 				widget_highlight_update(wmap, highlighted_old, highlighted_new);
 			}
 			else {
@@ -398,7 +325,7 @@ void WM_widgetmap_widgets_update(const bContext *C, wmWidgetMap *wmap)
 				if (!sel_new)
 					continue;
 
-				BLI_assert(widget_compare(sel_old, sel_new));
+				BLI_assert(wm_widget_compare(sel_old, sel_new));
 
 				/* widget was selected and highlighted */
 				if (sel_old->flag & WM_WIDGET_HIGHLIGHT) {
@@ -534,155 +461,6 @@ void WM_modal_handler_attach_widgetgroup(
 	WM_event_add_mousemove(C);
 }
 
-/**
- * Assign an idname that is unique in \a wgroup to \a widget.
- *
- * \param rawname  Name used as basis to define final unique idname.
- */
-static void widget_unique_idname_set(wmWidgetGroup *wgroup, wmWidget *widget, const char *rawname)
-{
-	if (wgroup->type->idname[0]) {
-		BLI_snprintf(widget->idname, sizeof(widget->idname), "%s_%s", wgroup->type->idname, rawname);
-	}
-	else {
-		BLI_strncpy(widget->idname, rawname, sizeof(widget->idname));
-	}
-
-	/* ensure name is unique, append '.001', '.002', etc if not */
-	BLI_uniquename(&wgroup->widgets, widget, "Widget", '.', offsetof(wmWidget, idname), sizeof(widget->idname));
-}
-
-/**
- * Register \a widget.
- *
- * \param name  name used to create a unique idname for \a widget in \a wgroup
- */
-bool wm_widget_register(wmWidgetGroup *wgroup, wmWidget *widget, const char *name)
-{
-	const float col_default[4] = {1.0f, 1.0f, 1.0f, 1.0f};
-
-	widget_unique_idname_set(wgroup, widget, name);
-
-	widget->user_scale = 1.0f;
-	widget->line_width = 1.0f;
-
-	/* defaults */
-	copy_v4_v4(widget->col, col_default);
-	copy_v4_v4(widget->col_hi, col_default);
-
-	/* create at least one property for interaction */
-	if (widget->max_prop == 0) {
-		widget->max_prop = 1;
-	}
-
-	widget->props = MEM_callocN(sizeof(PropertyRNA *) * widget->max_prop, "widget->props");
-	widget->ptr = MEM_callocN(sizeof(PointerRNA) * widget->max_prop, "widget->ptr");
-
-	widget->wgroup = wgroup;
-
-	BLI_addtail(&wgroup->widgets, widget);
-	return true;
-}
-
-
-/** \name Widget Creation API
- *
- * API for defining data on widget creation.
- *
- * \{ */
-
-void WM_widget_set_property(wmWidget *widget, const int slot, PointerRNA *ptr, const char *propname)
-{
-	if (slot < 0 || slot >= widget->max_prop) {
-		fprintf(stderr, "invalid index %d when binding property for widget type %s\n", slot, widget->idname);
-		return;
-	}
-
-	/* if widget evokes an operator we cannot use it for property manipulation */
-	widget->opname = NULL;
-	widget->ptr[slot] = *ptr;
-	widget->props[slot] = RNA_struct_find_property(ptr, propname);
-
-	if (widget->bind_to_prop)
-		widget->bind_to_prop(widget, slot);
-}
-
-PointerRNA *WM_widget_set_operator(wmWidget *widget, const char *opname)
-{
-	wmOperatorType *ot = WM_operatortype_find(opname, 0);
-
-	if (ot) {
-		widget->opname = opname;
-
-		if (widget->opptr.data) {
-			WM_operator_properties_free(&widget->opptr);
-		}
-		WM_operator_properties_create_ptr(&widget->opptr, ot);
-
-		return &widget->opptr;
-	}
-	else {
-		fprintf(stderr, "Error binding operator to widget: operator %s not found!\n", opname);
-	}
-
-	return NULL;
-}
-
-/**
- * \brief Set widget select callback.
- *
- * Callback is called when widget gets selected/deselected.
- */
-void WM_widget_set_func_select(wmWidget *widget, void (*select)(bContext *, wmWidget *, const int action))
-{
-	widget->flag |= WM_WIDGET_SELECTABLE;
-	widget->select = select;
-}
-
-void WM_widget_set_origin(wmWidget *widget, const float origin[3])
-{
-	copy_v3_v3(widget->origin, origin);
-}
-
-void WM_widget_set_offset(wmWidget *widget, const float offset[3])
-{
-	copy_v3_v3(widget->offset, offset);
-}
-
-void WM_widget_set_flag(wmWidget *widget, const int flag, const bool enable)
-{
-	if (enable) {
-		widget->flag |= flag;
-	}
-	else {
-		widget->flag &= ~flag;
-	}
-}
-
-void WM_widget_set_scale(wmWidget *widget, const float scale)
-{
-	widget->user_scale = scale;
-}
-
-void WM_widget_set_line_width(wmWidget *widget, const float line_width)
-{
-	widget->line_width = line_width;
-}
-
-/**
- * Set widget rgba colors.
- *
- * \param col  Normal state color.
- * \param col_hi  Highlighted state color.
- */
-void WM_widget_set_colors(wmWidget *widget, const float col[4], const float col_hi[4])
-{
-	copy_v4_v4(widget->col, col);
-	copy_v4_v4(widget->col_hi, col_hi);
-}
-
-/** \} */ // Widget Creation API
-
 
 /** \name Widget operators
  *
@@ -782,69 +560,6 @@ bool WM_widgetmap_select_all(bContext *C, wmWidgetMap *wmap, const int action

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list