diff options
author | Julian Eisel <eiseljulian@gmail.com> | 2015-09-25 23:09:41 +0300 |
---|---|---|
committer | Julian Eisel <eiseljulian@gmail.com> | 2015-09-25 23:09:41 +0300 |
commit | 77d809cd6b6f306c7c355ee3cf27aa20d4816b9b (patch) | |
tree | 8b92fb8762e3997a75ddab25dbd597d3eaa83047 /source | |
parent | 3b29e53626f9044ce6e5b75ca1c91bf467c493d1 (diff) |
Bunch of minor cleanup
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/windowmanager/WM_api.h | 16 | ||||
-rw-r--r-- | source/blender/windowmanager/WM_types.h | 6 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_generic_widgets.c | 106 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_widgets.c | 151 | ||||
-rw-r--r-- | source/blender/windowmanager/wm.h | 20 | ||||
-rw-r--r-- | source/blender/windowmanager/wm_event_system.h | 16 |
6 files changed, 161 insertions, 154 deletions
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 1e5e09bb9e4..60aea031209 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -504,12 +504,12 @@ struct wmWidget *WM_widget_new(void (*draw)(const struct bContext *, struct wmWi int (*intersect)(struct bContext *, const struct wmEvent *, struct wmWidget *), int (*handler)(struct bContext *, const struct wmEvent *, struct wmWidget *)); -void WM_widgets_update(const struct bContext *C, struct wmWidgetMap *wmap); -void WM_widgets_draw(const struct bContext *C, const struct wmWidgetMap *wmap, const bool in_scene); -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); -void WM_widgetgroup_customdata_set(struct wmWidgetGroup *wgroup, void *data); +void WM_widgets_update(const struct bContext *C, struct wmWidgetMap *wmap); +void WM_widgets_draw(const struct bContext *C, const struct wmWidgetMap *wmap, const bool in_scene); +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); +void WM_widgetgroup_customdata_set(struct wmWidgetGroup *wgroup, void *data); void *WM_widgetgroup_customdata(const struct wmWidgetGroup *wgroup); /* wmWidget->flag */ @@ -536,14 +536,14 @@ 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(wmKeyConfig *config, struct wmWidgetGroupType *wgroup); +wmKeyMap *WM_widgetgroup_keymap_common(wmKeyConfig *config, const char *wgroupname); struct wmWidgetMapType *WM_widgetmaptype_find(const char *idname, const int spaceid, const int regionid, const bool is_3d, const bool create); struct wmWidgetGroupType *WM_widgetgrouptype_new( int (*poll)(const struct bContext *, struct wmWidgetGroupType *), void (*create)(const struct bContext *, struct wmWidgetGroup *), - wmKeyMap *(*keymap_init)(wmKeyConfig *, struct wmWidgetGroupType *), + wmKeyMap *(*keymap_init)(wmKeyConfig *, const char *), const struct Main *bmain, const char *mapidname, const char *name, const short spaceid, const short regionid, const bool is_3d); void WM_widgetgrouptype_unregister(struct bContext *C, struct Main *bmain, struct wmWidgetGroupType *wgroup); diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index a68e125cb4e..3e43047c96c 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -674,12 +674,10 @@ typedef struct wmDropBox { /* WidgetGroups store and manage groups of widgets. - * They are responsible for drawing necessary widgets and updating their state and position. - * Also they */ + * They are responsible for drawing necessary widgets and updating their state and position. */ typedef struct wmWidget wmWidget; typedef struct wmWidgetGroup wmWidgetGroup; typedef struct wmWidgetMapType wmWidgetMapType; -typedef struct wmWidgetGroupType wmWidgetGroupType; /* factory class for a widgetgroup type, gets called every time a new area is spawned */ typedef struct wmWidgetGroupType { @@ -695,7 +693,7 @@ typedef struct wmWidgetGroupType { void (*create)(const struct bContext *C, struct wmWidgetGroup *wgroup); /* keymap init callback for this widgetgroup */ - struct wmKeyMap *(*keymap_init)(struct wmKeyConfig *, struct wmWidgetGroupType *); + struct wmKeyMap *(*keymap_init)(struct wmKeyConfig *, const char *); /* keymap created with callback from above */ struct wmKeyMap *keymap; diff --git a/source/blender/windowmanager/intern/wm_generic_widgets.c b/source/blender/windowmanager/intern/wm_generic_widgets.c index 65d626348be..7e26c086ba0 100644 --- a/source/blender/windowmanager/intern/wm_generic_widgets.c +++ b/source/blender/windowmanager/intern/wm_generic_widgets.c @@ -277,7 +277,7 @@ static void arrow_draw_geom(const ArrowWidget *arrow, const bool select) GLUquadricObj *qobj = gluNewQuadric(); const float len = 0.25f; const float width = 0.06f; - const bool use_lighting = !select && ((U.tw_flag & V3D_SHADED_WIDGETS) != 0); + const bool use_lighting = select == false && ((U.tw_flag & V3D_SHADED_WIDGETS) != 0); /* translate to line end */ glTranslatef(0.0f, 0.0f, arrow->len); @@ -298,7 +298,6 @@ static void arrow_draw_geom(const ArrowWidget *arrow, const bool select) } glPopMatrix(); - (void)select; #endif } @@ -337,7 +336,7 @@ static void arrow_draw_intern(ArrowWidget *arrow, const bool select, const bool } glEnable(GL_BLEND); - glTranslatef(UNPACK3(arrow->widget.offset)); + glTranslate3fv(arrow->widget.offset); arrow_draw_geom(arrow, select); glDisable(GL_BLEND); @@ -355,7 +354,7 @@ static void arrow_draw_intern(ArrowWidget *arrow, const bool select, const bool glEnable(GL_BLEND); glColor4f(0.5f, 0.5f, 0.5f, 0.5f); - glTranslatef(UNPACK3(arrow->widget.offset)); + glTranslate3fv(arrow->widget.offset); arrow_draw_geom(arrow, select); glDisable(GL_BLEND); @@ -396,6 +395,7 @@ static int widget_arrow_handler(bContext *C, const wmEvent *event, wmWidget *wid float facdir = 1.0f; bool use_vertical = false; + copy_v3_v3(orig_origin, data->orig_origin); orig_origin[3] = 1.0f; add_v3_v3v3(offset, orig_origin, arrow->direction); @@ -766,7 +766,7 @@ static void dial_draw_geom(const DialWidget *dial, const bool select) gluDisk(qobj, 0.0, width, resol, 1); glLineWidth(1.0); - (void)select; + UNUSED_VARS(select); #endif glDisable(GL_MULTISAMPLE_ARB); @@ -791,7 +791,7 @@ static void dial_draw_intern(DialWidget *dial, const bool select, const bool hig else glColor4fv(dial->widget.col); - glTranslatef(UNPACK3(dial->widget.offset)); + glTranslate3fv(dial->widget.offset); dial_draw_geom(dial, select); glPopMatrix(); @@ -972,7 +972,7 @@ static void widget_plane_draw_intern(PlaneWidget *plane, const bool UNUSED(selec col_inner[3] *= 0.5f; glEnable(GL_BLEND); - glTranslatef(UNPACK3(plane->widget.offset)); + glTranslate3fv(plane->widget.offset); widget_plane_draw_geom(col_inner, col_outer); glDisable(GL_BLEND); @@ -1105,7 +1105,7 @@ static void rect_transform_draw_interaction( { float verts[4][2]; unsigned short elems[4] = {0, 1, 3, 2}; - + switch (highlighted) { case WIDGET_RECT_TRANSFORM_INTERSECT_SCALEX_LEFT: verts[0][0] = -half_w + w; @@ -1117,7 +1117,7 @@ static void rect_transform_draw_interaction( verts[3][0] = -half_w + w; verts[3][1] = half_h; break; - + case WIDGET_RECT_TRANSFORM_INTERSECT_SCALEX_RIGHT: verts[0][0] = half_w - w; verts[0][1] = -half_h; @@ -1128,7 +1128,7 @@ static void rect_transform_draw_interaction( verts[3][0] = half_w - w; verts[3][1] = half_h; break; - + case WIDGET_RECT_TRANSFORM_INTERSECT_SCALEY_DOWN: verts[0][0] = -half_w; verts[0][1] = -half_h + h; @@ -1139,7 +1139,7 @@ static void rect_transform_draw_interaction( verts[3][0] = half_w; verts[3][1] = -half_h + h; break; - + case WIDGET_RECT_TRANSFORM_INTERSECT_SCALEY_UP: verts[0][0] = -half_w; verts[0][1] = half_h - h; @@ -1150,11 +1150,11 @@ static void rect_transform_draw_interaction( verts[3][0] = half_w; verts[3][1] = half_h - h; break; - + default: return; } - + glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(2, GL_FLOAT, 0, verts); glLineWidth(line_width + 3.0); @@ -1165,7 +1165,7 @@ static void rect_transform_draw_interaction( glDrawArrays(GL_LINE_STRIP, 0, 3); glLineWidth(1.0); - (void)elems; + UNUSED_VARS(elems); } static void widget_rect_transform_draw(const bContext *UNUSED(C), wmWidget *widget) @@ -1177,12 +1177,12 @@ static void widget_rect_transform_draw(const bContext *UNUSED(C), wmWidget *widg float half_w = w / 2.0f; float half_h = h / 2.0f; float aspx = 1.0f, aspy = 1.0f; - + r.xmin = -half_w; r.ymin = -half_h; r.xmax = half_w; r.ymax = half_h; - + glPushMatrix(); glTranslatef(widget->origin[0] + widget->offset[0], widget->origin[1] + widget->offset[1], 0.0f); if (cage->style & WIDGET_RECT_TRANSFORM_STYLE_SCALE_UNIFORM) @@ -1245,7 +1245,7 @@ static int widget_rect_transform_intersect(bContext *UNUSED(C), const wmEvent *e bool isect; rctf r; float aspx = 1.0f, aspy = 1.0f; - + /* rotate mouse in relation to the center and relocate it */ sub_v2_v2v2(point_local, mouse, widget->origin); point_local[0] -= widget->offset[0]; @@ -1258,7 +1258,7 @@ static int widget_rect_transform_intersect(bContext *UNUSED(C), const wmEvent *e point_local[0] /= cage->scale[0]; point_local[1] /= cage->scale[0]; } - + if (cage->w > cage->h) aspx = h / w; else @@ -1271,9 +1271,9 @@ static int widget_rect_transform_intersect(bContext *UNUSED(C), const wmEvent *e r.ymin = -half_h + h; r.xmax = half_w - w; r.ymax = half_h - h; - + isect = BLI_rctf_isect_pt_v(&r, point_local); - + if (isect) return WIDGET_RECT_TRANSFORM_INTERSECT_TRANSLATE; @@ -1283,43 +1283,43 @@ static int widget_rect_transform_intersect(bContext *UNUSED(C), const wmEvent *e r.ymin = -half_h; r.xmax = -half_w + w; r.ymax = half_h; - + isect = BLI_rctf_isect_pt_v(&r, point_local); - + if (isect) return WIDGET_RECT_TRANSFORM_INTERSECT_SCALEX_LEFT; - + r.xmin = half_w - w; r.ymin = -half_h; r.xmax = half_w; r.ymax = half_h; - + isect = BLI_rctf_isect_pt_v(&r, point_local); - + if (isect) return WIDGET_RECT_TRANSFORM_INTERSECT_SCALEX_RIGHT; - + r.xmin = -half_w; r.ymin = -half_h; r.xmax = half_w; r.ymax = -half_h + h; - + isect = BLI_rctf_isect_pt_v(&r, point_local); - + if (isect) return WIDGET_RECT_TRANSFORM_INTERSECT_SCALEY_DOWN; - + r.xmin = -half_w; r.ymin = half_h - h; r.xmax = half_w; r.ymax = half_h; - + isect = BLI_rctf_isect_pt_v(&r, point_local); - + if (isect) return WIDGET_RECT_TRANSFORM_INTERSECT_SCALEY_UP; } - + return 0; } @@ -1343,13 +1343,13 @@ static bool widget_rect_transform_get_property(wmWidget *widget, const int slot, fprintf(stderr, "Rect Transform widget offset not only be bound to array float property"); return false; } - RNA_property_float_get_array(&widget->ptr[slot], widget->props[slot], value); } else if (slot == RECT_TRANSFORM_SLOT_SCALE) { RectTransformWidget *cage = (RectTransformWidget *)widget; - if (cage->style & WIDGET_RECT_TRANSFORM_STYLE_SCALE_UNIFORM) + if (cage->style & WIDGET_RECT_TRANSFORM_STYLE_SCALE_UNIFORM) { *value = RNA_property_float_get(&widget->ptr[slot], widget->props[slot]); + } else { if (RNA_property_array_length(&widget->ptr[slot], widget->props[slot]) != 2) { fprintf(stderr, "Rect Transform widget scale not only be bound to array float property"); @@ -1359,7 +1359,7 @@ static bool widget_rect_transform_get_property(wmWidget *widget, const int slot, } } } - + return true; } @@ -1367,15 +1367,15 @@ static int widget_rect_transform_invoke(bContext *UNUSED(C), const wmEvent *even { RectTransformWidget *cage = (RectTransformWidget *) widget; RectTransformInteraction *data = MEM_callocN(sizeof (RectTransformInteraction), "cage_interaction"); - + copy_v2_v2(data->orig_offset, widget->offset); copy_v2_v2(data->orig_scale, cage->scale); - + data->orig_mouse[0] = event->mval[0]; data->orig_mouse[1] = event->mval[1]; - + widget->interaction_data = data; - + return OPERATOR_RUNNING_MODAL; } @@ -1387,10 +1387,10 @@ static int widget_rect_transform_handler(bContext *C, const wmEvent *event, wmWi float valuex, valuey; /* needed here as well in case clamping occurs */ const float orig_ofx = widget->offset[0], orig_ofy = widget->offset[1]; - + valuex = (event->mval[0] - data->orig_mouse[0]); valuey = (event->mval[1] - data->orig_mouse[1]); - + if (widget->highlighted_part == WIDGET_RECT_TRANSFORM_INTERSECT_TRANSLATE) { widget->offset[0] = data->orig_offset[0] + valuex; widget->offset[1] = data->orig_offset[1] + valuey; @@ -1405,7 +1405,7 @@ static int widget_rect_transform_handler(bContext *C, const wmEvent *event, wmWi } else if (widget->highlighted_part == WIDGET_RECT_TRANSFORM_INTERSECT_SCALEY_DOWN) { widget->offset[1] = data->orig_offset[1] + valuey / 2.0; - + if (cage->style & WIDGET_RECT_TRANSFORM_STYLE_SCALE_UNIFORM) { cage->scale[0] = (cage->h * data->orig_scale[0] - valuey) / cage->h; } @@ -1415,7 +1415,7 @@ static int widget_rect_transform_handler(bContext *C, const wmEvent *event, wmWi } else if (widget->highlighted_part == WIDGET_RECT_TRANSFORM_INTERSECT_SCALEY_UP) { widget->offset[1] = data->orig_offset[1] + valuey / 2.0; - + if (cage->style & WIDGET_RECT_TRANSFORM_STYLE_SCALE_UNIFORM) { cage->scale[0] = (cage->h * data->orig_scale[0] + valuey) / cage->h; } @@ -1423,7 +1423,7 @@ static int widget_rect_transform_handler(bContext *C, const wmEvent *event, wmWi cage->scale[1] = (cage->h * data->orig_scale[1] + valuey) / cage->h; } } - + /* clamping - make sure widget is at least 5 pixels wide */ if (cage->style & WIDGET_RECT_TRANSFORM_STYLE_SCALE_UNIFORM) { if (cage->scale[0] < WIDGET_RECT_MIN_WIDTH / cage->h || @@ -1444,7 +1444,7 @@ static int widget_rect_transform_handler(bContext *C, const wmEvent *event, wmWi widget->offset[1] = orig_ofy; } } - + if (widget->props[RECT_TRANSFORM_SLOT_OFFSET]) { PointerRNA ptr = widget->ptr[RECT_TRANSFORM_SLOT_OFFSET]; PropertyRNA *prop = widget->props[RECT_TRANSFORM_SLOT_OFFSET]; @@ -1465,17 +1465,17 @@ static int widget_rect_transform_handler(bContext *C, const wmEvent *event, wmWi } RNA_property_update(C, &ptr, prop); } - + /* tag the region for redraw */ ED_region_tag_redraw(ar); - + return OPERATOR_PASS_THROUGH; } static void widget_rect_transform_bind_to_prop(wmWidget *widget, const int slot) { RectTransformWidget *cage = (RectTransformWidget *) widget; - + if (slot == RECT_TRANSFORM_SLOT_OFFSET) widget_rect_transform_get_property(widget, RECT_TRANSFORM_SLOT_OFFSET, widget->offset); if (slot == RECT_TRANSFORM_SLOT_SCALE) @@ -1532,9 +1532,9 @@ wmWidget *WIDGET_rect_transform_new( cage->style = style; cage->w = width; cage->h = height; - + wm_widget_register(wgroup, &cage->widget, name); - + return (wmWidget *)cage; } @@ -1564,7 +1564,7 @@ static void widget_facemap_draw(const bContext *C, wmWidget *widget) FacemapWidget *fmap_widget = (FacemapWidget *)widget; glPushMatrix(); glMultMatrixf(fmap_widget->ob->obmat); - glTranslatef(UNPACK3(widget->offset)); + glTranslate3fv(widget->offset); glEnable(GL_MULTISAMPLE_ARB); ED_draw_object_facemap(CTX_data_scene(C), fmap_widget->ob, fmap_widget->facemap); glDisable(GL_MULTISAMPLE_ARB); @@ -1610,7 +1610,7 @@ wmWidget *WIDGET_facemap_new( fmap_widget->style = style; wm_widget_register(wgroup, &fmap_widget->widget, name); - + return (wmWidget *)fmap_widget; } @@ -1622,5 +1622,5 @@ wmWidget *WIDGET_facemap_new( void fix_linking_widget_lib(void) { - (void) 0; + (void)0; } diff --git a/source/blender/windowmanager/intern/wm_widgets.c b/source/blender/windowmanager/intern/wm_widgets.c index 78835172dbd..613d20c14f8 100644 --- a/source/blender/windowmanager/intern/wm_widgets.c +++ b/source/blender/windowmanager/intern/wm_widgets.c @@ -15,8 +15,7 @@ * 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 + * The Original Code is Copyright (C) 2014 Blender Foundation. * All rights reserved. * * Contributor(s): Blender Foundation, 2008 @@ -102,18 +101,19 @@ static ListBase widgetmaptypes = {NULL, NULL}; wmWidgetGroupType *WM_widgetgrouptype_new( int (*poll)(const bContext *C, wmWidgetGroupType *), void (*create)(const bContext *, wmWidgetGroup *), - wmKeyMap *(*keymap_init)(wmKeyConfig *, wmWidgetGroupType *), + wmKeyMap *(*keymap_init)(wmKeyConfig *, const char *), const Main *bmain, const char *mapidname, const char *name, const short spaceid, const short regionid, const bool is_3d) { wmWidgetMapType *wmaptype = WM_widgetmaptype_find(mapidname, spaceid, regionid, is_3d, false); wmWidgetGroupType *wgrouptype; - + bScreen *sc; + if (!wmaptype) { fprintf(stderr, "widgetgrouptype creation: widgetmap type does not exist"); return NULL; } - + wgrouptype = MEM_callocN(sizeof(wmWidgetGroupType), "widgetgroup"); wgrouptype->poll = poll; @@ -128,43 +128,46 @@ wmWidgetGroupType *WM_widgetgrouptype_new( /* 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 */ - if (bmain) { - wmWindowManager *wm = bmain->wm.first; - bScreen *sc; + /* Main is missing on startup when we create new areas. + * So this is only called for widgets initialized on runtime */ + if (!bmain) + return wgrouptype; - /* init keymap - on startup there's an extra call to init keymaps for 'permanent' widgets */ - wm_widgetgrouptype_keymap_init(wgrouptype, wm->defaultconf); - /* now create a widget for all existing areas */ - for (sc = bmain->screen.first; sc; sc = sc->id.next) { - ScrArea *sa; - for (sa = sc->areabase.first; sa; sa = sa->next) { - SpaceLink *sl; - - for (sl = sa->spacedata.first; sl; sl = sl->next) { - ARegion *ar; - ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase; - - for (ar = lb->first; ar; ar = ar->next) { - wmWidgetMap *wmap; - for (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); - } + /* 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 (sc = bmain->screen.first; sc; sc = sc->id.next) { + ScrArea *sa; + + for (sa = sc->areabase.first; sa; sa = sa->next) { + SpaceLink *sl; + + for (sl = sa->spacedata.first; sl; sl = sl->next) { + ARegion *ar; + ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase; + + for (ar = lb->first; ar; ar = ar->next) { + wmWidgetMap *wmap; + + for (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); } } } } } } - + return wgrouptype; } @@ -174,9 +177,9 @@ wmWidget *WM_widget_new(void (*draw)(const bContext *C, wmWidget *customdata), int (*handler)(bContext *C, const wmEvent *event, wmWidget *widget)) { wmWidget *widget; - + widget = MEM_callocN(sizeof(wmWidget), "widget"); - + widget->draw = draw; widget->handler = handler; widget->intersect = intersect; @@ -194,7 +197,7 @@ static void wm_widget_delete(ListBase *widgetlist, wmWidget *widget) MEM_freeN(widget->props); MEM_freeN(widget->ptr); - + BLI_freelinkN(widgetlist, widget); } @@ -346,7 +349,7 @@ void WM_widgets_draw(const bContext *C, const wmWidgetMap *wmap, const bool in_s } else if (wmap->widgetgroups.first) { wmWidgetGroup *wgroup; - + for (wgroup = wmap->widgetgroups.first; wgroup; wgroup = wgroup->next) { if (!wgroup->type->poll || wgroup->type->poll(C, wgroup->type)) { for (widget = wgroup->widgets.first; widget; widget = widget->next) { @@ -376,10 +379,10 @@ void WM_event_add_area_widgetmap_handlers(ARegion *ar) { wmWidgetMap *wmap; wmEventHandler *handler; - + for (wmap = ar->widgetmaps.first; wmap; wmap = wmap->next) { handler = MEM_callocN(sizeof(wmEventHandler), "widget handler"); - + handler->widgetmap = wmap; BLI_addtail(&ar->handlers, handler); } @@ -400,7 +403,7 @@ void WM_modal_handler_attach_widgetgroup( wmWidgetMap *wmap; for (wmap = handler->op_region->widgetmaps.first; wmap; wmap = wmap->next) { wmWidgetMapType *wmaptype = wmap->type; - + if (wmaptype->spaceid == wgrouptype->spaceid && wmaptype->regionid == wgrouptype->regionid) { handler->widgetmap = wmap; } @@ -460,7 +463,7 @@ bool wm_widget_register(wmWidgetGroup *wgroup, wmWidget *widget, const char *nam 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"); @@ -646,12 +649,12 @@ static int widget_tweak_invoke(bContext *C, wmOperator *UNUSED(op), const wmEven return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH); } - /* ugly hack - send widget update event */ - ((wmEvent *)event)->type = EVT_WIDGET_UPDATE; - /* handle widget */ widget->handler(C, event, widget); + /* ugly hack - send widget update event */ + ((wmEvent *)event)->type = EVT_WIDGET_UPDATE; + return OPERATOR_FINISHED; } @@ -709,8 +712,11 @@ wmWidgetMapType *WM_widgetmaptype_find( wmWidgetMapType *wmaptype; for (wmaptype = widgetmaptypes.first; wmaptype; wmaptype = wmaptype->next) { - if (wmaptype->spaceid == spaceid && wmaptype->regionid == regionid && wmaptype->is_3d == is_3d - && strcmp(wmaptype->idname, idname) == 0) { + if (wmaptype->spaceid == spaceid && + wmaptype->regionid == regionid && + wmaptype->is_3d == is_3d && + STREQ(wmaptype->idname, idname)) + { return wmaptype; } } @@ -723,14 +729,14 @@ wmWidgetMapType *WM_widgetmaptype_find( wmaptype->is_3d = is_3d; BLI_strncpy(wmaptype->idname, idname, 64); BLI_addhead(&widgetmaptypes, wmaptype); - + return wmaptype; } void WM_widgetmaptypes_free(void) { wmWidgetMapType *wmaptype; - + for (wmaptype = widgetmaptypes.first; wmaptype; wmaptype = wmaptype->next) { BLI_freelistN(&wmaptype->widgetgrouptypes); } @@ -772,38 +778,38 @@ static int wm_widget_find_highlighted_3D_intern( const bool do_passes = GPU_select_query_check_active(); extern void view3d_winmatrix_set(ARegion *ar, View3D *v3d, rctf *rect); - + + rect.xmin = event->mval[0] - hotspot; rect.xmax = event->mval[0] + hotspot; rect.ymin = event->mval[1] - hotspot; rect.ymax = event->mval[1] + hotspot; - + selrect = rect; - + view3d_winmatrix_set(ar, v3d, &rect); mul_m4_m4m4(rv3d->persmat, rv3d->winmat, rv3d->viewmat); - + if (do_passes) GPU_select_begin(buffer, 64, &selrect, GPU_SELECT_NEAREST_FIRST_PASS, 0); else GPU_select_begin(buffer, 64, &selrect, GPU_SELECT_ALL, 0); /* do the drawing */ widget_find_active_3D_loop(C, visible_widgets); - + hits = GPU_select_end(); - + if (do_passes) { GPU_select_begin(buffer, 64, &selrect, GPU_SELECT_NEAREST_SECOND_PASS, hits); widget_find_active_3D_loop(C, visible_widgets); GPU_select_end(); } - + view3d_winmatrix_set(ar, v3d, NULL); mul_m4_m4m4(rv3d->persmat, rv3d->winmat, rv3d->viewmat); if (hits == 1) { return buffer[3]; - } /* find the widget the value belongs to */ else if (hits > 1) { @@ -825,6 +831,7 @@ static int wm_widget_find_highlighted_3D_intern( return minval; } + return -1; } @@ -856,24 +863,24 @@ wmWidget *wm_widget_find_highlighted_3D(wmWidgetMap *wmap, bContext *C, const wm *part = 0; /* set up view matrices */ view3d_operator_needs_opengl(C); - + ret = wm_widget_find_highlighted_3D_intern(&visible_widgets, C, event, 0.5f * hotspot); - + if (ret != -1) { LinkData *link; int retsec; retsec = wm_widget_find_highlighted_3D_intern(&visible_widgets, C, event, 0.2f * hotspot); - + if (retsec != -1) ret = retsec; - + link = BLI_findlink(&visible_widgets, ret >> 8); *part = ret & 255; result = link->data; } BLI_freelistN(&visible_widgets); - + return result; } @@ -905,7 +912,7 @@ bool WM_widgetmap_cursor_set(const wmWidgetMap *wmap, wmWindow *win) return true; } } - + return false; } @@ -916,9 +923,9 @@ void wm_widgetmap_set_highlighted_widget(wmWidgetMap *wmap, bContext *C, wmWidge wmap->highlighted_widget->flag &= ~WM_WIDGET_HIGHLIGHT; wmap->highlighted_widget->highlighted_part = 0; } - + wmap->highlighted_widget = widget; - + if (widget) { widget->flag |= WM_WIDGET_HIGHLIGHT; widget->highlighted_part = part; @@ -936,7 +943,7 @@ void wm_widgetmap_set_highlighted_widget(wmWidgetMap *wmap, bContext *C, wmWidge WM_cursor_set(win, CURSOR_STD); } } - + /* tag the region for redraw */ if (C) { ARegion *ar = CTX_wm_region(C); @@ -1008,7 +1015,7 @@ void wm_widgetmap_set_active_widget( } } wmap->active_widget = NULL; - + if (C) { ARegion *ar = CTX_wm_region(C); ED_region_tag_redraw(ar); @@ -1148,7 +1155,7 @@ void WM_widgetmap_delete(wmWidgetMap *wmap) for (wgroup = wmap->widgetgroups.first; wgroup; wgroup = wgroup->next) { wmWidget *widget; - + for (widget = wgroup->widgets.first; widget;) { wmWidget *widget_next = widget->next; wm_widget_delete(&wgroup->widgets, widget); @@ -1196,9 +1203,9 @@ static void wm_widgetgroup_free(bContext *C, wmWidgetMap *wmap, wmWidgetGroup *w /** * Common default keymap for widget groups */ -wmKeyMap *WM_widgetgroup_keymap_common(wmKeyConfig *config, wmWidgetGroupType *wgrouptype) +wmKeyMap *WM_widgetgroup_keymap_common(wmKeyConfig *config, const char *wgroupname) { - wmKeyMap *km = WM_keymap_find(config, wgrouptype->name, 0, 0); + wmKeyMap *km = WM_keymap_find(config, wgroupname, 0, 0); wmKeyMapItem *kmi; kmi = WM_keymap_add_item(km, "WIDGETGROUP_OT_widget_set_active", ACTIONMOUSE, KM_PRESS, 0, 0); @@ -1218,7 +1225,7 @@ wmKeyMap *WM_widgetgroup_keymap_common(wmKeyConfig *config, wmWidgetGroupType *w void wm_widgetgrouptype_keymap_init(wmWidgetGroupType *wgrouptype, wmKeyConfig *keyconf) { - wgrouptype->keymap = wgrouptype->keymap_init(keyconf, wgrouptype); + wgrouptype->keymap = wgrouptype->keymap_init(keyconf, wgrouptype->name); } void WM_widgetgrouptype_unregister(bContext *C, Main *bmain, wmWidgetGroupType *wgrouptype) @@ -1253,8 +1260,10 @@ void WM_widgetgrouptype_unregister(bContext *C, Main *bmain, wmWidgetGroupType * } wmaptype = WM_widgetmaptype_find(wgrouptype->mapidname, wgrouptype->spaceid, wgrouptype->regionid, wgrouptype->is_3d, false); + BLI_remlink(&wmaptype->widgetgrouptypes, wgrouptype); wgrouptype->prev = wgrouptype->next = NULL; + MEM_freeN(wgrouptype); } diff --git a/source/blender/windowmanager/wm.h b/source/blender/windowmanager/wm.h index 6dbe3617852..f2bed99815d 100644 --- a/source/blender/windowmanager/wm.h +++ b/source/blender/windowmanager/wm.h @@ -49,10 +49,10 @@ typedef struct wmPaintCursor { void (*draw)(bContext *C, int, int, void *customdata); } wmPaintCursor; -/* widgets are set per screen/area/region by registering them on widgetmaps */ +/* widgets are set per region by registering them on widgetmaps */ typedef struct wmWidget { struct wmWidget *next, *prev; - + char idname[MAX_NAME + 4]; /* + 4 for unique '.001', '.002', etc suffix */ /* pointer back to parent widget group */ @@ -83,8 +83,8 @@ typedef struct wmWidget { void (*cancel)(struct bContext *C, struct wmWidget *widget); int (*get_cursor)(struct wmWidget *widget); - - int flag; /* flags set by drawing and interaction, such as highlighting */ + + int flag; /* flags set by drawing and interaction, such as highlighting */ unsigned char highlighted_part; @@ -112,14 +112,14 @@ typedef struct wmWidget { const char *opname; /* operator properties if widget spawns and controls an operator, or owner pointer if widget spawns and controls a property */ - struct PointerRNA opptr; + PointerRNA opptr; /* maximum number of properties attached to the widget */ int max_prop; - + /* arrays of properties attached to various widget parameters. As the widget is interacted with, those properties get updated */ - struct PointerRNA *ptr; - struct PropertyRNA **props; + PointerRNA *ptr; + PropertyRNA **props; } wmWidget; @@ -169,8 +169,8 @@ void wm_open_init_load_ui(wmOperator *op, bool use_prefs); void wm_open_init_use_scripts(wmOperator *op, bool use_prefs); /* wm_widgets.c */ -bool wm_widgetmap_is_3d(const struct wmWidgetMap *wmap); -bool wm_widget_register(struct wmWidgetGroup *wgroup, struct wmWidget *widget, const char *name); +bool wm_widgetmap_is_3d(const wmWidgetMap *wmap); +bool wm_widget_register(wmWidgetGroup *wgroup, wmWidget *widget, const char *name); void wm_widgets_keymap(wmKeyConfig *keyconf); void WIDGETGROUP_OT_widget_set_active(wmOperatorType *ot); diff --git a/source/blender/windowmanager/wm_event_system.h b/source/blender/windowmanager/wm_event_system.h index 14f571b89ce..2d9e5dbfc54 100644 --- a/source/blender/windowmanager/wm_event_system.h +++ b/source/blender/windowmanager/wm_event_system.h @@ -106,16 +106,16 @@ void wm_widgetmap_handler_context(bContext *C, wmEventHandler *handler); void wm_widgetgrouptype_keymap_init(wmWidgetGroupType *wgrouptype, wmKeyConfig *keyconf); -struct wmWidget *wm_widget_find_highlighted_3D(struct wmWidgetMap *wmap, struct bContext *C, const struct wmEvent *event, unsigned char *part); -wmWidget *wm_widget_find_highlighted(struct wmWidgetMap *wmap, bContext *C, const struct wmEvent *event, unsigned char *part); -void wm_widgetmap_set_highlighted_widget(struct wmWidgetMap *wmap, struct bContext *C, struct wmWidget *widget, unsigned char part); -struct wmWidget *wm_widgetmap_get_highlighted_widget(struct wmWidgetMap *wmap); +wmWidget *wm_widget_find_highlighted_3D(wmWidgetMap *wmap, bContext *C, const wmEvent *event, unsigned char *part); +wmWidget *wm_widget_find_highlighted(wmWidgetMap *wmap, bContext *C, const wmEvent *event, unsigned char *part); +void wm_widgetmap_set_highlighted_widget(wmWidgetMap *wmap, bContext *C, wmWidget *widget, unsigned char part); +wmWidget *wm_widgetmap_get_highlighted_widget(wmWidgetMap *wmap); -void wm_widgetmap_set_active_widget(struct wmWidgetMap *wmap, struct bContext *C, const struct wmEvent *event, struct wmWidget *widget); -struct wmWidget *wm_widgetmap_get_active_widget(struct wmWidgetMap *wmap); +void wm_widgetmap_set_active_widget(wmWidgetMap *wmap, bContext *C, const wmEvent *event, wmWidget *widget); +wmWidget *wm_widgetmap_get_active_widget(wmWidgetMap *wmap); -void wm_widgetmap_set_selected_widget(struct bContext *C, wmWidgetMap *wmap, wmWidget *widget); -struct wmWidget *wm_widgetmap_get_selected_widget(wmWidgetMap *wmap); +void wm_widgetmap_set_selected_widget(bContext *C, wmWidgetMap *wmap, wmWidget *widget); +wmWidget *wm_widgetmap_get_selected_widget(wmWidgetMap *wmap); #endif /* __WM_EVENT_SYSTEM_H__ */ |