Revision: 2503
http://sourceforge.net/p/swingme/code/2503
Author: yuranet
Date: 2021-07-02 14:08:34 +0000 (Fri, 02 Jul 2021)
Log Message:
-----------
fps indicator and much faster drawing
Modified Paths:
--------------
iOSME/build.gradle
iOSME/src/javax/microedition/lcdui/Canvas.java
iOSME/src/javax/microedition/lcdui/Graphics.java
iOSME/src/net/yura/ios/AppController.java
Added Paths:
-----------
iOSME/src/net/yura/ios/plaf/
iOSME/src/net/yura/ios/plaf/IOSBorder.java
iOSME/src/net/yura/ios/plaf/IOSLookAndFeel.java
Modified: iOSME/build.gradle
===================================================================
--- iOSME/build.gradle 2021-07-02 14:00:44 UTC (rev 2502)
+++ iOSME/build.gradle 2021-07-02 14:08:34 UTC (rev 2503)
@@ -17,6 +17,9 @@
java {
srcDirs('src')
}
+ resources {
+ srcDirs('res')
+ }
}
}
Modified: iOSME/src/javax/microedition/lcdui/Canvas.java
===================================================================
--- iOSME/src/javax/microedition/lcdui/Canvas.java 2021-07-02 14:00:44 UTC (rev 2502)
+++ iOSME/src/javax/microedition/lcdui/Canvas.java 2021-07-02 14:08:34 UTC (rev 2503)
@@ -44,7 +44,7 @@
}
public void setFullScreenMode(boolean fullScreen) {
- // do nothing, is this possible on android?
+ // do nothing, is this possible on ios?
}
public int getGameAction(int keyCode) {
@@ -128,6 +128,10 @@
// we can only ever call setNeedsDisplay from main thread or it does nothing
if (NSThread.isMainThread_static() && !painting) {
canvasView.setNeedsDisplayInRect(rect);
+
+ //#mdebug debug
+ if (fpsRect != null) canvasView.setNeedsDisplayInRect(fpsRect);
+ //#enddebug
}
else {
NSOperationQueue.mainQueue().addOperationWithBlock(new NSOperationQueue.Block_addOperationWithBlock() {
@@ -134,6 +138,10 @@
@Override
public void call_addOperationWithBlock() {
canvasView.setNeedsDisplayInRect(rect);
+
+ //#mdebug debug
+ if (fpsRect != null) canvasView.setNeedsDisplayInRect(fpsRect);
+ //#enddebug
}
});
}
@@ -177,6 +185,10 @@
try {
painting = true;
paint(g);
+
+ //#mdebug debug
+ showFramesPerSec(g);
+ //#enddebug
}
finally {
painting = false;
@@ -183,6 +195,43 @@
}
}
+
+
+ // -- debug code ---
+ private long lastDrawTime;
+ private int nFrames;
+ private String fpsStr = "0.0fps";
+ private CGRect fpsRect;
+
+ private void showFramesPerSec(Graphics graphics) {
+ nFrames++;
+ long timeNow = System.currentTimeMillis();
+ long timeDiff = timeNow - lastDrawTime;
+
+ if (timeDiff > 1000) {
+ long fps = nFrames * 10000 / timeDiff;
+ fpsStr = (fps / 10) + "." + (fps % 10) + "fps";
+
+ lastDrawTime = timeNow;
+ nFrames = 0;
+ }
+
+ int x = 2;
+ int y = 5;
+
+ if (fpsRect == null) {
+ Font font = graphics.getFont();
+ int fontH = font.getHeight() + 4;
+ int fontW = font.stringWidth("99.9fps") + 4;
+ fpsRect = new CGRect(new CGPoint(x, y), new CGSize(fontW, fontH));
+ }
+
+ graphics.setColor(0xFF000000);
+ graphics.fillRect(x, y, (int) fpsRect.size().width(), (int) fpsRect.size().height());
+ graphics.setColor(0xFFFFFFFF);
+ graphics.drawString(fpsStr, x + 1, y + 1, 0);
+ }
+
public boolean hasPointerEvents() {
return true;
}
@@ -251,8 +300,7 @@
}
public void serviceRepaints() {
- throw new RuntimeException("not implemented");
- //AndroidMeApp.getIntance().invokeAndWait(new Thread());
+ NSOperationQueue.mainQueue().waitUntilAllOperationsAreFinished();
}
public String getKeyName(int keyCode) {
Modified: iOSME/src/javax/microedition/lcdui/Graphics.java
===================================================================
--- iOSME/src/javax/microedition/lcdui/Graphics.java 2021-07-02 14:00:44 UTC (rev 2502)
+++ iOSME/src/javax/microedition/lcdui/Graphics.java 2021-07-02 14:08:34 UTC (rev 2503)
@@ -1,18 +1,12 @@
package javax.microedition.lcdui;
-import apple.corefoundation.c.CoreFoundation;
-import apple.corefoundation.opaque.CFAttributedStringRef;
import apple.coregraphics.c.CoreGraphics;
import apple.coregraphics.opaque.CGColorRef;
import apple.coregraphics.opaque.CGContextRef;
import apple.coregraphics.opaque.CGFontRef;
-import apple.coregraphics.opaque.CGImageRef;
import apple.coregraphics.struct.CGPoint;
import apple.coregraphics.struct.CGRect;
import apple.coregraphics.struct.CGSize;
-import apple.coretext.c.CoreText;
-import apple.coretext.opaque.CTLineRef;
-import apple.foundation.NSAttributedString;
import apple.foundation.NSMutableDictionary;
import apple.foundation.NSString;
import apple.uikit.UIBezierPath;
@@ -24,7 +18,6 @@
import javax.microedition.lcdui.game.Sprite;
import android.graphics.ColorMatrix;
import org.moe.natj.general.ptr.NFloatPtr;
-import org.moe.natj.general.ptr.VoidPtr;
import org.moe.natj.general.ptr.impl.PtrFactory;
import org.moe.natj.objc.ObjCRuntime;
@@ -303,7 +296,7 @@
attributes.put(UIKit.NSForegroundColorAttributeName(), color);
NSString string = NSString.stringWithString(str);
- boolean same = myContextIsCurrent();
+ boolean same = isCurrentContext();
if (!same) UIKit.UIGraphicsPushContext(context);
string.drawAtPointWithAttributes(new CGPoint(tx + newx, ty + newy), attributes); // this method handles new lines in the text
@@ -387,7 +380,7 @@
// we get the image first, this may close a current bitmap context
UIImage uiImageToDraw = image.getUIImage();
- boolean same = myContextIsCurrent();
+ boolean same = isCurrentContext();
if (!same) UIKit.UIGraphicsPushContext(context);
uiImageToDraw.drawInRect(imageRect);
@@ -394,7 +387,7 @@
if (!same) UIKit.UIGraphicsPopContext();
}
- private boolean myContextIsCurrent() {
+ public boolean isCurrentContext() {
CGContextRef current = UIKit.UIGraphicsGetCurrentContext();
return current != null && current.getPeer().equals(context.getPeer());
}
@@ -468,10 +461,28 @@
if (nRefs > 1) {
throw new IllegalArgumentException("Bad Anchor " + anchor);
}
+/*
+ // this does not improve performance at all
+ if (transform == Sprite.TRANS_NONE) {
+ UIImage img = src.getUIImage();
+ CGRect oldClip = CoreGraphics.CGContextGetClipBoundingBox(context);
+ CGRect clip = getDestRect(anchorX, anchorY, destWidth, destHeight);
+ CoreGraphics.CGContextClipToRect(context, clip);
+
+ boolean same = isCurrentContext();
+
+ if (!same) UIKit.UIGraphicsPushContext(context);
+ img.drawInRect(getDestRect(anchorX - xSrc, anchorY - ySrc, src.getWidth(), src.getHeight()));
+ if (!same) UIKit.UIGraphicsPopContext();
+
+ CoreGraphics.CGContextResetClip(context);
+ CoreGraphics.CGContextClipToRect(context, oldClip);
+ }
+*/
UIImage transformed = src.getUIImage(xSrc, ySrc, width, height, transform);
- boolean same = myContextIsCurrent();
+ boolean same = isCurrentContext();
if (!same) UIKit.UIGraphicsPushContext(context);
transformed.drawInRect(getDestRect(anchorX, anchorY, destWidth, destHeight));
Modified: iOSME/src/net/yura/ios/AppController.java
===================================================================
--- iOSME/src/net/yura/ios/AppController.java 2021-07-02 14:00:44 UTC (rev 2502)
+++ iOSME/src/net/yura/ios/AppController.java 2021-07-02 14:08:34 UTC (rev 2503)
@@ -1,12 +1,10 @@
package net.yura.ios;
import org.moe.natj.general.Pointer;
-
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.MIDlet;
-
import apple.foundation.NSArray;
import apple.foundation.NSDictionary;
import apple.uikit.NSLayoutConstraint;
Added: iOSME/src/net/yura/ios/plaf/IOSBorder.java
===================================================================
--- iOSME/src/net/yura/ios/plaf/IOSBorder.java (rev 0)
+++ iOSME/src/net/yura/ios/plaf/IOSBorder.java 2021-07-02 14:08:34 UTC (rev 2503)
@@ -0,0 +1,35 @@
+package net.yura.ios.plaf;
+
+import net.yura.mobile.gui.Graphics2D;
+import net.yura.mobile.gui.border.EmptyBorder;
+import net.yura.mobile.gui.components.Component;
+import apple.coregraphics.struct.CGPoint;
+import apple.coregraphics.struct.CGRect;
+import apple.coregraphics.struct.CGSize;
+import apple.uikit.UIImage;
+import apple.uikit.c.UIKit;
+
+public class IOSBorder extends EmptyBorder {
+
+ private UIImage resizableImage;
+
+ public IOSBorder(UIImage resizableImage, int top, int left, int bottom, int right) {
+ super(top, left, bottom, right);
+ this.resizableImage = resizableImage;
+ }
+
+ @Override
+ public void paintBorder(Component c, Graphics2D g, int width, int height) {
+ int tx = g.getTranslateX();
+ int ty = g.getTranslateY();
+ CGRect rect = new CGRect(new CGPoint(tx - left, ty - top), new CGSize(width + left + right, height + top + bottom));
+
+ int transform = g.getTransform();
+
+ boolean same = g.getGraphics().isCurrentContext();
+
+ if (!same) UIKit.UIGraphicsPushContext(g.getGraphics().getContext());
+ resizableImage.drawInRect(rect);
+ if (!same) UIKit.UIGraphicsPopContext();
+ }
+}
Added: iOSME/src/net/yura/ios/plaf/IOSLookAndFeel.java
===================================================================
--- iOSME/src/net/yura/ios/plaf/IOSLookAndFeel.java (rev 0)
+++ iOSME/src/net/yura/ios/plaf/IOSLookAndFeel.java 2021-07-02 14:08:34 UTC (rev 2503)
@@ -0,0 +1,48 @@
+package net.yura.ios.plaf;
+
+import net.yura.mobile.gui.Icon;
+import net.yura.mobile.gui.border.Border;
+import net.yura.mobile.gui.border.MatteBorder;
+import net.yura.mobile.gui.plaf.SynthLookAndFeel;
+import java.io.InputStream;
+import javax.microedition.lcdui.Image;
+import apple.uikit.UIImage;
+import apple.uikit.enums.UIImageResizingMode;
+import apple.uikit.struct.UIEdgeInsets;
+
+public class IOSLookAndFeel extends SynthLookAndFeel {
+
+ @Override
+ protected Border getBorder(String path) {
+ MatteBorder ninePatch = (MatteBorder)super.getBorder(path);
+ return convertBorder(ninePatch);
+ }
+
+ @Override
+ protected Border getBorder(String path, int top, int left, int bottom, int right, int t, int l, int b, int r, boolean back, int color) {
+ MatteBorder ninePatch = (MatteBorder)super.getBorder(path, top, left, bottom, right, t, l, b, r, back, color);
+ return convertBorder(ninePatch);
+ }
+
+ private IOSBorder convertBorder(Border border) {
+ if (border instanceof MatteBorder) {
+ MatteBorder ninePatch = (MatteBorder) border;
+ UIImage orgImg = ninePatch.getTileIcon().getImage().getUIImage();
+ int[] insets = ninePatch.getImageEdgeInsets();
+ UIImage borderImg = orgImg.resizableImageWithCapInsetsResizingMode(new UIEdgeInsets(insets[0], insets[1], insets[2], insets[3]), UIImageResizingMode.Stretch);
+ return new IOSBorder(borderImg, ninePatch.getTop(), ninePatch.getLeft(), ninePatch.getBottom(), ninePatch.getRight());
+ }
+ return null;
+ }
+
+ public IOSLookAndFeel() {
+ try {
+ InputStream data = SynthLookAndFeel.class.getResourceAsStream("/iOS_theme.xml");
+ load(data);
+ data.close();
+ }
+ catch (Exception ex) {
+ throw new IllegalStateException("can not find resource files for ios theme");
+ }
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|