styles.adoc 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. = styles
  2. :revnumber: 2.0
  3. :revdate: 2020/07/27
  4. == Creating a new Theme
  5. === Understanding Styles
  6. The Style class is set up to be as open ended as possible for creating custom controls.
  7. Each property of a style can be one of the following data type:
  8. * String
  9. * float
  10. * int
  11. * boolean
  12. * ColorRGBA
  13. * Vector2f
  14. * Vector3f
  15. * Vector4f
  16. * Effect
  17. * Object
  18. To retrieve a tag from a style you must use the get method for the data type you trying to retrieve like so:
  19. [source,java]
  20. ----
  21. screen.getStyle("StyleName").getColorRGBA("TagNameInStyle");
  22. ----
  23. These can be used as flags for configuring you control, or style specific info for default Look & Feel
  24. Lets look at the Button.xml file as an example:
  25. [source,htmlblock]
  26. ----
  27. <root>
  28. <element name=”Button”>
  29. <font>
  30. <property name=”fontSize” type=”float” value=”18″ />
  31. <property name=”fontColor” type=”ColorRGBA”>
  32. <r value=”0.8″ />
  33. <g value=”0.8″ />
  34. <b value=”0.8″ />
  35. <a value=”1.0″ />
  36. </property>
  37. <property name=”textAlign” type=”String” value=”Center” />
  38. <property name=”textVAlign” type=”String” value=”Center” />
  39. <property name=”textWrap” type=”String” value=”Clip” />
  40. <property name=”hoverColor” type=”ColorRGBA”>
  41. <r value=”1.0″ />
  42. <g value=”1.0″ />
  43. <b value=”1.0″ />
  44. <a value=”1.0″ />
  45. </property>
  46. <property name=”pressedColor” type=”ColorRGBA”>
  47. <r value=”0.6″ />
  48. <g value=”0.6″ />
  49. <b value=”0.6″ />
  50. <a value=”1.0″ />
  51. </property>
  52. </font>
  53. <attributes>
  54. <property name=”resizeBorders” type=”Vector4f”>
  55. <x value=”5″ />
  56. <y value=”5″ />
  57. <z value=”5″ />
  58. <w value=”5″ />
  59. </property>
  60. <property name=”defaultSize” type=”Vector2f”>
  61. <x value=”100″ />
  62. <y value=”30″ />
  63. </property>
  64. </attributes>
  65. <images>
  66. <property name=”defaultImg” type=”String” value=”tonegod/gui/style/def/Button/button_x_u.png” />
  67. <property name=”hoverImg” type=”String” value=”tonegod/gui/style/def/Button/button_x_h.png” />
  68. <property name=”pressedImg” type=”String” value=”tonegod/gui/style/def/Button/button_x_d.png” />
  69. </images>
  70. <effects>
  71. <property name=”event0″ type=”Effect”>
  72. <event value=”Hover” />
  73. <effect value=”Pulse” />
  74. <speed value=”3″ />
  75. </property>
  76. <property name=”event1″ type=”Effect”>
  77. <event value=”Press” />
  78. <effect value=”ImageSwap” />
  79. <speed value=”0″ />
  80. </property>
  81. <property name=”event2″ type=”Effect”>
  82. <event value=”LoseFocus” />
  83. <effect value=”ImageSwap” />
  84. <speed value=”0″ />
  85. </property>
  86. </effects>
  87. </element>
  88. </root>
  89. ----
  90. The Style XML file for any given control can contain as many element tags as you would like. Each becomes another style that can be retrieved via:
  91. [source,java]
  92. ----
  93. screen.getStyle("styleName");
  94. ----
  95. Each element tag is divided into 4 sections:
  96. * fonts
  97. * attributes
  98. * images
  99. * effects
  100. The first 3 are interchangeable and only there for organizational purposes.
  101. The 4th (effects) is more specific, as the effects are stored and retrieved via the EffectManage of the Screen.
  102. The tags for storing properties are formatted as follows:
  103. * If the data type has a single value, the value is stored in the single property tag:
  104. [source,htmlblock]
  105. ----
  106. <property name="ID" type="float" value="0.5" />
  107. ----
  108. * If the data type has multiple value, the property tag would contain inner tags named after the value, like such:
  109. [source,htmlblock]
  110. ----
  111. <property name="ID" type="Vector4f />
  112. <x value="0.5 />
  113. <y value="0.5 />
  114. <z value="0.5 />
  115. <w value="0.5 />
  116. </property>
  117. ----
  118. Again, to retrieve this you would call:
  119. [source,java]
  120. ----
  121. screen.getStyle("styleName").getVector4f("ID");
  122. ----
  123. === The 'effects' Tag
  124. To add a default effect to a control, you would add a property tag under the 'effects' tag, like so:
  125. [source,htmlblock]
  126. ----
  127. <property name=”event0″ type=”Effect”>
  128. <event value=”Hover” />
  129. <effect value=”Pulse” />
  130. <speed value=”3″ />
  131. </property>
  132. ----
  133. Using Effects can be found HERE.
  134. === style_map.xml
  135. The style_map.xml file consists of a list of all other XML documents that contain style information for controls. All other XMLdocs could very well could be a single XML document containing all styles, however, for organization purposes, I read in as many from this list as you would like to add.
  136. Each entry in the style_map.xml file are formatted as follows:
  137. [source,htmlblock]
  138. ----
  139. <style control=”CustomControl” path=”somePath/MyNewControl.xml” />
  140. ----
  141. [NOTE]
  142. ====
  143. The control= property is not enforced, it is their for you to keep track of what XML file is used for what control.
  144. ====
  145. === To set up a custom global Look & Feel for your UI
  146. ==== STEP 1: Copy the style_map.xml file to a local directory in your Project Assets folder.
  147. [source,htmlblock]
  148. ----
  149. <?xml version="1.0" encoding="UTF-8"?>
  150. <root>
  151. <cursors path="somePath/Cursors.xml" />
  152. <audio path="somePath/Audio.xml" />
  153. <style control="Font" path="somePath/Fonts.xml" />
  154. <style control="Common" path="somePath/Common.xml" />
  155. <style control="Scrolling" path="somePath/Scrolling.xml" />
  156. <style control="Window" path="somePath/Window.xml" />
  157. <style control="Button" path="somePath/Button.xml" />
  158. <style control="Menu" path="somePath/Menu.xml" />
  159. <style control="Label" path="somePath/Label.xml" />
  160. <style control="Slider" path="somePath/Slider.xml" />
  161. <style control="TextField" path="somePath/TextField.xml" />
  162. <style control="ChatBox" path="somePath/ChatBox.xml" />
  163. <style control="Indicator" path="somePath/Indicator.xml" />
  164. </root>
  165. ----
  166. ==== STEP 2: Point your Screen class to the new style_map.xml file.
  167. [source,java]
  168. ----
  169. Screen screen = new Screen(this, "somePath/style_map.xml");
  170. ----
  171. You can now copy the existing XML docs for each listed in the style_map.xml file and make the adjustments you would like as default styles.
  172. [IMPORTANT]
  173. ====
  174. Don't forget to update the path in the style_map.xml file to point to your local copy for each control XML file you copy/edit.
  175. ====