Blender  V2.93
interface_eyedropper.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2009 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "DNA_screen_types.h"
25 #include "DNA_space_types.h"
26 
27 #include "BKE_context.h"
28 #include "BKE_screen.h"
29 
30 #include "UI_interface.h"
31 
32 #include "WM_api.h"
33 #include "WM_types.h"
34 
35 #include "interface_intern.h"
36 
37 #include "interface_eyedropper_intern.h" /* own include */
38 
39 /* -------------------------------------------------------------------- */
40 /* Keymap
41  */
46 {
47  static const EnumPropertyItem modal_items[] = {
48  {EYE_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
49  {EYE_MODAL_SAMPLE_CONFIRM, "SAMPLE_CONFIRM", 0, "Confirm Sampling", ""},
50  {EYE_MODAL_SAMPLE_BEGIN, "SAMPLE_BEGIN", 0, "Start Sampling", ""},
51  {EYE_MODAL_SAMPLE_RESET, "SAMPLE_RESET", 0, "Reset Sampling", ""},
52  {0, NULL, 0, NULL, NULL},
53  };
54 
55  wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "Eyedropper Modal Map");
56 
57  /* this function is called for each spacetype, only needs to add map once */
58  if (keymap && keymap->modal_items) {
59  return NULL;
60  }
61 
62  keymap = WM_modalkeymap_ensure(keyconf, "Eyedropper Modal Map", modal_items);
63 
64  /* assign to operators */
65  WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_colorramp");
66  WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_color");
67  WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_id");
68  WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_depth");
69  WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_driver");
70  WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_gpencil_color");
71 
72  return keymap;
73 }
74 
76 {
77  static const EnumPropertyItem modal_items_point[] = {
78  {EYE_MODAL_POINT_CANCEL, "CANCEL", 0, "Cancel", ""},
79  {EYE_MODAL_POINT_SAMPLE, "SAMPLE_SAMPLE", 0, "Sample a Point", ""},
80  {EYE_MODAL_POINT_CONFIRM, "SAMPLE_CONFIRM", 0, "Confirm Sampling", ""},
81  {EYE_MODAL_POINT_RESET, "SAMPLE_RESET", 0, "Reset Sampling", ""},
82  {0, NULL, 0, NULL, NULL},
83  };
84 
85  wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "Eyedropper ColorRamp PointSampling Map");
86  if (keymap && keymap->modal_items) {
87  return keymap;
88  }
89 
90  keymap = WM_modalkeymap_ensure(
91  keyconf, "Eyedropper ColorRamp PointSampling Map", modal_items_point);
92 
93  /* assign to operators */
94  WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_colorramp_point");
95 
96  return keymap;
97 }
98 
101 /* -------------------------------------------------------------------- */
102 /* Utility Functions
103  */
106 static void eyedropper_draw_cursor_text_ex(const int x, const int y, const char *name)
107 {
108  const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
109 
110  const float col_fg[4] = {1.0f, 1.0f, 1.0f, 1.0f};
111  const float col_bg[4] = {0.0f, 0.0f, 0.0f, 0.2f};
112 
113  UI_fontstyle_draw_simple_backdrop(fstyle, x, y + U.widget_unit, name, col_fg, col_bg);
114 }
115 
116 void eyedropper_draw_cursor_text_window(const struct wmWindow *window, const char *name)
117 {
118  if (name[0] == '\0') {
119  return;
120  }
121 
122  const int x = window->eventstate->x;
123  const int y = window->eventstate->y;
124 
126 }
127 
129  const ARegion *region,
130  const char *name)
131 {
132  wmWindow *win = CTX_wm_window(C);
133  const int x = win->eventstate->x;
134  const int y = win->eventstate->y;
135 
136  if ((name[0] == '\0') || (BLI_rcti_isect_pt(&region->winrct, x, y) == false)) {
137  return;
138  }
139 
140  const int mval[2] = {
141  x - region->winrct.xmin,
142  y - region->winrct.ymin,
143  };
144 
145  eyedropper_draw_cursor_text_ex(mval[0], mval[1], name);
146 }
147 
158 {
159  bScreen *screen = CTX_wm_screen(C);
160  ScrArea *area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, event->x, event->y);
161  const ARegion *region = BKE_area_find_region_xy(area, RGN_TYPE_ANY, event->x, event->y);
162 
163  uiBut *but = ui_but_find_mouse_over(region, event);
164 
165  if (ELEM(NULL, but, but->rnapoin.data, but->rnaprop)) {
166  return NULL;
167  }
168  return but;
169 }
170 
struct bScreen * CTX_wm_screen(const bContext *C)
Definition: context.c:709
struct wmWindow * CTX_wm_window(const bContext *C)
Definition: context.c:699
struct ScrArea * BKE_screen_find_area_xy(struct bScreen *screen, const int spacetype, int x, int y)
Definition: screen.c:1018
struct ARegion * BKE_area_find_region_xy(struct ScrArea *area, const int regiontype, int x, int y)
Definition: screen.c:933
bool BLI_rcti_isect_pt(const struct rcti *rect, const int x, const int y)
#define ELEM(...)
#define RGN_TYPE_ANY
#define SPACE_TYPE_ANY
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
#define C
Definition: RandGen.cpp:39
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
unsigned int U
Definition: btGjkEpa3.h:78
wmKeyMap * eyedropper_modal_keymap(wmKeyConfig *keyconf)
static void eyedropper_draw_cursor_text_ex(const int x, const int y, const char *name)
uiBut * eyedropper_get_property_button_under_mouse(bContext *C, const wmEvent *event)
void eyedropper_draw_cursor_text_window(const struct wmWindow *window, const char *name)
void eyedropper_draw_cursor_text_region(const struct bContext *C, const ARegion *region, const char *name)
wmKeyMap * eyedropper_colorband_modal_keymap(wmKeyConfig *keyconf)
@ EYE_MODAL_POINT_CANCEL
@ EYE_MODAL_POINT_SAMPLE
@ EYE_MODAL_POINT_CONFIRM
@ EYE_MODAL_SAMPLE_BEGIN
@ EYE_MODAL_SAMPLE_RESET
@ EYE_MODAL_SAMPLE_CONFIRM
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:52
int ymin
Definition: DNA_vec_types.h:80
int xmin
Definition: DNA_vec_types.h:79
struct PropertyRNA * rnaprop
struct PointerRNA rnapoin
int y
Definition: WM_types.h:581
int x
Definition: WM_types.h:581
const void * modal_items
struct wmEvent * eventstate
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