[Bf-blender-cvs] [e103c97] master: Numerical input for changing brush size, strenght or angle.

Antony Riakiotakis noreply at git.blender.org
Mon Nov 17 16:02:51 CET 2014


Commit: e103c9773f14d211bfe3d5e0e27dac7f556c23b3
Author: Antony Riakiotakis
Date:   Mon Nov 17 15:44:19 2014 +0100
Branches: master
https://developer.blender.org/rBe103c9773f14d211bfe3d5e0e27dac7f556c23b3

Numerical input for changing brush size, strenght or angle.

Patch by Martin Vykoukal, thanks!

This patch adds ability to change brush parameters with keyboard, which
is missing functionality from 2.4x.
Original report: T28811

Reviewers: psy-fi

Differential Revision: https://developer.blender.org/D837

===================================================================

M	source/blender/windowmanager/intern/wm_operators.c

===================================================================

diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index fe943e1..dd19a41 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -78,6 +78,7 @@
 #include "BKE_report.h"
 #include "BKE_scene.h"
 #include "BKE_screen.h" /* BKE_ST_MAXNAME */
+#include "BKE_unit.h"
 #include "BKE_utildefines.h"
 
 #include "BKE_idcode.h"
@@ -90,6 +91,7 @@
 #include "IMB_imbuf_types.h"
 #include "IMB_imbuf.h"
 
+#include "ED_numinput.h"
 #include "ED_screen.h"
 #include "ED_util.h"
 #include "ED_view3d.h"
@@ -3731,6 +3733,7 @@ void WM_OT_straightline_gesture(wmOperatorType *ot)
 #define WM_RADIAL_CONTROL_DISPLAY_SIZE 200
 #define WM_RADIAL_CONTROL_DISPLAY_MIN_SIZE 35
 #define WM_RADIAL_CONTROL_DISPLAY_WIDTH (WM_RADIAL_CONTROL_DISPLAY_SIZE - WM_RADIAL_CONTROL_DISPLAY_MIN_SIZE)
