ProgressPaintable.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibGfx/StylePainter.h>
  7. #include <LibWeb/Painting/ProgressPaintable.h>
  8. namespace Web::Painting {
  9. JS::NonnullGCPtr<ProgressPaintable> ProgressPaintable::create(Layout::Progress const& layout_box)
  10. {
  11. return layout_box.heap().allocate_without_realm<ProgressPaintable>(layout_box);
  12. }
  13. ProgressPaintable::ProgressPaintable(Layout::Progress const& layout_box)
  14. : PaintableBox(layout_box)
  15. {
  16. }
  17. Layout::Progress const& ProgressPaintable::layout_box() const
  18. {
  19. return static_cast<Layout::Progress const&>(layout_node());
  20. }
  21. void ProgressPaintable::paint(PaintContext& context, PaintPhase phase) const
  22. {
  23. if (!is_visible())
  24. return;
  25. if (phase == PaintPhase::Foreground) {
  26. auto progress_rect = context.rounded_device_rect(absolute_rect());
  27. auto min_frame_thickness = context.rounded_device_pixels(3);
  28. auto frame_thickness = min(min(progress_rect.width(), progress_rect.height()) / 6, min_frame_thickness);
  29. Gfx::StylePainter::paint_progressbar(context.painter(), progress_rect.shrunken(frame_thickness, frame_thickness).to_type<int>(), context.palette(), 0, round_to<int>(layout_box().dom_node().max()), round_to<int>(layout_box().dom_node().value()), ""sv);
  30. Gfx::StylePainter::paint_frame(context.painter(), progress_rect.to_type<int>(), context.palette(), Gfx::FrameShape::Box, Gfx::FrameShadow::Raised, frame_thickness.value());
  31. }
  32. }
  33. }