Skip to content

Commit

Permalink
Made Window have borders by default, according to EngineGlobals
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdantas committed Aug 21, 2014
1 parent 26c16d5 commit c4603ca
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 65 deletions.
7 changes: 4 additions & 3 deletions deps/Engine/Flow/StateManager.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include <Engine/Flow/StateManager.hpp>
#include <Game/States/GameStateGame.hpp>
#include <Game/States/GameStateMainMenu.hpp>
#include <Engine/InputManager.hpp>
#include <Engine/Helpers/Utils.hpp>
#include <Game/Config/Globals.hpp>

#include <States/GameStateGame.hpp>
#include <States/GameStateMainMenu.hpp>
#include <Config/Globals.hpp>

StateManager::StateManager():
currentState(NULL),
Expand Down
14 changes: 3 additions & 11 deletions deps/Engine/Graphics/Layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,10 @@ void Layout::windowsInit()
if (EngineGlobals::Screen::center_vertically)
main_y = current_height/2 - intendedHeight/2;

this->main = new Window(main_x,
main_y,
intendedWidth,
intendedHeight);
this->main = new Window(main_x, main_y, intendedWidth, intendedHeight);

if ((EngineGlobals::Screen::outer_border) &&
(EngineGlobals::Screen::show_borders))
{
this->main->borders(EngineGlobals::Screen::fancy_borders ?
Window::BORDER_FANCY :
Window::BORDER_REGULAR);
}
if (! EngineGlobals::Screen::outer_border)
this->main->borders(Window::BORDER_NONE);

this->main->refresh();
}
Expand Down
13 changes: 0 additions & 13 deletions deps/Engine/Graphics/Widgets/Dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ void Dialog::show(std::string message, bool pressAnyKey)

Window dialog(window_x, window_y, window_width, window_height);

if (EngineGlobals::Screen::show_borders)
{
dialog.borders(EngineGlobals::Screen::fancy_borders ?
Window::BORDER_FANCY :
Window::BORDER_REGULAR);
}

// Before showing anything on the screen we must
// call `refresh()`, to... well, refresh the
// main screen buffer
Expand Down Expand Up @@ -65,12 +58,6 @@ bool Dialog::askBool(std::string question, std::string title, bool default_value
question.size() + 2 + 10, // borders + empty space
5);

if (EngineGlobals::Screen::show_borders)
{
dialog.borders(EngineGlobals::Screen::fancy_borders ?
Window::BORDER_FANCY :
Window::BORDER_REGULAR);
}
if (! title.empty())
dialog.setTitle(title);

Expand Down
14 changes: 14 additions & 0 deletions deps/Engine/Graphics/Window.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <Engine/Graphics/Window.hpp>
#include <Engine/EngineGlobals.hpp>

#include <sstream> // stringstream
#include <iostream>
Expand Down Expand Up @@ -38,6 +39,8 @@ Window::Window(int x, int y, int w, int h):

if (!this->win)
this->error = true;

this->setBorders();
}
Window::Window(Window* parent, int x, int y, int width, int height):
win(NULL),
Expand Down Expand Up @@ -75,6 +78,8 @@ Window::Window(Window* parent, int x, int y, int width, int height):
this->win = derwin(parent->win, height, width, y, x);
if (!win)
this->error = true;

this->setBorders();
}
Window::~Window()
{
Expand Down Expand Up @@ -206,6 +211,15 @@ void Window::borders(BorderType type)
wborder(this->win, '|', '|', '-', '-', '+', '+', '+', '+');
}
}
void Window::setBorders()
{
if (EngineGlobals::Screen::show_borders)
{
this->borders(EngineGlobals::Screen::fancy_borders ?
Window::BORDER_FANCY :
Window::BORDER_REGULAR);
}
}
void Window::horizontalLine(int x, int y, int c, int width, ColorPair pair)
{
Colors::pairActivate(this->win, pair);
Expand Down
5 changes: 5 additions & 0 deletions deps/Engine/Graphics/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,13 @@ class Window
int getX() const;
int getY() const;

/// Applies border of #type to this Window.
void borders(BorderType type);

/// Applies a board style dependent on the
/// EngineGlobals settings
void setBorders();

void horizontalLine(int x, int y, int c, int width, ColorPair pair);

enum WindowTitlePosition
Expand Down
28 changes: 8 additions & 20 deletions src/Display/Layouts/LayoutGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ void LayoutGame::windowsInit()

// Leftmost window
this->gamewin = new Window(this->main,
WINDOW_FILL,
WINDOW_FILL,
WINDOW_FILL,
this->main->getH() - 3);
WINDOW_FILL, WINDOW_FILL,
WINDOW_FILL, this->main->getH() - 3);

this->gamewin->borders(Window::BORDER_NONE);

this->info = new Window(this->main,
WINDOW_FILL,
this->main->getH() - 2,
WINDOW_FILL,
1);
WINDOW_FILL, this->main->getH() - 2,
WINDOW_FILL, 1);

this->info->borders(Window::BORDER_NONE);

// Le pause window.
this->pause = new Window(this->main,
Expand All @@ -48,12 +48,6 @@ void LayoutGame::windowsInit()
this->main->getW() / 2,
7);

if (EngineGlobals::Screen::show_borders)
{
this->pause->borders(EngineGlobals::Screen::fancy_borders ?
Window::BORDER_FANCY :
Window::BORDER_REGULAR);
}
this->pause->setTitle("Paused");

// Le help window.
Expand All @@ -63,12 +57,6 @@ void LayoutGame::windowsInit()
this->main->getW() / 2,
this->main->getH() / 2);

if (EngineGlobals::Screen::show_borders)
{
this->help->borders(EngineGlobals::Screen::fancy_borders ?
Window::BORDER_FANCY :
Window::BORDER_REGULAR);
}
this->help->setTitle("Help");

this->helpWindows = new WindowGameHelp();
Expand Down
8 changes: 1 addition & 7 deletions src/Display/Layouts/LayoutMainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,8 @@ void LayoutMainMenu::windowsInit()
0,
24,
WINDOW_FILL);
this->menu->setTitle("Main Menu");

if (EngineGlobals::Screen::show_borders)
{
this->menu->borders(EngineGlobals::Screen::fancy_borders ?
Window::BORDER_FANCY :
Window::BORDER_REGULAR);
}
this->menu->setTitle("Main Menu");
this->menu->refresh();

// ANIMATION
Expand Down
15 changes: 4 additions & 11 deletions src/Display/WindowGameHelp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,18 @@ WindowGameHelp::WindowGameHelp()
int windowx = Layout::screenWidth/2 - width/2;
int windowy = Layout::screenHeight/2 - height/2;

this->main = new Window(windowx,
windowy,
width,
height);

if (EngineGlobals::Screen::show_borders)
{
this->main->borders(EngineGlobals::Screen::fancy_borders ?
Window::BORDER_FANCY :
Window::BORDER_REGULAR);
}
this->main = new Window(windowx, windowy, width, height);

Window* win;

// Help
win = new Window(this->main, 0, 0, WINDOW_FILL, WINDOW_FILL);
win->borders(Window::BORDER_NONE);

this->windows.push_back(win);

win = new Window(this->main, 0, 0, WINDOW_FILL, WINDOW_FILL);
win->borders(Window::BORDER_NONE);
this->windows.push_back(win);
}
void WindowGameHelp::run()
Expand Down

0 comments on commit c4603ca

Please sign in to comment.