Versatile Java game engine with pluggable backends (this was used in Rogue, I think)
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.
gamecore/src/mightypork/gamecore/gui/components/layout/linear/AbstractLinearWrapper.java

79 lines
1.5 KiB

package mightypork.gamecore.gui.components.layout.linear;
import java.util.Collection;
import mightypork.gamecore.gui.components.Component;
import mightypork.gamecore.gui.components.LinearComponent;
import mightypork.utils.eventbus.clients.ClientList;
import mightypork.utils.eventbus.clients.DelegatingClient;
/**
* Converts a component into a linear component
*
* @author Ondřej Hruška (MightyPork)
*/
public abstract class AbstractLinearWrapper extends LinearComponent implements DelegatingClient {
protected final Component wrapped;
private final ClientList list;
/**
* @param wrapped wrapped component. Can be null.
*/
public AbstractLinearWrapper(Component wrapped)
{
this.wrapped = wrapped;
if (wrapped != null) {
if (wrapped instanceof LinearComponent) {
((LinearComponent) wrapped).setHeight(height());
((LinearComponent) wrapped).setOrigin(origin());
} else {
wrapped.setRect(this);
}
}
list = new ClientList(wrapped);
}
@Override
protected void renderComponent()
{
if (wrapped != null) wrapped.render();
}
@Override
public Collection<?> getChildClients()
{
return list;
}
@Override
public boolean doesDelegate()
{
return true;
}
@Override
public void setEnabled(boolean yes)
{
if (yes != super.isDirectlyEnabled()) {
super.setEnabled(yes);
wrapped.setIndirectlyEnabled(yes);
}
}
@Override
public void setIndirectlyEnabled(boolean yes)
{
super.setIndirectlyEnabled(yes);
wrapped.setIndirectlyEnabled(yes);
}
}