|
14 | 14 | #include "driver/KeyEvent.h" |
15 | 15 | #include "driver/MouseCoords.h" |
16 | 16 | #include "helpers/mathFuncs.h" |
| 17 | +#include "mockupDrivers/MockupVideoDriver.h" |
17 | 18 | #include "ogl/glFont.h" |
18 | 19 | #include "uiHelper/uiHelpers.hpp" |
19 | 20 | #include "libsiedler2/ArchivItem_Bitmap_Player.h" |
|
27 | 28 | #include <boost/test/unit_test.hpp> |
28 | 29 | #include <Loader.h> |
29 | 30 | #include <array> |
| 31 | +#include <limits> |
30 | 32 | #include <numeric> |
31 | 33 |
|
32 | 34 | // LCOV_EXCL_START |
@@ -54,6 +56,26 @@ static std::unique_ptr<glFont> createMockFont(const std::vector<char32_t>& chars |
54 | 56 |
|
55 | 57 | BOOST_AUTO_TEST_SUITE(Controls) |
56 | 58 |
|
| 59 | +BOOST_FIXTURE_TEST_CASE(MouseOver, uiHelper::Fixture) |
| 60 | +{ |
| 61 | + const auto pos = rttr::test::randomPoint<DrawPoint>(0, std::numeric_limits<DrawPoint::ElementType>::max() / 2); |
| 62 | + const auto size = rttr::test::randomPoint<Extent>(10, std::numeric_limits<DrawPoint::ElementType>::max() / 2); |
| 63 | + const auto font = createMockFont({'H', 'e', 'l', 'o', '?'}); |
| 64 | + ctrlTextButton bt(nullptr, 1, pos, size, TextureColor::Bricks, "Hello", font.get(), ""); |
| 65 | + BOOST_TEST(bt.IsMouseOver(pos)); |
| 66 | + BOOST_TEST(!bt.IsMouseOver(pos - DrawPoint(1, 0))); |
| 67 | + BOOST_TEST(!bt.IsMouseOver(pos - DrawPoint(0, 1))); |
| 68 | + BOOST_TEST(bt.IsMouseOver(pos + size / 2u)); |
| 69 | + BOOST_TEST(bt.IsMouseOver(pos + size - DrawPoint(1, 1))); |
| 70 | + BOOST_TEST(!bt.IsMouseOver(pos + size)); |
| 71 | + BOOST_TEST(!bt.IsMouseOver(pos + size + DrawPoint(0, 1))); |
| 72 | + // Without argument asks the video driver for the mouse position |
| 73 | + uiHelper::GetVideoDriver()->SetMousePos(pos + size / 2u); |
| 74 | + BOOST_TEST(bt.IsMouseOver()); |
| 75 | + uiHelper::GetVideoDriver()->SetMousePos(pos + size * 2u); |
| 76 | + BOOST_TEST(!bt.IsMouseOver()); |
| 77 | +} |
| 78 | + |
57 | 79 | static void resizeMap(libsiedler2::ArchivItem_Map& glMap, const Extent& size) |
58 | 80 | { |
59 | 81 | libsiedler2::ArchivItem_Map map; |
|
0 commit comments