-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
UIScreen.h
147 lines (114 loc) · 3.41 KB
/
UIScreen.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#pragma once
#include <mutex>
#include <string>
#include <deque>
#include "Common/Math/lin/vec3.h"
#include "Common/UI/Screen.h"
#include "Common/UI/ViewGroup.h"
using namespace Lin;
class I18NCategory;
namespace Draw {
class DrawContext;
}
enum class QueuedEventType : u8 {
KEY,
AXIS,
TOUCH,
};
struct QueuedEvent {
QueuedEventType type;
union {
TouchInput touch;
KeyInput key;
AxisInput axis;
};
};
class UIScreen : public Screen {
public:
UIScreen();
~UIScreen();
void update() override;
void render(ScreenRenderMode mode) override;
void deviceLost() override;
void deviceRestored() override;
virtual void touch(const TouchInput &touch);
virtual bool key(const KeyInput &key);
virtual void axis(const AxisInput &axis);
bool UnsyncTouch(const TouchInput &touch) override;
bool UnsyncKey(const KeyInput &key) override;
void UnsyncAxis(const AxisInput *axes, size_t count) override;
TouchInput transformTouch(const TouchInput &touch) override;
virtual void TriggerFinish(DialogResult result);
// Some useful default event handlers
UI::EventReturn OnOK(UI::EventParams &e);
UI::EventReturn OnCancel(UI::EventParams &e);
UI::EventReturn OnBack(UI::EventParams &e);
protected:
virtual void CreateViews() = 0;
void RecreateViews() override { recreateViews_ = true; }
bool UseVerticalLayout() const;
UI::ViewGroup *root_ = nullptr;
Vec3 translation_ = Vec3(0.0f);
Vec3 scale_ = Vec3(1.0f);
float alpha_ = 1.0f;
bool ignoreInsets_ = false;
bool ignoreInput_ = false;
protected:
virtual void DrawBackground(UIContext &ui) {}
void SetupViewport();
void DoRecreateViews();
bool recreateViews_ = true;
bool lastVertical_;
private:
std::mutex eventQueueLock_;
std::deque<QueuedEvent> eventQueue_;
};
class UIDialogScreen : public UIScreen {
public:
UIDialogScreen() : UIScreen(), finished_(false) {}
bool key(const KeyInput &key) override;
void sendMessage(UIMessage message, const char *value) override;
private:
bool finished_;
};
class PopupScreen : public UIDialogScreen {
public:
PopupScreen(std::string title, std::string button1 = "", std::string button2 = "");
virtual void CreatePopupContents(UI::ViewGroup *parent) = 0;
void CreateViews() override;
bool isTransparent() const override { return true; }
void touch(const TouchInput &touch) override;
bool key(const KeyInput &key) override;
void TriggerFinish(DialogResult result) override;
void SetPopupOrigin(const UI::View *view);
void SetPopupOffset(float y);
void SetHasDropShadow(bool has) { hasDropShadow_ = has; }
// For the postproc param sliders on DisplayLayoutScreen
bool wantBrightBackground() const override { return !hasDropShadow_; }
protected:
virtual bool FillVertical() const { return false; }
virtual UI::Size PopupWidth() const { return 550; }
virtual bool ShowButtons() const { return true; }
virtual bool CanComplete(DialogResult result) { return true; }
virtual void OnCompleted(DialogResult result) {}
virtual bool HasTitleBar() const { return true; }
const std::string &Title() { return title_; }
void update() override;
private:
UI::LinearLayout *box_ = nullptr;
UI::Button *defaultButton_ = nullptr;
std::string title_;
std::string button1_;
std::string button2_;
enum {
FRAMES_LEAD_IN = 6,
FRAMES_LEAD_OUT = 4,
};
int frames_ = 0;
int finishFrame_ = -1;
DialogResult finishResult_ = DR_CANCEL;
bool hasPopupOrigin_ = false;
Point popupOrigin_;
float offsetY_ = 0.0f;
bool hasDropShadow_ = true;
};