diff options
Diffstat (limited to 'source/blender/editors/space_graph/graph_edit.c')
-rw-r--r-- | source/blender/editors/space_graph/graph_edit.c | 162 |
1 files changed, 158 insertions, 4 deletions
diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c index 3de3ecebc44..f55a9dc45f3 100644 --- a/source/blender/editors/space_graph/graph_edit.c +++ b/source/blender/editors/space_graph/graph_edit.c @@ -59,6 +59,7 @@ #include "BKE_nla.h" #include "BKE_context.h" #include "BKE_report.h" +#include "BKE_screen.h" #include "UI_view2d.h" @@ -982,7 +983,7 @@ void GRAPH_OT_delete(wmOperatorType *ot) /* ******************** Clean Keyframes Operator ************************* */ -static void clean_graph_keys(bAnimContext *ac, float thresh) +static void clean_graph_keys(bAnimContext *ac, float thresh, bool clean_chan) { ListBase anim_data = {NULL, NULL}; bAnimListElem *ale; @@ -994,7 +995,7 @@ static void clean_graph_keys(bAnimContext *ac, float thresh) /* loop through filtered data and clean curves */ for (ale = anim_data.first; ale; ale = ale->next) { - clean_fcurve((FCurve *)ale->key_data, thresh); + clean_fcurve(ac, ale, thresh, clean_chan); ale->update |= ANIM_UPDATE_DEFAULT; } @@ -1009,6 +1010,7 @@ static int graphkeys_clean_exec(bContext *C, wmOperator *op) { bAnimContext ac; float thresh; + bool clean_chan; /* get editor data */ if (ANIM_animdata_get_context(C, &ac) == 0) @@ -1016,9 +1018,9 @@ static int graphkeys_clean_exec(bContext *C, wmOperator *op) /* get cleaning threshold */ thresh = RNA_float_get(op->ptr, "threshold"); - + clean_chan = RNA_boolean_get(op->ptr, "channels"); /* clean keyframes */ - clean_graph_keys(&ac, thresh); + clean_graph_keys(&ac, thresh, clean_chan); /* set notifier that keyframes have changed */ WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL); @@ -1043,6 +1045,7 @@ void GRAPH_OT_clean(wmOperatorType *ot) /* properties */ ot->prop = RNA_def_float(ot->srna, "threshold", 0.001f, 0.0f, FLT_MAX, "Threshold", "", 0.0f, 1000.0f); + RNA_def_boolean(ot->srna, "channels", false, "Channels", ""); } /* ******************** Bake F-Curve Operator *********************** */ @@ -2491,3 +2494,154 @@ void GRAPH_OT_fmodifier_paste(wmOperatorType *ot) } /* ************************************************************************** */ + +typedef struct BackDropTransformData { + float init_offset[2]; + float init_zoom; + short event_type; + wmWidgetGroupType *cagetype; +} BackDropTransformData; + +static int graph_widget_backdrop_transform_poll(bContext *C) +{ + SpaceIpo *sipo = CTX_wm_space_graph(C); + ARegion *ar = CTX_wm_region(C); + + return ((sipo != NULL) && + (ar->type->regionid == RGN_TYPE_WINDOW) && + (sipo->flag & SIPO_DRAW_BACKDROP) && + (sipo->backdrop_camera)); +} + +static void widgetgroup_backdrop_draw(const struct bContext *C, struct wmWidgetGroup *wgroup) +{ + ARegion *ar = CTX_wm_region(C); + wmOperator *op = wgroup->type->op; + Scene *scene = CTX_data_scene(C); + int width = (scene->r.size * scene->r.xsch) / 150.0f; + int height = (scene->r.size * scene->r.ysch) / 150.0f; + float origin[3]; + + wmWidget *cage = WIDGET_rect_transform_new(wgroup, WIDGET_RECT_TRANSFORM_STYLE_SCALE_UNIFORM | + WIDGET_RECT_TRANSFORM_STYLE_TRANSLATE, width, height); + WM_widget_property(cage, RECT_TRANSFORM_SLOT_OFFSET, op->ptr, "offset"); + WM_widget_property(cage, RECT_TRANSFORM_SLOT_SCALE, op->ptr, "scale"); + + origin[0] = BLI_rcti_size_x(&ar->winrct) / 2.0f; + origin[1] = BLI_rcti_size_y(&ar->winrct) / 2.0f; + + WM_widget_set_origin(cage, origin); +} + +static int graph_widget_backdrop_transform_invoke(bContext *C, wmOperator *op, const wmEvent *event) +{ + ScrArea *sa = CTX_wm_area(C); + SpaceIpo *sipo = CTX_wm_space_graph(C); + /* no poll, lives always for the duration of the operator */ + wmWidgetGroupType *cagetype = WM_widgetgrouptype_new(NULL, widgetgroup_backdrop_draw, CTX_data_main(C), "Graph_Canvas", SPACE_IPO, RGN_TYPE_WINDOW, false); + struct wmEventHandler *handler = WM_event_add_modal_handler(C, op); + BackDropTransformData *data = MEM_mallocN(sizeof(BackDropTransformData), "overdrop transform data"); + WM_modal_handler_attach_widgetgroup(C, handler, cagetype, op); + + RNA_float_set_array(op->ptr, "offset", sipo->backdrop_offset); + RNA_float_set(op->ptr, "scale", sipo->backdrop_zoom); + + copy_v2_v2(data->init_offset, sipo->backdrop_offset); + data->init_zoom = sipo->backdrop_zoom; + data->cagetype = cagetype; + data->event_type = event->type; + + op->customdata = data; + + ED_area_headerprint(sa, "Drag to place, and scale, Space/Enter/Caller key to confirm, R to recenter, RClick/Esc to cancel"); + + return OPERATOR_RUNNING_MODAL; +} + +static void graph_widget_backdrop_transform_finish(bContext *C, BackDropTransformData *data) +{ + ScrArea *sa = CTX_wm_area(C); + ED_area_headerprint(sa, NULL); + WM_widgetgrouptype_unregister(C, CTX_data_main(C), data->cagetype); + MEM_freeN(data); +} + +static void graph_widget_backdrop_transform_cancel(struct bContext *C, struct wmOperator *op) +{ + BackDropTransformData *data = op->customdata; + graph_widget_backdrop_transform_finish(C, data); +} + +static int graph_widget_backdrop_transform_modal(bContext *C, wmOperator *op, const wmEvent *event) +{ + BackDropTransformData *data = op->customdata; + + if (event->type == data->event_type && event->val == KM_PRESS) { + graph_widget_backdrop_transform_finish(C, data); + return OPERATOR_FINISHED; + } + + switch (event->type) { + case EVT_WIDGET_UPDATE: { + SpaceIpo *sipo = CTX_wm_space_graph(C); + RNA_float_get_array(op->ptr, "offset", sipo->backdrop_offset); + sipo->backdrop_zoom = RNA_float_get(op->ptr, "scale"); + break; + } + case RKEY: + { + SpaceIpo *sipo = CTX_wm_space_graph(C); + ARegion *ar = CTX_wm_region(C); + float zero[2] = {0.0f}; + RNA_float_set_array(op->ptr, "offset", zero); + RNA_float_set(op->ptr, "scale", 1.0f); + copy_v2_v2(sipo->backdrop_offset, zero); + sipo->backdrop_zoom = 1.0f; + ED_region_tag_redraw(ar); + /* add a mousemove to refresh the widget */ + WM_event_add_mousemove(C); + break; + } + case RETKEY: + case PADENTER: + case SPACEKEY: + { + graph_widget_backdrop_transform_finish(C, data); + return OPERATOR_FINISHED; + } + case ESCKEY: + case RIGHTMOUSE: + { + SpaceIpo *sipo = CTX_wm_space_graph(C); + copy_v2_v2(sipo->backdrop_offset, data->init_offset); + sipo->backdrop_zoom = data->init_zoom; + + graph_widget_backdrop_transform_finish(C, data); + return OPERATOR_CANCELLED; + } + } + + return OPERATOR_RUNNING_MODAL; +} + +void GRAPH_OT_widget_backdrop_transform(struct wmOperatorType *ot) +{ + float default_offset[2] = {0.0f, 0.0f}; + + /* identifiers */ + ot->name = "Transform Backdrop"; + ot->idname = "GRAPH_OT_widget_backdrop_transform"; + ot->description = ""; + + /* api callbacks */ + ot->invoke = graph_widget_backdrop_transform_invoke; + ot->modal = graph_widget_backdrop_transform_modal; + ot->poll = graph_widget_backdrop_transform_poll; + ot->cancel = graph_widget_backdrop_transform_cancel; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + RNA_def_float_array(ot->srna, "offset", 2, default_offset, FLT_MIN, FLT_MAX, "Offset", "Offset of the backdrop", FLT_MIN, FLT_MAX); + RNA_def_float(ot->srna, "scale", 1.0f, 0.0f, FLT_MAX, "Scale", "Scale of the backdrop", 0.0f, FLT_MAX); +} |