Class Drawable
-
-
Field Summary
Fields Modifier and Type Field Description private final transient HashMap<Event, Function2<Drawable, Event, Boolean>>eventHandlersprivate transient StringsimpleNameprivate Vec2<Unit>sizeprivate transient Rendererrendererprivate transient PolyUIpolyUIprivate BooleanacceptsInputprivate final transient ByteinitStageprivate final transient BooleanmouseOverprivate Booleanrendersprivate final Layoutlayoutprivate BooleanconsumesHoverprivate Floatxprivate Floatyprivate Floatwidthprivate Floatheightprivate Booleanexistsprivate transient FloattrueXprivate transient FloattrueYprivate final Unit.TypeatTypeprivate final Unit.TypesizeTypeprivate final BooleanisDynamicprivate Doublerotationprivate DoubleskewXprivate DoubleskewYprivate FloatscaleXprivate FloatscaleYprivate Floatalphaprivate transient Floatacxprivate transient Floatacyprivate final Vec2<Unit>atprivate final BooleanrawResize
-
Method Summary
Modifier and Type Method Description final HashMap<Event, Function2<Drawable, Event, Boolean>>getEventHandlers()StringgetSimpleName()This is the name of this drawable, and it will be consistent over reboots of the program, so you can use it to get drawables from a layout by ID, e. UnitsetSimpleName(String simpleName)This is the name of this drawable, and it will be consistent over reboots of the program, so you can use it to get drawables from a layout by ID, e. abstract Vec2<Unit>getSize()size of this drawable. abstract UnitsetSize(Vec2<Unit> size)size of this drawable. final RenderergetRenderer()final UnitsetRenderer(Renderer renderer)final PolyUIgetPolyUI()final UnitsetPolyUI(PolyUI polyUI)final BooleangetAcceptsInput()final UnitsetAcceptsInput(Boolean acceptsInput)final BytegetInitStage()This is the initialization stage of this drawable. final BooleangetMouseOver()weather or not the mouse is currently over this drawable. BooleangetRenders()UnitsetRenders(Boolean renders)weather or not this drawable should be rendered. abstract LayoutgetLayout()Reference to the layout encapsulating this drawable. abstract BooleangetConsumesHover()If this is true, the drawable will be the only drawable that is allowed to be hovered at once.abstract UnitsetConsumesHover(Boolean consumesHover)If this is true, the drawable will be the only drawable that is allowed to be hovered at once.final FloatgetX()final UnitsetX(Float x)final FloatgetY()final UnitsetY(Float y)final FloatgetWidth()final UnitsetWidth(Float width)final FloatgetHeight()final UnitsetHeight(Float height)final BooleangetExists()This flag controls weather this drawable exists, meaning if it accepts events and renders. final UnitsetExists(Boolean exists)This flag controls weather this drawable exists, meaning if it accepts events and renders. final FloatgetTrueX()true X value (i.e. final UnitsetTrueX(Float trueX)true X value (i.e. final FloatgetTrueY()true Y value (i.e. final UnitsetTrueY(Float trueY)true Y value (i.e. final Unit.TypegetAtType()final Unit.TypegetSizeType()final BooleanisDynamic()final DoublegetRotation()current rotation of this drawable (radians). final UnitsetRotation(Double rotation)current rotation of this drawable (radians). final DoublegetSkewX()current skew in x dimension of this drawable (radians). final UnitsetSkewX(Double skewX)current skew in x dimension of this drawable (radians). final DoublegetSkewY()current skew in y dimension of this drawable (radians). final UnitsetSkewY(Double skewY)current skew in y dimension of this drawable (radians). final FloatgetScaleX()current scale in x dimension of this drawable. final UnitsetScaleX(Float scaleX)current scale in x dimension of this drawable. final FloatgetScaleY()current scale in y dimension of this drawable. final UnitsetScaleY(Float scaleY)current scale in y dimension of this drawable. final FloatgetAlpha()The alpha value of this drawable. final UnitsetAlpha(Float alpha)The alpha value of this drawable. final FloatgetAcx()at cache x for transformations. final UnitsetAcx(@ApiStatus.Internal() Float acx)at cache x for transformations. final FloatgetAcy()at cache y for transformations. final UnitsetAcy(@ApiStatus.Internal() Float acy)at cache y for transformations. Vec2<Unit>getAt()position relative to the parents position. final BooleangetRawResize()This property controls weather this drawable resizes "raw", meaning it will not respect the aspect ratio. FloattrueX()Calculate the true X value (i.e. FloattrueY()Calculate the true Y value (i.e. UnitpreRender(Long deltaTimeNanos)pre-render functions, such as applying transforms. abstract Unitrender()draw script for this drawable. UnitpostRender()Called after rendering, for functions such as removing transformations. abstract UnitcalculateBounds()Calculate the position and size of this drawable. Unitrescale(Float scaleX, Float scaleY)Method that is called when the physical size of the total window area changes. BooleancanBeRemoved()function that should return true if it is ready to be removed from its parent. UnitdebugRender()add a debug render overlay for this drawable. Booleanaccept(Event event)called when this drawable receives an event. final <E extends Event, S extends Drawable> UnitaddEventHandler(S $self, E event, Function2<S, E, Boolean> handler)final <E extends Event, S extends Drawable> UnitaddEventhandler(S $self, E event, Function2<S, E, Unit> handler)final <S extends Drawable> Unitevents(S $self, Function1<EventDSL<S>, Unit> dsl)Unitreset()Use this function to reset your drawable's PolyText if it is using one. Unitsetup(Renderer renderer, PolyUI polyUI)give this a renderer reference and a PolyUI reference. UnitdebugPrint()debug print for this drawable. UnitonInitComplete()This function is called when initialization of a drawable is complete, so it has been fully calculated. UnitonParentInitComplete()This function is called when initialization of this parent is complete. BooleanisInside(Float x, Float y)BooleanisInside(Float x, Float y, Float width, Float height)Booleanintersects(Float x, Float y, Float width, Float height)final UnitdoDynamicSize()final LayoutgetContainingLayout()Return the layout of the highest order (the one inside the master layout) that contains this drawable. Drawableclone()Implement this function to enable cloning of your Drawable. Vec2<Unit>calculateSize()Implement this function to return the size of this drawable, if no size is specified during construction. abstract UnitonColorsChanged(Colors colors)Function that is called when the colors attached to this drawable change. abstract UnitonFontsChanged(FontFamily fonts)Function that is called when the fonts attached to this drawable change. UnitaddOperation(DrawableOp drawableOp, Function1<Drawable, Unit> onFinish)Add a DrawableOp to this drawable. final UnitremoveOperation(DrawableOp drawableOp)Remove an operation from this drawable. final UnitscaleBy(Float xFactor, Float yFactor, Animation.Type animation, Long durationNanos, Function1<Drawable, Unit> onFinish)Scale this drawable by the given amount, in the X and Y dimensions. final UnitscaleTo(Float xFactor, Float yFactor, Animation.Type animation, Long durationNanos, Function1<Drawable, Unit> onFinish)Scale this drawable to the given amount, in the X and Y dimensions. final UnitrotateTo(Double degrees, Animation.Type animation, Long durationNanos, Function1<Drawable, Unit> onFinish)Rotate this drawable to the given amount, in degrees. final UnitrotateBy(Double degrees, Animation.Type animation, Long durationNanos, Function1<Drawable, Unit> onFinish)Rotate this drawable by the given amount, in degrees. final UnitskewTo(Double skewX, Double skewY, Animation.Type animation, Long durationNanos)Skew this drawable to the given amount, in degrees. final UnitskewBy(Double skewX, Double skewY, Animation.Type animation, Long durationNanos)Skew this drawable by the given amount, in degrees. final UnitmoveTo(Vec2<Unit> to, Animation.Type animation, Long durationNanos, Function1<Drawable, Unit> onFinish)move this drawable to the provided point. final UnitmoveBy(Vec2<Unit> by, Animation.Type animation, Long durationNanos, Function1<Drawable, Unit> onFinish)move this drawable by the given amount. final UnitfadeTo(Float alpha, Animation.Type animation, Long durationNanos, Function1<Drawable, Unit> onFinish)Fade this drawable to the given alpha. final UnitfadeBy(Float alpha, Animation.Type animation, Long durationNanos, Function1<Drawable, Unit> onFinish)Fade this drawable by the given amount. final UnitanimateTo(Vec2<Unit> to, Vec2<Unit> size, Double degrees, Float scaleX, Float scaleY, Double skewX, Double skewY, Animation.Type animation, Long durationNanos)Bulk-add drawable operations to this drawable. final UnitanimateBy(Vec2<Unit> to, Vec2<Unit> size, Double degrees, Float scaleX, Float scaleY, Double skewX, Double skewY, Animation.Type animation, Long durationNanos)Bulk-add drawable operations to this drawable. final Unitresize(Vec2<Unit> toSize, Animation.Type animation, Long durationNanos, Function1<Drawable, Unit> onFinish)resize this drawable to the given size. -
-
Method Detail
-
getSimpleName
String getSimpleName()
This is the name of this drawable, and it will be consistent over reboots of the program, so you can use it to get drawables from a layout by ID, e.g:
val text = myLayout["Text@4cf777e8"] as Text
-
setSimpleName
Unit setSimpleName(String simpleName)
This is the name of this drawable, and it will be consistent over reboots of the program, so you can use it to get drawables from a layout by ID, e.g:
val text = myLayout["Text@4cf777e8"] as Text
-
getRenderer
final Renderer getRenderer()
-
setRenderer
final Unit setRenderer(Renderer renderer)
-
getAcceptsInput
final Boolean getAcceptsInput()
-
setAcceptsInput
final Unit setAcceptsInput(Boolean acceptsInput)
-
getInitStage
final Byte getInitStage()
This is the initialization stage of this drawable.
-
getMouseOver
final Boolean getMouseOver()
weather or not the mouse is currently over this drawable.
DO NOT modify this value. It is managed automatically by org.polyfrost.polyui.event.EventManager. Changing this directly will not cause you to receive events.
-
getRenders
Boolean getRenders()
-
setRenders
Unit setRenders(Boolean renders)
weather or not this drawable should be rendered.
This is controlled by Layout.clipDrawables to save resources by not drawing drawables which cannot be seen.
It is only respected by Layout by default. This means that if you are calling render yourself (which you really shouldn't), you should check this value.
-
getLayout
abstract Layout getLayout()
Reference to the layout encapsulating this drawable. For components, this is never null, but for layout, it can be null (meaning its parent is the polyui).
In pretty much every situation it is safe to
!!this, as any layout you create will have parent of PolyUI.master. If you are doingthis.layout.layoutor deeper, you should null-check.
-
getConsumesHover
abstract Boolean getConsumesHover()
If this is
true, the drawable will be the only drawable that is allowed to be hovered at once.There are essentially two modes for hovering in PolyUI, and by default, components are in the "normal" (
false) mode, where only one of them can be hovered as once as would be expected, but layouts are in the "group" (true) mode, so will still receive the events even if another drawable is hovered, for example scrolling.
-
setConsumesHover
abstract Unit setConsumesHover(Boolean consumesHover)
If this is
true, the drawable will be the only drawable that is allowed to be hovered at once.There are essentially two modes for hovering in PolyUI, and by default, components are in the "normal" (
false) mode, where only one of them can be hovered as once as would be expected, but layouts are in the "group" (true) mode, so will still receive the events even if another drawable is hovered, for example scrolling.
-
getExists
final Boolean getExists()
This flag controls weather this drawable exists, meaning if it accepts events and renders.
Additionally:
In layouts, they will display as empty (no drawables) if this is false.
In components, they will be excluded from calculations.
-
setExists
final Unit setExists(Boolean exists)
This flag controls weather this drawable exists, meaning if it accepts events and renders.
Additionally:
In layouts, they will display as empty (no drawables) if this is false.
In components, they will be excluded from calculations.
-
getSizeType
final Unit.Type getSizeType()
-
getRotation
final Double getRotation()
current rotation of this drawable (radians).
-
setRotation
final Unit setRotation(Double rotation)
current rotation of this drawable (radians).
-
getRawResize
final Boolean getRawResize()
This property controls weather this drawable resizes "raw", meaning it will not respect the aspect ratio.
By default, it is
false, so when resized, the smallest increase is used for both width and height. This means that it will stay at the same aspect ratio.
-
trueX
Float trueX()
Calculate the true X value (i.e. not relative to the layout)
This method will NOT assign the value to the trueX field.
-
trueY
Float trueY()
Calculate the true Y value (i.e. not relative to the layout)
This method will NOT assign the value to the trueY field.
-
preRender
@MustBeInvokedByOverriders() Unit preRender(Long deltaTimeNanos)
pre-render functions, such as applying transforms. In this method, you should set needsRedraw to true if you have something to redraw for the next frame.
- Parameters:
deltaTimeNanos- the time in nanoseconds since the last frame.
-
postRender
Unit postRender()
Called after rendering, for functions such as removing transformations.
make sure to call super Drawable.postRender!
-
calculateBounds
abstract Unit calculateBounds()
Calculate the position and size of this drawable. Make sure to call doDynamicSize in this method to avoid issues with sizing.
This method is called once the layout is populated for children and component, and when a recalculation is requested.
The value of layout's bounds will be updated after this method is called, so do not use layout's bounds as an updated value in this method.
-
rescale
Unit rescale(Float scaleX, Float scaleY)
Method that is called when the physical size of the total window area changes.
-
canBeRemoved
Boolean canBeRemoved()
function that should return true if it is ready to be removed from its parent.
This is used for drawables that need to wait for an animation to finish before being removed.
-
debugRender
Unit debugRender()
add a debug render overlay for this drawable. This is always rendered regardless of the layout re-rendering if debug mode is on.
-
accept
@MustBeInvokedByOverriders() Boolean accept(Event event)
called when this drawable receives an event.
make sure to call super.accept()!
-
addEventHandler
final <E extends Event, S extends Drawable> Unit addEventHandler(S $self, E event, Function2<S, E, Boolean> handler)
-
addEventhandler
final <E extends Event, S extends Drawable> Unit addEventhandler(S $self, E event, Function2<S, E, Unit> handler)
-
setup
Unit setup(Renderer renderer, PolyUI polyUI)
give this a renderer reference and a PolyUI reference.
You can also use this method to do some calculations (such as text widths) that are not dependent on other sizes.
If you need a method that has access to component's sizes, see here or here (if you are operating on yourself only).
this method is called once, and only once.
-
debugPrint
Unit debugPrint()
debug print for this drawable.
-
onInitComplete
Unit onInitComplete()
This function is called when initialization of a drawable is complete, so it has been fully calculated.
This function is called once, and only once.
-
onParentInitComplete
Unit onParentInitComplete()
This function is called when initialization of this parent is complete.
This function is called once, and only once.
-
doDynamicSize
final Unit doDynamicSize()
-
getContainingLayout
final Layout getContainingLayout()
Return the layout of the highest order (the one inside the master layout) that contains this drawable.
If this is the master layout, it is returned.
-
clone
Drawable clone()
Implement this function to enable cloning of your Drawable.
If this function is not implemented, attempts to clone the drawable will not compile due to type erasure, but if this is ignored a CloneNotSupportedException will be thrown.
-
calculateSize
Vec2<Unit> calculateSize()
Implement this function to return the size of this drawable, if no size is specified during construction.
This should be so that if the drawable can determine its own size (for example, it is an image), then the size parameter in the constructor can be omitted using:
size: Vec2<org.polyfrost.polyui.unit.Unit>? = null;and this method needs to be implemented!Otherwise, the size parameter in the constructor must be specified.
-
onColorsChanged
@MustBeInvokedByOverriders() abstract Unit onColorsChanged(Colors colors)
Function that is called when the colors attached to this drawable change.
If this is a layout, the colors will change, and all its children and components will be notified and updated accordingly.
Make sure to call super.onColorsChanged() if you override this!
-
onFontsChanged
@MustBeInvokedByOverriders() abstract Unit onFontsChanged(FontFamily fonts)
Function that is called when the fonts attached to this drawable change.
If this is a layout, the fonts will change, and all its children and components will be notified and updated accordingly.
Make sure to call super.onFontsChanged() if you override this!
-
addOperation
Unit addOperation(DrawableOp drawableOp, Function1<Drawable, Unit> onFinish)
Add a DrawableOp to this drawable.
-
removeOperation
final Unit removeOperation(DrawableOp drawableOp)
Remove an operation from this drawable.
-
scaleBy
final Unit scaleBy(Float xFactor, Float yFactor, Animation.Type animation, Long durationNanos, Function1<Drawable, Unit> onFinish)
Scale this drawable by the given amount, in the X and Y dimensions.
Please note that this ignores all bounds, and will simply scale this drawable, meaning that it can be clipped by its layout, and overlap nearby drawable.
-
scaleTo
final Unit scaleTo(Float xFactor, Float yFactor, Animation.Type animation, Long durationNanos, Function1<Drawable, Unit> onFinish)
Scale this drawable to the given amount, in the X and Y dimensions.
Please note that this ignores all bounds, and will simply scale this drawable, meaning that it can be clipped by its layout, and overlap nearby drawable.
-
rotateTo
final Unit rotateTo(Double degrees, Animation.Type animation, Long durationNanos, Function1<Drawable, Unit> onFinish)
Rotate this drawable to the given amount, in degrees. The amount is MOD 360 to return a value between 0-360 always.
Please note that this ignores all bounds, and will simply scale this drawable, meaning that it can be clipped by its layout, and overlap nearby drawable.
-
rotateBy
final Unit rotateBy(Double degrees, Animation.Type animation, Long durationNanos, Function1<Drawable, Unit> onFinish)
Rotate this drawable by the given amount, in degrees.
Please note that this ignores all bounds, and will simply scale this drawable, meaning that it can be clipped by its layout, and overlap nearby drawable.
-
skewTo
final Unit skewTo(Double skewX, Double skewY, Animation.Type animation, Long durationNanos)
Skew this drawable to the given amount, in degrees.
Please note that this ignores all bounds, and will simply scale this drawable, meaning that it can be clipped by its layout, and overlap nearby drawable.
-
skewBy
final Unit skewBy(Double skewX, Double skewY, Animation.Type animation, Long durationNanos)
Skew this drawable by the given amount, in degrees.
Please note that this ignores all bounds, and will simply scale this drawable, meaning that it can be clipped by its layout, and overlap nearby drawable.
-
moveTo
final Unit moveTo(Vec2<Unit> to, Animation.Type animation, Long durationNanos, Function1<Drawable, Unit> onFinish)
move this drawable to the provided point.
Please note that this ignores all bounds, and will simply scale this drawable, meaning that it can be clipped by its layout, and overlap nearby drawable.
-
moveBy
final Unit moveBy(Vec2<Unit> by, Animation.Type animation, Long durationNanos, Function1<Drawable, Unit> onFinish)
move this drawable by the given amount.
Please note that this ignores all bounds, and will simply scale this drawable, meaning that it can be clipped by its layout, and overlap nearby drawable.
-
fadeTo
final Unit fadeTo(Float alpha, Animation.Type animation, Long durationNanos, Function1<Drawable, Unit> onFinish)
Fade this drawable to the given alpha.
-
fadeBy
final Unit fadeBy(Float alpha, Animation.Type animation, Long durationNanos, Function1<Drawable, Unit> onFinish)
Fade this drawable by the given amount.
-
animateTo
final Unit animateTo(Vec2<Unit> to, Vec2<Unit> size, Double degrees, Float scaleX, Float scaleY, Double skewX, Double skewY, Animation.Type animation, Long durationNanos)
Bulk-add drawable operations to this drawable.
-
animateBy
final Unit animateBy(Vec2<Unit> to, Vec2<Unit> size, Double degrees, Float scaleX, Float scaleY, Double skewX, Double skewY, Animation.Type animation, Long durationNanos)
Bulk-add drawable operations to this drawable.
-
-
-
-