nsnake
Classic snake game for the terminal
Loading...
Searching...
No Matches
Window Class Reference

A segment of the terminal screen (2D char matrix). More...

#include <Window.hpp>

Public Types

enum  BorderType { BORDER_NONE , BORDER_REGULAR , BORDER_FANCY }
 
enum  WindowTitlePosition { TOP_LEFT , TOP_RIGHT , BOTTOM_LEFT , BOTTOM_RIGHT }
 

Public Member Functions

 Window (int x, int y, int w, int h)
 
 Window (Window *parent, int x, int y, int width, int height)
 
virtual void resize (int w, int h)
 
bool isValid ()
 
void print (std::string str, int x, int y, ColorPair pair=0)
 Shows text #str at x y on the window with color #pair.
 
void print (std::vector< std::string > lines, int x, int y, ColorPair pair=0)
 Shows multiple text lines #lines at x y on the window with color #pair.
 
void printChar (int c, int x, int y, ColorPair pair=0)
 Shows #c at x y with color #pair.
 
void setBackground (chtype ch, ColorPair pair)
 
void refresh ()
 
void clear ()
 
int getW () const
 
int getH () const
 
int getX () const
 
int getY () const
 
void borders (BorderType type)
 
void horizontalLine (int x, int y, int c, int width, ColorPair pair)
 
void setTitle (std::string title, WindowTitlePosition position=Window::TOP_LEFT)
 Sets a text that will appear at the top of the Window.
 

Public Attributes

WINDOW * win
 Ncurses' internal data structure.
 

Protected Attributes

bool error
 Tells if we've got some initialization error.
 
int x
 
int y
 
int width
 
int height
 
BorderType borderType
 
std::string topLeftTitle
 
std::string topRightTitle
 
std::string bottomLeftTitle
 
std::string bottomRightTitle
 

Detailed Description

A segment of the terminal screen (2D char matrix).

Definition at line 16 of file Window.hpp.

Member Enumeration Documentation

◆ BorderType

enum Window::BorderType

Definition at line 19 of file Window.hpp.

◆ WindowTitlePosition

enum Window::WindowTitlePosition

Definition at line 70 of file Window.hpp.

Constructor & Destructor Documentation

◆ Window() [1/2]

Window::Window ( int x,
int y,
int w,
int h )

Definition at line 24 of file Window.cpp.

◆ Window() [2/2]

Window::Window ( Window * parent,
int x,
int y,
int width,
int height )

Definition at line 42 of file Window.cpp.

◆ ~Window()

Window::~Window ( )
virtual

Definition at line 79 of file Window.cpp.

Member Function Documentation

◆ borders()

void Window::borders ( BorderType type)

Definition at line 184 of file Window.cpp.

◆ clear()

void Window::clear ( )

Definition at line 128 of file Window.cpp.

◆ getH()

int Window::getH ( ) const

Definition at line 172 of file Window.cpp.

◆ getW()

int Window::getW ( ) const

Definition at line 168 of file Window.cpp.

◆ getX()

int Window::getX ( ) const

Definition at line 176 of file Window.cpp.

◆ getY()

int Window::getY ( ) const

Definition at line 180 of file Window.cpp.

◆ horizontalLine()

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

Definition at line 209 of file Window.cpp.

◆ isValid()

bool Window::isValid ( )

Definition at line 84 of file Window.cpp.

◆ print() [1/2]

void Window::print ( std::string str,
int x,
int y,
ColorPair pair = 0 )

Shows text #str at x y on the window with color #pair.

Note
It defaults to white text on black background.

Definition at line 94 of file Window.cpp.

◆ print() [2/2]

void Window::print ( std::vector< std::string > lines,
int x,
int y,
ColorPair pair = 0 )

Shows multiple text lines #lines at x y on the window with color #pair.

Note
It also defaults to white text on black background.
Use it together with Utils::String::split:
window.print(Utils::String::split("multiple\nlines", '\n'),
            x, y, color_pair);

Definition at line 100 of file Window.cpp.

◆ printChar()

void Window::printChar ( int c,
int x,
int y,
ColorPair pair = 0 )

Shows #c at x y with color #pair.

Note
It also defaults to white text on black background.

Definition at line 105 of file Window.cpp.

◆ refresh()

void Window::refresh ( )

Definition at line 115 of file Window.cpp.

◆ resize()

void Window::resize ( int w,
int h )
virtual

Definition at line 88 of file Window.cpp.

◆ setBackground()

void Window::setBackground ( chtype ch,
ColorPair pair )

Definition at line 111 of file Window.cpp.

◆ setTitle()

void Window::setTitle ( std::string title,
WindowTitlePosition position = Window::TOP_LEFT )

Sets a text that will appear at the top of the Window.

By default it's shown on top of the borders, with a highlighted color tone.

Definition at line 214 of file Window.cpp.

Member Data Documentation

◆ borderType

BorderType Window::borderType
protected

Definition at line 96 of file Window.hpp.

◆ bottomLeftTitle

std::string Window::bottomLeftTitle
protected

Definition at line 100 of file Window.hpp.

◆ bottomRightTitle

std::string Window::bottomRightTitle
protected

Definition at line 101 of file Window.hpp.

◆ error

bool Window::error
protected

Tells if we've got some initialization error.

Definition at line 89 of file Window.hpp.

◆ height

int Window::height
protected

Definition at line 94 of file Window.hpp.

◆ topLeftTitle

std::string Window::topLeftTitle
protected

Definition at line 98 of file Window.hpp.

◆ topRightTitle

std::string Window::topRightTitle
protected

Definition at line 99 of file Window.hpp.

◆ width

int Window::width
protected

Definition at line 93 of file Window.hpp.

◆ win

WINDOW* Window::win

Ncurses' internal data structure.

IT'S PUBLIC BECAUSE SOMETIMES I NEED TO CALL DIRECT NCURSES CALLS - FIX THIS

Definition at line 85 of file Window.hpp.

◆ x

int Window::x
protected

Definition at line 91 of file Window.hpp.

◆ y

int Window::y
protected

Definition at line 92 of file Window.hpp.


The documentation for this class was generated from the following files: