-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMenu.h
180 lines (155 loc) · 3.84 KB
/
Menu.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
Copyright (c) 2024 Sidhin S Thomas. All rights reserved
*/
#pragma once
#include <cstdint>
#include <functional>
#include <string>
#include <SFML/Graphics/RenderTarget.hpp>
#include <SFML/Graphics.hpp>
namespace Menu
{
/// <summary>
/// Interface for a Menu object.
/// </summary>
class IMenu
{
public:
/// <summary>
/// Destructor.
/// </summary>
virtual ~IMenu();
/// <summary>
/// Draws the built menu on the provided render target.
/// </summary>
/// <param name="window">Target to draw on.</param>
virtual void Draw(sf::RenderTarget& window) = 0;
/// <summary>
/// Handles a window event applied to the menu.
/// </summary>
/// <param name="event">Received event.</param>
/// <param name="window">Render target to be passed along for actions tied to menu items.</param>
virtual void HandleEvent(const sf::Event& event, sf::RenderTarget& window) = 0;
};
/// <summary>
/// Defines alignment options to be applied to containers.
/// </summary>
enum class Align
{
/// <summary>
/// Aligns containers to the left of the window.
/// </summary>
Left = 0,
/// <summary>
/// Aligns containers to the center of the window.
/// </summary>
Center = 1,
/// <summary>
/// Aligns containers to the right of the window.
/// </summary>
Right = 2
};
/// <summary>
/// Definition of a text menu item.
/// </summary>
struct MenuItem
{
/// <summary>
/// Text to appear on the menu item.
/// </summary>
std::string Name;
/// <summary>
/// Action function to be called when the menu item is selected.
/// </summary>
std::function<void(sf::RenderTarget&)> Action;
};
/// <summary>
/// Container to store padding values.
/// </summary>
struct Padding
{
/// <summary>
/// Padding to apply to the bottom of the container.
/// Units in pixels.
/// </summary>
float Bottom = 0.0f;
/// <summary>
/// Padding to apply to the left of the container.
/// Units in pixels.
/// </summary>
float Left = 0.0f;
/// <summary>
/// Padding to apply to the right of the container.
/// Units in pixels.
/// </summary>
float Right = 0.0f;
/// <summary>
/// Padding to apply to the top of the container.
/// Units in pixels.
/// </summary>
float Top = 0.0f;
};
/// <summary>
/// Style definition of a menu item.
/// </summary>
struct Style
{
/// <summary>
/// Alignment of the menu item text.
/// </summary>
Align Alignment = Align::Center;
/// <summary>
/// Standard color of menu item text.
/// </summary>
sf::Color Color;
/// <summary>
/// Font to use for the menu item text.
/// </summary>
sf::Font Font;
/// <summary>
/// Font size to use for menu item text.
/// </summary>
std::uint32_t FontSize = 8;
/// <summary>
/// Padding to use for menu item text.
/// </summary>
Padding Padding;
};
/// <summary>
/// Configuration container of the menu.
/// </summary>
struct MenuConfig
{
/// <summary>
/// List of the menu items to be in the menu.
/// </summary>
std::vector<MenuItem> Items;
/// <summary>
/// Style to apply to all Items.
/// </summary>
Style ItemStyle;
/// <summary>
/// Color to apply to items when they are actively selected.
/// </summary>
sf::Color SelectedItemColor;
/// <summary>
/// Style to apply to title.
/// </summary>
Style TitleStyle;
/// <summary>
/// Text to use on the title.
/// </summary>
std::string TitleText;
/// <summary>
/// Scaling factor to apply to the menu.
/// </summary>
float ScalingFactor = 1.0;
};
/// <summary>
/// Factory function to build a Menu interface reference.
/// </summary>
/// <param name="windowSize">Overall size of the window.</param>
/// <param name="menuConfig">Configuration of the menu.</param>
/// <returns>Menu instance.</returns>
std::shared_ptr<IMenu> BuildMenu(const sf::Vector2u& windowSize, const MenuConfig& menuConfig);
}