[SUB] Loading Bar

A forum to store posts deemed exceptionally wise and useful

Will you use this loadingbar?

Yes
47
84%
No
9
16%
 
Total votes: 56

DarkWhoppy
Posts: 386
Joined: Thu Sep 25, 2003 12:43 pm
Contact:

[SUB] Loading Bar

Post by DarkWhoppy »

Here's a nifty little loading bar, it works great too. There is no need to call "draw()" between beginScene() and endScene(). The loadingbar class takes a Device as one paramter and will call beginScene() and endScene() when the draw() function is called. If you want you can add a background image, but make sure its drawn BEFORE the loading bar data. If you don't want the border, or would like to just turn the order on/off. Add your own function.

It goes by percentage... or you can change it and hardcode the X position. (which would be... gay lol)

I used Niko's border drawing code. . . so thanks Niko! :D

Code: Select all

[b]EXAMPLE[/b]

CLoadingBar* LoadBar;

LoadBar = new CLoadingBar(_device,rect<s32>(0,25,800,50),true,7);

LoadBar->setPercent(25);
LoadBar->draw();

//Load some more stuff
LoadBar->setPercent(50);
LoadBar->draw();

//Load more stuff
LoadBar->setPercent(100);
LoadBar->draw();

LoadBar->setVisible(false);
/*****************************************************
The CPP File
*****************************************************/

Code: Select all


#include "CLoadingBar.h"

void CLoadingBar::draw()
{
    if(!isVisible)
    { return; }

    _driver->beginScene(true, true, SColor(0,50,50,50));

    if (Border)
	{
		BorderRect.LowerRightCorner.Y = BorderRect.UpperLeftCorner.Y + 1;
		_driver->draw2DRectangle(skin->getColor(EGDC_3D_SHADOW), BorderRect, &AbsoluteBorderRect);

		BorderRect.LowerRightCorner.Y = AbsoluteBorderRect.LowerRightCorner.Y;
		BorderRect.LowerRightCorner.X = BorderRect.UpperLeftCorner.X + 1;
		_driver->draw2DRectangle(skin->getColor(EGDC_3D_SHADOW), BorderRect, &AbsoluteBorderRect);

		BorderRect = AbsoluteBorderRect;
		BorderRect.UpperLeftCorner.X = BorderRect.LowerRightCorner.X - 1;
		_driver->draw2DRectangle(skin->getColor(EGDC_3D_HIGH_LIGHT), BorderRect, &AbsoluteBorderRect);

		BorderRect = AbsoluteBorderRect;
		BorderRect.UpperLeftCorner.Y = AbsoluteBorderRect.LowerRightCorner.Y - 1;
		BorderRect.LowerRightCorner.Y = AbsoluteBorderRect.LowerRightCorner.Y;
		_driver->draw2DRectangle(skin->getColor(EGDC_3D_HIGH_LIGHT), BorderRect, &AbsoluteBorderRect);

		BorderRect = AbsoluteBorderRect;
		BorderRect.UpperLeftCorner.X += 3;
	}

	//if(Percent == 0) { return; }
	MaxNum = AbsoluteBorderRect.LowerRightCorner.X - 1;
	PercentNum = (Percent * MaxNum) / 100;
	PercentNum += BorderRect.UpperLeftCorner.X;

	LoadRect = BorderRect;
	LoadRect.UpperLeftCorner.X = BorderRect.UpperLeftCorner.X;
	LoadRect.LowerRightCorner.X = PercentNum;
	LoadRect.LowerRightCorner.Y -= 1;

	_driver->draw2DRectangle(SColor(255,0,80,150),LoadRect,&AbsoluteBorderRect);

	_driver->endScene();

	if(Percent == 100)
	{ isDone = true; }
}



/*******************************************************
The H File
*******************************************************/

Code: Select all


#ifndef CLOADING_BAR_H
#define CLOADING_BAR_H

#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

class CLoadingBar 
{
    IrrlichtDevice* _device;
    IVideoDriver* _driver;
    IGUIEnvironment* _gui;

    //GUI Skin
    IGUISkin* skin;

    // Percentage of loading bar.
    s32 Percent;
    s32 PercentNum;
    s32 MaxNum; //The far right X pos of the border

    //Visible?
    bool isVisible;
    bool isDone;

    //Draw border?
    bool Border;
    rect<s32> BorderRect;
    rect<s32> AbsoluteBorderRect;

    //Loading bar rectangle
    rect<s32> LoadRect;

public:
    CLoadingBar(IrrlichtDevice* in_d, const rect<s32>& rectangle,bool vis,s32 TotalNum)
    :_device(in_d),Percent(0),Border(true),isVisible(vis),AbsoluteBorderRect(rectangle),BorderRect(rectangle),
     MaxNum(TotalNum),isDone(false)
    {
        _driver = _device->getVideoDriver();
        _gui = _device->getGUIEnvironment();
        skin = _gui->getSkin();
    }
    ~CLoadingBar() { }

    void draw();
    void setVisible(bool t_f)
    { isVisible = t_f; }

    void setPercent(s32 p)
    { Percent = p; }

    s32 getPercent()
    { return Percent; }

    bool isComplete()
    { return isDone; }

};

#endif
Programmer of the Irrlicht Scene Editor:
Homepage - Forum Thread
Version 2 on its way!!
DarkWhoppy
Posts: 386
Joined: Thu Sep 25, 2003 12:43 pm
Contact:

Post by DarkWhoppy »

Here's a screenshot:

Image
Programmer of the Irrlicht Scene Editor:
Homepage - Forum Thread
Version 2 on its way!!
dawasw
Posts: 357
Joined: Tue Aug 10, 2004 4:39 pm
Location: Poland

Post by dawasw »

Looks very nice, it may be very useful for those, who want to have "everything" in their project. But now most of people care about levels/models/gameplay/physics etc. and not too many of us will even think about a detail like loading bar, but i must say, that it is very nice detail.
schick
Posts: 230
Joined: Tue Oct 07, 2003 3:55 pm
Location: Germany
Contact:

Post by schick »

GUI elements are always welcome, but i appreciate it if it really was a GUI element. You should derive it from IGUIElement so it should be suitable to all needs.

Cheers,

Schick
Please send me an e-mail instead of a private message.
DarkWhoppy
Posts: 386
Joined: Thu Sep 25, 2003 12:43 pm
Contact:

Post by DarkWhoppy »

Well, I coded it for my own use. But if you want it to be an "Official GUI Element" it wouldn't be hard to copy and paste the code and change the constructor, etc...
Programmer of the Irrlicht Scene Editor:
Homepage - Forum Thread
Version 2 on its way!!
katoun
Posts: 239
Joined: Mon Nov 15, 2004 9:39 am
Location: Romania
Contact:

Post by katoun »

