// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
#pragma once
#include "Engine/Core/Types/StringView.h"
#include "Engine/Scripting/ScriptingType.h"
///
/// Specifies identifiers to indicate the return value of a dialog box.
///
API_ENUM() enum class DialogResult
{
///
/// The abort.
///
Abort = 0,
///
/// The cancel.
///
Cancel,
///
/// The ignore.
///
Ignore,
///
/// The no.
///
No,
///
/// The none.
///
None,
///
/// The ok.
///
OK,
///
/// The retry.
///
Retry,
///
/// The yes.
///
Yes,
};
///
/// Specifies constants defining which information to display.
///
API_ENUM() enum class MessageBoxIcon
{
///
/// Asterisk
///
Asterisk,
///
/// Error
///
Error,
///
/// Exclamation
///
Exclamation,
///
/// Hand
///
Hand,
///
/// Information
///
Information,
///
/// None
///
None,
///
/// Question
///
Question,
///
/// Stop
///
Stop,
///
/// Warning
///
Warning,
};
///
/// Specifies constants defining which buttons to display on a Message Box.
///
API_ENUM() enum class MessageBoxButtons
{
///
/// Abort, Retry, Ignore
///
AbortRetryIgnore,
///
/// OK
///
OK,
///
/// OK, Cancel
///
OKCancel,
///
/// Retry, Cancel
///
RetryCancel,
///
/// Yes, No
///
YesNo,
///
/// Yes, No, Cancel
///
YesNoCancel,
};
///
/// Message dialogs utility (native platform).
///
API_CLASS(Static) class MessageBox
{
DECLARE_SCRIPTING_TYPE_NO_SPAWN(MessageBox);
///
/// Displays a message box with specified text.
///
/// The text to display in the message box.
/// The message box dialog result.
API_FUNCTION() FORCE_INLINE static DialogResult Show(const StringView& text)
{
return Show(nullptr, text, TEXT("Info"), MessageBoxButtons::OK, MessageBoxIcon::None);
}
///
/// Displays a message box with specified text and caption.
///
/// The text to display in the message box.
/// The text to display in the title bar of the message box.
/// The message box dialog result.
API_FUNCTION() FORCE_INLINE static DialogResult Show(const StringView& text, const StringView& caption)
{
return Show(nullptr, text, caption, MessageBoxButtons::OK, MessageBoxIcon::None);
}
///
/// Displays a message box with specified text, caption, buttons, and icon.
///
/// The text to display in the message box.
/// The text to display in the title bar of the message box.
/// One of the MessageBoxButtons values that specifies which buttons to display in the message box.
/// The message box dialog result.
API_FUNCTION() FORCE_INLINE static DialogResult Show(const StringView& text, const StringView& caption, MessageBoxButtons buttons)
{
return Show(nullptr, text, caption, buttons, MessageBoxIcon::None);
}
///
/// Displays a message box with specified text, caption, buttons, and icon.
///
/// The text to display in the message box.
/// The text to display in the title bar of the message box.
/// One of the MessageBoxButtons values that specifies which buttons to display in the message box.
/// One of the MessageBoxIcon values that specifies which icon to display in the message box.
/// The message box dialog result.
API_FUNCTION() FORCE_INLINE static DialogResult Show(const StringView& text, const StringView& caption, MessageBoxButtons buttons, MessageBoxIcon icon)
{
return Show(nullptr, text, caption, buttons, icon);
}
///
/// Displays a message box with specified text.
///
/// The parent window or null if not used.
/// The text to display in the message box.
/// The message box dialog result.
API_FUNCTION() FORCE_INLINE static DialogResult Show(Window* parent, const StringView& text)
{
return Show(parent, *text, TEXT("Info"), MessageBoxButtons::OK, MessageBoxIcon::None);
}
///
/// Displays a message box with specified text and caption.
///
/// The parent window or null if not used.
/// The text to display in the message box.
/// The text to display in the title bar of the message box.
/// The message box dialog result.
API_FUNCTION() FORCE_INLINE static DialogResult Show(Window* parent, const StringView& text, const StringView& caption)
{
return Show(parent, *text, *caption, MessageBoxButtons::OK, MessageBoxIcon::None);
}
///
/// Displays a message box with specified text, caption and buttons.
///
/// The parent window or null if not used.
/// The text to display in the message box.
/// The text to display in the title bar of the message box.
/// One of the MessageBoxButtons values that specifies which buttons to display in the message box.
/// The message box dialog result.
API_FUNCTION() FORCE_INLINE static DialogResult Show(Window* parent, const StringView& text, const StringView& caption, MessageBoxButtons buttons)
{
return Show(parent, text, caption, buttons, MessageBoxIcon::None);
}
///
/// Displays a message box with specified text, caption, buttons, and icon.
///
/// The parent window or null if not used.
/// The text to display in the message box.
/// The text to display in the title bar of the message box.
/// One of the MessageBoxButtons values that specifies which buttons to display in the message box.
/// One of the MessageBoxIcon values that specifies which icon to display in the message box.
/// The message box dialog result.
API_FUNCTION() static DialogResult Show(Window* parent, const StringView& text, const StringView& caption, MessageBoxButtons buttons, MessageBoxIcon icon);
private:
#if PLATFORM_SDL && PLATFORM_LINUX
static DialogResult ShowFallback(Window* parent, const StringView& text, const StringView& caption, MessageBoxButtons buttons, MessageBoxIcon icon);
#endif
};