resizing images for gui

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.

resizing images for gui

Postby aburt11 » Wed Jun 13, 2012 11:14 am

hey there,
i am building my gui using images, but i dont know how i would get them to rescale.
any help??
gui.cpp
cpp Code: Select all
 
#include "main.h"
 
 
void redNovember::fadeInTransition()
{
        fader->setColor(video::SColor(0,0,0,0));
        fader->fadeOut(4000);
}
 
void redNovember::fadeOutTransition()
{
        fader->setColor(video::SColor(0,0,0,0));
        fader->fadeIn(4000);
}
 
void redNovember::showInGameMenu()
{
 
        driver->enableMaterial2D();
 
device->getGUIEnvironment()->addImage(
        driver->getTexture("assets/gui/ingamemenu_placeholder.png"),
                        core::position2d<s32>(800,600)); //testing
       
                gui::IGUIStaticText* diagnostics = device->getGUIEnvironment()->addStaticText(
                        L"", core::rect<s32>(10, 10, 400, 20));
                diagnostics->setOverrideColor(video::SColor(255, 255, 255, 0));
 
                driver->enableMaterial2D(false);
       
        //show the mouse cursor
        device->getCursorControl()->setVisible(true);
 
}
 
void redNovember::hideInGameMenu()
{
        //hide the mouse cursor
        device->getCursorControl()->setVisible(false);
}
 
void redNovember::MenuBG()
{
        LoadScene("assets/Levels/Main Menu/main.3ds","assets/Levels/Main Menu/main.jpg");
 
}
 
void redNovember::DrawText(const char* TextContext,int textx1,int texty1,int textx2,int texty2)
{
        font->draw(TextContext,
                core::rect<s32>(textx1,texty1,textx2,texty2),
                video::SColor(255,255,255,255));
}
 
[color=#FF40BF]void redNovember::StartMenu()
{
        LoadImage("assets/gui/Menu/skylinelogoblack.png",300,200);
        LoadImage("assets/gui/Menu/skylinetitlecredit.png",400,400);
}
 
[/color]
 
void redNovember::MainMenu()
{
 
        LoadImage("assets/gui/Menu/skylinelogoblack.png",GameWindowWidth/2,GameWindowHeight/2);//Skyline Logo
}
 


scene.cpp
cpp Code: Select all
#include "main.h"
 
//put some stuff here regarding loading the scene file with the gui later on in the coding
 
//char selectedScene;
 
 
[color=#FF40BF]void redNovember::LoadImage(const char* ImageFilename,int ImagePosX, int ImagePosY)
{
        device->getGUIEnvironment()->addImage(
                                driver->getTexture(ImageFilename),
                                core::position2d<s32>(ImagePosX,ImagePosY));
 
}
[/color]
 
void redNovember::LoadScene(const char* SceneModelFile, const char* SceneTextureFile)
{
 
        IAnimatedMesh* model = smgr->getMesh(SceneModelFile); //placeholder.3ds
                IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( model );
       
                if (node)
                {
                        //video::ITexture* bump = driver->getTexture(""); bump mapping
                        //driver->makeNormalMapTexture(bump,9.0f);
               
                        //node->setMaterialFlag(EMF_LIGHTING, false);
                        node->setMaterialTexture( 0, driver->getTexture(SceneTextureFile) );
                        node->setPosition(core::vector3df(0,0,0));
                        node->setMaterialFlag(EMF_LIGHTING,false);
                        node->setMaterialFlag(EMF_FOG_ENABLE,false);
                //      node->setMaterialType((video::E_MATERIAL_TYPE)bokehDOFMaterial);
                       
                        //node->setMaterialType((video::E_MATERIAL_TYPE)ssaoMaterial); //not working properly yet!
                }
       
}
 
 
 
 
 
 
void redNovember::initSkybox(const char* up,const char* down,const char* left, const char* right, const char* front, const char* back)
{
        // create skybox and skydome
        driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);
 
        scene::ISceneNode* skybox=smgr->addSkyBoxSceneNode(
                driver->getTexture(up),
                driver->getTexture(down),
                driver->getTexture(left),
                driver->getTexture(right),
                driver->getTexture(front),
                driver->getTexture(back));
}
 
void redNovember::initSkydome(const char* skydomefile)
{
        scene::ISceneNode* skydome=smgr->addSkyDomeSceneNode(driver->getTexture(skydomefile),50,50,0.95f,1.0f); ///change end values
 
        driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);
}


main.cpp
cpp Code: Select all
 
#include "main.h"
#include "luamanager.h"
#include "physicsmanager.h"
 
LuaManager * LUA = new LuaManager;
//newtonManager* PHYS = new newtonManager;
redNovember* SYS = new redNovember;
MyEventReceiver receiver;
bool InGame;
 
 
 
 
void redNovember::GameLoop()
{
        /*
        if(!InGame)
                {
                        SYS->StartMenu();
       
       
                }*/

       
};
 
 
 
