diff options
author | Diego Borghetti <bdiego@gmail.com> | 2008-01-14 22:44:20 +0300 |
---|---|---|
committer | Diego Borghetti <bdiego@gmail.com> | 2008-01-14 22:44:20 +0300 |
commit | 2a0055401e86bd2344564184cd7a48170d984367 (patch) | |
tree | 6ce393d7a983b410a3c5d99943742a6336f6eb0b | |
parent | 49eb7a3eed225f8ff109a5b10b1a3192bcdd4f1b (diff) |
New API to access Operator properties.
This is a simple API around IDProperty to store properties
in the Operator, it is really simple and this first commit
just add support for IDP_INT data type.
Take care that this "properties" are not save yet and you get
some "Error totblock" more with this.
I add some notes to the WM_api.h file, please check this,
comment and ideas are welcome.
-rw-r--r-- | source/blender/editors/screen/screen_edit.c | 22 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_windowmanager_types.h | 2 | ||||
-rw-r--r-- | source/blender/windowmanager/WM_api.h | 16 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm.c | 15 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 42 |
5 files changed, 91 insertions, 6 deletions
diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c index cbb0e82b185..19dc9446314 100644 --- a/source/blender/editors/screen/screen_edit.c +++ b/source/blender/editors/screen/screen_edit.c @@ -646,16 +646,13 @@ int screen_cursor_test(bContext *C, wmOperator *op, wmEvent *event) */ -/* "global" variables for all functions inside this operator */ -/* we could do it with properties? */ -static int bigger, smaller, dir, origval; - /* validate selection inside screen, set variables OK */ /* return 0: init failed */ static int move_areas_init (bContext *C, wmOperator *op) { ScrEdge *actedge= screen_find_active_scredge(C->screen, op->veci.x, op->veci.y); ScrArea *sa; + int bigger, smaller, dir, origval; if(actedge==NULL) return 0; @@ -691,7 +688,12 @@ static int move_areas_init (bContext *C, wmOperator *op) } } } - + + OP_set_int(op, "bigger", bigger); + OP_set_int(op, "smaller", smaller); + OP_set_int(op, "dir", dir); + OP_set_int(op, "origval", origval); + return 1; } @@ -700,6 +702,12 @@ static int move_areas_init (bContext *C, wmOperator *op) static int move_areas_exec(bContext *C, wmOperator *op) { ScrVert *v1; + int bigger, smaller, dir, origval; + + OP_get_int(op, "bigger", &bigger); + OP_get_int(op, "smaller", &smaller); + OP_get_int(op, "dir", &dir); + OP_get_int(op, "origval", &origval); op->delta= CLAMPIS(op->delta, -smaller, bigger); @@ -760,6 +768,10 @@ static int move_areas_invoke (bContext *C, wmOperator *op, wmEvent *event) /* return 0 = stop evaluating for next handlers */ static int move_areas_modal (bContext *C, wmOperator *op, wmEvent *event) { + int dir; + + OP_get_int(op, "dir", &dir); + /* execute the events */ switch(event->type) { case MOUSEMOVE: diff --git a/source/blender/makesdna/DNA_windowmanager_types.h b/source/blender/makesdna/DNA_windowmanager_types.h index 49275e7d056..f74cc659645 100644 --- a/source/blender/makesdna/DNA_windowmanager_types.h +++ b/source/blender/makesdna/DNA_windowmanager_types.h @@ -163,7 +163,7 @@ typedef struct wmOperator { /* custom storage, dna pointer */ void *customdata; /* or IDproperty list */ - void *properties; + IDProperty *properties; } wmOperator; diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 915c55f4cf7..727b228405b 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -81,6 +81,22 @@ int WM_operator_winactive (struct bContext *C); wmOperatorType *WM_operatortype_find(const char *idname); void WM_operatortypelist_append(ListBase *lb); +/* + * Operator property api + * + * Some notes to take care: + * + * OP_set_int try to append a new property to the operator, + * if the property already exist, just replace it with the + * value in other case make a new property and append it. + * + * OP_get_int return 0 on success (found the property) or + * != 0 if can't found the property in the operator. + * The property value are store in the "value" pointer. + */ +void OP_set_int(wmOperator *op, char *name, int value); +int OP_get_int(wmOperator *op, char *name, int *value); + /* OpenGL wrappers, mimicing opengl syntax */ void wmLoadMatrix (wmWindow *win, float mat[][4]); void wmGetMatrix (wmWindow *win, float mat[][4]); diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c index 19bf8e67db7..d0319da593b 100644 --- a/source/blender/windowmanager/intern/wm.c +++ b/source/blender/windowmanager/intern/wm.c @@ -36,6 +36,7 @@ #include "BKE_global.h" #include "BKE_library.h" #include "BKE_main.h" +#include "BKE_idprop.h" #include "WM_api.h" #include "WM_types.h" @@ -124,6 +125,7 @@ void wm_add_default(bContext *C) /* context is allowed to be NULL, do net free wm itself (library.c) */ void wm_close_and_free(bContext *C, wmWindowManager *wm) { + wmOperator *op; wmWindow *win; while((win= wm->windows.first)) { @@ -131,6 +133,19 @@ void wm_close_and_free(bContext *C, wmWindowManager *wm) wm_window_free(C, win); } + op= wm->operators.first; + while(op) { + /* + * Need this, because if the operator don't have + * properties also don't have group. + */ + if(op->properties) { + IDP_FreeGroup(op->properties); + op->properties= NULL; + } + op= op->next; + } + BLI_freelistN(&wm->operators); BLI_freelistN(&wm->windowkeymap); diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 27f8b48451a..4c26ef4b115 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -28,6 +28,7 @@ #include <string.h> +#include "DNA_ID.h" #include "DNA_windowmanager_types.h" #include "MEM_guardedalloc.h" @@ -38,6 +39,7 @@ #include "BKE_global.h" #include "BKE_library.h" #include "BKE_main.h" +#include "BKE_idprop.h" #include "WM_api.h" #include "WM_types.h" @@ -136,7 +138,47 @@ void wm_operatortype_init(void) ADD_OPTYPE(WM_OT_window_fullscreen_toggle); } +/* wrapped to get property from a operator. */ +IDProperty *op_get_property(wmOperator *op, char *name) +{ + IDProperty *prop= IDP_GetPropertyFromGroup(op->properties, name); + return(prop); +} + +/* + * We need create a "group" to store the operator properties. + * We don't have a WM_operator_new or some thing like that, + * so this function is called by all the OP_set_* function + * in case that op->properties is equal to NULL. + */ +void op_init_property(wmOperator *op) +{ + IDPropertyTemplate val; + op->properties= IDP_New(IDP_GROUP, val, "property"); +} +/* ***** Property API, exported ***** */ +void OP_set_int(wmOperator *op, char *name, int value) +{ + IDPropertyTemplate val; + IDProperty *prop; + + if(!op->properties) + op_init_property(op); + val.i= value; + prop= IDP_New(IDP_INT, val, name); + IDP_ReplaceInGroup(op->properties, prop); +} +int OP_get_int(wmOperator *op, char *name, int *value) +{ + IDProperty *prop= op_get_property(op, name); + int status= 1; + if ((prop) && (prop->type == IDP_INT)) { + (*value)= prop->data.val; + status= 0; + } + return (status); +} |