Skip to content

Commit

Permalink
PlatformGraphics: Some cleanups in translation and clipRect setup.
Browse files Browse the repository at this point in the history
Those are far-reaching, so despite not finding any regressions on
what i've tested so far, there's no guarantee it won't break stuff
that previously worked.
  • Loading branch information
AShiningRay committed Dec 19, 2024
1 parent 16e2222 commit b339a0e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 59 deletions.
48 changes: 15 additions & 33 deletions src/javax/microedition/lcdui/Graphics.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package javax.microedition.lcdui;

import java.awt.Rectangle;

import org.recompile.mobile.PlatformGraphics;

public class Graphics
Expand All @@ -34,10 +36,7 @@ public class Graphics
protected int translateX = 0;
protected int translateY = 0;

protected int clipX = 0;
protected int clipY = 0;
protected int clipWidth = 0;
protected int clipHeight = 0;
protected Rectangle clip;

protected int color = 0xFFFFFF;
protected Font font = Font.getDefaultFont();
Expand Down Expand Up @@ -80,7 +79,7 @@ public void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3) { }

public int getColor() { return color; }

public int getDisplayColor(int trycolor) { return trycolor; }
public int getDisplayColor(int color) { return color; }

public Font getFont() { return font; }

Expand All @@ -105,45 +104,28 @@ public void clipRect(int x, int y, int width, int height) { }

public void setClip(int x, int y, int width, int height) { }

public int getClipHeight() { return clipHeight; }
public int getClipHeight() { return clip.height; }

public int getClipWidth() { return clipWidth; }
public int getClipWidth() { return clip.width; }

public int getClipX() { return clipX; }
public int getClipX() { return clip.x; }

public int getClipY() { return clipY; }
public int getClipY() { return clip.y; }

public void translate(int x, int y)
{
translateX += x;
translateY += y;
}
public void translate(int x, int y) { }

public int getTranslateX()
{
return translateX;
}
public int getTranslateX() { return translateX; }

public int getTranslateY()
{
return translateY;
}
public int getTranslateY() { return translateY; }

public void setColor(int RGB) { color = RGB; }
public void setColor(int RGB) { }

public void setColor(int red, int green, int blue) { color = (red<<16) + (green<<8) + blue; }
public void setColor(int red, int green, int blue) { }

public void setFont(Font newfont) { font = newfont; }

public void setGrayScale(int value)
{
value = value & 0xFF;
setColor((value<<16) + (value<<8) + value);
}
public void setGrayScale(int value) { }

public void setStrokeStyle(int style)
{
strokeStyle = style;
}
public void setStrokeStyle(int style) { }

}
42 changes: 16 additions & 26 deletions src/org/recompile/mobile/PlatformGraphics.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,8 @@ public PlatformGraphics(PlatformImage image)

platformGraphics = this;

clipX = 0;
clipY = 0;
clipWidth = canvas.getWidth();
clipHeight = canvas.getHeight();
clip = new Rectangle(0, 0, canvas.getWidth(), canvas.getHeight());
gc.getClipBounds(clip);

setColor(0,0,0);
setStrokeStyle(SOLID);
Expand All @@ -87,7 +85,8 @@ public PlatformGraphics(PlatformImage image)

public void reset() //Internal use method, resets the Graphics object to its inital values
{
translate(-1 * translateX, -1 * translateY);
translate(-translateX, -translateY);
translateX = translateY = 0;
setClip(0, 0, canvas.getWidth(), canvas.getHeight());
setColor(0,0,0);
setFont(Font.getDefaultFont());
Expand Down Expand Up @@ -216,6 +215,12 @@ public void drawRegion(Image image, int subx, int suby, int subw, int subh, int
{
if (subw <= 0 || subh <= 0) { return; }

if (subx < 0 || suby < 0 || subx + subw > image.platformImage.getCanvas().getWidth()
|| suby + subh > image.platformImage.getCanvas().getHeight())
{
throw new IllegalArgumentException("Source region exceeds image bounds.");
}

try
{
if(transform == 0)
Expand Down Expand Up @@ -397,24 +402,15 @@ public void setFont(Font font)

public void setClip(int x, int y, int width, int height)
{
gc.setClip(x, y, width, height);
Rectangle rect=new Rectangle();
gc.getClipBounds(rect);
clipX = (int) rect.getX();
clipY = (int) rect.getY();
clipWidth = (int)rect.getWidth();
clipHeight = (int)rect.getHeight();
clip.setBounds(x, y, width, height);
gc.setClip(clip);
}

public void clipRect(int x, int y, int width, int height)
{
gc.clipRect(x, y, width, height);
Rectangle rect=new Rectangle();
gc.getClipBounds(rect);
clipX = (int) rect.getX();
clipY = (int) rect.getY();
clipWidth = (int)rect.getWidth();
clipHeight = (int)rect.getHeight();
Rectangle newClip = new Rectangle(x, y, width, height);
clip = clip.intersection(newClip);
gc.setClip(clip);
}

public int getTranslateX() { return translateX; }
Expand All @@ -426,27 +422,21 @@ public void translate(int x, int y)
translateX += x;
translateY += y;
gc.translate(x, y);
Rectangle rect=new Rectangle();
gc.getClipBounds(rect);
clipX = (int) rect.getX();
clipY = (int) rect.getY();
}

private int AnchorX(int x, int width, int anchor)
{
int xout = x;
if((anchor & HCENTER)>0) { xout = x-(width/2); }
if((anchor & RIGHT)>0) { xout = x-width; }
if((anchor & LEFT)>0) { xout = x; }
return xout;
}

private int AnchorY(int y, int height, int anchor)
{
int yout = y;
if((anchor & VCENTER)>0) { yout = y-(height/2); }
if((anchor & TOP)>0) { yout = y; }
if((anchor & BOTTOM)>0) { yout = y-height; }
if((anchor & VCENTER)>0) { yout = y-(height/2); }
if((anchor & BASELINE)>0) { yout = y+height; }
return yout;
}
Expand Down

0 comments on commit b339a0e

Please sign in to comment.