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.
106 lines
2.0 KiB
106 lines
2.0 KiB
11 years ago
|
package mightypork.rogue.gui.constraints;
|
||
11 years ago
|
|
||
|
|
||
|
import java.util.LinkedList;
|
||
|
|
||
|
import mightypork.rogue.AppAccess;
|
||
|
import mightypork.rogue.bus.ChildClient;
|
||
11 years ago
|
import mightypork.utils.control.bus.EventBus;
|
||
11 years ago
|
import mightypork.utils.math.constraints.ConstraintContext;
|
||
|
import mightypork.utils.math.constraints.RectConstraint;
|
||
11 years ago
|
import mightypork.utils.math.coord.Rect;
|
||
|
|
||
|
|
||
11 years ago
|
/**
|
||
|
* Bag for {@link RenderableWithContext} elements with constraints.<br>
|
||
|
* Elements are exposed to {@link EventBus}.
|
||
|
*
|
||
|
* @author MightyPork
|
||
|
*/
|
||
11 years ago
|
public class ElementHolder extends ChildClient implements ConstraintContext, RenderableWithContext {
|
||
11 years ago
|
|
||
11 years ago
|
private LinkedList<RenderableWithContext> elements = new LinkedList<RenderableWithContext>();
|
||
|
private ConstraintContext context;
|
||
11 years ago
|
|
||
|
|
||
|
public ElementHolder(AppAccess app) {
|
||
|
super(app);
|
||
|
}
|
||
|
|
||
|
|
||
11 years ago
|
public ElementHolder(AppAccess app, ConstraintContext context) {
|
||
11 years ago
|
super(app);
|
||
|
this.context = context;
|
||
|
}
|
||
|
|
||
|
|
||
|
@Override
|
||
11 years ago
|
public void setContext(ConstraintContext context)
|
||
11 years ago
|
{
|
||
|
this.context = context;
|
||
|
}
|
||
|
|
||
|
|
||
11 years ago
|
@Override
|
||
|
public void render()
|
||
|
{
|
||
|
for (Renderable element : elements) {
|
||
|
element.render();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
@Override
|
||
|
public Rect getRect()
|
||
|
{
|
||
|
return context.getRect();
|
||
|
}
|
||
|
|
||
|
|
||
11 years ago
|
/**
|
||
|
* Add element to the holder.
|
||
|
*
|
||
|
* @param elem
|
||
|
*/
|
||
11 years ago
|
public void add(RenderableWithContext elem)
|
||
11 years ago
|
{
|
||
|
if (elem == null) return;
|
||
|
elem.setContext(this);
|
||
|
elements.add(elem);
|
||
|
addChildClient(elem);
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Add element to the holder.
|
||
|
*
|
||
11 years ago
|
* @param elem element; it's context will be set to the constraint.
|
||
|
* @param constraint Constraint to be used for the element. It's context
|
||
|
* will be set to this {@link ElementHolder}
|
||
11 years ago
|
*/
|
||
11 years ago
|
public void add(RenderableWithContext elem, RectConstraint constraint)
|
||
11 years ago
|
{
|
||
|
if (elem == null) return;
|
||
|
|
||
|
constraint.setContext(this);
|
||
|
elem.setContext(constraint);
|
||
|
|
||
|
elements.add(elem);
|
||
|
addChildClient(elem);
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Remove element from the holder
|
||
|
*
|
||
|
* @param elem
|
||
|
*/
|
||
11 years ago
|
public void remove(RenderableWithContext elem)
|
||
11 years ago
|
{
|
||
|
if (elem == null) return;
|
||
|
elements.remove(elem);
|
||
|
removeChildClient(elem);
|
||
|
}
|
||
|
|
||
|
}
|