#include "AbstractScreen.h" #include "EventLoop.h" #include "Event.h" #include "Widget.h" #include #include "TerminalWidget.h" static AbstractScreen* s_the; extern TerminalWidget* g_tw; AbstractScreen& AbstractScreen::the() { ASSERT(s_the); return *s_the; } AbstractScreen::AbstractScreen(unsigned width, unsigned height) : Object(nullptr) , m_width(width) , m_height(height) { ASSERT(!s_the); s_the = this; } AbstractScreen::~AbstractScreen() { } void AbstractScreen::event(Event& event) { if (event.type() == Event::MouseMove || event.type() == Event::MouseDown || event.type() == Event::MouseUp) { auto& me = static_cast(event); //printf("AbstractScreen::onMouseMove: %d, %d\n", me.x(), me.y()); auto result = m_rootWidget->hitTest(me.x(), me.y()); //printf("hit test for %d,%d found: %s{%p} %d,%d\n", me.x(), me.y(), result.widget->className(), result.widget, result.localX, result.localY); auto localEvent = make(event.type(), result.localX, result.localY, me.button()); result.widget->event(*localEvent); return Object::event(event); } if (event.type() == Event::KeyDown || event.type() == Event::KeyUp) { // FIXME: Implement proper focus. Widget* focusedWidget = g_tw; return focusedWidget->event(event); } return Object::event(event); } void AbstractScreen::setRootWidget(Widget* widget) { // FIXME: Should we support switching root widgets? ASSERT(!m_rootWidget); ASSERT(widget); m_rootWidget = widget; EventLoop::main().postEvent(m_rootWidget, make()); }