StyleBase.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. using System.Numerics;
  2. using Content.Client.Resources;
  3. using Content.Client.UserInterface.Controls;
  4. using Robust.Client.Graphics;
  5. using Robust.Client.ResourceManagement;
  6. using Robust.Client.UserInterface;
  7. using Robust.Client.UserInterface.Controls;
  8. using Robust.Client.UserInterface.CustomControls;
  9. using Robust.Shared.Maths;
  10. namespace Content.Client.Stylesheets
  11. {
  12. public abstract class StyleBase
  13. {
  14. public const string ClassHighDivider = "HighDivider";
  15. public const string ClassLowDivider = "LowDivider";
  16. public const string StyleClassLabelHeading = "LabelHeading";
  17. public const string StyleClassLabelSubText = "LabelSubText";
  18. public const string StyleClassItalic = "Italic";
  19. public const string ClassAngleRect = "AngleRect";
  20. public const string ButtonOpenRight = "OpenRight";
  21. public const string ButtonOpenLeft = "OpenLeft";
  22. public const string ButtonOpenBoth = "OpenBoth";
  23. public const string ButtonSquare = "ButtonSquare";
  24. public const string ButtonCaution = "Caution";
  25. public const int DefaultGrabberSize = 10;
  26. public abstract Stylesheet Stylesheet { get; }
  27. protected StyleRule[] BaseRules { get; }
  28. protected StyleBoxTexture BaseButton { get; }
  29. protected StyleBoxTexture BaseButtonOpenRight { get; }
  30. protected StyleBoxTexture BaseButtonOpenLeft { get; }
  31. protected StyleBoxTexture BaseButtonOpenBoth { get; }
  32. protected StyleBoxTexture BaseButtonSquare { get; }
  33. protected StyleBoxTexture BaseAngleRect { get; }
  34. protected StyleBoxTexture AngleBorderRect { get; }
  35. protected StyleBase(IResourceCache resCache)
  36. {
  37. var notoSans12 = resCache.GetFont
  38. (
  39. new []
  40. {
  41. "/Fonts/NotoSans/NotoSans-Regular.ttf",
  42. "/Fonts/NotoSans/NotoSansSymbols-Regular.ttf",
  43. "/Fonts/NotoSans/NotoSansSymbols2-Regular.ttf"
  44. },
  45. 12
  46. );
  47. var notoSans12Italic = resCache.GetFont
  48. (
  49. new []
  50. {
  51. "/Fonts/NotoSans/NotoSans-Italic.ttf",
  52. "/Fonts/NotoSans/NotoSansSymbols-Regular.ttf",
  53. "/Fonts/NotoSans/NotoSansSymbols2-Regular.ttf"
  54. },
  55. 12
  56. );
  57. var textureCloseButton = resCache.GetTexture("/Textures/Interface/Nano/cross.svg.png");
  58. // Button styles.
  59. var buttonTex = resCache.GetTexture("/Textures/Interface/Nano/button.svg.96dpi.png");
  60. BaseButton = new StyleBoxTexture
  61. {
  62. Texture = buttonTex,
  63. };
  64. BaseButton.SetPatchMargin(StyleBox.Margin.All, 10);
  65. BaseButton.SetPadding(StyleBox.Margin.All, 1);
  66. BaseButton.SetContentMarginOverride(StyleBox.Margin.Vertical, 2);
  67. BaseButton.SetContentMarginOverride(StyleBox.Margin.Horizontal, 14);
  68. BaseButtonOpenRight = new StyleBoxTexture(BaseButton)
  69. {
  70. Texture = new AtlasTexture(buttonTex, UIBox2.FromDimensions(new Vector2(0, 0), new Vector2(14, 24))),
  71. };
  72. BaseButtonOpenRight.SetPatchMargin(StyleBox.Margin.Right, 0);
  73. BaseButtonOpenRight.SetContentMarginOverride(StyleBox.Margin.Right, 8);
  74. BaseButtonOpenRight.SetPadding(StyleBox.Margin.Right, 2);
  75. BaseButtonOpenLeft = new StyleBoxTexture(BaseButton)
  76. {
  77. Texture = new AtlasTexture(buttonTex, UIBox2.FromDimensions(new Vector2(10, 0), new Vector2(14, 24))),
  78. };
  79. BaseButtonOpenLeft.SetPatchMargin(StyleBox.Margin.Left, 0);
  80. BaseButtonOpenLeft.SetContentMarginOverride(StyleBox.Margin.Left, 8);
  81. BaseButtonOpenLeft.SetPadding(StyleBox.Margin.Left, 1);
  82. BaseButtonOpenBoth = new StyleBoxTexture(BaseButton)
  83. {
  84. Texture = new AtlasTexture(buttonTex, UIBox2.FromDimensions(new Vector2(10, 0), new Vector2(3, 24))),
  85. };
  86. BaseButtonOpenBoth.SetPatchMargin(StyleBox.Margin.Horizontal, 0);
  87. BaseButtonOpenBoth.SetContentMarginOverride(StyleBox.Margin.Horizontal, 8);
  88. BaseButtonOpenBoth.SetPadding(StyleBox.Margin.Right, 2);
  89. BaseButtonOpenBoth.SetPadding(StyleBox.Margin.Left, 1);
  90. BaseButtonSquare = new StyleBoxTexture(BaseButton)
  91. {
  92. Texture = new AtlasTexture(buttonTex, UIBox2.FromDimensions(new Vector2(10, 0), new Vector2(3, 24))),
  93. };
  94. BaseButtonSquare.SetPatchMargin(StyleBox.Margin.Horizontal, 0);
  95. BaseButtonSquare.SetContentMarginOverride(StyleBox.Margin.Horizontal, 8);
  96. BaseButtonSquare.SetPadding(StyleBox.Margin.Right, 2);
  97. BaseButtonSquare.SetPadding(StyleBox.Margin.Left, 1);
  98. BaseAngleRect = new StyleBoxTexture
  99. {
  100. Texture = buttonTex,
  101. };
  102. BaseAngleRect.SetPatchMargin(StyleBox.Margin.All, 10);
  103. AngleBorderRect = new StyleBoxTexture
  104. {
  105. Texture = resCache.GetTexture("/Textures/Interface/Nano/geometric_panel_border.svg.96dpi.png"),
  106. };
  107. AngleBorderRect.SetPatchMargin(StyleBox.Margin.All, 10);
  108. var vScrollBarGrabberNormal = new StyleBoxFlat
  109. {
  110. BackgroundColor = Color.Gray.WithAlpha(0.35f), ContentMarginLeftOverride = DefaultGrabberSize,
  111. ContentMarginTopOverride = DefaultGrabberSize
  112. };
  113. var vScrollBarGrabberHover = new StyleBoxFlat
  114. {
  115. BackgroundColor = new Color(140, 140, 140).WithAlpha(0.35f), ContentMarginLeftOverride = DefaultGrabberSize,
  116. ContentMarginTopOverride = DefaultGrabberSize
  117. };
  118. var vScrollBarGrabberGrabbed = new StyleBoxFlat
  119. {
  120. BackgroundColor = new Color(160, 160, 160).WithAlpha(0.35f), ContentMarginLeftOverride = DefaultGrabberSize,
  121. ContentMarginTopOverride = DefaultGrabberSize
  122. };
  123. var hScrollBarGrabberNormal = new StyleBoxFlat
  124. {
  125. BackgroundColor = Color.Gray.WithAlpha(0.35f), ContentMarginTopOverride = DefaultGrabberSize
  126. };
  127. var hScrollBarGrabberHover = new StyleBoxFlat
  128. {
  129. BackgroundColor = new Color(140, 140, 140).WithAlpha(0.35f), ContentMarginTopOverride = DefaultGrabberSize
  130. };
  131. var hScrollBarGrabberGrabbed = new StyleBoxFlat
  132. {
  133. BackgroundColor = new Color(160, 160, 160).WithAlpha(0.35f), ContentMarginTopOverride = DefaultGrabberSize
  134. };
  135. BaseRules = new[]
  136. {
  137. // Default font.
  138. new StyleRule(
  139. new SelectorElement(null, null, null, null),
  140. new[]
  141. {
  142. new StyleProperty("font", notoSans12),
  143. }),
  144. // Default font.
  145. new StyleRule(
  146. new SelectorElement(null, new[] {StyleClassItalic}, null, null),
  147. new[]
  148. {
  149. new StyleProperty("font", notoSans12Italic),
  150. }),
  151. // Window close button base texture.
  152. new StyleRule(
  153. new SelectorElement(typeof(TextureButton), new[] {DefaultWindow.StyleClassWindowCloseButton}, null,
  154. null),
  155. new[]
  156. {
  157. new StyleProperty(TextureButton.StylePropertyTexture, textureCloseButton),
  158. new StyleProperty(Control.StylePropertyModulateSelf, Color.FromHex("#4B596A")),
  159. }),
  160. // Window close button hover.
  161. new StyleRule(
  162. new SelectorElement(typeof(TextureButton), new[] {DefaultWindow.StyleClassWindowCloseButton}, null,
  163. new[] {TextureButton.StylePseudoClassHover}),
  164. new[]
  165. {
  166. new StyleProperty(Control.StylePropertyModulateSelf, Color.FromHex("#7F3636")),
  167. }),
  168. // Window close button pressed.
  169. new StyleRule(
  170. new SelectorElement(typeof(TextureButton), new[] {DefaultWindow.StyleClassWindowCloseButton}, null,
  171. new[] {TextureButton.StylePseudoClassPressed}),
  172. new[]
  173. {
  174. new StyleProperty(Control.StylePropertyModulateSelf, Color.FromHex("#753131")),
  175. }),
  176. // Scroll bars
  177. new StyleRule(new SelectorElement(typeof(VScrollBar), null, null, null),
  178. new[]
  179. {
  180. new StyleProperty(ScrollBar.StylePropertyGrabber,
  181. vScrollBarGrabberNormal),
  182. }),
  183. new StyleRule(
  184. new SelectorElement(typeof(VScrollBar), null, null, new[] {ScrollBar.StylePseudoClassHover}),
  185. new[]
  186. {
  187. new StyleProperty(ScrollBar.StylePropertyGrabber,
  188. vScrollBarGrabberHover),
  189. }),
  190. new StyleRule(
  191. new SelectorElement(typeof(VScrollBar), null, null, new[] {ScrollBar.StylePseudoClassGrabbed}),
  192. new[]
  193. {
  194. new StyleProperty(ScrollBar.StylePropertyGrabber,
  195. vScrollBarGrabberGrabbed),
  196. }),
  197. new StyleRule(new SelectorElement(typeof(HScrollBar), null, null, null),
  198. new[]
  199. {
  200. new StyleProperty(ScrollBar.StylePropertyGrabber,
  201. hScrollBarGrabberNormal),
  202. }),
  203. new StyleRule(
  204. new SelectorElement(typeof(HScrollBar), null, null, new[] {ScrollBar.StylePseudoClassHover}),
  205. new[]
  206. {
  207. new StyleProperty(ScrollBar.StylePropertyGrabber,
  208. hScrollBarGrabberHover),
  209. }),
  210. new StyleRule(
  211. new SelectorElement(typeof(HScrollBar), null, null, new[] {ScrollBar.StylePseudoClassGrabbed}),
  212. new[]
  213. {
  214. new StyleProperty(ScrollBar.StylePropertyGrabber,
  215. hScrollBarGrabberGrabbed),
  216. }),
  217. };
  218. }
  219. }
  220. }