[Bf-blender-cvs] [aadbdb80484] master: Cleanup: split eyedropper_color_sample_fl into more specific utilities

Germano Cavalcante noreply at git.blender.org
Thu Aug 26 19:17:02 CEST 2021


Commit: aadbdb80484c374f054c23502c76511be588fd77
Author: Germano Cavalcante
Date:   Thu Aug 26 14:12:21 2021 -0300
Branches: master
https://developer.blender.org/rBaadbdb80484c374f054c23502c76511be588fd77

Cleanup: split eyedropper_color_sample_fl into more specific utilities

The window and region find utility can be used in other eyedropper
operators.

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

M	source/blender/editors/interface/interface_eyedropper.c
M	source/blender/editors/interface/interface_eyedropper_color.c
M	source/blender/editors/interface/interface_eyedropper_intern.h

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

diff --git a/source/blender/editors/interface/interface_eyedropper.c b/source/blender/editors/interface/interface_eyedropper.c
index b52bfc81b7a..59629e9f1e6 100644
--- a/source/blender/editors/interface/interface_eyedropper.c
+++ b/source/blender/editors/interface/interface_eyedropper.c
@@ -168,4 +168,25 @@ uiBut *eyedropper_get_property_button_under_mouse(bContext *C, const wmEvent *ev
   return but;
 }
 
+void datadropper_win_area_find(
+    const bContext *C, const int mval[2], int r_mval[2], wmWindow **r_win, ScrArea **r_area)
+{
+  bScreen *screen = CTX_wm_screen(C);
+
+  *r_win = CTX_wm_window(C);
+  *r_area = BKE_screen_find_area_xy(screen, -1, mval[0], mval[1]);
+  if (*r_area == NULL) {
+    wmWindowManager *wm = CTX_wm_manager(C);
+    *r_win = WM_window_find_under_cursor(wm, NULL, *r_win, mval, r_mval);
+    if (*r_win) {
+      screen = WM_window_get_active_screen(*r_win);
+      *r_area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, r_mval[0], r_mval[1]);
+    }
+  }
+  else if (mval != r_mval) {
+    r_mval[0] = mval[0];
+    r_mval[1] = mval[1];
+  }
+}
+
 /** \} */
diff --git a/source/blender/editors/interface/interface_eyedropper_color.c b/source/blender/editors/interface/interface_eyedropper_color.c
index a8542c47fc2..9d06fb2b27a 100644
--- a/source/blender/editors/interface/interface_eyedropper_color.c
+++ b/source/blender/editors/interface/interface_eyedropper_color.c
@@ -337,50 +337,41 @@ void eyedropper_color_sample_fl(bContext *C, int mx, int my, float r_col[3])
   const char *display_device = CTX_data_scene(C)->display_settings.display_device;
   struct ColorManagedDisplay *display = IMB_colormanagement_display_get_named(display_device);
 
-  wmWindow *win = CTX_wm_window(C);
-  bScreen *screen = CTX_wm_screen(C);
-  ScrArea *area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, mx, my);
-  if (area == NULL) {
-    int mval[2] = {mx, my};
-    win = WM_window_find_under_cursor(wm, NULL, win, mval, mval);
-    if (win) {
-      mx = mval[0];
-      my = mval[1];
-      screen = WM_window_get_active_screen(win);
-      area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, mx, my);
-    }
-  }
+  wmWindow *win;
+  ScrArea *area;
+  int mval[2] = {mx, my};
+  datadropper_win_area_find(C, mval, mval, &win, &area);
 
   if (area) {
     if (area->spacetype == SPACE_IMAGE) {
-      ARegion *region = BKE_area_find_region_xy(area, RGN_TYPE_WINDOW, mx, my);
+      ARegion *region = BKE_area_find_region_xy(area, RGN_TYPE_WINDOW, mval[0], mval[1]);
       if (region) {
         SpaceImage *sima = area->spacedata.first;
-        int mval[2] = {mx - region->winrct.xmin, my - region->winrct.ymin};
+        int region_mval[2] = {mval[0] - region->winrct.xmin, mval[1] - region->winrct.ymin};
 
-        if (ED_space_image_color_sample(sima, region, mval, r_col, NULL)) {
+        if (ED_space_image_color_sample(sima, region, region_mval, r_col, NULL)) {
           return;
         }
       }
     }
     else if (area->spacetype == SPACE_NODE) {
-      ARegion *region = BKE_area_find_region_xy(area, RGN_TYPE_WINDOW, mx, my);
+      ARegion *region = BKE_area_find_region_xy(area, RGN_TYPE_WINDOW, mval[0], mval[1]);
       if (region) {
         SpaceNode *snode = area->spacedata.first;
-        const int mval[2] = {mx - region->winrct.xmin, my - region->winrct.ymin};
+        int region_mval[2] = {mval[0] - region->winrct.xmin, mval[1] - region->winrct.ymin};
 
-        if (ED_space_node_color_sample(bmain, snode, region, mval, r_col)) {
+        if (ED_space_node_color_sample(bmain, snode, region, region_mval, r_col)) {
           return;
         }
       }
     }
     else if (area->spacetype == SPACE_CLIP) {
-      ARegion *region = BKE_area_find_region_xy(area, RGN_TYPE_WINDOW, mx, my);
+      ARegion *region = BKE_area_find_region_xy(area, RGN_TYPE_WINDOW, mval[0], mval[1]);
       if (region) {
         SpaceClip *sc = area->spacedata.first;
-        int mval[2] = {mx - region->winrct.xmin, my - region->winrct.ymin};
+        int region_mval[2] = {mval[0] - region->winrct.xmin, mval[1] - region->winrct.ymin};
 
-        if (ED_space_clip_color_sample(sc, region, mval, r_col)) {
+        if (ED_space_clip_color_sample(sc, region, region_mval, r_col)) {
           return;
         }
       }
@@ -389,7 +380,6 @@ void eyedropper_color_sample_fl(bContext *C, int mx, int my, float r_col[3])
 
   if (win) {
     /* Fallback to simple opengl picker. */
-    const int mval[2] = {mx, my};
     WM_window_pixel_sample_read(wm, win, mval, r_col);
     IMB_colormanagement_display_to_scene_linear_v3(r_col, display);
   }
diff --git a/source/blender/editors/interface/interface_eyedropper_intern.h b/source/blender/editors/interface/interface_eyedropper_intern.h
index 96a2c6ed111..2957ea337e0 100644
--- a/source/blender/editors/interface/interface_eyedropper_intern.h
+++ b/source/blender/editors/interface/interface_eyedropper_intern.h
@@ -28,6 +28,11 @@ void eyedropper_draw_cursor_text_region(const struct bContext *C,
                                         const struct ARegion *region,
                                         const char *name);
 uiBut *eyedropper_get_property_button_under_mouse(bContext *C, const wmEvent *event);
+void datadropper_win_area_find(const struct bContext *C,
+                               const int mval[2],
+                               int r_mval[2],
+                               struct wmWindow **r_win,
+                               struct ScrArea **r_area);
 
 /* interface_eyedropper_color.c (expose for color-band picker) */
 void eyedropper_color_sample_fl(bContext *C, int mx, int my, float r_col[3]);



More information about the Bf-blender-cvs mailing list