Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
GameMenu.hpp
1#pragma once
2
3#include "Common.hpp"
4#include "GameMenu.hpp"
5#include "resources/Font.hpp"
6
12
13public:
21 MenuButton(const glm::vec2 & screenPos, const glm::vec2 & meshSize, float screenScale, int actionTag, const Texture * texture);
22
27 bool contains(const glm::vec2 & mousePos) const;
28
32 enum class State : uint {
33 OFF,
34 HOVER,
35 ON
36 };
37 State state = State::OFF;
38
39 glm::vec2 pos = glm::vec2(0.0f);
40 glm::vec2 size = glm::vec2(1.0f);
41 glm::vec2 scale = glm::vec2(1.0f);
42 float displayScale = 1.0f;
43 int tag = 0;
44 const Texture * tid = nullptr;
45};
46
47
48STD_HASH(MenuButton::State)
49
50
54class MenuToggle : public MenuButton {
55public:
63 MenuToggle(const glm::vec2 & screenPos, const glm::vec2 & meshSize, float screenScale, int actionTag, const Texture * texture);
64
65 glm::vec2 posBox = glm::vec2(0.0f);
66 glm::vec2 posImg = glm::vec2(0.0f);
67 glm::vec2 scaleBox = glm::vec2(1.0f);
68 const float checkBoxScale = 0.65f;
69};
70
75class MenuImage {
76public:
82 MenuImage(const glm::vec2 & screenPos, float screenScale, const Texture * texture);
83
84 glm::vec2 pos = glm::vec2(0.0f);
85 glm::vec2 size = glm::vec2(1.0f);
86 glm::vec2 scale = glm::vec2(1.0f);
87 const Texture * tid = nullptr;
88};
89
94class MenuLabel {
95public:
103 MenuLabel(const glm::vec2 & screenPos, float verticalScale, const Font * font, Font::Alignment alignment);
104
108 void update(const std::string & text);
109
110 Mesh mesh = Mesh("");
111 glm::vec2 pos = glm::vec2(0.0f);
112 const Texture * tid = nullptr;
113
114private:
115 float _vScale = 1.0f;
116 const Font * _font = nullptr;
117 Font::Alignment _align = Font::Alignment::LEFT;
118};
119
124class GameMenu {
125public:
130 void update(const glm::vec2 & screenResolution, float initialRatio);
131
132 ~GameMenu();
133
134 std::vector<MenuButton> buttons;
135 std::vector<MenuToggle> toggles;
136 std::vector<MenuImage> images;
137 std::vector<MenuLabel> labels;
138 const Texture * backgroundImage = nullptr;
139};
Font loading and storage: texture atlas, codepoints supported, dimensions of each glyph.
Definition: Font.hpp:12
Alignment
Text alignment.
Definition: Font.hpp:15
A game menu containing buttons, toggles and images.
Definition: GameMenu.hpp:124
void update(const glm::vec2 &screenResolution, float initialRatio)
Definition: GameMenu.cpp:34
const Texture * backgroundImage
The background texure.
Definition: GameMenu.hpp:138
std::vector< MenuImage > images
The menu images.
Definition: GameMenu.hpp:136
std::vector< MenuButton > buttons
The menu buttons.
Definition: GameMenu.hpp:134
std::vector< MenuToggle > toggles
The menu toggles.
Definition: GameMenu.hpp:135
std::vector< MenuLabel > labels
The menu custom labels.
Definition: GameMenu.hpp:137
Represents a button in a menu.
Definition: GameMenu.hpp:11
int tag
Action ID.
Definition: GameMenu.hpp:43
bool contains(const glm::vec2 &mousePos) const
Definition: GameMenu.cpp:8
glm::vec2 size
Screen size.
Definition: GameMenu.hpp:40
glm::vec2 pos
Screen position.
Definition: GameMenu.hpp:39
float displayScale
Initial display scale.
Definition: GameMenu.hpp:42
glm::vec2 scale
Screen scale.
Definition: GameMenu.hpp:41
State
Button state.
Definition: GameMenu.hpp:32
State state
The button interaction state.
Definition: GameMenu.hpp:37
const Texture * tid
Text texture.
Definition: GameMenu.hpp:44
Represents a fixed image displayed in a menu.
Definition: GameMenu.hpp:75
glm::vec2 scale
Scaling.
Definition: GameMenu.hpp:86
glm::vec2 pos
Image position.
Definition: GameMenu.hpp:84
glm::vec2 size
Screen size.
Definition: GameMenu.hpp:85
const Texture * tid
Texture.
Definition: GameMenu.hpp:87
A dynamic text label.
Definition: GameMenu.hpp:94
float _vScale
Vertical size on screen.
Definition: GameMenu.hpp:115
Mesh mesh
Label mesh.
Definition: GameMenu.hpp:110
const Font * _font
Font atlas.
Definition: GameMenu.hpp:116
const Texture * tid
Font texture shortcut.
Definition: GameMenu.hpp:112
Font::Alignment _align
Text alignement.
Definition: GameMenu.hpp:117
void update(const std::string &text)
Definition: GameMenu.cpp:30
glm::vec2 pos
Label position.
Definition: GameMenu.hpp:111
Represents a toggle in a menu.
Definition: GameMenu.hpp:54
Represents a geometric mesh composed of vertices, other attributes and triangles.
Definition: Mesh.hpp:15
Represents a texture containing one or more images, stored on the CPU and/or GPU.
Definition: Texture.hpp:12