int redNovember::shutdown()
{
        LUA->DropLua();
        delete LUA;
        //PHYS->drop();
 
        device->drop();
       
        //delete PHYS;
        delete SYS;
        return 0;
}
 
int main()
{
        InGame = false;
 
[color=#FF40BF]
        SYS->initIrrlicht();
 
        if(!InGame)
        {
                SYS->MenuBG();
 
        LUA->loadScript("assets/scripts/test.lua"); //main scripthook
        SYS->StartMenu();
[/color]
 
        }
        else
        {
 
//      SYS->LoadScene();
        SYS->initFPSCamera();
       
       
        SYS->initFog();
        SYS->initSkydome("assets/skydome/storm1.jpg");
        }
       
       
        SYS->renderScene();
 
 
        SYS->shutdown();
 
}
 
void redNovember::initIrrlicht()
{
        GameWindowWidth = 800;
        GameWindowHeight = 600;
        GameWindowFullscreen = false;
       
        device = createDevice(EDT_OPENGL, dimension2d<u32>(GameWindowWidth, GameWindowHeight), 32,
                GameWindowFullscreen, false, true,&receiver);
 
        device->setWindowCaption(L"Project: Red November");
 
        driver = device->getVideoDriver();
        smgr = device->getSceneManager();
        guienv = device->getGUIEnvironment();
 
        device->getCursorControl()->setVisible(false); //hide cursor
        fader = device->getGUIEnvironment()->addInOutFader();
 
        //initialize state switches
        showGameMenu = false;
       
         //font =
                //device->getGUIEnvironment()->getFont("assets/helvetica.ttf");
 
       
        // And tell the device to use our custom event receiver.
        device->setEventReceiver(&receiver);
       
 
 
}
 
 
void redNovember::renderScene()
{
        int lastFPS = -1;
 
        while(device->run())
        {
               
                inputHandle(); //input handler
 
                GameLoop();
 
 
                if(!device->isWindowActive())
                {
                        //add pause functions here
 
 
                }
                if (device->isWindowActive())
                {
                        driver->beginScene(true, true, video::SColor(255,200,200,200));
 
                        smgr->drawAll();
 
                        guienv->drawAll();
                        device->getGUIEnvironment()->drawAll(); // draw the gui environment (the logo)
 
                        driver->endScene();
 
                        int fps = driver->getFPS();
 
                        if (lastFPS != fps)
                        {
                                core::stringw str = L"[";
                                str += driver->getName();
                                str += "] FPS:";
                                str += fps;
 
                                device->setWindowCaption(str.c_str());
                                lastFPS = fps;
                        }
                }
                else
                        device->yield();
        }
 
}
 
 
void redNovember::inputHandle()
{
       
        if(InGame)
        {
 
                if(showGameMenu)
                {
                        showInGameMenu();
 
                        if(receiver.IsKeyDown(irr::KEY_ESCAPE))
                                showGameMenu = false;
                }
                else
                {
                        hideInGameMenu();
                        if(receiver.IsKeyDown(irr::KEY_ESCAPE))
                                showGameMenu = true;
                }
       
        }
        else // equals main menu
        {
 
        }
                       
       
};
 
 



ive highlighted the relative code in pink.
aburt11
 
Posts: 66
Joined: Sun Jan 15, 2012 10:27 am

Re: resizing images for gui

Postby CuteAlien » Wed Jun 13, 2012 11:53 am

Don't see pink, but in general you have 2 ways to resize images. Fist make it scalable with setScaleImage (true) (might even be default). Then you can use setRelativePosition with core::rect and just set a larger rectangle.
The alternative to resizing each image is when you want to have it resized for different solutions. Then it's better if all elements have a common parent element. You resize only the parent and all childrens have alignment flags, set with setAlignment, to define how they behave when the parent resizes.
IRC: #irrlicht on irc.freenode.net
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Games with Irrlicht: http://www.irrgheist.com/
News: http://www.reddit.com/r/irrlicht/
User avatar
CuteAlien
Admin
 
Posts: 5396
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: resizing images for gui

Postby aburt11 » Thu Jun 14, 2012 3:50 am

are they even real functions??
aburt11
 
Posts: 66
Joined: Sun Jan 15, 2012 10:27 am

Re: resizing images for gui

Postby CuteAlien » Thu Jun 14, 2012 8:31 am

aburt11 wrote:are they even real functions??


Not exactly sure what you mean. But if you talk about the functions I mentioned - they are member functions of IGUIImage and the base-class IGUIElement.
IRC: #irrlicht on irc.freenode.net
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Games with Irrlicht: http://www.irrgheist.com/
News: http://www.reddit.com/r/irrlicht/
User avatar
CuteAlien
Admin
 
Posts: 5396
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany


Return to Beginners Help

Who is online

Users browsing this forum: Google [Bot] and 1 guest