Add the ability for Sliders and their corresponding Screens to have the ability to move in steps greater than 1.

No float support, only the integer screens are affected.
This commit is contained in:
The Dax committed 2014-05-05 23:47:22 -04:00
1 parent 92dd4db72e
commit fbdf659723
4 files changed
+26 -10

No files matched your search

+9 -4
View File
@@ -271,13 +271,18 @@ PopupSliderChoice::PopupSliderChoice(int *value, int minValue, int maxValue, con
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) {
OnClick.Handle(this, &PopupSliderChoice::HandleClick);
}
PopupSliderChoiceFloat::PopupSliderChoiceFloat(float *value, float minValue, float maxValue, const std::string &text, ScreenManager *screenManager, LayoutParams *layoutParams)
: Choice(text, "", false, layoutParams), value_(value), minValue_(minValue), maxValue_(maxValue), screenManager_(screenManager) {
OnClick.Handle(this, &PopupSliderChoiceFloat::HandleClick);
}
EventReturn PopupSliderChoice::HandleClick(EventParams &e) {
SliderPopupScreen *popupScreen = new SliderPopupScreen(value_, minValue_, maxValue_, text_);
SliderPopupScreen *popupScreen = new SliderPopupScreen(value_, minValue_, maxValue_, text_, step_);
popupScreen->OnChange.Handle(this, &PopupSliderChoice::HandleChange);
screenManager_->push(popupScreen);
return EVENT_DONE;
@@ -327,13 +332,13 @@ void PopupSliderChoiceFloat::Draw(UIContext &dc) {
}
EventReturn SliderPopupScreen::OnDecrease(EventParams &params) {
sliderValue_--;
sliderValue_ -= step_;
slider_->Clamp();
return EVENT_DONE;
}
EventReturn SliderPopupScreen::OnIncrease(EventParams &params) {
sliderValue_++;
sliderValue_ += step_;
slider_->Clamp();
return EVENT_DONE;
}
@@ -342,7 +347,7 @@ 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_, new LinearLayoutParams(1.0f));
slider_ = new Slider(&sliderValue_, minValue_, maxValue_, step_, new LinearLayoutParams(1.0f));
lin->Add(slider_);
lin->Add(new Button(" - "))->OnClick.Handle(this, &SliderPopupScreen::OnDecrease);
lin->Add(new Button(" + "))->OnClick.Handle(this, &SliderPopupScreen::OnIncrease);
+7 -2
View File
@@ -114,7 +114,8 @@ namespace UI {
class SliderPopupScreen : public PopupScreen {
public:
SliderPopupScreen(int *value, int minValue, int maxValue, const std::string &title) : PopupScreen(title, "OK", "Cancel"), value_(value), minValue_(minValue), maxValue_(maxValue) {}
SliderPopupScreen(int *value, int minValue, int maxValue, const std::string &title, int step = 1)
: PopupScreen(title, "OK", "Cancel"), value_(value), minValue_(minValue), maxValue_(maxValue), step_(step) {}
void CreatePopupContents(ViewGroup *parent);
Event OnChange;
@@ -128,11 +129,13 @@ private:
int sliderValue_;
int minValue_;
int maxValue_;
float step_;
};
class SliderFloatPopupScreen : public PopupScreen {
public:
SliderFloatPopupScreen(float *value, float minValue, float maxValue, const std::string &title) : PopupScreen(title, "OK", "Cancel"), value_(value), minValue_(minValue), maxValue_(maxValue) {}
SliderFloatPopupScreen(float *value, float minValue, float maxValue, const std::string &title)
: PopupScreen(title, "OK", "Cancel"), value_(value), minValue_(minValue), maxValue_(maxValue) {}
void CreatePopupContents(UI::ViewGroup *parent);
Event OnChange;
@@ -182,6 +185,7 @@ private:
class PopupSliderChoice : public Choice {
public:
PopupSliderChoice(int *value, int minValue, int maxValue, const std::string &text, ScreenManager *screenManager, LayoutParams *layoutParams = 0);
PopupSliderChoice(int *value, int minValue, int maxValue, const std::string &text, int step, ScreenManager *screenManager, LayoutParams *layoutParams = 0);
void Draw(UIContext &dc);
@@ -194,6 +198,7 @@ private:
int *value_;
int minValue_;
int maxValue_;
float step_;
ScreenManager *screenManager_;
};
+7 -4
View File
@@ -622,18 +622,18 @@ void Slider::Key(const KeyInput &input) {
case NKCODE_DPAD_LEFT:
case NKCODE_MINUS:
case NKCODE_NUMPAD_SUBTRACT:
*value_ -= 1;
*value_ -= step_;
break;
case NKCODE_DPAD_RIGHT:
case NKCODE_PLUS:
case NKCODE_NUMPAD_ADD:
*value_ += 1;
*value_ += step_;
break;
case NKCODE_PAGE_UP:
*value_ -= 10;
*value_ -= step_ * 10;
break;
case NKCODE_PAGE_DOWN:
*value_ += 10;
*value_ += step_ * 10;
break;
case NKCODE_MOVE_HOME:
*value_ = minValue_;
@@ -658,6 +658,9 @@ void Slider::Touch(const TouchInput &input) {
void Slider::Clamp() {
if (*value_ < minValue_) *value_ = minValue_;
else if (*value_ > maxValue_) *value_ = maxValue_;
// Clamp the value to be a multiple of the nearest step (e.g. if step == 5, value == 293, it'll round down to 290).
*value_ = *value_ - fmodf(*value_, step_);
}
void Slider::Draw(UIContext &dc) {
+3
View File
@@ -439,6 +439,8 @@ class Slider : public Clickable {
public:
Slider(int *value, int minValue, int maxValue, LayoutParams *layoutParams = 0)
: Clickable(layoutParams), value_(value), showPercent_(false), minValue_(minValue), maxValue_(maxValue), paddingLeft_(5), paddingRight_(70) {}
Slider(int *value, int minValue, int maxValue, int step = 1, LayoutParams *layoutParams = 0)
: Clickable(layoutParams), value_(value), showPercent_(false), minValue_(minValue), maxValue_(maxValue), paddingLeft_(5), paddingRight_(70), step_(step) {}
virtual void Draw(UIContext &dc);
virtual void Key(const KeyInput &input);
virtual void Touch(const TouchInput &input);
@@ -454,6 +456,7 @@ private:
int maxValue_;
float paddingLeft_;
float paddingRight_;
float step_;
};
class SliderFloat : public Clickable {