[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58445] trunk/blender: Select more/ less tool for mask splines

Sv. Lockal lockalsash at gmail.com
Sat Jul 20 12:24:16 CEST 2013


Revision: 58445
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58445
Author:   lockal
Date:     2013-07-20 10:24:16 +0000 (Sat, 20 Jul 2013)
Log Message:
-----------
Select more/less tool for mask splines

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/properties_mask_common.py
    trunk/blender/source/blender/editors/mask/mask_edit.c
    trunk/blender/source/blender/editors/mask/mask_intern.h
    trunk/blender/source/blender/editors/mask/mask_select.c

Modified: trunk/blender/release/scripts/startup/bl_ui/properties_mask_common.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/properties_mask_common.py	2013-07-20 09:29:25 UTC (rev 58444)
+++ trunk/blender/release/scripts/startup/bl_ui/properties_mask_common.py	2013-07-20 10:24:16 UTC (rev 58445)
@@ -339,6 +339,11 @@
 
         layout.separator()
 
+        layout.operator("mask.select_more")
+        layout.operator("mask.select_less")
+
+        layout.separator()
+
         layout.operator("mask.select_all").action = 'TOGGLE'
         layout.operator("mask.select_all", text="Inverse").action = 'INVERT'
 

Modified: trunk/blender/source/blender/editors/mask/mask_edit.c
===================================================================
--- trunk/blender/source/blender/editors/mask/mask_edit.c	2013-07-20 09:29:25 UTC (rev 58444)
+++ trunk/blender/source/blender/editors/mask/mask_edit.c	2013-07-20 10:24:16 UTC (rev 58445)
@@ -390,6 +390,8 @@
 	WM_operatortype_append(MASK_OT_select_circle);
 	WM_operatortype_append(MASK_OT_select_linked_pick);
 	WM_operatortype_append(MASK_OT_select_linked);
+	WM_operatortype_append(MASK_OT_select_more);
+	WM_operatortype_append(MASK_OT_select_less);
 
 	/* hide/reveal */
 	WM_operatortype_append(MASK_OT_hide_view_clear);
@@ -466,6 +468,9 @@
 	kmi = WM_keymap_add_item(keymap, "MASK_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL | KM_SHIFT | KM_ALT, 0);
 	RNA_boolean_set(kmi->ptr, "deselect", TRUE);
 
+	WM_keymap_add_item(keymap, "MASK_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
+	WM_keymap_add_item(keymap, "MASK_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0);
+
 	/* hide/reveal */
 	WM_keymap_add_item(keymap, "MASK_OT_hide_view_clear", HKEY, KM_PRESS, KM_ALT, 0);
 	kmi = WM_keymap_add_item(keymap, "MASK_OT_hide_view_set", HKEY, KM_PRESS, 0, 0);

Modified: trunk/blender/source/blender/editors/mask/mask_intern.h
===================================================================
--- trunk/blender/source/blender/editors/mask/mask_intern.h	2013-07-20 09:29:25 UTC (rev 58444)
+++ trunk/blender/source/blender/editors/mask/mask_intern.h	2013-07-20 10:24:16 UTC (rev 58445)
@@ -88,6 +88,8 @@
 void MASK_OT_select_circle(struct wmOperatorType *ot);
 void MASK_OT_select_linked_pick(struct wmOperatorType *ot);
 void MASK_OT_select_linked(struct wmOperatorType *ot);
+void MASK_OT_select_more(struct wmOperatorType *ot);
+void MASK_OT_select_less(struct wmOperatorType *ot);
 
 int ED_mask_spline_select_check(struct MaskSpline *spline);
 int ED_mask_layer_select_check(struct MaskLayer *masklay);

Modified: trunk/blender/source/blender/editors/mask/mask_select.c
===================================================================
--- trunk/blender/source/blender/editors/mask/mask_select.c	2013-07-20 09:29:25 UTC (rev 58444)
+++ trunk/blender/source/blender/editors/mask/mask_select.c	2013-07-20 10:24:16 UTC (rev 58445)
@@ -793,3 +793,115 @@
 	/* flags */
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
+
+/**************** Select more/less **************/
+
+static int mask_select_more_less(bContext *C, bool more)
+{
+	Mask *mask = CTX_data_edit_mask(C);
+	MaskLayer *masklay;
+
+	for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
+		MaskSpline *spline;
+
+		if (masklay->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) {
+			continue;
+		}
+
+		for (spline = masklay->splines.first; spline; spline = spline->next) {
+			int i;
+			bool start_sel, end_sel, prev_sel, cur_sel, cyclic = spline->flag & MASK_SPLINE_CYCLIC;
+
+			// reselect point if any handle is selected to make the result more predictable
+			for (i = 0; i < spline->tot_point; i++) {
+				BKE_mask_point_select_set(spline->points + i, MASKPOINT_ISSEL_ANY(spline->points + i));
+			}
+
+			// select more/less does not affect empty/single point splines
+			if (spline->tot_point < 2) {
+				continue;
+			}
+
+			if (cyclic) {
+				start_sel = !!MASKPOINT_ISSEL_KNOT(spline->points);
+				end_sel = !!MASKPOINT_ISSEL_KNOT(&spline->points[spline->tot_point - 1]);
+			}
+
+			for (i = 0; i < spline->tot_point; i++) {
+				if (i == 0 && !cyclic) {
+					continue;
+				}
+
+				prev_sel = (i > 0) ? !!MASKPOINT_ISSEL_KNOT(&spline->points[i - 1]) : end_sel;
+				cur_sel = !!MASKPOINT_ISSEL_KNOT(&spline->points[i]);
+
+				if (cur_sel != more) {
+					if (prev_sel == more) {
+						BKE_mask_point_select_set(&spline->points[i], more);
+					}
+					i++;
+				}
+			}
+
+			for (i = spline->tot_point - 1; i >= 0; i--) {
+				if (i == spline->tot_point - 1 && !cyclic) {
+					continue;
+				}
+
+				prev_sel = (i < spline->tot_point - 1) ? !!MASKPOINT_ISSEL_KNOT(&spline->points[i + 1]) : start_sel;
+				cur_sel = !!MASKPOINT_ISSEL_KNOT(&spline->points[i]);
+
+				if (cur_sel != more) {
+					if (prev_sel == more) {
+						BKE_mask_point_select_set(&spline->points[i], more);
+					}
+					i--;
+				}
+			}
+		}
+	}
+
+	WM_event_add_notifier(C, NC_MASK | ND_SELECT, mask);
+
+	return OPERATOR_FINISHED;
+}
+
+static int mask_select_more_exec(bContext *C, wmOperator *UNUSED(op))
+{
+	return mask_select_more_less(C, true);
+}
+
+void MASK_OT_select_more(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Select More";
+	ot->idname = "MASK_OT_select_more";
+	ot->description = "Select more spline points connected to initial selection";
+
+	/* api callbacks */
+	ot->exec = mask_select_more_exec;
+	ot->poll = ED_maskedit_mask_poll;
+
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+static int mask_select_less_exec(bContext *C, wmOperator *UNUSED(op))
+{
+	return mask_select_more_less(C, false);
+}
+
+void MASK_OT_select_less(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Select Less";
+	ot->idname = "MASK_OT_select_less";
+	ot->description = "Deselect spline points at the boundary of each selection region";
+
+	/* api callbacks */
+	ot->exec = mask_select_less_exec;
+	ot->poll = ED_maskedit_mask_poll;
+
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}




More information about the Bf-blender-cvs mailing list