B15F
Board 15 Famulus Edition
view.h
1 #ifndef VIEW_H
2 #define VIEW_H
3 
4 #include <iostream>
5 #include <cmath>
6 #include <vector>
7 #include <functional>
8 #include <ncurses.h> // sudo apt-get install libncurses5-dev
9 #include <sys/ioctl.h>
10 #include <unistd.h>
11 #include <signal.h>
12 #include "../drv/b15f.h"
13 
14 extern std::string ERR_MSG;
15 typedef std::function<void(int)> call_t;
16 
19 class View
20 {
21 public:
25  View(void);
26 
30  virtual ~View(void);
31 
37  static void setWinContext(WINDOW* win);
38 
42  static WINDOW* getWinContext(void);
43 
50  static std::vector<std::string> str_split(const std::string& str, const std::string delim);
51 
56  virtual void setTitle(std::string title);
57 
63  virtual void repaint(void);
64 
69  virtual void draw(void) = 0;
70 
75  virtual call_t keypress(int& key) = 0;
76 
77 
78 protected:
79  int width;
80  int height;
81  int start_x = 0;
82  int start_y = 0;
83  std::string title;
84  std::vector<call_t> calls;
85 
86  static WINDOW* win;
87  constexpr static int KEY_ENT = 10;
88 };
89 
90 #endif // VIEW_H
View::height
int height
height of view in terminal characters
Definition: view.h:80
View::width
int width
width of view in terminal characters
Definition: view.h:79
View::title
std::string title
title of the view
Definition: view.h:83
View::~View
virtual ~View(void)
Definition: view.cpp:15
View::getWinContext
static WINDOW * getWinContext(void)
Definition: view.cpp:24
View
Definition: view.h:19
View::calls
std::vector< call_t > calls
calls (function pointers) for different button actions in the view (if any)
Definition: view.h:84
View::win
static WINDOW * win
static window contexts for all views
Definition: view.h:86
View::setWinContext
static void setWinContext(WINDOW *win)
Definition: view.cpp:19
View::str_split
static std::vector< std::string > str_split(const std::string &str, const std::string delim)
Definition: view.cpp:30
View::repaint
virtual void repaint(void)
Definition: view.cpp:52
View::keypress
virtual call_t keypress(int &key)=0
View::start_x
int start_x
x offset (characters) in the terminal, used to center the window on repaint()
Definition: view.h:81
View::View
View(void)
Definition: view.cpp:5
View::setTitle
virtual void setTitle(std::string title)
Definition: view.cpp:47
View::start_y
int start_y
y offset (characters) in the terminal, used to center the window on repaint()
Definition: view.h:82
View::draw
virtual void draw(void)=0
View::KEY_ENT
constexpr static int KEY_ENT
Key value for the Enter key.
Definition: view.h:87