GStyle.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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, bool pressed)
  14. {
  15. Color button_color = Color::LightGray;
  16. Color highlight_color = Color::White;
  17. Color shadow_color = Color(96, 96, 96);
  18. painter.draw_rect(rect, Color::Black, true);
  19. painter.translate(rect.location());
  20. if (pressed) {
  21. // Base
  22. painter.fill_rect({ 1, 1, rect.width() - 2, rect.height() - 2 }, button_color);
  23. // Sunken shadow
  24. painter.draw_line({ 1, 1 }, { rect.width() - 2, 1 }, shadow_color);
  25. painter.draw_line({ 1, 2 }, {1, rect.height() - 2 }, shadow_color);
  26. } else {
  27. // Base
  28. painter.fill_rect({ 3, 3, rect.width() - 5, rect.height() - 5 }, button_color);
  29. painter.fill_rect_with_gradient({ 3, 3, rect.width() - 5, rect.height() - 5 }, button_color, Color::White);
  30. // White highlight
  31. painter.draw_line({ 1, 1 }, { rect.width() - 2, 1 }, highlight_color);
  32. painter.draw_line({ 1, 2 }, { rect.width() - 3, 2 }, highlight_color);
  33. painter.draw_line({ 1, 3 }, { 1, rect.height() - 2 }, highlight_color);
  34. painter.draw_line({ 2, 3 }, { 2, rect.height() - 3 }, highlight_color);
  35. // Gray shadow
  36. painter.draw_line({ rect.width() - 2, 1 }, { rect.width() - 2, rect.height() - 4 }, shadow_color);
  37. painter.draw_line({ rect.width() - 3, 2 }, { rect.width() - 3, rect.height() - 4 }, shadow_color);
  38. painter.draw_line({ 1, rect.height() - 2 }, { rect.width() - 2, rect.height() - 2 }, shadow_color);
  39. painter.draw_line({ 2, rect.height() - 3 }, { rect.width() - 2, rect.height() - 3 }, shadow_color);
  40. }
  41. painter.translate(-rect.location().x(), -rect.location().y());
  42. }