Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2010-09-20 17:10:30 +0000
committerStijn Buys <ingar@osirion.org>2010-09-20 17:10:30 +0000
commitd45baecf980dcabcbb528fcc220ec67d9bf3f2ed (patch)
tree2855cec05118967e15695c2a1458cee2e2beb926 /src/ui
parente40f70a3af1142e6c0c89c6ea2ee47b996495661 (diff)
display correct cargo size in game::Shipmodel info, ui::Slider scrollwheel support
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/slider.cc54
-rw-r--r--src/ui/slider.h4
2 files changed, 54 insertions, 4 deletions
diff --git a/src/ui/slider.cc b/src/ui/slider.cc
index 5de82b2..b5a38f1 100644
--- a/src/ui/slider.cc
+++ b/src/ui/slider.cc
@@ -16,9 +16,15 @@ Slider::Slider(Widget *parent, const float minimum, const float maximum) : Widge
slider_maximum = maximum;
slider_value = slider_minimum;
- slider_minbutton = new ui::Button(this, "<");
+ slider_minbutton = new ui::Button(this, "<<");
slider_minbutton->set_border(false);
+ slider_decbutton = new ui::Button(this, "<");
+ slider_decbutton->set_border(false);
+
+ slider_incbutton = new ui::Button(this, ">");
+ slider_incbutton->set_border(false);
+
slider_maxbutton = new ui::Button(this, ">>");
slider_maxbutton->set_border(false);
@@ -75,16 +81,50 @@ bool Slider::on_emit(Widget *sender, const Event event, void *data)
slider_value = slider_minimum;
emit(EventSliderChanged, this);
return true;
+ } else if (sender == slider_decbutton) {
+ if (slider_value > slider_minimum) {
+ slider_value--;
+ emit(EventSliderChanged, this);
+ }
+ return true;
+ } else if (sender == slider_incbutton) {
+ if (slider_value < slider_maximum) {
+ slider_value++;
+ emit(EventSliderChanged, this);
+ }
+ return true;
} else if (sender == slider_maxbutton) {
slider_value = slider_maximum;
emit(EventSliderChanged, this);
return true;
}
}
-
return false;
}
+bool Slider::on_keypress(const int key, const unsigned int modifier)
+{
+ switch (key) {
+
+ case 512 + SDL_BUTTON_WHEELUP:
+ if (slider_value < slider_maximum) {
+ slider_value++;
+ emit(EventSliderChanged, this);
+ }
+ return true;
+ break;
+
+ case 512 + SDL_BUTTON_WHEELDOWN:
+ if (slider_value > slider_minimum) {
+ slider_value--;
+ emit(EventSliderChanged, this);
+ }
+ return true;
+ break;
+ }
+
+ return false;
+}
void Slider::resize()
{
@@ -92,17 +132,23 @@ void Slider::resize()
slider_minbutton->set_size(height(), height());
slider_minbutton->set_location(0, 0);
+ slider_decbutton->set_size(height(), height());
+ slider_decbutton->set_location(slider_minbutton->right(), 0);
+
slider_maxbutton->set_size(height(), height());
slider_maxbutton->set_location(width() - slider_maxbutton->width(), 0);
+
+ slider_incbutton->set_size(height(), height());
+ slider_incbutton->set_location(slider_maxbutton->left() - slider_incbutton->width() , 0);
}
void Slider::draw()
{
if (slider_maximum > slider_minimum) {
const float range = (slider_value - slider_minimum) / (slider_maximum - slider_minimum);
- const float x = (width() - 3.0f * height()) * range;
+ const float x = (width() - 5.0f * height()) * range;
Paint::set_color(palette()->foreground());
- Paint::draw_rectangle(math::Vector2f(global_location().x() + height() + x, global_location().y()), math::Vector2f(height(), height()));
+ Paint::draw_rectangle(math::Vector2f(global_location().x() + 2.0f * height() + x + 1, global_location().y() +1 ), math::Vector2f(height() - 2, height() - 2));
}
Widget::draw();
diff --git a/src/ui/slider.h b/src/ui/slider.h
index 8bcb427..46dfd50 100644
--- a/src/ui/slider.h
+++ b/src/ui/slider.h
@@ -82,6 +82,8 @@ protected:
virtual void draw();
virtual bool on_emit(Widget *sender, const Event event, void *data=0);
+
+ virtual bool on_keypress(const int key, const unsigned int modifier);
private:
/// validate slider value
@@ -92,6 +94,8 @@ private:
float slider_value;
Button *slider_minbutton;
+ Button *slider_decbutton;
+ Button *slider_incbutton;
Button *slider_maxbutton;
};