Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/windowing
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2024-09-11 19:52:01 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2024-09-11 19:52:01 +1000
commit3c4a2eb71eea73c7e505ab631a1abc484f9e7b92 (patch)
tree4f93ca3fec31a5768d168f47f40b6ff1e6a7b949 /source/windowing
parenta98ff51ef7384f9e7d51e821880e9420c8110cb6 (diff)
tooltip stuff
Diffstat (limited to 'source/windowing')
-rw-r--r--source/windowing/StarPaneManager.cpp44
-rw-r--r--source/windowing/StarPaneManager.hpp7
2 files changed, 24 insertions, 27 deletions
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<PaneLayer> 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<PaneLayer> 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<MouseButtonDownEvent>()) {
- 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;
};
}