summaryrefslogtreecommitdiff
path: root/include/ncurses/window.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/ncurses/window.hpp')
-rw-r--r--include/ncurses/window.hpp50
1 files changed, 48 insertions, 2 deletions
diff --git a/include/ncurses/window.hpp b/include/ncurses/window.hpp
index 7d26776..fc1c87c 100644
--- a/include/ncurses/window.hpp
+++ b/include/ncurses/window.hpp
@@ -1,15 +1,61 @@
#ifndef INCLUDE_NCURSES_WINDOW_HPP_
#define INCLUDE_NCURSES_WINDOW_HPP_
-#include <ncurses/utils/macros.hpp>
+#include <vector>
+
+#include <ncurses/utils/preamble.hpp>
namespace NCURSES_CPP_NAMESPACE {
class window {
public:
- window(int i);
+ // basic
+ window(int lines, int cols, int begin_y, int begin_x)
+ : win_(newwin(lines, cols, begin_y, begin_x)), parent_(nullptr) {}
+
+ window(window &parent, int lines, int cols, int begin_y, int begin_x)
+ : win_(subwin(parent.win_, lines, cols, begin_y, begin_x)),
+ parent_(&parent) {}
+
+ window(const window &other)
+ : win_(dupwin(other.win_)), parent_(other.parent_) {}
+
+ window(window &&other) : win_(other.win_) { other.win_ = nullptr; }
+
+ window &operator=(const window &other) {
+ delwin(win_);
+ win_ = dupwin(other.win_);
+ return *this;
+ }
+
+ window &operator=(window &&other) {
+ delwin(win_);
+ win_ = other.win_;
+ other.win_ = nullptr;
+ return *this;
+ }
+
+ explicit operator WINDOW *() const { return win_; }
+
+ virtual ~window() { free_window(); }
+
+ // interface
private:
+ void add_subwin(window &win) { subwins_.push_back(&win); }
+ void free_window() {
+ if (win_) {
+ delwin(win_);
+ for (auto it : subwins_) {
+ it->free_window();
+ }
+ }
+ win_ = nullptr;
+ }
+
+ WINDOW *win_;
+ window *parent_;
+ std::vector<window *> subwins_;
};
} // namespace NCURSES_CPP_NAMESPACE