tweaked gradient rendering

v5stable
Ondřej Hruška 11 years ago
parent 861d007b27
commit dacb43df3a
  1. 2
      src/mightypork/gamecore/audio/SoundSystem.java
  2. 2
      src/mightypork/gamecore/audio/players/LoopPlayer.java
  3. 2
      src/mightypork/gamecore/control/BaseApp.java
  4. 2
      src/mightypork/gamecore/control/bus/events/UpdateEvent.java
  5. 2
      src/mightypork/gamecore/control/timing/Pollable.java
  6. 4
      src/mightypork/gamecore/control/timing/Poller.java
  7. 2
      src/mightypork/gamecore/control/timing/Updateable.java
  8. 56
      src/mightypork/gamecore/gui/components/painters/QuadPainter.java
  9. 27
      src/mightypork/gamecore/gui/constraints/Constraints.java
  10. 3
      src/mightypork/gamecore/gui/constraints/RectCache.java
  11. 2
      src/mightypork/gamecore/input/InputSystem.java
  12. 47
      src/mightypork/gamecore/render/Render.java
  13. 116
      src/mightypork/rogue/App.java
  14. 2
      src/mightypork/rogue/screens/test_bouncyboxes/BouncyBox.java
  15. 2
      src/mightypork/rogue/screens/test_cat_sound/LayerFlyingCat.java
  16. 2
      src/mightypork/rogue/screens/test_font/ScreenTestFont.java
  17. 8
      src/mightypork/rogue/screens/test_render/LayerTestGradient.java
  18. 2
      src/mightypork/utils/math/animation/AnimDouble.java
  19. 2
      src/mightypork/utils/math/coord/CoordAnimated.java

@ -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,4 +1,4 @@
package mightypork.gamecore.control.interf;
package mightypork.gamecore.control.timing;
/**

@ -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,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,57 +56,27 @@ public class App extends BaseApp {
}
/**
* Handle a crash
*
* @param error
*/
public static void onCrash(Throwable error)
{
if (Log.ready()) {
Log.e("The game has crashed!", error);
} else {
System.err.println("The game has crashed!");
error.printStackTrace();
}
if (inst != null) inst.shutdown();
}
@Override
protected void preInit()
{
// to get dot instead of comma in floats
Locale.setDefault(Locale.ENGLISH);
}
@Override
protected LogInstance createLog()
protected void initScreens(ScreenRegistry screens)
{
final LogInstance log = Log.create("runtime", Paths.LOGS, 10);
log.setFileLevel(Level.WARNING);
log.setSysoutLevel(Level.ALL);
log.enable(Config.LOGGING_ENABLED);
log.enableSysout(Config.LOG_TO_STDOUT);
screens.add(new ScreenTestBouncy(this));
screens.add(new ScreenTestCat(this));
screens.add(new ScreenTestFont(this));
screens.add(new ScreenTestRender(this));
return log;
screens.showScreen("test.render");
}
@Override
protected void initDisplay(DisplaySystem display)
protected void initBus(EventBus bus)
{
display.createMainWindow(Const.WINDOW_W, Const.WINDOW_H, true, Config.START_IN_FS, Const.TITLEBAR);
display.setTargetFps(Const.FPS_RENDER);
}
super.initBus(bus);
// custom channels
bus.addChannel(ActionRequest.class, ActionRequest.Listener.class);
@Override
protected void initSoundSystem(SoundSystem audio)
{
audio.setMasterVolume(1);
//bus.detailedLogging = true;
}
@ -146,47 +116,77 @@ public class App extends BaseApp {
@Override
protected GameLoop createLoop()
protected void preInit()
{
return new MainLoop(this);
// to get dot instead of comma in floats
Locale.setDefault(Locale.ENGLISH);
}
@Override
protected void initResources()
protected LogInstance createLog()
{
Res.load(this);
final LogInstance log = Log.create("runtime", Paths.LOGS, 10);
log.setFileLevel(Level.WARNING);
log.setSysoutLevel(Level.ALL);
log.enable(Config.LOGGING_ENABLED);
log.enableSysout(Config.LOG_TO_STDOUT);
return log;
}
@Override
protected void initScreens(ScreenRegistry screens)
protected void initDisplay(DisplaySystem display)
{
screens.add(new ScreenTestBouncy(this));
screens.add(new ScreenTestCat(this));
screens.add(new ScreenTestFont(this));
screens.add(new ScreenTestRender(this));
display.createMainWindow(Const.WINDOW_W, Const.WINDOW_H, true, Config.START_IN_FS, Const.TITLEBAR);
display.setTargetFps(Const.FPS_RENDER);
}
screens.showScreen("test.cat");
@Override
protected void initSoundSystem(SoundSystem audio)
{
audio.setMasterVolume(1);
}
@Override
protected File getLockFile()
protected GameLoop createLoop()
{
return Paths.LOCK;
return new MainLoop(this);
}
@Override
protected void initBus(EventBus bus)
protected void initResources()
{
super.initBus(bus);
Res.load(this);
}
// custom channels
bus.addChannel(ActionRequest.class, ActionRequest.Listener.class);
bus.detailedLogging = true;
@Override
protected File getLockFile()
{
return Paths.LOCK;
}
/**
* Handle a crash
*
* @param error
*/
public static void onCrash(Throwable error)
{
if (Log.ready()) {
Log.e("The game has crashed!", error);
} else {
System.err.println("The game has crashed!");
error.printStackTrace();
}
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;

Loading…
Cancel
Save