Blender  V3.3
interface_eyedropper.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2009 Blender Foundation. All rights reserved. */
3 
8 #include "DNA_screen_types.h"
9 #include "DNA_space_types.h"
10 
11 #include "BLI_math_color.h"
12 #include "BLI_math_vector.h"
13 
14 #include "BKE_context.h"
15 #include "BKE_screen.h"
16 
17 #include "UI_interface.h"
18 
19 #include "WM_api.h"
20 #include "WM_types.h"
21 
22 #include "interface_intern.h"
23 
24 #include "eyedropper_intern.h" /* own include */
25 
26 /* -------------------------------------------------------------------- */
27 /* Keymap
28  */
33 {
34  static const EnumPropertyItem modal_items[] = {
35  {EYE_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
36  {EYE_MODAL_SAMPLE_CONFIRM, "SAMPLE_CONFIRM", 0, "Confirm Sampling", ""},
37  {EYE_MODAL_SAMPLE_BEGIN, "SAMPLE_BEGIN", 0, "Start Sampling", ""},
38  {EYE_MODAL_SAMPLE_RESET, "SAMPLE_RESET", 0, "Reset Sampling", ""},
39  {0, NULL, 0, NULL, NULL},
40  };
41 
42  wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "Eyedropper Modal Map");
43 
44  /* this function is called for each spacetype, only needs to add map once */
45  if (keymap && keymap->modal_items) {
46  return NULL;
47  }
48 
49  keymap = WM_modalkeymap_ensure(keyconf, "Eyedropper Modal Map", modal_items);
50 
51  /* assign to operators */
52  WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_colorramp");
53  WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_color");
54  WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_id");
55  WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_depth");
56  WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_driver");
57  WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_gpencil_color");
58 
59  return keymap;
60 }
61 
63 {
64  static const EnumPropertyItem modal_items_point[] = {
65  {EYE_MODAL_POINT_CANCEL, "CANCEL", 0, "Cancel", ""},
66  {EYE_MODAL_POINT_SAMPLE, "SAMPLE_SAMPLE", 0, "Sample a Point", ""},
67  {EYE_MODAL_POINT_CONFIRM, "SAMPLE_CONFIRM", 0, "Confirm Sampling", ""},
68  {EYE_MODAL_POINT_RESET, "SAMPLE_RESET", 0, "Reset Sampling", ""},
69  {0, NULL, 0, NULL, NULL},
70  };
71 
72  wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "Eyedropper ColorRamp PointSampling Map");
73  if (keymap && keymap->modal_items) {
74  return keymap;
75  }
76 
77  keymap = WM_modalkeymap_ensure(
78  keyconf, "Eyedropper ColorRamp PointSampling Map", modal_items_point);
79 
80  /* assign to operators */
81  WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_colorramp_point");
82 
83  return keymap;
84 }
85 
88 /* -------------------------------------------------------------------- */
89 /* Utility Functions
90  */
91 
95 static void eyedropper_draw_cursor_text_ex(const int xy[2], const char *name)
96 {
97  const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
98 
99  /* Use the theme settings from tooltips. */
100  const bTheme *btheme = UI_GetTheme();
101  const uiWidgetColors *wcol = &btheme->tui.wcol_tooltip;
102 
103  float col_fg[4], col_bg[4];
104  rgba_uchar_to_float(col_fg, wcol->text);
105  rgba_uchar_to_float(col_bg, wcol->inner);
106 
107  UI_fontstyle_draw_simple_backdrop(fstyle, xy[0], xy[1] + U.widget_unit, name, col_fg, col_bg);
108 }
109 
110 void eyedropper_draw_cursor_text_window(const struct wmWindow *window, const char *name)
111 {
112  if (name[0] == '\0') {
113  return;
114  }
115 
117 }
118 
119 void eyedropper_draw_cursor_text_region(const int xy[2], const char *name)
120 {
121  if (name[0] == '\0') {
122  return;
123  }
124 
126 }
127 
129 {
130  bScreen *screen = CTX_wm_screen(C);
132  const ARegion *region = BKE_area_find_region_xy(area, RGN_TYPE_ANY, event->xy);
133 
134  uiBut *but = ui_but_find_mouse_over(region, event);
135 
136  if (ELEM(NULL, but, but->rnapoin.data, but->rnaprop)) {
137  return NULL;
138  }
139  return but;
140 }
141 
143  const bContext *C, const int mval[2], int r_mval[2], wmWindow **r_win, ScrArea **r_area)
144 {
145  bScreen *screen = CTX_wm_screen(C);
146 
147  *r_win = CTX_wm_window(C);
148  *r_area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, mval);
149  if (*r_area == NULL) {
150  *r_win = WM_window_find_under_cursor(*r_win, mval, r_mval);
151  if (*r_win) {
152  screen = WM_window_get_active_screen(*r_win);
153  *r_area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, r_mval);
154  }
155  }
156  else if (mval != r_mval) {
157  copy_v2_v2_int(r_mval, mval);
158  }
159 }
160 
struct bScreen * CTX_wm_screen(const bContext *C)
Definition: context.c:733
struct wmWindow * CTX_wm_window(const bContext *C)
Definition: context.c:723
struct ScrArea struct ScrArea * BKE_screen_find_area_xy(struct bScreen *screen, int spacetype, const int xy[2]) ATTR_NONNULL(1
struct ARegion * BKE_area_find_region_xy(struct ScrArea *area, int regiontype, const int xy[2]) ATTR_NONNULL(3)
Definition: screen.c:898
void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4])
Definition: math_color.c:383
MINLINE void copy_v2_v2_int(int r[2], const int a[2])
#define ELEM(...)
#define RGN_TYPE_ANY
#define SPACE_TYPE_ANY
#define C
Definition: RandGen.cpp:25
void UI_fontstyle_draw_simple_backdrop(const struct uiFontStyle *fs, float x, float y, const char *str, const float col_fg[4], const float col_bg[4])
#define UI_FSTYLE_WIDGET
struct bTheme * UI_GetTheme(void)
Definition: resources.c:1067
unsigned int U
Definition: btGjkEpa3.h:78
@ EYE_MODAL_SAMPLE_BEGIN
@ EYE_MODAL_SAMPLE_RESET
@ EYE_MODAL_CANCEL
@ EYE_MODAL_SAMPLE_CONFIRM
@ EYE_MODAL_POINT_CANCEL
@ EYE_MODAL_POINT_RESET
@ EYE_MODAL_POINT_SAMPLE
@ EYE_MODAL_POINT_CONFIRM
wmKeyMap * eyedropper_modal_keymap(wmKeyConfig *keyconf)
uiBut * eyedropper_get_property_button_under_mouse(bContext *C, const wmEvent *event)
static void eyedropper_draw_cursor_text_ex(const int xy[2], const char *name)
void eyedropper_draw_cursor_text_window(const struct wmWindow *window, const char *name)
void eyedropper_draw_cursor_text_region(const int xy[2], const char *name)
void datadropper_win_area_find(const bContext *C, const int mval[2], int r_mval[2], wmWindow **r_win, ScrArea **r_area)
wmKeyMap * eyedropper_colorband_modal_keymap(wmKeyConfig *keyconf)
uiBut * ui_but_find_mouse_over(const struct ARegion *region, const struct wmEvent *event) ATTR_WARN_UNUSED_RESULT
static void area(int d1, int d2, int e1, int e2, float weights[2])
void * data
Definition: RNA_types.h:38
uiWidgetColors wcol_tooltip
ThemeUI tui
struct PropertyRNA * rnaprop
struct PointerRNA rnapoin
unsigned char inner[4]
unsigned char text[4]
int xy[2]
Definition: WM_types.h:682
const void * modal_items
struct wmEvent * eventstate
int xy[2]
Definition: wm_draw.c:135
wmKeyMap * WM_modalkeymap_find(wmKeyConfig *keyconf, const char *idname)
Definition: wm_keymap.c:914
void WM_modalkeymap_assign(wmKeyMap *km, const char *opname)
Definition: wm_keymap.c:985
wmKeyMap * WM_modalkeymap_ensure(wmKeyConfig *keyconf, const char *idname, const EnumPropertyItem *items)
Definition: wm_keymap.c:888
wmWindow * WM_window_find_under_cursor(wmWindow *win, const int mval[2], int r_mval[2])
Definition: wm_window.c:1904
bScreen * WM_window_get_active_screen(const wmWindow *win)
Definition: wm_window.c:2300