diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ui/input_util.cpp | 23 | ||||
-rw-r--r-- | src/ui/input_util.hpp | 18 | ||||
-rw-r--r-- | src/ui/ui_base.cpp | 17 | ||||
-rw-r--r-- | src/ui/ui_base.hpp | 26 |
4 files changed, 50 insertions, 34 deletions
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(); } |