Blender V4.5
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 "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 */
32
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
89
90/* -------------------------------------------------------------------- */
91/* Utility Functions
92 */
93
96
97void eyedropper_draw_cursor_text_region(const int xy[2], const char *name)
98{
99 if (name[0] == '\0') {
100 return;
101 }
102
103 const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
104
105 /* Use the theme settings from tooltips. */
106 const bTheme *btheme = UI_GetTheme();
107 const uiWidgetColors *wcol = &btheme->tui.wcol_tooltip;
108
109 float col_fg[4], col_bg[4];
110 rgba_uchar_to_float(col_fg, wcol->text);
111 rgba_uchar_to_float(col_bg, wcol->inner);
112
113 UI_fontstyle_draw_simple_backdrop(fstyle, xy[0], xy[1] + U.widget_unit, name, col_fg, col_bg);
114}
115
117{
118 bScreen *screen = CTX_wm_screen(C);
119 ScrArea *area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, event->xy);
120 const ARegion *region = BKE_area_find_region_xy(area, RGN_TYPE_ANY, event->xy);
121
122 uiBut *but = ui_but_find_mouse_over(region, event);
123
124 if (ELEM(nullptr, but, but->rnapoin.data, but->rnaprop)) {
125 return nullptr;
126 }
127 return but;
128}
129
131 const int event_xy[2],
132 int r_event_xy[2],
133 wmWindow **r_win,
134 ScrArea **r_area)
135{
136 bScreen *screen = CTX_wm_screen(C);
137
138 *r_win = CTX_wm_window(C);
139 *r_area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, event_xy);
140 if (*r_area == nullptr) {
141 *r_win = WM_window_find_under_cursor(*r_win, event_xy, r_event_xy);
142 if (*r_win) {
143 screen = WM_window_get_active_screen(*r_win);
144 *r_area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, r_event_xy);
145 }
146 }
147 else if (event_xy != r_event_xy) {
148 copy_v2_v2_int(r_event_xy, event_xy);
149 }
150}
151
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:869
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
#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])
#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)
uiBut * ui_but_find_mouse_over(const ARegion *region, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
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:758
const void * modal_items
int xy[2]
Definition wm_draw.cc:174
wmKeyMap * WM_modalkeymap_ensure(wmKeyConfig *keyconf, const char *idname, const EnumPropertyItem *items)
Definition wm_keymap.cc:929
void WM_modalkeymap_assign(wmKeyMap *km, const char *opname)
wmKeyMap * WM_modalkeymap_find(wmKeyConfig *keyconf, const char *idname)
Definition wm_keymap.cc:956
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)