element.adoc 4.5 KB

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