Render themes: SVG resources on iOS, improves #69
This commit is contained in:
parent
4c5de7453d
commit
21ea5a7842
@ -20,7 +20,7 @@ If you have any questions or problems, don't hesitate to ask our public [mailing
|
|||||||
- bitmap: any quadtree-scheme tiles as texture
|
- bitmap: any quadtree-scheme tiles as texture
|
||||||
- Backends:
|
- Backends:
|
||||||
- Android (optional libGDX)
|
- Android (optional libGDX)
|
||||||
- iOS (using libGDX/RoboVM)
|
- iOS (using libGDX/RoboVM) ([instructions](docs/ios.md))
|
||||||
- Desktop (using libGDX/JGLFW)
|
- Desktop (using libGDX/JGLFW)
|
||||||
- HTML5/WebGL (using libGDX/GWT)
|
- HTML5/WebGL (using libGDX/GWT)
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ If you have any questions or problems, don't hesitate to ask our public [mailing
|
|||||||
- **vtm-web** HTML5/GWT backend
|
- **vtm-web** HTML5/GWT backend
|
||||||
- **vtm-web-app** HTML5/GWT application
|
- **vtm-web-app** HTML5/GWT application
|
||||||
|
|
||||||
The libGDX backends for iOS and GWT are experimental.
|
The libGDX backend for GWT is experimental.
|
||||||
|
|
||||||
## Master build downloads
|
## Master build downloads
|
||||||
- [Latest jars and Samples applications](http://ci.mapsforge.org/job/vtm/)
|
- [Latest jars and Samples applications](http://ci.mapsforge.org/job/vtm/)
|
||||||
|
57
docs/ios.md
57
docs/ios.md
@ -1,50 +1,49 @@
|
|||||||
###Implement Exemple:
|
### Implementation example
|
||||||
|
|
||||||
RoboVm needs the native libs/frameworks for create a build!
|
RoboVm needs the native libs / frameworks to create a build.
|
||||||
Copy this files from vtm-ios-0.6.0-SNAPSHOT-natives.jar into a temp folder!
|
Copy those files from `vtm-ios-0.6.0-SNAPSHOT-natives.jar` into a temp folder.
|
||||||
|
|
||||||
Create a copy task into your <b>build.gradle</b>
|
Create a copy task into your **build.gradle**.
|
||||||
|
|
||||||
```java
|
```groovy
|
||||||
task copyFrameWorks(type: Copy) {
|
task copyFrameWorks(type: Copy) {
|
||||||
from(zipTree("./libs/vtm-ios-0.6.0-SNAPSHOT-natives.jar"))
|
from(zipTree("./libs/vtm-ios-0.6.0-SNAPSHOT-natives.jar"))
|
||||||
into("${buildDir}/native")
|
into("${buildDir}/native")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
tasks.withType(org.gradle.api.tasks.compile.JavaCompile) {
|
tasks.withType(org.gradle.api.tasks.compile.JavaCompile) {
|
||||||
compileTask -> compileTask.dependsOn copyFrameWorks
|
compileTask -> compileTask.dependsOn copyFrameWorks
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Now you can configure your robovm.xml to implement the vtm-natives and the SVG-Framework
|
Now you can configure your `robovm.xml` to implement the vtm-natives and the SVG-Framework.
|
||||||
|
|
||||||
```
|
```xml
|
||||||
<libs>
|
<libs>
|
||||||
<lib>z</lib>
|
<lib>z</lib>
|
||||||
<lib>build/native/libvtm-jni.a</lib> <!--vtm native -->
|
<lib>build/native/libvtm-jni.a</lib> <!--vtm native -->
|
||||||
</libs>
|
</libs>
|
||||||
<frameworkPaths>
|
<frameworkPaths>
|
||||||
<path>build/native</path> <!--SVGgh framework path -->
|
<path>build/native</path> <!--SVGgh framework path -->
|
||||||
</frameworkPaths>
|
</frameworkPaths>
|
||||||
<frameworks>
|
<frameworks>
|
||||||
<framework>SVGgh</framework> <!--SVGgh framework name -->
|
<framework>SVGgh</framework> <!--SVGgh framework name -->
|
||||||
<framework>UIKit</framework>
|
<framework>UIKit</framework>
|
||||||
<framework>OpenGLES</framework>
|
<framework>OpenGLES</framework>
|
||||||
<framework>QuartzCore</framework>
|
<framework>QuartzCore</framework>
|
||||||
<framework>CoreGraphics</framework>
|
<framework>CoreGraphics</framework>
|
||||||
<framework>OpenAL</framework>
|
<framework>OpenAL</framework>
|
||||||
<framework>AudioToolbox</framework>
|
<framework>AudioToolbox</framework>
|
||||||
<framework>AVFoundation</framework>
|
<framework>AVFoundation</framework>
|
||||||
</frameworks>
|
</frameworks>
|
||||||
```
|
```
|
||||||
|
|
||||||
Remember, the implementation of a iOS- framework is possible since iOS 8!
|
Remember the implementation of a iOS framework is possible since iOS 8.
|
||||||
So we must set the min iOS-Version at Info.plist.xml!
|
So we must set the min iOS-Version at `Info.plist.xml`.
|
||||||
|
|
||||||
```
|
```xml
|
||||||
<dict>
|
<dict>
|
||||||
<key>MinimumOSVersion</key>
|
<key>MinimumOSVersion</key>
|
||||||
<string>8.0</string>
|
<string>8.0</string>
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
@ -123,10 +123,11 @@ public class IosBitmap implements Bitmap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* protected constructor for create IosBitmap from IosSvgBitmap
|
* Protected constructor for create IosBitmap from IosSvgBitmap.
|
||||||
|
*
|
||||||
* @param image
|
* @param image
|
||||||
*/
|
*/
|
||||||
protected IosBitmap(UIImage image){
|
protected IosBitmap(UIImage image) {
|
||||||
CGImage cgiIimage = image.getCGImage();
|
CGImage cgiIimage = image.getCGImage();
|
||||||
this.width = (int) cgiIimage.getWidth();
|
this.width = (int) cgiIimage.getWidth();
|
||||||
this.height = (int) cgiIimage.getHeight();
|
this.height = (int) cgiIimage.getHeight();
|
||||||
@ -138,7 +139,6 @@ public class IosBitmap implements Bitmap {
|
|||||||
// can dispose helper images for release memory
|
// can dispose helper images for release memory
|
||||||
image.dispose();
|
image.dispose();
|
||||||
cgiIimage.dispose();
|
cgiIimage.dispose();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ public class IosGraphics extends CanvasAdapter {
|
|||||||
try {
|
try {
|
||||||
return new IosSvgBitmap(inputStream);
|
return new IosSvgBitmap(inputStream);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("decodeSvgImpl", e);
|
log.error("decodeSvgBitmapImpl", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2016 Longri
|
* Copyright 2016 Longri
|
||||||
|
* Copyright 2016 devemux86
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under the
|
* This program is free software: you can redistribute it and/or modify it under the
|
||||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||||
@ -14,34 +15,43 @@
|
|||||||
*/
|
*/
|
||||||
package org.oscim.ios.backend;
|
package org.oscim.ios.backend;
|
||||||
|
|
||||||
|
|
||||||
import org.oscim.backend.CanvasAdapter;
|
import org.oscim.backend.CanvasAdapter;
|
||||||
|
import org.oscim.utils.IOUtils;
|
||||||
import org.robovm.apple.coregraphics.CGRect;
|
import org.robovm.apple.coregraphics.CGRect;
|
||||||
import org.robovm.apple.coregraphics.CGSize;
|
import org.robovm.apple.coregraphics.CGSize;
|
||||||
import org.robovm.apple.uikit.UIImage;
|
import org.robovm.apple.uikit.UIImage;
|
||||||
import svg.SVGRenderer;
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
/**
|
import svg.SVGRenderer;
|
||||||
* Created by Longri on 17.07.16.
|
|
||||||
*/
|
|
||||||
public class IosSvgBitmap extends IosBitmap {
|
public class IosSvgBitmap extends IosBitmap {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(IosSvgBitmap.class);
|
||||||
|
|
||||||
private static final float DEFAULT_SIZE = 400f;
|
private static final float DEFAULT_SIZE = 400f;
|
||||||
|
|
||||||
/**
|
private static String getStringFromInputStream(InputStream is) {
|
||||||
* Constructor<br>
|
StringBuilder sb = new StringBuilder();
|
||||||
* @param inputStream
|
BufferedReader br = null;
|
||||||
* @throws IOException
|
String line;
|
||||||
*/
|
try {
|
||||||
public IosSvgBitmap(InputStream inputStream) throws IOException {
|
br = new BufferedReader(new InputStreamReader(is));
|
||||||
super(getUIImage(inputStream));
|
while ((line = br.readLine()) != null) {
|
||||||
|
sb.append(line);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
} finally {
|
||||||
|
IOUtils.closeQuietly(br);
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
//get UIImage from SVG file
|
|
||||||
private static UIImage getUIImage(InputStream inputStream) {
|
private static UIImage getUIImage(InputStream inputStream) {
|
||||||
String svg = getStringFromInputStream(inputStream);
|
String svg = getStringFromInputStream(inputStream);
|
||||||
SVGRenderer renderer = new SVGRenderer(svg);
|
SVGRenderer renderer = new SVGRenderer(svg);
|
||||||
@ -56,32 +66,7 @@ public class IosSvgBitmap extends IosBitmap {
|
|||||||
return renderer.asImageWithSize(new CGSize(bitmapWidth, bitmapHeight), 1);
|
return renderer.asImageWithSize(new CGSize(bitmapWidth, bitmapHeight), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IosSvgBitmap(InputStream inputStream) throws IOException {
|
||||||
// convert InputStream to String
|
super(getUIImage(inputStream));
|
||||||
private static String getStringFromInputStream(InputStream is) {
|
|
||||||
|
|
||||||
BufferedReader br = null;
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
|
|
||||||
String line;
|
|
||||||
try {
|
|
||||||
|
|
||||||
br = new BufferedReader(new InputStreamReader(is));
|
|
||||||
while ((line = br.readLine()) != null) {
|
|
||||||
sb.append(line);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
if (br != null) {
|
|
||||||
try {
|
|
||||||
br.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,10 @@ import org.robovm.apple.coregraphics.CGAffineTransform;
|
|||||||
import org.robovm.apple.foundation.NSObjectProtocol;
|
import org.robovm.apple.foundation.NSObjectProtocol;
|
||||||
import org.robovm.objc.annotation.Property;
|
import org.robovm.objc.annotation.Property;
|
||||||
|
|
||||||
public interface GHRenderable extends NSObjectProtocol{
|
public interface GHRenderable extends NSObjectProtocol {
|
||||||
@Property(selector = "transform")
|
@Property(selector = "transform")
|
||||||
public CGAffineTransform getTransform();
|
public CGAffineTransform getTransform();
|
||||||
|
|
||||||
@Property(selector = "hidden")
|
@Property(selector = "hidden")
|
||||||
public boolean isHidden();
|
public boolean isHidden();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,10 @@ import org.robovm.apple.foundation.NSObject;
|
|||||||
import org.robovm.apple.uikit.UIColor;
|
import org.robovm.apple.uikit.UIColor;
|
||||||
import org.robovm.objc.annotation.Method;
|
import org.robovm.objc.annotation.Method;
|
||||||
|
|
||||||
public interface SVGContext {
|
public interface SVGContext {
|
||||||
@Method(selector = "colorForSVGColorString:")
|
@Method(selector = "colorForSVGColorString:")
|
||||||
public UIColor colorForSVGColorString(String svgColorString);
|
public UIColor colorForSVGColorString(String svgColorString);
|
||||||
|
|
||||||
@Method(selector = "objectAtURL:")
|
@Method(selector = "objectAtURL:")
|
||||||
public NSObject objectAtURL(String aLocation);
|
public NSObject objectAtURL(String aLocation);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,22 +10,39 @@ import org.robovm.rt.bro.annotation.Library;
|
|||||||
import org.robovm.rt.bro.annotation.Pointer;
|
import org.robovm.rt.bro.annotation.Pointer;
|
||||||
import org.robovm.rt.bro.ptr.Ptr;
|
import org.robovm.rt.bro.ptr.Ptr;
|
||||||
|
|
||||||
@Library(Library.INTERNAL)
|
@Library(Library.INTERNAL)
|
||||||
@NativeClass("SVGParser")
|
@NativeClass("SVGParser")
|
||||||
public class SVGParser extends NSObject {
|
public class SVGParser extends NSObject {
|
||||||
public static class SVGParserPtr extends Ptr<SVGParser, SVGParserPtr> {}
|
public static class SVGParserPtr extends Ptr<SVGParser, SVGParserPtr> {
|
||||||
static { ObjCRuntime.bind(SVGParser.class); }/*</bind>*/
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
ObjCRuntime.bind(SVGParser.class);
|
||||||
|
}/*</bind>*/
|
||||||
|
|
||||||
|
public SVGParser() {
|
||||||
|
}
|
||||||
|
|
||||||
|
;
|
||||||
|
|
||||||
|
protected SVGParser(long handle) {
|
||||||
|
super(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected SVGParser(SkipInit skipInit) {
|
||||||
|
super(skipInit);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SVGParser(String utf8String) {
|
||||||
|
super((SkipInit) null);
|
||||||
|
initObject(init(utf8String));
|
||||||
|
}
|
||||||
|
|
||||||
public SVGParser() {};
|
|
||||||
protected SVGParser(long handle) { super(handle); }
|
|
||||||
protected SVGParser(SkipInit skipInit) { super(skipInit); }
|
|
||||||
|
|
||||||
public SVGParser(String utf8String) { super((SkipInit) null); initObject(init(utf8String)); }
|
|
||||||
|
|
||||||
@Method(selector = "initWithString:")
|
@Method(selector = "initWithString:")
|
||||||
protected native @Pointer long init(String utf8String);
|
protected native
|
||||||
|
@Pointer
|
||||||
|
long init(String utf8String);
|
||||||
|
|
||||||
@Property(selector = "parserError")
|
@Property(selector = "parserError")
|
||||||
public native NSError getParserError();
|
public native NSError getParserError();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,37 +16,56 @@ import org.robovm.rt.bro.annotation.MachineSizedFloat;
|
|||||||
import org.robovm.rt.bro.annotation.Pointer;
|
import org.robovm.rt.bro.annotation.Pointer;
|
||||||
import org.robovm.rt.bro.ptr.Ptr;
|
import org.robovm.rt.bro.ptr.Ptr;
|
||||||
|
|
||||||
@Library(Library.INTERNAL)
|
@Library(Library.INTERNAL)
|
||||||
@NativeClass("SVGRenderer")
|
@NativeClass("SVGRenderer")
|
||||||
public class SVGRenderer extends SVGParser implements SVGContext, GHRenderable {
|
public class SVGRenderer extends SVGParser implements SVGContext, GHRenderable {
|
||||||
public static class SVGRendererPtr extends Ptr<SVGRenderer, SVGRendererPtr> {}
|
public static class SVGRendererPtr extends Ptr<SVGRenderer, SVGRendererPtr> {
|
||||||
static { ObjCRuntime.bind(SVGRenderer.class); }/*</bind>*/
|
}
|
||||||
|
|
||||||
public SVGRenderer() {};
|
static {
|
||||||
protected SVGRenderer(long handle) { super(handle); }
|
ObjCRuntime.bind(SVGRenderer.class);
|
||||||
protected SVGRenderer(SkipInit skipInit) { super(skipInit); }
|
}/*</bind>*/
|
||||||
|
|
||||||
|
public SVGRenderer() {
|
||||||
|
}
|
||||||
|
|
||||||
|
;
|
||||||
|
|
||||||
|
protected SVGRenderer(long handle) {
|
||||||
|
super(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected SVGRenderer(SkipInit skipInit) {
|
||||||
|
super(skipInit);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SVGRenderer(String utf8String) {
|
||||||
|
super((SkipInit) null);
|
||||||
|
initObject(init(utf8String));
|
||||||
|
}
|
||||||
|
|
||||||
public SVGRenderer(String utf8String) { super((SkipInit) null); initObject(init(utf8String)); }
|
|
||||||
|
|
||||||
@Method(selector = "initWithString:")
|
@Method(selector = "initWithString:")
|
||||||
protected native @Pointer long init(String utf8String);
|
protected native
|
||||||
|
@Pointer
|
||||||
|
long init(String utf8String);
|
||||||
|
|
||||||
@Property(selector = "viewRect")
|
@Property(selector = "viewRect")
|
||||||
public native @ByVal CGRect getViewRect();
|
public native
|
||||||
|
@ByVal
|
||||||
|
CGRect getViewRect();
|
||||||
|
|
||||||
@Method(selector = "colorForSVGColorString:")
|
@Method(selector = "colorForSVGColorString:")
|
||||||
public native UIColor colorForSVGColorString(String svgColorString);
|
public native UIColor colorForSVGColorString(String svgColorString);
|
||||||
|
|
||||||
@Method(selector = "objectAtURL:")
|
@Method(selector = "objectAtURL:")
|
||||||
public native NSObject objectAtURL(String aLocation);
|
public native NSObject objectAtURL(String aLocation);
|
||||||
|
|
||||||
@Property(selector = "transform")
|
@Property(selector = "transform")
|
||||||
public native CGAffineTransform getTransform();
|
public native CGAffineTransform getTransform();
|
||||||
|
|
||||||
@Property(selector = "hidden")
|
@Property(selector = "hidden")
|
||||||
public native boolean isHidden();
|
public native boolean isHidden();
|
||||||
|
|
||||||
@Method(selector = "asImageWithSize:andScale:")
|
@Method(selector = "asImageWithSize:andScale:")
|
||||||
public native UIImage asImageWithSize(@ByVal CGSize maximumSize, @MachineSizedFloat double scale);
|
public native UIImage asImageWithSize(@ByVal CGSize maximumSize, @MachineSizedFloat double scale);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user