Widget.cpp 906 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) 2022, Sahan Fernando <sahan.h.fernando@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibGUI/Label.h>
  7. #include <LibGUI/Painter.h>
  8. #include "Widget.h"
  9. ErrorOr<NonnullRefPtr<Demo>> Demo::create()
  10. {
  11. auto demo = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) Demo));
  12. demo->m_bitmap = TRY(Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { DRAWTARGET_WIDTH, DRAWTARGET_HEIGHT }));
  13. demo->m_bitmap->fill(Gfx::Color::Black);
  14. return demo;
  15. }
  16. Demo::Demo()
  17. {
  18. m_cycles = 0;
  19. stop_timer();
  20. start_timer(16);
  21. }
  22. Demo::~Demo() { }
  23. void Demo::paint_event(GUI::PaintEvent& event)
  24. {
  25. GUI::Painter painter(*this);
  26. painter.add_clip_rect(event.rect());
  27. painter.draw_scaled_bitmap(rect(), *m_bitmap, m_bitmap->rect());
  28. }
  29. void Demo::timer_event(Core::TimerEvent&)
  30. {
  31. m_cycles += 1;
  32. update_frame(m_bitmap, m_cycles);
  33. update();
  34. }