/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Code/Tools/Libs/GuiFoundation/Widgets/Implementation/WidgetUtils.cpp
78 строк
3 KB
Jan Krassnigg
Migrate code to use Make* functions (#1022)
03 авг 2023, 08:07
Не верифицирован
03 авг 2023, 08:07
c42cf1d
Код
Авторство
О чём код?
#include <GuiFoundation/GuiFoundationPCH.h> #include <Foundation/Math/BoundingBox.h> #include <Foundation/Math/Declarations.h> #include <GuiFoundation/Widgets/WidgetUtils.h> #include <QApplication> #include <QRect> QScreen& ezWidgetUtils::GetClosestScreen(const QPoint& point) { QScreen* pClosestScreen = QApplication::screenAt(point); if (pClosestScreen == nullptr) { QList<QScreen*> screens = QApplication::screens(); float fShortestDistance = ezMath::Infinity<float>(); for (QScreen* pScreen : screens) { const QRect geom = pScreen->geometry(); ezBoundingBox ezGeom = ezBoundingBox::MakeFromCenterAndHalfExtents(ezVec3(geom.center().x(), geom.center().y(), 0), ezVec3(geom.width() / 2.0f, geom.height() / 2.0f, 0)); const ezVec3 ezPoint(point.x(), point.y(), 0); if (ezGeom.Contains(ezPoint)) { return *pScreen; } float fDistance = ezGeom.GetDistanceSquaredTo(ezPoint); if (fDistance < fShortestDistance) { fShortestDistance = fDistance; pClosestScreen = pScreen; } } EZ_ASSERT_DEV(pClosestScreen != nullptr, "There are no screens connected, UI cannot function."); } return *pClosestScreen; } void ezWidgetUtils::AdjustGridDensity( double& ref_fFinestDensity, double& ref_fRoughDensity, ezUInt32 uiWindowWidth, double fViewportSceneWidth, ezUInt32 uiMinPixelsForStep) { const double fMaxStepsFitInWindow = (double)uiWindowWidth / (double)uiMinPixelsForStep; const double fStartDensity = ref_fFinestDensity; ezInt32 iFactor = 1; double fNewDensity = ref_fFinestDensity; ezInt32 iFactors[2] = {5, 2}; ezInt32 iLastFactor = 0; while (true) { const double fStepsAtDensity = fViewportSceneWidth / fNewDensity; if (fStepsAtDensity < fMaxStepsFitInWindow) break; iFactor *= iFactors[iLastFactor]; fNewDensity = fStartDensity * iFactor; iLastFactor = (iLastFactor + 1) % 2; } ref_fFinestDensity = fStartDensity * iFactor; iFactor *= iFactors[iLastFactor]; ref_fRoughDensity = fStartDensity * iFactor; } void ezWidgetUtils::ComputeGridExtentsX(const QRectF& viewportSceneRect, double fGridStops, double& out_fMinX, double& out_fMaxX) { out_fMinX = ezMath::RoundDown((double)viewportSceneRect.left(), fGridStops); out_fMaxX = ezMath::RoundUp((double)viewportSceneRect.right(), fGridStops); } void ezWidgetUtils::ComputeGridExtentsY(const QRectF& viewportSceneRect, double fGridStops, double& out_fMinY, double& out_fMaxY) { out_fMinY = ezMath::RoundDown((double)viewportSceneRect.top(), fGridStops); out_fMaxY = ezMath::RoundUp((double)viewportSceneRect.bottom(), fGridStops); }