button.adoc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. = button
  2. :author:
  3. :revnumber:
  4. :revdate: 2016/03/17 20:48
  5. :relfileprefix: ../../../
  6. :imagesdir: ../../..
  7. ifdef::env-github,env-browser[:outfilesuffix: .adoc]
  8. == Button Class
  9. * Buttons have a default state, a hover state and a pressed state.
  10. * They implement the tonegodGUI MouseButtonListener & MouseFocusListener interfaces
  11. * They provide an optional stillPressed event
  12. * Can either consist of text label or icon
  13. * They can be set to Toggle mode.
  14. * They have default effects set for Hover, Pressed & LoseFocus
  15. * Buttons are an abstract class providing methods for handling user input
  16. Again, the same three options for constructor are available as show in the <<jme3/contributions/tonegodgui/quickstart#,Quick Start Guide>>.
  17. *Constructor 1:*
  18. [source,java]
  19. ----
  20. /** Parameters:
  21. * Screen screen,
  22. * String UID,
  23. * Vector2f position
  24. */
  25. Button button = new Button(screen, “button”, new Vector2f(15, 15));
  26. ----
  27. *Constructor 2:*
  28. [source,java]
  29. ----
  30. /** Additional Parameter:
  31. * Vector2f dimensions */
  32. Button button = new Button(screen, “button”, new Vector2f(15, 15),
  33. new Vector2f(100, 25)
  34. );
  35. ----
  36. *Constructor 3:*
  37. [source,java]
  38. ----
  39. /** Additional Parameters:
  40. * Vector4f resizeBorders,
  41. * String defaultImg
  42. */
  43. Button button = new Button(screen, “button”, new Vector2f(15, 15), new Vector2f(100, 25),
  44. new Vector4f(5,5,5,5),
  45. “tonegod/gui/style/def/Button/button_u_x.png”
  46. );
  47. ----
  48. === Hover State
  49. You can override the default hover state using the following method:
  50. [source,java]
  51. ----
  52. // Override the information used by the hover effect
  53. button.setButtonHoverInfo(String imagePath, ColorRGBA textHoverColor);
  54. ----
  55. === Pressed State
  56. You can override the default pressed state using the following method:
  57. [source,java]
  58. ----
  59. // Override the information used by the pressed effect
  60. button.setButtonPressedInfo(String imagePath, ColorRGBA textPressedColor);
  61. ----
  62. === Abstract Event Methods:
  63. [source,java]
  64. ----
  65. public void onButtonMouseLeftDown(MouseButtonEvent evt, boolean toggled);
  66. public void onButtonMouseRightDown(MouseButtonEvent evt, boolean toggled);
  67. public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled);
  68. public void onButtonMouseRightUp(MouseButtonEvent evt, boolean toggled);
  69. public void onButtonFocus(MouseMotionEvent evt);
  70. public void onButtonLostFocus(MouseMotionEvent evt);
  71. public void onButtonStillPressedInterval();
  72. ----
  73. === Adding an Icon
  74. In place of text, you can use an image icon by calling the following method:
  75. [source,java]
  76. ----
  77. button.setButtonIcon(float width, float height, String texturePath);
  78. ----
  79. === Methods specific to the Button class
  80. [source,java]
  81. ----
  82. //Toggle info
  83. button.setIsToggleButton(boolean isToggleButton); // Also provides a getter
  84. button.getIsToggleButton();
  85. button.getIsToggled();
  86. // Additional state info
  87. button.clearAltImages();
  88. // Enabling/disabling invternal calls (StillPressed event)
  89. button.setInterval(float intervalsPerSecond); // 0 deactivates
  90. ----
  91. [NOTE]
  92. ====
  93. When not otherwise specified, use the primitive Element method for setting the text of a control. For instance, to set the text of the Button instance, you simply call:
  94. [source,java]
  95. ----
  96. button.setText(String text);
  97. ----
  98. ====
  99. == ButtonAdapter Class
  100. Tips for using the Button class:
  101. . Create a button
  102. . Implement all abstract methods
  103. . Write your code for the event handlers you wish to use
  104. . Change the Button to a ButtonAdapter
  105. . Remove all unused event handler methods