Blender V4.3
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
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 "UI_interface.hh"
19
20#include "WM_api.hh"
21#include "WM_types.hh"
22
23#include "interface_intern.hh"
24
25#include "eyedropper_intern.hh" /* own include */
26
27/* -------------------------------------------------------------------- */
28/* Keymap
29 */
34{
35 static const EnumPropertyItem modal_items[] = {
36 {EYE_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
37 {EYE_MODAL_SAMPLE_CONFIRM, "SAMPLE_CONFIRM", 0, "Confirm Sampling", ""},
38 {EYE_MODAL_SAMPLE_BEGIN, "SAMPLE_BEGIN", 0, "Start Sampling", ""},
39 {EYE_MODAL_SAMPLE_RESET, "SAMPLE_RESET", 0, "Reset Sampling", ""},
40 {0, nullptr, 0, nullptr, nullptr},
41 };
42
43 wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "Eyedropper Modal Map");
44
45 /* This function is called for each space-type, only needs to add map once. */
46 if (keymap && keymap->modal_items) {
47 return nullptr;
48 }
49
50 keymap = WM_modalkeymap_ensure(keyconf, "Eyedropper Modal Map", modal_items);
51
52 /* assign to operators */
53 WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_colorramp");
54 WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_color");
55 WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_id");
56 WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_bone");
57 WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_depth");
58 WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_driver");
59 WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_grease_pencil_color");
60
61 return keymap;
62}
63
65{
66 static const EnumPropertyItem modal_items_point[] = {
67 {EYE_MODAL_POINT_CANCEL, "CANCEL", 0, "Cancel", ""},
68 {EYE_MODAL_POINT_SAMPLE, "SAMPLE_SAMPLE", 0, "Sample a Point", ""},
69 {EYE_MODAL_POINT_CONFIRM, "SAMPLE_CONFIRM", 0, "Confirm Sampling", ""},
70 {EYE_MODAL_POINT_RESET, "SAMPLE_RESET", 0, "Reset Sampling", ""},
71 {0, nullptr, 0, nullptr, nullptr},
72 };
73
74 wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "Eyedropper ColorRamp PointSampling Map");
75 if (keymap && keymap->modal_items) {
76 return keymap;
77 }
78
79 keymap = WM_modalkeymap_ensure(
80 keyconf, "Eyedropper ColorRamp PointSampling Map", modal_items_point);
81
82 /* assign to operators */
83 WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_colorramp_point");
84
85 return keymap;
86}
87
90/* -------------------------------------------------------------------- */
91/* Utility Functions
92 */
93
97static void eyedropper_draw_cursor_text_ex(const int xy[2], const char *name)
98{
99 const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
100
101 /* Use the theme settings from tooltips. */
102 const bTheme *btheme = UI_GetTheme();
103 const uiWidgetColors *wcol = &btheme->tui.wcol_tooltip;
104
105 float col_fg[4], col_bg[4];
106 rgba_uchar_to_float(col_fg, wcol->text);
107 rgba_uchar_to_float(col_bg, wcol->inner);
108
109 UI_fontstyle_draw_simple_backdrop(fstyle, xy[0], xy[1] + U.widget_unit, name, col_fg, col_bg);
110}
111
112void eyedropper_draw_cursor_text_window(const wmWindow *window, const char *name)
113{
114 if (name[0] == '\0') {
115 return;
116 }
117
119}
120
121void eyedropper_draw_cursor_text_region(const int xy[2], const char *name)
122{
123 if (name[0] == '\0') {
124 return;
125 }
126
128}
129
131{
132 bScreen *screen = CTX_wm_screen(C);
133 ScrArea *area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, event->xy);
134 const ARegion *region = BKE_area_find_region_xy(area, RGN_TYPE_ANY, event->xy);
135
136 uiBut *but = ui_but_find_mouse_over(region, event);
137
138 if (ELEM(nullptr, but, but->rnapoin.data, but->rnaprop)) {
139 return nullptr;
140 }
141 return but;
142}
143
145 const int event_xy[2],
146 int r_event_xy[2],
147 wmWindow **r_win,
148 ScrArea **r_area)
149{
150 bScreen *screen = CTX_wm_screen(C);
151
152 *r_win = CTX_wm_window(C);
153 *r_area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, event_xy);
154 if (*r_area == nullptr) {
155 *r_win = WM_window_find_under_cursor(*r_win, event_xy, r_event_xy);
156 if (*r_win) {
157 screen = WM_window_get_active_screen(*r_win);
158 *r_area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, r_event_xy);
159 }
160 }
161 else if (event_xy != r_event_xy) {
162 copy_v2_v2_int(r_event_xy, event_xy);
163 }
164}
165
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:844
ScrArea ScrArea * BKE_screen_find_area_xy(const bScreen *screen, int spacetype, const int xy[2]) ATTR_NONNULL(1
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
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])
#define UI_FSTYLE_WIDGET
bTheme * UI_GetTheme()
unsigned int U
Definition btGjkEpa3.h:78
@ EYE_MODAL_POINT_CANCEL
@ EYE_MODAL_POINT_RESET
@ EYE_MODAL_POINT_SAMPLE
@ EYE_MODAL_POINT_CONFIRM
@ EYE_MODAL_SAMPLE_BEGIN
@ EYE_MODAL_SAMPLE_RESET
@ EYE_MODAL_CANCEL
@ EYE_MODAL_SAMPLE_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)
static void eyedropper_draw_cursor_text_ex(const int xy[2], const char *name)
void eyedropper_draw_cursor_text_region(const int xy[2], const char *name)
void eyedropper_draw_cursor_text_window(const wmWindow *window, const char *name)
uiBut * ui_but_find_mouse_over(const ARegion *region, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
void * data
Definition RNA_types.hh:42
uiWidgetColors wcol_tooltip
PropertyRNA * rnaprop
PointerRNA rnapoin
unsigned char inner[4]
unsigned char text[4]
int xy[2]
Definition WM_types.hh:726
const void * modal_items
struct wmEvent * eventstate
int xy[2]
Definition wm_draw.cc:170
wmKeyMap * WM_modalkeymap_ensure(wmKeyConfig *keyconf, const char *idname, const EnumPropertyItem *items)
Definition wm_keymap.cc:933
void WM_modalkeymap_assign(wmKeyMap *km, const char *opname)
wmKeyMap * WM_modalkeymap_find(wmKeyConfig *keyconf, const char *idname)
Definition wm_keymap.cc:960
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)