Blender V5.3
wm_dragdrop.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2010 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include <cstring>
12#include <functional>
13
15
16#include "DNA_asset_types.h"
17#include "DNA_screen_types.h"
18#include "DNA_space_types.h"
20
21#include "MEM_guardedalloc.h"
22
23#include "BLT_translation.hh"
24
25#include "BLI_fileops.hh"
26#include "BLI_listbase.hh"
27#include "BLI_math_color_c.hh"
28#include "BLI_path_utils.hh"
29#include "BLI_string.hh"
30#include "BLI_string_utf8.hh"
31
32#include "BIF_glutil.hh"
33
34#include "BKE_context.hh"
35#include "BKE_global.hh"
36#include "BKE_idprop.hh"
37#include "BKE_idtype.hh"
38#include "BKE_lib_id.hh"
39#include "BKE_main.hh"
41#include "BKE_preview_image.hh"
42#include "BKE_screen.hh"
43
44#include "BLO_readfile.hh"
45
46#include "ED_asset.hh"
47#include "ED_fileselect.hh"
48#include "ED_screen.hh"
49
50#include "GPU_shader_builtin.hh"
51#include "GPU_state.hh"
52
53#include "IMB_imbuf.hh"
54#include "IMB_imbuf_types.hh"
55
56#include "GHOST_Types.hh"
57
58#include "UI_interface.hh"
59#include "UI_interface_icons.hh"
60#include "UI_resources.hh"
61
62#include "RNA_access.hh"
63
64#include "WM_api.hh"
65#include "WM_types.hh"
66#include "wm.hh"
67#include "wm_event_system.hh"
68#include "wm_window.hh"
69
70#include <fmt/format.h>
71
72namespace blender {
73
74/* ****************************************************** */
75
76struct wmDropBoxMap;
77static ListBaseT<wmDropBoxMap> dropboxes = {nullptr, nullptr};
78
79static void wm_drag_free_asset_data(wmDragAsset **asset_data);
80static void wm_drag_free_path_data(wmDragPath **path_data);
81
82static void wm_drop_item_free_data(wmDropBox *drop);
83static void wm_drop_item_clear_runtime(wmDropBox *drop);
84
87
88/* Drop box maps are stored global for now. */
89/* These are part of blender's UI/space specs, and not like keymaps. */
90/* When editors become configurable, they can add their own dropbox definitions. */
91
94
95 ListBaseT<wmDropBox> dropboxes;
98};
99
105
111
112ListBaseT<wmDropBox> *WM_dropboxmap_find(const char *idname, int spaceid, int regionid)
113{
114 for (wmDropBoxMap &dm : dropboxes) {
115 if (dm.spaceid == spaceid && dm.regionid == regionid) {
116 if (STREQLEN(idname, dm.idname, KMAP_MAX_NAME)) {
117 return &dm.dropboxes;
118 }
119 }
120 }
121
123 STRNCPY_UTF8(dm->idname, idname);
124 dm->spaceid = spaceid;
125 dm->regionid = regionid;
127
128 return &dm->dropboxes;
129}
130
131wmDropBox *WM_dropbox_add(ListBaseT<wmDropBox> *lb,
132 const char *idname,
133 bool (*poll)(bContext *C, wmDrag *drag, const wmEvent *event),
134 void (*copy)(bContext *C, wmDrag *drag, wmDropBox *drop),
135 void (*cancel)(Main *bmain, wmDrag *drag, wmDropBox *drop),
136 WMDropboxTooltipFunc tooltip)
137{
138 wmOperatorType *ot = WM_operatortype_find(idname, true);
139 if (ot == nullptr) {
140 printf("Error: dropbox with unknown operator: %s\n", idname);
141 return nullptr;
142 }
143
144 wmDropBox *drop = MEM_new_zeroed<wmDropBox>(__func__);
145 drop->poll = poll;
146 drop->copy = copy;
147 drop->cancel = cancel;
148 drop->tooltip = tooltip;
149 drop->ot = ot;
150 STRNCPY(drop->opname, idname);
151
152 WM_operator_properties_alloc(&(drop->ptr), &(drop->properties), idname);
154
155 /* Signal for no context, see #STRUCT_NO_CONTEXT_WITHOUT_OWNER_ID. */
156 drop->ptr->owner_id = nullptr;
157
158 BLI_addtail(lb, drop);
159
160 return drop;
161}
162
164 const eWM_DragDataType drag_type,
165 const std::function<void(bContext &C, wmDrag &drag)> on_drag_start)
166{
167 wmDragPrefetchHandler handler{};
168 handler.drag_type = drag_type;
169 handler.on_drag_start = on_drag_start;
170
171 global_prefetch_handlers().append(handler);
172}
173
175{
176 /* NOTE(@ideasman42): this closely follows #wm_keymap_item_properties_update_ot.
177 * `keep_properties` is implied because drop boxes aren't dynamically added & removed.
178 * It's possible in the future drop-boxes can be (un)registered by scripts.
179 * In this case we might want to remove drop-boxes that point to missing operators. */
180 wmOperatorType *ot = WM_operatortype_find(drop->opname, false);
181 if (ot == nullptr) {
182 /* Allow for the operator to be added back and re-validated, keep it's properties. */
184 drop->ot = nullptr;
185 return;
186 }
187
188 if (drop->ptr == nullptr) {
189 WM_operator_properties_alloc(&(drop->ptr), &(drop->properties), drop->opname);
191 }
192 else {
193 if (ot->srna != drop->ptr->type) {
195 if (drop->properties) {
196 drop->ptr->data = drop->properties;
197 }
199 }
200 }
201
202 if (drop->ptr) {
203 drop->ptr->owner_id = nullptr;
204 }
205 drop->ot = ot;
206}
207
209{
210 for (wmDropBoxMap &dm : dropboxes) {
211 for (wmDropBox &drop : dm.dropboxes) {
213 }
214 }
215}
216
218{
219 if (drop->ptr) {
221 MEM_delete(drop->ptr);
222 drop->ptr = nullptr;
223 drop->properties = nullptr;
224 }
225 else if (drop->properties) {
227 drop->properties = nullptr;
228 }
229}
230
232{
233 IDProperty *properties = drop->properties;
234 drop->properties = nullptr;
235 if (drop->ptr) {
236 drop->ptr->data = nullptr;
237 }
239 drop->properties = properties;
240}
241
243{
244
245 for (wmDropBoxMap &dm : dropboxes) {
246 for (wmDropBox &drop : dm.dropboxes) {
248 }
249 dm.dropboxes.free_no_destruct();
250 }
251
252 dropboxes.free_no_destruct();
253}
254
255/* *********************************** */
256
257static void wm_dropbox_invoke(bContext *C, wmDrag *drag)
258{
260 if (handler.drag_type == drag->type) {
261 handler.on_drag_start(*C, *drag);
262 }
263 }
264
266
267 /* Create a bitmap flag matrix of all currently visible region and area types.
268 * Everything that isn't visible in the current window should not prefetch any data. */
269 bool area_region_tag[SPACE_TYPE_NUM][RGN_TYPE_NUM] = {{false}};
270
271 for (wmWindow &win : wm->windows) {
272 bScreen *screen = WM_window_get_active_screen(&win);
273 ED_screen_areas_iter (&win, screen, area) {
274 for (ARegion &region : area->regionbase) {
275 if (region.runtime->visible) {
276 BLI_assert(area->spacetype < SPACE_TYPE_NUM);
278 area_region_tag[area->spacetype][region.regiontype] = true;
279 }
280 }
281 }
282 }
283
284 for (wmDropBoxMap &dm : dropboxes) {
285 if (!area_region_tag[dm.spaceid][dm.regionid]) {
286 continue;
287 }
288 for (wmDropBox &drop : dm.dropboxes) {
289 if (drag->drop_state.ui_context) {
290 CTX_store_set(C, drag->drop_state.ui_context.get());
291 }
292
293 if (drop.on_drag_start) {
294 drop.on_drag_start(C, drag);
295 }
296 CTX_store_set(C, nullptr);
297 }
298 }
299}
300
301wmDrag *WM_drag_data_create(bContext *C, int icon, eWM_DragDataType type, void *poin, uint flags)
302{
303 wmDrag *drag = MEM_new<wmDrag>(__func__);
304
305 /* Keep track of future multi-touch drag too, add a mouse-pointer id or so. */
306 /* If multiple drags are added, they're drawn as list. */
307
308 drag->flags = static_cast<eWM_DragFlags>(flags);
309 drag->icon = icon;
310 drag->type = type;
311 switch (type) {
312 case WM_DRAG_PATH:
313 drag->poin = poin;
314 drag->flags |= WM_DRAG_FREE_DATA;
315 break;
316 case WM_DRAG_ID:
317 if (poin) {
318 WM_drag_add_local_ID(drag, static_cast<ID *>(poin), nullptr);
319 }
320 break;
322 case WM_DRAG_ASSET:
324 /* Move ownership of poin to wmDrag. */
325 drag->poin = poin;
326 drag->flags |= WM_DRAG_FREE_DATA;
327 break;
328 /* The asset-list case is special: We get multiple assets from context and attach them to the
329 * drag item. */
330 case WM_DRAG_ASSET_LIST: {
331 Vector<PointerRNA> asset_links = CTX_data_collection_get(C, "selected_assets");
332 for (const PointerRNA &ptr : asset_links) {
334 static_cast<const asset_system::AssetRepresentation *>(ptr.data);
335 WM_drag_add_asset_list_item(drag, asset);
336 }
337 break;
338 }
339 default:
340 drag->poin = poin;
341 break;
342 }
343
344 return drag;
345}
346
348{
350
351 BLI_addtail(&wm->runtime->drags, drag);
352 wm_dropbox_invoke(C, drag);
353}
354
355void WM_event_start_drag(bContext *C, int icon, eWM_DragDataType type, void *poin, uint flags)
356{
357 wmDrag *drag = WM_drag_data_create(C, icon, type, poin, flags);
359}
360
362{
363 for (wmDrag &drag : wm->runtime->drags) {
364 if (wmDropBox *dropbox = drag.drop_state.active_dropbox) {
365 WM_event_timer_remove(wm, win, dropbox->timer);
366 dropbox->timer = nullptr;
367 }
368 }
369}
370
372{
373 /* Turn off modal cursor for all windows. */
374 for (wmWindow &win : wm->windows) {
376 }
377
379
380 /* Active area should always redraw, even if canceled. */
381 int event_xy_target[2];
383 win, win->runtime->eventstate->xy, event_xy_target);
384 if (target_win) {
385 const bScreen *screen = WM_window_get_active_screen(target_win);
387
388 /* Ensure the correct area cursor is restored. */
389 target_win->tag_cursor_refresh = true;
390 WM_event_add_mousemove(target_win);
391 }
392}
393
394static std::unique_ptr<bContextStore> wm_drop_ui_context_create(const bContext *C)
395{
397 if (!active_but) {
398 return nullptr;
399 }
400
401 const bContextStore *but_context = button_context_get(active_but);
402 if (!but_context) {
403 return nullptr;
404 }
405
406 return std::make_unique<bContextStore>(*but_context);
407}
408
409void WM_event_drag_image(wmDrag *drag, const ImBuf *imb, float scale)
410{
411 drag->imb = imb;
412 drag->imbuf_scale = scale;
413}
414
416{
417 BLI_assert(drag->type == WM_DRAG_PATH);
418 const SpaceFile *sfile = CTX_wm_space_file(C);
419 if (!sfile) {
420 return;
421 }
424 for (const std::string &path : selected_paths) {
425 paths.append(path.c_str());
426 }
427 if (paths.is_empty()) {
428 return;
429 }
430 WM_drag_data_free(drag->type, drag->poin);
431 drag->poin = WM_drag_create_path_data(paths);
432}
433
434void WM_event_drag_preview_icon(wmDrag *drag, int icon_id)
435{
436 BLI_assert_msg(!drag->imb, "Drag image and preview are mutually exclusive");
437 drag->preview_icon_id = icon_id;
438}
439
440void WM_drag_data_free(eWM_DragDataType dragtype, void *poin)
441{
442 /* Don't require all the callers to have a nullptr-check, just allow passing nullptr. */
443 if (!poin) {
444 return;
445 }
446
447 /* Not too nice, could become a callback. */
448 switch (dragtype) {
449 case WM_DRAG_ASSET: {
450 wmDragAsset *asset_data = static_cast<wmDragAsset *>(poin);
451 wm_drag_free_asset_data(&asset_data);
452 break;
453 }
454 case WM_DRAG_PATH: {
455 wmDragPath *path_data = static_cast<wmDragPath *>(poin);
456 wm_drag_free_path_data(&path_data);
457 break;
458 }
459 case WM_DRAG_STRING: {
460 std::string *str = static_cast<std::string *>(poin);
461 MEM_delete(str);
462 break;
463 }
468 break;
469 }
470 default:
471 MEM_delete_void(poin);
472 break;
473 }
474}
475
477{
480 }
481 if (drag->flags & WM_DRAG_FREE_DATA) {
482 WM_drag_data_free(drag->type, drag->poin);
483 }
484 drag->drop_state.ui_context.reset();
485 drag->ids.free_no_destruct();
486 for (wmDragAssetListItem &asset_item : drag->asset_items.items_mutable()) {
487 if (asset_item.is_external) {
488 wm_drag_free_asset_data(&asset_item.asset_data.external_info);
489 }
490 BLI_freelinkN(&drag->asset_items, &asset_item);
491 }
492 MEM_delete(drag);
493}
494
495void WM_drag_free_list(ListBaseT<wmDrag> *lb)
496{
497 while (wmDrag *drag = static_cast<wmDrag *>(BLI_pophead(lb))) {
498 WM_drag_free(drag);
499 }
500}
501
502static std::string dropbox_tooltip(bContext *C, wmDrag *drag, const int xy[2], wmDropBox *drop)
503{
504 if (drop->tooltip) {
505 return drop->tooltip(C, drag, xy, drop);
506 }
507 if (drop->ot) {
508 return WM_operatortype_name(drop->ot, drop->ptr);
509 }
510 return {};
511}
512
514 ListBaseT<wmEventHandler> *handlers,
515 wmDrag *drag,
516 const wmEvent *event)
517{
518 for (wmEventHandler &handler_base : *handlers) {
519 if (handler_base.type == WM_HANDLER_TYPE_DROPBOX) {
520 wmEventHandler_Dropbox *handler = reinterpret_cast<wmEventHandler_Dropbox *>(&handler_base);
521 if (handler->dropboxes) {
522 for (wmDropBox &drop : *handler->dropboxes) {
523 if (drag->drop_state.ui_context) {
524 CTX_store_set(C, drag->drop_state.ui_context.get());
525 }
526
527 if (!drop.poll(C, drag, event)) {
528 /* If the drop's poll fails, don't set the disabled-info. This would be too aggressive.
529 * Instead show it only if the drop box could be used in principle, but the operator
530 * can't be executed. */
531 continue;
532 }
533
534 const wm::OpCallContext opcontext = wm_drop_operator_context_get(&drop);
535 if (drop.ot && WM_operator_poll_context(C, drop.ot, opcontext)) {
536 /* Get dropbox tooltip now, #wm_drag_draw_tooltip can use a different draw context. */
537 drag->drop_state.tooltip = dropbox_tooltip(C, drag, event->xy, &drop);
538 CTX_store_set(C, nullptr);
539 return &drop;
540 }
541
542 /* Attempt to set the disabled hint when the poll fails. Will always be the last hint set
543 * when there are multiple failing polls (could allow multiple disabled-hints too). */
544 bool free_disabled_info = false;
545 const char *disabled_hint = CTX_wm_operator_poll_msg_get(C, &free_disabled_info);
546 if (disabled_hint) {
547 drag->drop_state.disabled_info = disabled_hint;
548 if (free_disabled_info) {
549 MEM_SAFE_DELETE(disabled_hint);
550 }
551 }
552 }
553 }
554 }
555 }
556 CTX_store_set(C, nullptr);
557 return nullptr;
558}
559
561{
562 for (const wmDrag &drag : wm.runtime->drags) {
563 if (drag.type == WM_DRAG_ASSET) {
564 return true;
565 }
566 }
567 return false;
568}
569
570static bool drag_global_poll(const bContext *C,
571 const wmDrag *drag,
572 std::string * /*r_status_info*/,
573 std::string *r_disabled_info)
574{
575 if (wmDragAsset *asset_data = WM_drag_get_asset_data(drag, 0)) {
576 if (asset_data->asset->is_online_only()) {
577 *r_disabled_info = RPT_("Asset needs downloading first");
578 return false;
579 }
580 }
581
582 if (!wm_drag_asset_path_exists(drag).value_or(true)) {
584 /* Return false without displaying a message. The "Asset not found" message below tends to
585 * show up twice when both #WM_DRAG_ASSET and #WM_DRAG_ASSET_LIST are present. Skip the check
586 * for the former if the latter exists. */
587 return false;
588 }
589
590 *r_disabled_info = RPT_("Asset not found");
591 return false;
592 }
593
594 return true;
595}
596
597/* Return active operator tooltip/name when mouse is in box. */
598static wmDropBox *wm_dropbox_active(bContext *C, wmDrag *drag, const wmEvent *event)
599{
600 drag->drop_state.disabled_info = std::nullopt;
601
602 std::string disabled_info;
603 /* The red of the `disabled_info` looks scary. Use this instead for non-error conditions, it will
604 * show in the normal text color. */
605 std::string status_info;
606 /* Always do these checks for dragging (as if they were in every poll). */
607 if (!drag_global_poll(C, drag, &status_info, &disabled_info)) {
608 drag->drop_state.disabled_info = disabled_info;
609 /* Just use the tooltip for status info. There's no drop-box active to fill it anyway. */
610 drag->drop_state.tooltip = status_info;
611 return nullptr;
612 }
613
614 wmWindow *win = CTX_wm_window(C);
616 ScrArea *area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, event->xy);
617 wmDropBox *drop = nullptr;
618
619 if (area) {
620 ARegion *region = ED_area_find_region_xy_visual(area, RGN_TYPE_ANY, event->xy);
621 if (region) {
622 drop = dropbox_active(C, &region->runtime->handlers, drag, event);
623 }
624
625 if (!drop) {
626 drop = dropbox_active(C, &area->handlers, drag, event);
627 }
628 }
629 if (!drop) {
630 drop = dropbox_active(C, &win->runtime->handlers, drag, event);
631 }
632 return drop;
633}
634
638static void wm_drop_update_active(bContext *C, wmDrag *drag, const wmEvent *event)
639{
640 wmWindow *win = CTX_wm_window(C);
641 const int2 win_size = WM_window_native_pixel_size(win);
642
643 /* For multi-window drags, we only do this if mouse inside. */
644 if (event->xy[0] < 0 || event->xy[1] < 0 || event->xy[0] > win_size[0] ||
645 event->xy[1] > win_size[1])
646 {
647 return;
648 }
649
650 /* Update UI context, before polling so polls can query this context. */
651 drag->drop_state.ui_context.reset();
653 drag->drop_state.tooltip = "";
654
655 wmDropBox *drop_prev = drag->drop_state.active_dropbox;
656 wmDropBox *drop = wm_dropbox_active(C, drag, event);
657 if (drop != drop_prev) {
658 if (drop_prev) {
659 /* Remove timer if any when exiting the dropbox. */
660 WM_event_timer_remove(CTX_wm_manager(C), nullptr, drop_prev->timer);
661 drop_prev->timer = nullptr;
662 if (drop_prev->on_exit) {
663 drop_prev->on_exit(drop_prev, drag);
664 BLI_assert(drop_prev->draw_data == nullptr);
665 }
666 }
667 if (drop && drop->on_enter) {
668 drop->on_enter(drop, drag);
669 }
670 drag->drop_state.active_dropbox = drop;
671 drag->drop_state.area_from = drop ? CTX_wm_area(C) : nullptr;
672 drag->drop_state.region_from = drop ? CTX_wm_region(C) : nullptr;
673 }
674
675 if (!drag->drop_state.active_dropbox) {
676 drag->drop_state.ui_context.reset();
677 }
678}
679
681{
682 const wm::OpCallContext opcontext = wm_drop_operator_context_get(drop);
683
684 if (drag->drop_state.ui_context) {
685 CTX_store_set(C, drag->drop_state.ui_context.get());
686 }
687
688 /* Optionally copy drag information to operator properties. Don't call it if the
689 * operator fails anyway, it might do more than just set properties (e.g.
690 * typically import an asset). */
691 if (drop->copy && WM_operator_poll_context(C, drop->ot, opcontext)) {
692 drop->copy(C, drag, drop);
693 }
694
696}
697
698void wm_drop_end(bContext *C, wmDrag * /*drag*/, wmDropBox * /*drop*/)
699{
700 CTX_store_set(C, nullptr);
701}
702
704{
705 if (!ELEM(event->type, TIMER, MOUSEMOVE, EVT_DROP)) {
706 return;
707 }
709 const ARegion *region = CTX_wm_region(C);
710
711 /* Make sure the timer event belongs to an active dropbox in the currently handled region, skip
712 * handling this event otherwise. */
713 {
714 if (event->type == TIMER) {
715 bool has_drag_timer = false;
716
717 for (const wmDrag &drag : wm->runtime->drags) {
718 if (drag.drop_state.active_dropbox &&
719 (event->customdata == drag.drop_state.active_dropbox->timer) &&
720 (region == drag.drop_state.region_from))
721 {
722 has_drag_timer = true;
723 }
724 }
725 if (!has_drag_timer) {
726 return;
727 }
728 }
729 }
730
731 bool any_active = false;
732 for (wmDrag &drag : wm->runtime->drags) {
733 /* This is to update tooltip during drag and timer events. */
734 wm_drop_update_active(C, &drag, event);
735
736 if (wmDropBox *dropbox = drag.drop_state.active_dropbox) {
737 any_active = true;
738 if (dropbox->on_event_while_hover) {
739 dropbox->on_event_while_hover(C, *dropbox, event);
740 }
741 }
742 }
743
744 /* Change the cursor to display that dropping isn't possible here. But only if there is something
745 * being dragged actually. Cursor will be restored in #wm_drags_exit(). */
746 if (!wm->runtime->drags.is_empty() && ELEM(event->type, MOUSEMOVE, EVT_DROP)) {
748 }
749}
750
755
756/* ************** IDs ***************** */
757
758void WM_drag_add_local_ID(wmDrag *drag, ID *id, ID *from_parent)
759{
760 /* Don't drag the same ID twice. */
761 for (wmDragID &drag_id : drag->ids) {
762 if (drag_id.id == id) {
763 if (drag_id.from_parent == nullptr) {
764 drag_id.from_parent = from_parent;
765 }
766 return;
767 }
768 }
769
770 /* Add to list. */
771 wmDragID *drag_id = MEM_new_zeroed<wmDragID>(__func__);
772 drag_id->id = id;
773 drag_id->from_parent = from_parent;
774 BLI_addtail(&drag->ids, drag_id);
775}
776
777ID *WM_drag_get_local_ID(const wmDrag *drag, short idcode)
778{
779 if (drag->type != WM_DRAG_ID) {
780 return nullptr;
781 }
782
783 wmDragID *drag_id = drag->ids.first();
784 if (!drag_id) {
785 return nullptr;
786 }
787
788 ID *id = drag_id->id;
789 return (idcode == 0 || GS(id->name) == idcode) ? id : nullptr;
790}
791
792ID *WM_drag_get_local_ID_from_event(const wmEvent *event, short idcode)
793{
794 if (event->custom != EVT_DATA_DRAGDROP) {
795 return nullptr;
796 }
797
798 ListBaseT<wmDrag> *lb = static_cast<ListBaseT<wmDrag> *>(event->customdata);
799 return WM_drag_get_local_ID(lb->first(), idcode);
800}
801
802bool WM_drag_is_ID_type(const wmDrag *drag, int idcode)
803{
804 return WM_drag_get_local_ID(drag, idcode) || WM_drag_get_asset_data(drag, idcode);
805}
806
808 const AssetImportSettings &import_settings)
809{
810 wmDragAsset *asset_drag = MEM_new<wmDragAsset>(__func__);
811
812 asset_drag->asset = asset;
813 asset_drag->import_settings = import_settings;
814
815 return asset_drag;
816}
817
818static void wm_drag_free_asset_data(wmDragAsset **asset_data)
819{
820 if (*asset_data) {
821 MEM_delete(*asset_data);
822 *asset_data = nullptr;
823 }
824}
825
827{
828 if (drag->type != WM_DRAG_ASSET) {
829 return nullptr;
830 }
831
832 wmDragAsset *asset_drag = static_cast<wmDragAsset *>(drag->poin);
833 ID_Type asset_idcode = asset_drag->asset->get_id_type();
834 return ELEM(idcode, 0, asset_idcode) ? asset_drag : nullptr;
835}
836
838{
839 wmDragAsset *drag_asset = WM_drag_get_asset_data(drag, idcode);
840 if (drag_asset) {
841 return &drag_asset->asset->get_metadata();
842 }
843
844 ID *local_id = WM_drag_get_local_ID(drag, idcode);
845 if (local_id) {
846 return local_id->asset_data;
847 }
848
849 return nullptr;
850}
851
852ID *WM_drag_asset_id_import(const bContext *C, wmDragAsset *asset_drag, const int flag_extra)
853{
854 /* Only support passing in limited flags. */
855 BLI_assert(flag_extra == (flag_extra & FILE_AUTOSELECT));
856 /* #eFileSel_Params_Flag + #eBLOLibLinkFlags */
857 int flag = flag_extra | FILE_ACTIVE_COLLECTION;
858
861 }
862
863 ed::asset::ImportInstantiateContext instantiate_context;
864 instantiate_context.scene = CTX_data_scene(C);
865 instantiate_context.view_layer = CTX_data_view_layer(C);
866 instantiate_context.view3d = CTX_wm_view3d(C);
867
868 /* FIXME: Link/Append should happens in the operator called at the end of drop process, not from
869 * here. */
871 *asset_drag->asset,
872 flag,
873 asset_drag->import_settings.method,
874 instantiate_context,
876}
877
879{
880 if (drag->type != WM_DRAG_ASSET) {
881 return false;
882 }
883
884 const wmDragAsset *asset_drag = WM_drag_get_asset_data(drag, 0);
885 return asset_drag->import_settings.method == ASSET_IMPORT_LINK;
886}
887
889{
890 if (drag->type != WM_DRAG_ASSET) {
891 return false;
892 }
893
894 const wmDragAsset *asset_drag = WM_drag_get_asset_data(drag, 0);
895 return asset_drag->import_settings.method == ASSET_IMPORT_PACK;
896}
897
899{
900 if (!ELEM(drag->type, WM_DRAG_ASSET, WM_DRAG_ID)) {
901 return nullptr;
902 }
903
904 if (drag->type == WM_DRAG_ID) {
905 return WM_drag_get_local_ID(drag, idcode);
906 }
907
908 wmDragAsset *asset_drag = WM_drag_get_asset_data(drag, idcode);
909 if (!asset_drag) {
910 return nullptr;
911 }
912
913 /* Link/append the asset. */
914 return WM_drag_asset_id_import(C, asset_drag, 0);
915}
916
918{
919 if (drag->type != WM_DRAG_ASSET) {
920 return;
921 }
922
923 wmDragAsset *asset_drag = WM_drag_get_asset_data(drag, 0);
924 if (!asset_drag) {
925 return;
926 }
927
928 ID_Type asset_id_type = asset_drag->asset->get_id_type();
929 /* Try to find the imported ID. For this to work either a "session_uid" or "name" property must
930 * have been defined (see #WM_operator_properties_id_lookup()). */
932 bmain, drop->ptr, asset_id_type);
933 if (id != nullptr) {
934 /* Do not delete the dragged ID if it has any user, otherwise if it is a 're-used' ID it will
935 * cause #95636. Note that we need first to add the user that we want to remove in
936 * #BKE_id_free_us. */
937 id_us_plus(id);
938 BKE_id_free_us(bmain, id);
939 }
940}
941
943{
944 if (drag->type != WM_DRAG_ASSET_CATALOG) {
945 return nullptr;
946 }
947
948 return static_cast<wmDragAssetCatalog *>(drag->poin);
949}
950
952{
954
955 /* No guarantee that the same asset isn't added twice. */
956
957 /* Add to list. */
959 ID *local_id = asset->local_id();
960 if (local_id) {
961 drag_asset->is_external = false;
962 drag_asset->asset_data.local_id = local_id;
963 }
964 else {
965 drag_asset->is_external = true;
966
967 AssetImportSettings import_settings{};
968 import_settings.method = ASSET_IMPORT_APPEND;
969 import_settings.use_instance_collections = false;
970
971 drag_asset->asset_data.external_info = WM_drag_create_asset_data(asset, import_settings);
972 }
973 BLI_addtail(&drag->asset_items, drag_asset);
974}
975
976const ListBaseT<wmDragAssetListItem> *WM_drag_asset_list_get(const wmDrag *drag)
977{
978 if (drag->type != WM_DRAG_ASSET_LIST) {
979 return nullptr;
980 }
981
982 return &drag->asset_items;
983}
984
985std::optional<bool> wm_drag_asset_path_exists(const wmDrag *drag)
986{
988 return {};
989 }
990
991 if (const wmDragAsset *asset_drag = WM_drag_get_asset_data(drag, 0)) {
992 return BLI_is_file(asset_drag->asset->full_library_path().c_str());
993 }
994
995 if (const ListBaseT<wmDragAssetListItem> *asset_drags = WM_drag_asset_list_get(drag)) {
996
997 if (asset_drags->is_empty()) {
998 /* #button_drag_start() will start a drag of type WM_DRAG_ASSET_LIST for dragging a
999 * WM_DRAG_ID button (so we do not early out above in this case). Its #asset_items list will
1000 * always be empty though, so avoid returning false at the end of this function, treat this
1001 * special case more like not being a "real" WM_DRAG_ASSET_LIST. */
1002 return {};
1003 }
1004
1005 for (wmDragAssetListItem &asset_item : *asset_drags) {
1006 if (!asset_item.is_external ||
1007 BLI_is_file(asset_item.asset_data.external_info->asset->full_library_path().c_str()))
1008 {
1009 return true;
1010 }
1011 }
1012 }
1013 return false;
1014}
1015
1017{
1018 BLI_assert(!paths.is_empty());
1019 wmDragPath *path_data = MEM_new<wmDragPath>("wmDragPath");
1020
1021 for (const char *path : paths) {
1022 path_data->paths.append(path);
1023 const int type_flag = ED_path_extension_type(path);
1024 path_data->file_types_bit_flag |= type_flag;
1025 path_data->file_types.append(type_flag);
1026 }
1027
1028 path_data->tooltip = path_data->paths[0];
1029
1030 if (path_data->paths.size() > 1) {
1031 std::string path_count = std::to_string(path_data->paths.size());
1032 path_data->tooltip = fmt::format(fmt::runtime(TIP_("Dragging {} files")), path_count);
1033 }
1034
1035 return path_data;
1036}
1037
1038static void wm_drag_free_path_data(wmDragPath **path_data)
1039{
1040 MEM_delete(*path_data);
1041 *path_data = nullptr;
1042}
1043
1044const char *WM_drag_get_single_path(const wmDrag *drag)
1045{
1046 if (drag->type != WM_DRAG_PATH) {
1047 return nullptr;
1048 }
1049
1050 const wmDragPath *path_data = static_cast<const wmDragPath *>(drag->poin);
1051 return path_data->paths[0].c_str();
1052}
1053
1054const char *WM_drag_get_single_path(const wmDrag *drag, int file_type)
1055{
1056 if (drag->type != WM_DRAG_PATH) {
1057 return nullptr;
1058 }
1059 const wmDragPath *path_data = static_cast<const wmDragPath *>(drag->poin);
1060 const Span<int> file_types = path_data->file_types;
1061
1062 const auto *itr = std::find_if(
1063 file_types.begin(), file_types.end(), [file_type](const int file_fype_test) {
1064 return file_fype_test & file_type;
1065 });
1066
1067 if (itr == file_types.end()) {
1068 return nullptr;
1069 }
1070 const int index = itr - file_types.begin();
1071 return path_data->paths[index].c_str();
1072}
1073
1074bool WM_drag_has_path_file_type(const wmDrag *drag, int file_type)
1075{
1076 if (drag->type != WM_DRAG_PATH) {
1077 return false;
1078 }
1079 const wmDragPath *path_data = static_cast<const wmDragPath *>(drag->poin);
1080 return bool(path_data->file_types_bit_flag & file_type);
1081}
1082
1084{
1085 if (drag->type != WM_DRAG_PATH) {
1086 return Span<std::string>();
1087 }
1088
1089 const wmDragPath *path_data = static_cast<const wmDragPath *>(drag->poin);
1090 return path_data->paths.as_span();
1091}
1092
1094{
1095 if (drag->type != WM_DRAG_PATH) {
1096 return 0;
1097 }
1098
1099 const wmDragPath *path_data = static_cast<const wmDragPath *>(drag->poin);
1100 return path_data->file_types[0];
1101}
1102
1103const std::string &WM_drag_get_string(const wmDrag *drag)
1104{
1105 BLI_assert(drag->type == WM_DRAG_STRING);
1106 const std::string *str = static_cast<const std::string *>(drag->poin);
1107 return *str;
1108}
1109
1110std::string WM_drag_get_string_firstline(const wmDrag *drag)
1111{
1112 BLI_assert(drag->type == WM_DRAG_STRING);
1113 const std::string *str = static_cast<const std::string *>(drag->poin);
1114 const size_t str_eol = str->find('\n');
1115 if (str_eol != std::string::npos) {
1116 return str->substr(0, str_eol);
1117 }
1118 return *str;
1119}
1120
1121/* ************** draw ***************** */
1122
1123static void wm_drop_operator_draw(const StringRef name, int x, int y)
1124{
1125 const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
1126
1127 /* Use the theme settings from tooltips. */
1128 const bTheme *btheme = ui::theme::theme_get();
1129 const uiWidgetColors *wcol = &btheme->tui.wcol_tooltip;
1130
1131 float col_fg[4], col_bg[4];
1132 rgba_uchar_to_float(col_fg, wcol->text);
1133 rgba_uchar_to_float(col_bg, wcol->inner);
1134
1135 ui::fontstyle_draw_simple_backdrop(fstyle, x, y, name, col_fg, col_bg);
1136}
1137
1138static void wm_drop_redalert_draw(const StringRef redalert_str, int x, int y)
1139{
1140 const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
1141 const bTheme *btheme = ui::theme::theme_get();
1142 const uiWidgetColors *wcol = &btheme->tui.wcol_tooltip;
1143
1144 float col_fg[4], col_bg[4], col_alert[4];
1145 rgba_uchar_to_float(col_bg, wcol->inner);
1146 rgba_uchar_to_float(col_fg, wcol->text);
1148
1149 /* Alert color's alpha is used to blend between the text and alert tint.
1150 * This ensures the text be always readable, lighter or darker depending on the theme. */
1151 col_fg[0] = (1.0f - col_alert[3]) * col_fg[0] + (col_alert[3] * col_alert[0]);
1152 col_fg[1] = (1.0f - col_alert[3]) * col_fg[1] + (col_alert[3] * col_alert[1]);
1153 col_fg[2] = (1.0f - col_alert[3]) * col_fg[2] + (col_alert[3] * col_alert[2]);
1154
1155 ui::fontstyle_draw_simple_backdrop(fstyle, x, y, redalert_str, col_fg, col_bg);
1156}
1157
1158const std::string WM_drag_get_item_name(wmDrag *drag)
1159{
1160 switch (drag->type) {
1161 case WM_DRAG_ID: {
1162 ID *id = WM_drag_get_local_ID(drag, 0);
1163 const int dragged_ids = drag->ids.count();
1164
1165 if (dragged_ids == 1) {
1166 return id->name + 2;
1167 }
1168 if (id) {
1169 return std::to_string(dragged_ids) + " " + BKE_idtype_idcode_to_name_plural(GS(id->name));
1170 }
1171 break;
1172 }
1173 case WM_DRAG_ASSET: {
1174 const wmDragAsset *asset_drag = WM_drag_get_asset_data(drag, 0);
1175 return asset_drag->asset->get_name();
1176 }
1177 case WM_DRAG_PATH: {
1178 const wmDragPath *path_drag_data = static_cast<const wmDragPath *>(drag->poin);
1179 return path_drag_data->tooltip;
1180 }
1181 case WM_DRAG_NAME:
1182 return static_cast<const char *>(drag->poin);
1183 default:
1184 break;
1185 }
1186 return "";
1187}
1188
1190{
1191 return round_fl_to_int(drag->imb->x * drag->imbuf_scale);
1192}
1193
1195{
1196 return round_fl_to_int(drag->imb->y * drag->imbuf_scale);
1197}
1198
1200{
1202}
1203
1204static void wm_drag_draw_icon(bContext * /*C*/, wmWindow * /*win*/, wmDrag *drag, const int xy[2])
1205{
1206 int x, y;
1207
1208 if (const int64_t path_count = WM_drag_get_paths(drag).size(); path_count > 1) {
1209 /* Custom scale to improve path count readability. */
1210 const float scale = UI_SCALE_FAC * 1.15f;
1211 x = xy[0] - int(8.0f * scale);
1212 y = xy[1] - int(scale);
1213 const uchar text_col[] = {255, 255, 255, 255};
1214 ui::IconTextOverlay text_overlay;
1215 icon_text_overlay_init_from_count(&text_overlay, path_count);
1216 icon_draw_ex(x, y, ICON_DOCUMENTS, 1.0f / scale, 1.0f, 0.0f, text_col, false, &text_overlay);
1217 }
1218 else if (drag->imb) {
1219 /* This could also get the preview image of an ID when dragging one. But the big preview icon
1220 * may actually not always be wanted, for example when dragging objects in the Outliner it gets
1221 * in the way. So make the drag user set an image buffer explicitly (e.g. through
1222 * #button_drag_attach_image()). */
1223
1224 x = xy[0] - (wm_drag_imbuf_icon_width_get(drag) / 2);
1225 y = xy[1] - (wm_drag_imbuf_icon_height_get(drag) / 2);
1226
1227 const float col[4] = {1.0f, 1.0f, 1.0f, 0.65f}; /* This blends texture. */
1229 drawer.draw(x,
1230 y,
1231 drag->imb->x,
1232 drag->imb->y,
1233 gpu::TextureFormat::UNORM_8_8_8_8,
1234 false,
1235 drag->imb->byte_data(),
1236 drag->imbuf_scale,
1237 drag->imbuf_scale,
1238 col);
1239 }
1240 else if (drag->preview_icon_id) {
1241 const int size = wm_drag_preview_icon_size_get();
1242 x = xy[0] - (size / 2);
1243 y = xy[1] - (size / 2);
1244
1245 ui::icon_draw_preview(x, y, drag->preview_icon_id, 1.0, 0.8, size);
1246 }
1247 else {
1248 int padding = 4 * UI_SCALE_FAC;
1249 x = xy[0] - 2 * padding;
1250 y = xy[1] - 2 * UI_SCALE_FAC;
1251
1252 const uchar text_col[] = {255, 255, 255, 255};
1254 x, y, drag->icon, UI_INV_SCALE_FAC, 0.8, 0.0f, text_col, false, UI_NO_ICON_OVERLAY_TEXT);
1255 }
1256}
1257
1258static void wm_drag_draw_item_name(wmDrag *drag, const int x, const int y)
1259{
1260 const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
1261 const uchar text_col[] = {255, 255, 255, 255};
1262 ui::fontstyle_draw_simple(fstyle, x, y, WM_drag_get_item_name(drag).c_str(), text_col);
1263}
1264
1265void WM_drag_draw_item_name_fn(bContext * /*C*/, wmWindow *win, wmDrag *drag, const int xy[2])
1266{
1267 int x = xy[0] + 10 * UI_SCALE_FAC;
1268 int y = xy[1] + 1 * UI_SCALE_FAC;
1269
1270 /* Needs zero offset here or it looks blurry. #128112. */
1271 wmWindowViewport_ex(win, 0.0f);
1272 wm_drag_draw_item_name(drag, x, y);
1273}
1274
1275static void wm_drag_draw_tooltip(bContext *C, wmWindow *win, wmDrag *drag, const int xy[2])
1276{
1277 if (!CTX_wm_region(C)) {
1278 /* Some callbacks require the region. */
1279 return;
1280 }
1281 int iconsize = UI_ICON_SIZE;
1282 int padding = 4 * UI_SCALE_FAC;
1283 StringRef tooltip = drag->drop_state.tooltip;
1284 const bool has_disabled_info = drag->drop_state.disabled_info &&
1285 drag->drop_state.disabled_info.value()[0];
1286 if (tooltip.is_empty() && !has_disabled_info) {
1287 return;
1288 }
1289
1290 const int winsize_y = WM_window_native_pixel_y(win);
1291 int x, y;
1292 if (drag->imb) {
1293 const int icon_width = wm_drag_imbuf_icon_width_get(drag);
1294 const int icon_height = wm_drag_imbuf_icon_height_get(drag);
1295
1296 x = xy[0] - (icon_width / 2);
1297
1298 if (xy[1] + (icon_height / 2) + padding + iconsize < winsize_y) {
1299 y = xy[1] + (icon_height / 2) + padding;
1300 }
1301 else {
1302 y = xy[1] - (icon_height / 2) - padding - iconsize - padding - iconsize;
1303 }
1304 }
1305 if (WM_drag_get_paths(drag).size() > 1) {
1306 x = xy[0] - 2 * padding;
1307
1308 if (xy[1] + 2 * 1.15 * iconsize < winsize_y) {
1309 y = xy[1] + 1.15f * (iconsize + 6 * UI_SCALE_FAC);
1310 }
1311 else {
1312 y = xy[1] - 1.15f * (iconsize + padding);
1313 }
1314 }
1315 else if (drag->preview_icon_id) {
1316 const int size = wm_drag_preview_icon_size_get();
1317
1318 x = xy[0] - (size / 2);
1319
1320 if (xy[1] + (size / 2) + padding + iconsize < winsize_y) {
1321 y = xy[1] + (size / 2) + padding;
1322 }
1323 else {
1324 y = xy[1] - (size / 2) - padding - iconsize - padding - iconsize;
1325 }
1326 }
1327 else {
1328 x = xy[0] - 2 * padding;
1329
1330 if (xy[1] + iconsize + iconsize < winsize_y) {
1331 y = (xy[1] + iconsize) + padding;
1332 }
1333 else {
1334 y = (xy[1] - iconsize) - padding;
1335 }
1336 }
1337
1338 if (!tooltip.is_empty()) {
1339 wm_drop_operator_draw(tooltip, x, y);
1340 }
1341 else if (has_disabled_info) {
1343 }
1344}
1345
1346static void wm_drag_draw_default(bContext *C, wmWindow *win, wmDrag *drag, const int xy[2])
1347{
1348 int xy_tmp[2] = {UNPACK2(xy)};
1349
1350 /* Image or icon. */
1351 wm_drag_draw_icon(C, win, drag, xy_tmp);
1352
1353 /* Item name. */
1354 if (drag->imb) {
1355 int iconsize = UI_ICON_SIZE;
1356 xy_tmp[0] = xy[0] - (wm_drag_imbuf_icon_width_get(drag) / 2);
1357 xy_tmp[1] = xy[1] - (wm_drag_imbuf_icon_height_get(drag) / 2) - iconsize;
1358 }
1359 else if (drag->preview_icon_id) {
1360 const int icon_size = UI_ICON_SIZE;
1361 const int preview_size = wm_drag_preview_icon_size_get();
1362 xy_tmp[0] = xy[0] - (preview_size / 2);
1363 xy_tmp[1] = xy[1] - (preview_size / 2) - icon_size;
1364 }
1365 else {
1366 xy_tmp[0] = xy[0] + 10 * UI_SCALE_FAC;
1367 xy_tmp[1] = xy[1] + 1 * UI_SCALE_FAC;
1368 }
1369 if (WM_drag_get_paths(drag).size() < 2) {
1370 wm_drag_draw_item_name(drag, UNPACK2(xy_tmp));
1371 }
1372
1373 /* Operator name with round-box. */
1374 wm_drag_draw_tooltip(C, win, drag, xy);
1375}
1376
1377void WM_drag_draw_default_fn(bContext *C, wmWindow *win, wmDrag *drag, const int xy[2])
1378{
1379 wm_drag_draw_default(C, win, drag, xy);
1380}
1381
1383{
1384 const int *xy = win->runtime->eventstate->xy;
1385
1386 int xy_buf[2];
1388 wm_cursor_position_get(win, &xy_buf[0], &xy_buf[1]))
1389 {
1390 xy = xy_buf;
1391 }
1392
1393 bScreen *screen = CTX_wm_screen(C);
1394 /* To start with, use the area and region under the mouse cursor, just like event handling. The
1395 * operator context may still override it. */
1396 ScrArea *area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, xy);
1398 /* Will be overridden and unset eventually. */
1400
1402
1403 /* Should we support multi-line drag draws? Maybe not, more types mixed won't work well. */
1405 for (wmDrag &drag : wm->runtime->drags) {
1406 if (drag.drop_state.active_dropbox) {
1409 CTX_store_set(C, drag.drop_state.ui_context.get());
1410
1411 if (region && drag.drop_state.active_dropbox->draw_in_view) {
1412 wmViewport(&region->winrct);
1413 drag.drop_state.active_dropbox->draw_in_view(C, win, &drag, xy);
1414 wmWindowViewport(win);
1415 }
1416
1417 /* Drawing should be allowed to assume the context from handling and polling (that's why we
1418 * restore it above). */
1420 drag.drop_state.active_dropbox->draw_droptip(C, win, &drag, xy);
1421 continue;
1422 }
1423 }
1424 else if (region) {
1425 CTX_wm_area_set(C, area);
1426 CTX_wm_region_set(C, region);
1427 }
1428
1429 /* Needs zero offset here or it looks blurry. #128112. */
1430 wmWindowViewport_ex(win, 0.0f);
1431 wm_drag_draw_default(C, win, &drag, xy);
1432 }
1434 CTX_wm_area_set(C, nullptr);
1435 CTX_wm_region_set(C, nullptr);
1436 CTX_store_set(C, nullptr);
1437}
1438
1439} // namespace blender
Main runtime representation of an asset.
File and directory operations.
#define STRNCPY_UTF8(dst, src)
external readfile function prototypes.
#define RPT_(msgid)
#define TIP_(msgid)
#define RGN_TYPE_ANY
#define RGN_TYPE_NUM
#define SPACE_TYPE_NUM
#define SPACE_TYPE_ANY
#define UI_SCALE_FAC
#define UI_INV_SCALE_FAC
#define UI_ICON_SIZE
#define KMAP_MAX_NAME
#define ED_screen_areas_iter(win, screen, area_name)
Definition ED_screen.hh:322
@ GHOST_kGrabWrap
@ GHOST_kGrabHide
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define UI_FSTYLE_WIDGET
#define UI_NO_ICON_OVERLAY_TEXT
#define PREVIEW_DRAG_DRAW_SIZE
#define UNPACK2(a)
#define STREQLEN(a, b, n)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
void draw(float x, float y, int img_w, int img_h, gpu::TextureFormat gpu_format, bool use_filter, const void *rect, float scale_x, float scale_y, const float color[4])
Definition glutil.cc:45
constexpr const T * end() const
Definition BLI_span.hh:228
constexpr const T * begin() const
Definition BLI_span.hh:224
constexpr bool is_empty() const
Definition BLI_span.hh:264
void append(const T &value)
bool is_empty() const
constexpr bool is_empty() const
void append(const T &value)
Span< T > as_span() const
int64_t size() const
#define str(s)
#define storage(slot, qualifiers)
float3x3 scale(float3x3 mat, float2 scale)
void item_reference_free(bNodeTreeInterfaceItemReference *item_reference)
ID * asset_local_id_ensure_imported(Main &bmain, const asset_system::AssetRepresentation &asset, int flags=0, const std::optional< eAssetImportMethod > import_method=std::nullopt, const std::optional< ImportInstantiateContext > instantiate_context=std::nullopt, ReportList *reports=nullptr)
void get_color_4fv(int colorid, float col[4])
const bTheme * theme_get()
void fontstyle_draw_simple_backdrop(const uiFontStyle *fs, float x, float y, StringRef str, const float col_fg[4], const float col_bg[4])
void icon_draw_ex(float x, float y, int icon_id, float aspect, float alpha, float desaturate, const uchar mono_color[4], bool mono_border, const IconTextOverlay *text_overlay, const bool inverted=false, float scale=1.0f)
void icon_draw_preview(float x, float y, int icon_id, float aspect, float alpha, int size)
void fontstyle_draw_simple(const uiFontStyle *fs, float x, float y, const char *str, const uchar col[4])
Button * region_active_but_get(const ARegion *region)
BMesh Iterators.
static void wm_drag_draw_item_name(wmDrag *drag, const int x, const int y)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
ID * WM_drag_get_local_ID_from_event(const wmEvent *event, short idcode)
const char * WM_drag_get_single_path(const wmDrag *drag)
Vector< std::string > ED_fileselect_selected_files_full_paths(const SpaceFile *sfile)
Definition filesel.cc:1534
Vector< PointerRNA > CTX_data_collection_get(const bContext *C, const char *member)
static Vector< wmDragPrefetchHandler > & global_prefetch_handlers()
ScrArea * CTX_wm_area(const bContext *C)
__int64 int64_t
Definition BKE_text.h:90
MINLINE void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4])
wmDropBox * WM_dropbox_add(ListBaseT< wmDropBox > *lb, const char *idname, bool(*poll)(bContext *C, wmDrag *drag, const wmEvent *event), void(*copy)(bContext *C, wmDrag *drag, wmDropBox *drop), void(*cancel)(Main *bmain, wmDrag *drag, wmDropBox *drop), WMDropboxTooltipFunc tooltip)
char * STRNCPY(char(&dst)[N], const char *src)
void wmViewport(const rcti *winrct)
const ListBaseT< wmDragAssetListItem > * WM_drag_asset_list_get(const wmDrag *drag)
uint padding(uint offset, uint alignment)
wmDragAsset * WM_drag_create_asset_data(const asset_system::AssetRepresentation *asset, const AssetImportSettings &import_settings)
wmDragAsset * WM_drag_get_asset_data(const wmDrag *drag, int idcode)
void wm_drags_exit(wmWindowManager *wm, wmWindow *win)
static void wm_drag_draw_icon(bContext *, wmWindow *, wmDrag *drag, const int xy[2])
void WM_operator_properties_alloc(PointerRNA **ptr, IDProperty **properties, const char *opstring)
void WM_drag_free_imported_drag_ID(Main *bmain, wmDrag *drag, wmDropBox *drop)
Free asset ID imported for canceled drop.
unsigned int uint
Definition BKE_text.h:55
std::string WM_operatortype_name(wmOperatorType *ot, PointerRNA *properties)
void WM_operator_properties_sanitize(PointerRNA *ptr, const bool no_context)
void BKE_id_free_us(Main *bmain, void *idv) ATTR_NONNULL()
void WM_event_start_drag(bContext *C, int icon, eWM_DragDataType type, void *poin, uint flags)
std::string(*)(bContext *C, wmDrag *drag, const int xy[2], wmDropBox *drop) WMDropboxTooltipFunc
Definition WM_types.hh:1378
MINLINE int round_fl_to_int(float a)
void wmWindowViewport(const wmWindow *win)
void id_us_plus(ID *id)
Definition lib_id.cc:433
int ED_path_extension_type(const char *path)
Definition filelist.cc:1852
const std::string WM_drag_get_item_name(wmDrag *drag)
int WM_window_native_pixel_y(const wmWindow *win)
void wm_drop_end(bContext *C, wmDrag *, wmDropBox *)
void WM_operator_properties_free(PointerRNA *ptr)
ID * WM_operator_properties_id_lookup_from_name_or_session_uid(Main *bmain, PointerRNA *ptr, const ID_Type type)
static std::string dropbox_tooltip(bContext *C, wmDrag *drag, const int xy[2], wmDropBox *drop)
wmWindow * WM_window_find_under_cursor(wmWindow *win, const int event_xy[2], int r_event_xy_other[2])
void WM_cursor_modal_set(wmWindow *win, int val)
void wm_drop_prepare(bContext *C, wmDrag *drag, wmDropBox *drop)
PointerRNA WM_operator_properties_create_ptr(wmOperatorType *ot)
@ WM_DRAG_NODE_TREE_INTERFACE
Definition WM_types.hh:1317
@ WM_DRAG_GREASE_PENCIL_LAYER
Definition WM_types.hh:1315
@ WM_DRAG_NAME
Definition WM_types.hh:1303
@ WM_DRAG_ASSET
Definition WM_types.hh:1294
@ WM_DRAG_STRING
Definition WM_types.hh:1311
@ WM_DRAG_ASSET_CATALOG
Definition WM_types.hh:1314
@ WM_DRAG_PATH
Definition WM_types.hh:1302
@ WM_DRAG_ASSET_LIST
Definition WM_types.hh:1300
static wmDropBox * wm_dropbox_active(bContext *C, wmDrag *drag, const wmEvent *event)
wmWindow * CTX_wm_window(const bContext *C)
ID * WM_drag_get_local_ID_or_import_from_asset(const bContext *C, const wmDrag *drag, int idcode)
static int wm_drag_imbuf_icon_height_get(const wmDrag *drag)
static void wm_drop_operator_draw(const StringRef name, int x, int y)
static bool drag_global_poll(const bContext *C, const wmDrag *drag, std::string *, std::string *r_disabled_info)
@ BLO_LIBLINK_COLLECTION_INSTANCE
const std::string & WM_drag_get_string(const wmDrag *drag)
bool WM_drag_is_ID_type(const wmDrag *drag, int idcode)
void wm_dropbox_free()
void MEM_delete_void(void *vmemh)
void WM_event_drag_path_override_poin_data_with_space_file_paths(const bContext *C, wmDrag *drag)
ViewLayer * CTX_data_view_layer(const bContext *C)
@ GPU_BLEND_NONE
Definition GPU_state.hh:88
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:90
void * BLI_pophead(ListBase *listbase) ATTR_NONNULL(1)
Definition listbase.cc:259
static void wm_drop_update_active(bContext *C, wmDrag *drag, const wmEvent *event)
bool WM_drag_asset_will_import_packed(const wmDrag *drag)
bool WM_drag_has_path_file_type(const wmDrag *drag, int file_type)
bool wm_cursor_position_get(wmWindow *win, int *r_x, int *r_y)
VecBase< int32_t, 2 > int2
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
@ ASSET_IMPORT_APPEND
unsigned char uchar
Definition BKE_text.h:58
wmDragAssetCatalog * WM_drag_get_asset_catalog_data(const wmDrag *drag)
static void wm_drag_free_asset_data(wmDragAsset **asset_data)
void WM_event_drag_image(wmDrag *drag, const ImBuf *imb, float scale)
wmWindowManager * CTX_wm_manager(const bContext *C)
void wm_drags_draw(bContext *C, wmWindow *win)
@ FILE_ACTIVE_COLLECTION
void BLI_freelinkN(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:277
void WM_cursor_modal_restore(wmWindow *win)
void wmWindowViewport_ex(const wmWindow *win, float offset)
const char * BKE_idtype_idcode_to_name_plural(short idcode)
Definition idtype.cc:268
void WM_drag_draw_item_name_fn(bContext *, wmWindow *win, wmDrag *drag, const int xy[2])
const char * CTX_wm_operator_poll_msg_get(bContext *C, bool *r_free)
bool WM_operator_poll_context(bContext *C, wmOperatorType *ot, wm::OpCallContext context)
wmDrag * WM_drag_data_create(bContext *C, int icon, eWM_DragDataType type, void *poin, uint flags)
void WM_dropbox_update_ot()
@ WM_HANDLER_TYPE_DROPBOX
static void wm_drop_item_clear_runtime(wmDropBox *drop)
@ WM_DRAG_FREE_DATA
Definition WM_types.hh:1324
ScrArea ScrArea * BKE_screen_find_area_xy(const bScreen *screen, int spacetype, const int xy[2]) ATTR_NONNULL(1
Definition screen.cc:1226
bool WM_drag_asset_will_import_linked(const wmDrag *drag)
static void wm_drag_free_path_data(wmDragPath **path_data)
wm::OpCallContext wm_drop_operator_context_get(const wmDropBox *)
void WM_drag_data_free(eWM_DragDataType dragtype, void *poin)
void WM_event_drag_preview_icon(wmDrag *drag, int icon_id)
int WM_drag_get_path_file_type(const wmDrag *drag)
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
static bool has_single_asset_drag(const wmWindowManager &wm)
ARegion * ED_area_find_region_xy_visual(const ScrArea *area, int regiontype, const int event_xy[2])
@ WM_CURSOR_DEFAULT
Definition wm_cursors.hh:17
@ WM_CURSOR_STOP
Definition wm_cursors.hh:20
static void wm_dropbox_invoke(bContext *C, wmDrag *drag)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
Main * CTX_data_main(const bContext *C)
static void wm_drop_item_free_data(wmDropBox *drop)
void IDP_FreeProperty(IDProperty *prop)
Definition idprop.cc:1403
int2 WM_window_native_pixel_size(const wmWindow *win)
AssetMetaData * WM_drag_get_asset_meta_data(const wmDrag *drag, int idcode)
ID_Type GS(const char *name)
Definition DNA_ID.h:410
Span< std::string > WM_drag_get_paths(const wmDrag *drag)
static wmDropBox * dropbox_active(bContext *C, ListBaseT< wmEventHandler > *handlers, wmDrag *drag, const wmEvent *event)
static int wm_drag_imbuf_icon_width_get(const wmDrag *drag)
static ListBaseT< wmDropBoxMap > dropboxes
SpaceFile * CTX_wm_space_file(const bContext *C)
void WM_drag_global_prefetch_handler_add(const eWM_DragDataType drag_type, const std::function< void(bContext &C, wmDrag &drag)> on_drag_start)
Scene * CTX_data_scene(const bContext *C)
std::optional< bool > wm_drag_asset_path_exists(const wmDrag *drag)
bScreen * CTX_wm_screen(const bContext *C)
void CTX_wm_region_set(bContext *C, ARegion *region)
void WM_event_timer_remove(wmWindowManager *wm, wmWindow *, wmTimer *timer)
void WM_drag_add_asset_list_item(wmDrag *drag, const asset_system::AssetRepresentation *asset)
std::string WM_drag_get_string_firstline(const wmDrag *drag)
void WM_drag_add_local_ID(wmDrag *drag, ID *id, ID *from_parent)
void GPU_blend(GPUBlend blend)
Definition gpu_state.cc:44
void wm_drags_handle_events(bContext *C, const wmEvent *event)
void WM_event_start_prepared_drag(bContext *C, wmDrag *drag)
ID * WM_drag_get_local_ID(const wmDrag *drag, short idcode)
wmDragPath * WM_drag_create_path_data(Span< const char * > paths)
static int wm_drag_preview_icon_size_get()
ListBaseT< wmDropBox > * WM_dropboxmap_find(const char *idname, int spaceid, int regionid)
void CTX_store_set(bContext *C, const bContextStore *store)
ReportList * CTX_wm_reports(const bContext *C)
void WM_event_add_mousemove(wmWindow *win)
static void wm_dragdrop_free_timer(wmWindowManager *wm, wmWindow *win)
void WM_drag_draw_default_fn(bContext *C, wmWindow *win, wmDrag *drag, const int xy[2])
bScreen * WM_window_get_active_screen(const wmWindow *win)
bool BLI_is_file(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:469
ARegion * CTX_wm_region(const bContext *C)
void WM_drag_free_list(ListBaseT< wmDrag > *lb)
void ED_region_tag_redraw_no_rebuild(ARegion *region)
Definition area.cc:727
static std::unique_ptr< bContextStore > wm_drop_ui_context_create(const bContext *C)
static void wm_drop_redalert_draw(const StringRef redalert_str, int x, int y)
void WM_drag_free(wmDrag *drag)
View3D * CTX_wm_view3d(const bContext *C)
ID * WM_drag_asset_id_import(const bContext *C, wmDragAsset *asset_drag, const int flag_extra)
static void wm_drag_draw_tooltip(bContext *C, wmWindow *win, wmDrag *drag, const int xy[2])
void CTX_wm_area_set(bContext *C, ScrArea *area)
static void wm_dropbox_item_update_ot(wmDropBox *drop)
static void wm_drag_draw_default(bContext *C, wmWindow *win, wmDrag *drag, const int xy[2])
uiWidgetColors wcol_tooltip
ThemeUI tui
bke::ARegionRuntime * runtime
eRegion_Type regiontype
The meta-data of an asset. By creating and giving this for a data-block (ID.asset_data),...
struct AssetMetaData * asset_data
Definition DNA_ID.h:424
const uint8_t * byte_data() const
StructRNA * type
Definition RNA_types.hh:63
ListBaseT< struct wmEventHandler > handlers
struct ARegion * active_region
ListBaseT< wmEventHandler > handlers
ListBaseT< wmEventHandler > handlers
std::unique_ptr< bContextStore > ui_context
Definition WM_types.hh:1408
std::optional< std::string > disabled_info
Definition WM_types.hh:1415
union blender::wmDragAssetListItem::@062304063216271107026210217273137152074304244210 asset_data
const asset_system::AssetRepresentation * asset
Definition WM_types.hh:1337
AssetImportSettings import_settings
Definition WM_types.hh:1338
Vector< std::string > paths
Definition WM_types.hh:1365
std::string tooltip
Definition WM_types.hh:1370
Vector< int > file_types
Definition WM_types.hh:1367
std::function< void(bContext &C, wmDrag &drag)> on_drag_start
wmDragActiveDropState drop_state
Definition WM_types.hh:1433
eWM_DragFlags flags
Definition WM_types.hh:1435
eWM_DragDataType type
Definition WM_types.hh:1424
const ImBuf * imb
Definition WM_types.hh:1428
ListBaseT< wmDragID > ids
Definition WM_types.hh:1438
ListBaseT< wmDragAssetListItem > asset_items
Definition WM_types.hh:1440
ListBaseT< wmDropBox > dropboxes
char idname[KMAP_MAX_NAME]
wmDropBoxMap * prev
wmDropBoxMap * next
void(*) draw_droptip(bContext *C, wmWindow *win, wmDrag *drag, const int xy[2])
Definition WM_types.hh:1488
IDProperty * properties
Definition WM_types.hh:1522
WMDropboxTooltipFunc tooltip
Definition WM_types.hh:1509
void(*) copy(bContext *C, wmDrag *drag, wmDropBox *drop)
Definition WM_types.hh:1475
PointerRNA * ptr
Definition WM_types.hh:1524
void(*) on_enter(wmDropBox *drop, wmDrag *drag)
Definition WM_types.hh:1466
bool(*) poll(bContext *C, wmDrag *drag, const wmEvent *event)
Definition WM_types.hh:1456
void(*) cancel(Main *bmain, wmDrag *drag, wmDropBox *drop)
Definition WM_types.hh:1481
void(*) on_drag_start(bContext *C, wmDrag *drag)
Definition WM_types.hh:1463
void(*) on_exit(wmDropBox *drop, wmDrag *drag)
Definition WM_types.hh:1472
void(*) draw_in_view(bContext *C, wmWindow *win, wmDrag *drag, const int xy[2])
Definition WM_types.hh:1496
wmOperatorType * ot
Definition WM_types.hh:1517
ListBaseT< wmDropBox > * dropboxes
wmEventType type
Definition WM_types.hh:817
bke::WindowRuntime * runtime
unsigned char inner[4]
unsigned char text[4]