[Bf-blender-cvs] [585204b] wiggly-widgets: Dummy handler for arrows, take care of some allocation issues for operators.
Antony Riakiotakis
noreply at git.blender.org
Fri Oct 17 15:09:58 CEST 2014
Commit: 585204bd6102b7ca0a1bfb7059e324c6d0cb2102
Author: Antony Riakiotakis
Date: Fri Oct 17 15:09:51 2014 +0200
Branches: wiggly-widgets
https://developer.blender.org/rB585204bd6102b7ca0a1bfb7059e324c6d0cb2102
Dummy handler for arrows, take care of some allocation issues for
operators.
===================================================================
M source/blender/windowmanager/WM_api.h
M source/blender/windowmanager/intern/wm_generic_widgets.c
M source/blender/windowmanager/intern/wm_widgets.c
M source/blender/windowmanager/wm.h
===================================================================
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 9292fe3..758d2e5 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -473,7 +473,7 @@ struct wmWidgetGroup *WM_widgetgroup_new(bool (*poll)(struct wmWidgetGroup *, co
struct wmWidget *WM_widget_new(void (*draw)(struct wmWidget *, const struct bContext *, float scale),
void (*render_3d_intersection)(const struct bContext *, struct wmWidget *, float, int),
int (*intersect)(struct bContext *C, const struct wmEvent *event, struct wmWidget *customdata),
- int (*activate)(struct bContext *, const struct wmEvent *, struct wmWidget *, struct PointerRNA *),
+ int (*initialize_op)(struct bContext *, const struct wmEvent *, struct wmWidget *, struct PointerRNA *),
int (*handler)(struct bContext *, const struct wmEvent *, struct wmWidget *),
void *customdata, bool free_data, char *opname, char *prop);
@@ -509,7 +509,7 @@ enum {
};
struct wmWidget *WIDGET_arrow_new(int style,
- int (*activate)(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget, struct PointerRNA *ptr),
+ int (*initialize_op)(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget, struct PointerRNA *ptr),
const char *opname,
const char *prop,
void *customdata);
@@ -517,7 +517,7 @@ void WIDGET_arrow_set_color(struct wmWidget *widget, float color[4]);
void WIDGET_arrow_set_direction(struct wmWidget *widget, float direction[3]);
struct wmWidget *WIDGET_dial_new(int style,
- int (*activate)(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget, struct PointerRNA *ptr),
+ int (*initialize_op)(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget, struct PointerRNA *ptr),
const char *opname,
const char *prop,
void *customdata);
diff --git a/source/blender/windowmanager/intern/wm_generic_widgets.c b/source/blender/windowmanager/intern/wm_generic_widgets.c
index de6fe11..cd17d8c 100644
--- a/source/blender/windowmanager/intern/wm_generic_widgets.c
+++ b/source/blender/windowmanager/intern/wm_generic_widgets.c
@@ -177,9 +177,13 @@ static void widget_arrow_draw(struct wmWidget *widget, const struct bContext *UN
arrow_draw_intern((ArrowWidget *)widget, false, (widget->flag & WM_WIDGET_HIGHLIGHT) != 0, scale);
}
+static int widget_arrow_handler(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget)
+{
+ return OPERATOR_FINISHED;
+}
wmWidget *WIDGET_arrow_new(int style,
- int (*activate)(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget, struct PointerRNA *ptr),
+ int (*initialize_op)(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget, struct PointerRNA *ptr),
const char *opname, const char *prop, void *customdata)
{
float dir_default[3] = {0.0f, 0.0f, 1.0f};
@@ -197,8 +201,9 @@ wmWidget *WIDGET_arrow_new(int style,
arrow = MEM_callocN(sizeof(ArrowWidget), "arrowwidget");
arrow->widget.draw = widget_arrow_draw;
- arrow->widget.activate = activate;
+ arrow->widget.initialize_op = initialize_op;
arrow->widget.intersect = NULL;
+ arrow->widget.handler = widget_arrow_handler;
arrow->widget.render_3d_intersection = widget_arrow_render_3d_intersect;
arrow->widget.opname = opname;
arrow->widget.prop = prop;
@@ -305,7 +310,7 @@ static void widget_dial_draw(struct wmWidget *widget, const struct bContext *C,
}
wmWidget *WIDGET_dial_new(int style,
- int (*activate)(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget, struct PointerRNA *ptr),
+ int (*initialize_op)(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget, struct PointerRNA *ptr),
const char *opname, const char *prop, void *customdata)
{
float dir_default[3] = {0.0f, 0.0f, 1.0f};
@@ -323,7 +328,7 @@ wmWidget *WIDGET_dial_new(int style,
dial = MEM_callocN(sizeof(ArrowWidget), "arrowwidget");
dial->widget.draw = widget_dial_draw;
- dial->widget.activate = activate;
+ dial->widget.initialize_op = initialize_op;
dial->widget.intersect = NULL;
dial->widget.render_3d_intersection = widget_dial_render_3d_intersect;
dial->widget.opname = opname;
diff --git a/source/blender/windowmanager/intern/wm_widgets.c b/source/blender/windowmanager/intern/wm_widgets.c
index 4af3c1a..7f695dd 100644
--- a/source/blender/windowmanager/intern/wm_widgets.c
+++ b/source/blender/windowmanager/intern/wm_widgets.c
@@ -138,7 +138,7 @@ ListBase *WM_widgetgroup_widgets(struct wmWidgetGroup *wgroup)
wmWidget *WM_widget_new(void (*draw)(struct wmWidget *customdata, const struct bContext *C, float scale),
void (*render_3d_intersection)(const struct bContext *C, struct wmWidget *customdata, float scale, int selectionbase),
int (*intersect)(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget),
- int (*activate)(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget, struct PointerRNA *),
+ int (*initialize_op)(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget, struct PointerRNA *),
int (*handler)(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget),
void *customdata, bool free_data, char *opname, char *prop)
{
@@ -147,7 +147,7 @@ wmWidget *WM_widget_new(void (*draw)(struct wmWidget *customdata, const struct b
widget = MEM_callocN(sizeof(wmWidget), "widget");
widget->draw = draw;
- widget->activate = activate;
+ widget->initialize_op = initialize_op;
widget->handler = handler;
widget->intersect = intersect;
widget->render_3d_intersection = render_3d_intersection;
@@ -528,11 +528,17 @@ void wm_widgetmap_set_active_widget(struct wmWidgetMap *wmap, struct bContext *C
wmOperatorType *ot = widget->ot = WM_operatortype_find(widget->opname, 0);
if (ot) {
+ widget->flag |= WM_WIDGET_ACTIVE;
+ /* first activate the widget itself */
+ if (widget->activate_state) {
+ widget->activate_state(C, event, widget, WIDGET_ACTIVATE);
+ }
+
WM_operator_properties_create_ptr(&widget->opptr, ot);
/* time to initialize those properties now */
- if (widget->activate) {
- widget->activate(C, event, widget, &widget->opptr);
+ if (widget->initialize_op) {
+ widget->initialize_op(C, event, widget, &widget->opptr);
}
WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &widget->opptr);
@@ -552,7 +558,18 @@ void wm_widgetmap_set_active_widget(struct wmWidgetMap *wmap, struct bContext *C
}
else {
ARegion *ar = CTX_wm_region(C);
+ widget = wmap->active_widget;
+
/* deactivate, widget but first take care of some stuff */
+ if (widget) {
+ widget->flag &= ~WM_WIDGET_ACTIVE;
+ /* first activate the widget itself */
+ if (widget->activate_state) {
+ widget->activate_state(C, event, widget, WIDGET_DEACTIVATE);
+ }
+
+ WM_operator_properties_clear(&widget->opptr);
+ }
wmap->active_widget = NULL;
ED_region_tag_redraw(ar);
diff --git a/source/blender/windowmanager/wm.h b/source/blender/windowmanager/wm.h
index 06d9e6f..08781bb 100644
--- a/source/blender/windowmanager/wm.h
+++ b/source/blender/windowmanager/wm.h
@@ -61,14 +61,17 @@ typedef struct wmWidget {
/* determines 3d intersection by rendering the widget in a selection routine. */
void (*render_3d_intersection)(const struct bContext *C, struct wmWidget *widget, float scale, int selectionbase);
- /* activate the widget when the user clicks on it */
- int (*activate)(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget, struct PointerRNA *opptr);
+ /* initialize the operator properties when the user clicks the widget */
+ int (*initialize_op)(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget, struct PointerRNA *opptr);
/* handler used by the widget. Usually handles interaction tied to a widget type */
int (*handler)(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget);
int flag; /* flags set by drawing and interaction, such as highlighting */
+ /* activate a widget state when the user clicks on it */
+ int (*activate_state)(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget, int state);
+
/* position in space, 2d or 3d */
float origin[3];
@@ -88,10 +91,19 @@ typedef struct wmWidget {
struct PointerRNA opptr;
} wmWidget;
+#define WIDGET_ACTIVATE 1
+#define WIDGET_DEACTIVATE 2
+
/* wmWidget->flag */
-#define WM_WIDGET_HIGHLIGHT (1 << 0)
-#define WM_WIDGET_FREE_DATA (1 << 1)
-#define WM_WIDGET_SKIP_DRAW (1 << 2)
+enum widgetflags {
+ /* states */
+ WM_WIDGET_HIGHLIGHT = (1 << 0),
+ WM_WIDGET_ACTIVE = (1 << 1),
+
+ /* other stuff */
+ WM_WIDGET_FREE_DATA = (1 << 2),
+ WM_WIDGET_SKIP_DRAW = (1 << 3)
+};
extern void wm_close_and_free(bContext *C, wmWindowManager *);
extern void wm_close_and_free_all(bContext *C, ListBase *);
More information about the Bf-blender-cvs
mailing list