Platform: Add MessageBox
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
#include <Nazara/Platform/Enums.hpp>
|
||||
#include <Nazara/Platform/Icon.hpp>
|
||||
#include <Nazara/Platform/Keyboard.hpp>
|
||||
#include <Nazara/Platform/MessageBox.hpp>
|
||||
#include <Nazara/Platform/Mouse.hpp>
|
||||
#include <Nazara/Platform/Platform.hpp>
|
||||
#include <Nazara/Platform/VideoMode.hpp>
|
||||
|
||||
@@ -20,6 +20,45 @@ namespace Nz
|
||||
Max = Text
|
||||
};
|
||||
|
||||
enum class MessageBoxButtonRole
|
||||
{
|
||||
Accept,
|
||||
None,
|
||||
Reject,
|
||||
|
||||
Max = Reject
|
||||
};
|
||||
|
||||
enum class MessageBoxType
|
||||
{
|
||||
Info,
|
||||
Error,
|
||||
Warning,
|
||||
|
||||
Max = Warning
|
||||
};
|
||||
|
||||
enum class MessageBoxStandardButton
|
||||
{
|
||||
Abort,
|
||||
Apply,
|
||||
Cancel,
|
||||
Close,
|
||||
Discard,
|
||||
Ignore,
|
||||
No,
|
||||
NoToAll,
|
||||
Ok,
|
||||
Reset,
|
||||
Retry,
|
||||
Save,
|
||||
SaveAll,
|
||||
Yes,
|
||||
YesToAll,
|
||||
|
||||
Max = YesToAll
|
||||
};
|
||||
|
||||
enum class SystemCursor
|
||||
{
|
||||
Crosshair,
|
||||
|
||||
79
include/Nazara/Platform/MessageBox.hpp
Normal file
79
include/Nazara/Platform/MessageBox.hpp
Normal file
@@ -0,0 +1,79 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Platform module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PLATFORM_MESSAGEBOX_HPP
|
||||
#define NAZARA_PLATFORM_MESSAGEBOX_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Platform/Config.hpp>
|
||||
#include <Nazara/Platform/Enums.hpp>
|
||||
#include <NazaraUtils/Result.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Window;
|
||||
|
||||
class NAZARA_PLATFORM_API MessageBox
|
||||
{
|
||||
public:
|
||||
struct ColorScheme;
|
||||
|
||||
inline MessageBox(MessageBoxType type, std::string title, std::string message);
|
||||
MessageBox(const MessageBox&) = delete;
|
||||
MessageBox(MessageBox&&) = delete;
|
||||
~MessageBox() = default;
|
||||
|
||||
inline void AddButton(int id, std::string text, MessageBoxButtonRole role = MessageBoxButtonRole::None);
|
||||
void AddButton(int id, MessageBoxStandardButton standardButton);
|
||||
|
||||
inline const ColorScheme* GetColorSchemeOverride() const;
|
||||
inline const std::string& GetMessage() const;
|
||||
inline const std::string& GetTitle() const;
|
||||
|
||||
inline void OverrideColorScheme(const ColorScheme& colorScheme);
|
||||
|
||||
inline void ResetColorScheme();
|
||||
|
||||
Result<int, const char*> Show(Window* parent = nullptr) const;
|
||||
|
||||
inline void UpdateMessage(std::string message);
|
||||
inline void UpdateTitle(std::string title);
|
||||
inline void UpdateType(MessageBoxType type);
|
||||
|
||||
MessageBox& operator=(const MessageBox&) = delete;
|
||||
MessageBox& operator=(MessageBox&&) = delete;
|
||||
|
||||
struct ColorScheme
|
||||
{
|
||||
Color backgroundColor = Color::White();
|
||||
Color textColor = Color::Black();
|
||||
Color buttonBackgroundColor = Color::Gray();
|
||||
Color buttonBorderColor = Color::Black();
|
||||
Color buttonSelectedColor = Color::Blue();
|
||||
};
|
||||
|
||||
private:
|
||||
struct ButtonData
|
||||
{
|
||||
MessageBoxButtonRole role;
|
||||
std::string text;
|
||||
int buttonId;
|
||||
};
|
||||
|
||||
std::optional<ColorScheme> m_colorSchemeOverride;
|
||||
std::string m_message;
|
||||
std::string m_title;
|
||||
std::vector<ButtonData> m_buttons;
|
||||
MessageBoxType m_type;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Platform/MessageBox.inl>
|
||||
|
||||
#endif // NAZARA_PLATFORM_MESSAGEBOX_HPP
|
||||
70
include/Nazara/Platform/MessageBox.inl
Normal file
70
include/Nazara/Platform/MessageBox.inl
Normal file
@@ -0,0 +1,70 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Platform module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <NazaraUtils/Algorithm.hpp>
|
||||
#include <Nazara/Platform/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline MessageBox::MessageBox(MessageBoxType type, std::string title, std::string message) :
|
||||
m_message(std::move(message)),
|
||||
m_title(std::move(title)),
|
||||
m_type(type)
|
||||
{
|
||||
}
|
||||
|
||||
inline void MessageBox::AddButton(int id, std::string text, MessageBoxButtonRole role)
|
||||
{
|
||||
m_buttons.push_back({
|
||||
.role = role,
|
||||
.text = std::move(text),
|
||||
.buttonId = id
|
||||
});
|
||||
}
|
||||
|
||||
inline auto MessageBox::GetColorSchemeOverride() const -> const ColorScheme*
|
||||
{
|
||||
if (!m_colorSchemeOverride)
|
||||
return nullptr;
|
||||
|
||||
return &m_colorSchemeOverride.value();
|
||||
}
|
||||
|
||||
inline const std::string& MessageBox::GetMessage() const
|
||||
{
|
||||
return m_message;
|
||||
}
|
||||
|
||||
inline const std::string& Nz::MessageBox::GetTitle() const
|
||||
{
|
||||
return m_title;
|
||||
}
|
||||
|
||||
inline void MessageBox::OverrideColorScheme(const ColorScheme& colorScheme)
|
||||
{
|
||||
m_colorSchemeOverride = colorScheme;
|
||||
}
|
||||
|
||||
inline void MessageBox::ResetColorScheme()
|
||||
{
|
||||
m_colorSchemeOverride = std::nullopt;
|
||||
}
|
||||
|
||||
inline void MessageBox::UpdateMessage(std::string message)
|
||||
{
|
||||
m_message = std::move(message);
|
||||
}
|
||||
|
||||
inline void MessageBox::UpdateTitle(std::string title)
|
||||
{
|
||||
m_title = std::move(title);
|
||||
}
|
||||
|
||||
inline void MessageBox::UpdateType(MessageBoxType type)
|
||||
{
|
||||
m_type = type;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Platform/DebugOff.hpp>
|
||||
@@ -32,6 +32,7 @@ namespace Nz
|
||||
{
|
||||
friend WindowImpl;
|
||||
friend class InputImpl;
|
||||
friend class MessageBox;
|
||||
friend class Mouse;
|
||||
friend class Platform;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user