| 11 | using namespace text; |
| 12 | |
| 13 | class CustomWindow { |
| 14 | public: |
| 15 | void create(const std::string& title, int w, int h, os::Window* parent = nullptr) |
| 16 | { |
| 17 | os::WindowSpec spec; |
| 18 | |
| 19 | if (parent) { |
| 20 | spec.floating(true); |
| 21 | spec.parent(parent); |
| 22 | spec.minimizable(false); |
| 23 | |
| 24 | gfx::Rect rc = parent->frame(); |
| 25 | spec.frame(gfx::Rect(rc.x2() - w / 2, rc.y + rc.h / 2 - h / 2, w, h)); |
| 26 | spec.position(os::WindowSpec::Position::Frame); |
| 27 | } |
| 28 | else { |
| 29 | spec.contentRect(gfx::Rect(0, 0, w, h)); |
| 30 | spec.position(os::WindowSpec::Position::Default); |
| 31 | } |
| 32 | |
| 33 | m_nativeWindow = System::instance()->makeWindow(spec); |
| 34 | m_nativeWindow->setTitle(title); |
| 35 | m_nativeWindow->setUserData(this); |
| 36 | |
| 37 | redraw(); |
| 38 | } |
| 39 | |
| 40 | void close() { m_nativeWindow = nullptr; } |
| 41 | |
| 42 | void focus() { m_nativeWindow->activate(); } |
| 43 | |
| 44 | bool isVisible() const { return (m_nativeWindow && m_nativeWindow->isVisible()); } |
| 45 | |
| 46 | void redraw() |
| 47 | { |
| 48 | auto rc = m_nativeWindow->surface()->bounds(); |
| 49 | onRedraw(m_nativeWindow->surface(), rc); |
| 50 | |
| 51 | if (m_nativeWindow->isVisible()) |
| 52 | m_nativeWindow->invalidateRegion(gfx::Region(rc)); |
| 53 | else |
| 54 | m_nativeWindow->setVisible(true); |
| 55 | } |
| 56 | |
| 57 | virtual bool isFloating() const { return false; } |
| 58 | |
| 59 | virtual bool handleEvent(os::Event& ev) |
| 60 | { |
| 61 | switch (ev.type()) { |
| 62 | case os::Event::CloseWindow: return false; |
| 63 | |
| 64 | case os::Event::ResizeWindow: redraw(); break; |
| 65 | |
| 66 | case os::Event::KeyDown: |
| 67 | if (ev.scancode() == os::kKeyEsc) |
| 68 | return false; |
| 69 | else if (ev.scancode() == os::kKeyEnter || ev.scancode() == os::kKeyEnterPad) |
| 70 | onEnterKey(); |
nothing calls this directly
no outgoing calls
no test coverage detected