Hi.
I just made an IGUILoadBar and it works fine.(It's now part of an set of inplementations for Irrlicht0.8 but I dont have yet a space where to put it on the web)
Ah, and you can change the color of the loading bar.
If anyone interested in the code for the implementation post a reply and when I'll read it I shall write you the code.
Happy codding.
Kat'Oun
TheRLG
Posts: 372
Joined: Thu Oct 07, 2004 11:20 pm

Post by TheRLG »

katoun wrote:Hi.
I just made an IGUILoadBar and it works fine.(It's now part of an set of inplementations for Irrlicht0.8 but I dont have yet a space where to put it on the web)
Ah, and you can change the color of the loading bar.
If anyone interested in the code for the implementation post a reply and when I'll read it I shall write you the code.
Happy codding.
Post it up ;-)
katoun
Posts: 239
Joined: Mon Nov 15, 2004 9:39 am
Location: Romania
Contact:

Post by katoun »

Hello
You must know that are 4 file that must be 'upgades' but just a feu lines are changed(I mean added) form the original code:
include/Irrlicht.h
include/IGUIEnvironment.h
CGUIEnvironment.h
CGUIEnvironment.cpp
The next 3 are added files to create the loadin bar class:

include/IGUILoadBar.h(added)
CGUILoadBar.h(added)
CGUILoadBar.cpp(added)

And now the code in the same order:

//////Irrlicht.h/////////

/* Irrlicht.h -- interface of the 'Irrlicht Engine' version 0.6

Copyright (C) 2002-2005 Nikolaus Gebhardt

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.

Please note that the Irrlicht Engine is based in part on the work of the
Independent JPEG Group and the zlib. This means that if you use the Irrlicht
Engine in your product, you must acknowledge somewhere in your documentation
that you've used the IJG code. It would also be nice to mention that you use
the Irrlicht Engine and the zlib. See the README files in the jpeglib and
the zlib for further informations.
*/

#ifndef __IRRLICHT_H_INCLUDED__
#define __IRRLICHT_H_INCLUDED__

#include "aabbox3d.h"
#include "array.h"
#include "SColor.h"
#include "SLight.h"
#include "dimension2d.h"
#include "EDriverTypes.h"
#include "heapsort.h"
#include "IAnimatedMesh.h"
#include "IAnimatedMeshMD2.h"
#include "IAnimatedMeshMS3D.h"
#include "IAnimatedMeshX.h"
#include "IAnimatedMeshSceneNode.h"
#include "IBspTreeSceneNode.h"
#include "ICameraSceneNode.h"
#include "IDummyTransformationSceneNode.h"
#include "IEventReceiver.h"
#include "IFileList.h"
#include "IFileSystem.h"
#include "IGUIButton.h"
#include "IGUICheckBox.h"
#include "IGUIContextMenu.h"
#include "IGUIComboBox.h"
#include "IGUIElement.h"
#include "IGUIEditBox.h"
#include "IGUIEnvironment.h"
#include "IGUIFileOpenDialog.h"
#include "IGUIFont.h"
#include "IGUIImage.h"
#include "IGUIInOutFader.h"
#include "IGUIListBox.h"
#include "IGUIMeshViewer.h"
#include "IGUIScrollBar.h"
#include "IGUISkin.h"
#include "IGUIStaticText.h"
#include "IGUITabControl.h"
#include "IGUIWindow.h"
#include "IGUIToolbar.h"
#include "IGUILoadBar.h"
#include "ILightSceneNode.h"
#include "ILogger.h"
#include "IMesh.h"
#include "IMeshBuffer.h"
#include "IMeshManipulator.h"
#include "IMetaTriangleSelector.h"
#include "IReadFile.h"
#include "IrrlichtDevice.h"
#include "irrMath.h"
#include "irrString.h"
#include "ISceneManager.h"
#include "ISceneNode.h"
#include "ITriangleSelector.h"
#include "ISceneNodeAnimator.h"
#include "ISceneCollisionManager.h"
#include "IMaterialRenderer.h"
#include "ISceneNodeAnimatorCollisionResponse.h"
#include "IShaderConstantSetCallBack.h"
#include "IParticleSystemSceneNode.h"
#include "ITerrainSceneNode.h"
#include "IParticleEmitter.h"
#include "IParticleAffector.h"
#include "IBillboardSceneNode.h"
#include "ITexture.h"
#include "IUnknown.h"
#include "IVideoDriver.h"
#include "IVideoModeList.h"
#include "IWriteFile.h"
#include "IXMLReader.h"
#include "IXMLWriter.h"
#include "Keycodes.h"
#include "line2d.h"
#include "line3d.h"
#include "irrList.h"
#include "matrix4.h"
#include "plane3d.h"
#include "plane3d.h"
#include "vector2d.h"
#include "vector3d.h"
#include "triangle3d.h"
#include "position2d.h"
#include "quaternion.h"
#include "rect.h"
#include "S3DVertex.h"
#include "SAnimatedMesh.h"
#include "SKeyMap.h"
#include "SMaterial.h"
#include "SMesh.h"
#include "SMeshBuffer.h"
#include "SMeshBufferLightMap.h"
#include "SMeshBufferTangents.h"
#include "irrTypes.h"

//! Irrlicht SDK Version
#define IRRLICHT_SDK_VERSION L"0.8"

/*! \mainpage Irrlicht Engine 0.8 API documentation
*
* \section intro Introduction
*
* Welcome to the Irrlicht Engine API documentation.
* Here you'll find any information you'll need to develop applications with
* the Irrlicht Engine. If you look for a tutorial on how to start, take a look
* at the homepage of the Irrlicht Engine at
* <A HREF="http://irrlicht.sourceforge.net" >irrlicht.sourceforge.net</A>
* or into the SDK in the directory \examples.
*
* The Irrlicht Engine is intended to be an easy-to-use 3d engine, so
* this documentation is an important part of it. If you have any questions or
* suggestions, just send a email to the author of the engine, Nikolaus Gebhardt
* (niko (at) code3d.com).
*
* \section links Links
*
* <A HREF="namespaces.html">Namespaces</A>: A very good place to start reading
* the documentation.<BR>
* <A HREF="annotated.html">Compound list</A>: List of all classes with descriptions.<BR>
* <A HREF="hierarchy.html">Class hierarchy</A>: Class hierarchy list.<BR>
* <A HREF="classes.html">Alphabetical class list</A>: Good place to find forgotten class names.<BR>
*
* \section example Short example
*
* A simple application, starting up the engine, loading a Quake 2 animated
* model file and the corresponding texture, animating and displaying it
* in front of a blue background and placing a user controlable 3d camera
* would look like the following code. I think this example shows the usage
* of the engine quite well:
*
* \code
* #include <Irrlicht.h>
* using namespace irr;
*
* int main()
* {
* // start up the engine
* IrrlichtDevice *device = createDevice(video::EDT_DIRECTX8,
* core::dimension2d<s32>(640,480), false);
*
* video::IVideoDriver* driver = device->getVideoDriver();
* scene::ISceneManager* scenemgr = device->getSceneManager();
*
* device->setWindowCaption(L"Hello World!");
*
* // load and show quake2 .md2 model
* scene::ISceneNode* node = scenemgr->addAnimatedMeshSceneNode(
* scenemgr->getMesh("quake2model.md2"));
*
* // if everything worked, add a texture and disable lighting
* if (node)
* {
* node->setMaterialTexture(0, driver->getTexture("texture.bmp"));
* node->setMaterialFlag(video::EMF_LIGHTING, false);
* }
*
* // add a first person shooter style user controlled camera
* scenemgr->addCameraSceneNodeFPS();
*
* // draw everything
* while(device->run() && driver)
* {
* driver->beginScene(true, true, video::SColor(255,0,0,255));
* scenemgr->drawAll();
* driver->endScene();
* }
*
* // delete device
* device->drop();
* return 0;
* }
* \endcode
*
* If you would like to replace the simple blue screen background by
* a cool Quake 3 Map, optimized by an octtree, just insert this code
* somewhere before the while loop:
*
* \code
* // add .pk3 archive to the file system
* device->getFileSystem()->addZipFileArchive("quake3map.pk3");
*
* // load .bsp file and show it using an octtree
* scenemgr->addOctTreeSceneNode(
* scenemgr->getMesh("quake3map.bsp"));
* \endcode
*
* As you can see, the engine uses namespaces. Everything in the engine is
* placed into the namespace 'irr', but there are also 5 sub namespaces.
* You can find a list of all namespaces with descriptions at the
* <A HREF="namespaces.html"> namespaces page</A>.
* This is also a good place to start reading the documentation. If you
* don't want always write the namespace names, just use all namespaces like
* this:
* \code
* using namespace core;
* using namespace scene;
* using namespace video;
* using namespace io;
* using namespace gui;
* \endcode
*
* There is a lot more the engine can do, but I hope this gave a short
* overview over the basic features of the engine.
*/

#include <wchar.h>
#ifdef _WIN32
//! Define for swprintf because this method does not match the ISO C standard
//! on Win32 platforms, but it does on all other ones.
#define swprintf _snwprintf
#endif // WIN32

#ifdef WIN32

#ifdef IRRLICHT_EXPORTS
#define IRRLICHT_API __declspec(dllexport)
#else
#define IRRLICHT_API __declspec(dllimport)
#endif // IRRLICHT_EXPORT
#else
#define IRRLICHT_API
#endif // WIN32

#if defined(_STDCALL_SUPPORTED)
#define IRRCALLCONV __stdcall // Declare the calling convention.
#else
#define IRRCALLCONV
#endif // STDCALL_SUPPORTED


//! Everything in the Irrlicht Engine can be found in this namespace.
namespace irr
{
//! Creates an Irrlicht device. The Irrlicht device is the root object for using the engine.
/** \param deviceType: Type of the device. This can currently be video::DT_NULL,
video::EDT_SOFTWARE, video::EDT_DIRECTX8, video::EDT_DIRECTX9 and video::EDT_OPENGL.
\param windowSize: Size of the window or the video mode in fullscreen mode.
\param bits: Bits per pixel in fullscreen mode. Ignored if windowed mode.
\param fullscreen: Should be set to true if the device should run in fullscreen. Otherwise
the device runs in window mode.
\param stencilbuffer: Specifies if the stencil buffer should be enabled. Set this to true,
if you want the engine be able to draw stencil buffer shadows. Note that not all
devices are able to use the stencil buffer. If they don't no shadows will be drawn.
\param vsync: Specifies vertical syncronisation: If set to true, the driver will wait
for the vertical retrace period, otherwise not.
\param receiver: A user created event receiver.
\param sdk_version_do_not_use: Don't use or change this parameter. Always set it to
IRRLICHT_SDK_VERSION, which is done by default. This is needed for sdk version checks.
\return Returns pointer to the created IrrlichtDevice or null if the
device could not be created.
*/

#ifdef __cplusplus
extern "C" { // do not use C++ decorations
#endif

IRRLICHT_API IrrlichtDevice* IRRCALLCONV createDevice(
video::E_DRIVER_TYPE deviceType = video::EDT_SOFTWARE,
const core::dimension2d<s32>& windowSize = core::dimension2d<s32>(640,480),
u32 bits = 16,
bool fullscreen = false,
bool stencilbuffer=false,
bool vsync=false,
IEventReceiver* receiver = 0,
const wchar_t* sdk_version_do_not_use = IRRLICHT_SDK_VERSION);

#ifdef __cplusplus
} // close extern C
#endif

// THE FOLLOWING IS AN EMPTY LIST OF ALL SUB NAMESPACES
// EXISTING ONLY FOR THE DOCUMENTION SOFTWARE DOXYGEN.

//! In this namespace can be found basic classes like vectors, planes, arrays, lists and so on.
namespace core
{
}

//! The gui namespace contains useful classes for easy creation of a graphical user interface.
namespace gui
{
}

//! This namespace provides interfaces for input/output: Reading and writing files, accessing zip archives, xml files, ...
namespace io
{
}

//! All scene management can be found in this namespace: Mesh loading, special scene nodes like octrees and billboards, ...
namespace scene
{
}

//! The video namespace contains classes for accessing the video driver. All 2d and 3d rendering is done here.
namespace video
{
}
}


#endif

/////////IGUIEnvironment.h///////////

// Copyright (C) 2002-2005 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h

#ifndef __I_GUI_ENVIRNMENT_H_INCLUDED__
#define __I_GUI_ENVIRNMENT_H_INCLUDED__

#include "rect.h"
#include "IUnknown.h"
#include "IEventReceiver.h"
#include "irrTypes.h"
#include "IGUIWindow.h"

namespace irr
{

namespace video
{
class IVideoDriver;
class ITexture;
}

namespace gui
{

class IGUIElement;
class IGUISkin;
class IGUIFont;
class IGUIScrollBar;
class IGUIImage;
class IGUIMeshViewer;
class IGUICheckBox;
class IGUIListBox;
class IGUIFileOpenDialog;
class IGUIInOutFader;
class IGUIStaticText;
class IGUIEditBox;
class IGUITabControl;
class IGUITab;
class IGUIContextMenu;
class IGUIComboBox;
class IGUIToolBar;
class IGUILoadBar;

//! GUI Environment. Used as factory and manager of all other GUI elements.
class IGUIEnvironment : public IUnknown
{
public:

//! destructor
virtual ~IGUIEnvironment() {};

//! Draws all gui elements.
virtual void drawAll() = 0;

//! Sets the focus to an element.
virtual void setFocus(IGUIElement* element) = 0;

//! Removes the focus from an element.
virtual void removeFocus(IGUIElement* element) = 0;

//! Returns if the element has focus
virtual bool hasFocus(IGUIElement* element) = 0;

//! Returns the current video driver.
virtual video::IVideoDriver* getVideoDriver() = 0;

//! Posts an input event to the environment. Usually you do not have to
//! use this method, it is used by the internal engine.
virtual bool postEventFromUser(SEvent event) = 0;

//! This sets a new event receiver for gui events. Usually you do not have to
//! use this method, it is used by the internal engine.
virtual void setUserEventReceiver(IEventReceiver* evr) = 0;

//! Returns pointer to the current gui skin.
virtual IGUISkin* getSkin() = 0;

//! Returns pointer to the font with the specified file name. Loads the font if
//! it was not loaded before. Returns 0 if the font could not be loaded.
//! \return
//! returns a pointer to the font.
//! This pointer should not be dropped. See IUnknown::drop() for more information.
virtual IGUIFont* getFont(const c8* filename) = 0;

//! Returns the default built-in font.
virtual IGUIFont* getBuiltInFont() = 0;

//! Returns the root gui element. This is the first gui element, parent of all other
//! gui elements. You'll never need to use this method, unless you are not creating
//! your own gui elements, trying to add them to the gui elements without a parent.
//! The returned pointer should not be dropped. See IUnknown::drop() for more information.
virtual IGUIElement* getRootGUIElement() = 0;

//! Adds an button element.
//! \return
//! Returns a pointer to the created button. Returns 0 if an error occured.
//! This pointer should not be dropped. See IUnknown::drop() for more information.
virtual IGUIButton* addButton(const core::rect<s32>& rectangle,
IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0) = 0;

//! Adds an empty window element.
//! \param modal: Defines if the dialog is modal. This means, that all other
//! gui elements which were created before the message box cannot be used
//! until this messagebox is removed.
//! \return
//! Returns a pointer to the created window. Returns 0 if an error occured.
//! This pointer should not be dropped. See IUnknown::drop() for more information.
virtual IGUIWindow* addWindow(const core::rect<s32>& rectangle, bool modal = false,
const wchar_t* text=0, IGUIElement* parent=0, s32 id=-1) = 0;

//! Adds a message box.
//! \param caption: Text to be displayed the title of the message box.
//! \param text: Text to be displayed in the body of the message box.
//! \param modal: Defines if the dialog is modal. This means, that all other
//! gui elements which were created before the message box cannot be used
//! until this messagebox is removed.
//! \param flags: Flags specifying the layout of the message box. For example
//! to create a message box with an OK and a CANCEL button on it, set this
//! to (EMBF_OK | EMBF_CANCEL).
//! \param parent: Parent gui element of the message box.
//! \param id: Id with which the gui element can be identified.
//! \return
//! Returns a pointer to the created message box. Returns 0 if an error occured.
//! This pointer should not be dropped. See IUnknown::drop() for more information.
virtual IGUIWindow* addMessageBox(const wchar_t* caption, const wchar_t* text=0,
bool modal = true, s32 flags = EMBF_OK, IGUIElement* parent=0, s32 id=-1) = 0;

//! Adds a scrollbar.
//! \return
//! Returns a pointer to the created scrollbar. Returns 0 if an error occured.
//! This pointer should not be dropped. See IUnknown::drop() for more information.
virtual IGUIScrollBar* addScrollBar(bool horizontal, const core::rect<s32>& rectangle, IGUIElement* parent=0, s32 id=-1) = 0;

//! Adds an image element.
//! \param image: Image to be displayed.
//! \param pos: Position of the image. The width and height of the image is taken
//! from the image.
//! \param useAlphaChannel: Sets if the image should use the alpha channel of the texture
//! to draw itself.
//! \return
//! Returns a pointer to the created image element. Returns 0 if an error occured.
//! This pointer should not be dropped. See IUnknown::drop() for more information.
virtual IGUIImage* addImage(video::ITexture* image, core::position2d<s32> pos,
bool useAlphaChannel=true, IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0) = 0;

//! Adds an image element. Use IGUIImage::setImage later to set the image to be displayed.
//! \return
//! Returns a pointer to the created image element. Returns 0 if an error occured.
//! This pointer should not be dropped. See IUnknown::drop() for more information.
virtual IGUIImage* addImage(const core::rect<s32>& rectangle,
IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0) = 0;

//! Adds a checkbox element.
//! \return
//! Returns a pointer to the created check box. Returns 0 if an error occured.
//! This pointer should not be dropped. See IUnknown::drop() for more information.
virtual IGUICheckBox* addCheckBox(bool checked, const core::rect<s32>& rectangle, IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0) = 0;

//! Adds a list box element.
//! \return
//! Returns a pointer to the created list box. Returns 0 if an error occured.
//! This pointer should not be dropped. See IUnknown::drop() for more information.
virtual IGUIListBox* addListBox(const core::rect<s32>& rectangle,
IGUIElement* parent=0, s32 id=-1, bool drawBackground=false) = 0;

//! Adds an mesh viewer. Not 100% implemented yet.
//! \return
//! Returns a pointer to the created mesh viewer. Returns 0 if an error occured.
//! This pointer should not be dropped. See IUnknown::drop() for more information.
virtual IGUIMeshViewer* addMeshViewer(const core::rect<s32>& rectangle, IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0) = 0;

//! Adds a file open dialog.
//! \param modal: Defines if the dialog is modal. This means, that all other
//! gui elements which were created before the message box cannot be used
//! until this messagebox is removed.
//! \return
//! Returns a pointer to the created file open dialog. Returns 0 if an error occured.
//! This pointer should not be dropped. See IUnknown::drop() for more information.
virtual IGUIFileOpenDialog* addFileOpenDialog(const wchar_t* title = 0, bool modal=true, IGUIElement* parent=0, s32 id=-1) = 0;

//! Adds a static text. The returned pointer must not be dropped.
//! \param text is the text to be displayed. Can be altered after creation with SetText().
//! \param rectangle is the position of the static text.
//! \param border has to be set to true if the static text should have a 3d border.
//! \param wordWrap specifyes, if the text should be wrapped into multiple lines.
//! \param parent is the parent item of the element. E.g. a window. Set it to 0 to place the fader directly in the environment.
//! \param id is a s32 to identify the static text element.
//! \return
//! Returns a pointer to the created static text. Returns 0 if an error occured.
//! This pointer should not be dropped. See IUnknown::drop() for more information.
virtual IGUIStaticText* addStaticText(const wchar_t* text, const core::rect<s32>& rectangle,
bool border=false, bool wordWrap=true, IGUIElement* parent=0, s32 id=-1) = 0;

//! Adds an edit box. Supports unicode input from every keyboard around the world,
//! scrolling, copying and pasting (exchanging data with the clipboard directly), maximum
//! character amount, marking and all shortcuts like ctrl+X, ctrl+V, ctrg+C,
//! shift+Left, shift+Right, Home, End, and so on.
//! \param text is the text to be displayed. Can be altered after creation with SetText().
//! \param rectangle is the position of the edit box.
//! \param border has to be set to true if the edit box should have a 3d border.
//! \param parent is the parent item of the element. E.g. a window. Set it to 0 to place the edit box directly in the environment.
//! \param id is a s32 to identify the edit box.
//! \return
//! Returns a pointer to the created static text. Returns 0 if an error occured.
//! This pointer should not be dropped. See IUnknown::drop() for more information.
virtual IGUIEditBox* addEditBox(const wchar_t* text, const core::rect<s32>& rectangle,
bool border=true, IGUIElement* parent=0, s32 id=-1) = 0;

//! Adds an element for fading in or out.
//! \param rectangle: Pointer to rectangle specifing the borders of the element.
//! If the pointer is NULL, the whole screen is used.
//! \param parent: Parent item of the element. E.g. a window. Set it to 0 to place the static text directly in the environment.
//! \param id: A s32 to identify the text.
//! \return
//! Returns a pointer to the created in-out-fader. Returns 0 if an error occured.
//! This pointer should not be dropped. See IUnknown::drop() for more information.
virtual IGUIInOutFader* addInOutFader(const core::rect<s32>* rectangle=0, IGUIElement* parent=0, s32 id=-1) = 0;

//! Adds a tab control to the environment.
//! \param rectangle is the position of the tab control.
//! \param parent is the parent item of the element. E.g. a window. Set it to 0 to place the tab control directly in the environment.
//! \param fillbackground specifies if the background of the tab control should be drawn to.
//! \param border specifiys if a flat 3d border should be drawn.
//! This is usually not necesarry unless you don't place the control directly into the environment without a window as parent.
//! \param id is a s32 to identify the tab control.
//! \return
//! Returns a pointer to the created tab control element. Returns 0 if an error occured.
//! This pointer should not be dropped. See IUnknown::drop() for more information.
virtual IGUITabControl* addTabControl(const core::rect<s32>& rectangle,
IGUIElement* parent=0, bool fillbackground=false,
bool border=true, s32 id=-1) = 0;

//! Adds tab to the environment. You can use this element to group
//! other elements. This is not used for creating tabs on tab controls,
//! please use IGUITabControl::addTab() for this instead.
//! \param rectangle is the position of the tab.
//! \param parent is the parent item of the element. E.g. a window. Set it to 0 to place the tab directly in the environment.
//! \param id is a s32 to identify the tab.
virtual IGUITab* addTab(const core::rect<s32>& rectangle,
IGUIElement* parent=0, s32 id=-1) = 0;

//! Adds a context menu to the environment.
//! \param rectangle is the position of the menu. Note that the menu is
//! resizing itself based on what items you add.
//! \param parent is the parent item of the element. E.g. a window. Set it to 0 to place the menu directly in the environment.
//! \param id is a s32 to identify the menu.
virtual IGUIContextMenu* addContextMenu(const core::rect<s32>& rectangle,
IGUIElement* parent=0, s32 id=-1) = 0;

//! Adds a menu to the environment. This is like the menu you can find on top
//! of most windows in modern graphical user interfaces.
//! \param parent is the parent item of the element. E.g. a window. Set it to 0 to place the menu directly in the environment.
//! \param id is a s32 to identify the menu.
virtual IGUIContextMenu* addMenu(IGUIElement* parent=0, s32 id=-1) = 0;

//! Adds a toolbar to the environment. It is like a menu is always placed on top
//! in its parent, and contains buttons.
//! \param parent is the parent item of the element. E.g. a window. Set it to 0 to place the tool bar directly in the environment.
//! \param id is a s32 to identify the tool bar.
virtual IGUIToolBar* addToolBar(IGUIElement* parent=0, s32 id=-1) = 0;

//! Adds a combo box to the environment.
//! \param parent is the parent item of the element. E.g. a window. Set it to 0 to place the combo box directly in the environment.
//! \param id is a s32 to identify the combo box.
virtual IGUIComboBox* addComboBox(const core::rect<s32>& rectangle,
IGUIElement* parent=0, s32 id=-1) = 0;

//! Adds an loadbar element.
//! \return
//! Returns a pointer to the created loadbar. Returns 0 if an error occured.
//! This pointer should not be dropped. See IUnknown::drop() for more information.
virtual IGUILoadBar* addLoadBar(const core::rect<s32>& rectangle,
IGUIElement* parent=0, s32 id=-1, bool vis=true,s32 TotalNum=7) = 0;


};


} // end namespace gui
} // end namespace irr

#endif

/////////CGUIEnvironment.h//////////////////////

// Copyright (C) 2002-2005 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h

#ifndef __C_GUI_ENVIRNMENT_H_INCLUDED__
#define __C_GUI_ENVIRNMENT_H_INCLUDED__

#include "IGUIEnvironment.h"
#include "IGUIElement.h"
#include "array.h"
#include "IFileSystem.h"
#include "IOSOperator.h"

namespace irr
{
namespace gui
{

class CGUIEnvironment : public IGUIEnvironment, IGUIElement
{
public:

//! constructor
CGUIEnvironment(io::IFileSystem* fs, video::IVideoDriver* driver, IOSOperator* op);

//! destructor
virtual ~CGUIEnvironment();

//! draws all gui elements
virtual void drawAll();

//! returns the current video driver
virtual video::IVideoDriver* getVideoDriver();

//! posts an input event to the environment
virtual bool postEventFromUser(SEvent event);

//! This sets a new event receiver for gui events. Usually you do not have to
//! use this method, it is used by the internal engine.
virtual void setUserEventReceiver(IEventReceiver* evr);

//! called if an event happened.
virtual bool OnEvent(SEvent event);

//! returns the current gui skin
virtual IGUISkin* getSkin();

//! returns the font
virtual IGUIFont* getFont(const c8* filename);

//! adds an button. The returned pointer must not be dropped.
virtual IGUIButton* addButton(const core::rect<s32>& rectangle, IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0);

//! adds a window. The returned pointer must not be dropped.
virtual IGUIWindow* addWindow(const core::rect<s32>& rectangle, bool modal = false,
const wchar_t* text=0, IGUIElement* parent=0, s32 id=-1);

//! Adds a message box.
virtual IGUIWindow* addMessageBox(const wchar_t* caption, const wchar_t* text=0,
bool modal = true, s32 flag = EMBF_OK, IGUIElement* parent=0, s32 id=-1);

//! adds a scrollbar. The returned pointer must not be dropped.
virtual IGUIScrollBar* addScrollBar(bool horizontal, const core::rect<s32>& rectangle, IGUIElement* parent=0, s32 id=-1);

//! Adds an image element.
virtual IGUIImage* addImage(video::ITexture* image, core::position2d<s32> pos,
bool useAlphaChannel=true, IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0);

//! adds an image. The returned pointer must not be dropped.
virtual IGUIImage* addImage(const core::rect<s32>& rectangle,
IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0);

//! adds a checkbox
virtual IGUICheckBox* addCheckBox(bool checked, const core::rect<s32>& rectangle, IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0);

//! adds a list box
virtual IGUIListBox* addListBox(const core::rect<s32>& rectangle,
IGUIElement* parent=0, s32 id=-1, bool drawBackground=false);

//! adds an mesh viewer. The returned pointer must not be dropped.
virtual IGUIMeshViewer* addMeshViewer(const core::rect<s32>& rectangle, IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0);

//! Adds a file open dialog.
virtual IGUIFileOpenDialog* addFileOpenDialog(const wchar_t* title = 0, bool modal=true, IGUIElement* parent=0, s32 id=-1);

//! adds a static text. The returned pointer must not be dropped.
virtual IGUIStaticText* addStaticText(const wchar_t* text, const core::rect<s32>& rectangle,
bool border=false, bool wordWrap=true, IGUIElement* parent=0, s32 id=-1);

//! Adds an edit box. The returned pointer must not be dropped.
virtual IGUIEditBox* addEditBox(const wchar_t* text, const core::rect<s32>& rectangle,
bool border=false, IGUIElement* parent=0, s32 id=-1);

//! Adds a tab control to the environment.
virtual IGUITabControl* addTabControl(const core::rect<s32>& rectangle,
IGUIElement* parent=0, bool fillbackground=false, bool border=true, s32 id=-1);

//! Adds tab to the environment.
virtual IGUITab* addTab(const core::rect<s32>& rectangle,
IGUIElement* parent=0, s32 id=-1);

//! Adds a context menu to the environment.
virtual IGUIContextMenu* addContextMenu(const core::rect<s32>& rectangle,
IGUIElement* parent=0, s32 id=-1);

//! Adds a menu to the environment.
virtual IGUIContextMenu* addMenu(IGUIElement* parent=0, s32 id=-1);

//! Adds a toolbar to the environment. It is like a menu is always placed on top
//! in its parent, and contains buttons.
virtual IGUIToolBar* addToolBar(IGUIElement* parent=0, s32 id=-1);

//! Adds a combo box to the environment.
virtual IGUIComboBox* addComboBox(const core::rect<s32>& rectangle,
IGUIElement* parent=0, s32 id=-1);

virtual IGUILoadBar* addLoadBar(const core::rect<s32>& rectangle,
IGUIElement* parent=0, s32 id=-1, bool vis=true,s32 TotalNum=7);

//! sets the focus to an element
virtual void setFocus(IGUIElement* element);

//! removes the focus from an element
virtual void removeFocus(IGUIElement* element);

//! Returns if the element has focus
virtual bool hasFocus(IGUIElement* element);

//! returns default font
virtual IGUIFont* getBuiltInFont();

//! Adds an element for fading in or out.
virtual IGUIInOutFader* addInOutFader(const core::rect<s32>* rectangle=0, IGUIElement* parent=0, s32 id=-1);

//! Returns the root gui element.
virtual IGUIElement* getRootGUIElement();

private:

struct SFont
{
core::stringc Filename;
IGUIFont* Font;

bool operator < (const SFont& other) const
{
return (Filename < other.Filename);
}
};

void updateHoveredElement(core::position2d<s32> mousePos);

void loadBuidInFont();

core::array<SFont> Fonts;
video::IVideoDriver* Driver;
IGUIElement* Hovered;
IGUIElement* Focus;
IGUISkin* CurrentSkin;
io::IFileSystem* FileSystem;
IEventReceiver* UserReceiver;
IOSOperator* Operator;
};

} // end namespace gui
} // end namespace irr

#endif

//////////CGUIEnvironment.cpp//////

// Copyright (C) 2002-2005 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h

#include "CGUIEnvironment.h"
#include "IVideoDriver.h"
#include "IGUISkin.h"

#include "CGUIButton.h"
#include "CGUIWindow.h"
#include "CGUIScrollBar.h"
#include "CGUIFont.h"
#include "CGUIImage.h"
#include "CGUIMeshViewer.h"
#include "CGUICheckBox.h"
#include "CGUIListBox.h"
#include "CGUIFileOpenDialog.h"
#include "CGUIStaticText.h"
#include "CGUIEditBox.h"
#include "CGUIInOutFader.h"
#include "CGUIMessageBox.h"
#include "CGUIModalScreen.h"
#include "CGUITabControl.h"
#include "CGUIContextMenu.h"
#include "CGUIComboBox.h"
#include "CGUIMenu.h"
#include "CGUIToolBar.h"
#include "CGUILoadBar.h"

#include "BuildInFont.h"
#include "os.h"

namespace irr
{
namespace gui
{

//! constructor
CGUIEnvironment::CGUIEnvironment(io::IFileSystem* fs, video::IVideoDriver* driver, IOSOperator* op)
: IGUIElement(0, 0, 0, core::rect<s32>(core::position2d<s32>(0,0), driver ? driver->getScreenSize() : core::dimension2d<s32>(0,0))),
Hovered(0), CurrentSkin(0), Driver(driver),
Focus(0), FileSystem(fs), UserReceiver(0), Operator(op)
{
if (Driver)
Driver->grab();

if (FileSystem)
FileSystem->grab();

if (Operator)
Operator->grab();

#ifdef _DEBUG
IGUIEnvironment::setDebugName("CGUIEnvironment IGUIEnvironment");
IGUIElement::setDebugName("CGUIEnvironment IGUIElement");
#endif

loadBuidInFont();

CurrentSkin = createSkin(EGST_WINDOWS_STANDARD);
CurrentSkin->setFont(getBuiltInFont());
}


//! destructor
CGUIEnvironment::~CGUIEnvironment()
{
if (Hovered)
Hovered->drop();

if (CurrentSkin)
CurrentSkin->drop();

if (Driver)
Driver->drop();

if (Focus)
Focus->drop();

if (FileSystem)
FileSystem->drop();

if (Operator)
Operator->drop();

// delete all fonts

for (u32 i=0; i<Fonts.size(); ++i)
Fonts.Font->drop();
}



void CGUIEnvironment::loadBuidInFont()
{
const c8* filename = "#DefaultFont";

io::IReadFile* file = io::createMemoryReadFile(BuildInFontData, BuildInFontDataSize, filename, false);

CGUIFont* font = new CGUIFont(Driver);
if (!font->load(file))
{
os::Printer::log("Error: Could not load built-in Font.", ELL_ERROR);
font->drop();
file->drop();
return;
}

SFont f;
f.Filename = filename;
f.Font = font;
Fonts.push_back(f);

file->drop();
}



//! draws all gui elements
void CGUIEnvironment::drawAll()
{
if (Driver)
{
core::dimension2d<s32> dim = Driver->getScreenSize();
if (AbsoluteRect.LowerRightCorner.X != dim.Width ||
AbsoluteRect.LowerRightCorner.Y != dim.Height)
{
// resize gui environment
RelativeRect.LowerRightCorner.X = Driver->getScreenSize().Width;
RelativeRect.LowerRightCorner.Y = Driver->getScreenSize().Height;
AbsoluteClippingRect = RelativeRect;
AbsoluteRect = RelativeRect;
updateAbsolutePosition();
}
}

draw();
}


//! sets the focus to an element
void CGUIEnvironment::setFocus(IGUIElement* element)
{
if (Focus == element)
return;

removeFocus(Focus);

Focus = element;
if (Focus)
Focus->grab();
}


//! removes the focus from an element
void CGUIEnvironment::removeFocus(IGUIElement* element)
{
if (Focus && Focus==element)
{
SEvent e;
e.EventType = EET_GUI_EVENT;
e.GUIEvent.Caller = this;
e.GUIEvent.EventType = EGET_ELEMENT_FOCUS_LOST;
Focus->OnEvent(e);
Focus->drop();
Focus = 0;
}
}


//! Returns if the element has focus
bool CGUIEnvironment::hasFocus(IGUIElement* element)
{
return element == Focus;
}



//! returns the current video driver
video::IVideoDriver* CGUIEnvironment::getVideoDriver()
{
return Driver;
}



//! called by ui if an event happened.
bool CGUIEnvironment::OnEvent(SEvent event)
{
if (UserReceiver && event.GUIEvent.Caller != this)
return UserReceiver->OnEvent(event);

return false;
}


void CGUIEnvironment::updateHoveredElement(core::position2d<s32> mousePos)
{
IGUIElement* lastHovered = Hovered;

Hovered = getElementFromPoint(mousePos);

if (Hovered)
{
Hovered->grab();

if (Hovered != lastHovered)
{
SEvent event;
event.EventType = EET_GUI_EVENT;

if (lastHovered)
{
event.GUIEvent.Caller = lastHovered;
event.GUIEvent.EventType = EGET_ELEMENT_LEFT;
lastHovered->OnEvent(event);
}

event.GUIEvent.Caller = Hovered;
event.GUIEvent.EventType = EGET_ELEMENT_HOVERED;
Hovered->OnEvent(event);
}
}

if (lastHovered)
lastHovered->drop();
}


//! This sets a new event receiver for gui events. Usually you do not have to
//! use this method, it is used by the internal engine.
void CGUIEnvironment::setUserEventReceiver(IEventReceiver* evr)
{
UserReceiver = evr;
}


//! posts an input event to the environment
bool CGUIEnvironment::postEventFromUser(SEvent event)
{
switch(event.EventType)
{
case EET_GUI_EVENT:
// hey, why is the user sending gui events..?
break;
case EET_MOUSE_INPUT_EVENT:

// sending input to focus, stopping of focus processed input

if (Focus && Focus->OnEvent(event))
return true;

if (!Focus) // focus could have died in last call
{
// trying to send input to hovered element
updateHoveredElement(core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y));

if (Hovered && Hovered != this)
return Hovered->OnEvent(event);
}
break;
case EET_KEY_INPUT_EVENT:
if (Focus && Focus != this)
return Focus->OnEvent(event);
break;
} // end switch

return false;
}



//! returns the current gui skin
IGUISkin* CGUIEnvironment::getSkin()
{
return CurrentSkin;
}


//! adds an button. The returned pointer must not be dropped.
IGUIButton* CGUIEnvironment::addButton(const core::rect<s32>& rectangle, IGUIElement* parent, s32 id, const wchar_t* text)
{
IGUIButton* button = new CGUIButton(this, parent ? parent : this, id, rectangle);
if (text)
button->setText(text);
button->drop();
return button;
}


//! adds a window. The returned pointer must not be dropped.
IGUIWindow* CGUIEnvironment::addWindow(const core::rect<s32>& rectangle, bool modal,
const wchar_t* text, IGUIElement* parent, s32 id)
{
parent = parent ? parent : this;

if (modal)
{
parent = new CGUIModalScreen(this, parent, -1);
parent->drop();
}

IGUIWindow* win = new CGUIWindow(this, parent, id, rectangle);
if (text)
win->setText(text);
win->drop();

return win;
}


//! Adds a message box.
IGUIWindow* CGUIEnvironment::addMessageBox(const wchar_t* caption, const wchar_t* text,
bool modal, s32 flag, IGUIElement* parent, s32 id)
{
if (!CurrentSkin)
return 0;

parent = parent ? parent : this;

core::rect<s32> rect;
core::dimension2d<s32> screenDim, msgBoxDim;

screenDim.Width = parent->getAbsolutePosition().getWidth();
screenDim.Height = parent->getAbsolutePosition().getHeight();
msgBoxDim.Width = CurrentSkin->getSize(gui::EGDS_MESSAGE_BOX_WIDTH);
msgBoxDim.Height = CurrentSkin->getSize(gui::EGDS_MESSAGE_BOX_HEIGHT);

rect.UpperLeftCorner.X = (screenDim.Width - msgBoxDim.Width) / 2;
rect.UpperLeftCorner.Y = (screenDim.Height - msgBoxDim.Height) / 2;
rect.LowerRightCorner.X = rect.UpperLeftCorner.X + msgBoxDim.Width;
rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + msgBoxDim.Height;

if (modal)
{
parent = new CGUIModalScreen(this, parent, -1);
parent->drop();
}

IGUIWindow* win = new CGUIMessageBox(this, caption, text, flag,
parent, id, rect);

win->drop();
return win;
}


//! adds a scrollbar. The returned pointer must not be dropped.
IGUIScrollBar* CGUIEnvironment::addScrollBar(bool horizontal, const core::rect<s32>& rectangle, IGUIElement* parent, s32 id)
{
IGUIScrollBar* bar = new CGUIScrollBar(horizontal, this, parent ? parent : this, id, rectangle);
bar->drop();
return bar;
}


//! Adds an image element.
IGUIImage* CGUIEnvironment::addImage(video::ITexture* image, core::position2d<s32> pos,
bool useAlphaChannel, IGUIElement* parent, s32 id, const wchar_t* text)
{
if (!image)
return 0;

core::dimension2d<s32> sz = image->getOriginalSize();
IGUIImage* img = new CGUIImage(this, parent ? parent : this,
id, core::rect<s32>(pos, sz));

if (text)
img->setText(text);

if (useAlphaChannel)
img->setUseAlphaChannel(true);

img->setImage(image);

img->drop();
return img;
}


//! adds an image. The returned pointer must not be dropped.
IGUIImage* CGUIEnvironment::addImage(const core::rect<s32>& rectangle, IGUIElement* parent, s32 id, const wchar_t* text)
{
IGUIImage* img = new CGUIImage(this, parent ? parent : this,
id, rectangle);

if (text)
img->setText(text);

img->drop();
return img;
}


//! adds an mesh viewer. The returned pointer must not be dropped.
IGUIMeshViewer* CGUIEnvironment::addMeshViewer(const core::rect<s32>& rectangle, IGUIElement* parent, s32 id, const wchar_t* text)
{
IGUIMeshViewer* v = new CGUIMeshViewer(this, parent ? parent : this,
id, rectangle);

if (text)
v->setText(text);

v->drop();
return v;
}


//! adds a checkbox
IGUICheckBox* CGUIEnvironment::addCheckBox(bool checked, const core::rect<s32>& rectangle, IGUIElement* parent, s32 id, const wchar_t* text)
{
IGUICheckBox* b = new CGUICheckBox(checked, this,
parent ? parent : this , id , rectangle);

if (text)
b->setText(text);

b->drop();
return b;
}



//! adds a list box
IGUIListBox* CGUIEnvironment::addListBox(const core::rect<s32>& rectangle,
IGUIElement* parent, s32 id,
bool drawBackground)
{
IGUIListBox* b = new CGUIListBox(this, parent ? parent : this, id, rectangle,
true, drawBackground, false);
b->setIconFont(getBuiltInFont());
b->drop();
return b;

}



//! adds a file open dialog. The returned pointer must not be dropped.
IGUIFileOpenDialog* CGUIEnvironment::addFileOpenDialog(const wchar_t* title,
bool modal,
IGUIElement* parent, s32 id)
{
parent = parent ? parent : this;

if (modal)
{
parent = new CGUIModalScreen(this, parent, -1);
parent->drop();
}

IGUIFileOpenDialog* d = new CGUIFileOpenDialog(FileSystem, title,
this, parent, id);

d->drop();
return d;
}



//! adds a static text. The returned pointer must not be dropped.
IGUIStaticText* CGUIEnvironment::addStaticText(const wchar_t* text,
const core::rect<s32>& rectangle,
bool border,
bool wordWrap,
IGUIElement* parent, s32 id)
{
IGUIStaticText* d = new CGUIStaticText(text, border, this,
parent ? parent : this, id, rectangle);

d->setWordWrap(wordWrap);
d->drop();

return d;
}



//! Adds an edit box. The returned pointer must not be dropped.
IGUIEditBox* CGUIEnvironment::addEditBox(const wchar_t* text,
const core::rect<s32>& rectangle,
bool border, IGUIElement* parent,
s32 id)
{
IGUIEditBox* d = new CGUIEditBox(text, border, this,
parent ? parent : this, id, rectangle, Operator);

d->drop();
return d;
}

//! Adds a tab control to the environment.
IGUITabControl* CGUIEnvironment::addTabControl(const core::rect<s32>& rectangle,
IGUIElement* parent, bool fillbackground, bool border, s32 id)
{
IGUITabControl* t = new CGUITabControl(this, parent ? parent : this,
rectangle, fillbackground, border, id);
t->drop();
return t;
}


//! Adds tab to the environment.
IGUITab* CGUIEnvironment::addTab(const core::rect<s32>& rectangle,
IGUIElement* parent, s32 id)
{
IGUITab* t = new CGUITab(-1, this, parent ? parent : this,
rectangle, id);
t->drop();
return t;
}


//! Adds a context menu to the environment.
IGUIContextMenu* CGUIEnvironment::addContextMenu(const core::rect<s32>& rectangle,
IGUIElement* parent, s32 id)
{
IGUIContextMenu* c = new CGUIContextMenu(this,
parent ? parent : this, id, rectangle);
c->drop();
return c;
}


//! Adds a menu to the environment.
IGUIContextMenu* CGUIEnvironment::addMenu(IGUIElement* parent, s32 id)
{
if (!parent)
parent = this;

IGUIContextMenu* c = new CGUIMenu(this,
parent, id, core::rect<s32>(0,0,
parent->getAbsolutePosition().getWidth(),
parent->getAbsolutePosition().getHeight()));

c->drop();
return c;
}

//! Adds a toolbar to the environment. It is like a menu is always placed on top
//! in its parent, and contains buttons.
IGUIToolBar* CGUIEnvironment::addToolBar(IGUIElement* parent, s32 id)
{
if (!parent)
parent = this;

IGUIToolBar* b = new CGUIToolBar(this, parent, id, core::rect<s32>(0,0,10,10));
b->drop();
return b;
}



//! Adds an element for fading in or out.
IGUIInOutFader* CGUIEnvironment::addInOutFader(const core::rect<s32>* rectangle, IGUIElement* parent, s32 id)
{
core::rect<s32> rect;

if (rectangle)
rect = *rectangle;
else
if (Driver)
rect = core::rect<s32>(core::position2d<s32>(0,0), Driver->getScreenSize());

if (!parent)
parent = this;

IGUIInOutFader* fader = new CGUIInOutFader(this, parent, id, rect);
fader->drop();
return fader;
}


//! Adds a combo box to the environment.
IGUIComboBox* CGUIEnvironment::addComboBox(const core::rect<s32>& rectangle,
IGUIElement* parent, s32 id)
{
IGUIComboBox* t = new CGUIComboBox(this, parent ? parent : this,
id, rectangle);
t->drop();
return t;

}
IGUILoadBar* CGUIEnvironment::addLoadBar(const core::rect<s32>& rectangle,
IGUIElement* parent, s32 id, bool vis,s32 TotalNum)
{
IGUILoadBar* loadbar = new CGUILoadBar(this, parent ? parent : this, id, rectangle,vis,TotalNum);

loadbar->drop();
return loadbar;
}


//! returns the font
IGUIFont* CGUIEnvironment::getFont(const c8* filename)
{
// search existing font

SFont f;
if (!filename)
filename = "";

f.Filename = filename;
f.Filename.make_lower();

s32 index = Fonts.binary_search(f);
if (index != -1)
return Fonts[index].Font;

// not existing yet. try to load font.

CGUIFont* font = new CGUIFont(Driver);
if (!font->load(filename))
{
font->drop();
return 0;
}

// add to fonts.

f.Font = font;
Fonts.push_back(f);

return font;
}



//! returns default font
IGUIFont* CGUIEnvironment::getBuiltInFont()
{
if (Fonts.empty())
return 0;

return Fonts[0].Font;
}


//! Returns the root gui element.
IGUIElement* CGUIEnvironment::getRootGUIElement()
{
return this;
}



//! creates an GUI Environment
IGUIEnvironment* createGUIEnvironment(io::IFileSystem* fs, video::IVideoDriver* Driver,
IOSOperator* op)
{
return new CGUIEnvironment(fs, Driver, op);
}

} // end namespace gui
} // end namespace irr

