mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-09-04 03:35:19 +02:00
Editable touch controls: Added Reset button and fixed build in VS 2010
This commit is contained in:
@@ -1,3 +1,22 @@
|
||||
// Copyright (c) 2013- PPSSPP Project.
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, version 2.0 or later versions.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official git repository and contact information can be found at
|
||||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "TouchControlLayoutScreen.h"
|
||||
#include "Core/Config.h"
|
||||
#include "Core/System.h"
|
||||
@@ -10,31 +29,31 @@
|
||||
|
||||
static const int leftMargin = 140;
|
||||
|
||||
|
||||
//convert from screen coordinates (leftMargin to dp_xres) to actual fullscreen coordinates (0 to dp_xres)
|
||||
int toFullscreenCoord(int screenx){
|
||||
// convert from screen coordinates (leftMargin to dp_xres) to actual fullscreen coordinates (0 to dp_xres)
|
||||
static inline int toFullscreenCoord(int screenx) {
|
||||
return ((float)dp_xres / (dp_xres - leftMargin)) * (screenx - leftMargin);
|
||||
}
|
||||
|
||||
//convert from external fullscreen coordinates(0 to dp_xres) to the current partial coordinates (leftMargin to dp_xres)
|
||||
int fromFullscreenCoord(int controllerX){
|
||||
// convert from external fullscreen coordinates(0 to dp_xres) to the current partial coordinates (leftMargin to dp_xres)
|
||||
static inline int fromFullscreenCoord(int controllerX) {
|
||||
return leftMargin + ((dp_xres - leftMargin) / (float)dp_xres) * controllerX;
|
||||
};
|
||||
|
||||
class DragDropButton : public MultiTouchButton{
|
||||
class DragDropButton : public MultiTouchButton {
|
||||
public:
|
||||
DragDropButton(int &x, int &y, int bgImg, int img, float scale)
|
||||
: MultiTouchButton(bgImg, img, scale, new UI::AnchorLayoutParams(fromFullscreenCoord(x), y, UI::NONE, UI::NONE, true)), x_(x), y_(y){
|
||||
: MultiTouchButton(bgImg, img, scale, new UI::AnchorLayoutParams(fromFullscreenCoord(x), y, UI::NONE, UI::NONE, true)),
|
||||
x_(x), y_(y) {
|
||||
scale_ = scale;
|
||||
}
|
||||
|
||||
virtual bool IsDown(){
|
||||
virtual bool IsDown() {
|
||||
//don't want the button to enlarge and throw the user's perspective
|
||||
//of button size off whack.
|
||||
return false;
|
||||
};
|
||||
|
||||
void SavePosition(){
|
||||
void SavePosition() {
|
||||
x_ = toFullscreenCoord(bounds_.centerX());
|
||||
y_ = bounds_.centerY();
|
||||
}
|
||||
@@ -43,11 +62,10 @@ private:
|
||||
int &x_, &y_;
|
||||
};
|
||||
|
||||
|
||||
class PSPActionButtons : public DragDropButton{
|
||||
class PSPActionButtons : public DragDropButton {
|
||||
public:
|
||||
PSPActionButtons(int &x, int &y, int actionButtonSpacing, float scale)
|
||||
: DragDropButton(x, y, -1, -1, scale), actionButtonSpacing_(actionButtonSpacing){
|
||||
: DragDropButton(x, y, -1, -1, scale), actionButtonSpacing_(actionButtonSpacing) {
|
||||
using namespace UI;
|
||||
roundId_ = I_ROUND;
|
||||
|
||||
@@ -57,10 +75,9 @@ public:
|
||||
squareId_ = I_SQUARE;
|
||||
};
|
||||
|
||||
void Draw(UIContext &dc){
|
||||
void Draw(UIContext &dc) {
|
||||
float opacity = g_Config.iTouchButtonOpacity / 100.0f;
|
||||
|
||||
|
||||
uint32_t colorBg = colorAlpha(0xc0b080, opacity);
|
||||
uint32_t color = colorAlpha(0xFFFFFF, opacity);
|
||||
|
||||
@@ -88,6 +105,7 @@ public:
|
||||
//w += 2 * actionButtonSpacing_;
|
||||
//h += 2 * actionButtonSpacing_;
|
||||
};
|
||||
|
||||
private:
|
||||
int roundId_;
|
||||
int circleId_, crossId_, triangleId_, squareId_;
|
||||
@@ -95,13 +113,13 @@ private:
|
||||
int actionButtonSpacing_;
|
||||
};
|
||||
|
||||
class PSPDPadButtons : public DragDropButton{
|
||||
class PSPDPadButtons : public DragDropButton {
|
||||
public:
|
||||
PSPDPadButtons(int &x, int &y, int DpadRadius, float scale)
|
||||
: DragDropButton(x, y, -1, -1, scale), DpadRadius_(DpadRadius){
|
||||
: DragDropButton(x, y, -1, -1, scale), DpadRadius_(DpadRadius) {
|
||||
}
|
||||
|
||||
void Draw(UIContext &dc){
|
||||
void Draw(UIContext &dc) {
|
||||
float opacity = g_Config.iTouchButtonOpacity / 100.0f;
|
||||
|
||||
uint32_t colorBg = colorAlpha(0xc0b080, opacity);
|
||||
@@ -133,19 +151,16 @@ private:
|
||||
int DpadRadius_;
|
||||
};
|
||||
|
||||
|
||||
|
||||
TouchControlLayoutScreen::TouchControlLayoutScreen(){
|
||||
TouchControlLayoutScreen::TouchControlLayoutScreen() {
|
||||
pickedControl_ = 0;
|
||||
};
|
||||
|
||||
void TouchControlLayoutScreen::touch(const TouchInput &touch){
|
||||
void TouchControlLayoutScreen::touch(const TouchInput &touch) {
|
||||
UIScreen::touch(touch);
|
||||
|
||||
using namespace UI;
|
||||
|
||||
//this is if - not else if as up and move can occur simultaneously
|
||||
if ((touch.flags & TOUCH_MOVE) && pickedControl_ != 0){
|
||||
if ((touch.flags & TOUCH_MOVE) && pickedControl_ != 0) {
|
||||
const Bounds &bounds = pickedControl_->GetBounds();
|
||||
|
||||
int mintouchX = leftMargin + bounds.w * 0.5;
|
||||
@@ -157,37 +172,33 @@ void TouchControlLayoutScreen::touch(const TouchInput &touch){
|
||||
int newX = bounds.centerX(), newY = bounds.centerY();
|
||||
|
||||
//we have to handle x and y separately since even if x is blocked, y may not be.
|
||||
if(touch.x > mintouchX && touch.x < maxTouchX){
|
||||
if (touch.x > mintouchX && touch.x < maxTouchX) {
|
||||
//if the leftmost point of the control is ahead of the margin,
|
||||
//move it. Otherwise, don't.
|
||||
newX = touch.x;
|
||||
}
|
||||
if(touch.y > minTouchY && touch.y < maxTouchY){
|
||||
if (touch.y > minTouchY && touch.y < maxTouchY) {
|
||||
newY = touch.y;
|
||||
}
|
||||
|
||||
ILOG("position: x = %d; y = %d", newX, newY);
|
||||
pickedControl_->ReplaceLayoutParams(new UI::AnchorLayoutParams(newX, newY, NONE, NONE,true));
|
||||
// ILOG("position: x = %d; y = %d", newX, newY);
|
||||
pickedControl_->ReplaceLayoutParams(new UI::AnchorLayoutParams(newX, newY, NONE, NONE, true));
|
||||
}
|
||||
|
||||
else if ((touch.flags & TOUCH_DOWN) && pickedControl_ == 0){
|
||||
if ((touch.flags & TOUCH_DOWN) && pickedControl_ == 0) {
|
||||
ILOG("->->->picked up")
|
||||
pickedControl_ = getPickedControl(touch.x, touch.y);
|
||||
}
|
||||
|
||||
else if ((touch.flags & TOUCH_UP) && pickedControl_ != 0){
|
||||
if ((touch.flags & TOUCH_UP) && pickedControl_ != 0) {
|
||||
pickedControl_->SavePosition();
|
||||
ILOG("->->->dropped down")
|
||||
pickedControl_ = 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
UI::EventReturn TouchControlLayoutScreen::OnBack(UI::EventParams &e){
|
||||
UI::EventReturn TouchControlLayoutScreen::OnBack(UI::EventParams &e) {
|
||||
g_Config.Save();
|
||||
|
||||
if(PSP_IsInited()) {
|
||||
if (PSP_IsInited()) {
|
||||
screenManager()->finishDialog(this, DR_CANCEL);
|
||||
} else {
|
||||
screenManager()->finishDialog(this, DR_OK);
|
||||
@@ -196,13 +207,33 @@ UI::EventReturn TouchControlLayoutScreen::OnBack(UI::EventParams &e){
|
||||
return UI::EVENT_DONE;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
void TouchControlLayoutScreen::CreateViews(){
|
||||
//setup g_Config for button layout
|
||||
UI::EventReturn TouchControlLayoutScreen::OnReset(UI::EventParams &e) {
|
||||
g_Config.iActionButtonSpacing = -1;
|
||||
g_Config.iActionButtonCenterX = -1;
|
||||
g_Config.iActionButtonCenterY = -1;
|
||||
g_Config.iDpadRadius = -1;
|
||||
g_Config.iDpadX = -1;
|
||||
g_Config.iDpadY = -1;
|
||||
g_Config.iStartKeyX = -1;
|
||||
g_Config.iStartKeyY = -1;
|
||||
g_Config.iSelectKeyX = -1;
|
||||
g_Config.iSelectKeyY = -1;
|
||||
g_Config.iUnthrottleKeyX = -1;
|
||||
g_Config.iUnthrottleKeyY = -1;
|
||||
g_Config.iLKeyX = -1;
|
||||
g_Config.iLKeyY = -1;
|
||||
g_Config.iRKeyX = -1;
|
||||
g_Config.iRKeyY = -1;
|
||||
g_Config.iAnalogStickX = -1;
|
||||
g_Config.iAnalogStickY = -1;
|
||||
InitPadLayout();
|
||||
RecreateViews();
|
||||
return UI::EVENT_DONE;
|
||||
};
|
||||
|
||||
void TouchControlLayoutScreen::CreateViews() {
|
||||
// setup g_Config for button layout
|
||||
InitPadLayout();
|
||||
|
||||
using namespace UI;
|
||||
|
||||
@@ -210,11 +241,13 @@ void TouchControlLayoutScreen::CreateViews(){
|
||||
|
||||
root_ = new AnchorLayout(new LayoutParams(FILL_PARENT, FILL_PARENT));
|
||||
|
||||
Choice *reset = new Choice(d->T("Reset"), "", false, new AnchorLayoutParams(leftMargin, WRAP_CONTENT, 10, NONE, NONE, 84));
|
||||
Choice *back = new Choice(d->T("Back"), "", false, new AnchorLayoutParams(leftMargin, WRAP_CONTENT, 10, NONE, NONE, 10));
|
||||
reset->OnClick.Handle(this, &TouchControlLayoutScreen::OnReset);
|
||||
back->OnClick.Handle(this, &TouchControlLayoutScreen::OnBack);
|
||||
root_->Add(reset);
|
||||
root_->Add(back);
|
||||
|
||||
|
||||
TabHolder *tabHolder = new TabHolder(ORIENT_VERTICAL, leftMargin, new AnchorLayoutParams(10, 0, 10, 0, false));
|
||||
root_->Add(tabHolder);
|
||||
|
||||
@@ -224,6 +257,7 @@ void TouchControlLayoutScreen::CreateViews(){
|
||||
AnchorLayout *controlsHolder = new AnchorLayout(new LayoutParams(FILL_PARENT, FILL_PARENT));
|
||||
|
||||
float scale = g_Config.fButtonScale;
|
||||
controls_.clear();
|
||||
controls_.push_back(new PSPActionButtons(g_Config.iActionButtonCenterX, g_Config.iActionButtonCenterY, g_Config.iActionButtonSpacing, scale));
|
||||
controls_.push_back(new PSPDPadButtons(g_Config.iDpadX, g_Config.iDpadY, g_Config.iDpadRadius, scale));
|
||||
|
||||
@@ -241,28 +275,25 @@ void TouchControlLayoutScreen::CreateViews(){
|
||||
I18NCategory *c = GetI18NCategory("Controls");
|
||||
tabHolder->AddTab(c->T("Controls"), controlsHolder);
|
||||
|
||||
|
||||
for(UI::View *control : controls_){
|
||||
root_->Add(control);
|
||||
for (size_t i = 0; i < controls_.size(); i++) {
|
||||
root_->Add(controls_[i]);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
//return the control which was picked up bu the touchEvent. If a control
|
||||
//was already picked up, then it's being dragged around, so just return that instead
|
||||
DragDropButton *TouchControlLayoutScreen::getPickedControl(const int x, const int y){
|
||||
|
||||
if(pickedControl_ != 0){
|
||||
// return the control which was picked up by the touchEvent. If a control
|
||||
// was already picked up, then it's being dragged around, so just return that instead
|
||||
DragDropButton *TouchControlLayoutScreen::getPickedControl(const int x, const int y) {
|
||||
if (pickedControl_ != 0) {
|
||||
return pickedControl_;
|
||||
}
|
||||
|
||||
for(DragDropButton *control : controls_){
|
||||
for (size_t i = 0; i < controls_.size(); i++) {
|
||||
DragDropButton *control = controls_[i];
|
||||
const Bounds &bounds = control->GetBounds();
|
||||
static const int thresholdFactor = 1.5;
|
||||
|
||||
Bounds tolerantBounds(bounds.x, bounds.y, bounds.w * thresholdFactor, bounds.h * thresholdFactor);
|
||||
if(tolerantBounds.Contains(x, y)){
|
||||
if (tolerantBounds.Contains(x, y)) {
|
||||
return control;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user