Blender V5.3
wm_cursors.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2005-2007 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
20
21#include <cstring>
22
23#include "GHOST_IWindow.hh"
24#include "GHOST_Types.hh"
25
26#include "BLI_string_utf8.hh"
27#include "BLI_utildefines.hh"
28
29#include "DNA_listBase.h"
30#include "DNA_userdef_types.h"
31#include "DNA_workspace_types.h"
32
33#include "BKE_global.hh"
34#include "BKE_main.hh"
35
36#include "BLF_api.hh"
37
38#ifndef WITH_HEADLESS
39# include "nanosvgrast.h"
40# include "svg_cursors.h"
41#endif
42
43#include "WM_api.hh"
44#include "WM_types.hh"
45#include "wm_cursors.hh"
46#include "wm_window.hh"
47
48namespace blender {
49
56constexpr int CURSOR_HARDWARE_SIZE_MAX = 255;
57
62#define CURSOR_TEXT_BUFFER_SIZE 24
63
65struct BCursor {
70 const char *svg_source;
79};
80
84static BCursor g_cursors[WM_CURSOR_NUM] = {{nullptr}};
85
88{
89 switch (curs) {
92 case WM_CURSOR_WAIT:
94 case WM_CURSOR_EDIT:
95 case WM_CURSOR_CROSS:
97 case WM_CURSOR_MOVE:
101 case WM_CURSOR_Y_MOVE:
103 case WM_CURSOR_COPY:
105 case WM_CURSOR_HAND:
115 case WM_CURSOR_STOP:
117 case WM_CURSOR_KNIFE:
131 case WM_CURSOR_PAINT:
133 case WM_CURSOR_DOT:
135 case WM_CURSOR_CROSSC:
137 case WM_CURSOR_ERASER:
157 case WM_CURSOR_BLADE:
159 case WM_CURSOR_SLIP:
161 default:
163 }
164}
165
169static int wm_cursor_size(const wmWindow *win)
170{
171 /* Keep for testing. */
172 if (false) {
173 /* Scaling with UI scale can be useful for magnified captures. */
174 return std::lround(21.0f * UI_SCALE_FAC);
175 }
176
177 /* The DPI as a scale without the UI scale preference. */
178 const float system_scale = WM_window_dpi_get_scale(win);
179
180 return std::lround(WM_cursor_preferred_logical_size(true) * system_scale);
181}
182
186static void cursor_bitmap_rgba_flip_y(uint8_t *buffer, const size_t size[2])
187{
188 uint *top, *bottom, *line;
189 const size_t x_size = size[0];
190 size_t y_size = size[1];
191 const size_t stride = x_size * sizeof(int);
192
193 top = reinterpret_cast<uint *>(buffer);
194 bottom = top + ((y_size - 1) * x_size);
195 line = MEM_new_array_uninitialized<uint>(x_size, "linebuf");
196
197 y_size >>= 1;
198 for (; y_size > 0; y_size--) {
199 memcpy(line, top, stride);
200 memcpy(top, bottom, stride);
201 memcpy(bottom, line, stride);
202 bottom -= x_size;
203 top += x_size;
204 }
205
206 MEM_delete(line);
207}
208
217static uint8_t *cursor_bitmap_from_svg(const char *svg,
218 const int cursor_size,
219 uint8_t *(*alloc_fn)(size_t size),
220 int r_bitmap_size[2])
221{
222#ifdef WITH_HEADLESS
223 UNUSED_VARS(svg, cursor_size, alloc_fn, r_bitmap_size);
224 return nullptr;
225#else
226 /* #nsvgParse alters the source string. */
227 std::string svg_source = svg;
228
229 NSVGimage *image = nsvgParse(svg_source.data(), "px", 96.0f);
230 if (image == nullptr) {
231 return nullptr;
232 }
233 if (image->width == 0 || image->height == 0) {
234 nsvgDelete(image);
235 return nullptr;
236 }
237 NSVGrasterizer *rast = nsvgCreateRasterizer();
238 if (rast == nullptr) {
239 nsvgDelete(image);
240 return nullptr;
241 }
242
243 const float scale = float(cursor_size) / 1600.0f;
244 const size_t dest_size[2] = {
245 std::min(size_t(ceil(image->width * scale)), size_t(cursor_size)),
246 std::min(size_t(ceil(image->height * scale)), size_t(cursor_size)),
247 };
248
249 uint8_t *bitmap_rgba = alloc_fn(sizeof(uint8_t[4]) * dest_size[0] * dest_size[1]);
250 if (bitmap_rgba == nullptr) {
251 return nullptr;
252 }
253
254 nsvgRasterize(
255 rast, image, 0.0f, 0.0f, scale, bitmap_rgba, dest_size[0], dest_size[1], dest_size[0] * 4);
256
257 nsvgDeleteRasterizer(rast);
258 nsvgDelete(image);
259
260 r_bitmap_size[0] = dest_size[0];
261 r_bitmap_size[1] = dest_size[1];
262
263 return bitmap_rgba;
264#endif /* !WITH_HEADLESS */
265}
266
270static void cursor_rgba_to_xbm_32(const uint8_t *rgba,
271 const int bitmap_size[2],
272 uint8_t *bitmap,
273 uint8_t *mask)
274{
275 for (int y = 0; y < bitmap_size[1]; y++) {
276 for (int x = 0; x < bitmap_size[0]; x++) {
277 int i = (y * bitmap_size[0] * 4) + (x * 4);
278 int j = (y * 4) + (x >> 3);
279 int k = (x % 8);
280 if (rgba[i + 3] > 128) {
281 if (rgba[i] > 128) {
282 bitmap[j] |= (1 << k);
283 }
284 mask[j] |= (1 << k);
285 }
286 }
287 }
288}
289
291{
293 cursor_generator->generate_fn = [](const GHOST_CursorGenerator *cursor_generator,
294 const int cursor_size,
295 const int cursor_size_max,
296 uint8_t *(*alloc_fn)(size_t size),
297 int r_bitmap_size[2],
298 int r_hot_spot[2],
299 bool *r_can_invert_color) -> uint8_t * {
300 const BCursor &cursor = *static_cast<const BCursor *>(cursor_generator->user_data);
301 /* Currently SVG uses the `cursor_size` as the maximum. */
302 UNUSED_VARS(cursor_size_max);
303
304 int bitmap_size[2];
305 uint8_t *bitmap_rgba = cursor_bitmap_from_svg(
306 cursor.svg_source, cursor_size, alloc_fn, bitmap_size);
307
308 if (bitmap_rgba == nullptr) [[unlikely]] {
309 return nullptr;
310 }
311
312 r_bitmap_size[0] = bitmap_size[0];
313 r_bitmap_size[1] = bitmap_size[1];
314
315 r_hot_spot[0] = int(cursor.hotspot[0] * (bitmap_size[0] - 1));
316 r_hot_spot[1] = int(cursor.hotspot[1] * (bitmap_size[1] - 1));
317
318 *r_can_invert_color = cursor.can_invert;
319
320 return bitmap_rgba;
321 };
322
323 cursor_generator->user_data = const_cast<void *>(static_cast<const void *>(&cursor));
324 cursor_generator->free_fn = [](GHOST_CursorGenerator *cursor_generator) {
325 MEM_delete(cursor_generator);
326 };
327
328 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
329 GHOST_TSuccess success = ghost_window->setCustomCursorGenerator(cursor_generator);
330
331 return (success == GHOST_kSuccess) ? true : false;
332}
333
334static bool window_set_custom_cursor_pixmap(wmWindow *win, const BCursor &cursor)
335{
336 /* Option to force use of 1bpp XBitMap cursors is needed for testing. */
337 const bool use_only_1bpp_cursors = false;
338
339 const bool use_rgba = !use_only_1bpp_cursors &&
341
342 const int max_size = use_rgba ? CURSOR_HARDWARE_SIZE_MAX : 32;
343 const int size = std::min(wm_cursor_size(win), max_size);
344
345 int bitmap_size[2] = {0, 0};
346 uint8_t *bitmap_rgba = cursor_bitmap_from_svg(
347 cursor.svg_source,
348 size,
349 [](size_t size) -> uint8_t * {
350 return MEM_new_array_uninitialized<uint8_t>(size, "wm.cursor");
351 },
352 bitmap_size);
353 if (bitmap_rgba == nullptr) [[unlikely]] {
354 return false;
355 }
356
357 const int hot_spot[2] = {
358 int(cursor.hotspot[0] * (bitmap_size[0] - 1)),
359 int(cursor.hotspot[1] * (bitmap_size[1] - 1)),
360 };
361
362 GHOST_TSuccess success;
363
364 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
365 if (use_rgba) {
366 success = ghost_window->setCustomCursorShape(
367 bitmap_rgba, nullptr, bitmap_size, hot_spot, cursor.can_invert);
368 }
369 else {
370 int bitmap_size_fixed[2] = {32, 32};
371
372 uint8_t bitmap[4 * 32] = {0};
373 uint8_t mask[4 * 32] = {0};
374 cursor_rgba_to_xbm_32(bitmap_rgba, bitmap_size, bitmap, mask);
375 success = ghost_window->setCustomCursorShape(
376 bitmap, mask, bitmap_size_fixed, hot_spot, cursor.can_invert);
377 }
378
379 MEM_delete(bitmap_rgba);
380 return (success == GHOST_kSuccess) ? true : false;
381}
382
383static bool window_set_custom_cursor(wmWindow *win, const BCursor &cursor)
384{
386 return window_set_custom_cursor_generator(win, cursor);
387 }
388 return window_set_custom_cursor_pixmap(win, cursor);
389}
390
391void WM_cursor_set(wmWindow *win, int curs)
392{
393 /* Option to not use any OS-supplied cursors is needed for testing. */
394 const bool use_only_custom_cursors = false;
395
396 if (G.background) {
397 return;
398 }
399
400 if (win == nullptr) {
401 /* Can't set custom cursor before window initialization. */
402 return;
403 }
404
405 if (curs == WM_CURSOR_DEFAULT && win->modalcursor) {
406 /* If the cursor was set to default during the modal operation,
407 * this usually indicates that win->lastcursor is not relevant anymore.
408 * So update lastcursor to the default cursor as this is usually a safe
409 * cursor shape to fall back to (see #144345).
410 */
411 win->lastcursor = curs;
412 curs = win->modalcursor;
413 }
414
415 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
416
417 if (curs == WM_CURSOR_NONE) {
418 ghost_window->setCursorVisibility(false);
419 return;
420 }
421
422 ghost_window->setCursorVisibility(true);
423
424 if (win->cursor == curs) {
425 return; /* Cursor is already set. */
426 }
427
428 win->cursor = curs;
429
430 if (curs < 0 || curs >= WM_CURSOR_NUM) {
431 BLI_assert_msg(0, "Invalid cursor number");
432 return;
433 }
434
436
437 if (!use_only_custom_cursors && ghost_cursor != GHOST_kStandardCursorCustom &&
438 ghost_window->hasCursorShape(ghost_cursor))
439 {
440 /* Use native GHOST cursor when available. */
441 ghost_window->setCursorShape(ghost_cursor);
442 }
443 else {
444 const BCursor &bcursor = g_cursors[curs];
445 if (!bcursor.svg_source || !window_set_custom_cursor(win, bcursor)) {
446 /* Fall back to default cursor if no bitmap found. */
448 }
449 }
450}
451
452bool WM_cursor_set_from_tool(wmWindow *win, const ScrArea *area, const ARegion *region)
453{
454 if (region && !ELEM(region->regiontype, RGN_TYPE_WINDOW, RGN_TYPE_PREVIEW)) {
455 return false;
456 }
457
458 bToolRef_Runtime *tref_rt = (area && area->runtime.tool) ? area->runtime.tool->runtime : nullptr;
459 if (tref_rt && tref_rt->cursor != WM_CURSOR_DEFAULT) {
460 if (win->modalcursor == 0) {
461 WM_cursor_set(win, tref_rt->cursor);
462 win->cursor = tref_rt->cursor;
463 return true;
464 }
465 }
466 return false;
467}
468
470{
471 return (win->grabcursor == 0 && win->modalcursor == 0);
472}
473
474void WM_cursor_modal_set(wmWindow *win, int val)
475{
476 if (win->lastcursor == 0) {
477 win->lastcursor = win->cursor;
478 }
479 win->modalcursor = val;
480 WM_cursor_set(win, val);
481}
482
484{
485 win->modalcursor = 0;
486 if (win->lastcursor) {
487 WM_cursor_set(win, win->lastcursor);
488 }
489 win->lastcursor = 0;
490}
491
492void WM_cursor_wait(bool val)
493{
494 if (!G.background) {
495 wmWindowManager *wm = G_MAIN->wm.first();
496 wmWindow *win = wm ? wm->windows.first() : nullptr;
497
498 for (; win; win = win->next) {
499 if (val) {
501 }
502 else {
504 }
505 }
506 }
507}
508
511 const rcti *wrap_region,
512 const bool hide)
513{
514 int _wrap_region_buf[4];
515 int *wrap_region_screen = nullptr;
516
517 /* Only grab cursor when not running debug.
518 * It helps not to get a stuck WM when hitting a break-point. */
521
522 if (wrap_region) {
523 wrap_region_screen = _wrap_region_buf;
524 wrap_region_screen[0] = wrap_region->xmin;
525 wrap_region_screen[1] = wrap_region->ymax;
526 wrap_region_screen[2] = wrap_region->xmax;
527 wrap_region_screen[3] = wrap_region->ymin;
528 wm_cursor_position_to_ghost_screen_coords(win, &wrap_region_screen[0], &wrap_region_screen[1]);
529 wm_cursor_position_to_ghost_screen_coords(win, &wrap_region_screen[2], &wrap_region_screen[3]);
530 }
531
532 if (hide) {
533 mode = GHOST_kGrabHide;
534 }
535 else if (wrap != WM_CURSOR_WRAP_NONE) {
536 mode = GHOST_kGrabWrap;
537
538 if (wrap == WM_CURSOR_WRAP_X) {
539 mode_axis = GHOST_kAxisX;
540 }
541 else if (wrap == WM_CURSOR_WRAP_Y) {
542 mode_axis = GHOST_kAxisY;
543 }
544 }
545
546 if ((G.debug & G_DEBUG) == 0) {
547 if (win->runtime->ghostwin) {
548 if (win->runtime->eventstate->tablet.is_motion_absolute == false) {
549 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
550 if (wrap_region_screen) {
551 GHOST_Rect wrap_region_screen_rect(wrap_region_screen[0],
552 wrap_region_screen[1],
553 wrap_region_screen[2],
554 wrap_region_screen[3]);
555 ghost_window->setCursorGrab(mode, mode_axis, &wrap_region_screen_rect, nullptr);
556 }
557 else {
558 ghost_window->setCursorGrab(mode, mode_axis, nullptr, nullptr);
559 }
560 }
561
562 win->grabcursor = mode;
563 }
564 }
565}
566
567void WM_cursor_grab_disable(wmWindow *win, const int mouse_ungrab_xy[2])
568{
569 if ((G.debug & G_DEBUG) == 0) {
570 if (win && win->runtime->ghostwin) {
571 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
572
573 if (mouse_ungrab_xy) {
574 int32_t mouse_xy[2] = {mouse_ungrab_xy[0], mouse_ungrab_xy[1]};
575 wm_cursor_position_to_ghost_screen_coords(win, &mouse_xy[0], &mouse_xy[1]);
576 ghost_window->setCursorGrab(GHOST_kGrabDisable, GHOST_kAxisNone, nullptr, mouse_xy);
577 }
578 else {
579 ghost_window->setCursorGrab(GHOST_kGrabDisable, GHOST_kAxisNone, nullptr, nullptr);
580 }
581
583 }
584 }
585}
586
587static void wm_cursor_warp_relative(wmWindow *win, int x, int y)
588{
589 /* NOTE: don't use #wmEvent coords because of continuous grab, see: #36409. */
590 int cx, cy;
591 if (wm_cursor_position_get(win, &cx, &cy)) {
592 WM_cursor_warp(win, cx + x, cy + y);
593 }
594}
595
596bool wm_cursor_arrow_move(wmWindow *win, const wmEvent *event)
597{
598 /* TODO: give it a modal keymap? Hard coded for now. */
599
600 if (win && event->val == KM_PRESS) {
601 /* Must move at least this much to avoid rounding in WM_cursor_warp. */
602 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
603 const float fac = ghost_window->getNativePixelSize();
604
605 if (event->type == EVT_UPARROWKEY) {
606 wm_cursor_warp_relative(win, 0, fac);
607 return true;
608 }
609 if (event->type == EVT_DOWNARROWKEY) {
610 wm_cursor_warp_relative(win, 0, -fac);
611 return true;
612 }
613 if (event->type == EVT_LEFTARROWKEY) {
614 wm_cursor_warp_relative(win, -fac, 0);
615 return true;
616 }
617 if (event->type == EVT_RIGHTARROWKEY) {
618 wm_cursor_warp_relative(win, fac, 0);
619 return true;
620 }
621 }
622 return false;
623}
624
626{
627 /* 10 16x16 digits. */
628 const uchar number_bitmaps[][32] = {
629 {0x00, 0x00, 0xf0, 0x0f, 0xf8, 0x1f, 0x1c, 0x38, 0x0c, 0x30, 0x0c,
630 0x30, 0x0c, 0x30, 0x0c, 0x30, 0x0c, 0x30, 0x0c, 0x30, 0x0c, 0x30,
631 0x0c, 0x30, 0x1c, 0x38, 0xf8, 0x1f, 0xf0, 0x0f, 0x00, 0x00},
632 {0x00, 0x00, 0x80, 0x01, 0xc0, 0x01, 0xf0, 0x01, 0xbc, 0x01, 0x8c,
633 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01,
634 0x80, 0x01, 0x80, 0x01, 0xfc, 0x3f, 0xfc, 0x3f, 0x00, 0x00},
635 {0x00, 0x00, 0xf0, 0x1f, 0xf8, 0x3f, 0x1c, 0x30, 0x0c, 0x30, 0x00,
636 0x30, 0x00, 0x30, 0xe0, 0x3f, 0xf0, 0x1f, 0x38, 0x00, 0x1c, 0x00,
637 0x0c, 0x00, 0x0c, 0x00, 0xfc, 0x3f, 0xfc, 0x3f, 0x00, 0x00},
638 {0x00, 0x00, 0xf0, 0x0f, 0xf8, 0x1f, 0x1c, 0x38, 0x00, 0x30, 0x00,
639 0x30, 0x00, 0x38, 0xf0, 0x1f, 0xf0, 0x1f, 0x00, 0x38, 0x00, 0x30,
640 0x00, 0x30, 0x1c, 0x38, 0xf8, 0x1f, 0xf0, 0x0f, 0x00, 0x00},
641 {0x00, 0x00, 0x00, 0x0f, 0x80, 0x0f, 0xc0, 0x0d, 0xe0, 0x0c, 0x70,
642 0x0c, 0x38, 0x0c, 0x1c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
643 0xfc, 0x3f, 0xfc, 0x3f, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x00},
644 {0x00, 0x00, 0xfc, 0x3f, 0xfc, 0x3f, 0x0c, 0x00, 0x0c, 0x00, 0x0c,
645 0x00, 0xfc, 0x0f, 0xfc, 0x1f, 0x00, 0x38, 0x00, 0x30, 0x00, 0x30,
646 0x00, 0x30, 0x0c, 0x38, 0xfc, 0x1f, 0xf8, 0x0f, 0x00, 0x00},
647 {0x00, 0x00, 0xc0, 0x3f, 0xe0, 0x3f, 0x70, 0x00, 0x38, 0x00, 0x1c,
648 0x00, 0xfc, 0x0f, 0xfc, 0x1f, 0x0c, 0x38, 0x0c, 0x30, 0x0c, 0x30,
649 0x0c, 0x30, 0x1c, 0x38, 0xf8, 0x1f, 0xf0, 0x0f, 0x00, 0x00},
650 {0x00, 0x00, 0xfc, 0x3f, 0xfc, 0x3f, 0x0c, 0x30, 0x0c, 0x38, 0x00,
651 0x18, 0x00, 0x1c, 0x00, 0x0c, 0x00, 0x0e, 0x00, 0x06, 0x00, 0x07,
652 0x00, 0x03, 0x80, 0x03, 0x80, 0x01, 0x80, 0x01, 0x00, 0x00},
653 {0x00, 0x00, 0xf0, 0x0f, 0xf8, 0x1f, 0x1c, 0x38, 0x0c, 0x30, 0x0c,
654 0x30, 0x1c, 0x38, 0xf8, 0x1f, 0xf8, 0x1f, 0x1c, 0x38, 0x0c, 0x30,
655 0x0c, 0x30, 0x1c, 0x38, 0xf8, 0x1f, 0xf0, 0x0f, 0x00, 0x00},
656 {0x00, 0x00, 0xf0, 0x0f, 0xf8, 0x1f, 0x1c, 0x38, 0x0c, 0x30, 0x0c,
657 0x30, 0x0c, 0x30, 0x1c, 0x30, 0xf8, 0x3f, 0xf0, 0x3f, 0x00, 0x38,
658 0x00, 0x1c, 0x00, 0x0e, 0xfc, 0x07, 0xfc, 0x03, 0x00, 0x00},
659 };
660 uint8_t mask[32][4] = {{0}};
661 uint8_t bitmap[32][4] = {{0}};
662
663 /* Print number bottom right justified. */
664 for (int idx = 3; nr && idx >= 0; idx--) {
665 const uchar *digit = number_bitmaps[nr % 10];
666 int x = idx % 2;
667 int y = idx / 2;
668
669 for (int i = 0; i < 16; i++) {
670 bitmap[i + y * 16][x * 2] = digit[i * 2];
671 bitmap[i + y * 16][(x * 2) + 1] = digit[(i * 2) + 1];
672 }
673 for (int i = 0; i < 16; i++) {
674 mask[i + y * 16][x * 2] = 0xFF;
675 mask[i + y * 16][(x * 2) + 1] = 0xFF;
676 }
677
678 nr /= 10;
679 }
680
681 const int size[2] = {32, 32};
682 const int hot_spot[2] = {15, 15};
683
684 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
685 return ghost_window->setCustomCursorShape(bitmap[0], mask[0], size, hot_spot, false) ==
687}
688
690{
691 /* 10 8x8 digits. */
692 const char number_bitmaps[10][8] = {
693 {0, 56, 68, 68, 68, 68, 68, 56},
694 {0, 24, 16, 16, 16, 16, 16, 56},
695 {0, 60, 66, 32, 16, 8, 4, 126},
696 {0, 124, 32, 16, 56, 64, 66, 60},
697 {0, 32, 48, 40, 36, 126, 32, 32},
698 {0, 124, 4, 60, 64, 64, 68, 56},
699 {0, 56, 4, 4, 60, 68, 68, 56},
700 {0, 124, 64, 32, 16, 8, 8, 8},
701 {0, 60, 66, 66, 60, 66, 66, 60},
702 {0, 56, 68, 68, 120, 64, 68, 56},
703 };
704 uint8_t mask[16][2] = {{0}};
705 uint8_t bitmap[16][2] = {{0}};
706
707 /* Print number bottom right justified. */
708 for (int idx = 3; nr && idx >= 0; idx--) {
709 const char *digit = number_bitmaps[nr % 10];
710 int x = idx % 2;
711 int y = idx / 2;
712
713 for (int i = 0; i < 8; i++) {
714 bitmap[i + y * 8][x] = digit[i];
715 }
716 for (int i = 0; i < 8; i++) {
717 mask[i + y * 8][x] = 0xFF;
718 }
719 nr /= 10;
720 }
721
722 const int size[2] = {16, 16};
723 const int hot_spot[2] = {7, 7};
724 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
725 ghost_window->setCustomCursorShape(reinterpret_cast<uint8_t *>(bitmap),
726 reinterpret_cast<uint8_t *>(mask),
727 size,
728 hot_spot,
729 false);
730}
731
740static uint8_t *cursor_bitmap_from_text(const char *text,
741 const int cursor_size,
742 const int cursor_size_max,
743 int font_id,
744 uint8_t *(*alloc_fn)(size_t size),
745 int r_bitmap_size[2])
746{
747 /* Smaller than a full cursor size since this is typically wider.
748 * Also, use a small scale to avoid scaling single numbers up
749 * which are then shrunk when more digits are added since this seems strange. */
750 int font_size = (cursor_size * 3) / 4;
751 int font_dims[2];
752 int font_padding;
753
754 int font_descender;
755
756 /* At least 1 even on an empty string else the cursor is blank. */
757 const size_t text_len = strlen(text);
758 const int text_units = std::max(1, BLI_str_utf8_column_count(text, text_len));
759 const bool text_to_draw = text_len != 0;
760
761 for (int pass = 0; pass < 2; pass++) {
762 BLF_size(font_id, font_size);
763
764 /* Use fixed sizes instead of calculating the bounds of the text
765 * because the text can jitter based on differences in the glyphs. */
766 font_dims[0] = BLF_fixed_width(font_id) * text_units;
767 font_dims[1] = BLF_height_max(font_id);
768 font_descender = -BLF_descender(font_id);
769
770 font_padding = font_size / 6;
771 font_dims[0] += font_padding * 2;
772 font_dims[1] += (font_padding * 2) + font_descender;
773
774 if (pass == 0) {
775 const int font_dims_max = std::max(font_dims[0], font_dims[1]);
776 if (font_dims_max <= cursor_size_max) {
777 break;
778 }
779 /* +1 to scale down more than a small fraction. */
780 constexpr int fixed_pt = 1024;
781 font_size = ((font_size * fixed_pt) * cursor_size_max) / (font_dims_max * fixed_pt);
782 }
783 }
784
785 /* Camping by `cursor_size` is a safeguard to ensure the size *never* exceeds the bounds.
786 * In practice this should happen rarely - if at all. */
787 const size_t dest_size[2] = {
788 size_t(std::min(font_dims[0], cursor_size_max)),
789 size_t(std::min(font_dims[1], cursor_size_max)),
790 };
791
792 uint8_t *bitmap_rgba = alloc_fn(sizeof(uint8_t[4]) * dest_size[0] * dest_size[1]);
793 if (bitmap_rgba == nullptr) {
794 return nullptr;
795 }
796 std::fill_n(reinterpret_cast<uint32_t *>(bitmap_rgba), dest_size[0] * dest_size[1], 0xA0000000);
797
798 if (text_to_draw) {
799 const float color[4] = {1.0f, 1.0f, 1.0f, 1.0f};
800 BLF_buffer_col(font_id, color);
801 BLF_buffer(font_id, nullptr, bitmap_rgba, dest_size[0], dest_size[1], 4, nullptr);
802 BLF_position(font_id, font_padding, font_padding + font_descender, 0.0f);
803 BLF_draw_buffer(font_id, text, text_len);
804 BLF_buffer(font_id, nullptr, nullptr, 0, 0, 4, nullptr);
805
806 cursor_bitmap_rgba_flip_y(bitmap_rgba, dest_size);
807 }
808
809 r_bitmap_size[0] = dest_size[0];
810 r_bitmap_size[1] = dest_size[1];
811
812 return bitmap_rgba;
813}
814
815static bool wm_cursor_text_generator(wmWindow *win, const char *text, int font_id)
816{
817 struct wmCursorText {
818 char text[CURSOR_TEXT_BUFFER_SIZE];
819 int font_id;
820 };
821
823 cursor_generator->generate_fn = [](const GHOST_CursorGenerator *cursor_generator,
824 const int cursor_size,
825 const int cursor_size_max,
826 uint8_t *(*alloc_fn)(size_t size),
827 int r_bitmap_size[2],
828 int r_hot_spot[2],
829 bool *r_can_invert_color) -> uint8_t * {
830 const wmCursorText &cursor_text = *static_cast<const wmCursorText *>(
831 cursor_generator->user_data);
832
833 int bitmap_size[2];
834 uint8_t *bitmap_rgba = cursor_bitmap_from_text(cursor_text.text,
835 cursor_size,
836 cursor_size_max,
837 cursor_text.font_id,
838 alloc_fn,
839 bitmap_size);
840
841 if (bitmap_rgba == nullptr) [[unlikely]] {
842 return nullptr;
843 }
844
845 r_bitmap_size[0] = bitmap_size[0];
846 r_bitmap_size[1] = bitmap_size[1];
847
848 r_hot_spot[0] = bitmap_size[0] / 2;
849 r_hot_spot[1] = bitmap_size[1] / 2;
850
851 /* Always use a dark background, not optional. */
852 *r_can_invert_color = false;
853
854 return bitmap_rgba;
855 };
856
857 wmCursorText *cursor_text = MEM_new<wmCursorText>(__func__);
858 STRNCPY_UTF8(cursor_text->text, text);
859 cursor_text->font_id = font_id;
860
861 cursor_generator->user_data = static_cast<void *>(cursor_text);
862 cursor_generator->free_fn = [](GHOST_CursorGenerator *cursor_generator) {
863 const wmCursorText *cursor_text = static_cast<wmCursorText *>(cursor_generator->user_data);
864 MEM_delete(cursor_text);
865 MEM_delete(cursor_generator);
866 };
867
868 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
869 GHOST_TSuccess success = ghost_window->setCustomCursorGenerator(cursor_generator);
870
871 return (success == GHOST_kSuccess) ? true : false;
872}
873
874static bool wm_cursor_text_pixmap(wmWindow *win, const char *text, int font_id)
875{
876 const int cursor_size = wm_cursor_size(win);
877 /* This is arbitrary. Use a larger value than the cursor size since the text is often wider than
878 * it is tall. In that case constraining to the cursor size tends to make the text too small.
879 * On the other hand allowing of the text to be much wider than other curses also seems strange,
880 * so constrain to twice the cursor size. */
881 const int cursor_size_max = std::min(cursor_size * 2, CURSOR_HARDWARE_SIZE_MAX);
882
883 int bitmap_size[2];
884 uint8_t *bitmap_rgba = cursor_bitmap_from_text(
885 text,
886 cursor_size,
887 cursor_size_max,
888 font_id,
889 [](size_t size) -> uint8_t * {
890 return MEM_new_array_uninitialized<uint8_t>(size, "wm.cursor");
891 },
892 bitmap_size);
893 if (bitmap_rgba == nullptr) {
894 return false;
895 }
896
897 const int hot_spot[2] = {
898 bitmap_size[0] / 2,
899 bitmap_size[1] / 2,
900 };
901 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
902 GHOST_TSuccess success = ghost_window->setCustomCursorShape(bitmap_rgba,
903 nullptr,
904 bitmap_size,
905 hot_spot,
906 /* Always use a black background. */
907 false);
908 MEM_delete(bitmap_rgba);
909
910 return (success == GHOST_kSuccess) ? true : false;
911}
912
913static bool wm_cursor_text(wmWindow *win, const char *text, int font_id)
914{
916 return wm_cursor_text_generator(win, text, font_id);
917 }
918 return wm_cursor_text_pixmap(win, text, font_id);
919}
920
925static void wm_cursor_number_impl(wmWindow *win, int nr, bool is_percentage)
926{
927 if (win->lastcursor == 0) {
928 win->lastcursor = win->cursor;
929 }
930 /* Negative numbers not supported by #wm_cursor_time_large & #wm_cursor_time_small.
931 * Make absolute to show *something* although in typical usage this shouldn't be negative.
932 * NOTE: Use of unsigned here to allow negation when `nr` is `std::numeric_limits<int>::min()`
933 * which *can't* be negated. */
934 const uint32_t nr_abs = nr >= 0 ? uint32_t(nr) : -uint32_t(nr);
935
937 char text[CURSOR_TEXT_BUFFER_SIZE];
938 if (is_percentage) {
939 /* Left pad to avoid resizing text between 9% & 10%. */
940 SNPRINTF_UTF8(text, "%2u.%02u", nr_abs / 100, nr_abs % 100);
941 }
942 else {
943 SNPRINTF_UTF8(text, "%u", nr_abs);
944 }
945 wm_cursor_text(win, text, blf_mono_font);
946 }
947 else if (wm_cursor_size(win) < 24 || !wm_cursor_time_large(win, nr_abs)) {
948 wm_cursor_time_small(win, nr_abs);
949 }
950
951 /* Unset current cursor value so it's properly reset to #wmWindow::lastcursor. */
952 win->cursor = 0;
953}
954
955void WM_cursor_time(wmWindow *win, int nr)
956{
957 wm_cursor_number_impl(win, nr, false);
958}
959
960void WM_cursor_progress(wmWindow *win, float progress_factor)
961{
962 constexpr int nr_max = 10000;
963 const int nr = std::clamp(int(std::round(double(progress_factor) * nr_max)), 0, nr_max);
964 wm_cursor_number_impl(win, nr, true);
965}
966
967#ifndef WITH_HEADLESS
968static void wm_add_cursor(wmCursorType cursor,
969 const char *svg_source,
970 const float2 &hotspot,
971 bool can_invert = false)
972{
973 g_cursors[cursor].svg_source = svg_source;
974 g_cursors[cursor].hotspot = hotspot;
975 g_cursors[cursor].can_invert = can_invert;
976}
977#endif /* !WITH_HEADLESS */
978
980{
981#ifndef WITH_HEADLESS
982 wm_add_cursor(WM_CURSOR_DEFAULT, datatoc_cursor_pointer_svg, {0.0f, 0.0f}, true);
983 wm_add_cursor(WM_CURSOR_NW_ARROW, datatoc_cursor_pointer_svg, {0.0f, 0.0f}, true);
984 wm_add_cursor(WM_CURSOR_COPY, datatoc_cursor_pointer_svg, {0.0f, 0.0f}, true);
985 wm_add_cursor(WM_CURSOR_MOVE, datatoc_cursor_pointer_svg, {0.0f, 0.0f}, true);
986 wm_add_cursor(WM_CURSOR_TEXT_EDIT, datatoc_cursor_text_edit_svg, {0.5f, 0.5f});
987 wm_add_cursor(WM_CURSOR_WAIT, datatoc_cursor_wait_svg, {0.5f, 0.5f});
988 wm_add_cursor(WM_CURSOR_STOP, datatoc_cursor_stop_svg, {0.5f, 0.5f});
989 wm_add_cursor(WM_CURSOR_EDIT, datatoc_cursor_crosshair_svg, {0.5f, 0.5f});
990 wm_add_cursor(WM_CURSOR_HAND, datatoc_cursor_hand_svg, {0.5f, 0.5f});
991 wm_add_cursor(WM_CURSOR_HAND_CLOSED, datatoc_cursor_hand_closed_svg, {0.5f, 0.5f});
992 wm_add_cursor(WM_CURSOR_HAND_POINT, datatoc_cursor_hand_point_svg, {0.5f, 0.5f});
993 wm_add_cursor(WM_CURSOR_CROSS, datatoc_cursor_crosshair_svg, {0.5f, 0.5f});
994 wm_add_cursor(WM_CURSOR_PAINT, datatoc_cursor_paint_svg, {0.5f, 0.5f});
995 wm_add_cursor(WM_CURSOR_DOT, datatoc_cursor_dot_svg, {0.5f, 0.5f});
996 wm_add_cursor(WM_CURSOR_CROSSC, datatoc_cursor_crossc_svg, {0.5f, 0.5f});
997 wm_add_cursor(WM_CURSOR_KNIFE, datatoc_cursor_knife_svg, {0.0f, 1.0f});
998 wm_add_cursor(WM_CURSOR_BLADE, datatoc_cursor_blade_svg, {0.0f, 0.375f});
999 wm_add_cursor(WM_CURSOR_VERTEX_LOOP, datatoc_cursor_vertex_loop_svg, {0.0f, 0.0f});
1000 wm_add_cursor(WM_CURSOR_PAINT_BRUSH, datatoc_cursor_pencil_svg, {0.0f, 1.0f});
1001 wm_add_cursor(WM_CURSOR_ERASER, datatoc_cursor_eraser_svg, {0.0f, 1.0f});
1002 wm_add_cursor(WM_CURSOR_EYEDROPPER, datatoc_cursor_eyedropper_svg, {0.0f, 1.0f});
1003 wm_add_cursor(WM_CURSOR_SWAP_AREA, datatoc_cursor_swap_area_svg, {0.5f, 0.5f});
1004 wm_add_cursor(WM_CURSOR_X_MOVE, datatoc_cursor_x_move_svg, {0.5f, 0.5f});
1005 wm_add_cursor(WM_CURSOR_EW_ARROW, datatoc_cursor_x_move_svg, {0.5f, 0.5f});
1006 wm_add_cursor(WM_CURSOR_Y_MOVE, datatoc_cursor_y_move_svg, {0.5f, 0.5f});
1007 wm_add_cursor(WM_CURSOR_NS_ARROW, datatoc_cursor_y_move_svg, {0.5f, 0.5f});
1008 wm_add_cursor(WM_CURSOR_H_SPLIT, datatoc_cursor_h_split_svg, {0.5f, 0.5f});
1009 wm_add_cursor(WM_CURSOR_V_SPLIT, datatoc_cursor_v_split_svg, {0.5f, 0.5f});
1010 wm_add_cursor(WM_CURSOR_N_ARROW, datatoc_cursor_n_arrow_svg, {0.5f, 0.5f});
1011 wm_add_cursor(WM_CURSOR_S_ARROW, datatoc_cursor_s_arrow_svg, {0.5f, 0.5f});
1012 wm_add_cursor(WM_CURSOR_E_ARROW, datatoc_cursor_e_arrow_svg, {0.5f, 0.5f});
1013 wm_add_cursor(WM_CURSOR_W_ARROW, datatoc_cursor_w_arrow_svg, {0.5f, 0.5f});
1014 wm_add_cursor(WM_CURSOR_NSEW_SCROLL, datatoc_cursor_nsew_scroll_svg, {0.5f, 0.5f});
1015 wm_add_cursor(WM_CURSOR_EW_SCROLL, datatoc_cursor_ew_scroll_svg, {0.5f, 0.5f});
1016 wm_add_cursor(WM_CURSOR_NS_SCROLL, datatoc_cursor_ns_scroll_svg, {0.5f, 0.5f});
1017 wm_add_cursor(WM_CURSOR_ZOOM_IN, datatoc_cursor_zoom_in_svg, {0.32f, 0.32f});
1018 wm_add_cursor(WM_CURSOR_ZOOM_OUT, datatoc_cursor_zoom_out_svg, {0.32f, 0.32f});
1019 wm_add_cursor(WM_CURSOR_MUTE, datatoc_cursor_mute_svg, {0.59f, 0.59f});
1020 wm_add_cursor(WM_CURSOR_PICK_AREA, datatoc_cursor_pick_area_svg, {0.5f, 0.5f});
1021 wm_add_cursor(WM_CURSOR_BOTH_HANDLES, datatoc_cursor_both_handles_svg, {0.5f, 0.5f});
1022 wm_add_cursor(WM_CURSOR_RIGHT_HANDLE, datatoc_cursor_right_handle_svg, {0.5f, 0.5f});
1023 wm_add_cursor(WM_CURSOR_LEFT_HANDLE, datatoc_cursor_left_handle_svg, {0.5f, 0.5f});
1024 wm_add_cursor(WM_CURSOR_SLIP, datatoc_cursor_slip_svg, {0.5f, 0.5f});
1025#endif /* !WITH_HEADLESS */
1026}
1027
1028} // namespace blender
#define G_MAIN
#define SNPRINTF_UTF8(dst, format,...)
#define STRNCPY_UTF8(dst, src)
These structs are the foundation for all linked lists in the library system.
#define UI_SCALE_FAC
GHOST_TStandardCursor
@ GHOST_kStandardCursorLeftHandle
@ GHOST_kStandardCursorHandClosed
@ GHOST_kStandardCursorHandOpen
@ GHOST_kStandardCursorZoomIn
@ GHOST_kStandardCursorVerticalSplit
@ GHOST_kStandardCursorCopy
@ GHOST_kStandardCursorWait
@ GHOST_kStandardCursorRightHandle
@ GHOST_kStandardCursorHorizontalSplit
@ GHOST_kStandardCursorStop
@ GHOST_kStandardCursorCrosshair
@ GHOST_kStandardCursorCustom
@ GHOST_kStandardCursorNSEWScroll
@ GHOST_kStandardCursorLeftRight
@ GHOST_kStandardCursorPencil
@ GHOST_kStandardCursorNSScroll
@ GHOST_kStandardCursorCrosshairA
@ GHOST_kStandardCursorUpDown
@ GHOST_kStandardCursorUpArrow
@ GHOST_kStandardCursorHandPoint
@ GHOST_kStandardCursorBothHandles
@ GHOST_kStandardCursorEyedropper
@ GHOST_kStandardCursorKnife
@ GHOST_kStandardCursorMove
@ GHOST_kStandardCursorCrosshairB
@ GHOST_kStandardCursorBlade
@ GHOST_kStandardCursorSlip
@ GHOST_kStandardCursorDownArrow
@ GHOST_kStandardCursorEraser
@ GHOST_kStandardCursorDefault
@ GHOST_kStandardCursorEWScroll
@ GHOST_kStandardCursorRightArrow
@ GHOST_kStandardCursorCrosshairC
@ GHOST_kStandardCursorZoomOut
@ GHOST_kStandardCursorText
@ GHOST_kStandardCursorLeftArrow
GHOST_TAxisFlag
@ GHOST_kAxisX
@ GHOST_kAxisY
@ GHOST_kAxisNone
GHOST_TSuccess
@ GHOST_kSuccess
GHOST_TGrabCursorMode
@ GHOST_kGrabWrap
@ GHOST_kGrabDisable
@ GHOST_kGrabHide
@ GHOST_kGrabNormal
#define UNUSED_VARS(...)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
virtual GHOST_TSuccess setCursorShape(GHOST_TStandardCursor cursor_shape)=0
virtual GHOST_TSuccess setCustomCursorShape(const uint8_t *bitmap, const uint8_t *mask, const int size[2], const int hot_spot[2], bool can_invert_color)=0
virtual float getNativePixelSize()=0
virtual GHOST_TSuccess setCursorVisibility(bool visible)=0
virtual GHOST_TSuccess setCustomCursorGenerator(GHOST_CursorGenerator *cursor_generator)=0
virtual GHOST_TSuccess setCursorGrab(GHOST_TGrabCursorMode, GHOST_TAxisFlag, GHOST_Rect *, int32_t[2])
virtual GHOST_TSuccess hasCursorShape(GHOST_TStandardCursor cursor_shape)=0
#define ceil
float3x3 scale(float3x3 mat, float2 scale)
BLI_INLINE Texture * wrap(MTLTexture *texture)
BMesh Iterators.
static uint8_t * cursor_bitmap_from_svg(const char *svg, const int cursor_size, uint8_t *(*alloc_fn)(size_t size), int r_bitmap_size[2])
void wm_init_cursor_data()
void BLF_position(int fontid, float x, float y, float z)
Definition blf.cc:390
unsigned int uint
Definition BKE_text.h:55
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
bool WM_cursor_set_from_tool(wmWindow *win, const ScrArea *area, const ARegion *region)
eWM_CursorWrapAxis
Definition WM_types.hh:238
@ WM_CURSOR_WRAP_Y
Definition WM_types.hh:241
@ WM_CURSOR_WRAP_X
Definition WM_types.hh:240
@ WM_CURSOR_WRAP_NONE
Definition WM_types.hh:239
void BLF_buffer(int fontid, float *fbuf, unsigned char *cbuf, int w, int h, int channel_count, const ColorSpace *colorspace)
Definition blf.cc:989
static bool window_set_custom_cursor(wmWindow *win, const BCursor &cursor)
void WM_cursor_modal_set(wmWindow *win, int val)
uint WM_cursor_preferred_logical_size(const bool hardware_cursor)
void wm_cursor_position_to_ghost_screen_coords(wmWindow *win, int *x, int *y)
static bool window_set_custom_cursor_pixmap(wmWindow *win, const BCursor &cursor)
static bool window_set_custom_cursor_generator(wmWindow *win, const BCursor &cursor)
void WM_cursor_progress(wmWindow *win, float progress_factor)
Global G
Definition blender.cc:57
unsigned int uint32_t
Definition BKE_text.h:81
void BLF_size(int fontid, float size)
Definition blf.cc:445
bool wm_cursor_position_get(wmWindow *win, int *r_x, int *r_y)
VecBase< float, 2 > float2
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
unsigned char uchar
Definition BKE_text.h:58
static bool wm_cursor_text_pixmap(wmWindow *win, const char *text, int font_id)
void WM_cursor_grab_enable(wmWindow *win, const eWM_CursorWrapAxis wrap, const rcti *wrap_region, const bool hide)
constexpr int CURSOR_HARDWARE_SIZE_MAX
Definition wm_cursors.cc:56
static bool wm_cursor_text_generator(wmWindow *win, const char *text, int font_id)
static bool wm_cursor_time_large(wmWindow *win, uint32_t nr)
unsigned char uint8_t
Definition BKE_text.h:79
int BLI_str_utf8_column_count(const char *str, size_t str_len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void WM_cursor_modal_restore(wmWindow *win)
void WM_cursor_time(wmWindow *win, int nr)
static int wm_cursor_size(const wmWindow *win)
float BLF_fixed_width(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:848
void WM_cursor_grab_disable(wmWindow *win, const int mouse_ungrab_xy[2])
static void wm_cursor_warp_relative(wmWindow *win, int x, int y)
static void wm_cursor_time_small(wmWindow *win, uint32_t nr)
static void cursor_rgba_to_xbm_32(const uint8_t *rgba, const int bitmap_size[2], uint8_t *bitmap, uint8_t *mask)
static void wm_cursor_number_impl(wmWindow *win, int nr, bool is_percentage)
void BLF_buffer_col(int fontid, const float srgb_color[4]) ATTR_NONNULL(2)
Definition blf.cc:1057
@ WM_CAPABILITY_CURSOR_RGBA
Definition WM_api.hh:247
@ WM_CAPABILITY_CURSOR_GENERATOR
Definition WM_api.hh:249
static BCursor g_cursors[WM_CURSOR_NUM]
Definition wm_cursors.cc:84
static GHOST_TStandardCursor convert_to_ghost_standard_cursor(wmCursorType curs)
Definition wm_cursors.cc:87
int BLF_height_max(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:883
@ WM_CURSOR_NS_SCROLL
Definition wm_cursors.hh:55
@ WM_CURSOR_WAIT
Definition wm_cursors.hh:19
@ WM_CURSOR_LEFT_HANDLE
Definition wm_cursors.hh:66
@ WM_CURSOR_HAND_CLOSED
Definition wm_cursors.hh:25
@ WM_CURSOR_MOVE
Definition wm_cursors.hh:23
@ WM_CURSOR_TEXT_EDIT
Definition wm_cursors.hh:18
@ WM_CURSOR_MUTE
Definition wm_cursors.hh:62
@ WM_CURSOR_PAINT
Definition wm_cursors.hh:29
@ WM_CURSOR_Y_MOVE
Definition wm_cursors.hh:42
@ WM_CURSOR_H_SPLIT
Definition wm_cursors.hh:43
@ WM_CURSOR_BLADE
Definition wm_cursors.hh:34
@ WM_CURSOR_E_ARROW
Definition wm_cursors.hh:51
@ WM_CURSOR_EDIT
Definition wm_cursors.hh:21
@ WM_CURSOR_ZOOM_OUT
Definition wm_cursors.hh:59
@ WM_CURSOR_CROSSC
Definition wm_cursors.hh:31
@ WM_CURSOR_HAND
Definition wm_cursors.hh:24
@ WM_CURSOR_ZOOM_IN
Definition wm_cursors.hh:58
@ WM_CURSOR_PAINT_BRUSH
Definition wm_cursors.hh:36
@ WM_CURSOR_NSEW_SCROLL
Definition wm_cursors.hh:54
@ WM_CURSOR_SWAP_AREA
Definition wm_cursors.hh:40
@ WM_CURSOR_DEFAULT
Definition wm_cursors.hh:17
@ WM_CURSOR_STOP
Definition wm_cursors.hh:20
@ WM_CURSOR_X_MOVE
Definition wm_cursors.hh:41
@ WM_CURSOR_RIGHT_HANDLE
Definition wm_cursors.hh:67
@ WM_CURSOR_HAND_POINT
Definition wm_cursors.hh:26
@ WM_CURSOR_NS_ARROW
Definition wm_cursors.hh:47
@ WM_CURSOR_SLIP
Definition wm_cursors.hh:69
@ WM_CURSOR_NUM
Definition wm_cursors.hh:72
@ WM_CURSOR_DOT
Definition wm_cursors.hh:30
@ WM_CURSOR_NONE
Definition wm_cursors.hh:61
@ WM_CURSOR_EW_SCROLL
Definition wm_cursors.hh:56
@ WM_CURSOR_EW_ARROW
Definition wm_cursors.hh:48
@ WM_CURSOR_BOTH_HANDLES
Definition wm_cursors.hh:68
@ WM_CURSOR_PICK_AREA
Definition wm_cursors.hh:64
@ WM_CURSOR_VERTEX_LOOP
Definition wm_cursors.hh:35
@ WM_CURSOR_NW_ARROW
Definition wm_cursors.hh:46
@ WM_CURSOR_CROSS
Definition wm_cursors.hh:28
@ WM_CURSOR_ERASER
Definition wm_cursors.hh:37
@ WM_CURSOR_EYEDROPPER
Definition wm_cursors.hh:38
@ WM_CURSOR_S_ARROW
Definition wm_cursors.hh:50
@ WM_CURSOR_COPY
Definition wm_cursors.hh:22
@ WM_CURSOR_W_ARROW
Definition wm_cursors.hh:52
@ WM_CURSOR_V_SPLIT
Definition wm_cursors.hh:44
@ WM_CURSOR_KNIFE
Definition wm_cursors.hh:33
@ WM_CURSOR_N_ARROW
Definition wm_cursors.hh:49
static void cursor_bitmap_rgba_flip_y(uint8_t *buffer, const size_t size[2])
static void wm_add_cursor(wmCursorType cursor, const char *svg_source, const float2 &hotspot, bool can_invert=false)
eWM_CapabilitiesFlag WM_capabilities_flag()
int BLF_descender(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:905
signed int int32_t
Definition BKE_text.h:78
static bool wm_cursor_text(wmWindow *win, const char *text, int font_id)
void BLF_draw_buffer(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_NONNULL(2)
Definition blf.cc:1087
int blf_mono_font
Definition blf.cc:50
void WM_cursor_set(wmWindow *win, int curs)
bool WM_cursor_modal_is_set_ok(const wmWindow *win)
float WM_window_dpi_get_scale(const wmWindow *win)
Definition wm_window.cc:784
void WM_cursor_warp(wmWindow *win, int x, int y)
void WM_cursor_wait(bool val)
bool wm_cursor_arrow_move(wmWindow *win, const wmEvent *event)
static uint8_t * cursor_bitmap_from_text(const char *text, const int cursor_size, const int cursor_size_max, int font_id, uint8_t *(*alloc_fn)(size_t size), int r_bitmap_size[2])
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
uint8_t *(*) generate_fn(const struct GHOST_CursorGenerator *cursor_generator, int cursor_size, int cursor_size_max, uint8_t *(*alloc_fn)(size_t size), int r_bitmap_size[2], int r_hot_spot[2], bool *r_can_invert_color)
void(*) free_fn(struct GHOST_CursorGenerator *cursor_generator)
GHOST_TUserDataPtr user_data
eRegion_Type regiontype
const char * svg_source
Definition wm_cursors.cc:70
ScrArea_Runtime runtime
bToolRef_Runtime * runtime
wmTabletData tablet
Definition WM_types.hh:846
wmEventType type
Definition WM_types.hh:817
bke::WindowRuntime * runtime
#define CURSOR_TEXT_BUFFER_SIZE
Definition wm_cursors.cc:62