mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-16 19:13:40 +01:00
Merge pull request #16860 from unknownbrackets/ui-ctrl-press
UI: Highlight buttons on press in visual PSP map
This commit is contained in:
2 files changed
+90
-2
No files matched your search
@@ -970,6 +970,12 @@ public:
|
||||
if (img_.isValid()) {
|
||||
scales[0] *= scaleX_;
|
||||
scales[1] *= scaleY_;
|
||||
if (timeLastPressed_ >= 0.0) {
|
||||
double sincePress = time_now_d() - timeLastPressed_;
|
||||
if (sincePress < 1.0) {
|
||||
c = colorBlend(c, dc.theme->itemDownStyle.background.color, (float)sincePress);
|
||||
}
|
||||
}
|
||||
dc.Draw()->DrawImageRotatedStretch(img_, bounds_.Offset(offsetX_, offsetY_), scales, angle_, c);
|
||||
}
|
||||
}
|
||||
@@ -1010,6 +1016,10 @@ public:
|
||||
return button_;
|
||||
}
|
||||
|
||||
void NotifyPressed() {
|
||||
timeLastPressed_ = time_now_d();
|
||||
}
|
||||
|
||||
private:
|
||||
int button_;
|
||||
ImageID img_;
|
||||
@@ -1021,6 +1031,7 @@ private:
|
||||
float offsetY_ = 0.0f;
|
||||
bool flipHBG_ = false;
|
||||
int *selectedButton_ = nullptr;
|
||||
double timeLastPressed_ = -1.0;
|
||||
};
|
||||
|
||||
class MockPSP : public UI::AnchorLayout {
|
||||
@@ -1030,8 +1041,11 @@ public:
|
||||
MockPSP(UI::LayoutParams *layoutParams = nullptr);
|
||||
void SelectButton(int btn);
|
||||
void FocusButton(int btn);
|
||||
void NotifyPressed(int btn);
|
||||
float GetPopupOffset();
|
||||
|
||||
bool SubviewFocused(View *view) override;
|
||||
|
||||
UI::Event ButtonClick;
|
||||
|
||||
private:
|
||||
@@ -1042,6 +1056,7 @@ private:
|
||||
UI::EventReturn OnSelectButton(UI::EventParams &e);
|
||||
|
||||
std::unordered_map<int, MockButton *> buttons_;
|
||||
UI::TextView *labelView_ = nullptr;
|
||||
int selectedButton_ = 0;
|
||||
};
|
||||
|
||||
@@ -1070,6 +1085,10 @@ MockPSP::MockPSP(UI::LayoutParams *layoutParams) : AnchorLayout(layoutParams) {
|
||||
AddButton(CTRL_CIRCLE, ImageID("I_CIRCLE"), ImageID("I_ROUND_LINE"), 0.0f, LayoutSize(23.0f, 23.0f, 446.0f, 74.0f))->SetScale(0.7f);
|
||||
AddButton(CTRL_CROSS, ImageID("I_CROSS"), ImageID("I_ROUND_LINE"), 0.0f, LayoutSize(23.0f, 23.0f, 419.0f, 102.0f))->SetScale(0.7f);
|
||||
AddButton(CTRL_SQUARE, ImageID("I_SQUARE"), ImageID("I_ROUND_LINE"), 0.0f, LayoutSize(23.0f, 23.0f, 392.0f, 74.0f))->SetScale(0.7f);
|
||||
|
||||
labelView_ = Add(new UI::TextView(""));
|
||||
labelView_->SetShadow(true);
|
||||
labelView_->SetVisibility(UI::V_GONE);
|
||||
}
|
||||
|
||||
void MockPSP::SelectButton(int btn) {
|
||||
@@ -1077,9 +1096,31 @@ void MockPSP::SelectButton(int btn) {
|
||||
}
|
||||
|
||||
void MockPSP::FocusButton(int btn) {
|
||||
MockButton *view = buttons_[selectedButton_];
|
||||
if (view)
|
||||
MockButton *view = buttons_[btn];
|
||||
if (view) {
|
||||
view->SetFocus();
|
||||
} else {
|
||||
labelView_->SetVisibility(UI::V_GONE);
|
||||
}
|
||||
}
|
||||
|
||||
void MockPSP::NotifyPressed(int btn) {
|
||||
MockButton *view = buttons_[btn];
|
||||
if (view)
|
||||
view->NotifyPressed();
|
||||
}
|
||||
|
||||
bool MockPSP::SubviewFocused(View *view) {
|
||||
for (auto it : buttons_) {
|
||||
if (view == it.second) {
|
||||
labelView_->SetVisibility(UI::V_VISIBLE);
|
||||
labelView_->SetText(KeyMap::GetPspButtonName(it.first));
|
||||
|
||||
const Bounds &pos = view->GetBounds().Offset(-GetBounds().x, -GetBounds().y);
|
||||
labelView_->ReplaceLayoutParams(new UI::AnchorLayoutParams(pos.centerX(), pos.y2() + 5, UI::NONE, UI::NONE));
|
||||
}
|
||||
}
|
||||
return AnchorLayout::SubviewFocused(view);
|
||||
}
|
||||
|
||||
float MockPSP::GetPopupOffset() {
|
||||
@@ -1162,6 +1203,50 @@ void VisualMappingScreen::CreateViews() {
|
||||
root_->Add(rightColumn);
|
||||
}
|
||||
|
||||
bool VisualMappingScreen::key(const KeyInput &key) {
|
||||
if (key.flags & KEY_DOWN) {
|
||||
std::vector<int> pspKeys;
|
||||
KeyMap::KeyToPspButton(key.deviceId, key.keyCode, &pspKeys);
|
||||
for (int pspKey : pspKeys) {
|
||||
switch (pspKey) {
|
||||
case VIRTKEY_AXIS_X_MIN:
|
||||
case VIRTKEY_AXIS_Y_MIN:
|
||||
case VIRTKEY_AXIS_X_MAX:
|
||||
case VIRTKEY_AXIS_Y_MAX:
|
||||
psp_->NotifyPressed(VIRTKEY_AXIS_Y_MAX);
|
||||
break;
|
||||
default:
|
||||
psp_->NotifyPressed(pspKey);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return UIDialogScreenWithGameBackground::key(key);
|
||||
}
|
||||
|
||||
void VisualMappingScreen::axis(const AxisInput &axis) {
|
||||
std::vector<int> results;
|
||||
if (axis.value >= g_Config.fAnalogDeadzone * 0.7f)
|
||||
KeyMap::AxisToPspButton(axis.deviceId, axis.axisId, 1, &results);
|
||||
if (axis.value <= g_Config.fAnalogDeadzone * -0.7f)
|
||||
KeyMap::AxisToPspButton(axis.deviceId, axis.axisId, -1, &results);
|
||||
|
||||
for (int result : results) {
|
||||
switch (result) {
|
||||
case VIRTKEY_AXIS_X_MIN:
|
||||
case VIRTKEY_AXIS_Y_MIN:
|
||||
case VIRTKEY_AXIS_X_MAX:
|
||||
case VIRTKEY_AXIS_Y_MAX:
|
||||
psp_->NotifyPressed(VIRTKEY_AXIS_Y_MAX);
|
||||
break;
|
||||
default:
|
||||
psp_->NotifyPressed(result);
|
||||
break;
|
||||
}
|
||||
}
|
||||
UIDialogScreenWithGameBackground::axis(axis);
|
||||
}
|
||||
|
||||
void VisualMappingScreen::resized() {
|
||||
UIDialogScreenWithGameBackground::resized();
|
||||
RecreateViews();
|
||||
|
||||
@@ -177,6 +177,9 @@ public:
|
||||
|
||||
const char *tag() const override { return "VisualMapping"; }
|
||||
|
||||
bool key(const KeyInput &key) override;
|
||||
void axis(const AxisInput &axis) override;
|
||||
|
||||
protected:
|
||||
void CreateViews() override;
|
||||
|
||||
|
||||
Reference in new issue
Block a user