/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Code/Tools/Libs/GuiFoundation/Widgets/Implementation/GridBarWidget.cpp
114 строк
3 KB
C-Core
Array usage cleanup (#1864)
11 мар 2026, 23:44
Не верифицирован
11 мар 2026, 23:44
f7cb730
Код
Авторство
О чём код?
#include <GuiFoundation/GuiFoundationPCH.h> #include <Foundation/Containers/HybridArray.h> #include <Foundation/Math/Math.h> #include <Foundation/Strings/StringBuilder.h> #include <GuiFoundation/Widgets/GridBarWidget.moc.h> #include <GuiFoundation/Widgets/WidgetUtils.h> #include <QPainter> #include <QTextOption> #include <qevent.h> ezQGridBarWidget::ezQGridBarWidget(QWidget* pParent) : QWidget(pParent) { m_ViewportSceneRect.setRect(0, 1, 1, 1); m_fFineGridStops = 10; m_fTextGridStops = 100; } void ezQGridBarWidget::SetConfig( const QRectF& viewportSceneRect, double fTextGridStops, double fFineGridStops, ezDelegate<QPointF(const QPointF&)> mapFromSceneFunc) { m_MapFromSceneFunc = mapFromSceneFunc; bool bUpdate = false; if (m_ViewportSceneRect != viewportSceneRect) { m_ViewportSceneRect = viewportSceneRect; bUpdate = true; } if (m_fTextGridStops != fTextGridStops) { m_fTextGridStops = fTextGridStops; bUpdate = true; } if (m_fFineGridStops != fFineGridStops) { m_fFineGridStops = fFineGridStops; bUpdate = true; } if (bUpdate) { update(); } } void ezQGridBarWidget::paintEvent(QPaintEvent* e) { if (!m_MapFromSceneFunc.IsValid()) { QWidget::paintEvent(e); return; } QPainter Painter(this); QPainter* painter = &Painter; painter->setRenderHint(QPainter::Antialiasing); painter->setRenderHint(QPainter::TextAntialiasing); QRect areaRect = rect(); // background painter->fillRect(areaRect, palette().button()); painter->translate(0.5, 0.5); // render fine grid stop lines { double fSceneMinX, fSceneMaxX; ezWidgetUtils::ComputeGridExtentsX(m_ViewportSceneRect, m_fFineGridStops, fSceneMinX, fSceneMaxX); fSceneMinX = ezMath::Max(fSceneMinX, 0.0); painter->setPen(palette().buttonText().color()); ezTempHybridArray<QLine, 100> lines; // some overcompensation for the case that the GraphicsView displays a scrollbar at the side for (double x = fSceneMinX; x <= fSceneMaxX + m_fTextGridStops; x += m_fFineGridStops) { const QPointF pos = m_MapFromSceneFunc(QPointF(x, 0)); QLine& l = lines.ExpandAndGetRef(); l.setLine(pos.x(), areaRect.bottom() - 3, pos.x(), areaRect.bottom()); } painter->drawLines(lines.GetData(), lines.GetCount()); } // Grid Stop Value Text { double fSceneMinX, fSceneMaxX; ezWidgetUtils::ComputeGridExtentsX(m_ViewportSceneRect, m_fTextGridStops, fSceneMinX, fSceneMaxX); fSceneMinX = ezMath::Max(fSceneMinX, 0.0); QTextOption textOpt(Qt::AlignCenter); QRectF textRect; painter->setPen(palette().buttonText().color()); ezStringBuilder tmp; for (double x = fSceneMinX; x <= fSceneMaxX; x += m_fTextGridStops) { const QPointF pos = m_MapFromSceneFunc(QPointF(x, 0)); textRect.setRect(pos.x() - 50, areaRect.top(), 99, areaRect.height()); tmp.SetFormat("{0}", ezArgF(x)); painter->drawText(textRect, tmp.GetData(), textOpt); } } }