element.adoc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. = element
  2. :author:
  3. :revnumber:
  4. :revdate: 2016/03/17 20:48
  5. :relfileprefix: ../../../
  6. :imagesdir: ../../..
  7. ifdef::env-github,env-browser[:outfilesuffix: .adoc]
  8. == The Element Class
  9. All controls are extensions of the Element class and thus, provide common methods for handling common features. Before getting to specific controls, I thought it might be a good idea to cover some of the common methods for changing basic properties… such as: text, etc.
  10. === Constructors
  11. The Element class only provides a single constructor using all 6 of the common parameters:
  12. [source,java]
  13. ----
  14. /**
  15. * Parameters:
  16. * Screen screen
  17. * String UID
  18. * Vector2f position
  19. * Vector2f dimensions
  20. * Vector4f resizeBorders
  21. * String defaultImgPath
  22. */
  23. Element el = new Element(
  24. screen,
  25. “SomeID”,
  26. new Vector2f(5,5),
  27. new Vector2f(100,100),
  28. new Vector4f(5,5,5,5),
  29. “someImgPath.png”
  30. );
  31. ----
  32. [NOTE]
  33. ====
  34. All setter provide getters.
  35. ====
  36. === Text/Font Related Methods
  37. [source,java]
  38. ----
  39. element.setFont(String font path)
  40. element.setFontSize(float fontSize);
  41. element.setFontColor(ColorRGBA fontColor);
  42. element.setTextAlign(BitmapFont.Align textAlign);
  43. element.setTextVAlign(BitmapFont.VAlign textVAlign);
  44. element.setTextWrap(LineWrapMode textWrap);
  45. element.setTextPosition(float x, float y);
  46. element.setTextPadding(float textPadding);
  47. element.setText(String text);
  48. ----
  49. === Element Positions/Dimensions Related Methods
  50. [source,java]
  51. ----
  52. element.setPosition(Vector2f position);
  53. element.setPosition(float x, float y);
  54. element.setX(float x);
  55. element.setY(float y);
  56. element.setDimensions(Vector2f dimensions);
  57. element.setDimensions(float w, float h);
  58. element.setWidth(float width);
  59. element.setHeight(float height);
  60. element.setMinDimensions(new Vector2f(float x, float y));
  61. ----
  62. === Other Positions/Dimensions Related Methods
  63. Since position and dimensions are relative to the Element’s parent Element, there are additional getters provided for retrieving absolute X, Y, Width & Height (absolute positions start from screen coords 0, 0)
  64. [source,java]
  65. ----
  66. element.getAbsoluteX();
  67. element.getAbsoluteY();
  68. element.getAbsoluteWidth();
  69. element.getAbsoluteHeight();
  70. ----
  71. === Child Elements
  72. There are additional methods that provide recursive updates to child Elements:
  73. [source,java]
  74. ----
  75. element.moveTo(float x, float y);
  76. element.resize(float diffX, floar diffY, Element.Borders dir);
  77. ----
  78. === Element Display Methods
  79. [source,java]
  80. ----
  81. el.show();
  82. el.showWithEffect();
  83. el.hide();
  84. el.hideWithEffect();
  85. ----
  86. === Hooks
  87. Overridable hooks are provided for default behavoirs:
  88. [source,java]
  89. ----
  90. public void controlResizeHook() { }
  91. public void controlMoveHook() { }
  92. public void controlCleanupHook() { }
  93. ----
  94. === Clipping
  95. To have the element be clipped by another element's bounds, use:
  96. [source,java]
  97. ----
  98. el.setClippingLayer(Element element);
  99. ----
  100. To set the clipping layer of the Element and propagate clipping to all children of the Element, use:
  101. [source,java]
  102. ----
  103. el.setControlClippingLayer(Element element);
  104. ----
  105. === Accessing the Element's Components
  106. [source,java]
  107. ----
  108. el.getGeometry(); // The element's Geometry
  109. el.getModel(); // The element's mesh
  110. el.getTextElement(); // BitmapText (null if setText() has not been previously called)
  111. ----
  112. === Modifying the Material
  113. There are plenty of methods that allow for modifying the look & feel of the Element:
  114. [source,java]
  115. ----
  116. // Accessing the element's material
  117. el.getElementMaterial();
  118. // Updating the texture:
  119. el.setColorMap(String imgPath); // To modify the element's base texture
  120. el.setAlphaMap(String imgPath); // To set the element's alphamap
  121. // Using gradient fills:
  122. el.getModel().setGradientFillHorizontal(ColorRGBA start, ColorRGBA end);
  123. el.getModel().setGradientFillVertical(ColorRGBA start, ColorRGBA end);
  124. // Defining each vertex color
  125. el.getModel().setColorBuffer(FloatBuffer colors);
  126. // Adjusting the element's alpha
  127. el.setGlobalAlpha(float alpha);
  128. ----
  129. === Effect Related Methods
  130. [source,java]
  131. ----
  132. el.addEffect(Effect effect);
  133. el.removeEffect(Effect.EffectEvent effectEvent);
  134. el.populateEffects(String styleName); // Loads all effects associated with a Style
  135. ----
  136. === Drag & Drop Related Methods
  137. [source,java]
  138. ----
  139. el.setIsDragDropDragElement(boolean isDragElement);
  140. el.setIsDragDropDropElement(boolean isDropElement);
  141. // for retrieving the current drop object under the element, use:
  142. screen.getDropObject();
  143. ----
  144. [NOTE]
  145. ====
  146. You must manage your own list of acceptable drop objects as any Element flagged as isDropObject will be returned.
  147. ====
  148. === Storing & Retrieving Custom Data
  149. [source,java]
  150. ----
  151. el.setElementUserData(Object data);
  152. el.getElementUserData();
  153. ----