Skip to content

Commit

Permalink
Merge branch 'devel' into sdl-native
Browse files Browse the repository at this point in the history
  • Loading branch information
AShiningRay authored Oct 21, 2024
2 parents 3827624 + 091dbaf commit 5d2b56d
Show file tree
Hide file tree
Showing 22 changed files with 1,798 additions and 2,038 deletions.
48 changes: 14 additions & 34 deletions src/javax/microedition/lcdui/Display.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public class Display
public static final int COLOR_BORDER = 4;
public static final int COLOR_HIGHLIGHTED_BORDER = 5;


private Displayable current;

private static Display display;
Expand Down Expand Up @@ -77,11 +76,8 @@ public Display()
public void callSerially(Runnable r)
{
LCDUILock.lock();
try {
serialCalls.add(r);
} finally {
LCDUILock.unlock();
}
try { serialCalls.add(r); }
finally { LCDUILock.unlock(); }
}
private class SerialCallTimerTask extends TimerTask
{
Expand All @@ -94,13 +90,12 @@ public void run()
synchronized (calloutLock)
{
LCDUILock.lock();
try {
try
{
Runnable call = serialCalls.get(0);
serialCalls.removeElementAt(0);
call.run();
} finally {
LCDUILock.unlock();
}
} finally { LCDUILock.unlock(); }
}
}
catch (Exception e) { }
Expand All @@ -121,10 +116,7 @@ public int getBestImageHeight(int imageType)
return Mobile.getPlatform().lcdHeight;
}

public int getBestImageWidth(int imageType)
{
return Mobile.getPlatform().lcdWidth;
}
public int getBestImageWidth(int imageType) { return Mobile.getPlatform().lcdWidth; }

public int getBorderStyle(boolean highlighted) { return 0; }

Expand Down Expand Up @@ -154,30 +146,20 @@ public int getColor(int colorSpecifier)

public void setCurrent(Displayable next)
{
if (next == null){
return;
}
if (next == null){ return; }
if (current == next || insideSetCurrent) { return; }

LCDUILock.lock();
try {
if (current == next || insideSetCurrent)
{
return;
}

try
{
try
{
insideSetCurrent = true;

try {
if (current != null) {
current.hideNotify();
}
try
{
Mobile.getPlatform().keyState = 0; // reset keystate
next.showNotify();
} finally {
insideSetCurrent = false;
}
} finally { insideSetCurrent = false; }

current = next;
current.notifySetCurrent();
Expand All @@ -189,9 +171,7 @@ public void setCurrent(Displayable next)
System.out.println("Problem with setCurrent(next)");
e.printStackTrace();
}
} finally {
LCDUILock.unlock();
}
} finally { LCDUILock.unlock(); }
}

public void setCurrent(Alert alert, Displayable next)
Expand Down
43 changes: 26 additions & 17 deletions src/javax/microedition/lcdui/Font.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,21 @@ public final class Font
public static final int STYLE_PLAIN = 0;
public static final int STYLE_UNDERLINED = 4;

private static final int[] fontSizes =
{
8, 8, 10, // < 128 minimum px dimension
8, 11, 12, // < 176 minimum px dimension
9, 12, 14, // < 220 minimum px dimension
10, 14, 16, // >= 220 minimum px dimension
};

private static Font defaultFont = null;

private static int screenType = -4;
private int face;
private int style;
private int size;

private static Font defaultFont = null;

public PlatformFont platformFont;

private Font(int fontFace, int fontStyle, int fontSize)
Expand All @@ -54,6 +62,15 @@ private Font(int fontFace, int fontStyle, int fontSize)
platformFont = new PlatformFont(this);
}

public static void setScreenSize(int width, int height)
{
final int minSize = Math.min(width, height);
if (minSize < 128) { screenType = 0; }
else if (minSize < 176) { screenType = 1; }
else if (minSize < 220) { screenType = 2; }
else { screenType = 3; }
}

