Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/animation/drivers.c
| Show First 20 Lines • Show All 431 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| PointerRNA ptr = {{NULL}}; | PointerRNA ptr = {{NULL}}; | ||||
| PropertyRNA *prop = NULL; | PropertyRNA *prop = NULL; | ||||
| int success = 0; | int success = 0; | ||||
| int index; | int index; | ||||
| const bool all = RNA_boolean_get(op->ptr, "all"); | const bool all = RNA_boolean_get(op->ptr, "all"); | ||||
| /* try to create driver using property retrieved from UI */ | /* try to create driver using property retrieved from UI */ | ||||
| uiContextActiveProperty(C, &ptr, &prop, &index); | UI_context_active_but_prop_get(C, &ptr, &prop, &index); | ||||
| if (all) | if (all) | ||||
| index = -1; | index = -1; | ||||
| if (ptr.id.data && ptr.data && prop && RNA_property_animateable(&ptr, prop)) { | if (ptr.id.data && ptr.data && prop && RNA_property_animateable(&ptr, prop)) { | ||||
| char *path = BKE_animdata_driver_path_hack(C, &ptr, prop, NULL); | char *path = BKE_animdata_driver_path_hack(C, &ptr, prop, NULL); | ||||
| short flags = CREATEDRIVER_WITH_DEFAULT_DVAR; | short flags = CREATEDRIVER_WITH_DEFAULT_DVAR; | ||||
| if (path) { | if (path) { | ||||
| success += ANIM_add_driver(op->reports, ptr.id.data, path, index, flags, DRIVER_TYPE_PYTHON); | success += ANIM_add_driver(op->reports, ptr.id.data, path, index, flags, DRIVER_TYPE_PYTHON); | ||||
| MEM_freeN(path); | MEM_freeN(path); | ||||
| } | } | ||||
| } | } | ||||
| if (success) { | if (success) { | ||||
| /* send updates */ | /* send updates */ | ||||
| uiContextAnimUpdate(C); | UI_context_update_anim_flag(C); | ||||
| WM_event_add_notifier(C, NC_ANIMATION | ND_FCURVES_ORDER, NULL); // XXX | WM_event_add_notifier(C, NC_ANIMATION | ND_FCURVES_ORDER, NULL); // XXX | ||||
| } | } | ||||
| return (success) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; | return (success) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; | ||||
| } | } | ||||
| void ANIM_OT_driver_button_add(wmOperatorType *ot) | void ANIM_OT_driver_button_add(wmOperatorType *ot) | ||||
| Show All 20 Lines | |||||
| { | { | ||||
| PointerRNA ptr = {{NULL}}; | PointerRNA ptr = {{NULL}}; | ||||
| PropertyRNA *prop = NULL; | PropertyRNA *prop = NULL; | ||||
| short success = 0; | short success = 0; | ||||
| int index; | int index; | ||||
| const bool all = RNA_boolean_get(op->ptr, "all"); | const bool all = RNA_boolean_get(op->ptr, "all"); | ||||
| /* try to find driver using property retrieved from UI */ | /* try to find driver using property retrieved from UI */ | ||||
| uiContextActiveProperty(C, &ptr, &prop, &index); | UI_context_active_but_prop_get(C, &ptr, &prop, &index); | ||||
| if (all) | if (all) | ||||
| index = -1; | index = -1; | ||||
| if (ptr.id.data && ptr.data && prop) { | if (ptr.id.data && ptr.data && prop) { | ||||
| char *path = BKE_animdata_driver_path_hack(C, &ptr, prop, NULL); | char *path = BKE_animdata_driver_path_hack(C, &ptr, prop, NULL); | ||||
| success = ANIM_remove_driver(op->reports, ptr.id.data, path, index, 0); | success = ANIM_remove_driver(op->reports, ptr.id.data, path, index, 0); | ||||
| MEM_freeN(path); | MEM_freeN(path); | ||||
| } | } | ||||
| if (success) { | if (success) { | ||||
| /* send updates */ | /* send updates */ | ||||
| uiContextAnimUpdate(C); | UI_context_update_anim_flag(C); | ||||
| WM_event_add_notifier(C, NC_ANIMATION | ND_FCURVES_ORDER, NULL); // XXX | WM_event_add_notifier(C, NC_ANIMATION | ND_FCURVES_ORDER, NULL); // XXX | ||||
| } | } | ||||
| return (success) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; | return (success) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; | ||||
| } | } | ||||
| void ANIM_OT_driver_button_remove(wmOperatorType *ot) | void ANIM_OT_driver_button_remove(wmOperatorType *ot) | ||||
| Show All 19 Lines | |||||
| static int copy_driver_button_exec(bContext *C, wmOperator *op) | static int copy_driver_button_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| PointerRNA ptr = {{NULL}}; | PointerRNA ptr = {{NULL}}; | ||||
| PropertyRNA *prop = NULL; | PropertyRNA *prop = NULL; | ||||
| short success = 0; | short success = 0; | ||||
| int index; | int index; | ||||
| /* try to create driver using property retrieved from UI */ | /* try to create driver using property retrieved from UI */ | ||||
| uiContextActiveProperty(C, &ptr, &prop, &index); | UI_context_active_but_prop_get(C, &ptr, &prop, &index); | ||||
| if (ptr.id.data && ptr.data && prop && RNA_property_animateable(&ptr, prop)) { | if (ptr.id.data && ptr.data && prop && RNA_property_animateable(&ptr, prop)) { | ||||
| char *path = BKE_animdata_driver_path_hack(C, &ptr, prop, NULL); | char *path = BKE_animdata_driver_path_hack(C, &ptr, prop, NULL); | ||||
| if (path) { | if (path) { | ||||
| /* only copy the driver for the button that this was involved for */ | /* only copy the driver for the button that this was involved for */ | ||||
| success = ANIM_copy_driver(op->reports, ptr.id.data, path, index, 0); | success = ANIM_copy_driver(op->reports, ptr.id.data, path, index, 0); | ||||
| uiContextAnimUpdate(C); | UI_context_update_anim_flag(C); | ||||
| MEM_freeN(path); | MEM_freeN(path); | ||||
| } | } | ||||
| } | } | ||||
| /* since we're just copying, we don't really need to do anything else...*/ | /* since we're just copying, we don't really need to do anything else...*/ | ||||
| return (success) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; | return (success) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; | ||||
| } | } | ||||
| Show All 18 Lines | |||||
| static int paste_driver_button_exec(bContext *C, wmOperator *op) | static int paste_driver_button_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| PointerRNA ptr = {{NULL}}; | PointerRNA ptr = {{NULL}}; | ||||
| PropertyRNA *prop = NULL; | PropertyRNA *prop = NULL; | ||||
| short success = 0; | short success = 0; | ||||
| int index; | int index; | ||||
| /* try to create driver using property retrieved from UI */ | /* try to create driver using property retrieved from UI */ | ||||
| uiContextActiveProperty(C, &ptr, &prop, &index); | UI_context_active_but_prop_get(C, &ptr, &prop, &index); | ||||
| if (ptr.id.data && ptr.data && prop && RNA_property_animateable(&ptr, prop)) { | if (ptr.id.data && ptr.data && prop && RNA_property_animateable(&ptr, prop)) { | ||||
| char *path = BKE_animdata_driver_path_hack(C, &ptr, prop, NULL); | char *path = BKE_animdata_driver_path_hack(C, &ptr, prop, NULL); | ||||
| if (path) { | if (path) { | ||||
| /* only copy the driver for the button that this was involved for */ | /* only copy the driver for the button that this was involved for */ | ||||
| success = ANIM_paste_driver(op->reports, ptr.id.data, path, index, 0); | success = ANIM_paste_driver(op->reports, ptr.id.data, path, index, 0); | ||||
| uiContextAnimUpdate(C); | UI_context_update_anim_flag(C); | ||||
| MEM_freeN(path); | MEM_freeN(path); | ||||
| } | } | ||||
| } | } | ||||
| /* since we're just copying, we don't really need to do anything else...*/ | /* since we're just copying, we don't really need to do anything else...*/ | ||||
| return (success) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; | return (success) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; | ||||
| } | } | ||||
| Show All 17 Lines | |||||