nsnake
Classic snake game for the terminal
Toggle main menu visibility
Loading...
Searching...
No Matches
src
Interface
Layout.cpp
1
#include <Interface/Layout.hpp>
2
#include <Interface/Ncurses.hpp>
3
#include <Config/Globals.hpp>
4
#include <Misc/Utils.hpp>
5
6
#include <iostream>
7
#include <cstdlib>
8
9
int
Layout::screenWidth
= 0;
10
int
Layout::screenHeight
= 0;
11
12
static
int
intendedWidth;
13
static
int
intendedHeight;
14
15
Layout::Layout(
int
width,
int
height):
16
main(NULL)
17
{
18
intendedWidth = width;
19
intendedHeight = height;
20
}
21
Layout::~Layout()
22
{ }
23
void
Layout::windowsInit()
24
{
25
clear();
26
27
// Gets the current width and height of the whole terminal.
28
int
current_height, current_width;
29
getmaxyx(stdscr, current_height, current_width);
30
31
if
((current_width < intendedWidth) ||
32
(current_height < intendedHeight))
33
{
34
Ncurses::exit
();
35
std::cerr <<
"Error! Your console screen is smaller than"
36
<< intendedWidth <<
"x"
<< intendedHeight <<
"\n"
37
<<
"Please resize your window and try again"
38
<< std::endl;
39
40
exit
(EXIT_FAILURE);
41
}
42
43
// Sets global info
44
Layout::screenWidth
= current_width;
45
Layout::screenHeight
= current_height;
46
47
// Creating the main window for this layout.
48
// We'll center based on user's settings
49
int
main_x = 0;
50
int
main_y = 0;
51
52
if
(Globals::Screen::center_horizontally)
53
main_x = current_width/2 - intendedWidth/2;
54
55
if
(Globals::Screen::center_vertically)
56
main_y = current_height/2 - intendedHeight/2;
57
58
this->
main
=
new
Window(main_x,
59
main_y,
60
intendedWidth,
61
intendedHeight);
62
63
if
((Globals::Screen::outer_border) &&
64
(Globals::Screen::show_borders))
65
{
66
this->
main
->borders(Globals::Screen::fancy_borders ?
67
Window::BORDER_FANCY :
68
Window::BORDER_REGULAR);
69
}
70
71
this->
main
->refresh();
72
}
73
void
Layout::windowsExit()
74
{
75
SAFE_DELETE(this->
main
);
76
}
77
void
Layout::draw()
78
{
79
// When subclassing, make sure to implement this!
80
}
81
Layout::main
Window * main
Layout's main Window, where all the others are inside.
Definition
Layout.hpp:33
Layout::screenWidth
static int screenWidth
Full width of the terminal right now.
Definition
Layout.hpp:19
Layout::screenHeight
static int screenHeight
Full height of the terminal right now.
Definition
Layout.hpp:22
Globals::exit
void exit()
Warns the user about any errors and warnings found during the program's execution.
Definition
Globals.cpp:143
Ncurses::exit
void exit()
Quits Ncurses mode.
Definition
Ncurses.cpp:25
Generated on
for nsnake by
1.17.0