nsnake
Classic snake game for the terminal
Window.hpp
1 #ifndef WINDOW_H_DEFINED
2 #define WINDOW_H_DEFINED
3 
4 #include <string>
5 #include <vector>
6 #include <ncurses.h>
7 
8 #include <Interface/Colors.hpp>
9 
12 #define WINDOW_FILL 0
13 
16 class Window
17 {
18 public:
19  enum BorderType
20  {
21  BORDER_NONE, BORDER_REGULAR, BORDER_FANCY
22  };
23 
24  Window(int x, int y, int w, int h);
25 
26  Window(Window* parent, int x, int y, int width, int height);
27 
28  virtual ~Window();
29 
30  virtual void resize(int w, int h);
31 
32  bool isValid();
33 
37  void print(std::string str, int x, int y, ColorPair pair=0);
38 
48  void print(std::vector<std::string> lines, int x, int y, ColorPair pair=0);
49 
53  void printChar(int c, int x, int y, ColorPair pair=0);
54 
55  void setBackground(chtype ch, ColorPair pair);
56 
57  void refresh();
58 
59  void clear();
60 
61  int getW() const;
62  int getH() const;
63  int getX() const;
64  int getY() const;
65 
66  void borders(BorderType type);
67 
68  void horizontalLine(int x, int y, int c, int width, ColorPair pair);
69 
70  enum WindowTitlePosition
71  {
72  TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT
73  };
74 
80  void setTitle(std::string title, WindowTitlePosition position=Window::TOP_LEFT);
81 
85  WINDOW* win;
86 
87 protected:
89  bool error;
90 
91  int x;
92  int y;
93  int width;
94  int height;
95 
96  BorderType borderType;
97 
98  std::string topLeftTitle;
99  std::string topRightTitle;
100  std::string bottomLeftTitle;
101  std::string bottomRightTitle;
102 };
103 
104 #endif //WINDOW_H_DEFINED
105 
WINDOW * win
Ncurses&#39; internal data structure.
Definition: Window.hpp:85
A segment of the terminal screen (2D char matrix).
Definition: Window.hpp:16
bool error
Tells if we&#39;ve got some initialization error.
Definition: Window.hpp:89
void setTitle(std::string title, WindowTitlePosition position=Window::TOP_LEFT)
Sets a text that will appear at the top of the Window.
Definition: Window.cpp:214
void printChar(int c, int x, int y, ColorPair pair=0)
Shows #c at #x #y with color #pair.
Definition: Window.cpp:105
void print(std::string str, int x, int y, ColorPair pair=0)
Shows text #str at #x #y on the window with color #pair.
Definition: Window.cpp:94