1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:57:35 +00:00

Start bringing up LibGUI properly (formerly Widgets.)

This commit is contained in:
Andreas Kling 2019-01-20 05:48:43 +01:00
parent b91479d9b9
commit 8eae89a405
17 changed files with 258 additions and 33 deletions

View file

@ -80,9 +80,9 @@ private:
enum class MouseButton : byte {
None = 0,
Left,
Middle,
Right,
Left = 1,
Right = 2,
Middle = 4,
};
enum KeyboardKey {
@ -121,9 +121,10 @@ private:
class MouseEvent final : public WSEvent {
public:
MouseEvent(Type type, int x, int y, MouseButton button = MouseButton::None)
MouseEvent(Type type, const Point& position, unsigned buttons, MouseButton button = MouseButton::None)
: WSEvent(type)
, m_position(x, y)
, m_position(position)
, m_buttons(buttons)
, m_button(button)
{
}
@ -132,8 +133,10 @@ public:
int x() const { return m_position.x(); }
int y() const { return m_position.y(); }
MouseButton button() const { return m_button; }
unsigned buttons() const { return m_buttons; }
private:
Point m_position;
unsigned m_buttons { 0 };
MouseButton m_button { MouseButton::None };
};

View file

@ -41,8 +41,13 @@ void WSScreen::on_receive_mouse_data(int dx, int dy, bool left_button, bool righ
m_cursor_location.set_x(width() - 1);
if (m_cursor_location.y() >= height())
m_cursor_location.set_y(height() - 1);
unsigned buttons = 0;
if (left_button)
buttons |= (unsigned)MouseButton::Left;
if (right_button)
buttons |= (unsigned)MouseButton::Right;
if (m_cursor_location != prev_location) {
auto event = make<MouseEvent>(WSEvent::MouseMove, m_cursor_location.x(), m_cursor_location.y());
auto event = make<MouseEvent>(WSEvent::MouseMove, m_cursor_location, buttons);
WSEventLoop::the().post_event(&WSWindowManager::the(), move(event));
}
bool prev_left_button = m_left_mouse_button_pressed;
@ -50,11 +55,11 @@ void WSScreen::on_receive_mouse_data(int dx, int dy, bool left_button, bool righ
m_left_mouse_button_pressed = left_button;
m_right_mouse_button_pressed = right_button;
if (prev_left_button != left_button) {
auto event = make<MouseEvent>(left_button ? WSEvent::MouseDown : WSEvent::MouseUp, m_cursor_location.x(), m_cursor_location.y(), MouseButton::Left);
auto event = make<MouseEvent>(left_button ? WSEvent::MouseDown : WSEvent::MouseUp, m_cursor_location, buttons, MouseButton::Left);
WSEventLoop::the().post_event(&WSWindowManager::the(), move(event));
}
if (prev_right_button != right_button) {
auto event = make<MouseEvent>(right_button ? WSEvent::MouseDown : WSEvent::MouseUp, m_cursor_location.x(), m_cursor_location.y(), MouseButton::Right);
auto event = make<MouseEvent>(right_button ? WSEvent::MouseDown : WSEvent::MouseUp, m_cursor_location, buttons, MouseButton::Right);
WSEventLoop::the().post_event(&WSWindowManager::the(), move(event));
}
if (m_cursor_location != prev_location || prev_left_button != left_button)

View file

@ -59,6 +59,7 @@ void WSWindow::event(WSEvent& event)
case WSEvent::MouseMove:
gui_event.type = GUI_Event::Type::MouseMove;
gui_event.mouse.position = static_cast<MouseEvent&>(event).position();
gui_event.mouse.button = GUI_MouseButton::NoButton;
break;
case WSEvent::MouseDown:
gui_event.type = GUI_Event::Type::MouseDown;

View file

@ -285,9 +285,10 @@ void WSWindowManager::process_mouse_event(MouseEvent& event)
move_to_front(*window);
set_active_window(window);
}
// FIXME: Re-use the existing event instead of crafting a new one?
auto localEvent = make<MouseEvent>(event.type(), event.x() - window->rect().x(), event.y() - window->rect().y(), event.button());
window->event(*localEvent);
// FIXME: Should we just alter the coordinates of the existing MouseEvent and pass it through?
Point position { event.x() - window->rect().x(), event.y() - window->rect().y() };
auto local_event = make<MouseEvent>(event.type(), position, event.buttons(), event.button());
window->event(*local_event);
return;
}
}