diff --git a/lib/tlPlay/Viewport.cpp b/lib/tlPlay/Viewport.cpp index 6706357b..6d834ed6 100644 --- a/lib/tlPlay/Viewport.cpp +++ b/lib/tlPlay/Viewport.cpp @@ -4,6 +4,9 @@ #include +#include +#include + #include namespace tl @@ -15,29 +18,14 @@ namespace tl std::shared_ptr > hud; double fps = 0.0; size_t droppedFrames = 0; - std::vector text; - struct SizeData - { - int sizeInit = true; - int margin = 0; - int spacing = 0; - - bool textInit = true; - image::FontInfo fontInfo; - image::FontMetrics fontMetrics; - std::vector textSize; - }; - SizeData size; - - struct DrawData - { - std::vector > > glyphs; - }; - DrawData draw; + std::shared_ptr fpsLabel; + std::shared_ptr colorPickerLabel; + std::shared_ptr hudLayout; std::shared_ptr > fpsObserver; std::shared_ptr > droppedFramesObserver; + std::shared_ptr > colorPickerObserver; }; void Viewport::_init( @@ -46,7 +34,21 @@ namespace tl { TimelineViewport::_init(context, parent); TLRENDER_P(); + p.hud = observer::Value::create(false); + + p.fpsLabel = ui::Label::create(context); + p.fpsLabel->setMarginRole(ui::SizeRole::MarginInside); + p.fpsLabel->setBackgroundRole(ui::ColorRole::Base); + + p.colorPickerLabel = ui::Label::create(context); + + p.hudLayout = ui::GridLayout::create(context, shared_from_this()); + p.hudLayout->setMarginRole(ui::SizeRole::MarginSmall); + p.fpsLabel->setParent(p.hudLayout); + p.hudLayout->setGridPos(p.fpsLabel, 0, 0); + p.hudLayout->hide(); + p.fpsObserver = observer::ValueObserver::create( observeFPS(), [this](double value) @@ -61,6 +63,11 @@ namespace tl _p->droppedFrames = value; _textUpdate(); }); + p.colorPickerObserver = observer::ValueObserver::create( + observeColorPicker(), + [this](const image::Color4f& value) + { + }); } Viewport::Viewport() : @@ -94,101 +101,31 @@ namespace tl TLRENDER_P(); if (p.hud->setIfChanged(value)) { - _updates |= ui::Update::Draw; - } - } - - void Viewport::sizeHintEvent(const ui::SizeHintEvent& event) - { - const bool displayScaleChanged = event.displayScale != _displayScale; - TimelineViewport::sizeHintEvent(event); - TLRENDER_P(); - - if (displayScaleChanged || p.size.sizeInit) - { - p.size.margin = event.style->getSizeRole(ui::SizeRole::MarginSmall, _displayScale); - p.size.spacing = event.style->getSizeRole(ui::SizeRole::SpacingSmall, _displayScale); + p.hudLayout->setVisible(value); } - if (displayScaleChanged || p.size.textInit || p.size.sizeInit) - { - p.size.fontInfo = event.style->getFontRole(ui::FontRole::Mono, _displayScale); - p.size.fontMetrics = event.fontSystem->getMetrics(p.size.fontInfo); - p.size.textSize.clear(); - for (const auto& text : p.text) - { - p.size.textSize.push_back( - event.fontSystem->getSize(text, p.size.fontInfo)); - } - p.draw.glyphs.clear(); - } - p.size.sizeInit = false; - p.size.textInit = false; } - void Viewport::clipEvent(const math::Box2i& clipRect, bool clipped) + void Viewport::setGeometry(const math::Box2i& value) { - TimelineViewport::clipEvent(clipRect, clipped); + TimelineViewport::setGeometry(value); TLRENDER_P(); - if (clipped) - { - p.draw.glyphs.clear(); - } + p.hudLayout->setGeometry(value); } - void Viewport::drawEvent( - const math::Box2i& drawRect, - const ui::DrawEvent& event) + void Viewport::sizeHintEvent(const ui::SizeHintEvent& event) { - TimelineViewport::drawEvent(drawRect, event); + TimelineViewport::sizeHintEvent(event); TLRENDER_P(); - const math::Box2i& g = _geometry; - if (p.hud->get()) - { - if (!p.text.empty() && p.draw.glyphs.empty()) - { - for (const auto& text : p.text) - { - p.draw.glyphs.push_back( - event.fontSystem->getGlyphs(text, p.size.fontInfo)); - } - } - - const math::Box2i g2 = g.margin(-p.size.margin); - int x = g2.min.x; - int y = g2.min.y; - for (size_t i = 0; - i < p.text.size() && i < p.size.textSize.size() && i < p.draw.glyphs.size(); - ++i) - { - const math::Box2i g3( - x, - y, - p.size.textSize[i].w + p.size.margin * 2, - p.size.textSize[i].h + p.size.margin * 2); - event.render->drawRect(g3, event.style->getColorRole(ui::ColorRole::Base)); - const math::Vector2i pos( - g3.min.x + p.size.margin, - g3.min.y + p.size.margin + p.size.fontMetrics.ascender); - event.render->drawText( - p.draw.glyphs[i], - pos, - event.style->getColorRole(ui::ColorRole::Text)); - y += g3.h(); - } - } + _sizeHint = p.hudLayout->getSizeHint(); } void Viewport::_textUpdate() { TLRENDER_P(); - p.text.clear(); - p.text.push_back( + p.fpsLabel->setText( string::Format("FPS: {0} ({1} dropped)"). arg(p.fps, 2, 4). arg(p.droppedFrames)); - p.size.textInit = true; - _updates |= ui::Update::Size; - _updates |= ui::Update::Draw; } } } diff --git a/lib/tlPlay/Viewport.h b/lib/tlPlay/Viewport.h index 25858fcf..e321276b 100644 --- a/lib/tlPlay/Viewport.h +++ b/lib/tlPlay/Viewport.h @@ -37,9 +37,8 @@ namespace tl //! Set whether the HUD is enabled. void setHUD(bool); + void setGeometry(const math::Box2i&) override; void sizeHintEvent(const ui::SizeHintEvent&) override; - void clipEvent(const math::Box2i&, bool) override; - void drawEvent(const math::Box2i&, const ui::DrawEvent&) override; private: void _textUpdate(); diff --git a/lib/tlQtWidget/ContainerWidget.cpp b/lib/tlQtWidget/ContainerWidget.cpp index e3479fc2..f5fa6cb9 100644 --- a/lib/tlQtWidget/ContainerWidget.cpp +++ b/lib/tlQtWidget/ContainerWidget.cpp @@ -319,7 +319,7 @@ namespace tl { TLRENDER_P(); const math::Size2i renderSize(_toUI(width()), _toUI(height())); - if (_getDrawUpdate(p.window)) + if (_hasDrawUpdate(p.window)) { try { @@ -688,7 +688,7 @@ namespace tl widget->tickEvent(visible, enabled, event); } - bool ContainerWidget::_getSizeUpdate(const std::shared_ptr& widget) const + bool ContainerWidget::_hasSizeUpdate(const std::shared_ptr& widget) const { bool out = widget->getUpdates() & ui::Update::Size; if (out) @@ -699,7 +699,7 @@ namespace tl { for (const auto& child : widget->getChildren()) { - out |= _getSizeUpdate(child); + out |= _hasSizeUpdate(child); } } return out; @@ -764,7 +764,7 @@ namespace tl } } - bool ContainerWidget::_getDrawUpdate(const std::shared_ptr& widget) const + bool ContainerWidget::_hasDrawUpdate(const std::shared_ptr& widget) const { bool out = false; if (!widget->isClipped()) @@ -778,7 +778,7 @@ namespace tl { for (const auto& child : widget->getChildren()) { - out |= _getDrawUpdate(child); + out |= _hasDrawUpdate(child); } } } @@ -854,14 +854,14 @@ namespace tl if (_p) { _tickEvent(); - if (_getSizeUpdate(_p->window)) + if (_hasSizeUpdate(_p->window)) { _sizeHintEvent(); _setGeometry(); _clipEvent(); updateGeometry(); } - if (_getDrawUpdate(_p->window)) + if (_hasDrawUpdate(_p->window)) { update(); } diff --git a/lib/tlQtWidget/ContainerWidget.h b/lib/tlQtWidget/ContainerWidget.h index 4e0b3ac8..3c702dcf 100644 --- a/lib/tlQtWidget/ContainerWidget.h +++ b/lib/tlQtWidget/ContainerWidget.h @@ -71,7 +71,7 @@ namespace tl bool enabled, const ui::TickEvent&); - bool _getSizeUpdate(const std::shared_ptr&) const; + bool _hasSizeUpdate(const std::shared_ptr&) const; void _sizeHintEvent(); void _sizeHintEvent( const std::shared_ptr&, @@ -85,7 +85,7 @@ namespace tl const math::Box2i&, bool clipped); - bool _getDrawUpdate(const std::shared_ptr&) const; + bool _hasDrawUpdate(const std::shared_ptr&) const; void _drawEvent( const std::shared_ptr&, const math::Box2i&,