Monopoly — Portage moderne 0.1.0
Portage moderne C/C++23 du Monopoly de 1999
Loading...
Searching...
No Matches
MousePointer.cpp
Go to the documentation of this file.
1#include "MousePointer.hpp"
2#include "ChatRuntime.hpp"
3#include <SDL3/SDL.h>
4#include <cstdint>
5
7{
8 namespace { State pointer; }
9
11 {
12 pointer = {};
13 pointer.initialized = true;
14 return true;
15 }
16 void shutdown() { pointer = {}; }
17 void updatePosition(int x, int y, bool inside) noexcept
18 {
19 pointer.x = x;
20 pointer.y = y;
21 pointer.inside = inside;
22 if (!inside) pointer.kind = CursorKind::Pointer;
23 }
24 void setLeftDown(bool down) noexcept { pointer.leftDown = down; }
25 void setEnabled(bool enabled) noexcept { pointer.enabled = enabled; }
26 const State& stateReadOnly() noexcept { return pointer; }
27 bool assetVisible(const State& state) noexcept
28 {
29 return state.initialized && state.enabled && state.inside &&
31 }
33 {
34 if (!state.initialized || !state.inside) return NativeCursorKind::Arrow;
35 if (!state.enabled) return NativeCursorKind::Hidden;
38 }
39 void updateChatCursor(const chat::State& chat) noexcept
40 {
41 if (!pointer.inside || !chat.boxActive || chat.shaded)
42 {
44 return;
45 }
46 // UDChat.cpp:1000 preserves the current type during either window drag.
47 if (chat.moving || chat.sizing || chat.scrolling ||
48 chat.fluffMoving || chat.fluffSizing || chat.fluffScrolling) return;
49 const std::int64_t left = static_cast<std::int64_t>(chat.windowX) + 5;
50 const std::int64_t right = static_cast<std::int64_t>(chat.windowX) + chat.windowWidth - 20;
51 const std::int64_t bottom = static_cast<std::int64_t>(chat.windowY) + chat.windowHeight - 4;
52 const auto top = bottom - chat.fontHeight;
53 if (chat.fontHeight > 0 && pointer.x >= left && pointer.x < right &&
54 pointer.y >= top && pointer.y < bottom)
56 else if (!pointer.leftDown)
58 }
59
62 {
63 if (applied_ && current_ == kind) return true;
65 {
66 if (!SDL_HideCursor()) return false;
67 }
68 else
69 {
72 {
74 cursor = text_;
75 }
76 if (!cursor || !SDL_SetCursor(cursor) || !SDL_ShowCursor()) return false;
77 }
78 current_ = kind;
79 applied_ = true;
80 return true;
81 }
83 {
85 {
88 if (text_) SDL_DestroyCursor(text_);
89 }
90 text_ = nullptr;
91 applied_ = false;
92 }
93}
std::atomic< float > left
std::atomic< float > right
int bottom
int top
bool enabled
Definition Engine.cpp:170
unsigned state
unsigned index
Kind kind
bool sync(NativeCursorKind kind)
NativeCursorKind nativeCursorKind(const State &state, bool assetReady) noexcept
void setLeftDown(bool down) noexcept
bool assetVisible(const State &state) noexcept
void updatePosition(int x, int y, bool inside) noexcept
const State & stateReadOnly() noexcept
void setEnabled(bool enabled) noexcept
void updateChatCursor(const chat::State &chat) noexcept