Make a text box

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
RRain
Posts: 5
Joined: Sun Apr 06, 2008 8:39 pm

Make a text box

Post by RRain »

Firstly I have read over and played with the code from the 7 movement and .5 user interface examples for the past week and I still cannot get this to work. Ultimatley I would like you to be within certain distance of a node when you click on that node a specific text box will open (with dialogue). I am nowhere near my goal.

I thought to start just making a text box show up on screen while I was playing would be enough but i couldn't get anywhere. I have played with code 1,000 times but no luck.

So I started with a button but no luck there either. I'm sure its something stupid in my code I'm missing or put something in the wrong place but I can't seem to find it.


I'm sure you can tell this is just a mix of two different examples but its not working for me! Thanks a lot for your time.

Code: Select all

include <irrlicht.h>
#include <iostream>
//deleted header files from here i don't need because i'm not using visual studio
using namespace irr;
using namespace gui;//added appropriate namespaces
IrrlichtDevice *Device = 0;
/*
core::stringc StartUpModelFile;
core::stringw MessageText;
core::stringw Caption;
scene::IAnimatedMeshSceneNode* Model = 0;
scene::ISceneNode* SkyBox = 0;//here up to 12 may only be needed for the xml parsing, look into it
*/
class MyEventReceiver : public IEventReceiver//event reciever, edit it later
{
public:
	virtual bool OnEvent(const SEvent& event)
	{
		if (event.EventType == EET_GUI_EVENT)
		{
			s32 id = event.GUIEvent.Caller->getID();
			IGUIEnvironment* env = device->getGUIEnvironment();

            switch(event.GUIEvent.EventType)
            {

       case EGET_BUTTON_CLICKED:
              if (id == 101)
              {
                 device->closeDevice();
                 return true;
              }

              if (id == 102)
              {
                 listbox->addItem(L"Window created");
                 cnt += 30;
                 if (cnt > 200)
                   cnt = 0;

                 IGUIWindow* window = env->addWindow(
                       rect<s32>(100 + cnt, 100 + cnt, 300 + cnt, 200 + cnt),
                       false, // modal?
                       L"Test window");

                 env->addStaticText(L"Please close me",
                       rect<s32>(35,35,140,50),
                       true, // border?,
                       false, // wordwrap?
                       window);

                 return true;
              }

              if (id == 103)
              {
                 listbox->addItem(L"File open");
                 env->addFileOpenDialog(L"Please choose a file.");
                 return true;
              }

              break;
          }
       }
       return false;
    }
 };

int main()
{
	// let user select driver type

	video::E_DRIVER_TYPE driverType;

	printf("Please select the driver you want for this example:\n"\
		" (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n"\
		" (d) Software Renderer\n (e) Burning's Software Renderer\n"\
		" (f) NullDevice\n (otherKey) exit\n\n");

	char i;
	std::cin >> i;

	switch(i)
	{
		case 'a': driverType = video::EDT_DIRECT3D9;break;
		case 'b': driverType = video::EDT_DIRECT3D8;break;
		case 'c': driverType = video::EDT_OPENGL;   break;
		case 'd': driverType = video::EDT_SOFTWARE; break;
		case 'e': driverType = video::EDT_BURNINGSVIDEO;break;
		case 'f': driverType = video::EDT_NULL;     break;
		default: return 0;
	}

	// create device

MyEventReceiver receiver;
device->setEventReceiver(&receiver);
device->setWindowCaption(L"Irrlicht Engine - User Inferface Demo");

video::IVideoDriver* driver = device->getVideoDriver();
IGUIEnvironment* env = device->getGUIEnvironment();


	if (device == 0)
		return 1; // could not create selected driver.

//added this but its not nessasary
    Device->setResizeAble(true);//obviously makes the window resizeable
	Device->setWindowCaption(L"Loading...");	//and sets caption
//stopped adding semi-useless code

env->addButton(rect<s32>(10,240,100,270), 0, 101, L"Quit");//added a quit button
//THIS DOSEN'T EVEN WORK
	video::IVideoDriver* driver = device->getVideoDriver();
	scene::ISceneManager* smgr = device->getSceneManager();


	device->getFileSystem()->addZipFileArchive("../../media/map-20kdm2.pk3");


	scene::IAnimatedMesh* q3levelmesh = smgr->getMesh("20kdm2.bsp");
	scene::ISceneNode* q3node = 0;

	if (q3levelmesh)
		q3node = smgr->addOctTreeSceneNode(q3levelmesh->getMesh(0));


	scene::ITriangleSelector* selector = 0;

	if (q3node)
	{
		q3node->setPosition(core::vector3df(-1350,-130,-1400));

		selector = smgr->createOctTreeTriangleSelector(q3levelmesh->getMesh(0), q3node, 128);
		q3node->setTriangleSelector(selector);
	}




	scene::ICameraSceneNode* camera =
		smgr->addCameraSceneNodeFPS(0, 100.0f, 300.0f, -1, 0, 0, true);
	camera->setPosition(core::vector3df(-100,50,-150));

	if (selector)
	{
		scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
			selector, camera, core::vector3df(30,50,30),
			core::vector3df(0,-3,0),
			core::vector3df(0,50,0));
		selector->drop();
		camera->addAnimator(anim);
		anim->drop();
	}



	// disable mouse cursor

	device->getCursorControl()->setVisible(false);

	// add billboard

	scene::IBillboardSceneNode * bill = smgr->addBillboardSceneNode();
	bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR );
	bill->setMaterialTexture(0, driver->getTexture("../../media/particle.bmp"));
	bill->setMaterialFlag(video::EMF_LIGHTING, false);
	bill->setMaterialFlag(video::EMF_ZBUFFER, false);
	bill->setSize(core::dimension2d<f32>(20.0f, 20.0f));

	// add 3 animated faeries.

	video::SMaterial material;
	material.setTexture(0, driver->getTexture("../../media/faerie2.bmp"));
	material.Lighting = true;

	scene::IAnimatedMeshSceneNode* node = 0;
	scene::IAnimatedMesh* faerie = smgr->getMesh("../../media/faerie.md2");

	if (faerie)
	{
		node = smgr->addAnimatedMeshSceneNode(faerie);
		node->setPosition(core::vector3df(-70,0,-90));
		node->setMD2Animation(scene::EMAT_RUN);
		node->getMaterial(0) = material;

		node = smgr->addAnimatedMeshSceneNode(faerie);
		node->setPosition(core::vector3df(-70,0,-30));
		node->setMD2Animation(scene::EMAT_SALUTE);
		node->getMaterial(0) = material;

		node = smgr->addAnimatedMeshSceneNode(faerie);
		node->setPosition(core::vector3df(-70,0,-60));
		node->setMD2Animation(scene::EMAT_JUMP);
		node->getMaterial(0) = material;
	}

	material.setTexture(0, 0);
	material.Lighting = false;

	// Add a light

	smgr->addLightSceneNode(0, core::vector3df(-60,100,400),
		video::SColorf(1.0f,1.0f,1.0f,1.0f),
		600.0f);




	scene::ISceneNode* selectedSceneNode = 0;
	scene::ISceneNode* lastSelectedSceneNode = 0;


	int lastFPS = -1;

