Skip to content

Commit

Permalink
Some improvements, comments and polishing.
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaMoo committed Dec 21, 2015
1 parent 079670b commit ca2a09d
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 118 deletions.
12 changes: 10 additions & 2 deletions Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,14 @@ static int DefaultInternalResolution() {
#endif
}

static int DefaultZoomType() {
if (pixel_xres < 1.3 * pixel_yres) {
return 1;
} else {
return 2;
}
}

static bool DefaultTimerHack() {
// Has been in use on Symbian since v0.7. Preferred option.
#ifdef __SYMBIAN32__
Expand Down Expand Up @@ -440,10 +448,10 @@ static ConfigSetting graphicsSettings[] = {
#endif

// TODO: Replace these settings with a list of options
ConfigSetting("SmallDisplayZoom", &g_Config.iSmallDisplayZoom, 2, true, true),
ConfigSetting("SmallDisplayZoomType", &g_Config.iSmallDisplayZoomType, &DefaultZoomType, true, true),
ConfigSetting("SmallDisplayOffsetX", &g_Config.fSmallDisplayOffsetX, 0.5f, true, true),
ConfigSetting("SmallDisplayOffsetY", &g_Config.fSmallDisplayOffsetY, 0.5f, true, true),
ConfigSetting("SmallDisplayCustomZoom", &g_Config.fSmallDisplayCustomZoom, 8.0f, true, true),
ConfigSetting("SmallDisplayZoomLevel", &g_Config.fSmallDisplayZoomLevel, 1.0f, true, true),
ConfigSetting("ImmersiveMode", &g_Config.bImmersiveMode, false, true, true),

ReportedConfigSetting("TrueColor", &g_Config.bTrueColor, true, true, true),
Expand Down
4 changes: 2 additions & 2 deletions Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ struct Config {
int iRenderingMode; // 0 = non-buffered rendering 1 = buffered rendering 2 = Read Framebuffer to memory (CPU) 3 = Read Framebuffer to memory (GPU)
int iTexFiltering; // 1 = off , 2 = nearest , 3 = linear , 4 = linear(CG)
int iBufFilter; // 1 = linear, 2 = nearest
int iSmallDisplayZoom; // Used to fit display into screen 0 = stretch, 1 = partial stretch, 2 = auto, anything higher is used to set's integer zoom of psp resolution and allows manual editing
int iSmallDisplayZoomType; // Used to fit display into screen 0 = stretch, 1 = partial stretch, 2 = auto scaling, 3 = manual scaling.
float fSmallDisplayOffsetX; // Along with Y it goes from 0.0 to 1.0, XY (0.5, 0.5) = center of the screen
float fSmallDisplayOffsetY;
float fSmallDisplayCustomZoom; //This is actually used for zoom, both in and out.
float fSmallDisplayZoomLevel; //This is used for zoom values, both in and out.
bool bImmersiveMode; // Mode on Android Kitkat 4.4 that hides the back button etc.
bool bVSync;
int iFrameSkip;
Expand Down
14 changes: 7 additions & 7 deletions GPU/Common/FramebufferCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ void CenterDisplayOutputRect(float *x, float *y, float *w, float *h, float origW

bool rotated = rotation == ROTATION_LOCKED_VERTICAL || rotation == ROTATION_LOCKED_VERTICAL180;

if (g_Config.iSmallDisplayZoom == 0) {
if (g_Config.iSmallDisplayZoomType == 0) { // Stretching
outW = frameW;
outH = frameH;
} else {
if (g_Config.iSmallDisplayZoom > 2) {
if (g_Config.iSmallDisplayZoomType == 3) { // Manual Scaling
float offsetX = (g_Config.fSmallDisplayOffsetX - 0.5f) * 2.0f * frameW;
float offsetY = (g_Config.fSmallDisplayOffsetY - 0.5f) * 2.0f * frameH;
// Have to invert Y for GL
Expand All @@ -49,7 +49,7 @@ void CenterDisplayOutputRect(float *x, float *y, float *w, float *h, float origW
#else
offsetY = offsetY * -1.0f;
#endif
float customZoom = g_Config.fSmallDisplayCustomZoom / 8.0f;
float customZoom = g_Config.fSmallDisplayZoomLevel;
float smallDisplayW = origW * customZoom;
float smallDisplayH = origH * customZoom;
if (!rotated) {
Expand All @@ -65,7 +65,7 @@ void CenterDisplayOutputRect(float *x, float *y, float *w, float *h, float origW
*h = floorf(smallDisplayW);
return;
}
} else {
} else if (g_Config.iSmallDisplayZoomType == 2) { // Auto Scaling
float pixelCrop = frameH / 270.0f;
float resCommonWidescreen = pixelCrop - floor(pixelCrop);
if (!rotated && resCommonWidescreen == 0.0f) {
Expand All @@ -79,19 +79,19 @@ void CenterDisplayOutputRect(float *x, float *y, float *w, float *h, float origW

float origRatio = !rotated ? origW / origH : origH / origW;
float frameRatio = frameW / frameH;

if (origRatio > frameRatio) {
// Image is wider than frame. Center vertically.
outW = frameW;
outH = frameW / origRatio;
// Stretch a little bit
if (!rotated && g_Config.iSmallDisplayZoom == 1)
if (!rotated && g_Config.iSmallDisplayZoomType == 1) // Partial Stretch
outH = (frameH + outH) / 2.0f; // (408 + 720) / 2 = 564
} else {
// Image is taller than frame. Center horizontally.
outW = frameH * origRatio;
outH = frameH;
if (rotated && g_Config.iSmallDisplayZoom == 1)
if (rotated && g_Config.iSmallDisplayZoomType == 1) // Partial Stretch
outW = (frameH + outH) / 2.0f; // (408 + 720) / 2 = 564
}
}
Expand Down
9 changes: 3 additions & 6 deletions Qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,7 @@ void MainWindow::updateMenus()
}

foreach(QAction * action, displayLayoutGroup->actions()) {
if (g_Config.iSmallDisplayZoom == action->data().toInt()) {
if (g_Config.iSmallDisplayZoom > 2) {
g_Config.fSmallDisplayCustomZoom = (float)((g_Config.iSmallDisplayZoom - 2) * 8);
}
if (g_Config.iSmallDisplayZoomType == action->data().toInt()) {

if (gpu)
gpu->Resized();
Expand Down Expand Up @@ -548,8 +545,8 @@ void MainWindow::createMenus()

MenuTree* displayLayoutMenu = new MenuTree(this, videoMenu, QT_TR_NOOP("&Display Layout Options"));
displayLayoutGroup = new MenuActionGroup(this, displayLayoutMenu, SLOT(displayLayoutGroup_triggered(QAction *)),
QStringList() << "Stretched" << "Partialy stretched" << "Auto Scaling" << "1x" << "2x" << "3x" << "4x" << "5x" << "6x" << "7x" << "8x" << "9x" << "10x",
QList<int>() << 0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12);
QStringList() << "Stretched" << "Partialy stretched" << "Auto Scaling" << "Manual Scaling",
QList<int>() << 0 << 1 << 2 << 3);
videoMenu->addSeparator();
videoMenu->add(new MenuAction(this, SLOT(transformAct()), QT_TR_NOOP("&Hardware Transform"), Qt::Key_F6))
->addEventChecked(&g_Config.bHardwareTransform);
Expand Down
2 changes: 1 addition & 1 deletion Qt/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private slots:

void screenGroup_triggered(QAction *action) { SetZoom(action->data().toInt()); }

void displayLayoutGroup_triggered(QAction *action) { g_Config.iSmallDisplayZoom = action->data().toInt(); }
void displayLayoutGroup_triggered(QAction *action) { g_Config.iSmallDisplayZoomType = action->data().toInt(); }
void transformAct() { g_Config.bHardwareTransform = !g_Config.bHardwareTransform; }
void vertexCacheAct() { g_Config.bVertexCache = !g_Config.bVertexCache; }
void frameskipAct() { g_Config.iFrameSkip = !g_Config.iFrameSkip; }
Expand Down
52 changes: 28 additions & 24 deletions UI/DisplayLayoutScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ bool DisplayLayoutScreen::touch(const TouchInput &touch) {
using namespace UI;

int mode = mode_->GetSelection();
if (g_Config.iSmallDisplayZoom == 2) { mode = -1; }
if (g_Config.iSmallDisplayZoomType == 2) { mode = -1; }

const Bounds &screen_bounds = screenManager()->getUIContext()->GetBounds();

Expand Down Expand Up @@ -126,6 +126,7 @@ bool DisplayLayoutScreen::touch(const TouchInput &touch) {
picked_->SaveDisplayPosition();
picked_ = 0;
}
g_Config.fSmallDisplayZoomLevel = startScale_ / 8.0f;
return true;
};

Expand All @@ -140,13 +141,12 @@ UI::EventReturn DisplayLayoutScreen::OnCenter(UI::EventParams &e) {
return UI::EVENT_DONE;
};

UI::EventReturn DisplayLayoutScreen::OnZoomChange(UI::EventParams &e) {
if (g_Config.iSmallDisplayZoom > 2) {
g_Config.fSmallDisplayCustomZoom = (float)((g_Config.iSmallDisplayZoom - 2) * 8);
} else {
UI::EventReturn DisplayLayoutScreen::OnZoomTypeChange(UI::EventParams &e) {
if (g_Config.iSmallDisplayZoomType < 3) {
const Bounds &bounds = screenManager()->getUIContext()->GetBounds();
float autoBound = bounds.w / 480.0f * 8.0f;
g_Config.fSmallDisplayCustomZoom = autoBound;
float autoBound = bounds.w / 480.0f;
g_Config.fSmallDisplayZoomLevel = autoBound;
displayRepresentationScale_ = g_Config.fSmallDisplayZoomLevel * 8.0f;
g_Config.fSmallDisplayOffsetX = 0.5f;
g_Config.fSmallDisplayOffsetY = 0.5f;
}
Expand Down Expand Up @@ -191,9 +191,9 @@ void DisplayLayoutScreen::CreateViews() {
horizontalBoundaryR->AddTab("", bottomBoundary);

Choice *back = new Choice(di->T("Back"), "", false, new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 10));
static const char *zoomLevels[] = { "Full Stretch", "Partial Stretch", "Auto Scaling", "1x", "2x", "3x", "4x", "5x", "6x", "7x", "8x", "9x", "10x" };
zoom_ = new PopupMultiChoice(&g_Config.iSmallDisplayZoom, cw->T("Options"), zoomLevels, 0, ARRAY_SIZE(zoomLevels), gr->GetName(), screenManager(), new AnchorLayoutParams(400, WRAP_CONTENT, local_dp_xres / 2 - 200, NONE, NONE, 10));
zoom_->OnChoice.Handle(this, &DisplayLayoutScreen::OnZoomChange);
static const char *zoomLevels[] = { "Stretching", "Partial Stretch", "Auto Scaling", "Manual Scaling" };
zoom_ = new PopupMultiChoice(&g_Config.iSmallDisplayZoomType, cw->T("Options"), zoomLevels, 0, ARRAY_SIZE(zoomLevels), gr->GetName(), screenManager(), new AnchorLayoutParams(400, WRAP_CONTENT, local_dp_xres / 2 - 200, NONE, NONE, 10));
zoom_->OnChoice.Handle(this, &DisplayLayoutScreen::OnZoomTypeChange);

static const char *displayRotation[] = { "Landscape", "Portrait", "Landscape Reversed", "Portrait Reversed" };
rotation_ = new PopupMultiChoice(&g_Config.iInternalScreenRotation, gr->T("Rotation"), displayRotation, 1, ARRAY_SIZE(displayRotation), gr->GetName(), screenManager(), new AnchorLayoutParams(400, WRAP_CONTENT, local_dp_xres / 2 - 200, NONE, NONE, local_dp_yres - 64));
Expand All @@ -202,59 +202,63 @@ void DisplayLayoutScreen::CreateViews() {
bool bRotated = false;
if (g_Config.iRenderingMode != FB_NON_BUFFERED_MODE && (g_Config.iInternalScreenRotation == ROTATION_LOCKED_VERTICAL || g_Config.iInternalScreenRotation == ROTATION_LOCKED_VERTICAL180)) { bRotated = true; }
mode_ = new ChoiceStrip(ORIENT_VERTICAL, new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 158 + 64 + 10));
if (g_Config.iSmallDisplayZoom > 1) {
if (g_Config.iSmallDisplayZoom == 2) {
displayRepresentationScale_ = g_Config.fSmallDisplayZoomLevel * 8.0f; // Visual representation image is just icon size and have to be scaled 8 times to match PSP native resolution which is used as 1.0 for zoom
if (g_Config.iSmallDisplayZoomType > 1) { // Scaling
if (g_Config.iSmallDisplayZoomType == 2) { // Auto Scaling
mode_->AddChoice(gr->T("Auto Scaling"));
mode_->ReplaceLayoutParams(new AnchorLayoutParams(0, 0, local_dp_xres / 2.0f - 70.0f, NONE, NONE, local_dp_yres / 2.0f + 32.0f));
float autoBound = local_dp_yres / 270.0f * 8.0f;
float autoBound = local_dp_yres / 270.0f;
// Case of screen rotated ~ only works with buffered rendering
if (bRotated) {
autoBound = local_dp_yres / 480.0f * 8.0f;
autoBound = local_dp_yres / 480.0f;
}
else { // Without rotation in common cases like 1080p we cut off 2 pixels of height, this reflects other cases
float resCommonWidescreen = autoBound - floor(autoBound);
if (resCommonWidescreen != 0.0f) {
float ratio = local_dp_xres / local_dp_yres;
if (ratio < orgRatio) {
autoBound = local_dp_xres / 480.0f * 8.0f;
autoBound = local_dp_xres / 480.0f;
}
else {
autoBound = local_dp_yres / 272.0f * 8.0f;
autoBound = local_dp_yres / 272.0f;
}
}
}
g_Config.fSmallDisplayCustomZoom = autoBound;
g_Config.fSmallDisplayZoomLevel = autoBound;
displayRepresentationScale_ = g_Config.fSmallDisplayZoomLevel * 8.0f;
g_Config.fSmallDisplayOffsetX = 0.5f;
g_Config.fSmallDisplayOffsetY = 0.5f;
} else {
} else { // Manual Scaling
Choice *center = new Choice(di->T("Center"), "", false, new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 74));
center->OnClick.Handle(this, &DisplayLayoutScreen::OnCenter);
root_->Add(center);
PopupSliderChoiceFloat *zoomlvl_ = new PopupSliderChoiceFloat(&g_Config.fSmallDisplayZoomLevel, 1.0f, 10.0f, di->T("Zoom"), 1.0f, screenManager(), "* PSP res", new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 134));
root_->Add(zoomlvl_);
mode_->AddChoice(di->T("Move"));
mode_->AddChoice(di->T("Resize"));
mode_->SetSelection(0);
}
displayRepresentation_ = new DragDropDisplay(g_Config.fSmallDisplayOffsetX, g_Config.fSmallDisplayOffsetY, I_PSP_DISPLAY, g_Config.fSmallDisplayCustomZoom);
displayRepresentation_ = new DragDropDisplay(g_Config.fSmallDisplayOffsetX, g_Config.fSmallDisplayOffsetY, I_PSP_DISPLAY, displayRepresentationScale_);
displayRepresentation_->SetVisibility(V_VISIBLE);
} else {
} else { // Stretching
mode_->AddChoice(gr->T("Stretching"));
mode_->ReplaceLayoutParams(new AnchorLayoutParams(0, 0, local_dp_xres / 2.0f - 70.0f, NONE, NONE, local_dp_yres / 2.0f + 32.0f));
displayRepresentation_ = new DragDropDisplay(g_Config.fSmallDisplayOffsetX, g_Config.fSmallDisplayOffsetY, I_PSP_DISPLAY, g_Config.fSmallDisplayCustomZoom);
displayRepresentation_ = new DragDropDisplay(g_Config.fSmallDisplayOffsetX, g_Config.fSmallDisplayOffsetY, I_PSP_DISPLAY, displayRepresentationScale_);
displayRepresentation_->SetVisibility(V_INVISIBLE);
float width = local_dp_xres / 2.0f;
float height = local_dp_yres / 2.0f;
if (g_Config.iSmallDisplayZoom == 0) { // Stretched
if (g_Config.iSmallDisplayZoomType == 0) { // Stretched
Choice *stretched = new Choice("", "", false, new AnchorLayoutParams(width, height, width - width / 2.0f, NONE, NONE, height - height / 2.0f));
root_->Add(stretched);
} else { // Partially stretched
float origRatio = !bRotated ? 480.0f / 272.0f : 272.0f / 480.0f;
float frameRatio = width / height;
if (origRatio > frameRatio) {
height = width / origRatio;
if (!bRotated && g_Config.iSmallDisplayZoom == 1) { height = (272.0f + height) / 2.0f; }
if (!bRotated && g_Config.iSmallDisplayZoomType == 1) { height = (272.0f + height) / 2.0f; }
} else {
width = height * origRatio;
if (bRotated && g_Config.iSmallDisplayZoom == 1) { width = (272.0f + height) / 2.0f; }
if (bRotated && g_Config.iSmallDisplayZoomType == 1) { width = (272.0f + height) / 2.0f; }
}
Choice *stretched = new Choice("", "", false, new AnchorLayoutParams(width, height, local_dp_xres / 2.0f - width / 2.0f, NONE, NONE, local_dp_yres / 2.0f - height / 2.0f));
root_->Add(stretched);
Expand Down
4 changes: 3 additions & 1 deletion UI/DisplayLayoutScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,20 @@ class DisplayLayoutScreen : public UIDialogScreenWithBackground {

protected:
virtual UI::EventReturn OnCenter(UI::EventParams &e);
virtual UI::EventReturn OnZoomChange(UI::EventParams &e);
virtual UI::EventReturn OnZoomTypeChange(UI::EventParams &e);

private:
DragDropDisplay *picked_;
DragDropDisplay *displayRepresentation_;
UI::ChoiceStrip *mode_;
UI::PopupMultiChoice *zoom_;
UI::PopupMultiChoice *rotation_;
UI::PopupSliderChoiceFloat *zoomlvl_;
bool displayRotEnable_;
// Touch down state for drag to resize etc
float startX_;
float startY_;
float startScale_;
float displayRepresentationScale_;

};
5 changes: 5 additions & 0 deletions UI/EmuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#include "UI/GameInfoCache.h"
#include "UI/MiscScreens.h"
#include "UI/ControlMappingScreen.h"
#include "UI/DisplayLayoutScreen.h"
#include "UI/GameSettingsScreen.h"
#include "UI/InstallZipScreen.h"
#include "UI/ProfilerDraw.h"
Expand Down Expand Up @@ -229,6 +230,10 @@ void EmuScreen::sendMessage(const char *message, const char *value) {
UpdateUIState(UISTATE_MENU);
releaseButtons();
screenManager()->push(new ControlMappingScreen());
} else if (!strcmp(message, "display layout editor")) {
UpdateUIState(UISTATE_MENU);
releaseButtons();
screenManager()->push(new DisplayLayoutScreen());
} else if (!strcmp(message, "settings")) {
UpdateUIState(UISTATE_MENU);
releaseButtons();
Expand Down
4 changes: 4 additions & 0 deletions UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,10 @@ void GameSettingsScreen::sendMessage(const char *message, const char *value) {
UpdateUIState(UISTATE_MENU);
screenManager()->push(new ControlMappingScreen());
}
if (!strcmp(message, "display layout editor")) {
UpdateUIState(UISTATE_MENU);
screenManager()->push(new DisplayLayoutScreen());
}
}

void GameSettingsScreen::onFinish(DialogResult result) {
Expand Down
5 changes: 5 additions & 0 deletions UI/MainScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "UI/GameSettingsScreen.h"
#include "UI/MiscScreens.h"
#include "UI/ControlMappingScreen.h"
#include "UI/DisplayLayoutScreen.h"
#include "UI/SavedataScreen.h"
#include "UI/Store.h"
#include "UI/ui_atlas.h"
Expand Down Expand Up @@ -887,6 +888,10 @@ void MainScreen::sendMessage(const char *message, const char *value) {
UpdateUIState(UISTATE_MENU);
screenManager()->push(new ControlMappingScreen());
}
if (!strcmp(message, "display layout editor")) {
UpdateUIState(UISTATE_MENU);
screenManager()->push(new DisplayLayoutScreen());
}
if (!strcmp(message, "settings")) {
UpdateUIState(UISTATE_MENU);
screenManager()->push(new GameSettingsScreen(""));
Expand Down
Loading

0 comments on commit ca2a09d

Please sign in to comment.