Add ability to change nickname and take screenshot to Qt Desktop UI.

This commit is contained in:
Sacha 2013-12-08 04:57:06 +10:00
parent 0a0351d2b0
commit d5147c4234
8 changed files with 103 additions and 14 deletions

View File

@ -75,7 +75,7 @@ public:
virtual bool CanCreateShortcut() {return false;}
virtual bool CreateDesktopShortcut(std::string argumentPath, std::string title) {return false;}
#ifdef _WIN32
#if defined(_WIN32) || (defined(USING_QT_UI) && !defined(USING_GLES2))
// Implement this on your platform to grab text input from the user for whatever purpose.
virtual bool InputBoxGetString(char *title, const char *defaultValue, char *outValue, size_t outlength) { return false; }
virtual bool InputBoxGetWString(const wchar_t *title, const std::wstring &defaultvalue, std::wstring &outvalue) { return false; }

View File

@ -88,7 +88,7 @@ SOURCES += $$P/UI/*Screen.cpp \
$$P/android/jni/TestRunner.cpp
HEADERS += $$P/UI/*.h
INCLUDEPATH += $$P $$P/Common $$P/native
INCLUDEPATH += $$P $$P/Common $$P/native $$P/native/ext/libpng16
# Use forms UI for desktop platforms
!mobile_platform {

View File

@ -1,9 +1,11 @@
// This file is Qt Desktop's equivalent of NativeApp.cpp
#include <QFileInfo>
#include <QInputDialog>
#include <QDebug>
#include <QDir>
#include <QCoreApplication>
#include <png.h>
#include "QtHost.h"
#include "LogManager.h"
@ -21,6 +23,7 @@
#include "ui/ui_context.h"
#include "gfx_es2/draw_text.h"
#include "GPU/ge_constants.h"
#include "ext/jpge/jpge.h"
static UI::Theme ui_theme;
@ -41,6 +44,8 @@ static bool isMessagePending;
static std::string pendingMessage;
static std::string pendingValue;
bool g_TakeScreenshot;
QtHost::QtHost(MainWindow *mainWindow_)
: mainWindow(mainWindow_)
, m_GPUStep(false)
@ -238,6 +243,31 @@ void QtHost::NextGPUStep()
m_hGPUStepEvent.notify_one();
}
bool QtHost::InputBoxGetString(char *title, const char *defaultValue, char *outValue, size_t outLength)
{
bool ok;
QString text = QInputDialog::getText(mainWindow, title, title, QLineEdit::Normal, defaultValue, &ok);
if (ok && !text.isEmpty()) {
strcpy(outValue, text.toStdString().c_str());
return true;
} else {
return false;
}
}
bool QtHost::InputBoxGetWString(const wchar_t *title, const std::wstring &defaultValue, std::wstring &outValue)
{
bool ok;
QString text = QInputDialog::getText(mainWindow, QString::fromStdWString(title), QString::fromStdWString(title), QLineEdit::Normal, QString::fromStdWString(defaultValue), &ok);
if (ok && !text.isEmpty()) {
outValue = text.toStdWString();
return true;
} else {
return false;
}
}
void NativeInit(int argc, const char *argv[], const char *savegame_directory, const char *external_directory, const char *installID)
{
isMessagePending = false;
@ -347,6 +377,57 @@ int NativeMix(short *audio, int num_samples)
return 0;
}
void TakeScreenshot() {
g_TakeScreenshot = false;
mkDir(g_Config.memCardDirectory + "/PSP/SCREENSHOT");
// First, find a free filename.
int i = 0;
char temp[256];
while (i < 10000){
if(g_Config.bScreenshotsAsPNG)
sprintf(temp, "%s/PSP/SCREENSHOT/screen%05d.png", g_Config.memCardDirectory.c_str(), i);
else
sprintf(temp, "%s/PSP/SCREENSHOT/screen%05d.jpg", g_Config.memCardDirectory.c_str(), i);
FileInfo info;
if (!getFileInfo(temp, &info))
break;
i++;
}
// Okay, allocate a buffer.
u8 *buffer = new u8[3 * pixel_xres * pixel_yres];
// Silly openGL reads upside down, we flip to another buffer for simplicity.
u8 *flipbuffer = new u8[3 * pixel_xres * pixel_yres];
glReadPixels(0, 0, pixel_xres, pixel_yres, GL_RGB, GL_UNSIGNED_BYTE, buffer);
for (int y = 0; y < pixel_yres; y++) {
memcpy(flipbuffer + y * pixel_xres * 3, buffer + (pixel_yres - y - 1) * pixel_xres * 3, pixel_xres * 3);
}
if (g_Config.bScreenshotsAsPNG) {
png_image png;
memset(&png, 0, sizeof(png));
png.version = PNG_IMAGE_VERSION;
png.format = PNG_FORMAT_RGB;
png.width = pixel_xres;
png.height = pixel_yres;
png_image_write_to_file(&png, temp, 0, flipbuffer, pixel_xres * 3, NULL);
png_image_free(&png);
} else {
jpge::params params;
params.m_quality = 90;
compress_image_to_jpeg_file(temp, pixel_xres, pixel_yres, 3, flipbuffer, params);
}
delete [] buffer;
delete [] flipbuffer;
osm.Show(temp);
}
void NativeInitGraphics()
{
gl_lost_manager_init();
@ -444,6 +525,9 @@ void NativeRender()
if (screenManager->getUIContext()->Text()) {
screenManager->getUIContext()->Text()->OncePerFrame();
}
if (g_TakeScreenshot)
TakeScreenshot();
}
void NativeMessageReceived(const char *message, const char *value)

View File

@ -57,6 +57,8 @@ public:
void SendGPUStart();
void SetGPUStep(bool value, int flag = 0, u32 data = 0);
void NextGPUStep();
bool InputBoxGetString(char *title, const char *defaultValue, char *outValue, size_t outlength);
bool InputBoxGetWString(const wchar_t *title, const std::wstring &defaultValue, std::wstring &outValue);
signals:
void BootDoneSignal();

View File

@ -454,6 +454,8 @@ void MainWindow::createMenus()
debugMenu->addSeparator();
debugMenu->add(new MenuAction(this, SLOT(dumpNextAct()), QT_TR_NOOP("Dump next frame to log")))
->addDisableState(UISTATE_MENU);
debugMenu->add(new MenuAction(this, SLOT(takeScreen()), QT_TR_NOOP("Take Screenshot"), Qt::Key_F12))
->addDisableState(UISTATE_MENU);
debugMenu->addSeparator();
debugMenu->add(new MenuAction(this, SLOT(disasmAct()), QT_TR_NOOP("Disassembly"), Qt::CTRL + Qt::Key_D))
->addDisableState(UISTATE_MENU);

View File

@ -15,6 +15,8 @@
#include "debugger_displaylist.h"
#include "base/QtMain.h"
extern bool g_TakeScreenshot;
class QtEmuGL;
class MenuAction;
class MenuTree;
@ -68,6 +70,7 @@ private slots:
void smapAct();
void resetTableAct();
void dumpNextAct();
void takeScreen() { g_TakeScreenshot = true; }
void disasmAct();
void dpyListAct();
void consoleAct();

View File

@ -293,7 +293,7 @@ void GameSettingsScreen::CreateViews() {
systemSettings->Add(new ItemHeader(s->T("PSP Settings")));
// TODO: Come up with a way to display a keyboard for mobile users,
// so until then, this is Windows/Desktop only.
#ifdef _WIN32
#if defined(_WIN32) || (defined(USING_QT_UI) && !defined(USING_GLES2))
systemSettings->Add(new Choice(s->T("Change Nickname")))->OnClick.Handle(this, &GameSettingsScreen::OnChangeNickname);
// Screenshot functionality is not yet available on non-Windows
systemSettings->Add(new CheckBox(&g_Config.bScreenshotsAsPNG, s->T("Screenshots as PNG")));
@ -432,8 +432,7 @@ void GlobalSettingsScreen::CreateViews() {
}*/
UI::EventReturn GameSettingsScreen::OnChangeNickname(UI::EventParams &e) {
#ifdef _WIN32
#if defined(_WIN32) || (defined(USING_QT_UI) && !defined(USING_GLES2))
const size_t name_len = 256;
char name[name_len];
@ -442,8 +441,8 @@ UI::EventReturn GameSettingsScreen::OnChangeNickname(UI::EventParams &e) {
if (host->InputBoxGetString("Enter a new PSP nickname", g_Config.sNickName.c_str(), name, name_len)) {
g_Config.sNickName = name;
}
#endif
#endif
return UI::EVENT_DONE;
}

View File

@ -503,8 +503,8 @@ void NativeShutdownGraphics() {
}
void TakeScreenshot() {
#ifdef _WIN32
g_TakeScreenshot = false;
#ifdef _WIN32
mkDir(g_Config.memCardDirectory + "/PSP/SCREENSHOT");
// First, find a free filename.
@ -523,14 +523,14 @@ void TakeScreenshot() {
}
// Okay, allocate a buffer.
u8 *buffer = new u8[4 * pixel_xres * pixel_yres];
u8 *buffer = new u8[3 * pixel_xres * pixel_yres];
// Silly openGL reads upside down, we flip to another buffer for simplicity.
u8 *flipbuffer = new u8[4 * pixel_xres * pixel_yres];
u8 *flipbuffer = new u8[3 * pixel_xres * pixel_yres];
glReadPixels(0, 0, pixel_xres, pixel_yres, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
glReadPixels(0, 0, pixel_xres, pixel_yres, GL_RGB, GL_UNSIGNED_BYTE, buffer);
for (int y = 0; y < pixel_yres; y++) {
memcpy(flipbuffer + y * pixel_xres * 4, buffer + (pixel_yres - y - 1) * pixel_xres * 4, pixel_xres * 4);
memcpy(flipbuffer + y * pixel_xres * 3, buffer + (pixel_yres - y - 1) * pixel_xres * 3, pixel_xres * 3);
}
if (g_Config.bScreenshotsAsPNG) {
@ -540,13 +540,12 @@ void TakeScreenshot() {
png.format = PNG_FORMAT_RGB;
png.width = pixel_xres;
png.height = pixel_yres;
int stride = PNG_IMAGE_ROW_STRIDE(png);
png_image_write_to_file(&png, temp, 0, flipbuffer, pixel_xres * 4, NULL);
png_image_write_to_file(&png, temp, 0, flipbuffer, pixel_xres * 3, NULL);
png_image_free(&png);
} else {
jpge::params params;
params.m_quality = 90;
compress_image_to_jpeg_file(temp, pixel_xres, pixel_yres, 4, flipbuffer, params);
compress_image_to_jpeg_file(temp, pixel_xres, pixel_yres, 3, flipbuffer, params);
}
delete [] buffer;