tweaked gradient rendering
This commit is contained in:
@@ -10,7 +10,7 @@ import mightypork.gamecore.audio.players.LoopPlayer;
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.control.bus.clients.RootBusNode;
|
||||
import mightypork.gamecore.control.bus.events.ResourceLoadRequest;
|
||||
import mightypork.gamecore.control.interf.Updateable;
|
||||
import mightypork.gamecore.control.timing.Updateable;
|
||||
import mightypork.utils.math.Calc.Buffers;
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ package mightypork.gamecore.audio.players;
|
||||
|
||||
import mightypork.gamecore.audio.DeferredAudio;
|
||||
import mightypork.gamecore.audio.Volume;
|
||||
import mightypork.gamecore.control.interf.Updateable;
|
||||
import mightypork.gamecore.control.timing.Pauseable;
|
||||
import mightypork.gamecore.control.timing.Updateable;
|
||||
import mightypork.utils.math.animation.AnimDouble;
|
||||
|
||||
import org.lwjgl.openal.AL10;
|
||||
|
||||
@@ -10,7 +10,7 @@ import mightypork.gamecore.control.bus.EventBus;
|
||||
import mightypork.gamecore.control.bus.events.*;
|
||||
import mightypork.gamecore.control.interf.Destroyable;
|
||||
import mightypork.gamecore.control.interf.NoImpl;
|
||||
import mightypork.gamecore.control.interf.Updateable;
|
||||
import mightypork.gamecore.control.timing.Updateable;
|
||||
import mightypork.gamecore.gui.screens.ScreenRegistry;
|
||||
import mightypork.gamecore.input.InputSystem;
|
||||
import mightypork.gamecore.loading.AsyncResourceLoader;
|
||||
|
||||
@@ -3,7 +3,7 @@ package mightypork.gamecore.control.bus.events;
|
||||
|
||||
import mightypork.gamecore.control.bus.events.types.ImmediateEvent;
|
||||
import mightypork.gamecore.control.bus.events.types.UnloggedEvent;
|
||||
import mightypork.gamecore.control.interf.Updateable;
|
||||
import mightypork.gamecore.control.timing.Updateable;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package mightypork.gamecore.control.interf;
|
||||
package mightypork.gamecore.control.timing;
|
||||
|
||||
|
||||
/**
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
package mightypork.gamecore.gui.constraints;
|
||||
package mightypork.gamecore.control.timing;
|
||||
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import mightypork.gamecore.control.interf.Pollable;
|
||||
import mightypork.gamecore.gui.constraints.RectCache;
|
||||
|
||||
|
||||
/**
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package mightypork.gamecore.control.interf;
|
||||
package mightypork.gamecore.control.timing;
|
||||
|
||||
|
||||
/**
|
||||
@@ -0,0 +1,56 @@
|
||||
package mightypork.gamecore.gui.components.painters;
|
||||
|
||||
|
||||
import mightypork.gamecore.gui.components.PluggableRenderer;
|
||||
import mightypork.gamecore.render.Render;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
|
||||
|
||||
/**
|
||||
* Draws image in given rect
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public class QuadPainter extends PluggableRenderer {
|
||||
|
||||
private final RGB colorHMinVMin;
|
||||
private final RGB colorHMaxVMin;
|
||||
private final RGB colorHMaxVMax;
|
||||
private final RGB colorHMinVMax;
|
||||
|
||||
|
||||
/**
|
||||
* Painter with cokloured vertices.
|
||||
*
|
||||
* @param colorHMinVMin
|
||||
* @param colorHMaxVMin
|
||||
* @param colorHMaxVMax
|
||||
* @param colorHMinVMax
|
||||
*/
|
||||
public QuadPainter(RGB colorHMinVMin, RGB colorHMaxVMin, RGB colorHMaxVMax, RGB colorHMinVMax) {
|
||||
this.colorHMinVMin = colorHMinVMin;
|
||||
this.colorHMaxVMin = colorHMaxVMin;
|
||||
this.colorHMaxVMax = colorHMaxVMax;
|
||||
this.colorHMinVMax = colorHMinVMax;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void render()
|
||||
{
|
||||
Render.quadColor(getRect(), colorHMinVMin, colorHMaxVMin, colorHMaxVMax, colorHMinVMax);
|
||||
}
|
||||
|
||||
|
||||
public static QuadPainter gradH(RGB colorLeft, RGB colorRight)
|
||||
{
|
||||
return new QuadPainter(colorLeft, colorRight, colorRight, colorLeft);
|
||||
}
|
||||
|
||||
|
||||
public static QuadPainter gradV(RGB colorTop, RGB colorBottom)
|
||||
{
|
||||
return new QuadPainter(colorTop, colorTop, colorBottom, colorBottom);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package mightypork.gamecore.gui.constraints;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.timing.Poller;
|
||||
import mightypork.gamecore.input.InputSystem;
|
||||
import mightypork.gamecore.render.DisplaySystem;
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
@@ -352,7 +353,7 @@ public class Constraints {
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _shrink_up(final RectConstraint r, final Object shrink)
|
||||
public static RectConstraint _shrink_top(final RectConstraint r, final Object shrink)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@@ -365,7 +366,7 @@ public class Constraints {
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _shrink_down(final RectConstraint r, final Object shrink)
|
||||
public static RectConstraint _shrink_bottom(final RectConstraint r, final Object shrink)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@@ -484,6 +485,12 @@ public class Constraints {
|
||||
|
||||
/* ================= Box creation ================= */
|
||||
|
||||
public static RectConstraint _box(final Object side)
|
||||
{
|
||||
return _box(side, side);
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _box(final Object width, final Object height)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
@@ -565,6 +572,22 @@ public class Constraints {
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint _centered(final RectConstraint r, final RectConstraint centerTo)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
final Coord size = r.getRect().getSize();
|
||||
final Coord center = centerTo.getRect().getCenter();
|
||||
|
||||
return Rect.fromSize(center.x - size.x / 2D, center.y - size.y / 2D, size.x, size.y);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Center rect around given coords
|
||||
*
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package mightypork.gamecore.gui.constraints;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.interf.Pollable;
|
||||
import mightypork.gamecore.control.timing.Pollable;
|
||||
import mightypork.gamecore.control.timing.Poller;
|
||||
import mightypork.utils.math.coord.Rect;
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import mightypork.gamecore.control.bus.clients.RootBusNode;
|
||||
import mightypork.gamecore.control.bus.events.KeyEvent;
|
||||
import mightypork.gamecore.control.bus.events.MouseButtonEvent;
|
||||
import mightypork.gamecore.control.bus.events.MouseMotionEvent;
|
||||
import mightypork.gamecore.control.interf.Updateable;
|
||||
import mightypork.gamecore.control.timing.Updateable;
|
||||
import mightypork.gamecore.render.DisplaySystem;
|
||||
import mightypork.rogue.events.ActionRequest;
|
||||
import mightypork.rogue.events.ActionRequest.RequestType;
|
||||
|
||||
@@ -357,10 +357,25 @@ public class Render {
|
||||
* Draw quad with horizontal gradient
|
||||
*
|
||||
* @param quad drawn quad bounds
|
||||
* @param colorLeft left color
|
||||
* @param colorRight right color
|
||||
* @param color1 left color
|
||||
* @param color2 right color
|
||||
*/
|
||||
public static void quadGradH(Rect quad, RGB colorLeft, RGB colorRight)
|
||||
public static void quadGradH(Rect quad, RGB color1, RGB color2)
|
||||
{
|
||||
quadColor(quad, color1, color2, color2, color1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw quad with coloured vertices.
|
||||
*
|
||||
* @param quad drawn quad bounds
|
||||
* @param colorHMinVMin
|
||||
* @param colorHMaxVMin
|
||||
* @param colorHMaxVMax
|
||||
* @param colorHMinVMax
|
||||
*/
|
||||
public static void quadColor(Rect quad, RGB colorHMinVMin, RGB colorHMaxVMin, RGB colorHMaxVMax, RGB colorHMinVMax)
|
||||
{
|
||||
final double x1 = quad.xMin();
|
||||
final double y1 = quad.yMin();
|
||||
@@ -371,14 +386,14 @@ public class Render {
|
||||
unbindTexture();
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
setColor(colorLeft);
|
||||
setColor(colorHMinVMax);
|
||||
glVertex2d(x1, y2);
|
||||
setColor(colorRight);
|
||||
setColor(colorHMaxVMax);
|
||||
glVertex2d(x2, y2);
|
||||
|
||||
setColor(colorRight);
|
||||
setColor(colorHMaxVMin);
|
||||
glVertex2d(x2, y1);
|
||||
setColor(colorLeft);
|
||||
setColor(colorHMinVMin);
|
||||
glVertex2d(x1, y1);
|
||||
glEnd();
|
||||
}
|
||||
@@ -393,23 +408,7 @@ public class Render {
|
||||
*/
|
||||
public static void quadGradV(Rect quad, RGB color1, RGB color2)
|
||||
{
|
||||
final double x1 = quad.xMin();
|
||||
final double y1 = quad.yMin();
|
||||
final double x2 = quad.xMax();
|
||||
final double y2 = quad.yMax();
|
||||
|
||||
// draw with color
|
||||
unbindTexture();
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
setColor(color1);
|
||||
glVertex2d(x1, y1);
|
||||
glVertex2d(x2, y1);
|
||||
|
||||
setColor(color2);
|
||||
glVertex2d(x2, y2);
|
||||
glVertex2d(x1, y2);
|
||||
glEnd();
|
||||
quadColor(quad, color1, color1, color2, color2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -56,21 +56,62 @@ public class App extends BaseApp {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle a crash
|
||||
*
|
||||
* @param error
|
||||
*/
|
||||
public static void onCrash(Throwable error)
|
||||
@Override
|
||||
protected void initScreens(ScreenRegistry screens)
|
||||
{
|
||||
if (Log.ready()) {
|
||||
Log.e("The game has crashed!", error);
|
||||
} else {
|
||||
System.err.println("The game has crashed!");
|
||||
error.printStackTrace();
|
||||
}
|
||||
screens.add(new ScreenTestBouncy(this));
|
||||
screens.add(new ScreenTestCat(this));
|
||||
screens.add(new ScreenTestFont(this));
|
||||
screens.add(new ScreenTestRender(this));
|
||||
|
||||
if (inst != null) inst.shutdown();
|
||||
screens.showScreen("test.render");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void initBus(EventBus bus)
|
||||
{
|
||||
super.initBus(bus);
|
||||
|
||||
// custom channels
|
||||
bus.addChannel(ActionRequest.class, ActionRequest.Listener.class);
|
||||
|
||||
//bus.detailedLogging = true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void initInputSystem(InputSystem input)
|
||||
{
|
||||
// Go fullscreen
|
||||
getInput().bindKeyStroke(new KeyStroke(Keys.KEY_F11), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
getEventBus().send(new ActionRequest(RequestType.FULLSCREEN));
|
||||
}
|
||||
});
|
||||
|
||||
// Take screenshot
|
||||
getInput().bindKeyStroke(new KeyStroke(Keys.KEY_F2), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
getEventBus().send(new ActionRequest(RequestType.SCREENSHOT));
|
||||
}
|
||||
});
|
||||
|
||||
// Exit
|
||||
getInput().bindKeyStroke(new KeyStroke(Keys.KEY_LCONTROL, Keys.KEY_Q), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
getEventBus().send(new ActionRequest(RequestType.SHUTDOWN));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -110,41 +151,6 @@ public class App extends BaseApp {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void initInputSystem(InputSystem input)
|
||||
{
|
||||
// Go fullscreen
|
||||
getInput().bindKeyStroke(new KeyStroke(Keys.KEY_F11), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
getEventBus().send(new ActionRequest(RequestType.FULLSCREEN));
|
||||
}
|
||||
});
|
||||
|
||||
// Take screenshot
|
||||
getInput().bindKeyStroke(new KeyStroke(Keys.KEY_F2), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
getEventBus().send(new ActionRequest(RequestType.SCREENSHOT));
|
||||
}
|
||||
});
|
||||
|
||||
// Exit
|
||||
getInput().bindKeyStroke(new KeyStroke(Keys.KEY_LCONTROL, Keys.KEY_Q), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
getEventBus().send(new ActionRequest(RequestType.SHUTDOWN));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected GameLoop createLoop()
|
||||
{
|
||||
@@ -159,18 +165,6 @@ public class App extends BaseApp {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void initScreens(ScreenRegistry screens)
|
||||
{
|
||||
screens.add(new ScreenTestBouncy(this));
|
||||
screens.add(new ScreenTestCat(this));
|
||||
screens.add(new ScreenTestFont(this));
|
||||
screens.add(new ScreenTestRender(this));
|
||||
|
||||
screens.showScreen("test.cat");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected File getLockFile()
|
||||
{
|
||||
@@ -178,15 +172,21 @@ public class App extends BaseApp {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void initBus(EventBus bus)
|
||||
/**
|
||||
* Handle a crash
|
||||
*
|
||||
* @param error
|
||||
*/
|
||||
public static void onCrash(Throwable error)
|
||||
{
|
||||
super.initBus(bus);
|
||||
if (Log.ready()) {
|
||||
Log.e("The game has crashed!", error);
|
||||
} else {
|
||||
System.err.println("The game has crashed!");
|
||||
error.printStackTrace();
|
||||
}
|
||||
|
||||
// custom channels
|
||||
bus.addChannel(ActionRequest.class, ActionRequest.Listener.class);
|
||||
|
||||
bus.detailedLogging = true;
|
||||
if (inst != null) inst.shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import static mightypork.gamecore.gui.constraints.Constraints.*;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import mightypork.gamecore.control.interf.Updateable;
|
||||
import mightypork.gamecore.control.timing.Updateable;
|
||||
import mightypork.gamecore.gui.components.PluggableRenderer;
|
||||
import mightypork.gamecore.gui.constraints.NumberConstraint;
|
||||
import mightypork.gamecore.gui.constraints.RectConstraint;
|
||||
|
||||
@@ -6,7 +6,7 @@ import static mightypork.gamecore.gui.constraints.Constraints.*;
|
||||
import java.util.Random;
|
||||
|
||||
import mightypork.gamecore.control.bus.events.MouseButtonEvent;
|
||||
import mightypork.gamecore.control.interf.Updateable;
|
||||
import mightypork.gamecore.control.timing.Updateable;
|
||||
import mightypork.gamecore.gui.components.painters.ImagePainter;
|
||||
import mightypork.gamecore.gui.components.painters.TextPainter;
|
||||
import mightypork.gamecore.gui.constraints.RectConstraint;
|
||||
|
||||
@@ -22,7 +22,7 @@ public class ScreenTestFont extends Screen {
|
||||
tp = new TextPainter(Res.getFont("default"), Align.CENTER, RGB.GREEN);
|
||||
tp.setText("Hello World!");
|
||||
|
||||
final RectConstraint strbox = _grow(_center(this), 0, _div(_height(this), 10));
|
||||
final RectConstraint strbox = _centered(_box(_div(_screenH, 10)), this);
|
||||
|
||||
tp.setContext(strbox);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package mightypork.rogue.screens.test_render;
|
||||
|
||||
|
||||
import static mightypork.gamecore.gui.constraints.Constraints.*;
|
||||
import mightypork.gamecore.gui.constraints.Poller;
|
||||
import mightypork.gamecore.control.timing.Poller;
|
||||
import mightypork.gamecore.gui.constraints.RectConstraint;
|
||||
import mightypork.gamecore.gui.screens.Screen;
|
||||
import mightypork.gamecore.gui.screens.ScreenLayer;
|
||||
@@ -17,24 +17,22 @@ public class LayerTestGradient extends ScreenLayer {
|
||||
|
||||
private final RectConstraint pos1;
|
||||
private final RectConstraint pos2;
|
||||
private final RectConstraint pos3;
|
||||
|
||||
|
||||
public LayerTestGradient(Screen screen) {
|
||||
super(screen);
|
||||
|
||||
pos1 = _cache(p, _grow_down(_top_edge(this), 64));
|
||||
pos2 = _cache(p, _shrink_up(_grow_right(_left_edge(this), 64), 64));
|
||||
pos3 = _cache(p, _move(_grow(_center(this), 70, 10), 100, 100));
|
||||
pos2 = _cache(p, _shrink_top(_grow_right(_left_edge(this), 64), 64));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void render()
|
||||
{
|
||||
Render.quadColor(getRect(), RGB.WHITE, RGB.BLUE, RGB.BLACK, RGB.PURPLE);
|
||||
Render.quadGradH(pos1.getRect(), RGB.GREEN, RGB.RED);
|
||||
Render.quadGradV(pos2.getRect(), RGB.WHITE, RGB.PURPLE);
|
||||
Render.quad(pos3.getRect(), RGB.RED);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package mightypork.utils.math.animation;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.interf.Updateable;
|
||||
import mightypork.gamecore.control.timing.Pauseable;
|
||||
import mightypork.gamecore.control.timing.Updateable;
|
||||
import mightypork.gamecore.gui.constraints.NumberConstraint;
|
||||
import mightypork.utils.math.Calc;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package mightypork.utils.math.coord;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.interf.Updateable;
|
||||
import mightypork.gamecore.control.timing.Updateable;
|
||||
import mightypork.utils.math.Calc;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user