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
30using MessageBoxRaw = SDL_MessageBoxData;
31
32// Forward decl
33struct MessageBox;
34
48
50 SDL_MESSAGEBOX_ERROR;
51
53 SDL_MESSAGEBOX_WARNING;
54
56 SDL_MESSAGEBOX_INFORMATION;
57
59 SDL_MESSAGEBOX_BUTTONS_LEFT_TO_RIGHT;
60
62 SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT;
63
65
77
79 SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT;
81
83 SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT;
85
87
93using MessageBoxButtonData = SDL_MessageBoxButtonData;
94
100using MessageBoxColor = SDL_MessageBoxColor;
101
111using MessageBoxColorType = SDL_MessageBoxColorType;
112
114 SDL_MESSAGEBOX_COLOR_BACKGROUND;
115
117 SDL_MESSAGEBOX_COLOR_TEXT;
118
120 SDL_MESSAGEBOX_COLOR_BUTTON_BORDER;
121
123 SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND;
124
126 SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED;
127
129 SDL_MESSAGEBOX_COLOR_COUNT;
132
138using MessageBoxColorScheme = SDL_MessageBoxColorScheme;
139
146{
152 constexpr MessageBox(const MessageBoxRaw& messageBox = {})
153 : MessageBoxRaw(messageBox)
154 {
155 }
156
168 WindowRef window,
169 const char* title,
170 const char* message,
171 std::span<const MessageBoxButtonData> buttons,
173 : MessageBoxRaw{flags,
174 window.get(),
175 title,
176 message,
177 int(buttons.size()),
178 buttons.data(),
179 colorScheme}
180 {
181 }
182
188 constexpr SDL_MessageBoxFlags GetFlags() const { return flags; }
189
196 constexpr MessageBox& SetFlags(SDL_MessageBoxFlags newFlags)
197 {
198 flags = newFlags;
199 return *this;
200 }
201
207 constexpr SDL_Window* GetWindow() const { return window; }
208
215 constexpr MessageBox& SetWindow(SDL_Window* newWindow)
216 {
217 window = newWindow;
218 return *this;
219 }
220
226 constexpr const char* GetTitle() const { return title; }
227
234 constexpr MessageBox& SetTitle(const char* newTitle)
235 {
236 title = newTitle;
237 return *this;
238 }
239
245 constexpr const char* GetMessage() const { return message; }
246
253 constexpr MessageBox& SetMessage(const char* newMessage)
254 {
255 message = newMessage;
256 return *this;
257 }
258
264 constexpr int GetNumbuttons() const { return numbuttons; }
265
272 constexpr MessageBox& SetNumbuttons(int newNumbuttons)
273 {
274 numbuttons = newNumbuttons;
275 return *this;
276 }
277
283 constexpr std::span<const MessageBoxButtonData> GetButtons() const
284 {
285 if (numbuttons == 0) return {};
286 return std::span(buttons, size_t(numbuttons));
287 }
288
296 std::span<const MessageBoxButtonData> newButtons)
297 {
298 if (newButtons.empty()) {
299 numbuttons = 0;
300 buttons = nullptr;
301 } else {
302 numbuttons = newButtons.size();
303 buttons = newButtons.data();
304 }
305 return *this;
306 }
307
313 constexpr const MessageBoxColorScheme* GetColorScheme() const
314 {
315 return colorScheme;
316 }
317
326 {
327 colorScheme = newColorScheme;
328 return *this;
329 }
330
363 void Show(int* buttonid) const;
364};
365
399inline void ShowMessageBox(const MessageBoxRaw& messageboxdata, int* buttonid)
400{
401 CheckError(SDL_ShowMessageBox(&messageboxdata, buttonid));
402}
403
404inline void MessageBox::Show(int* buttonid) const
405{
406 SDL::ShowMessageBox(*this, buttonid);
407}
408
449 StringParam title,
450 StringParam message,
451 WindowParam window)
452{
453 CheckError(SDL_ShowSimpleMessageBox(flags, title, message, window));
454}
455
457
458} // namespace SDL
459
460#endif /* SDL3PP_MESSAGEBOX_H_ */
Optional-like shim for references.
Definition: SDL3pp_optionalRef.h:20
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:198
constexpr MessageBoxFlags MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT
buttons placed right to left
Definition: SDL3pp_messagebox.h:61
SDL_MessageBoxButtonData MessageBoxButtonData
Individual button data.
Definition: SDL3pp_messagebox.h:93
SDL_MessageBoxData MessageBoxRaw
Alias to raw representation for MessageBox.
Definition: SDL3pp_messagebox.h:30
constexpr MessageBoxFlags MESSAGEBOX_INFORMATION
informational dialog
Definition: SDL3pp_messagebox.h:55
Uint32 MessageBoxFlags
Message box flags.
Definition: SDL3pp_messagebox.h:47
constexpr MessageBoxButtonFlags MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT
Marks the default button when escape is hit.
Definition: SDL3pp_messagebox.h:82
void Show(int *buttonid) const
Create a modal message box.
Definition: SDL3pp_messagebox.h:404
constexpr MessageBoxColorType MESSAGEBOX_COLOR_COUNT
Size of the colors array of MessageBoxColorScheme.
Definition: SDL3pp_messagebox.h:128
SDL_MessageBoxColorType MessageBoxColorType
An enumeration of indices inside the colors array of MessageBoxColorScheme.
Definition: SDL3pp_messagebox.h:111
constexpr MessageBoxColorType MESSAGEBOX_COLOR_BUTTON_BORDER
BUTTON_BORDER.
Definition: SDL3pp_messagebox.h:119
constexpr MessageBoxColorType MESSAGEBOX_COLOR_BUTTON_BACKGROUND
BUTTON_BACKGROUND.
Definition: SDL3pp_messagebox.h:122
constexpr MessageBoxButtonFlags MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT
Marks the default button when return is hit.
Definition: SDL3pp_messagebox.h:78
constexpr MessageBoxFlags MESSAGEBOX_ERROR
error dialog
Definition: SDL3pp_messagebox.h:49
constexpr MessageBoxFlags MESSAGEBOX_BUTTONS_LEFT_TO_RIGHT
buttons placed left to right
Definition: SDL3pp_messagebox.h:58
SDL_MessageBoxColorScheme MessageBoxColorScheme
A set of colors to use for message box dialogs.
Definition: SDL3pp_messagebox.h:138
constexpr MessageBoxColorType MESSAGEBOX_COLOR_TEXT
TEXT.
Definition: SDL3pp_messagebox.h:116
void ShowSimpleMessageBox(MessageBoxFlags flags, StringParam title, StringParam message, WindowParam window)
Display a simple modal message box.
Definition: SDL3pp_messagebox.h:448
constexpr MessageBoxFlags MESSAGEBOX_WARNING
warning dialog
Definition: SDL3pp_messagebox.h:52
constexpr MessageBoxColorType MESSAGEBOX_COLOR_BUTTON_SELECTED
BUTTON_SELECTED.
Definition: SDL3pp_messagebox.h:125
constexpr MessageBoxColorType MESSAGEBOX_COLOR_BACKGROUND
BACKGROUND.
Definition: SDL3pp_messagebox.h:113
SDL_MessageBoxColor MessageBoxColor
RGB value used in a message box color scheme.
Definition: SDL3pp_messagebox.h:100
Uint32 MessageBoxButtonFlags
MessageBoxButtonData flags.
Definition: SDL3pp_messagebox.h:76
void ShowMessageBox(const MessageBoxRaw &messageboxdata, int *buttonid)
Create a modal message box.
Definition: SDL3pp_messagebox.h:399
Uint32 Uint32
An unsigned 32-bit integer type.
Definition: SDL3pp_stdinc.h:328
Main include header for the SDL3pp library.
MessageBox structure containing title, text, window, etc.
Definition: SDL3pp_messagebox.h:146
constexpr MessageBox & SetColorScheme(OptionalRef< const MessageBoxColorScheme > newColorScheme)
Set the colorScheme.
Definition: SDL3pp_messagebox.h:324
constexpr SDL_Window * GetWindow() const
Get the window.
Definition: SDL3pp_messagebox.h:207
constexpr MessageBox & SetTitle(const char *newTitle)
Set the title.
Definition: SDL3pp_messagebox.h:234
constexpr MessageBox & SetMessage(const char *newMessage)
Set the message.
Definition: SDL3pp_messagebox.h:253
constexpr const char * GetMessage() const
Get the message.
Definition: SDL3pp_messagebox.h:245
constexpr const char * GetTitle() const
Get the title.
Definition: SDL3pp_messagebox.h:226
constexpr std::span< const MessageBoxButtonData > GetButtons() const
Get the buttons.
Definition: SDL3pp_messagebox.h:283
constexpr SDL_MessageBoxFlags GetFlags() const
Get the flags.
Definition: SDL3pp_messagebox.h:188
constexpr MessageBox & SetNumbuttons(int newNumbuttons)
Set the numbuttons.
Definition: SDL3pp_messagebox.h:272
constexpr int GetNumbuttons() const
Get the numbuttons.
Definition: SDL3pp_messagebox.h:264
constexpr const MessageBoxColorScheme * GetColorScheme() const
Get the colorScheme.
Definition: SDL3pp_messagebox.h:313
constexpr MessageBox(MessageBoxFlags flags, WindowRef window, const char *title, const char *message, std::span< const MessageBoxButtonData > buttons, OptionalRef< const MessageBoxColorScheme > colorScheme)
Constructs from its fields.
Definition: SDL3pp_messagebox.h:167
constexpr MessageBox & SetFlags(SDL_MessageBoxFlags newFlags)
Set the flags.
Definition: SDL3pp_messagebox.h:196
constexpr MessageBox(const MessageBoxRaw &messageBox={})
Wraps MessageBox.
Definition: SDL3pp_messagebox.h:152
constexpr MessageBox & SetButtons(std::span< const MessageBoxButtonData > newButtons)
Set the buttons.
Definition: SDL3pp_messagebox.h:295
constexpr MessageBox & SetWindow(SDL_Window *newWindow)
Set the window.
Definition: SDL3pp_messagebox.h:215
Safely wrap Window for non owning parameters.
Definition: SDL3pp_video.h:57
Semi-safe reference for Window.
Definition: SDL3pp_video.h:2925