Remove more bad uses of dp_xres. Fix a data flow issue

(could end up with "feedback" if modifying the screen bounds)
This commit is contained in:
Henrik Rydgard 2014-02-10 15:55:21 +01:00
parent c6caff61bf
commit ca9d0ea5cf
8 changed files with 83 additions and 66 deletions

View file

@ -696,6 +696,7 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) {
}
// MIGRATION: For users who had the old static touch layout, aren't I nice?
// We can probably kill this in 0.9.8 or something.
if (fDpadX > 1.0 || fDpadY > 1.0) { // Likely the rest are too!
float screen_width = dp_xres;
float screen_height = dp_yres;

View file

@ -122,7 +122,6 @@ void UpdateScreenScale(int width, int height) {
}
static inline void UpdateRunLoop() {
UpdateScreenScale(PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight);
{
{
#ifdef _WIN32

View file

@ -453,8 +453,9 @@ void EmuScreen::processAxis(const AxisInput &axis, int direction) {
}
void EmuScreen::CreateViews() {
InitPadLayout();
root_ = CreatePadLayout(&pauseTrigger_);
const Bounds &bounds = screenManager()->getUIContext()->GetBounds();
InitPadLayout(bounds.w, bounds.h);
root_ = CreatePadLayout(bounds.w, bounds.h, &pauseTrigger_);
if (g_Config.bShowDeveloperMenu) {
root_->Add(new UI::Button("DevMenu"))->OnClick.Handle(this, &EmuScreen::OnDevTools);
}

View file

@ -16,7 +16,6 @@
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include "GamepadEmu.h"
#include "base/display.h"
#include "base/colorutil.h"
#include "base/NativeApp.h"
#include "math/math_util.h"
@ -297,7 +296,7 @@ void PSPStick::ProcessTouch(float x, float y, bool down) {
}
}
void InitPadLayout(float globalScale) {
void InitPadLayout(float xres, float yres, float globalScale) {
const float scale = globalScale;
// PSP buttons (triangle, circle, square, cross)---------------------
@ -308,13 +307,13 @@ void InitPadLayout(float globalScale) {
// Position of the circle button (the PSP circle button). It is the farthest to the left
float Action_button_spacing = g_Config.fActionButtonSpacing * baseActionButtonSpacing;
int Action_button_center_X = dp_xres - Action_button_spacing * 2;
int Action_button_center_Y = dp_yres - Action_button_spacing * 2;
int Action_button_center_X = xres - Action_button_spacing * 2;
int Action_button_center_Y = yres - Action_button_spacing * 2;
if (g_Config.fActionButtonCenterX == -1.0 || g_Config.fActionButtonCenterY == -1.0) {
// Setup defaults
g_Config.fActionButtonCenterX = (float)Action_button_center_X / dp_xres;
g_Config.fActionButtonCenterY = (float)Action_button_center_Y / dp_yres;
g_Config.fActionButtonCenterX = (float)Action_button_center_X / xres;
g_Config.fActionButtonCenterY = (float)Action_button_center_Y / yres;
}
//D-PAD (up down left right) (aka PSP cross)----------------------------
@ -322,25 +321,25 @@ void InitPadLayout(float globalScale) {
// TODO: Make configurable
int D_pad_X = 2.5 * D_pad_Radius * scale;
int D_pad_Y = dp_yres - D_pad_Radius * scale;
int D_pad_Y = yres - D_pad_Radius * scale;
if (g_Config.bShowTouchAnalogStick) {
D_pad_Y -= 200 * scale;
}
if (g_Config.fDpadX == -1.0 || g_Config.fDpadY == -1.0 ) {
//setup defaults
g_Config.fDpadX = (float)D_pad_X / dp_xres;
g_Config.fDpadY = (float)D_pad_Y / dp_yres;
g_Config.fDpadX = (float)D_pad_X / xres;
g_Config.fDpadY = (float)D_pad_Y / yres;
}
//analog stick-------------------------------------------------------
//keep the analog stick right below the D pad
int analog_stick_X = D_pad_X;
int analog_stick_Y = dp_yres - 80 * scale;
int analog_stick_Y = yres - 80 * scale;
if (g_Config.fAnalogStickX == -1.0 || g_Config.fAnalogStickY == -1.0 ) {
g_Config.fAnalogStickX = (float)analog_stick_X / dp_xres;
g_Config.fAnalogStickY = (float)analog_stick_Y / dp_yres;
g_Config.fAnalogStickX = (float)analog_stick_X / xres;
g_Config.fAnalogStickY = (float)analog_stick_Y / yres;
g_Config.fAnalogStickScale = scale;
}
@ -348,30 +347,30 @@ void InitPadLayout(float globalScale) {
//space between the bottom keys (space between select, start and un-throttle)
const int bottom_key_spacing = 100 * scale;
int start_key_X = dp_xres / 2 + (bottom_key_spacing) * scale;
int start_key_Y = dp_yres - 60 * scale;
int start_key_X = xres / 2 + (bottom_key_spacing) * scale;
int start_key_Y = yres - 60 * scale;
if (g_Config.fStartKeyX == -1.0 || g_Config.fStartKeyY == -1.0 ) {
g_Config.fStartKeyX = (float)start_key_X / dp_xres;
g_Config.fStartKeyY = (float)start_key_Y / dp_yres;
g_Config.fStartKeyX = (float)start_key_X / xres;
g_Config.fStartKeyY = (float)start_key_Y / yres;
g_Config.fStartKeyScale = scale;
}
int select_key_X = dp_xres / 2;
int select_key_Y = dp_yres - 60 * scale;
int select_key_X = xres / 2;
int select_key_Y = yres - 60 * scale;
if (g_Config.fSelectKeyX == -1.0 || g_Config.fSelectKeyY == -1.0 ) {
g_Config.fSelectKeyX = (float)select_key_X / dp_xres;
g_Config.fSelectKeyY = (float)select_key_Y / dp_yres;
g_Config.fSelectKeyX = (float)select_key_X / xres;
g_Config.fSelectKeyY = (float)select_key_Y / yres;
g_Config.fSelectKeyScale = scale;
}
int unthrottle_key_X = dp_xres / 2 - (bottom_key_spacing) * scale;
int unthrottle_key_Y = dp_yres - 60 * scale;
int unthrottle_key_X = xres / 2 - (bottom_key_spacing) * scale;
int unthrottle_key_Y = yres - 60 * scale;
if (g_Config.fUnthrottleKeyX == -1.0 || g_Config.fUnthrottleKeyY == -1.0 ) {
g_Config.fUnthrottleKeyX = (float)unthrottle_key_X / dp_xres;
g_Config.fUnthrottleKeyY = (float)unthrottle_key_Y / dp_yres;
g_Config.fUnthrottleKeyX = (float)unthrottle_key_X / xres;
g_Config.fUnthrottleKeyY = (float)unthrottle_key_Y / yres;
g_Config.fUnthrottleKeyScale = scale;
}
@ -380,35 +379,35 @@ void InitPadLayout(float globalScale) {
int l_key_Y = 40 * scale;
if (g_Config.fLKeyX == -1.0 || g_Config.fLKeyY == -1.0 ) {
g_Config.fLKeyX = (float)l_key_X / dp_xres;
g_Config.fLKeyY = (float)l_key_Y / dp_yres;
g_Config.fLKeyX = (float)l_key_X / xres;
g_Config.fLKeyY = (float)l_key_Y / yres;
g_Config.fLKeyScale = scale;
}
int r_key_X = dp_xres - 60 * scale;
int r_key_X = xres - 60 * scale;
int r_key_Y = 40 * scale;
if (g_Config.fRKeyX == -1.0 || g_Config.fRKeyY == -1.0 ) {
g_Config.fRKeyX = (float)r_key_X / dp_xres;
g_Config.fRKeyY = (float)r_key_Y / dp_yres;
g_Config.fRKeyX = (float)r_key_X / xres;
g_Config.fRKeyY = (float)r_key_Y / yres;
g_Config.fRKeyScale = scale;
}
};
UI::ViewGroup *CreatePadLayout(bool *pause) {
UI::ViewGroup *CreatePadLayout(float xres, float yres, bool *pause) {
//standard coord system
using namespace UI;
AnchorLayout *root = new AnchorLayout(new LayoutParams(FILL_PARENT, FILL_PARENT));
//PSP buttons (triangle, circle, square, cross)---------------------
//space between the PSP buttons (traingle, circle, square and cross)
const float Action_button_scale = g_Config.fActionButtonScale;
const float Action_button_spacing = g_Config.fActionButtonSpacing * baseActionButtonSpacing;
//position of the circle button (the PSP circle button). It is the farthest to the left
float Action_button_center_X = g_Config.fActionButtonCenterX * dp_xres;
float Action_button_center_Y = g_Config.fActionButtonCenterY * dp_yres;
float Action_button_center_X = g_Config.fActionButtonCenterX * xres;
float Action_button_center_Y = g_Config.fActionButtonCenterY * yres;
const float Action_circle_button_X = Action_button_center_X + Action_button_spacing;
const float Action_circle_button_Y = Action_button_center_Y;
@ -425,40 +424,40 @@ UI::ViewGroup *CreatePadLayout(bool *pause) {
//D-PAD (up down left right) (aka PSP cross)--------------------------------------------------------------
//radius to the D-pad
float D_pad_X = g_Config.fDpadX * dp_xres;
float D_pad_Y = g_Config.fDpadY * dp_yres;
float D_pad_X = g_Config.fDpadX * xres;
float D_pad_Y = g_Config.fDpadY * yres;
float D_pad_scale = g_Config.fDpadScale;
float D_pad_spacing = g_Config.fDpadSpacing;
//select, start, throttle--------------------------------------------
//space between the bottom keys (space between select, start and un-throttle)
float start_key_X = g_Config.fStartKeyX * dp_xres;
float start_key_Y = g_Config.fStartKeyY * dp_yres;
float start_key_X = g_Config.fStartKeyX * xres;
float start_key_Y = g_Config.fStartKeyY * yres;
float start_key_scale = g_Config.fStartKeyScale;
float select_key_X = g_Config.fSelectKeyX * dp_xres;
float select_key_Y = g_Config.fSelectKeyY * dp_yres;
float select_key_X = g_Config.fSelectKeyX * xres;
float select_key_Y = g_Config.fSelectKeyY * yres;
float select_key_scale = g_Config.fSelectKeyScale;
float unthrottle_key_X = g_Config.fUnthrottleKeyX * dp_xres;
float unthrottle_key_Y = g_Config.fUnthrottleKeyY * dp_yres;
float unthrottle_key_X = g_Config.fUnthrottleKeyX * xres;
float unthrottle_key_Y = g_Config.fUnthrottleKeyY * yres;
float unthrottle_key_scale = g_Config.fUnthrottleKeyScale;
//L and R------------------------------------------------------------
float l_key_X = g_Config.fLKeyX * dp_xres;
float l_key_Y = g_Config.fLKeyY * dp_yres;
float l_key_X = g_Config.fLKeyX * xres;
float l_key_Y = g_Config.fLKeyY * yres;
float l_key_scale = g_Config.fLKeyScale;
float r_key_X = g_Config.fRKeyX * dp_xres;
float r_key_Y = g_Config.fRKeyY * dp_yres;
float r_key_X = g_Config.fRKeyX * xres;
float r_key_Y = g_Config.fRKeyY * yres;
float r_key_scale = g_Config.fRKeyScale;
//analog stick-------------------------------------------------------
float analog_stick_X = g_Config.fAnalogStickX * dp_xres;
float analog_stick_Y = g_Config.fAnalogStickY * dp_yres;
float analog_stick_X = g_Config.fAnalogStickX * xres;
float analog_stick_Y = g_Config.fAnalogStickY * yres;
float analog_stick_scale = g_Config.fAnalogStickScale;
const int halfW = dp_xres / 2;
const int halfW = xres / 2;
if (g_Config.bShowTouchControls) {
int roundImage = g_Config.iTouchButtonStyle ? I_ROUND_LINE : I_ROUND;

View file

@ -122,8 +122,8 @@ private:
//initializes the layout from Config. if a default layout does not exist,
//it sets up default values
void InitPadLayout(float globalScale = 1.15f);
UI::ViewGroup *CreatePadLayout(bool *pause);
void InitPadLayout(float xres, float yres, float globalScale = 1.15f);
UI::ViewGroup *CreatePadLayout(float xres, float yres, bool *pause);
const int D_pad_Radius = 50;
const int baseActionButtonSpacing = 60;

View file

@ -624,6 +624,7 @@ void NativeRender() {
// Apply the UIContext bounds as a 2D transformation matrix.
Matrix4x4 ortho;
ortho.setOrtho(0.0f, xres, yres, 0.0f, -1.0f, 1.0f);
glsl_bind(UIShader_Get());
glUniformMatrix4fv(UIShader_Get()->u_worldviewproj, 1, GL_FALSE, ortho.getReadPtr());
@ -782,7 +783,9 @@ void NativeMessageReceived(const char *message, const char *value) {
}
void NativeResized() {
uiContext->SetBounds(Bounds(0, 0, dp_xres, dp_yres));
if (uiContext) {
uiContext->SetBounds(Bounds(0, 0, dp_xres, dp_yres));
}
}
void NativeShutdown() {

View file

@ -17,7 +17,6 @@
#include <vector>
#include "base/display.h"
#include "base/colorutil.h"
#include "gfx_es2/draw_buffer.h"
#include "i18n/i18n.h"
@ -32,6 +31,10 @@
static const int leftColumnWidth = 140;
// Ugly hackery, need to rework some stuff to get around this
static float local_dp_xres;
static float local_dp_yres;
static u32 GetButtonColor() {
return g_Config.iTouchButtonStyle == 1 ? 0xFFFFFF : 0xc0b080;
}
@ -39,7 +42,7 @@ static u32 GetButtonColor() {
class DragDropButton : public MultiTouchButton {
public:
DragDropButton(float &x, float &y, int bgImg, int img, float &scale)
: MultiTouchButton(bgImg, img, scale, new UI::AnchorLayoutParams(fromFullscreenCoord(x), y*dp_yres, UI::NONE, UI::NONE, true)),
: MultiTouchButton(bgImg, img, scale, new UI::AnchorLayoutParams(fromFullscreenCoord(x), y*local_dp_yres, UI::NONE, UI::NONE, true)),
x_(x), y_(y), theScale_(scale) {
scale_ = theScale_;
}
@ -52,7 +55,7 @@ public:
virtual void SavePosition() {
x_ = toFullscreenCoord(bounds_.centerX());
y_ = bounds_.centerY() / dp_yres;
y_ = bounds_.centerY() / local_dp_yres;
scale_ = theScale_;
}
@ -65,12 +68,12 @@ public:
private:
// convert from screen coordinates (leftColumnWidth to dp_xres) to actual fullscreen coordinates (0 to 1.0)
inline float toFullscreenCoord(int screenx) {
return (float)(screenx - leftColumnWidth) / (dp_xres - leftColumnWidth);
return (float)(screenx - leftColumnWidth) / (local_dp_xres - leftColumnWidth);
}
// convert from external fullscreen coordinates(0 to 1.0) to the current partial coordinates (leftColumnWidth to dp_xres)
inline int fromFullscreenCoord(float controllerX) {
return leftColumnWidth + (dp_xres - leftColumnWidth) * controllerX;
return leftColumnWidth + (local_dp_xres - leftColumnWidth) * controllerX;
};
float &x_, &y_;
@ -218,15 +221,17 @@ void TouchControlLayoutScreen::touch(const TouchInput &touch) {
int mode = mode_->GetSelection();
const Bounds &screen_bounds = screenManager()->getUIContext()->GetBounds();
if ((touch.flags & TOUCH_MOVE) && pickedControl_ != 0) {
if (mode == 0) {
const Bounds &bounds = pickedControl_->GetBounds();
int mintouchX = leftColumnWidth + bounds.w * 0.5;
int maxTouchX = dp_xres - bounds.w * 0.5;
int maxTouchX = screen_bounds.w - bounds.w * 0.5;
int minTouchY = bounds.h * 0.5;
int maxTouchY = dp_yres - bounds.h * 0.5;
int maxTouchY = screen_bounds.h - bounds.h * 0.5;
int newX = bounds.centerX(), newY = bounds.centerY();
@ -284,7 +289,8 @@ UI::EventReturn TouchControlLayoutScreen::OnVisibility(UI::EventParams &e) {
UI::EventReturn TouchControlLayoutScreen::OnReset(UI::EventParams &e) {
ILOG("Resetting touch control layout");
g_Config.ResetControlLayout();
InitPadLayout();
const Bounds &bounds = screenManager()->getUIContext()->GetBounds();
InitPadLayout(bounds.w, bounds.h);
RecreateViews();
return UI::EVENT_DONE;
};
@ -295,7 +301,11 @@ void TouchControlLayoutScreen::dialogFinished(const Screen *dialog, DialogResult
void TouchControlLayoutScreen::CreateViews() {
// setup g_Config for button layout
InitPadLayout();
const Bounds &bounds = screenManager()->getUIContext()->GetBounds();
InitPadLayout(bounds.w, bounds.h);
local_dp_xres = bounds.w;
local_dp_yres = bounds.h;
using namespace UI;

View file

@ -210,6 +210,7 @@ namespace MainWindow
}
void ResizeDisplay(bool displayOSM = true, bool noWindowMovement = false) {
int width = PSP_CoreParameter().pixelWidth, height = PSP_CoreParameter().pixelHeight;
RECT rc;
GetClientRect(hwndMain, &rc);
if (!noWindowMovement) {
@ -217,9 +218,10 @@ namespace MainWindow
(rc.bottom - rc.top) == PSP_CoreParameter().pixelHeight)
return;
PSP_CoreParameter().pixelWidth = rc.right - rc.left;
PSP_CoreParameter().pixelHeight = rc.bottom - rc.top;
MoveWindow(hwndDisplay, 0, 0, PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight, TRUE);
width = rc.right - rc.left;
height = rc.bottom - rc.top;
// Moves the internal window, not the frame. TODO: Get rid of the internal window.
MoveWindow(hwndDisplay, 0, 0, width, height, TRUE);
}
// Round up to a zoom factor for the render size.
@ -227,6 +229,7 @@ namespace MainWindow
if (zoom == 0) // auto mode
zoom = (rc.right - rc.left + 479) / 480;
// Actually, auto mode should be more granular...
PSP_CoreParameter().renderWidth = 480 * zoom;
PSP_CoreParameter().renderHeight = 272 * zoom;
@ -239,6 +242,7 @@ namespace MainWindow
osm.Show(g->T(message), 2.0f);
}
UpdateScreenScale(width, height);
NativeMessageReceived("gpu resized", "");
}