IGUIImage* img = env->addImage(
		driver->getTexture("../../media/irrlichtlogoalpha.tga"),
		position2d<int>(10,10));

	while(device->run())
	if (device->isWindowActive())
	{
		driver->beginScene(true, true, 0);

		smgr->drawAll();


		core::line3d<f32> line;
		line.start = camera->getPosition();
		line.end = line.start + (camera->getTarget() - line.start).normalize() * 1000.0f;

		core::vector3df intersection;
		core::triangle3df tri;

		if (smgr->getSceneCollisionManager()->getCollisionPoint(
			line, selector, intersection, tri))
		{
			bill->setPosition(intersection);

			driver->setTransform(video::ETS_WORLD, core::matrix4());
			driver->setMaterial(material);
			driver->draw3DTriangle(tri, video::SColor(0,255,0,0));
		}




		selectedSceneNode = smgr->getSceneCollisionManager()->getSceneNodeFromCameraBB(camera);

		if (lastSelectedSceneNode)
			lastSelectedSceneNode->setMaterialFlag(video::EMF_LIGHTING, true);

		if (selectedSceneNode == q3node || selectedSceneNode == bill)
			selectedSceneNode = 0;

		if (selectedSceneNode)
			selectedSceneNode->setMaterialFlag(video::EMF_LIGHTING, false);

		lastSelectedSceneNode = selectedSceneNode;


		/*
		That's it, we just have to finish drawing.
		*/

		driver->endScene();

		int fps = driver->getFPS();

		if (lastFPS != fps)
		{
		  core::stringw str = L"Caption";
		  str += driver->getName();
		  str += "] FPS:";
		  str += fps;

		  device->setWindowCaption(str.c_str());
		  lastFPS = fps;
		}
	}

	device->drop();

	return 0;
}
Ariemeth
Posts: 3
Joined: Sat Jun 07, 2008 12:54 pm

Post by Ariemeth »

I'm still rather new the Irrlicht engine, however I believe your issue may just be you are not calling the GuiManager to draw its contents in your main loop. You could try to add gui->drawAll(); just after smgr->drawAll(); in your main loop.
renegadeandy
Posts: 122
Joined: Sun May 25, 2008 11:14 pm
Location: Scotland
Contact:

Post by renegadeandy »

that is why -> for both reasons the textbox and the button - these are gui elements and will not be drawn unless the gui->drawAll() is called!

Silly! :P
RRain
Posts: 5
Joined: Sun Apr 06, 2008 8:39 pm

Post by RRain »

ok guys this may have fixed it but i cannot tell. I am getting an error now and its annoying the crap out of me.

Code: Select all

expected primary expression before '->' token
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Well, I guess it will work when you use env->drawAll(), because you named your GUI environment env, not gui :roll:
RRain
Posts: 5
Joined: Sun Apr 06, 2008 8:39 pm

Post by RRain »

hybrid wrote:Well, I guess it will work when you use env->drawAll(), because you named your GUI environment env, not gui :roll:
Wow, how did I miss that? It must of just been a late night or something. I'm sure that will fix my problem but I can't fix it right now because I have to go to work soon. Thanks for your help (even though that was such an obvious problem)
Post Reply