Enable / fix iOS module, closes #29

This commit is contained in:
Longri
2016-06-19 21:14:39 +02:00
committed by Emux
parent 2b171739aa
commit 11d7002841
14 changed files with 1519 additions and 306 deletions

View File

@@ -1,78 +1,64 @@
/*
* Copyright 2016 Longri
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.ios.backend;
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.CGRect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.TextureData;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.BitmapFont.Glyph;
/**
* iOS specific implementation of {@link Canvas}<br>
* <br>
* Created by Longri on 25.06.16.
*/
public class IosCanvas implements Canvas {
IosBitmap bitmap;
static BitmapFont font = new BitmapFont();
static final Logger log = LoggerFactory.getLogger(IosCanvas.class);
public IosCanvas() {
// canvas comes with gdx pixmap
}
CGBitmapContext cgBitmapContext;
@Override
public void setBitmap(Bitmap bitmap) {
this.bitmap = (IosBitmap) bitmap;
this.bitmap.pixmap.setColor(0);
this.bitmap.pixmap.fill();
}
@Override
public void setBitmap(Bitmap bitmap) {
cgBitmapContext = ((IosBitmap) bitmap).cgBitmapContext;
}
@Override
public void drawText(String string, float x, float y, Paint paint) {
if (bitmap == null) {
// log.debug("no bitmap set");
return;
}
@Override
public void drawText(String string, float x, float y, Paint fill, Paint stroke) {
// IosPaint p = (IosPaint) paint;
//flip Y-axis
y = this.cgBitmapContext.getHeight() - y;
Pixmap pixmap = bitmap.pixmap;
IosPaint iosFill = (IosPaint) fill;
if (stroke != null) {
IosPaint iosStroke = (IosPaint) stroke;
iosFill.setStrokeWidth(iosStroke.strokeWidth);
iosFill.setStrokeColor(iosStroke.getColor());
}
iosFill.drawLine(this.cgBitmapContext, string, x, y);
}
TextureData td = font.getRegion().getTexture().getTextureData();
if (!td.isPrepared())
td.prepare();
Pixmap f = td.consumePixmap();
int adv = (int) x;
Glyph last = null;
int ch = (int) font.getCapHeight();
int h = (int) font.getLineHeight();
int yy = (int) (y - font.getLineHeight());
if (y < 0)
y = 0;
// pixmap.setColor(0xff0000ff);
// int w = (int) font.getBounds(string).width;
// pixmap.drawRectangle((int) x - 4, (int) y - 4, w + 8, h + 8);
for (int i = 0; i < string.length(); i++) {
char c = string.charAt(i);
Glyph g = font.getData().getGlyph(c);
if (g == null)
g = font.getData().getGlyph(' ');
if (i > 0)
adv += last.getKerning(c);
pixmap.drawPixmap(f, adv, //- g.xoffset,
yy - (g.height + g.yoffset) - (h - ch),
g.srcX, g.srcY,
g.width, g.height);
adv += g.width;
last = g;
}
}
@Override
public void drawBitmap(Bitmap bitmap, float x, float y) {
}
@Override
public void drawBitmap(Bitmap bitmap, float x, float y) {
this.cgBitmapContext.saveGState();
this.cgBitmapContext.translateCTM(x, y);
this.cgBitmapContext.drawImage(new CGRect(0, 0, bitmap.getWidth(), bitmap.getHeight()),
((IosBitmap) bitmap).cgBitmapContext.toImage());
this.cgBitmapContext.restoreGState();
}
}