ImageWidget.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. #pragma once
  8. #include <LibCore/Timer.h>
  9. #include <LibGUI/Frame.h>
  10. #include <LibGfx/ImageFormats/ImageDecoder.h>
  11. namespace GUI {
  12. class ImageWidget : public Frame {
  13. C_OBJECT(ImageWidget)
  14. public:
  15. virtual ~ImageWidget() override = default;
  16. void set_bitmap(Gfx::Bitmap const*);
  17. Gfx::Bitmap const* bitmap() const { return m_bitmap.ptr(); }
  18. void set_should_stretch(bool value) { m_should_stretch = value; }
  19. bool should_stretch() const { return m_should_stretch; }
  20. void set_auto_resize(bool value);
  21. bool auto_resize() const { return m_auto_resize; }
  22. void animate();
  23. void load_from_file(StringView);
  24. int opacity_percent() const { return m_opacity_percent; }
  25. void set_opacity_percent(int percent);
  26. Function<void()> on_click;
  27. protected:
  28. explicit ImageWidget(StringView text = {});
  29. virtual void mousedown_event(GUI::MouseEvent&) override;
  30. virtual void paint_event(PaintEvent&) override;
  31. private:
  32. RefPtr<Gfx::Bitmap const> m_bitmap;
  33. bool m_should_stretch { false };
  34. bool m_auto_resize { false };
  35. RefPtr<Gfx::ImageDecoder> m_image_decoder;
  36. size_t m_current_frame_index { 0 };
  37. size_t m_loops_completed { 0 };
  38. NonnullRefPtr<Core::Timer> m_timer;
  39. int m_opacity_percent { 100 };
  40. };
  41. }