mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-13 17:49:29 +01:00
Improve pop-up UI for integer slider screens. Add a text entry box and units.
# Conflicts: # UI/GameSettingsScreen.cpp
This commit is contained in:
1 parent
064a09bda4
commit
bf84fda058
4 files changed
+79
-29
No files matched your search
@@ -322,13 +322,13 @@ void PopupMultiChoice::Draw(UIContext &dc) {
|
||||
dc.DrawText(valueText_.c_str(), bounds_.x2() - paddingX, bounds_.centerY(), style.fgColor, ALIGN_RIGHT | ALIGN_VCENTER);
|
||||
}
|
||||
|
||||
PopupSliderChoice::PopupSliderChoice(int *value, int minValue, int maxValue, const std::string &text, ScreenManager *screenManager, LayoutParams *layoutParams)
|
||||
: Choice(text, "", false, layoutParams), value_(value), minValue_(minValue), maxValue_(maxValue), step_(1), screenManager_(screenManager) {
|
||||
PopupSliderChoice::PopupSliderChoice(int *value, int minValue, int maxValue, const std::string &text, ScreenManager *screenManager, const std::string &units, LayoutParams *layoutParams)
|
||||
: Choice(text, "", false, layoutParams), value_(value), minValue_(minValue), maxValue_(maxValue), step_(1), screenManager_(screenManager), units_(units) {
|
||||
OnClick.Handle(this, &PopupSliderChoice::HandleClick);
|
||||
}
|
||||
|
||||
PopupSliderChoice::PopupSliderChoice(int *value, int minValue, int maxValue, const std::string &text, int step, ScreenManager *screenManager, LayoutParams *layoutParams)
|
||||
: Choice(text, "", false, layoutParams), value_(value), minValue_(minValue), maxValue_(maxValue), step_(step), screenManager_(screenManager) {
|
||||
PopupSliderChoice::PopupSliderChoice(int *value, int minValue, int maxValue, const std::string &text, int step, ScreenManager *screenManager, const std::string &units, LayoutParams *layoutParams)
|
||||
: Choice(text, "", false, layoutParams), value_(value), minValue_(minValue), maxValue_(maxValue), step_(step), screenManager_(screenManager), units_(units) {
|
||||
OnClick.Handle(this, &PopupSliderChoice::HandleClick);
|
||||
}
|
||||
|
||||
@@ -345,7 +345,7 @@ PopupSliderChoiceFloat::PopupSliderChoiceFloat(float *value, float minValue, flo
|
||||
EventReturn PopupSliderChoice::HandleClick(EventParams &e) {
|
||||
restoreFocus_ = HasFocus();
|
||||
|
||||
SliderPopupScreen *popupScreen = new SliderPopupScreen(value_, minValue_, maxValue_, text_, step_);
|
||||
SliderPopupScreen *popupScreen = new SliderPopupScreen(value_, minValue_, maxValue_, text_, step_, units_);
|
||||
popupScreen->OnChange.Handle(this, &PopupSliderChoice::HandleChange);
|
||||
screenManager_->push(popupScreen);
|
||||
return EVENT_DONE;
|
||||
@@ -405,25 +405,69 @@ void PopupSliderChoiceFloat::Draw(UIContext &dc) {
|
||||
}
|
||||
|
||||
EventReturn SliderPopupScreen::OnDecrease(EventParams ¶ms) {
|
||||
if (sliderValue_ > minValue_ && sliderValue_ < maxValue_) {
|
||||
sliderValue_ = step_ * floor((sliderValue_ / step_) + 0.5f);
|
||||
}
|
||||
sliderValue_ -= step_;
|
||||
slider_->Clamp();
|
||||
changing_ = true;
|
||||
char temp[64];
|
||||
sprintf(temp, "%d", sliderValue_);
|
||||
edit_->SetText(temp);
|
||||
changing_ = false;
|
||||
return EVENT_DONE;
|
||||
}
|
||||
|
||||
EventReturn SliderPopupScreen::OnIncrease(EventParams ¶ms) {
|
||||
if (sliderValue_ > minValue_ && sliderValue_ < maxValue_) {
|
||||
sliderValue_ = step_ * floor((sliderValue_ / step_) + 0.5f);
|
||||
}
|
||||
sliderValue_ += step_;
|
||||
slider_->Clamp();
|
||||
changing_ = true;
|
||||
char temp[64];
|
||||
sprintf(temp, "%d", sliderValue_);
|
||||
edit_->SetText(temp);
|
||||
changing_ = false;
|
||||
return EVENT_DONE;
|
||||
}
|
||||
|
||||
EventReturn SliderPopupScreen::OnSliderChange(EventParams ¶ms) {
|
||||
changing_ = true;
|
||||
char temp[64];
|
||||
sprintf(temp, "%d", sliderValue_);
|
||||
edit_->SetText(temp);
|
||||
changing_ = false;
|
||||
return EVENT_DONE;
|
||||
}
|
||||
|
||||
EventReturn SliderPopupScreen::OnTextChange(EventParams ¶ms) {
|
||||
if (!changing_) {
|
||||
sliderValue_ = atoi(edit_->GetText().c_str());
|
||||
slider_->Clamp();
|
||||
}
|
||||
return EVENT_DONE;
|
||||
}
|
||||
|
||||
void SliderPopupScreen::CreatePopupContents(UI::ViewGroup *parent) {
|
||||
using namespace UI;
|
||||
sliderValue_ = *value_;
|
||||
LinearLayout *lin = parent->Add(new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(UI::Margins(10, 5))));
|
||||
slider_ = new Slider(&sliderValue_, minValue_, maxValue_, step_, new LinearLayoutParams(1.0f));
|
||||
lin->Add(slider_);
|
||||
LinearLayout *vert = parent->Add(new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(UI::Margins(10, 10))));
|
||||
slider_ = new Slider(&sliderValue_, minValue_, maxValue_, new LinearLayoutParams(UI::Margins(10, 10)));
|
||||
slider_->OnClick.Handle(this, &SliderPopupScreen::OnSliderChange);
|
||||
vert->Add(slider_);
|
||||
LinearLayout *lin = vert->Add(new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(UI::Margins(10, 10))));
|
||||
lin->Add(new Button(" - "))->OnClick.Handle(this, &SliderPopupScreen::OnDecrease);
|
||||
lin->Add(new Button(" + "))->OnClick.Handle(this, &SliderPopupScreen::OnIncrease);
|
||||
char temp[64];
|
||||
sprintf(temp, "%d", sliderValue_);
|
||||
edit_ = new TextEdit(temp, "", new LinearLayoutParams(10.0f));
|
||||
edit_->SetMaxLen(16);
|
||||
edit_->OnTextChange.Handle(this, &SliderPopupScreen::OnTextChange);
|
||||
changing_ = false;
|
||||
lin->Add(edit_);
|
||||
if (&units_)
|
||||
lin->Add(new TextView(units_, new LinearLayoutParams(10.0f)));
|
||||
|
||||
UI::SetFocusedView(slider_);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user