aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CruUI.vcxproj2
-rw-r--r--CruUI.vcxproj.filters6
-rw-r--r--src/ui/input_util.cpp23
-rw-r--r--src/ui/input_util.hpp18
-rw-r--r--src/ui/ui_base.cpp17
-rw-r--r--src/ui/ui_base.hpp26
6 files changed, 58 insertions, 34 deletions
diff --git a/CruUI.vcxproj b/CruUI.vcxproj
index 30f39f28..449779d3 100644
--- a/CruUI.vcxproj
+++ b/CruUI.vcxproj
@@ -148,6 +148,7 @@
<ClCompile Include="src\ui\controls\toggle_button.cpp" />
<ClCompile Include="src\ui\cursor.cpp" />
<ClCompile Include="src\ui\events\ui_event.cpp" />
+ <ClCompile Include="src\ui\input_util.cpp" />
<ClCompile Include="src\ui\layout_base.cpp" />
<ClCompile Include="src\ui\ui_manager.cpp" />
<ClCompile Include="src\ui\ui_base.cpp" />
@@ -174,6 +175,7 @@
<ClInclude Include="src\ui\convert_util.hpp" />
<ClInclude Include="src\ui\cursor.hpp" />
<ClInclude Include="src\ui\events\ui_event.hpp" />
+ <ClInclude Include="src\ui\input_util.hpp" />
<ClInclude Include="src\ui\layout_base.hpp" />
<ClInclude Include="src\ui\ui_manager.hpp" />
<ClInclude Include="src\ui\ui_base.hpp" />
diff --git a/CruUI.vcxproj.filters b/CruUI.vcxproj.filters
index 71025931..99033bf7 100644
--- a/CruUI.vcxproj.filters
+++ b/CruUI.vcxproj.filters
@@ -93,6 +93,9 @@
<ClCompile Include="src\ui\controls\scroll_control.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="src\ui\input_util.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\graph\graph.hpp">
@@ -191,6 +194,9 @@
<ClInclude Include="src\pre.hpp">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="src\ui\input_util.hpp">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\application.cpp">
diff --git a/src/ui/input_util.cpp b/src/ui/input_util.cpp
new file mode 100644
index 00000000..6cf2d695
--- /dev/null
+++ b/src/ui/input_util.cpp
@@ -0,0 +1,23 @@
+#include "input_util.hpp"
+
+#include "system_headers.hpp"
+
+namespace cru::ui
+{
+ bool IsKeyDown(const int virtual_code)
+ {
+ const auto result = ::GetKeyState(virtual_code);
+ return (static_cast<unsigned short>(result) & 0x8000) != 0;
+ }
+
+ bool IsKeyToggled(const int virtual_code)
+ {
+ const auto result = ::GetKeyState(virtual_code);
+ return (static_cast<unsigned short>(result) & 1) != 0;
+ }
+
+ bool IsAnyMouseButtonDown()
+ {
+ return IsKeyDown(VK_LBUTTON) || IsKeyDown(VK_RBUTTON) || IsKeyDown(VK_MBUTTON);
+ }
+}
diff --git a/src/ui/input_util.hpp b/src/ui/input_util.hpp
new file mode 100644
index 00000000..13f568b3
--- /dev/null
+++ b/src/ui/input_util.hpp
@@ -0,0 +1,18 @@
+#pragma once
+
+// ReSharper disable once CppUnusedIncludeDirective
+#include "pre.hpp"
+
+namespace cru::ui
+{
+ enum class MouseButton
+ {
+ Left,
+ Right,
+ Middle
+ };
+
+ bool IsKeyDown(int virtual_code);
+ bool IsKeyToggled(int virtual_code);
+ bool IsAnyMouseButtonDown();
+}
diff --git a/src/ui/ui_base.cpp b/src/ui/ui_base.cpp
index c91fcd7b..2853011d 100644
--- a/src/ui/ui_base.cpp
+++ b/src/ui/ui_base.cpp
@@ -1,23 +1,6 @@
#include "ui_base.hpp"
-#include "system_headers.hpp"
-
namespace cru::ui
{
- bool IsKeyDown(const int virtual_code)
- {
- const auto result = ::GetKeyState(virtual_code);
- return (static_cast<unsigned short>(result) & 0x8000) != 0;
- }
-
- bool IsKeyToggled(const int virtual_code)
- {
- const auto result = ::GetKeyState(virtual_code);
- return (static_cast<unsigned short>(result) & 1) != 0;
- }
- bool IsAnyMouseButtonDown()
- {
- return IsKeyDown(VK_LBUTTON) || IsKeyDown(VK_RBUTTON) || IsKeyDown(VK_MBUTTON);
- }
}
diff --git a/src/ui/ui_base.hpp b/src/ui/ui_base.hpp
index b898b2ed..e57af530 100644
--- a/src/ui/ui_base.hpp
+++ b/src/ui/ui_base.hpp
@@ -8,7 +8,7 @@
namespace cru::ui
{
- struct Point
+ struct Point final
{
constexpr static Point Zero()
{
@@ -32,7 +32,8 @@ namespace cru::ui
return !(left == right);
}
- struct Size
+
+ struct Size final
{
constexpr static Size Zero()
{
@@ -46,12 +47,12 @@ namespace cru::ui
float height = 0;
};
- constexpr Size operator + (const Size& left, const Size& right)
+ constexpr Size operator+(const Size& left, const Size& right)
{
return Size(left.width + right.width, left.height + right.height);
}
- constexpr Size operator - (const Size& left, const Size& right)
+ constexpr Size operator-(const Size& left, const Size& right)
{
return Size(left.width - right.width, left.height - right.height);
}
@@ -66,7 +67,8 @@ namespace cru::ui
return !(left == right);
}
- struct Thickness
+
+ struct Thickness final
{
constexpr static Thickness Zero()
{
@@ -120,7 +122,7 @@ namespace cru::ui
float bottom;
};
- struct Rect
+ struct Rect final
{
constexpr Rect() = default;
constexpr Rect(const float left, const float top, const float width, const float height)
@@ -188,14 +190,8 @@ namespace cru::ui
float height = 0.0f;
};
- enum class MouseButton
- {
- Left,
- Right,
- Middle
- };
- struct TextRange
+ struct TextRange final
{
constexpr static std::optional<TextRange> FromTwoSides(unsigned first, unsigned second)
{
@@ -223,8 +219,4 @@ namespace cru::ui
unsigned position = 0;
unsigned count = 0;
};
-
- bool IsKeyDown(int virtual_code);
- bool IsKeyToggled(int virtual_code);
- bool IsAnyMouseButtonDown();
}