diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-07-12 06:06:15 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-07-12 06:06:15 +0400 |
commit | 3116062a828e24ed2e91c219ab338a38030f2f42 (patch) | |
tree | fe77a0722deaee3afd521b4a596bbe5c1c827b2e /source/blender/editors/interface/interface_anim.c | |
parent | 8b9bb47a3faf753cb0ca2ec0e9c6a741c7af31c2 (diff) |
2.5: Couple of small fun features
* Text window font size now supports full range 8-32, instead of
just 12 and 15. I added BLF_fixed_width to get the character
width of a fixed size font.
* Buttons do undo push on change again.
* Animated/Keyframe/Driver colors are now themable, with blend
value to blend with original color. Set this to 0.5 now to
give colors less constrast.
* Fix tooltip popping up with RMB menu open, and missing redraw.
* Autokeyframe now works for buttons.
* Driver expressions can be edited in place in a button now.
(still some refresh issues).
* Also made python driver default for the Add Driver function
in the RMB button. This way you don't have to open a Graph
editor if you just want to type an expression. Also, the
default expression then is the current value.
* Tooltips now show some extra info, not sure what is good to
have, but currently I added:
* Shortcut key for operator buttons.
* Python struct & property name for RNA buttons.
* Expression for driven values.
* Value for text/search/pointer buttons.
Diffstat (limited to 'source/blender/editors/interface/interface_anim.c')
-rw-r--r-- | source/blender/editors/interface/interface_anim.c | 141 |
1 files changed, 115 insertions, 26 deletions
diff --git a/source/blender/editors/interface/interface_anim.c b/source/blender/editors/interface/interface_anim.c index 7c439f408ba..4a2ef50a31b 100644 --- a/source/blender/editors/interface/interface_anim.c +++ b/source/blender/editors/interface/interface_anim.c @@ -10,6 +10,7 @@ #include "DNA_screen_types.h" #include "BLI_listbase.h" +#include "BLI_string.h" #include "BKE_animsys.h" #include "BKE_context.h" @@ -27,49 +28,135 @@ #include "interface_intern.h" -void ui_but_anim_flag(uiBut *but, float cfra) +static FCurve *ui_but_get_fcurve(uiBut *but, bAction **action, int *driven) { - but->flag &= ~(UI_BUT_ANIMATED|UI_BUT_ANIMATED_KEY|UI_BUT_DRIVEN); - + FCurve *fcu= NULL; + + *driven= 0; + /* there must be some RNA-pointer + property combo for this button */ - if (but->rnaprop && but->rnapoin.id.data && + if(but->rnaprop && but->rnapoin.id.data && RNA_property_animateable(&but->rnapoin, but->rnaprop)) { AnimData *adt= BKE_animdata_from_id(but->rnapoin.id.data); - FCurve *fcu; char *path; - if (adt) { - if ((adt->action && adt->action->curves.first) || (adt->drivers.first)) { + if(adt) { + if((adt->action && adt->action->curves.first) || (adt->drivers.first)) { /* XXX this function call can become a performance bottleneck */ path= RNA_path_from_ID_to_property(&but->rnapoin, but->rnaprop); - - if (path) { + + if(path) { /* animation takes priority over drivers */ - if (adt->action && adt->action->curves.first) { + if(adt->action && adt->action->curves.first) fcu= list_find_fcurve(&adt->action->curves, path, but->rnaindex); - - if (fcu) { - but->flag |= UI_BUT_ANIMATED; - - if (fcurve_frame_has_keyframe(fcu, cfra, 0)) - but->flag |= UI_BUT_ANIMATED_KEY; - } - } /* if not animated, check if driven */ - if ((but->flag & UI_BUT_ANIMATED)==0 && (adt->drivers.first)) { + if(!fcu && (adt->drivers.first)) { fcu= list_find_fcurve(&adt->drivers, path, but->rnaindex); - if (fcu) - but->flag |= UI_BUT_DRIVEN; + if(fcu) + *driven= 1; } - + + if(fcu && action) + *action= adt->action; + MEM_freeN(path); } } } } + + return fcu; +} + +void ui_but_anim_flag(uiBut *but, float cfra) +{ + FCurve *fcu; + int driven; + + but->flag &= ~(UI_BUT_ANIMATED|UI_BUT_ANIMATED_KEY|UI_BUT_DRIVEN); + + fcu= ui_but_get_fcurve(but, NULL, &driven); + + if(fcu) { + if(!driven) { + but->flag |= UI_BUT_ANIMATED; + + if(fcurve_frame_has_keyframe(fcu, cfra, 0)) + but->flag |= UI_BUT_ANIMATED_KEY; + } + else { + but->flag |= UI_BUT_DRIVEN; + } + } +} + +int ui_but_anim_expression_get(uiBut *but, char *str, int maxlen) +{ + FCurve *fcu; + ChannelDriver *driver; + int driven; + + fcu= ui_but_get_fcurve(but, NULL, &driven); + + if(fcu && driven) { + driver= fcu->driver; + + if(driver && driver->type == DRIVER_TYPE_PYTHON) { + BLI_strncpy(str, driver->expression, maxlen); + return 1; + } + } + + return 0; +} + +int ui_but_anim_expression_set(uiBut *but, const char *str) +{ + FCurve *fcu; + ChannelDriver *driver; + int driven; + + fcu= ui_but_get_fcurve(but, NULL, &driven); + + if(fcu && driven) { + driver= fcu->driver; + + if(driver && driver->type == DRIVER_TYPE_PYTHON) { + BLI_strncpy(driver->expression, str, sizeof(driver->expression)); + return 1; + } + } + + return 0; +} + +void ui_but_anim_autokey(uiBut *but, Scene *scene, float cfra) +{ + ID *id; + bAction *action; + FCurve *fcu; + int driven; + + fcu= ui_but_get_fcurve(but, &action, &driven); + + if(fcu && !driven) { + id= but->rnapoin.id.data; + + if(autokeyframe_cfra_can_key(scene, id)) { + short flag = 0; + + if (IS_AUTOKEY_FLAG(INSERTNEEDED)) + flag |= INSERTKEY_NEEDED; + if (IS_AUTOKEY_FLAG(AUTOMATKEY)) + flag |= INSERTKEY_MATRIX; + + fcu->flag &= ~FCURVE_SELECTED; + insert_keyframe(id, action, ((fcu->grp)?(fcu->grp->name):(NULL)), fcu->rna_path, fcu->array_index, cfra, flag); + } + } } void uiAnimContextProperty(const bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop, int *index) @@ -140,6 +227,7 @@ void ui_but_anim_menu(bContext *C, uiBut *but) uiItemBooleanO(layout, "Delete Keyframe", 0, "ANIM_OT_delete_keyframe_button", "all", 0); } } + else if(but->flag & UI_BUT_DRIVEN); else if(RNA_property_animateable(&but->rnapoin, but->rnaprop)) { if(length) { uiItemBooleanO(layout, "Insert Keyframes", 0, "ANIM_OT_insert_keyframe_button", "all", 1); @@ -153,17 +241,18 @@ void ui_but_anim_menu(bContext *C, uiBut *but) uiItemS(layout); if(length) { - uiItemBooleanO(layout, "Remove Driver", 0, "ANIM_OT_remove_driver_button", "all", 1); - uiItemBooleanO(layout, "Remove Single Driver", 0, "ANIM_OT_remove_driver_button", "all", 0); + uiItemBooleanO(layout, "Delete Drivers", 0, "ANIM_OT_remove_driver_button", "all", 1); + uiItemBooleanO(layout, "Delete Single Driver", 0, "ANIM_OT_remove_driver_button", "all", 0); } else - uiItemBooleanO(layout, "Remove Driver", 0, "ANIM_OT_remove_driver_button", "all", 0); + uiItemBooleanO(layout, "Delete Driver", 0, "ANIM_OT_remove_driver_button", "all", 0); } + else if(but->flag & UI_BUT_ANIMATED_KEY); else if(RNA_property_animateable(&but->rnapoin, but->rnaprop)) { uiItemS(layout); if(length) { - uiItemBooleanO(layout, "Add Driver", 0, "ANIM_OT_add_driver_button", "all", 1); + uiItemBooleanO(layout, "Add Drivers", 0, "ANIM_OT_add_driver_button", "all", 1); uiItemBooleanO(layout, "Add Single Driver", 0, "ANIM_OT_add_driver_button", "all", 0); } else |