2021-05-09 08:19:20 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Richard Gráčik <r.gracik@gmail.com>
|
2022-02-26 18:41:10 +00:00
|
|
|
* Copyright (c) 2022, kleines Filmröllchen <filmroellchen@serenityos.org>
|
2021-05-09 08:19:20 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
2022-09-17 23:14:45 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-12-14 21:43:27 +00:00
|
|
|
#include <AK/EnumBits.h>
|
2022-02-26 18:41:10 +00:00
|
|
|
#include <AK/NonnullRefPtr.h>
|
|
|
|
#include <AK/RefPtr.h>
|
2022-12-14 21:43:27 +00:00
|
|
|
#include <AK/Types.h>
|
2021-05-09 08:19:20 +00:00
|
|
|
#include <LibCore/ElapsedTimer.h>
|
2021-05-18 17:12:05 +00:00
|
|
|
#include <LibGUI/Menu.h>
|
2021-09-07 19:56:27 +00:00
|
|
|
#include <LibGUI/MouseTracker.h>
|
2021-05-09 08:19:20 +00:00
|
|
|
#include <LibGUI/Widget.h>
|
2022-02-26 18:41:10 +00:00
|
|
|
#include <LibGfx/Bitmap.h>
|
2021-05-09 08:19:20 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2021-09-07 19:56:27 +00:00
|
|
|
class CatDog final : public GUI::Widget
|
|
|
|
, GUI::MouseTracker {
|
2021-05-09 08:19:20 +00:00
|
|
|
C_OBJECT(CatDog);
|
|
|
|
|
|
|
|
public:
|
2022-12-13 15:38:09 +00:00
|
|
|
static ErrorOr<NonnullRefPtr<CatDog>> create();
|
|
|
|
|
2021-05-09 08:19:20 +00:00
|
|
|
virtual void timer_event(Core::TimerEvent&) override;
|
|
|
|
virtual void paint_event(GUI::PaintEvent& event) override;
|
2022-12-06 20:27:44 +00:00
|
|
|
virtual void track_mouse_move(Gfx::IntPoint point) override;
|
2021-05-09 10:13:51 +00:00
|
|
|
virtual void mousedown_event(GUI::MouseEvent& event) override;
|
2021-05-18 17:12:05 +00:00
|
|
|
virtual void context_menu_event(GUI::ContextMenuEvent& event) override;
|
2021-05-09 08:19:20 +00:00
|
|
|
|
2021-05-09 10:13:51 +00:00
|
|
|
Function<void()> on_click;
|
2021-05-18 17:12:05 +00:00
|
|
|
Function<void(GUI::ContextMenuEvent&)> on_context_menu_request;
|
2021-05-09 10:13:51 +00:00
|
|
|
|
2022-12-14 21:43:27 +00:00
|
|
|
void set_roaming(bool roaming);
|
2024-05-08 18:54:06 +00:00
|
|
|
void set_sleeping(bool sleeping);
|
2022-12-14 21:43:27 +00:00
|
|
|
|
|
|
|
[[nodiscard]] bool is_artist() const;
|
|
|
|
[[nodiscard]] bool is_inspector() const;
|
2024-05-08 18:54:06 +00:00
|
|
|
[[nodiscard]] bool is_sleeping() const;
|
2022-02-26 18:41:10 +00:00
|
|
|
|
2021-05-09 08:19:20 +00:00
|
|
|
private:
|
2022-12-14 21:43:27 +00:00
|
|
|
enum class State : u16 {
|
|
|
|
Frame1 = 0x0,
|
|
|
|
Frame2 = 0x1,
|
2021-05-18 17:12:05 +00:00
|
|
|
|
2022-12-14 21:43:27 +00:00
|
|
|
Up = 0x10,
|
|
|
|
Down = 0x20,
|
|
|
|
Left = 0x40,
|
|
|
|
Right = 0x80,
|
|
|
|
|
|
|
|
Directions = Up | Down | Left | Right,
|
|
|
|
|
|
|
|
Roaming = 0x0100,
|
|
|
|
Idle = 0x0200,
|
|
|
|
Sleeping = 0x0400,
|
|
|
|
Alert = 0x0800,
|
|
|
|
|
|
|
|
GenericCatDog = 0x0000,
|
|
|
|
Inspector = 0x1000,
|
|
|
|
Artist = 0x2000
|
|
|
|
};
|
|
|
|
|
|
|
|
AK_ENUM_BITWISE_FRIEND_OPERATORS(State);
|
|
|
|
|
|
|
|
struct ImageForState {
|
|
|
|
State state;
|
|
|
|
NonnullRefPtr<Gfx::Bitmap> bitmap;
|
|
|
|
};
|
|
|
|
|
|
|
|
Vector<ImageForState> m_images;
|
|
|
|
|
|
|
|
Gfx::IntPoint m_mouse_offset {};
|
|
|
|
Core::ElapsedTimer m_idle_sleep_timer;
|
2021-05-09 08:19:20 +00:00
|
|
|
|
2023-02-09 02:02:46 +00:00
|
|
|
NonnullOwnPtr<Core::File> m_proc_all;
|
2022-02-26 18:44:30 +00:00
|
|
|
|
2022-12-14 21:43:27 +00:00
|
|
|
State m_state { State::Roaming };
|
|
|
|
State m_frame { State::Frame1 };
|
|
|
|
|
|
|
|
CatDog();
|
|
|
|
|
|
|
|
[[nodiscard]] Gfx::Bitmap& bitmap_for_state() const;
|
|
|
|
[[nodiscard]] State special_application_states() const;
|
2021-05-09 08:19:20 +00:00
|
|
|
};
|