From 4228d5f7eec817cb0b0ceb3128668129002914d8 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 7 May 2012 19:25:11 +0200 Subject: [PATCH] Made Progress Bars working --- src/CMakeLists.txt | 1 + src/IProgressBar.cpp | 9 +-------- src/IProgressBar.h | 8 ++------ src/game.cpp | 18 ++++++++++++------ 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 891ece6..532272a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -277,6 +277,7 @@ set(minetest_SRCS filecache.cpp tile.cpp game.cpp + IProgressBar.cpp ) # Server sources diff --git a/src/IProgressBar.cpp b/src/IProgressBar.cpp index 248ec17..a72caac 100644 --- a/src/IProgressBar.cpp +++ b/src/IProgressBar.cpp @@ -1,11 +1,10 @@ #include "IProgressBar.h" -IProgressBar::IProgressBar(IGUIEnvironment * guienv,const core::rect& rectangle,s32 id,IGUIElement * parent, IGUIFont * font) : IGUIElement(EGUIET_ELEMENT,guienv,parent,id,rectangle) +IProgressBar::IProgressBar(IGUIEnvironment * guienv,const core::rect& rectangle,s32 id,IGUIElement * parent) : IGUIElement(EGUIET_ELEMENT,guienv,parent,id,rectangle) { total = rectangle.LowerRightCorner.X - rectangle.UpperLeftCorner.X; gui = guienv; bar = rectangle; - textfont = font; if(parent == 0) guienv->getRootGUIElement()->addChild(this); //Ensure that draw method is called @@ -14,17 +13,12 @@ IProgressBar::IProgressBar(IGUIEnvironment * guienv,const core::rect& recta emptycolor.set(255,0,0,0); border = bar; this->setProgress(0); - this->setText(""); } void IProgressBar::setColors(irr::video::SColor progress,irr::video::SColor filling) { fillcolor = progress; emptycolor = filling; } -void setText(std::string s) -{ - text = s; -} void IProgressBar::addBorder(irr::s32 size,irr::video::SColor color) { bordercolor = color; @@ -54,5 +48,4 @@ void IProgressBar::draw() vdriver->draw2DRectangle(bordercolor,border); vdriver->draw2DRectangle(fillcolor,tofill); vdriver->draw2DRectangle(emptycolor,empty); - textfont->draw(text, position, video::SColor color, false, true, bar) } diff --git a/src/IProgressBar.h b/src/IProgressBar.h index 8fe1d18..8db5dde 100644 --- a/src/IProgressBar.h +++ b/src/IProgressBar.h @@ -1,6 +1,7 @@ #ifndef IPROGRESSBAR_HEADER #define IPROGRESSBAR_HEADER #include "common_irrlicht.h" +#include using namespace irr; using namespace core; @@ -10,7 +11,7 @@ class IProgressBar : public IGUIElement { public: - IProgressBar(IGUIEnvironment * guienv,const core::rect& rectangle,s32 id=-1,IGUIElement * parent=0, IGUIFont * font=0); + IProgressBar(IGUIEnvironment * guienv,const core::rect& rectangle,s32 id=-1,IGUIElement * parent=0); /*Set percentage in positive percentual (0~100). Please note that a call to this function with others values, will set the progress bar to 0.*/ @@ -21,9 +22,6 @@ public: /*Allow you to add a "border" into your bar. You MUST specify the size (of course in pixel) of the border. You can also pass a color parameter (Black by default)*/ void addBorder(irr::s32 size,irr::video::SColor color = irr::video::SColor(255,0,0,0)); - - /*Set the Text of the Progress Bar*/ - void setText(std::string s); virtual void draw(); @@ -36,13 +34,11 @@ private: rect border; //Border rect tofill; //Percentage indicator rect empty; //"Empty" indicator - std::string text; // Text in the Progress Bar irr::video::SColor fillcolor; irr::video::SColor emptycolor; irr::video::SColor bordercolor; irr::video::IVideoDriver * vdriver; - irr::gui::IGUIFont * textfont; }; #endif diff --git a/src/game.cpp b/src/game.cpp index a1f55d5..35ce9a9 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1096,21 +1096,27 @@ void the_game( ss<<(client.nodedefReceived()?L"[X]":L"[ ]"); ss< 90) { + ss<getScreenSize(); core::vector2d textsize_u = font->getDimension(ss.str().c_str()); core::vector2d textsize(textsize_u.X,textsize_u.Y); core::vector2d center(screensize.X/2, screensize.Y/2); - core::rect progrect(center - textsize/2, (center + textsize/2) + screensize.Y/16); - IProgressBar * pb = new IProgressBar(guienv,progrect,-1,0,font); + core::rect progrect(center - textsize/2, center + textsize/2); + IProgressBar * pb = new IProgressBar(guienv,progrect); pb->setProgress((irr::u32)(client.mediaReceiveProgress()*100+0.5)); - pb->addBorder(1); - pb->setText("Media"); + pb->addBorder(2, irr::video::SColor(255,105,105,105)); + pb->setColors(irr::video::SColor(255,19,136,8), irr::video::SColor(255,128,128,128)); pb->drop(); + draw_load_screen(ss.str(), driver, font, false); driver->endScene(); + pb->remove(); // Delay a bit sleep_ms(1000*frametime);