2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2021-09-30 16:26:56 +02:00
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
|
* \ingroup edinterface
|
|
|
|
|
*/
|
|
|
|
|
|
2024-01-19 10:45:33 -05:00
|
|
|
#include <fmt/format.h>
|
|
|
|
|
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_context.hh"
|
2025-02-07 17:47:16 +01:00
|
|
|
#include "BKE_library.hh"
|
2021-09-30 16:26:56 +02:00
|
|
|
|
2024-02-09 18:59:42 +01:00
|
|
|
#include "BLT_translation.hh"
|
2022-03-03 15:28:48 -08:00
|
|
|
|
|
|
|
|
#include "DNA_material_types.h"
|
2022-03-04 10:35:22 +11:00
|
|
|
#include "DNA_space_types.h"
|
2021-09-30 16:26:56 +02:00
|
|
|
|
2021-10-26 18:48:24 +02:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2023-08-10 22:40:27 +02:00
|
|
|
#include "RNA_access.hh"
|
2024-07-10 18:30:02 +02:00
|
|
|
#include "RNA_prototypes.hh"
|
2021-10-27 15:50:14 +02:00
|
|
|
|
2023-08-04 23:11:22 +02:00
|
|
|
#include "WM_api.hh"
|
2021-09-30 16:26:56 +02:00
|
|
|
|
2023-03-22 18:45:35 +01:00
|
|
|
#include "UI_interface.hh"
|
|
|
|
|
|
|
|
|
|
using namespace blender::ui;
|
2021-09-30 16:26:56 +02:00
|
|
|
|
2022-03-04 10:35:22 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
/** \name View Drag/Drop Callbacks
|
2022-03-04 10:35:22 +11:00
|
|
|
* \{ */
|
|
|
|
|
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
static bool ui_view_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
|
2021-09-30 16:26:56 +02:00
|
|
|
{
|
|
|
|
|
const ARegion *region = CTX_wm_region(C);
|
2023-03-22 18:45:35 +01:00
|
|
|
|
2023-03-23 14:28:50 +11:00
|
|
|
std::unique_ptr<DropTargetInterface> drop_target = region_views_find_drop_target_at(region,
|
|
|
|
|
event->xy);
|
2023-03-22 18:45:35 +01:00
|
|
|
if (!drop_target) {
|
2021-09-30 16:26:56 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-04 12:10:58 +01:00
|
|
|
if (drag->drop_state.free_disabled_info) {
|
|
|
|
|
MEM_SAFE_FREE(drag->drop_state.disabled_info);
|
2021-10-26 18:48:24 +02:00
|
|
|
}
|
2021-11-04 12:10:58 +01:00
|
|
|
drag->drop_state.free_disabled_info = false;
|
2023-03-22 18:45:35 +01:00
|
|
|
|
|
|
|
|
return drop_target->can_drop(*drag, &drag->drop_state.disabled_info);
|
2021-09-30 16:26:56 +02:00
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:45:33 -05:00
|
|
|
static std::string ui_view_drop_tooltip(bContext *C,
|
|
|
|
|
wmDrag *drag,
|
|
|
|
|
const int xy[2],
|
|
|
|
|
wmDropBox * /*drop*/)
|
2021-09-30 16:26:56 +02:00
|
|
|
{
|
UI: Basic tree-view drag & drop reordering and inserting support
No user visible changes expected, these are just the internal API preparations.
Modifies the Drop API for views so that tree-views can choose to insert items
before, after and into other items.
Note: While there is support for drag-tooltips that can explain how an item
will be inserted, there is no drawing yet like in the Outliner, that indicates
if an item is inserted before, after or into. There is some work on that but
that can be done separately.
Changes:
- Removes `AbstractViewDropTarget` that was shared between tree- and
grid-views, and adds `AbstractTreeViewDropTarget` and
`AbstractGridViewDropTarget`. The tree-view needs specialized handling now,
and although they could share some code still, it's not worth having another
level of inheritance.
- Modifies the drop-target API to use `DragInfo` which contains more info about
the dragging operation than just the `wmDrag`.
- Adds `determine_drop_location()` to the `DropTargetInterface` which drop
targets can use to determine when dropping means inserting before, after or
into.
- Store the block and region in the view. This is needed unfortunately but
shouldn't be an issue since the tree view is recreated on redraws, together
with the block.
- Various smaller tweaks and additions to views as needed.
TODO (outside scope of this change): Increase row height so there is no gap
between tree view items, but keep things visually the same otherwise. This
reduces flickering while dragging.
Pull Request: https://projects.blender.org/blender/blender/pulls/109825
2023-07-11 14:30:26 +02:00
|
|
|
const wmWindow *win = CTX_wm_window(C);
|
2021-09-30 16:26:56 +02:00
|
|
|
const ARegion *region = CTX_wm_region(C);
|
2023-03-23 14:28:50 +11:00
|
|
|
std::unique_ptr<DropTargetInterface> drop_target = region_views_find_drop_target_at(region, xy);
|
2021-09-30 16:26:56 +02:00
|
|
|
|
2024-02-16 17:39:21 +01:00
|
|
|
if (drop_target == nullptr) {
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
UI: Basic tree-view drag & drop reordering and inserting support
No user visible changes expected, these are just the internal API preparations.
Modifies the Drop API for views so that tree-views can choose to insert items
before, after and into other items.
Note: While there is support for drag-tooltips that can explain how an item
will be inserted, there is no drawing yet like in the Outliner, that indicates
if an item is inserted before, after or into. There is some work on that but
that can be done separately.
Changes:
- Removes `AbstractViewDropTarget` that was shared between tree- and
grid-views, and adds `AbstractTreeViewDropTarget` and
`AbstractGridViewDropTarget`. The tree-view needs specialized handling now,
and although they could share some code still, it's not worth having another
level of inheritance.
- Modifies the drop-target API to use `DragInfo` which contains more info about
the dragging operation than just the `wmDrag`.
- Adds `determine_drop_location()` to the `DropTargetInterface` which drop
targets can use to determine when dropping means inserting before, after or
into.
- Store the block and region in the view. This is needed unfortunately but
shouldn't be an issue since the tree view is recreated on redraws, together
with the block.
- Various smaller tweaks and additions to views as needed.
TODO (outside scope of this change): Increase row height so there is no gap
between tree view items, but keep things visually the same otherwise. This
reduces flickering while dragging.
Pull Request: https://projects.blender.org/blender/blender/pulls/109825
2023-07-11 14:30:26 +02:00
|
|
|
return drop_target_tooltip(*region, *drop_target, *drag, *win->eventstate);
|
2021-09-30 16:26:56 +02:00
|
|
|
}
|
|
|
|
|
|
2022-03-04 10:35:22 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Name Drag/Drop Callbacks
|
|
|
|
|
* \{ */
|
2021-10-27 15:50:14 +02:00
|
|
|
|
2023-06-03 08:36:28 +10:00
|
|
|
static bool ui_drop_name_poll(bContext *C, wmDrag *drag, const wmEvent * /*event*/)
|
2021-10-27 15:50:14 +02:00
|
|
|
{
|
|
|
|
|
return UI_but_active_drop_name(C) && (drag->type == WM_DRAG_ID);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
static void ui_drop_name_copy(bContext * /*C*/, wmDrag *drag, wmDropBox *drop)
|
2021-10-27 15:50:14 +02:00
|
|
|
{
|
|
|
|
|
const ID *id = WM_drag_get_local_ID(drag, 0);
|
|
|
|
|
RNA_string_set(drop->ptr, "string", id->name + 2);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-15 17:29:54 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
2022-03-04 10:35:22 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Material Drag/Drop Callbacks
|
|
|
|
|
* \{ */
|
2022-03-03 15:28:48 -08:00
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
static bool ui_drop_material_poll(bContext *C, wmDrag *drag, const wmEvent * /*event*/)
|
2022-03-03 15:28:48 -08:00
|
|
|
{
|
|
|
|
|
PointerRNA mat_slot = CTX_data_pointer_get_type(C, "material_slot", &RNA_MaterialSlot);
|
2024-10-17 14:54:45 +02:00
|
|
|
if (RNA_pointer_is_null(&mat_slot)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
PointerRNA ob_ptr = CTX_data_pointer_get_type(C, "object", &RNA_Object);
|
|
|
|
|
if (RNA_pointer_is_null(&ob_ptr)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Object *ob = static_cast<Object *>(ob_ptr.data);
|
|
|
|
|
|
|
|
|
|
return WM_drag_is_ID_type(drag, ID_MA) && ID_IS_EDITABLE(&ob->id) &&
|
|
|
|
|
!ID_IS_OVERRIDE_LIBRARY(&ob->id);
|
2022-03-03 15:28:48 -08:00
|
|
|
}
|
|
|
|
|
|
2023-07-28 12:16:52 +02:00
|
|
|
static void ui_drop_material_copy(bContext *C, wmDrag *drag, wmDropBox *drop)
|
2022-03-03 15:28:48 -08:00
|
|
|
{
|
2023-07-28 12:16:52 +02:00
|
|
|
const ID *id = WM_drag_get_local_ID_or_import_from_asset(C, drag, ID_MA);
|
2024-01-22 13:47:13 +01:00
|
|
|
RNA_int_set(drop->ptr, "session_uid", int(id->session_uid));
|
2022-03-03 15:28:48 -08:00
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:45:33 -05:00
|
|
|
static std::string ui_drop_material_tooltip(bContext *C,
|
|
|
|
|
wmDrag *drag,
|
|
|
|
|
const int /*xy*/[2],
|
|
|
|
|
wmDropBox * /*drop*/)
|
2022-03-03 15:28:48 -08:00
|
|
|
{
|
|
|
|
|
PointerRNA rna_ptr = CTX_data_pointer_get_type(C, "object", &RNA_Object);
|
|
|
|
|
Object *ob = (Object *)rna_ptr.data;
|
|
|
|
|
BLI_assert(ob);
|
|
|
|
|
|
|
|
|
|
PointerRNA mat_slot = CTX_data_pointer_get_type(C, "material_slot", &RNA_MaterialSlot);
|
|
|
|
|
BLI_assert(mat_slot.data);
|
|
|
|
|
|
|
|
|
|
const int target_slot = RNA_int_get(&mat_slot, "slot_index") + 1;
|
|
|
|
|
|
|
|
|
|
PointerRNA rna_prev_material = RNA_pointer_get(&mat_slot, "material");
|
|
|
|
|
Material *prev_mat_in_slot = (Material *)rna_prev_material.data;
|
|
|
|
|
const char *dragged_material_name = WM_drag_get_item_name(drag);
|
|
|
|
|
|
|
|
|
|
if (prev_mat_in_slot) {
|
2024-11-20 10:41:29 +01:00
|
|
|
return fmt::format(fmt::runtime(TIP_("Drop {} on slot {} (replacing {}) of {}")),
|
2024-01-19 10:45:33 -05:00
|
|
|
dragged_material_name,
|
|
|
|
|
target_slot,
|
|
|
|
|
prev_mat_in_slot->id.name + 2,
|
|
|
|
|
ob->id.name + 2);
|
2022-03-03 15:28:48 -08:00
|
|
|
}
|
2024-01-19 10:45:33 -05:00
|
|
|
if (target_slot == ob->actcol) {
|
2024-11-20 10:41:29 +01:00
|
|
|
return fmt::format(fmt::runtime(TIP_("Drop {} on slot {} (active slot) of {}")),
|
2024-01-19 10:45:33 -05:00
|
|
|
dragged_material_name,
|
|
|
|
|
target_slot,
|
|
|
|
|
ob->id.name + 2);
|
2022-03-03 15:28:48 -08:00
|
|
|
}
|
2024-11-20 10:41:29 +01:00
|
|
|
return fmt::format(fmt::runtime(TIP_("Drop {} on slot {} of {}")),
|
|
|
|
|
dragged_material_name,
|
|
|
|
|
target_slot,
|
|
|
|
|
ob->id.name + 2);
|
2022-03-03 15:28:48 -08:00
|
|
|
}
|
|
|
|
|
|
2022-03-04 10:35:22 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
2022-03-03 15:28:48 -08:00
|
|
|
/* -------------------------------------------------------------------- */
|
2022-03-04 10:35:22 +11:00
|
|
|
/** \name Add User Interface Drop Boxes
|
|
|
|
|
* \{ */
|
2021-10-27 15:50:14 +02:00
|
|
|
|
2021-09-30 16:26:56 +02:00
|
|
|
void ED_dropboxes_ui()
|
|
|
|
|
{
|
2023-09-14 13:32:42 +10:00
|
|
|
ListBase *lb = WM_dropboxmap_find("User Interface", SPACE_EMPTY, RGN_TYPE_WINDOW);
|
2021-09-30 16:26:56 +02:00
|
|
|
|
UI: Port view item features to base class, merge view item button types
No user visible changes expected.
Merges the tree row and grid tile button types, which were mostly doing
the same things. The idea is that there is a button type for
highlighting, as well as supporting general view item features (e.g.
renaming, drag/drop, etc.). So instead there is a view item button type
now. Also ports view item features like renaming, custom context menus,
drag controllers and drop controllers to `ui::AbstractViewItem` (the new
base class for all view items).
This should be quite an improvement because:
- Merges code that was duplicated over view items.
- Mentioned features (renaming, drag & drop, ...) are much easier to
implement in new view types now. Most of it comes "for free".
- Further features will immediately become availalbe to all views (e.g.
selection).
- Simplifies APIs, there don't have to be functions for individual view
item types anymore.
- View item classes are split and thus less overwhelming visually.
- View item buttons now share all code (drawing, handling, etc.)
- We're soon running out of available button types, this commit merges
two into one.
I was hoping I could do this in multiple smaller commits, but things
were quite intertwined so that would've taken quite some effort.
2022-07-19 16:14:42 +02:00
|
|
|
WM_dropbox_add(lb, "UI_OT_view_drop", ui_view_drop_poll, nullptr, nullptr, ui_view_drop_tooltip);
|
2021-10-27 15:50:14 +02:00
|
|
|
WM_dropbox_add(lb,
|
|
|
|
|
"UI_OT_drop_name",
|
|
|
|
|
ui_drop_name_poll,
|
|
|
|
|
ui_drop_name_copy,
|
|
|
|
|
WM_drag_free_imported_drag_ID,
|
|
|
|
|
nullptr);
|
2022-03-03 15:28:48 -08:00
|
|
|
WM_dropbox_add(lb,
|
|
|
|
|
"UI_OT_drop_material",
|
|
|
|
|
ui_drop_material_poll,
|
|
|
|
|
ui_drop_material_copy,
|
|
|
|
|
WM_drag_free_imported_drag_ID,
|
|
|
|
|
ui_drop_material_tooltip);
|
2021-09-30 16:26:56 +02:00
|
|
|
}
|
2022-03-04 10:35:22 +11:00
|
|
|
|
|
|
|
|
/** \} */
|