Set screen offset for bitmap rendering

This commit is contained in:
Andrey Novikov 2016-07-19 12:24:37 +03:00
parent c8ff7a9e07
commit 418329441f
2 changed files with 39 additions and 1 deletions

View File

@ -1,5 +1,6 @@
/*
* Copyright 2013 Hannes Janetzek
* Copyright 2016 Andrey Novikov
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
@ -31,6 +32,9 @@ public class BitmapRenderer extends BucketRenderer {
private int mHeight;
private boolean initialized;
private boolean mUpdateBitmap;
private boolean center;
private int xOffset;
private int yOffset;
/**
* @param bitmap with dimension being power of two
@ -46,6 +50,12 @@ public class BitmapRenderer extends BucketRenderer {
initialized = false;
}
public synchronized void setDrawOffset(boolean center, int xOffset, int yOffset) {
this.center = center;
this.xOffset = xOffset;
this.yOffset = yOffset;
}
public synchronized void updateBitmap() {
mUpdateBitmap = true;
}
@ -80,7 +90,7 @@ public class BitmapRenderer extends BucketRenderer {
@Override
public synchronized void render(GLViewport v) {
v.useScreenCoordinates(false, 8);
v.setScreenOffset(center, xOffset, yOffset, 8);
BitmapBucket.Renderer.draw(buckets.get(), v, 1, 1);
}
}

View File

@ -1,3 +1,20 @@
/*
* Copyright 2013 Hannes Janetzek
* Copyright 2016 Andrey Novikov
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
* 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.renderer;
import org.oscim.core.MapPosition;
@ -45,6 +62,17 @@ public class GLViewport extends Viewport {
mvp.multiplyLhs(proj);
}
/**
* Set MVP offset in screen pixel coordinates
*/
public void setScreenOffset(boolean center, int xOffset, int yOffset, float scale) {
float invScale = 1f / scale;
float x = center ? xOffset : -mWidth / 2 + xOffset;
float y = center ? yOffset : -mHeight / 2 + yOffset;
mvp.setTransScale(x, y, invScale);
mvp.multiplyLhs(proj);
}
protected boolean changed;
public boolean changed() {