diff --git a/Common/UI/View.cpp b/Common/UI/View.cpp index 8cc84f4925..b2f3dac943 100644 --- a/Common/UI/View.cpp +++ b/Common/UI/View.cpp @@ -851,8 +851,15 @@ bool BitCheckBox::Toggled() const { } void Button::GetContentDimensions(const UIContext &dc, float &w, float &h) const { - if (imageID_.isValid()) { - dc.Draw()->GetAtlas()->measureImage(imageID_, &w, &h); + ImageID imageId; + if (imageFunc_) { + imageId = imageFunc_(); + } else { + imageId = imageID_; + } + + if (imageId.isValid()) { + dc.Draw()->GetAtlas()->measureImage(imageId, &w, &h); } else { w = 0.0f; h = 0.0f; @@ -864,7 +871,7 @@ void Button::GetContentDimensions(const UIContext &dc, float &w, float &h) const dc.MeasureText(dc.GetTheme().uiFont, 1.0f, 1.0f, text_, &width, &height); w += width; - if (imageID_.isValid()) { + if (imageId.isValid()) { w += paddingW_; } h = std::max(h, height); @@ -902,19 +909,26 @@ void Button::Draw(UIContext &dc) { tw *= scale_; th *= scale_; - if (tw > bounds_.w || imageID_.isValid()) { + ImageID imageId; + if (imageFunc_) { + imageId = imageFunc_(); + } else { + imageId = imageID_; + } + + if (tw > bounds_.w || imageId.isValid()) { dc.PushScissor(bounds_); } dc.SetFontStyle(dc.GetTheme().uiFont); dc.SetFontScale(scale_, scale_); - if (imageID_.isValid() && (ignoreText_ || text_.empty())) { - dc.Draw()->DrawImage(imageID_, bounds_.centerX(), bounds_.centerY(), scale_, style.fgColor, ALIGN_CENTER); + if (imageId.isValid() && (ignoreText_ || text_.empty())) { + dc.Draw()->DrawImage(imageId, bounds_.centerX(), bounds_.centerY(), scale_, style.fgColor, ALIGN_CENTER); } else if (!text_.empty()) { float textX = bounds_.centerX(); - if (imageID_.isValid()) { - const AtlasImage *img = dc.Draw()->GetAtlas()->getImage(imageID_); + if (imageId.isValid()) { + const AtlasImage *img = dc.Draw()->GetAtlas()->getImage(imageId); if (img) { - dc.Draw()->DrawImage(imageID_, bounds_.centerX() - tw / 2 - 5, bounds_.centerY(), 1.0f, style.fgColor, ALIGN_CENTER); + dc.Draw()->DrawImage(imageId, bounds_.centerX() - tw / 2 - 5, bounds_.centerY(), 1.0f, style.fgColor, ALIGN_CENTER); textX += img->w / 2.0f; } } @@ -922,7 +936,7 @@ void Button::Draw(UIContext &dc) { } dc.SetFontScale(1.0f, 1.0f); - if (tw > bounds_.w || imageID_.isValid()) { + if (tw > bounds_.w || imageId.isValid()) { dc.PopScissor(); } } diff --git a/Common/UI/View.h b/Common/UI/View.h index 793ac39e1d..94077ee92c 100644 --- a/Common/UI/View.h +++ b/Common/UI/View.h @@ -562,6 +562,9 @@ public: void SetImageID(ImageID imageID) { imageID_ = imageID; } + void SetImageIDFunc(std::function func) { + imageFunc_ = func; + } void SetIgnoreText(bool ignore) { ignoreText_ = ignore; } @@ -574,6 +577,7 @@ private: Style style_; std::string text_; ImageID imageID_; + std::function imageFunc_; int paddingW_ = 16; int paddingH_ = 8; float scale_ = 1.0f; diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 36b1e0c7ab..be0ba46d06 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -1456,16 +1456,15 @@ void MainScreen::CreateViews() { ViewGroup *logo = new LogoView(false, new LinearLayoutParams(FILL_PARENT, 80.0f)); #if !defined(MOBILE_DEVICE) auto gr = GetI18NCategory(I18NCat::GRAPHICS); - ImageID icon(g_Config.bFullScreen ? "I_RESTORE" : "I_FULLSCREEN"); - UI::Button *fullscreenButton = logo->Add(new Button("", icon, new AnchorLayoutParams(48, 48, NONE, 0, 0, NONE, Centering::None))); + Button *fullscreenButton = logo->Add(new Button("", ImageID(), new AnchorLayoutParams(48, 48, NONE, 0, 0, NONE, Centering::None))); fullscreenButton->SetIgnoreText(true); - fullscreenButton->OnClick.Add([fullscreenButton](UI::EventParams &e) { - if (fullscreenButton) { - fullscreenButton->SetImageID(ImageID(!g_Config.bFullScreen ? "I_RESTORE" : "I_FULLSCREEN")); - } + fullscreenButton->OnClick.Add([this](UI::EventParams &e) { g_Config.bFullScreen = !g_Config.bFullScreen; System_ApplyFullscreenState(); }); + fullscreenButton->SetImageIDFunc([this]() { + return g_Config.bFullScreen ? ImageID("I_RESTORE") : ImageID("I_FULLSCREEN"); + }); #endif rightColumnItems->Add(logo); diff --git a/Windows/MainWindow.cpp b/Windows/MainWindow.cpp index b1e12f4e85..6c4e4f3a92 100644 --- a/Windows/MainWindow.cpp +++ b/Windows/MainWindow.cpp @@ -335,7 +335,6 @@ namespace MainWindow { g_Config.iWindowY = wp.rcNormalPosition.top; g_Config.iWindowWidth = wp.rcNormalPosition.right - wp.rcNormalPosition.left; g_Config.iWindowHeight = wp.rcNormalPosition.bottom - wp.rcNormalPosition.top; - wp.showCmd = SW_SHOW; } if (g_Config.bFullScreenMulti) { @@ -352,6 +351,7 @@ namespace MainWindow { totalX, totalY, totalWidth, totalHeight, SWP_NOOWNERZORDER | SWP_FRAMECHANGED); + ShowWindow(hWnd, SW_SHOW); } else { MONITORINFO mi = {sizeof(mi)}; if (GetMonitorInfo(MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST), &mi)) { @@ -365,6 +365,7 @@ namespace MainWindow { mi.rcMonitor.bottom - mi.rcMonitor.top, SWP_NOOWNERZORDER | SWP_FRAMECHANGED); } + ShowWindow(hWnd, SW_SHOW); } } else if (!goFullscreen && isCurrentlyFullscreen) { INFO_LOG(Log::System, "ApplyFullscreenState: Exiting fullscreen to %s mode at %dx%d+%d+%d", @@ -502,7 +503,7 @@ namespace MainWindow { g_hMenu = GetMenu(hwndMain); - WINDOWPLACEMENT placement = {sizeof(WINDOWPLACEMENT)}; + WINDOWPLACEMENT placement{sizeof(WINDOWPLACEMENT)}; if ((g_Config.iWindowX == -1 && g_Config.iWindowY == -1) || g_Config.iWindowWidth < 20 || g_Config.iWindowHeight < 20) { RECT rc = DetermineDefaultWindowRectangle(); // Should be a first boot, or just bad parameters. Reset. @@ -513,7 +514,8 @@ namespace MainWindow { g_Config.iWindowHeight = rc.bottom - rc.top; } - placement.showCmd = WindowSizeStateToShowCmd((WindowSizeState)g_Config.iWindowSizeState); + // Start as hidden in fullscreen mode. Makes for a nicer transition. + placement.showCmd = g_Config.bFullScreen ? SW_HIDE : WindowSizeStateToShowCmd((WindowSizeState)g_Config.iWindowSizeState); placement.rcNormalPosition.left = g_Config.iWindowX; placement.rcNormalPosition.top = g_Config.iWindowY; placement.rcNormalPosition.right = g_Config.iWindowX + g_Config.iWindowWidth; @@ -525,6 +527,7 @@ namespace MainWindow { const DWM_WINDOW_CORNER_PREFERENCE pref = DWMWCP_DONOTROUND; DwmSetWindowAttribute(hwndMain, DWMWA_WINDOW_CORNER_PREFERENCE, &pref, sizeof(pref)); + ApplyFullscreenState(hwndMain, g_Config.bFullScreen); MainMenuInit(hwndMain, g_hMenu); @@ -534,8 +537,6 @@ namespace MainWindow { hideCursor = true; SetTimer(hwndMain, TIMER_CURSORUPDATE, CURSORUPDATE_INTERVAL_MS, 0); - ApplyFullscreenState(hwndMain, g_Config.bFullScreen); - W32Util::MakeTopMost(hwndMain, g_Config.bTopMost); touchHandler.registerTouchWindow(hwndMain); diff --git a/Windows/main.cpp b/Windows/main.cpp index e78cefb2fa..4f9e182265 100644 --- a/Windows/main.cpp +++ b/Windows/main.cpp @@ -1093,6 +1093,15 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin break; } + // NOTE: We need to parse --fullscreen early, before we create the window. + if (!wcscmp(wideArgs[i].c_str(), L"--fullscreen")) { + g_Config.bFullScreen = true; + g_Config.DoNotSaveSetting(&g_Config.bFullScreen); + } else if (!wcscmp(wideArgs[i].c_str(), L"--windowed")) { + g_Config.bFullScreen = false; + g_Config.DoNotSaveSetting(&g_Config.bFullScreen); + } + if (wideArgs[i].find(gpuBackend) != std::wstring::npos && wideArgs[i].size() > gpuBackend.size()) { const std::wstring restOfOption = wideArgs[i].substr(gpuBackend.size()); @@ -1115,6 +1124,7 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin } } } + } #ifdef _DEBUG g_Config.bEnableLogging = true; diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index 592419e6fb..734519bc3b 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -110,7 +110,9 @@ - + diff --git a/android/src/main/res/values/themes.xml b/android/src/main/res/values/themes.xml new file mode 100644 index 0000000000..2a88963b27 --- /dev/null +++ b/android/src/main/res/values/themes.xml @@ -0,0 +1,11 @@ + + + + diff --git a/android/src/org/ppsspp/ppsspp/ImageResultProxyActivity.java b/android/src/org/ppsspp/ppsspp/ImageResultProxyActivity.java new file mode 100644 index 0000000000..2211aa69c4 --- /dev/null +++ b/android/src/org/ppsspp/ppsspp/ImageResultProxyActivity.java @@ -0,0 +1,79 @@ +package org.ppsspp.ppsspp; + +import android.app.Activity; +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import androidx.activity.result.ActivityResultLauncher; +import androidx.activity.result.contract.ActivityResultContracts; +import androidx.appcompat.app.AppCompatActivity; +import android.util.Log; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +public class ImageResultProxyActivity extends AppCompatActivity { + public static final String TAG = "PPSSPP"; + + private String copyToCache(Uri selectedImage) { + Log.i(TAG, "Selected image: " + selectedImage); + File tempFile = new File(getExternalCacheDir(), "temp_import.jpg"); + + try (InputStream in = getContentResolver().openInputStream(selectedImage); + OutputStream out = new FileOutputStream(tempFile)) { + + byte[] buf = new byte[8192]; + int len; + while ((len = in.read(buf)) > 0) { + out.write(buf, 0, len); + } + + // Pass the local path back instead of the content:// URI + String returnPath = tempFile.getAbsolutePath(); + Log.i(TAG, "Return path: " + returnPath); + return returnPath; + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Get the Intent that was meant for the picker + Intent pickerIntent = getIntent().getParcelableExtra("picker_intent"); + int requestId = getIntent().getIntExtra("request_id", -1); + + Log.i(TAG, "Setting up activity launch, requestId = " + requestId); + + ActivityResultLauncher launcher = registerForActivityResult( + new ActivityResultContracts.StartActivityForResult(), + result -> { + Log.i(TAG, "Packing return intent, requestId = " + requestId); + + Intent returnIntent = new Intent(this, PpssppActivity.class); + if (result.getResultCode() == Activity.RESULT_OK && result.getData() != null) { + String localPath = copyToCache(result.getData().getData()); + Log.i(TAG, "Putting extra: " + localPath); + // Pass the result back to the SingleInstance activity. + returnIntent.putExtra("result_path", localPath); + } + + returnIntent.putExtra("result_code", result.getResultCode()); + returnIntent.putExtra("request_id", requestId); + + // This flag is key: it finds the existing instance of your main activity + returnIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); + startActivity(returnIntent); + finish(); + } + ); + + launcher.launch(pickerIntent); + } +} diff --git a/android/src/org/ppsspp/ppsspp/PpssppActivity.java b/android/src/org/ppsspp/ppsspp/PpssppActivity.java index f7763dcecf..0f51934df8 100644 --- a/android/src/org/ppsspp/ppsspp/PpssppActivity.java +++ b/android/src/org/ppsspp/ppsspp/PpssppActivity.java @@ -1643,9 +1643,13 @@ public class PpssppActivity extends AppCompatActivity implements SensorEventList try { int requestId = Integer.parseInt(params); int packedResultCode = packResultCode(RESULT_LOAD_IMAGE, requestId); + // 1. To Launch the picker: + Intent picker = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); + Intent proxy = new Intent(this, ImageResultProxyActivity.class); + proxy.putExtra("picker_intent", picker); + proxy.putExtra("request_id", requestId); Log.i(TAG, "image request ID: " + requestId + " packed: " + packedResultCode); - Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); - startActivityForResult(i, packedResultCode); + startActivity(proxy); return true; } catch (Exception e) { // For example, android.content.ActivityNotFoundException NativeApp.reportException(e, params); @@ -1945,16 +1949,57 @@ public class PpssppActivity extends AppCompatActivity implements SensorEventList } } + public static void logIntentExtras(Intent intent) { + if (intent == null) { + Log.i(TAG, "Intent is null"); + return; + } + Bundle bundle = intent.getExtras(); + if (bundle != null) { + for (String key : bundle.keySet()) { + Object value = bundle.get(key); + String type = (value != null) ? value.getClass().getSimpleName() : "null"; + Log.i(TAG, String.format("Extra Key: %s | Value: %s | Type: %s", key, value, type)); + } + } else { + Log.i(TAG, "Intent has no extras."); + } + } + @Override public void onNewIntent(Intent intent) { super.onNewIntent(intent); - setIntent(intent); - String value = parseIntent(intent); - if (value != null) { - // TODO: Actually send a command to the native code to launch the new game. - Log.i(TAG, "NEW INTENT AT RUNTIME: " + value); - Log.i(TAG, "Posting a 'shortcutParam' message to the C++ code."); - NativeApp.sendMessageFromJava("shortcutParam", value); + + Log.i(TAG, "onNewIntent: " + intent.toString()); + + if (intent.hasExtra("request_id")) { + logIntentExtras(intent); + // This was a proxied image request. + int requestId = intent.getIntExtra("request_id", -1); + int resultCode = intent.getIntExtra("result_code", RESULT_CANCELED); + String path = intent.getStringExtra("result_path"); + + if (path != null) { + Log.i(TAG, "Received valid intent: " + path); + Log.i(TAG, "requestId: " + requestId + " resultCode: " + resultCode); + + // Now you can call your native method + NativeApp.sendRequestResult(requestId, (resultCode == RESULT_OK), path, resultCode); + } else { + Log.i(TAG, "Received failed intent"); + Log.i(TAG, "requestId: " + requestId + " resultCode: " + resultCode); + NativeApp.sendRequestResult(requestId, false,"", resultCode); + } + } else { + // Someone launched a shortcut while we were running.... + setIntent(intent); + String value = parseIntent(intent); + if (value != null) { + // TODO: Actually send a command to the native code to launch the new game. + Log.i(TAG, "NEW INTENT AT RUNTIME: " + value); + Log.i(TAG, "Posting a 'shortcutParam' message to the C++ code."); + NativeApp.sendMessageFromJava("shortcutParam", value); + } } }