parent
7ee201a6f7
commit
3cad5ad202
@ -1,160 +0,0 @@ |
||||
package mightypork.gamecore.gui.components; |
||||
|
||||
|
||||
import java.util.Collection; |
||||
import java.util.LinkedList; |
||||
|
||||
import mightypork.gamecore.audio.SoundSystem; |
||||
import mightypork.gamecore.control.AppAccess; |
||||
import mightypork.gamecore.control.AppSubModule; |
||||
import mightypork.gamecore.control.bus.EventBus; |
||||
import mightypork.gamecore.input.InputSystem; |
||||
import mightypork.gamecore.render.DisplaySystem; |
||||
import mightypork.utils.math.constraints.rect.proxy.RectBound; |
||||
|
||||
|
||||
public abstract class AbstractLayoutComponent extends AbstractVisualComponent implements LayoutComponent, AppAccess { |
||||
|
||||
private boolean enabled; |
||||
|
||||
private final AppSubModule subModule; |
||||
final LinkedList<Component> elements = new LinkedList<>(); |
||||
|
||||
|
||||
public AbstractLayoutComponent(AppAccess app, RectBound context) { |
||||
this.subModule = new AppSubModule(app); |
||||
setRect(context); |
||||
} |
||||
|
||||
|
||||
public AbstractLayoutComponent(AppAccess app) { |
||||
this(app, null); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public EventBus getEventBus() |
||||
{ |
||||
return subModule.getEventBus(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public Collection<Object> getChildClients() |
||||
{ |
||||
return subModule.getChildClients(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public boolean doesDelegate() |
||||
{ |
||||
return subModule.doesDelegate(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public boolean isListening() |
||||
{ |
||||
return subModule.isListening(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public SoundSystem getSoundSystem() |
||||
{ |
||||
return subModule.getSoundSystem(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public InputSystem getInput() |
||||
{ |
||||
return subModule.getInput(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public DisplaySystem getDisplay() |
||||
{ |
||||
return subModule.getDisplay(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void shutdown() |
||||
{ |
||||
subModule.shutdown(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void addChildClient(Object client) |
||||
{ |
||||
subModule.addChildClient(client); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void removeChildClient(Object client) |
||||
{ |
||||
subModule.removeChildClient(client); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void enable(boolean yes) |
||||
{ |
||||
subModule.setDelegating(yes); |
||||
subModule.setListening(yes); |
||||
enabled = yes; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public boolean isEnabled() |
||||
{ |
||||
return enabled; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Add element to the holder, setting it's context.<br> |
||||
* Element must then be then attached using the <code>attach</code> method. |
||||
* |
||||
* @param elem element |
||||
*/ |
||||
public abstract void add(Component elem); |
||||
|
||||
|
||||
/** |
||||
* Connect to bus and add to element list |
||||
* |
||||
* @param elem element; it's context will be set to the constraint. |
||||
*/ |
||||
public final void attach(Component elem) |
||||
{ |
||||
if (elem == null) return; |
||||
|
||||
elements.add(elem); |
||||
addChildClient(elem); |
||||
} |
||||
|
||||
@Override |
||||
public void renderComponent() |
||||
{ |
||||
for (final Component element : elements) { |
||||
element.render(); |
||||
} |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void updateLayout() |
||||
{ |
||||
for (final Component element : elements) { |
||||
element.render(); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,30 @@ |
||||
package mightypork.gamecore.gui.components; |
||||
|
||||
|
||||
import mightypork.gamecore.control.bus.events.MouseButtonEvent; |
||||
|
||||
|
||||
public abstract class ClickableComponent extends InputComponent { |
||||
|
||||
private boolean btnDownOver; |
||||
|
||||
|
||||
@Override |
||||
public void receive(MouseButtonEvent event) |
||||
{ |
||||
if (!event.isButtonEvent()) return; |
||||
|
||||
if (event.isDown()) { |
||||
btnDownOver = event.isOver(this); |
||||
} |
||||
|
||||
if (event.isUp()) { |
||||
|
||||
if (btnDownOver && event.isOver(this)) { |
||||
triggerAction(); |
||||
} |
||||
|
||||
btnDownOver = false; |
||||
} |
||||
} |
||||
} |
@ -1,11 +1,43 @@ |
||||
package mightypork.gamecore.gui.components; |
||||
|
||||
|
||||
import mightypork.gamecore.control.bus.clients.ToggleableClient; |
||||
import mightypork.gamecore.control.bus.events.MouseButtonEvent; |
||||
import mightypork.gamecore.control.interf.Enableable; |
||||
import mightypork.gamecore.gui.Action; |
||||
import mightypork.gamecore.gui.ActionTrigger; |
||||
|
||||
|
||||
public interface InputComponent extends Component, Enableable, ActionTrigger, ToggleableClient { |
||||
public abstract class InputComponent extends VisualComponent implements Component, Enableable, ActionTrigger, MouseButtonEvent.Listener { |
||||
|
||||
private boolean enabled; |
||||
private Action action; |
||||
|
||||
|
||||
@Override |
||||
public void setAction(Action action) |
||||
{ |
||||
this.action = action; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void enable(boolean yes) |
||||
{ |
||||
this.enabled = yes; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public boolean isEnabled() |
||||
{ |
||||
return enabled; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public abstract void renderComponent(); |
||||
|
||||
protected void triggerAction() { |
||||
action.run(); |
||||
} |
||||
} |
||||
|
@ -1,9 +1,154 @@ |
||||
package mightypork.gamecore.gui.components; |
||||
|
||||
|
||||
import java.util.Collection; |
||||
import java.util.LinkedList; |
||||
|
||||
import mightypork.gamecore.audio.SoundSystem; |
||||
import mightypork.gamecore.control.AppAccess; |
||||
import mightypork.gamecore.control.AppSubModule; |
||||
import mightypork.gamecore.control.bus.EventBus; |
||||
import mightypork.gamecore.control.bus.clients.ClientHub; |
||||
import mightypork.gamecore.control.interf.Enableable; |
||||
import mightypork.gamecore.input.InputSystem; |
||||
import mightypork.gamecore.render.DisplaySystem; |
||||
import mightypork.utils.math.constraints.rect.proxy.RectBound; |
||||
|
||||
|
||||
public abstract class LayoutComponent extends VisualComponent implements Component, Enableable, ClientHub, AppAccess { |
||||
|
||||
private boolean enabled; |
||||
|
||||
private final AppSubModule subModule; |
||||
final LinkedList<Component> components = new LinkedList<>(); |
||||
|
||||
|
||||
public LayoutComponent(AppAccess app, RectBound context) { |
||||
this.subModule = new AppSubModule(app); |
||||
setRect(context); |
||||
} |
||||
|
||||
|
||||
public LayoutComponent(AppAccess app) { |
||||
this(app, null); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public EventBus getEventBus() |
||||
{ |
||||
return subModule.getEventBus(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public Collection<Object> getChildClients() |
||||
{ |
||||
return subModule.getChildClients(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public boolean doesDelegate() |
||||
{ |
||||
return subModule.doesDelegate(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public boolean isListening() |
||||
{ |
||||
return subModule.isListening(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public SoundSystem getSoundSystem() |
||||
{ |
||||
return subModule.getSoundSystem(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public InputSystem getInput() |
||||
{ |
||||
return subModule.getInput(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public DisplaySystem getDisplay() |
||||
{ |
||||
return subModule.getDisplay(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void shutdown() |
||||
{ |
||||
subModule.shutdown(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void addChildClient(Object client) |
||||
{ |
||||
subModule.addChildClient(client); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void removeChildClient(Object client) |
||||
{ |
||||
subModule.removeChildClient(client); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void enable(boolean yes) |
||||
{ |
||||
subModule.setDelegating(yes); |
||||
subModule.setListening(yes); |
||||
enabled = yes; |
||||
} |
||||
|
||||
public interface LayoutComponent extends Component, Enableable, ClientHub { |
||||
|
||||
@Override |
||||
public boolean isEnabled() |
||||
{ |
||||
return enabled; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Connect to bus and add to element list |
||||
* |
||||
* @param component added component, whose context has already been set. |
||||
*/ |
||||
public final void attach(Component component) |
||||
{ |
||||
if (component == null) return; |
||||
|
||||
components.add(component); |
||||
addChildClient(component); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void renderComponent() |
||||
{ |
||||
for (final Component cmp : components) { |
||||
cmp.render(); |
||||
} |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void updateLayout() |
||||
{ |
||||
for (final Component cmp : components) { |
||||
cmp.updateLayout(); |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
@ -0,0 +1,38 @@ |
||||
package mightypork.gamecore.gui.components.layout; |
||||
|
||||
|
||||
import mightypork.gamecore.control.AppAccess; |
||||
import mightypork.gamecore.gui.components.LayoutComponent; |
||||
import mightypork.gamecore.gui.components.Component; |
||||
import mightypork.utils.math.constraints.rect.proxy.RectBound; |
||||
|
||||
|
||||
/** |
||||
* Layout for components with arbitrary constraints. |
||||
* |
||||
* @author MightyPork |
||||
*/ |
||||
public class ConstraintLayout extends LayoutComponent { |
||||
|
||||
public ConstraintLayout(AppAccess app) { |
||||
super(app); |
||||
} |
||||
|
||||
|
||||
public ConstraintLayout(AppAccess app, RectBound context) { |
||||
super(app, context); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Add a component to the layout.<br> |
||||
* The component's rect must be set up manually. |
||||
* |
||||
* @param component |
||||
*/ |
||||
public void add(Component component) |
||||
{ |
||||
attach(component); |
||||
} |
||||
|
||||
} |
@ -1,45 +0,0 @@ |
||||
package mightypork.rogue.screens.test_font; |
||||
|
||||
|
||||
import mightypork.gamecore.control.AppAccess; |
||||
import mightypork.gamecore.gui.components.painters.TextPainter; |
||||
import mightypork.gamecore.gui.screens.Screen; |
||||
import mightypork.gamecore.render.fonts.FontRenderer.Align; |
||||
import mightypork.rogue.Res; |
||||
import mightypork.utils.math.color.RGB; |
||||
import mightypork.utils.math.constraints.num.Num; |
||||
import mightypork.utils.math.constraints.rect.Rect; |
||||
|
||||
|
||||
public class ScreenTestFont extends Screen { |
||||
|
||||
private final TextPainter tp; |
||||
|
||||
|
||||
public ScreenTestFont(AppAccess app) { |
||||
super(app); |
||||
|
||||
tp = new TextPainter(Res.getFont("default"), Align.CENTER, RGB.GREEN); |
||||
tp.setText("Hello World!"); |
||||
|
||||
final Num h = bounds().height().mul(0.1); |
||||
final Rect strbox = Rect.make(Num.ZERO, h).centerTo(bounds()); |
||||
|
||||
tp.setRect(strbox); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected void renderScreen() |
||||
{ |
||||
tp.render(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public String getName() |
||||
{ |
||||
return "test.font"; |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue