diff options
author | wm4 <wm4@nowhere> | 2012-09-18 14:00:08 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2012-10-12 10:10:31 +0200 |
commit | cac7702565b560d5a16bc82bf553d1a4c08297e1 (patch) | |
tree | 5d1246e28da246dc26fa54de267c35545ac0f09f /m_property.c | |
parent | 3d67041089c7945dcea0162c0038e495d588b379 (diff) | |
download | mpv-cac7702565b560d5a16bc82bf553d1a4c08297e1.tar.bz2 mpv-cac7702565b560d5a16bc82bf553d1a4c08297e1.tar.xz |
commands: handle property stepping in a generic way
Instead of forcing each property implementation implement its own logic
for M_PROPERTY_STEP_UP/M_PROPERTY_STEP_DOWN, handle it in the generic
property code.
Rename the M_PROPERTY_STEP_UP command to M_PROPERTY_SWITCH (the other
property command, M_PROPERTY_STEP_DOWN, isn't needed anymore: stepping
downwards is done by passing a negative argument). Always use double as
argument type; it makes the code easier, and covers all property types.
Move the code which does the actual type-specific value stepping to
m_option.c (the idea is that m_option handles types).
Some properties still have custom handlers implemented with
M_PROPERTY_SWITCH. They can't be mapped to the generic mechanism,
because their value range is dynamic or entirely unknown.
For some properties, the default step stride is changed to 1. This is no
issue, because the default bindings in input.conf all use an explicit
stride in the affected cases.
Diffstat (limited to 'm_property.c')
-rw-r--r-- | m_property.c | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/m_property.c b/m_property.c index fac3ec8285..c35cc51f9d 100644 --- a/m_property.c +++ b/m_property.c @@ -116,6 +116,28 @@ int m_property_do(const m_option_t *prop_list, const char *name, m_option_free(opt, val); free(val); return r; + case M_PROPERTY_SWITCH: + if ((r = do_action(prop_list, name, M_PROPERTY_SWITCH, arg, ctx)) != + M_PROPERTY_NOT_IMPLEMENTED) + return r; + if ((r = + do_action(prop_list, name, M_PROPERTY_GET_TYPE, &opt, ctx)) <= 0) + return r; + // Fallback to m_option + if (!opt->type->add) + return M_PROPERTY_NOT_IMPLEMENTED; + val = calloc(1, opt->type->size); + if ((r = do_action(prop_list, name, M_PROPERTY_GET, val, ctx)) <= 0) { + free(val); + return r; + } + bool wrap = opt->type == &m_option_type_choice || + opt->type == &m_option_type_flag; + opt->type->add(opt, val, *(double*)arg, wrap); + r = do_action(prop_list, name, M_PROPERTY_SET, val, ctx); + m_option_free(opt, val); + free(val); + return r; } return do_action(prop_list, name, action, arg, ctx); } @@ -264,12 +286,6 @@ int m_property_int_range(const m_option_t *prop, int action, M_PROPERTY_CLAMP(prop, *(int *)arg); *var = *(int *)arg; return 1; - case M_PROPERTY_STEP_UP: - case M_PROPERTY_STEP_DOWN: - *var += (arg ? *(int *)arg : 1) * - (action == M_PROPERTY_STEP_DOWN ? -1 : 1); - M_PROPERTY_CLAMP(prop, *var); - return 1; } return m_property_int_ro(prop, action, arg, *var); } @@ -292,10 +308,6 @@ int m_property_flag(const m_option_t *prop, int action, void *arg, int *var) { switch (action) { - case M_PROPERTY_STEP_UP: - case M_PROPERTY_STEP_DOWN: - *var = *var == prop->min ? prop->max : prop->min; - return 1; case M_PROPERTY_PRINT: return m_property_flag_ro(prop, action, arg, *var); } @@ -330,12 +342,6 @@ int m_property_float_range(const m_option_t *prop, int action, M_PROPERTY_CLAMP(prop, *(float *)arg); *var = *(float *)arg; return 1; - case M_PROPERTY_STEP_UP: - case M_PROPERTY_STEP_DOWN: - *var += (arg ? *(float *)arg : 0.1) * - (action == M_PROPERTY_STEP_DOWN ? -1 : 1); - M_PROPERTY_CLAMP(prop, *var); - return 1; } return m_property_float_ro(prop, action, arg, *var); } |