fixed components and painters, some tweaks to layer system

v5stable
ondra 11 years ago
parent 7ee201a6f7
commit 3cad5ad202
  1. 5
      src/mightypork/gamecore/gui/Action.java
  2. 160
      src/mightypork/gamecore/gui/components/AbstractLayoutComponent.java
  3. 30
      src/mightypork/gamecore/gui/components/ClickableComponent.java
  4. 36
      src/mightypork/gamecore/gui/components/InputComponent.java
  5. 147
      src/mightypork/gamecore/gui/components/LayoutComponent.java
  6. 10
      src/mightypork/gamecore/gui/components/VisualComponent.java
  7. 5
      src/mightypork/gamecore/gui/components/layout/ColumnHolder.java
  8. 38
      src/mightypork/gamecore/gui/components/layout/ConstraintLayout.java
  9. 5
      src/mightypork/gamecore/gui/components/layout/RowHolder.java
  10. 14
      src/mightypork/gamecore/gui/components/painters/ImagePainter.java
  11. 4
      src/mightypork/gamecore/gui/components/painters/QuadPainter.java
  12. 4
      src/mightypork/gamecore/gui/components/painters/TextPainter.java
  13. 21
      src/mightypork/gamecore/gui/screens/Screen.java
  14. 72
      src/mightypork/gamecore/gui/screens/ScreenLayer.java
  15. 2
      src/mightypork/gamecore/input/InputSystem.java
  16. 12
      src/mightypork/gamecore/render/DisplaySystem.java
  17. 11
      src/mightypork/gamecore/render/fonts/impl/CachedFont.java
  18. 2
      src/mightypork/gamecore/render/fonts/impl/NullFont.java
  19. 4
      src/mightypork/rogue/App.java
  20. 4
      src/mightypork/rogue/Res.java
  21. 12
      src/mightypork/rogue/screens/LayerFps.java
  22. 6
      src/mightypork/rogue/screens/test_bouncyboxes/BouncyBox.java
  23. 20
      src/mightypork/rogue/screens/test_bouncyboxes/LayerBouncyBoxes.java
  24. 79
      src/mightypork/rogue/screens/test_cat_sound/LayerFlyingCat.java
  25. 45
      src/mightypork/rogue/screens/test_font/ScreenTestFont.java
  26. 10
      src/mightypork/rogue/screens/test_render/LayerTestGradient.java
  27. 2
      src/mightypork/rogue/screens/test_render/ScreenTestRender.java
  28. 21
      src/mightypork/utils/math/constraints/vect/Vect.java

@ -36,6 +36,9 @@ public abstract class Action implements Runnable, Enableable {
} }
/**
* Run the action, if it's enabled.
*/
@Override @Override
public final void run() public final void run()
{ {
@ -46,6 +49,6 @@ public abstract class Action implements Runnable, Enableable {
/** /**
* Do the work. * Do the work.
*/ */
public abstract void execute(); protected abstract void execute();
} }

@ -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; 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.control.interf.Enableable;
import mightypork.gamecore.gui.Action;
import mightypork.gamecore.gui.ActionTrigger; 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; 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.bus.clients.ClientHub;
import mightypork.gamecore.control.interf.Enableable; 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();
}
}
} }

