nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
cursor.cc
Go to the documentation of this file.
1#include "client/cursor.h"
2
3#include <imgui.h>
4#include <raylib.h>
5
6namespace nanommo {
7
8namespace {
9
10int GuiCursor() {
11 switch (ImGui::GetMouseCursor()) {
12 case ImGuiMouseCursor_TextInput:
13 return MOUSE_CURSOR_IBEAM;
14 case ImGuiMouseCursor_Hand:
15 return MOUSE_CURSOR_POINTING_HAND;
16 case ImGuiMouseCursor_ResizeAll:
17 return MOUSE_CURSOR_RESIZE_ALL;
18 case ImGuiMouseCursor_ResizeEW:
19 return MOUSE_CURSOR_RESIZE_EW;
20 case ImGuiMouseCursor_ResizeNS:
21 return MOUSE_CURSOR_RESIZE_NS;
22 case ImGuiMouseCursor_ResizeNESW:
23 return MOUSE_CURSOR_RESIZE_NESW;
24 case ImGuiMouseCursor_ResizeNWSE:
25 return MOUSE_CURSOR_RESIZE_NWSE;
26 case ImGuiMouseCursor_NotAllowed:
27 return MOUSE_CURSOR_NOT_ALLOWED;
28 default:
29 return MOUSE_CURSOR_DEFAULT;
30 }
31}
32
33} // namespace
34
35void UpdateCursor(Pointing pointing) {
36 int cursor = MOUSE_CURSOR_DEFAULT;
37 if (ImGui::GetIO().WantCaptureMouse) {
38 cursor = GuiCursor();
39 } else if (pointing == Pointing::kNpc) {
40 cursor = MOUSE_CURSOR_POINTING_HAND;
41 } else if (pointing == Pointing::kMonster) {
42 cursor = MOUSE_CURSOR_CROSSHAIR;
43 }
44 // Each change asks the window system for a cursor, so only on a change.
45 static int shown = -1;
46 if (cursor != shown) {
47 SetMouseCursor(cursor);
48 shown = cursor;
49 }
50}
51
52} // namespace nanommo
Definition chat.cc:9
void UpdateCursor(Pointing pointing)
Definition cursor.cc:35
Pointing
What the mouse is over in the world.
Definition cursor.h:7