//////IGUILoadBar.h(added)///////

#ifndef __I_GUI_LOADBAR_H_INCLUDED__
#define __I_GUI_LOADBAR_H_INCLUDED__

#include "IGUIElement.h"
#include "SColor.h"

namespace irr
{

namespace gui
{
class IGUILoadBar : public IGUIElement
{
public:
//! constructor
IGUILoadBar(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle,bool vis,s32 TotalNum)
: IGUIElement(environment, parent, id, rectangle) {}
//! destructor
~IGUILoadBar() {};

virtual void setVisible(bool t_f=true)=0;

virtual void setPercent(s32 p=0)=0;

virtual void setColor(video::SColor color)=0;

virtual s32 getPercent()=0;

virtual bool isComplete()=0;


};


} // end namespace gui
} // end namespace irr

#endif

////// CGUILoadBar.h(added)////////

#ifndef __C_GUI_LOADBAR_H_INCLUDED__
#define __C_GUI_LOADBAR_H_INCLUDED__

#include "IGUILoadBar.h"
#include "SColor.h"


namespace irr
{
namespace gui
{
class CGUILoadBar : public IGUILoadBar
{
public:

//! constructor
CGUILoadBar(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle,bool vis=true,s32 TotalNum=7);

//! destructor
~CGUILoadBar();

virtual void draw();

virtual void setVisible(bool t_f=true);

virtual void setPercent(s32 p=0);

virtual void setColor(video::SColor color);

virtual s32 getPercent();

virtual bool isComplete();

private:

// Percentage of loading bar.
s32 Percent;
s32 PercentNum;
s32 MaxNum; //The far right X pos of the border

//Visible?
bool isVisible;
bool isDone;

//Draw border?
bool Border;
core::rect<s32> BorderRect;
core::rect<s32> AbsoluteBorderRect;

//Loading bar rectangle
core::rect<s32> LoadRect;
//Loading color
video::SColor loadcolor;

};


} // end namespace gui
} // end namespace irr

