[Bf-blender-cvs] [8f9e8c1] temp_widgets_files_refactor: Move wmWidgetMap(Type) functions into own file
Julian Eisel
noreply at git.blender.org
Mon Feb 8 17:35:34 CET 2016
Commit: 8f9e8c18a70407706b6bb0768130c210b9f93e12
Author: Julian Eisel
Date: Mon Feb 8 17:28:27 2016 +0100
Branches: temp_widgets_files_refactor
https://developer.blender.org/rB8f9e8c18a70407706b6bb0768130c210b9f93e12
Move wmWidgetMap(Type) functions into own file
Think one file for wmWidgetMap and wmWidgetMapType is enough.
===================================================================
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
M source/blender/windowmanager/widgets/wm_widget.c
A source/blender/windowmanager/widgets/wm_widgetmap.c
M source/blender/windowmanager/widgets/wm_widgets.h
M source/blender/windowmanager/widgets/wm_widgets_intern.h
M source/blender/windowmanager/wm.h
===================================================================
diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt
index 8907546..2ed63c0 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_widgetmap.c
widgets/widget_library/arrow_widget.c
widgets/widget_library/cage_widget.c
widgets/widget_library/dial_widget.c
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index b83c42b..10b12e9 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -525,9 +525,6 @@ bool WM_event_is_tablet(const struct wmEvent *event);
* TODO getting a bit crowded here - maybe move into own .h file?
*/
-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);
void WM_event_add_area_widgetmap_handlers(struct ARegion *ar);
void WM_modal_handler_attach_widgetgroup(struct bContext *C, struct wmEventHandler *handler,
struct wmWidgetGroupType *wgrouptype, struct wmOperator *op);
@@ -556,22 +553,6 @@ void WM_widget_set_colors(struct wmWidget *widget, const float col[4], const flo
wmKeyMap *WM_widgetgroup_keymap_common(const struct wmWidgetGroupType *wgrouptype, wmKeyConfig *config);
-bool WM_widgetmap_select_all(struct bContext *C, struct wmWidgetMap *wmap, const int action);
-
-struct wmWidgetMapType_Params {
- const char *idname;
- const int spaceid;
- const int regionid;
- const int flag;
-};
-
-struct wmWidgetMapType *WM_widgetmaptype_find(
- const struct wmWidgetMapType_Params *wmap_params);
-struct wmWidgetMapType *WM_widgetmaptype_ensure(
- const struct wmWidgetMapType_Params *wmap_params);
-struct wmWidgetMap *WM_widgetmap_from_type(
- const struct wmWidgetMapType_Params *wmap_params);
-
struct wmWidgetGroupType *WM_widgetgrouptype_register_ptr(
const struct Main *bmain, struct wmWidgetMapType *wmaptype,
int (*poll)(const struct bContext *, struct wmWidgetGroupType *),
@@ -592,11 +573,6 @@ void WM_widgetgrouptype_init_runtime(
void WM_widgetgrouptype_unregister(struct bContext *C, struct Main *bmain, struct wmWidgetGroupType *wgroup);
-void WM_widgetmap_delete(struct wmWidgetMap *wmap);
-bool WM_widgetmap_cursor_set(const struct wmWidgetMap *wmap, struct wmWindow *win);
-
-void WM_widgetmaptypes_free(void);
-
#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 8e284c3..a524af6 100644
--- a/source/blender/windowmanager/intern/wm_widgets.c
+++ b/source/blender/windowmanager/intern/wm_widgets.c
@@ -74,33 +74,6 @@
#include "RNA_define.h"
#include "BPY_extern.h"
-/**
- * This is a container for all widget types that can be instantiated in a region.
- * (similar to dropboxes).
- *
- * \note There is only ever one of these for every (area, region) combination.
- */
-typedef struct wmWidgetMapType {
- wmWidgetMapType *next, *prev;
- char idname[64];
- short spaceid, regionid;
- /* widgetTypeflags */
- int flag;
- /* types of widgetgroups for this widgetmap type */
- ListBase widgetgrouptypes;
-} wmWidgetMapType;
-
-
-/* store all widgetboxmaps here. Anyone who wants to register a widget for a certain
- * area type can query the widgetbox to do so */
-static ListBase widgetmaptypes = {NULL, NULL};
-
-/**
- * Hash table of all visible widgets to avoid unnecessary loops and wmWidgetGroupType->poll checks.
- * Collected in WM_widgets_update, freed in WM_widgets_draw.
- */
-static GHash *draw_widgets = NULL;
-
/**
* A varsion of #WM_widgetgrouptype_register when theres no need to search for the \a wmaptype.
@@ -188,245 +161,6 @@ void WM_widgetgrouptype_init_runtime(
}
}
-/**
- * Creates and returns idname hash table for (visible) widgets in \a wmap
- *
- * \param poll Polling function for excluding widgets.
- * \param data Custom data passed to \a poll
- */
-static GHash *wm_widgetmap_widget_hash_new(
- const bContext *C, wmWidgetMap *wmap,
- bool (*poll)(const wmWidget *, void *),
- void *data, const bool include_hidden)
-{
- GHash *hash = BLI_ghash_str_new(__func__);
-
- /* collect widgets */
- for (wmWidgetGroup *wgroup = wmap->widgetgroups.first; wgroup; wgroup = wgroup->next) {
- if (!wgroup->type->poll || wgroup->type->poll(C, wgroup->type)) {
- for (wmWidget *widget = wgroup->widgets.first; widget; widget = widget->next) {
- if ((include_hidden || (widget->flag & WM_WIDGET_HIDDEN) == 0) &&
- (!poll || poll(widget, data)))
- {
- BLI_ghash_insert(hash, widget->idname, widget);
- }
- }
- }
- }
-
- return hash;
-}
-
-/**
- * Initialize keymaps for all existing widget-groups
- */
-void wm_widgets_keymap(wmKeyConfig *keyconf)
-{
- wmWidgetMapType *wmaptype;
- wmWidgetGroupType *wgrouptype;
-
- for (wmaptype = widgetmaptypes.first; wmaptype; wmaptype = wmaptype->next) {
- for (wgrouptype = wmaptype->widgetgrouptypes.first; wgrouptype; wgrouptype = wgrouptype->next) {
- wm_widgetgrouptype_keymap_init(wgrouptype, keyconf);
- }
- }
-}
-
-static void widget_highlight_update(wmWidgetMap *wmap, const wmWidget *old_, wmWidget *new_)
-{
- new_->flag |= WM_WIDGET_HIGHLIGHT;
- wmap->wmap_context.highlighted_widget = new_;
- new_->highlighted_part = old_->highlighted_part;
-}
-
-void WM_widgetmap_widgets_update(const bContext *C, wmWidgetMap *wmap)
-{
- wmWidget *widget = wmap->wmap_context.active_widget;
-
- if (!wmap)
- return;
-
- if (!draw_widgets) {
- draw_widgets = BLI_ghash_str_new(__func__);
- }
-
- if (widget) {
- if ((widget->flag & WM_WIDGET_HIDDEN) == 0) {
- wm_widget_calculate_scale(widget, C);
- BLI_ghash_reinsert(draw_widgets, widget->idname, widget, NULL, NULL);
- }
- }
- else if (!BLI_listbase_is_empty(&wmap->widgetgroups)) {
- wmWidget *highlighted_old = NULL;
-
- for (wmWidgetGroup *wgroup = wmap->widgetgroups.first; wgroup; wgroup = wgroup->next) {
- if (!wgroup->type->poll || wgroup->type->poll(C, wgroup->type)) {
- /* first delete and recreate the widgets */
- for (widget = wgroup->widgets.first; widget;) {
- wmWidget *widget_next = widget->next;
-
- /* do not delete selected and highlighted widgets,
- * keep them to compare with new ones */
- if (widget->flag & WM_WIDGET_SELECTED) {
- BLI_remlink(&wgroup->widgets, widget);
- widget->next = widget->prev = NULL;
- }
- else if (widget->flag & WM_WIDGET_HIGHLIGHT) {
- highlighted_old = widget;
- BLI_remlink(&wgroup->widgets, widget);
- widget->next = widget->prev = NULL;
- }
- else {
- wm_widget_delete(&wgroup->widgets, widget);
- }
- widget = widget_next;
- }
-
- if (wgroup->type->create) {
- wgroup->type->create(C, wgroup);
- }
-
- for (widget = wgroup->widgets.first; widget; widget = widget->next) {
- if (widget->flag & WM_WIDGET_HIDDEN)
- continue;
-
- wm_widget_calculate_scale(widget, C);
- /* insert newly created widget into hash table */
- BLI_ghash_reinsert(draw_widgets, widget->idname, widget, NULL, NULL);
- }
-
- /* *** From now on, draw_widgets hash table can be used! *** */
-
- }
- }
-
- if (highlighted_old) {
- wmWidget *highlighted_new = BLI_ghash_lookup(draw_widgets, highlighted_old->idname);
- if (highlighted_new) {
- BLI_assert(wm_widget_compare(highlighted_old, highlighted_new));
- widget_highlight_update(wmap, highlighted_old, highlighted_new);
- }
- else {
- /* if we didn't find a highlighted widget, delete the old one here,
- * happens when switching modes while the cursor is hovering over a widget for eg. */
- wmap->wmap_context.highlighted_widget = NULL;
- }
-
- wm_widget_delete(NULL, highlighted_old);
- highlighted_old = NULL;
- }
-
- if (wmap->wmap_context.selected_widgets) {
- for (int i = 0; i < wmap->wmap_context.tot_selected; i++) {
- wmWidget *sel_old = wmap->wmap_context.selected_widgets[i];
- wmWidget *sel_new = BLI_ghash_lookup(draw_widgets, sel_old->idname);
-
- /* fails if wgtype->poll state changed */
- if (!sel_new)
- continue;
-
- BLI_assert(wm_widget_compare(sel_old, sel_new));
-
- /* widget was selected and highlighted */
- if (sel_old->flag & WM_WIDGET_HIGHLIGHT) {
- widget_highlight_update(wmap, sel_old, sel_new);
- }
- wm_widget_data_free(sel_old);
- /* XXX freeing sel_old leads to crashes, hrmpf */
-
- sel_new->flag |= WM_WIDGET_SELECTED;
- wmap->wmap_context.selected_widgets[i] = sel_new;
- }
- }
- }
-}
-
-/**
- * Draw all visible widgets in \a wmap.
- * Uses global draw_widgets hash table.
- *
- * \param in_scene draw depth-culled widgets (wmWidget->flag WM_WIDGET_SCENE_DEPTH) - TODO
- * \param free_drawwidgets free global draw_widgets hash table (always enable for last draw call in region!).
- */
-void WM_widgetmap_widgets_draw(
- const bContext *C, const wmWidgetMap *wmap,
- const bool in_scene, const bool free_drawwidgets)
-{
- const bool draw_multisample = (U.ogl_multisamples != USER_MULTISAMPLE_NONE);
- const bool use_lighting = (U.tw_flag & V3D_SHADED_WIDGETS) != 0;
-
- if (!wmap)
- return;
-
- /* enable multisampling */
- if (draw_multisample) {
- glEnable(GL_MULTISAMPLE);
- }
-
- if (use_lighting) {
- const float lightpos[4] = {0.0, 0.0, 1.0, 0.0};
- const float diffuse[4] = {1.0, 1.0, 1.0, 0.0};
-
- glPushAttrib(GL_LIGHTING_BIT | GL_ENABLE_BIT);
-
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- glEnable(GL_COLOR_MATERIAL);
- glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
- glPushMatrix();
- glLoadIdentity();
- glLightfv(GL_LIGHT0, GL_POSITION, lightpos);
- glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
- glPopMatrix();
- }
-
-
- wmWidget *widget = wmap->wmap_context.active_widget;
-
- if (widget && in_scene == (widget->flag & WM_WIDGET_SCENE_DEPTH)) {
- if (widget->flag & WM_WID
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list