Blender V5.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
8
9#include "DNA_screen_types.h"
10#include "DNA_space_types.h"
11
12#include "BLI_math_color_c.hh"
13#include "BLI_math_vector_c.hh"
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
25namespace blender::ui {
26
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/* -------------------------------------------------------------------- */
91
92void eyedropper_draw_cursor_text_region(const int xy[2], const char *name)
93{
94 if (name[0] == '\0') {
95 return;
96 }
97
98 const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
99
100 /* Use the theme settings from tooltips. */
101 const bTheme *btheme = theme::theme_get();
102 const uiWidgetColors *wcol = &btheme->tui.wcol_tooltip;
103
104 float col_fg[4], col_bg[4];
105 rgba_uchar_to_float(col_fg, wcol->text);
106 rgba_uchar_to_float(col_bg, wcol->inner);
107
108 fontstyle_draw_simple_backdrop(fstyle, xy[0], xy[1] + U.widget_unit, name, col_fg, col_bg);
109}
110
112{
113 bScreen *screen = CTX_wm_screen(C);
114 ScrArea *area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, event->xy);
115 const ARegion *region = BKE_area_find_region_xy(area, RGN_TYPE_ANY, event->xy);
116
117 Button *but = but_find_mouse_over(region, event);
118
119 if (!but || !but->rnapoin || !but->rnaprop) {
120 return nullptr;
121 }
122 return but;
123}
124
126 const int event_xy[2],
127 int r_event_xy[2],
128 wmWindow **r_win,
129 ScrArea **r_area)
130{
131 bScreen *screen = CTX_wm_screen(C);
132
133 *r_win = CTX_wm_window(C);
134 *r_area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, event_xy);
135 if (*r_area == nullptr) {
136 *r_win = WM_window_find_under_cursor(*r_win, event_xy, r_event_xy);
137 if (*r_win) {
138 screen = WM_window_get_active_screen(*r_win);
139 *r_area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, r_event_xy);
140 }
141 }
142 else if (event_xy != r_event_xy) {
143 copy_v2_v2_int(r_event_xy, event_xy);
144 }
145}
146
148
149} // namespace blender::ui
#define RGN_TYPE_ANY
#define SPACE_TYPE_ANY
#define C
Definition RandGen.cpp:29
#define UI_FSTYLE_WIDGET
const bTheme * theme_get()
Button * but_find_mouse_over(const ARegion *region, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
void fontstyle_draw_simple_backdrop(const uiFontStyle *fs, float x, float y, StringRef str, const float col_fg[4], const float col_bg[4])
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_modal_keymap(wmKeyConfig *keyconf)
void eyedropper_draw_cursor_text_region(const int xy[2], const char *name)
wmKeyMap * eyedropper_colorband_modal_keymap(wmKeyConfig *keyconf)
Button * eyedropper_get_property_button_under_mouse(bContext *C, const wmEvent *event)
UserDef U
Definition blender.cc:58
MINLINE void copy_v2_v2_int(int r[2], const int a[2])
MINLINE void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4])
wmKeyMap * WM_modalkeymap_find(wmKeyConfig *keyconf, const char *idname)
Definition wm_keymap.cc:999
wmWindow * WM_window_find_under_cursor(wmWindow *win, const int event_xy[2], int r_event_xy_other[2])
wmWindow * CTX_wm_window(const bContext *C)
ScrArea ScrArea * BKE_screen_find_area_xy(const bScreen *screen, int spacetype, const int xy[2]) ATTR_NONNULL(1
Definition screen.cc:1226
void WM_modalkeymap_assign(wmKeyMap *km, const char *opname)
bScreen * CTX_wm_screen(const bContext *C)
wmKeyMap * WM_modalkeymap_ensure(wmKeyConfig *keyconf, const char *idname, const EnumPropertyItem *items)
Definition wm_keymap.cc:972
bScreen * WM_window_get_active_screen(const wmWindow *win)
ARegion * BKE_area_find_region_xy(const ScrArea *area, int regiontype, const int xy[2]) ATTR_NONNULL(3)
Definition screen.cc:1053
uiWidgetColors wcol_tooltip
ThemeUI tui
unsigned char inner[4]
unsigned char text[4]