wip: windows api surface
Some checks reported errors
continuous-integration/drone/push Build was killed
Some checks reported errors
continuous-integration/drone/push Build was killed
This commit is contained in:
parent
451a8d5ea6
commit
90d9226e28
4 changed files with 681 additions and 461 deletions
|
|
@ -32,9 +32,7 @@ public:
|
|||
GainFocusEvent,
|
||||
KeyPressedEvent,
|
||||
KeyReleasedEvent,
|
||||
MouseMovedEvent,
|
||||
ButtonPressedEvent,
|
||||
ButtonReleasedEvent>;
|
||||
PointerEvent>;
|
||||
|
||||
using Request = std::variant<
|
||||
ModifyTitleRequest,
|
||||
|
|
@ -66,6 +64,8 @@ public:
|
|||
{
|
||||
std::string_view title;
|
||||
|
||||
math::vec2_i32 position;
|
||||
|
||||
math::vec2_u32 resolution;
|
||||
|
||||
bool vsync;
|
||||
|
|
|
|||
|
|
@ -27,27 +27,6 @@ private:
|
|||
Key m_key;
|
||||
};
|
||||
|
||||
class KeyRepeatEvent
|
||||
{
|
||||
public:
|
||||
KeyRepeatEvent(Key key): m_key(key)
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_key() const -> Key
|
||||
{
|
||||
return m_key;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto to_string() const -> std::string
|
||||
{
|
||||
return std::format("KeyRepeated: {}", std::to_underlying(m_key));
|
||||
}
|
||||
|
||||
private:
|
||||
Key m_key;
|
||||
};
|
||||
|
||||
class KeyReleasedEvent
|
||||
{
|
||||
public:
|
||||
|
|
@ -90,10 +69,10 @@ private:
|
|||
Key m_character;
|
||||
};
|
||||
|
||||
class MouseMovedEvent
|
||||
class PointerEvent
|
||||
{
|
||||
public:
|
||||
MouseMovedEvent(f32 x, f32 y): m_position(x, y)
|
||||
PointerEvent(f32 x, f32 y): m_position(x, y)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -114,7 +93,7 @@ public:
|
|||
|
||||
[[nodiscard]] auto to_string() const -> std::string
|
||||
{
|
||||
return std::format("MouseMoved: {}, {}", m_position.x, m_position.y);
|
||||
return std::format("Pointer: {}, {}", m_position.x, m_position.y);
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
@ -144,48 +123,6 @@ private:
|
|||
f32 m_offset;
|
||||
};
|
||||
|
||||
class ButtonPressedEvent
|
||||
{
|
||||
public:
|
||||
ButtonPressedEvent(Key button): m_button(button)
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_button() const -> Key
|
||||
{
|
||||
return m_button;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto to_string() const -> std::string
|
||||
{
|
||||
return std::format("ButtonPressed: {}", std::to_underlying(m_button));
|
||||
}
|
||||
|
||||
private:
|
||||
Key m_button;
|
||||
};
|
||||
|
||||
class ButtonReleasedEvent
|
||||
{
|
||||
public:
|
||||
ButtonReleasedEvent(Key button): m_button(button)
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_button() const -> Key
|
||||
{
|
||||
return m_button;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto to_string() const -> std::string
|
||||
{
|
||||
return std::format("ButtonReleased: {}", std::to_underlying(m_button));
|
||||
}
|
||||
|
||||
private:
|
||||
Key m_button;
|
||||
};
|
||||
|
||||
class ClosedEvent
|
||||
{
|
||||
public:
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,5 +1,16 @@
|
|||
#if defined(LIGHT_PLATFORM_LINUX)
|
||||
#elif defined(LIGHT_PLATFORM_WINDOWS)
|
||||
#include <Windows.h>
|
||||
#include <Winuser.h>
|
||||
|
||||
#else
|
||||
#error "Unsupported platform"
|
||||
#endif
|
||||
|
||||
import test;
|
||||
import time;
|
||||
import input.codes;
|
||||
import logger;
|
||||
import surface.system;
|
||||
import surface.events;
|
||||
import surface.requests;
|
||||
|
|
@ -21,9 +32,26 @@ using ::lt::surface::System;
|
|||
};
|
||||
}
|
||||
|
||||
|
||||
// void simulate_key_down(lt::surface::SurfaceComponent &surface, lt::Key key)
|
||||
// {
|
||||
// #if defined(LIGHT_PLATFORM_LINUX)
|
||||
// #elif defined(LIGHT_PLATFORM_WINDOWS)
|
||||
// #endif
|
||||
// }
|
||||
//
|
||||
// void simulate_key_up(lt::Key key)
|
||||
// {
|
||||
// #if defined(LIGHT_PLATFORM_LINUX)
|
||||
// #elif defined(LIGHT_PLATFORM_WINDOWS)
|
||||
// #endif
|
||||
// }
|
||||
|
||||
constexpr auto title = "TestWindow";
|
||||
constexpr auto width = 800u;
|
||||
constexpr auto height = 600u;
|
||||
constexpr auto position_x = 100;
|
||||
constexpr auto position_y = 200;
|
||||
constexpr auto vsync = true;
|
||||
constexpr auto visible = false;
|
||||
|
||||
|
|
@ -44,6 +72,7 @@ public:
|
|||
auto create_component(
|
||||
SurfaceComponent::CreateInfo info = SurfaceComponent::CreateInfo {
|
||||
.title = title,
|
||||
.position = { position_x, position_y },
|
||||
.resolution = { width, height },
|
||||
.vsync = vsync,
|
||||
.visible = visible,
|
||||
|
|
@ -215,7 +244,7 @@ Suite tick = "ticking"_suite = [] {
|
|||
surface.push_event(lt::surface::MovedEvent({}, {}));
|
||||
expect_eq(surface.peek_events().size(), 1);
|
||||
|
||||
surface.push_event(lt::surface::ButtonPressedEvent({}));
|
||||
surface.push_event(lt::surface::KeyPressedEvent({}));
|
||||
expect_eq(surface.peek_events().size(), 2);
|
||||
|
||||
system.tick(tick_info());
|
||||
|
|
@ -257,3 +286,125 @@ Suite tick = "ticking"_suite = [] {
|
|||
expect_eq(surface.get_resolution(), resolution);
|
||||
};
|
||||
};
|
||||
|
||||
#if defined(LIGHT_PLATFORM_WINDOWS)
|
||||
|
||||
Suite windows_window_proc = "windows_window_proc"_suite = [] {
|
||||
auto fixture = Fixture {};
|
||||
auto system = System { fixture.registry() };
|
||||
auto &surface = **fixture.create_component();
|
||||
auto [hwnd] = surface.get_native_data();
|
||||
const auto &events = surface.peek_events();
|
||||
|
||||
system.tick({});
|
||||
Case { "WM_SETFOCUS" } = [&] {
|
||||
expect_eq(events.size(), 0u);
|
||||
::SendMessage(hwnd, WM_SETFOCUS, {}, {});
|
||||
expect_eq(events.size(), 1u);
|
||||
|
||||
ignore = std::get<lt::surface::GainFocusEvent>(events.front());
|
||||
};
|
||||
|
||||
system.tick({});
|
||||
Case { "WM_KILLFOCUS" } = [&] {
|
||||
expect_eq(events.size(), 0u);
|
||||
::SendMessage(hwnd, WM_KILLFOCUS, {}, {});
|
||||
expect_eq(events.size(), 1u);
|
||||
|
||||
ignore = std::get<lt::surface::LostFocusEvent>(events.front());
|
||||
};
|
||||
|
||||
system.tick({});
|
||||
Case { "WM_SIZE" } = [&] {
|
||||
const auto new_width = width + 50;
|
||||
const auto new_height = height + 60;
|
||||
|
||||
expect_eq(events.size(), 0u);
|
||||
::SendMessage(hwnd, WM_SIZE, {}, MAKELPARAM(new_width, new_height));
|
||||
expect_eq(events.size(), 1u);
|
||||
|
||||
const auto &event = std::get<lt::surface::ResizedEvent>(events.front());
|
||||
expect_eq(event.get_size().x, new_width);
|
||||
expect_eq(event.get_size().y, new_height);
|
||||
|
||||
expect_eq(surface.get_resolution().x, new_width);
|
||||
expect_eq(surface.get_resolution().y, new_height);
|
||||
};
|
||||
|
||||
system.tick({});
|
||||
Case { "WM_MOVE" } = [&] {
|
||||
const auto new_x = position_x + 120;
|
||||
const auto new_y = position_y + 150;
|
||||
|
||||
expect_eq(events.size(), 0u);
|
||||
::SendMessage(hwnd, WM_MOVE, {}, MAKELPARAM(new_x, new_y));
|
||||
expect_eq(events.size(), 1u);
|
||||
|
||||
const auto &event = std::get<lt::surface::MovedEvent>(events.front());
|
||||
expect_eq(event.get_position().x, new_x);
|
||||
expect_eq(event.get_position().y, new_y);
|
||||
|
||||
expect_eq(surface.get_position().x, new_x);
|
||||
expect_eq(surface.get_position().y, new_y);
|
||||
};
|
||||
|
||||
system.tick({});
|
||||
Case { "WM_MOUSEWHEEL" } = [&] {
|
||||
};
|
||||
|
||||
system.tick({});
|
||||
Case { "WM_LBUTTONDOWN" } = [&] {
|
||||
};
|
||||
|
||||
system.tick({});
|
||||
Case { "WM_LBUTTONUP" } = [&] {
|
||||
};
|
||||
|
||||
system.tick({});
|
||||
Case { "WM_RBUTTONDOWN" } = [&] {
|
||||
};
|
||||
|
||||
system.tick({});
|
||||
Case { "WM_RBUTTONUP" } = [&] {
|
||||
};
|
||||
|
||||
system.tick({});
|
||||
Case { "WM_MBUTTONDOWN" } = [&] {
|
||||
};
|
||||
|
||||
system.tick({});
|
||||
Case { "WM_MBUTTONUP" } = [&] {
|
||||
};
|
||||
|
||||
system.tick({});
|
||||
Case { "WM_XBUTTONDOWN" } = [&] {
|
||||
};
|
||||
|
||||
system.tick({});
|
||||
Case { "WM_XBUTTONUP" } = [&] {
|
||||
};
|
||||
|
||||
system.tick({});
|
||||
Case { "WM_KEYDOWN" } = [&] {
|
||||
expect_eq(events.size(), 0u);
|
||||
::SendMessage(hwnd, WM_KEYDOWN, System::to_native_key(lt::Key::escape), {});
|
||||
expect_eq(events.size(), 1u);
|
||||
|
||||
const auto &event = std::get<lt::surface::KeyPressedEvent>(events.front());
|
||||
expect_eq(event.get_key(), lt::Key::escape);
|
||||
};
|
||||
|
||||
system.tick({});
|
||||
Case { "WM_KEYUP" } = [&] {
|
||||
};
|
||||
|
||||
system.tick({});
|
||||
Case { "WM_CLOSE" } = [&] {
|
||||
};
|
||||
|
||||
system.tick({});
|
||||
Case { "WM_DESTROY" } = [&] {
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue