/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Code/Editor/EditorFramework/DragDrop/Implementation/DragDropHandler.cpp
119 строк
3 KB
Ingrater
Clang-format fixes and update to 18.1.1 (#1234)
10 мар 2024, 15:51
Не верифицирован
10 мар 2024, 15:51
2f16acf
Код
Авторство
О чём код?
#include <EditorFramework/EditorFrameworkPCH.h> #include <EditorFramework/DragDrop/DragDropHandler.h> EZ_BEGIN_DYNAMIC_REFLECTED_TYPE(ezDragDropHandler, 1, ezRTTINoAllocator) EZ_END_DYNAMIC_REFLECTED_TYPE; ezDragDropHandler* ezDragDropHandler::s_pActiveDnD = nullptr; ezDragDropHandler::ezDragDropHandler() = default; ezDragDropHandler* ezDragDropHandler::FindDragDropHandler(const ezDragDropInfo* pInfo) { float fBestValue = 0.0f; ezDragDropHandler* pBestDnD = nullptr; ezRTTI::ForEachDerivedType<ezDragDropHandler>( [&](const ezRTTI* pRtti) { ezDragDropHandler* pDnD = pRtti->GetAllocator()->Allocate<ezDragDropHandler>(); const float fValue = pDnD->CanHandle(pInfo); if (fValue > fBestValue) { if (pBestDnD != nullptr) { pBestDnD->GetDynamicRTTI()->GetAllocator()->Deallocate(pBestDnD); } fBestValue = fValue; pBestDnD = pDnD; } else { pDnD->GetDynamicRTTI()->GetAllocator()->Deallocate(pDnD); } }, ezRTTI::ForEachOptions::ExcludeNonAllocatable); return pBestDnD; } bool ezDragDropHandler::BeginDragDropOperation(const ezDragDropInfo* pInfo, ezDragDropConfig* pConfigToFillOut) { EZ_ASSERT_DEV(s_pActiveDnD == nullptr, "A drag & drop handler is already active"); ezDragDropHandler* pHandler = FindDragDropHandler(pInfo); if (pHandler != nullptr) { if (pConfigToFillOut != nullptr) pHandler->RequestConfiguration(pConfigToFillOut); s_pActiveDnD = pHandler; s_pActiveDnD->OnDragBegin(pInfo); return true; } return false; } void ezDragDropHandler::UpdateDragDropOperation(const ezDragDropInfo* pInfo) { if (s_pActiveDnD == nullptr) return; s_pActiveDnD->OnDragUpdate(pInfo); } void ezDragDropHandler::FinishDragDrop(const ezDragDropInfo* pInfo) { if (s_pActiveDnD == nullptr) return; s_pActiveDnD->OnDrop(pInfo); s_pActiveDnD->GetDynamicRTTI()->GetAllocator()->Deallocate(s_pActiveDnD); s_pActiveDnD = nullptr; } void ezDragDropHandler::CancelDragDrop() { if (s_pActiveDnD == nullptr) return; s_pActiveDnD->OnDragCancel(); s_pActiveDnD->GetDynamicRTTI()->GetAllocator()->Deallocate(s_pActiveDnD); s_pActiveDnD = nullptr; } bool ezDragDropHandler::CanDropOnly(const ezDragDropInfo* pInfo) { EZ_ASSERT_DEV(s_pActiveDnD == nullptr, "A drag & drop handler is already active"); ezDragDropHandler* pHandler = FindDragDropHandler(pInfo); if (pHandler != nullptr) { pHandler->GetDynamicRTTI()->GetAllocator()->Deallocate(pHandler); return true; } return false; } bool ezDragDropHandler::DropOnly(const ezDragDropInfo* pInfo) { EZ_ASSERT_DEV(s_pActiveDnD == nullptr, "A drag & drop handler is already active"); if (BeginDragDropOperation(pInfo)) { FinishDragDrop(pInfo); return true; } return false; }