quickstart.adoc 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. = quickstart
  2. :author:
  3. :revnumber:
  4. :revdate: 2016/03/17 20:48
  5. :relfileprefix: ../../../
  6. :imagesdir: ../../..
  7. ifdef::env-github,env-browser[:outfilesuffix: .adoc]
  8. == Quick Start Guide:
  9. For anyone who just wants to jump right in and read as you go, here are the basics for getting a UI up and running in minutes.
  10. === Step 1: Creating the Screen Control
  11. This can be done one of two ways.
  12. *Method 1* - Using the provided default style information:
  13. [source,java]
  14. ----
  15. // this = any JME Application
  16. Screen screen = new Screen(this);
  17. guiNode.addControl(screen);
  18. ----
  19. *Method 2* - Providing a path to another Style map:
  20. [source,java]
  21. ----
  22. // this = any JME Application
  23. Screen screen = new Screen(this, “tonegod/gui/style/def/style_map.xml”);
  24. guiNode.addControl(screen);
  25. ----
  26. [NOTE]
  27. ====
  28. style_map.xml consists of a list of xml documents containing varied styles for varied use. You can copy the default style map and replace one, many, all with project specific style (Covered later in this tutorial).
  29. ====
  30. === Step 2: Adding a Control to the Screen
  31. Might as well start with something interesting as all control contructors follow the same format. Let go with a window and then we’ll add a button to it.
  32. *Constructor 1:* +
  33. Here are the three contrustor choices for creating the window:
  34. [source,java]
  35. ----
  36. /** Parameters:
  37. * Screen screen,
  38. * String UID,
  39. * Vector2f position
  40. */
  41. Window win = new Window(screen, “win”, new Vector2f(15, 15));
  42. screen.addElement(win);
  43. ----
  44. And… boom! You have a fancy new resizable, movable window as part of you’re UI. Now, let’s take a look at the two additional constructors.
  45. *Constructor 2:* +
  46. The second adds a 4th parameter to specify the windows dimensions, like such:
  47. [source,java]
  48. ----
  49. /** Additional Parameter:
  50. * Vector2f dimensions */
  51. Window win = new Window(screen, “win”, new Vector2f(15, 15),
  52. new Vector2f(400, 300)
  53. );
  54. screen.addElement(win);
  55. ----
  56. *Constructor 3:* +
  57. The third option adds 2 more parameters and looks like this:
  58. [source,java]
  59. ----
  60. /** Additional Parameters:
  61. * Vector4f resizeBorders,
  62. * String defaultImg
  63. */
  64. Window win = new Window(screen, “win”, new Vector2f(15, 15), new Vector2f(400, 300),
  65. new Vector4f(14,14,14,14),
  66. “tonegod/gui/style/def/Window/panel_x.png”
  67. );
  68. screen.addElement(win);
  69. ----
  70. [NOTE]
  71. ====
  72. 3 new constructor options have been added recently. They are the same as the 3 above minus the UID parameter.
  73. ====
  74. Any parameters not specified are derived from the defaults specified in the Window style information.
  75. [NOTE]
  76. ====
  77. The occasional control extends this contructor format, adding an additional Orientation parameter or possibly a boolean flag for controls that provide multiple configurable layouts.
  78. ====
  79. === Step 3: Adding a Button to the Window
  80. Now we can add a button to the window that will create even MORE windows!
  81. The Button class is one of the only +++<abbr title="Graphical User Interface">GUI</abbr>+++ control classes that implements JME’s Control interface. The Control only becomes active if setInterval is called because the Button requires the use of stillPressed events. This and much more will be cover in later documentation. Again, you ave the three options above for creating an instance of the button control.
  82. [NOTE]
  83. ====
  84. The button control (like many controls) is abstract and provides methods for handling user input.
  85. ====
  86. First, lets setup a method to create new windows:
  87. [source,java]
  88. ----
  89. private int winCount = 0;
  90. public final void createNewWindow(String someWindowTitle) {
  91. Window nWin = new Window(
  92. screen,
  93. “Window” + winCount,
  94. new Vector2f( (screen.getWidth()/2)-175, (screen.getHeight()/2)-100 )
  95. );
  96. nWin.setWindowTitle(someWindowTitle);
  97. screen.addElement(nWin);
  98. winCount++;
  99. }
  100. ----
  101. Now we can add the button will call our create window method.
  102. [source,java]
  103. ----
  104. /** Parameters:
  105. * Screen screen,
  106. * String UID,
  107. * Vector2f position
  108. */
  109. ButtonAdapter makeWindow = new ButtonAdapter( screen, “Btn1″, new Vector2f(15, 55) ) {
  110. @Override
  111. public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
  112. createNewWindow(“New Window ” + winCount);
  113. }
  114. };
  115. // Add it to out initial window
  116. win.addChild(makeWindow);
  117. ----
  118. [TIP]
  119. ====
  120. For layout purposes, it is suggested that you add all child Elements to a control PRIOR to adding the control to the screen… so, create a window, add a button, add window to screen.
  121. ====
  122. *A Bit More Info:* +
  123. All controls are based on the Element class which has access to all default behaviors. Behaviors can be enabled disabled on ANY control or primitive Element.
  124. == A Few of the Common Behaviors:
  125. [source,java]
  126. ----
  127. // Makes control resizable from defined borders
  128. element.setIsResizable(boolean);
  129. // Makes the control movable
  130. element.setIsMovable(boolean);
  131. // Constrained to parent dimensions
  132. element.setLockToParentBounds(boolean);
  133. // On interaction effects direct parent instead of self
  134. element.setEffectParent(boolean);
  135. // On interaction effects absolute parent (screen lvl) instead of self
  136. element.setEffectAbsoluteParent(boolean);
  137. // allows the control to scale north/south from any encapsulating parent resize
  138. element.setScaleNS(boolean);
  139. // allows the control to scale east/west from any encapsulating parent resize
  140. element.setScaleEW(boolean);
  141. element.setDockN(boolean); // also enables/disables dock south
  142. element.setDockS(boolean); // also enables/disables dock north
  143. element.setDockE(boolean); // also enables/disables dock west
  144. element.setDockW(boolean); // also enables/disables dock east
  145. // Forcing the element to ignore the mouse
  146. element.setIgnoreMouse(boolean);
  147. ----
  148. [NOTE]
  149. ====
  150. There are more behaviors, however, these are the most critical when creating custom controls to ensure that nested Elements react as you would like when a parent Element is altered.
  151. ====
  152. == Quick Start Example In Full
  153. [source,java]
  154. ----
  155. public int winCount = 0;
  156. private Screen screen;
  157. public final void createNewWindow(String someWindowTitle) {
  158. Window nWin = new Window(
  159. screen,
  160. “Window” + winCount,
  161. new Vector2f( (screen.getWidth()/2)-175, (screen.getHeight()/2)-100 )
  162. );
  163. nWin.setWindowTitle(someWindowTitle);
  164. screen.addElement(nWin);
  165. winCount++;
  166. }
  167. public void simpleInitApp() {
  168. screen = new Screen(this, “tonegod/gui/style/def/style_map.xml”);
  169. screen.initialize();
  170. guiNode.addControl(screen);
  171. // Add window
  172. Window win = new Window(screen, “win”, new Vector2f(15, 15));
  173. // create button and add to window
  174. ButtonAdapter makeWindow = new ButtonAdapter( screen, “Btn1″, new Vector2f(15, 55) ) {
  175. @Override
  176. public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
  177. createNewWindow(“New Window ” + winCount);
  178. }
  179. };
  180. // Add it to our initial window
  181. win.addChild(makeWindow);
  182. // Add window to the screen
  183. screen.addElement(win);
  184. }
  185. ----