-
Notifications
You must be signed in to change notification settings - Fork 0
/
View.hpp
83 lines (71 loc) · 2.19 KB
/
View.hpp
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
#ifndef MINESWEEPER_VIEW_HPP
#define MINESWEEPER_VIEW_HPP
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/Text.hpp>
#include <optional>
#include "Model.hpp"
#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/RectangleShape.hpp>
class View {
public:
enum class Button { Quit, Restart, Size, None };
View(sf::RenderWindow &window, Model &model);
Button buttonUnderMouse() const;
std::optional<std::pair<int, int>> cellUnderMouse() const;
void update();
void zoomIn();
void zoomOut();
void closeWindow();
private:
using ButtonArea = sf::RectangleShape;
enum class ButtonType { Big, Small };
enum class ButtonStatus { Released, Highlighted, Pressed };
enum class ButtonIcon {
SmallButton,
BigButton,
One,
Two,
Three,
Four,
Five,
Six,
Seven,
Eight,
Mine,
Flag,
QuestionMark,
Happy,
Sad,
Quit,
None
};
void loadResources();
void drawBackground();
void drawCells();
void drawMenu();
void drawCellButton(int col, int row);
void drawMenuButton(const sf::Vector2f &pos, Button button);
void drawMenuDisplay(const sf::Vector2f &pos, const std::string &content);
void drawIconOnButton(ButtonArea &button, ButtonIcon icon);
void drawTextOnButton(ButtonArea &button, const std::string &content);
void scaleWindow();
ButtonArea makeButtonArea(const sf::Vector2f &pos, ButtonType type) const;
float buttonOutlineThickness(ButtonType type) const;
sf::Color buttonColor(ButtonType type, ButtonStatus status) const;
sf::Vector2f buttonSize(ButtonType type) const;
sf::Vector2f cellButtonSize() const;
sf::Vector2f cellButtonPosition(int col, int row) const;
ButtonStatus buttonStatus(const ButtonArea &area) const;
ButtonStatus menuButtonStatus(const ButtonArea &area, Button button);
ButtonStatus cellButtonStatus(const ButtonArea &area, const Cell &cell);
std::string buttonContent(View::Button button) const;
ButtonIcon cellButtonIcon(const Cell &cell) const;
Model &m_model;
sf::RenderWindow &m_window;
sf::Font m_font;
std::map<ButtonIcon, sf::Texture> m_icons;
Button m_buttonUnderMouse;
std::optional<std::pair<int, int>> m_cellUnderMouse;
float m_zoomLevel;
};
#endif