Made Progress Bars working

master
sfan5 2012-05-07 19:25:11 +02:00
parent 540f50aa53
commit 4228d5f7ee
4 changed files with 16 additions and 20 deletions

View File

@ -277,6 +277,7 @@ set(minetest_SRCS
filecache.cpp
tile.cpp
game.cpp
IProgressBar.cpp
)
# Server sources

View File

@ -1,11 +1,10 @@
#include "IProgressBar.h"
IProgressBar::IProgressBar(IGUIEnvironment * guienv,const core::rect<s32>& rectangle,s32 id,IGUIElement * parent, IGUIFont * font) : IGUIElement(EGUIET_ELEMENT,guienv,parent,id,rectangle)
IProgressBar::IProgressBar(IGUIEnvironment * guienv,const core::rect<s32>& 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<s32>& 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)
}

View File

@ -1,6 +1,7 @@
#ifndef IPROGRESSBAR_HEADER
#define IPROGRESSBAR_HEADER
#include "common_irrlicht.h"
#include <string>
using namespace irr;
using namespace core;
@ -10,7 +11,7 @@ class IProgressBar : public IGUIElement
{
public:
IProgressBar(IGUIEnvironment * guienv,const core::rect<s32>& rectangle,s32 id=-1,IGUIElement * parent=0, IGUIFont * font=0);
IProgressBar(IGUIEnvironment * guienv,const core::rect<s32>& 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<s32> border; //Border
rect<s32> tofill; //Percentage indicator
rect<s32> 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

View File

@ -1096,21 +1096,27 @@ void the_game(
ss<<(client.nodedefReceived()?L"[X]":L"[ ]");
ss<<L" Node definitions\n";
//ss<<L"["<<(int)(client.mediaReceiveProgress()*100+0.5)<<L"%] ";
//ss<<L" Media\n";
if((int)(client.mediaReceiveProgress()*100+0.5) > 90) {
ss<<L"[X]";
} else {
ss<<L"[ ]";
}
ss<<L" Media\n";
draw_load_screen(ss.str(), driver, font, false);
v2u32 screensize = driver->getScreenSize();
core::vector2d<u32> textsize_u = font->getDimension(ss.str().c_str());
core::vector2d<s32> textsize(textsize_u.X,textsize_u.Y);
core::vector2d<s32> center(screensize.X/2, screensize.Y/2);
core::rect<s32> progrect(center - textsize/2, (center + textsize/2) + screensize.Y/16);
IProgressBar * pb = new IProgressBar(guienv,progrect,-1,0,font);
core::rect<s32> 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);