mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
mobile/ebitenmobileview: Bug fix: Use Math.floor to shrink the size a little bit
Fixes #956
This commit is contained in:
parent
43a8881ab8
commit
bf07ead6ae
@ -377,20 +377,16 @@ public class EbitenView extends ViewGroup {
|
||||
initialized_ = true;
|
||||
}
|
||||
|
||||
int widthInDp = (int)Math.floor(pxToDp(right - left));
|
||||
int heightInDp = (int)Math.floor(pxToDp(bottom - top));
|
||||
int widthInDp = (int)Math.ceil(pxToDp(right - left));
|
||||
int heightInDp = (int)Math.ceil(pxToDp(bottom - top));
|
||||
Ebitenmobileview.layout(widthInDp, heightInDp, new ViewRectSetter() {
|
||||
@Override
|
||||
public void setViewRect(long xInDp, long yInDp, long widthInDp, long heightInDp) {
|
||||
int width = (int)Math.ceil(dpToPx(widthInDp));
|
||||
int height = (int)Math.ceil(dpToPx(heightInDp));
|
||||
int x = (int)Math.ceil(dpToPx(xInDp));
|
||||
int y = (int)Math.ceil(dpToPx(yInDp));
|
||||
// Use even numbers to avoid glitches (#956).
|
||||
final int xInPx = x / 2 * 2;
|
||||
final int yInPx = y / 2 * 2;
|
||||
final int widthInPx = width / 2 * 2;
|
||||
final int heightInPx = height / 2 * 2;
|
||||
// Use Math.floor to use smaller and safer values, or glitches can appear (#956).
|
||||
final int widthInPx = (int)Math.floor(dpToPx(widthInDp));
|
||||
final int heightInPx = (int)Math.floor(dpToPx(heightInDp));
|
||||
final int xInPx = (int)Math.floor(dpToPx(xInDp));
|
||||
final int yInPx = (int)Math.floor(dpToPx(yInDp));
|
||||
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
File diff suppressed because one or more lines are too long
@ -49,8 +49,10 @@ func layout(viewWidth, viewHeight int, viewRectSetter ViewRectSetter) {
|
||||
scaleY := float64(viewHeight) / float64(h)
|
||||
scale := math.Min(scaleX, scaleY)
|
||||
|
||||
width := int(math.Ceil(float64(w) * scale))
|
||||
height := int(math.Ceil(float64(h) * scale))
|
||||
// To convert a logical offscreen size to the actual screen size, use Math.floor to use smaller and safer
|
||||
// values, or glitches can appear (#956).
|
||||
width := int(math.Floor(float64(w) * scale))
|
||||
height := int(math.Floor(float64(h) * scale))
|
||||
x := (viewWidth - width) / 2
|
||||
y := (viewHeight - height) / 2
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user