ImageWidget.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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/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* bitmap() { return m_bitmap.ptr(); }
  18. Gfx::Bitmap const* bitmap() const { return m_bitmap.ptr(); }
  19. void set_should_stretch(bool value) { m_should_stretch = value; }
  20. bool should_stretch() const { return m_should_stretch; }
  21. void set_auto_resize(bool value);
  22. bool auto_resize() const { return m_auto_resize; }
  23. void animate();
  24. void load_from_file(StringView);
  25. int opacity_percent() const { return m_opacity_percent; }
  26. void set_opacity_percent(int percent);
  27. Function<void()> on_click;
  28. protected:
  29. explicit ImageWidget(StringView text = {});
  30. virtual void mousedown_event(GUI::MouseEvent&) override;
  31. virtual void paint_event(PaintEvent&) override;
  32. private:
  33. RefPtr<Gfx::Bitmap> m_bitmap;
  34. bool m_should_stretch { false };
  35. bool m_auto_resize { false };
  36. RefPtr<Gfx::ImageDecoder> m_image_decoder;
  37. size_t m_current_frame_index { 0 };
  38. size_t m_loops_completed { 0 };
  39. NonnullRefPtr<Core::Timer> m_timer;
  40. int m_opacity_percent { 100 };
  41. };
  42. }