diff options
author | Joshua Leung <aligorith@gmail.com> | 2009-07-02 05:01:18 +0400 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2009-07-02 05:01:18 +0400 |
commit | ede921fdfac1c76b8c54cae1723fbe9efd891939 (patch) | |
tree | 3f192151aa85c6caa690a41a676d761c0c6a5c7a /source/blender/editors | |
parent | 66c86278204a3b9fac090c36539ce8efcb2bf0ba (diff) |
NLA SoC: Proper poll callbacks for Graph Editor
For now, some of these polls may be a bit too restrictive, but at least we have some unified+cleaned bases to work from now (instead of relying on the generic ED_operator_area_active).
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/space_graph/graph_buttons.c | 28 | ||||
-rw-r--r-- | source/blender/editors/space_graph/graph_draw.c | 40 | ||||
-rw-r--r-- | source/blender/editors/space_graph/graph_edit.c | 46 | ||||
-rw-r--r-- | source/blender/editors/space_graph/graph_intern.h | 9 | ||||
-rw-r--r-- | source/blender/editors/space_graph/graph_ops.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_graph/graph_select.c | 8 | ||||
-rw-r--r-- | source/blender/editors/space_graph/graph_utils.c | 288 |
7 files changed, 325 insertions, 96 deletions
diff --git a/source/blender/editors/space_graph/graph_buttons.c b/source/blender/editors/space_graph/graph_buttons.c index ea4f017c9bb..f2dcd297866 100644 --- a/source/blender/editors/space_graph/graph_buttons.c +++ b/source/blender/editors/space_graph/graph_buttons.c @@ -1000,34 +1000,6 @@ static void graph_panel_modifiers(const bContext *C, Panel *pa) /* ******************* general ******************************** */ -/* Find 'active' F-Curve. It must be editable, since that's the purpose of these buttons (subject to change). - * We return the 'wrapper' since it contains valuable context info (about hierarchy), which will need to be freed - * when the caller is done with it. - */ -// TODO: move this to anim api with another name? -bAnimListElem *get_active_fcurve_channel (bAnimContext *ac) -{ - ListBase anim_data = {NULL, NULL}; - int filter= (ANIMFILTER_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_ACTIVE | ANIMFILTER_CURVESONLY); - int items = ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); - - /* We take the first F-Curve only, since some other ones may have had 'active' flag set - * if they were from linked data. - */ - if (items) { - bAnimListElem *ale= (bAnimListElem *)anim_data.first; - - /* remove first item from list, then free the rest of the list and return the stored one */ - BLI_remlink(&anim_data, ale); - BLI_freelistN(&anim_data); - - return ale; - } - - /* no active F-Curve */ - return NULL; -} - void graph_buttons_register(ARegionType *art) { PanelType *pt; diff --git a/source/blender/editors/space_graph/graph_draw.c b/source/blender/editors/space_graph/graph_draw.c index 6393b6877b9..66168f2ed87 100644 --- a/source/blender/editors/space_graph/graph_draw.c +++ b/source/blender/editors/space_graph/graph_draw.c @@ -775,46 +775,6 @@ void graph_draw_ghost_curves (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, Vie glDisable(GL_BLEND); } -/* check if any FModifiers to draw controls for - fcm is 'active' modifier */ -static short fcurve_needs_draw_fmodifier_controls (FCurve *fcu, FModifier *fcm) -{ - /* don't draw if there aren't any modifiers at all */ - if (fcu->modifiers.first == NULL) - return 0; - - /* if there's an active modifier - don't draw if it doesn't drastically - * alter the curve... - */ - if (fcm) { - switch (fcm->type) { - /* clearly harmless */ - case FMODIFIER_TYPE_CYCLES: - return 0; - - /* borderline... */ - case FMODIFIER_TYPE_NOISE: - return 0; - } - } - - /* if only one modifier - don't draw if it is muted or disabled */ - if (fcu->modifiers.first == fcu->modifiers.last) { - fcm= fcu->modifiers.first; - if (fcm->flag & (FMODIFIER_FLAG_DISABLED|FMODIFIER_FLAG_MUTED)) - return 0; - } - - /* if only active modifier - don't draw if it is muted or disabled */ - if (fcm) { - if (fcm->flag & (FMODIFIER_FLAG_DISABLED|FMODIFIER_FLAG_MUTED)) - return 0; - } - - /* if we're still here, this means that there are modifiers with controls to be drawn */ - // FIXME: what happens if all the modifiers were muted/disabled - return 1; -} - /* This is called twice from space_graph.c -> graph_main_area_draw() * Unselected then selected F-Curves are drawn so that they do not occlude each other. */ diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c index 4ea14a365e4..ca47e69cc75 100644 --- a/source/blender/editors/space_graph/graph_edit.c +++ b/source/blender/editors/space_graph/graph_edit.c @@ -189,7 +189,7 @@ void GRAPH_OT_previewrange_set (wmOperatorType *ot) /* api callbacks */ ot->exec= graphkeys_previewrange_exec; - ot->poll= ED_operator_areaactive; + ot->poll= graphop_visible_keyframes_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -236,7 +236,7 @@ void GRAPH_OT_view_all (wmOperatorType *ot) /* api callbacks */ ot->exec= graphkeys_viewall_exec; - ot->poll= ED_operator_areaactive; + ot->poll= graphop_visible_keyframes_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -347,7 +347,7 @@ void GRAPH_OT_ghost_curves_create (wmOperatorType *ot) /* api callbacks */ ot->exec= graphkeys_create_ghostcurves_exec; - ot->poll= ED_operator_areaactive; + ot->poll= graphop_visible_keyframes_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -390,7 +390,7 @@ void GRAPH_OT_ghost_curves_clear (wmOperatorType *ot) /* api callbacks */ ot->exec= graphkeys_clear_ghostcurves_exec; - ot->poll= ED_operator_areaactive; + ot->poll= ED_operator_ipo_active; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -488,7 +488,7 @@ void GRAPH_OT_insert_keyframe (wmOperatorType *ot) /* api callbacks */ ot->invoke= WM_menu_invoke; ot->exec= graphkeys_insertkey_exec; - ot->poll= ED_operator_ipo_active; // xxx + ot->poll= graphop_editable_keyframes_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -575,7 +575,7 @@ void GRAPH_OT_click_insert (wmOperatorType *ot) /* api callbacks */ ot->invoke= graphkeys_click_insert_invoke; ot->exec= graphkeys_click_insert_exec; - ot->poll= ED_operator_areaactive; // XXX active + editable poll + ot->poll= graphop_active_fcurve_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -657,7 +657,7 @@ void GRAPH_OT_copy (wmOperatorType *ot) /* api callbacks */ ot->exec= graphkeys_copy_exec; - ot->poll= ED_operator_areaactive; + ot->poll= graphop_editable_keyframes_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -696,7 +696,7 @@ void GRAPH_OT_paste (wmOperatorType *ot) /* api callbacks */ ot->exec= graphkeys_paste_exec; - ot->poll= ED_operator_areaactive; + ot->poll= graphop_editable_keyframes_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -764,7 +764,7 @@ void GRAPH_OT_duplicate (wmOperatorType *ot) /* api callbacks */ ot->invoke= graphkeys_duplicate_invoke; ot->exec= graphkeys_duplicate_exec; - ot->poll= ED_operator_areaactive; + ot->poll= graphop_editable_keyframes_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -825,7 +825,7 @@ void GRAPH_OT_delete (wmOperatorType *ot) /* api callbacks */ ot->invoke= WM_operator_confirm; ot->exec= graphkeys_delete_exec; - ot->poll= ED_operator_areaactive; + ot->poll= graphop_editable_keyframes_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -886,7 +886,7 @@ void GRAPH_OT_clean (wmOperatorType *ot) /* api callbacks */ //ot->invoke= // XXX we need that number popup for this! ot->exec= graphkeys_clean_exec; - ot->poll= ED_operator_areaactive; + ot->poll= graphop_editable_keyframes_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -967,7 +967,7 @@ void GRAPH_OT_bake (wmOperatorType *ot) /* api callbacks */ ot->invoke= WM_operator_confirm; // FIXME... ot->exec= graphkeys_bake_exec; - ot->poll= ED_operator_areaactive; + ot->poll= graphop_editable_keyframes_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -1092,7 +1092,7 @@ void GRAPH_OT_sample (wmOperatorType *ot) /* api callbacks */ ot->exec= graphkeys_sample_exec; - ot->poll= ED_operator_areaactive; + ot->poll= graphop_editable_keyframes_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -1167,7 +1167,7 @@ void GRAPH_OT_extrapolation_type (wmOperatorType *ot) /* api callbacks */ ot->invoke= WM_menu_invoke; ot->exec= graphkeys_expo_exec; - ot->poll= ED_operator_areaactive; + ot->poll= graphop_editable_keyframes_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -1235,7 +1235,7 @@ void GRAPH_OT_interpolation_type (wmOperatorType *ot) /* api callbacks */ ot->invoke= WM_menu_invoke; ot->exec= graphkeys_ipo_exec; - ot->poll= ED_operator_areaactive; + ot->poll= graphop_editable_keyframes_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -1322,7 +1322,7 @@ void GRAPH_OT_handletype (wmOperatorType *ot) /* api callbacks */ ot->invoke= WM_menu_invoke; ot->exec= graphkeys_handletype_exec; - ot->poll= ED_operator_areaactive; + ot->poll= graphop_editable_keyframes_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -1411,7 +1411,7 @@ void GRAPH_OT_euler_filter (wmOperatorType *ot) /* api callbacks */ ot->exec= graphkeys_euler_filter_exec; - ot->poll= ED_operator_areaactive; + ot->poll= graphop_editable_keyframes_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -1438,7 +1438,7 @@ static int graphkeys_framejump_exec(bContext *C, wmOperator *op) memset(&bed, 0, sizeof(BeztEditData)); /* loop over action data, averaging values */ - filter= (ANIMFILTER_VISIBLE | ANIMFILTER_CURVEVISIBLE| ANIMFILTER_CURVESONLY); + filter= (ANIMFILTER_VISIBLE | ANIMFILTER_CURVEVISIBLE | ANIMFILTER_CURVESONLY); ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); for (ale= anim_data.first; ale; ale= ale->next) { @@ -1476,7 +1476,7 @@ void GRAPH_OT_frame_jump (wmOperatorType *ot) /* api callbacks */ ot->exec= graphkeys_framejump_exec; - ot->poll= ED_operator_areaactive; + ot->poll= graphop_visible_keyframes_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -1568,7 +1568,7 @@ void GRAPH_OT_snap (wmOperatorType *ot) /* api callbacks */ ot->invoke= WM_menu_invoke; ot->exec= graphkeys_snap_exec; - ot->poll= ED_operator_areaactive; + ot->poll= graphop_editable_keyframes_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -1679,7 +1679,7 @@ void GRAPH_OT_mirror (wmOperatorType *ot) /* api callbacks */ ot->invoke= WM_menu_invoke; ot->exec= graphkeys_mirror_exec; - ot->poll= ED_operator_areaactive; + ot->poll= graphop_editable_keyframes_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -1732,7 +1732,7 @@ void GRAPH_OT_smooth (wmOperatorType *ot) /* api callbacks */ ot->exec= graphkeys_smooth_exec; - ot->poll= ED_operator_areaactive; + ot->poll= graphop_editable_keyframes_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -1795,7 +1795,7 @@ void GRAPH_OT_fmodifier_add (wmOperatorType *ot) /* api callbacks */ ot->invoke= WM_menu_invoke; ot->exec= graph_fmodifier_add_exec; - ot->poll= ED_operator_areaactive; // XXX need active F-Curve + ot->poll= graphop_active_fcurve_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; diff --git a/source/blender/editors/space_graph/graph_intern.h b/source/blender/editors/space_graph/graph_intern.h index d520a63c126..fd7fe7cc6c9 100644 --- a/source/blender/editors/space_graph/graph_intern.h +++ b/source/blender/editors/space_graph/graph_intern.h @@ -141,8 +141,17 @@ void GRAPH_OT_ghost_curves_clear(struct wmOperatorType *ot); void GRAPH_OT_properties(struct wmOperatorType *ot); void graph_buttons_register(struct ARegionType *art); +/* ***************************************** */ +/* graph_utils.c */ + struct bAnimListElem *get_active_fcurve_channel(struct bAnimContext *ac); +short fcurve_needs_draw_fmodifier_controls(struct FCurve *fcu, struct FModifier *fcm); + +int graphop_visible_keyframes_poll(struct bContext *C); +int graphop_editable_keyframes_poll(struct bContext *C); +int graphop_active_fcurve_poll(struct bContext *C); + /* ***************************************** */ /* graph_ops.c */ void graphedit_keymap(struct wmWindowManager *wm); diff --git a/source/blender/editors/space_graph/graph_ops.c b/source/blender/editors/space_graph/graph_ops.c index 012bfd944b4..d5e93dafaf0 100644 --- a/source/blender/editors/space_graph/graph_ops.c +++ b/source/blender/editors/space_graph/graph_ops.c @@ -92,7 +92,7 @@ void GRAPH_OT_view_togglehandles (wmOperatorType *ot) /* callbacks */ ot->exec= view_toggle_handles_exec; - ot->poll= ED_operator_areaactive; + ot->poll= ED_operator_ipo_active; } /* ************************** registration - operator types **********************************/ diff --git a/source/blender/editors/space_graph/graph_select.c b/source/blender/editors/space_graph/graph_select.c index afe66ed179e..11af86ca83b 100644 --- a/source/blender/editors/space_graph/graph_select.c +++ b/source/blender/editors/space_graph/graph_select.c @@ -182,7 +182,7 @@ void GRAPH_OT_select_all_toggle (wmOperatorType *ot) /* api callbacks */ ot->exec= graphkeys_deselectall_exec; - ot->poll= ED_operator_areaactive; + ot->poll= graphop_visible_keyframes_poll; /* flags */ ot->flag= OPTYPE_REGISTER/*|OPTYPE_UNDO*/; @@ -316,7 +316,7 @@ void GRAPH_OT_select_border(wmOperatorType *ot) ot->exec= graphkeys_borderselect_exec; ot->modal= WM_border_select_modal; - ot->poll= ED_operator_areaactive; + ot->poll= graphop_visible_keyframes_poll; /* flags */ ot->flag= OPTYPE_REGISTER/*|OPTYPE_UNDO*/; @@ -506,7 +506,7 @@ void GRAPH_OT_select_column (wmOperatorType *ot) /* api callbacks */ ot->exec= graphkeys_columnselect_exec; - ot->poll= ED_operator_areaactive; + ot->poll= graphop_visible_keyframes_poll; /* flags */ ot->flag= OPTYPE_REGISTER/*|OPTYPE_UNDO*/; @@ -926,7 +926,7 @@ void GRAPH_OT_clickselect (wmOperatorType *ot) /* api callbacks */ ot->invoke= graphkeys_clickselect_invoke; - ot->poll= ED_operator_areaactive; + ot->poll= graphop_visible_keyframes_poll; /* id-props */ // XXX should we make this into separate operators? diff --git a/source/blender/editors/space_graph/graph_utils.c b/source/blender/editors/space_graph/graph_utils.c new file mode 100644 index 00000000000..b1ec795a089 --- /dev/null +++ b/source/blender/editors/space_graph/graph_utils.c @@ -0,0 +1,288 @@ +/** + * $Id: + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2009 Blender Foundation. + * All rights reserved. + * + * + * Contributor(s): Blender Foundation, Joshua Leung + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include <string.h> +#include <stdio.h> +#include <math.h> +#include <float.h> + +#include "DNA_anim_types.h" +#include "DNA_action_types.h" +#include "DNA_object_types.h" +#include "DNA_space_types.h" +#include "DNA_scene_types.h" +#include "DNA_screen_types.h" +#include "DNA_userdef_types.h" + +#include "MEM_guardedalloc.h" + +#include "BLI_arithb.h" +#include "BLI_blenlib.h" +#include "BLI_editVert.h" +#include "BLI_rand.h" + +#include "BKE_animsys.h" +#include "BKE_action.h" +#include "BKE_context.h" +#include "BKE_curve.h" +#include "BKE_customdata.h" +#include "BKE_depsgraph.h" +#include "BKE_fcurve.h" +#include "BKE_object.h" +#include "BKE_global.h" +#include "BKE_scene.h" +#include "BKE_screen.h" +#include "BKE_utildefines.h" + +#include "BIF_gl.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "RNA_access.h" +#include "RNA_define.h" + +#include "ED_anim_api.h" +#include "ED_keyframing.h" +#include "ED_screen.h" +#include "ED_types.h" +#include "ED_util.h" + +#include "UI_interface.h" +#include "UI_resources.h" +#include "UI_view2d.h" + +#include "graph_intern.h" // own include + +/* ************************************************************** */ +/* Active F-Curve */ + +/* Find 'active' F-Curve. It must be editable, since that's the purpose of these buttons (subject to change). + * We return the 'wrapper' since it contains valuable context info (about hierarchy), which will need to be freed + * when the caller is done with it. + */ +bAnimListElem *get_active_fcurve_channel (bAnimContext *ac) +{ + ListBase anim_data = {NULL, NULL}; + int filter= (ANIMFILTER_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_ACTIVE | ANIMFILTER_CURVESONLY); + int items = ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); + + /* We take the first F-Curve only, since some other ones may have had 'active' flag set + * if they were from linked data. + */ + if (items) { + bAnimListElem *ale= (bAnimListElem *)anim_data.first; + + /* remove first item from list, then free the rest of the list and return the stored one */ + BLI_remlink(&anim_data, ale); + BLI_freelistN(&anim_data); + + return ale; + } + + /* no active F-Curve */ + return NULL; +} + +/* ************************************************************** */ +/* Operator Polling Callbacks */ + +/* check if any FModifiers to draw controls for - fcm is 'active' modifier + * used for the polling callbacks + also for drawing + */ +short fcurve_needs_draw_fmodifier_controls (FCurve *fcu, FModifier *fcm) +{ + /* don't draw if there aren't any modifiers at all */ + if (fcu->modifiers.first == NULL) + return 0; + + /* if there's an active modifier - don't draw if it doesn't drastically + * alter the curve... + */ + if (fcm) { + switch (fcm->type) { + /* clearly harmless */ + case FMODIFIER_TYPE_CYCLES: + return 0; + + /* borderline... */ + case FMODIFIER_TYPE_NOISE: + return 0; + } + } + + /* if only one modifier - don't draw if it is muted or disabled */ + if (fcu->modifiers.first == fcu->modifiers.last) { + fcm= fcu->modifiers.first; + if (fcm->flag & (FMODIFIER_FLAG_DISABLED|FMODIFIER_FLAG_MUTED)) + return 0; + } + + /* if only active modifier - don't draw if it is muted or disabled */ + if (fcm) { + if (fcm->flag & (FMODIFIER_FLAG_DISABLED|FMODIFIER_FLAG_MUTED)) + return 0; + } + + /* if we're still here, this means that there are modifiers with controls to be drawn */ + // FIXME: what happens if all the modifiers were muted/disabled + return 1; +} + +/* ------------------- */ + +/* Check if there are any visible keyframes (for selection tools) */ +int graphop_visible_keyframes_poll (bContext *C) +{ + bAnimContext ac; + bAnimListElem *ale; + ListBase anim_data = {NULL, NULL}; + ScrArea *sa= CTX_wm_area(C); + int filter, items; + short found = 0; + + /* firstly, check if in Graph Editor */ + // TODO: also check for region? + if ((sa == NULL) || (sa->spacetype != SPACE_IPO)) + return 0; + + /* try to init Anim-Context stuff ourselves and check */ + if (ANIM_animdata_get_context(C, &ac) == 0) + return 0; + + /* loop over the visible (selection doesn't matter) F-Curves, and see if they're suitable + * stopping on the first successful match + */ + filter= (ANIMFILTER_VISIBLE | ANIMFILTER_CURVESONLY); + items = ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); + if (items == 0) + return 0; + + for (ale = anim_data.first; ale; ale= ale->next) { + FCurve *fcu= (FCurve *)ale->data; + FModifier *fcm; + + /* visible curves for selection must fulfull the following criteria: + * - it has bezier keyframes + * - F-Curve modifiers do not interfere with the result too much + * (i.e. the modifier-control drawing check returns false) + */ + if (fcu->bezt == NULL) + continue; + fcm= fcurve_find_active_modifier(fcu); + + found= (fcurve_needs_draw_fmodifier_controls(fcu, fcm) == 0); + if (found) break; + } + + /* cleanup and return findings */ + BLI_freelistN(&anim_data); + return found; +} + +/* Check if there are any visible + editable keyframes (for editing tools) */ +int graphop_editable_keyframes_poll (bContext *C) +{ + bAnimContext ac; + bAnimListElem *ale; + ListBase anim_data = {NULL, NULL}; + ScrArea *sa= CTX_wm_area(C); + int filter, items; + short found = 0; + + /* firstly, check if in Graph Editor */ + // TODO: also check for region? + if ((sa == NULL) || (sa->spacetype != SPACE_IPO)) + return 0; + + /* try to init Anim-Context stuff ourselves and check */ + if (ANIM_animdata_get_context(C, &ac) == 0) + return 0; + + /* loop over the editable (selected + editable) F-Curves, and see if they're suitable + * stopping on the first successful match + */ + filter= (ANIMFILTER_VISIBLE | ANIMFILTER_SEL | ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY); + items = ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); + if (items == 0) + return 0; + + for (ale = anim_data.first; ale; ale= ale->next) { + FCurve *fcu= (FCurve *)ale->data; + FModifier *fcm; + + /* editable curves must fulfull the following criteria: + * - it has bezier keyframes + * - it must not be protected from editing (this is already checked for with the foredit flag + * - F-Curve modifiers do not interfere with the result too much + * (i.e. the modifier-control drawing check returns false) + */ + if (fcu->bezt == NULL) + continue; + fcm= fcurve_find_active_modifier(fcu); + + found= (fcurve_needs_draw_fmodifier_controls(fcu, fcm) == 0); + if (found) break; + } + + /* cleanup and return findings */ + BLI_freelistN(&anim_data); + return found; +} + +/* has active F-Curve that's editable */ +int graphop_active_fcurve_poll (bContext *C) +{ + bAnimContext ac; + bAnimListElem *ale; + ScrArea *sa= CTX_wm_area(C); + short has_fcurve= 0; + + /* firstly, check if in Graph Editor */ + // TODO: also check for region? + if ((sa == NULL) || (sa->spacetype != SPACE_IPO)) + return 0; + + /* try to init Anim-Context stuff ourselves and check */ + if (ANIM_animdata_get_context(C, &ac) == 0) + return 0; + + /* try to get the Active F-Curve */ + ale= get_active_fcurve_channel(&ac); + if (ale == NULL) + return 0; + + /* free temp data... */ + has_fcurve= ((ale->data) && (ale->type == ANIMTYPE_FCURVE)); + MEM_freeN(ale); + + /* return success */ + return has_fcurve; +} + +/* ************************************************************** */ |