From 3e8ea1aa78e0e684f502c3b01551bcbc437466d7 Mon Sep 17 00:00:00 2001 From: dgis Date: Fri, 29 Nov 2019 08:41:40 +0100 Subject: [PATCH] Version 1.2beta5 (2019-11-28) Improve overlapping LCD screen --- ReadMe.txt | 4 +- app/build.gradle | 2 +- app/src/main/assets/ReadMe.txt | 4 +- .../calculator/LCDOverlappingView.java | 101 +++++++++--------- .../emulator/calculator/MainScreenView.java | 17 +++ app/src/main/res/values/arrays.xml | 4 +- 6 files changed, 75 insertions(+), 57 deletions(-) diff --git a/ReadMe.txt b/ReadMe.txt index 6643c83..b61bf2e 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -54,12 +54,12 @@ NOT WORKING YET CHANGES -Version 1.7beta3 (2019-11-24) +Version 1.7beta3 (2019-11-28) - Updated source code from Eric Rechlin's Emu48 version 1.61+ that was merged from Christoph Gießelink's Emu48 version 1.62. - Allow to take a screenshot of the fullscreen including the skin. - Add the KML Icon if present in the navigation menu header (only support PNG or 32bits BMP in the ICO file). -- Add an optional overlapping LCD part stuck to the screen when swiping the 2 calc parts (Experimental). +- Add an optional overlapping LCD part stuck to the screen when swiping the 2 calc parts. - Improve loading speed by caching the KML folder. - Support the transparency in the KML Global Color. diff --git a/app/build.gradle b/app/build.gradle index faa77b2..1f5a5df 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -33,7 +33,7 @@ android { applicationId "org.emulator.forty.eight" minSdkVersion 19 targetSdkVersion 28 - versionCode 9 + versionCode 10 versionName "1.7" setProperty("archivesBaseName", "Emu48-v$versionName") testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" diff --git a/app/src/main/assets/ReadMe.txt b/app/src/main/assets/ReadMe.txt index 3e9e3d9..4666650 100644 --- a/app/src/main/assets/ReadMe.txt +++ b/app/src/main/assets/ReadMe.txt @@ -54,12 +54,12 @@ NOT WORKING YET CHANGES -Version 1.7beta3 (2019-11-24) +Version 1.7beta3 (2019-11-28) - Updated source code from Eric Rechlin's Emu48 version 1.61+ that was merged from Christoph Gießelink's Emu48 version 1.62. - Allow to take a screenshot of the fullscreen including the skin. - Add the KML Icon if present in the navigation menu header (only support PNG or 32bits BMP in the ICO file). -- Add an optional overlapping LCD part stuck to the screen when swiping the 2 calc parts (Experimental). +- Add an optional overlapping LCD part stuck to the screen when swiping the 2 calc parts. - Improve loading speed by caching the KML folder. - Support the transparency in the KML Global Color. diff --git a/app/src/main/java/org/emulator/calculator/LCDOverlappingView.java b/app/src/main/java/org/emulator/calculator/LCDOverlappingView.java index df65119..b6768ba 100644 --- a/app/src/main/java/org/emulator/calculator/LCDOverlappingView.java +++ b/app/src/main/java/org/emulator/calculator/LCDOverlappingView.java @@ -1,3 +1,17 @@ +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 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 General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + package org.emulator.calculator; import android.app.Activity; @@ -221,8 +235,7 @@ public class LCDOverlappingView extends View { return; switch (type) { case NativeLib.CALLBACK_TYPE_INVALIDATE: - //if(debug) Log.d(TAG, "PAINT updateCallback() postInvalidate()"); - if(debug) Log.d(TAG, "updateCallback() CALLBACK_TYPE_INVALIDATE"); + //if(debug) Log.d(TAG, "updateCallback() CALLBACK_TYPE_INVALIDATE"); if(bitmapLCD.getWidth() > 1) postInvalidate(); break; @@ -265,32 +278,22 @@ public class LCDOverlappingView extends View { int lcdHeight = Math.max(1, NativeLib.getScreenHeight()); if(this.overlappingLCDMode == OVERLAPPING_LCD_MODE_AUTO) { - float viewPanOffsetX = this.mainScreenView.viewPanOffsetX; - float viewPanOffsetY = this.mainScreenView.viewPanOffsetY; - float viewScaleFactorX = this.mainScreenView.viewScaleFactorX; - float viewScaleFactorY = this.mainScreenView.viewScaleFactorY; - - int finalViewWidth = (int) (lcdWidth * viewScaleFactorX); - int finalViewHeight = (int) (lcdHeight * viewScaleFactorY); post(() -> { - FrameLayout.LayoutParams viewFlowLayout = new FrameLayout.LayoutParams(finalViewWidth, finalViewHeight); - if(viewPanOffsetX > 0) - viewFlowLayout.leftMargin = (int)(viewScaleFactorX * NativeLib.getScreenPositionX() + viewPanOffsetX); - else - viewFlowLayout.leftMargin = this.mainScreenView.getWidth() - (int)(viewScaleFactorX * (this.mainScreenView.virtualSizeWidth - NativeLib.getScreenPositionX())); - if(viewPanOffsetY >= 0) - viewFlowLayout.topMargin = (int)(viewScaleFactorY * NativeLib.getScreenPositionY() + viewPanOffsetY); - else - viewFlowLayout.topMargin = (int)(viewScaleFactorY * NativeLib.getScreenPositionY()); - int tolerance = 80; - if (viewFlowLayout.leftMargin + finalViewWidth < tolerance) + int viewLCDWidth = (int) (lcdWidth * this.mainScreenView.defaultViewScaleFactorX); + int viewLCDHeight = (int) (lcdHeight * this.mainScreenView.defaultViewScaleFactorY); + FrameLayout.LayoutParams viewFlowLayout = new FrameLayout.LayoutParams(viewLCDWidth, viewLCDHeight); + viewFlowLayout.leftMargin = (int)(this.mainScreenView.defaultViewScaleFactorX * (float)NativeLib.getScreenPositionX() + this.mainScreenView.defaultViewPanOffsetX); + viewFlowLayout.topMargin = (int)(this.mainScreenView.defaultViewScaleFactorY * (float)NativeLib.getScreenPositionY() + this.mainScreenView.defaultViewPanOffsetY); + + int tolerance = 80; // In case of miscalculation + if (viewFlowLayout.leftMargin + viewLCDWidth < tolerance) viewFlowLayout.leftMargin = 0; if (viewFlowLayout.leftMargin + tolerance > this.mainScreenView.getWidth()) - viewFlowLayout.leftMargin = this.mainScreenView.getWidth() - finalViewWidth; - if (viewFlowLayout.topMargin + finalViewHeight < tolerance) + viewFlowLayout.leftMargin = this.mainScreenView.getWidth() - viewLCDWidth; + if (viewFlowLayout.topMargin + viewLCDHeight < tolerance) viewFlowLayout.topMargin = 0; if (viewFlowLayout.topMargin + tolerance > this.mainScreenView.getHeight()) - viewFlowLayout.topMargin = this.mainScreenView.getHeight() - finalViewHeight; + viewFlowLayout.topMargin = this.mainScreenView.getHeight() - viewLCDHeight; if(debug) Log.d(TAG, "updateLayout() leftMargin: " + viewFlowLayout.leftMargin + ", topMargin: " + viewFlowLayout.topMargin + ", width: " + viewFlowLayout.width + ", height: " + viewFlowLayout.height); setLayoutParams(viewFlowLayout); @@ -299,39 +302,37 @@ public class LCDOverlappingView extends View { } else if(this.overlappingLCDMode == OVERLAPPING_LCD_MODE_MANUAL) { if(firstTime) { firstTime = false; - float scale = sharedPreferences.getFloat("settings_lcd_overlapping_scale", 1.0f); - if (scale < 0.01f) - scale = 0.01f; - int viewWidth = (int) (lcdWidth * scale); - int viewHeight = (int) (lcdHeight * scale); - if (viewWidth < minViewSize && viewHeight < minViewSize) { - if (bitmapRatio > 0.0f) { - if (bitmapRatio < 1.0f) { - viewWidth = (int) minViewSize; - viewHeight = (int) (viewWidth * bitmapRatio); - } else { - viewHeight = (int) minViewSize; - viewWidth = (int) (viewHeight / bitmapRatio); - } - } else { - viewWidth = (int) minViewSize; - viewHeight = (int) minViewSize; - } - } - - int finalViewWidth = viewWidth; - int finalViewHeight = viewHeight; post(() -> { - FrameLayout.LayoutParams viewFlowLayout = new FrameLayout.LayoutParams(finalViewWidth, finalViewHeight); + float scale = sharedPreferences.getFloat("settings_lcd_overlapping_scale", 1.0f); + if (scale < 0.01f) + scale = 0.01f; + int viewWidth = (int) (lcdWidth * scale); + int viewHeight = (int) (lcdHeight * scale); + if (viewWidth < minViewSize && viewHeight < minViewSize) { + if (bitmapRatio > 0.0f) { + if (bitmapRatio < 1.0f) { + viewWidth = (int) minViewSize; + viewHeight = (int) (viewWidth * bitmapRatio); + } else { + viewHeight = (int) minViewSize; + viewWidth = (int) (viewHeight / bitmapRatio); + } + } else { + viewWidth = (int) minViewSize; + viewHeight = (int) minViewSize; + } + } + + FrameLayout.LayoutParams viewFlowLayout = new FrameLayout.LayoutParams(viewWidth, viewHeight); viewFlowLayout.leftMargin = sharedPreferences.getInt("settings_lcd_overlapping_x", 20); viewFlowLayout.topMargin = sharedPreferences.getInt("settings_lcd_overlapping_y", 80); int tolerance = 80; - if (viewFlowLayout.leftMargin + finalViewWidth < tolerance) - viewFlowLayout.leftMargin = tolerance - finalViewWidth; + if (viewFlowLayout.leftMargin + viewWidth < tolerance) + viewFlowLayout.leftMargin = tolerance - viewWidth; if (viewFlowLayout.leftMargin + tolerance > this.mainScreenView.getWidth()) viewFlowLayout.leftMargin = this.mainScreenView.getWidth() - tolerance; - if (viewFlowLayout.topMargin + finalViewHeight < tolerance) - viewFlowLayout.topMargin = tolerance - finalViewHeight; + if (viewFlowLayout.topMargin + viewHeight < tolerance) + viewFlowLayout.topMargin = tolerance - viewHeight; if (viewFlowLayout.topMargin + tolerance > this.mainScreenView.getHeight()) viewFlowLayout.topMargin = this.mainScreenView.getHeight() - tolerance; if(debug) Log.d(TAG, "updateLayout() leftMargin: " + viewFlowLayout.leftMargin + ", topMargin: " + viewFlowLayout.topMargin diff --git a/app/src/main/java/org/emulator/calculator/MainScreenView.java b/app/src/main/java/org/emulator/calculator/MainScreenView.java index e274274..24aa661 100644 --- a/app/src/main/java/org/emulator/calculator/MainScreenView.java +++ b/app/src/main/java/org/emulator/calculator/MainScreenView.java @@ -50,6 +50,12 @@ public class MainScreenView extends PanAndScaleView { private boolean autoRotation = false; private boolean autoZoom = false; + public float defaultViewScaleFactorX = 1.0f; + public float defaultViewScaleFactorY = 1.0f; + public float defaultViewPanOffsetX = 0.0f; + public float defaultViewPanOffsetY = 0.0f; + + public MainScreenView(Context context) { super(context); @@ -294,6 +300,12 @@ public class MainScreenView extends PanAndScaleView { viewPanOffsetY = translateY; constrainPan(); + + defaultViewScaleFactorX = viewScaleFactorX; + defaultViewScaleFactorY = viewScaleFactorY; + defaultViewPanOffsetX = viewPanOffsetX; + defaultViewPanOffsetY = viewPanOffsetY; + if(this.onUpdateLayoutListener != null) this.onUpdateLayoutListener.run(); return; @@ -304,6 +316,11 @@ public class MainScreenView extends PanAndScaleView { // Else, the screens orientations are the same, so we set the calculator in fullscreen resetViewport(); + defaultViewScaleFactorX = viewScaleFactorX; + defaultViewScaleFactorY = viewScaleFactorY; + defaultViewPanOffsetX = viewPanOffsetX; + defaultViewPanOffsetY = viewPanOffsetY; + if(this.onUpdateLayoutListener != null) this.onUpdateLayoutListener.run(); } diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 8c72c14..7ed5f23 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -38,8 +38,8 @@ No Overlapping LCD - Auto - Manual + Auto (Double touch) + Manual (Zoom or pan) 0