-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgame_view_layout.h
158 lines (131 loc) · 5.23 KB
/
game_view_layout.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
#ifndef GAME_VIEW_LAYOUT_H
#define GAME_VIEW_LAYOUT_H
#include "ccfwd.h"
#include "screen_rect.h"
#include "game_coordinat.h"
#include "screen_coordinat.h"
#include "layout.h"
#include "side.h"
#include <iosfwd>
#include <vector>
/// The layout of the game view
///
/// x x x x x x
/// 1 2 3 4 5 6
///
/// +-------------------------------------------+
/// | |
/// | 3----------+ 1-------------+ 9----------+ | y1 -
/// | | unit | | | | unit | | | 100 pixels
/// | +----------4 | board | +----------A | y2 -
/// | | controls | | | | controls | | | 100 pixels
/// | +----------6 | | +----------C | y4 -
/// | | | |
/// | 5----------+ | | B----------+ | y5
/// | | log | | | | log | |
/// | +----------6 | | +----------C | y6
/// | | | |
/// | 7----------+ | | D----------+ | y7
/// | | debug | | | | debug | |
/// | +----------8 +-------------2 +----------E | y8
/// | |
/// +-------------------------------------------+
///
/// ^ ^ ^ ^ ^ ^
/// | | | | | |
/// +----------+ +------------+ +----------+
/// panel_width board_width panel_width
/// 300 pixels remainder 300 pixels
///
class game_view_layout
{
public:
explicit game_view_layout(
const screen_coordinat& window_size = get_default_screen_size(),
const int margin_width = get_default_margin_width()
);
const auto& get_board() const noexcept { return m_board; }
const screen_rect& get_controls(const side player) const noexcept;
/// The square that shows:
/// 1. the action name, e.g. 'attack'
/// Use \link{get_controls_key_name} to get the screen_rect
/// for this section
/// 2. the action icon, e.g. an arrow that points to a cross for attack.
/// Use \link{get_controls_key_icon} to get the screen_rect
/// for this section
/// 3. the user input, e.g. 'Q' or LMB.
/// Use \link{get_controls_key_input} to get the screen_rect
/// for this section
const screen_rect& get_controls_key(const side player, const action_number& key) const noexcept;
/// The square that show the icon of the user input, e.g. an arrow
/// as is part of \link{get_controls_key}
screen_rect get_controls_key_icon(const side player, const action_number& key) const noexcept;
/// The square that show the user input needed, e.g. 'Q',
/// as is part of \link{get_controls_key}
screen_rect get_controls_key_input(const side player, const action_number& key) const noexcept;
/// The square that show the text for the name of the user input,
/// e.g. 'attack',
/// as is part of \link{get_controls_key}
screen_rect get_controls_key_name(const side player, const action_number& key) const noexcept;
const screen_rect& get_debug(const side player) const noexcept;
const screen_rect& get_log(const side player) const noexcept;
const screen_rect& get_units(const side player) const noexcept;
screen_coordinat get_window_size() const noexcept { return m_window_size; }
private:
screen_rect m_board;
screen_rect m_controls_lhs;
screen_rect m_controls_lhs_key_1;
screen_rect m_controls_lhs_key_2;
screen_rect m_controls_lhs_key_3;
screen_rect m_controls_lhs_key_4;
screen_rect m_controls_rhs;
screen_rect m_controls_rhs_key_1;
screen_rect m_controls_rhs_key_2;
screen_rect m_controls_rhs_key_3;
screen_rect m_controls_rhs_key_4;
screen_rect m_debug_lhs;
screen_rect m_debug_rhs;
screen_rect m_log_lhs;
screen_rect m_log_rhs;
screen_rect m_units_lhs;
screen_rect m_units_rhs;
/// The size of the window
screen_coordinat m_window_size;
};
/// Convert an in-game coordinat to an on-screen coordinat
screen_coordinat convert_to_screen_coordinat(
const game_coordinat& coordinat,
const game_view_layout& layout
);
/// Convert an in-game coordinat to an on-screen coordinat
screen_rect convert_to_screen_rect(
const game_rect& coordinat,
const game_view_layout& layout
);
/// Convert an in-game square to an on-screen screen rectange
screen_rect convert_to_screen_rect(
const square& s,
const game_view_layout& layout
);
/// Convert an on-screen coordinat to an in-game coordinat
game_coordinat convert_to_game_coordinat(
const screen_coordinat& coordinat,
const game_view_layout& layout
);
/// Get the height of the board in pixels
int get_board_height(const game_view_layout& layout) noexcept;
/// Get the width of the board in pixels
int get_board_width(const game_view_layout& layout) noexcept;
/// Get the height of a square
double get_square_height(const game_view_layout& layout) noexcept;
/// Get the width of a square
double get_square_width(const game_view_layout& layout) noexcept;
/// Get the panels in the layout
std::vector<screen_rect> get_panels(
const game_view_layout& layout,
const bool show_debug_panel = true
);
/// Test the game_view_layout class
void test_game_view_layout();
std::ostream& operator<<(std::ostream& os, const game_view_layout& layout) noexcept;
#endif // GAME_VIEW_LAYOUT_H