2013-10-19 22:34:48 +00:00
|
|
|
// 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>
|
|
|
|
|
2014-02-10 11:38:23 +00:00
|
|
|
#include "base/colorutil.h"
|
|
|
|
#include "gfx_es2/draw_buffer.h"
|
|
|
|
#include "i18n/i18n.h"
|
|
|
|
#include "ui/ui_context.h"
|
|
|
|
#include "ui_atlas.h"
|
|
|
|
|
2013-10-09 20:15:56 +00:00
|
|
|
#include "TouchControlLayoutScreen.h"
|
2013-10-20 15:33:18 +00:00
|
|
|
#include "TouchControlVisibilityScreen.h"
|
2013-10-09 20:15:56 +00:00
|
|
|
#include "Core/Config.h"
|
|
|
|
#include "Core/System.h"
|
|
|
|
#include "GamepadEmu.h"
|
|
|
|
|
2013-12-02 14:15:19 +00:00
|
|
|
static const int leftColumnWidth = 140;
|
2013-10-09 20:15:56 +00:00
|
|
|
|
2014-02-10 14:55:21 +00:00
|
|
|
// Ugly hackery, need to rework some stuff to get around this
|
|
|
|
static float local_dp_xres;
|
|
|
|
static float local_dp_yres;
|
|
|
|
|
2013-12-10 22:19:37 +00:00
|
|
|
static u32 GetButtonColor() {
|
|
|
|
return g_Config.iTouchButtonStyle == 1 ? 0xFFFFFF : 0xc0b080;
|
|
|
|
}
|
|
|
|
|
2013-10-19 22:34:48 +00:00
|
|
|
class DragDropButton : public MultiTouchButton {
|
2013-10-09 20:15:56 +00:00
|
|
|
public:
|
2013-12-02 14:15:19 +00:00
|
|
|
DragDropButton(float &x, float &y, int bgImg, int img, float &scale)
|
2014-02-10 14:55:21 +00:00
|
|
|
: MultiTouchButton(bgImg, img, scale, new UI::AnchorLayoutParams(fromFullscreenCoord(x), y*local_dp_yres, UI::NONE, UI::NONE, true)),
|
2013-12-02 14:15:19 +00:00
|
|
|
x_(x), y_(y), theScale_(scale) {
|
|
|
|
scale_ = theScale_;
|
2013-10-09 20:15:56 +00:00
|
|
|
}
|
|
|
|
|
2013-10-19 22:34:48 +00:00
|
|
|
virtual bool IsDown() {
|
2013-12-02 14:15:19 +00:00
|
|
|
// Don't want the button to enlarge and throw the user's perspective
|
|
|
|
// of button size off whack.
|
2013-10-09 20:15:56 +00:00
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2013-12-02 14:15:19 +00:00
|
|
|
virtual void SavePosition() {
|
2013-10-09 20:15:56 +00:00
|
|
|
x_ = toFullscreenCoord(bounds_.centerX());
|
2014-02-10 14:55:21 +00:00
|
|
|
y_ = bounds_.centerY() / local_dp_yres;
|
2013-12-02 14:15:19 +00:00
|
|
|
scale_ = theScale_;
|
2013-10-09 20:15:56 +00:00
|
|
|
}
|
|
|
|
|
2013-12-02 14:15:19 +00:00
|
|
|
virtual float GetScale() const { return theScale_; }
|
|
|
|
virtual void SetScale(float s) { theScale_ = s; scale_ = s; }
|
|
|
|
|
|
|
|
virtual float GetSpacing() const { return 1.0f; }
|
|
|
|
virtual void SetSpacing(float s) { }
|
|
|
|
|
2013-10-09 20:15:56 +00:00
|
|
|
private:
|
2014-02-10 11:38:23 +00:00
|
|
|
// convert from screen coordinates (leftColumnWidth to dp_xres) to actual fullscreen coordinates (0 to 1.0)
|
|
|
|
inline float toFullscreenCoord(int screenx) {
|
2014-02-10 14:55:21 +00:00
|
|
|
return (float)(screenx - leftColumnWidth) / (local_dp_xres - leftColumnWidth);
|
2014-02-10 11:38:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// convert from external fullscreen coordinates(0 to 1.0) to the current partial coordinates (leftColumnWidth to dp_xres)
|
|
|
|
inline int fromFullscreenCoord(float controllerX) {
|
2014-02-10 14:55:21 +00:00
|
|
|
return leftColumnWidth + (local_dp_xres - leftColumnWidth) * controllerX;
|
2014-02-10 11:38:23 +00:00
|
|
|
};
|
|
|
|
|
2013-11-05 04:52:31 +00:00
|
|
|
float &x_, &y_;
|
2013-12-02 14:15:19 +00:00
|
|
|
float &theScale_;
|
2013-10-09 20:15:56 +00:00
|
|
|
};
|
|
|
|
|
2013-10-19 22:34:48 +00:00
|
|
|
class PSPActionButtons : public DragDropButton {
|
2013-10-09 20:15:56 +00:00
|
|
|
public:
|
2013-12-02 14:15:19 +00:00
|
|
|
PSPActionButtons(float &x, float &y, float &scale, float &spacing)
|
|
|
|
: DragDropButton(x, y, -1, -1, scale), spacing_(spacing) {
|
2013-10-09 20:15:56 +00:00
|
|
|
using namespace UI;
|
2013-12-10 22:19:37 +00:00
|
|
|
roundId_ = g_Config.iTouchButtonStyle ? I_ROUND_LINE : I_ROUND;
|
2013-10-09 20:15:56 +00:00
|
|
|
|
|
|
|
circleId_ = I_CIRCLE;
|
|
|
|
crossId_ = I_CROSS;
|
|
|
|
triangleId_ = I_TRIANGLE;
|
|
|
|
squareId_ = I_SQUARE;
|
2013-10-20 10:06:01 +00:00
|
|
|
|
|
|
|
circleVisible_ = triangleVisible_ = squareVisible_ = crossVisible_ = true;
|
2013-10-09 20:15:56 +00:00
|
|
|
};
|
|
|
|
|
2013-10-20 10:06:01 +00:00
|
|
|
void setCircleVisibility(bool visible){
|
|
|
|
circleVisible_ = visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setCrossVisibility(bool visible){
|
|
|
|
crossVisible_ = visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setTriangleVisibility(bool visible){
|
|
|
|
triangleVisible_ = visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setSquareVisibility(bool visible){
|
|
|
|
squareVisible_ = visible;
|
|
|
|
}
|
|
|
|
|
2013-10-19 22:34:48 +00:00
|
|
|
void Draw(UIContext &dc) {
|
2013-10-09 20:15:56 +00:00
|
|
|
float opacity = g_Config.iTouchButtonOpacity / 100.0f;
|
|
|
|
|
2013-12-10 22:19:37 +00:00
|
|
|
uint32_t colorBg = colorAlpha(GetButtonColor(), opacity);
|
2013-10-09 20:15:56 +00:00
|
|
|
uint32_t color = colorAlpha(0xFFFFFF, opacity);
|
|
|
|
|
|
|
|
int centerX = bounds_.centerX();
|
|
|
|
int centerY = bounds_.centerY();
|
|
|
|
|
2013-12-02 14:15:19 +00:00
|
|
|
float spacing = spacing_ * baseActionButtonSpacing;
|
2013-10-20 10:06:01 +00:00
|
|
|
if (circleVisible_) {
|
2013-12-02 14:15:19 +00:00
|
|
|
dc.Draw()->DrawImageRotated(roundId_, centerX + spacing, centerY, scale_, 0, colorBg, false);
|
|
|
|
dc.Draw()->DrawImageRotated(circleId_, centerX + spacing, centerY, scale_, 0, color, false);
|
2013-10-20 10:06:01 +00:00
|
|
|
}
|
2013-10-09 20:15:56 +00:00
|
|
|
|
2013-10-20 10:06:01 +00:00
|
|
|
if (crossVisible_) {
|
2013-12-02 14:15:19 +00:00
|
|
|
dc.Draw()->DrawImageRotated(roundId_, centerX, centerY + spacing, scale_, 0, colorBg, false);
|
|
|
|
dc.Draw()->DrawImageRotated(crossId_, centerX, centerY + spacing, scale_, 0, color, false);
|
2013-10-20 10:06:01 +00:00
|
|
|
}
|
2013-10-09 20:15:56 +00:00
|
|
|
|
2013-10-20 10:06:01 +00:00
|
|
|
if (triangleVisible_) {
|
2013-12-11 19:52:13 +00:00
|
|
|
float y = centerY - spacing;
|
|
|
|
y -= 2.8f * scale_;
|
2013-12-02 14:15:19 +00:00
|
|
|
dc.Draw()->DrawImageRotated(roundId_, centerX, centerY - spacing, scale_, 0, colorBg, false);
|
2013-12-11 19:52:13 +00:00
|
|
|
dc.Draw()->DrawImageRotated(triangleId_, centerX, y, scale_, 0, color, false);
|
2013-10-20 10:06:01 +00:00
|
|
|
}
|
2013-12-02 14:15:19 +00:00
|
|
|
|
|
|
|
if (squareVisible_) {
|
|
|
|
dc.Draw()->DrawImageRotated(roundId_, centerX - spacing, centerY, scale_, 0, colorBg, false);
|
|
|
|
dc.Draw()->DrawImageRotated(squareId_, centerX - spacing, centerY, scale_, 0, color, false);
|
2013-10-20 10:06:01 +00:00
|
|
|
}
|
2013-10-09 20:15:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void GetContentDimensions(const UIContext &dc, float &w, float &h) const{
|
|
|
|
const AtlasImage &image = dc.Draw()->GetAtlas()->images[roundId_];
|
|
|
|
|
2013-12-02 14:15:19 +00:00
|
|
|
w = (2 * baseActionButtonSpacing * spacing_) + image.w * scale_;
|
|
|
|
h = (2 * baseActionButtonSpacing * spacing_) + image.h * scale_;
|
|
|
|
}
|
2013-10-19 22:34:48 +00:00
|
|
|
|
2013-12-02 14:15:19 +00:00
|
|
|
virtual float GetSpacing() const { return spacing_; }
|
|
|
|
virtual void SetSpacing(float s) { spacing_ = s; }
|
|
|
|
|
|
|
|
virtual void SavePosition() {
|
|
|
|
DragDropButton::SavePosition();
|
|
|
|
}
|
2013-10-20 10:06:01 +00:00
|
|
|
|
2013-12-02 14:15:19 +00:00
|
|
|
private:
|
2013-10-20 10:06:01 +00:00
|
|
|
bool circleVisible_, crossVisible_, triangleVisible_, squareVisible_;
|
|
|
|
|
2013-10-09 20:15:56 +00:00
|
|
|
int roundId_;
|
|
|
|
int circleId_, crossId_, triangleId_, squareId_;
|
|
|
|
|
2013-12-02 14:15:19 +00:00
|
|
|
float &spacing_;
|
2013-10-09 20:15:56 +00:00
|
|
|
};
|
|
|
|
|
2013-10-19 22:34:48 +00:00
|
|
|
class PSPDPadButtons : public DragDropButton {
|
2013-10-09 20:15:56 +00:00
|
|
|
public:
|
2013-12-02 14:15:19 +00:00
|
|
|
PSPDPadButtons(float &x, float &y, float &scale, float &spacing)
|
|
|
|
: DragDropButton(x, y, -1, -1, scale), spacing_(spacing) {
|
2013-10-09 20:15:56 +00:00
|
|
|
}
|
|
|
|
|
2013-10-19 22:34:48 +00:00
|
|
|
void Draw(UIContext &dc) {
|
2013-10-09 20:15:56 +00:00
|
|
|
float opacity = g_Config.iTouchButtonOpacity / 100.0f;
|
|
|
|
|
2013-12-10 22:19:37 +00:00
|
|
|
uint32_t colorBg = colorAlpha(GetButtonColor(), opacity);
|
2013-10-09 20:15:56 +00:00
|
|
|
uint32_t color = colorAlpha(0xFFFFFF, opacity);
|
|
|
|
|
|
|
|
static const float xoff[4] = {1, 0, -1, 0};
|
|
|
|
static const float yoff[4] = {0, 1, 0, -1};
|
|
|
|
|
2013-12-10 22:19:37 +00:00
|
|
|
int dirImage = g_Config.iTouchButtonStyle ? I_DIR_LINE : I_DIR;
|
|
|
|
|
2013-10-09 20:15:56 +00:00
|
|
|
for (int i = 0; i < 4; i++) {
|
2013-12-11 19:52:13 +00:00
|
|
|
float r = D_pad_Radius * spacing_;
|
|
|
|
float x = bounds_.centerX() + xoff[i] * r;
|
|
|
|
float y = bounds_.centerY() + yoff[i] * r;
|
|
|
|
float x2 = bounds_.centerX() + xoff[i] * (r + 10.f * scale_);
|
|
|
|
float y2 = bounds_.centerY() + yoff[i] * (r + 10.f * scale_);
|
2013-10-09 20:15:56 +00:00
|
|
|
float angle = i * M_PI / 2;
|
|
|
|
|
2013-12-10 22:19:37 +00:00
|
|
|
dc.Draw()->DrawImageRotated(dirImage, x, y, scale_, angle + PI, colorBg, false);
|
2013-12-11 19:52:13 +00:00
|
|
|
dc.Draw()->DrawImageRotated(I_ARROW, x2, y2, scale_, angle + PI, color);
|
2013-10-09 20:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetContentDimensions(const UIContext &dc, float &w, float &h) const{
|
|
|
|
const AtlasImage &image = dc.Draw()->GetAtlas()->images[I_DIR];
|
2013-12-02 14:15:19 +00:00
|
|
|
w = 2 * D_pad_Radius * spacing_ + image.w * scale_;
|
|
|
|
h = 2 * D_pad_Radius * spacing_ + image.h * scale_;
|
2013-10-09 20:15:56 +00:00
|
|
|
};
|
2013-12-06 14:29:14 +00:00
|
|
|
|
2013-12-02 14:15:19 +00:00
|
|
|
float GetSpacing() const { return spacing_; }
|
|
|
|
virtual void SetSpacing(float s) { spacing_ = s; }
|
2013-10-09 20:15:56 +00:00
|
|
|
|
|
|
|
private:
|
2013-12-02 14:15:19 +00:00
|
|
|
float &spacing_;
|
|
|
|
};
|
2013-10-09 20:15:56 +00:00
|
|
|
|
2013-10-19 22:34:48 +00:00
|
|
|
TouchControlLayoutScreen::TouchControlLayoutScreen() {
|
2013-10-09 20:15:56 +00:00
|
|
|
pickedControl_ = 0;
|
|
|
|
};
|
|
|
|
|
2014-06-15 11:04:59 +00:00
|
|
|
bool TouchControlLayoutScreen::touch(const TouchInput &touch) {
|
2013-10-09 20:15:56 +00:00
|
|
|
UIScreen::touch(touch);
|
|
|
|
|
|
|
|
using namespace UI;
|
|
|
|
|
2013-12-02 14:15:19 +00:00
|
|
|
int mode = mode_->GetSelection();
|
2013-10-09 20:15:56 +00:00
|
|
|
|
2014-02-10 14:55:21 +00:00
|
|
|
const Bounds &screen_bounds = screenManager()->getUIContext()->GetBounds();
|
|
|
|
|
2013-12-02 14:15:19 +00:00
|
|
|
if ((touch.flags & TOUCH_MOVE) && pickedControl_ != 0) {
|
|
|
|
if (mode == 0) {
|
|
|
|
const Bounds &bounds = pickedControl_->GetBounds();
|
|
|
|
|
|
|
|
int mintouchX = leftColumnWidth + bounds.w * 0.5;
|
2014-02-10 14:55:21 +00:00
|
|
|
int maxTouchX = screen_bounds.w - bounds.w * 0.5;
|
2013-12-02 14:15:19 +00:00
|
|
|
|
|
|
|
int minTouchY = bounds.h * 0.5;
|
2014-02-10 14:55:21 +00:00
|
|
|
int maxTouchY = screen_bounds.h - bounds.h * 0.5;
|
2013-12-02 14:15:19 +00:00
|
|
|
|
|
|
|
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 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) {
|
|
|
|
newY = touch.y;
|
|
|
|
}
|
|
|
|
pickedControl_->ReplaceLayoutParams(new UI::AnchorLayoutParams(newX, newY, NONE, NONE, true));
|
|
|
|
} else if (mode == 1) {
|
|
|
|
// Resize. Vertical = scaling, horizontal = spacing;
|
|
|
|
// Up should be bigger so let's negate in that direction
|
|
|
|
float diffX = (touch.x - startX_);
|
|
|
|
float diffY = -(touch.y - startY_);
|
|
|
|
|
|
|
|
float movementScale = 0.02f;
|
|
|
|
float newScale = startScale_ + diffY * movementScale;
|
|
|
|
float newSpacing = startSpacing_ + diffX * movementScale;
|
|
|
|
if (newScale > 3.0f) newScale = 3.0f;
|
|
|
|
if (newScale < 0.5f) newScale = 0.5f;
|
|
|
|
if (newSpacing > 3.0f) newSpacing = 3.0f;
|
|
|
|
if (newSpacing < 0.5f) newSpacing = 0.5f;
|
|
|
|
pickedControl_->SetSpacing(newSpacing);
|
|
|
|
pickedControl_->SetScale(newScale);
|
2013-10-09 20:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
2013-10-19 22:34:48 +00:00
|
|
|
if ((touch.flags & TOUCH_DOWN) && pickedControl_ == 0) {
|
2013-10-09 20:15:56 +00:00
|
|
|
pickedControl_ = getPickedControl(touch.x, touch.y);
|
2013-12-02 14:15:19 +00:00
|
|
|
if (pickedControl_) {
|
|
|
|
startX_ = touch.x;
|
|
|
|
startY_ = touch.y;
|
|
|
|
startSpacing_ = pickedControl_->GetSpacing();
|
|
|
|
startScale_ = pickedControl_->GetScale();
|
|
|
|
}
|
2013-10-09 20:15:56 +00:00
|
|
|
}
|
2013-10-19 22:34:48 +00:00
|
|
|
if ((touch.flags & TOUCH_UP) && pickedControl_ != 0) {
|
2013-10-09 20:15:56 +00:00
|
|
|
pickedControl_->SavePosition();
|
|
|
|
pickedControl_ = 0;
|
2013-10-19 22:34:48 +00:00
|
|
|
}
|
2014-06-15 11:04:59 +00:00
|
|
|
return true;
|
2013-10-09 20:15:56 +00:00
|
|
|
};
|
|
|
|
|
2013-10-25 11:19:08 +00:00
|
|
|
void TouchControlLayoutScreen::onFinish(DialogResult reason) {
|
|
|
|
g_Config.Save();
|
|
|
|
}
|
|
|
|
|
2013-10-20 15:33:18 +00:00
|
|
|
UI::EventReturn TouchControlLayoutScreen::OnVisibility(UI::EventParams &e) {
|
|
|
|
screenManager()->push(new TouchControlVisibilityScreen());
|
|
|
|
return UI::EVENT_DONE;
|
|
|
|
}
|
|
|
|
|
2013-10-19 22:34:48 +00:00
|
|
|
UI::EventReturn TouchControlLayoutScreen::OnReset(UI::EventParams &e) {
|
2013-12-02 14:15:19 +00:00
|
|
|
ILOG("Resetting touch control layout");
|
2013-12-12 13:52:46 +00:00
|
|
|
g_Config.ResetControlLayout();
|
2014-02-10 14:55:21 +00:00
|
|
|
const Bounds &bounds = screenManager()->getUIContext()->GetBounds();
|
|
|
|
InitPadLayout(bounds.w, bounds.h);
|
2013-10-19 22:34:48 +00:00
|
|
|
RecreateViews();
|
|
|
|
return UI::EVENT_DONE;
|
|
|
|
};
|
2013-10-09 20:15:56 +00:00
|
|
|
|
2013-10-20 15:33:18 +00:00
|
|
|
void TouchControlLayoutScreen::dialogFinished(const Screen *dialog, DialogResult result) {
|
|
|
|
RecreateViews();
|
|
|
|
}
|
|
|
|
|
2013-10-19 22:34:48 +00:00
|
|
|
void TouchControlLayoutScreen::CreateViews() {
|
|
|
|
// setup g_Config for button layout
|
2014-02-10 14:55:21 +00:00
|
|
|
const Bounds &bounds = screenManager()->getUIContext()->GetBounds();
|
|
|
|
InitPadLayout(bounds.w, bounds.h);
|
|
|
|
|
|
|
|
local_dp_xres = bounds.w;
|
|
|
|
local_dp_yres = bounds.h;
|
2013-10-09 20:15:56 +00:00
|
|
|
|
|
|
|
using namespace UI;
|
|
|
|
|
2015-07-01 20:31:04 +00:00
|
|
|
I18NCategory *co = GetI18NCategory("Controls");
|
2015-07-01 21:26:55 +00:00
|
|
|
I18NCategory *di = GetI18NCategory("Dialog");
|
2013-10-09 20:15:56 +00:00
|
|
|
|
|
|
|
root_ = new AnchorLayout(new LayoutParams(FILL_PARENT, FILL_PARENT));
|
|
|
|
|
2015-07-01 21:26:55 +00:00
|
|
|
Choice *reset = new Choice(di->T("Reset"), "", false, new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 84));
|
|
|
|
Choice *back = new Choice(di->T("Back"), "", false, new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 10));
|
2015-07-01 20:31:04 +00:00
|
|
|
Choice *visibility = new Choice(co->T("Visibility"), "", false, new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 158));
|
|
|
|
// controlsSettings->Add(new PopupSliderChoiceFloat(&g_Config.fButtonScale, 0.80, 2.0, co->T("Button Scaling"), screenManager()))
|
2013-12-02 14:15:19 +00:00
|
|
|
// ->OnChange.Handle(this, &GameSettingsScreen::OnChangeControlScaling);
|
|
|
|
|
|
|
|
mode_ = new ChoiceStrip(ORIENT_VERTICAL, new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 158 + 64 + 10));
|
2015-07-01 21:26:55 +00:00
|
|
|
mode_->AddChoice(di->T("Move"));
|
|
|
|
mode_->AddChoice(di->T("Resize"));
|
2013-12-02 14:15:19 +00:00
|
|
|
mode_->SetSelection(0);
|
|
|
|
|
2013-10-19 22:34:48 +00:00
|
|
|
reset->OnClick.Handle(this, &TouchControlLayoutScreen::OnReset);
|
2013-10-28 15:04:53 +00:00
|
|
|
back->OnClick.Handle<UIScreen>(this, &UIScreen::OnBack);
|
2013-10-20 15:33:18 +00:00
|
|
|
visibility->OnClick.Handle(this, &TouchControlLayoutScreen::OnVisibility);
|
2013-12-02 14:15:19 +00:00
|
|
|
root_->Add(mode_);
|
2013-10-20 15:33:18 +00:00
|
|
|
root_->Add(visibility);
|
2013-10-19 22:34:48 +00:00
|
|
|
root_->Add(reset);
|
2013-10-09 20:15:56 +00:00
|
|
|
root_->Add(back);
|
|
|
|
|
2013-12-02 14:15:19 +00:00
|
|
|
TabHolder *tabHolder = new TabHolder(ORIENT_VERTICAL, leftColumnWidth, new AnchorLayoutParams(10, 0, 10, 0, false));
|
2013-10-09 20:15:56 +00:00
|
|
|
root_->Add(tabHolder);
|
|
|
|
|
2013-10-28 15:04:53 +00:00
|
|
|
// this is more for show than anything else. It's used to provide a boundary
|
|
|
|
// so that buttons like back can be placed within the boundary.
|
|
|
|
// serves no other purpose.
|
2013-10-09 20:15:56 +00:00
|
|
|
AnchorLayout *controlsHolder = new AnchorLayout(new LayoutParams(FILL_PARENT, FILL_PARENT));
|
|
|
|
|
2013-10-20 10:06:01 +00:00
|
|
|
I18NCategory *ms = GetI18NCategory("MainSettings");
|
|
|
|
|
|
|
|
tabHolder->AddTab(ms->T("Controls"), controlsHolder);
|
|
|
|
|
2013-12-02 14:15:19 +00:00
|
|
|
if (!g_Config.bShowTouchControls) {
|
|
|
|
// Shouldn't even be able to get here as the way into this dialog should be closed.
|
2013-10-20 10:06:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-19 22:34:48 +00:00
|
|
|
controls_.clear();
|
2013-10-09 20:15:56 +00:00
|
|
|
|
2013-12-02 14:15:19 +00:00
|
|
|
PSPActionButtons *actionButtons = new PSPActionButtons(g_Config.fActionButtonCenterX, g_Config.fActionButtonCenterY, g_Config.fActionButtonScale, g_Config.fActionButtonSpacing);
|
2013-10-20 10:06:01 +00:00
|
|
|
actionButtons->setCircleVisibility(g_Config.bShowTouchCircle);
|
|
|
|
actionButtons->setCrossVisibility(g_Config.bShowTouchCross);
|
|
|
|
actionButtons->setTriangleVisibility(g_Config.bShowTouchTriangle);
|
|
|
|
actionButtons->setSquareVisibility(g_Config.bShowTouchSquare);
|
|
|
|
|
|
|
|
controls_.push_back(actionButtons);
|
2013-10-20 15:33:18 +00:00
|
|
|
|
2013-12-10 22:19:37 +00:00
|
|
|
int rectImage = g_Config.iTouchButtonStyle ? I_RECT_LINE : I_RECT;
|
|
|
|
int shoulderImage = g_Config.iTouchButtonStyle ? I_SHOULDER_LINE : I_SHOULDER;
|
|
|
|
int dirImage = g_Config.iTouchButtonStyle ? I_DIR_LINE : I_DIR;
|
|
|
|
int stickImage = g_Config.iTouchButtonStyle ? I_STICK_LINE : I_STICK;
|
|
|
|
int stickBg = g_Config.iTouchButtonStyle ? I_STICK_BG_LINE : I_STICK_BG;
|
|
|
|
|
2013-10-30 14:12:16 +00:00
|
|
|
if (g_Config.bShowTouchDpad) {
|
2013-12-02 14:15:19 +00:00
|
|
|
controls_.push_back(new PSPDPadButtons(g_Config.fDpadX, g_Config.fDpadY, g_Config.fDpadScale, g_Config.fDpadSpacing));
|
2013-10-20 10:06:01 +00:00
|
|
|
}
|
|
|
|
|
2013-10-20 15:33:18 +00:00
|
|
|
if (g_Config.bShowTouchSelect) {
|
2013-12-10 22:19:37 +00:00
|
|
|
controls_.push_back(new DragDropButton(g_Config.fSelectKeyX, g_Config.fSelectKeyY, rectImage, I_SELECT, g_Config.fSelectKeyScale));
|
2013-10-20 15:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (g_Config.bShowTouchStart) {
|
2013-12-10 22:19:37 +00:00
|
|
|
controls_.push_back(new DragDropButton(g_Config.fStartKeyX, g_Config.fStartKeyY, rectImage, I_START, g_Config.fStartKeyScale));
|
2013-10-20 15:33:18 +00:00
|
|
|
}
|
|
|
|
|
2013-10-20 10:06:01 +00:00
|
|
|
if (g_Config.bShowTouchUnthrottle) {
|
2013-12-10 22:19:37 +00:00
|
|
|
DragDropButton *unthrottle = new DragDropButton(g_Config.fUnthrottleKeyX, g_Config.fUnthrottleKeyY, rectImage, I_ARROW, g_Config.fUnthrottleKeyScale);
|
2013-10-20 10:06:01 +00:00
|
|
|
unthrottle->SetAngle(180.0f);
|
|
|
|
controls_.push_back(unthrottle);
|
|
|
|
}
|
|
|
|
|
2013-10-20 15:33:18 +00:00
|
|
|
if (g_Config.bShowTouchLTrigger) {
|
2013-12-10 22:19:37 +00:00
|
|
|
controls_.push_back(new DragDropButton(g_Config.fLKeyX, g_Config.fLKeyY, shoulderImage, I_L, g_Config.fLKeyScale));
|
2013-10-20 15:33:18 +00:00
|
|
|
}
|
|
|
|
|
2013-10-20 10:06:01 +00:00
|
|
|
if (g_Config.bShowTouchRTrigger) {
|
2013-12-10 22:19:37 +00:00
|
|
|
DragDropButton *rbutton = new DragDropButton(g_Config.fRKeyX, g_Config.fRKeyY, shoulderImage, I_R, g_Config.fRKeyScale);
|
2013-10-20 10:06:01 +00:00
|
|
|
rbutton->FlipImageH(true);
|
|
|
|
controls_.push_back(rbutton);
|
|
|
|
}
|
2013-10-09 20:15:56 +00:00
|
|
|
|
2013-10-20 03:14:51 +00:00
|
|
|
if (g_Config.bShowTouchAnalogStick) {
|
2013-12-10 22:19:37 +00:00
|
|
|
controls_.push_back(new DragDropButton(g_Config.fAnalogStickX, g_Config.fAnalogStickY, stickBg, stickImage, g_Config.fAnalogStickScale));
|
2013-10-09 20:15:56 +00:00
|
|
|
};
|
|
|
|
|
2013-10-19 22:34:48 +00:00
|
|
|
for (size_t i = 0; i < controls_.size(); i++) {
|
|
|
|
root_->Add(controls_[i]);
|
2013-10-09 20:15:56 +00:00
|
|
|
}
|
2013-10-20 15:33:18 +00:00
|
|
|
}
|
2013-10-09 20:15:56 +00:00
|
|
|
|
2013-10-19 22:34:48 +00:00
|
|
|
// 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) {
|
2013-10-09 20:15:56 +00:00
|
|
|
return pickedControl_;
|
|
|
|
}
|
|
|
|
|
2013-10-19 22:34:48 +00:00
|
|
|
for (size_t i = 0; i < controls_.size(); i++) {
|
|
|
|
DragDropButton *control = controls_[i];
|
2013-10-09 20:15:56 +00:00
|
|
|
const Bounds &bounds = control->GetBounds();
|
2013-10-31 12:34:34 +00:00
|
|
|
const float thresholdFactor = 1.5f;
|
2013-10-09 20:15:56 +00:00
|
|
|
|
|
|
|
Bounds tolerantBounds(bounds.x, bounds.y, bounds.w * thresholdFactor, bounds.h * thresholdFactor);
|
2013-10-19 22:34:48 +00:00
|
|
|
if (tolerantBounds.Contains(x, y)) {
|
2013-10-09 20:15:56 +00:00
|
|
|
return control;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|