From 0c509866a37ab47ff0e48d357ca55e31658c37c2 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Thu, 16 Sep 2010 14:12:27 +0000 Subject: map info support, initial trade window --- src/ui/Makefile.am | 6 +++-- src/ui/listview.cc | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ui/listview.h | 50 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 src/ui/listview.cc create mode 100644 src/ui/listview.h (limited to 'src/ui') diff --git a/src/ui/Makefile.am b/src/ui/Makefile.am index 561935c..98c8dab 100644 --- a/src/ui/Makefile.am +++ b/src/ui/Makefile.am @@ -8,11 +8,13 @@ noinst_LTLIBRARIES = libui.la endif noinst_HEADERS = bitmap.h button.h console.h container.h definitions.h font.h \ - iconbutton.h inputbox.h label.h menu.h modelview.h paint.h palette.h scrollpane.h toolbar.h ui.h widget.h \ + iconbutton.h inputbox.h label.h listview.h menu.h modelview.h paint.h \ + palette.h scrollpane.h toolbar.h ui.h widget.h \ window.h libui_la_SOURCES = bitmap.cc button.cc console.cc container.cc \ - font.cc iconbutton.cc inputbox.cc label.cc menu.cc modelview.cc paint.cc palette.cc scrollpane.cc \ + font.cc iconbutton.cc inputbox.cc label.cc listview.cc \ + menu.cc modelview.cc paint.cc palette.cc scrollpane.cc \ toolbar.cc ui.cc widget.cc window.cc libui_la_LDFLAGS = -avoid-version -no-undefined diff --git a/src/ui/listview.cc b/src/ui/listview.cc new file mode 100644 index 0000000..56fa324 --- /dev/null +++ b/src/ui/listview.cc @@ -0,0 +1,68 @@ +/* + ui/listview.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#include "ui/listview.h" + +namespace ui +{ + +ListView::ListView(Widget *parent) : Widget(parent) +{ + set_label("listview"); + set_border(true); +} + +ListView::~ListView() +{ +} + +void ListView::set_scroll(float scroll) +{ + listview_scroll = scroll; + if (listview_scroll < 0) + listview_scroll = 0; + + // calculate maximal scroll size + float top = 0; + for (Children::iterator it = children().begin(); it != children().end(); it++) { + top += (*it)->height(); + } + if (listview_scroll > top) listview_scroll = top; +} + +void ListView::inc_scroll(float scroll) +{ + set_scroll(listview_scroll + scroll); +} + +void ListView::dec_scroll(float scroll) +{ + set_scroll(listview_scroll - scroll); +} + +void ListView::resize() +{ + float content_top = 0; + + // reposition all children within the container + for (Children::iterator it = children().begin(); it != children().end(); it++) { + (*it)->set_width(width()); + if (content_top - listview_scroll < 0) { + // child widget is invisible + (*it)->hide(); + } else if ((content_top - listview_scroll) >= height()) { + // child widget is invisible + (*it)->hide(); + } else { + (*it)->show(); + (*it)->set_location(0, content_top - listview_scroll); + } + + content_top += (*it)->height(); + } +} + +} diff --git a/src/ui/listview.h b/src/ui/listview.h new file mode 100644 index 0000000..25fd07c --- /dev/null +++ b/src/ui/listview.h @@ -0,0 +1,50 @@ +/* + ui/listview.h + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#ifndef __INCLUDED_UI_LISTVIEW_H__ +#define __INCLUDED_UI_LISTVIEW_H__ + +#include +#include "ui/widget.h" + +namespace ui +{ + +/** + * @brief a list of selectable items + **/ +class ListView : public Widget +{ +public: + ListView(Widget *parent=0); + ~ListView(); + + /// current scroll position + inline float scroll() const { + return listview_scroll; + } + + /* -- mutators --------------------------------------------- */ + + /// set scroll + void set_scroll(float scroll); + + /// scroll down + void inc_scroll(float scroll); + + /// scroll up + void dec_scroll(float scroll); + +protected: + virtual void resize(); + +private: + float listview_scroll; +}; + +} // namespacd ui + +#endif // __INCLUDED_UI_LISTVIEW_H__ -- cgit v1.2.3