Remade constraint system, improved rendering & font.
This commit is contained in:
@@ -17,6 +17,7 @@ import mightypork.rogue.gui.screens.test_cat_sound.ScreenTestCat;
|
||||
import mightypork.rogue.gui.screens.test_font.ScreenTestFont;
|
||||
import mightypork.rogue.input.InputSystem;
|
||||
import mightypork.rogue.input.KeyStroke;
|
||||
import mightypork.rogue.input.Keys;
|
||||
import mightypork.rogue.render.DisplaySystem;
|
||||
import mightypork.rogue.sounds.SoundSystem;
|
||||
import mightypork.rogue.util.SlickLogRedirector;
|
||||
@@ -26,8 +27,6 @@ import mightypork.utils.control.interf.Updateable;
|
||||
import mightypork.utils.logging.Log;
|
||||
import mightypork.utils.logging.LogInstance;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
|
||||
/**
|
||||
* Main class
|
||||
@@ -197,7 +196,7 @@ public class App implements AppAccess {
|
||||
screens.add(new ScreenTestCat(this));
|
||||
screens.add(new ScreenTestFont(this));
|
||||
|
||||
screens.showScreen("test.font");
|
||||
screens.showScreen("test.bouncy");
|
||||
}
|
||||
|
||||
|
||||
@@ -228,7 +227,7 @@ public class App implements AppAccess {
|
||||
Log.f3("Setting up hot keys...");
|
||||
|
||||
// Go fullscreen
|
||||
input().bindKeyStroke(new KeyStroke(Keyboard.KEY_F11), new Runnable() {
|
||||
input().bindKeyStroke(new KeyStroke(Keys.KEY_F11), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
@@ -238,7 +237,7 @@ public class App implements AppAccess {
|
||||
});
|
||||
|
||||
// Take screenshot
|
||||
input().bindKeyStroke(new KeyStroke(Keyboard.KEY_F2), new Runnable() {
|
||||
input().bindKeyStroke(new KeyStroke(Keys.KEY_F2), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
@@ -248,7 +247,7 @@ public class App implements AppAccess {
|
||||
});
|
||||
|
||||
// Exit
|
||||
input().bindKeyStroke(new KeyStroke(Keyboard.KEY_LCONTROL, Keyboard.KEY_Q), new Runnable() {
|
||||
input().bindKeyStroke(new KeyStroke(Keys.KEY_LCONTROL, Keys.KEY_Q), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
|
||||
@@ -55,7 +55,7 @@ public class Res {
|
||||
|
||||
private static void loadFonts()
|
||||
{
|
||||
fonts.loadFont("PolygonPixel_16", new DeferredFont("/res/font/PolygonPixel5x7Standard.ttf", null, 32, FontStyle.PLAIN, true));
|
||||
fonts.loadFont("default", new DeferredFont("/res/font/PolygonPixel5x7Standard.ttf", null, 32, FontStyle.PLAIN, true));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import mightypork.rogue.AppAdapter;
|
||||
import mightypork.utils.control.bus.EventBus;
|
||||
import mightypork.utils.control.bus.clients.DelegatingClient;
|
||||
import mightypork.utils.control.bus.clients.ToggleableClient;
|
||||
import mightypork.utils.logging.Log;
|
||||
|
||||
|
||||
/**
|
||||
@@ -60,8 +59,6 @@ public class ChildClient extends AppAdapter implements DelegatingClient, Togglea
|
||||
{
|
||||
if (bus().isClientValid(client)) {
|
||||
clients.add(client);
|
||||
} else {
|
||||
Log.w("Client rejected by bus: " + client.getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,13 @@ public class ActionRequest implements Event<ActionRequest.Listener> {
|
||||
void requestAction(RequestType request);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "ActionRequest(" + type + ")";
|
||||
}
|
||||
|
||||
public static enum RequestType
|
||||
{
|
||||
FULLSCREEN, SCREENSHOT, SHUTDOWN;
|
||||
|
||||
@@ -20,7 +20,7 @@ import mightypork.utils.math.coord.Coord;
|
||||
* @author MightyPork
|
||||
*/
|
||||
@MustLoadInMainThread
|
||||
@LoggedName(name="Font")
|
||||
@LoggedName(name = "Font")
|
||||
public class DeferredFont extends BaseDeferredResource implements GLFont {
|
||||
|
||||
public static enum FontStyle
|
||||
@@ -144,37 +144,6 @@ public class DeferredFont extends BaseDeferredResource implements GLFont {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw string at 0,0
|
||||
*
|
||||
* @param str string to draw
|
||||
* @param color draw color
|
||||
* @param startIndex first drawn character index
|
||||
* @param endIndex last drawn character index
|
||||
*/
|
||||
@Override
|
||||
public void draw(String str, RGB color, int startIndex, int endIndex)
|
||||
{
|
||||
if (!ensureLoaded()) return;
|
||||
|
||||
font.draw(str, color, startIndex, endIndex);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw string 0,0
|
||||
*
|
||||
* @param str string to draw
|
||||
*/
|
||||
@Override
|
||||
public void draw(String str)
|
||||
{
|
||||
if (!ensureLoaded()) return;
|
||||
|
||||
font.draw(str);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get size needed to render give string
|
||||
*
|
||||
|
||||
@@ -13,7 +13,7 @@ import mightypork.utils.logging.LoggedName;
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
@LoggedName(name="FontNative")
|
||||
@LoggedName(name = "FontNative")
|
||||
public class DeferredFontNative extends DeferredFont {
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package mightypork.rogue.fonts;
|
||||
|
||||
|
||||
import mightypork.rogue.render.Render;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
import mightypork.utils.math.coord.Rect;
|
||||
|
||||
|
||||
public class FontRenderer {
|
||||
|
||||
private final GLFont font;
|
||||
|
||||
|
||||
public FontRenderer(GLFont font) {
|
||||
|
||||
if (font == null) throw new NullPointerException("Font cannot be null.");
|
||||
|
||||
this.font = font;
|
||||
}
|
||||
|
||||
|
||||
public void draw(String text, Coord pos, double height, RGB color)
|
||||
{
|
||||
Render.pushState();
|
||||
|
||||
Render.translate(pos.round());
|
||||
Render.scaleXY(getScale(height));
|
||||
|
||||
font.draw(text, color);
|
||||
|
||||
Render.popState();
|
||||
}
|
||||
|
||||
|
||||
public Coord getNeededSpace(String text, double height)
|
||||
{
|
||||
return font.getNeededSpace(text).mul(getScale(height));
|
||||
}
|
||||
|
||||
|
||||
public double getWidth(String text, double height)
|
||||
{
|
||||
return getNeededSpace(text, height).x;
|
||||
}
|
||||
|
||||
|
||||
public Rect getBounds(String text, Coord pos, double height)
|
||||
{
|
||||
return Rect.fromSize(getNeededSpace(text, height)).add(pos);
|
||||
}
|
||||
|
||||
|
||||
private double getScale(double height)
|
||||
{
|
||||
return height / font.getHeight();
|
||||
}
|
||||
}
|
||||
@@ -16,25 +16,6 @@ public interface GLFont {
|
||||
void draw(String text, RGB color);
|
||||
|
||||
|
||||
/**
|
||||
* Draw string at position
|
||||
*
|
||||
* @param text string to draw
|
||||
* @param color draw color
|
||||
* @param startIndex first drawn character index
|
||||
* @param endIndex last drawn character index
|
||||
*/
|
||||
void draw(String text, RGB color, int startIndex, int endIndex);
|
||||
|
||||
|
||||
/**
|
||||
* Draw string at position
|
||||
*
|
||||
* @param str string to draw
|
||||
*/
|
||||
void draw(String str);
|
||||
|
||||
|
||||
/**
|
||||
* Get suize needed to render give string
|
||||
*
|
||||
|
||||
@@ -19,20 +19,6 @@ public class NullFont implements GLFont {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void draw(String str, RGB color, int startIndex, int endIndex)
|
||||
{
|
||||
// nope
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void draw(String str)
|
||||
{
|
||||
// nope
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Coord getNeededSpace(String str)
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@ import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
import java.awt.Font;
|
||||
|
||||
import mightypork.rogue.render.Render;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
|
||||
@@ -53,7 +54,7 @@ public class SlickFont implements GLFont {
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
}
|
||||
|
||||
@@ -67,37 +68,12 @@ public class SlickFont implements GLFont {
|
||||
@Override
|
||||
public void draw(String str, RGB color)
|
||||
{
|
||||
Render.pushState();
|
||||
|
||||
prepareForRender();
|
||||
ttf.drawString(0, 0, str, rgbToSlickColor(color));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw substring in color
|
||||
*
|
||||
* @param str string to draw
|
||||
* @param color text color
|
||||
* @param startIndex first char to draw
|
||||
* @param endIndex last char to draw (INCLUDING!)
|
||||
*/
|
||||
@Override
|
||||
public void draw(String str, RGB color, int startIndex, int endIndex)
|
||||
{
|
||||
prepareForRender();
|
||||
ttf.drawString(0, 0, str, rgbToSlickColor(color), startIndex, endIndex);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw in white
|
||||
*
|
||||
* @param str chars to draw
|
||||
*/
|
||||
@Override
|
||||
public void draw(String str)
|
||||
{
|
||||
prepareForRender();
|
||||
ttf.drawString(0, 0, str);
|
||||
|
||||
Render.popState();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
package mightypork.rogue.gui.constraints;
|
||||
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import mightypork.rogue.AppAccess;
|
||||
import mightypork.rogue.bus.ChildClient;
|
||||
import mightypork.rogue.render.Renderable;
|
||||
import mightypork.utils.control.bus.EventBus;
|
||||
import mightypork.utils.math.constraints.ConstraintContext;
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
import mightypork.utils.math.coord.Rect;
|
||||
|
||||
|
||||
/**
|
||||
* Bag for {@link PluggableRenderable} elements with constraints.<br>
|
||||
* Elements are exposed to {@link EventBus}.
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public class ElementHolder extends ChildClient implements ConstraintContext, PluggableRenderable {
|
||||
|
||||
private final LinkedList<PluggableRenderable> elements = new LinkedList<PluggableRenderable>();
|
||||
private ConstraintContext context;
|
||||
|
||||
|
||||
public ElementHolder(AppAccess app) {
|
||||
super(app);
|
||||
}
|
||||
|
||||
|
||||
public ElementHolder(AppAccess app, ConstraintContext context) {
|
||||
super(app);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setContext(ConstraintContext context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void render()
|
||||
{
|
||||
for (final Renderable element : elements) {
|
||||
element.render();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return context.getRect();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add element to the holder.
|
||||
*
|
||||
* @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}
|
||||
*/
|
||||
public void add(PluggableRenderable elem, RectConstraint constraint)
|
||||
{
|
||||
if (elem == null) return;
|
||||
|
||||
constraint.setContext(this);
|
||||
elem.setContext(constraint);
|
||||
|
||||
elements.add(elem);
|
||||
addChildClient(elem);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove element from the holder
|
||||
*
|
||||
* @param elem
|
||||
*/
|
||||
public void remove(PluggableRenderable elem)
|
||||
{
|
||||
if (elem == null) return;
|
||||
elements.remove(elem);
|
||||
removeChildClient(elem);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package mightypork.rogue.gui.constraints;
|
||||
|
||||
|
||||
import mightypork.rogue.render.Renderable;
|
||||
import mightypork.utils.math.constraints.SettableContext;
|
||||
|
||||
|
||||
/**
|
||||
* {@link Renderable} with {@link SettableContext}
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public interface PluggableRenderable extends Renderable, SettableContext {
|
||||
// methods from both interfaces
|
||||
}
|
||||
+9
-12
@@ -1,9 +1,9 @@
|
||||
package mightypork.rogue.gui.constraints;
|
||||
package mightypork.rogue.gui.renderers;
|
||||
|
||||
|
||||
import static mightypork.utils.math.constraints.ConstraintFactory.*;
|
||||
import mightypork.rogue.AppAccess;
|
||||
import mightypork.utils.math.constraints.ConstraintContext;
|
||||
import mightypork.utils.math.constraints.RectEvaluable;
|
||||
|
||||
|
||||
public class ColumnHolder extends ElementHolder {
|
||||
@@ -12,7 +12,7 @@ public class ColumnHolder extends ElementHolder {
|
||||
private int col = 0;
|
||||
|
||||
|
||||
public ColumnHolder(AppAccess app, ConstraintContext context, int rows) {
|
||||
public ColumnHolder(AppAccess app, RectEvaluable context, int rows) {
|
||||
super(app, context);
|
||||
this.cols = rows;
|
||||
}
|
||||
@@ -29,17 +29,14 @@ public class ColumnHolder extends ElementHolder {
|
||||
*
|
||||
* @param elem
|
||||
*/
|
||||
public void addRow(PluggableRenderable elem)
|
||||
@Override
|
||||
public void add(final PluggableRenderable elem)
|
||||
{
|
||||
if (elem == null) return;
|
||||
add(elem, c_column(null, cols, col++));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void remove(PluggableRenderable elem)
|
||||
{
|
||||
throw new UnsupportedOperationException("Can't remove from ColumnHolder.");
|
||||
|
||||
elem.setContext(c_column(this, cols, col++));
|
||||
|
||||
attach(elem);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package mightypork.rogue.gui.renderers;
|
||||
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import mightypork.rogue.AppAccess;
|
||||
import mightypork.rogue.bus.ChildClient;
|
||||
import mightypork.rogue.render.Renderable;
|
||||
import mightypork.utils.control.bus.EventBus;
|
||||
import mightypork.utils.math.constraints.RectEvaluable;
|
||||
import mightypork.utils.math.coord.Rect;
|
||||
|
||||
|
||||
/**
|
||||
* Bag for {@link PluggableRenderer} elements with constraints.<br>
|
||||
* Elements are exposed to {@link EventBus}.
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public abstract class ElementHolder extends ChildClient implements PluggableRenderable {
|
||||
|
||||
private final LinkedList<PluggableRenderable> elements = new LinkedList<PluggableRenderable>();
|
||||
private RectEvaluable context;
|
||||
|
||||
|
||||
public ElementHolder(AppAccess app) {
|
||||
super(app);
|
||||
}
|
||||
|
||||
|
||||
public ElementHolder(AppAccess app, RectEvaluable context) {
|
||||
super(app);
|
||||
setContext(context);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final void setContext(RectEvaluable context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final void render()
|
||||
{
|
||||
for (final Renderable element : elements) {
|
||||
element.render();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final Rect getRect()
|
||||
{
|
||||
return context.getRect();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 final void attach(PluggableRenderable elem)
|
||||
{
|
||||
if (elem == null) return;
|
||||
|
||||
elements.add(elem);
|
||||
addChildClient(elem);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package mightypork.rogue.gui.renderers;
|
||||
|
||||
|
||||
import mightypork.rogue.render.Render;
|
||||
import mightypork.rogue.textures.TxQuad;
|
||||
|
||||
|
||||
public class ImageRenderer extends PluggableRenderer {
|
||||
|
||||
private TxQuad texture;
|
||||
|
||||
|
||||
public ImageRenderer(TxQuad texture) {
|
||||
this.texture = texture;
|
||||
}
|
||||
|
||||
|
||||
public void setTexture(TxQuad texture)
|
||||
{
|
||||
this.texture = texture;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void render()
|
||||
{
|
||||
Render.quadTextured(getRect(), texture);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package mightypork.rogue.gui.renderers;
|
||||
|
||||
|
||||
import mightypork.rogue.render.Renderable;
|
||||
import mightypork.utils.math.constraints.PluggableContext;
|
||||
import mightypork.utils.math.constraints.RectEvaluable;
|
||||
import mightypork.utils.math.coord.Rect;
|
||||
|
||||
|
||||
public interface PluggableRenderable extends Renderable, PluggableContext {
|
||||
|
||||
@Override
|
||||
void render();
|
||||
|
||||
|
||||
@Override
|
||||
Rect getRect();
|
||||
|
||||
|
||||
@Override
|
||||
void setContext(RectEvaluable rect);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package mightypork.rogue.gui.renderers;
|
||||
|
||||
|
||||
import mightypork.rogue.render.Renderable;
|
||||
import mightypork.utils.math.constraints.ContextAdapter;
|
||||
import mightypork.utils.math.constraints.RectEvaluable;
|
||||
import mightypork.utils.math.coord.Rect;
|
||||
|
||||
|
||||
/**
|
||||
* {@link Renderable} with pluggable context
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public abstract class PluggableRenderer extends ContextAdapter implements PluggableRenderable {
|
||||
|
||||
@Override
|
||||
public abstract void render();
|
||||
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return super.getRect();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setContext(RectEvaluable rect)
|
||||
{
|
||||
super.setContext(rect);
|
||||
}
|
||||
}
|
||||
+9
-12
@@ -1,9 +1,9 @@
|
||||
package mightypork.rogue.gui.constraints;
|
||||
package mightypork.rogue.gui.renderers;
|
||||
|
||||
|
||||
import static mightypork.utils.math.constraints.ConstraintFactory.*;
|
||||
import mightypork.rogue.AppAccess;
|
||||
import mightypork.utils.math.constraints.ConstraintContext;
|
||||
import mightypork.utils.math.constraints.RectEvaluable;
|
||||
|
||||
|
||||
public class RowHolder extends ElementHolder {
|
||||
@@ -12,7 +12,7 @@ public class RowHolder extends ElementHolder {
|
||||
private int row = 0;
|
||||
|
||||
|
||||
public RowHolder(AppAccess app, ConstraintContext context, int rows) {
|
||||
public RowHolder(AppAccess app, RectEvaluable context, int rows) {
|
||||
super(app, context);
|
||||
this.rows = rows;
|
||||
}
|
||||
@@ -29,17 +29,14 @@ public class RowHolder extends ElementHolder {
|
||||
*
|
||||
* @param elem
|
||||
*/
|
||||
public void addRow(PluggableRenderable elem)
|
||||
@Override
|
||||
public void add(final PluggableRenderable elem)
|
||||
{
|
||||
if (elem == null) return;
|
||||
add(elem, c_row(null, rows, row++));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void remove(PluggableRenderable elem)
|
||||
{
|
||||
throw new UnsupportedOperationException("Can't remove from RowHolder.");
|
||||
|
||||
elem.setContext(c_row(this, rows, row++));
|
||||
|
||||
attach(elem);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package mightypork.rogue.gui.renderers;
|
||||
|
||||
|
||||
import mightypork.rogue.fonts.FontRenderer;
|
||||
import mightypork.rogue.fonts.GLFont;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
|
||||
|
||||
public class TextRenderer extends PluggableRenderer {
|
||||
|
||||
public static enum Align
|
||||
{
|
||||
LEFT, CENTER, RIGHT;
|
||||
}
|
||||
|
||||
private FontRenderer font;
|
||||
private String text;
|
||||
private RGB color;
|
||||
private Align align;
|
||||
|
||||
|
||||
public TextRenderer(GLFont font, String text, RGB color, Align align) {
|
||||
this.font = new FontRenderer(font);
|
||||
this.text = text;
|
||||
this.color = color;
|
||||
this.align = align;
|
||||
}
|
||||
|
||||
|
||||
public void setFont(FontRenderer font)
|
||||
{
|
||||
this.font = font;
|
||||
}
|
||||
|
||||
|
||||
public void setText(String text)
|
||||
{
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
|
||||
public void setColor(RGB color)
|
||||
{
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
|
||||
public void setAlign(Align align)
|
||||
{
|
||||
this.align = align;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void render()
|
||||
{
|
||||
final double h = getRect().getHeight();
|
||||
|
||||
final double w = font.getWidth(text, h);
|
||||
|
||||
final Coord start;
|
||||
|
||||
switch (align) {
|
||||
case LEFT:
|
||||
start = getRect().getMin();
|
||||
break;
|
||||
|
||||
case CENTER:
|
||||
start = getRect().getCenterV1().sub_ip(w / 2D, 0);
|
||||
break;
|
||||
|
||||
case RIGHT:
|
||||
default:
|
||||
start = getRect().getX2Y1().sub_ip(w, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
font.draw(text, start, h, color);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import mightypork.rogue.input.KeyBindingPool;
|
||||
import mightypork.rogue.input.KeyStroke;
|
||||
import mightypork.rogue.render.Renderable;
|
||||
import mightypork.utils.control.interf.Destroyable;
|
||||
import mightypork.utils.math.constraints.ConstraintContext;
|
||||
import mightypork.utils.math.constraints.RectEvaluable;
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
import mightypork.utils.math.coord.Rect;
|
||||
|
||||
@@ -20,7 +20,7 @@ import mightypork.utils.math.coord.Rect;
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public abstract class Screen extends ChildClient implements Renderable, Destroyable, KeyBinder, ConstraintContext, ScreenChangeEvent.Listener {
|
||||
public abstract class Screen extends ChildClient implements Renderable, Destroyable, KeyBinder, RectEvaluable, ScreenChangeEvent.Listener {
|
||||
|
||||
private final KeyBindingPool keybindings = new KeyBindingPool();
|
||||
|
||||
@@ -70,7 +70,7 @@ public abstract class Screen extends ChildClient implements Renderable, Destroya
|
||||
active = true;
|
||||
needSetupViewport = true;
|
||||
|
||||
onSizeChanged(getRect().size());
|
||||
onSizeChanged(getRect().getSize());
|
||||
onScreenEnter();
|
||||
|
||||
// enable events
|
||||
|
||||
@@ -6,7 +6,7 @@ import mightypork.rogue.input.KeyBinder;
|
||||
import mightypork.rogue.input.KeyBindingPool;
|
||||
import mightypork.rogue.input.KeyStroke;
|
||||
import mightypork.rogue.render.Renderable;
|
||||
import mightypork.utils.math.constraints.ConstraintContext;
|
||||
import mightypork.utils.math.constraints.RectEvaluable;
|
||||
import mightypork.utils.math.coord.Rect;
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import mightypork.utils.math.coord.Rect;
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public abstract class ScreenLayer extends ChildClient implements Renderable, ConstraintContext, KeyBinder {
|
||||
public abstract class ScreenLayer extends ChildClient implements Renderable, RectEvaluable, KeyBinder {
|
||||
|
||||
private final Screen screen;
|
||||
|
||||
|
||||
@@ -5,37 +5,33 @@ import static mightypork.utils.math.constraints.ConstraintFactory.*;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import mightypork.rogue.gui.constraints.PluggableRenderable;
|
||||
import mightypork.rogue.gui.renderers.PluggableRenderer;
|
||||
import mightypork.rogue.render.Render;
|
||||
import mightypork.utils.control.interf.Updateable;
|
||||
import mightypork.utils.math.animation.AnimDouble;
|
||||
import mightypork.utils.math.animation.Easing;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.constraints.ConstraintContext;
|
||||
import mightypork.utils.math.constraints.NumConstraint;
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
import mightypork.utils.math.coord.Rect;
|
||||
import mightypork.utils.math.constraints.NumEvaluable;
|
||||
import mightypork.utils.math.constraints.RectEvaluable;
|
||||
|
||||
|
||||
public class BouncyBox implements PluggableRenderable, Updateable, ConstraintContext {
|
||||
public class BouncyBox extends PluggableRenderer implements Updateable {
|
||||
|
||||
private final Random rand = new Random();
|
||||
|
||||
private ConstraintContext context;
|
||||
|
||||
private final RectConstraint box;
|
||||
private final RectEvaluable box;
|
||||
|
||||
private final AnimDouble pos = new AnimDouble(0, Easing.BOUNCE_OUT);
|
||||
|
||||
|
||||
public BouncyBox() {
|
||||
// create box
|
||||
final NumConstraint side = c_height(this);
|
||||
RectConstraint abox = c_box_sized(this, side, side);
|
||||
final NumEvaluable side = c_height(this);
|
||||
RectEvaluable abox = c_box(this, side, side);
|
||||
|
||||
// move
|
||||
final NumConstraint move_length = c_sub(c_width(this), side);
|
||||
final NumConstraint offset = c_mul(move_length, c_n(pos));
|
||||
final NumEvaluable move_length = c_sub(c_width(this), side);
|
||||
final NumEvaluable offset = c_mul(move_length, c_n(pos));
|
||||
abox = c_move(abox, offset, c_n(0));
|
||||
|
||||
// add padding
|
||||
@@ -45,13 +41,6 @@ public class BouncyBox implements PluggableRenderable, Updateable, ConstraintCon
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
return context.getRect();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void render()
|
||||
{
|
||||
@@ -59,22 +48,15 @@ public class BouncyBox implements PluggableRenderable, Updateable, ConstraintCon
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setContext(ConstraintContext context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
public void goLeft()
|
||||
{
|
||||
pos.animate(1, 0, 2 + rand.nextDouble() * 1);
|
||||
pos.animate(1, 0, 1 + rand.nextDouble() * 1);
|
||||
}
|
||||
|
||||
|
||||
public void goRight()
|
||||
{
|
||||
pos.animate(0, 1, 2 + rand.nextDouble() * 1);
|
||||
pos.animate(0, 1, 1 + rand.nextDouble() * 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,10 +6,16 @@ import static mightypork.utils.math.constraints.ConstraintFactory.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import mightypork.rogue.gui.constraints.RowHolder;
|
||||
import mightypork.rogue.Res;
|
||||
import mightypork.rogue.gui.renderers.RowHolder;
|
||||
import mightypork.rogue.gui.renderers.TextRenderer;
|
||||
import mightypork.rogue.gui.renderers.TextRenderer.Align;
|
||||
import mightypork.rogue.gui.screens.Screen;
|
||||
import mightypork.rogue.gui.screens.ScreenLayer;
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
import mightypork.rogue.input.KeyStroke;
|
||||
import mightypork.rogue.input.Keys;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.constraints.RectEvaluable;
|
||||
|
||||
|
||||
public class LayerBouncyBoxes extends ScreenLayer {
|
||||
@@ -21,17 +27,37 @@ public class LayerBouncyBoxes extends ScreenLayer {
|
||||
public LayerBouncyBoxes(Screen screen) {
|
||||
super(screen);
|
||||
|
||||
bindKeyStroke(new KeyStroke(true, Keys.KEY_RIGHT), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
goRight();
|
||||
}
|
||||
});
|
||||
|
||||
bindKeyStroke(new KeyStroke(true, Keys.KEY_LEFT), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
goLeft();
|
||||
}
|
||||
});
|
||||
|
||||
// shrink screen rect by 8% on all sides
|
||||
final RectConstraint holder_rect = c_shrink(this, c_percent(c_height(this), c_n(8)));
|
||||
final RectEvaluable holder_rect = c_shrink(this, c_percent(c_height(this), c_n(8)));
|
||||
|
||||
addChildClient(layout = new RowHolder(screen, holder_rect, 16));
|
||||
addChildClient(layout = new RowHolder(screen, holder_rect, 8));
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
for (int i = 0; i < 7; i++) {
|
||||
final BouncyBox bbr = new BouncyBox();
|
||||
layout.addRow(bbr);
|
||||
layout.add(bbr);
|
||||
boxes.add(bbr);
|
||||
}
|
||||
|
||||
layout.add(new TextRenderer(Res.getFont("default"), "This is a text, yo!", RGB.WHITE, Align.LEFT));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,8 +5,7 @@ import mightypork.rogue.AppAccess;
|
||||
import mightypork.rogue.bus.events.ScreenRequestEvent;
|
||||
import mightypork.rogue.gui.screens.LayeredScreen;
|
||||
import mightypork.rogue.input.KeyStroke;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import mightypork.rogue.input.Keys;
|
||||
|
||||
|
||||
public class ScreenTestBouncy extends LayeredScreen {
|
||||
@@ -21,25 +20,7 @@ public class ScreenTestBouncy extends LayeredScreen {
|
||||
|
||||
addLayer(layer);
|
||||
|
||||
bindKeyStroke(new KeyStroke(true, Keyboard.KEY_RIGHT), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
layer.goRight();
|
||||
}
|
||||
});
|
||||
|
||||
bindKeyStroke(new KeyStroke(true, Keyboard.KEY_LEFT), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
layer.goLeft();
|
||||
}
|
||||
});
|
||||
|
||||
bindKeyStroke(new KeyStroke(Keyboard.KEY_C), new Runnable() {
|
||||
bindKeyStroke(new KeyStroke(Keys.KEY_C), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
|
||||
@@ -7,45 +7,60 @@ import java.util.Random;
|
||||
|
||||
import mightypork.rogue.Res;
|
||||
import mightypork.rogue.bus.events.MouseButtonEvent;
|
||||
import mightypork.rogue.gui.renderers.ImageRenderer;
|
||||
import mightypork.rogue.gui.renderers.TextRenderer;
|
||||
import mightypork.rogue.gui.renderers.TextRenderer.Align;
|
||||
import mightypork.rogue.gui.screens.Screen;
|
||||
import mightypork.rogue.gui.screens.ScreenLayer;
|
||||
import mightypork.rogue.input.KeyStroke;
|
||||
import mightypork.rogue.render.Render;
|
||||
import mightypork.rogue.input.Keys;
|
||||
import mightypork.utils.control.interf.Updateable;
|
||||
import mightypork.utils.math.animation.AnimDouble;
|
||||
import mightypork.utils.math.animation.Easing;
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.constraints.RectEvaluable;
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.newdawn.slick.opengl.Texture;
|
||||
|
||||
|
||||
public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButtonEvent.Listener {
|
||||
|
||||
private final RectConstraint kittenbox;
|
||||
|
||||
private final AnimDouble s = new AnimDouble(400, Easing.SINE_BOTH);
|
||||
private final AnimDouble x = new AnimDouble(200, Easing.ELASTIC_OUT);
|
||||
private final AnimDouble y = new AnimDouble(200, Easing.ELASTIC_OUT);
|
||||
private final AnimDouble size = new AnimDouble(400, Easing.SINE_BOTH);
|
||||
private final AnimDouble xPos = new AnimDouble(200, Easing.ELASTIC_OUT);
|
||||
private final AnimDouble yPos = new AnimDouble(200, Easing.ELASTIC_OUT);
|
||||
|
||||
private final Random rand = new Random();
|
||||
|
||||
private final Texture cat_tx = Res.getTexture("test.kitten");
|
||||
private final ImageRenderer cat;
|
||||
private final TextRenderer text;
|
||||
|
||||
|
||||
public LayerFlyingCat(Screen screen) {
|
||||
super(screen);
|
||||
|
||||
kittenbox = c_move(c_box_sized(this, c_n(s), c_n(s)), c_n(x), c_n(y));
|
||||
xPos.setTo(disp().getWidth() / 2);
|
||||
yPos.setTo(disp().getHeight() / 2);
|
||||
|
||||
bindKeyStroke(new KeyStroke(Keyboard.KEY_RETURN), new Runnable() {
|
||||
cat = new ImageRenderer(Res.getTxQuad("test.kitten"));
|
||||
cat.setContext(c_centered(c_box(this, c_n(size), c_n(size)), c_n(xPos), c_n(yPos)));
|
||||
|
||||
//@formatter:off
|
||||
final RectEvaluable flyingFontBox = c_centered(
|
||||
c_box(this, c_n(0), c_n(64)),
|
||||
input().c_mouse_x(),
|
||||
input().c_mouse_y()
|
||||
);
|
||||
//@formatter:on
|
||||
|
||||
text = new TextRenderer(Res.getFont("default"), "YO", RGB.YELLOW, Align.CENTER);
|
||||
text.setContext(flyingFontBox);
|
||||
|
||||
bindKeyStroke(new KeyStroke(Keys.KEY_RETURN), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
x.fadeTo(disp().getWidth() / 2 - s.getTo() / 2, 2);
|
||||
y.fadeTo(disp().getHeight() / 2 - s.getTo() / 2, 2);
|
||||
xPos.fadeTo(disp().getWidth() / 2, 2);
|
||||
yPos.fadeTo(disp().getHeight() / 2, 2);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -54,9 +69,9 @@ public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButt
|
||||
@Override
|
||||
public void update(double delta)
|
||||
{
|
||||
s.update(delta);
|
||||
x.update(delta);
|
||||
y.update(delta);
|
||||
size.update(delta);
|
||||
xPos.update(delta);
|
||||
yPos.update(delta);
|
||||
}
|
||||
|
||||
|
||||
@@ -67,20 +82,19 @@ public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButt
|
||||
|
||||
final Coord pos = event.getPos();
|
||||
|
||||
final double newSize = 200 + rand.nextInt(600);
|
||||
|
||||
final double t = 2;
|
||||
|
||||
s.fadeTo(newSize, t / 2D);
|
||||
x.fadeTo(pos.x - newSize / 2D, t);
|
||||
y.fadeTo(pos.y - newSize / 2D, t);
|
||||
size.fadeTo(100 + rand.nextInt(700), t / 2D);
|
||||
xPos.fadeTo(pos.x, t);
|
||||
yPos.fadeTo(pos.y, t);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void render()
|
||||
{
|
||||
Render.quadTextured(kittenbox.getRect(), cat_tx);
|
||||
cat.render();
|
||||
text.render();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,8 +8,7 @@ import mightypork.rogue.bus.events.ActionRequest.RequestType;
|
||||
import mightypork.rogue.bus.events.ScreenRequestEvent;
|
||||
import mightypork.rogue.gui.screens.LayeredScreen;
|
||||
import mightypork.rogue.input.KeyStroke;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import mightypork.rogue.input.Keys;
|
||||
|
||||
|
||||
public class ScreenTestCat extends LayeredScreen {
|
||||
@@ -22,7 +21,7 @@ public class ScreenTestCat extends LayeredScreen {
|
||||
|
||||
addLayer(layer = new LayerFlyingCat(this));
|
||||
|
||||
bindKeyStroke(new KeyStroke(Keyboard.KEY_ESCAPE), new Runnable() {
|
||||
bindKeyStroke(new KeyStroke(Keys.KEY_ESCAPE), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
@@ -32,7 +31,7 @@ public class ScreenTestCat extends LayeredScreen {
|
||||
}
|
||||
});
|
||||
|
||||
bindKeyStroke(new KeyStroke(Keyboard.KEY_B), new Runnable() {
|
||||
bindKeyStroke(new KeyStroke(Keys.KEY_B), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
|
||||
@@ -3,16 +3,21 @@ package mightypork.rogue.gui.screens.test_font;
|
||||
|
||||
import mightypork.rogue.AppAccess;
|
||||
import mightypork.rogue.Res;
|
||||
import mightypork.rogue.fonts.GLFont;
|
||||
import mightypork.rogue.fonts.FontRenderer;
|
||||
import mightypork.rogue.gui.screens.Screen;
|
||||
import mightypork.rogue.render.Render;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
|
||||
|
||||
public class ScreenTestFont extends Screen {
|
||||
|
||||
private final FontRenderer fr;
|
||||
|
||||
|
||||
public ScreenTestFont(AppAccess app) {
|
||||
super(app);
|
||||
|
||||
fr = new FontRenderer(Res.getFont("default"));
|
||||
}
|
||||
|
||||
|
||||
@@ -40,15 +45,24 @@ public class ScreenTestFont extends Screen {
|
||||
@Override
|
||||
protected void renderScreen()
|
||||
{
|
||||
final GLFont font = Res.getFont("PolygonPixel_16");
|
||||
final String str = "O hai";
|
||||
|
||||
final String s = "It works!";
|
||||
final double scale = getRect().height() / 50D;
|
||||
Render.pushState();
|
||||
Render.translate(getRect().getCenter().sub(font.getNeededSpace(s).mul(scale).half()));
|
||||
Render.scale(new Coord(scale));
|
||||
font.draw("It works!");
|
||||
Render.popState();
|
||||
final double height = getRect().getHeight() / 5D;
|
||||
final Coord space = fr.getNeededSpace(str, height);
|
||||
|
||||
final Coord origin = getRect().getCenter().sub(space.half());
|
||||
|
||||
fr.draw(str, origin, height, RGB.GREEN);
|
||||
|
||||
// final GLFont font = Res.getFont("");
|
||||
//
|
||||
// final String s = "It works!";
|
||||
// final double scale = getRect().height() / 50D;
|
||||
// Render.pushState();
|
||||
// Render.translate(getRect().getCenter().sub(font.getNeededSpace(s).mul(scale).half()));
|
||||
// Render.scale(new Coord(scale));
|
||||
// font.draw("It works!");
|
||||
// Render.popState();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import mightypork.rogue.bus.events.KeyboardEvent;
|
||||
import mightypork.rogue.bus.events.MouseButtonEvent;
|
||||
import mightypork.rogue.bus.events.MouseMotionEvent;
|
||||
import mightypork.utils.control.interf.Updateable;
|
||||
import mightypork.utils.math.constraints.NumEvaluable;
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
|
||||
import org.lwjgl.LWJGLException;
|
||||
@@ -154,4 +155,53 @@ public class InputSystem extends Subsystem implements Updateable, KeyBinder {
|
||||
{
|
||||
this.yAxisDown = yAxisDown;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get absolute mouse position
|
||||
*
|
||||
* @return mouse position
|
||||
*/
|
||||
public Coord getMousePos()
|
||||
{
|
||||
final Coord pos = new Coord(Mouse.getX(), Mouse.getY());
|
||||
flipScrY(pos);
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
||||
public void grabMouse(boolean grab)
|
||||
{
|
||||
Mouse.setGrabbed(grab);
|
||||
}
|
||||
|
||||
private final NumEvaluable cmousex = new NumEvaluable() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return getMousePos().x;
|
||||
}
|
||||
};
|
||||
|
||||
private final NumEvaluable cmousey = new NumEvaluable() {
|
||||
|
||||
@Override
|
||||
public double getValue()
|
||||
{
|
||||
return getMousePos().y;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public NumEvaluable c_mouse_x()
|
||||
{
|
||||
return cmousex;
|
||||
}
|
||||
|
||||
|
||||
public NumEvaluable c_mouse_y()
|
||||
{
|
||||
return cmousey;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
package mightypork.rogue.input;
|
||||
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
|
||||
/**
|
||||
* Key constants, from LWJGL {@link Keyboard}
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public interface Keys {
|
||||
|
||||
//@formatter:off
|
||||
|
||||
public static final int CHAR_NONE = '\0';
|
||||
|
||||
public static final int KEY_NONE = 0x00;
|
||||
|
||||
public static final int KEY_ESCAPE = 0x01;
|
||||
|
||||
public static final int KEY_1 = 0x02;
|
||||
public static final int KEY_2 = 0x03;
|
||||
public static final int KEY_3 = 0x04;
|
||||
public static final int KEY_4 = 0x05;
|
||||
public static final int KEY_5 = 0x06;
|
||||
public static final int KEY_6 = 0x07;
|
||||
public static final int KEY_7 = 0x08;
|
||||
public static final int KEY_8 = 0x09;
|
||||
public static final int KEY_9 = 0x0A;
|
||||
public static final int KEY_0 = 0x0B;
|
||||
|
||||
public static final int KEY_Q = 0x10;
|
||||
public static final int KEY_W = 0x11;
|
||||
public static final int KEY_E = 0x12;
|
||||
public static final int KEY_R = 0x13;
|
||||
public static final int KEY_T = 0x14;
|
||||
public static final int KEY_Y = 0x15;
|
||||
public static final int KEY_U = 0x16;
|
||||
public static final int KEY_I = 0x17;
|
||||
public static final int KEY_O = 0x18;
|
||||
public static final int KEY_P = 0x19;
|
||||
public static final int KEY_A = 0x1E;
|
||||
public static final int KEY_S = 0x1F;
|
||||
public static final int KEY_D = 0x20;
|
||||
public static final int KEY_F = 0x21;
|
||||
public static final int KEY_G = 0x22;
|
||||
public static final int KEY_H = 0x23;
|
||||
public static final int KEY_J = 0x24;
|
||||
public static final int KEY_K = 0x25;
|
||||
public static final int KEY_L = 0x26;
|
||||
public static final int KEY_Z = 0x2C;
|
||||
public static final int KEY_X = 0x2D;
|
||||
public static final int KEY_C = 0x2E;
|
||||
public static final int KEY_V = 0x2F;
|
||||
public static final int KEY_B = 0x30;
|
||||
public static final int KEY_N = 0x31;
|
||||
public static final int KEY_M = 0x32;
|
||||
|
||||
public static final int KEY_MINUS = 0x0C;
|
||||
public static final int KEY_EQUALS = 0x0D;
|
||||
public static final int KEY_SLASH = 0x35;
|
||||
public static final int KEY_BACKSLASH = 0x2B;
|
||||
public static final int KEY_LBRACKET = 0x1A;
|
||||
public static final int KEY_RBRACKET = 0x1B;
|
||||
public static final int KEY_SEMICOLON = 0x27;
|
||||
public static final int KEY_APOSTROPHE = 0x28;
|
||||
public static final int KEY_GRAVE = 0x29;
|
||||
public static final int KEY_COMMA = 0x33;
|
||||
public static final int KEY_PERIOD = 0x34;
|
||||
|
||||
public static final int KEY_SPACE = 0x39;
|
||||
public static final int KEY_BACKSPACE = 0x0E;
|
||||
public static final int KEY_TAB = 0x0F;
|
||||
|
||||
public static final int KEY_F1 = 0x3B;
|
||||
public static final int KEY_F2 = 0x3C;
|
||||
public static final int KEY_F3 = 0x3D;
|
||||
public static final int KEY_F4 = 0x3E;
|
||||
public static final int KEY_F5 = 0x3F;
|
||||
public static final int KEY_F6 = 0x40;
|
||||
public static final int KEY_F7 = 0x41;
|
||||
public static final int KEY_F8 = 0x42;
|
||||
public static final int KEY_F9 = 0x43;
|
||||
public static final int KEY_F10 = 0x44;
|
||||
public static final int KEY_F11 = 0x57;
|
||||
public static final int KEY_F12 = 0x58;
|
||||
public static final int KEY_F13 = 0x64;
|
||||
public static final int KEY_F14 = 0x65;
|
||||
public static final int KEY_F15 = 0x66;
|
||||
|
||||
public static final int KEY_CAPSLOCK = 0x3A;
|
||||
public static final int KEY_SCROLLLOCK = 0x46;
|
||||
public static final int KEY_NUMLOCK = 0x45;
|
||||
|
||||
public static final int KEY_SUBTRACT = 0x4A; /* - on numeric keypad */
|
||||
public static final int KEY_ADD = 0x4E; /* + on numeric keypad */
|
||||
public static final int KEY_NUMPAD0 = 0x52;
|
||||
public static final int KEY_NUMPAD1 = 0x4F;
|
||||
public static final int KEY_NUMPAD2 = 0x50;
|
||||
public static final int KEY_NUMPAD3 = 0x51;
|
||||
public static final int KEY_NUMPAD4 = 0x4B;
|
||||
public static final int KEY_NUMPAD5 = 0x4C;
|
||||
public static final int KEY_NUMPAD6 = 0x4D;
|
||||
public static final int KEY_NUMPAD7 = 0x47;
|
||||
public static final int KEY_NUMPAD8 = 0x48;
|
||||
public static final int KEY_NUMPAD9 = 0x49;
|
||||
public static final int KEY_DECIMAL = 0x53; /* . on numeric keypad */
|
||||
public static final int KEY_NUMPADENTER = 0x9C; /* Enter on numeric keypad */
|
||||
public static final int KEY_DIVIDE = 0xB5; /* / on numeric keypad */
|
||||
public static final int KEY_MULTIPLY = 0x37; /* * on numeric keypad */
|
||||
|
||||
public static final int KEY_LCONTROL = 0x1D;
|
||||
public static final int KEY_RCONTROL = 0x9D;
|
||||
public static final int KEY_LALT = 0x38;
|
||||
public static final int KEY_RALT = 0xB8;
|
||||
public static final int KEY_LSHIFT = 0x2A;
|
||||
public static final int KEY_RSHIFT = 0x36;
|
||||
public static final int KEY_LMETA = 0xDB;
|
||||
public static final int KEY_RMETA = 0xDC;
|
||||
|
||||
|
||||
public static final int KEY_UP = 0xC8; /* UpArrow on arrow keypad */
|
||||
public static final int KEY_DOWN = 0xD0; /* DownArrow on arrow keypad */
|
||||
public static final int KEY_LEFT = 0xCB; /* LeftArrow on arrow keypad */
|
||||
public static final int KEY_RIGHT = 0xCD; /* RightArrow on arrow keypad */
|
||||
|
||||
public static final int KEY_HOME = 0xC7; /* Home on arrow keypad */
|
||||
public static final int KEY_END = 0xCF; /* End on arrow keypad */
|
||||
|
||||
public static final int KEY_PAGEUP = 0xC9; /* PgUp on arrow keypad */
|
||||
public static final int KEY_PAGEDOWN = 0xD1; /* PgDn on arrow keypad */
|
||||
|
||||
public static final int KEY_RETURN = 0x1C;
|
||||
public static final int KEY_PAUSE = 0xC5; /* Pause */
|
||||
public static final int KEY_INSERT = 0xD2; /* Insert on arrow keypad */
|
||||
public static final int KEY_DELETE = 0xD3; /* Delete on arrow keypad */
|
||||
|
||||
//@formatter:on
|
||||
}
|
||||
@@ -64,7 +64,7 @@ public class AsyncResourceLoader extends Thread implements ResourceLoadRequest.L
|
||||
// textures & fonts needs to be loaded in main thread
|
||||
if (def.getClass().isAnnotationPresent(MustLoadInMainThread.class)) {
|
||||
|
||||
Log.f3("<LOADER> Delegating to main thread:\n "+Log.str(def));
|
||||
Log.f3("<LOADER> Delegating to main thread:\n " + Log.str(def));
|
||||
|
||||
app.bus().send(new MainLoopTaskRequest(new Runnable() {
|
||||
|
||||
@@ -78,7 +78,7 @@ public class AsyncResourceLoader extends Thread implements ResourceLoadRequest.L
|
||||
continue;
|
||||
}
|
||||
|
||||
Log.f3("<LOADER> Loading async:\n "+Log.str(def));
|
||||
Log.f3("<LOADER> Loading async:\n " + Log.str(def));
|
||||
|
||||
exs.submit(new Runnable() {
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import mightypork.rogue.AppAccess;
|
||||
import mightypork.rogue.bus.Subsystem;
|
||||
import mightypork.rogue.bus.events.ScreenChangeEvent;
|
||||
import mightypork.utils.logging.Log;
|
||||
import mightypork.utils.math.constraints.ConstraintContext;
|
||||
import mightypork.utils.math.constraints.RectEvaluable;
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
import mightypork.utils.math.coord.Rect;
|
||||
|
||||
@@ -19,7 +19,7 @@ import org.lwjgl.opengl.Display;
|
||||
import org.lwjgl.opengl.DisplayMode;
|
||||
|
||||
|
||||
public class DisplaySystem extends Subsystem implements ConstraintContext {
|
||||
public class DisplaySystem extends Subsystem implements RectEvaluable {
|
||||
|
||||
private DisplayMode windowDisplayMode;
|
||||
private int targetFps;
|
||||
|
||||
@@ -12,7 +12,7 @@ import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
import mightypork.utils.math.coord.Rect;
|
||||
|
||||
import org.newdawn.slick.opengl.SlickCallable;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.newdawn.slick.opengl.Texture;
|
||||
import org.newdawn.slick.opengl.TextureImpl;
|
||||
import org.newdawn.slick.opengl.TextureLoader;
|
||||
@@ -48,6 +48,11 @@ public class Render {
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
}
|
||||
|
||||
|
||||
@@ -96,6 +101,17 @@ public class Render {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Scale by X factor
|
||||
*
|
||||
* @param factor scaling factor
|
||||
*/
|
||||
public static void scaleXY(double factor)
|
||||
{
|
||||
glScaled(factor, factor, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Scale by X factor
|
||||
*
|
||||
@@ -174,13 +190,25 @@ public class Render {
|
||||
glRotated(angle, vec.x, vec.y, vec.z);
|
||||
}
|
||||
|
||||
private static int pushed = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Store GL state
|
||||
*/
|
||||
public static void pushState()
|
||||
{
|
||||
SlickCallable.enterSafeBlock();
|
||||
pushed++;
|
||||
|
||||
if (pushed >= 3) {
|
||||
Log.w("Suspicious amount of state pushes: " + pushed);
|
||||
}
|
||||
|
||||
// Log.f3("push : "+pushed);
|
||||
|
||||
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
|
||||
GL11.glPushClientAttrib(GL11.GL_ALL_CLIENT_ATTRIB_BITS);
|
||||
GL11.glPushMatrix();
|
||||
}
|
||||
|
||||
|
||||
@@ -189,7 +217,17 @@ public class Render {
|
||||
*/
|
||||
public static void popState()
|
||||
{
|
||||
SlickCallable.leaveSafeBlock();
|
||||
if (pushed == 0) {
|
||||
Log.w("Pop without push.");
|
||||
}
|
||||
|
||||
pushed--;
|
||||
|
||||
// Log.f3("pop : "+pushed);
|
||||
|
||||
GL11.glPopMatrix();
|
||||
GL11.glPopClientAttrib();
|
||||
GL11.glPopAttrib();
|
||||
}
|
||||
|
||||
|
||||
@@ -278,10 +316,10 @@ public class Render {
|
||||
*/
|
||||
public static void quad(Rect quad)
|
||||
{
|
||||
final double left = quad.xMin();
|
||||
final double bottom = quad.yMin();
|
||||
final double right = quad.xMax();
|
||||
final double top = quad.yMax();
|
||||
final double left = quad.x1();
|
||||
final double bottom = quad.y1();
|
||||
final double right = quad.x2();
|
||||
final double top = quad.y2();
|
||||
|
||||
// draw with color
|
||||
unbindTexture();
|
||||
@@ -318,15 +356,15 @@ public class Render {
|
||||
*/
|
||||
public static void quadUV_nobound(Rect quad, Rect uvs)
|
||||
{
|
||||
final double left = quad.xMin();
|
||||
final double bottom = quad.yMin();
|
||||
final double right = quad.xMax();
|
||||
final double top = quad.yMax();
|
||||
final double left = quad.x1();
|
||||
final double bottom = quad.y1();
|
||||
final double right = quad.x2();
|
||||
final double top = quad.y2();
|
||||
|
||||
final double tleft = uvs.xMin();
|
||||
final double tbottom = uvs.yMin();
|
||||
final double tright = uvs.xMax();
|
||||
final double ttop = uvs.yMax();
|
||||
final double tleft = uvs.x1();
|
||||
final double tbottom = uvs.y1();
|
||||
final double tright = uvs.x2();
|
||||
final double ttop = uvs.y2();
|
||||
|
||||
// quad with texture
|
||||
glTexCoord2d(tleft, ttop);
|
||||
@@ -342,10 +380,10 @@ public class Render {
|
||||
|
||||
public static void quadGradH(Rect quad, RGB colorLeft, RGB colorRight)
|
||||
{
|
||||
final double left = quad.xMin();
|
||||
final double bottom = quad.yMin();
|
||||
final double right = quad.yMax();
|
||||
final double top = quad.yMax();
|
||||
final double left = quad.x1();
|
||||
final double bottom = quad.y1();
|
||||
final double right = quad.y2();
|
||||
final double top = quad.y2();
|
||||
|
||||
// draw with color
|
||||
unbindTexture();
|
||||
@@ -366,10 +404,10 @@ public class Render {
|
||||
|
||||
public static void quadGradV(Rect quad, RGB colorTop, RGB colorBottom)
|
||||
{
|
||||
final double left = quad.xMin();
|
||||
final double bottom = quad.yMin();
|
||||
final double right = quad.yMax();
|
||||
final double top = quad.yMax();
|
||||
final double left = quad.x1();
|
||||
final double bottom = quad.y1();
|
||||
final double right = quad.y2();
|
||||
final double top = quad.y2();
|
||||
|
||||
// draw with color
|
||||
unbindTexture();
|
||||
@@ -396,9 +434,11 @@ public class Render {
|
||||
*/
|
||||
public static void quadTextured(Rect quad, Rect uvs, Texture texture, RGB tint)
|
||||
{
|
||||
pushState();
|
||||
bindTexture(texture);
|
||||
setColor(tint);
|
||||
quadUV(quad, uvs);
|
||||
popState();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import org.newdawn.slick.openal.SoundStore;
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
@LoggedName(name="Audio")
|
||||
@LoggedName(name = "Audio")
|
||||
public class DeferredAudio extends BaseDeferredResource {
|
||||
|
||||
private enum PlayMode
|
||||
|
||||
@@ -11,7 +11,7 @@ import mightypork.utils.logging.LoggedName;
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
@LoggedName(name="NullAudio")
|
||||
@LoggedName(name = "NullAudio")
|
||||
public class NullAudio extends DeferredAudio implements NullResource {
|
||||
|
||||
public NullAudio() {
|
||||
|
||||
@@ -17,7 +17,7 @@ import org.newdawn.slick.opengl.Texture;
|
||||
* @author MightyPork
|
||||
*/
|
||||
@MustLoadInMainThread
|
||||
@LoggedName(name="Texture")
|
||||
@LoggedName(name = "Texture")
|
||||
public class DeferredTexture extends BaseDeferredResource implements FilteredTexture {
|
||||
|
||||
private Texture backingTexture;
|
||||
|
||||
@@ -62,6 +62,8 @@ public class TextureBank extends AppAdapter {
|
||||
|
||||
textures.put(key, tx);
|
||||
lastTx = tx;
|
||||
|
||||
makeQuad(key, Rect.one());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ public class TxQuad {
|
||||
|
||||
/**
|
||||
* @param tx Texture
|
||||
* @param uvs Rect of texturwe UVs (pixels - from left top)
|
||||
* @param uvs Rect of texture UVs (0-1)
|
||||
*/
|
||||
public TxQuad(Texture tx, Rect uvs) {
|
||||
this.tx = tx;
|
||||
|
||||
@@ -1,58 +1,67 @@
|
||||
package mightypork.rogue.util;
|
||||
|
||||
|
||||
import mightypork.utils.logging.LogInstance;
|
||||
|
||||
import org.newdawn.slick.util.LogSystem;
|
||||
|
||||
|
||||
public class SlickLogRedirector implements LogSystem {
|
||||
|
||||
LogInstance l;
|
||||
|
||||
|
||||
|
||||
public SlickLogRedirector(LogInstance log) {
|
||||
this.l = log;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void error(String msg, Throwable e)
|
||||
{
|
||||
l.e(msg, e);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void error(Throwable e)
|
||||
{
|
||||
l.e(e);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void error(String msg)
|
||||
{
|
||||
l.e(msg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void warn(String msg)
|
||||
{
|
||||
l.w(msg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void warn(String msg, Throwable e)
|
||||
{
|
||||
l.e(msg, e);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void info(String msg)
|
||||
{
|
||||
l.i(msg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void debug(String msg)
|
||||
{
|
||||
l.f3(msg);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user