summaryrefslogtreecommitdiffstats
path: root/include/window.hpp
blob: 791fbd6eac2d2c149c69188a45176125a470ceb7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#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_TITLE_ID "Title"
#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