Fix syntax for ID keyword.
[blender-staging.git] / source / blender / editors / space_graph / graph_buttons.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2009 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Blender Foundation, Joshua Leung
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include <string.h>
30 #include <stdio.h>
31 #include <math.h>
32 #include <float.h>
33
34 #include "DNA_anim_types.h"
35 #include "DNA_action_types.h"
36 #include "DNA_object_types.h"
37 #include "DNA_space_types.h"
38 #include "DNA_scene_types.h"
39 #include "DNA_screen_types.h"
40 #include "DNA_userdef_types.h"
41
42 #include "MEM_guardedalloc.h"
43
44 #include "BLI_math.h"
45 #include "BLI_blenlib.h"
46 #include "BLI_editVert.h"
47 #include "BLI_rand.h"
48
49 #include "BKE_action.h"
50 #include "BKE_animsys.h"
51 #include "BKE_context.h"
52 #include "BKE_curve.h"
53 #include "BKE_customdata.h"
54 #include "BKE_depsgraph.h"
55 #include "BKE_fcurve.h"
56 #include "BKE_library.h"
57 #include "BKE_main.h"
58 #include "BKE_object.h"
59 #include "BKE_scene.h"
60 #include "BKE_screen.h"
61 #include "BKE_utildefines.h"
62
63 #include "BIF_gl.h"
64
65 #include "WM_api.h"
66 #include "WM_types.h"
67
68 #include "RNA_access.h"
69 #include "RNA_define.h"
70
71 #include "ED_anim_api.h"
72 #include "ED_keyframing.h"
73 #include "ED_screen.h"
74 #include "ED_types.h"
75 #include "ED_util.h"
76
77 #include "UI_interface.h"
78 #include "UI_resources.h"
79 #include "UI_view2d.h"
80
81 #include "graph_intern.h"       // own include
82
83 /* XXX */
84
85 /* temporary definition for limits of float number buttons (FLT_MAX tends to infinity with old system) */
86 #define UI_FLT_MAX      10000.0f
87
88
89 /* ******************* graph editor space & buttons ************** */
90
91 #define B_NOP           1
92 #define B_REDR          2
93
94 /* -------------- */
95
96 static void do_graph_region_buttons(bContext *C, void *arg, int event)
97 {
98         //Scene *scene= CTX_data_scene(C);
99         
100         switch(event) {
101
102         }
103         
104         /* default for now */
105         //WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, ob);
106 }
107
108 /* -------------- */
109
110 static int graph_panel_context(const bContext *C, bAnimListElem **ale, FCurve **fcu)
111 {
112         bAnimContext ac;
113         bAnimListElem *elem= NULL;
114         
115         /* for now, only draw if we could init the anim-context info (necessary for all animation-related tools) 
116          * to work correctly is able to be correctly retrieved. There's no point showing empty panels?
117          */
118         if (ANIM_animdata_get_context(C, &ac) == 0) 
119                 return 0;
120         
121         /* try to find 'active' F-Curve */
122         elem= get_active_fcurve_channel(&ac);
123         if(elem == NULL) 
124                 return 0;
125         
126         if(fcu)
127                 *fcu= (FCurve*)elem->data;
128         if(ale)
129                 *ale= elem;
130         else
131                 MEM_freeN(elem);
132         
133         return 1;
134 }
135
136 static int graph_panel_poll(const bContext *C, PanelType *pt)
137 {
138         return graph_panel_context(C, NULL, NULL);
139 }
140
141 /* -------------- */
142
143 /* Graph Editor View Settings */
144 static void graph_panel_view(const bContext *C, Panel *pa)
145 {
146         bScreen *sc= CTX_wm_screen(C);
147         SpaceIpo *sipo= CTX_wm_space_graph(C);
148         Scene *scene= CTX_data_scene(C);
149         PointerRNA spaceptr, sceneptr;
150         uiLayout *col, *subcol, *row;
151         
152         /* get RNA pointers for use when creating the UI elements */
153         RNA_id_pointer_create(&scene->id, &sceneptr);
154         RNA_pointer_create(&sc->id, &RNA_SpaceGraphEditor, sipo, &spaceptr);
155
156         /* 2D-Cursor */
157         col= uiLayoutColumn(pa->layout, 0);
158                 uiItemR(col, NULL, 0, &spaceptr, "show_cursor", 0);
159                 
160                 subcol= uiLayoutColumn(col, 1);
161                 uiLayoutSetActive(subcol, RNA_boolean_get(&spaceptr, "show_cursor")); 
162                         uiItemO(subcol, "Cursor from Selection", 0, "GRAPH_OT_frame_jump");
163                 
164                 subcol= uiLayoutColumn(col, 1);
165                 uiLayoutSetActive(subcol, RNA_boolean_get(&spaceptr, "show_cursor")); 
166                         row= uiLayoutSplit(subcol, 0.7, 1);
167                                 uiItemR(row, "Cursor X", 0, &sceneptr, "current_frame", 0);
168                                 uiItemEnumO(row, "To Keys", 0, "GRAPH_OT_snap", "type", GRAPHKEYS_SNAP_CFRA);
169                         row= uiLayoutSplit(subcol, 0.7, 1);
170                                 uiItemR(row, "Cursor Y", 0, &spaceptr, "cursor_value", 0);
171                                 uiItemEnumO(row, "To Keys", 0, "GRAPH_OT_snap", "type", GRAPHKEYS_SNAP_VALUE);
172 }
173
174 /* ******************* active F-Curve ************** */
175
176 static void graph_panel_properties(const bContext *C, Panel *pa)
177 {
178         bAnimListElem *ale;
179         FCurve *fcu;
180         PointerRNA fcu_ptr;
181         uiLayout *layout = pa->layout;
182         uiLayout *col, *row, *subrow;
183         uiBlock *block;
184         char name[256];
185         int icon = 0;
186
187         if (!graph_panel_context(C, &ale, &fcu))
188                 return;
189         
190         block= uiLayoutGetBlock(layout);
191         uiBlockSetHandleFunc(block, do_graph_region_buttons, NULL);
192         
193         /* F-Curve pointer */
194         RNA_pointer_create(ale->id, &RNA_FCurve, fcu, &fcu_ptr);
195         
196         /* user-friendly 'name' for F-Curve */
197         // TODO: only show the path if this is invalid?
198         col= uiLayoutColumn(layout, 0);
199                 icon= getname_anim_fcurve(name, ale->id, fcu);
200                 uiItemL(col, name, icon);
201                 
202         /* RNA-Path Editing - only really should be enabled when things aren't working */
203         col= uiLayoutColumn(layout, 1);
204                 uiLayoutSetEnabled(col, (fcu->flag & FCURVE_DISABLED)); 
205                 uiItemR(col, "", ICON_RNA, &fcu_ptr, "data_path", 0);
206                 uiItemR(col, NULL, 0, &fcu_ptr, "array_index", 0);
207                 
208         /* color settings */
209         col= uiLayoutColumn(layout, 1);
210                 uiItemL(col, "Display Color:", 0);
211                 
212                 row= uiLayoutRow(col, 1);
213                         uiItemR(row, "", 0, &fcu_ptr, "color_mode", 0);
214                         
215                         subrow= uiLayoutRow(row, 1);
216                                 uiLayoutSetEnabled(subrow, (fcu->color_mode==FCURVE_COLOR_CUSTOM));
217                                 uiItemR(subrow, "", 0, &fcu_ptr, "color", 0);
218         
219         /* TODO: the following settings could be added here
220          *      - Access details (ID-block + RNA-Path + Array Index)
221          *      - ...
222          */
223
224         MEM_freeN(ale);
225 }
226
227 /* ******************* drivers ******************************** */
228
229 #define B_IPO_DEPCHANGE         10
230
231 static void do_graph_region_driver_buttons(bContext *C, void *arg, int event)
232 {
233         Scene *scene= CTX_data_scene(C);
234         
235         switch (event) {
236                 case B_IPO_DEPCHANGE:
237                 {
238                         /* rebuild depsgraph for the new deps */
239                         DAG_scene_sort(scene);
240                         
241                         /* force an update of depsgraph */
242                         DAG_ids_flush_update(0);
243                 }
244                         break;
245         }
246         
247         /* default for now */
248         WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene); // XXX could use better notifier
249 }
250
251 /* callback to remove the active driver */
252 static void driver_remove_cb (bContext *C, void *ale_v, void *dummy_v)
253 {
254         bAnimListElem *ale= (bAnimListElem *)ale_v;
255         ID *id= ale->id;
256         FCurve *fcu= ale->data;
257         
258         /* try to get F-Curve that driver lives on, and ID block which has this AnimData */
259         if (ELEM(NULL, id, fcu))
260                 return;
261         
262         /* call API method to remove this driver  */    
263         ANIM_remove_driver(id, fcu->rna_path, fcu->array_index, 0);
264 }
265
266 /* callback to add a target variable to the active driver */
267 static void driver_add_var_cb (bContext *C, void *driver_v, void *dummy_v)
268 {
269         ChannelDriver *driver= (ChannelDriver *)driver_v;
270         
271         /* add a new variable */
272         driver_add_new_variable(driver);
273 }
274
275 /* callback to remove target variable from active driver */
276 static void driver_delete_var_cb (bContext *C, void *driver_v, void *dvar_v)
277 {
278         ChannelDriver *driver= (ChannelDriver *)driver_v;
279         DriverVar *dvar= (DriverVar *)dvar_v;
280         
281         /* remove the active variable */
282         driver_free_variable(driver, dvar);
283 }
284
285 /* callback to reset the driver's flags */
286 static void driver_update_flags_cb (bContext *C, void *fcu_v, void *dummy_v)
287 {
288         FCurve *fcu= (FCurve *)fcu_v;
289         ChannelDriver *driver= fcu->driver;
290         
291         /* clear invalid flags */
292         fcu->flag &= ~FCURVE_DISABLED; // XXX?
293         driver->flag &= ~DRIVER_FLAG_INVALID;
294 }
295
296 /* drivers panel poll */
297 static int graph_panel_drivers_poll(const bContext *C, PanelType *pt)
298 {
299         SpaceIpo *sipo= CTX_wm_space_graph(C);
300
301         if(sipo->mode != SIPO_MODE_DRIVERS)
302                 return 0;
303
304         return graph_panel_context(C, NULL, NULL);
305 }
306
307
308 /* settings for 'single property' driver variable type */
309 static void graph_panel_driverVar__singleProp(const bContext *C, uiLayout *layout, ID *id, DriverVar *dvar)
310 {
311         DriverTarget *dtar= &dvar->targets[0];
312         PointerRNA dtar_ptr;
313         uiLayout *row, *col;
314         uiBlock *block;
315         
316         /* initialise RNA pointer to the target */
317         RNA_pointer_create(id, &RNA_DriverTarget, dtar, &dtar_ptr); 
318         
319         /* Target ID */
320         row= uiLayoutRow(layout, 0);
321                 uiTemplateAnyID(row, (bContext *)C, &dtar_ptr, "id", "id_type", "Prop:");
322         
323         /* Target Property */
324         // TODO: make this less technical...
325         if (dtar->id) {
326                 PointerRNA root_ptr;
327                 
328                 /* get pointer for resolving the property selected */
329                 RNA_id_pointer_create(dtar->id, &root_ptr);
330                 
331                 col= uiLayoutColumn(layout, 1);
332                 block= uiLayoutGetBlock(col);
333                         /* rna path */
334                         uiTemplatePathBuilder(col, (bContext *)C, &dtar_ptr, "data_path", &root_ptr, "Path");
335         }
336 }
337
338 /* settings for 'rotation difference' driver variable type */
339 static void graph_panel_driverVar__rotDiff(const bContext *C, uiLayout *layout, ID *id, DriverVar *dvar)
340 {
341         DriverTarget *dtar= &dvar->targets[0];
342         DriverTarget *dtar2= &dvar->targets[1];
343         Object *ob1 = (Object *)dtar->id;
344         Object *ob2 = (Object *)dtar2->id;
345         PointerRNA dtar_ptr, dtar2_ptr;
346         uiLayout *col;
347         
348         /* initialise RNA pointer to the target */
349         RNA_pointer_create(id, &RNA_DriverTarget, dtar, &dtar_ptr); 
350         RNA_pointer_create(id, &RNA_DriverTarget, dtar2, &dtar2_ptr); 
351         
352         /* Bone 1 */
353         col= uiLayoutColumn(layout, 1);
354                 uiTemplateAnyID(col, (bContext *)C, &dtar_ptr, "id", "id_type", "Bone 1:");
355                 
356                 if (dtar->id && ob1->pose) {
357                         PointerRNA tar_ptr;
358                         
359                         RNA_pointer_create(dtar->id, &RNA_Pose, ob1->pose, &tar_ptr);
360                         uiItemPointerR(col, "", ICON_BONE_DATA, &dtar_ptr, "bone_target", &tar_ptr, "bones");
361                 }
362         
363         col= uiLayoutColumn(layout, 1);
364                 uiTemplateAnyID(col, (bContext *)C, &dtar2_ptr, "id", "id_type", "Bone 2:");
365                 
366                 if (dtar2->id && ob2->pose) {
367                         PointerRNA tar_ptr;
368                         
369                         RNA_pointer_create(dtar2->id, &RNA_Pose, ob2->pose, &tar_ptr);
370                         uiItemPointerR(col, "", ICON_BONE_DATA, &dtar2_ptr, "bone_target", &tar_ptr, "bones");
371                 }
372 }
373
374 /* settings for 'location difference' driver variable type */
375 static void graph_panel_driverVar__locDiff(const bContext *C, uiLayout *layout, ID *id, DriverVar *dvar)
376 {
377         DriverTarget *dtar= &dvar->targets[0];
378         DriverTarget *dtar2= &dvar->targets[1];
379         Object *ob1 = (Object *)dtar->id;
380         Object *ob2 = (Object *)dtar2->id;
381         PointerRNA dtar_ptr, dtar2_ptr;
382         uiLayout *col;
383         
384         /* initialise RNA pointer to the target */
385         RNA_pointer_create(id, &RNA_DriverTarget, dtar, &dtar_ptr); 
386         RNA_pointer_create(id, &RNA_DriverTarget, dtar2, &dtar2_ptr); 
387         
388         /* Bone 1 */
389         col= uiLayoutColumn(layout, 1);
390                 uiTemplateAnyID(col, (bContext *)C, &dtar_ptr, "id", "id_type", "Ob/Bone 1:");
391                 
392                 if (dtar->id && ob1->pose) {
393                         PointerRNA tar_ptr;
394                         
395                         RNA_pointer_create(dtar->id, &RNA_Pose, ob1->pose, &tar_ptr);
396                         uiItemPointerR(col, "", ICON_BONE_DATA, &dtar_ptr, "bone_target", &tar_ptr, "bones");
397                 }
398                 
399                 uiItemR(col, NULL, 0, &dtar_ptr, "use_local_space_transforms", 0);
400         
401         col= uiLayoutColumn(layout, 1);
402                 uiTemplateAnyID(col, (bContext *)C, &dtar2_ptr, "id", "id_type", "Ob/Bone 2:");
403                 
404                 if (dtar2->id && ob2->pose) {
405                         PointerRNA tar_ptr;
406                         
407                         RNA_pointer_create(dtar2->id, &RNA_Pose, ob2->pose, &tar_ptr);
408                         uiItemPointerR(col, "", ICON_BONE_DATA, &dtar2_ptr, "bone_target", &tar_ptr, "bones");
409                 }
410                 
411                 uiItemR(col, NULL, 0, &dtar2_ptr, "use_local_space_transforms", 0);
412 }
413
414 /* settings for 'transform channel' driver variable type */
415 static void graph_panel_driverVar__transChan(const bContext *C, uiLayout *layout, ID *id, DriverVar *dvar)
416 {
417         DriverTarget *dtar= &dvar->targets[0];
418         Object *ob = (Object *)dtar->id;
419         PointerRNA dtar_ptr;
420         uiLayout *col, *row;
421         
422         /* initialise RNA pointer to the target */
423         RNA_pointer_create(id, &RNA_DriverTarget, dtar, &dtar_ptr); 
424         
425         /* properties */
426         col= uiLayoutColumn(layout, 1);
427                 uiTemplateAnyID(col, (bContext *)C, &dtar_ptr, "id", "id_type", "Ob/Bone:");
428                 
429                 if (dtar->id && ob->pose) {
430                         PointerRNA tar_ptr;
431                         
432                         RNA_pointer_create(dtar->id, &RNA_Pose, ob->pose, &tar_ptr);
433                         uiItemPointerR(col, "", ICON_BONE_DATA, &dtar_ptr, "bone_target", &tar_ptr, "bones");
434                 }
435                 
436                 row= uiLayoutRow(layout, 1);
437                         uiItemR(row, "", 0, &dtar_ptr, "transform_type", 0);
438                         uiItemR(row, NULL, 0, &dtar_ptr, "use_local_space_transforms", 0);
439 }
440
441 /* driver settings for active F-Curve (only for 'Drivers' mode) */
442 static void graph_panel_drivers(const bContext *C, Panel *pa)
443 {
444         bAnimListElem *ale;
445         FCurve *fcu;
446         ChannelDriver *driver;
447         DriverVar *dvar;
448         
449         PointerRNA driver_ptr;
450         uiLayout *col;
451         uiBlock *block;
452         uiBut *but;
453         
454         /* Get settings from context */
455         if (!graph_panel_context(C, &ale, &fcu))
456                 return;
457         driver= fcu->driver;
458         
459         /* set event handler for panel */
460         block= uiLayoutGetBlock(pa->layout); // xxx?
461         uiBlockSetHandleFunc(block, do_graph_region_driver_buttons, NULL);
462         
463         /* general actions - management */
464         col= uiLayoutColumn(pa->layout, 0);
465         block= uiLayoutGetBlock(col);
466                 but= uiDefBut(block, BUT, B_IPO_DEPCHANGE, "Update Dependencies", 0, 0, 10*UI_UNIT_X, 22, NULL, 0.0, 0.0, 0, 0, "Force updates of dependencies");
467                 uiButSetFunc(but, driver_update_flags_cb, fcu, NULL);
468                 
469                 but= uiDefBut(block, BUT, B_IPO_DEPCHANGE, "Remove Driver", 0, 0, 10*UI_UNIT_X, 18, NULL, 0.0, 0.0, 0, 0, "Remove this driver");
470                 uiButSetNFunc(but, driver_remove_cb, MEM_dupallocN(ale), NULL);
471                 
472         /* driver-level settings - type, expressions, and errors */
473         RNA_pointer_create(ale->id, &RNA_Driver, driver, &driver_ptr);
474         
475         col= uiLayoutColumn(pa->layout, 1);
476         block= uiLayoutGetBlock(col);
477                 uiItemR(col, NULL, 0, &driver_ptr, "type", 0);
478                 
479                 /* show expression box if doing scripted drivers, and/or error messages when invalid drivers exist */
480                 if (driver->type == DRIVER_TYPE_PYTHON) {
481                         /* expression */
482                         uiItemR(col, "Expr", 0, &driver_ptr, "expression", 0);
483                         
484                         /* errors? */
485                         if (driver->flag & DRIVER_FLAG_INVALID)
486                                 uiItemL(col, "ERROR: invalid Python expression", ICON_ERROR);
487                 }
488                 else {
489                         /* errors? */
490                         if (driver->flag & DRIVER_FLAG_INVALID)
491                                 uiItemL(col, "ERROR: invalid target channel(s)", ICON_ERROR);
492                 }
493                 
494         col= uiLayoutColumn(pa->layout, 1);
495                 /* debug setting */
496                 uiItemR(col, NULL, 0, &driver_ptr, "show_debug_info", 0);
497                 
498                 /* value of driver */
499                 if (driver->flag & DRIVER_FLAG_SHOWDEBUG) {
500                         uiLayout *row= uiLayoutRow(col, 1);
501                         char valBuf[32];
502                         
503                         uiItemL(row, "Driver Value:", 0);
504                         
505                         sprintf(valBuf, "%.3f", driver->curval);
506                         uiItemL(row, valBuf, 0);
507                 }
508         
509         /* add driver variables */
510         col= uiLayoutColumn(pa->layout, 0);
511         block= uiLayoutGetBlock(col);
512                 but= uiDefBut(block, BUT, B_IPO_DEPCHANGE, "Add Variable", 0, 0, 10*UI_UNIT_X, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "Add a new target variable for this Driver");
513                 uiButSetFunc(but, driver_add_var_cb, driver, NULL);
514         
515         /* loop over targets, drawing them */
516         for (dvar= driver->variables.first; dvar; dvar= dvar->next) {
517                 PointerRNA dvar_ptr;
518                 uiLayout *box, *row;
519                 
520                 /* sub-layout column for this variable's settings */
521                 col= uiLayoutColumn(pa->layout, 1);
522                 
523                 /* header panel */
524                 box= uiLayoutBox(col);
525                         /* first row context info for driver */
526                         RNA_pointer_create(ale->id, &RNA_DriverVariable, dvar, &dvar_ptr);
527                         
528                         row= uiLayoutRow(box, 0);
529                         block= uiLayoutGetBlock(row);
530                                 /* variable name */
531                                 uiItemR(row, "", 0, &dvar_ptr, "name", 0);
532                                 
533                                 /* remove button */
534                                 uiBlockSetEmboss(block, UI_EMBOSSN);
535                                         but= uiDefIconBut(block, BUT, B_IPO_DEPCHANGE, ICON_X, 290, 0, UI_UNIT_X, UI_UNIT_Y, NULL, 0.0, 0.0, 0.0, 0.0, "Delete target variable.");
536                                         uiButSetFunc(but, driver_delete_var_cb, driver, dvar);
537                                 uiBlockSetEmboss(block, UI_EMBOSS);
538                         
539                         /* variable type */
540                         row= uiLayoutRow(box, 0);
541                                 uiItemR(row, "", 0, &dvar_ptr, "type", 0);
542                                 
543                 /* variable type settings */
544                 box= uiLayoutBox(col);
545                         /* controls to draw depends on the type of variable */
546                         switch (dvar->type) {
547                                 case DVAR_TYPE_SINGLE_PROP:     /* single property */
548                                         graph_panel_driverVar__singleProp(C, box, ale->id, dvar);
549                                         break;
550                                 case DVAR_TYPE_ROT_DIFF: /* rotational difference */
551                                         graph_panel_driverVar__rotDiff(C, box, ale->id, dvar);
552                                         break;
553                                 case DVAR_TYPE_LOC_DIFF: /* location difference */
554                                         graph_panel_driverVar__locDiff(C, box, ale->id, dvar);
555                                         break;
556                                 case DVAR_TYPE_TRANSFORM_CHAN: /* transform channel */
557                                         graph_panel_driverVar__transChan(C, box, ale->id, dvar);
558                                         break;
559                         }
560                         
561                 /* value of variable */
562                 if (driver->flag & DRIVER_FLAG_SHOWDEBUG) {
563                         uiLayout *row;
564                         char valBuf[32];
565                         
566                         box= uiLayoutBox(col);
567                         row= uiLayoutRow(box, 1);
568                                 uiItemL(row, "Value:", 0);
569                                 
570                                 sprintf(valBuf, "%.3f", dvar->curval);
571                                 uiItemL(row, valBuf, 0);
572                 }
573         }
574         
575         /* cleanup */
576         MEM_freeN(ale);
577 }
578
579 /* ******************* f-modifiers ******************************** */
580 /* all the drawing code is in editors/animation/fmodifier_ui.c */
581
582 #define B_FMODIFIER_REDRAW              20
583
584 static void do_graph_region_modifier_buttons(bContext *C, void *arg, int event)
585 {
586         switch (event) {
587                 case B_REDR:
588                 case B_FMODIFIER_REDRAW: // XXX this should send depsgraph updates too
589                         WM_event_add_notifier(C, NC_ANIMATION, NULL); // XXX need a notifier specially for F-Modifiers
590                         break;
591         }
592 }
593
594 static void graph_panel_modifiers(const bContext *C, Panel *pa) 
595 {
596         bAnimListElem *ale;
597         FCurve *fcu;
598         FModifier *fcm;
599         uiLayout *col, *row;
600         uiBlock *block;
601         
602         if (!graph_panel_context(C, &ale, &fcu))
603                 return;
604         
605         block= uiLayoutGetBlock(pa->layout);
606         uiBlockSetHandleFunc(block, do_graph_region_modifier_buttons, NULL);
607         
608         /* 'add modifier' button at top of panel */
609         {
610                 row= uiLayoutRow(pa->layout, 0);
611                 block= uiLayoutGetBlock(row);
612                 
613                 // XXX for now, this will be a operator button which calls a 'add modifier' operator
614                 uiDefButO(block, BUT, "GRAPH_OT_fmodifier_add", WM_OP_INVOKE_REGION_WIN, "Add Modifier", 10, 0, 150, 20, "Adds a new F-Curve Modifier for the active F-Curve");
615                 
616                 /* copy/paste (as sub-row)*/
617                 row= uiLayoutRow(row, 1);
618                         uiItemO(row, "", ICON_COPYDOWN, "GRAPH_OT_fmodifier_copy");
619                         uiItemO(row, "", ICON_PASTEDOWN, "GRAPH_OT_fmodifier_paste");
620         }
621         
622         /* draw each modifier */
623         for (fcm= fcu->modifiers.first; fcm; fcm= fcm->next) {
624                 col= uiLayoutColumn(pa->layout, 1);
625                 
626                 ANIM_uiTemplate_fmodifier_draw(col, ale->id, &fcu->modifiers, fcm);
627         }
628
629         MEM_freeN(ale);
630 }
631
632 /* ******************* general ******************************** */
633
634 void graph_buttons_register(ARegionType *art)
635 {
636         PanelType *pt;
637
638         pt= MEM_callocN(sizeof(PanelType), "spacetype graph panel view");
639         strcpy(pt->idname, "GRAPH_PT_view");
640         strcpy(pt->label, "View Properties");
641         pt->draw= graph_panel_view;
642         BLI_addtail(&art->paneltypes, pt);
643         
644         pt= MEM_callocN(sizeof(PanelType), "spacetype graph panel properties");
645         strcpy(pt->idname, "GRAPH_PT_properties");
646         strcpy(pt->label, "Active F-Curve");
647         pt->draw= graph_panel_properties;
648         pt->poll= graph_panel_poll;
649         BLI_addtail(&art->paneltypes, pt);
650
651         pt= MEM_callocN(sizeof(PanelType), "spacetype graph panel drivers");
652         strcpy(pt->idname, "GRAPH_PT_drivers");
653         strcpy(pt->label, "Drivers");
654         pt->draw= graph_panel_drivers;
655         pt->poll= graph_panel_drivers_poll;
656         BLI_addtail(&art->paneltypes, pt);
657
658         pt= MEM_callocN(sizeof(PanelType), "spacetype graph panel modifiers");
659         strcpy(pt->idname, "GRAPH_PT_modifiers");
660         strcpy(pt->label, "Modifiers");
661         pt->draw= graph_panel_modifiers;
662         pt->poll= graph_panel_poll;
663         BLI_addtail(&art->paneltypes, pt);
664 }
665
666 static int graph_properties(bContext *C, wmOperator *op)
667 {
668         ScrArea *sa= CTX_wm_area(C);
669         ARegion *ar= graph_has_buttons_region(sa);
670         
671         if(ar)
672                 ED_region_toggle_hidden(C, ar);
673
674         return OPERATOR_FINISHED;
675 }
676
677 void GRAPH_OT_properties(wmOperatorType *ot)
678 {
679         ot->name= "Properties";
680         ot->idname= "GRAPH_OT_properties";
681         
682         ot->exec= graph_properties;
683         ot->poll= ED_operator_ipo_active; // xxx
684         
685         /* flags */
686         ot->flag= 0;
687 }