Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/animation/anim_channels_defines.c
| Show First 20 Lines • Show All 4,421 Lines • ▼ Show 20 Lines | static void draw_setting_widget(bAnimContext *ac, bAnimListElem *ale, const bAnimChannelType *acf, | ||||
| if ((ale->fcurve_owner_id != NULL && ID_IS_LINKED(ale->fcurve_owner_id)) || | if ((ale->fcurve_owner_id != NULL && ID_IS_LINKED(ale->fcurve_owner_id)) || | ||||
| (ale->id != NULL && ID_IS_LINKED(ale->id))) | (ale->id != NULL && ID_IS_LINKED(ale->id))) | ||||
| { | { | ||||
| UI_but_flag_enable(but, UI_BUT_DISABLED); | UI_but_flag_enable(but, UI_BUT_DISABLED); | ||||
| } | } | ||||
| } | } | ||||
| /* Draw UI widgets the given channel */ | /* Draw UI widgets the given channel */ | ||||
| void ANIM_channel_draw_widgets(const bContext *C, bAnimContext *ac, bAnimListElem *ale, uiBlock *block, float yminc, float ymaxc, size_t channel_index) | void ANIM_channel_draw_widgets( | ||||
| const bContext *C, | |||||
| bAnimContext *ac, | |||||
| bAnimListElem *ale, | |||||
| uiBlock *block, | |||||
| rctf *rect, | |||||
| size_t channel_index) | |||||
| { | { | ||||
| const bAnimChannelType *acf = ANIM_channel_get_typeinfo(ale); | const bAnimChannelType *acf = ANIM_channel_get_typeinfo(ale); | ||||
| View2D *v2d = &ac->ar->v2d; | View2D *v2d = &ac->ar->v2d; | ||||
| float y, ymid /*, ytext*/; | float ymid; | ||||
| short offset; | const short channel_height = round_fl_to_int(BLI_rctf_size_y(rect)); | ||||
| const bool is_being_renamed = achannel_is_being_renamed(ac, acf, channel_index); | const bool is_being_renamed = achannel_is_being_renamed(ac, acf, channel_index); | ||||
| /* sanity checks - don't draw anything */ | /* sanity checks - don't draw anything */ | ||||
| if (ELEM(NULL, acf, ale, block)) | if (ELEM(NULL, acf, ale, block)) | ||||
| return; | return; | ||||
| /* get initial offset */ | /* get initial offset */ | ||||
| if (acf->get_offset) | short offset = rect->xmin; | ||||
| offset = acf->get_offset(ac, ale); | if (acf->get_offset) { | ||||
| else | offset += acf->get_offset(ac, ale); | ||||
| offset = 0; | } | ||||
| /* calculate appropriate y-coordinates for icon buttons | /* calculate appropriate y-coordinates for icon buttons */ | ||||
| */ | ymid = BLI_rctf_cent_y(rect) - 0.5f * ICON_WIDTH; | ||||
| y = (ymaxc - yminc) / 2 + yminc; | |||||
| ymid = y - 0.5f * ICON_WIDTH; | |||||
| /* no button backdrop behind icons */ | /* no button backdrop behind icons */ | ||||
| UI_block_emboss_set(block, UI_EMBOSS_NONE); | UI_block_emboss_set(block, UI_EMBOSS_NONE); | ||||
| /* step 1) draw expand widget ....................................... */ | /* step 1) draw expand widget ....................................... */ | ||||
| if (acf->has_setting(ac, ale, ACHANNEL_SETTING_EXPAND)) { | if (acf->has_setting(ac, ale, ACHANNEL_SETTING_EXPAND)) { | ||||
| draw_setting_widget(ac, ale, acf, block, offset, ymid, ACHANNEL_SETTING_EXPAND); | draw_setting_widget(ac, ale, acf, block, offset, ymid, ACHANNEL_SETTING_EXPAND); | ||||
| offset += ICON_WIDTH; | offset += ICON_WIDTH; | ||||
| ▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | if (is_being_renamed) { | ||||
| PropertyRNA *prop = NULL; | PropertyRNA *prop = NULL; | ||||
| /* draw renaming widget if we can get RNA pointer for it | /* draw renaming widget if we can get RNA pointer for it | ||||
| * NOTE: property may only be available in some cases, even if we have | * NOTE: property may only be available in some cases, even if we have | ||||
| * a callback available (e.g. broken F-Curve rename) | * a callback available (e.g. broken F-Curve rename) | ||||
| */ | */ | ||||
| if (acf->name_prop(ale, &ptr, &prop)) { | if (acf->name_prop(ale, &ptr, &prop)) { | ||||
| const short margin_x = 3 * round_fl_to_int(UI_DPI_FAC); | const short margin_x = 3 * round_fl_to_int(UI_DPI_FAC); | ||||
| const short channel_height = round_fl_to_int(ymaxc - yminc); | |||||
| const short width = ac->ar->winx - offset - (margin_x * 2); | const short width = ac->ar->winx - offset - (margin_x * 2); | ||||
| uiBut *but; | uiBut *but; | ||||
| UI_block_emboss_set(block, UI_EMBOSS); | UI_block_emboss_set(block, UI_EMBOSS); | ||||
| but = uiDefButR(block, UI_BTYPE_TEXT, 1, "", offset + margin_x, yminc, | but = uiDefButR(block, UI_BTYPE_TEXT, 1, "", offset + margin_x, rect->ymin, | ||||
| MAX2(width, RENAME_TEXT_MIN_WIDTH), channel_height, | MAX2(width, RENAME_TEXT_MIN_WIDTH), channel_height, | ||||
| &ptr, RNA_property_identifier(prop), -1, 0, 0, -1, -1, NULL); | &ptr, RNA_property_identifier(prop), -1, 0, 0, -1, -1, NULL); | ||||
| /* copy what outliner does here, see outliner_buttons */ | /* copy what outliner does here, see outliner_buttons */ | ||||
| if (UI_but_active_only(C, ac->ar, block, but) == false) { | if (UI_but_active_only(C, ac->ar, block, but) == false) { | ||||
| ac->ads->renameIndex = 0; | ac->ads->renameIndex = 0; | ||||
| /* send notifiers */ | /* send notifiers */ | ||||
| WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN | NA_RENAME, NULL); | WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN | NA_RENAME, NULL); | ||||
| } | } | ||||
| UI_block_emboss_set(block, UI_EMBOSS_NONE); | UI_block_emboss_set(block, UI_EMBOSS_NONE); | ||||
| } | } | ||||
| else { | else { | ||||
| /* Cannot get property/cannot or rename for some reason, so clear rename index | /* Cannot get property/cannot or rename for some reason, so clear rename index | ||||
| * so that this doesn't hang around, and the name can be drawn normally - T47492 | * so that this doesn't hang around, and the name can be drawn normally - T47492 | ||||
| */ | */ | ||||
| ac->ads->renameIndex = 0; | ac->ads->renameIndex = 0; | ||||
| WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN, NULL); | WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN, NULL); | ||||
| } | } | ||||
| } | } | ||||
| /* step 5) draw mute+protection toggles + (sliders) ....................... */ | /* step 5) draw mute+protection toggles + (sliders) ....................... */ | ||||
| /* reset offset - now goes from RHS of panel */ | /* reset offset - now goes from RHS of panel */ | ||||
| offset = 0; | offset = (int)rect->xmax; | ||||
| // TODO: when drawing sliders, make those draw instead of these toggles if not enough space | // TODO: when drawing sliders, make those draw instead of these toggles if not enough space | ||||
| if (v2d && !is_being_renamed) { | if (v2d && !is_being_renamed) { | ||||
| short draw_sliders = 0; | short draw_sliders = 0; | ||||
| /* check if we need to show the sliders */ | /* check if we need to show the sliders */ | ||||
| if ((ac->sl) && ELEM(ac->spacetype, SPACE_ACTION, SPACE_GRAPH)) { | if ((ac->sl) && ELEM(ac->spacetype, SPACE_ACTION, SPACE_GRAPH)) { | ||||
| switch (ac->spacetype) { | switch (ac->spacetype) { | ||||
| Show All 11 Lines | if ((ac->sl) && ELEM(ac->spacetype, SPACE_ACTION, SPACE_GRAPH)) { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* check if there's enough space for the toggles if the sliders are drawn too */ | /* check if there's enough space for the toggles if the sliders are drawn too */ | ||||
| if (!(draw_sliders) || (BLI_rcti_size_x(&v2d->mask) > ACHANNEL_BUTTON_WIDTH / 2) ) { | if (!(draw_sliders) || (BLI_rcti_size_x(&v2d->mask) > ACHANNEL_BUTTON_WIDTH / 2) ) { | ||||
| /* protect... */ | /* protect... */ | ||||
| if (acf->has_setting(ac, ale, ACHANNEL_SETTING_PROTECT)) { | if (acf->has_setting(ac, ale, ACHANNEL_SETTING_PROTECT)) { | ||||
| offset += ICON_WIDTH; | offset -= ICON_WIDTH; | ||||
| draw_setting_widget(ac, ale, acf, block, (int)v2d->cur.xmax - offset, ymid, ACHANNEL_SETTING_PROTECT); | draw_setting_widget(ac, ale, acf, block, offset, ymid, ACHANNEL_SETTING_PROTECT); | ||||
| } | } | ||||
| /* mute... */ | /* mute... */ | ||||
| if (acf->has_setting(ac, ale, ACHANNEL_SETTING_MUTE)) { | if (acf->has_setting(ac, ale, ACHANNEL_SETTING_MUTE)) { | ||||
| offset += ICON_WIDTH; | offset -= ICON_WIDTH; | ||||
| draw_setting_widget(ac, ale, acf, block, (int)v2d->cur.xmax - offset, ymid, ACHANNEL_SETTING_MUTE); | draw_setting_widget(ac, ale, acf, block, offset, ymid, ACHANNEL_SETTING_MUTE); | ||||
| } | } | ||||
| if (ale->type == ANIMTYPE_GPLAYER) { | if (ale->type == ANIMTYPE_GPLAYER) { | ||||
| /* Not technically "mute" (in terms of anim channels, but this sets layer visibility instead) */ | /* Not technically "mute" (in terms of anim channels, but this sets layer visibility instead) */ | ||||
| offset += ICON_WIDTH; | offset -= ICON_WIDTH; | ||||
| draw_setting_widget(ac, ale, acf, block, (int)v2d->cur.xmax - offset, ymid, ACHANNEL_SETTING_VISIBLE); | draw_setting_widget(ac, ale, acf, block, offset, ymid, ACHANNEL_SETTING_VISIBLE); | ||||
| } | } | ||||
| /* modifiers disable */ | /* modifiers disable */ | ||||
| if (acf->has_setting(ac, ale, ACHANNEL_SETTING_MOD_OFF)) { | if (acf->has_setting(ac, ale, ACHANNEL_SETTING_MOD_OFF)) { | ||||
| /* hack: extra spacing, to avoid touching the mute toggle */ | /* hack: extra spacing, to avoid touching the mute toggle */ | ||||
| offset += ICON_WIDTH * 1.2f; | offset -= ICON_WIDTH * 1.2f; | ||||
| draw_setting_widget(ac, ale, acf, block, (int)v2d->cur.xmax - offset, ymid, ACHANNEL_SETTING_MOD_OFF); | draw_setting_widget(ac, ale, acf, block, offset, ymid, ACHANNEL_SETTING_MOD_OFF); | ||||
| } | } | ||||
| /* ----------- */ | /* ----------- */ | ||||
| /* pinned... */ | /* pinned... */ | ||||
| if (acf->has_setting(ac, ale, ACHANNEL_SETTING_PINNED)) { | if (acf->has_setting(ac, ale, ACHANNEL_SETTING_PINNED)) { | ||||
| offset += ICON_WIDTH; | offset -= ICON_WIDTH; | ||||
| draw_setting_widget(ac, ale, acf, block, (int)v2d->cur.xmax - offset, ymid, ACHANNEL_SETTING_PINNED); | draw_setting_widget(ac, ale, acf, block, offset, ymid, ACHANNEL_SETTING_PINNED); | ||||
| } | } | ||||
| /* NLA Action "pushdown" */ | /* NLA Action "pushdown" */ | ||||
| if ((ale->type == ANIMTYPE_NLAACTION) && (ale->adt && ale->adt->action) && !(ale->adt->flag & ADT_NLA_EDIT_ON)) { | if ((ale->type == ANIMTYPE_NLAACTION) && (ale->adt && ale->adt->action) && !(ale->adt->flag & ADT_NLA_EDIT_ON)) { | ||||
| uiBut *but; | uiBut *but; | ||||
| PointerRNA *opptr_b; | PointerRNA *opptr_b; | ||||
| UI_block_emboss_set(block, UI_EMBOSS); | UI_block_emboss_set(block, UI_EMBOSS); | ||||
| offset += UI_UNIT_X; | offset -= UI_UNIT_X; | ||||
| but = uiDefIconButO(block, UI_BTYPE_BUT, "NLA_OT_action_pushdown", WM_OP_INVOKE_DEFAULT, ICON_NLA_PUSHDOWN, | but = uiDefIconButO(block, UI_BTYPE_BUT, "NLA_OT_action_pushdown", WM_OP_INVOKE_DEFAULT, ICON_NLA_PUSHDOWN, | ||||
| (int)v2d->cur.xmax - offset, ymid, UI_UNIT_X, UI_UNIT_X, NULL); | offset, ymid, UI_UNIT_X, UI_UNIT_X, NULL); | ||||
| opptr_b = UI_but_operator_ptr_get(but); | opptr_b = UI_but_operator_ptr_get(but); | ||||
| RNA_int_set(opptr_b, "channel_index", channel_index); | RNA_int_set(opptr_b, "channel_index", channel_index); | ||||
| UI_block_emboss_set(block, UI_EMBOSS_NONE); | UI_block_emboss_set(block, UI_EMBOSS_NONE); | ||||
| } | } | ||||
| } | } | ||||
| /* draw slider | /* draw slider | ||||
| * - even if we can draw sliders for this view, we must also check that the channel-type supports them | * - even if we can draw sliders for this view, we must also check that the channel-type supports them | ||||
| * (only only F-Curves really can support them for now) | * (only only F-Curves really can support them for now) | ||||
| * - to make things easier, we use RNA-autobuts for this so that changes are reflected immediately, | * - to make things easier, we use RNA-autobuts for this so that changes are reflected immediately, | ||||
| * wherever they occurred. BUT, we don't use the layout engine, otherwise we'd get wrong alignment, | * wherever they occurred. BUT, we don't use the layout engine, otherwise we'd get wrong alignment, | ||||
| * and wouldn't be able to auto-keyframe... | * and wouldn't be able to auto-keyframe... | ||||
| * - slider should start before the toggles (if they're visible) to keep a clean line down the side | * - slider should start before the toggles (if they're visible) to keep a clean line down the side | ||||
| */ | */ | ||||
| if ((draw_sliders) && ELEM(ale->type, ANIMTYPE_FCURVE, ANIMTYPE_NLACURVE, ANIMTYPE_SHAPEKEY)) { | if ((draw_sliders) && ELEM(ale->type, ANIMTYPE_FCURVE, ANIMTYPE_NLACURVE, ANIMTYPE_SHAPEKEY)) { | ||||
| /* adjust offset */ | /* adjust offset */ | ||||
| // TODO: make slider width dynamic, so that they can be easier to use when the view is wide enough | // TODO: make slider width dynamic, so that they can be easier to use when the view is wide enough | ||||
| offset += SLIDER_WIDTH; | offset -= SLIDER_WIDTH; | ||||
| /* need backdrop behind sliders... */ | /* need backdrop behind sliders... */ | ||||
| UI_block_emboss_set(block, UI_EMBOSS); | UI_block_emboss_set(block, UI_EMBOSS); | ||||
| if (ale->owner) { /* Slider using custom RNA Access ---------- */ | if (ale->owner) { /* Slider using custom RNA Access ---------- */ | ||||
| if (ale->type == ANIMTYPE_NLACURVE) { | if (ale->type == ANIMTYPE_NLACURVE) { | ||||
| NlaStrip *strip = (NlaStrip *)ale->owner; | NlaStrip *strip = (NlaStrip *)ale->owner; | ||||
| FCurve *fcu = (FCurve *)ale->data; | FCurve *fcu = (FCurve *)ale->data; | ||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| PropertyRNA *prop; | PropertyRNA *prop; | ||||
| /* create RNA pointers */ | /* create RNA pointers */ | ||||
| RNA_pointer_create(ale->id, &RNA_NlaStrip, strip, &ptr); | RNA_pointer_create(ale->id, &RNA_NlaStrip, strip, &ptr); | ||||
| prop = RNA_struct_find_property(&ptr, fcu->rna_path); | prop = RNA_struct_find_property(&ptr, fcu->rna_path); | ||||
| /* create property slider */ | /* create property slider */ | ||||
| if (prop) { | if (prop) { | ||||
| uiBut *but; | uiBut *but; | ||||
| /* create the slider button, and assign relevant callback to ensure keyframes are inserted... */ | /* create the slider button, and assign relevant callback to ensure keyframes are inserted... */ | ||||
| but = uiDefAutoButR(block, &ptr, prop, fcu->array_index, "", ICON_NONE, (int)v2d->cur.xmax - offset, ymid, SLIDER_WIDTH, (int)ymaxc - yminc); | but = uiDefAutoButR(block, &ptr, prop, fcu->array_index, "", ICON_NONE, offset, ymid, SLIDER_WIDTH, channel_height); | ||||
| UI_but_func_set(but, achannel_setting_slider_nla_curve_cb, ale->id, ale->data); | UI_but_func_set(but, achannel_setting_slider_nla_curve_cb, ale->id, ale->data); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else if (ale->id) { /* Slider using RNA Access --------------- */ | else if (ale->id) { /* Slider using RNA Access --------------- */ | ||||
| PointerRNA id_ptr, ptr; | PointerRNA id_ptr, ptr; | ||||
| PropertyRNA *prop; | PropertyRNA *prop; | ||||
| char *rna_path = NULL; | char *rna_path = NULL; | ||||
| Show All 20 Lines | if ((draw_sliders) && ELEM(ale->type, ANIMTYPE_FCURVE, ANIMTYPE_NLACURVE, ANIMTYPE_SHAPEKEY)) { | ||||
| /* get RNA pointer, and resolve the path */ | /* get RNA pointer, and resolve the path */ | ||||
| RNA_id_pointer_create(ale->id, &id_ptr); | RNA_id_pointer_create(ale->id, &id_ptr); | ||||
| /* try to resolve the path */ | /* try to resolve the path */ | ||||
| if (RNA_path_resolve_property(&id_ptr, rna_path, &ptr, &prop)) { | if (RNA_path_resolve_property(&id_ptr, rna_path, &ptr, &prop)) { | ||||
| uiBut *but; | uiBut *but; | ||||
| /* create the slider button, and assign relevant callback to ensure keyframes are inserted... */ | /* create the slider button, and assign relevant callback to ensure keyframes are inserted... */ | ||||
| but = uiDefAutoButR(block, &ptr, prop, array_index, "", ICON_NONE, (int)v2d->cur.xmax - offset, ymid, SLIDER_WIDTH, (int)ymaxc - yminc); | but = uiDefAutoButR(block, &ptr, prop, array_index, "", ICON_NONE, offset, ymid, SLIDER_WIDTH, channel_height); | ||||
| /* assign keyframing function according to slider type */ | /* assign keyframing function according to slider type */ | ||||
| if (ale->type == ANIMTYPE_SHAPEKEY) | if (ale->type == ANIMTYPE_SHAPEKEY) | ||||
| UI_but_func_set(but, achannel_setting_slider_shapekey_cb, ale->id, ale->data); | UI_but_func_set(but, achannel_setting_slider_shapekey_cb, ale->id, ale->data); | ||||
| else | else | ||||
| UI_but_func_set(but, achannel_setting_slider_cb, ale->id, ale->data); | UI_but_func_set(but, achannel_setting_slider_cb, ale->id, ale->data); | ||||
| } | } | ||||
| Show All 13 Lines | |||||