Commit 3be5efb0 authored by Stephanie Gawroriski's avatar Stephanie Gawroriski
Browse files

Refactor double buffered graphics and implement for i-mode and LCDUI, note...

Refactor double buffered graphics and implement for i-mode and LCDUI, note that currently a black screen is shown.
parent f7aa6645
// ---------------------------------------------------------------------------
// SquirrelJME
// Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------
package cc.squirreljme.runtime.lcdui.gfx;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
/**
* This class implements a double buffered image which may be used for
* graphics operations.
*
* @since 2022/02/25
*/
public final class DoubleBuffer
{
/** The proxy for the off-screen graphics. */
private final ProxyGraphicsTarget _offScreenProxy =
new ProxyGraphicsTarget(Image.createImage(1, 1)
.getGraphics());
/** The off-screen buffer. */
private final SingleBuffer _offScreen =
new SingleBuffer();
/** The on-screen buffer. */
private final SingleBuffer _onScreen =
new SingleBuffer();
/** The last used width. */
private int _lastWidth =
-1;
/** The last used height. */
private int _lastHeight =
-1;
/**
* Flushes the off-screen buffer to be on-screen.
*
* @since 2022/02/25
*/
public void flush()
{
this._onScreen.copyFrom(this._offScreen);
}
/**
* Returns a graphics object for drawing into the off-screen buffer.
*
* @param __width The buffer width.
* @param __height The buffer height.
* @return The graphics to draw onto the image.
* @throws IllegalArgumentException If the width and/or height are invalid.
* @since 2022/02/25
*/
public Graphics getGraphics(int __width, int __height)
throws IllegalArgumentException
{
// {@squirreljme.error EB32 Invalid buffer dimensions.}
if (__width <= 0 || __height <= 0)
throw new IllegalArgumentException("EB32");
// We use the proxy regardless
ProxyGraphicsTarget proxy = this._offScreenProxy;
ProxyGraphics rv = new ProxyGraphics(proxy);
// If the surface area has not changed, then we can freely use the same
// graphics object, this will help reduce load on double-buffered
// operations
int lastWidth = this._lastWidth;
int lastHeight = this._lastHeight;
if (__width == lastWidth || __height == lastHeight)
return rv;
// Otherwise, remember our new screen space and use the graphics it
// produces
proxy.setGraphics(this._offScreen.getGraphics(__width, __height));
this._lastWidth = __width;
this._lastHeight = __height;
return rv;
}
/**
* Paints the on-screen buffer onto the given graphics instance.
*
* @param __g The graphics to paint onto.
* @since 2022/02/25
*/
public void paint(Graphics __g)
{
this._onScreen.paint(__g);
}
}
// ---------------------------------------------------------------------------
// SquirrelJME
// Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------
package cc.squirreljme.runtime.lcdui.gfx;
import cc.squirreljme.runtime.cldc.debug.Debugging;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.Text;
/**
* This is a proxy version of {@link Graphics} where each instance can
* refer to a single graphics instance. When a draw operation occurs, the
* parameters of this current graphics will be set on the target.
*
* @see ProxyGraphicsTarget
* @since 2022/02/25
*/
public final class ProxyGraphics
extends Graphics
{
/** The target graphics to draw into. */
protected final ProxyGraphicsTarget target;
/** The current alpha color. */
private int _argbColor;
/** The current blending mode. */
private int _blendingMode;
/** The clip height. */
private int _clipHeight;
/** The clip width. */
private int _clipWidth;
/** The clip X position. */
private int _clipX;
/** The clip Y position. */
private int _clipY;
/** The current font used. */
private Font _font;
/** The current stroke style. */
private int _strokeStyle;
/** The current X translation. */
private int _transX;
/** The current Y translation. */
private int _transY;
/**
* Initializes the proxy graphics with the given target.
*
* @param __target The target graphics proxy.
* @throws NullPointerException On null arguments.
* @since 2022/02/25
*/
public ProxyGraphics(ProxyGraphicsTarget __target)
throws NullPointerException
{
if (__target == null)
throw new NullPointerException("NARG");
this.target = __target;
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public void clipRect(int __a, int __b, int __c, int __d)
{
throw Debugging.todo();
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public void copyArea(int __a, int __b, int __c, int __d, int __e,
int __f, int __g)
{
this.__graphics().copyArea(__a, __b, __c, __d, __e, __f, __g);
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public void drawArc(int __a, int __b, int __c, int __d, int __e,
int __f)
{
this.__graphics().drawArc(__a, __b, __c, __d, __e, __f);
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public void drawARGB16(short[] __data, int __off, int __scanlen,
int __x, int __y, int __w, int __h)
{
this.__graphics().drawARGB16(__data, __off, __scanlen, __x, __y, __w,
__h);
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public void drawChar(char __a, int __b, int __c, int __d)
{
this.__graphics().drawChar(__a, __b, __c, __d);
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public void drawChars(char[] __a, int __b, int __c, int __d,
int __e, int __f)
{
this.__graphics().drawChars(__a, __b, __c, __d, __e, __f);
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public void drawImage(Image __a, int __b, int __c, int __d)
{
this.__graphics().drawImage(__a, __b, __c, __d);
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public void drawLine(int __a, int __b, int __c, int __d)
{
this.__graphics().drawLine(__a, __b, __c, __d);
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public void drawRGB(int[] __a, int __b, int __c, int __d, int __e,
int __f, int __g, boolean __h)
{
this.__graphics().drawRGB(__a, __b, __c, __d, __e, __f, __g, __h);
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public void drawRGB16(short[] __data, int __off, int __scanlen,
int __x, int __y, int __w, int __h)
{
this.__graphics().drawRGB16(__data, __off, __scanlen, __x, __y, __w, __h);
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public void drawRect(int __a, int __b, int __c, int __d)
{
this.__graphics().drawRect(__a, __b, __c, __d);
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public void drawRegion(Image __a, int __b, int __c, int __d,
int __e, int __f, int __g, int __h, int __i)
{
this.__graphics().drawRegion(__a, __b, __c, __d, __e, __f, __g, __h,
__i);
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public void drawRegion(Image __src, int __xsrc, int __ysrc,
int __w, int __h, int __trans, int __xdest, int __ydest, int __anch,
int __wdest, int __hdest)
{
this.__graphics().drawRegion(__src, __xsrc, __ysrc, __w, __h, __trans,
__xdest, __ydest, __anch, __wdest, __hdest);
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public void drawRoundRect(int __a, int __b, int __c, int __d,
int __e, int __f)
{
this.__graphics().drawRoundRect(__a, __b, __c, __d, __e, __f);
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public void drawString(String __a, int __b, int __c, int __d)
{
this.__graphics().drawString(__a, __b, __c, __d);
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public void drawSubstring(String __a, int __b, int __c, int __d,
int __e, int __f)
{
this.__graphics().drawSubstring(__a, __b, __c, __d, __e, __f);
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public void drawText(Text __t, int __x, int __y)
{
this.__graphics().drawText(__t, __x, __y);
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public void fillArc(int __a, int __b, int __c, int __d, int __e,
int __f)
{
this.__graphics().fillArc(__a, __b, __c, __d, __e, __f);
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public void fillRect(int __a, int __b, int __c, int __d)
{
this.__graphics().fillRect(__a, __b, __c, __d);
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public void fillRoundRect(int __a, int __b, int __c, int __d,
int __e, int __f)
{
this.__graphics().fillRoundRect(__a, __b, __c, __d, __e, __f);
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public void fillTriangle(int __a, int __b, int __c, int __d,
int __e, int __f)
{
this.__graphics().fillTriangle(__a, __b, __c, __d, __e, __f);
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public int getAlpha()
{
return (this._argbColor >> 24) & 0xFF;
}
/**
* {@inheritDoc}
* @since 2017/02/10
*/
@Override
public int getAlphaColor()
{
return this._argbColor;
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public int getBlendingMode()
{
return this._blendingMode;
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public int getBlueComponent()
{
return (this._argbColor) & 0xFF;
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public int getClipHeight()
{
return this._clipHeight;
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public int getClipWidth()
{
return this._clipWidth;
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public int getClipX()
{
return this._clipX - this._transX;
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public int getClipY()
{
return this._clipY - this._transY;
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public int getColor()
{
return this._argbColor & 0xFFFFFF;
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public int getDisplayColor(int __a)
{
return this.__graphics().getDisplayColor(__a);
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public Font getFont()
{
return this.__font();
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public int getGrayScale()
{
return (((this._argbColor >> 16) & 0xFF) +
((this._argbColor >> 8) & 0xFF) +
((this._argbColor) & 0xFF)) / 3;
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public int getGreenComponent()
{
return (this._argbColor >> 8) & 0xFF;
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public int getRedComponent()
{
return (this._argbColor >> 16) & 0xFF;
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public int getStrokeStyle()
{
return this._strokeStyle;
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public int getTranslateX()
{
return this._transX;
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public int getTranslateY()
{
return this._transY;
}
/**
* {@inheritDoc}
* @since 2022/02/25
*/
@Override
public void setAlpha(int __a)
{
this.setAlphaColor(__a,
this.getRedComponent(),
this.getGreenComponent(),
this.getBlueComponent());