styles.adoc 6.8 KB

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