-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
1,546 additions
and
1,466 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// Created by Dmitry Khrykin on 2020-01-30. | ||
// | ||
|
||
#include "event.h" | ||
|
||
stg::event::event(stg::event::key_modifiers modifiers) | ||
: modifiers(modifiers) { | ||
} | ||
|
||
stg::mouse_event::mouse_event(const stg::point &position, | ||
stg::event::key_modifiers modifiers) | ||
: event(modifiers), | ||
position(position) { | ||
} | ||
|
||
bool stg::event::is(stg::event::key_modifiers mod) const { | ||
return modifiers == mod; | ||
} | ||
|
||
bool stg::event::with(stg::event::key_modifiers mod) const { | ||
return (modifiers & mod) == mod; | ||
} | ||
|
||
std::ostream &stg::operator<<(std::ostream &os, const stg::mouse_event &e) { | ||
os << "mouse_event {\n"; | ||
os << " position: [" << e.position.x << ", " << e.position.y << "]\n"; | ||
os << " modifiers: ["; | ||
if (e.with(mouse_event::left_key)) { | ||
os << " left_key "; | ||
} | ||
if (e.with(mouse_event::right_key)) { | ||
os << " right_key "; | ||
} | ||
if (e.with(mouse_event::ctrl_key)) { | ||
os << " ctrl_key "; | ||
} | ||
os << "]\n"; | ||
os << "}\n"; | ||
|
||
return os; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// Created by Dmitry Khrykin on 2020-01-30. | ||
// | ||
|
||
#ifndef STRATEGR_EVENT_H | ||
#define STRATEGR_EVENT_H | ||
|
||
#include "geometry.h" | ||
|
||
namespace stg { | ||
struct event { | ||
using key_modifiers = uint8_t; | ||
|
||
static constexpr key_modifiers left_key = 1u << 0u; | ||
static constexpr key_modifiers right_key = 1u << 1u; | ||
static constexpr key_modifiers ctrl_key = 1u << 2u; | ||
|
||
explicit event(key_modifiers modifiers); | ||
|
||
template<class QtLikeEvent> | ||
event(QtLikeEvent *evt) { | ||
if (evt->modifiers() == 0x04000000) { | ||
modifiers |= ctrl_key; | ||
}; | ||
} | ||
|
||
bool is(key_modifiers mod) const; | ||
bool with(key_modifiers mod) const; | ||
|
||
key_modifiers modifiers = 0; | ||
}; | ||
|
||
struct mouse_event : public event { | ||
mouse_event(const point &position, key_modifiers modifiers); | ||
|
||
template<class QtLikeEvent> | ||
mouse_event(QtLikeEvent *evt) : event(evt), position(evt->pos()) { | ||
if (evt->buttons() == 1) { | ||
modifiers |= left_key; | ||
} else if (evt->buttons() == 2) { | ||
modifiers |= right_key; | ||
} | ||
} | ||
|
||
friend std::ostream &operator<<(std::ostream &os, const mouse_event &e); | ||
point position; | ||
}; | ||
}; | ||
|
||
|
||
#endif //STRATEGR_EVENT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.