0.4.1
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
TouchTracker.cpp
Go to the documentation of this file.
1// This file is part of INSTINCT, the INS Toolkit for Integrated
2// Navigation Concepts and Training by the Institute of Navigation of
3// the University of Stuttgart, Germany.
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
9#include "TouchTracker.hpp"
10
11#include <map>
12
13namespace NAV::gui
14{
15
16/// @brief Comparison operator for node Ids
18{
19 /// @brief Smaller comparison operator for node Ids
20 /// @param[in] lhs Left-hand-side of the operator
21 /// @param[in] rhs Right-hand-side of the operator
22 /// @return Whether lhs < rhs
23 bool operator()(const ax::NodeEditor::NodeId& lhs, const ax::NodeEditor::NodeId& rhs) const
24 {
25 return lhs.AsPointer() < rhs.AsPointer();
26 }
27};
28
29namespace
30{
31const float m_TouchTime = 1.0F;
32std::map<ax::NodeEditor::NodeId, float, NodeIdLess> m_NodeTouchTime;
33
34} // namespace
35} // namespace NAV::gui
36
37/// @brief Trigger a touch event on the specified node
38/// @param[in] id Id of the node to trigger the event on
39void NAV::gui::TouchNode(ax::NodeEditor::NodeId id)
40{
41 m_NodeTouchTime[id] = m_TouchTime;
42}
43
44/// @brief Get the Touch Progress for the specified node
45/// @param[in] id Id of the Node to check
46/// @return The Touch progress towards the touch time
47float NAV::gui::GetTouchProgress(ax::NodeEditor::NodeId id)
48{
49 auto it = m_NodeTouchTime.find(id);
50 if (it != m_NodeTouchTime.end() && it->second > 0.0F)
51 {
52 return (m_TouchTime - it->second) / m_TouchTime;
53 }
54
55 return 0.0F;
56}
57
58/// @brief Updates the touch events for all nodes
59/// @param[in] deltaTime Time elapsed since last frame, in [seconds]
60void NAV::gui::UpdateTouch(float deltaTime)
61{
62 for (auto& entry : m_NodeTouchTime)
63 {
64 if (entry.second > 0.0F)
65 {
66 entry.second -= deltaTime;
67 }
68 }
69}
Touch Event Tracker.
float GetTouchProgress(ax::NodeEditor::NodeId id)
Get the Touch Progress for the specified node.
void TouchNode(ax::NodeEditor::NodeId id)
Trigger a touch event on the specified node.
void UpdateTouch(float deltaTime)
Updates the touch events for all nodes.
Comparison operator for node Ids.
bool operator()(const ax::NodeEditor::NodeId &lhs, const ax::NodeEditor::NodeId &rhs) const
Smaller comparison operator for node Ids.