[Bf-blender-cvs] [626c844105a] master: Cleanup: rename wmEvent.prev_click_* to prev_press_*

Campbell Barton noreply at git.blender.org
Tue Mar 8 23:25:49 CET 2022


Commit: 626c844105afc3b2455f5a1b87ac8a7839a7e0bf
Author: Campbell Barton
Date:   Wed Mar 9 09:01:28 2022 +1100
Branches: master
https://developer.blender.org/rB626c844105afc3b2455f5a1b87ac8a7839a7e0bf

Cleanup: rename wmEvent.prev_click_* to prev_press_*

At the time of naming these members only some event types generated
click events so it made some sense to differentiate a click.

Now all buttons support click & drag it's more logical to use the
prefix "prev_press_" as any press event will set these values.

Also update doc-strings.

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

M	source/blender/editors/sculpt_paint/sculpt_cloth.c
M	source/blender/editors/sculpt_paint/sculpt_filter_color.c
M	source/blender/editors/sculpt_paint/sculpt_filter_mesh.c
M	source/blender/makesrna/intern/rna_wm.c
M	source/blender/windowmanager/WM_types.h
M	source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c
M	source/blender/windowmanager/intern/wm_event_query.c
M	source/blender/windowmanager/intern/wm_event_system.c

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

diff --git a/source/blender/editors/sculpt_paint/sculpt_cloth.c b/source/blender/editors/sculpt_paint/sculpt_cloth.c
index 80ba7601cb1..a4cfb611138 100644
--- a/source/blender/editors/sculpt_paint/sculpt_cloth.c
+++ b/source/blender/editors/sculpt_paint/sculpt_cloth.c
@@ -1502,7 +1502,7 @@ static int sculpt_cloth_filter_modal(bContext *C, wmOperator *op, const wmEvent
     return OPERATOR_RUNNING_MODAL;
   }
 
-  const float len = event->prev_click_xy[0] - event->xy[0];
+  const float len = event->prev_press_xy[0] - event->xy[0];
   filter_strength = filter_strength * -len * 0.001f * UI_DPI_FAC;
 
   SCULPT_vertex_random_access_ensure(ss);
diff --git a/source/blender/editors/sculpt_paint/sculpt_filter_color.c b/source/blender/editors/sculpt_paint/sculpt_filter_color.c
index 93e2d721962..377f1e0ed32 100644
--- a/source/blender/editors/sculpt_paint/sculpt_filter_color.c
+++ b/source/blender/editors/sculpt_paint/sculpt_filter_color.c
@@ -215,7 +215,7 @@ static int sculpt_color_filter_modal(bContext *C, wmOperator *op, const wmEvent
     return OPERATOR_RUNNING_MODAL;
   }
 
-  const float len = event->prev_click_xy[0] - event->xy[0];
+  const float len = event->prev_press_xy[0] - event->xy[0];
   filter_strength = filter_strength * -len * 0.001f;
 
   float fill_color[3];
diff --git a/source/blender/editors/sculpt_paint/sculpt_filter_mesh.c b/source/blender/editors/sculpt_paint/sculpt_filter_mesh.c
index ac2c83d3a9c..b73e182fcab 100644
--- a/source/blender/editors/sculpt_paint/sculpt_filter_mesh.c
+++ b/source/blender/editors/sculpt_paint/sculpt_filter_mesh.c
@@ -606,7 +606,7 @@ static int sculpt_mesh_filter_modal(bContext *C, wmOperator *op, const wmEvent *
     return OPERATOR_RUNNING_MODAL;
   }
 
-  const float len = event->prev_click_xy[0] - event->xy[0];
+  const float len = event->prev_press_xy[0] - event->xy[0];
   filter_strength = filter_strength * -len * 0.001f * UI_DPI_FAC;
 
   SCULPT_vertex_random_access_ensure(ss);
diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c
index bc879d8254a..a850f8862bc 100644
--- a/source/blender/makesrna/intern/rna_wm.c
+++ b/source/blender/makesrna/intern/rna_wm.c
@@ -2103,14 +2103,14 @@ static void rna_def_event(BlenderRNA *brna)
       prop, "Mouse Previous Y Position", "The window relative vertical location of the mouse");
 
   prop = RNA_def_property(srna, "mouse_prev_press_x", PROP_INT, PROP_NONE);
