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 ?
Cursor position in title bar
Cursor position in title bar
Please forgive any spelling mistake i could have done , this is my 2nd language.
Re: Cursor position in title bar
// 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());
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());
Re: Cursor position in title bar
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:
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.
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;
}
Please forgive any spelling mistake i could have done , this is my 2nd language.
Re: Cursor position in title bar
Use the same method only use device-getcursorcontrol-get position. X and y
Re: Cursor position in title bar
Thanks for the replies seven, i have almost what i need.
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 ?
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;
}
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.
Re: Cursor position in title bar
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
Put the text = blah blah and the text += cursor so it is inside the while device run loop. Then it executes every loop
Re: Cursor position in title bar
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.
Re: Cursor position in title bar
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;
}
Re: Cursor position in title bar
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
Please forgive any spelling mistake i could have done , this is my 2nd language.
Re: Cursor position in title bar
Solved
Please forgive any spelling mistake i could have done , this is my 2nd language.