-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUiMenu.hh
89 lines (67 loc) · 2.39 KB
/
UiMenu.hh
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
#pragma once
#include "BackgroundConfig.hh"
#include "Controls.hh"
#include "MenuConfig.hh"
#include "Renderer.hh"
#include <core_utils/CoreObject.hh>
#include <memory>
#include <optional>
namespace pge {
class UiMenu;
using UiMenuPtr = std::unique_ptr<UiMenu>;
class UiMenu : public utils::CoreObject
{
public:
UiMenu(const MenuConfig &config, const BackgroundConfig &bg);
~UiMenu() override = default;
bool visible() const noexcept;
void setVisible(const bool visible) noexcept;
void setEnabled(const bool enabled) noexcept;
void setHighlightable(const bool highlightable) noexcept;
void setPosition(const Vec2i &position);
void setClickCallback(const std::optional<ClickCallback> &callback);
void setGameClickCallback(const std::optional<GameCallback> &callback);
void addMenu(UiMenuPtr child);
void clearChildren();
auto getBgColor() const -> Color;
void updateBgColor(const Color &color);
void render(Renderer &engine) const;
virtual bool processUserInput(UserInputData &inputData);
protected:
auto absolutePosition() const noexcept -> Vec2i;
auto dims() const noexcept -> Vec2i;
struct State
{
bool visible{true};
bool disabled{false};
bool highlightable{false};
bool highlighted{false};
bool propagateEventsToChildren{true};
CustomRenderMode customRenderMode{CustomRenderMode::POST_RENDER};
};
auto state() const noexcept -> const State &;
void setLostFocusCallback(const ClickCallback &callback);
virtual void renderCustom(Renderer &engine) const;
private:
Vec2i m_pos{};
Vec2i m_dims{10, 10};
State m_state{};
MenuLayout m_layout{MenuLayout::VERTICAL};
bool m_expandChildrenToFit{true};
BackgroundConfig m_bg{};
std::optional<HighlightCallback> m_highlightCallback{};
std::optional<ClickCallback> m_clickCallback{};
std::optional<LostFocusCallback> m_lostFocusCallback{};
std::optional<GameCallback> m_gameClickCallback{};
UiMenu *m_parent{nullptr};
std::vector<UiMenuPtr> m_children{};
void initializeFromConfig(const MenuConfig &config);
void renderSelf(Renderer &engine) const;
auto getColorFromState() const -> Color;
bool isWithinMenu(const Vec2i &pos) const;
void onRelevantInput(UserInputData &inputData);
void updateLayoutAfterChildChange();
void adaptChildrenToMatchHorizontalSize(const float desiredXSize);
void adaptChildrenToMatchVerticalSize(const float desiredYSize);
};
} // namespace pge