Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2015-12-27 09:46:55 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-12-27 10:01:11 +0300
commitf820c45534c653c7a2baa799b99067710def136b (patch)
tree7f08c2e1fa8e5aa2dbdbe38c64a1684495df124f /source/blender/windowmanager/intern/wm_operator_props.c
parentb254905c384d87764cd92ed631f86f3f97caa4de (diff)
WM: add checker_interval utility functions
Diffstat (limited to 'source/blender/windowmanager/intern/wm_operator_props.c')
-rw-r--r--source/blender/windowmanager/intern/wm_operator_props.c32
1 files changed, 32 insertions, 0 deletions
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));
+}