Cursor position in title bar

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.
Post Reply
2ant
Posts: 8
Joined: Mon Jul 14, 2014 7:06 pm

Cursor position in title bar

Post by 2ant »

Hello everyone, i am new at using c++ and irrlicht.
I want to display the cursor position in the title bar next to the title and i don't know how to get something that "device->setWindowCaption" can use.
Can you help me ?
Please forgive any spelling mistake i could have done , this is my 2nd language.
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: Cursor position in title bar

Post by Seven »

// declare a stringw variable and set it to some text
stringw text(L"Irrlicht - camera position = ");

// add the camera position X,Y,Z to the text variable, with a space padding between them
text += camera->getAbsolutePosition().X;
text += L" ";
text += camera->getAbsolutePosition().Y;
text += L" ";
text += camera->getAbsolutePosition().Z;

// set the window text
device->setWindowCaption(text.c_str());
2ant
Posts: 8
Joined: Mon Jul 14, 2014 7:06 pm

Re: Cursor position in title bar

Post by 2ant »

I should have given more info, i don't have a camera, i'm just using some 2d and gui fonctions.
Here is my code:

Code: Select all

#include <IRR/irrlicht.h>
 
using namespace irr;
 
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
 
int main(void)
{
    IrrlichtDevice *device = createDevice (EDT_OPENGL,dimension2d<irr::u32>(1280,720),32,false,true,false,0);
        IVideoDriver* driver = device->getVideoDriver ();
        ISceneManager *sceneManager = device->getSceneManager ();
 
 
        IGUIEnvironment *gui = device->getGUIEnvironment();
 
        gui->addStaticText(L"Plop",rect<s32>(300,20,400,60), true, true, 0, -1, true);
 
        gui->addImage(driver->getTexture("knight1.png"),position2d<int>(10,10));
        gui->addImage(driver->getTexture("knight2.png"),position2d<int>(500,10));
 
 
        stringw text(L"Irrlicht - camera position = ");
 
        device->setWindowCaption(text.c_str());
 
 
    while (device->run ())
        {
            driver->beginScene(true, true,SColor(255,128,225,255));
            sceneManager->drawAll();
            gui->drawAll();
            driver->endScene();
        }
           device->drop ();
    return 0;
}
 
I think i need to use the getposition or getrelativeposition from ICursorControl and put it in a string like you told me but i don't know how.
Please forgive any spelling mistake i could have done , this is my 2nd language.
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: Cursor position in title bar

Post by Seven »

Use the same method only use device-getcursorcontrol-get position. X and y
2ant
Posts: 8
Joined: Mon Jul 14, 2014 7:06 pm

Re: Cursor position in title bar

Post by 2ant »

Thanks for the replies seven, i have almost what i need.

Code: Select all

#include <IRR/irrlicht.h>
 
using namespace irr;
 
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
 
stringw text(L"Irrlicht - cursor position = ");
 
int main(void)
{
    IrrlichtDevice *device = createDevice (EDT_OPENGL,dimension2d<irr::u32>(1280,720),32,false,true,false,0);
        IVideoDriver* driver = device->getVideoDriver ();
        ISceneManager *sceneManager = device->getSceneManager ();
 
 
        IGUIEnvironment *gui = device->getGUIEnvironment();
 
        gui->addStaticText(L"Plop",rect<s32>(300,20,400,60), true, true, 0, -1, true);
 
        gui->addImage(driver->getTexture("knight1.png"),position2d<int>(10,10));
        gui->addImage(driver->getTexture("knight2.png"),position2d<int>(500,10));
 
 
        text += device->getCursorControl ()-> getPosition().X;
        text += device->getCursorControl ()-> getPosition().Y;
 
        device->setWindowCaption(text.c_str());
 
 
    while (device->run ())
        {
            driver->beginScene(true, true,SColor(255,128,225,255));
            sceneManager->drawAll();
            gui->drawAll();
            driver->endScene();
        }
           device->drop ();
    return 0;
}
 
It compile and works fine but the position is not in real time, it is the position of the cursor when i start my program.
What can i do to have the position update itself as the cursor move (or not ?
Please forgive any spelling mistake i could have done , this is my 2nd language.
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: Cursor position in title bar

Post by Seven »

The text+= cursor only executes once.
Put the text = blah blah and the text += cursor so it is inside the while device run loop. Then it executes every loop
2ant
Posts: 8
Joined: Mon Jul 14, 2014 7:06 pm

Re: Cursor position in title bar

Post by 2ant »

I manage to do it, but the += operator doesnt delete the old positions and it immediately fill all the title bar and i can't change it to = or the compiler yells at me .
Please forgive any spelling mistake i could have done , this is my 2nd language.
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: Cursor position in title bar

Post by Seven »

Code: Select all

 
#include <IRR/irrlicht.h>
 
using namespace irr;
 
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
 
int main(void)
{
    IrrlichtDevice *device = createDevice (EDT_OPENGL,dimension2d<irr::u32>(1280,720),32,false,true,false,0);
        IVideoDriver* driver = device->getVideoDriver ();
        ISceneManager *sceneManager = device->getSceneManager ();
 
 
        IGUIEnvironment *gui = device->getGUIEnvironment();
 
        gui->addStaticText(L"Plop",rect<s32>(300,20,400,60), true, true, 0, -1, true);
 
        gui->addImage(driver->getTexture("knight1.png"),position2d<int>(10,10));
        gui->addImage(driver->getTexture("knight2.png"),position2d<int>(500,10));
 
 
    while (device->run ())
        {
              stringw text(L"Irrlicht - cursor position = ");
              text += device->getCursorControl ()-> getPosition().X;
              text += device->getCursorControl ()-> getPosition().Y;
        
             device->setWindowCaption(text.c_str());
 
            driver->beginScene(true, true,SColor(255,128,225,255));
            sceneManager->drawAll();
            gui->drawAll();
            driver->endScene();
        }
           device->drop ();
    return 0;
}
2ant
Posts: 8
Joined: Mon Jul 14, 2014 7:06 pm

Re: Cursor position in title bar

Post by 2ant »

Thank you very much seven , i had not placed the "stringw text" line in the loop and it was enough to anger the compiler.Now it's working perfectly :D
Please forgive any spelling mistake i could have done , this is my 2nd language.
2ant
Posts: 8
Joined: Mon Jul 14, 2014 7:06 pm

Re: Cursor position in title bar

Post by 2ant »

Solved
Please forgive any spelling mistake i could have done , this is my 2nd language.
Post Reply