diff options
-rw-r--r-- | source/blender/editors/animation/anim_intern.h | 2 | ||||
-rw-r--r-- | source/blender/editors/animation/anim_ops.c | 2 | ||||
-rw-r--r-- | source/blender/editors/animation/drivers.c | 43 | ||||
-rw-r--r-- | source/blender/editors/include/UI_interface.h | 3 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 9 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_ops.c | 234 | ||||
-rw-r--r-- | source/blender/makesrna/RNA_access.h | 13 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 125 |
8 files changed, 380 insertions, 51 deletions
diff --git a/source/blender/editors/animation/anim_intern.h b/source/blender/editors/animation/anim_intern.h index bc4f528d43f..2d363a52248 100644 --- a/source/blender/editors/animation/anim_intern.h +++ b/source/blender/editors/animation/anim_intern.h @@ -79,6 +79,4 @@ void ANIM_OT_driver_button_remove(struct wmOperatorType *ot); void ANIM_OT_copy_driver_button(struct wmOperatorType *ot); void ANIM_OT_paste_driver_button(struct wmOperatorType *ot); -void ANIM_OT_copy_clipboard_button(struct wmOperatorType *ot); - #endif // ANIM_INTERN_H diff --git a/source/blender/editors/animation/anim_ops.c b/source/blender/editors/animation/anim_ops.c index 6aa638b1ada..9544bb70855 100644 --- a/source/blender/editors/animation/anim_ops.c +++ b/source/blender/editors/animation/anim_ops.c @@ -362,8 +362,6 @@ void ED_operatortypes_anim(void) WM_operatortype_append(ANIM_OT_driver_button_remove); WM_operatortype_append(ANIM_OT_copy_driver_button); WM_operatortype_append(ANIM_OT_paste_driver_button); - - WM_operatortype_append(ANIM_OT_copy_clipboard_button); WM_operatortype_append(ANIM_OT_keyingset_button_add); diff --git a/source/blender/editors/animation/drivers.c b/source/blender/editors/animation/drivers.c index bc7005b82c4..59e52c0d489 100644 --- a/source/blender/editors/animation/drivers.c +++ b/source/blender/editors/animation/drivers.c @@ -581,47 +581,4 @@ void ANIM_OT_paste_driver_button (wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } - -/* Copy to Clipboard Button Operator ------------------------ */ - -static int copy_clipboard_button_exec(bContext *C, wmOperator *op) -{ - PointerRNA ptr; - PropertyRNA *prop= NULL; - char *path; - short success= 0; - int index; - - /* try to create driver using property retrieved from UI */ - memset(&ptr, 0, sizeof(PointerRNA)); - uiAnimContextProperty(C, &ptr, &prop, &index); - - if (ptr.data && prop) { - path= RNA_path_from_ID_to_property(&ptr, prop); - - if (path) { - WM_clipboard_text_set(path, FALSE); - MEM_freeN(path); - } - } - - /* since we're just copying, we don't really need to do anything else...*/ - return (success)? OPERATOR_FINISHED: OPERATOR_CANCELLED; -} - -void ANIM_OT_copy_clipboard_button(wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "Copy Data Path"; - ot->idname= "ANIM_OT_copy_clipboard_button"; - ot->description= "Copy the RNA data path for this property to the clipboard."; - - /* callbacks */ - ot->exec= copy_clipboard_button_exec; - //op->poll= ??? // TODO: need to have some valid property before this can be done - - /* flags */ - ot->flag= OPTYPE_REGISTER; -} - /* ************************************************** */ diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 5b512da55c9..f0e52a13d3f 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -688,6 +688,9 @@ void uiItemMenuF(uiLayout *layout, char *name, int icon, uiMenuCreateFunc func, void uiItemMenuEnumO(uiLayout *layout, char *name, int icon, char *opname, char *propname); void uiItemMenuEnumR(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr, char *propname); +/* UI Operators */ +void ui_buttons_operatortypes(void); + /* Helpers for Operators */ void uiAnimContextProperty(const struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop, int *index); void uiFileBrowseContextProperty(const struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop); diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index a43506778d8..9604704dde8 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -3499,9 +3499,14 @@ static int ui_but_menu(bContext *C, uiBut *but) //Copy Property Value //Paste Property Value - //uiItemO(layout, "Reset to Default Value", 0, "WM_OT_property_value_reset_button"); + if(length) { + uiItemBooleanO(layout, "Reset All to Default Values", 0, "UI_OT_reset_default_button", "all", 1); + uiItemBooleanO(layout, "Reset Single to Default Value", 0, "UI_OT_reset_default_button", "all", 0); + } + else + uiItemO(layout, "Reset to Default Value", 0, "UI_OT_reset_default_button"); - uiItemO(layout, "Copy Data Path", 0, "ANIM_OT_copy_clipboard_button"); + uiItemO(layout, "Copy Data Path", 0, "UI_OT_copy_clipboard_button"); uiItemS(layout); } diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c new file mode 100644 index 00000000000..a5caf1c930b --- /dev/null +++ b/source/blender/editors/interface/interface_ops.c @@ -0,0 +1,234 @@ +/** + * $Id: interface_ops.c 24699 2009-11-20 10:21:31Z aligorith $ + * + * ***** 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) 2009 Blender Foundation. + * All rights reserved. + * + * Contributor(s): Blender Foundation, Joshua Leung + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include <stdio.h> +#include <math.h> +#include <string.h> + + +#include "MEM_guardedalloc.h" + +#include "DNA_scene_types.h" +#include "DNA_screen_types.h" +#include "DNA_space_types.h" +#include "DNA_userdef_types.h" +#include "DNA_vec_types.h" +#include "DNA_view2d_types.h" + +#include "BLI_blenlib.h" + +#include "BKE_context.h" +#include "BKE_utildefines.h" + +#include "RNA_access.h" +#include "RNA_define.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "BIF_gl.h" + +#include "ED_screen.h" + +#include "UI_interface.h" +#include "UI_resources.h" + +/* ********************************************************** */ + +/* Copy to Clipboard Button Operator ------------------------ */ + +static int copy_clipboard_button_exec(bContext *C, wmOperator *op) +{ + PointerRNA ptr; + PropertyRNA *prop= NULL; + char *path; + short success= 0; + int index; + + /* try to create driver using property retrieved from UI */ + memset(&ptr, 0, sizeof(PointerRNA)); + uiAnimContextProperty(C, &ptr, &prop, &index); + + if (ptr.data && prop) { + path= RNA_path_from_ID_to_property(&ptr, prop); + + if (path) { + WM_clipboard_text_set(path, FALSE); + MEM_freeN(path); + } + } + + /* since we're just copying, we don't really need to do anything else...*/ + return (success)? OPERATOR_FINISHED: OPERATOR_CANCELLED; +} + +void UI_OT_copy_clipboard_button(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Copy Data Path"; + ot->idname= "UI_OT_copy_clipboard_button"; + ot->description= "Copy the RNA data path for this property to the clipboard."; + + /* callbacks */ + ot->exec= copy_clipboard_button_exec; + //op->poll= ??? // TODO: need to have some valid property before this can be done + + /* flags */ + ot->flag= OPTYPE_REGISTER; +} + +/* Reset to Default Values Button Operator ------------------------ */ + +static int reset_default_button_exec(bContext *C, wmOperator *op) +{ + PointerRNA ptr; + PropertyRNA *prop= NULL; + short success= 0; + int index, len; + int all = RNA_boolean_get(op->ptr, "all"); + + /* try to reset the nominated setting to its default value */ + memset(&ptr, 0, sizeof(PointerRNA)); + uiAnimContextProperty(C, &ptr, &prop, &index); + + /* if there is a valid property that is editable... */ + if (ptr.data && prop && RNA_property_editable(&ptr, prop)) { + /* get the length of the array to work with */ + len= RNA_property_array_length(&ptr, prop); + + /* get and set the default values as appropriate for the various types */ + switch (RNA_property_type(prop)) { + case PROP_BOOLEAN: + if (len) { + if (all) { + int *tmparray= MEM_callocN(sizeof(int)*len, "reset_defaults - boolean"); + + RNA_property_boolean_get_default_array(&ptr, prop, tmparray); + RNA_property_boolean_set_array(&ptr, prop, tmparray); + + MEM_freeN(tmparray); + } + else { + int value= RNA_property_boolean_get_default_index(&ptr, prop, index); + RNA_property_boolean_set_index(&ptr, prop, index, value); + } + } + else { + int value= RNA_property_boolean_get_default(&ptr, prop); + RNA_property_boolean_set(&ptr, prop, value); + } + break; + case PROP_INT: + if (len) { + if (all) { + int *tmparray= MEM_callocN(sizeof(int)*len, "reset_defaults - int"); + + RNA_property_int_get_default_array(&ptr, prop, tmparray); + RNA_property_int_set_array(&ptr, prop, tmparray); + + MEM_freeN(tmparray); + } + else { + int value= RNA_property_int_get_default_index(&ptr, prop, index); + RNA_property_int_set_index(&ptr, prop, index, value); + } + } + else { + int value= RNA_property_int_get_default(&ptr, prop); + RNA_property_int_set(&ptr, prop, value); + } + break; + case PROP_FLOAT: + if (len) { + if (all) { + float *tmparray= MEM_callocN(sizeof(float)*len, "reset_defaults - float"); + + RNA_property_float_get_default_array(&ptr, prop, tmparray); + RNA_property_float_set_array(&ptr, prop, tmparray); + + MEM_freeN(tmparray); + } + else { + float value= RNA_property_float_get_default_index(&ptr, prop, index); + RNA_property_float_set_index(&ptr, prop, index, value); + } + } + else { + float value= RNA_property_float_get_default(&ptr, prop); + RNA_property_float_set(&ptr, prop, value); + } + break; + case PROP_ENUM: + { + int value= RNA_property_enum_get_default(&ptr, prop); + RNA_property_enum_set(&ptr, prop, value); + } + break; + + //case PROP_POINTER: + //case PROP_STRING: + default: + // FIXME: many of the other types such as strings and pointers need this implemented too! + break; + } + + /* perform updates required for this property */ + RNA_property_update(C, &ptr, prop); + + success= 1; + } + + return (success)? OPERATOR_FINISHED: OPERATOR_CANCELLED; +} + +void UI_OT_reset_default_button(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Reset to Default Value"; + ot->idname= "UI_OT_reset_default_button"; + ot->description= "Copy the RNA data path for this property to the clipboard."; + + /* callbacks */ + ot->exec= reset_default_button_exec; + //op->poll= ??? // TODO: need to have some valid property before this can be done + + /* flags */ + ot->flag= OPTYPE_REGISTER; + + /* properties */ + RNA_def_boolean(ot->srna, "all", 1, "All", "Reset to default values all elements of the array."); +} + +/* ********************************************************* */ +/* Registration */ + +void ui_buttons_operatortypes(void) +{ + WM_operatortype_append(UI_OT_copy_clipboard_button); + WM_operatortype_append(UI_OT_reset_default_button); +} + diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index edbe55ba11d..188c6b2474b 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -660,6 +660,9 @@ void RNA_property_boolean_get_array(PointerRNA *ptr, PropertyRNA *prop, int *val int RNA_property_boolean_get_index(PointerRNA *ptr, PropertyRNA *prop, int index); void RNA_property_boolean_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *values); void RNA_property_boolean_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, int value); +int RNA_property_boolean_get_default(PointerRNA *ptr, PropertyRNA *prop); +void RNA_property_boolean_get_default_array(PointerRNA *ptr, PropertyRNA *prop, int *values); +int RNA_property_boolean_get_default_index(PointerRNA *ptr, PropertyRNA *prop, int index); int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop); void RNA_property_int_set(PointerRNA *ptr, PropertyRNA *prop, int value); @@ -667,6 +670,9 @@ void RNA_property_int_get_array(PointerRNA *ptr, PropertyRNA *prop, int *values) int RNA_property_int_get_index(PointerRNA *ptr, PropertyRNA *prop, int index); void RNA_property_int_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *values); void RNA_property_int_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, int value); +int RNA_property_int_get_default(PointerRNA *ptr, PropertyRNA *prop); +void RNA_property_int_get_default_array(PointerRNA *ptr, PropertyRNA *prop, int *values); +int RNA_property_int_get_default_index(PointerRNA *ptr, PropertyRNA *prop, int index); float RNA_property_float_get(PointerRNA *ptr, PropertyRNA *prop); void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value); @@ -674,17 +680,22 @@ void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *val float RNA_property_float_get_index(PointerRNA *ptr, PropertyRNA *prop, int index); void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const float *values); void RNA_property_float_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, float value); +float RNA_property_float_get_default(PointerRNA *ptr, PropertyRNA *prop); +void RNA_property_float_get_default_array(PointerRNA *ptr, PropertyRNA *prop, float *values); +float RNA_property_float_get_default_index(PointerRNA *ptr, PropertyRNA *prop, int index); void RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop, char *value); char *RNA_property_string_get_alloc(PointerRNA *ptr, PropertyRNA *prop, char *fixedbuf, int fixedlen); int RNA_property_string_length(PointerRNA *ptr, PropertyRNA *prop); -void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *value); +// TODO: get default strings... int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop); void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value); +int RNA_property_enum_get_default(PointerRNA *ptr, PropertyRNA *prop); PointerRNA RNA_property_pointer_get(PointerRNA *ptr, PropertyRNA *prop); void RNA_property_pointer_set(PointerRNA *ptr, PropertyRNA *prop, PointerRNA ptr_value); +// TODO: get default pointers... void RNA_property_collection_begin(PointerRNA *ptr, PropertyRNA *prop, CollectionPropertyIterator *iter); void RNA_property_collection_next(CollectionPropertyIterator *iter); diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 68499ebd42c..53f5407e521 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -1276,6 +1276,45 @@ void RNA_property_boolean_set_index(PointerRNA *ptr, PropertyRNA *prop, int inde } } +int RNA_property_boolean_get_default(PointerRNA *ptr, PropertyRNA *prop) +{ + BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop; + return bprop->defaultvalue; +} + +void RNA_property_boolean_get_default_array(PointerRNA *ptr, PropertyRNA *prop, int *values) +{ + BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop; + + if(prop->arraydimension == 0) + values[0]= bprop->defaultvalue; + else if(bprop->defaultarray) + memcpy(values, bprop->defaultarray, sizeof(int)*prop->totarraylength); + else + memset(values, 0, sizeof(int)*prop->totarraylength); +} + +int RNA_property_boolean_get_default_index(PointerRNA *ptr, PropertyRNA *prop, int index) +{ + int tmp[RNA_MAX_ARRAY_LENGTH]; + int len= rna_ensure_property_array_length(ptr, prop); + + if(len <= RNA_MAX_ARRAY_LENGTH) { + RNA_property_boolean_get_default_array(ptr, prop, tmp); + return tmp[index]; + } + else { + int *tmparray, value; + + tmparray= MEM_callocN(sizeof(int)*len, "RNA_property_boolean_get_default_index"); + RNA_property_boolean_get_default_array(ptr, prop, tmparray); + value= tmparray[index]; + MEM_freeN(tmparray); + + return value; + } +} + int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop) { IntPropertyRNA *iprop= (IntPropertyRNA*)prop; @@ -1404,6 +1443,45 @@ void RNA_property_int_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, i } } +int RNA_property_int_get_default(PointerRNA *ptr, PropertyRNA *prop) +{ + IntPropertyRNA *iprop= (IntPropertyRNA*)prop; + return iprop->defaultvalue; +} + +void RNA_property_int_get_default_array(PointerRNA *ptr, PropertyRNA *prop, int *values) +{ + IntPropertyRNA *iprop= (IntPropertyRNA*)prop; + + if(prop->arraydimension == 0) + values[0]= iprop->defaultvalue; + else if(iprop->defaultarray) + memcpy(values, iprop->defaultarray, sizeof(int)*prop->totarraylength); + else + memset(values, 0, sizeof(int)*prop->totarraylength); +} + +int RNA_property_int_get_default_index(PointerRNA *ptr, PropertyRNA *prop, int index) +{ + int tmp[RNA_MAX_ARRAY_LENGTH]; + int len= rna_ensure_property_array_length(ptr, prop); + + if(len <= RNA_MAX_ARRAY_LENGTH) { + RNA_property_int_get_default_array(ptr, prop, tmp); + return tmp[index]; + } + else { + int *tmparray, value; + + tmparray= MEM_callocN(sizeof(int)*len, "RNA_property_int_get_default_index"); + RNA_property_int_get_default_array(ptr, prop, tmparray); + value= tmparray[index]; + MEM_freeN(tmparray); + + return value; + } +} + float RNA_property_float_get(PointerRNA *ptr, PropertyRNA *prop) { FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop; @@ -1559,6 +1637,45 @@ void RNA_property_float_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, } } +float RNA_property_float_get_default(PointerRNA *ptr, PropertyRNA *prop) +{ + FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop; + return fprop->defaultvalue; +} + +void RNA_property_float_get_default_array(PointerRNA *ptr, PropertyRNA *prop, float *values) +{ + FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop; + + if(prop->arraydimension == 0) + values[0]= fprop->defaultvalue; + else if(fprop->defaultarray) + memcpy(values, fprop->defaultarray, sizeof(float)*prop->totarraylength); + else + memset(values, 0, sizeof(float)*prop->totarraylength); +} + +float RNA_property_float_get_default_index(PointerRNA *ptr, PropertyRNA *prop, int index) +{ + float tmp[RNA_MAX_ARRAY_LENGTH]; + int len= rna_ensure_property_array_length(ptr, prop); + + if(len <= RNA_MAX_ARRAY_LENGTH) { + RNA_property_float_get_default_array(ptr, prop, tmp); + return tmp[index]; + } + else { + float *tmparray, value; + + tmparray= MEM_callocN(sizeof(float)*len, "RNA_property_float_get_default_index"); + RNA_property_float_get_default_array(ptr, prop, tmparray); + value= tmparray[index]; + MEM_freeN(tmparray); + + return value; + } +} + void RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop, char *value) { StringPropertyRNA *sprop= (StringPropertyRNA*)prop; @@ -1637,7 +1754,6 @@ int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop) return eprop->defaultvalue; } - void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value) { EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop; @@ -1660,6 +1776,13 @@ void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value) } } +int RNA_property_enum_get_default(PointerRNA *ptr, PropertyRNA *prop) +{ + EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop; + return eprop->defaultvalue; +} + + PointerRNA RNA_property_pointer_get(PointerRNA *ptr, PropertyRNA *prop) { PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop; |