#endif


//////// CGUILoadBar.cpp(added)/////

#include "CGUILoadBar.h"
#include "IGUISkin.h"
#include "IGUIEnvironment.h"
#include "IVideoDriver.h"

namespace irr
{
namespace gui
{
//! constructor
CGUILoadBar::CGUILoadBar(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle,bool vis,s32 TotalNum)
: IGUILoadBar(environment, parent, id, rectangle,vis,TotalNum),
Percent(0),Border(true),isVisible(vis),AbsoluteBorderRect(rectangle),BorderRect(rectangle),
MaxNum(TotalNum),isDone(false),loadcolor(video::SColor(255,0,80,150))
{

#ifdef _DEBUG
setDebugName("CGUILoadBar");
#endif
}
//! destructor
CGUILoadBar::~CGUILoadBar()
{

}

void CGUILoadBar::draw()
{
if (!IsVisible)
return;
IGUISkin* skin = Environment->getSkin();
irr::video::IVideoDriver* driver = Environment->getVideoDriver();

if (Border)
{
BorderRect.LowerRightCorner.Y = BorderRect.UpperLeftCorner.Y + 1;
driver->draw2DRectangle(skin->getColor(EGDC_3D_SHADOW), BorderRect, &AbsoluteBorderRect);

BorderRect.LowerRightCorner.Y = AbsoluteBorderRect.LowerRightCorner.Y;
BorderRect.LowerRightCorner.X = BorderRect.UpperLeftCorner.X + 1;
driver->draw2DRectangle(skin->getColor(EGDC_3D_SHADOW), BorderRect, &AbsoluteBorderRect);

BorderRect = AbsoluteBorderRect;
BorderRect.UpperLeftCorner.X = BorderRect.LowerRightCorner.X - 1;
driver->draw2DRectangle(skin->getColor(EGDC_3D_HIGH_LIGHT), BorderRect, &AbsoluteBorderRect);

BorderRect = AbsoluteBorderRect;
BorderRect.UpperLeftCorner.Y = AbsoluteBorderRect.LowerRightCorner.Y - 1;
BorderRect.LowerRightCorner.Y = AbsoluteBorderRect.LowerRightCorner.Y;
driver->draw2DRectangle(skin->getColor(EGDC_3D_HIGH_LIGHT), BorderRect, &AbsoluteBorderRect);

BorderRect = AbsoluteBorderRect;
BorderRect.UpperLeftCorner.X += 3;
}

//if(Percent == 0) { return; }
MaxNum = AbsoluteBorderRect.LowerRightCorner.X - 1;
PercentNum = (Percent * MaxNum) / 100;
PercentNum += BorderRect.UpperLeftCorner.X;

LoadRect = BorderRect;
LoadRect.UpperLeftCorner.X = BorderRect.UpperLeftCorner.X;
LoadRect.LowerRightCorner.X = PercentNum;
LoadRect.LowerRightCorner.Y -= 1;

driver->draw2DRectangle(loadcolor,LoadRect,&AbsoluteBorderRect);


if(Percent == 100)
{ isDone = true; }


IGUIElement::draw();
}

void CGUILoadBar::setVisible(bool t_f)
{
isVisible = t_f;
}

void CGUILoadBar::setPercent(s32 p)
{
Percent = p;
}

void CGUILoadBar::setColor(video::SColor color)
{
loadcolor=color;
}

s32 CGUILoadBar::getPercent()
{
return Percent;
}

bool CGUILoadBar::isComplete()
{
return isDone;
}





} // end namespace gui
} // end namespace irr

