123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- = element
- :author:
- :revnumber:
- :revdate: 2016/03/17 20:48
- :relfileprefix: ../../../
- :imagesdir: ../../..
- ifdef::env-github,env-browser[:outfilesuffix: .adoc]
- == The Element Class
- 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.
- === Constructors
- The Element class only provides a single constructor using all 6 of the common parameters:
- [source,java]
- ----
- /**
- * Parameters:
- * Screen screen
- * String UID
- * Vector2f position
- * Vector2f dimensions
- * Vector4f resizeBorders
- * String defaultImgPath
- */
- Element el = new Element(
- screen,
- “SomeID”,
- new Vector2f(5,5),
- new Vector2f(100,100),
- new Vector4f(5,5,5,5),
- “someImgPath.png”
- );
- ----
- [NOTE]
- ====
- All setter provide getters.
- ====
- === Text/Font Related Methods
- [source,java]
- ----
- element.setFont(String font path)
- element.setFontSize(float fontSize);
- element.setFontColor(ColorRGBA fontColor);
- element.setTextAlign(BitmapFont.Align textAlign);
- element.setTextVAlign(BitmapFont.VAlign textVAlign);
- element.setTextWrap(LineWrapMode textWrap);
- element.setTextPosition(float x, float y);
- element.setTextPadding(float textPadding);
- element.setText(String text);
- ----
- === Element Positions/Dimensions Related Methods
- [source,java]
- ----
- element.setPosition(Vector2f position);
- element.setPosition(float x, float y);
- element.setX(float x);
- element.setY(float y);
- element.setDimensions(Vector2f dimensions);
- element.setDimensions(float w, float h);
- element.setWidth(float width);
- element.setHeight(float height);
- element.setMinDimensions(new Vector2f(float x, float y));
- ----
- === Other Positions/Dimensions Related Methods
- 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)
- [source,java]
- ----
- element.getAbsoluteX();
- element.getAbsoluteY();
- element.getAbsoluteWidth();
- element.getAbsoluteHeight();
- ----
- === Child Elements
- There are additional methods that provide recursive updates to child Elements:
- [source,java]
- ----
- element.moveTo(float x, float y);
- element.resize(float diffX, floar diffY, Element.Borders dir);
- ----
- === Element Display Methods
- [source,java]
- ----
- el.show();
- el.showWithEffect();
- el.hide();
- el.hideWithEffect();
- ----
- === Hooks
- Overridable hooks are provided for default behavoirs:
- [source,java]
- ----
- public void controlResizeHook() { }
- public void controlMoveHook() { }
- public void controlCleanupHook() { }
- ----
- === Clipping
- To have the element be clipped by another element's bounds, use:
- [source,java]
- ----
- el.setClippingLayer(Element element);
- ----
- To set the clipping layer of the Element and propagate clipping to all children of the Element, use:
- [source,java]
- ----
- el.setControlClippingLayer(Element element);
- ----
- === Accessing the Element's Components
- [source,java]
- ----
- el.getGeometry(); // The element's Geometry
- el.getModel(); // The element's mesh
- el.getTextElement(); // BitmapText (null if setText() has not been previously called)
- ----
- === Modifying the Material
- There are plenty of methods that allow for modifying the look & feel of the Element:
- [source,java]
- ----
- // Accessing the element's material
- el.getElementMaterial();
- // Updating the texture:
- el.setColorMap(String imgPath); // To modify the element's base texture
- el.setAlphaMap(String imgPath); // To set the element's alphamap
- // Using gradient fills:
- el.getModel().setGradientFillHorizontal(ColorRGBA start, ColorRGBA end);
- el.getModel().setGradientFillVertical(ColorRGBA start, ColorRGBA end);
- // Defining each vertex color
- el.getModel().setColorBuffer(FloatBuffer colors);
- // Adjusting the element's alpha
- el.setGlobalAlpha(float alpha);
- ----
- === Effect Related Methods
- [source,java]
- ----
- el.addEffect(Effect effect);
- el.removeEffect(Effect.EffectEvent effectEvent);
- el.populateEffects(String styleName); // Loads all effects associated with a Style
- ----
- === Drag & Drop Related Methods
- [source,java]
- ----
- el.setIsDragDropDragElement(boolean isDragElement);
- el.setIsDragDropDropElement(boolean isDropElement);
- // for retrieving the current drop object under the element, use:
- screen.getDropObject();
- ----
- [NOTE]
- ====
- You must manage your own list of acceptable drop objects as any Element flagged as isDropObject will be returned.
- ====
- === Storing & Retrieving Custom Data
- [source,java]
- ----
- el.setElementUserData(Object data);
- el.getElementUserData();
- ----
|