SeparatorWidget.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2022, the SerenityOS developers.
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <LibGUI/Painter.h>
  8. #include <LibGUI/SeparatorWidget.h>
  9. #include <LibGfx/Palette.h>
  10. REGISTER_WIDGET(GUI, HorizontalSeparator)
  11. REGISTER_WIDGET(GUI, VerticalSeparator)
  12. namespace GUI {
  13. SeparatorWidget::SeparatorWidget(Gfx::Orientation orientation)
  14. : m_orientation(orientation)
  15. {
  16. if (m_orientation == Gfx::Orientation::Vertical)
  17. set_fixed_width(8);
  18. else
  19. set_fixed_height(8);
  20. }
  21. void SeparatorWidget::paint_event(PaintEvent& event)
  22. {
  23. Painter painter(*this);
  24. painter.add_clip_rect(event.rect());
  25. if (m_orientation == Gfx::Orientation::Vertical) {
  26. painter.translate(rect().center().x() - 1, 0);
  27. painter.draw_line({ 0, 0 }, { 0, rect().bottom() }, palette().threed_shadow1());
  28. painter.draw_line({ 1, 0 }, { 1, rect().bottom() }, palette().threed_highlight());
  29. } else {
  30. painter.translate(0, rect().center().y() - 1);
  31. painter.draw_line({ 0, 0 }, { rect().right(), 0 }, palette().threed_shadow1());
  32. painter.draw_line({ 0, 1 }, { rect().right(), 1 }, palette().threed_highlight());
  33. }
  34. }
  35. }