forked from minecraft-linux/mcpelauncher-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow_callbacks.h
69 lines (54 loc) · 2.03 KB
/
window_callbacks.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#pragma once
#include <game_window.h>
#include <unordered_map>
#include "jni/jni_support.h"
#include "fake_inputqueue.h"
#include <chrono>
class WindowCallbacks {
private:
struct GamepadData {
float axis[6];
bool button[15];
GamepadData();
};
GameWindow &window;
JniSupport &jniSupport;
FakeInputQueue &inputQueue;
std::unordered_map<int, GamepadData> gamepads;
bool useDirectMouseInput, useDirectKeyboardInput;
bool modCTRL = false;
bool needsQueueGamepadInput = true;
bool fullscreen = false;
enum class InputMode {
Touch,
Mouse,
Gamepad,
Unknown,
};
InputMode inputMode = InputMode::Unknown;
std::chrono::high_resolution_clock::time_point lastUpdated;
bool hasInputMode(InputMode want = InputMode::Unknown, bool changeMode = true);
void queueGamepadAxisInputIfNeeded(int gamepad);
public:
WindowCallbacks(GameWindow &window, JniSupport &jniSupport, FakeInputQueue &inputQueue);
static void loadGamepadMappings();
void registerCallbacks();
void markRequeueGamepadInput() { needsQueueGamepadInput = true; }
void onWindowSizeCallback(int w, int h);
void onClose();
void onMouseButton(double x, double y, int btn, MouseButtonAction action);
void onMousePosition(double x, double y);
void onMouseRelativePosition(double x, double y);
void onMouseScroll(double x, double y, double dx, double dy);
void onTouchStart(int id, double x, double y);
void onTouchUpdate(int id, double x, double y);
void onTouchEnd(int id, double x, double y);
void onKeyboard(KeyCode key, KeyAction action);
void onKeyboardText(std::string const& c);
void onPaste(std::string const& str);
void onGamepadState(int gamepad, bool connected);
void onGamepadButton(int gamepad, GamepadButtonId btn, bool pressed);
void onGamepadAxis(int gamepad, GamepadAxisId ax, float value);
static int mapMinecraftToAndroidKey(KeyCode code);
static int mapGamepadToAndroidKey(GamepadButtonId btn);
};