diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-12-27 09:46:55 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-12-27 10:01:11 +0300 |
commit | f820c45534c653c7a2baa799b99067710def136b (patch) | |
tree | 7f08c2e1fa8e5aa2dbdbe38c64a1684495df124f /source/blender/windowmanager | |
parent | b254905c384d87764cd92ed631f86f3f97caa4de (diff) |
WM: add checker_interval utility functions
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r-- | source/blender/windowmanager/WM_api.h | 10 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_operator_props.c | 32 |
2 files changed, 42 insertions, 0 deletions
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 9d1f4457013..3f89140888b 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -302,6 +302,16 @@ void WM_operator_properties_select_all(struct wmOperatorType *ot); void WM_operator_properties_select_action(struct wmOperatorType *ot, int default_action); void WM_operator_properties_select_action_simple(struct wmOperatorType *ot, int default_action); void WM_operator_properties_select_random(struct wmOperatorType *ot); +struct CheckerIntervalParams { + int nth; /* bypass when set to zero */ + int skip; + int offset; +}; +void WM_operator_properties_checker_interval(struct wmOperatorType *ot, bool nth_can_disable); +void WM_operator_properties_checker_interval_from_op( + struct wmOperator *op, struct CheckerIntervalParams *op_params); +bool WM_operator_properties_checker_interval_test( + const struct CheckerIntervalParams *op_params, int depth); /* MOVE THIS SOMEWHERE ELSE */ diff --git a/source/blender/windowmanager/intern/wm_operator_props.c b/source/blender/windowmanager/intern/wm_operator_props.c index a59fbf9d528..c74bb46356d 100644 --- a/source/blender/windowmanager/intern/wm_operator_props.c +++ b/source/blender/windowmanager/intern/wm_operator_props.c @@ -31,6 +31,7 @@ #include "DNA_space_types.h" #include "BLI_rect.h" +#include "BLI_math_base.h" #include "UI_resources.h" @@ -248,3 +249,34 @@ void WM_operator_properties_gesture_straightline(wmOperatorType *ot, int cursor) RNA_def_property_flag(prop, PROP_HIDDEN); } } + +/** + * \param nth_can_disable: Enable if we want to be able to select no interval at all. + */ +void WM_operator_properties_checker_interval(wmOperatorType *ot, bool nth_can_disable) +{ + const int nth_default = nth_can_disable ? 1 : 2; + const int nth_min = min_ii(nth_default, 2); + RNA_def_int(ot->srna, "nth", nth_default, nth_min, INT_MAX, "Nth Selection", "", nth_min, 100); + RNA_def_int(ot->srna, "skip", 1, 1, INT_MAX, "Skip", "", 1, 100); + RNA_def_int(ot->srna, "offset", 0, INT_MIN, INT_MAX, "Offset", "", -100, 100); +} + +void WM_operator_properties_checker_interval_from_op( + struct wmOperator *op, struct CheckerIntervalParams *op_params) +{ + const int nth = RNA_int_get(op->ptr, "nth") - 1; + const int skip = RNA_int_get(op->ptr, "skip"); + int offset = RNA_int_get(op->ptr, "offset"); + + op_params->nth = nth; + op_params->skip = skip; + op_params->offset = mod_i(offset, nth + skip); /* so input of offset zero ends up being (nth - 1) */ +} + +bool WM_operator_properties_checker_interval_test( + const struct CheckerIntervalParams *op_params, int depth) +{ + return ((op_params->nth == 0) || + ((op_params->offset + depth) % (op_params->skip + op_params->nth) >= op_params->skip)); +} |