mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Add feature to auto-hide buttons after X seconds.
This commit is contained in:
parent
39d1dd3a01
commit
a3f9b954d1
5 changed files with 70 additions and 25 deletions
|
@ -567,6 +567,7 @@ static ConfigSetting controlSettings[] = {
|
|||
ConfigSetting("GamepadOnlyFocused", &g_Config.bGamepadOnlyFocused, false, true, true),
|
||||
ConfigSetting("TouchButtonStyle", &g_Config.iTouchButtonStyle, 1, true, true),
|
||||
ConfigSetting("TouchButtonOpacity", &g_Config.iTouchButtonOpacity, 65, true, true),
|
||||
ConfigSetting("TouchButtonHideSeconds", &g_Config.iTouchButtonHideSeconds, 0, true, true),
|
||||
ConfigSetting("AutoCenterTouchAnalog", &g_Config.bAutoCenterTouchAnalog, false, true, true),
|
||||
|
||||
// -1.0f means uninitialized, set in GamepadEmu::CreatePadLayout().
|
||||
|
|
|
@ -242,8 +242,8 @@ public:
|
|||
bool bGamepadOnlyFocused;
|
||||
// Control Style
|
||||
int iTouchButtonStyle;
|
||||
// Control Positions
|
||||
int iTouchButtonOpacity;
|
||||
int iTouchButtonHideSeconds;
|
||||
// Floating analog stick (recenters on thumb on press).
|
||||
bool bAutoCenterTouchAnalog;
|
||||
|
||||
|
|
|
@ -427,8 +427,10 @@ void GameSettingsScreen::CreateViews() {
|
|||
|
||||
CheckBox *disableDiags = controlsSettings->Add(new CheckBox(&g_Config.bDisableDpadDiagonals, co->T("Disable D-Pad diagonals (4-way touch)")));
|
||||
disableDiags->SetEnabledPtr(&g_Config.bShowTouchControls);
|
||||
View *opacity = controlsSettings->Add(new PopupSliderChoice(&g_Config.iTouchButtonOpacity, 0, 100, co->T("Button Opacity"), screenManager(),"%"));
|
||||
View *opacity = controlsSettings->Add(new PopupSliderChoice(&g_Config.iTouchButtonOpacity, 0, 100, co->T("Button Opacity"), screenManager(), "%"));
|
||||
opacity->SetEnabledPtr(&g_Config.bShowTouchControls);
|
||||
PopupSliderChoice *autoHide = controlsSettings->Add(new PopupSliderChoice(&g_Config.iTouchButtonHideSeconds, 0, 300, co->T("Auto-hide buttons after (0 = off)"), screenManager(), "seconds"));
|
||||
autoHide->SetEnabledPtr(&g_Config.bShowTouchControls);
|
||||
static const char *touchControlStyles[] = {"Classic", "Thin borders"};
|
||||
View *style = controlsSettings->Add(new PopupMultiChoice(&g_Config.iTouchButtonStyle, co->T("Button style"), touchControlStyles, 0, ARRAY_SIZE(touchControlStyles), co->GetName(), screenManager()));
|
||||
style->SetEnabledPtr(&g_Config.bShowTouchControls);
|
||||
|
|
|
@ -33,6 +33,34 @@ static u32 GetButtonColor() {
|
|||
return g_Config.iTouchButtonStyle == 1 ? 0xFFFFFF : 0xc0b080;
|
||||
}
|
||||
|
||||
int GamepadView::framesWithoutTouch_;
|
||||
|
||||
void GamepadView::Touch(const TouchInput &input) {
|
||||
framesWithoutTouch_ = 0;
|
||||
}
|
||||
|
||||
void GamepadView::Update(const InputState &input) {
|
||||
++framesWithoutTouch_;
|
||||
}
|
||||
|
||||
float GamepadView::GetButtonOpacity() {
|
||||
int fadeAfterFrames = g_Config.iTouchButtonHideSeconds * 60;
|
||||
int fadeTransitionFrames = std::min(fadeAfterFrames, 5 * 60);
|
||||
float opacity = g_Config.iTouchButtonOpacity / 100.0f;
|
||||
|
||||
float multiplier = 1.0f;
|
||||
if (framesWithoutTouch_ > fadeAfterFrames && fadeAfterFrames != 0) {
|
||||
if (framesWithoutTouch_ > fadeAfterFrames + fadeTransitionFrames) {
|
||||
multiplier = 0.0f;
|
||||
} else {
|
||||
int framesIntoFade = framesWithoutTouch_ - fadeAfterFrames;
|
||||
multiplier = 1.0f - (framesIntoFade / (float)fadeTransitionFrames);
|
||||
}
|
||||
}
|
||||
|
||||
return opacity * multiplier;
|
||||
}
|
||||
|
||||
void MultiTouchButton::GetContentDimensions(const UIContext &dc, float &w, float &h) const {
|
||||
const AtlasImage &image = dc.Draw()->GetAtlas()->images[bgImg_];
|
||||
w = image.w * scale_;
|
||||
|
@ -40,6 +68,7 @@ void MultiTouchButton::GetContentDimensions(const UIContext &dc, float &w, float
|
|||
}
|
||||
|
||||
void MultiTouchButton::Touch(const TouchInput &input) {
|
||||
GamepadView::Touch(input);
|
||||
if ((input.flags & TOUCH_DOWN) && bounds_.Contains(input.x, input.y)) {
|
||||
pointerDownMask_ |= 1 << input.id;
|
||||
}
|
||||
|
@ -58,7 +87,7 @@ void MultiTouchButton::Touch(const TouchInput &input) {
|
|||
}
|
||||
|
||||
void MultiTouchButton::Draw(UIContext &dc) {
|
||||
float opacity = g_Config.iTouchButtonOpacity / 100.0f;
|
||||
float opacity = GetButtonOpacity();
|
||||
|
||||
float scale = scale_;
|
||||
if (IsDown()) {
|
||||
|
@ -132,7 +161,7 @@ bool PSPButton::IsDown() {
|
|||
}
|
||||
|
||||
PSPDpad::PSPDpad(int arrowIndex, int overlayIndex, float scale, float spacing, UI::LayoutParams *layoutParams)
|
||||
: UI::View(layoutParams), arrowIndex_(arrowIndex), overlayIndex_(overlayIndex),
|
||||
: GamepadView(layoutParams), arrowIndex_(arrowIndex), overlayIndex_(overlayIndex),
|
||||
scale_(scale), spacing_(spacing), dragPointerId_(-1), down_(0) {
|
||||
}
|
||||
|
||||
|
@ -143,6 +172,7 @@ void PSPDpad::GetContentDimensions(const UIContext &dc, float &w, float &h) cons
|
|||
|
||||
void PSPDpad::Touch(const TouchInput &input) {
|
||||
int lastDown = down_;
|
||||
GamepadView::Touch(input);
|
||||
|
||||
if (input.flags & TOUCH_DOWN) {
|
||||
if (dragPointerId_ == -1 && bounds_.Contains(input.x, input.y)) {
|
||||
|
@ -222,7 +252,7 @@ void PSPDpad::ProcessTouch(float x, float y, bool down) {
|
|||
}
|
||||
|
||||
void PSPDpad::Draw(UIContext &dc) {
|
||||
float opacity = g_Config.iTouchButtonOpacity / 100.0f;
|
||||
float opacity = GetButtonOpacity();
|
||||
|
||||
uint32_t colorBg = colorAlpha(GetButtonColor(), opacity);
|
||||
uint32_t color = colorAlpha(0xFFFFFF, opacity);
|
||||
|
@ -246,7 +276,7 @@ void PSPDpad::Draw(UIContext &dc) {
|
|||
}
|
||||
|
||||
PSPStick::PSPStick(int bgImg, int stickImg, int stick, float scale, UI::LayoutParams *layoutParams)
|
||||
: UI::View(layoutParams), dragPointerId_(-1), bgImg_(bgImg), stickImageIndex_(stickImg), stick_(stick), scale_(scale), centerX_(-1), centerY_(-1) {
|
||||
: GamepadView(layoutParams), dragPointerId_(-1), bgImg_(bgImg), stickImageIndex_(stickImg), stick_(stick), scale_(scale), centerX_(-1), centerY_(-1) {
|
||||
stick_size_ = 50;
|
||||
}
|
||||
|
||||
|
@ -257,7 +287,7 @@ void PSPStick::GetContentDimensions(const UIContext &dc, float &w, float &h) con
|
|||
}
|
||||
|
||||
void PSPStick::Draw(UIContext &dc) {
|
||||
float opacity = g_Config.iTouchButtonOpacity / 100.0f;
|
||||
float opacity = GetButtonOpacity();
|
||||
|
||||
uint32_t colorBg = colorAlpha(GetButtonColor(), opacity);
|
||||
uint32_t color = colorAlpha(0x808080, opacity);
|
||||
|
@ -278,6 +308,7 @@ void PSPStick::Draw(UIContext &dc) {
|
|||
}
|
||||
|
||||
void PSPStick::Touch(const TouchInput &input) {
|
||||
GamepadView::Touch(input);
|
||||
if (input.flags & TOUCH_RELEASE_ALL) {
|
||||
dragPointerId_ = -1;
|
||||
centerX_ = bounds_.centerX();
|
||||
|
|
|
@ -23,17 +23,32 @@
|
|||
#include "ui/view.h"
|
||||
#include "ui/viewgroup.h"
|
||||
|
||||
class MultiTouchButton : public UI::View {
|
||||
class GamepadView : public UI::View {
|
||||
public:
|
||||
MultiTouchButton(int bgImg, int img, float scale, UI::LayoutParams *layoutParams)
|
||||
: UI::View(layoutParams), pointerDownMask_(0), scale_(scale), bgImg_(bgImg), img_(img), angle_(0.0f), flipImageH_(false) {
|
||||
GamepadView(UI::LayoutParams *layoutParams) : UI::View(layoutParams) {
|
||||
}
|
||||
|
||||
virtual bool Key(const KeyInput &input) override { return false; }
|
||||
virtual void Update(const InputState &input) override {}
|
||||
virtual void Touch(const TouchInput &input) override;
|
||||
virtual void Draw(UIContext &dc) override;
|
||||
virtual void GetContentDimensions(const UIContext &dc, float &w, float &h) const override;
|
||||
void Touch(const TouchInput &input) override;
|
||||
bool Key(const KeyInput &input) override {
|
||||
return false;
|
||||
}
|
||||
void Update(const InputState &input) override;
|
||||
|
||||
protected:
|
||||
float GetButtonOpacity();
|
||||
|
||||
static int framesWithoutTouch_;
|
||||
};
|
||||
|
||||
class MultiTouchButton : public GamepadView {
|
||||
public:
|
||||
MultiTouchButton(int bgImg, int img, float scale, UI::LayoutParams *layoutParams)
|
||||
: GamepadView(layoutParams), pointerDownMask_(0), scale_(scale), bgImg_(bgImg), img_(img), angle_(0.0f), flipImageH_(false) {
|
||||
}
|
||||
|
||||
void Touch(const TouchInput &input) override;
|
||||
void Draw(UIContext &dc) override;
|
||||
void GetContentDimensions(const UIContext &dc, float &w, float &h) const override;
|
||||
virtual bool IsDown() { return pointerDownMask_ != 0; }
|
||||
// chainable
|
||||
MultiTouchButton *FlipImageH(bool flip) { flipImageH_ = flip; return this; }
|
||||
|
@ -56,8 +71,8 @@ public:
|
|||
: MultiTouchButton(bgImg, img, scale, layoutParams), value_(value) {
|
||||
|
||||
}
|
||||
virtual void Touch(const TouchInput &input) override;
|
||||
virtual bool IsDown() override { return *value_; }
|
||||
void Touch(const TouchInput &input) override;
|
||||
bool IsDown() override { return *value_; }
|
||||
|
||||
private:
|
||||
bool *value_;
|
||||
|
@ -69,18 +84,16 @@ public:
|
|||
: MultiTouchButton(bgImg, img, scale, layoutParams), pspButtonBit_(pspButtonBit) {
|
||||
}
|
||||
void Touch(const TouchInput &input) override;
|
||||
virtual bool IsDown() override;
|
||||
bool IsDown() override;
|
||||
|
||||
private:
|
||||
int pspButtonBit_;
|
||||
};
|
||||
|
||||
class PSPDpad : public UI::View {
|
||||
class PSPDpad : public GamepadView {
|
||||
public:
|
||||
PSPDpad(int arrowIndex, int overlayIndex, float scale, float spacing, UI::LayoutParams *layoutParams);
|
||||
|
||||
bool Key(const KeyInput &input) override { return false; }
|
||||
void Update(const InputState &input) override {}
|
||||
void Touch(const TouchInput &input) override;
|
||||
void Draw(UIContext &dc) override;
|
||||
void GetContentDimensions(const UIContext &dc, float &w, float &h) const override;
|
||||
|
@ -97,12 +110,10 @@ private:
|
|||
int down_;
|
||||
};
|
||||
|
||||
class PSPStick : public UI::View {
|
||||
class PSPStick : public GamepadView {
|
||||
public:
|
||||
PSPStick(int bgImg, int stickImg, int stick, float scale, UI::LayoutParams *layoutParams);
|
||||
|
||||
bool Key(const KeyInput &input) override { return false; }
|
||||
void Update(const InputState &input) override {}
|
||||
void Touch(const TouchInput &input) override;
|
||||
void Draw(UIContext &dc) override;
|
||||
void GetContentDimensions(const UIContext &dc, float &w, float &h) const override;
|
||||
|
@ -136,7 +147,7 @@ public:
|
|||
ComboKey(int pspButtonBit, int bgImg, int img, float scale, UI::LayoutParams *layoutParams)
|
||||
: MultiTouchButton(bgImg, img, scale, layoutParams), pspButtonBit_(pspButtonBit) {
|
||||
}
|
||||
virtual void Touch(const TouchInput &input);
|
||||
void Touch(const TouchInput &input) override;
|
||||
private:
|
||||
int pspButtonBit_;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue