Editbox is greyed out?

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
utimagus
Posts: 17
Joined: Fri May 26, 2006 2:55 pm

Editbox is greyed out?

Post by utimagus »

I have the following code for two editbox's:
env->addEditBox(L"", core::rect<s32>(364, 412, 539, 432), true, 0, -1);
env->addEditBox(L"", core::rect<s32>(364, 380, 539, 400), true, 0, -1);

however when I compile and run the program, the editbox's are greyed out and will not accept input. I figured the problem was with my code. So I went to the MeshViewer demo and looked it over to see if what the differance is between my editbox's that don't take input and the ones in the demo that do take input. Alas I can't seem to find any differance other than the ones in the demo being the children of a tab. So basically I need to know what I'm doing wrong with my editbox's.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

You might want to check to see that you don't have a user event receiver that is intercepting all of the keyboard input. If your event receiver returns true when a key is pressed, the gui will never receive that message, so it will appear that it is ignoring your input.

Also, the default edit box background color is partially transparent, so they may look disabled when rendering on top of a dark scene. You can change the background of the edit boxes pretty easily.

Code: Select all

  env->getSkin()->setColor(gui::EGDC_WINDOW, video::SColor(255, 250, 250, 250));
Travis
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

I don't know what u mean with greyed out.....they are normaly grey but i had a similar problem in an early attemp with irrlicht. my eventreceiver caught every input from my keyboard and nothing went throught to the gui. maybe it's that and u have to redesign ur receiver.

edit: shouldn't open a threaht then go away come back later and write a reply without reloading...lol
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
utimagus
Posts: 17
Joined: Fri May 26, 2006 2:55 pm

Post by utimagus »

ok the color fix made it so it wasn't greyed out. however normally in an edit box there is some sort of cursor to show that you can enter data into it. this is not the case here. any ideas on how to make it so you can get a cursor to show up in the editbox and to allow data to be entered therein.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

If the edit box has the focus you should see a flashing cursor. It isn't super visible with the default font, but it is there.

Another reason you may be having problems entering text is that you could have an invisible gui element on top of the edit box. When you click in the edit box, the event is picked up by that invisible gui control.

Travis
utimagus
Posts: 17
Joined: Fri May 26, 2006 2:55 pm

Post by utimagus »

makes sense with the focus. So the million dollar question is how do I give it focus? There shouldn't be any gui elements above the edit box as there are only 2 edit boxes and they display in two differant parts of the window.
utimagus
Posts: 17
Joined: Fri May 26, 2006 2:55 pm

Post by utimagus »

ok I managed to give it focus, now there is the cursor but I am not able to input data. Is there something else that must be set in order to be allowed to enter data?
utimagus
Posts: 17
Joined: Fri May 26, 2006 2:55 pm

Post by utimagus »

may as well post all my code as well :)
// Tempest-ToW.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


#include <irrlicht.h>
#include <iostream>
#include <windows.h>

//set namespaces so we can do things a bit faster
using namespace irr;
using namespace gui;

#pragma comment(lib, "Irrlicht.lib")

//Initialize globals
// create device
IrrlichtDevice *device = createDevice(video::EDT_DIRECT3D9, core::dimension2d<s32>(800, 600));
video::IVideoDriver* driver = device->getVideoDriver();
video::ITexture* images = NULL;
core::stringw MessageText;
core::stringw Caption;

//initializes the gui
IGUIEnvironment* env = device->getGUIEnvironment();

int cnt = 200;

enum{
PRE_LOGIN = 0,
LOGIN_SCREEN = 1
};

class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
if (event.EventType == EET_GUI_EVENT)
{
s32 id = event.GUIEvent.Caller->getID();

switch(event.GUIEvent.EventType)
{

case EGET_BUTTON_CLICKED:

if (id == 103)
{
IGUIWindow* window = env->addWindow(core::rect<s32>(100 + cnt, 100 + cnt, 300 + cnt, 200 + cnt),
false, // modal?
L"Not Implemented");

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

return true;
}
break;
}
}
return false;
}
};

void SceneIndex(video::IVideoDriver* driver, video::ITexture* images, unsigned char state)
{
switch(state)
{
case PRE_LOGIN:
//loads the image we want and sets what color should be transparent..
images = driver->getTexture("Media\\2d\\ShadowSoftLogo.jpg");
driver->draw2DImage(images, core::position2d<s32>(0,0));
break;

case LOGIN_SCREEN:

IGUIElement * element;


//loads the image we want and sets what color should be transparent..
images = driver->getTexture("Media\\2d\\loginscreen.jpg");
// draw login screen image
driver->draw2DImage(images, core::position2d<s32>(0,0));

// create the toolbox window
env->addEditBox(L"", core::rect<s32>(364, 412, 539, 432), true, 0, 100);
env->addEditBox(L"", core::rect<s32>(364, 380, 539, 400), true, 0, 101);
env->addButton(core::rect<s32>(420, 344, 540, 364), 0, 104, L"Register an Account");
env->addButton(core::rect<s32>(370, 344, 414, 364), 0, 103, L"Login");

//env->setFocus(element);


env->getSkin()->setColor(gui::EGDC_WINDOW, video::SColor(255, 250, 250, 250));

break;
}
}

unsigned char GetState(const int& ticks)
{
if(ticks < 5000)
return 0;

if(ticks > 5000)
return 1;
}


void RunGame()
{

MyEventReceiver receiver;

device->setEventReceiver(&receiver);
device->setWindowCaption(L"Tempest: Trials of War");
int ticks = 0;
while(device->run() && driver)
{

ticks++;
driver->beginScene(true, true, video::SColor(0,0,0,0));
//things to be drawn happen after beginscene

SceneIndex(driver, images, GetState(ticks));

env->drawAll();
driver->endScene();
}
device->drop();
}


int WINAPI WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
RunGame();
return 0;
}
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Congrats dude, you have written one very big memory leak... :)

You are calling SceneIndex() every tick. After 5000 ticks [the amount of time will vary depending on screen resolution and graphics card], your GetState() will start returning 1 [LOGIN_SCREEN]. As a result, SceneIndex() will add a series of gui elements. You add all of the gui elements to the screen over and over every tick.

When you try to make one of the edit boxes have the focus, another is rendered right on top of it, making it look like it never got the focus.

You can prove to yourself that this is actually the problem by making the following change...

Code: Select all

unsigned char GetState(const int& ticks) 
{ 
   if(ticks < 5000) 
      return PRE_LOGIN; 

   if(ticks == 5000) 
      return LOGIN_SCREEN; 

   return 2;
} 
Travis
utimagus
Posts: 17
Joined: Fri May 26, 2006 2:55 pm

Post by utimagus »

hmmm makes sense. I will change my code once i get my machine fixed as I believe my motherboard just ate itself...
Post Reply