public int charsWidth(char[] ch, int offset, int length)
{
String str = new String(ch, offset, length);
Expand All @@ -76,9 +93,7 @@ public static Font getDefaultFont()

public static Font getFont(int face, int style, int size) { return new Font(face, style, size); }

public int getHeight() {
return platformFont.getHeight();
}
public int getHeight() { return platformFont.getHeight(); }

public int getSize() { return size; }

Expand All @@ -94,24 +109,18 @@ public int getHeight() {

public boolean isUnderlined() { return (style & STYLE_UNDERLINED) == STYLE_UNDERLINED; }

public int stringWidth(String str)
{
return platformFont.stringWidth(str);
}
public int stringWidth(String str) { return platformFont.stringWidth(str); }

public int substringWidth(String str, int offset, int len)
{
return stringWidth(str.substring(offset, offset+len));
}
public int substringWidth(String str, int offset, int len) { return stringWidth(str.substring(offset, offset+len)); }

private int convertSize(int size)
{
switch(size)
{
case SIZE_LARGE : return 14;
case SIZE_MEDIUM : return 12;
case SIZE_SMALL : return 10;
default : return 10;
case SIZE_LARGE : return fontSizes[3*screenType + 2];
case SIZE_MEDIUM : return fontSizes[3*screenType + 1];
case SIZE_SMALL :
default : return fontSizes[3*screenType];
}
}
}
15 changes: 10 additions & 5 deletions src/javax/microedition/lcdui/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.IOException;
import java.io.InputStream;

import javax.microedition.lcdui.game.Sprite;

import org.recompile.mobile.Mobile;
import org.recompile.mobile.PlatformImage;
Expand All @@ -32,20 +33,23 @@ public class Image
public int width;
public int height;

public static Image createImage(byte[] imageData, int imageOffset, int imageLength)
public static Image createImage(byte[] imageData, int imageOffset, int imageLength) throws IllegalArgumentException
{
//System.out.println("Create Image from image data ");
if (imageData == null) {throw new NullPointerException();}
if (imageOffset + imageLength > imageData.length) {throw new ArrayIndexOutOfBoundsException();}

PlatformImage t = new PlatformImage(imageData, imageOffset, imageLength);
if(t.isNull) { throw new IllegalArgumentException(); }
return t;
}

public static Image createImage(Image source)
{
//System.out.println("Create Image from Image ");
if (source == null) {throw new NullPointerException();}
// If the source is immutable, just return it, despite the docs not mentioning it directly
if (!source.isMutable()) { return source; }

return new PlatformImage(source);
}

Expand All @@ -55,15 +59,17 @@ public static Image createImage(Image img, int x, int y, int width, int height,
if (img == null) {throw new NullPointerException();}
if (x+width > img.getWidth() || y+height > img.getHeight()) {throw new IllegalArgumentException();}
if (width <= 0 || height <= 0) {throw new IllegalArgumentException();}

if(!img.isMutable() && (x+width == img.getWidth() && y+height == img.getHeight()) && transform == Sprite.TRANS_NONE) { return img; }

return new PlatformImage(img, x, y, width, height, transform);
}

public static Image createImage(InputStream stream) throws IOException
public static Image createImage(InputStream stream) throws IOException, IllegalArgumentException
{
//System.out.println("Create Image stream");
if (stream == null) {throw new NullPointerException();}
PlatformImage t = new PlatformImage(stream);
if(t.isNull) { throw new IOException(); }
return t;
}

Expand All @@ -79,7 +85,6 @@ public static Image createImage(String name) throws IOException
//System.out.println("Create Image " + name);
if (name == null) {throw new NullPointerException();}
PlatformImage t = new PlatformImage(name);
if(t.isNull) { throw new IOException(); }
return t;
}

Expand Down
16 changes: 6 additions & 10 deletions src/javax/microedition/lcdui/game/LayerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@
public class LayerManager
{

private int layers;

private Layer component[] = new Layer[4];

protected int x;
protected int y;
protected int width;
protected int height;
private int layers;
private int x;
private int y;
private int width;
private int height;


public LayerManager() { setViewWindow(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE); }
Expand Down Expand Up @@ -112,10 +111,7 @@ private boolean exist(Layer l)
{
if (l == null) { return false; }

for (int i = layers; --i >= 0; )
{
if (component[i] == l) { return true; }
}
for (int i = layers; --i >= 0; ) { if (component[i] == l) { return true; } }
return false;
}

Expand Down
Loading

0 comments on commit 5d2b56d

Please sign in to comment.