2009-04-03 23:30:32 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "DNA_anim_types.h"
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
|
|
|
|
#include "BLI_listbase.h"
|
|
|
|
|
|
|
|
#include "BKE_animsys.h"
|
|
|
|
#include "BKE_context.h"
|
|
|
|
#include "BKE_fcurve.h"
|
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
#include "RNA_types.h"
|
|
|
|
|
|
|
|
#include "UI_interface.h"
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
|
|
#include "interface_intern.h"
|
|
|
|
|
|
|
|
void ui_but_anim_flag(uiBut *but, float cfra)
|
|
|
|
{
|
2009-04-10 13:08:12 +00:00
|
|
|
but->flag &= ~(UI_BUT_ANIMATED|UI_BUT_ANIMATED_KEY|UI_BUT_DRIVEN);
|
2009-04-03 23:30:32 +00:00
|
|
|
|
|
|
|
if(but->rnaprop && but->rnapoin.id.data) {
|
|
|
|
AnimData *adt= BKE_animdata_from_id(but->rnapoin.id.data);
|
|
|
|
FCurve *fcu;
|
|
|
|
char *path;
|
|
|
|
|
2009-04-10 13:08:12 +00:00
|
|
|
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) {
|
|
|
|
/* animation takes priority over drivers */
|
|
|
|
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 (on_keyframe_fcurve(fcu, cfra))
|
|
|
|
but->flag |= UI_BUT_ANIMATED_KEY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if not animated, check if driven */
|
|
|
|
if ((but->flag & UI_BUT_ANIMATED)==0 && (adt->drivers.first)) {
|
|
|
|
fcu= list_find_fcurve(&adt->drivers, path, but->rnaindex);
|
|
|
|
|
|
|
|
if (fcu)
|
|
|
|
but->flag |= UI_BUT_DRIVEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
MEM_freeN(path);
|
2009-04-03 23:30:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiAnimContextProperty(const bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop, int *index)
|
|
|
|
{
|
|
|
|
ARegion *ar= CTX_wm_region(C);
|
|
|
|
uiBlock *block;
|
|
|
|
uiBut *but;
|
|
|
|
|
|
|
|
if(ar) {
|
|
|
|
for(block=ar->uiblocks.first; block; block=block->next) {
|
|
|
|
for(but=block->buttons.first; but; but= but->next) {
|
|
|
|
if(but->active && but->rnapoin.id.data) {
|
|
|
|
*ptr= but->rnapoin;
|
|
|
|
*prop= but->rnaprop;
|
|
|
|
*index= but->rnaindex;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ui_but_anim_insert_keyframe(bContext *C)
|
|
|
|
{
|
|
|
|
/* this operator calls uiAnimContextProperty above */
|
|
|
|
WM_operator_name_call(C, "ANIM_OT_insert_keyframe_button", WM_OP_INVOKE_DEFAULT, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ui_but_anim_delete_keyframe(bContext *C)
|
|
|
|
{
|
|
|
|
/* this operator calls uiAnimContextProperty above */
|
|
|
|
WM_operator_name_call(C, "ANIM_OT_delete_keyframe_button", WM_OP_INVOKE_DEFAULT, NULL);
|
|
|
|
}
|
|
|
|
|
2009-04-10 13:08:12 +00:00
|
|
|
void ui_but_anim_add_driver(bContext *C)
|
|
|
|
{
|
|
|
|
/* this operator calls uiAnimContextProperty above */
|
|
|
|
WM_operator_name_call(C, "ANIM_OT_add_driver_button", WM_OP_INVOKE_DEFAULT, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ui_but_anim_remove_driver(bContext *C)
|
|
|
|
{
|
|
|
|
/* this operator calls uiAnimContextProperty above */
|
|
|
|
WM_operator_name_call(C, "ANIM_OT_remove_driver_button", WM_OP_INVOKE_DEFAULT, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: refine the logic for adding/removing drivers...
|
2009-04-03 23:30:32 +00:00
|
|
|
void ui_but_anim_menu(bContext *C, uiBut *but)
|
|
|
|
{
|
2009-04-22 18:39:44 +00:00
|
|
|
uiPopupMenu *pup;
|
|
|
|
uiLayout *layout;
|
2009-04-03 23:30:32 +00:00
|
|
|
int length;
|
|
|
|
|
|
|
|
if(but->rnapoin.data && but->rnaprop) {
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
pup= uiPupMenuBegin(C, RNA_property_ui_name(but->rnaprop), 0);
|
2009-04-22 18:39:44 +00:00
|
|
|
layout= uiPupMenuLayout(pup);
|
2009-05-05 09:56:22 +00:00
|
|
|
|
2009-04-19 13:37:59 +00:00
|
|
|
length= RNA_property_array_length(but->rnaprop);
|
2009-05-05 09:56:22 +00:00
|
|
|
|
2009-04-03 23:30:32 +00:00
|
|
|
if(but->flag & UI_BUT_ANIMATED_KEY) {
|
|
|
|
if(length) {
|
2009-05-05 09:56:22 +00:00
|
|
|
uiItemBooleanO(layout, "Replace Keyframes", 0, "ANIM_OT_insert_keyframe_button", "all", 1);
|
|
|
|
uiItemBooleanO(layout, "Replace Single Keyframe", 0, "ANIM_OT_insert_keyframe_button", "all", 0);
|
2009-04-22 18:39:44 +00:00
|
|
|
uiItemBooleanO(layout, "Delete Keyframes", 0, "ANIM_OT_delete_keyframe_button", "all", 1);
|
|
|
|
uiItemBooleanO(layout, "Delete Single Keyframe", 0, "ANIM_OT_delete_keyframe_button", "all", 0);
|
2009-04-03 23:30:32 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-05-05 09:56:22 +00:00
|
|
|
uiItemBooleanO(layout, "Replace Keyframe", 0, "ANIM_OT_insert_keyframe_button", "all", 0);
|
2009-04-22 18:39:44 +00:00
|
|
|
uiItemBooleanO(layout, "Delete Keyframe", 0, "ANIM_OT_delete_keyframe_button", "all", 0);
|
2009-04-03 23:30:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(RNA_property_animateable(&but->rnapoin, but->rnaprop)) {
|
|
|
|
if(length) {
|
2009-04-22 18:39:44 +00:00
|
|
|
uiItemBooleanO(layout, "Insert Keyframes", 0, "ANIM_OT_insert_keyframe_button", "all", 1);
|
|
|
|
uiItemBooleanO(layout, "Insert Single Keyframe", 0, "ANIM_OT_insert_keyframe_button", "all", 0);
|
2009-05-05 09:56:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
uiItemBooleanO(layout, "Insert Keyframe", 0, "ANIM_OT_insert_keyframe_button", "all", 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(but->flag & UI_BUT_DRIVEN) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
uiItemBooleanO(layout, "Remove Driver", 0, "ANIM_OT_remove_driver_button", "all", 0);
|
|
|
|
}
|
|
|
|
else if(RNA_property_animateable(&but->rnapoin, but->rnaprop)) {
|
|
|
|
uiItemS(layout);
|
|
|
|
|
|
|
|
if(length) {
|
2009-04-22 18:39:44 +00:00
|
|
|
uiItemBooleanO(layout, "Add Driver", 0, "ANIM_OT_add_driver_button", "all", 1);
|
|
|
|
uiItemBooleanO(layout, "Add Single Driver", 0, "ANIM_OT_add_driver_button", "all", 0);
|
2009-04-03 23:30:32 +00:00
|
|
|
}
|
2009-05-05 09:56:22 +00:00
|
|
|
else
|
2009-04-22 18:39:44 +00:00
|
|
|
uiItemBooleanO(layout, "Add Driver", 0, "ANIM_OT_add_driver_button", "all", 0);
|
2009-04-03 23:30:32 +00:00
|
|
|
}
|
|
|
|
|
2009-04-22 18:39:44 +00:00
|
|
|
uiPupMenuEnd(C, pup);
|
2009-04-03 23:30:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|