nsnake
Classic snake game for the terminal
Loading...
Searching...
No Matches
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
11
12static int intendedWidth;
13static int intendedHeight;
14
15Layout::Layout(int width, int height):
16 main(NULL)
17{
18 intendedWidth = width;
19 intendedHeight = height;
20}
21Layout::~Layout()
22{ }
23void 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 {
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}
73void Layout::windowsExit()
74{
75 SAFE_DELETE(this->main);
76}
77void Layout::draw()
78{
79 // When subclassing, make sure to implement this!
80}
81
Window * main
Layout's main Window, where all the others are inside.
Definition Layout.hpp:33
static int screenWidth
Full width of the terminal right now.
Definition Layout.hpp:19
static int screenHeight
Full height of the terminal right now.
Definition Layout.hpp:22
A segment of the terminal screen (2D char matrix).
Definition Window.hpp:17
void exit()
Warns the user about any errors and warnings found during the program's execution.
Definition Globals.cpp:143
void exit()
Quits Ncurses mode.
Definition Ncurses.cpp:25