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
29using MessageBoxRaw = SDL_MessageBoxData;
30
31// Forward decl
32struct MessageBox;
33
47
49 SDL_MESSAGEBOX_ERROR;
50
52 SDL_MESSAGEBOX_WARNING;
53
55 SDL_MESSAGEBOX_INFORMATION;
56
58 SDL_MESSAGEBOX_BUTTONS_LEFT_TO_RIGHT;
59
61 SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT;
62
64
76
78 SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT;
80
82 SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT;
84
86
92using MessageBoxButtonData = SDL_MessageBoxButtonData;
93
99using MessageBoxColor = SDL_MessageBoxColor;
100
107using MessageBoxColorType = SDL_MessageBoxColorType;
108
110 SDL_MESSAGEBOX_COLOR_BACKGROUND;
111
113 SDL_MESSAGEBOX_COLOR_TEXT;
114
116 SDL_MESSAGEBOX_COLOR_BUTTON_BORDER;
117
119 SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND;
120
122 SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED;
123
125 SDL_MESSAGEBOX_COLOR_COUNT;
128
134using MessageBoxColorScheme = SDL_MessageBoxColorScheme;
135
142{
148 constexpr MessageBox(const MessageBoxRaw& messageBox = {}) noexcept
149 : MessageBoxRaw(messageBox)
150 {
151 }
152
163 constexpr MessageBox(
164 MessageBoxFlags flags,
165 WindowRef window,
166 const char* title,
167 const char* message,
168 std::span<const MessageBoxButtonData> buttons,
169 OptionalRef<const MessageBoxColorScheme> colorScheme) noexcept
170 : MessageBoxRaw{flags,
171 window.get(),
172 title,
173 message,
174 int(buttons.size()),
175 buttons.data(),
176 colorScheme}
177 {
178 }
179
185 constexpr SDL_MessageBoxFlags GetFlags() const noexcept { return flags; }
186
193 constexpr MessageBox& SetFlags(SDL_MessageBoxFlags newFlags) noexcept
194 {
195 flags = newFlags;
196 return *this;
197 }
198
204 constexpr SDL_Window* GetWindow() const noexcept { return window; }
205
212 constexpr MessageBox& SetWindow(SDL_Window* newWindow) noexcept
213 {
214 window = newWindow;
215 return *this;
216 }
217
223 constexpr const char* GetTitle() const noexcept { return title; }
224
231 constexpr MessageBox& SetTitle(const char* newTitle) noexcept
232 {
233 title = newTitle;
234 return *this;
235 }
236
242 constexpr const char* GetMessage() const noexcept { return message; }
243
250 constexpr MessageBox& SetMessage(const char* newMessage) noexcept
251 {
252 message = newMessage;
253 return *this;
254 }
255
261 constexpr int GetNumbuttons() const noexcept { return numbuttons; }
262
269 constexpr MessageBox& SetNumbuttons(int newNumbuttons) noexcept
270 {
271 numbuttons = newNumbuttons;
272 return *this;
273 }
274
280 constexpr std::span<const MessageBoxButtonData> GetButtons() const noexcept
281 {
282 if (numbuttons == 0) return {};
283 return std::span(buttons, size_t(numbuttons));
284 }
285
293 std::span<const MessageBoxButtonData> newButtons) noexcept
294 {
295 if (newButtons.empty()) {
296 numbuttons = 0;
297 buttons = nullptr;
298 } else {
299 numbuttons = newButtons.size();
300 buttons = newButtons.data();
301 }
302 return *this;
303 }
304
310 constexpr const MessageBoxColorScheme* GetColorScheme() const noexcept
311 {
312 return colorScheme;
313 }
314
322 OptionalRef<const MessageBoxColorScheme> newColorScheme) noexcept
323 {
324 colorScheme = newColorScheme;
325 return *this;
326 }
327
359 void Show(int* buttonid) const;
360};
361
393inline void ShowMessageBox(const MessageBoxRaw& messageboxdata, int* buttonid)
394{
395 CheckError(SDL_ShowMessageBox(&messageboxdata, buttonid));
396}
397
398inline void MessageBox::Show(int* buttonid) const
399{
400 SDL::ShowMessageBox(*this, buttonid);
401}
402
443 StringParam title,
444 StringParam message,
445 WindowParam window)
446{
447 CheckError(SDL_ShowSimpleMessageBox(flags, title, message, window));
448}
449
451
452} // namespace SDL
453
454#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:197
constexpr MessageBoxFlags MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT
buttons placed right to left
Definition: SDL3pp_messagebox.h:60
SDL_MessageBoxButtonData MessageBoxButtonData
Individual button data.
Definition: SDL3pp_messagebox.h:92
SDL_MessageBoxData MessageBoxRaw
Alias to raw representation for MessageBox.
Definition: SDL3pp_messagebox.h:29
constexpr MessageBoxFlags MESSAGEBOX_INFORMATION
informational dialog
Definition: SDL3pp_messagebox.h:54
Uint32 MessageBoxFlags
Message box flags.
Definition: SDL3pp_messagebox.h:46
constexpr MessageBoxButtonFlags MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT
Marks the default button when escape is hit.
Definition: SDL3pp_messagebox.h:81
void Show(int *buttonid) const
Create a modal message box.
Definition: SDL3pp_messagebox.h:398
constexpr MessageBoxColorType MESSAGEBOX_COLOR_COUNT
Size of the colors array of MessageBoxColorScheme.
Definition: SDL3pp_messagebox.h:124
SDL_MessageBoxColorType MessageBoxColorType
An enumeration of indices inside the colors array of MessageBoxColorScheme.
Definition: SDL3pp_messagebox.h:107
constexpr MessageBoxColorType MESSAGEBOX_COLOR_BUTTON_BORDER
BUTTON_BORDER.
Definition: SDL3pp_messagebox.h:115
constexpr MessageBoxColorType MESSAGEBOX_COLOR_BUTTON_BACKGROUND
BUTTON_BACKGROUND.
Definition: SDL3pp_messagebox.h:118
constexpr MessageBoxButtonFlags MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT
Marks the default button when return is hit.
Definition: SDL3pp_messagebox.h:77
constexpr MessageBoxFlags MESSAGEBOX_ERROR
error dialog
Definition: SDL3pp_messagebox.h:48
constexpr MessageBoxFlags MESSAGEBOX_BUTTONS_LEFT_TO_RIGHT
buttons placed left to right
Definition: SDL3pp_messagebox.h:57
SDL_MessageBoxColorScheme MessageBoxColorScheme
A set of colors to use for message box dialogs.
Definition: SDL3pp_messagebox.h:134
constexpr MessageBoxColorType MESSAGEBOX_COLOR_TEXT
TEXT.
Definition: SDL3pp_messagebox.h:112
void ShowSimpleMessageBox(MessageBoxFlags flags, StringParam title, StringParam message, WindowParam window)
Display a simple modal message box.
Definition: SDL3pp_messagebox.h:442
constexpr MessageBoxFlags MESSAGEBOX_WARNING
warning dialog
Definition: SDL3pp_messagebox.h:51
constexpr MessageBoxColorType MESSAGEBOX_COLOR_BUTTON_SELECTED
BUTTON_SELECTED.
Definition: SDL3pp_messagebox.h:121
constexpr MessageBoxColorType MESSAGEBOX_COLOR_BACKGROUND
BACKGROUND.
Definition: SDL3pp_messagebox.h:109
SDL_MessageBoxColor MessageBoxColor
RGB value used in a message box color scheme.
Definition: SDL3pp_messagebox.h:99
Uint32 MessageBoxButtonFlags
MessageBoxButtonData flags.
Definition: SDL3pp_messagebox.h:75
void ShowMessageBox(const MessageBoxRaw &messageboxdata, int *buttonid)
Create a modal message box.
Definition: SDL3pp_messagebox.h:393
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition: SDL3pp_stdinc.h:341
Main include header for the SDL3pp library.
MessageBox structure containing title, text, window, etc.
Definition: SDL3pp_messagebox.h:142
constexpr SDL_Window * GetWindow() const noexcept
Get the window.
Definition: SDL3pp_messagebox.h:204
constexpr const char * GetMessage() const noexcept
Get the message.
Definition: SDL3pp_messagebox.h:242
constexpr MessageBox & SetFlags(SDL_MessageBoxFlags newFlags) noexcept
Set the flags.
Definition: SDL3pp_messagebox.h:193
constexpr MessageBox & SetButtons(std::span< const MessageBoxButtonData > newButtons) noexcept
Set the buttons.
Definition: SDL3pp_messagebox.h:292
constexpr std::span< const MessageBoxButtonData > GetButtons() const noexcept
Get the buttons.
Definition: SDL3pp_messagebox.h:280
constexpr MessageBox(const MessageBoxRaw &messageBox={}) noexcept
Wraps MessageBox.
Definition: SDL3pp_messagebox.h:148
constexpr const char * GetTitle() const noexcept
Get the title.
Definition: SDL3pp_messagebox.h:223
constexpr int GetNumbuttons() const noexcept
Get the numbuttons.
Definition: SDL3pp_messagebox.h:261
constexpr MessageBox(MessageBoxFlags flags, WindowRef window, const char *title, const char *message, std::span< const MessageBoxButtonData > buttons, OptionalRef< const MessageBoxColorScheme > colorScheme) noexcept
Constructs from its fields.
Definition: SDL3pp_messagebox.h:163
constexpr MessageBox & SetMessage(const char *newMessage) noexcept
Set the message.
Definition: SDL3pp_messagebox.h:250
constexpr MessageBox & SetColorScheme(OptionalRef< const MessageBoxColorScheme > newColorScheme) noexcept
Set the colorScheme.
Definition: SDL3pp_messagebox.h:321
constexpr const MessageBoxColorScheme * GetColorScheme() const noexcept
Get the colorScheme.
Definition: SDL3pp_messagebox.h:310
constexpr MessageBox & SetNumbuttons(int newNumbuttons) noexcept
Set the numbuttons.
Definition: SDL3pp_messagebox.h:269
constexpr MessageBox & SetWindow(SDL_Window *newWindow) noexcept
Set the window.
Definition: SDL3pp_messagebox.h:212
constexpr MessageBox & SetTitle(const char *newTitle) noexcept
Set the title.
Definition: SDL3pp_messagebox.h:231
constexpr SDL_MessageBoxFlags GetFlags() const noexcept
Get the flags.
Definition: SDL3pp_messagebox.h:185
Safely wrap Window for non owning parameters.
Definition: SDL3pp_video.h:54
Semi-safe reference for Window.
Definition: SDL3pp_video.h:2962