2012-11-01 15:19:01 +00:00
|
|
|
// Copyright (c) 2012- 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
|
2012-11-04 22:01:49 +00:00
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
// 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/.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-10-01 07:36:43 +00:00
|
|
|
#include "Common/Input/InputState.h"
|
2020-10-04 21:24:14 +00:00
|
|
|
#include "Common/Render/DrawBuffer.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2020-10-04 18:48:47 +00:00
|
|
|
#include "Common/UI/View.h"
|
|
|
|
#include "Common/UI/ViewGroup.h"
|
2018-06-17 06:00:21 +00:00
|
|
|
#include "Core/CoreParameter.h"
|
2013-07-20 10:06:06 +00:00
|
|
|
|
2015-12-20 20:40:47 +00:00
|
|
|
class GamepadView : public UI::View {
|
|
|
|
public:
|
2021-02-22 00:38:02 +00:00
|
|
|
GamepadView(const char *key, UI::LayoutParams *layoutParams);
|
2015-12-20 20:40:47 +00:00
|
|
|
|
|
|
|
void Touch(const TouchInput &input) override;
|
|
|
|
bool Key(const KeyInput &input) override {
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-15 05:01:18 +00:00
|
|
|
void Update() override;
|
2021-02-22 00:38:02 +00:00
|
|
|
std::string DescribeText() const override;
|
2015-12-20 20:40:47 +00:00
|
|
|
|
|
|
|
protected:
|
2017-06-03 15:41:56 +00:00
|
|
|
virtual float GetButtonOpacity();
|
2015-12-20 20:40:47 +00:00
|
|
|
|
2021-02-22 00:38:02 +00:00
|
|
|
const char *key_;
|
2020-08-15 22:13:19 +00:00
|
|
|
double lastFrameTime_;
|
|
|
|
float secondsWithoutTouch_ = 0.0;
|
2015-12-20 20:40:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class MultiTouchButton : public GamepadView {
|
2013-07-20 10:06:06 +00:00
|
|
|
public:
|
2021-02-22 00:38:02 +00:00
|
|
|
MultiTouchButton(const char *key, ImageID bgImg, ImageID bgDownImg, ImageID img, float scale, UI::LayoutParams *layoutParams)
|
|
|
|
: GamepadView(key, layoutParams), scale_(scale), bgImg_(bgImg), bgDownImg_(bgDownImg), img_(img) {
|
2013-07-20 10:06:06 +00:00
|
|
|
}
|
|
|
|
|
2015-12-20 20:40:47 +00:00
|
|
|
void Touch(const TouchInput &input) override;
|
|
|
|
void Draw(UIContext &dc) override;
|
|
|
|
void GetContentDimensions(const UIContext &dc, float &w, float &h) const override;
|
2013-07-20 18:48:21 +00:00
|
|
|
virtual bool IsDown() { return pointerDownMask_ != 0; }
|
2013-07-20 12:05:07 +00:00
|
|
|
// chainable
|
|
|
|
MultiTouchButton *FlipImageH(bool flip) { flipImageH_ = flip; return this; }
|
2018-06-17 06:00:21 +00:00
|
|
|
MultiTouchButton *SetAngle(float angle) { angle_ = angle; bgAngle_ = angle; return this; }
|
|
|
|
MultiTouchButton *SetAngle(float angle, float bgAngle) { angle_ = angle; bgAngle_ = bgAngle; return this; }
|
2013-07-20 10:06:06 +00:00
|
|
|
|
|
|
|
protected:
|
2018-06-17 06:00:21 +00:00
|
|
|
uint32_t pointerDownMask_ = 0;
|
2013-10-09 20:15:56 +00:00
|
|
|
float scale_;
|
2013-07-20 10:06:06 +00:00
|
|
|
|
|
|
|
private:
|
2020-02-29 20:51:14 +00:00
|
|
|
ImageID bgImg_;
|
|
|
|
ImageID bgDownImg_;
|
|
|
|
ImageID img_;
|
2018-06-17 06:00:21 +00:00
|
|
|
float bgAngle_ = 0.0f;
|
|
|
|
float angle_ = 0.0f;
|
|
|
|
bool flipImageH_ = false;
|
2013-07-20 10:06:06 +00:00
|
|
|
};
|
|
|
|
|
2013-07-20 12:05:07 +00:00
|
|
|
class BoolButton : public MultiTouchButton {
|
|
|
|
public:
|
2021-02-22 00:38:02 +00:00
|
|
|
BoolButton(bool *value, const char *key, ImageID bgImg, ImageID bgDownImg, ImageID img, float scale, UI::LayoutParams *layoutParams)
|
|
|
|
: MultiTouchButton(key, bgImg, bgDownImg, img, scale, layoutParams), value_(value) {
|
2013-07-20 12:05:07 +00:00
|
|
|
|
|
|
|
}
|
2015-12-20 20:40:47 +00:00
|
|
|
void Touch(const TouchInput &input) override;
|
|
|
|
bool IsDown() override { return *value_; }
|
2013-07-20 12:05:07 +00:00
|
|
|
|
2018-06-23 18:06:56 +00:00
|
|
|
UI::Event OnChange;
|
|
|
|
|
2013-07-20 12:05:07 +00:00
|
|
|
private:
|
|
|
|
bool *value_;
|
|
|
|
};
|
|
|
|
|
2018-06-17 06:00:21 +00:00
|
|
|
class FPSLimitButton : public MultiTouchButton {
|
|
|
|
public:
|
2021-02-22 00:38:02 +00:00
|
|
|
FPSLimitButton(FPSLimit limit, const char *key, ImageID bgImg, ImageID bgDownImg, ImageID img, float scale, UI::LayoutParams *layoutParams)
|
|
|
|
: MultiTouchButton(key, bgImg, bgDownImg, img, scale, layoutParams), limit_(limit) {
|
2018-06-17 06:00:21 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
void Touch(const TouchInput &input) override;
|
|
|
|
bool IsDown() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
FPSLimit limit_;
|
|
|
|
};
|
|
|
|
|
2020-01-28 07:52:18 +00:00
|
|
|
class RapidFireButton : public MultiTouchButton {
|
|
|
|
public:
|
2021-02-22 00:38:02 +00:00
|
|
|
RapidFireButton(const char *key, ImageID bgImg, ImageID bgDownImg, ImageID img, float scale, UI::LayoutParams *layoutParams)
|
|
|
|
: MultiTouchButton(key, bgImg, bgDownImg, img, scale, layoutParams) {
|
2020-01-28 07:52:18 +00:00
|
|
|
}
|
|
|
|
void Touch(const TouchInput &input) override;
|
|
|
|
bool IsDown() override;
|
|
|
|
};
|
|
|
|
|
2020-03-22 23:45:22 +00:00
|
|
|
class AnalogRotationButton : public MultiTouchButton {
|
|
|
|
public:
|
2021-02-22 00:38:02 +00:00
|
|
|
AnalogRotationButton(bool clockWise, const char *key, ImageID bgImg, ImageID bgDownImg, ImageID img, float scale, UI::LayoutParams *layoutParams)
|
|
|
|
: MultiTouchButton(key, bgImg, bgDownImg, img, scale, layoutParams), clockWise_(clockWise) {
|
2020-03-22 23:45:22 +00:00
|
|
|
}
|
|
|
|
void Touch(const TouchInput &input) override;
|
|
|
|
void Update() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool autoRotating_ = false;
|
2020-03-23 08:24:36 +00:00
|
|
|
bool clockWise_;
|
2020-03-22 23:45:22 +00:00
|
|
|
};
|
|
|
|
|
2013-07-20 10:06:06 +00:00
|
|
|
class PSPButton : public MultiTouchButton {
|
|
|
|
public:
|
2021-02-22 00:38:02 +00:00
|
|
|
PSPButton(int pspButtonBit, const char *key, ImageID bgImg, ImageID bgDownImg, ImageID img, float scale, UI::LayoutParams *layoutParams)
|
|
|
|
: MultiTouchButton(key, bgImg, bgDownImg, img, scale, layoutParams), pspButtonBit_(pspButtonBit) {
|
2013-07-20 10:06:06 +00:00
|
|
|
}
|
2015-02-02 23:11:51 +00:00
|
|
|
void Touch(const TouchInput &input) override;
|
2015-12-20 20:40:47 +00:00
|
|
|
bool IsDown() override;
|
2013-07-20 10:06:06 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
int pspButtonBit_;
|
|
|
|
};
|
|
|
|
|
2015-12-20 20:40:47 +00:00
|
|
|
class PSPDpad : public GamepadView {
|
2013-07-20 10:06:06 +00:00
|
|
|
public:
|
2021-02-22 00:38:02 +00:00
|
|
|
PSPDpad(ImageID arrowIndex, const char *key, ImageID arrowDownIndex, ImageID overlayIndex, float scale, float spacing, UI::LayoutParams *layoutParams);
|
2013-07-20 10:06:06 +00:00
|
|
|
|
2015-02-02 23:11:51 +00:00
|
|
|
void Touch(const TouchInput &input) override;
|
|
|
|
void Draw(UIContext &dc) override;
|
|
|
|
void GetContentDimensions(const UIContext &dc, float &w, float &h) const override;
|
2013-07-20 10:06:06 +00:00
|
|
|
|
|
|
|
private:
|
2013-07-20 10:54:33 +00:00
|
|
|
void ProcessTouch(float x, float y, bool down);
|
2020-02-29 20:51:14 +00:00
|
|
|
ImageID arrowIndex_;
|
|
|
|
ImageID arrowDownIndex_;
|
|
|
|
ImageID overlayIndex_;
|
2013-07-20 10:54:33 +00:00
|
|
|
|
2013-07-20 18:48:21 +00:00
|
|
|
float scale_;
|
2013-12-02 14:15:19 +00:00
|
|
|
float spacing_;
|
2013-07-20 18:48:21 +00:00
|
|
|
|
2013-07-20 10:54:33 +00:00
|
|
|
int dragPointerId_;
|
2013-07-20 10:06:06 +00:00
|
|
|
int down_;
|
|
|
|
};
|
|
|
|
|
2015-12-20 20:40:47 +00:00
|
|
|
class PSPStick : public GamepadView {
|
2013-07-20 10:06:06 +00:00
|
|
|
public:
|
2021-02-22 00:38:02 +00:00
|
|
|
PSPStick(ImageID bgImg, const char *key, ImageID stickImg, ImageID stickDownImg, int stick, float scale, UI::LayoutParams *layoutParams);
|
2013-07-20 12:05:07 +00:00
|
|
|
|
2015-02-02 23:11:51 +00:00
|
|
|
void Touch(const TouchInput &input) override;
|
|
|
|
void Draw(UIContext &dc) override;
|
|
|
|
void GetContentDimensions(const UIContext &dc, float &w, float &h) const override;
|
2013-07-20 10:06:06 +00:00
|
|
|
|
2019-11-13 17:55:18 +00:00
|
|
|
protected:
|
2013-07-20 12:05:07 +00:00
|
|
|
int dragPointerId_;
|
2020-02-29 20:51:14 +00:00
|
|
|
ImageID bgImg_;
|
|
|
|
ImageID stickImageIndex_;
|
|
|
|
ImageID stickDownImg_;
|
|
|
|
|
2013-07-20 10:06:06 +00:00
|
|
|
int stick_;
|
2013-07-20 12:05:07 +00:00
|
|
|
float stick_size_;
|
2013-07-20 10:06:06 +00:00
|
|
|
float scale_;
|
2015-03-05 09:58:25 +00:00
|
|
|
|
|
|
|
float centerX_;
|
|
|
|
float centerY_;
|
2019-11-13 17:55:18 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void ProcessTouch(float x, float y, bool down);
|
|
|
|
};
|
|
|
|
|
|
|
|
class PSPCustomStick : public PSPStick {
|
|
|
|
public:
|
2021-02-22 00:38:02 +00:00
|
|
|
PSPCustomStick(ImageID bgImg, const char *key, ImageID stickImg, ImageID stickDownImg, float scale, UI::LayoutParams *layoutParams);
|
2019-11-13 17:55:18 +00:00
|
|
|
|
|
|
|
void Touch(const TouchInput &input) override;
|
|
|
|
void Draw(UIContext &dc) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void ProcessTouch(float x, float y, bool down);
|
|
|
|
|
2020-03-05 17:29:35 +00:00
|
|
|
float posX_ = 0.0f;
|
|
|
|
float posY_ = 0.0f;
|
2013-07-20 10:06:06 +00:00
|
|
|
};
|
|
|
|
|
2013-10-09 20:15:56 +00:00
|
|
|
//initializes the layout from Config. if a default layout does not exist,
|
|
|
|
//it sets up default values
|
2014-02-10 14:55:21 +00:00
|
|
|
void InitPadLayout(float xres, float yres, float globalScale = 1.15f);
|
|
|
|
UI::ViewGroup *CreatePadLayout(float xres, float yres, bool *pause);
|
2013-12-02 14:15:19 +00:00
|
|
|
|
|
|
|
const int D_pad_Radius = 50;
|
|
|
|
const int baseActionButtonSpacing = 60;
|
|
|
|
|
2015-06-28 05:34:05 +00:00
|
|
|
class ComboKey : public MultiTouchButton {
|
|
|
|
public:
|
2021-02-22 00:38:02 +00:00
|
|
|
ComboKey(int pspButtonBit, const char *key, bool toggle, ImageID bgImg, ImageID bgDownImg, ImageID img, float scale, UI::LayoutParams *layoutParams)
|
|
|
|
: MultiTouchButton(key, bgImg, bgDownImg, img, scale, layoutParams), pspButtonBit_(pspButtonBit), toggle_(toggle) {
|
2015-06-28 05:34:05 +00:00
|
|
|
}
|
2015-12-20 20:40:47 +00:00
|
|
|
void Touch(const TouchInput &input) override;
|
2015-06-28 05:34:05 +00:00
|
|
|
private:
|
|
|
|
int pspButtonBit_;
|
2020-02-12 14:48:49 +00:00
|
|
|
bool toggle_;
|
2015-06-28 05:34:05 +00:00
|
|
|
};
|