diff options
author | Ton Roosendaal <ton@blender.org> | 2008-11-19 19:28:11 +0300 |
---|---|---|
committer | Ton Roosendaal <ton@blender.org> | 2008-11-19 19:28:11 +0300 |
commit | a1b2c0c0fb7adb1758b0503a5422c377f8d0f73e (patch) | |
tree | e34a21c6621c407b6b140ef107797b9d29819ee7 /source/blender/windowmanager | |
parent | fd8c94fdb156ce83f5aa70eddcd85b0af6f1456a (diff) |
Code shuffle to make a bit more structure.
- operator definitions, callbacks, registry to WM and handlers for it are
now always in a file xxxx_ops.c or xxxx_operators.c, in the bottom you
will find the registry and handler code.
- fixed some confusing naming conventions "rip_area vs area_join" etc. Now
stick to convention to first name subject, then operation (like UI :).
So it's area_rip, screen_add, and so on.
- Nicely put exported calls (outside module) together in bottom: this using
names such as ED_screen_duplicate().
- Moved Operator-Property API to new C file.
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r-- | source/blender/windowmanager/WM_api.h | 34 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm.c | 11 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_operator_props.c | 298 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 268 | ||||
-rw-r--r-- | source/blender/windowmanager/wm.h | 1 |
5 files changed, 324 insertions, 288 deletions
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 86e6fe77c73..b81184df049 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -139,23 +139,23 @@ int WM_border_select_modal (struct bContext *C, wmOperator *op, struct wmEvent * len= 4; <---- set the size!! * OP_get_int_array (op, "vector", vec, &len); */ -void OP_set_int(wmOperator *op, char *name, int value); -void OP_set_float(wmOperator *op, char *name, float value); -void OP_set_string(wmOperator *op, char *name, char *str); -void OP_set_int_array(wmOperator *op, char *name, int *array, short len); -void OP_set_float_array(wmOperator *op, char *name, float *array, short len); - -int OP_get_int(wmOperator *op, char *name, int *value); -int OP_get_float(wmOperator *op, char *name, float *value); -char *OP_get_string(wmOperator *op, char *name); -int OP_get_int_array(wmOperator *op, char *name, int *array, short *len); -int OP_get_float_array(wmOperator *op, char *name, float *array, short *len); - -void OP_verify_int(wmOperator *op, char *name, int value, int *result); -void OP_verify_float(wmOperator *op, char *name, float value, int *result); -char *OP_verify_string(wmOperator *op, char *name, char *str); -void OP_verify_int_array(wmOperator *op, char *name, int *array, short len, int *resultarray, short *resultlen); -void OP_verify_float_array(wmOperator *op, char *name, float *array, short len, float *resultarray, short *resultlen); +void OP_set_int (wmOperator *op, char *name, int value); +void OP_set_float (wmOperator *op, char *name, float value); +void OP_set_string (wmOperator *op, char *name, char *str); +void OP_set_int_array(wmOperator *op, char *name, int *array, short len); +void OP_set_float_array(wmOperator *op, char *name, float *array, short len); + +int OP_get_int (wmOperator *op, char *name, int *value); +int OP_get_float (wmOperator *op, char *name, float *value); +char *OP_get_string (wmOperator *op, char *name); +int OP_get_int_array(wmOperator *op, char *name, int *array, short *len); +int OP_get_float_array(wmOperator *op, char *name, float *array, short *len); + +void OP_verify_int (wmOperator *op, char *name, int value, int *result); +void OP_verify_float (wmOperator *op, char *name, float value, int *result); +char *OP_verify_string(wmOperator *op, char *name, char *str); +void OP_verify_int_array(wmOperator *op, char *name, int *array, short len, int *resultarray, short *resultlen); +void OP_verify_float_array(wmOperator *op, char *name, float *array, short len, float *resultarray, short *resultlen); /* * Need call this function in the "exit callback" diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c index cafc7a7b597..165ca88ab71 100644 --- a/source/blender/windowmanager/intern/wm.c +++ b/source/blender/windowmanager/intern/wm.c @@ -74,17 +74,6 @@ void wm_operator_register(wmWindowManager *wm, wmOperator *op) } } -/* **************** standard keymap for WM ********************** */ - -/* default keymap for windows and screens, only call once per WM */ -static void wm_window_keymap(wmWindowManager *wm) -{ - /* note, this doesn't replace existing keymap items */ - WM_keymap_verify_item(&wm->windowkeymap, "WM_OT_window_duplicate", AKEY, KM_PRESS, 0, 0); - WM_keymap_verify_item(&wm->windowkeymap, "WM_OT_save_homefile", UKEY, KM_PRESS, KM_CTRL, 0); - WM_keymap_verify_item(&wm->windowkeymap, "WM_OT_window_fullscreen_toggle", FKEY, KM_PRESS, 0, 0); - WM_keymap_verify_item(&wm->windowkeymap, "WM_OT_exit_blender", QKEY, KM_PRESS, KM_CTRL, 0); -} /* ****************************************** */ diff --git a/source/blender/windowmanager/intern/wm_operator_props.c b/source/blender/windowmanager/intern/wm_operator_props.c new file mode 100644 index 00000000000..9ba350fbb04 --- /dev/null +++ b/source/blender/windowmanager/intern/wm_operator_props.c @@ -0,0 +1,298 @@ +/** +* $Id: + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2008 Blender Foundation. + * All rights reserved. + * + * + * Contributor(s): Blender Foundation + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include "DNA_ID.h" + +#include "MEM_guardedalloc.h" + +#include "BKE_idprop.h" + +#include "WM_api.h" + + +/* wrapped to get property from a operator. */ +static IDProperty *op_get_property(wmOperator *op, char *name) +{ + IDProperty *prop; + + if(!op->properties) + return NULL; + + 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. + */ +static void op_init_property(wmOperator *op) +{ + IDPropertyTemplate val; + val.i = 0; /* silence MSVC warning about uninitialized var when debugging */ + op->properties= IDP_New(IDP_GROUP, val, "property"); +} + +/* ***** Property API, exported ***** */ +void OP_free_property(wmOperator *op) +{ + if(op->properties) { + IDP_FreeProperty(op->properties); + /* + * This need change, when the idprop code only + * need call IDP_FreeProperty. (check BKE_idprop.h) + */ + MEM_freeN(op->properties); + op->properties= NULL; + } +} + +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); +} + +void OP_set_float(wmOperator *op, char *name, float value) +{ + IDPropertyTemplate val; + IDProperty *prop; + + if(!op->properties) + op_init_property(op); + + val.f= value; + prop= IDP_New(IDP_FLOAT, val, name); + IDP_ReplaceInGroup(op->properties, prop); +} + +void OP_set_int_array(wmOperator *op, char *name, int *array, short len) +{ + IDPropertyTemplate val; + IDProperty *prop; + short i; + int *pointer; + + if(!op->properties) + op_init_property(op); + + val.array.len= len; + val.array.type= IDP_INT; + prop= IDP_New(IDP_ARRAY, val, name); + + pointer= (int *)prop->data.pointer; + for(i= 0; i < len; i++) + pointer[i]= array[i]; + IDP_ReplaceInGroup(op->properties, prop); +} + +void OP_set_float_array(wmOperator *op, char *name, float *array, short len) +{ + IDPropertyTemplate val; + IDProperty *prop; + short i; + float *pointer; + + if(!op->properties) + op_init_property(op); + + val.array.len= len; + val.array.type= IDP_FLOAT; + prop= IDP_New(IDP_ARRAY, val, name); + + pointer= (float *) prop->data.pointer; + for(i= 0; i < len; i++) + pointer[i]= array[i]; + IDP_ReplaceInGroup(op->properties, prop); +} + +void OP_set_string(wmOperator *op, char *name, char *str) +{ + IDPropertyTemplate val; + IDProperty *prop; + + if(!op->properties) + op_init_property(op); + + val.str= str; + prop= IDP_New(IDP_STRING, 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= 0; + + if ((prop) && (prop->type == IDP_INT)) { + (*value)= prop->data.val; + status= 1; + } + return (status); +} + +int OP_get_float(wmOperator *op, char *name, float *value) +{ + IDProperty *prop= op_get_property(op, name); + int status= 0; + + if ((prop) && (prop->type == IDP_FLOAT)) { + (*value)= *(float*)&prop->data.val; + status= 1; + } + return (status); +} + +int OP_get_int_array(wmOperator *op, char *name, int *array, short *len) +{ + IDProperty *prop= op_get_property(op, name); + short i; + int status= 0; + int *pointer; + + if ((prop) && (prop->type == IDP_ARRAY)) { + pointer= (int *) prop->data.pointer; + + for(i= 0; (i < prop->len) && (i < *len); i++) + array[i]= pointer[i]; + + (*len)= i; + status= 1; + } + return (status); +} + +int OP_get_float_array(wmOperator *op, char *name, float *array, short *len) +{ + IDProperty *prop= op_get_property(op, name); + short i; + float *pointer; + int status= 0; + + if ((prop) && (prop->type == IDP_ARRAY)) { + pointer= (float *) prop->data.pointer; + + for(i= 0; (i < prop->len) && (i < *len); i++) + array[i]= pointer[i]; + + (*len)= i; + status= 1; + } + return (status); +} + +char *OP_get_string(wmOperator *op, char *name) +{ + IDProperty *prop= op_get_property(op, name); + if ((prop) && (prop->type == IDP_STRING)) + return ((char *) prop->data.pointer); + return (NULL); +} + +void OP_verify_int(wmOperator *op, char *name, int value, int *result) +{ + int rvalue; + + if(OP_get_int(op, name, &rvalue)) + value= rvalue; + else + OP_set_int(op, name, value); + + if(result) + *result= value; +} + +void OP_verify_float(wmOperator *op, char *name, float value, int *result) +{ + float rvalue; + + if(OP_get_float(op, name, &rvalue)) + value= rvalue; + else + OP_set_float(op, name, value); + + if(result) + *result= value; +} + +char *OP_verify_string(wmOperator *op, char *name, char *str) +{ + char *result= OP_get_string(op, name); + + if(!result) { + OP_set_string(op, name, str); + result= OP_get_string(op, name); + } + + return result; +} + +void OP_verify_int_array(wmOperator *op, char *name, int *array, short len, int *resultarray, short *resultlen) +{ + int rarray[1]; + short rlen= 1; + + if(resultarray && resultlen) { + if(!OP_get_int_array(op, name, resultarray, &rlen)) { + OP_set_int_array(op, name, array, len); + OP_get_int_array(op, name, resultarray, resultlen); + } + } + else { + if(!OP_get_int_array(op, name, rarray, &rlen)) + OP_set_int_array(op, name, array, len); + } +} + +void OP_verify_float_array(wmOperator *op, char *name, float *array, short len, float *resultarray, short *resultlen) +{ + float rarray[1]; + short rlen= 1; + + if(resultarray && resultlen) { + if(!OP_get_float_array(op, name, resultarray, &rlen)) { + OP_set_float_array(op, name, array, len); + OP_get_float_array(op, name, resultarray, resultlen); + } + } + else { + if(!OP_get_float_array(op, name, rarray, &rlen)) + OP_set_float_array(op, name, array, len); + } +} + + diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 32efa8eb71a..5374592180e 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -236,265 +236,13 @@ void wm_operatortype_init(void) WM_operatortype_append(WM_OT_exit_blender); } -/* ******************************************************* */ - -/* wrapped to get property from a operator. */ -IDProperty *op_get_property(wmOperator *op, char *name) -{ - IDProperty *prop; - - if(!op->properties) - return NULL; - - 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; - val.i = 0; /* silence MSVC warning about uninitialized var when debugging */ - op->properties= IDP_New(IDP_GROUP, val, "property"); -} - -/* ***** Property API, exported ***** */ -void OP_free_property(wmOperator *op) -{ - if(op->properties) { - IDP_FreeProperty(op->properties); - /* - * This need change, when the idprop code only - * need call IDP_FreeProperty. (check BKE_idprop.h) - */ - MEM_freeN(op->properties); - op->properties= NULL; - } -} - -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); -} - -void OP_set_float(wmOperator *op, char *name, float value) -{ - IDPropertyTemplate val; - IDProperty *prop; - - if(!op->properties) - op_init_property(op); - - val.f= value; - prop= IDP_New(IDP_FLOAT, val, name); - IDP_ReplaceInGroup(op->properties, prop); -} - -void OP_set_int_array(wmOperator *op, char *name, int *array, short len) -{ - IDPropertyTemplate val; - IDProperty *prop; - short i; - int *pointer; - - if(!op->properties) - op_init_property(op); - - val.array.len= len; - val.array.type= IDP_INT; - prop= IDP_New(IDP_ARRAY, val, name); - - pointer= (int *)prop->data.pointer; - for(i= 0; i < len; i++) - pointer[i]= array[i]; - IDP_ReplaceInGroup(op->properties, prop); -} - -void OP_set_float_array(wmOperator *op, char *name, float *array, short len) -{ - IDPropertyTemplate val; - IDProperty *prop; - short i; - float *pointer; - - if(!op->properties) - op_init_property(op); - - val.array.len= len; - val.array.type= IDP_FLOAT; - prop= IDP_New(IDP_ARRAY, val, name); - - pointer= (float *) prop->data.pointer; - for(i= 0; i < len; i++) - pointer[i]= array[i]; - IDP_ReplaceInGroup(op->properties, prop); -} - -void OP_set_string(wmOperator *op, char *name, char *str) -{ - IDPropertyTemplate val; - IDProperty *prop; - - if(!op->properties) - op_init_property(op); - - val.str= str; - prop= IDP_New(IDP_STRING, 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= 0; - - if ((prop) && (prop->type == IDP_INT)) { - (*value)= prop->data.val; - status= 1; - } - return (status); -} - -int OP_get_float(wmOperator *op, char *name, float *value) -{ - IDProperty *prop= op_get_property(op, name); - int status= 0; - - if ((prop) && (prop->type == IDP_FLOAT)) { - (*value)= *(float*)&prop->data.val; - status= 1; - } - return (status); -} - -int OP_get_int_array(wmOperator *op, char *name, int *array, short *len) -{ - IDProperty *prop= op_get_property(op, name); - short i; - int status= 0; - int *pointer; - - if ((prop) && (prop->type == IDP_ARRAY)) { - pointer= (int *) prop->data.pointer; - - for(i= 0; (i < prop->len) && (i < *len); i++) - array[i]= pointer[i]; - - (*len)= i; - status= 1; - } - return (status); -} - -int OP_get_float_array(wmOperator *op, char *name, float *array, short *len) -{ - IDProperty *prop= op_get_property(op, name); - short i; - float *pointer; - int status= 0; - - if ((prop) && (prop->type == IDP_ARRAY)) { - pointer= (float *) prop->data.pointer; - - for(i= 0; (i < prop->len) && (i < *len); i++) - array[i]= pointer[i]; - - (*len)= i; - status= 1; - } - return (status); -} - -char *OP_get_string(wmOperator *op, char *name) -{ - IDProperty *prop= op_get_property(op, name); - if ((prop) && (prop->type == IDP_STRING)) - return ((char *) prop->data.pointer); - return (NULL); -} - -void OP_verify_int(wmOperator *op, char *name, int value, int *result) -{ - int rvalue; - - if(OP_get_int(op, name, &rvalue)) - value= rvalue; - else - OP_set_int(op, name, value); - - if(result) - *result= value; -} - -void OP_verify_float(wmOperator *op, char *name, float value, int *result) -{ - float rvalue; - - if(OP_get_float(op, name, &rvalue)) - value= rvalue; - else - OP_set_float(op, name, value); - - if(result) - *result= value; -} - -char *OP_verify_string(wmOperator *op, char *name, char *str) -{ - char *result= OP_get_string(op, name); - - if(!result) { - OP_set_string(op, name, str); - result= OP_get_string(op, name); - } - - return result; -} - -void OP_verify_int_array(wmOperator *op, char *name, int *array, short len, int *resultarray, short *resultlen) -{ - int rarray[1]; - short rlen= 1; - - if(resultarray && resultlen) { - if(!OP_get_int_array(op, name, resultarray, &rlen)) { - OP_set_int_array(op, name, array, len); - OP_get_int_array(op, name, resultarray, resultlen); - } - } - else { - if(!OP_get_int_array(op, name, rarray, &rlen)) - OP_set_int_array(op, name, array, len); - } -} - -void OP_verify_float_array(wmOperator *op, char *name, float *array, short len, float *resultarray, short *resultlen) -{ - float rarray[1]; - short rlen= 1; - - if(resultarray && resultlen) { - if(!OP_get_float_array(op, name, resultarray, &rlen)) { - OP_set_float_array(op, name, array, len); - OP_get_float_array(op, name, resultarray, resultlen); - } - } - else { - if(!OP_get_float_array(op, name, rarray, &rlen)) - OP_set_float_array(op, name, array, len); - } +/* default keymap for windows and screens, only call once per WM */ +void wm_window_keymap(wmWindowManager *wm) +{ + /* note, this doesn't replace existing keymap items */ + WM_keymap_verify_item(&wm->windowkeymap, "WM_OT_window_duplicate", AKEY, KM_PRESS, 0, 0); + WM_keymap_verify_item(&wm->windowkeymap, "WM_OT_save_homefile", UKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_verify_item(&wm->windowkeymap, "WM_OT_window_fullscreen_toggle", FKEY, KM_PRESS, 0, 0); + WM_keymap_verify_item(&wm->windowkeymap, "WM_OT_exit_blender", QKEY, KM_PRESS, KM_CTRL, 0); } diff --git a/source/blender/windowmanager/wm.h b/source/blender/windowmanager/wm.h index 4699374a612..ec9c56f6404 100644 --- a/source/blender/windowmanager/wm.h +++ b/source/blender/windowmanager/wm.h @@ -45,6 +45,7 @@ extern void wm_report_free(wmReport *report); /* wm_operator.c, for init/exit */ void wm_operatortype_free(void); void wm_operatortype_init(void); +void wm_window_keymap(wmWindowManager *wm); /* wm_gesture.c */ void wm_gesture_draw(struct wmWindow *win); |