diff --git a/vtm-ios/src/org/oscim/ios/IOSMapApp.java b/vtm-ios/src/org/oscim/ios/IOSMapApp.java index f17151ac..3575511a 100644 --- a/vtm-ios/src/org/oscim/ios/IOSMapApp.java +++ b/vtm-ios/src/org/oscim/ios/IOSMapApp.java @@ -17,21 +17,59 @@ */ package org.oscim.ios; - import org.oscim.backend.GLAdapter; import org.oscim.gdx.GdxAssets; import org.oscim.gdx.GdxMap; import org.oscim.ios.backend.IosGL; import org.oscim.ios.backend.IosGraphics; - +import org.oscim.layers.GroupLayer; +import org.oscim.layers.tile.buildings.BuildingLayer; +import org.oscim.layers.tile.vector.VectorTileLayer; +import org.oscim.layers.tile.vector.labeling.LabelLayer; +import org.oscim.map.Map; +import org.oscim.renderer.BitmapRenderer; +import org.oscim.renderer.GLViewport; +import org.oscim.scalebar.DefaultMapScaleBar; +import org.oscim.scalebar.ImperialUnitAdapter; +import org.oscim.scalebar.MapScaleBar; +import org.oscim.scalebar.MapScaleBarLayer; +import org.oscim.scalebar.MetricUnitAdapter; +import org.oscim.theme.VtmThemes; +import org.oscim.tiling.source.oscimap4.OSciMap4TileSource; public class IOSMapApp extends GdxMap { public static void init() { - // init globals IosGraphics.init(); GdxAssets.init("assets/"); GLAdapter.init(new IosGL()); } + + @Override + public void createLayers() { + Map map = getMap(); + + VectorTileLayer l = map.setBaseMap(new OSciMap4TileSource()); + + GroupLayer groupLayer = new GroupLayer(mMap); + groupLayer.layers.add(new BuildingLayer(map, l)); + groupLayer.layers.add(new LabelLayer(map, l)); + map.layers().add(groupLayer); + + DefaultMapScaleBar mapScaleBar = new DefaultMapScaleBar(mMap); + mapScaleBar.setScaleBarMode(DefaultMapScaleBar.ScaleBarMode.BOTH); + mapScaleBar.setDistanceUnitAdapter(MetricUnitAdapter.INSTANCE); + mapScaleBar.setSecondaryDistanceUnitAdapter(ImperialUnitAdapter.INSTANCE); + mapScaleBar.setScaleBarPosition(MapScaleBar.ScaleBarPosition.BOTTOM_LEFT); + + MapScaleBarLayer mapScaleBarLayer = new MapScaleBarLayer(mMap, mapScaleBar); + BitmapRenderer renderer = mapScaleBarLayer.getRenderer(); + renderer.setPosition(GLViewport.Position.BOTTOM_LEFT); + renderer.setOffset(5, 0); + map.layers().add(mapScaleBarLayer); + + map.setTheme(VtmThemes.DEFAULT); + map.setMapPosition(53.075, 8.808, 1 << 17); + } } diff --git a/vtm-ios/src/org/oscim/ios/RobovmLauncher.java b/vtm-ios/src/org/oscim/ios/RobovmLauncher.java index 88c6a8db..b862db15 100644 --- a/vtm-ios/src/org/oscim/ios/RobovmLauncher.java +++ b/vtm-ios/src/org/oscim/ios/RobovmLauncher.java @@ -1,15 +1,24 @@ +/* + * Copyright 2016 Longri + * Copyright 2016 devemux86 + * + * 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 + * Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * this program. If not, see . + */ package org.oscim.ios; import com.badlogic.gdx.backends.iosrobovm.IOSApplication; import com.badlogic.gdx.backends.iosrobovm.IOSApplicationConfiguration; import org.oscim.backend.CanvasAdapter; -import org.oscim.layers.tile.buildings.BuildingLayer; -import org.oscim.layers.tile.vector.VectorTileLayer; -import org.oscim.layers.tile.vector.labeling.LabelLayer; -import org.oscim.map.Map; -import org.oscim.theme.VtmThemes; -import org.oscim.tiling.source.oscimap4.OSciMap4TileSource; import org.robovm.apple.foundation.NSAutoreleasePool; import org.robovm.apple.glkit.GLKViewDrawableStencilFormat; import org.robovm.apple.uikit.UIApplication; @@ -20,46 +29,25 @@ public class RobovmLauncher extends IOSApplication.Delegate { @Override protected IOSApplication createApplication() { - IOSApplicationConfiguration config = new IOSApplicationConfiguration(); config.orientationLandscape = true; config.orientationPortrait = true; config.stencilFormat = GLKViewDrawableStencilFormat._8; - float scale = (float) (getIosVersion() >= 8 ? UIScreen.getMainScreen().getNativeScale() : UIScreen.getMainScreen() - .getScale()); - + float scale = (float) (getIosVersion() >= 8 ? UIScreen.getMainScreen().getNativeScale() : UIScreen.getMainScreen().getScale()); CanvasAdapter.dpi *= scale; - IOSMapApp iosMapApp = new IOSMapApp() { - @Override - public void createLayers() { - Map map = getMap(); - - - VectorTileLayer l = map.setBaseMap(new OSciMap4TileSource()); - - map.layers().add(new BuildingLayer(map, l)); - map.layers().add(new LabelLayer(map, l)); - - map.setTheme(VtmThemes.DEFAULT); - map.setMapPosition(53.075, 8.808, 1 << 17); - } - - }; - + IOSMapApp iosMapApp = new IOSMapApp(); IOSMapApp.init(); return new IOSApplication(iosMapApp, config); } - private int getIosVersion() { String systemVersion = UIDevice.getCurrentDevice().getSystemVersion(); return Integer.parseInt(systemVersion.split("\\.")[0]); } - public static void main(String[] argv) { NSAutoreleasePool pool = new NSAutoreleasePool(); System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "TRACE"); diff --git a/vtm-ios/src/org/oscim/ios/backend/IosCanvas.java b/vtm-ios/src/org/oscim/ios/backend/IosCanvas.java index e4cc2c72..6e0285b7 100644 --- a/vtm-ios/src/org/oscim/ios/backend/IosCanvas.java +++ b/vtm-ios/src/org/oscim/ios/backend/IosCanvas.java @@ -19,6 +19,7 @@ import org.oscim.backend.canvas.Bitmap; import org.oscim.backend.canvas.Canvas; import org.oscim.backend.canvas.Paint; import org.robovm.apple.coregraphics.CGBitmapContext; +import org.robovm.apple.coregraphics.CGBlendMode; import org.robovm.apple.coregraphics.CGRect; /** @@ -26,6 +27,28 @@ import org.robovm.apple.coregraphics.CGRect; */ public class IosCanvas implements Canvas { + static void setFillColor(CGBitmapContext bctx, int color) { + float blue = (color & 0xFF) / 255f; + color >>= 8; + float green = (color & 0xFF) / 255f; + color >>= 8; + float red = (color & 0xFF) / 255f; + color >>= 8; + float alpha = (color & 0xFF) / 255f; + bctx.setRGBFillColor(red, green, blue, alpha); + } + + static void setStrokeColor(CGBitmapContext bctx, int color) { + float blue = (color & 0xFF) / 255f; + color >>= 8; + float green = (color & 0xFF) / 255f; + color >>= 8; + float red = (color & 0xFF) / 255f; + color >>= 8; + float alpha = (color & 0xFF) / 255f; + bctx.setRGBStrokeColor(red, green, blue, alpha); + } + CGBitmapContext cgBitmapContext; @Override @@ -54,6 +77,7 @@ public class IosCanvas implements Canvas { IosPaint iosStroke = (IosPaint) stroke; iosFill.setStrokeWidth(iosStroke.strokeWidth); iosFill.setStrokeColor(iosStroke.getColor()); + iosStroke.drawLine(this.cgBitmapContext, string, x, y); } iosFill.drawLine(this.cgBitmapContext, string, x, y); } @@ -69,12 +93,32 @@ public class IosCanvas implements Canvas { @Override public void drawLine(int x1, int y1, int x2, int y2, Paint paint) { - // TODO + + //flip Y-axis + y1 = (int) (this.cgBitmapContext.getHeight() - y1); + y2 = (int) (this.cgBitmapContext.getHeight() - y2); + + // set Stroke properties + this.cgBitmapContext.setLineWidth(((IosPaint) paint).strokeWidth); + this.cgBitmapContext.setLineCap(((IosPaint) paint).getIosStrokeCap()); + this.cgBitmapContext.setLineJoin(((IosPaint) paint).getIosStrokeJoin()); + setStrokeColor(this.cgBitmapContext, (paint.getColor())); + + //draw line + this.cgBitmapContext.beginPath(); + this.cgBitmapContext.moveToPoint(x1, y1); + this.cgBitmapContext.addLineToPoint(x2, y2); + this.cgBitmapContext.strokePath(); } @Override public void fillColor(int color) { - // TODO + CGRect rect = new CGRect(0, 0, this.cgBitmapContext.getWidth(), this.cgBitmapContext.getHeight()); + setFillColor(this.cgBitmapContext, (color)); + this.cgBitmapContext.setBlendMode(CGBlendMode.Clear); + this.cgBitmapContext.fillRect(rect); + this.cgBitmapContext.setBlendMode(CGBlendMode.Normal); + this.cgBitmapContext.fillRect(rect); } @Override diff --git a/vtm-ios/src/org/oscim/ios/backend/IosPaint.java b/vtm-ios/src/org/oscim/ios/backend/IosPaint.java index 4fe54ea3..77fce1bc 100644 --- a/vtm-ios/src/org/oscim/ios/backend/IosPaint.java +++ b/vtm-ios/src/org/oscim/ios/backend/IosPaint.java @@ -114,11 +114,19 @@ public class IosPaint implements Paint { return new UIColor(colorR, colorG, colorB, colorA); } + public CGLineCap getIosStrokeCap() { + return this.cap; + } + @Override public void setStrokeCap(Cap cap) { this.cap = getLineCap(cap); } + public CGLineJoin getIosStrokeJoin() { + return this.join; + } + @Override public void setStrokeJoin(Join join) { this.join = getLineJoin(join); @@ -163,7 +171,6 @@ public class IosPaint implements Paint { } } - @Override public float measureText(String text) { if (ctLineIsDirty || !text.equals(lastText)) { @@ -173,7 +180,6 @@ public class IosPaint implements Paint { return (float) ctLine.getWidth(); } - private void createCTLine(String text) { if (ctLineIsDirty) { synchronized (attribs) { @@ -198,9 +204,7 @@ public class IosPaint implements Paint { } } - private void createIosFont() { - /* DEVICE_DEFAULT = [iOS == getDeviceDefault()], [Android == 'Roboto'] MONOSPACE = [iOS == 'Courier'], [Android == 'Droid Sans Mono'] @@ -208,7 +212,6 @@ public class IosPaint implements Paint { SERIF = [iOS == 'Georgia'], [Android == 'Droid Serif'] */ - String fontname = DEFAULT_FONT_NAME; switch (this.fontFamily) { case DEFAULT: @@ -309,7 +312,6 @@ public class IosPaint implements Paint { } } - public void drawLine(CGBitmapContext cgBitmapContext, String text, float x, float y) { if (ctLineIsDirty || !text.equals(lastText)) { ctLineIsDirty = true; @@ -318,7 +320,7 @@ public class IosPaint implements Paint { cgBitmapContext.saveGState(); cgBitmapContext.setShouldAntialias(true); cgBitmapContext.setTextPosition(x, y + descent); - cgBitmapContext.setBlendMode(CGBlendMode.Overlay); + cgBitmapContext.setBlendMode(CGBlendMode.Normal); ctLine.draw(cgBitmapContext); @@ -337,8 +339,7 @@ public class IosPaint implements Paint { @Override public float getTextHeight(String text) { - // TODO - return 0; + return this.fontHeight; } @Override