Serenity Operating System
at master 57 lines 1.4 kB view raw
1/* 2 * Copyright (c) 2020, Hüseyin Aslıtürk <asliturk@hotmail.com> 3 * Copyright (c) 2022, the SerenityOS developers. 4 * 5 * SPDX-License-Identifier: BSD-2-Clause 6 */ 7 8#pragma once 9 10#include <LibCore/Timer.h> 11#include <LibGUI/Frame.h> 12#include <LibGfx/ImageDecoder.h> 13 14namespace GUI { 15 16class ImageWidget : public Frame { 17 C_OBJECT(ImageWidget) 18public: 19 virtual ~ImageWidget() override = default; 20 21 void set_bitmap(Gfx::Bitmap const*); 22 Gfx::Bitmap const* bitmap() const { return m_bitmap.ptr(); } 23 24 void set_should_stretch(bool value) { m_should_stretch = value; } 25 bool should_stretch() const { return m_should_stretch; } 26 27 void set_auto_resize(bool value); 28 bool auto_resize() const { return m_auto_resize; } 29 30 void animate(); 31 void load_from_file(StringView); 32 33 int opacity_percent() const { return m_opacity_percent; } 34 void set_opacity_percent(int percent); 35 36 Function<void()> on_click; 37 38protected: 39 explicit ImageWidget(StringView text = {}); 40 41 virtual void mousedown_event(GUI::MouseEvent&) override; 42 virtual void paint_event(PaintEvent&) override; 43 44private: 45 RefPtr<Gfx::Bitmap const> m_bitmap; 46 bool m_should_stretch { false }; 47 bool m_auto_resize { false }; 48 49 RefPtr<Gfx::ImageDecoder> m_image_decoder; 50 size_t m_current_frame_index { 0 }; 51 size_t m_loops_completed { 0 }; 52 NonnullRefPtr<Core::Timer> m_timer; 53 54 int m_opacity_percent { 100 }; 55}; 56 57}