-  RNA_def_property_int_sdna(prop, NULL, "prev_click_xy[0]");
+  RNA_def_property_int_sdna(prop, NULL, "prev_press_xy[0]");
   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
   RNA_def_property_ui_text(prop,
                            "Mouse Previous X Press Position",
                            "The window relative horizontal location of the last press event");
 
   prop = RNA_def_property(srna, "mouse_prev_press_y", PROP_INT, PROP_NONE);
-  RNA_def_property_int_sdna(prop, NULL, "prev_click_xy[1]");
+  RNA_def_property_int_sdna(prop, NULL, "prev_press_xy[1]");
   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
   RNA_def_property_ui_text(prop,
                            "Mouse Previous Y Press Position",
diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h
index 3d8577933cf..8934f714c21 100644
--- a/source/blender/windowmanager/WM_types.h
+++ b/source/blender/windowmanager/WM_types.h
@@ -238,6 +238,7 @@ enum {
   KM_SHIFT = (1 << 0),
   KM_CTRL = (1 << 1),
   KM_ALT = (1 << 2),
+  /** Use for Windows-Key on MS-Windows, Command-key on macOS and Super on Linux. */
   KM_OSKEY = (1 << 3),
 
   /* Used for key-map item creation function arguments. */
@@ -268,7 +269,7 @@ enum {
   KM_CLICK = 3,
   KM_DBL_CLICK = 4,
   /**
-   * \note The cursor location at the point dragging starts is set to #wmEvent.prev_click_xy
+   * \note The cursor location at the point dragging starts is set to #wmEvent.prev_press_xy
    * some operators such as box selection should use this location instead of #wmEvent.xy.
    */
   KM_CLICK_DRAG = 5,
@@ -629,23 +630,39 @@ typedef struct wmTabletData {
  * event comes from event manager and from keymap.
  *
  *
- * Previous State
- * ==============
+ * Previous State (`prev_*`)
+ * =========================
  *
- * Events hold information about the previous event,
- * this is used for detecting click and double-click events (the timer is needed for double-click).
- * See #wm_event_add_ghostevent for implementation details.
+ * Events hold information about the previous event.
  *
- * Notes:
- *
- * - The previous values are only set for mouse button and keyboard events.
- *   See: #ISKEYBOARD_OR_BUTTON macro.
+ * - Previous values are only set for events types that generate #KM_PRESS.
+ *   See: #ISKEYBOARD_OR_BUTTON.
  *
  * - Previous x/y are exceptions: #wmEvent.prev
  *   these are set on mouse motion, see #MOUSEMOVE & track-pad events.
  *
  * - Modal key-map handling sets `prev_val` & `prev_type` to `val` & `type`,
  *   this allows modal keys-maps to check the original values (needed in some cases).
+ *
+ *
+ * Press State (`prev_press_*`)
+ * ============================
+ *
+ * Events hold information about the state when the last #KM_PRESS event was added.
+ * This is used for generating #KM_CLICK, #KM_DBL_CLICK & #KM_CLICK_DRAG events.
+ * See #wm_handlers_do for the implementation.
+ *
+ * - Previous values are only set when a #KM_PRESS event is detected.
+ *   See: #ISKEYBOARD_OR_BUTTON.
+ *
+ * - The reason to differentiate between "press" and the previous event state is
+ *   the previous event may be set by key-release events. In the case of a single key click
+ *   this isn't a problem however releasing other keys such as modifiers prevents click/click-drag
+ *   events from being detected, see: T89989.
+ *
+ * - Mouse-wheel events are excluded even though they generate #KM_PRESS
+ *   as clicking and dragging don't make sense for mouse wheel events.
+ *
  */
 typedef struct wmEvent {
   struct wmEvent *next, *prev;
@@ -667,38 +684,16 @@ typedef struct wmEvent {
   /** From ghost, fallback if utf8 isn't set. */
   char ascii;
 
-  /** The previous value of `type`. */
-  short prev_type;
-  /** The previous value of `val`. */
-  short prev_val;
-  /**
-   * The previous value of #wmEvent.xy,
-   * Unlike other previous state variables, this is set on any mouse motion.
-   * Use `prev_click` for the value at time of pressing.
-   */
-  int prev_xy[2];
-
-  /** The `type` at the point of the click action. */
-  short prev_click_type;
-  /** The time when the key is pressed, see #PIL_check_seconds_timer. */
-  double prev_click_time;
-  /** The location when the key is pressed (used to enforce drag thresholds). */
-  int prev_click_xy[2];
-  /** The `modifier` at the point of the click action. */
-  uint8_t prev_click_modifier;
-  /** The `keymodifier` at the point of the click action. */
-  short prev_click_keymodifier;
-
-  /**
-   * Modifier states.
-   * #KM_SHIFT, #KM_CTRL, #KM_ALT & #KM_OSKEY is apple or windows-key.
-   */
+  /** Modifier states: #KM_SHIFT, #KM_CTRL, #KM_ALT & #KM_OSKEY. */
   uint8_t modifier;
 
   /** The direction (for #KM_CLICK_DRAG events only). */
   int8_t direction;
 
-  /** Raw-key modifier (allow using any key as a modifier). */
+  /**
+   * Raw-key modifier (allow using any key as a modifier).
+   * Compatible with values in `type`.
+   */
   short keymodifier;
 
   /** Tablet info, available for mouse move and button events. */
@@ -707,11 +702,44 @@ typedef struct wmEvent {
   eWM_EventFlag flag;
 
   /* Custom data. */
-  /** Custom data type, stylus, 6dof, see wm_event_types.h */
+
+  /** Custom data type, stylus, 6-DOF, see `wm_event_types.h`. */
   short custom;
   short customdata_free;
   /** Ascii, unicode, mouse-coords, angles, vectors, NDOF data, drag-drop info. */
   void *customdata;
+
+  /* Previous State. */
+
+  /** The previous value of `type`. */
+  short prev_type;
+  /** The previous value of `val`. */
+  short prev_val;
+  /**
+   * The previous value of #wmEvent.xy,
+   * Unlike other previous state variables, this is set on any mouse motion.
+   * Use `prev_press_*` for the value at time of pressing.
+   */
+  int prev_xy[2];
+
+  /* Previous Press State (when `val == KM_PRESS`). */
+
+  /** The `type` at the point of the press action. */
+  short prev_press_type;
+  /**
+   * The location when the key is pressed.
+   * used to enforce drag threshold & calculate the `direction`.
+   */
+  int prev_press_xy[2];
+  /** The `modifier` at the point of the press action. */
+  uint8_t prev_press_modifier;
+  /** The `keymodifier` at the point of the press action. */
+  short prev_press_keymodifier;
+  /**
+   * The time when the key is pressed, see #PIL_check_seconds_timer.
+   * Used to detect double-click events.
+   */
+  double prev_press_time;
 } wmEvent;
 
 /**
diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c
index b3ef9b27667..beef74ce2e2 100644
--- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c
+++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c
@@ -1137,7 +1137,7 @@ void WM_gizmo_group_refresh(const bContext *C, wmGizmoGroup *gzgroup)
       BLI_assert(region->gizmo_map == gzmap);
       /* Check if the tweak event originated from this region. */
       if ((win->eventstate != NULL) && (win->event_queue_check_drag) &&
-          BLI_rcti_isect_pt_v(&region->winrct, win->eventstate->prev_click_xy)) {
+          BLI_rcti_isect_pt_v(&region->winrct, win->eventstate->prev_press_xy)) {
         /* We need to run refresh again. */
         gzgroup->init_flag &= ~WM_GIZMOGROUP_INIT_REFRESH;
         WM_gizmomap_tag_refresh_drawstep(gzmap, WM_gizmomap_drawstep_from_gizmo_group(gzgroup));
diff --git a/source/blender/windowmanager/intern/wm_event_query.c b/source/blender/windowmanager/intern/wm_event_query.c
index c9f83a5d811..9a7d31f8bb8 100644
--- a/source/blender/windowmanager/intern/wm_event_query.c
+++ b/source/blender/windowmanager/intern/wm_event_query.c
@@ -227,8 +227,8 @@ bool WM_event_is_mouse_drag_or_press(const wmEvent *event)
 int WM_event_drag_direction(const wmEvent *event)
 {
   const int delta[2] = {
-    

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list