GStyle.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include <LibGUI/GStyle.h>
  2. #include <SharedGraphics/Painter.h>
  3. static GStyle* s_the;
  4. GStyle& GStyle::the()
  5. {
  6. if (!s_the)
  7. s_the = new GStyle;
  8. return *s_the;
  9. }
  10. GStyle::GStyle()
  11. {
  12. }
  13. void GStyle::paint_button(Painter& painter, const Rect& rect, GButtonStyle button_style, bool pressed, bool hovered)
  14. {
  15. Color button_color = Color::LightGray;
  16. Color highlight_color = Color::White;
  17. Color shadow_color = Color(96, 96, 96);
  18. if (button_style == GButtonStyle::Normal)
  19. painter.draw_rect(rect, Color::Black, true);
  20. painter.translate(rect.location());
  21. if (pressed) {
  22. // Base
  23. painter.fill_rect({ 1, 1, rect.width() - 2, rect.height() - 2 }, button_color);
  24. // Sunken shadow
  25. painter.draw_line({ 1, 1 }, { rect.width() - 2, 1 }, shadow_color);
  26. painter.draw_line({ 1, 2 }, {1, rect.height() - 2 }, shadow_color);
  27. // Bottom highlight
  28. painter.draw_line({ rect.width() - 2, 1 }, { rect.width() - 2, rect.height() - 3 }, highlight_color);
  29. painter.draw_line({ 1, rect.height() - 2 }, { rect.width() - 2, rect.height() - 2 }, highlight_color);
  30. } else if (button_style == GButtonStyle::Normal || (button_style == GButtonStyle::CoolBar && hovered)) {
  31. // Base
  32. painter.fill_rect({ 3, 3, rect.width() - 5, rect.height() - 5 }, button_color);
  33. painter.fill_rect_with_gradient({ 2, 2, rect.width() - 3, rect.height() - 3 }, button_color, Color::White);
  34. // White highlight
  35. painter.draw_line({ 1, 1 }, { rect.width() - 2, 1 }, highlight_color);
  36. painter.draw_line({ 1, 2 }, { 1, rect.height() - 2 }, highlight_color);
  37. // Gray shadow
  38. painter.draw_line({ rect.width() - 2, 1 }, { rect.width() - 2, rect.height() - 3 }, shadow_color);
  39. painter.draw_line({ 1, rect.height() - 2 }, { rect.width() - 2, rect.height() - 2 }, shadow_color);
  40. }
  41. painter.translate(-rect.location().x(), -rect.location().y());
  42. }