+#define WM_RADIAL_CONTROL_HEADER_LENGTH 180
 #define WM_RADIAL_MAX_STR 6
 
 typedef struct {
@@ -3748,8 +3751,24 @@ typedef struct {
 	ListBase orig_paintcursors;
 	bool use_secondary_tex;
 	void *cursor;
+    NumInput num_input;
 } RadialControl;
 
+static void radial_control_update_header(wmOperator *op, bContext *C)
+{
+    RadialControl *rc = op->customdata;
+    char msg[WM_RADIAL_CONTROL_HEADER_LENGTH];
+    ScrArea *sa = CTX_wm_area(C);
+    Scene *scene = CTX_data_scene(C);
+
+    if (sa && hasNumInput(&rc->num_input)) {
+        char num_str[NUM_STR_REP_LEN];
+        outputNumInput(&rc->num_input, num_str, &scene->unit);
+        BLI_snprintf(msg, WM_RADIAL_CONTROL_HEADER_LENGTH, "%s: %s", RNA_property_ui_name(rc->prop), num_str);
+        ED_area_headerprint(sa, msg);
+    }
+}
+
 static void radial_control_set_initial_mouse(RadialControl *rc, const wmEvent *event)
 {
 	float d[2] = {0, 0};
@@ -4134,6 +4153,13 @@ static int radial_control_invoke(bContext *C, wmOperator *op, const wmEvent *eve
 			return OPERATOR_CANCELLED;
 	}
 
+    /* initialize numerical input */
+    initNumInput(&rc->num_input);
+    rc->num_input.idx_max = 0;
+    rc->num_input.val_flag[0] |= NUM_NO_NEGATIVE;
+    rc->num_input.unit_sys = USER_UNIT_NONE;
+    rc->num_input.unit_type[0] = B_UNIT_LENGTH;
+
 	/* get subtype of property */
 	rc->subtype = RNA_property_subtype(rc->prop);
 	if (!ELEM(rc->subtype, PROP_NONE, PROP_DISTANCE, PROP_FACTOR, PROP_PERCENTAGE, PROP_ANGLE, PROP_PIXEL)) {
@@ -4141,7 +4167,7 @@ static int radial_control_invoke(bContext *C, wmOperator *op, const wmEvent *eve
 		MEM_freeN(rc);
 		return OPERATOR_CANCELLED;
 	}
-		
+
 	rc->current_value = rc->initial_value;
 	radial_control_set_initial_mouse(rc, event);
 	radial_control_set_tex(rc);
@@ -4178,11 +4204,16 @@ static void radial_control_cancel(bContext *C, wmOperator *op)
 {
 	RadialControl *rc = op->customdata;
 	wmWindowManager *wm = CTX_wm_manager(C);
+    ScrArea *sa = CTX_wm_area(C);
 
 	if (rc->dial) {
 		MEM_freeN(rc->dial);
 		rc->dial = NULL;
 	}
+
+    if (sa) {
+        ED_area_headerprint(sa, NULL);
+    }
 	
 	WM_paint_cursor_end(wm, rc->cursor);
 
@@ -4206,134 +4237,170 @@ static int radial_control_modal(bContext *C, wmOperator *op, const wmEvent *even
 	float delta[2], ret = OPERATOR_RUNNING_MODAL;
 	bool snap;
 	float angle_precision = 0.0f;
+    const bool has_numInput = hasNumInput(&rc->num_input);
+    bool handled = false;
+    float numValue;
 	/* TODO: fix hardcoded events */
 
 	snap = event->ctrl != 0;
 
-	switch (event->type) {
-		case MOUSEMOVE:
-			if (rc->slow_mode) {
-				if (rc->subtype == PROP_ANGLE) {
-					float position[2] = {event->x, event->y};
-					
-					/* calculate the initial angle here first */
-					delta[0] = rc->initial_mouse[0] - rc->slow_mouse[0];
-					delta[1] = rc->initial_mouse[1] - rc->slow_mouse[1];
-					
-					/* precision angle gets calculated from dial and gets added later */
-					angle_precision = -0.1f * BLI_dial_angle(rc->dial, position);
-				}
-				else {
-					delta[0] = rc->initial_mouse[0] - rc->slow_mouse[0];
-					delta[1] = rc->initial_mouse[1] - rc->slow_mouse[1];
-					
-					if (rc->zoom_prop) {
-						RNA_property_float_get_array(&rc->zoom_ptr, rc->zoom_prop, zoom);
-						delta[0] /= zoom[0];
-						delta[1] /= zoom[1];
-					}
-					
-					dist = len_v2(delta);
-					
-					delta[0] = event->x - rc->slow_mouse[0];
-					delta[1] = event->y - rc->slow_mouse[1];
-					
-					if (rc->zoom_prop) {
-						delta[0] /= zoom[0];
-						delta[1] /= zoom[1];
-					}
-					
-					dist = dist + 0.1f * (delta[0] + delta[1]);
-				}
-			}
-			else {
-				delta[0] = rc->initial_mouse[0] - event->x;
-				delta[1] = rc->initial_mouse[1] - event->y;
-
-				if (rc->zoom_prop) {
-					RNA_property_float_get_array(&rc->zoom_ptr, rc->zoom_prop, zoom);
-					delta[0] /= zoom[0];
-					delta[1] /= zoom[1];
-				}
-	
-				dist = len_v2(delta);				
-			}
-
-			/* calculate new value and apply snapping  */
-			switch (rc->subtype) {
-				case PROP_NONE:
-				case PROP_DISTANCE:
-				case PROP_PERCENTAGE:
-				case PROP_PIXEL:
-					new_value = dist;
-					if (snap) new_value = ((int)new_value + 5) / 10 * 10;
-					break;
-				case PROP_FACTOR:
-					new_value = (WM_RADIAL_CONTROL_DISPLAY_SIZE - dist) / WM_RADIAL_CONTROL_DISPLAY_WIDTH;
-					if (snap) new_value = ((int)ceil(new_value * 10.f) * 10.0f) / 100.f;
-					break;
-				case PROP_ANGLE:
-					new_value = atan2f(delta[1], delta[0]) + M_PI + angle_precision;
-					new_value = fmod(new_value, 2.0f * (float)M_PI);
-					if (new_value < 0.0f)
-						new_value += 2.0f * (float)M_PI;
-					if (snap) new_value = DEG2RADF(((int)RAD2DEGF(new_value) + 5) / 10 * 10);
-					break;
-				default:
-					new_value = dist; /* dummy value, should this ever happen? - campbell */
-					break;
-			}
-
-			/* clamp and update */
-			CLAMP(new_value, rc->min_value, rc->max_value);
-			radial_control_set_value(rc, new_value);
-			rc->current_value = new_value;
-			break;
-
-		case ESCKEY:
-		case RIGHTMOUSE:
-			/* canceled; restore original value */
-			radial_control_set_value(rc, rc->initial_value);
-			ret = OPERATOR_CANCELLED;
-			break;
-
-		case LEFTMOUSE:
-		case PADENTER:
-			/* done; value already set */
-			RNA_property_update(C, &rc->ptr, rc->prop);
-			ret = OPERATOR_FINISHED;
-			break;
-			
-		case LEFTSHIFTKEY:
-		case RIGHTSHIFTKEY:
-			if (event->val == KM_PRESS) {
-				rc->slow_mouse[0] = event->x;
-				rc->slow_mouse[1] = event->y;
-				rc->slow_mode = true;
-				if (rc->subtype == PROP_ANGLE) {
-					float initial_position[2] = {UNPACK2(rc->initial_mouse)};
-					float current_position[2] = {UNPACK2(rc->slow_mouse)};
-					rc->dial = BLI_dial_initialize(initial_position, 0.0f);
-					/* immediately set the position to get a an initial direction */
-					BLI_dial_angle(rc->dial, current_position);
-				}
-			}
-			if (event->val == KM_RELEASE) {
-				rc->slow_mode = false;
-				if (rc->dial) {
-					MEM_freeN(rc->dial);
-					rc->dial = NULL;
-				}
-			}
-			break;
-	}
-
-	ED_region_tag_redraw(CTX_wm_region(C));
-
-	if (ret != OPERATOR_RUNNING_MODAL)
-		radial_control_cancel(C, op);
-
-	return ret;
+    /* Modal numinput active, try to handle numeric inputs first... */
+    if (event->val == KM_PRESS && has_numInput && handleNumInput(C, &rc->num_input, event)) {
+        handled = true;
+        applyNumInput(&rc->num_input, &numValue);
+        CLAMP(numValue, rc->min_value, rc->max_value);
+        new_value = numValue;
+
+        radial_control_set_value(rc, new_value);
+        rc->current_value = new_value;
+        radial_control_update_header(op, C);
+        return OPERATOR_RUNNING_MODAL;
+    }
+    else {
+        handled = false;
+        switch (event->type) {
+        case ESCKEY:
+        case RIGHTMOUSE:
+            /* canceled; restore original value */
+            radial_control_set_value(rc, rc->initial_value);
+            ret = OPERATOR_CANCELLED;
+            break;
+
+        case LEFTMOUSE:
+        case PADENTER:
+        case RETKEY:
+            /* done; value already set */
+            RNA_property_update(C, &rc->ptr, rc->prop);
+            ret = OPERATOR_FINISHED;
+            break;
+
+        case MOUSEMOVE:
+            if (!has_numInput) {
+                if (rc->slow_mode) {
+                    if (rc->subtype == PROP_ANGLE) {
+                        float position[2] = {event->x, event->y};
+
+                        /* calculate the initial angle here first */
+                        delta[0] = rc->initial_mouse[0] - rc->slow_mouse[0];
+                        delta[1] = rc->initial_mouse[1] - rc->slow_mouse[1];
+
+                        /* precision angle gets calculated from dial and gets added later */
+                        angle_precision = -0.1f * BLI_dial_angle(rc->dial, position);
+                    }
+                    else {
+                        delta[0] = rc->initial_mouse[0] - rc->slow_mouse[0];
+                        delta[1] = rc->initial_mouse[1] - rc->slow_mouse[1];
+
+                        if (rc->zoom_prop) {
+                            RNA_property_float_get_array(&rc->zoom_ptr, rc->zoom_prop, zoom);
+                            delta[0] /= zoom[0];
+                            delta[1] /= zoom[1];
+                        }
+
+                        dist = len_v2(delta);
+
+                        delta[0] = event->x - rc->slow_mouse[0];
+                        delta[1] = event->y - rc->slow_mouse[1];
+
+                        if (rc->zoom_prop) {
+                            delta[0] /= zoom[0];
+                            delta[1] /= zoom[1];
+                        }
+
+                        dist = dist + 0.1f * (delta[0] + delta[1]);
+                    }
+                }
+                else {
+                    delta[0] = rc->initial_mouse[0] - event->x;
+                    delta[1] = rc->initial_mouse[1] - event->y;
+
+                    if (rc->zoom_prop) {
+                        RNA_property_float_get_array(&rc->zoom_ptr, rc->zoom_prop, zoom);
+                        delta[0] /= zoom[0];
+                        delta[1] /= zoom[1];
+                    }
+
+                    dist = len_v2(delta);
+                }
+
+                /* calculate new value and apply snapping  */
+               

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list