SystemTheme.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include <LibCore/CConfigFile.h>
  2. #include <LibDraw/SystemTheme.h>
  3. static SystemTheme dummy_theme;
  4. static const SystemTheme* theme_page = &dummy_theme;
  5. static RefPtr<SharedBuffer> theme_buffer;
  6. const SystemTheme& current_system_theme()
  7. {
  8. ASSERT(theme_page);
  9. return *theme_page;
  10. }
  11. int current_system_theme_buffer_id()
  12. {
  13. ASSERT(theme_buffer);
  14. return theme_buffer->shared_buffer_id();
  15. }
  16. void set_system_theme(SharedBuffer& buffer)
  17. {
  18. theme_buffer = buffer;
  19. theme_page = (SystemTheme*)theme_buffer->data();
  20. }
  21. RefPtr<SharedBuffer> load_system_theme(const String& path)
  22. {
  23. auto file = CConfigFile::open(path);
  24. auto buffer = SharedBuffer::create_with_size(sizeof(SystemTheme));
  25. dbg() << "Created shared buffer with id " << buffer->shared_buffer_id();
  26. auto* data = (SystemTheme*)buffer->data();
  27. auto get = [&](auto& name) {
  28. auto color_string = file->read_entry("Colors", name);
  29. auto color = Color::from_string(color_string);
  30. if (!color.has_value())
  31. return Color(Color::Black);
  32. dbg() << "Parsed system color '" << name << "' = " << color.value();
  33. return color.value();
  34. };
  35. #define DO_COLOR(x) \
  36. data->color[(int)ColorRole::x] = get(#x)
  37. DO_COLOR(DesktopBackground);
  38. DO_COLOR(ThreedHighlight);
  39. DO_COLOR(ThreedShadow1);
  40. DO_COLOR(ThreedShadow2);
  41. DO_COLOR(HoverHighlight);
  42. DO_COLOR(Selection);
  43. DO_COLOR(SelectionText);
  44. DO_COLOR(Window);
  45. DO_COLOR(WindowText);
  46. DO_COLOR(Base);
  47. DO_COLOR(Button);
  48. DO_COLOR(ButtonText);
  49. DO_COLOR(DesktopBackground);
  50. DO_COLOR(ActiveWindowBorder1);
  51. DO_COLOR(ActiveWindowBorder2);
  52. DO_COLOR(ActiveWindowTitle);
  53. DO_COLOR(InactiveWindowBorder1);
  54. DO_COLOR(InactiveWindowBorder2);
  55. DO_COLOR(InactiveWindowTitle);
  56. DO_COLOR(MovingWindowBorder1);
  57. DO_COLOR(MovingWindowBorder2);
  58. DO_COLOR(MovingWindowTitle);
  59. DO_COLOR(HighlightWindowBorder1);
  60. DO_COLOR(HighlightWindowBorder2);
  61. DO_COLOR(HighlightWindowTitle);
  62. DO_COLOR(MenuStripe);
  63. DO_COLOR(MenuBase);
  64. DO_COLOR(MenuSelection);
  65. buffer->seal();
  66. buffer->share_globally();
  67. return buffer;
  68. }