tonegodgui_quickstart.adoc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. = tonegodgui_quickstart
  2. :revnumber: 2.0
  3. :revdate: 2020/07/27
  4. == Quick Start Guide:
  5. 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.
  6. The first step is to create the screen control. This can be done one of two ways.
  7. . Using the provided default style information:
  8. +
  9. [source,java]
  10. ----
  11. // this = any JME Application
  12. Screen screen = new Screen(this);
  13. screen.initialize();
  14. guiNode.addControl(screen);
  15. ----
  16. . Providing a path to another Style map.
  17. +
  18. [source,java]
  19. ----
  20. // this = any JME Application
  21. Screen screen = new Screen(this, "tonegod/gui/style/def/style_map.xml");
  22. screen.initialize();
  23. guiNode.addControl(screen);
  24. ----
  25. NOTE: 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).
  26. Next, we add a control. Might as well start with something interesting as all control constructors follow the same format. Let go with a window and then we’ll add a button to it. Here are the three constructor choices for creating the window:
  27. [source,java]
  28. ----
  29. /** Parameters:
  30. * Screen screen,
  31. * String UID,
  32. * Vector2f position
  33. */
  34. Window win = new Window(screen, "win", new Vector2f(15, 15));
  35. screen.addElement(win);
  36. ----
  37. 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.
  38. The second adds a 4th parameter to specify the windows dimensions, like such:
  39. [source,java]
  40. ----
  41. /** Additional Parameter:
  42. * Vector2f dimensions */
  43. Window win = new Window(screen, "win", new Vector2f(15, 15),
  44. new Vector2f(400, 300)
  45. );
  46. screen.addElement(win);
  47. ----
  48. The third option adds 2 more parameters and looks like this:
  49. [source,java]
  50. ----
  51. /** Additional Parameters:
  52. * Vector4f resizeBorders,
  53. * String defaultImg
  54. */
  55. Window win = new Window(screen, "win", new Vector2f(15, 15), new Vector2f(400, 300),
  56. new Vector4f(14,14,14,14),
  57. "tonegod/gui/style/def/Window/panel_x.png"
  58. );
  59. screen.addElement(win);
  60. ----
  61. Any parameters not specified are derived from the defaults specified in the Window style information.
  62. NOTE: The occasional control extends this constructor format, adding an additional Orientation parameter or possibly a boolean flag for controls that provide multiple configurable layouts.
  63. So, now lets add a button to the window that will create more windows!
  64. 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.
  65. NOTE: The button control (like many controls) is abstract and provides methods for handling user input. All events can be consumed by using evt.setConsumed();
  66. First, lets setup a method to create new windows:
  67. [source,java]
  68. ----
  69. private int winCount = 0;
  70. public final void createNewWindow(String someWindowTitle) {
  71. Window nWin = new Window(
  72. screen,
  73. "Window " + winCount,
  74. new Vector2f( (screen.getWidth()/2)-175, (screen.getHeight()/2)-100 )
  75. );
  76. nWin.setWindowTitle(someWindowTitle);
  77. screen.addElement(nWin);
  78. winCount++;
  79. }
  80. ----
  81. Now lets add the button to allow users to create new window:
  82. [source,java]
  83. ----
  84. /** Parameters:
  85. * Screen screen,
  86. * String UID,
  87. * Vector2f position
  88. */
  89. ButtonAdapter makeWindow = new ButtonAdapter( screen, "Btn1", new Vector2f(15, 55) ) {
  90. @Override
  91. public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
  92. createNewWindow("New Window " + winCount);
  93. }
  94. };
  95. // Add it to out initial window
  96. win.addChild(makeWindow);
  97. ----
  98. [NOTE]
  99. ====
  100. 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.
  101. *A Bit More Info:* 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.
  102. ====
  103. == A Few of the Common Behaviors:
  104. [source,java]
  105. ----
  106. // Makes control resizable from defined borders
  107. setIsResizable(boolean);
  108. // Makes the control movable
  109. setIsMovable(boolean);
  110. // Constrained to parent dimensions
  111. setLockToParentBounds(boolean);
  112. // On interaction effects direct parent instead of self
  113. setEffectParent(boolean);
  114. // On interaction effects absolute parent (screen lvl) instead of self
  115. setEffectAbsoluteParent(boolean);
  116. // allows the control to scale north/south from any encapsulating parent resize
  117. setScaleNS(boolean);
  118. // allows the control to scale east/west from any encapsulating parent resize
  119. setScaleEW(boolean);
  120. setDockN(boolean); // also enables/disables dock south
  121. setDockS(boolean); // also enables/disables dock north
  122. setDockE(boolean); // also enables/disables dock west
  123. setDockW(boolean); // also enables/disables dock east
  124. setIgnoreMouse(boolean);
  125. ----
  126. NOTE: There are far 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.