Serenity Operating System
at master 67 lines 1.6 kB view raw
1/* 2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#pragma once 8 9#include <AK/Function.h> 10#include <AK/Weakable.h> 11#include <LibGfx/Bitmap.h> 12#include <LibGfx/Forward.h> 13#include <LibGfx/Rect.h> 14#include <WindowServer/MultiScaleBitmaps.h> 15 16namespace WindowServer { 17 18class MouseEvent; 19class Screen; 20class WindowFrame; 21 22class Button : public Weakable<Button> { 23public: 24 Button(WindowFrame&, Function<void(Button&)>&& on_click_handler); 25 ~Button(); 26 27 Gfx::IntRect relative_rect() const { return m_relative_rect; } 28 void set_relative_rect(Gfx::IntRect const& rect) { m_relative_rect = rect; } 29 30 Gfx::IntRect rect() const { return { {}, m_relative_rect.size() }; } 31 Gfx::IntRect screen_rect() const; 32 33 void paint(Screen&, Gfx::Painter&); 34 35 void on_mouse_event(MouseEvent const&); 36 37 Function<void(Button&)> on_click; 38 Function<void(Button&)> on_secondary_click; 39 Function<void(Button&)> on_middle_click; 40 41 bool is_visible() const { return m_visible; } 42 43 struct Icon { 44 RefPtr<MultiScaleBitmaps> bitmap { nullptr }; 45 RefPtr<MultiScaleBitmaps> hover_bitmap { nullptr }; 46 }; 47 48 void set_icon(Icon const& icon) { m_icon = icon; } 49 50 enum class Style { 51 Normal, 52 IconOnly 53 }; 54 55 void set_style(Style style) { m_style = style; } 56 57private: 58 WindowFrame& m_frame; 59 Gfx::IntRect m_relative_rect; 60 Icon m_icon; 61 bool m_pressed { false }; 62 bool m_visible { true }; 63 bool m_hovered { false }; 64 Style m_style { Style::Normal }; 65}; 66 67}