ImageWidget.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (c) 2020, Hüseyin Aslıtürk <asliturk@hotmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibCore/Timer.h>
  8. #include <LibGUI/Frame.h>
  9. namespace GUI {
  10. class ImageWidget : public Frame {
  11. C_OBJECT(ImageWidget)
  12. public:
  13. virtual ~ImageWidget() override;
  14. void set_bitmap(const Gfx::Bitmap*);
  15. Gfx::Bitmap* bitmap() { return m_bitmap.ptr(); }
  16. void set_should_stretch(bool value) { m_should_stretch = value; }
  17. bool should_stretch() const { return m_should_stretch; }
  18. void set_auto_resize(bool value);
  19. bool auto_resize() const { return m_auto_resize; }
  20. void animate();
  21. void load_from_file(const StringView&);
  22. int opacity_percent() const { return m_opacity_percent; }
  23. void set_opacity_percent(int percent);
  24. Function<void()> on_click;
  25. protected:
  26. explicit ImageWidget(const StringView& text = {});
  27. virtual void mousedown_event(GUI::MouseEvent&) override;
  28. virtual void paint_event(PaintEvent&) override;
  29. private:
  30. RefPtr<Gfx::Bitmap> m_bitmap;
  31. bool m_should_stretch { false };
  32. bool m_auto_resize { false };
  33. RefPtr<Gfx::ImageDecoder> m_image_decoder;
  34. size_t m_current_frame_index { 0 };
  35. size_t m_loops_completed { 0 };
  36. NonnullRefPtr<Core::Timer> m_timer;
  37. int m_opacity_percent { 100 };
  38. };
  39. }