Eyes: Switch to new mouse-tracking method

This commit is contained in:
Ben Wiederhake 2021-09-07 21:22:38 +02:00 committed by Andreas Kling
parent 45126655cd
commit c6546c7b03
Notes: sideshowbarker 2024-07-18 04:27:52 +09:00
3 changed files with 7 additions and 19 deletions

View file

@ -8,26 +8,15 @@
#include <AK/Math.h>
#include <LibGUI/Painter.h>
#include <LibGUI/Window.h>
#include <LibGUI/WindowServerConnection.h>
#include <LibGfx/Palette.h>
EyesWidget::~EyesWidget()
{
}
void EyesWidget::track_cursor_globally()
void EyesWidget::track_mouse_move(Gfx::IntPoint const& point)
{
VERIFY(window());
auto window_id = window()->window_id();
VERIFY(window_id >= 0);
set_global_cursor_tracking(true);
GUI::WindowServerConnection::the().async_set_global_cursor_tracking(window_id, true);
}
void EyesWidget::mousemove_event(GUI::MouseEvent& event)
{
m_mouse_position = event.position();
m_mouse_position = point - window()->position();
update();
}

View file

@ -6,15 +6,15 @@
#pragma once
#include <LibGUI/MouseTracker.h>
#include <LibGUI/Widget.h>
#include <LibGfx/Point.h>
class EyesWidget final : public GUI::Widget {
class EyesWidget final : public GUI::Widget
, GUI::MouseTracker {
C_OBJECT(EyesWidget)
public:
virtual ~EyesWidget();
void track_cursor_globally();
private:
EyesWidget(int num_eyes, int full_rows, int extra)
@ -25,8 +25,8 @@ private:
m_eyes_in_row = m_full_rows > 0 ? (num_eyes - m_extra_columns) / m_full_rows : m_extra_columns;
}
virtual void mousemove_event(GUI::MouseEvent&) override;
virtual void paint_event(GUI::PaintEvent&) override;
virtual void track_mouse_move(Gfx::IntPoint const&) override;
void render_eyeball(int row, int column, GUI::Painter&) const;
Gfx::IntPoint pupil_center(Gfx::IntRect& eyeball_bounds) const;

View file

@ -76,7 +76,7 @@ int main(int argc, char* argv[])
window->resize(75 * (full_rows > 0 ? max_in_row : extra_columns), 100 * (full_rows + (extra_columns > 0 ? 1 : 0)));
window->set_has_alpha_channel(true);
auto& eyes = window->set_main_widget<EyesWidget>(num_eyes, full_rows, extra_columns);
window->set_main_widget<EyesWidget>(num_eyes, full_rows, extra_columns);
auto& file_menu = window->add_menu("&File");
file_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); }));
@ -85,7 +85,6 @@ int main(int argc, char* argv[])
help_menu.add_action(GUI::CommonActions::make_about_action("Eyes Demo", app_icon, window));
window->show();
eyes.track_cursor_globally();
return app->exec();
}