SeparatorWidget.cpp 1.2 KB

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