Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2010-09-18 13:25:37 +0000
committerStijn Buys <ingar@osirion.org>2010-09-18 13:25:37 +0000
commitfc4809e41bc5694231046eb2fd4c324c4daba13f (patch)
tree02f183a0779aa0457e13f42037f3631ea28b7b65 /src/ui/scrollpane.cc
parent8c6a1a404ac8d1589a37d54b3b7ce0d776fe4751 (diff)
cosmetic updates in engine list functions, trade menu updates
Diffstat (limited to 'src/ui/scrollpane.cc')
-rw-r--r--src/ui/scrollpane.cc62
1 files changed, 47 insertions, 15 deletions
diff --git a/src/ui/scrollpane.cc b/src/ui/scrollpane.cc
index 38260e0..48391c5 100644
--- a/src/ui/scrollpane.cc
+++ b/src/ui/scrollpane.cc
@@ -18,6 +18,7 @@ ScrollPane::ScrollPane(Widget *parent, ui::Text &text) : Widget(parent), scrollp
set_label("scrollpane");
set_alignment(AlignBottom);
scrollpane_scroll = 0;
+ scrollpane_offset = 1;
}
ScrollPane::~ScrollPane()
@@ -29,7 +30,7 @@ void ScrollPane::set_alignment(const unsigned int alignment)
scrollpane_alignment = alignment;
}
-void ScrollPane::set_scroll(int scroll)
+void ScrollPane::set_scroll(const int scroll)
{
scrollpane_scroll = scroll;
@@ -39,22 +40,52 @@ void ScrollPane::set_scroll(int scroll)
scrollpane_scroll = 0;
}
-void ScrollPane::inc_scroll(int scroll)
+void ScrollPane::inc_scroll(const int scroll)
{
scrollpane_scroll += scroll;
if (scrollpane_scroll > (int) scrollpane_text.size())
scrollpane_scroll = (int) scrollpane_text.size();
+ else if (scrollpane_scroll < 0)
+ scrollpane_scroll = 0;
}
-void ScrollPane::dec_scroll(int scroll)
+void ScrollPane::dec_scroll(const int scroll)
{
scrollpane_scroll -= scroll;
- if (scrollpane_scroll < 0)
+ if (scrollpane_scroll > (int) scrollpane_text.size())
+ scrollpane_scroll = (int) scrollpane_text.size();
+ else if (scrollpane_scroll < 0)
scrollpane_scroll = 0;
}
+void ScrollPane::set_offset(const int offset)
+{
+ scrollpane_offset = offset;
+}
+
+bool ScrollPane::on_keypress(const int key, const unsigned int modifier)
+{
+ // number of lines to scroll
+ int alignmentmodifier =( (alignment() & AlignTop) == AlignTop) ? -1 : 1;
+
+ switch (key) {
+
+ case 512 + SDL_BUTTON_WHEELUP:
+ inc_scroll(alignmentmodifier * scrollpane_offset);
+ return true;
+ break;
+
+ case 512 + SDL_BUTTON_WHEELDOWN:
+ dec_scroll(alignmentmodifier * scrollpane_offset);
+ return true;
+ break;
+ }
+
+ return false;
+}
+
void ScrollPane::draw()
{
render::Text::setfont(font()->name().c_str(), font()->width(), font()->height());
@@ -69,12 +100,17 @@ void ScrollPane::draw()
scrollpane_scroll = (int) scrollpane_text.size();
else if (scrollpane_scroll < 0)
scrollpane_scroll = 0;
-
- int bottom = (int) scrollpane_text.size() - scrollpane_scroll;
+
+ int bottom = 0;
int current_line = 0;
-
+
+ if ((alignment() & AlignTop) == AlignTop) {
+ bottom = text_height + (int) scrollpane_scroll;
+ } else {
+ bottom = (int) scrollpane_text.size() - scrollpane_scroll;
+ }
+
ui::Text lines;
-
for (ui::Text::const_iterator it = scrollpane_text.begin(); it != scrollpane_text.end() && current_line < bottom; it++) {
if (current_line >= bottom - text_height) {
std::string linedata(*it);
@@ -169,13 +205,9 @@ void ScrollPane::draw()
float y = 0;
if ((alignment() & AlignTop) == AlignTop) {
- int i = (int) lines.size();
- for (ui::Text::iterator it = lines.begin(); it != lines.end(); it++) {
- if (i <= text_height) {
- render::Text::draw(gl.x(), gl.y() + y, (*it));
- y += font()->height();
- }
- i--;
+ for (ui::Text::iterator it = lines.begin(); (y + font()->height() < height()) && (it != lines.end()); it++) {
+ render::Text::draw(gl.x(), gl.y() + y, (*it));
+ y += font()->height();
}
} else {
y = height() - font()->height();