1 #include "hpp/Mouse.hpp"
9 namespace rolmodl::mouse {
12 void useRaw(Cursor* c) noexcept {
13 using detail::active_cursor;
15 if (active_cursor !=
nullptr)
16 active_cursor->unused();
17 SDL_SetCursor(c ==
nullptr ? SDL_GetDefaultCursor() : c->unsafeRaw());
21 void useDefault() noexcept {
22 unsafe::useRaw(
nullptr);
26 Cursor create(
const Type t) {
27 SDL_Cursor* c = SDL_CreateSystemCursor(type::unsafe::toSDLEnum(t));
34 return create(Type::arrow);
37 return create(Type::iBeam);
40 return create(Type::wait);
43 return create(Type::crosshair);
46 return create(Type::waitArrow);
49 return create(Type::forbidden);
52 return create(Type::hand);
57 return create(Type::resize_nw_se);
60 return create(Type::resize_ne_sw);
63 return create(Type::resize_we);
66 return create(Type::resize_ns);
69 return create(Type::resize_all);
75 Cursor::Cursor() noexcept : Cursor(
nullptr)
77 Cursor::Cursor(SDL_Cursor* data) noexcept :
81 Cursor::Cursor(Cursor&& that) noexcept :
87 if (cursor::detail::active_cursor ==
this) {
95 Cursor& Cursor::operator=(Cursor&& that) noexcept {
100 void swap(Cursor& a, Cursor& b) noexcept {
102 swap(a.data_, b.data_);
103 swap(a.destructed_, b.destructed_);
106 void Cursor::use() noexcept {
107 cursor::unsafe::useRaw(
this);
109 void Cursor::unused() noexcept {
114 void Cursor::free() noexcept {
115 if (data_ !=
nullptr)
116 SDL_FreeCursor(data_);
119 SDL_Cursor* Cursor::unsafeRaw() noexcept {
120 assert(data_ !=
nullptr);
125 BaseState::BaseState(
const uint32_t b) noexcept :
128 const geom::Pos& BaseState::pos() const noexcept {
131 const BtnState& BaseState::btnState() const noexcept {
136 State::State() noexcept :
137 BaseState(SDL_GetMouseState(&p_.x, &p_.y))
139 GlobalState::GlobalState() noexcept :
140 BaseState(SDL_GetGlobalMouseState(&p_.x, &p_.y))
150 void move(
const geom::Pos p) {