summaryrefslogtreecommitdiffstats
path: root/include/window.hpp
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2022-06-22 17:41:59 -0400
committerJon Santmyer <jon@jonsantmyer.com>2022-06-22 17:41:59 -0400
commit5e3a2492c7bb73daa4e27398daaf490d09980ff3 (patch)
tree75178d823d596b6a898002c3f1d45b9ceede0e1e /include/window.hpp
downloadsystemviewer-5e3a2492c7bb73daa4e27398daaf490d09980ff3.tar.gz
systemviewer-5e3a2492c7bb73daa4e27398daaf490d09980ff3.tar.bz2
systemviewer-5e3a2492c7bb73daa4e27398daaf490d09980ff3.zip
Base system viewer with data loaded from csv files
Diffstat (limited to 'include/window.hpp')
-rw-r--r--include/window.hpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/include/window.hpp b/include/window.hpp
new file mode 100644
index 0000000..78001ea
--- /dev/null
+++ b/include/window.hpp
@@ -0,0 +1,69 @@
+#ifndef WINDOW_HPP
+#define WINDOW_HPP 1
+
+#include "util.hpp"
+#include "straw.hpp"
+#include <memory>
+#include <unordered_map>
+
+//Wrapper for screens that act like windows
+class Window {
+ straw::screen<screenchr> m_border;
+ straw::screen<screenchr> m_screen;
+ std::string m_title;
+ bool m_hidden;
+public:
+ explicit Window(const std::string Title, unsigned X, unsigned Y, unsigned W, unsigned H, bool hidden = false) :
+ m_border(X, Y, W, 1), m_screen(X, Y+1, W, H-1), m_title(Title), m_hidden(hidden) {}
+ ~Window() = default;
+
+ template<typename T>
+ friend Window &operator<<(Window &o, const T &t) {
+ o.m_screen << t;
+ return o;
+ }
+
+ straw::screen<screenchr> *screen() { return &m_screen; }
+ std::string title() const { return m_title; }
+
+ void draw(bool focus);
+
+ void setHidden(bool mode) { m_hidden = mode; }
+ bool hidden() const { return m_hidden; }
+};
+
+#define WINDOW_SYSTEMVIEW_ID "Systemview"
+#define WINDOW_SYSTEMVIEW_SEARCH_ID "SystemviewSearch"
+#define WINDOW_BODYINFO_ID "Bodyinfo"
+#define WINDOW_EVENTS_ID "Events"
+#define WINDOW_TIMEMAN_ID "Timeman"
+
+class WindowContext {
+ std::unordered_map<std::string, Window> m_windows;
+ std::vector<std::string> m_windowOrder;
+ unsigned m_focus;
+public:
+ WindowContext() : m_focus(0) {}
+ ~WindowContext() {}
+
+ void registerWindow(const std::string &id,
+ const std::string &title,
+ unsigned x, unsigned y,
+ unsigned w, unsigned h,
+ bool hidden = false);
+
+ Window &operator[](const std::string &id) { return m_windows.at(id); }
+ Window &operator[](unsigned id) { return m_windows.at(m_windowOrder[id]); }
+ Window &operator()() { return m_windows.at(m_windowOrder[m_focus]); }
+
+ void update(int code);
+ void draw();
+
+ void setWindowHidden(const std::string &id, bool mode);
+ void focus(const std::string &id);
+
+ unsigned getFocused() { return m_focus; }
+ std::string getFocusedString() { return m_windowOrder[m_focus]; }
+};
+
+#endif