remove unused includes
[blender-staging.git] / source / blender / editors / interface / interface_anim.c
1
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5
6 #include "MEM_guardedalloc.h"
7
8 #include "DNA_anim_types.h"
9 #include "DNA_scene_types.h"
10 #include "DNA_screen_types.h"
11
12 #include "BLI_listbase.h"
13 #include "BLI_string.h"
14
15 #include "BKE_context.h"
16 #include "BKE_fcurve.h"
17
18
19 #include "ED_keyframing.h"
20
21 #include "UI_interface.h"
22
23 #include "WM_api.h"
24 #include "WM_types.h"
25
26 #include "interface_intern.h"
27
28 static FCurve *ui_but_get_fcurve(uiBut *but, bAction **action, int *driven)
29 {
30         return rna_get_fcurve(&but->rnapoin, but->rnaprop, but->rnaindex, action, driven);
31 }
32
33 void ui_but_anim_flag(uiBut *but, float cfra)
34 {
35         FCurve *fcu;
36         int driven;
37
38         but->flag &= ~(UI_BUT_ANIMATED|UI_BUT_ANIMATED_KEY|UI_BUT_DRIVEN);
39
40         fcu= ui_but_get_fcurve(but, NULL, &driven);
41
42         if(fcu) {
43                 if(!driven) {
44                         but->flag |= UI_BUT_ANIMATED;
45                         
46                         if(fcurve_frame_has_keyframe(fcu, cfra, 0))
47                                 but->flag |= UI_BUT_ANIMATED_KEY;
48                 }
49                 else {
50                         but->flag |= UI_BUT_DRIVEN;
51                 }
52         }
53 }
54
55 int ui_but_anim_expression_get(uiBut *but, char *str, int maxlen)
56 {
57         FCurve *fcu;
58         ChannelDriver *driver;
59         int driven;
60
61         fcu= ui_but_get_fcurve(but, NULL, &driven);
62
63         if(fcu && driven) {
64                 driver= fcu->driver;
65
66                 if(driver && driver->type == DRIVER_TYPE_PYTHON) {
67                         BLI_strncpy(str, driver->expression, maxlen);
68                         return 1;
69                 }
70         }
71
72         return 0;
73 }
74
75 int ui_but_anim_expression_set(uiBut *but, const char *str)
76 {
77         FCurve *fcu;
78         ChannelDriver *driver;
79         int driven;
80
81         fcu= ui_but_get_fcurve(but, NULL, &driven);
82
83         if(fcu && driven) {
84                 driver= fcu->driver;
85
86                 if(driver && driver->type == DRIVER_TYPE_PYTHON) {
87                         BLI_strncpy(driver->expression, str, sizeof(driver->expression));
88                         return 1;
89                 }
90         }
91
92         return 0;
93 }
94
95 void ui_but_anim_autokey(bContext *C, uiBut *but, Scene *scene, float cfra)
96 {
97         ID *id;
98         bAction *action;
99         FCurve *fcu;
100         int driven;
101
102         fcu= ui_but_get_fcurve(but, &action, &driven);
103
104         if(fcu && !driven) {
105                 id= but->rnapoin.id.data;
106                 
107                 // TODO: this should probably respect the keyingset only option for anim
108                 if(autokeyframe_cfra_can_key(scene, id)) {
109                         short flag = ANIM_get_keyframing_flags(scene, 1);
110                         
111                         fcu->flag &= ~FCURVE_SELECTED;
112                         insert_keyframe(id, action, ((fcu->grp)?(fcu->grp->name):(NULL)), fcu->rna_path, fcu->array_index, cfra, flag);
113                         WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
114                 }
115         }
116 }
117
118 void uiAnimContextProperty(const bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop, int *index)
119 {
120         ARegion *ar= CTX_wm_region(C);
121         uiBlock *block;
122         uiBut *but;
123
124         memset(ptr, 0, sizeof(*ptr));
125         *prop= NULL;
126         *index= 0;
127
128         if(ar) {
129                 for(block=ar->uiblocks.first; block; block=block->next) {
130                         for(but=block->buttons.first; but; but= but->next) {
131                                 if((but->active || but->flag & UI_BUT_LAST_ACTIVE) && but->rnapoin.id.data) {
132                                         *ptr= but->rnapoin;
133                                         *prop= but->rnaprop;
134                                         *index= but->rnaindex;
135                                         return;
136                                 }
137                         }
138                 }
139         }
140 }
141
142 void ui_but_anim_insert_keyframe(bContext *C)
143 {
144         /* this operator calls uiAnimContextProperty above */
145         WM_operator_name_call(C, "ANIM_OT_keyframe_insert_button", WM_OP_INVOKE_DEFAULT, NULL);
146 }
147
148 void ui_but_anim_delete_keyframe(bContext *C)
149 {
150         /* this operator calls uiAnimContextProperty above */
151         WM_operator_name_call(C, "ANIM_OT_keyframe_delete_button", WM_OP_INVOKE_DEFAULT, NULL);
152 }
153
154 void ui_but_anim_add_driver(bContext *C)
155 {
156         /* this operator calls uiAnimContextProperty above */
157         WM_operator_name_call(C, "ANIM_OT_driver_button_add", WM_OP_INVOKE_DEFAULT, NULL);
158 }
159
160 void ui_but_anim_remove_driver(bContext *C)
161 {
162         /* this operator calls uiAnimContextProperty above */
163         WM_operator_name_call(C, "ANIM_OT_driver_button_remove", WM_OP_INVOKE_DEFAULT, NULL);
164 }
165
166 void ui_but_anim_copy_driver(bContext *C)
167 {
168         /* this operator calls uiAnimContextProperty above */
169         WM_operator_name_call(C, "ANIM_OT_copy_driver_button", WM_OP_INVOKE_DEFAULT, NULL);
170 }
171
172 void ui_but_anim_paste_driver(bContext *C)
173 {
174         /* this operator calls uiAnimContextProperty above */
175         WM_operator_name_call(C, "ANIM_OT_paste_driver_button", WM_OP_INVOKE_DEFAULT, NULL);
176 }
177
178 void ui_but_anim_add_keyingset(bContext *C)
179 {
180         /* this operator calls uiAnimContextProperty above */
181         WM_operator_name_call(C, "ANIM_OT_keyingset_button_add", WM_OP_INVOKE_DEFAULT, NULL);
182 }
183
184 void ui_but_anim_remove_keyingset(bContext *C)
185 {
186         /* this operator calls uiAnimContextProperty above */
187         WM_operator_name_call(C, "ANIM_OT_keyingset_button_remove", WM_OP_INVOKE_DEFAULT, NULL);
188 }