parent
							
								
									086a630fb9
								
							
						
					
					
						commit
						7ee201a6f7
					
				@ -0,0 +1,92 @@ | 
				
			|||||||
 | 
					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 | 
				
			||||||
 | 
					 *  | 
				
			||||||
 | 
					 * @author MightyPork | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					public abstract class AbstractVisualComponent extends AbstractRectCache implements Component, LayoutChangeEvent.Listener { | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						private Rect source; | 
				
			||||||
 | 
						private boolean visible = true; | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@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) | 
				
			||||||
 | 
						 */ | 
				
			||||||
 | 
						public abstract void renderComponent(); | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						@DefaultImpl | 
				
			||||||
 | 
						public void updateLayout() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,11 @@ | 
				
			|||||||
 | 
					package mightypork.gamecore.gui.components; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.gamecore.control.bus.clients.ToggleableClient; | 
				
			||||||
 | 
					import mightypork.gamecore.control.interf.Enableable; | 
				
			||||||
 | 
					import mightypork.gamecore.gui.ActionTrigger; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public interface InputComponent extends Component, Enableable, ActionTrigger, ToggleableClient { | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,9 @@ | 
				
			|||||||
 | 
					package mightypork.gamecore.gui.components; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.gamecore.control.bus.clients.ClientHub; | 
				
			||||||
 | 
					import mightypork.gamecore.control.interf.Enableable; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public interface LayoutComponent extends Component, Enableable, ClientHub { | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
					} | 
				
			||||||
@ -1,55 +0,0 @@ | 
				
			|||||||
package mightypork.gamecore.gui.components; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import mightypork.utils.annotations.DefaultImpl; | 
					 | 
				
			||||||
import mightypork.utils.math.constraints.rect.*; | 
					 | 
				
			||||||
import mightypork.utils.math.constraints.rect.caching.AbstractRectCache; | 
					 | 
				
			||||||
import mightypork.utils.math.constraints.rect.caching.RectCache; | 
					 | 
				
			||||||
import mightypork.utils.math.constraints.rect.proxy.RectBound; | 
					 | 
				
			||||||
import mightypork.utils.math.constraints.rect.proxy.RectBoundAdapter; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/** | 
					 | 
				
			||||||
 * {@link Renderable} with pluggable context | 
					 | 
				
			||||||
 *  | 
					 | 
				
			||||||
 * @author MightyPork | 
					 | 
				
			||||||
 */ | 
					 | 
				
			||||||
public abstract class SimplePainter extends AbstractRectCache implements PluggableRenderable { | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	private RectCache source; | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public Rect getRect() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return super.getRect(); | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public void setRect(RectBound rect) | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		this.source = new RectBoundAdapter(rect).cached(); | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public Rect getCacheSource() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return source; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public abstract void render(); | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	/** | 
					 | 
				
			||||||
	 * Called after constraint was changed; contained constraints can now poll too. | 
					 | 
				
			||||||
	 */ | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	@DefaultImpl | 
					 | 
				
			||||||
	public void onChange() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
} | 
					 | 
				
			||||||
@ -1,75 +0,0 @@ | 
				
			|||||||
package mightypork.gamecore.gui.components.layout; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.util.LinkedList; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import mightypork.gamecore.control.AppAccess; | 
					 | 
				
			||||||
import mightypork.gamecore.control.bus.EventBus; | 
					 | 
				
			||||||
import mightypork.gamecore.gui.components.BusEnabledPainter; | 
					 | 
				
			||||||
import mightypork.gamecore.gui.components.PluggableRenderable; | 
					 | 
				
			||||||
import mightypork.gamecore.gui.components.Renderable; | 
					 | 
				
			||||||
import mightypork.gamecore.gui.components.SimplePainter; | 
					 | 
				
			||||||
import mightypork.utils.math.constraints.rect.proxy.RectBound; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/** | 
					 | 
				
			||||||
 * Bag for {@link SimplePainter} elements with constraints.<br> | 
					 | 
				
			||||||
 * Elements are exposed to {@link EventBus}. | 
					 | 
				
			||||||
 *  | 
					 | 
				
			||||||
 * @author MightyPork | 
					 | 
				
			||||||
 */ | 
					 | 
				
			||||||
public abstract class AbstractLayout extends BusEnabledPainter { | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	final LinkedList<PluggableRenderable> elements = new LinkedList<>(); | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	/** | 
					 | 
				
			||||||
	 * @param app app access | 
					 | 
				
			||||||
	 */ | 
					 | 
				
			||||||
	public AbstractLayout(AppAccess app) { | 
					 | 
				
			||||||
		super(app); | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	/** | 
					 | 
				
			||||||
	 * @param app app access | 
					 | 
				
			||||||
	 * @param context boudning context | 
					 | 
				
			||||||
	 */ | 
					 | 
				
			||||||
	public AbstractLayout(AppAccess app, RectBound context) { | 
					 | 
				
			||||||
		super(app); | 
					 | 
				
			||||||
		setRect(context); | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	/** | 
					 | 
				
			||||||
	 * Add element to the holder, setting it's context.<br> | 
					 | 
				
			||||||
	 * Element must then be attached using the <code>attach</code> method. | 
					 | 
				
			||||||
	 *  | 
					 | 
				
			||||||
	 * @param elem element | 
					 | 
				
			||||||
	 */ | 
					 | 
				
			||||||
	public abstract void add(PluggableRenderable elem); | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	/** | 
					 | 
				
			||||||
	 * Connect to bus and add to element list | 
					 | 
				
			||||||
	 *  | 
					 | 
				
			||||||
	 * @param elem element; it's context will be set to the constraint. | 
					 | 
				
			||||||
	 */ | 
					 | 
				
			||||||
	public void attach(PluggableRenderable elem) | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		if (elem == null) return; | 
					 | 
				
			||||||
		 | 
					 | 
				
			||||||
		elements.add(elem); | 
					 | 
				
			||||||
		addChildClient(elem); | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public void paint() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		for (final Renderable element : elements) { | 
					 | 
				
			||||||
			element.render(); | 
					 | 
				
			||||||
		} | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
} | 
					 | 
				
			||||||
					Loading…
					
					
				
		Reference in new issue