Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/buymenu.cc10
-rw-r--r--src/client/hud.cc28
-rw-r--r--src/client/infowidget.cc26
-rw-r--r--src/client/inventorylistview.cc2
-rw-r--r--src/client/trademenu.cc67
-rw-r--r--src/client/trademenu.h7
-rw-r--r--src/client/video.cc2
-rw-r--r--src/client/worldview.cc10
-rw-r--r--src/core/info.cc5
-rw-r--r--src/core/info.h17
-rw-r--r--src/core/inventory.cc22
-rw-r--r--src/core/inventory.h77
-rw-r--r--src/game/base/cargo.cc70
-rw-r--r--src/game/base/ship.cc6
-rw-r--r--src/game/base/shipmodel.h2
-rw-r--r--src/render/text.cc42
-rw-r--r--src/render/text.h39
-rw-r--r--src/ui/Makefile.am13
-rw-r--r--src/ui/bitmap.cc4
-rw-r--r--src/ui/button.cc12
-rw-r--r--src/ui/console.cc4
-rw-r--r--src/ui/container.cc4
-rw-r--r--src/ui/iconbutton.cc12
-rw-r--r--src/ui/inputbox.cc18
-rw-r--r--src/ui/label.cc4
-rw-r--r--src/ui/label.h4
-rw-r--r--src/ui/listitem.cc16
-rwxr-xr-xsrc/ui/modelview.cc24
-rwxr-xr-xsrc/ui/modelview.h10
-rw-r--r--src/ui/paint.cc96
-rw-r--r--src/ui/paint.h58
-rw-r--r--src/ui/plaintext.cc58
-rw-r--r--src/ui/plaintext.h63
-rw-r--r--src/ui/ui.cc19
-rw-r--r--src/ui/widget.cc12
-rw-r--r--src/ui/window.cc4
36 files changed, 573 insertions, 294 deletions
diff --git a/src/client/buymenu.cc b/src/client/buymenu.cc
index a106659..ba93f42 100644
--- a/src/client/buymenu.cc
+++ b/src/client/buymenu.cc
@@ -29,6 +29,11 @@ BuyMenu::BuyMenu(ui::Widget *parent, const char * label) : ui::Window(parent)
menu_buywindow->set_background(true);
menu_buywindow->set_border(true);
+ menu_modelview = new ui::ModelView(menu_buywindow);
+ menu_modelview->set_label("modelview");
+ menu_modelview->set_background(false);
+ menu_modelview->set_border(false);
+
menu_namelabel = new ui::Label(menu_buywindow);
menu_namelabel->set_label("label");
menu_namelabel->set_background(false);
@@ -36,11 +41,6 @@ BuyMenu::BuyMenu(ui::Widget *parent, const char * label) : ui::Window(parent)
menu_namelabel->set_font(ui::root()->font_large());
menu_namelabel->set_alignment(ui::AlignCenter);
- menu_modelview = new ui::ModelView(menu_buywindow);
- menu_modelview->set_label("modelview");
- menu_modelview->set_background(false);
- menu_modelview->set_border(false);
-
menu_scrollpane = new ui::ScrollPane(menu_buywindow, menu_infotext);
menu_scrollpane->set_background(false);
menu_scrollpane->set_border(false);
diff --git a/src/client/hud.cc b/src/client/hud.cc
index 3a7601b..d712987 100644
--- a/src/client/hud.cc
+++ b/src/client/hud.cc
@@ -28,7 +28,7 @@ HUD::HUD(ui::Widget *parent) : Widget(parent)
hud_toolbar->add_button("", "Chat", "ui_chat");
hud_toolbar->add_button("", "Map", "ui_map");
*/
- hud_center = new ui::Bitmap(this, "pointers/center");
+ hud_center = new ui::Bitmap(this, "bitmaps/pointers/center");
hud_center->set_color(palette()->pointer());
}
@@ -180,7 +180,7 @@ void HUD::draw_target(core::Entity *entity, bool is_active_target)
if (is_active_target) {
// entity name and distance
- std::stringstream strdistance;
+ std::ostringstream strdistance;
float d = math::distance(core::localcontrol()->location(), entity->location()) - entity->radius() - core::localcontrol()->radius();
if (d > 0) {
if (d > 100.0f) {
@@ -213,7 +213,7 @@ void HUD::draw_target(core::Entity *entity, bool is_active_target)
cy - r - 4 - render::Text::fontheight(), entity->name());
render::Text::draw(cx - aux::text_length(strdistance.str()) * render::Text::fontwidth() * 0.5f,
- cy + r + 4, strdistance);
+ cy + r + 4, strdistance.str());
}
}
@@ -235,7 +235,6 @@ bool HUD::on_keypress(const int key, const unsigned int modifier)
void HUD::draw()
{
using namespace render;
- std::stringstream status;
if (core::localcontrol() && (input::mouse_control || input::joystick_control) &&
(render::Camera::mode() == render::Camera::Cockpit || render::Camera::mode() == render::Camera::Track)) {
@@ -248,7 +247,6 @@ void HUD::draw()
Text::setfont("gui", 12, 18);
Text::setcolor('N'); //set normal color
-
core::Zone *zone = core::localcontrol()->zone();
// draw HUD targets
@@ -269,7 +267,7 @@ void HUD::draw()
/*
unsigned int state = core::localcontrol()->state();
if (state) {
- std::stringstream statestr;
+ std::ostringstream statestr;
statestr.clear();
if (state == core::Entity::ImpulseInitiate) {
statestr << "^FInitializing kinetic impulse drive " << core::localcontrol()->timer();
@@ -281,15 +279,13 @@ void HUD::draw()
statestr << "^FJumping...";
}
- Text::draw(4, render::State::height() - Text::fontheight()*3 - 4, statestr);
+ Text::draw(4, render::State::height() - Text::fontheight()*3 - 4, statestr.str());
}
*/
const core::Entity *target = targets::current();
- std::stringstream strdistance;
-
if (target) {
- std::stringstream strtarget;
+ std::ostringstream strtarget;
strtarget << "^B" << target->name() << "\n^B";
float d = math::distance(core::localcontrol()->location(), target->location())
@@ -316,15 +312,15 @@ void HUD::draw()
} else {
strtarget << " --";
}
- strtarget << '\n';
- Text::draw(width() - 4 - Text::fontwidth()*30, height() - Text::fontheight()*2 - 4, strtarget);
+ Text::draw(width() - 4 - Text::fontwidth()*30, height() - Text::fontheight()*2 - 4, strtarget.str());
}
// draw player info
- std::stringstream playerinfostr;
+ std::ostringstream playerinfostr;
playerinfostr << "^B" << core::localcontrol()->name() << '\n' << "^Ncredits: " << core::localplayer()->credits();
- Text::draw(width() - 4 - Text::fontwidth()*52, height() - Text::fontheight()*2 - 4, playerinfostr);
+ Text::draw(width() - 4 - Text::fontwidth()*52, height() - Text::fontheight()*2 - 4, playerinfostr.str());
+ // draw thruster indicator
Textures::bind("bitmaps/hud/thruster_base"); // 316 x 32 bitmap
gl::color(1, 1, 1, 1);
gl::begin(gl::Quads);
@@ -388,9 +384,9 @@ void HUD::draw()
Text::setfont("gui", 14, 24);
Text::setcolor('B'); //set normal color
- std::stringstream speedstr;
+ std::ostringstream speedstr;
speedstr << "^B" << roundf(core::localcontrol()->speed() * 100.0f);
- Text::draw(316 + 4 + 10, height() - 6 - 16 - render::Text::fontwidth() / 2, speedstr);
+ Text::draw(316 + 4 + 10, height() - 6 - 16 - render::Text::fontwidth() / 2, speedstr.str());
Text::setfont("gui", 12, 18);
Text::setcolor('N'); //set normal color
diff --git a/src/client/infowidget.cc b/src/client/infowidget.cc
index 3081b8d..c4c85a1 100644
--- a/src/client/infowidget.cc
+++ b/src/client/infowidget.cc
@@ -25,7 +25,8 @@
namespace client
{
-void time_to_stream(std::stringstream &str, float time)
+// helper function
+void time_to_stream(std::ostringstream &str, float time)
{
int minutes = (int) floorf(time / 60.0f);
int seconds = (int) floorf(time - (float) minutes * 60.0f);
@@ -43,7 +44,7 @@ DevInfoWidget::DevInfoWidget(ui::Widget *parent) : ui::Widget(parent)
void DevInfoWidget::draw()
{
- std::stringstream textstream;
+ std::ostringstream textstream;
const core::Entity *target = targets::current();
float d = 0;
@@ -71,8 +72,8 @@ void DevInfoWidget::draw()
}
}
- ui::paint::color(palette()->foreground());
- ui::paint::text(global_location(), size(), font(), textstream);
+ ui::Paint::set_color(palette()->foreground());
+ ui::Paint::draw_text(global_location(), font(), textstream.str());
}
/* -- StatsInfoWidget ---------------------------------------------- */
@@ -109,7 +110,7 @@ void StatsInfoWidget::draw()
fps = roundf(((float) fps_counter_size ) / t);
}
- std::stringstream textstream;
+ std::ostringstream textstream;
if (core::game()) {
textstream << "^Ntime ^B";
@@ -140,8 +141,8 @@ void StatsInfoWidget::draw()
}
}
- ui::paint::color(palette()->foreground());
- ui::paint::text(global_location(), size(), font(), textstream);
+ ui::Paint::set_color(palette()->foreground());
+ ui::Paint::draw_text(global_location(), font(), textstream.str());
}
/* -- KeyInfoWidget ------------------------------------------------ */
@@ -155,10 +156,9 @@ KeyInfoWidget::KeyInfoWidget(ui::Widget *parent) : Widget(parent)
void KeyInfoWidget::draw()
{
- std::string label;
- ui::paint::color(palette()->highlight());
-
Key::Modifier mod = input::modifier();
+ std::string label;
+
if (mod != Key::None) {
if (mod == Key::Shift)
label.assign("shift+");
@@ -172,8 +172,10 @@ void KeyInfoWidget::draw()
label.append(input::last_key_pressed()->name());
}
- if (label.size())
- ui::paint::label(global_location(), size(), font(), label , ui::AlignCenter);
+ if (label.size()) {
+ ui::Paint::set_color(palette()->highlight());
+ ui::Paint::draw_label(global_location(), size(), font(), label , ui::AlignCenter);
+ }
}
}
diff --git a/src/client/inventorylistview.cc b/src/client/inventorylistview.cc
index d2752d6..0126ff4 100644
--- a/src/client/inventorylistview.cc
+++ b/src/client/inventorylistview.cc
@@ -64,7 +64,7 @@ void InventoryListView::set_inventory(core::Inventory *inventory, core::InfoType
void InventoryListView::draw()
{
- if (listview_timestamp != listview_inventory->timestamp()) {
+ if (listview_inventory && (listview_timestamp != listview_inventory->timestamp())) {
set_inventory(listview_inventory, listview_infotype);
}
diff --git a/src/client/trademenu.cc b/src/client/trademenu.cc
index d93864d..7ac3e7c 100644
--- a/src/client/trademenu.cc
+++ b/src/client/trademenu.cc
@@ -4,6 +4,8 @@
the terms of the GNU General Public License version 2
*/
+#include <iomanip>
+
#include "core/application.h"
#include "core/info.h"
#include "core/inventory.h"
@@ -13,8 +15,7 @@
#include "ui/listitem.h"
#include "client/trademenu.h"
-namespace client
-{
+namespace client {
TradeMenu::TradeMenu(ui::Widget *parent, const char * label) : ui::Window(parent)
{
@@ -28,7 +29,12 @@ TradeMenu::TradeMenu(ui::Widget *parent, const char * label) : ui::Window(parent
menu_tradewindow = new ui::Window(this);
menu_tradewindow->set_label("tradewindow");
menu_tradewindow->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_namelabel = new ui::Label(menu_tradewindow);
menu_namelabel->set_label("label");
menu_namelabel->set_background(false);
@@ -42,20 +48,12 @@ TradeMenu::TradeMenu(ui::Widget *parent, const char * label) : ui::Window(parent
menu_inventorylistview->set_background(false);
menu_inventorylistview->set_border(true);
- menu_inventorylabel = new ui::Label(menu_tradewindow);
- menu_inventorylabel->set_label("label");
- menu_inventorylabel->set_background(false);
- menu_inventorylabel->set_border(false);
- menu_inventorylabel->set_font(ui::root()->font_small());
- menu_inventorylabel->set_alignment(ui::AlignLeft);
-
+ menu_inventorytext = new ui::PlainText(menu_tradewindow);
+ menu_inventorytext->set_label("inventorytext");
+ menu_inventorytext->set_background(false);
+ menu_inventorytext->set_border(false);
+ menu_inventorytext->set_font(ui::root()->font_small());
-
- 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);
@@ -66,12 +64,11 @@ TradeMenu::TradeMenu(ui::Widget *parent, const char * label) : ui::Window(parent
menu_traderlistview->set_background(false);
menu_traderlistview->set_border(true);
- menu_traderlabel = new ui::Label(menu_tradewindow);
- menu_traderlabel->set_label("label");
- menu_traderlabel->set_background(false);
- menu_traderlabel->set_border(false);
- menu_traderlabel->set_font(ui::root()->font_small());
- menu_traderlabel->set_alignment(ui::AlignLeft);
+ menu_tradertext = new ui::PlainText(menu_tradewindow);
+ menu_tradertext->set_label("tradertext");
+ menu_tradertext->set_background(false);
+ menu_tradertext->set_border(false);
+ menu_tradertext->set_font(ui::root()->font_small());
menu_closebutton = new ui::Button(menu_tradewindow, "Return", "view hide");
@@ -116,7 +113,7 @@ void TradeMenu::set_item(ui::ListItem *item)
{
menu_infotext.clear();
menu_namelabel->set_text("Trade");
- menu_traderlabel->clear();
+ menu_tradertext->clear();
if (!item || !item->info()) {
menu_traderlistview->deselect();
@@ -153,8 +150,8 @@ void TradeMenu::set_item(ui::ListItem *item)
menu_buybutton->set_command("remote buy " + item->info()->type()->label() + " " + item->info()->label() + " 1; ");
std::ostringstream str;
- str << "Price: " << item->item()->price();
- menu_traderlabel->set_text(str.str());
+ str << "Price: " << std::setw(8) << item->item()->price() << '\n' << "Volume: " << std::setw(7) << std::setprecision(2) << item->info()->volume();
+ menu_tradertext->set_text(str.str());
menu_sellallbutton->hide();
menu_sellbutton->hide();
@@ -201,8 +198,8 @@ void TradeMenu::resize()
menu_inventorylistview->set_size(ui::UI::elementsize.width(), menu_tradewindow->height() - smallmargin * 2.0f - fontmargin * 6.0f);
menu_inventorylistview->set_location(fontmargin, fontmargin * 3.0f);
- menu_inventorylabel->set_size(menu_inventorylistview->width(), fontmargin);
- menu_inventorylabel->set_location(menu_inventorylistview->left(), menu_inventorylistview->bottom() + fontmargin);
+ menu_inventorytext->set_size(menu_inventorylistview->width(), fontmargin);
+ menu_inventorytext->set_location(menu_inventorylistview->left(), menu_inventorylistview->bottom() + fontmargin);
// resize modelview
menu_modelview->set_size(menu_tradewindow->width() - 2.0f * ui::UI::elementsize.width() - fontmargin * 4.0f, ui::UI::elementsize.width());
@@ -229,8 +226,8 @@ void TradeMenu::resize()
menu_traderlistview->set_size(ui::UI::elementsize.width(), menu_tradewindow->height() - smallmargin * 2.0f - fontmargin * 6.0f);
menu_traderlistview->set_location(menu_tradewindow->width() - menu_traderlistview->width() - fontmargin, fontmargin * 3.0f);
- menu_traderlabel->set_size(menu_traderlistview->width(), fontmargin);
- menu_traderlabel->set_location(menu_traderlistview->left(), menu_traderlistview->bottom() + fontmargin);
+ menu_tradertext->set_size(menu_traderlistview->width(), fontmargin);
+ menu_tradertext->set_location(menu_traderlistview->left(), menu_traderlistview->bottom() + fontmargin);
// resize close button
menu_closebutton->set_size(ui::UI::elementsize);
@@ -250,10 +247,16 @@ bool TradeMenu::on_emit(Widget *sender, const Event event, void *data)
void TradeMenu::draw()
{
std::stringstream str;
- str << "Credits: " << core::localplayer()->credits();
- menu_inventorylabel->set_text(str.str());
+ str << "Credit: " << std::setw(8) << core::localplayer()->credits();
+
+ if (core::localcontrol() && core::localcontrol()->inventory()) {
+ core::Inventory *inventory = core::localcontrol()->inventory();
+ str << '\n';
+ str << "Cargo: " << std::setprecision(2) << std::setw(6) << inventory->capacity_used() << " of " << inventory->capacity();
+ }
+ menu_inventorytext->set_text(str.str());
Window::draw();
}
-}
+} // namespace client
diff --git a/src/client/trademenu.h b/src/client/trademenu.h
index 5f56a08..6ee53b5 100644
--- a/src/client/trademenu.h
+++ b/src/client/trademenu.h
@@ -11,8 +11,9 @@
#include "ui/container.h"
#include "ui/label.h"
#include "ui/listitem.h"
-#include "ui/scrollpane.h"
#include "ui/modelview.h"
+#include "ui/plaintext.h"
+#include "ui/scrollpane.h"
#include "ui/widget.h"
#include "client/inventorylistview.h"
@@ -45,8 +46,8 @@ private:
ui::Window *menu_tradewindow;
ui::Button *menu_closebutton;
ui::Label *menu_namelabel;
- ui::Label *menu_inventorylabel;
- ui::Label *menu_traderlabel;
+ ui::PlainText *menu_inventorytext;
+ ui::PlainText *menu_tradertext;
ui::ModelView *menu_modelview;
ui::ScrollPane *menu_scrollpane;
diff --git a/src/client/video.cc b/src/client/video.cc
index 9e9d553..6eee36b 100644
--- a/src/client/video.cc
+++ b/src/client/video.cc
@@ -320,7 +320,7 @@ void draw_loader()
gl::color(1.0f, 1.0f, 1.0f, 1.0f);
math::Vector2f pos;
math::Vector2f size(render::State::width(), render::State::height());
- ui::paint::bitmap(pos, size, "loader");
+ ui::Paint::draw_bitmap(pos, size, "bitmaps/loader");
if (loader_message.size()) {
using render::Text;
diff --git a/src/client/worldview.cc b/src/client/worldview.cc
index c4f932b..684e08e 100644
--- a/src/client/worldview.cc
+++ b/src/client/worldview.cc
@@ -29,13 +29,13 @@ WorldView::WorldView(ui::Widget *parent) : ui::Widget(parent)
view_playerview->hide();
// icon buttons
- view_menubutton = new ui::IconButton(this, "icons/button_menu", "ui_menu");
+ view_menubutton = new ui::IconButton(this, "bitmaps/icons/button_menu", "ui_menu");
- view_launchbutton = new ui::IconButton(this, "icons/button_launch", "launch");
- view_dockbutton = new TargetIconButton(this, "icons/button_dock", "dock", core::Entity::Dockable);
+ view_launchbutton = new ui::IconButton(this, "bitmaps/icons/button_launch", "launch");
+ view_dockbutton = new TargetIconButton(this, "bitmaps/icons/button_dock", "dock", core::Entity::Dockable);
- view_chatbutton = new ui::IconButton(this, "icons/button_chat", "ui_chat");
- view_mapbutton = new ui::IconButton(this, "icons/button_map", "ui_map");
+ view_chatbutton = new ui::IconButton(this, "bitmaps/icons/button_chat", "ui_chat");
+ view_mapbutton = new ui::IconButton(this, "bitmaps/icons/button_map", "ui_map");
}
WorldView::~WorldView()
diff --git a/src/core/info.cc b/src/core/info.cc
index c331d91..16e68f5 100644
--- a/src/core/info.cc
+++ b/src/core/info.cc
@@ -67,6 +67,7 @@ Info::Info(const InfoType *type, const char *label) : Label(label)
info_model = 0;
info_timestamp = 0;
info_price = 0;
+ info_volume = 0;
}
// client-side constructor, id is passed as param
@@ -124,6 +125,10 @@ void Info::set_price(const long price)
info_price = price;
}
+void Info::set_volume(const float volume)
+{
+ info_volume = volume;
+}
void Info::set_timestamp(const unsigned long timestamp)
{
info_timestamp = timestamp;
diff --git a/src/core/info.h b/src/core/info.h
index 4b9c445..b3fa58f 100644
--- a/src/core/info.h
+++ b/src/core/info.h
@@ -95,6 +95,10 @@ public:
inline const long price() const {
return info_price;
}
+
+ inline const float volume() const {
+ return info_volume;
+ }
/**
* @brief timestamp
@@ -107,7 +111,9 @@ public:
return info_timestamp;
}
- /// text description
+ /**
+ * @brief text description
+ */
inline const Text & text() const {
return info_text;
}
@@ -122,8 +128,16 @@ public:
void set_model(const model::Model *model);
+ /**
+ * @brief associated price, in credits
+ */
void set_price(const long price);
+ /**
+ * @brief associated volume, in cubic meters
+ */
+ void set_volume(const float volume);
+
/// set the timestamp
void set_timestamp(const unsigned long timestamp);
@@ -159,6 +173,7 @@ private:
unsigned int info_id;
long info_price;
+ float info_volume;
unsigned long info_timestamp;
std::string info_modelname;
diff --git a/src/core/inventory.cc b/src/core/inventory.cc
index c659178..8f8c41a 100644
--- a/src/core/inventory.cc
+++ b/src/core/inventory.cc
@@ -13,15 +13,24 @@ namespace core
/* ---- class Inventory -------------------------------------------- */
-Inventory::Inventory()
+Inventory::Inventory(const float capacity)
{
inventory_timestamp = 0;
+ inventory_capacity = capacity;
+ inventory_capacity_used = 0;
}
Inventory::~Inventory()
{
clear();
inventory_timestamp = 0;
+ inventory_capacity = 0;
+ inventory_capacity_used = 0;
+}
+
+void Inventory::set_capacity(const float capacity)
+{
+ inventory_capacity = capacity;
}
void Inventory::set_timestamp(const unsigned long timestamp)
@@ -31,6 +40,7 @@ void Inventory::set_timestamp(const unsigned long timestamp)
void Inventory::set_dirty()
{
+ recalculate();
inventory_timestamp = core::game()->timestamp();
}
@@ -75,6 +85,16 @@ void Inventory::clear()
delete item;
}
inventory_items.clear();
+ inventory_capacity_used = 0;
+}
+
+void Inventory::recalculate()
+{
+ inventory_capacity_used = 0;
+ for (Items::const_iterator it = inventory_items.begin(); it != inventory_items.end(); it++) {
+ const Item *item = (*it);
+ inventory_capacity_used += item->amount() * item->info()->volume();
+ }
}
} // namespace core
diff --git a/src/core/inventory.h b/src/core/inventory.h
index 0a412b0..aff9790 100644
--- a/src/core/inventory.h
+++ b/src/core/inventory.h
@@ -21,20 +21,59 @@ class Inventory
{
public:
/**
- * @brief type definition for the items in the inventory
+ * @brief type definition for items in the inventory
*/
typedef std::vector<Item *> Items;
/**
* @brief default constructor
*/
- Inventory();
+ Inventory(const float capacity = 0);
/**
* @brief default destructor
*/
~Inventory();
+ /* ---- inspectors ------------------------------------------------- */
+
+ /**
+ * @brief items in the inventory
+ */
+ inline Items &items() {
+ return inventory_items;
+ };
+
+ /**
+ * @brief return the timestamp
+ */
+ inline const unsigned long timestamp() const {
+ return inventory_timestamp;
+ }
+
+ /**
+ * @brief return the maximal inventory capacity, in cubic meters
+ */
+ inline const float capacity() const {
+ return inventory_capacity;
+ }
+
+ /**
+ * @brief return the used inventory capacity, in cubic meters
+ */
+ inline const float capacity_used() const {
+ return inventory_capacity_used;
+ }
+
+ /**
+ * @brief return the availableinventory capacity, in cubic meters
+ */
+ inline const float capacity_available() const {
+ return inventory_capacity - inventory_capacity_used;
+ }
+
+ /* ---- mutators --------------------------------------------------- */
+
/**
* @brief add an item to the inventory
*/
@@ -54,32 +93,40 @@ public:
* @brief search the inventory for a specific item type
*/
Item *find(const Info *info);
-
- inline Items &items() {
- return inventory_items;
- };
-
- /**
- * @brief return the timestamp
- */
- inline const unsigned long timestamp() const {
- return inventory_timestamp;
- }
-
+
/**
* @brief set the timestamp
*/
void set_timestamp(const unsigned long timestamp);
/**
- * @brief set the timestamp to the current game time
+ * @brief mark the inventory as dirty
+ * This method will set the timestamp to the current game time
+ * and will recalculate the available capacity
+ * @see recalculate()
*/
void set_dirty();
+ /**
+ * @brief set the maximal inventory capacity, in cubic meters
+ */
+ void set_capacity(const float capacity);
+
private:
+ // recalculate inventory capacity
+ void recalculate();
+
+ // items in the inventory
Items inventory_items;
+
// timestamp when inventory was last updated
unsigned long inventory_timestamp;
+
+ // maximum inventory capacity, in cubic meters
+ float inventory_capacity;
+
+ // current capacity used, in cubic meters
+ float inventory_capacity_used;
};
} // namsepace core
diff --git a/src/game/base/cargo.cc b/src/game/base/cargo.cc
index 689ae92..536a701 100644
--- a/src/game/base/cargo.cc
+++ b/src/game/base/cargo.cc
@@ -4,6 +4,8 @@
the terms and conditions of the GNU General Public License version 2
*/
+#include <assert.h>
+
#include "base/game.h"
#include "base/cargo.h"
#include "filesystem/inifile.h"
@@ -36,6 +38,7 @@ bool Cargo::init()
Cargo *cargo = 0;
std::string str;
long l;
+ float f;
while (cargoini.getline()) {
if (cargoini.got_key()) {
@@ -61,6 +64,11 @@ bool Cargo::init()
} else if (cargoini.got_key_long("price", l)) {
cargo->set_price(l);
continue;
+
+ } else if (cargoini.got_key_float("volume", f)) {
+ cargo->set_volume(f);
+ continue;
+
} else {
cargoini.unkown_key();
}
@@ -88,6 +96,7 @@ bool Cargo::init()
Cargo::Cargo() : core::Info(cargo_infotype)
{
+ set_volume(1);
}
Cargo::~Cargo()
@@ -148,7 +157,6 @@ void Cargo::sell(core::EntityControlable *seller, core::Entity *buyer, const int
negotiated_price = buyer_item->price();
}
-
seller_item->set_amount(seller_item->amount() - negotiated_amount);
seller->owner()->set_credits(seller->owner()->credits() + negotiated_price * negotiated_amount);
seller->inventory()->set_dirty();
@@ -184,40 +192,70 @@ void Cargo::buy(core::EntityControlable *buyer, core::Entity *seller, const int
if (!amount) {
return;
}
-
- core::Item *buyer_item = buyer->inventory()->find(this);
- core::Item *seller_item = seller->inventory()->find(this);
-
+
+ // seller is the station or planet
+ core::Item *seller_item = seller->inventory()->find(this);
if (!seller_item) {
if (buyer->owner()) {
buyer->owner()->send("^B" + seller->name() + " ^Bdoes not sell " + name());
}
return;
+ } else {
+ assert(seller_item->info() == this);
}
int negotiated_amount = amount;
int negotiated_price = seller_item->price();
long cash = buyer->owner()->credits();
- // negative means 'as much as possible'
- if (negotiated_amount < 0) {
- negotiated_amount = cash / negotiated_price;
+ // check if the player has enough cash
+ if (negotiated_price > 0) {
+
+ // negative amount means 'as much as possible'
+ if (negotiated_amount < 0) {
+ negotiated_amount = cash / negotiated_price;
+ }
+
+ // maximum amount the player can afford
+ if (cash < negotiated_amount * negotiated_price) {
+ negotiated_amount = cash / negotiated_price;
+ }
+
+ if (negotiated_amount < 1) {
+ buyer->owner()->send("^WCan not afford transaction!");
+ return;
+ }
}
- if (cash < negotiated_amount * negotiated_price) {
- negotiated_amount = cash / negotiated_price;
+ // check cargo size - ignore zero volume cargo
+ if (volume() > 0 ) {
+
+ // maximum cargo size
+ if (negotiated_amount * volume() > buyer->inventory()->capacity_available()) {
+ negotiated_amount = buyer->inventory()->capacity_available() / volume();
+ }
+
+ if (negotiated_amount < 1) {
+ buyer->owner()->send("^WNot enough cargo space available!");
+ return;
+ }
}
- if (!negotiated_amount) {
- buyer->owner()->send("^WCan not afford transaction!");
- return;
- }
- // TODO cargo size check
+ if (negotiated_amount < 0) {
+ // unlimited amount of zero-cost cargo
+ buyer->owner()->send("^WNo unlimited amounts of zero-cost cargo available!");
+ return;
+ }
+
+ // buyer is the player
+ core::Item *buyer_item = buyer->inventory()->find(this);
if (!buyer_item) {
buyer_item = new core::Item(this);
buyer->inventory()->add(buyer_item);
- }
+ } else {
+ assert(buyer_item->info() == this);
+ }
buyer_item->inc_amount(negotiated_amount);
buyer->owner()->set_credits(buyer->owner()->credits() - negotiated_price * negotiated_amount);
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc
index 23929ea..d51a119 100644
--- a/src/game/base/ship.cc
+++ b/src/game/base/ship.cc
@@ -39,14 +39,20 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) : core::EntityControlable(
ship_jumpdepart = 0;
if (owner) {
+ // this ship is owned by a player
set_owner(owner);
get_color().assign(owner->color());
get_color_second().assign(owner->color_second());
std::string str(aux::text_strip(owner->name()));
aux::to_label(str);
set_label(str);
+
+ // add an inventory
set_inventory(new core::Inventory());
+ inventory()->set_capacity(shipmodel->maxcargo());
+
} else {
+ set_name(shipmodel->name());
set_label(shipmodel->label());
}
diff --git a/src/game/base/shipmodel.h b/src/game/base/shipmodel.h
index c5da05e..ef7ff15 100644
--- a/src/game/base/shipmodel.h
+++ b/src/game/base/shipmodel.h
@@ -51,7 +51,7 @@ public:
return shipmodel_turnspeed;
}
- /// size of the cargo hold
+ /// size of the cargo hold, in cubic meters
inline const float maxcargo() const {
return shipmodel_maxcargo;
}
diff --git a/src/render/text.cc b/src/render/text.cc
index bfa1474..c45357d 100644
--- a/src/render/text.cc
+++ b/src/render/text.cc
@@ -9,8 +9,7 @@
#include "render/textures.h"
#include "sys/sys.h"
-namespace render
-{
+namespace render {
float Text::text_fontwidth = 16.0f;
float Text::text_fontheight = 24.0f;
@@ -84,25 +83,26 @@ void Text::setcolor(const char color)
}
}
-void Text::setfont(const char *texture, float width, float height)
+void Text::setfont(const char *texture, const float width, const float height)
{
- std::string tf("bitmaps/fonts/");
- tf.append(texture);
+ std::string texture_filename("bitmaps/fonts/");
+ texture_filename.append(texture);
- Textures::bind(tf, false);
+ Textures::bind(texture_filename, false);
text_fontwidth = width;
text_fontheight = height;
}
-void Text::draw(float x, float y, const char ascii)
+// draw a single character
+void Text::draw(const float x, const float y, const char ascii)
{
if (ascii != ' ') {
int row = (int) ascii >> 4;
int col = (int) ascii & 15;
- float frow = row * 0.0625f;
- float fcol = col * 0.0625f;
+ float frow = (float) row * 0.0625f;
+ float fcol = (float) col * 0.0625f;
gl::begin(gl::Quads);
@@ -122,10 +122,13 @@ void Text::draw(float x, float y, const char ascii)
}
}
-
-void Text::draw(float x, float y, const char *text)
+// draw one or more lines of text
+void Text::draw(const float x, const float y, const char *text)
{
const char *c = text;
+ float x1 = x;
+ float y1 = y;
+
while (*c) {
if (aux::is_base_color_code(c)) {
c++;
@@ -133,14 +136,17 @@ void Text::draw(float x, float y, const char *text)
} else if (aux::is_core_color_code(c)) {
c++;
gl::color(*core_color[(size_t)(*c - 'A')]);
+ } else if (*c == '\n' ) {
+ y1 += text_fontheight;
+ x1 = x;
} else {
- draw(x, y, *c);
- x += text_fontwidth;
+ draw(x1, y1, *c);
+ x1 += text_fontwidth;
}
c++;
}
}
-
+/*
void Text::draw(float x, float y, std::stringstream & textstream)
{
char line[MAXCMDSIZE];
@@ -150,10 +156,6 @@ void Text::draw(float x, float y, std::stringstream & textstream)
}
textstream.clear();
}
+*/
-void Text::draw(float x, float y, const std::string & text)
-{
- draw(x, y, text.c_str());
-}
-
-}
+} // namespace render
diff --git a/src/render/text.h b/src/render/text.h
index 631f1cd..3f743ae 100644
--- a/src/render/text.h
+++ b/src/render/text.h
@@ -26,23 +26,34 @@ public:
/// assign system colors
static void assign_color(const char c, const math::Color &color);
- /// draw a text string
- static void draw(float x, float y, const std::string & text);
-
- /// draw a text string
-
- static void draw(float x, float y, const char *text);
- /// draw a text stream
- /** If the stream contains multiple lines, each new line will be
- * drawn at the same x value. The stream is cleared after reading
- */
- static void draw(float x, float y, std::stringstream & textstream);
+ /**
+ * @brief draw a single character
+ */
+ static void draw(const float x, const float y, const char ascii);
+
+ /**
+ * @brief draw a text string
+ * end-of-characters will be respected
+ */
+ static void draw(const float x, const float y, const char *text);
+
+ /**
+ * @brief draw a text string
+ * end-of-characters will be respected
+ */
+ inline static void draw(const float x, const float y, const std::string & text) {
+ draw(x, y, text.c_str());
+ }
- /// draw a character
- static void draw(float x, float y, const char ascii);
+ /* *
+ * @brief draw a text stream
+ * If the stream contains multiple lines, each new line will be
+ * drawn at the same x value. The stream is cleared after reading
+ */
+ //static void draw(float x, float y, std::stringstream & textstream);
/// set the font
- static void setfont(const char *texture, float width, float height);
+ static void setfont(const char *texture, const float width, const float height);
/// set the color
static void setcolor(const char color);
diff --git a/src/ui/Makefile.am b/src/ui/Makefile.am
index d12571d..e62a5dd 100644
--- a/src/ui/Makefile.am
+++ b/src/ui/Makefile.am
@@ -8,13 +8,14 @@ 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 listitem.h listview.h menu.h modelview.h paint.h \
- palette.h scrollpane.h toolbar.h ui.h widget.h \
- window.h
+ iconbutton.h inputbox.h label.h listitem.h listview.h \
+ menu.h modelview.h paint.h palette.h plaintext.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 listitem.cc listview.cc \
- menu.cc modelview.cc paint.cc palette.cc scrollpane.cc \
+libui_la_SOURCES = bitmap.cc button.cc console.cc container.cc font.cc \
+ iconbutton.cc inputbox.cc label.cc listitem.cc listview.cc \
+ menu.cc modelview.cc paint.cc palette.cc plaintext.cc scrollpane.cc \
toolbar.cc ui.cc widget.cc window.cc
+
libui_la_LDFLAGS = -avoid-version -no-undefined
diff --git a/src/ui/bitmap.cc b/src/ui/bitmap.cc
index 4af7714..5e19435 100644
--- a/src/ui/bitmap.cc
+++ b/src/ui/bitmap.cc
@@ -51,8 +51,8 @@ void Bitmap::set_color(const math::Color & color)
void Bitmap::draw_background()
{
if (bitmap_texture.size()) {
- paint::color(bitmap_color);
- paint::bitmap(global_location(), size(), bitmap_texture);
+ Paint::set_color(bitmap_color);
+ Paint::draw_bitmap(global_location(), size(), bitmap_texture);
}
}
diff --git a/src/ui/button.cc b/src/ui/button.cc
index 9196b90..95158a2 100644
--- a/src/ui/button.cc
+++ b/src/ui/button.cc
@@ -56,11 +56,11 @@ void Button::draw_border()
if (t > 0.5)
t = 1 - t;
color.a = 0.5f + t;
- paint::color(color);
+ Paint::set_color(color);
} else
- paint::color(palette()->border());
+ Paint::set_color(palette()->border());
- paint::border(global_location(), size());
+ Paint::draw_border(global_location(), size());
}
void Button::draw()
@@ -69,11 +69,11 @@ void Button::draw()
return;
if (has_mouse_focus())
- paint::color(palette()->highlight());
+ Paint::set_color(palette()->highlight());
else
- paint::color(palette()->foreground());
+ Paint::set_color(palette()->foreground());
- paint::label(global_location(), size(), font(), text(), alignment());
+ Paint::draw_label(global_location(), size(), font(), text(), alignment());
}
bool Button::on_keypress(const int key, const unsigned int modifier)
diff --git a/src/ui/console.cc b/src/ui/console.cc
index 6ce3593..7bd308e 100644
--- a/src/ui/console.cc
+++ b/src/ui/console.cc
@@ -194,13 +194,13 @@ void Console::draw()
math::Color fancy(palette()->fancy());
fancy.a = 0.5f;
- paint::color(fancy);
+ Paint::set_color(fancy);
std::string version(core::name() + ' ' + core::version());
s.assign(version.size() * font()->width(), font()->height());
math::Vector2f l(global_location());
l[0] += width() - s.width() - 4;
l[1] += height() - s.height() - 4;
- paint::text(l, s, font(), version);
+ Paint::draw_text(l, font(), version);
}
void Console::save_history()
diff --git a/src/ui/container.cc b/src/ui/container.cc
index 31d7549..d252c73 100644
--- a/src/ui/container.cc
+++ b/src/ui/container.cc
@@ -45,8 +45,8 @@ void Container::resize()
void Container::draw_border()
{
- paint::color(palette()->foreground());
- paint::border(global_location(), size());
+ Paint::set_color(palette()->foreground());
+ Paint::draw_border(global_location(), size());
}
}
diff --git a/src/ui/iconbutton.cc b/src/ui/iconbutton.cc
index ffdafe0..87203ee 100644
--- a/src/ui/iconbutton.cc
+++ b/src/ui/iconbutton.cc
@@ -79,14 +79,14 @@ void IconButton::draw()
return;
if (disabled()) {
- paint::color(palette()->disabled());
+ Paint::set_color(palette()->disabled());
} else if (has_mouse_focus()) {
- paint::color(palette()->highlight());
+ Paint::set_color(palette()->highlight());
} else {
- paint::color(palette()->foreground());
+ Paint::set_color(palette()->foreground());
}
- paint::bitmap(location(), size(), icon());
+ Paint::draw_bitmap(location(), size(), icon());
}
void IconButton::draw_border()
@@ -98,8 +98,8 @@ void IconButton::draw_border()
if (t > 0.5)
t = 1 - t;
color.a = 0.5f + t;
- paint::color(color);
- paint::border(global_location(), size());
+ Paint::set_color(color);
+ Paint::draw_border(global_location(), size());
}
}
diff --git a/src/ui/inputbox.cc b/src/ui/inputbox.cc
index 6f493e2..5656cb9 100644
--- a/src/ui/inputbox.cc
+++ b/src/ui/inputbox.cc
@@ -71,14 +71,14 @@ void InputBox::draw()
size_t text_width = (size_t) floorf(width() / font()->width());
size_t prompt_width = aux::text_length(input_prompt);
math::Vector2f v(global_location());
- paint::color(palette()->text());
+ Paint::set_color(palette()->text());
// draw the prompt
if (prompt_width) {
- paint::text(v, size(), font(), input_prompt);
+ Paint::draw_text(v, font(), input_prompt);
v[0] += prompt_width * font()->width();
}
- paint::color(palette()->text());
+ Paint::set_color(palette()->text());
// draw the part before the cursor
std::string firstpart(input_text.substr(0, input_pos));
@@ -98,7 +98,7 @@ void InputBox::draw()
while (*c && draw_width > text_width - prompt_width - 1) {
if (aux::is_color_code(c)) {
c++;
- paint::color_code(*c);
+ Paint::set_system_color(*c);
} else {
draw_width--;
}
@@ -106,14 +106,14 @@ void InputBox::draw()
}
if (*c) {
- paint::text(v, size(), font(), std::string(c));
+ Paint::draw_text(v, font(), std::string(c));
}
// draw the part behind the cursor
v[0] += draw_width * font()->width();
if (input_pos < input_text.size()) {
if (input_pos > 1 && aux::is_color_code(input_text.c_str() + input_pos - 1)) {
- paint::color_code(input_text[input_pos]);
+ Paint::set_system_color(input_text[input_pos]);
}
// limit to width
std::string secondpart;
@@ -128,18 +128,18 @@ void InputBox::draw()
c++;
}
- paint::text(v, size(), font(), secondpart);
+ Paint::draw_text(v, font(), secondpart);
}
// draw the cursor
if (has_input_focus() && (core::application()->time() - ::floorf(core::application()->time())) < 0.5f) {
std::string cursor("^B");
cursor += (char) 11;
- paint::text(v, size(), font(), cursor);
+ Paint::draw_text(v, font(), cursor);
}
// reset color
- paint::color(palette()->foreground());
+ Paint::set_color(palette()->foreground());
}
bool InputBox::on_keypress(const int key, const unsigned int modifier)
diff --git a/src/ui/label.cc b/src/ui/label.cc
index b6f72c7..ef5b14f 100644
--- a/src/ui/label.cc
+++ b/src/ui/label.cc
@@ -58,8 +58,8 @@ void Label::draw()
if (!label_text.size())
return;
- paint::color(palette()->foreground());
- paint::label(global_location(), size(), font(), text(), alignment());
+ Paint::set_color(palette()->foreground());
+ Paint::draw_label(global_location(), size(), font(), text(), alignment());
}
}
diff --git a/src/ui/label.h b/src/ui/label.h
index 2a38273..f187520 100644
--- a/src/ui/label.h
+++ b/src/ui/label.h
@@ -13,7 +13,9 @@
namespace ui
{
-/// a widget displaying centered text
+/**
+ * @brief a widget displaying a single line of text
+ */
class Label : public Widget
{
public:
diff --git a/src/ui/listitem.cc b/src/ui/listitem.cc
index 601d5a8..ff9ad18 100644
--- a/src/ui/listitem.cc
+++ b/src/ui/listitem.cc
@@ -30,11 +30,11 @@ void ListItem::draw_border()
if (t > 0.5)
t = 1 - t;
color.a = 0.5f + t;
- paint::color(color);
- paint::border(global_location(), size());
+ Paint::set_color(color);
+ Paint::draw_border(global_location(), size());
} else if ((static_cast<ListView *>(parent()))->selected() == this) {
- paint::color(palette()->border());
- paint::border(global_location(), size());
+ Paint::set_color(palette()->border());
+ Paint::draw_border(global_location(), size());
}
}
@@ -44,11 +44,11 @@ void ListItem::draw()
return;
if ( has_mouse_focus() || ((static_cast<ListView *>(parent()))->selected() == this)) {
- paint::color(palette()->highlight());
+ Paint::set_color(palette()->highlight());
} else {
- paint::color(palette()->foreground());
+ Paint::set_color(palette()->foreground());
}
- paint::label(global_location(), size(), font(), text(), alignment());
+ Paint::draw_label(global_location(), size(), font(), text(), alignment());
}
bool ListItem::on_keypress(const int key, const unsigned int modifier)
@@ -64,4 +64,4 @@ bool ListItem::on_keypress(const int key, const unsigned int modifier)
return false;
}
-} // namespace ui \ No newline at end of file
+} // namespace ui
diff --git a/src/ui/modelview.cc b/src/ui/modelview.cc
index 18cc091..c00cb07 100755
--- a/src/ui/modelview.cc
+++ b/src/ui/modelview.cc
@@ -35,17 +35,14 @@ void ModelView::print(const size_t indent) const
con_print << aux::pad_left(marker, indent*2) << label() << " \"" << modelname() << "\"" << std::endl;
}
-void ModelView::set_modelname(const std::string & modelname)
-{
- modelview_modelname.assign(modelname);
-}
-
void ModelView::set_modelname(const char *modelname)
{
if (modelname)
modelview_modelname.assign(modelname);
else
modelview_modelname.clear();
+
+ set_background(false);
}
void ModelView::set_color(const math::Color & color)
@@ -76,16 +73,23 @@ bool ModelView::on_keypress(const int key, const unsigned int modifier)
return false;
}
+void ModelView::draw_background()
+{
+ Paint::set_color(1.0f, 1.0f, 1.0f);
+ Paint::draw_bitmap(global_location(), size(), "textures/common/notex");
+}
+
void ModelView::draw()
{
if (!modelview_modelname.size()) {
return;
}
- paint::color(1.0f, 1.0f, 1.0f);
+ Paint::set_color(1.0f, 1.0f, 1.0f);
model::Model *model = model::Model::load(modelview_modelname);
if (!model) {
- paint::bitmap(global_location(), size(), "bitmaps/notex");
+ modelview_modelname.clear();
+ set_background(true);
return;
}
@@ -102,6 +106,8 @@ void ModelView::draw()
gl::enable(GL_CULL_FACE); // enable culling
gl::enable(GL_COLOR_MATERIAL); // enable color tracking
+
+ // FIXME - initialize lights
gl::enable(GL_LIGHTING);
// enable vertex arrays
@@ -130,8 +136,8 @@ void ModelView::draw()
void ModelView::draw_border()
{
- paint::color(palette()->foreground());
- paint::border(global_location(), size());
+ Paint::set_color(palette()->foreground());
+ Paint::draw_border(global_location(), size());
}
}
diff --git a/src/ui/modelview.h b/src/ui/modelview.h
index 54799f3..89b6554 100755
--- a/src/ui/modelview.h
+++ b/src/ui/modelview.h
@@ -26,8 +26,11 @@ public:
return modelview_color;
}
- void set_modelname(const std::string & modelname);
void set_modelname(const char *modelname);
+
+ inline void set_modelname(const std::string & modelname) {
+ set_modelname(modelname.c_str());
+ }
void set_color(const math::Color &color);
@@ -47,7 +50,10 @@ protected:
virtual void draw();
/// draw border
- void draw_border();
+ virtual void draw_border();
+
+ /// draw border
+ virtual void draw_background();
/// keypress event handler
virtual bool on_keypress(const int key, const unsigned int modifier);
diff --git a/src/ui/paint.cc b/src/ui/paint.cc
index b3d6197..6531b0e 100644
--- a/src/ui/paint.cc
+++ b/src/ui/paint.cc
@@ -11,90 +11,100 @@
#include "render/textures.h"
#include "ui/paint.h"
-namespace ui
-{
-
-// contains the interface between the user interface and the render library
-namespace paint
-{
+namespace ui {
-void assign_color(const char c, const math::Color &color)
+void Paint::set_color(float r, float g, float b, float a)
{
- render::Text::assign_color(c, color);
+ gl::color(r, g, b, a);
}
-void color(float r, float g, float b, float a)
+void Paint::set_color(math::Color const & color)
{
- gl::color(r, g, b, a);
+ gl::color(color);
}
-void color(math::Color const & color)
+void Paint::assign_system_color(const char c, const math::Color &color)
{
- gl::color(color);
+ render::Text::assign_color(c, color);
}
-void color_code(const char c)
+void Paint::set_system_color(const char c)
{
render::Text::setcolor(c);
}
-void border(const math::Vector2f &location, const math::Vector2f &size)
+void Paint::draw_border(const math::Vector2f &global_location, const math::Vector2f &size)
{
using namespace gl;
begin(LineLoop);
- vertex(location.x(), location.y());
- vertex(location.x() + size.width(), location.y());
- vertex(location.x() + size.width(), location.y() + size.height());
- vertex(location.x(), location.y() + size.height());
+ vertex(global_location.x(), global_location.y());
+ vertex(global_location.x() + size.width(), global_location.y());
+ vertex(global_location.x() + size.width(), global_location.y() + size.height());
+ vertex(global_location.x(), global_location.y() + size.height());
end();
}
-void rectangle(const math::Vector2f &location, const math::Vector2f &size)
+void Paint::draw_rectangle(const math::Vector2f &global_location, const math::Vector2f &size)
{
using namespace gl;
begin(Quads);
- vertex(location.x(), location.y());
- vertex(location.x() + size.width(), location.y());
- vertex(location.x() + size.width(), location.y() + size.height());
- vertex(location.x(), location.y() + size.height());
+ vertex(global_location.x(), global_location.y());
+ vertex(global_location.x() + size.width(), global_location.y());
+ vertex(global_location.x() + size.width(), global_location.y() + size.height());
+ vertex(global_location.x(), global_location.y() + size.height());
end();
}
// draw a bitmap
-void bitmap(const math::Vector2f &location, const math::Vector2f &size, std::string const &texture)
+void Paint::draw_bitmap(const math::Vector2f &global_location, const math::Vector2f &size, const std::string &texture)
{
- render::Textures::bind("bitmaps/" + texture);
+ render::Textures::bind(texture);
gl::enable(GL_TEXTURE_2D);
gl::begin(gl::Quads);
glTexCoord2f(0.0f, 0.0f);
- gl::vertex(location.x(), location.y());
+ gl::vertex(global_location.x(), global_location.y());
glTexCoord2f(1.0f, 0.0f);
- gl::vertex(location.x() + size.width(), location.y());
+ gl::vertex(global_location.x() + size.width(), global_location.y());
glTexCoord2f(1.0f, 1.0f);
- gl::vertex(location.x() + size.width(), location.y() + size.height());
+ gl::vertex(global_location.x() + size.width(), global_location.y() + size.height());
glTexCoord2f(0.0f, 1.0f);
- gl::vertex(location.x(), location.y() + size.height());
+ gl::vertex(global_location.x(), global_location.y() + size.height());
gl::end();
gl::disable(GL_TEXTURE_2D);
}
+
+// draw unaligned text
+void Paint::draw_text(const math::Vector2f &global_location, const Font *font, const std::string &text)
+{
+ render::Text::setfont(font->name().c_str(), font->width(), font->height());
+
+ // enable OpenGL textures
+ gl::enable(GL_TEXTURE_2D);
+
+ render::Text::draw(global_location.x(), global_location.y(), text);
+
+ // disable OpenGL textures
+ gl::disable(GL_TEXTURE_2D);
+}
+
// draw aligned text
-void label(const math::Vector2f &location, const math::Vector2f &size, const Font *font, const std::string &text, unsigned int align)
+void Paint::draw_label(const math::Vector2f &global_location, const math::Vector2f &size, const Font *font, const std::string &text, const unsigned int alignment)
{
- unsigned int align_horizontal = (align & 0x000F);
+ unsigned int align_horizontal = (alignment & 0x000F);
if (!align_horizontal)
align_horizontal = AlignLeft;
- unsigned int align_vertical = (align & 0x00F0);
+ unsigned int align_vertical = (alignment & 0x00F0);
if (!align_vertical)
align_vertical = AlignTop;
@@ -110,7 +120,7 @@ void label(const math::Vector2f &location, const math::Vector2f &size, const Fon
float text_width = (float) aux::text_strip(text).size() * font->width();
// calculate drawing position
- math::Vector2f v(location);
+ math::Vector2f v(global_location);
switch (align_horizontal) {
case AlignLeft:
@@ -143,20 +153,7 @@ void label(const math::Vector2f &location, const math::Vector2f &size, const Fon
}
-// draw unaligned text
-void text(const math::Vector2f &location, const math::Vector2f &size, const Font *font, const std::string &text)
-{
- render::Text::setfont(font->name().c_str(), font->width(), font->height());
-
- // enable OpenGL textures
- gl::enable(GL_TEXTURE_2D);
-
- render::Text::draw(location.x(), location.y(), text);
-
- // disable OpenGL textures
- gl::disable(GL_TEXTURE_2D);
-}
-
+/*
// draw unaligned text
void text(const math::Vector2f &location, const math::Vector2f &size, const Font *font, std::stringstream & textstream)
{
@@ -171,7 +168,6 @@ void text(const math::Vector2f &location, const math::Vector2f &size, const Font
// disable OpenGL textures
gl::disable(GL_TEXTURE_2D);
}
+*/
-}
-
-}
+} //namespace ui
diff --git a/src/ui/paint.h b/src/ui/paint.h
index 1d28574..2c48a35 100644
--- a/src/ui/paint.h
+++ b/src/ui/paint.h
@@ -9,46 +9,46 @@
#include "ui/widget.h"
-namespace ui
-{
-
-/// low-level widget paint functions
-namespace paint
-{
+namespace ui {
-/// assign system colors
-void assign_color(const char c, const math::Color &color);
+/**
+ * @brief low-level widget paint functions
+ * This class contains the interface between the user interface and the render library
+ */
-/// set paint color
-void color(float r = 0.0f, float g = 0.0f, float b = 0.0f, float a = 1.0f);
-
-/// set paint color
-void color(math::Color const & color);
+class Paint
+{
+public:
+ /// set paint color to RGB value
+ static void set_color(float r = 0.0f, float g = 0.0f, float b = 0.0f, float a = 1.0f);
-/// set paint color
-void color_code(const char c);
+ /// set paint color to RGB value
+ static void set_color(math::Color const & color);
-/// draw a border
-void border(const math::Vector2f &location, const math::Vector2f &size);
+ /// set paint color to system color code
+ static void set_system_color(const char c);
-/// draw a rectangle
-void rectangle(const math::Vector2f &location, const math::Vector2f &size);
+ /// assign system color code
+ static void assign_system_color(const char c, const math::Color &color);
-/// draw a rectangular bitmap
-void bitmap(const math::Vector2f &location, const math::Vector2f &size, std::string const &texture);
+ /// draw a border
+ static void draw_border(const math::Vector2f &global_location, const math::Vector2f &size);
-/// draw aligned text
-void label(const math::Vector2f &location, const math::Vector2f &size, const Font *font, const std::string &text, unsigned int align = AlignCenter);
+ /// draw a rectangle
+ static void draw_rectangle(const math::Vector2f &global_location, const math::Vector2f &size);
-/// draw unaligned text
-void text(const math::Vector2f &location, const math::Vector2f &size, const Font *font, const std::string &text);
+ /// draw a rectangular bitmap
+ static void draw_bitmap(const math::Vector2f &global_location, const math::Vector2f &size, const std::string &texture);
-/// draw unaligned text
-void text(const math::Vector2f &location, const math::Vector2f &size, const Font *font, std::stringstream & textstream);
+ /// draw unaligned text
+ static void draw_text(const math::Vector2f &global_location, const Font *font, const std::string &text);
+
+ /// draw aligned text
+ static void draw_label(const math::Vector2f &global_location, const math::Vector2f &size, const Font *font, const std::string &text, const unsigned int alignment = AlignCenter);
-}
+};
-}
+} // namespace ui
#endif // __INCLUDED_UI_PAINT_H__
diff --git a/src/ui/plaintext.cc b/src/ui/plaintext.cc
new file mode 100644
index 0000000..33e10fc
--- /dev/null
+++ b/src/ui/plaintext.cc
@@ -0,0 +1,58 @@
+/*
+ ui/text.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/paint.h"
+#include "ui/plaintext.h"
+
+namespace ui
+{
+
+PlainText::PlainText(Widget *parent, const char *text) : Widget(parent)
+{
+ set_label("text");
+ set_text(text);
+}
+
+PlainText::~PlainText()
+{
+}
+
+void PlainText::print(const size_t indent) const
+{
+ std::string marker("");
+ con_print << aux::pad_left(marker, indent*2) << label() << " \"" << text() << "\"" << std::endl;
+}
+
+void PlainText::clear()
+{
+ widget_text.clear();
+}
+
+void PlainText::set_text(const char *text)
+{
+ if (text)
+ widget_text.assign(text);
+ else
+ widget_text.clear();
+}
+
+void PlainText::set_text(const std::string &text)
+{
+ widget_text.assign(text);
+}
+
+void PlainText::draw()
+{
+ if (!text().size())
+ return;
+
+ Paint::set_color(palette()->foreground());
+ Paint::draw_text(global_location(), font(), text());
+}
+
+}
+
+
diff --git a/src/ui/plaintext.h b/src/ui/plaintext.h
new file mode 100644
index 0000000..b2fd7fb
--- /dev/null
+++ b/src/ui/plaintext.h
@@ -0,0 +1,63 @@
+/*
+ ui/text.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_PLAINTEXT_H__
+#define __INCLUDED_UI_PLAINTEXT_H__
+
+#include <string>
+#include "ui/widget.h"
+
+namespace ui
+{
+
+/**
+ * @brief a widget displaying unaligned text without wrapping
+ */
+class PlainText : public Widget
+{
+public:
+ PlainText(Widget *parent, const char *text = 0);
+ ~PlainText();
+
+ /**
+ * @brief the text the widget is currently displaying
+ */
+ inline const std::string & text() const {
+ return widget_text;
+ }
+
+ /**
+ * @brief set the text to be displayed
+ * @param text text, can contain end-of-line characters
+ */
+ void set_text(const std::string & text);
+
+ /**
+ * @brief set the text to be displayed
+ * @param text text, can contain end-of-line characters
+ */
+ void set_text(const char *text);
+
+ /**
+ * @brief clear the text
+ */
+ void clear();
+
+ /// print widget description
+ virtual void print(const size_t indent) const;
+
+protected:
+ /// draw the widget
+ virtual void draw();
+
+private:
+ std::string widget_text;
+};
+
+}
+
+#endif // __INCLUDED_UI_PLAINTEXT_H__
+
diff --git a/src/ui/ui.cc b/src/ui/ui.cc
index a6d54ab..5faf9fd 100644
--- a/src/ui/ui.cc
+++ b/src/ui/ui.cc
@@ -360,12 +360,12 @@ void UI::apply_render_options()
{
//con_debug << " initializing text colors" << std::endl;
// apply palette colors
- paint::assign_color('N', palette()->text());
- paint::assign_color('D', palette()->debug());
- paint::assign_color('B', palette()->bold());
- paint::assign_color('F', palette()->fancy());
- paint::assign_color('W', palette()->warning());
- paint::assign_color('E', palette()->error());
+ Paint::assign_system_color('N', palette()->text());
+ Paint::assign_system_color('D', palette()->debug());
+ Paint::assign_system_color('B', palette()->bold());
+ Paint::assign_system_color('F', palette()->fancy());
+ Paint::assign_system_color('W', palette()->warning());
+ Paint::assign_system_color('E', palette()->error());
}
@@ -567,11 +567,12 @@ void UI::draw_pointer()
} else {
c.a = 0.5f;
}
- paint::color(c);
+ Paint::set_color(c);
+
math::Vector2f pos(mouse_cursor.x() - pointer_size * 0.5f, mouse_cursor.y() - pointer_size * 0.5f);
math::Vector2f s(pointer_size, pointer_size);
- std::string texture("pointers/");
+ std::string texture("bitmaps/pointers/");
texture.append(mouse_pointer_bitmap);
if (mouse_pointer_animated) {
@@ -584,7 +585,7 @@ void UI::draw_pointer()
gl::translate(-mouse_cursor.x(), -mouse_cursor.y(), 0);
}
- paint::bitmap(pos, s, texture);
+ Paint::draw_bitmap(pos, s, texture);
if (mouse_pointer_animated) {
gl::pop();
diff --git a/src/ui/widget.cc b/src/ui/widget.cc
index 79281a1..b3aa27c 100644
--- a/src/ui/widget.cc
+++ b/src/ui/widget.cc
@@ -432,20 +432,20 @@ bool Widget::on_emit(Widget *sender, const Event event, void *data)
void Widget::draw_debug_border()
{
- paint::color(1.0f, 0.0f, 1.0f, 0.5f);
- paint::border(global_location(), size());
+ Paint::set_color(1.0f, 0.0f, 1.0f, 0.5f);
+ Paint::draw_border(global_location(), size());
}
void Widget::draw_background()
{
- paint::color(palette()->background());
- paint::rectangle(global_location(), size());
+ Paint::set_color(palette()->background());
+ Paint::draw_rectangle(global_location(), size());
}
void Widget::draw_border()
{
- paint::color(palette()->border());
- paint::border(global_location(), size());
+ Paint::set_color(palette()->border());
+ Paint::draw_border(global_location(), size());
}
void Widget::draw()
diff --git a/src/ui/window.cc b/src/ui/window.cc
index 0e545be..8571eec 100644
--- a/src/ui/window.cc
+++ b/src/ui/window.cc
@@ -47,8 +47,8 @@ void Window::clear_previous()
void Window::draw_border()
{
- paint::color(palette()->border());
- paint::border(global_location(), size());
+ Paint::set_color(palette()->border());
+ Paint::draw_border(global_location(), size());
}
}