Animation: Vertically locking the NLA so it doesn't scroll to infinity #109473

Merged
Nate Rupsis merged 10 commits from NLA-clamp-scroll into main 2023-07-19 16:12:22 +02:00
4 changed files with 29 additions and 18 deletions

View File

@ -171,6 +171,12 @@ void UI_view2d_mask_from_win(const struct View2D *v2d, struct rcti *r_mask);
void UI_view2d_zoom_cache_reset(void);
/**
* Clamp view2d area to what's visible, preventing
* scrolling vertically to infinity.
*/
Review

Both comment lines above end with extra trailing spaces.

Both comment lines above end with extra trailing spaces.
void UI_view2d_curRect_clamp_y(struct View2D *v2d);
/** \} */
/* -------------------------------------------------------------------- */

View File

@ -847,6 +847,20 @@ void UI_view2d_curRect_changed(const bContext *C, View2D *v2d)
}
}
void UI_view2d_curRect_clamp_y(struct View2D *v2d)
{
const float cur_height_y = BLI_rctf_size_y(&v2d->cur);

I think now that the function has moved the comment doesn't make sense here anymore. Especially because you also have it in nla_main_region_view2d_changed

I think now that the function has moved the comment doesn't make sense here anymore. Especially because you also have it in `nla_main_region_view2d_changed`
if (BLI_rctf_size_y(&v2d->cur) > BLI_rctf_size_y(&v2d->tot)) {
v2d->cur.ymin = -cur_height_y;
v2d->cur.ymax = 0;
}
else if (v2d->cur.ymin < v2d->tot.ymin) {
v2d->cur.ymin = v2d->tot.ymin;
v2d->cur.ymax = v2d->cur.ymin + cur_height_y;
}
}
/* ------------------ */
bool UI_view2d_area_supports_sync(ScrArea *area)

View File

@ -405,21 +405,6 @@ static void saction_channel_region_message_subscribe(const wmRegionMessageSubscr
}
}
static void action_clamp_scroll(ARegion *region)
{
View2D *v2d = &region->v2d;
const float cur_height_y = BLI_rctf_size_y(&v2d->cur);
if (BLI_rctf_size_y(&v2d->cur) > BLI_rctf_size_y(&v2d->tot)) {
v2d->cur.ymin = -cur_height_y;
v2d->cur.ymax = 0;
}
else if (v2d->cur.ymin < v2d->tot.ymin) {
v2d->cur.ymin = v2d->tot.ymin;
v2d->cur.ymax = v2d->cur.ymin + cur_height_y;
}
}
static void action_main_region_listener(const wmRegionListenerParams *params)
{
ARegion *region = params->region;
@ -880,9 +865,8 @@ static void action_space_blend_write(BlendWriter *writer, SpaceLink *sl)
static void action_main_region_view2d_changed(const bContext * /*C*/, ARegion *region)
{
/* V2D_KEEPTOT_STRICT cannot be used to clamp scrolling
* because it also clamps the x-axis to 0. */
action_clamp_scroll(region);
View2D *v2d = &region->v2d;
UI_view2d_curRect_clamp_y(v2d);
}
void ED_spacetype_action()

View File

@ -436,6 +436,12 @@ static void nla_main_region_message_subscribe(const wmRegionMessageSubscribePara
}
}
static void nla_main_region_view2d_changed(const bContext * /*C*/, ARegion *region)
{
View2D *v2d = &region->v2d;
UI_view2d_curRect_clamp_y(v2d);
}
static void nla_channel_region_listener(const wmRegionListenerParams *params)
{
ARegion *region = params->region;
@ -619,6 +625,7 @@ void ED_spacetype_nla()
art->draw_overlay = nla_main_region_draw_overlay;
art->listener = nla_main_region_listener;
art->message_subscribe = nla_main_region_message_subscribe;
art->on_view2d_changed = nla_main_region_view2d_changed;
art->keymapflag = ED_KEYMAP_VIEW2D | ED_KEYMAP_ANIMATION | ED_KEYMAP_FRAMES;
BLI_addhead(&st->regiontypes, art);