CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/UI/ControlMappingScreen.h
Views: 1401
1
// Copyright (c) 2013- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#pragma once
19
20
#include <functional>
21
#include <memory>
22
#include <set>
23
#include <mutex>
24
#include <vector>
25
#include <string>
26
27
#include "Common/UI/View.h"
28
#include "Common/UI/UIScreen.h"
29
#include "Common/Data/Text/I18n.h"
30
31
#include "Core/ControlMapper.h"
32
33
#include "UI/MiscScreens.h"
34
35
class SingleControlMapper;
36
37
class ControlMappingScreen : public UIDialogScreenWithGameBackground {
38
public:
39
explicit ControlMappingScreen(const Path &gamePath) : UIDialogScreenWithGameBackground(gamePath) {
40
categoryToggles_[0] = true;
41
categoryToggles_[1] = true;
42
categoryToggles_[2] = true;
43
categoryToggles_[3] = false;
44
}
45
const char *tag() const override { return "ControlMapping"; }
46
47
protected:
48
void CreateViews() override;
49
void update() override;
50
51
private:
52
UI::EventReturn OnAutoConfigure(UI::EventParams &params);
53
54
void dialogFinished(const Screen *dialog, DialogResult result) override;
55
56
UI::ScrollView *rightScroll_ = nullptr;
57
std::vector<SingleControlMapper *> mappers_;
58
int keyMapGeneration_ = -1;
59
60
bool categoryToggles_[10]{};
61
};
62
63
class KeyMappingNewKeyDialog : public PopupScreen {
64
public:
65
explicit KeyMappingNewKeyDialog(int btn, bool replace, std::function<void(KeyMap::MultiInputMapping)> callback, I18NCat i18n)
66
: PopupScreen(T(i18n, "Map Key"), "Cancel", ""), pspBtn_(btn), callback_(callback) {}
67
68
const char *tag() const override { return "KeyMappingNewKey"; }
69
70
bool key(const KeyInput &key) override;
71
void axis(const AxisInput &axis) override;
72
73
void SetDelay(float t);
74
75
protected:
76
void CreatePopupContents(UI::ViewGroup *parent) override;
77
78
bool FillVertical() const override { return false; }
79
bool ShowButtons() const override { return true; }
80
void OnCompleted(DialogResult result) override {}
81
82
private:
83
int pspBtn_;
84
std::function<void(KeyMap::MultiInputMapping)> callback_;
85
86
KeyMap::MultiInputMapping mapping_;
87
88
UI::View *comboMappingsNotEnabled_ = nullptr;
89
90
// We need to do our own detection for axis "keyup" here.
91
std::set<InputMapping> triggeredAxes_;
92
93
double delayUntil_ = 0.0f;
94
};
95
96
class KeyMappingNewMouseKeyDialog : public PopupScreen {
97
public:
98
KeyMappingNewMouseKeyDialog(int btn, bool replace, std::function<void(KeyMap::MultiInputMapping)> callback, I18NCat i18n)
99
: PopupScreen(T(i18n, "Map Mouse"), "", ""), pspBtn_(btn), callback_(callback) {}
100
101
const char *tag() const override { return "KeyMappingNewMouseKey"; }
102
103
bool key(const KeyInput &key) override;
104
void axis(const AxisInput &axis) override;
105
106
protected:
107
void CreatePopupContents(UI::ViewGroup *parent) override;
108
109
bool FillVertical() const override { return false; }
110
bool ShowButtons() const override { return true; }
111
void OnCompleted(DialogResult result) override {}
112
113
private:
114
int pspBtn_;
115
std::function<void(KeyMap::MultiInputMapping)> callback_;
116
bool mapped_ = false; // Prevent double registrations
117
};
118
119
class JoystickHistoryView;
120
121
class AnalogSetupScreen : public UIDialogScreenWithGameBackground {
122
public:
123
AnalogSetupScreen(const Path &gamePath);
124
125
bool key(const KeyInput &key) override;
126
void axis(const AxisInput &axis) override;
127
128
void update() override;
129
130
const char *tag() const override { return "AnalogSetup"; }
131
132
protected:
133
void CreateViews() override;
134
135
private:
136
UI::EventReturn OnResetToDefaults(UI::EventParams &e);
137
138
ControlMapper mapper_;
139
140
float analogX_[2]{};
141
float analogY_[2]{};
142
float rawX_[2]{};
143
float rawY_[2]{};
144
145
JoystickHistoryView *stickView_[2]{};
146
};
147
148
class MockPSP;
149
150
class VisualMappingScreen : public UIDialogScreenWithGameBackground {
151
public:
152
VisualMappingScreen(const Path &gamePath) : UIDialogScreenWithGameBackground(gamePath) {}
153
154
const char *tag() const override { return "VisualMapping"; }
155
156
bool key(const KeyInput &key) override;
157
void axis(const AxisInput &axis) override;
158
159
protected:
160
void CreateViews() override;
161
162
void dialogFinished(const Screen *dialog, DialogResult result) override;
163
void resized() override;
164
165
private:
166
UI::EventReturn OnMapButton(UI::EventParams &e);
167
UI::EventReturn OnBindAll(UI::EventParams &e);
168
void HandleKeyMapping(const KeyMap::MultiInputMapping &key);
169
void MapNext(bool successive);
170
171
MockPSP *psp_ = nullptr;
172
int nextKey_ = 0;
173
int bindAll_ = -1;
174
bool replace_ = false;
175
};
176
177