Refactor: Anim, use eBezTriple_KeyframeType
in more code
Instead of using `short key_type`, use `eBezTriple_KeyframeType key_type`, so that it's clear which type it is, and so that a `switch()` can cause compiler warnings when it's incomplete. This also adds missing `case`s to `switch`es where necessary, in a way that doesn't affect the outcome. There is one change that looks like it is a functional change, but it should provide the same result: ```diff - size -= 0.8f * key_type; + size *= 0.8f; ``` Since `size = 12` and in this case `key_type = 3`, the numerical values are the same, but now the code is consistently multiplying and thus should scale properly. Furthermore some overly obvious comments are removed and some missing `const` keywords have been added. No functional changes. Pull Request: https://projects.blender.org/blender/blender/pulls/120178
This commit is contained in:
parent
ea567c76ec
commit
85d77b79a6
@ -241,7 +241,7 @@ void initialize_bezt(BezTriple *beztr,
|
||||
|
||||
/* Set keyframe type value (supplied),
|
||||
* which should come from the scene settings in most cases. */
|
||||
BEZKEYTYPE(beztr) = settings.keyframe_type;
|
||||
BEZKEYTYPE_LVALUE(beztr) = settings.keyframe_type;
|
||||
|
||||
/* Set default values for "easing" interpolation mode settings.
|
||||
* NOTE: Even if these modes aren't currently used, if users switch
|
||||
|
@ -35,44 +35,42 @@
|
||||
|
||||
/* *************************** Keyframe Drawing *************************** */
|
||||
|
||||
void draw_keyframe_shape(float x,
|
||||
float y,
|
||||
void draw_keyframe_shape(const float x,
|
||||
const float y,
|
||||
float size,
|
||||
bool sel,
|
||||
short key_type,
|
||||
short mode,
|
||||
float alpha,
|
||||
const bool sel,
|
||||
const eBezTriple_KeyframeType key_type,
|
||||
const short mode,
|
||||
const float alpha,
|
||||
const KeyframeShaderBindings *sh_bindings,
|
||||
short handle_type,
|
||||
short extreme_type)
|
||||
const short handle_type,
|
||||
const short extreme_type)
|
||||
{
|
||||
bool draw_fill = ELEM(mode, KEYFRAME_SHAPE_INSIDE, KEYFRAME_SHAPE_BOTH);
|
||||
bool draw_outline = ELEM(mode, KEYFRAME_SHAPE_FRAME, KEYFRAME_SHAPE_BOTH);
|
||||
|
||||
BLI_assert(draw_fill || draw_outline);
|
||||
|
||||
/* tweak size of keyframe shape according to type of keyframe
|
||||
* - 'proper' keyframes have key_type = 0, so get drawn at full size
|
||||
*/
|
||||
/* Adjust size of keyframe shape according to type of keyframe. */
|
||||
switch (key_type) {
|
||||
case BEZT_KEYTYPE_KEYFRAME: /* must be full size */
|
||||
case BEZT_KEYTYPE_KEYFRAME:
|
||||
break;
|
||||
|
||||
case BEZT_KEYTYPE_BREAKDOWN: /* slightly smaller than normal keyframe */
|
||||
case BEZT_KEYTYPE_BREAKDOWN:
|
||||
size *= 0.85f;
|
||||
break;
|
||||
|
||||
case BEZT_KEYTYPE_MOVEHOLD: /* Slightly smaller than normal keyframes
|
||||
* (but by less than for breakdowns). */
|
||||
case BEZT_KEYTYPE_MOVEHOLD:
|
||||
size *= 0.925f;
|
||||
break;
|
||||
|
||||
case BEZT_KEYTYPE_EXTREME: /* slightly larger */
|
||||
case BEZT_KEYTYPE_EXTREME:
|
||||
size *= 1.2f;
|
||||
break;
|
||||
|
||||
default:
|
||||
size -= 0.8f * key_type;
|
||||
case BEZT_KEYTYPE_JITTER:
|
||||
size *= 0.8f;
|
||||
break;
|
||||
}
|
||||
|
||||
uchar fill_col[4];
|
||||
@ -96,8 +94,8 @@ void draw_keyframe_shape(float x,
|
||||
UI_GetThemeColor4ubv(sel ? TH_KEYTYPE_MOVEHOLD_SELECT : TH_KEYTYPE_MOVEHOLD, fill_col);
|
||||
break;
|
||||
case BEZT_KEYTYPE_KEYFRAME: /* traditional yellowish frames (default theme) */
|
||||
default:
|
||||
UI_GetThemeColor4ubv(sel ? TH_KEYTYPE_KEYFRAME_SELECT : TH_KEYTYPE_KEYFRAME, fill_col);
|
||||
break;
|
||||
}
|
||||
|
||||
/* NOTE: we don't use the straight alpha from the theme, or else effects such as
|
||||
@ -236,7 +234,7 @@ static void draw_keylist_block_gpencil(const DrawKeylistUIData *ctx,
|
||||
case BEZT_KEYTYPE_KEYFRAME:
|
||||
size *= 0.8f;
|
||||
break;
|
||||
default:
|
||||
case BEZT_KEYTYPE_EXTREME:
|
||||
break;
|
||||
}
|
||||
|
||||
@ -363,7 +361,7 @@ static void draw_keylist_keys(const DrawKeylistUIData *ctx,
|
||||
ypos,
|
||||
ctx->icon_size,
|
||||
(ak->sel & SELECT),
|
||||
ak->key_type,
|
||||
eBezTriple_KeyframeType(ak->key_type),
|
||||
KEYFRAME_SHAPE_BOTH,
|
||||
ctx->alpha,
|
||||
sh_bindings,
|
||||
|
@ -1371,7 +1371,7 @@ KeyframeEditFunc ANIM_editkeyframes_ipo(short mode)
|
||||
static short set_keytype_keyframe(KeyframeEditData * /*ked*/, BezTriple *bezt)
|
||||
{
|
||||
if (bezt->f2 & SELECT) {
|
||||
BEZKEYTYPE(bezt) = BEZT_KEYTYPE_KEYFRAME;
|
||||
BEZKEYTYPE_LVALUE(bezt) = BEZT_KEYTYPE_KEYFRAME;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -1379,7 +1379,7 @@ static short set_keytype_keyframe(KeyframeEditData * /*ked*/, BezTriple *bezt)
|
||||
static short set_keytype_breakdown(KeyframeEditData * /*ked*/, BezTriple *bezt)
|
||||
{
|
||||
if (bezt->f2 & SELECT) {
|
||||
BEZKEYTYPE(bezt) = BEZT_KEYTYPE_BREAKDOWN;
|
||||
BEZKEYTYPE_LVALUE(bezt) = BEZT_KEYTYPE_BREAKDOWN;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -1387,7 +1387,7 @@ static short set_keytype_breakdown(KeyframeEditData * /*ked*/, BezTriple *bezt)
|
||||
static short set_keytype_extreme(KeyframeEditData * /*ked*/, BezTriple *bezt)
|
||||
{
|
||||
if (bezt->f2 & SELECT) {
|
||||
BEZKEYTYPE(bezt) = BEZT_KEYTYPE_EXTREME;
|
||||
BEZKEYTYPE_LVALUE(bezt) = BEZT_KEYTYPE_EXTREME;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -1395,7 +1395,7 @@ static short set_keytype_extreme(KeyframeEditData * /*ked*/, BezTriple *bezt)
|
||||
static short set_keytype_jitter(KeyframeEditData * /*ked*/, BezTriple *bezt)
|
||||
{
|
||||
if (bezt->f2 & SELECT) {
|
||||
BEZKEYTYPE(bezt) = BEZT_KEYTYPE_JITTER;
|
||||
BEZKEYTYPE_LVALUE(bezt) = BEZT_KEYTYPE_JITTER;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -1403,30 +1403,32 @@ static short set_keytype_jitter(KeyframeEditData * /*ked*/, BezTriple *bezt)
|
||||
static short set_keytype_moving_hold(KeyframeEditData * /*ked*/, BezTriple *bezt)
|
||||
{
|
||||
if (bezt->f2 & SELECT) {
|
||||
BEZKEYTYPE(bezt) = BEZT_KEYTYPE_MOVEHOLD;
|
||||
BEZKEYTYPE_LVALUE(bezt) = BEZT_KEYTYPE_MOVEHOLD;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
KeyframeEditFunc ANIM_editkeyframes_keytype(short mode)
|
||||
KeyframeEditFunc ANIM_editkeyframes_keytype(const eBezTriple_KeyframeType keyframe_type)
|
||||
{
|
||||
switch (mode) {
|
||||
case BEZT_KEYTYPE_BREAKDOWN: /* breakdown */
|
||||
switch (keyframe_type) {
|
||||
case BEZT_KEYTYPE_BREAKDOWN:
|
||||
return set_keytype_breakdown;
|
||||
|
||||
case BEZT_KEYTYPE_EXTREME: /* extreme keyframe */
|
||||
case BEZT_KEYTYPE_EXTREME:
|
||||
return set_keytype_extreme;
|
||||
|
||||
case BEZT_KEYTYPE_JITTER: /* jitter keyframe */
|
||||
case BEZT_KEYTYPE_JITTER:
|
||||
return set_keytype_jitter;
|
||||
|
||||
case BEZT_KEYTYPE_MOVEHOLD: /* moving hold */
|
||||
case BEZT_KEYTYPE_MOVEHOLD:
|
||||
return set_keytype_moving_hold;
|
||||
|
||||
case BEZT_KEYTYPE_KEYFRAME: /* proper keyframe */
|
||||
default:
|
||||
case BEZT_KEYTYPE_KEYFRAME:
|
||||
return set_keytype_keyframe;
|
||||
}
|
||||
|
||||
BLI_assert_unreachable();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* ------- */
|
||||
|
@ -518,7 +518,7 @@ static ActKeyColumn *nalloc_ak_cel(void *data)
|
||||
/* Store settings based on state of BezTriple */
|
||||
ak->cfra = cel.frame_number;
|
||||
ak->sel = (cel.frame.flag & SELECT) != 0;
|
||||
ak->key_type = cel.frame.type;
|
||||
ak->key_type = eBezTriple_KeyframeType(cel.frame.type);
|
||||
|
||||
/* Count keyframes in this column */
|
||||
ak->totkey = 1;
|
||||
@ -559,7 +559,7 @@ static ActKeyColumn *nalloc_ak_gpframe(void *data)
|
||||
/* store settings based on state of BezTriple */
|
||||
ak->cfra = gpf->framenum;
|
||||
ak->sel = (gpf->flag & GP_FRAME_SELECT) ? SELECT : 0;
|
||||
ak->key_type = gpf->key_type;
|
||||
ak->key_type = eBezTriple_KeyframeType(gpf->key_type);
|
||||
|
||||
/* Count keyframes in this column. */
|
||||
ak->totkey = 1;
|
||||
|
@ -10,6 +10,8 @@
|
||||
|
||||
#include "BLI_sys_types.h"
|
||||
|
||||
#include "DNA_curve_types.h"
|
||||
|
||||
struct AnimData;
|
||||
struct ChannelDrawList;
|
||||
struct FCurve;
|
||||
@ -44,7 +46,7 @@ void draw_keyframe_shape(float x,
|
||||
float y,
|
||||
float size,
|
||||
bool sel,
|
||||
short key_type,
|
||||
eBezTriple_KeyframeType key_type,
|
||||
short mode,
|
||||
float alpha,
|
||||
const KeyframeShaderBindings *sh_bindings,
|
||||
|
@ -13,6 +13,8 @@
|
||||
|
||||
#include "ED_anim_api.hh" /* for enum eAnimFilter_Flags */
|
||||
|
||||
#include "DNA_curve_types.h"
|
||||
|
||||
struct BezTriple;
|
||||
struct ButterworthCoefficients;
|
||||
struct FCurve;
|
||||
@ -355,7 +357,7 @@ KeyframeEditFunc ANIM_editkeyframes_handles(short mode);
|
||||
* Set the interpolation type of the selected BezTriples in each F-Curve to the specified one.
|
||||
*/
|
||||
KeyframeEditFunc ANIM_editkeyframes_ipo(short mode);
|
||||
KeyframeEditFunc ANIM_editkeyframes_keytype(short mode);
|
||||
KeyframeEditFunc ANIM_editkeyframes_keytype(eBezTriple_KeyframeType keyframe_type);
|
||||
KeyframeEditFunc ANIM_editkeyframes_easing(short mode);
|
||||
|
||||
/** \} */
|
||||
|
@ -11,6 +11,8 @@
|
||||
#include "BLI_math_vector_types.hh"
|
||||
#include "BLI_range.h"
|
||||
|
||||
#include "DNA_curve_types.h"
|
||||
|
||||
struct AnimData;
|
||||
struct CacheFile;
|
||||
struct FCurve;
|
||||
@ -57,8 +59,7 @@ struct ActKeyColumn {
|
||||
char tree_col;
|
||||
|
||||
/* keyframe info */
|
||||
/** eBezTripe_KeyframeType */
|
||||
char key_type;
|
||||
eBezTriple_KeyframeType key_type;
|
||||
/** eKeyframeHandleDrawOpts */
|
||||
char handle_type;
|
||||
/** eKeyframeExtremeDrawOpts */
|
||||
|
@ -243,8 +243,13 @@ static void def_internal_vicon(int icon_id, VectorDrawFunc drawFunc)
|
||||
|
||||
/* Utilities */
|
||||
|
||||
static void vicon_keytype_draw_wrapper(
|
||||
int x, int y, int w, int h, float alpha, short key_type, short handle_type)
|
||||
static void vicon_keytype_draw_wrapper(const int x,
|
||||
const int y,
|
||||
const int w,
|
||||
const int h,
|
||||
const float alpha,
|
||||
const eBezTriple_KeyframeType key_type,
|
||||
const short handle_type)
|
||||
{
|
||||
/* Initialize dummy theme state for Action Editor - where these colors are defined
|
||||
* (since we're doing this off-screen, free from any particular space_id). */
|
||||
|
@ -1673,7 +1673,7 @@ void ACTION_OT_handle_type(wmOperatorType *ot)
|
||||
* \{ */
|
||||
|
||||
/* this function is responsible for setting keyframe type for keyframes */
|
||||
static void setkeytype_action_keys(bAnimContext *ac, short mode)
|
||||
static void setkeytype_action_keys(bAnimContext *ac, eBezTriple_KeyframeType mode)
|
||||
{
|
||||
ListBase anim_data = {nullptr, nullptr};
|
||||
eAnimFilter_Flags filter;
|
||||
@ -1722,7 +1722,6 @@ static void setkeytype_action_keys(bAnimContext *ac, short mode)
|
||||
static int actkeys_keytype_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
bAnimContext ac;
|
||||
short mode;
|
||||
|
||||
/* get editor data */
|
||||
if (ANIM_animdata_get_context(C, &ac) == 0) {
|
||||
@ -1734,11 +1733,8 @@ static int actkeys_keytype_exec(bContext *C, wmOperator *op)
|
||||
return OPERATOR_PASS_THROUGH;
|
||||
}
|
||||
|
||||
/* get handle setting mode */
|
||||
mode = RNA_enum_get(op->ptr, "type");
|
||||
|
||||
/* set handle type */
|
||||
setkeytype_action_keys(&ac, mode);
|
||||
const int mode = RNA_enum_get(op->ptr, "type");
|
||||
setkeytype_action_keys(&ac, eBezTriple_KeyframeType(mode));
|
||||
|
||||
/* set notifier that keyframe properties have changed */
|
||||
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME_PROP, nullptr);
|
||||
|
@ -111,7 +111,8 @@ typedef struct BezTriple {
|
||||
* Provide access to Keyframe Type info #eBezTriple_KeyframeType in #BezTriple::hide.
|
||||
* \note this is so that we can change it to another location.
|
||||
*/
|
||||
#define BEZKEYTYPE(bezt) ((bezt)->hide)
|
||||
#define BEZKEYTYPE(bezt) (eBezTriple_KeyframeType((bezt)->hide))
|
||||
#define BEZKEYTYPE_LVALUE(bezt) ((bezt)->hide)
|
||||
|
||||
/**
|
||||
* \note #BPoint.tilt location in struct is abused by Key system.
|
||||
|
Loading…
Reference in New Issue
Block a user