2020-01-18 05:38:21 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2019-04-05 13:40:36 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/Function.h>
|
2019-04-06 16:16:41 -03:00
|
|
|
#include <AK/Weakable.h>
|
2021-01-21 18:31:00 -03:00
|
|
|
#include <LibGfx/Bitmap.h>
|
2020-02-14 20:10:34 -03:00
|
|
|
#include <LibGfx/Forward.h>
|
2020-07-29 17:22:05 -03:00
|
|
|
#include <LibGfx/Rect.h>
|
2021-06-18 22:21:30 -03:00
|
|
|
#include <WindowServer/MultiScaleBitmaps.h>
|
2020-02-06 07:56:38 -03:00
|
|
|
|
2020-02-06 16:03:37 -03:00
|
|
|
namespace WindowServer {
|
2019-04-05 13:40:36 -03:00
|
|
|
|
2020-02-06 16:03:37 -03:00
|
|
|
class MouseEvent;
|
2021-06-18 22:21:30 -03:00
|
|
|
class Screen;
|
2020-02-06 16:03:37 -03:00
|
|
|
class WindowFrame;
|
|
|
|
|
|
|
|
|
|
class Button : public Weakable<Button> {
|
2019-04-05 13:40:36 -03:00
|
|
|
public:
|
2020-07-29 17:22:05 -03:00
|
|
|
Button(WindowFrame&, Function<void(Button&)>&& on_click_handler);
|
2020-02-06 16:03:37 -03:00
|
|
|
~Button();
|
2019-04-05 13:40:36 -03:00
|
|
|
|
2020-06-10 05:57:59 -03:00
|
|
|
Gfx::IntRect relative_rect() const { return m_relative_rect; }
|
|
|
|
|
void set_relative_rect(const Gfx::IntRect& rect) { m_relative_rect = rect; }
|
2019-04-05 16:33:34 -03:00
|
|
|
|
2020-06-10 05:57:59 -03:00
|
|
|
Gfx::IntRect rect() const { return { {}, m_relative_rect.size() }; }
|
|
|
|
|
Gfx::IntRect screen_rect() const;
|
2019-04-05 13:40:36 -03:00
|
|
|
|
2021-06-18 22:21:30 -03:00
|
|
|
void paint(Screen&, Gfx::Painter&);
|
2019-04-05 13:40:36 -03:00
|
|
|
|
2020-02-06 16:03:37 -03:00
|
|
|
void on_mouse_event(const MouseEvent&);
|
2019-04-05 13:40:36 -03:00
|
|
|
|
2020-02-06 16:03:37 -03:00
|
|
|
Function<void(Button&)> on_click;
|
2021-01-26 17:50:02 -03:00
|
|
|
Function<void(Button&)> on_right_click;
|
|
|
|
|
Function<void(Button&)> on_middle_click;
|
2019-04-05 13:40:36 -03:00
|
|
|
|
|
|
|
|
bool is_visible() const { return m_visible; }
|
|
|
|
|
|
2021-06-18 22:21:30 -03:00
|
|
|
void set_icon(const RefPtr<MultiScaleBitmaps>& icon) { m_icon = icon; }
|
2019-05-12 16:32:02 -03:00
|
|
|
|
2019-04-05 13:40:36 -03:00
|
|
|
private:
|
2020-02-06 16:03:37 -03:00
|
|
|
WindowFrame& m_frame;
|
2020-06-10 05:57:59 -03:00
|
|
|
Gfx::IntRect m_relative_rect;
|
2021-06-18 22:21:30 -03:00
|
|
|
RefPtr<MultiScaleBitmaps> m_icon;
|
2019-04-05 13:40:36 -03:00
|
|
|
bool m_pressed { false };
|
|
|
|
|
bool m_visible { true };
|
2019-04-05 23:08:09 -03:00
|
|
|
bool m_hovered { false };
|
2019-04-05 13:40:36 -03:00
|
|
|
};
|
2020-02-06 16:03:37 -03:00
|
|
|
|
|
|
|
|
}
|