tooltip stuff
This commit is contained in:
parent
a98ff51ef7
commit
3c4a2eb71e
@ -135,7 +135,7 @@ tuple<Image, Vec2I, bool> 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();
|
unsigned bpp = image.bytesPerPixel();
|
||||||
uint8_t* data = image.data() + bpp + ((image.width() * (image.height() - 2)) * bpp); // offset by 1 pixel as it's padded
|
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) {
|
for (size_t y = 0; y != height; ++y) {
|
||||||
|
@ -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.
|
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;
|
return operation;
|
||||||
|
|
||||||
if (which = !which)
|
if ((which = !which))
|
||||||
operation.colorReplaceMap[*(Vec4B*)&a] = *(Vec4B*)&b;
|
operation.colorReplaceMap[*(Vec4B*)&a] = *(Vec4B*)&b;
|
||||||
|
|
||||||
hexLen = 0;
|
hexLen = 0;
|
||||||
|
@ -17,11 +17,9 @@ EnumMap<PaneLayer> const PaneLayerNames{
|
|||||||
PaneManager::PaneManager()
|
PaneManager::PaneManager()
|
||||||
: m_context(GuiContext::singletonPtr()), m_prevInterfaceScale(1) {
|
: m_context(GuiContext::singletonPtr()), m_prevInterfaceScale(1) {
|
||||||
auto assets = Root::singleton().assets();
|
auto assets = Root::singleton().assets();
|
||||||
m_tooltipMouseoverTime = assets->json("/panes.config:tooltipMouseoverTime").toFloat();
|
|
||||||
m_tooltipMouseoverRadius = assets->json("/panes.config:tooltipMouseoverRadius").toFloat();
|
m_tooltipMouseoverRadius = assets->json("/panes.config:tooltipMouseoverRadius").toFloat();
|
||||||
m_tooltipMouseOffset = jsonToVec2I(assets->json("/panes.config:tooltipMouseoverOffset"));
|
m_tooltipMouseOffset = jsonToVec2I(assets->json("/panes.config:tooltipMouseoverOffset"));
|
||||||
|
m_tooltipShowTimer = GameTimer(assets->json("/panes.config:tooltipMouseoverTime").toFloat());
|
||||||
m_tooltipShowTimer = m_tooltipMouseoverTime;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PaneManager::displayPane(PaneLayer paneLayer, PanePtr const& pane, DismissCallback onDismiss) {
|
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 {
|
PanePtr PaneManager::getPaneAt(Vec2I const& position) const {
|
||||||
for (auto const& layerPair : m_displayedPanes) {
|
for (auto const& layerPair : m_displayedPanes) {
|
||||||
for (auto const& panePair : layerPair.second) {
|
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;
|
return panePair.first;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -185,12 +185,12 @@ bool PaneManager::sendInputEvent(InputEvent const& event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (event.is<MouseButtonDownEvent>()) {
|
if (event.is<MouseButtonDownEvent>()) {
|
||||||
m_tooltipShowTimer = m_tooltipMouseoverTime;
|
m_tooltipShowTimer.reset();
|
||||||
if (m_activeTooltip) {
|
if (m_activeTooltip) {
|
||||||
dismiss(m_activeTooltip);
|
dismiss(m_activeTooltip);
|
||||||
m_activeTooltip.reset();
|
m_activeTooltip.reset();
|
||||||
m_tooltipParentPane.reset();
|
m_tooltipParentPane.reset();
|
||||||
m_tooltipShowTimer = m_tooltipMouseoverTime;
|
m_tooltipShowTimer.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,29 +270,27 @@ void PaneManager::render() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PaneManager::update(float dt) {
|
void PaneManager::update(float dt) {
|
||||||
m_tooltipShowTimer -= GlobalTimestep;
|
auto newTooltipParentPane = getPaneAt(m_tooltipLastMousePos);
|
||||||
if (m_tooltipParentPane.expired())
|
|
||||||
m_tooltipParentPane.reset();
|
|
||||||
|
|
||||||
bool removeTooltip = vmag(m_tooltipInitialPosition - m_tooltipLastMousePos) > m_tooltipMouseoverRadius
|
bool updateTooltip = m_tooltipShowTimer.tick(dt) || (m_activeTooltip && (
|
||||||
|| m_tooltipParentPane.expired() || m_tooltipParentPane.lock()->inWindow(m_tooltipLastMousePos);
|
vmag(m_tooltipInitialPosition - m_tooltipLastMousePos) > m_tooltipMouseoverRadius
|
||||||
|
|| m_tooltipParentPane != newTooltipParentPane
|
||||||
|
|| !m_tooltipParentPane->inWindow(m_tooltipLastMousePos)));
|
||||||
|
|
||||||
if (removeTooltip) {
|
if (updateTooltip) {
|
||||||
dismiss(m_activeTooltip);
|
if (m_activeTooltip) {
|
||||||
m_activeTooltip.reset();
|
dismiss(m_activeTooltip);
|
||||||
m_tooltipParentPane.reset();
|
m_activeTooltip.reset();
|
||||||
}
|
m_tooltipParentPane.reset();
|
||||||
|
}
|
||||||
|
|
||||||
// Scan for a new tooltip if we just removed the old one, or the show timer has expired
|
m_tooltipShowTimer.reset();
|
||||||
if (removeTooltip || (m_tooltipShowTimer < 0 && !m_activeTooltip)) {
|
if (newTooltipParentPane) {
|
||||||
if (auto parentPane = getPaneAt(m_tooltipLastMousePos)) {
|
if (auto tooltip = newTooltipParentPane->createTooltip(m_tooltipLastMousePos)) {
|
||||||
if (auto tooltip = parentPane->createTooltip(m_tooltipLastMousePos)) {
|
|
||||||
m_activeTooltip = std::move(tooltip);
|
m_activeTooltip = std::move(tooltip);
|
||||||
m_tooltipParentPane = std::move(parentPane);
|
m_tooltipParentPane = std::move(newTooltipParentPane);
|
||||||
m_tooltipInitialPosition = m_tooltipLastMousePos;
|
m_tooltipInitialPosition = m_tooltipLastMousePos;
|
||||||
displayPane(PaneLayer::Tooltip, m_activeTooltip);
|
displayPane(PaneLayer::Tooltip, m_activeTooltip);
|
||||||
} else {
|
|
||||||
m_tooltipShowTimer = m_tooltipMouseoverTime;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "StarPane.hpp"
|
#include "StarPane.hpp"
|
||||||
#include "StarOrderedMap.hpp"
|
#include "StarOrderedMap.hpp"
|
||||||
#include "StarBiMap.hpp"
|
#include "StarBiMap.hpp"
|
||||||
|
#include "StarGameTimers.hpp"
|
||||||
|
|
||||||
namespace Star {
|
namespace Star {
|
||||||
|
|
||||||
@ -92,15 +93,13 @@ private:
|
|||||||
|
|
||||||
WidgetPtr m_backgroundWidget;
|
WidgetPtr m_backgroundWidget;
|
||||||
|
|
||||||
float m_tooltipMouseoverTime;
|
|
||||||
float m_tooltipMouseoverRadius;
|
float m_tooltipMouseoverRadius;
|
||||||
Vec2I m_tooltipMouseOffset;
|
Vec2I m_tooltipMouseOffset;
|
||||||
|
GameTimer m_tooltipShowTimer;
|
||||||
float m_tooltipShowTimer;
|
|
||||||
Vec2I m_tooltipLastMousePos;
|
Vec2I m_tooltipLastMousePos;
|
||||||
Vec2I m_tooltipInitialPosition;
|
Vec2I m_tooltipInitialPosition;
|
||||||
PanePtr m_activeTooltip;
|
PanePtr m_activeTooltip;
|
||||||
PaneWeakPtr m_tooltipParentPane;
|
PanePtr m_tooltipParentPane;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user