From 20a09d5edee690f86e7d0bae343086f6a46ffed4 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Mon, 14 Feb 2011 17:41:49 +0200 Subject: new hotbar, more minecraft-like --- src/guiInventoryMenu.cpp | 54 +++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 19 deletions(-) (limited to 'src/guiInventoryMenu.cpp') diff --git a/src/guiInventoryMenu.cpp b/src/guiInventoryMenu.cpp index 102a0ae72..ef795a5f4 100644 --- a/src/guiInventoryMenu.cpp +++ b/src/guiInventoryMenu.cpp @@ -21,21 +21,16 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "guiInventoryMenu.h" #include "constants.h" -void drawInventoryItem(gui::IGUIEnvironment* env, +void drawInventoryItem(video::IVideoDriver *driver, + gui::IGUIFont *font, InventoryItem *item, core::rect rect, const core::rect *clip) { - gui::IGUISkin* skin = env->getSkin(); - if (!skin) + if(item == NULL) return; - video::IVideoDriver* driver = env->getVideoDriver(); video::ITexture *texture = NULL; - - if(item != NULL) - { - texture = item->getImage(); - } + texture = item->getImage(); if(texture != NULL) { @@ -48,22 +43,28 @@ void drawInventoryItem(gui::IGUIEnvironment* env, } else { - video::SColor bgcolor(128,128,128,128); + video::SColor bgcolor(255,50,50,128); driver->draw2DRectangle(bgcolor, rect, clip); } - if(item != NULL) + if(font != NULL) { - gui::IGUIFont *font = skin->getFont(); std::string text = item->getText(); if(font && text != "") { - core::rect rect2(rect.UpperLeftCorner, - (core::dimension2d(rect.getWidth(), 15))); + v2u32 dim = font->getDimension(narrow_to_wide(text).c_str()); + v2s32 sdim(dim.X,dim.Y); + + core::rect rect2( + /*rect.UpperLeftCorner, + core::dimension2d(rect.getWidth(), 15)*/ + rect.LowerRightCorner - sdim, + sdim + ); video::SColor bgcolor(128,0,0,0); driver->draw2DRectangle(bgcolor, rect2, clip); - + font->draw(text.c_str(), rect2, video::SColor(255,255,255,255), false, false, clip); @@ -184,10 +185,16 @@ void GUIInventoryMenu::drawList(const ListDrawSpec &s) { video::IVideoDriver* driver = Environment->getVideoDriver(); + // Get font + gui::IGUIFont *font = NULL; + gui::IGUISkin* skin = Environment->getSkin(); + if (skin) + font = skin->getFont(); + InventoryList *ilist = m_inventory->getList(s.listname); core::rect imgrect(0,0,imgsize.X,imgsize.Y); - + for(s32 i=0; idraw2DRectangle(video::SColor(255,255,0,0), core::rect(rect.UpperLeftCorner - v2s32(2,2), rect.LowerRightCorner + v2s32(2,2)), - &AbsoluteClippingRect); + &AbsoluteClippingRect); + } + + if(item) + { + drawInventoryItem(driver, font, item, + rect, &AbsoluteClippingRect); + } + else + { + video::SColor bgcolor(255,128,128,128); + driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect); } - drawInventoryItem(Environment, item, - rect, &AbsoluteClippingRect); } } -- cgit v1.2.3