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.
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -163,7 +163,7 @@ typedef struct wmOperator {
|
||||
/* custom storage, dna pointer */
|
||||
void *customdata;
|
||||
/* or IDproperty list */
|
||||
void *properties;
|
||||
IDProperty *properties;
|
||||
|
||||
|
||||
} wmOperator;
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user