DoubleClickArrowWidget.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "DoubleClickArrowWidget.h"
  7. #include <LibGUI/Painter.h>
  8. #include <LibGfx/Font.h>
  9. REGISTER_WIDGET(MouseSettings, DoubleClickArrowWidget);
  10. namespace MouseSettings {
  11. DoubleClickArrowWidget::~DoubleClickArrowWidget()
  12. {
  13. }
  14. void DoubleClickArrowWidget::set_double_click_speed(int speed)
  15. {
  16. if (m_double_click_speed == speed)
  17. return;
  18. m_double_click_speed = speed;
  19. update();
  20. }
  21. DoubleClickArrowWidget::DoubleClickArrowWidget()
  22. {
  23. m_arrow_bitmap = Gfx::Bitmap::load_from_file("/res/graphics/double-click-down-arrow.png");
  24. }
  25. void DoubleClickArrowWidget::paint_event(GUI::PaintEvent& event)
  26. {
  27. GUI::Painter painter(*this);
  28. painter.add_clip_rect(event.rect());
  29. auto bottom_arrow_rect = m_arrow_bitmap->rect();
  30. bottom_arrow_rect.center_within(rect());
  31. bottom_arrow_rect.translate_by(0, m_arrow_bitmap->height() / 2);
  32. painter.blit_filtered(bottom_arrow_rect.location(), *m_arrow_bitmap, m_arrow_bitmap->rect(), [&](Color color) {
  33. return m_inverted ? color.inverted() : color;
  34. });
  35. auto top_arrow_rect = bottom_arrow_rect;
  36. top_arrow_rect.translate_by(0, -(m_double_click_speed / 50));
  37. painter.blit_filtered(top_arrow_rect.location(), *m_arrow_bitmap, m_arrow_bitmap->rect(), [&](Color color) {
  38. return m_inverted ? color.inverted() : color;
  39. });
  40. auto text_rect = rect();
  41. text_rect.set_y(bottom_arrow_rect.bottom());
  42. text_rect.set_height(font().glyph_height());
  43. }
  44. void DoubleClickArrowWidget::doubleclick_event(GUI::MouseEvent&)
  45. {
  46. m_inverted = !m_inverted;
  47. update();
  48. }
  49. }