Commit: fa6080bf332b50ec75b8cef6584fa7566fbe356b
Author: Antony Riakiotakis
Date:   Wed Aug 27 17:47:37 2014 +0200
Branches: master
https://developer.blender.org/rBfa6080bf332b50ec75b8cef6584fa7566fbe356b

Support better precision mode for angle properties in radial operator
(holding down shift key) by using the new dial functionality.

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

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 2730442..2482155 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -56,6 +56,7 @@
 #include "PIL_time.h"
 
 #include "BLI_blenlib.h"
+#include "BLI_dial.h"
 #include "BLI_dynstr.h" /*for WM_operator_pystring */
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
@@ -3694,6 +3695,7 @@ typedef struct {
        int initial_mouse[2];
        int slow_mouse[2];
        bool slow_mode;
+       Dial *dial;
        unsigned int gltex;
        ListBase orig_paintcursors;
        bool use_secondary_tex;
@@ -4127,6 +4129,11 @@ static void radial_control_cancel(bContext *C, 
wmOperator *op)
        RadialControl *rc = op->customdata;
        wmWindowManager *wm = CTX_wm_manager(C);
 
+       if (rc->dial) {
+               MEM_freeN(rc->dial);
+               rc->dial = NULL;
+       }
+       
        WM_paint_cursor_end(wm, rc->cursor);
 
        /* restore original paint cursors */
@@ -4148,6 +4155,7 @@ static int radial_control_modal(bContext *C, wmOperator 
*op, const wmEvent *even
        float new_value, dist, zoom[2];
        float delta[2], ret = OPERATOR_RUNNING_MODAL;
        bool snap;
+       float angle_precision = 0.0f;
        /* TODO: fix hardcoded events */
 
        snap = event->ctrl != 0;
@@ -4155,27 +4163,39 @@ static int radial_control_modal(bContext *C, wmOperator 
*op, const wmEvent *even
        switch (event->type) {
                case MOUSEMOVE:
                        if (rc->slow_mode) {
-                               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];
+                               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);
                                }
-       
-                               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];
+                               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]);
                                }
-       
-                               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;
@@ -4202,7 +4222,10 @@ static int radial_control_modal(bContext *C, wmOperator 
*op, const wmEvent *even
                                        if (snap) new_value = 
((int)ceil(new_value * 10.f) * 10.0f) / 100.f;
                                        break;
                                case PROP_ANGLE:
-                                       new_value = atan2(delta[1], delta[0]) + 
M_PI;
+                                       new_value = atan2(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:
@@ -4236,9 +4259,20 @@ static int radial_control_modal(bContext *C, wmOperator 
*op, const wmEvent *even
                                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;
        }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to