///////////end///////

I'm happy I can be helpfull to the comunity somehow.
Unfortunatly I dont have that much time, even thow ideas I have and migth say big ones for Irrlicht, but who to put them in practice? One person?It couldnt be done only by myself
i.e. look at the comercial engines on this page http://www.devmaster.net/engines and see that they were made by a team. Too bad Irrlicht dosent have a team. Ah and look at the open sorce engine on that page and on the 3-rd place you shall see ... gues who.
Kat'Oun
katoun
Posts: 239
Joined: Mon Nov 15, 2004 9:39 am
Location: Romania
Contact:

Post by katoun »

:lol:
I looked at my replay and I think I might add here all the source of the Irrlicht0.8 i'm modefing (adding options like the one above or things from IrrlichtNX and not in Irrlicht) :lol:
Ofcourse it would be a bad thing to do that :shock: .
I was kiding ofcourse!
Kat'Oun
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

You can grab DarkWhoppy's files here:
http://www.danielpatton.com/afecelis/fi ... ingbar.zip
MikeR
Posts: 767
Joined: Sun Dec 26, 2004 4:03 pm
Location: Northern California USA
Contact:

Post by MikeR »

I'm to the point that I decided to attempt this.
First off, I'm still learning so my questions may seem....
I put this code in main, just after my event reciever.
Is this the proper place?

