SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
SDL3pp_messagebox.h
1#ifndef SDL3PP_MESSAGEBOX_H_
2#define SDL3PP_MESSAGEBOX_H_
3
4#include <SDL3/SDL_messagebox.h>
5#include "SDL3pp_stdinc.h"
6#include "SDL3pp_video.h"
7
8namespace SDL {
9
42using MessageBoxFlags = Uint32;
43
45 SDL_MESSAGEBOX_ERROR;
46
48 SDL_MESSAGEBOX_WARNING;
49
51 SDL_MESSAGEBOX_INFORMATION;
52
54 SDL_MESSAGEBOX_BUTTONS_LEFT_TO_RIGHT;
55
57 SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT;
58
60
71using MessageBoxButtonFlags = Uint32;
72
74 SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT;
76
78 SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT;
80
82
88using MessageBoxButtonData = SDL_MessageBoxButtonData;
89
95using MessageBoxColor = SDL_MessageBoxColor;
96
106using MessageBoxColorType = SDL_MessageBoxColorType;
107
109 SDL_MESSAGEBOX_COLOR_BACKGROUND;
110
112 SDL_MESSAGEBOX_COLOR_TEXT;
113
115 SDL_MESSAGEBOX_COLOR_BUTTON_BORDER;
116
118 SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND;
119
121 SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED;
122
124 SDL_MESSAGEBOX_COLOR_COUNT;
125
127
133using MessageBoxColorScheme = SDL_MessageBoxColorScheme;
134
140struct MessageBox : SDL_MessageBoxData
141{
147 constexpr MessageBox(const SDL_MessageBoxData& messageBox = {})
148 : SDL_MessageBoxData{messageBox}
149 {
150 }
151
163 OptionalWindow window,
164 const char* title,
165 const char* message,
166 std::span<const MessageBoxButtonData> buttons,
168 : SDL_MessageBoxData{flags,
169 window.get(),
170 title,
171 message,
172 int(buttons.size()),
173 buttons.data(),
174 colorScheme}
175 {
176 }
177
209 void Show(int* buttonid) const
210 {
211 CheckError(SDL_ShowMessageBox(this, buttonid));
212 }
213
219 constexpr SDL_MessageBoxFlags GetFlags() const { return flags; }
220
227 constexpr MessageBox& SetFlags(SDL_MessageBoxFlags newFlags)
228 {
229 flags = newFlags;
230 return *this;
231 }
232
238 constexpr WindowRef GetWindow() const { return window; }
239
246 constexpr MessageBox& SetWindow(WindowRef newWindow)
247 {
248 window = newWindow.get();
249 return *this;
250 }
251
257 constexpr const char* GetTitle() const { return title; }
258
265 constexpr MessageBox& SetTitle(const char* newTitle)
266 {
267 title = newTitle;
268 return *this;
269 }
270
276 constexpr const char* GetMessage() const { return message; }
277
284 constexpr MessageBox& SetMessage(const char* newMessage)
285 {
286 message = newMessage;
287 return *this;
288 }
289
295 constexpr std::span<const MessageBoxButtonData> GetButtons() const
296 {
297 if (numbuttons == 0) return {};
298 return std::span(buttons, size_t(numbuttons));
299 }
300
308 std::span<const MessageBoxButtonData> newButtons)
309 {
310 if (newButtons.empty()) {
311 numbuttons = 0;
312 buttons = nullptr;
313 } else {
314 numbuttons = newButtons.size();
315 buttons = newButtons.data();
316 }
317 return *this;
318 }
319
325 constexpr const MessageBoxColorScheme* GetColorScheme() const
326 {
327 return colorScheme;
328 }
329
338 {
339 colorScheme = newColorScheme;
340 return *this;
341 }
342};
343
384 StringParam title,
385 StringParam message,
386 OptionalWindow window)
387{
388 CheckError(SDL_ShowSimpleMessageBox(flags, title, message, window.get()));
389}
390
392
393} // namespace SDL
394
395#endif /* SDL3PP_MESSAGEBOX_H_ */
Optional-like shim for references.
Definition SDL3pp_optionalRef.h:20
A optional reference to resource.
Definition SDL3pp_resource.h:88
constexpr T get() const
Return contained resource;.
Definition SDL3pp_resource.h:57
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:43
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:206
void ShowSimpleMessageBox(MessageBoxFlags flags, StringParam title, StringParam message, OptionalWindow window)
Display a simple modal message box.
Definition SDL3pp_messagebox.h:383
constexpr MessageBoxFlags MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT
buttons placed right to left
Definition SDL3pp_messagebox.h:56
SDL_MessageBoxButtonData MessageBoxButtonData
Individual button data.
Definition SDL3pp_messagebox.h:88
constexpr MessageBoxFlags MESSAGEBOX_INFORMATION
informational dialog
Definition SDL3pp_messagebox.h:50
Uint32 MessageBoxFlags
Message box flags.
Definition SDL3pp_messagebox.h:42
constexpr MessageBoxButtonFlags MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT
Marks the default button when escape is hit.
Definition SDL3pp_messagebox.h:77
constexpr MessageBoxColorType MESSAGEBOX_COLOR_COUNT
Count.
Definition SDL3pp_messagebox.h:123
SDL_MessageBoxColorType MessageBoxColorType
An enumeration of indices inside the colors array of MessageBoxColorScheme.
Definition SDL3pp_messagebox.h:106
constexpr MessageBoxColorType MESSAGEBOX_COLOR_BUTTON_BORDER
BUTTON_BORDER.
Definition SDL3pp_messagebox.h:114
constexpr MessageBoxColorType MESSAGEBOX_COLOR_BUTTON_BACKGROUND
BUTTON_BACKGROUND.
Definition SDL3pp_messagebox.h:117
constexpr MessageBoxButtonFlags MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT
Marks the default button when return is hit.
Definition SDL3pp_messagebox.h:73
constexpr MessageBoxFlags MESSAGEBOX_ERROR
error dialog
Definition SDL3pp_messagebox.h:44
constexpr MessageBoxFlags MESSAGEBOX_BUTTONS_LEFT_TO_RIGHT
buttons placed left to right
Definition SDL3pp_messagebox.h:53
SDL_MessageBoxColorScheme MessageBoxColorScheme
A set of colors to use for message box dialogs.
Definition SDL3pp_messagebox.h:133
constexpr MessageBoxColorType MESSAGEBOX_COLOR_TEXT
TEXT.
Definition SDL3pp_messagebox.h:111
constexpr MessageBoxFlags MESSAGEBOX_WARNING
warning dialog
Definition SDL3pp_messagebox.h:47
constexpr MessageBoxColorType MESSAGEBOX_COLOR_BUTTON_SELECTED
BUTTON_SELECTED.
Definition SDL3pp_messagebox.h:120
constexpr MessageBoxColorType MESSAGEBOX_COLOR_BACKGROUND
BACKGROUND.
Definition SDL3pp_messagebox.h:108
SDL_MessageBoxColor MessageBoxColor
RGB value used in a message box color scheme.
Definition SDL3pp_messagebox.h:95
Uint32 MessageBoxButtonFlags
MessageBoxButtonData flags.
Definition SDL3pp_messagebox.h:71
the main namespace where all SDL3pp public functions and types live
Definition SDL3pp_assert.h:7
MessageBox structure containing title, text, window, etc.
Definition SDL3pp_messagebox.h:141
constexpr MessageBox & SetColorScheme(OptionalRef< const MessageBoxColorScheme > newColorScheme)
Set the colorScheme.
Definition SDL3pp_messagebox.h:336
constexpr MessageBox & SetTitle(const char *newTitle)
Set the title.
Definition SDL3pp_messagebox.h:265
constexpr MessageBox & SetMessage(const char *newMessage)
Set the message.
Definition SDL3pp_messagebox.h:284
constexpr const char * GetMessage() const
Get the message.
Definition SDL3pp_messagebox.h:276
void Show(int *buttonid) const
Create a modal message box.
Definition SDL3pp_messagebox.h:209
constexpr const char * GetTitle() const
Get the title.
Definition SDL3pp_messagebox.h:257
constexpr WindowRef GetWindow() const
Get the window.
Definition SDL3pp_messagebox.h:238
constexpr std::span< const MessageBoxButtonData > GetButtons() const
Get the buttons.
Definition SDL3pp_messagebox.h:295
constexpr SDL_MessageBoxFlags GetFlags() const
Get the flags.
Definition SDL3pp_messagebox.h:219
constexpr MessageBox(const SDL_MessageBoxData &messageBox={})
Wraps MessageBox.
Definition SDL3pp_messagebox.h:147
constexpr MessageBox(MessageBoxFlags flags, OptionalWindow window, const char *title, const char *message, std::span< const MessageBoxButtonData > buttons, OptionalRef< const MessageBoxColorScheme > colorScheme)
Constructs from its fields.
Definition SDL3pp_messagebox.h:162
constexpr MessageBox & SetWindow(WindowRef newWindow)
Set the window.
Definition SDL3pp_messagebox.h:246
constexpr const MessageBoxColorScheme * GetColorScheme() const
Get the colorScheme.
Definition SDL3pp_messagebox.h:325
constexpr MessageBox & SetFlags(SDL_MessageBoxFlags newFlags)
Set the flags.
Definition SDL3pp_messagebox.h:227
constexpr MessageBox & SetButtons(std::span< const MessageBoxButtonData > newButtons)
Set the buttons.
Definition SDL3pp_messagebox.h:307
Handle to a non owned window.
Definition SDL3pp_video.h:2778