mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-15 16:48:24 +03:00
ab5266b924
There's some really hideous plumbing with globals going on here, but my priority right now is getting a basic VT100 terminal emulator working.
63 lines
1.7 KiB
C++
63 lines
1.7 KiB
C++
#include "AbstractScreen.h"
|
|
#include "EventLoop.h"
|
|
#include "Event.h"
|
|
#include "Widget.h"
|
|
#include <AK/Assertions.h>
|
|
#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<MouseEvent&>(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<MouseEvent>(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<ShowEvent>());
|
|
}
|