Fix dashed line drawing
[blender.git] / source / blender / windowmanager / intern / wm_gesture.c
index bc985087475986efaad9af2c58708774282fb1d2..b79de4370d032a964c62273fbeaf5d02de7a3d54 100644 (file)
@@ -128,15 +128,17 @@ bool WM_gesture_is_modal_first(const wmGesture *gesture)
 }
 
 /* tweak and line gestures */
-int wm_gesture_evaluate(wmGesture *gesture)
+int wm_gesture_evaluate(wmGesture *gesture, const wmEvent *event)
 {
   if (gesture->type == WM_GESTURE_TWEAK) {
     rcti *rect = gesture->customdata;
-    int dx = BLI_rcti_size_x(rect);
-    int dy = BLI_rcti_size_y(rect);
-    const int drag_threshold = WM_EVENT_CURSOR_CLICK_DRAG_THRESHOLD;
-    if (abs(dx) >= drag_threshold || abs(dy) >= drag_threshold) {
-      int theta = round_fl_to_int(4.0f * atan2f((float)dy, (float)dx) / (float)M_PI);
+    const int delta[2] = {
+        BLI_rcti_size_x(rect),
+        BLI_rcti_size_y(rect),
+    };
+
+    if (WM_event_drag_test_with_delta(event, delta)) {
+      int theta = round_fl_to_int(4.0f * atan2f((float)delta[1], (float)delta[0]) / (float)M_PI);
       int val = EVT_GESTURE_W;
 
       if (theta == 0) {
@@ -163,22 +165,30 @@ int wm_gesture_evaluate(wmGesture *gesture)
 
 #if 0
       /* debug */
-      if (val == 1)
+      if (val == 1) {
         printf("tweak north\n");
-      if (val == 2)
+      }
+      if (val == 2) {
         printf("tweak north-east\n");
-      if (val == 3)
+      }
+      if (val == 3) {
         printf("tweak east\n");
-      if (val == 4)
+      }
+      if (val == 4) {
         printf("tweak south-east\n");
-      if (val == 5)
+      }
+      if (val == 5) {
         printf("tweak south\n");
-      if (val == 6)
+      }
+      if (val == 6) {
         printf("tweak south-west\n");
-      if (val == 7)
+      }
+      if (val == 7) {
         printf("tweak west\n");
-      if (val == 8)
+      }
+      if (val == 8) {
         printf("tweak north-west\n");
+      }
 #endif
       return val;
     }
@@ -205,6 +215,7 @@ static void wm_gesture_draw_line(wmGesture *gt)
   immUniformArray4fv(
       "colors", (float *)(float[][4]){{0.4f, 0.4f, 0.4f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}}, 2);
   immUniform1f("dash_width", 8.0f);
+  immUniform1f("dash_factor", 0.5f);
 
   float xmin = (float)rect->xmin;
   float ymin = (float)rect->ymin;
@@ -247,6 +258,7 @@ static void wm_gesture_draw_rect(wmGesture *gt)
   immUniformArray4fv(
       "colors", (float *)(float[][4]){{0.4f, 0.4f, 0.4f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}}, 2);
   immUniform1f("dash_width", 8.0f);
+  immUniform1f("dash_factor", 0.5f);
 
   imm_draw_box_wire_2d(
       shdr_pos, (float)rect->xmin, (float)rect->ymin, (float)rect->xmax, (float)rect->ymax);
@@ -285,6 +297,7 @@ static void wm_gesture_draw_circle(wmGesture *gt)
   immUniformArray4fv(
       "colors", (float *)(float[][4]){{0.4f, 0.4f, 0.4f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}}, 2);
   immUniform1f("dash_width", 4.0f);
+  immUniform1f("dash_factor", 0.5f);
 
   imm_draw_circle_wire_2d(shdr_pos, (float)rect->xmin, (float)rect->ymin, (float)rect->xmax, 40);
 
@@ -408,6 +421,7 @@ static void wm_gesture_draw_lasso(wmGesture *gt, bool filled)
   immUniformArray4fv(
       "colors", (float *)(float[][4]){{0.4f, 0.4f, 0.4f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}}, 2);
   immUniform1f("dash_width", 2.0f);
+  immUniform1f("dash_factor", 0.5f);
 
   immBegin((gt->type == WM_GESTURE_LASSO) ? GPU_PRIM_LINE_LOOP : GPU_PRIM_LINE_STRIP, numverts);
 
@@ -441,6 +455,7 @@ static void wm_gesture_draw_cross(wmWindow *win, wmGesture *gt)
   immUniformArray4fv(
       "colors", (float *)(float[][4]){{0.4f, 0.4f, 0.4f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}}, 2);
   immUniform1f("dash_width", 8.0f);
+  immUniform1f("dash_factor", 0.5f);
 
   immBegin(GPU_PRIM_LINES, 4);
 
@@ -478,8 +493,11 @@ void wm_gesture_draw(wmWindow *win)
     if (gt->type == WM_GESTURE_RECT) {
       wm_gesture_draw_rect(gt);
     }
-    //      else if (gt->type == WM_GESTURE_TWEAK)
-    //          wm_gesture_draw_line(gt);
+#if 0
+    else if (gt->type == WM_GESTURE_TWEAK) {
+      wm_gesture_draw_line(gt);
+    }
+#endif
     else if (gt->type == WM_GESTURE_CIRCLE) {
       wm_gesture_draw_circle(gt);
     }