@ -10,16 +10,22 @@ import mightypork.utils.math.constraints.rect.proxy.RectBoundAdapter;
/** /**
* {@link Renderable} with pluggable context * {@link Renderable} with pluggable context. When caching is enabled, the
* layout update can be triggered by firing the {@link LayoutChangeEvent}.
* *
* @author MightyPork * @author MightyPork
*/ */
public abstract class AbstractVisualComponent extends AbstractRectCache implements Component, LayoutChangeEvent.Listener { public abstract class VisualComponent extends AbstractRectCache implements Component, LayoutChangeEvent.Listener {
private Rect source; private Rect source;
private boolean visible = true; private boolean visible = true;
public VisualComponent() {
super();
}
@Override @Override
public final Rect getRect() public final Rect getRect()
{ {

@ -2,7 +2,7 @@ package mightypork.gamecore.gui.components.layout;
import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.control.AppAccess;
import mightypork.gamecore.gui.components.AbstractLayoutComponent; import mightypork.gamecore.gui.components.LayoutComponent;
import mightypork.gamecore.gui.components.Component; import mightypork.gamecore.gui.components.Component;
import mightypork.utils.math.constraints.rect.builders.TiledRect; import mightypork.utils.math.constraints.rect.builders.TiledRect;
import mightypork.utils.math.constraints.rect.proxy.RectBound; import mightypork.utils.math.constraints.rect.proxy.RectBound;
@ -13,7 +13,7 @@ import mightypork.utils.math.constraints.rect.proxy.RectBound;
* *
* @author MightyPork * @author MightyPork
*/ */
public class ColumnHolder extends AbstractLayoutComponent { public class ColumnHolder extends LayoutComponent {
private final TiledRect tiler; private final TiledRect tiler;
private int col = 0; private int col = 0;
@ -47,7 +47,6 @@ public class ColumnHolder extends AbstractLayoutComponent {
* *
* @param elem * @param elem
*/ */
@Override
public void add(final Component elem) public void add(final Component elem)
{ {
if (elem == null) return; if (elem == null) return;

@ -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);
}
}

@ -2,7 +2,7 @@ package mightypork.gamecore.gui.components.layout;
import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.control.AppAccess;
import mightypork.gamecore.gui.components.AbstractLayoutComponent; import mightypork.gamecore.gui.components.LayoutComponent;
import mightypork.gamecore.gui.components.Component; import mightypork.gamecore.gui.components.Component;
import mightypork.utils.math.constraints.rect.builders.TiledRect; import mightypork.utils.math.constraints.rect.builders.TiledRect;
import mightypork.utils.math.constraints.rect.proxy.RectBound; import mightypork.utils.math.constraints.rect.proxy.RectBound;
@ -13,7 +13,7 @@ import mightypork.utils.math.constraints.rect.proxy.RectBound;
* *
* @author MightyPork * @author MightyPork
*/ */
public class RowHolder extends AbstractLayoutComponent { public class RowHolder extends LayoutComponent {
private final TiledRect tiler; private final TiledRect tiler;
private int row = 0; private int row = 0;
@ -47,7 +47,6 @@ public class RowHolder extends AbstractLayoutComponent {
* *
* @param elem * @param elem
*/ */
@Override
public void add(final Component elem) public void add(final Component elem)
{ {
if (elem == null) return; if (elem == null) return;

@ -1,7 +1,7 @@
package mightypork.gamecore.gui.components.painters; package mightypork.gamecore.gui.components.painters;
import mightypork.gamecore.gui.components.AbstractVisualComponent; import mightypork.gamecore.gui.components.VisualComponent;
import mightypork.gamecore.render.Render; import mightypork.gamecore.render.Render;
import mightypork.gamecore.render.textures.TxQuad; import mightypork.gamecore.render.textures.TxQuad;
@ -11,7 +11,7 @@ import mightypork.gamecore.render.textures.TxQuad;
* *
* @author MightyPork * @author MightyPork
*/ */
public class ImagePainter extends AbstractVisualComponent { public class ImagePainter extends VisualComponent {
private TxQuad texture; private TxQuad texture;
@ -33,18 +33,10 @@ public class ImagePainter extends AbstractVisualComponent {
} }
@Override
public void updateLayout()
{
Render.quadTextured(getRect(), texture);
}
@Override @Override
public void renderComponent() public void renderComponent()
{ {
// TODO Auto-generated method stub Render.quadTextured(getRect(), texture);
} }
} }

@ -1,7 +1,7 @@
package mightypork.gamecore.gui.components.painters; package mightypork.gamecore.gui.components.painters;
import mightypork.gamecore.gui.components.AbstractVisualComponent; import mightypork.gamecore.gui.components.VisualComponent;
import mightypork.gamecore.render.Render; import mightypork.gamecore.render.Render;
import mightypork.utils.annotations.FactoryMethod; import mightypork.utils.annotations.FactoryMethod;
import mightypork.utils.math.color.RGB; import mightypork.utils.math.color.RGB;
@ -12,7 +12,7 @@ import mightypork.utils.math.color.RGB;
* *
* @author MightyPork * @author MightyPork
*/ */
public class QuadPainter extends AbstractVisualComponent { public class QuadPainter extends VisualComponent {
@FactoryMethod @FactoryMethod
public static QuadPainter gradH(RGB colorLeft, RGB colorRight) public static QuadPainter gradH(RGB colorLeft, RGB colorRight)

@ -1,7 +1,7 @@
package mightypork.gamecore.gui.components.painters; package mightypork.gamecore.gui.components.painters;
import mightypork.gamecore.gui.components.AbstractVisualComponent; import mightypork.gamecore.gui.components.VisualComponent;
import mightypork.gamecore.render.fonts.FontRenderer; import mightypork.gamecore.render.fonts.FontRenderer;
import mightypork.gamecore.render.fonts.FontRenderer.Align; import mightypork.gamecore.render.fonts.FontRenderer.Align;
import mightypork.gamecore.render.fonts.GLFont; import mightypork.gamecore.render.fonts.GLFont;
@ -19,7 +19,7 @@ import mightypork.utils.string.StringProvider.StringWrapper;
* *
* @author MightyPork * @author MightyPork
*/ */
public class TextPainter extends AbstractVisualComponent { public class TextPainter extends VisualComponent {
private final FontRenderer font; private final FontRenderer font;
private RGB color; private RGB color;

@ -94,13 +94,13 @@ public abstract class Screen extends AppSubModule implements Renderable, KeyBind
@Override @Override
public void receive(ScreenChangeEvent event) public final void receive(ScreenChangeEvent event)
{ {
if (!isActive()) return; if (!isActive()) return;
onSizeChanged(event.getScreenSize()); onSizeChanged(event.getScreenSize());
// poll constraints // fire event
getEventBus().sendDirectToChildren(this, new LayoutChangeEvent()); getEventBus().sendDirectToChildren(this, new LayoutChangeEvent());
needSetupViewport = true; needSetupViewport = true;
@ -108,7 +108,7 @@ public abstract class Screen extends AppSubModule implements Renderable, KeyBind
@Override @Override
public Rect getRect() public final Rect getRect()
{ {
return getDisplay().getRect(); return getDisplay().getRect();
} }
@ -137,7 +137,6 @@ public abstract class Screen extends AppSubModule implements Renderable, KeyBind
@DefaultImpl @DefaultImpl
protected void onScreenEnter() protected void onScreenEnter()
{ {
//
} }
@ -147,7 +146,6 @@ public abstract class Screen extends AppSubModule implements Renderable, KeyBind
@DefaultImpl @DefaultImpl
protected void onScreenLeave() protected void onScreenLeave()
{ {
//
} }
@ -159,7 +157,6 @@ public abstract class Screen extends AppSubModule implements Renderable, KeyBind
@DefaultImpl @DefaultImpl
protected void onSizeChanged(Vect size) protected void onSizeChanged(Vect size)
{ {
//
} }
@ -174,16 +171,4 @@ public abstract class Screen extends AppSubModule implements Renderable, KeyBind
*/ */
public abstract String getName(); public abstract String getName();
protected final Rect bounds()
{
return getRect();
}
protected final Vect mouse()
{
return getInput().getMousePos();
}
} }

@ -1,15 +1,18 @@
package mightypork.gamecore.gui.screens; package mightypork.gamecore.gui.screens;
import java.util.Collection;
import java.util.LinkedHashSet;
import mightypork.gamecore.control.AppSubModule; import mightypork.gamecore.control.AppSubModule;
import mightypork.gamecore.control.timing.Updateable;
import mightypork.gamecore.gui.Hideable; import mightypork.gamecore.gui.Hideable;
import mightypork.gamecore.gui.components.Renderable; import mightypork.gamecore.gui.components.Renderable;
import mightypork.gamecore.gui.components.layout.ConstraintLayout;
import mightypork.gamecore.input.KeyBinder; import mightypork.gamecore.input.KeyBinder;
import mightypork.gamecore.input.KeyBindingPool; import mightypork.gamecore.input.KeyBindingPool;
import mightypork.gamecore.input.KeyStroke; import mightypork.gamecore.input.KeyStroke;
import mightypork.utils.annotations.DefaultImpl; import mightypork.utils.annotations.DefaultImpl;
import mightypork.utils.math.constraints.rect.Rect;
import mightypork.utils.math.constraints.rect.proxy.RectBound;
import mightypork.utils.math.constraints.vect.Vect; import mightypork.utils.math.constraints.vect.Vect;
@ -18,14 +21,25 @@ import mightypork.utils.math.constraints.vect.Vect;
* *
* @author MightyPork * @author MightyPork
*/ */
public abstract class ScreenLayer extends AppSubModule implements Comparable<ScreenLayer>, Renderable, RectBound, KeyBinder, Hideable { public abstract class ScreenLayer extends AppSubModule implements Updateable, Comparable<ScreenLayer>, Renderable, KeyBinder, Hideable {
private final Screen screen;
private boolean visible = true; private boolean visible = true;
private final KeyBindingPool keybindings = new KeyBindingPool(); private final KeyBindingPool keybindings = new KeyBindingPool();
/** Root layout, rendered and attached to the event bus */
protected final ConstraintLayout root;
protected final Vect mouse;
private final Screen screen;
/** Extra rendered items (outside root) */
protected final Collection<Renderable> rendered = new LinkedHashSet<>();
/** Extra updated items (outside root - those can just implement Updateable) */
protected final Collection<Updateable> updated = new LinkedHashSet<>();
/** /**
* @param screen parent screen * @param screen parent screen
@ -34,7 +48,17 @@ public abstract class ScreenLayer extends AppSubModule implements Comparable<Scr
super(screen); // screen as AppAccess super(screen); // screen as AppAccess
this.screen = screen; this.screen = screen;
this.mouse = getInput().getMousePos();
this.root = new ConstraintLayout(screen, screen);
addChildClient(root);
addChildClient(keybindings); addChildClient(keybindings);
rendered.add(root);
// root is on the bus, all attached components
// will receive events (such as update)
} }
@ -62,14 +86,7 @@ public abstract class ScreenLayer extends AppSubModule implements Comparable<Scr
@Override @Override
public Rect getRect() public final boolean isVisible()
{
return screen.getRect();
}
@Override
public boolean isVisible()
{ {
return visible; return visible;
} }
@ -95,7 +112,6 @@ public abstract class ScreenLayer extends AppSubModule implements Comparable<Scr
@DefaultImpl @DefaultImpl
protected void onScreenEnter() protected void onScreenEnter()
{ {
//
} }
@ -105,7 +121,6 @@ public abstract class ScreenLayer extends AppSubModule implements Comparable<Scr
@DefaultImpl @DefaultImpl
protected void onScreenLeave() protected void onScreenLeave()
{ {
//
} }
@ -117,25 +132,42 @@ public abstract class ScreenLayer extends AppSubModule implements Comparable<Scr
@DefaultImpl @DefaultImpl
protected void onSizeChanged(Vect size) protected void onSizeChanged(Vect size)
{ {
//
} }
/** /**
* @return higher = on top. * @return higher = on top.
*/ */
@DefaultImpl
public abstract int getPriority(); public abstract int getPriority();
protected final Rect bounds() @Override
public final void render()
{
if (!visible) return;
renderLayer();
}
/**
* Render layer contents.
*/
protected void renderLayer()
{ {
return screen.bounds(); // render renderables (including root layout)
for (Renderable r : rendered)
r.render();
} }
protected final Vect mouse() @Override
public void update(double delta)
{ {
return screen.mouse(); // update updateables
for (Updateable u : updated)
u.update(delta);
} }
} }

@ -174,7 +174,7 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
/** /**
* Get absolute mouse position * Get absolute mouse position. This vect is final and views at it can safely be made.
* *
* @return mouse position * @return mouse position
*/ */

@ -186,7 +186,7 @@ public class DisplaySystem extends AppModule implements RectBound {
/** /**
* Get screen size * Get screen size. This Vect is final and views at it can safely be made.
* *
* @return size * @return size
*/ */
@ -240,6 +240,9 @@ public class DisplaySystem extends AppModule implements RectBound {
} }
/**
* Get screen rect. This Rect is final and views at it can safely be made.
*/
@Override @Override
public Rect getRect() public Rect getRect()
{ {
@ -256,8 +259,13 @@ public class DisplaySystem extends AppModule implements RectBound {
} }
/**
* Get screen center. This vect is final and views at it can safely be made.
*
* @return screen center.
*/
public Vect getCenter() public Vect getCenter()
{ {
return getSize().half(); return rect.center();
} }
} }

@ -334,8 +334,9 @@ public class CachedFont implements GLFont {
private void drawQuad(float xmin, float ymin, float xmax, float ymax, float txmin, float tymin, float txmax, float tymax) private void drawQuad(float xmin, float ymin, float xmax, float ymax, float txmin, float tymin, float txmax, float tymax)
{ {
final float draw_h = xmax - xmin; final float draw_width = xmax - xmin;
final float draw_w = ymax - ymin; final float draw_height = ymax - ymin;
final float txmin01 = txmin / textureWidth; final float txmin01 = txmin / textureWidth;
final float tymin01 = tymin / textureHeight; final float tymin01 = tymin / textureHeight;
final float twidth01 = ((txmax - txmin) / textureWidth); final float twidth01 = ((txmax - txmin) / textureWidth);
@ -345,13 +346,13 @@ public class CachedFont implements GLFont {
glVertex2f(xmin, ymin); glVertex2f(xmin, ymin);
glTexCoord2f(txmin01, tymin01 + theight01); glTexCoord2f(txmin01, tymin01 + theight01);
glVertex2f(xmin, ymin + draw_w); glVertex2f(xmin, ymin + draw_height);
glTexCoord2f(txmin01 + twidth01, tymin01 + theight01); glTexCoord2f(txmin01 + twidth01, tymin01 + theight01);
glVertex2f(xmin + draw_h, ymin + draw_w); glVertex2f(xmin + draw_width, ymin + draw_height);
glTexCoord2f(txmin01 + twidth01, tymin01); glTexCoord2f(txmin01 + twidth01, tymin01);
glVertex2f(xmin + draw_h, ymin); glVertex2f(xmin + draw_width, ymin);
} }

@ -17,7 +17,7 @@ public class NullFont implements GLFont {
@Override @Override
public void draw(String str, RGB color) public void draw(String str, RGB color)
{ {
Log.w("Drawing with null font."); // yeah right
} }

@ -16,7 +16,6 @@ import mightypork.rogue.events.ActionRequest;
import mightypork.rogue.events.ActionRequest.RequestType; import mightypork.rogue.events.ActionRequest.RequestType;
import mightypork.rogue.screens.test_bouncyboxes.ScreenTestBouncy; import mightypork.rogue.screens.test_bouncyboxes.ScreenTestBouncy;
import mightypork.rogue.screens.test_cat_sound.ScreenTestCat; import mightypork.rogue.screens.test_cat_sound.ScreenTestCat;
import mightypork.rogue.screens.test_font.ScreenTestFont;
import mightypork.rogue.screens.test_render.ScreenTestRender; import mightypork.rogue.screens.test_render.ScreenTestRender;
import mightypork.utils.logging.Log; import mightypork.utils.logging.Log;
import mightypork.utils.logging.LogWriter; import mightypork.utils.logging.LogWriter;
@ -67,10 +66,9 @@ public class App extends BaseApp {
{ {
screens.add(new ScreenTestBouncy(this)); screens.add(new ScreenTestBouncy(this));
screens.add(new ScreenTestCat(this)); screens.add(new ScreenTestCat(this));
screens.add(new ScreenTestFont(this));
screens.add(new ScreenTestRender(this)); screens.add(new ScreenTestRender(this));
screens.showScreen("test.bouncy"); screens.showScreen("test.render");
} }

@ -62,6 +62,10 @@ public class Res {
font.setFilter(FilterMode.NEAREST); font.setFilter(FilterMode.NEAREST);
fonts.loadFont("default", font); fonts.loadFont("default", font);
font = new DeferredFont("/res/font/PressStart2P.ttf", Glyphs.basic, 16);
font.setAntialias(true);
font.setFilter(FilterMode.NEAREST);
fonts.loadFont("press_start", font);
} }

@ -38,7 +38,7 @@ public class LayerFps extends ScreenLayer {
final GLFont font = Res.getFont("default"); final GLFont font = Res.getFont("default");
final RectBound constraint = bounds().topRight().add(-8, 8).expand(0, 0, 0, 32); final RectBound constraint = root.topRight().add(-8, 8).expand(0, 0, 0, 32);
tp = new TextPainter(font, Align.RIGHT, RGB.WHITE, new StringProvider() { tp = new TextPainter(font, Align.RIGHT, RGB.WHITE, new StringProvider() {
@ -50,15 +50,9 @@ public class LayerFps extends ScreenLayer {
}); });
tp.setRect(constraint); tp.setRect(constraint);
tp.setShadow(RGB.BLACK, Vect.make(tp.height().div(16)));
tp.setShadow(RGB.BLACK, Vect.ONE); root.add(tp);
}
@Override
public void render()
{
tp.render();
} }

@ -4,7 +4,7 @@ package mightypork.rogue.screens.test_bouncyboxes;
import java.util.Random; import java.util.Random;
import mightypork.gamecore.control.timing.Updateable; import mightypork.gamecore.control.timing.Updateable;
import mightypork.gamecore.gui.components.AbstractVisualComponent; import mightypork.gamecore.gui.components.VisualComponent;
import mightypork.gamecore.render.Render; import mightypork.gamecore.render.Render;
import mightypork.utils.math.Easing; import mightypork.utils.math.Easing;
import mightypork.utils.math.color.RGB; import mightypork.utils.math.color.RGB;
@ -14,7 +14,7 @@ import mightypork.utils.math.constraints.rect.Rect;
import mightypork.utils.math.constraints.rect.caching.RectCache; import mightypork.utils.math.constraints.rect.caching.RectCache;
public class BouncyBox extends AbstractVisualComponent implements Updateable { public class BouncyBox extends VisualComponent implements Updateable {
private final Random rand = new Random(); private final Random rand = new Random();
@ -24,6 +24,8 @@ public class BouncyBox extends AbstractVisualComponent implements Updateable {
public BouncyBox() { public BouncyBox() {
enableCaching(true);
Rect abox; Rect abox;
abox = leftEdge().growRight(height()); abox = leftEdge().growRight(height());

@ -14,7 +14,6 @@ import mightypork.gamecore.render.fonts.FontRenderer.Align;
import mightypork.rogue.Res; import mightypork.rogue.Res;
import mightypork.utils.math.color.RGB; import mightypork.utils.math.color.RGB;
import mightypork.utils.math.constraints.num.Num; import mightypork.utils.math.constraints.num.Num;
import mightypork.utils.math.constraints.rect.Rect;
import mightypork.utils.math.constraints.vect.Vect; import mightypork.utils.math.constraints.vect.Vect;
@ -47,13 +46,9 @@ public class LayerBouncyBoxes extends ScreenLayer {
// shrink screen rect by 8% on all sides // shrink screen rect by 8% on all sides
final Rect b = bounds(); root.add(layout = new RowHolder(this, root.shrink(root.height().perc(5)), 10));
final Rect holder_rect = b.shrink(b.height().perc(8)); for (int i = 0; i < 9; i++) {
addChildClient(layout = new RowHolder(screen, holder_rect, 100));
for (int i = 0; i < 99; i++) {
final BouncyBox bbr = new BouncyBox(); final BouncyBox bbr = new BouncyBox();
layout.add(bbr); layout.add(bbr);
boxes.add(bbr); boxes.add(bbr);
@ -61,22 +56,13 @@ public class LayerBouncyBoxes extends ScreenLayer {
final TextPainter tp = new TextPainter(Res.getFont("default"), Align.LEFT, RGB.WHITE); final TextPainter tp = new TextPainter(Res.getFont("default"), Align.LEFT, RGB.WHITE);
tp.setText("Press \"C\" for \"Cat\" screen."); tp.setText("Press \"C\" for \"Cat\" screen.");
final Num shadowOffset = tp.height().div(16);
final Num shadowOffset = tp.height().div(16 * 2); // half pixel if 16px font
tp.setShadow(RGB.RED, Vect.make(shadowOffset, shadowOffset)); tp.setShadow(RGB.RED, Vect.make(shadowOffset, shadowOffset));
layout.add(tp); layout.add(tp);
} }
@Override
public void render()
{
layout.render();
}
public void goLeft() public void goLeft()
{ {
for (final BouncyBox bbr : boxes) { for (final BouncyBox bbr : boxes) {

@ -23,40 +23,54 @@ import mightypork.utils.math.constraints.vect.Vect;
import mightypork.utils.math.constraints.vect.mutable.VectAnimated; import mightypork.utils.math.constraints.vect.mutable.VectAnimated;
public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButtonEvent.Listener { public class LayerFlyingCat extends ScreenLayer implements MouseButtonEvent.Listener, Updateable {
private final NumAnimated size = new NumAnimated(400, Easing.SINE_BOTH); private final NumAnimated size = new NumAnimated(300, Easing.SINE_BOTH);
private final VectAnimated pos = VectAnimated.makeVar(Easing.ELASTIC_OUT); private final VectAnimated cat_position = VectAnimated.makeVar(Easing.ELASTIC_OUT);
private final Random rand = new Random(); private final Random rand = new Random();
private final ImagePainter cat;
private final TextPainter tp;
private final QuadPainter qp;
public LayerFlyingCat(Screen screen) { public LayerFlyingCat(Screen screen) {
super(screen); super(screen);
pos.setTo(getDisplay().getCenter()); // timing
pos.setDefaultDuration(3); updated.add(size);
updated.add(cat_position);
size.setTo(root.height().perc(60));
cat = new ImagePainter(Res.getTxQuad("test.kitten")); // cat
cat_position.setTo(getDisplay().getCenter());
cat_position.setDefaultDuration(3);
cat.setRect(Rect.make(size, size).centerTo(pos)); ImagePainter cat = new ImagePainter(Res.getTxQuad("test.kitten"));
cat.setRect(Rect.make(size, size).centerTo(cat_position));
cat.enableCaching(false);
tp = new TextPainter(Res.getFont("default")); // frame around cat
tp.setAlign(Align.CENTER); QuadPainter cat_frame = QuadPainter.gradV(RGB.YELLOW, RGB.RED);
tp.setColor(RGB.YELLOW); cat_frame.setRect(cat.grow(cat.height().mul(0.05)));
tp.setText("Meow!"); cat_frame.enableCaching(false);
tp.setShadow(RGB.dark(0.8), Vect.make(2, 2));
tp.setRect(Rect.make(64, 64).centerTo(mouse())); // frame shadow
QuadPainter cat_shadow = new QuadPainter(RGB.dark(0.4));
cat_shadow.setRect(cat_frame.move(Vect.make(cat.height().mul(0.05))));
cat_shadow.enableCaching(false);
qp = QuadPainter.gradV(RGB.YELLOW, RGB.RED); root.add(cat_shadow);
root.add(cat_frame);
root.add(cat);
qp.setRect(cat.getRect().bottomLeft().expand(size.half(), Num.ZERO, Num.ZERO, size.half()));
// Meow
TextPainter tp = new TextPainter(Res.getFont("press_start"));
tp.setAlign(Align.CENTER);
tp.setColor(RGB.YELLOW);
tp.setText("Meow!");
tp.setShadow(RGB.dark(0.5), Vect.make(tp.height().div(16)));
tp.setRect(Rect.make(Num.ZERO, cat.height().half()).centerTo(mouse));
tp.enableCaching(false);
root.add(tp);
/* /*
* Register keys * Register keys
*/ */
@ -65,46 +79,29 @@ public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButt
@Override @Override
public void run() public void run()
{ {
pos.setTo(getDisplay().getCenter()); cat_position.setTo(getDisplay().getCenter());
} }
}); });
} }
@Override
public void update(double delta)
{
size.update(delta);
pos.update(delta);
}
@Override @Override
public void receive(MouseButtonEvent event) public void receive(MouseButtonEvent event)
{ {
if (!event.isDown()) return; if (!event.isDown()) return;
final Vect pos = event.getPos(); this.cat_position.setTo(event.getPos());
this.pos.setTo(pos);
size.animate(200 + rand.nextInt(600), 1);
}
double newSize = root.height().perc(10 + rand.nextInt(40)).value();
@Override size.animate(newSize, 1);
public void render()
{
cat.render();
tp.render();
qp.render();
} }
@Override @Override
public int getPriority() public int getPriority()
{ {
return 0; return 10;
} }
} }

@ -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";
}
}

@ -17,15 +17,15 @@ public class LayerTestGradient extends ScreenLayer {
public LayerTestGradient(Screen screen) { public LayerTestGradient(Screen screen) {
super(screen); super(screen);
pos1 = bounds().topEdge().growDown(64); pos1 = root.topEdge().growDown(64);
pos2 = bounds().leftEdge().growUp(-64).growRight(64); pos2 = root.leftEdge().growUp(-64).growRight(64);
} }
@Override @Override
public void render() protected void renderLayer()
{ {
Render.quadColor(getRect(), RGB.WHITE, RGB.BLUE, RGB.BLACK, RGB.PURPLE); Render.quadColor(root, RGB.WHITE, RGB.BLUE, RGB.BLACK, RGB.PURPLE);
Render.quadGradH(pos1.getRect(), RGB.GREEN, RGB.RED); Render.quadGradH(pos1.getRect(), RGB.GREEN, RGB.RED);
Render.quadGradV(pos2.getRect(), RGB.WHITE, RGB.PURPLE); Render.quadGradV(pos2.getRect(), RGB.WHITE, RGB.PURPLE);
} }
@ -34,7 +34,7 @@ public class LayerTestGradient extends ScreenLayer {
@Override @Override
public int getPriority() public int getPriority()
{ {
return 5; return 0;
} }
} }

@ -4,6 +4,7 @@ package mightypork.rogue.screens.test_render;
import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.control.AppAccess;
import mightypork.gamecore.gui.screens.LayeredScreen; import mightypork.gamecore.gui.screens.LayeredScreen;
import mightypork.rogue.screens.LayerFps; import mightypork.rogue.screens.LayerFps;
import mightypork.rogue.screens.test_cat_sound.LayerFlyingCat;
public class ScreenTestRender extends LayeredScreen { public class ScreenTestRender extends LayeredScreen {
@ -13,6 +14,7 @@ public class ScreenTestRender extends LayeredScreen {
addLayer(new LayerFps(this)); addLayer(new LayerFps(this));
addLayer(new LayerTestGradient(this)); addLayer(new LayerTestGradient(this));
addLayer(new LayerFlyingCat(this));
} }

@ -27,6 +27,13 @@ public abstract class Vect implements VectBound, Digestable<VectDigest> {
public static final VectConst ONE = new VectConst(1, 1, 1); public static final VectConst ONE = new VectConst(1, 1, 1);
@FactoryMethod
public static Vect make(Num xy)
{
return make(xy, xy);
}
@FactoryMethod @FactoryMethod
public static Vect make(Num xc, Num yc) public static Vect make(Num xc, Num yc)
{ {
@ -48,6 +55,13 @@ public abstract class Vect implements VectBound, Digestable<VectDigest> {
} }
@FactoryMethod
public static VectConst make(NumConst xy)
{
return make(xy, xy);
}
@FactoryMethod @FactoryMethod
public static VectConst make(NumConst xc, NumConst yc) public static VectConst make(NumConst xc, NumConst yc)
{ {
@ -62,6 +76,13 @@ public abstract class Vect implements VectBound, Digestable<VectDigest> {
} }
@FactoryMethod
public static VectConst make(double xy)
{
return make(xy, xy);
}
@FactoryMethod @FactoryMethod
public static VectConst make(double x, double y) public static VectConst make(double x, double y)
{ {

Loading…
Cancel
Save