-
Notifications
You must be signed in to change notification settings - Fork 2
/
gui.hpp
262 lines (217 loc) · 8.25 KB
/
gui.hpp
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/*
* This file is part of Universal-Core
* Copyright (C) 2020-2021 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef _UNIVERSAL_CORE_GUI_HPP
#define _UNIVERSAL_CORE_GUI_HPP
#include "screen.hpp"
#include <3ds.h>
#include <citro2d.h>
#include <citro3d.h>
namespace Gui {
/*
Clear the Text Buffer.
*/
void clearTextBufs(void);
/*
Draw a sprite from a SpriteSheet.
sheet: The SpriteSheet which should be used.
imgIndex: The index of the sprite from the sheet which should be drawn.
x: The X Position where the sprite should be drawn.
y: The Y Position where the sprite should be drawn.
ScaleX: The X-Scale for the sprite. (Optional!)
ScaleY: The Y-Scale for the sprite. (Optional!)
*/
void DrawSprite(C2D_SpriteSheet sheet, size_t imgindex, int x, int y, float ScaleX = 1, float ScaleY = 1);
/*
Initialize the GUI with Citro2D & Citro3D and initialize the Textbuffer.
call this when initializing.
fontRegion: The region to use for the system font.
*/
Result init(CFG_Region fontRegion = CFG_REGION_USA);
/*
Load a system font.
fontRegion: The region to use for the system font.
*/
void loadSystemFont(CFG_Region fontRegion = CFG_REGION_USA);
/*
Load a Font. (BCFNT)
fnt: The C2D_Font variable which should be initialized.
Path: Path to the BCFNT file.
if you're unsure, just call 'Gui::init();' and it will load the system font.
*/
Result loadFont(C2D_Font &fnt, const char *Path = "");
/*
Unload a Font. (BCFNT)
fnt: The C2D_Font variable which should be unloaded.
*/
Result unloadFont(C2D_Font &fnt);
/*
Load a spritesheet.
Path: Path to the SpriteSheet file. (T3X)
sheet: Reference to the C2D_SpriteSheet declaration.
*/
Result loadSheet(const char *Path, C2D_SpriteSheet &sheet);
/*
Unload a spritesheet.
sheet: Reference to the C2D_SpriteSheet which should be free'd.
*/
Result unloadSheet(C2D_SpriteSheet &sheet);
/*
Exit the GUI.
Call this at exit.
*/
void exit(void);
/*
Reinit the GUI.
fontRegion: The region to use for the system font.
*/
Result reinit(CFG_Region fontRegion = CFG_REGION_USA);
/*
Draws a centered String.
x: The X Offset from center. (Center: 200 px on top, 160 px on Bottom.)
y: The Y Position of the Text.
size: The size of the Text.
color: The Color of the Text.
Text: The Text which should be displayed.
maxWidth: The maxWidth for the Text. (Optional!)
maxHeight: The maxHeight of the Text. (Optional!)
fnt: The Font which should be used. Uses SystemFont by default. (Optional!)
int flags: C2D text flags to use. (Optional!)
*/
void DrawStringCentered(float x, float y, float size, u32 color, const std::string &Text, int maxWidth = 0, int maxHeight = 0, C2D_Font fnt = nullptr, int flags = 0);
/*
Draws a String.
x: The X Position where the Text should be drawn.
y: The Y Position where the Text should be drawn.
size: The size of the Text.
color: The Color of the Text.
Text: The Text which should be displayed.
maxWidth: The maxWidth for the Text. (Optional!)
maxHeight: The maxHeight of the Text. (Optional!)
fnt: The Font which should be used. Uses SystemFont by default. (Optional!)
flags: C2D text flags to use.
*/
void DrawString(float x, float y, float size, u32 color, const std::string &Text, int maxWidth = 0, int maxHeight = 0, C2D_Font fnt = nullptr, int flags = 0);
/*
Get the width of a String.
size: The size of the Text.
Text: The Text where the width should be getted from.
fnt: The Font which should be used. Uses SystemFont by default. (Optional!)
*/
float GetStringWidth(float size, const std::string &Text, C2D_Font fnt = nullptr);
/*
Get the size of a String.
size: The size of the Text.
width: The width of the Text.
height: The height of the Text.
Text: The Text where the size should be getted from.
fnt: The Font which should be used. Uses SystemFont by default. (Optional!)
*/
void GetStringSize(float size, float *width, float *height, const std::string &Text, C2D_Font fnt = nullptr);
/*
Get the height of a String.
size: The size of the Text.
Text: The Text where the height should be getted from.
fnt: The Font which should be used. Uses SystemFont by default. (Optional!)
*/
float GetStringHeight(float size, const std::string &Text, C2D_Font fnt = nullptr);
/*
Draw a Rectangle.
x: X Position of the Rectangle.
y: Y Position of the Rectangle.
w: The width of the rectangle.
h: The height of the rectangle.
color: The color of the rectangle.
*/
bool Draw_Rect(float x, float y, float w, float h, u32 color);
/*
Used for the current Screen's Draw. (Optional!)
stack: Is it the stack variant?
*/
void DrawScreen(bool stack = false);
/*
Used for the current Screen's Logic. (Optional!)
hDown: the hidKeysDown() variable.
hDownRepeat: the hidKeysDownRepeat() variable.
hHeld: the HidKeysHeld() variable.
touch: The TouchPosition variable.
waitFade: Wheter to wait until the fade ends.
stack: Is it the stack variant?
*/
#ifdef UC_KEY_REPEAT
void ScreenLogic(u32 hDown, u32 hDownRepeat, u32 hHeld, touchPosition touch, bool waitFade = true, bool stack = false);
#else
void ScreenLogic(u32 hDown, u32 hHeld, touchPosition touch, bool waitFade = true, bool stack = false);
#endif
/*
Transfer the Temp Screen to the used one. (Optional!)
stack: Is it the stack variant?
It will check, if the tempScreen variable is not nullptr, so don't worry.
*/
void transferScreen(bool stack = false);
/*
Set a specific Screen with switch function. (Optional!)
screen: unique_ptr of the screen. (Optional by using the screen class.)
screenSwitch: Wheter to switch to the current screen.
stack: Is it the stack variant?
*/
void setScreen(std::unique_ptr<Screen> screen, bool fade = false, bool stack = false);
/*
Fades into screens and calls the constructor after it. (Optional!)
fadeoutFrames: Amount of frames for fadeout.
fadeinFrames: Amount of frames for fadein.
stack: Is it the stack variant?
*/
void fadeEffects(int fadeoutFrames = 6, int fadeinFrames = 6, bool stack = false);
void screenBack(bool fade = false); // Goes a screen back. (Set!) (Stack only!)
void screenBack2(); // Goes a screen back.(Action!) (Stack only!)
/*
Set on which screen to draw.
screen: The render target. (Targets are inside the screenCommon.hpp file.)
*/
void ScreenDraw(C3D_RenderTarget * screen);
/*
Draws a grid.
xPos: X Position of the grid.
yPos: Y Position of the grid.
Width: Width of the grid.
Height: Height of the grid.
color: Color of the grid.
bgColor: The BG Color from the grid. (Optional! It's transparent by default.)
*/
void drawGrid(float xPos, float yPos, float Width, float Height, u32 color, u32 bgColor = C2D_Color32(0, 0, 0, 0));
/*
Draws an animated selector.
xPos: X Position of the selector.
yPos: Y Position of the Selector.
Width: Width of the Selector.
Height: Height of the Selector.
speed: The speed of the animation. (Use .030f or something by default.)
SelectorColor: The Color of the Selector outline.
bgColor: The BG Color from the selector. (Optional! It's transparent by default.)
*/
void drawAnimatedSelector(float xPos, float yPos, float Width, float Height, float speed, u32 SelectorColor, u32 bgColor = C2D_Color32(0, 0, 0, 0));
};
#endif