diff options
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/menuview.cc | 3 | ||||
-rw-r--r-- | src/ui/scrollpane.cc | 27 | ||||
-rw-r--r-- | src/ui/scrollpane.h | 17 |
3 files changed, 37 insertions, 10 deletions
diff --git a/src/ui/menuview.cc b/src/ui/menuview.cc index 71bdd1a..43757e1 100644 --- a/src/ui/menuview.cc +++ b/src/ui/menuview.cc @@ -40,8 +40,7 @@ void MenuView::generate(core::Entity *entity, const char *menulabel) if (!menulabel) return; - - con_debug << "generating menu " << entity->label() << " " << menulabel << std::endl; + //con_debug << "generating menu " << entity->label() << " " << menulabel << std::endl; remove_children(); menu_container = new Container(this); diff --git a/src/ui/scrollpane.cc b/src/ui/scrollpane.cc index 69bc159..a1de7d5 100644 --- a/src/ui/scrollpane.cc +++ b/src/ui/scrollpane.cc @@ -16,12 +16,18 @@ namespace ui ScrollPane::ScrollPane(Widget *parent, ui::Text &text) : Widget(parent), scrollpane_text(text) { set_label("scrollpane"); + set_alignment(AlignBottom); } ScrollPane::~ScrollPane() { } +void ScrollPane::set_alignment(const unsigned int alignment) +{ + scrollpane_alignment = alignment; +} + void ScrollPane::set_scroll(int scroll) { scrollpane_scroll = scroll; @@ -157,13 +163,24 @@ void ScrollPane::draw() render::gl::color(palette()->text()); const math ::Vector2f gl(global_location()); - float y = height() - font()->height(); + float y = 0; - for (ui::Text::reverse_iterator rit = lines.rbegin(); (y >= 0) && (rit != lines.rend()); ++rit) { - render::Text::draw(gl.x, gl.y + y, (*rit)); - y -= font()->height(); + 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--; + } + } else { + y = height() - font()->height(); + for (ui::Text::reverse_iterator rit = lines.rbegin(); (y >= 0) && (rit != lines.rend()); ++rit) { + render::Text::draw(gl.x, gl.y + y, (*rit)); + y -= font()->height(); + } } - render::gl::disable(GL_TEXTURE_2D); } diff --git a/src/ui/scrollpane.h b/src/ui/scrollpane.h index 47e68ee..f0ffac1 100644 --- a/src/ui/scrollpane.h +++ b/src/ui/scrollpane.h @@ -19,7 +19,20 @@ class ScrollPane : public Widget public: ScrollPane(Widget *parent, ui::Text &text); ~ScrollPane(); + + /* -- inspectors ------------------------------------------- */ + + /// current scroll position + inline int scroll() const { return scrollpane_scroll; } + + /// text alignment + inline unsigned int alignment() const { return scrollpane_alignment; } + /// set text alignment + void set_alignment(const unsigned int alignment); + + /* -- mutators --------------------------------------------- */ + /// set scroll void set_scroll(int scroll); @@ -29,9 +42,6 @@ public: /// decrease scroll void dec_scroll(int scroll); - /// current scroll position - inline int scroll() const { return scrollpane_scroll; } - protected: /// draw the scroll pane virtual void draw(); @@ -39,6 +49,7 @@ protected: private: ui::Text &scrollpane_text; int scrollpane_scroll; + unsigned int scrollpane_alignment; }; } |