Code: Select all


CLoadingBar* LoadBar; 

LoadBar = new CLoadingBar(_device,rect<s32>(0,25,800,50),true,7); 

LoadBar->setPercent(25); 
LoadBar->draw(); 

//Load some more stuff 
LoadBar->setPercent(50); 
LoadBar->draw(); 

//Load more stuff 
LoadBar->setPercent(100); 
LoadBar->draw(); 

LoadBar->setVisible(false); 
I'm getting CLoadingBar undefined errors when I compile.
I have the cpp and h files added to my project.
I understand I need to define it, but don't know how.
If it exists in the real world, it can be created in 3d

Sys specs:
AMD 3700+ 64 processor
1.0 gb ram
e-Geforce 6600 graphics 256 mb onboard ram
puh
Posts: 356
Joined: Tue Aug 26, 2003 3:53 pm

Post by puh »

add #include "CLoadingBar.h" in top of your file
MikeR
Posts: 767
Joined: Sun Dec 26, 2004 4:03 pm
Location: Northern California USA
Contact:

Post by MikeR »

Lol. Was thinking about why this didn't work yesterday at work. That same thought came to mind. :D
I knew that. duhh, i can be such a dunce sometimes. :lol:
Thanks.

Edit:

Code: Select all

int main()
{
   //splash screen test
    CLoadingBar* LoadBar; 

LoadBar = new CLoadingBar(_device,rect<s32>(0,25,800,50),true,7); 

LoadBar->setPercent(25); 
LoadBar->draw(); 

//Load some more stuff 
LoadBar->setPercent(50); 
LoadBar->draw(); 

//Load more stuff 
LoadBar->setPercent(100); 
LoadBar->draw(); 

LoadBar->setVisible(false); 

//End Splash Screen  
Correct placing?
The h and cpp are in the same folder as the exe but this crashes the app.
If it exists in the real world, it can be created in 3d

Sys specs:
AMD 3700+ 64 processor
1.0 gb ram
e-Geforce 6600 graphics 256 mb onboard ram
Gao
Posts: 6
Joined: Wed Mar 01, 2006 7:55 pm

Post by Gao »

For me it works and very cool, but how can i add an image into the background and how can i turn off the border? :(
dejai
Posts: 522
Joined: Sat Apr 21, 2007 9:00 am

Post by dejai »

By doing something like this...

Code: Select all

void CBarLoader::Init()
{
 ITexture* Intro = _driver->getTexture("media/textures");
   Intro= ScaleTexture(Intro,  _driver , dimension2d<s32>((BorderRect.LowerRightCorner.X ), ( BorderRect.LowerRightCorner.Y)));
   _gui->addImage( Intro, position2d<s32>(0,0), true, 0, -1, 0);

}
Adding _gui_>drawAll(); in the draw function and

To scale for res I would use Lomesome Ducks Code..

Code: Select all


  ITexture* CLoadingBar::ScaleTexture(ITexture* tTex, IVideoDriver* vDriver, dimension2d<s32> dSize) 
         {
                     IImage* iImage1;
                     iImage1 = vDriver->createImageFromData(tTex->getColorFormat(), tTex->getSize(), tTex->lock());
                     ITexture* tNew;
                     tNew = vDriver->addTexture(dSize, "Texture");
                     IImage* iImage2 = vDriver->createImageFromData(tTex->getColorFormat(), dSize, tNew->lock());
                     iImage1->copyToScaling(iImage2);
                     tTex->unlock();
                     tTex = vDriver->addTexture(tTex->getName().c_str(),iImage2);
                     return tTex;
                     iImage1->drop();
                     iImage2->drop();
                     vDriver->removeTexture(tNew);
                  
         }
Done
Programming Blog: http://www.uberwolf.com
Post Reply