diff options
Diffstat (limited to 'source/blender/windowmanager')
-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 |
3 files changed, 73 insertions, 0 deletions
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); +} |