Blender  V2.93
interface_icons_event.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 
26 #include <math.h>
27 #include <stdlib.h>
28 #include <string.h>
29 
30 #include "MEM_guardedalloc.h"
31 
32 #include "GPU_batch.h"
33 #include "GPU_immediate.h"
34 #include "GPU_state.h"
35 
36 #include "BLI_blenlib.h"
37 #include "BLI_math_vector.h"
38 #include "BLI_utildefines.h"
39 
40 #include "DNA_brush_types.h"
41 #include "DNA_curve_types.h"
42 #include "DNA_dynamicpaint_types.h"
43 #include "DNA_object_types.h"
44 #include "DNA_screen_types.h"
45 #include "DNA_space_types.h"
46 #include "DNA_workspace_types.h"
47 
48 #include "RNA_access.h"
49 #include "RNA_enum_types.h"
50 
51 #include "BKE_appdir.h"
52 #include "BKE_icons.h"
53 #include "BKE_studiolight.h"
54 
55 #include "IMB_imbuf.h"
56 #include "IMB_imbuf_types.h"
57 #include "IMB_thumbs.h"
58 
59 #include "BLF_api.h"
60 
61 #include "DEG_depsgraph.h"
62 
63 #include "DRW_engine.h"
64 
65 #include "ED_datafiles.h"
66 #include "ED_keyframes_draw.h"
67 #include "ED_render.h"
68 
69 #include "UI_interface.h"
70 #include "UI_interface_icons.h"
71 
72 #include "WM_api.h"
73 #include "WM_types.h"
74 
75 #include "interface_intern.h"
76 
77 static void icon_draw_rect_input_text(const rctf *rect,
78  const float color[4],
79  const char *str,
80  int font_size)
81 {
83  const int font_id = BLF_default();
84  BLF_color4fv(font_id, color);
85  BLF_size(font_id, font_size * U.pixelsize, U.dpi);
86  float width, height;
88  const float x = rect->xmin + (((rect->xmax - rect->xmin) - width) / 2.0f);
89  const float y = rect->ymin + (((rect->ymax - rect->ymin) - height) / 2.0f);
90  BLF_position(font_id, x, y, 0.0f);
93 }
94 
95 static void icon_draw_rect_input_symbol(const rctf *rect, const float color[4], const char *str)
96 {
98  const int font_id = blf_mono_font;
99  BLF_color4fv(font_id, color);
100  BLF_size(font_id, 19 * U.pixelsize, U.dpi);
101  const float x = rect->xmin + (2.0f * U.pixelsize);
102  const float y = rect->ymin + (1.0f * U.pixelsize);
103  BLF_position(font_id, x, y, 0.0f);
106 }
107 
109  float y,
110  int w,
111  int h,
112  float UNUSED(alpha),
113  short event_type,
114  short UNUSED(event_value))
115 {
116  float color[4];
117  GPU_line_width(1.0f);
121  &(const rctf){
122  .xmin = (int)x - U.pixelsize,
123  .xmax = (int)(x + w),
124  .ymin = (int)y,
125  .ymax = (int)(y + h),
126  },
127  false,
128  3.0f * U.pixelsize,
129  color);
130 
131  const enum {
132  UNIX,
133  MACOS,
134  MSWIN,
135  } platform =
136 
137 #if defined(__APPLE__)
138  MACOS
139 #elif defined(_WIN32)
140  MSWIN
141 #else
142  UNIX
143 #endif
144  ;
145 
146  const rctf rect = {
147  .xmin = x,
148  .ymin = y,
149  .xmax = x + w,
150  .ymax = y + h,
151  };
152 
153  if ((event_type >= EVT_AKEY) && (event_type <= EVT_ZKEY)) {
154  const char str[2] = {'A' + (event_type - EVT_AKEY), '\0'};
155  icon_draw_rect_input_text(&rect, color, str, 13);
156  }
157  else if ((event_type >= EVT_F1KEY) && (event_type <= EVT_F12KEY)) {
158  char str[4];
159  SNPRINTF(str, "F%d", 1 + (event_type - EVT_F1KEY));
160  icon_draw_rect_input_text(&rect, color, str, event_type > EVT_F9KEY ? 8 : 10);
161  }
162  else if (event_type == EVT_LEFTSHIFTKEY) {
163  icon_draw_rect_input_symbol(&rect, color, (const char[]){0xe2, 0x87, 0xa7, 0x0});
164  }
165  else if (event_type == EVT_LEFTCTRLKEY) {
166  if (platform == MACOS) {
167  icon_draw_rect_input_symbol(&rect, color, (const char[]){0xe2, 0x8c, 0x83, 0x0});
168  }
169  else {
170  icon_draw_rect_input_text(&rect, color, "Ctrl", 9);
171  }
172  }
173  else if (event_type == EVT_LEFTALTKEY) {
174  if (platform == MACOS) {
175  icon_draw_rect_input_symbol(&rect, color, (const char[]){0xe2, 0x8c, 0xa5, 0x0});
176  }
177  else {
178  icon_draw_rect_input_text(&rect, color, "Alt", 10);
179  }
180  }
181  else if (event_type == EVT_OSKEY) {
182  if (platform == MACOS) {
183  icon_draw_rect_input_symbol(&rect, color, (const char[]){0xe2, 0x8c, 0x98, 0x0});
184  }
185  else if (platform == MSWIN) {
186  icon_draw_rect_input_symbol(&rect, color, (const char[]){0xe2, 0x9d, 0x96, 0x0});
187  }
188  else {
189  icon_draw_rect_input_text(&rect, color, "OS", 10);
190  }
191  }
192  else if (event_type == EVT_DELKEY) {
193  icon_draw_rect_input_text(&rect, color, "Del", 9);
194  }
195  else if (event_type == EVT_TABKEY) {
196  icon_draw_rect_input_symbol(&rect, color, (const char[]){0xe2, 0xad, 0xbe, 0x0});
197  }
198  else if (event_type == EVT_HOMEKEY) {
199  icon_draw_rect_input_text(&rect, color, "Home", 6);
200  }
201  else if (event_type == EVT_ENDKEY) {
202  icon_draw_rect_input_text(&rect, color, "End", 8);
203  }
204  else if (event_type == EVT_RETKEY) {
205  icon_draw_rect_input_symbol(&rect, color, (const char[]){0xe2, 0x8f, 0x8e, 0x0});
206  }
207  else if (event_type == EVT_ESCKEY) {
208  if (platform == MACOS) {
209  icon_draw_rect_input_symbol(&rect, color, (const char[]){0xe2, 0x8e, 0x8b, 0x0});
210  }
211  else {
212  icon_draw_rect_input_text(&rect, color, "Esc", 8);
213  }
214  }
215  else if (event_type == EVT_PAGEUPKEY) {
216  icon_draw_rect_input_text(&rect, color, (const char[]){'P', 0xe2, 0x86, 0x91, 0x0}, 8);
217  }
218  else if (event_type == EVT_PAGEDOWNKEY) {
219  icon_draw_rect_input_text(&rect, color, (const char[]){'P', 0xe2, 0x86, 0x93, 0x0}, 8);
220  }
221  else if (event_type == EVT_LEFTARROWKEY) {
222  icon_draw_rect_input_symbol(&rect, color, (const char[]){0xe2, 0x86, 0x90, 0x0});
223  }
224  else if (event_type == EVT_UPARROWKEY) {
225  icon_draw_rect_input_symbol(&rect, color, (const char[]){0xe2, 0x86, 0x91, 0x0});
226  }
227  else if (event_type == EVT_RIGHTARROWKEY) {
228  icon_draw_rect_input_symbol(&rect, color, (const char[]){0xe2, 0x86, 0x92, 0x0});
229  }
230  else if (event_type == EVT_DOWNARROWKEY) {
231  icon_draw_rect_input_symbol(&rect, color, (const char[]){0xe2, 0x86, 0x93, 0x0});
232  }
233  else if (event_type == EVT_SPACEKEY) {
234  icon_draw_rect_input_symbol(&rect, color, (const char[]){0xe2, 0x90, 0xa3, 0x0});
235  }
236 }
int BLF_default(void)
Definition: blf_default.c:55
void BLF_color4fv(int fontid, const float rgba[4])
Definition: blf.c:441
void BLF_width_and_height(int fontid, const char *str, size_t len, float *r_width, float *r_height) ATTR_NONNULL()
Definition: blf.c:698
void BLF_batch_draw_flush(void)
Definition: blf.c:476
void BLF_draw(int fontid, const char *str, size_t len) ATTR_NONNULL(2)
Definition: blf.c:542
#define BLF_DRAW_STR_DUMMY_MAX
Definition: BLF_api.h:283
int blf_mono_font
Definition: blf.c:70
void BLF_size(int fontid, int size, int dpi)
Definition: blf.c:367
void BLF_position(int fontid, float x, float y, float z)
Definition: blf.c:312
#define SNPRINTF(dst, format,...)
Definition: BLI_string.h:165
#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 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
_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
void GPU_line_width(float width)
Definition: gpu_state.cc:173
Contains defines and structs used throughout the imbuf module.
Read Guarded memory(de)allocation.
@ UI_CNR_ALL
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])
@ TH_TEXT
Definition: UI_resources.h:58
void UI_GetThemeColor4fv(int colorid, float col[4])
Definition: resources.c:1199
unsigned int U
Definition: btGjkEpa3.h:78
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119
static CCL_NAMESPACE_BEGIN const double alpha
#define str(s)
static void icon_draw_rect_input_symbol(const rctf *rect, const float color[4], const char *str)
static void icon_draw_rect_input_text(const rctf *rect, const float color[4], const char *str, int font_size)
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:85
float xmin
Definition: DNA_vec_types.h:85
float ymax
Definition: DNA_vec_types.h:86
float ymin
Definition: DNA_vec_types.h:86
@ 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