Blender  V3.3
interface_icons_event.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
12 #include <math.h>
13 #include <stdlib.h>
14 #include <string.h>
15 
16 #include "MEM_guardedalloc.h"
17 
18 #include "GPU_batch.h"
19 #include "GPU_immediate.h"
20 #include "GPU_state.h"
21 
22 #include "BLI_blenlib.h"
23 #include "BLI_math_vector.h"
24 #include "BLI_utildefines.h"
25 
26 #include "DNA_brush_types.h"
27 #include "DNA_curve_types.h"
28 #include "DNA_dynamicpaint_types.h"
29 #include "DNA_object_types.h"
30 #include "DNA_screen_types.h"
31 #include "DNA_space_types.h"
32 #include "DNA_workspace_types.h"
33 
34 #include "RNA_access.h"
35 #include "RNA_enum_types.h"
36 
37 #include "BKE_appdir.h"
38 #include "BKE_icons.h"
39 #include "BKE_studiolight.h"
40 
41 #include "IMB_imbuf.h"
42 #include "IMB_imbuf_types.h"
43 #include "IMB_thumbs.h"
44 
45 #include "BLF_api.h"
46 
47 #include "DEG_depsgraph.h"
48 
49 #include "DRW_engine.h"
50 
51 #include "ED_datafiles.h"
52 #include "ED_keyframes_draw.h"
53 #include "ED_render.h"
54 
55 #include "UI_interface.h"
56 #include "UI_interface_icons.h"
57 
58 #include "WM_api.h"
59 #include "WM_types.h"
60 
61 #include "interface_intern.h"
62 
63 static void icon_draw_rect_input_text(const rctf *rect,
64  const float color[4],
65  const char *str,
66  float font_size)
67 {
69  const int font_id = BLF_default();
70  BLF_color4fv(font_id, color);
71  BLF_size(font_id, font_size * U.pixelsize, U.dpi);
72  float width, height;
74  const float x = rect->xmin + (((rect->xmax - rect->xmin) - width) / 2.0f);
75  const float y = rect->ymin + (((rect->ymax - rect->ymin) - height) / 2.0f);
76  BLF_position(font_id, x, y, 0.0f);
79 }
80 
81 static void icon_draw_rect_input_symbol(const rctf *rect, const float color[4], const char *str)
82 {
84  const int font_id = blf_mono_font;
85  BLF_color4fv(font_id, color);
86  BLF_size(font_id, 19.0f * U.pixelsize, U.dpi);
87  const float x = rect->xmin + (2.0f * U.pixelsize);
88  const float y = rect->ymin + (1.0f * U.pixelsize);
89  BLF_position(font_id, x, y, 0.0f);
92 }
93 
95  float y,
96  int w,
97  int h,
98  float UNUSED(alpha),
99  short event_type,
100  short UNUSED(event_value))
101 {
102  float color[4];
103  GPU_line_width(1.0f);
107  &(const rctf){
108  .xmin = (int)x - U.pixelsize,
109  .xmax = (int)(x + w),
110  .ymin = (int)y,
111  .ymax = (int)(y + h),
112  },
113  false,
114  3.0f * U.pixelsize,
115  color);
116 
117  const enum {
118  UNIX,
119  MACOS,
120  MSWIN,
121  } platform =
122 
123 #if defined(__APPLE__)
124  MACOS
125 #elif defined(_WIN32)
126  MSWIN
127 #else
128  UNIX
129 #endif
130  ;
131 
132  const rctf rect = {
133  .xmin = x,
134  .ymin = y,
135  .xmax = x + w,
136  .ymax = y + h,
137  };
138 
139  if ((event_type >= EVT_AKEY) && (event_type <= EVT_ZKEY)) {
140  const char str[2] = {'A' + (event_type - EVT_AKEY), '\0'};
141  icon_draw_rect_input_text(&rect, color, str, 13.0f);
142  }
143  else if ((event_type >= EVT_F1KEY) && (event_type <= EVT_F12KEY)) {
144  char str[4];
145  SNPRINTF(str, "F%d", 1 + (event_type - EVT_F1KEY));
146  icon_draw_rect_input_text(&rect, color, str, event_type > EVT_F9KEY ? 8.0f : 10.0f);
147  }
148  else if (event_type == EVT_LEFTSHIFTKEY) { /* Right Shift has already been converted to left. */
149  icon_draw_rect_input_symbol(&rect, color, (const char[]){0xe2, 0x87, 0xa7, 0x0});
150  }
151  else if (event_type == EVT_LEFTCTRLKEY) { /* Right Shift has already been converted to left. */
152  if (platform == MACOS) {
153  icon_draw_rect_input_symbol(&rect, color, (const char[]){0xe2, 0x8c, 0x83, 0x0});
154  }
155  else {
156  icon_draw_rect_input_text(&rect, color, "Ctrl", 9.0f);
157  }
158  }
159  else if (event_type == EVT_LEFTALTKEY) { /* Right Alt has already been converted to left. */
160  if (platform == MACOS) {
161  icon_draw_rect_input_symbol(&rect, color, (const char[]){0xe2, 0x8c, 0xa5, 0x0});
162  }
163  else {
164  icon_draw_rect_input_text(&rect, color, "Alt", 10.0f);
165  }
166  }
167  else if (event_type == EVT_OSKEY) {
168  if (platform == MACOS) {
169  icon_draw_rect_input_symbol(&rect, color, (const char[]){0xe2, 0x8c, 0x98, 0x0});
170  }
171  else if (platform == MSWIN) {
172  icon_draw_rect_input_symbol(&rect, color, (const char[]){0xe2, 0x9d, 0x96, 0x0});
173  }
174  else {
175  icon_draw_rect_input_text(&rect, color, "OS", 10.0f);
176  }
177  }
178  else if (event_type == EVT_DELKEY) {
179  icon_draw_rect_input_text(&rect, color, "Del", 9.0f);
180  }
181  else if (event_type == EVT_TABKEY) {
182  icon_draw_rect_input_symbol(&rect, color, (const char[]){0xe2, 0xad, 0xbe, 0x0});
183  }
184  else if (event_type == EVT_HOMEKEY) {
185  icon_draw_rect_input_text(&rect, color, "Home", 6.0f);
186  }
187  else if (event_type == EVT_ENDKEY) {
188  icon_draw_rect_input_text(&rect, color, "End", 8.0f);
189  }
190  else if (event_type == EVT_RETKEY) {
191  icon_draw_rect_input_symbol(&rect, color, (const char[]){0xe2, 0x8f, 0x8e, 0x0});
192  }
193  else if (event_type == EVT_ESCKEY) {
194  if (platform == MACOS) {
195  icon_draw_rect_input_symbol(&rect, color, (const char[]){0xe2, 0x8e, 0x8b, 0x0});
196  }
197  else {
198  icon_draw_rect_input_text(&rect, color, "Esc", 8.0f);
199  }
200  }
201  else if (event_type == EVT_PAGEUPKEY) {
202  icon_draw_rect_input_text(&rect, color, (const char[]){'P', 0xe2, 0x86, 0x91, 0x0}, 8.0f);
203  }
204  else if (event_type == EVT_PAGEDOWNKEY) {
205  icon_draw_rect_input_text(&rect, color, (const char[]){'P', 0xe2, 0x86, 0x93, 0x0}, 8.0f);
206  }
207  else if (event_type == EVT_LEFTARROWKEY) {
208  icon_draw_rect_input_symbol(&rect, color, (const char[]){0xe2, 0x86, 0x90, 0x0});
209  }
210  else if (event_type == EVT_UPARROWKEY) {
211  icon_draw_rect_input_symbol(&rect, color, (const char[]){0xe2, 0x86, 0x91, 0x0});
212  }
213  else if (event_type == EVT_RIGHTARROWKEY) {
214  icon_draw_rect_input_symbol(&rect, color, (const char[]){0xe2, 0x86, 0x92, 0x0});
215  }
216  else if (event_type == EVT_DOWNARROWKEY) {
217  icon_draw_rect_input_symbol(&rect, color, (const char[]){0xe2, 0x86, 0x93, 0x0});
218  }
219  else if (event_type == EVT_SPACEKEY) {
220  icon_draw_rect_input_symbol(&rect, color, (const char[]){0xe2, 0x90, 0xa3, 0x0});
221  }
222 }
int BLF_default(void)
Definition: blf_default.c:44
void BLF_width_and_height(int fontid, const char *str, size_t str_len, float *r_width, float *r_height) ATTR_NONNULL()
Definition: blf.c:662
void BLF_color4fv(int fontid, const float rgba[4])
Definition: blf.c:437
void BLF_batch_draw_flush(void)
Definition: blf.c:472
#define BLF_DRAW_STR_DUMMY_MAX
Definition: BLF_api.h:356
void BLF_draw(int fontid, const char *str, size_t str_len) ATTR_NONNULL(2)
Definition: blf.c:538
int blf_mono_font
Definition: blf.c:48
void BLF_size(int fontid, float size, int dpi)
Definition: blf.c:363
void BLF_position(int fontid, float x, float y, float z)
Definition: blf.c:308
#define SNPRINTF(dst, format,...)
Definition: BLI_string.h:485
#define UNUSED(x)
Object is a sort of wrapper for general info.
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_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
_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 GLsizei width
void GPU_line_width(float width)
Definition: gpu_state.cc:158
Contains defines and structs used throughout the imbuf module.
Read Guarded memory(de)allocation.
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert a color
void UI_draw_roundbox_corner_set(int type)
void UI_draw_roundbox_aa(const struct rctf *rect, bool filled, float rad, const float color[4])
@ UI_CNR_ALL
@ TH_TEXT
Definition: UI_resources.h:42
void UI_GetThemeColor4fv(int colorid, float col[4])
Definition: resources.c:1173
unsigned int U
Definition: btGjkEpa3.h:78
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119
#define str(s)
static void icon_draw_rect_input_text(const rctf *rect, const float color[4], const char *str, float font_size)
static void icon_draw_rect_input_symbol(const rctf *rect, const float color[4], const char *str)
void icon_draw_rect_input(float x, float y, int w, int h, float UNUSED(alpha), short event_type, short UNUSED(event_value))
float xmax
Definition: DNA_vec_types.h:69
float xmin
Definition: DNA_vec_types.h:69
float ymax
Definition: DNA_vec_types.h:70
float ymin
Definition: DNA_vec_types.h:70
@ EVT_F1KEY
@ EVT_DELKEY
@ EVT_TABKEY
@ EVT_DOWNARROWKEY
@ EVT_AKEY
@ EVT_PAGEUPKEY
@ EVT_OSKEY
@ EVT_PAGEDOWNKEY
@ EVT_LEFTCTRLKEY
@ EVT_RIGHTARROWKEY
@ EVT_SPACEKEY
@ EVT_HOMEKEY
@ EVT_ENDKEY
@ EVT_UPARROWKEY
@ EVT_LEFTARROWKEY
@ EVT_LEFTALTKEY
@ EVT_ZKEY
@ EVT_ESCKEY
@ EVT_F12KEY
@ EVT_LEFTSHIFTKEY
@ EVT_F9KEY
@ EVT_RETKEY