mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
Eyes: Switch to new mouse-tracking method
This commit is contained in:
parent
45126655cd
commit
c6546c7b03
Notes:
sideshowbarker
2024-07-18 04:27:52 +09:00
Author: https://github.com/BenWiederhake Commit: https://github.com/SerenityOS/serenity/commit/c6546c7b039 Pull-request: https://github.com/SerenityOS/serenity/pull/9881
3 changed files with 7 additions and 19 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue