me-main #1

Merged
Nate Rupsis merged 123 commits from me-main into main 2023-02-13 18:39:11 +01:00
8 changed files with 133 additions and 109 deletions
Showing only changes of commit 666c2ea012 - Show all commits

View File

@ -4373,6 +4373,53 @@ static bool achannel_is_being_renamed(const bAnimContext *ac,
return false;
}
float ANIM_UI_get_keyframe_scale_factor(void)
{
bTheme *btheme = UI_GetTheme();
const float yscale_fac = btheme->space_action.keyframe_scale_fac;
/* clamp to avoid problems with uninitialized values... */
if (yscale_fac < 0.1f) {
return 1.0f;
}
return yscale_fac;
}
float ANIM_UI_get_channel_height(void)
{
return 0.8f * ANIM_UI_get_keyframe_scale_factor() * U.widget_unit;
}
float ANIM_UI_get_channel_skip(void)
{
return 0.1f * U.widget_unit;
}
float ANIM_UI_get_first_channel_top(View2D *v2d)
{
return UI_view2d_scale_get_y(v2d) * -UI_TIME_SCRUB_MARGIN_Y - ANIM_UI_get_channel_skip();
}
float ANIM_UI_get_channel_step(void)
{
return ANIM_UI_get_channel_height() + ANIM_UI_get_channel_skip();
}
float ANIM_UI_get_channels_total_height(View2D *v2d, const int item_count)
{
return ANIM_UI_get_first_channel_top(v2d) + ANIM_UI_get_channel_step() * (item_count + 1);
}
float ANIM_UI_get_channel_name_width(void)
{
return 10 * U.widget_unit;
}
float ANIM_UI_get_channel_button_width(void)
{
return 0.8f * U.widget_unit;
}
void ANIM_channel_draw(
bAnimContext *ac, bAnimListElem *ale, float yminc, float ymaxc, size_t channel_index)
{
@ -4566,7 +4613,8 @@ void ANIM_channel_draw(
}
/* 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) > ANIM_UI_get_channel_button_width() / 2)) {
/* protect... */
if (acf->has_setting(ac, ale, ACHANNEL_SETTING_PROTECT)) {
offset += ICON_WIDTH;
@ -5279,7 +5327,8 @@ void ANIM_channel_draw_widgets(const bContext *C,
}
/* 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) > ANIM_UI_get_channel_button_width() / 2)) {
/* protect... */
if (acf->has_setting(ac, ale, ACHANNEL_SETTING_PROTECT)) {
offset -= ICON_WIDTH;

View File

@ -2718,7 +2718,7 @@ static void box_select_anim_channels(bAnimContext *ac, rcti *rect, short selectm
ymax = NLACHANNEL_FIRST_TOP(ac);
}
else {
ymax = ACHANNEL_FIRST_TOP(ac);
ymax = ANIM_UI_get_first_channel_top(v2d);
}
/* loop over data, doing box select */
@ -2726,7 +2726,7 @@ static void box_select_anim_channels(bAnimContext *ac, rcti *rect, short selectm
float ymin;
if (ale->type == ANIMTYPE_GPDATABLOCK) {
ymax -= ACHANNEL_STEP(ac);
ymax -= ANIM_UI_get_channel_step();
continue;
}
@ -2734,7 +2734,7 @@ static void box_select_anim_channels(bAnimContext *ac, rcti *rect, short selectm
ymin = ymax - NLACHANNEL_STEP(snla);
}
else {
ymin = ymax - ACHANNEL_STEP(ac);
ymin = ymax - ANIM_UI_get_channel_step();
}
/* if channel is within border-select region, alter it */
@ -2948,10 +2948,10 @@ static int animchannels_channel_get(bAnimContext *ac, const int mval[2])
&channel_index);
}
else {
UI_view2d_listview_view_to_cell(ACHANNEL_NAMEWIDTH,
ACHANNEL_STEP(ac),
UI_view2d_listview_view_to_cell(ANIM_UI_get_channel_name_width(),
ANIM_UI_get_channel_step(),
0,
ACHANNEL_FIRST_TOP(ac),
ANIM_UI_get_first_channel_top(v2d),
x,
y,
NULL,
@ -3484,10 +3484,10 @@ static int animchannels_mouseclick_invoke(bContext *C, wmOperator *op, const wmE
/* figure out which channel user clicked in */
UI_view2d_region_to_view(v2d, event->mval[0], event->mval[1], &x, &y);
UI_view2d_listview_view_to_cell(ACHANNEL_NAMEWIDTH,
ACHANNEL_STEP(&ac),
UI_view2d_listview_view_to_cell(ANIM_UI_get_channel_name_width(),
ANIM_UI_get_channel_step(),
0,
ACHANNEL_FIRST_TOP(&ac),
ANIM_UI_get_first_channel_top(v2d),
x,
y,
NULL,

View File

@ -92,26 +92,6 @@
/* ************************************************************ */
/* Blender Context <-> Animation Context mapping */
/* ----------- Private Stuff - General -------------------- */
/* Get vertical scaling factor (i.e. typically used for keyframe size) */
static void animedit_get_yscale_factor(bAnimContext *ac)
{
bTheme *btheme = UI_GetTheme();
/* grab scale factor directly from action editor setting
* NOTE: This theme setting doesn't have an ID, as it cannot be accessed normally
* since it is a float, and the theme settings methods can only handle chars.
*/
ac->yscale_fac = btheme->space_action.keyframe_scale_fac;
/* clamp to avoid problems with uninitialized values... */
if (ac->yscale_fac < 0.1f) {
ac->yscale_fac = 1.0f;
}
// printf("yscale_fac = %f\n", ac->yscale_fac);
}
/* ----------- Private Stuff - Action Editor ------------- */
/* Get shapekey data being edited (for Action Editor -> ShapeKey mode) */
@ -408,9 +388,6 @@ bool ANIM_animdata_get_context(const bContext *C, bAnimContext *ac)
ac->spacetype = (area) ? area->spacetype : 0;
ac->regiontype = (region) ? region->regiontype : 0;
/* Initialize default y-scale factor. */
animedit_get_yscale_factor(ac);
/* get data context info */
/* XXX: if the below fails, try to grab this info from context instead...
* (to allow for scripting). */

View File

@ -94,8 +94,6 @@ typedef struct bAnimContext {
/** pointer to current reports list */
struct ReportList *reports;
/** Scale factor for height of channels (i.e. based on the size of keyframes). */
float yscale_fac;
} bAnimContext;
/* Main Data container types */
@ -430,28 +428,6 @@ ENUM_OPERATORS(eAnimFilter_Flags, ANIMFILTER_TMP_IGNORE_ONLYSEL);
/** \} */
/* -------------------------------------------------------------------- */
/** \name Channel Defines
* \{ */
/** Channel heights. */
#define ACHANNEL_FIRST_TOP(ac) \
(UI_view2d_scale_get_y(&(ac)->region->v2d) * -UI_TIME_SCRUB_MARGIN_Y - ACHANNEL_SKIP)
#define ACHANNEL_HEIGHT(ac) (0.8f * (ac)->yscale_fac * U.widget_unit)
#define ACHANNEL_SKIP (0.1f * U.widget_unit)
#define ACHANNEL_STEP(ac) (ACHANNEL_HEIGHT(ac) + ACHANNEL_SKIP)
/** Additional offset to give some room at the end. */
#define ACHANNEL_TOT_HEIGHT(ac, item_amount) \
(-ACHANNEL_FIRST_TOP(ac) + ACHANNEL_STEP(ac) * (item_amount + 1))
/** Channel widths. */
#define ACHANNEL_NAMEWIDTH (10 * U.widget_unit)
/** Channel toggle-buttons. */
#define ACHANNEL_BUTTON_WIDTH (0.8f * U.widget_unit)
/** \} */
/* -------------------------------------------------------------------- */
/** \name NLA Channel Defines
* \{ */
@ -612,6 +588,20 @@ typedef struct bAnimChannelType {
void *(*setting_ptr)(bAnimListElem *ale, eAnimChannel_Settings setting, short *type);
} bAnimChannelType;
/** \} */
/* -------------------------------------------------------------------- */
/** \name Channel dimensions API
* \{ */
float ANIM_UI_get_keyframe_scale_factor(void);
float ANIM_UI_get_channel_height(void);
float ANIM_UI_get_channel_skip(void);
float ANIM_UI_get_first_channel_top(View2D *v2d);
float ANIM_UI_get_channel_step(void);
float ANIM_UI_get_channels_total_height(View2D *v2d, int item_count);
float ANIM_UI_get_channel_name_width(void);
float ANIM_UI_get_channel_button_width(void);
/** \} */
/* -------------------------------------------------------------------- */

View File

@ -60,19 +60,20 @@ void draw_channel_names(bContext *C, bAnimContext *ac, ARegion *region)
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS);
items = ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
int height = ACHANNEL_TOT_HEIGHT(ac, items);
const int height = ANIM_UI_get_channels_total_height(v2d, items);
v2d->tot.ymin = -height;
/* need to do a view-sync here, so that the keys area doesn't jump around (it must copy this) */
UI_view2d_sync(NULL, ac->area, v2d, V2D_LOCK_COPY);
const float channel_step = ANIM_UI_get_channel_step();
/* Loop through channels, and set up drawing depending on their type. */
{ /* first pass: just the standard GL-drawing for backdrop + text */
size_t channel_index = 0;
float ymax = ACHANNEL_FIRST_TOP(ac);
float ymax = ANIM_UI_get_first_channel_top(v2d);
for (ale = anim_data.first; ale; ale = ale->next, ymax -= ACHANNEL_STEP(ac), channel_index++) {
float ymin = ymax - ACHANNEL_HEIGHT(ac);
for (ale = anim_data.first; ale; ale = ale->next, ymax -= channel_step, channel_index++) {
const float ymin = ymax - ANIM_UI_get_channel_height();
/* check if visible */
if (IN_RANGE(ymin, v2d->cur.ymin, v2d->cur.ymax) ||
@ -85,10 +86,10 @@ void draw_channel_names(bContext *C, bAnimContext *ac, ARegion *region)
{ /* second pass: widgets */
uiBlock *block = UI_block_begin(C, region, __func__, UI_EMBOSS);
size_t channel_index = 0;
float ymax = ACHANNEL_FIRST_TOP(ac);
float ymax = ANIM_UI_get_first_channel_top(v2d);
for (ale = anim_data.first; ale; ale = ale->next, ymax -= ACHANNEL_STEP(ac), channel_index++) {
float ymin = ymax - ACHANNEL_HEIGHT(ac);
for (ale = anim_data.first; ale; ale = ale->next, ymax -= channel_step, channel_index++) {
const float ymin = ymax - ANIM_UI_get_channel_height();
/* check if visible */
if (IN_RANGE(ymin, v2d->cur.ymin, v2d->cur.ymax) ||
@ -115,7 +116,7 @@ void draw_channel_names(bContext *C, bAnimContext *ac, ARegion *region)
#define EXTRA_SCROLL_PAD 100.0f
/* Draw manually set intended playback frame ranges for actions. */
static void draw_channel_action_ranges(bAnimContext *ac, ListBase *anim_data, View2D *v2d)
static void draw_channel_action_ranges(ListBase *anim_data, View2D *v2d)
{
/* Variables for coalescing the Y region of one action. */
bAction *cur_action = NULL;
@ -123,8 +124,8 @@ static void draw_channel_action_ranges(bAnimContext *ac, ListBase *anim_data, Vi
float cur_ymax;
/* Walk through channels, grouping contiguous spans referencing the same action. */
float ymax = ACHANNEL_FIRST_TOP(ac) + ACHANNEL_SKIP / 2;
float ystep = ACHANNEL_STEP(ac);
float ymax = ANIM_UI_get_first_channel_top(v2d) + ANIM_UI_get_channel_skip() / 2;
const float ystep = ANIM_UI_get_channel_step();
float ymin = ymax - ystep;
for (bAnimListElem *ale = anim_data->first; ale; ale = ale->next, ymax = ymin, ymin -= ystep) {
@ -193,13 +194,13 @@ void draw_channel_strips(bAnimContext *ac, SpaceAction *saction, ARegion *region
int filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS);
size_t items = ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
int height = ACHANNEL_TOT_HEIGHT(ac, items);
const int height = ANIM_UI_get_channels_total_height(v2d, items);
v2d->tot.ymin = -height;
/* Draw the manual frame ranges for actions in the background of the dopesheet.
* The action editor has already drawn the range for its action so it's not needed. */
if (ac->datatype == ANIMCONT_DOPESHEET) {
draw_channel_action_ranges(ac, &anim_data, v2d);
draw_channel_action_ranges(&anim_data, v2d);
}
/* Draw the background strips. */
@ -211,10 +212,10 @@ void draw_channel_strips(bAnimContext *ac, SpaceAction *saction, ARegion *region
GPU_blend(GPU_BLEND_ALPHA);
/* first backdrop strips */
float ymax = ACHANNEL_FIRST_TOP(ac);
for (ale = anim_data.first; ale; ale = ale->next, ymax -= ACHANNEL_STEP(ac)) {
float ymin = ymax - ACHANNEL_HEIGHT(ac);
float ymax = ANIM_UI_get_first_channel_top(v2d);
const float channel_step = ANIM_UI_get_channel_step();
for (ale = anim_data.first; ale; ale = ale->next, ymax -= channel_step) {
const float ymin = ymax - ANIM_UI_get_channel_height();
/* check if visible */
if (IN_RANGE(ymin, v2d->cur.ymin, v2d->cur.ymax) ||
@ -366,12 +367,14 @@ void draw_channel_strips(bAnimContext *ac, SpaceAction *saction, ARegion *region
action_flag &= ~(SACTION_SHOW_INTERPOLATION | SACTION_SHOW_EXTREMES);
}
ymax = ACHANNEL_FIRST_TOP(ac);
ymax = ANIM_UI_get_first_channel_top(v2d);
struct AnimKeylistDrawList *draw_list = ED_keylist_draw_list_create();
for (ale = anim_data.first; ale; ale = ale->next, ymax -= ACHANNEL_STEP(ac)) {
float ymin = ymax - ACHANNEL_HEIGHT(ac);
const float scale_factor = ANIM_UI_get_keyframe_scale_factor();
for (ale = anim_data.first; ale; ale = ale->next, ymax -= channel_step) {
const float ymin = ymax - ANIM_UI_get_channel_height();
float ycenter = (ymin + ymax) / 2.0f;
/* check if visible */
@ -384,32 +387,28 @@ void draw_channel_strips(bAnimContext *ac, SpaceAction *saction, ARegion *region
/* draw 'keyframes' for each specific datatype */
switch (ale->datatype) {
case ALE_ALL:
draw_summary_channel(draw_list, ale->data, ycenter, ac->yscale_fac, action_flag);
draw_summary_channel(draw_list, ale->data, ycenter, scale_factor, action_flag);
break;
case ALE_SCE:
draw_scene_channel(
draw_list, ads, ale->key_data, ycenter, ac->yscale_fac, action_flag);
draw_scene_channel(draw_list, ads, ale->key_data, ycenter, scale_factor, action_flag);
break;
case ALE_OB:
draw_object_channel(
draw_list, ads, ale->key_data, ycenter, ac->yscale_fac, action_flag);
draw_object_channel(draw_list, ads, ale->key_data, ycenter, scale_factor, action_flag);
break;
case ALE_ACT:
draw_action_channel(
draw_list, adt, ale->key_data, ycenter, ac->yscale_fac, action_flag);
draw_action_channel(draw_list, adt, ale->key_data, ycenter, scale_factor, action_flag);
break;
case ALE_GROUP:
draw_agroup_channel(draw_list, adt, ale->data, ycenter, ac->yscale_fac, action_flag);
draw_agroup_channel(draw_list, adt, ale->data, ycenter, scale_factor, action_flag);
break;
case ALE_FCURVE:
draw_fcurve_channel(
draw_list, adt, ale->key_data, ycenter, ac->yscale_fac, action_flag);
draw_fcurve_channel(draw_list, adt, ale->key_data, ycenter, scale_factor, action_flag);
break;
case ALE_GPFRAME:
draw_gpl_channel(draw_list, ads, ale->data, ycenter, ac->yscale_fac, action_flag);
draw_gpl_channel(draw_list, ads, ale->data, ycenter, scale_factor, action_flag);
break;
case ALE_MASKLAY:
draw_masklay_channel(draw_list, ads, ale->data, ycenter, ac->yscale_fac, action_flag);
draw_masklay_channel(draw_list, ads, ale->data, ycenter, scale_factor, action_flag);
break;
}
}

View File

@ -315,16 +315,16 @@ static bool actkeys_channels_get_selected_extents(bAnimContext *ac, float *r_min
ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
/* loop through all channels, finding the first one that's selected */
float ymax = ACHANNEL_FIRST_TOP(ac);
for (ale = anim_data.first; ale; ale = ale->next, ymax -= ACHANNEL_STEP(ac)) {
float ymax = ANIM_UI_get_first_channel_top(&ac->region->v2d);
const float channel_step = ANIM_UI_get_channel_step();
for (ale = anim_data.first; ale; ale = ale->next, ymax -= channel_step) {
const bAnimChannelType *acf = ANIM_channel_get_typeinfo(ale);
/* must be selected... */
if (acf && acf->has_setting(ac, ale, ACHANNEL_SETTING_SELECT) &&
ANIM_channel_setting_get(ac, ale, ACHANNEL_SETTING_SELECT)) {
/* update best estimate */
*r_min = ymax - ACHANNEL_HEIGHT(ac);
*r_min = ymax - ANIM_UI_get_channel_height();
*r_max = ymax;
/* is this high enough priority yet? */

View File

@ -61,8 +61,14 @@ static bAnimListElem *actkeys_find_list_element_at_position(bAnimContext *ac,
float view_x, view_y;
int channel_index;
UI_view2d_region_to_view(v2d, region_x, region_y, &view_x, &view_y);
UI_view2d_listview_view_to_cell(
0, ACHANNEL_STEP(ac), 0, ACHANNEL_FIRST_TOP(ac), view_x, view_y, NULL, &channel_index);
UI_view2d_listview_view_to_cell(0,
ANIM_UI_get_channel_step(),
0,
ANIM_UI_get_first_channel_top(v2d),
view_x,
view_y,
NULL,
&channel_index);
ListBase anim_data = {NULL, NULL};
ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
@ -152,7 +158,7 @@ static void actkeys_find_key_in_list_element(bAnimContext *ac,
AnimData *adt = ANIM_nla_mapping_get(ac, ale);
/* standard channel height (to allow for some slop) */
float key_hsize = ACHANNEL_HEIGHT(ac) * 0.8f;
float key_hsize = ANIM_UI_get_channel_height() * 0.8f;
/* half-size (for either side), but rounded up to nearest int (for easier targeting) */
key_hsize = roundf(key_hsize / 2.0f);
@ -462,14 +468,15 @@ static void box_select_action(bAnimContext *ac, const rcti rect, short mode, sho
/* init editing data */
memset(&sel_data.ked, 0, sizeof(KeyframeEditData));
float ymax = ACHANNEL_FIRST_TOP(ac);
float ymax = ANIM_UI_get_first_channel_top(v2d);
const float channel_step = ANIM_UI_get_channel_step();
/* loop over data, doing box select */
for (ale = anim_data.first; ale; ale = ale->next, ymax -= ACHANNEL_STEP(ac)) {
for (ale = anim_data.first; ale; ale = ale->next, ymax -= channel_step) {
AnimData *adt = ANIM_nla_mapping_get(ac, ale);
/* get new vertical minimum extent of channel */
float ymin = ymax - ACHANNEL_STEP(ac);
float ymin = ymax - channel_step;
/* set horizontal range (if applicable) */
if (ELEM(mode, ACTKEYS_BORDERSEL_FRAMERANGE, ACTKEYS_BORDERSEL_ALLKEYS)) {
@ -713,14 +720,15 @@ static void region_select_action_keys(
sel_data.ked.data = &scaled_rectf;
}
float ymax = ACHANNEL_FIRST_TOP(ac);
float ymax = ANIM_UI_get_first_channel_top(v2d);
const float channel_step = ANIM_UI_get_channel_step();
/* loop over data, doing region select */
for (ale = anim_data.first; ale; ale = ale->next, ymax -= ACHANNEL_STEP(ac)) {
for (ale = anim_data.first; ale; ale = ale->next, ymax -= channel_step) {
AnimData *adt = ANIM_nla_mapping_get(ac, ale);
/* get new vertical minimum extent of channel */
float ymin = ymax - ACHANNEL_STEP(ac);
const float ymin = ymax - channel_step;
/* compute midpoint of channel (used for testing if the key is in the region or not) */
sel_data.ked.channel_y = (ymin + ymax) / 2.0f;

View File

@ -1398,16 +1398,17 @@ void graph_draw_channel_names(bContext *C, bAnimContext *ac, ARegion *region)
/* Update max-extent of channels here (taking into account scrollers):
* - this is done to allow the channel list to be scrollable, but must be done here
* to avoid regenerating the list again and/or also because channels list is drawn first */
height = ACHANNEL_TOT_HEIGHT(ac, items);
height = ANIM_UI_get_channels_total_height(v2d, items);
v2d->tot.ymin = -height;
const float channel_step = ANIM_UI_get_channel_step();
/* Loop through channels, and set up drawing depending on their type. */
{ /* first pass: just the standard GL-drawing for backdrop + text */
size_t channel_index = 0;
float ymax = ACHANNEL_FIRST_TOP(ac);
float ymax = ANIM_UI_get_first_channel_top(v2d);
for (ale = anim_data.first; ale; ale = ale->next, ymax -= ACHANNEL_STEP(ac), channel_index++) {
float ymin = ymax - ACHANNEL_HEIGHT(ac);
for (ale = anim_data.first; ale; ale = ale->next, ymax -= channel_step, channel_index++) {
const float ymin = ymax - ANIM_UI_get_channel_height();
/* check if visible */
if (IN_RANGE(ymin, v2d->cur.ymin, v2d->cur.ymax) ||
@ -1420,13 +1421,13 @@ void graph_draw_channel_names(bContext *C, bAnimContext *ac, ARegion *region)
{ /* second pass: widgets */
uiBlock *block = UI_block_begin(C, region, __func__, UI_EMBOSS);
size_t channel_index = 0;
float ymax = ACHANNEL_FIRST_TOP(ac);
float ymax = ANIM_UI_get_first_channel_top(v2d);
/* set blending again, as may not be set in previous step */
GPU_blend(GPU_BLEND_ALPHA);
for (ale = anim_data.first; ale; ale = ale->next, ymax -= ACHANNEL_STEP(ac), channel_index++) {
float ymin = ymax - ACHANNEL_HEIGHT(ac);
for (ale = anim_data.first; ale; ale = ale->next, ymax -= channel_step, channel_index++) {
const float ymin = ymax - ANIM_UI_get_channel_height();
/* check if visible */
if (IN_RANGE(ymin, v2d->cur.ymin, v2d->cur.ymax) ||