Skip to content

Commit 7d1d4f9

Browse files
committed
change Event to be more type safe, and prepare SDL3 migration
1 parent 8452564 commit 7d1d4f9

File tree

11 files changed

+625
-312
lines changed

11 files changed

+625
-312
lines changed

examples/19-gridmap.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,11 @@ namespace {
204204
private:
205205
void do_process_event(const gf::Event& event) override
206206
{
207-
switch (event.type) {
207+
switch (event.type()) {
208208
case gf::EventType::MouseMoved:
209209
{
210-
auto mouse_position = event.mouse_motion.position;
210+
const auto& mouse_motion_event = event.from<gf::EventType::MouseMoved>();
211+
auto mouse_position = mouse_motion_event.position;
211212
auto mouse_location = position_to_world_location(mouse_position);
212213
gf::Vec2I position = m_grid_entity.grid().compute_position(mouse_location);
213214

examples/20-physics.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace {
2323

2424
int pixel(int x, int y)
2525
{
26-
return (ImageBitmap[(x >> 3) + y * ImageRowLength] >> (~x & 0x07)) & 1; // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
26+
return (ImageBitmap[(x >> 3) + (y * ImageRowLength)] >> (~x & 0x07)) & 1; // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
2727
}
2828

2929
class PhysicsEntity : public gf::Entity {
@@ -116,8 +116,8 @@ namespace {
116116

117117
void do_process_event(const gf::Event& event) override
118118
{
119-
if (event.type == gf::EventType::KeyPressed) {
120-
if (event.key.scancode == gf::Scancode::Space) {
119+
if (event.type() == gf::EventType::KeyPressed) {
120+
if (event.from<gf::EventType::KeyPressed>().scancode == gf::Scancode::Space) {
121121
m_entity.reset_world(m_random);
122122
}
123123
}

games/HOME/bits/WorldScene.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ namespace home {
6666

6767
void WorldScene::do_process_event(const gf::Event& event)
6868
{
69-
if (event.type == gf::EventType::MouseButtonPressed) {
70-
auto target = position_to_world_location(event.mouse_button.position);
69+
if (event.type() == gf::EventType::MouseButtonPressed) {
70+
auto target = position_to_world_location(event.from<gf::EventType::MouseButtonPressed>().position);
7171
gf::Log::debug("target: {}, {}", target.x, target.y);
7272
m_hero_entity.set_target(target);
7373
}

include/gf2/core/MouseTypes.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ namespace gf {
2424

2525
constexpr MouseId TouchMouseId = static_cast<MouseId>(0xFFFFFFFF);
2626

27+
enum class MouseWheelDirection : uint32_t { // NOLINT(performance-enum-size)
28+
Normal,
29+
Flipped,
30+
};
31+
2732
} // namespace gf
2833

2934
#endif // GF_MOUSE_TYPES_H

0 commit comments

Comments
 (0)