diff --git a/ReadMe.txt b/ReadMe.txt index c4394a1..23e80d9 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -58,7 +58,7 @@ Version 1.7 (2019-08-XX) - 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). -- Allow an optional overlapping LCD part stuck to the screen when swiping the 2 calc parts. +- Add an optional overlapping LCD part stuck to the screen when swiping the 2 calc parts (Experimental). Version 1.6 (2019-07-15) @@ -165,16 +165,14 @@ The Eric's Real scripts ("real*.kml" and "real*.bmp/png") are embedded in this a TODO -- Retain a key by right clicking if it is from a mouse. - Add the name of the file in the toast "State saved". -- Add the KML icon in the navigation menu header. +- The clock seems unsynchronized sometimes. +- Retain a key by right clicking if it is from a mouse. - Add the possibility to load and save the flash in another file. -- Add the possibility to deactivate the zoom. - Sometimes, the calculator seems to lag and finally freeze. - In Chrome OS: - The timezone seems to be GMT (localtime_r not right?)! - sometimes there is no OK button in the KML Script Compilation Result. -- The clock seems unsynchronized sometimes. - Add KML script loading dependencies fallback to the inner ROM (and may be KML include?). - Add a separation between the pixels (Suggestion from Jaime Meza). diff --git a/app/src/main/cpp/emu-jni.c b/app/src/main/cpp/emu-jni.c index 74c89cd..c86b02b 100644 --- a/app/src/main/cpp/emu-jni.c +++ b/app/src/main/cpp/emu-jni.c @@ -424,87 +424,6 @@ JNIEXPORT void JNICALL Java_org_emulator_calculator_NativeLib_changeBitmap(JNIEn } } -JNIEXPORT jboolean JNICALL Java_org_emulator_calculator_NativeLib_copyLCD(JNIEnv *env, jobject thisz, jobject bitmapLCD) { - - if(!bitmapLCD) - return JNI_FALSE; - - AndroidBitmapInfo bitmapLCDInfo; - int ret = AndroidBitmap_getInfo(env, bitmapLCD, &bitmapLCDInfo); - if (ret < 0) { - LOGE("AndroidBitmap_getInfo() failed ! error=%d", ret); - return JNI_FALSE; - } - -// INT nxSize, nySize; -// GetSizeLcdBitmap(&nxSize,&nySize); // get LCD size - - - void *pixelsDestination; - if ((ret = AndroidBitmap_lockPixels(env, bitmapLCD, &pixelsDestination)) < 0) { - LOGE("AndroidBitmap_lockPixels() failed ! error=%d", ret); - return JNI_FALSE; - } - - if(hLcdDC && hLcdDC->selectedBitmap) { - HBITMAP hBitmapSource = hLcdDC->selectedBitmap; - void * pixelsSource = (void *) hBitmapSource->bitmapBits; - BOOL reverseHeight = hBitmapSource->bitmapInfoHeader->biHeight < 0; - - int sourceWidth = hBitmapSource->bitmapInfoHeader->biWidth; - int sourceHeight = abs(hBitmapSource->bitmapInfoHeader->biHeight); // Can be < 0 - - UINT sourceBitCount = hBitmapSource->bitmapInfoHeader->biBitCount; - int sourceStride = 4 * ((sourceWidth * hBitmapSource->bitmapInfoHeader->biBitCount + 31) / 32); - - HPALETTE palette = hLcdDC->realizedPalette; - if(!palette) - palette = hLcdDC->selectedPalette; - PALETTEENTRY * palPalEntry = palette && palette->paletteLog && palette->paletteLog->palPalEntry ? - palette->paletteLog->palPalEntry : NULL; - if(!palPalEntry && sourceBitCount <= 8 && hBitmapSource->bitmapInfoHeader->biClrUsed > 0) - palPalEntry = (PALETTEENTRY *)hBitmapSource->bitmapInfo->bmiColors; - - - int destinationWidth = bitmapLCDInfo.width; - int destinationHeight = bitmapLCDInfo.height; - int destinationBitCount = 32; - int destinationStride = bitmapLCDInfo.stride; - - - EnterCriticalSection(&csGDILock); // solving NT GDI problems - UINT nLines = MAINSCREENHEIGHT; - - // copy header display area - StretchBltInternal(0, 0, 131*nLcdZoom*nGdiXZoom, Chipset.d0size*nLcdZoom*nGdiYZoom, pixelsDestination, destinationBitCount, - destinationStride, destinationWidth, destinationHeight, - Chipset.d0offset, 0, 131, Chipset.d0size, pixelsSource, sourceBitCount, - sourceStride, sourceWidth, sourceHeight, - SRCCOPY, reverseHeight, palPalEntry, 0, 0); - - - // copy main display area - StretchBltInternal(0, Chipset.d0size*nLcdZoom*nGdiYZoom, 131*nLcdZoom*nGdiXZoom, nLines*nLcdZoom*nGdiYZoom, pixelsDestination, destinationBitCount, - destinationStride, destinationWidth, destinationHeight, - Chipset.boffset, Chipset.d0size, 131, nLines, pixelsSource, sourceBitCount, - sourceStride, sourceWidth, sourceHeight, - SRCCOPY, reverseHeight, palPalEntry, 0, 0); - // copy menu display area - StretchBltInternal(0, (nLines+Chipset.d0size)*nLcdZoom*nGdiYZoom, 131*nLcdZoom*nGdiXZoom, MENUHEIGHT*nLcdZoom*nGdiYZoom, pixelsDestination, destinationBitCount, - destinationStride, destinationWidth, destinationHeight, - 0, (nLines+Chipset.d0size), 131, MENUHEIGHT, pixelsSource, sourceBitCount, - sourceStride, sourceWidth, sourceHeight, - SRCCOPY, reverseHeight, palPalEntry, 0, 0); - - LeaveCriticalSection(&csGDILock); - AndroidBitmap_unlockPixels(env, bitmapLCD); - return JNI_TRUE; - } - - return JNI_FALSE; -} - - JNIEXPORT void JNICALL Java_org_emulator_calculator_NativeLib_draw(JNIEnv *env, jobject thisz) { draw(); } diff --git a/app/src/main/cpp/win32-layer.c b/app/src/main/cpp/win32-layer.c index ba295a1..afaa4dc 100644 --- a/app/src/main/cpp/win32-layer.c +++ b/app/src/main/cpp/win32-layer.c @@ -1592,15 +1592,6 @@ BOOL GetWindowPlacement(HWND hWnd, WINDOWPLACEMENT *lpwndpl) { } BOOL SetWindowPlacement(HWND hWnd, CONST WINDOWPLACEMENT *lpwndpl) { return 0; } extern void draw(); - -void StretchBltInternal(int xDest, int yDest, int wDest, int hDest, const void *pixelsDestination, - int destinationBitCount, int destinationStride, int destinationWidth, - int destinationHeight, int xSrc, int ySrc, int hSrc, int wSrc, - const void *pixelsSource, UINT sourceBitCount, int sourceStride, - int sourceWidth, int sourceHeight, DWORD rop, BOOL reverseHeight, - const PALETTEENTRY *palPalEntry, COLORREF brushColor, - COLORREF backgroundColor); - BOOL InvalidateRect(HWND hWnd, CONST RECT *lpRect, BOOL bErase) { // Update when switch the screen off draw(); //TODO Need a true WM_PAINT event! diff --git a/app/src/main/java/org/emulator/calculator/LCDOverlappingView.java b/app/src/main/java/org/emulator/calculator/LCDOverlappingView.java index 3393e24..58c97bd 100644 --- a/app/src/main/java/org/emulator/calculator/LCDOverlappingView.java +++ b/app/src/main/java/org/emulator/calculator/LCDOverlappingView.java @@ -174,16 +174,11 @@ public class LCDOverlappingView extends View { canvas.drawColor(Color.RED); //TODO to remove if(this.overlappingLCDMode > 0 && bitmapLCD != null) { - canvas.save(); - if (bitmapLCD.getWidth() > 0 && bitmapLCD.getHeight() > 0) - canvas.scale((float) getWidth() / (float) bitmapLCD.getWidth(), (float) getHeight() / (float) bitmapLCD.getHeight()); - canvas.drawBitmap(bitmapLCD, 0, 0, paint); - canvas.restore(); -// int x = NativeLib.getScreenPositionX(); -// int y = NativeLib.getScreenPositionY(); -// srcBitmapCopy.set(x, y, x + NativeLib.getScreenWidth(), y + NativeLib.getScreenHeight()); -// dstBitmapCopy.set(0, 0, getWidth(), getHeight()); -// canvas.drawBitmap(mainScreenView.getBitmap(), srcBitmapCopy, dstBitmapCopy, paint); + int x = NativeLib.getScreenPositionX(); + int y = NativeLib.getScreenPositionY(); + srcBitmapCopy.set(x, y, x + NativeLib.getScreenWidth(), y + NativeLib.getScreenHeight()); + dstBitmapCopy.set(0, 0, getWidth(), getHeight()); + canvas.drawBitmap(mainScreenView.getBitmap(), srcBitmapCopy, dstBitmapCopy, paint); } } @@ -194,10 +189,8 @@ public class LCDOverlappingView extends View { case NativeLib.CALLBACK_TYPE_INVALIDATE: //if(debug) Log.d(TAG, "PAINT updateCallback() postInvalidate()"); if(debug) Log.d(TAG, "updateCallback() CALLBACK_TYPE_INVALIDATE"); - if(bitmapLCD.getWidth() > 1) { - NativeLib.copyLCD(bitmapLCD); + if(bitmapLCD.getWidth() > 1) postInvalidate(); - } break; case NativeLib.CALLBACK_TYPE_WINDOW_RESIZE: // New Bitmap size diff --git a/app/src/main/java/org/emulator/calculator/NativeLib.java b/app/src/main/java/org/emulator/calculator/NativeLib.java index a3b57ac..5ad5563 100644 --- a/app/src/main/java/org/emulator/calculator/NativeLib.java +++ b/app/src/main/java/org/emulator/calculator/NativeLib.java @@ -30,7 +30,6 @@ public class NativeLib { public static native void start(AssetManager mgr, Activity activity); public static native void stop(); public static native void changeBitmap(Bitmap bitmapMainScreen); - public static native boolean copyLCD(Bitmap bitmapLCD); public static native void draw(); public static native boolean buttonDown(int x, int y); public static native void buttonUp(int x, int y); diff --git a/app/src/main/java/org/emulator/forty/eight/MainActivity.java b/app/src/main/java/org/emulator/forty/eight/MainActivity.java index 3a52a11..e9df5b4 100644 --- a/app/src/main/java/org/emulator/forty/eight/MainActivity.java +++ b/app/src/main/java/org/emulator/forty/eight/MainActivity.java @@ -24,6 +24,8 @@ import android.content.SharedPreferences; import android.content.res.AssetManager; import android.graphics.Bitmap; import android.graphics.Color; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -1478,16 +1480,33 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On bitmapIcon.copyPixelsFromBuffer(buffer); } catch (Exception ex) { // Cannot load the icon - bitmapIcon.recycle(); +// bitmapIcon.recycle(); bitmapIcon = null; } } else if(bitmapIcon != null) { - bitmapIcon.recycle(); +// bitmapIcon.recycle(); bitmapIcon = null; } + if(bitmapIcon == null) + // Try to load the app icon + bitmapIcon = getApplicationIconBitmap(); changeHeaderIcon(); } + private Bitmap getApplicationIconBitmap() { + Drawable drawable = getApplicationInfo().loadIcon(getPackageManager()); + if (drawable instanceof BitmapDrawable) { + BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; + if (bitmapDrawable.getBitmap() != null) + return bitmapDrawable.getBitmap(); + } + + if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) + return Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); // Single color bitmap will be created of 1x1 pixel + else + return Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); + } + private void setPort1Settings(boolean port1Plugged, boolean port1Writable) { SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putBoolean("settings_port1en", port1Plugged);