Blender V5.0
interface_eyedropper.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "DNA_screen_types.h"
10#include "DNA_space_types.h"
11
12#include "BLI_math_color.h"
13#include "BLI_math_vector.h"
14
15#include "BKE_context.hh"
16#include "BKE_screen.hh"
17
18#include "WM_api.hh"
19#include "WM_types.hh"
20
21#include "interface_intern.hh"
22
23#include "eyedropper_intern.hh" /* own include */
24
25/* -------------------------------------------------------------------- */
26/* Keymap
27 */
30
32{
33 static const EnumPropertyItem modal_items[] = {
34 {EYE_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
35 {EYE_MODAL_SAMPLE_CONFIRM, "SAMPLE_CONFIRM", 0, "Confirm Sampling", ""},
36 {EYE_MODAL_SAMPLE_BEGIN, "SAMPLE_BEGIN", 0, "Start Sampling", ""},
37 {EYE_MODAL_SAMPLE_RESET, "SAMPLE_RESET", 0, "Reset Sampling", ""},
38 {0, nullptr, 0, nullptr, nullptr},
39 };
40
41 wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "Eyedropper Modal Map");
42
43 /* This function is called for each space-type, only needs to add map once. */
44 if (keymap && keymap->modal_items) {
45 return nullptr;
46 }
47
48 keymap = WM_modalkeymap_ensure(keyconf, "Eyedropper Modal Map", modal_items);
49
50 /* assign to operators */
51 WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_colorramp");
52 WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_color");
53 WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_id");
54 WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_bone");
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_grease_pencil_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, nullptr, 0, nullptr, nullptr},
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
87
88/* -------------------------------------------------------------------- */
89/* Utility Functions
90 */
91
94
95void eyedropper_draw_cursor_text_region(const int xy[2], const char *name)
96{
97 if (name[0] == '\0') {
98 return;
99 }
100
101 const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
102
103 /* Use the theme settings from tooltips. */
104 const bTheme *btheme = UI_GetTheme();
105 const uiWidgetColors *wcol = &btheme->tui.wcol_tooltip;
106
107 float col_fg[4], col_bg[4];
108 rgba_uchar_to_float(col_fg, wcol->text);
109 rgba_uchar_to_float(col_bg, wcol->inner);
110
111 UI_fontstyle_draw_simple_backdrop(fstyle, xy[0], xy[1] + U.widget_unit, name, col_fg, col_bg);
112}
113
115{
116 bScreen *screen = CTX_wm_screen(C);
117 ScrArea *area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, event->xy);
118 const ARegion *region = BKE_area_find_region_xy(area, RGN_TYPE_ANY, event->xy);
119
120 uiBut *but = UI_but_find_mouse_over(region, event);
121
122 if (ELEM(nullptr, but, but->rnapoin.data, but->rnaprop)) {
123 return nullptr;
124 }
125 return but;
126}
127
129 const int event_xy[2],
130 int r_event_xy[2],
131 wmWindow **r_win,
132 ScrArea **r_area)
133{
134 bScreen *screen = CTX_wm_screen(C);
135
136 *r_win = CTX_wm_window(C);
137 *r_area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, event_xy);
138 if (*r_area == nullptr) {
139 *r_win = WM_window_find_under_cursor(*r_win, event_xy, r_event_xy);
140 if (*r_win) {
141 screen = WM_window_get_active_screen(*r_win);
142 *r_area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, r_event_xy);
143 }
144 }
145 else if (event_xy != r_event_xy) {
146 copy_v2_v2_int(r_event_xy, event_xy);
147 }
148}
149
bScreen * CTX_wm_screen(const bContext *C)
wmWindow * CTX_wm_window(const bContext *C)
ARegion * BKE_area_find_region_xy(const ScrArea *area, int regiontype, const int xy[2]) ATTR_NONNULL(3)
Definition screen.cc:875
ScrArea ScrArea * BKE_screen_find_area_xy(const bScreen *screen, int spacetype, const int xy[2]) ATTR_NONNULL(1
MINLINE void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4])
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:29
void UI_fontstyle_draw_simple_backdrop(const uiFontStyle *fs, float x, float y, blender::StringRef str, const float col_fg[4], const float col_bg[4])
uiBut * UI_but_find_mouse_over(const ARegion *region, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
#define UI_FSTYLE_WIDGET
bTheme * UI_GetTheme()
#define U
@ 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
uiBut * eyedropper_get_property_button_under_mouse(bContext *C, const wmEvent *event)
void eyedropper_win_area_find(const bContext *C, const int event_xy[2], int r_event_xy[2], wmWindow **r_win, ScrArea **r_area)
wmKeyMap * eyedropper_colorband_modal_keymap(wmKeyConfig *keyconf)
wmKeyMap * eyedropper_modal_keymap(wmKeyConfig *keyconf)
void eyedropper_draw_cursor_text_region(const int xy[2], const char *name)
const char * name
void * data
Definition RNA_types.hh:53
uiWidgetColors wcol_tooltip
ThemeUI tui
PropertyRNA * rnaprop
PointerRNA rnapoin
unsigned char inner[4]
unsigned char text[4]
int xy[2]
Definition WM_types.hh:761
const void * modal_items
int xy[2]
Definition wm_draw.cc:178
wmKeyMap * WM_modalkeymap_ensure(wmKeyConfig *keyconf, const char *idname, const EnumPropertyItem *items)
Definition wm_keymap.cc:932
void WM_modalkeymap_assign(wmKeyMap *km, const char *opname)
wmKeyMap * WM_modalkeymap_find(wmKeyConfig *keyconf, const char *idname)
Definition wm_keymap.cc:959
wmWindow * WM_window_find_under_cursor(wmWindow *win, const int event_xy[2], int r_event_xy_other[2])
bScreen * WM_window_get_active_screen(const wmWindow *win)