From 3c4a2eb71eea73c7e505ab631a1abc484f9e7b92 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Wed, 11 Sep 2024 19:52:01 +1000 Subject: [PATCH] tooltip stuff --- source/core/StarFont.cpp | 2 +- source/core/StarImageProcessing.cpp | 2 +- source/windowing/StarPaneManager.cpp | 44 +++++++++++++--------------- source/windowing/StarPaneManager.hpp | 7 ++--- 4 files changed, 26 insertions(+), 29 deletions(-) diff --git a/source/core/StarFont.cpp b/source/core/StarFont.cpp index 07a6265..b0d20fc 100644 --- a/source/core/StarFont.cpp +++ b/source/core/StarFont.cpp @@ -135,7 +135,7 @@ tuple Font::render(String::Char c) { } } } - } else if (colored = slot->bitmap.pixel_mode == FT_PIXEL_MODE_BGRA) { + } else if (colored = (slot->bitmap.pixel_mode == FT_PIXEL_MODE_BGRA)) { unsigned bpp = image.bytesPerPixel(); uint8_t* data = image.data() + bpp + ((image.width() * (image.height() - 2)) * bpp); // offset by 1 pixel as it's padded for (size_t y = 0; y != height; ++y) { diff --git a/source/core/StarImageProcessing.cpp b/source/core/StarImageProcessing.cpp index 6d2c51d..390f600 100644 --- a/source/core/StarImageProcessing.cpp +++ b/source/core/StarImageProcessing.cpp @@ -214,7 +214,7 @@ ImageOperation imageOperationFromString(StringView string) { else // we're in A of A=B. In vanilla only A=B pairs are evaluated, so only throw an error if B is also there. return operation; - if (which = !which) + if ((which = !which)) operation.colorReplaceMap[*(Vec4B*)&a] = *(Vec4B*)&b; hexLen = 0; diff --git a/source/windowing/StarPaneManager.cpp b/source/windowing/StarPaneManager.cpp index 0bdc159..d8a727a 100644 --- a/source/windowing/StarPaneManager.cpp +++ b/source/windowing/StarPaneManager.cpp @@ -17,11 +17,9 @@ EnumMap const PaneLayerNames{ PaneManager::PaneManager() : m_context(GuiContext::singletonPtr()), m_prevInterfaceScale(1) { auto assets = Root::singleton().assets(); - m_tooltipMouseoverTime = assets->json("/panes.config:tooltipMouseoverTime").toFloat(); m_tooltipMouseoverRadius = assets->json("/panes.config:tooltipMouseoverRadius").toFloat(); m_tooltipMouseOffset = jsonToVec2I(assets->json("/panes.config:tooltipMouseoverOffset")); - - m_tooltipShowTimer = m_tooltipMouseoverTime; + m_tooltipShowTimer = GameTimer(assets->json("/panes.config:tooltipMouseoverTime").toFloat()); } void PaneManager::displayPane(PaneLayer paneLayer, PanePtr const& pane, DismissCallback onDismiss) { @@ -124,7 +122,9 @@ PanePtr PaneManager::getPaneAt(Set const& paneLayers, Vec2I const& po PanePtr PaneManager::getPaneAt(Vec2I const& position) const { for (auto const& layerPair : m_displayedPanes) { for (auto const& panePair : layerPair.second) { - if (panePair.first->inWindow(position) && panePair.first->active()) + if (panePair.first != m_activeTooltip + && panePair.first->inWindow(position) + && panePair.first->active()) return panePair.first; } } @@ -185,12 +185,12 @@ bool PaneManager::sendInputEvent(InputEvent const& event) { } if (event.is()) { - m_tooltipShowTimer = m_tooltipMouseoverTime; + m_tooltipShowTimer.reset(); if (m_activeTooltip) { dismiss(m_activeTooltip); m_activeTooltip.reset(); m_tooltipParentPane.reset(); - m_tooltipShowTimer = m_tooltipMouseoverTime; + m_tooltipShowTimer.reset(); } } @@ -270,29 +270,27 @@ void PaneManager::render() { } void PaneManager::update(float dt) { - m_tooltipShowTimer -= GlobalTimestep; - if (m_tooltipParentPane.expired()) - m_tooltipParentPane.reset(); + auto newTooltipParentPane = getPaneAt(m_tooltipLastMousePos); - bool removeTooltip = vmag(m_tooltipInitialPosition - m_tooltipLastMousePos) > m_tooltipMouseoverRadius - || m_tooltipParentPane.expired() || m_tooltipParentPane.lock()->inWindow(m_tooltipLastMousePos); + bool updateTooltip = m_tooltipShowTimer.tick(dt) || (m_activeTooltip && ( + vmag(m_tooltipInitialPosition - m_tooltipLastMousePos) > m_tooltipMouseoverRadius + || m_tooltipParentPane != newTooltipParentPane + || !m_tooltipParentPane->inWindow(m_tooltipLastMousePos))); - if (removeTooltip) { - dismiss(m_activeTooltip); - m_activeTooltip.reset(); - m_tooltipParentPane.reset(); - } + if (updateTooltip) { + if (m_activeTooltip) { + dismiss(m_activeTooltip); + m_activeTooltip.reset(); + m_tooltipParentPane.reset(); + } - // Scan for a new tooltip if we just removed the old one, or the show timer has expired - if (removeTooltip || (m_tooltipShowTimer < 0 && !m_activeTooltip)) { - if (auto parentPane = getPaneAt(m_tooltipLastMousePos)) { - if (auto tooltip = parentPane->createTooltip(m_tooltipLastMousePos)) { + m_tooltipShowTimer.reset(); + if (newTooltipParentPane) { + if (auto tooltip = newTooltipParentPane->createTooltip(m_tooltipLastMousePos)) { m_activeTooltip = std::move(tooltip); - m_tooltipParentPane = std::move(parentPane); + m_tooltipParentPane = std::move(newTooltipParentPane); m_tooltipInitialPosition = m_tooltipLastMousePos; displayPane(PaneLayer::Tooltip, m_activeTooltip); - } else { - m_tooltipShowTimer = m_tooltipMouseoverTime; } } } diff --git a/source/windowing/StarPaneManager.hpp b/source/windowing/StarPaneManager.hpp index b6d1032..3d507f3 100644 --- a/source/windowing/StarPaneManager.hpp +++ b/source/windowing/StarPaneManager.hpp @@ -3,6 +3,7 @@ #include "StarPane.hpp" #include "StarOrderedMap.hpp" #include "StarBiMap.hpp" +#include "StarGameTimers.hpp" namespace Star { @@ -92,15 +93,13 @@ private: WidgetPtr m_backgroundWidget; - float m_tooltipMouseoverTime; float m_tooltipMouseoverRadius; Vec2I m_tooltipMouseOffset; - - float m_tooltipShowTimer; + GameTimer m_tooltipShowTimer; Vec2I m_tooltipLastMousePos; Vec2I m_tooltipInitialPosition; PanePtr m_activeTooltip; - PaneWeakPtr m_tooltipParentPane; + PanePtr m_tooltipParentPane; }; }