diff options
author | Joshua Leung <aligorith@gmail.com> | 2014-05-09 07:46:21 +0400 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2014-05-09 07:49:36 +0400 |
commit | b3cd9d289a655c60e02494ad7b5f591b469a1ce2 (patch) | |
tree | 40f3c901ea9c7f2ab82e274e3275c9cefeaec79a /source | |
parent | 89abdb606d4e106385b313cfb8c8b2250118ca4d (diff) |
Code cleanup: Define a dedicated "channel_role" field for animchannel types
This makes it easier for finding the active or first selected channel
(where actual data channels need to be favoured over expanders - which come
first), as previously, long switch statements were needed everytime.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/animation/anim_channels_defines.c | 29 | ||||
-rw-r--r-- | source/blender/editors/include/ED_anim_api.h | 17 | ||||
-rw-r--r-- | source/blender/editors/space_action/action_edit.c | 56 |
3 files changed, 44 insertions, 58 deletions
diff --git a/source/blender/editors/animation/anim_channels_defines.c b/source/blender/editors/animation/anim_channels_defines.c index 97e18fff32e..1cd1a26678d 100644 --- a/source/blender/editors/animation/anim_channels_defines.c +++ b/source/blender/editors/animation/anim_channels_defines.c @@ -485,6 +485,7 @@ static void *acf_summary_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings s static bAnimChannelType ACF_SUMMARY = { "Summary", /* type name */ + ACHANNEL_ROLE_EXPANDER, /* role */ acf_summary_color, /* backdrop color */ acf_summary_backdrop, /* backdrop */ @@ -586,6 +587,7 @@ static void *acf_scene_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings set static bAnimChannelType ACF_SCENE = { "Scene", /* type name */ + ACHANNEL_ROLE_EXPANDER, /* role */ acf_generic_root_color, /* backdrop color */ acf_generic_root_backdrop, /* backdrop */ @@ -730,6 +732,7 @@ static void *acf_object_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings se static bAnimChannelType ACF_OBJECT = { "Object", /* type name */ + ACHANNEL_ROLE_EXPANDER, /* role */ acf_generic_root_color, /* backdrop color */ acf_generic_root_backdrop, /* backdrop */ @@ -879,6 +882,7 @@ static void *acf_group_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings UNU static bAnimChannelType ACF_GROUP = { "Group", /* type name */ + ACHANNEL_ROLE_CHANNEL, /* role */ acf_group_color, /* backdrop color */ acf_group_backdrop, /* backdrop */ @@ -987,6 +991,7 @@ static void *acf_fcurve_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings UN static bAnimChannelType ACF_FCURVE = { "F-Curve", /* type name */ + ACHANNEL_ROLE_CHANNEL, /* role */ acf_generic_channel_color, /* backdrop color */ acf_generic_channel_backdrop, /* backdrop */ @@ -1071,6 +1076,7 @@ static void *acf_fillactd_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings static bAnimChannelType ACF_FILLACTD = { "Ob-Action Filler", /* type name */ + ACHANNEL_ROLE_EXPANDER, /* role */ acf_generic_dataexpand_color, /* backdrop color */ acf_generic_dataexpand_backdrop, /* backdrop */ @@ -1150,6 +1156,7 @@ static void *acf_filldrivers_setting_ptr(bAnimListElem *ale, eAnimChannel_Settin static bAnimChannelType ACF_FILLDRIVERS = { "Drivers Filler", /* type name */ + ACHANNEL_ROLE_EXPANDER, /* role */ acf_generic_dataexpand_color, /* backdrop color */ acf_generic_dataexpand_backdrop, /* backdrop */ @@ -1227,6 +1234,7 @@ static void *acf_dsmat_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings set static bAnimChannelType ACF_DSMAT = { "Material Data Expander", /* type name */ + ACHANNEL_ROLE_EXPANDER, /* role */ acf_generic_dataexpand_color, /* backdrop color */ acf_generic_dataexpand_backdrop, /* backdrop */ @@ -1303,6 +1311,7 @@ static void *acf_dslam_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings set static bAnimChannelType ACF_DSLAM = { "Lamp Expander", /* type name */ + ACHANNEL_ROLE_EXPANDER, /* role */ acf_generic_dataexpand_color, /* backdrop color */ acf_generic_dataexpand_backdrop, /* backdrop */ @@ -1386,6 +1395,7 @@ static void *acf_dstex_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings set static bAnimChannelType ACF_DSTEX = { "Texture Data Expander", /* type name */ + ACHANNEL_ROLE_EXPANDER, /* role */ acf_generic_dataexpand_color, /* backdrop color */ acf_generic_dataexpand_backdrop, /* backdrop */ @@ -1462,6 +1472,7 @@ static void *acf_dscam_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings set static bAnimChannelType ACF_DSCAM = { "Camera Expander", /* type name */ + ACHANNEL_ROLE_EXPANDER, /* role */ acf_generic_dataexpand_color, /* backdrop color */ acf_generic_dataexpand_backdrop, /* backdrop */ @@ -1548,6 +1559,7 @@ static void *acf_dscur_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings set static bAnimChannelType ACF_DSCUR = { "Curve Expander", /* type name */ + ACHANNEL_ROLE_EXPANDER, /* role */ acf_generic_dataexpand_color, /* backdrop color */ acf_generic_dataexpand_backdrop, /* backdrop */ @@ -1624,6 +1636,7 @@ static void *acf_dsskey_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings se static bAnimChannelType ACF_DSSKEY = { "Shape Key Expander", /* type name */ + ACHANNEL_ROLE_EXPANDER, /* role */ acf_generic_dataexpand_color, /* backdrop color */ acf_generic_dataexpand_backdrop, /* backdrop */ @@ -1700,6 +1713,7 @@ static void *acf_dswor_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings set static bAnimChannelType ACF_DSWOR = { "World Expander", /* type name */ + ACHANNEL_ROLE_EXPANDER, /* role */ acf_generic_dataexpand_color, /* backdrop color */ acf_generic_dataexpand_backdrop, /* backdrop */ @@ -1776,6 +1790,7 @@ static void *acf_dspart_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings se static bAnimChannelType ACF_DSPART = { "Particle Data Expander", /* type name */ + ACHANNEL_ROLE_EXPANDER, /* role */ acf_generic_dataexpand_color, /* backdrop color */ acf_generic_dataexpand_backdrop, /* backdrop */ @@ -1852,6 +1867,7 @@ static void *acf_dsmball_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings s static bAnimChannelType ACF_DSMBALL = { "Metaball Expander", /* type name */ + ACHANNEL_ROLE_EXPANDER, /* role */ acf_generic_dataexpand_color, /* backdrop color */ acf_generic_dataexpand_backdrop, /* backdrop */ @@ -1928,6 +1944,7 @@ static void *acf_dsarm_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings set static bAnimChannelType ACF_DSARM = { "Armature Expander", /* type name */ + ACHANNEL_ROLE_EXPANDER, /* role */ acf_generic_dataexpand_color, /* backdrop color */ acf_generic_dataexpand_backdrop, /* backdrop */ @@ -2015,6 +2032,7 @@ static void *acf_dsntree_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings s static bAnimChannelType ACF_DSNTREE = { "Node Tree Expander", /* type name */ + ACHANNEL_ROLE_EXPANDER, /* role */ acf_generic_dataexpand_color, /* backdrop color */ acf_generic_dataexpand_backdrop, /* backdrop */ @@ -2091,6 +2109,7 @@ static void *acf_dslinestyle_setting_ptr(bAnimListElem *ale, eAnimChannel_Settin static bAnimChannelType ACF_DSLINESTYLE = { "Line Style Expander", /* type name */ + ACHANNEL_ROLE_EXPANDER, /* role */ acf_generic_dataexpand_color, /* backdrop color */ acf_generic_dataexpand_backdrop,/* backdrop */ @@ -2167,6 +2186,7 @@ static void *acf_dsmesh_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings se static bAnimChannelType ACF_DSMESH = { "Mesh Expander", /* type name */ + ACHANNEL_ROLE_EXPANDER, /* role */ acf_generic_dataexpand_color, /* backdrop color */ acf_generic_dataexpand_backdrop, /* backdrop */ @@ -2243,6 +2263,7 @@ static void *acf_dslat_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings set static bAnimChannelType ACF_DSLAT = { "Lattice Expander", /* type name */ + ACHANNEL_ROLE_EXPANDER, /* role */ acf_generic_dataexpand_color, /* backdrop color */ acf_generic_dataexpand_backdrop, /* backdrop */ @@ -2319,6 +2340,7 @@ static void *acf_dsspk_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings set static bAnimChannelType ACF_DSSPK = { "Speaker Expander", /* type name */ + ACHANNEL_ROLE_EXPANDER, /* role */ acf_generic_dataexpand_color, /* backdrop color */ acf_generic_dataexpand_backdrop, /* backdrop */ @@ -2426,6 +2448,7 @@ static void *acf_shapekey_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings static bAnimChannelType ACF_SHAPEKEY = { "Shape Key", /* type name */ + ACHANNEL_ROLE_CHANNEL, /* role */ acf_generic_channel_color, /* backdrop color */ acf_generic_channel_backdrop, /* backdrop */ @@ -2502,6 +2525,7 @@ static void *acf_gpd_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings UNUSE static bAnimChannelType ACF_GPD = { "GPencil Datablock", /* type name */ + ACHANNEL_ROLE_EXPANDER, /* role */ acf_gpd_color, /* backdrop color */ acf_group_backdrop, /* backdrop */ @@ -2591,6 +2615,7 @@ static void *acf_gpl_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings UNUSE static bAnimChannelType ACF_GPL = { "GPencil Layer", /* type name */ + ACHANNEL_ROLE_CHANNEL, /* role */ acf_generic_channel_color, /* backdrop color */ acf_generic_channel_backdrop, /* backdrop */ @@ -2668,6 +2693,7 @@ static void *acf_mask_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings UNUS static bAnimChannelType ACF_MASKDATA = { "Mask Datablock", /* type name */ + ACHANNEL_ROLE_EXPANDER, /* role */ acf_mask_color, /* backdrop color */ acf_group_backdrop, /* backdrop */ @@ -2754,6 +2780,7 @@ static void *acf_masklay_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings U static bAnimChannelType ACF_MASKLAYER = { "Mask Layer", /* type name */ + ACHANNEL_ROLE_CHANNEL, /* role */ acf_generic_channel_color, /* backdrop color */ acf_generic_channel_backdrop, /* backdrop */ @@ -2892,6 +2919,7 @@ static void *acf_nlatrack_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings static bAnimChannelType ACF_NLATRACK = { "NLA Track", /* type name */ + ACHANNEL_ROLE_CHANNEL, /* role */ acf_nlatrack_color, /* backdrop color */ acf_generic_channel_backdrop, /* backdrop */ @@ -3060,6 +3088,7 @@ static void *acf_nlaaction_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings static bAnimChannelType ACF_NLAACTION = { "NLA Active Action", /* type name */ + ACHANNEL_ROLE_CHANNEL, /* role */ acf_nlaaction_color, /* backdrop color (NOTE: the backdrop handles this too, since it needs special hacks) */ acf_nlaaction_backdrop, /* backdrop */ diff --git a/source/blender/editors/include/ED_anim_api.h b/source/blender/editors/include/ED_anim_api.h index c6b8d879180..10f3f1bef4c 100644 --- a/source/blender/editors/include/ED_anim_api.h +++ b/source/blender/editors/include/ED_anim_api.h @@ -163,7 +163,7 @@ typedef enum eAnim_ChannelType { ANIMTYPE_GPDATABLOCK, ANIMTYPE_GPLAYER, - + ANIMTYPE_MASKDATABLOCK, ANIMTYPE_MASKLAYER, @@ -362,6 +362,13 @@ bool ANIM_animdata_context_getdata(bAnimContext *ac); /* ------------------------ Drawing TypeInfo -------------------------- */ +/* role or level of animchannel in the hierarchy */ +typedef enum eAnimChannel_Role { + ACHANNEL_ROLE_EXPANDER = -1, /* datablock expander - a "composite" channel type */ + ACHANNEL_ROLE_SPECIAL = 0, /* special purposes - not generally for hierarchy processing */ + ACHANNEL_ROLE_CHANNEL = 1 /* data channel - a channel representing one of the actual building blocks of channels */ +} eAnimChannel_Role; + /* flag-setting behavior */ typedef enum eAnimChannels_SetFlag { ACHANNEL_SETFLAG_CLEAR = 0, /* turn off */ @@ -384,11 +391,13 @@ typedef enum eAnimChannel_Settings { /* Drawing, mouse handling, and flag setting behavior... */ typedef struct bAnimChannelType { - /* type data */ + /* -- Type data -- */ /* name of the channel type, for debugging */ const char *channel_type_name; + /* "level" or role in hierarchy - for finding the active channel */ + eAnimChannel_Role channel_role; - /* drawing */ + /* -- Drawing -- */ /* get RGB color that is used to draw the majority of the backdrop */ void (*get_backdrop_color)(bAnimContext *ac, bAnimListElem *ale, float r_color[3]); /* draw backdrop strip for channel */ @@ -405,7 +414,7 @@ typedef struct bAnimChannelType { /* get icon (for channel lists) */ int (*icon)(bAnimListElem *ale); - /* settings */ + /* -- Settings -- */ /* check if the given setting is valid in the current context */ bool (*has_setting)(bAnimContext *ac, bAnimListElem *ale, eAnimChannel_Settings setting); /* get the flag used for this setting */ diff --git a/source/blender/editors/space_action/action_edit.c b/source/blender/editors/space_action/action_edit.c index f38c94a2d59..92e727fc2d7 100644 --- a/source/blender/editors/space_action/action_edit.c +++ b/source/blender/editors/space_action/action_edit.c @@ -395,64 +395,12 @@ static bool actkeys_channels_get_selected_extents(bAnimContext *ac, float *min, *max = (float)(y + ACHANNEL_HEIGHT_HALF); /* is this high enough priority yet? */ - // TODO: refactor this check out into a utility function, and share this with other places which do stuff like this - switch (ale->type) { - /* datablock expanders - ignore unless nothing else comes along */ - case ANIMTYPE_SUMMARY: - found = -1; - break; - - case ANIMTYPE_SCENE: - case ANIMTYPE_OBJECT: - found = -1; - break; - - case ANIMTYPE_FILLACTD: - case ANIMTYPE_FILLDRIVERS: - case ANIMTYPE_DSMAT: - case ANIMTYPE_DSLAM: - case ANIMTYPE_DSCAM: - case ANIMTYPE_DSCUR: - case ANIMTYPE_DSSKEY: - case ANIMTYPE_DSWOR: - case ANIMTYPE_DSNTREE: - case ANIMTYPE_DSPART: - case ANIMTYPE_DSMBALL: - case ANIMTYPE_DSARM: - case ANIMTYPE_DSMESH: - case ANIMTYPE_DSTEX: - case ANIMTYPE_DSLAT: - case ANIMTYPE_DSLINESTYLE: - case ANIMTYPE_DSSPK: - found = -1; - break; - - case ANIMTYPE_GPDATABLOCK: - case ANIMTYPE_MASKDATABLOCK: - found = -1; - break; - - - /* actual channels */ - case ANIMTYPE_GROUP: - case ANIMTYPE_FCURVE: - case ANIMTYPE_SHAPEKEY: - found = 1; - break; - - case ANIMTYPE_GPLAYER: - case ANIMTYPE_MASKLAYER: - found = 1; - break; - - default: /* irrelevant */ - break; - } + found = acf->channel_role; /* only stop our search when we've found an actual channel * - datablock expanders get less priority so that we don't abort prematurely */ - if (found > 0) { + if (found == ACHANNEL_ROLE_CHANNEL) { break; } } |