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
parent8c6a1a404ac8d1589a37d54b3b7ce0d776fe4751 (diff)
cosmetic updates in engine list functions, trade menu updates
-rw-r--r--src/client/inventorylistview.cc6
-rw-r--r--src/client/playerview.cc22
-rw-r--r--src/client/trademenu.cc113
-rw-r--r--src/client/trademenu.h22
-rw-r--r--src/core/cvar.cc5
-rw-r--r--src/core/entity.cc46
-rw-r--r--src/core/func.cc7
-rw-r--r--src/core/info.cc8
-rw-r--r--src/core/zone.cc16
-rw-r--r--src/game/base/shipmodel.cc8
-rw-r--r--src/model/model.cc5
-rw-r--r--src/model/vertexarray.cc3
-rw-r--r--src/ui/console.cc1
-rw-r--r--src/ui/label.cc5
-rw-r--r--src/ui/label.h3
-rw-r--r--src/ui/scrollpane.cc62
-rw-r--r--src/ui/scrollpane.h24
17 files changed, 228 insertions, 128 deletions
diff --git a/src/client/inventorylistview.cc b/src/client/inventorylistview.cc
index 656adfb..1b46fd0 100644
--- a/src/client/inventorylistview.cc
+++ b/src/client/inventorylistview.cc
@@ -14,6 +14,9 @@ InventoryListView::InventoryListView(ui::Widget *parent) : ui::ListView (parent)
set_inventory(0, 0);
}
+InventoryListView::~InventoryListView() {
+}
+
void InventoryListView::set_inventory(core::Inventory *inventory, core::InfoType *info_type)
{
remove_children();
@@ -22,6 +25,9 @@ void InventoryListView::set_inventory(core::Inventory *inventory, core::InfoType
return;
}
+ // TODO scan the inventories and request updated infos
+ // update when necessary
+
for (core::Inventory::Items::const_iterator it = inventory->items().begin(); it != inventory->items().end(); it++) {
core::Item *item = (*it);
diff --git a/src/client/playerview.cc b/src/client/playerview.cc
index 4be64d2..2c2ecaa 100644
--- a/src/client/playerview.cc
+++ b/src/client/playerview.cc
@@ -133,15 +133,25 @@ void PlayerView::show_menu(const std::string & args)
// show buy menu
view_buymenu->show();
} else {
- con_print << "usage: view buy [infoid] show the buy menu for this kind of item" << std::endl;
+ con_print << "usage: view buy [info id] show the buy menu for this kind of item" << std::endl;
}
} else if (label.compare("trade") == 0) {
- // hide other menus
- view_buymenu->hide();
- view_entitymenu->hide();
- // show trade menu
- view_trademenu->show();
+ // invetory based trade
+ std::string typestr;
+
+ if(argstr >> typestr) {
+ aux::to_label(typestr);
+
+ // hide other menus
+ view_buymenu->hide();
+ view_entitymenu->hide();
+ // show trade menu
+ view_trademenu->show();
+ view_trademenu->set_item_type(core::InfoType::find(typestr));
+ } else {
+ con_print << "usage: view trade [string] show the trade menu for this type of items" << std::endl;
+ }
} else if (label.compare("hide") == 0) {
// hide all menus
diff --git a/src/client/trademenu.cc b/src/client/trademenu.cc
index 7e9be4f..e96f1a6 100644
--- a/src/client/trademenu.cc
+++ b/src/client/trademenu.cc
@@ -4,6 +4,9 @@
the terms of the GNU General Public License version 2
*/
+#include "core/application.h"
+#include "core/info.h"
+#include "core/inventory.h"
#include "ui/button.h"
#include "ui/paint.h"
#include "ui/ui.h"
@@ -34,13 +37,22 @@ TradeMenu::TradeMenu(ui::Widget *parent, const char * label) : ui::Window(parent
menu_namelabel->set_alignment(ui::AlignCenter);
menu_namelabel->show();
- menu_inventorylistview = new ui::ListView(menu_tradewindow);
+ menu_inventorylistview = new InventoryListView(menu_tradewindow);
menu_inventorylistview->set_label("inventorylistview");
menu_inventorylistview->set_background(false);
menu_inventorylistview->set_border(true);
+ menu_modelview = new ui::ModelView(menu_tradewindow);
+ menu_modelview->set_label("modelview");
+ menu_modelview->set_background(false);
+ menu_modelview->set_border(false);
+
+ menu_scrollpane = new ui::ScrollPane(menu_tradewindow, menu_infotext);
+ menu_scrollpane->set_background(false);
+ menu_scrollpane->set_border(false);
+ menu_scrollpane->set_alignment(ui::AlignTop);
- menu_traderlistview = new ui::ListView(menu_tradewindow);
+ menu_traderlistview = new InventoryListView(menu_tradewindow);
menu_traderlistview->set_label("traderlistview");
menu_traderlistview->set_background(false);
menu_traderlistview->set_border(true);
@@ -48,7 +60,7 @@ TradeMenu::TradeMenu(ui::Widget *parent, const char * label) : ui::Window(parent
menu_closebutton = new ui::Button(menu_tradewindow, "Return", "view hide");
std::string test("test");
- set_item_type(test);
+ set_item_type(0);
hide();
}
@@ -58,54 +70,55 @@ TradeMenu::~TradeMenu()
}
-void TradeMenu::set_item_type(std::string const & itemtype)
+void TradeMenu::set_item_type(core::InfoType *item_type)
{
- ui::ListItem *item_label = 0;
-
+ // reset
menu_namelabel->set_text(0);
+ menu_infotext.clear();
- // update inventorylistview
- menu_inventorylistview->remove_children();
-
- //core::Inventory *inventory = 0;
-
-
- item_label = new ui::ListItem(menu_inventorylistview, "Inventory item 1");
- item_label->set_height(item_label->font()->height() * 2.0f);
-
- item_label = new ui::ListItem(menu_inventorylistview, "Inventory item 2");
- item_label->set_height(item_label->font()->height() * 2.0f);
+ core::Inventory *inventory_player = 0;
+ core::Inventory *inventory_view = 0;
- item_label = new ui::ListItem(menu_inventorylistview, "Inventory item 3");
- item_label->set_height(item_label->font()->height() * 2.0f);
+ if (core::localcontrol())
+ inventory_player = core::localcontrol()->inventory();
- item_label = new ui::ListItem(menu_inventorylistview, "Inventory item 4");
- item_label->set_height(item_label->font()->height() * 2.0f);
+ if(core::localplayer()->view())
+ inventory_view = core::localplayer()->view()->inventory();
- item_label = new ui::ListItem(menu_inventorylistview, "Inventory item 5");
- item_label->set_height(item_label->font()->height() * 2.0f);
+ menu_inventorylistview->set_inventory(inventory_player, item_type);
+ menu_traderlistview->set_inventory(inventory_view, item_type);
- menu_inventorylistview->event_resize();
-
- // update traderlistview
- menu_traderlistview->remove_children();
-
- item_label = new ui::ListItem(menu_traderlistview, "Shop item 1");
- item_label->set_height(item_label->font()->height() * 2.0f);
-
- item_label = new ui::ListItem(menu_traderlistview, "Shop item 2");
- item_label->set_height(item_label->font()->height() * 2.0f);
-
- item_label = new ui::ListItem(menu_traderlistview, "Shop item 3");
- item_label->set_height(item_label->font()->height() * 2.0f);
-
- item_label = new ui::ListItem(menu_traderlistview, "Shop item 4");
- item_label->set_height(item_label->font()->height() * 2.0f);
+ set_item(0);
+}
+
+void TradeMenu::set_item(ui::ListItem *item)
+{
+ menu_namelabel->clear();
- item_label = new ui::ListItem(menu_traderlistview, "Shop item 5");
- item_label->set_height(item_label->font()->height() * 2.0f);
+ if (!item || !item->info()) {
+ menu_scrollpane->hide();
+ menu_modelview->hide();
+ return;
+ }
- menu_traderlistview->event_resize();
+ if (item->parent() == menu_inventorylistview) {
+ // item in ship inventory selected (SELL)
+ menu_namelabel->set_text("Sell " + item->text());
+
+ } else if (item->parent() == menu_traderlistview) {
+ // item in trader inventory selected (BUY)
+ menu_namelabel->set_text("Buy " + item->text());
+ }
+
+ if (item->info()) {
+ for (core::Info::Text::const_iterator it = item->info()->text().begin(); it != item->info()->text().end(); it++) {
+ menu_infotext.push_back((*it));
+ }
+ menu_scrollpane->show();
+
+ menu_modelview->set_modelname(item->info()->modelname());
+ menu_modelview->show();
+ }
}
void TradeMenu::resize()
@@ -128,6 +141,14 @@ void TradeMenu::resize()
menu_inventorylistview->set_size(ui::UI::elementsize.width(), menu_tradewindow->height() - smallmargin * 2.0f - fontmargin * 3.0f);
menu_inventorylistview->set_location(fontmargin, fontmargin * 3.0f);
+ // resize modelview
+ menu_modelview->set_size(menu_tradewindow->width() - 2.0f * ui::UI::elementsize.width() - fontmargin * 4.0f, ui::UI::elementsize.width());
+ menu_modelview->set_location(fontmargin * 2.0f + ui::UI::elementsize.width(), fontmargin * 3.0f);
+
+ // resize scrollpane
+ menu_scrollpane->set_size(menu_tradewindow->width() - 2.0f * ui::UI::elementsize.width() - fontmargin * 4.0f, menu_inventorylistview->height() - fontmargin - ui::UI::elementsize.width());
+ menu_scrollpane->set_location(fontmargin * 2.0f + ui::UI::elementsize.width(), fontmargin * 4.0f + ui::UI::elementsize.width());
+
// resize trader listview
menu_traderlistview->set_size(ui::UI::elementsize.width(), menu_tradewindow->height() - smallmargin * 2.0f - fontmargin * 3.0f);
menu_traderlistview->set_location(menu_tradewindow->width() - menu_traderlistview->width() - fontmargin, fontmargin * 3.0f);
@@ -140,13 +161,7 @@ void TradeMenu::resize()
bool TradeMenu::on_emit(Widget *sender, const Event event, void *data)
{
if (event == ui::Widget::EventListItemClicked) {
- if (sender->parent() == menu_inventorylistview) {
- // item from inventory selected
- menu_namelabel->set_text("SELL " + static_cast<ui::ListItem *>(sender)->text());
- } else if (sender->parent() == menu_traderlistview) {
- // item from trader selected
- menu_namelabel->set_text("BUY " + static_cast<ui::ListItem *>(sender)->text());
- }
+ set_item(static_cast<ui::ListItem *>(sender));
return true;
}
diff --git a/src/client/trademenu.h b/src/client/trademenu.h
index 37823b1..b95ee57 100644
--- a/src/client/trademenu.h
+++ b/src/client/trademenu.h
@@ -10,8 +10,11 @@
#include "core/info.h"
#include "ui/container.h"
#include "ui/label.h"
-#include "ui/listview.h"
+#include "ui/listitem.h"
+#include "ui/scrollpane.h"
+#include "ui/modelview.h"
#include "ui/widget.h"
+#include "client/inventorylistview.h"
namespace client
{
@@ -25,7 +28,7 @@ public:
~TradeMenu();
/// set the item type to trade
- void set_item_type(std::string const & itemtype);
+ void set_item_type(core::InfoType *item_type);
protected:
/// resize event handler
@@ -33,15 +36,20 @@ protected:
/// emit event handler
virtual bool on_emit(Widget *sender, const Event event, void *data);
-
+
private:
+ void set_item(ui::ListItem *item);
+
ui::Window *menu_tradewindow;
- ui::ListView *menu_inventorylistview;
- ui::ListView *menu_traderlistview;
ui::Button *menu_closebutton;
-
ui::Label *menu_namelabel;
-
+ ui::ModelView *menu_modelview;
+ ui::ScrollPane *menu_scrollpane;
+
+ InventoryListView *menu_inventorylistview;
+ InventoryListView *menu_traderlistview;
+
+ ui::Text menu_infotext;
};
}
diff --git a/src/core/cvar.cc b/src/core/cvar.cc
index f043028..a47b72e 100644
--- a/src/core/cvar.cc
+++ b/src/core/cvar.cc
@@ -167,8 +167,6 @@ Cvar *Cvar::find(const char* name)
void Cvar::list()
{
- con_print << "Flags: A=Archive G=Game R=ReadOnly" << std::endl;
-
Registry::iterator it;
for (it = cvar_registry.begin(); it != cvar_registry.end(); it++) {
std::string typeindicator;
@@ -190,7 +188,8 @@ void Cvar::list()
con_print << " " << typeindicator <<
" " << (*it).first << " " << (*it).second->str() << " ^N" << (*it).second->info() << std::endl;
}
- con_print << cvar_registry.size() << " registered variables" << std::endl;
+ con_print << " Flags: A=Archive G=Game R=ReadOnly" << std::endl;
+ con_print << "^B " << cvar_registry.size() << " registered variables" << std::endl;
}
}
diff --git a/src/core/entity.cc b/src/core/entity.cc
index 538aecb..0b3a402 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -81,6 +81,26 @@ void Entity::clear()
entity_nextid = 0;
}
+void Entity::list_inventory() const
+{
+ con_print << " entity id ^B" << id() << " ^Nlabel ^B" << label() << " ^Nname ^B" << name() << std::endl;
+ if (!entity_inventory) {
+ con_print << "no inventory availble" << std::endl;
+ return;
+ }
+
+ con_print << " ^Nid type label amount" << std::endl;
+ for (Inventory::Items::const_iterator it = entity_inventory->items().begin(); it != entity_inventory->items().end(); it++) {
+ Item *item = (*it);
+ con_print << " "
+ << " ^B" << std::setw(4) << item->info()->id()
+ << " ^N" << aux::pad_right((item->info()->type() ? item->info()->type()->label() : "NULL"), 8)
+ << " ^N" << aux::pad_right(item->info()->label(), 24)
+ << std::setw(5) << item->amount() << std::endl;
+ }
+ con_print << "^B " << entity_inventory->items().size() << " inventory items" << std::endl;
+}
+
void Entity::list_header()
{
con_print << " "
@@ -94,8 +114,8 @@ void Entity::list(const Entity *entity)
{
con_print << " "
<< "^B" << std::setw(4) << entity->id() << " "
- << "^B" << std::setfill('0') << std::setw(4) << entity->type() << ":" << std::setw(4) << entity->moduletype() << std::setfill(' ') << " "
- << "^B" << aux::pad_right(entity->label(), 24) << " "
+ << "^N" << std::setfill('0') << std::setw(4) << entity->type() << ":" << std::setw(4) << entity->moduletype() << std::setfill(' ') << " "
+ << "^N" << aux::pad_right(entity->label(), 24) << " "
<< "^N" << entity->name() << std::endl;
}
@@ -107,7 +127,7 @@ void Entity::list()
Entity *entity = (*it).second;
list(entity);
}
- con_print << entity_registry.size() << " entities" << std::endl;
+ con_print << "^B " << entity_registry.size() << " entities" << std::endl;
}
/* ---- class Entity ----------------------------------------------- */
@@ -401,26 +421,6 @@ void Entity::remove_menu(std::string const &label)
}
}
-void Entity::list_inventory() const
-{
- con_print << " ^B" << name() << "^N ";
- if (!entity_inventory) {
- con_print << "no inventory availble" << std::endl;
- return;
- }
- con_print << "inventory" << std::endl;
-
- for (Inventory::Items::const_iterator it = entity_inventory->items().begin(); it != entity_inventory->items().end(); it++) {
- Item *item = (*it);
- con_print << " "
- << " ^B" << std::setw(4) << item->info()->id()
- << " ^N" << (item->info()->type() ? item->info()->type()->label() : "NULL")
- << " ^N" << item->info()->label()
- << " amount " << item->amount() << std::endl;
- }
-
-}
-
/* ---- class EntityDynamic ---------------------------------------- */
EntityDynamic::EntityDynamic() : Entity()
diff --git a/src/core/func.cc b/src/core/func.cc
index 4072f39..aa49f17 100644
--- a/src/core/func.cc
+++ b/src/core/func.cc
@@ -108,8 +108,7 @@ Func *Func::find(const std::string &name)
void Func::list()
{
Registry::iterator it;
- con_print << "Flags: G=Game S=Shared" << std::endl;
-
+
for (it = func_registry.begin(); it != func_registry.end(); it++) {
std::string typeindicator;
if (((*it).second->flags() & Game) == Game)
@@ -122,8 +121,8 @@ void Func::list()
typeindicator += ' ';
con_print << " " << typeindicator << " " << (*it).second->name() << " " << (*it).second->info() << std::endl;
}
-
- con_print << func_registry.size() << " registered functions" << std::endl;
+ con_print << "Flags: G=Game S=Shared" << std::endl;
+ con_print << "^B " << func_registry.size() << " registered functions" << std::endl;
}
/* ---- Func ------------------------------------------------------ */
diff --git a/src/core/info.cc b/src/core/info.cc
index 1a4f68f..c331d91 100644
--- a/src/core/info.cc
+++ b/src/core/info.cc
@@ -365,8 +365,8 @@ void Info::list(const Info *info)
{
con_print << " "
<< "^B" << std::setw(4) << info->id() << " "
- << "^B" << (info->type() ? aux::pad_right(info->type()->label(), 8) : "NULL ") << " "
- << "^B" << aux::pad_right(info->label(), 12) << " "
+ << "^N" << (info->type() ? aux::pad_right(info->type()->label(), 8) : "NULL ") << " "
+ << "^N" << aux::pad_right(info->label(), 12) << " "
<< "^N" << info->name() << std::endl;
}
@@ -377,7 +377,7 @@ void Info::list()
Info *info = (*it);
list(info);
}
- con_print << info_registry.size() << " info " << aux::plural("record", info_registry.size()) << std::endl;
+ con_print << "^B " << info_registry.size() << " info " << aux::plural("record", info_registry.size()) << std::endl;
}
void Info::list(const InfoType *type)
@@ -391,7 +391,7 @@ void Info::list(const InfoType *type)
list(info);
}
}
- con_print << count << " " << type->label() << " info " << aux::plural("record", count) << std::endl;
+ con_print << "^B " << count << " " << type->label() << " info " << aux::plural("record", count) << std::endl;
}
}
diff --git a/src/core/zone.cc b/src/core/zone.cc
index ab38b1b..7fc3f4d 100644
--- a/src/core/zone.cc
+++ b/src/core/zone.cc
@@ -91,11 +91,19 @@ Zone *Zone::search(std::string const & searchname)
void Zone::list()
{
+ con_print << " "
+ << " id "
+ << "label "
+ << "name" << std::endl;
+
for (Registry::iterator it = zone_registry.begin(); it != zone_registry.end(); it++) {
Zone *zone = (*it).second;
- con_print << " id " << std::setw(4) << zone->id() << " " << zone->label() << std::endl;
+ con_print << " "
+ << "^B" << std::setw(4) << zone->id() << " "
+ << "^N" << aux::pad_right(zone->label(), 24) << " "
+ << "^N" << zone->name() << std::endl;
}
- con_print << zone_registry.size() << " registered zones" << std::endl;
+ con_print << "^B " << zone_registry.size() << " zones" << std::endl;
}
void Zone ::clear()
@@ -135,13 +143,13 @@ Zone::~Zone()
void Zone::print()
{
- con_print << "id ^B" << id() << " ^Nlabel ^B" << label() << " ^Nname ^B" << name() << std::endl;
+ con_print << " zone id ^B" << id() << " ^Nlabel ^B" << label() << " ^Nname ^B" << name() << std::endl;
Entity::list_header();
for (Content::iterator it = zone_content.begin(); it != zone_content.end(); it++) {
Entity *entity = (*it);
Entity::list(entity);
}
- con_print << zone_content.size() << " registered zone entities" << std::endl;
+ con_print << " ^B" << zone_content.size() << " zone entities" << std::endl;
}
void Zone::add(Entity *entity)
diff --git a/src/game/base/shipmodel.cc b/src/game/base/shipmodel.cc
index ee2e647..1dc8ba1 100644
--- a/src/game/base/shipmodel.cc
+++ b/src/game/base/shipmodel.cc
@@ -36,7 +36,9 @@ void ShipModel::generate_info()
{
//clear_text();
- add_text("");
+ if (text().size())
+ add_text("");
+
add_text("^BSpecifications:^N");
std::stringstream str;
str << "price: ^B" << price() << " ^Ncredits";
@@ -60,11 +62,11 @@ void ShipModel::generate_info()
str.str("");
if (jumpdrive()) {
- add_text("hyperspace jump drive capable");
+ add_text("^Bhyperspace jump drive");
}
if (dock()) {
- add_text("docking capable");
+ add_text("^Bdockable");
}
}
diff --git a/src/model/model.cc b/src/model/model.cc
index 5ba4deb..7552b07 100644
--- a/src/model/model.cc
+++ b/src/model/model.cc
@@ -172,11 +172,12 @@ void Model::list()
list_model((*mit).second);
}
- con_print << model_registry.size() << " registered models" << std::endl;
-
+
if (VertexArray::instance()) {
VertexArray::instance()->info();
}
+
+ con_print << "^B " << model_registry.size() << " registered models" << std::endl;
}
}
diff --git a/src/model/vertexarray.cc b/src/model/vertexarray.cc
index 861090c..67a13aa 100644
--- a/src/model/vertexarray.cc
+++ b/src/model/vertexarray.cc
@@ -163,8 +163,7 @@ void VertexArray::info() {
con_print << " vertex array "
<< vertex_index / mbfl << "/" << vertex_size / mbfl << "Mib "
<< vertex_index / 8 << "/" << vertex_size / 8 << " verts "
- << vertex_index * 100 / vertex_size << "% used"
- << std::endl;
+ << "^B" << vertex_index * 100 / vertex_size << "%^N used" << std::endl;
}
}
diff --git a/src/ui/console.cc b/src/ui/console.cc
index c486c65..6ce3593 100644
--- a/src/ui/console.cc
+++ b/src/ui/console.cc
@@ -78,6 +78,7 @@ void Console::show()
SDL_ShowCursor(SDL_ENABLE);
console_scrollpane->set_scroll(0);
+ console_scrollpane->set_offset(3);
history_pos = history.rbegin();
(*history_pos).clear();
diff --git a/src/ui/label.cc b/src/ui/label.cc
index 3284d0e..b6f72c7 100644
--- a/src/ui/label.cc
+++ b/src/ui/label.cc
@@ -30,6 +30,11 @@ void Label::print(const size_t indent) const
con_print << aux::pad_left(marker, indent*2) << label() << " \"" << text() << "\"" << std::endl;
}
+void Label::clear()
+{
+ label_text.clear();
+}
+
void Label::set_text(const char *text)
{
if (text)
diff --git a/src/ui/label.h b/src/ui/label.h
index 9188dc5..2a38273 100644
--- a/src/ui/label.h
+++ b/src/ui/label.h
@@ -28,6 +28,9 @@ public:
/// set the text alignment
void set_alignment(const unsigned int alignment);
+
+ /// clear the label text
+ void clear();
/// return the text displayed by the label
inline const std::string &text() const {
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();
diff --git a/src/ui/scrollpane.h b/src/ui/scrollpane.h
index 82c74c9..8fe8395 100644
--- a/src/ui/scrollpane.h
+++ b/src/ui/scrollpane.h
@@ -26,33 +26,45 @@ public:
inline int scroll() const {
return scrollpane_scroll;
}
+
+ /// current scroll offset
+ inline int offset() const {
+ return scrollpane_offset;
+ }
/// 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);
+ void set_scroll(const int scroll);
+
+ /// set scroll offset
+ void set_offset(const int offset);
/// increase scroll
- void inc_scroll(int scroll);
+ void inc_scroll(const int scroll);
/// decrease scroll
- void dec_scroll(int scroll);
+ void dec_scroll(const int scroll);
+
+ /// set text alignment
+ void set_alignment(const unsigned int alignment);
protected:
/// draw the scroll pane
virtual void draw();
+
+ /// key event handler provides mouse scrolling
+ virtual bool on_keypress(const int key, const unsigned int modifier);
private:
ui::Text &scrollpane_text;
int scrollpane_scroll;
+ int scrollpane_offset;
unsigned int scrollpane_alignment;
};