You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
1.6 KiB
99 lines
1.6 KiB
package mightypork.gamecore.gui.components;
|
|
|
|
|
|
import mightypork.gamecore.control.bus.events.LayoutChangeEvent;
|
|
import mightypork.utils.annotations.DefaultImpl;
|
|
import mightypork.utils.math.constraints.rect.Rect;
|
|
import mightypork.utils.math.constraints.rect.caching.AbstractRectCache;
|
|
import mightypork.utils.math.constraints.rect.proxy.RectBound;
|
|
import mightypork.utils.math.constraints.rect.proxy.RectBoundAdapter;
|
|
|
|
|
|
/**
|
|
* {@link Renderable} with pluggable context. When caching is enabled, the
|
|
* layout update can be triggered by firing the {@link LayoutChangeEvent}.
|
|
*
|
|
* @author MightyPork
|
|
*/
|
|
public abstract class VisualComponent extends AbstractRectCache implements Component, LayoutChangeEvent.Listener {
|
|
|
|
private Rect source;
|
|
private boolean visible = true;
|
|
|
|
|
|
public VisualComponent() {
|
|
super();
|
|
enableCaching(false);
|
|
}
|
|
|
|
|
|
@Override
|
|
public final Rect getRect()
|
|
{
|
|
return super.getRect();
|
|
}
|
|
|
|
|
|
@Override
|
|
public final void setRect(RectBound rect)
|
|
{
|
|
this.source = new RectBoundAdapter(rect);
|
|
}
|
|
|
|
|
|
@Override
|
|
public final boolean isVisible()
|
|
{
|
|
return visible;
|
|
}
|
|
|
|
|
|
@Override
|
|
public final void setVisible(boolean visible)
|
|
{
|
|
this.visible = visible;
|
|
}
|
|
|
|
|
|
@Override
|
|
public final Rect getCacheSource()
|
|
{
|
|
return source;
|
|
}
|
|
|
|
|
|
@Override
|
|
public final void render()
|
|
{
|
|
if (!visible) return;
|
|
|
|
renderComponent();
|
|
}
|
|
|
|
|
|
@Override
|
|
public final void onLayoutChanged()
|
|
{
|
|
poll();
|
|
}
|
|
|
|
|
|
@Override
|
|
public final void onChange()
|
|
{
|
|
updateLayout();
|
|
}
|
|
|
|
|
|
/**
|
|
* Draw the component (it's visible)
|
|
*/
|
|
protected abstract void renderComponent();
|
|
|
|
|
|
@Override
|
|
@DefaultImpl
|
|
public void updateLayout()
|
|
{
|
|
}
|
|
}
|
|
|