summaryrefslogtreecommitdiffstats
path: root/src/window.cpp
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 /src/window.cpp
downloadsystemviewer-5e3a2492c7bb73daa4e27398daaf490d09980ff3.tar.gz
systemviewer-5e3a2492c7bb73daa4e27398daaf490d09980ff3.tar.bz2
systemviewer-5e3a2492c7bb73daa4e27398daaf490d09980ff3.zip
Base system viewer with data loaded from csv files
Diffstat (limited to 'src/window.cpp')
-rw-r--r--src/window.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/window.cpp b/src/window.cpp
new file mode 100644
index 0000000..4e487f3
--- /dev/null
+++ b/src/window.cpp
@@ -0,0 +1,72 @@
+#include "window.hpp"
+#include "keybind.hpp"
+
+void
+Window::draw(bool focus)
+{
+ if(m_hidden) return;
+ if(focus) {
+ m_border << straw::setcolor(straw::BLACK, straw::WHITE) << straw::clear(' ') << straw::move(0, 0) << m_title << straw::resetcolor();
+ }else{
+ m_border << straw::setcolor(straw::WHITE, straw::BLACK) << straw::clear(' ') << straw::move(0, 0) << m_title;
+ }
+ m_border.flush();
+ m_screen.flush();
+}
+
+void
+WindowContext::registerWindow(const std::string &id,
+ const std::string &title,
+ unsigned x, unsigned y,
+ unsigned w, unsigned h,
+ bool hidden)
+{
+ m_windows.emplace(id, Window(title, x, y, w, h, hidden));
+ m_windowOrder.push_back(id);
+}
+
+void
+WindowContext::update(int code)
+{
+ if(code == KeyMan::binds[BIND_G_NEXTWIN].code) {
+ m_focus = (m_focus + 1) % m_windows.size();
+ while(m_windows.at(m_windowOrder[m_focus]).hidden()) {
+ m_focus = (m_focus + 1) % m_windows.size();
+ }
+ }
+ if(code == KeyMan::binds[BIND_G_PREVWIN].code) {
+ m_focus = (m_focus == 0 ? m_windows.size() - 1 : m_focus - 1);
+ while(m_windows.at(m_windowOrder[m_focus]).hidden()) {
+ m_focus = (m_focus == 0 ? m_windows.size() - 1 : m_focus - 1);
+ }
+ }
+}
+
+void
+WindowContext::draw()
+{
+ for(unsigned i = 0; i < m_windows.size(); i++) {
+ m_windows.at(m_windowOrder[i]).draw(i == m_focus);
+ }
+}
+
+void
+WindowContext::focus(const std::string &id)
+{
+ for(unsigned i = 0; i < m_windowOrder.size(); i++) {
+ if(m_windowOrder[i] == id) {
+ m_focus = i;
+ return;
+ }
+ }
+}
+
+void
+WindowContext::setWindowHidden(const std::string &id, bool mode)
+{
+ m_windows.at(id).setHidden(mode);
+ for(unsigned i = 0; i < m_windows.size(); i++) {
+ if(m_windowOrder[i] == id && mode) continue;
+ m_windows.at(m_windowOrder[i]) << straw::redraw();
+ }
+}