Hi everyone,
I jus encounterd a very weird problem. Can't figure out how it happend.
When i open the file open dialog box or suppose i create buttons on the GUI environment, i can't click the GUI buttons and button on the file open dialog.
I checked all return parameters but can't figure it out wot caused this problem.
All other events like mouse events and Image events are working smoothly.
It seems like it has been disabled automatically.
Need help.
[SOLVED]A weird problem on GUI Events!!!
-
- Posts: 102
- Joined: Sat Jan 17, 2009 4:33 am
- Location: Pune
- Contact:
[SOLVED]A weird problem on GUI Events!!!
Last edited by abhishekdey1985 on Tue May 19, 2009 11:43 am, edited 1 time in total.
I work on "The Best Real-Time 3D Engine"
-
- Posts: 102
- Joined: Sat Jan 17, 2009 4:33 am
- Location: Pune
- Contact:
SOLVED
Ok....solved it. Found an Extra return value in Mouse Input Event Reciever.
Thanx Sylence.
newz here's the my EventReceiver:
Thanx Sylence.
newz here's the my EventReceiver:
Code: Select all
#include "TVREventReceiver.h"
#include "main.h"
#include "CGUIFileSaveDialog.h"
#include <queue>
CGUIFileSaveDialog* dialog;
int clicked_icon = 0;
gui::IGUIImage *tobj,*tempobj;
scene::ISceneNode* SelectedNode = NULL;
bool guievent = false;
int cnt =0, glob_id=-1 ,prev_id=-1, id_set = -1, exitSeq = 0;
int sceneSelected = -1;
core::stringw Caption = "Information";
core::stringw MessageText = "Please Select a Scene before you can proceed.";
bool ShiftIsPressed = false, CtrlIsPressed = false;
bool LMouseButtonDown = false, RMouseButtonDown = false, MMouseButtonDown = false;
core::vector3df radius;
float RotateSpeed = 0.01f;
float ScaleSpeed = 0.01f;
int o_id = 1000, current_id = -1;
queue<int> Q;
bool switchCamera = false;
bool TVREventReceiver::OnEvent(const SEvent &event)
{
s32 id;
if(event.EventType == EET_KEY_INPUT_EVENT)
{
if (event.KeyInput.Shift) ShiftIsPressed = true;
else ShiftIsPressed = false;
if (event.KeyInput.Control) CtrlIsPressed = true;
else CtrlIsPressed = false;
if(event.KeyInput.PressedDown == false)
{
switch(event.KeyInput.Key)
{
case KEY_DELETE:
if(SelectedNode !=NULL)
{
current_id = scanAvailableObjectId(SelectedNode->getID(), 2);
if(current_id != -1)
{
SelectedNode->remove();
}
SelectedNode = NULL;
}
break;
case KEY_ESCAPE:
Device->closeDevice();break;
case KEY_KEY_C:
switchCamera = !switchCamera;
get3rdPersonCamera()->toggleCamera(switchCamera);
break;
case KEY_KEY_S:
dialog = new CGUIFileSaveDialog(L"Save File as...", env, env->getRootGUIElement(), -1);
break;
default:
break;
}
}
}
if(event.EventType == EET_GUI_EVENT)
{
id = event.GUIEvent.Caller->getID();
guievent = true;
switch(event.GUIEvent.EventType)
{
case gui::EGET_ELEMENT_HOVERED:
if(id>=0 && id<=7)
{
tobj = ((gui::IGUIImage *)event.GUIEvent.Caller);
tobj->setImage(getObjectMenuObject()->getHighlightedImage(id));
}
else if(id>=101 && id<=108)
{
tobj = ((gui::IGUIImage *)event.GUIEvent.Caller);
tobj->setImage(getMainMenuObject()->getHighlightedImageMM(id));
}
break;
case gui::EGET_ELEMENT_LEFT:
if(id>=0 && id<=7)
((gui::IGUIImage *)event.GUIEvent.Caller)->setImage(getObjectMenuObject()->getNormalImage(id));
else if(id>=101 && id<=108)
((gui::IGUIImage *)event.GUIEvent.Caller)->setImage(getMainMenuObject()->getNormalImageMM(id));
else
if(event.GUIEvent.Caller->getType() == gui::EGUIET_IMAGE)
glob_id = -1; id = -1;
tobj = NULL;
glob_id = -1;
break;
case gui::EGET_BUTTON_CLICKED:
switch(id)
{
case 8:
Device->closeDevice();
break;
case 9:
exitSeq = 0;
this->ExitProgram();
break;
}
case gui::EGET_FILE_SELECTED:
if(dialog!=NULL)
{
scene::ISceneManager *_smgr = Device->getSceneManager();
_smgr->saveScene(dialog->narrow(dialog->getFileName()).c_str());
}
break;
default: break;
}
glob_id=id;
}
if(event.EventType == EET_MOUSE_INPUT_EVENT)
{
if(event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
{
if(glob_id>=0 && glob_id<=7)
{
guievent?cnt++:cnt;
getL3MenuObject()->setActive(false);
this->processOnEvent();
}
else if(glob_id>=101 && glob_id<=108)
{
guievent?cnt++:cnt;
this->processOnEvent();
}
switch(glob_id)
{
case 10:
//env->addFileOpenDialog(L"Please select a Scene to open");
break;
case 11:
env->addFileOpenDialog(L"Please select a Scene file to Load");
break;
case 12:
dialog = new CGUIFileSaveDialog(L"Save File as...", env, env->getRootGUIElement(), -1);
break;
case 13:///Return to Main Menu.
getObjectMenuObject()->removeObjectMenu();
getMainMenuObject()->buildMainMenu(env, false);
getL2MenuObject()->hideLevel2Menu(0);
this->resetGlobalParameters();
getL3MenuObject()->resetL3();
get3rdPersonCamera()->disableSceneCamera();
Device->getSceneManager()->clear();
break;
case 70:
case 71:
case 72:
case 60:
case 61:
case 62:
case 50:
case 51:
case 52:
case 40:
case 41:
case 42:
case 43:
case 44:
case 30:
case 31:
case 32:
case 33:
getL3MenuObject()->buildLevel3(glob_id);
break;
}
///Load Objects on Click
if(true == getL3MenuObject()->isActive() && glob_id != -1)
{
std::string filename = getManageImportsObject()->getVMAQPath(glob_id);
o_id++;
current_id = this->scanAvailableObjectId(o_id, 1);
getManageImportsObject()->createNode(filename, current_id);
}
///DnD Functionality Here!
///Translate Vertically or Horizontally!
this->getCursorAndObjectPosition();
LMouseButtonDown = true;
///// This was the extra return statement. My mistake big time.
return (SelectedNode != 0);
}
if(event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN)
{
this->getCursorAndObjectPosition();
RMouseButtonDown = true;
return (SelectedNode != 0);
}
if(event.MouseInput.Event == EMIE_MMOUSE_PRESSED_DOWN)
{
MMouseButtonDown = true;
if(ShiftIsPressed == true || CtrlIsPressed == true)
{
this->getCursorAndObjectPosition();
return (SelectedNode != 0);
}
if(ShiftIsPressed == false || CtrlIsPressed == false)
{
SelectedNode = NULL;
cursorOld.X = event.MouseInput.X;
cursorOld.Y = event.MouseInput.Y;
cursorDelta.X = 0;
cursorDelta.Y = 0;
get3rdPersonCamera()->setOldCameraOrbit(get3rdPersonCamera()->getCameraOrbit());
get3rdPersonCamera()->setOldCameraAngle(get3rdPersonCamera()->getCameraAngle());
}
}
if(event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP)
{
LMouseButtonDown = false;
glob_id = -1;
}
if(event.MouseInput.Event == EMIE_RMOUSE_LEFT_UP)
{
RMouseButtonDown = false;
}
if(event.MouseInput.Event == EMIE_MMOUSE_LEFT_UP)
{
MMouseButtonDown = false;
}
///Listen to Mouse Wheel events and adjust zoom factor accordingly.
if(event.MouseInput.Event == EMIE_MOUSE_WHEEL)
{
get3rdPersonCamera()->adjustZoomFactor(event.MouseInput.Wheel);
}
if(event.MouseInput.Event == EMIE_MOUSE_MOVED)
{
if (SelectedNode && LMouseButtonDown)
{
core::vector3df p = SelectedNode->getPosition();
/// Vertical Movement: Shift Pressed
if (ShiftIsPressed)
{
core::plane3df const planeXY(SelectedNode->getAbsolutePosition(), core::vector3df(1.f, 0.f, 0.f));
core::position2di currentCursorPosition(Device->getCursorControl()->getPosition());
core::position2di effectiveObjectPosition = initialObjectPosition + currentCursorPosition - initialCursorPosition;
core::line3df ray(CollMan->getRayFromScreenCoordinates(effectiveObjectPosition, get3rdPersonCamera()->getTVRActiveCamera()));
core::vector3df intersectWithPlane;
core::vector3df oldPos = SelectedNode->getAbsolutePosition();
if(planeXY.getIntersectionWithLine(ray.start, ray.getVector(), intersectWithPlane))
{
intersectWithPlane.X = oldPos.X;
intersectWithPlane.Z = oldPos.Z;
SelectedNode->setPosition(intersectWithPlane);
}
}
//Horizontal Translation
else if(CtrlIsPressed)
{
radius = SelectedNode->getAbsolutePosition();
core::plane3df const planeXZ(SelectedNode->getAbsolutePosition(), core::vector3df(0.f, 1.f, 0.f));
core::position2di currentCursorPosition(Device->getCursorControl()->getPosition());
core::position2di effectiveObjectPosition = initialObjectPosition + currentCursorPosition - initialCursorPosition;
core::line3df ray(CollMan->getRayFromScreenCoordinates(effectiveObjectPosition, get3rdPersonCamera()->getTVRActiveCamera()));
core::vector3df intersectWithPlane;
if(planeXZ.getIntersectionWithLine(ray.start, ray.getVector(), intersectWithPlane))
{
SelectedNode->setPosition(intersectWithPlane);
}
}
}
else if (SelectedNode && RMouseButtonDown)
{
core::vector3df rot = SelectedNode->getRotation();
core::position2di currentCursorPosition(Device->getCursorControl()->getPosition());
if (ShiftIsPressed)
{
if (initialObjectPosition.X < currentCursorPosition.X) rot.Z -= RotateSpeed;
if (initialObjectPosition.X > currentCursorPosition.X) rot.Z += RotateSpeed;
if (initialObjectPosition.Y < currentCursorPosition.Y) rot.X -= 1;
if (initialObjectPosition.Y > currentCursorPosition.Y) rot.X += 1;
}
else if(CtrlIsPressed)
{
if (initialObjectPosition.X < currentCursorPosition.X) rot.Y += RotateSpeed;
if (initialObjectPosition.X > currentCursorPosition.X) rot.Y -= RotateSpeed;
if (initialObjectPosition.Y < currentCursorPosition.Y) rot.Z += 1;
if (initialObjectPosition.Y > currentCursorPosition.Y) rot.Z -= 1;
}
initialObjectPosition = currentCursorPosition;
SelectedNode->setRotation(rot);
}
else if(SelectedNode && MMouseButtonDown)
{
core::vector3df rot = SelectedNode->getRotation();
core::position2di currentCursorPosition(Device->getCursorControl()->getPosition());
if (ShiftIsPressed)
{
if (initialObjectPosition.X < currentCursorPosition.X) rot.Z += RotateSpeed*1.2;
if (initialObjectPosition.X > currentCursorPosition.X) rot.Z -= RotateSpeed*1.2;
if (initialObjectPosition.Y < currentCursorPosition.Y) rot.Y += 3;
if (initialObjectPosition.Y > currentCursorPosition.Y) rot.Y -= 3;
SelectedNode->setRotation(rot);
}
else
if (CtrlIsPressed)
{
core::vector3df scale = SelectedNode->getScale();
core::position2di currentCursorPosition(Device->getCursorControl()->getPosition());
if (initialObjectPosition.X > currentCursorPosition.X)
{
scale.X -= ScaleSpeed;
scale.Y -= ScaleSpeed;
scale.Z -= ScaleSpeed;
}
if (initialObjectPosition.X < currentCursorPosition.X)
{
scale.X += ScaleSpeed;
scale.Y += ScaleSpeed;
scale.Z += ScaleSpeed;
}
SelectedNode->setScale(scale);
}
initialObjectPosition = currentCursorPosition;
}
else
///3rd Person Camera Logic
if(CtrlIsPressed == false && ShiftIsPressed == false && SelectedNode == NULL)
{
if(MMouseButtonDown)
{
cursor.X = event.MouseInput.X;
cursor.Y = event.MouseInput.Y;
cursorDelta.X = cursor.X - cursorOld.X;
cursorDelta.Y = cursor.Y - cursorOld.Y;
if(cursorDelta.Y > 100) cursorDelta.Y = 100;
if(cursorDelta.Y < -100) cursorDelta.Y = -100;
get3rdPersonCamera()->OrbitCameraCalculation(cursorDelta);
}
}
}
}
return false;
}
void TVREventReceiver::processOnEvent(void)
{
if(tobj!=NULL && cnt==1)
{
if(glob_id>=0 && glob_id<=7)
{
tobj->setImage(getObjectMenuObject()->getClickedImage(glob_id));
getL2MenuObject()->identifyLevel2Menu(glob_id);
tobj->setColor(video::SColor(255,204,102,51));
}
else if(glob_id>=101 && glob_id<=106)
{
tobj->setImage(getMainMenuObject()->getHighlightedImageMM(glob_id));
tobj->setColor(video::SColor(255,0,153,255));
sceneSelected = glob_id;
}
tempobj = tobj;
prev_id = glob_id;
id_set = glob_id;
}
else if(tobj!=NULL && cnt>1 && tempobj == tobj)
{
if(glob_id>=0 && glob_id<=7)
{
tobj->setImage(getObjectMenuObject()->getClickedImage(glob_id));
getL2MenuObject()->hideLevel2Menu(glob_id);
tobj->setColor(video::SColor(255,255,255,255));
}
else if(glob_id>=101 && glob_id<=106)
{
tobj->setImage(getMainMenuObject()->getHighlightedImageMM(glob_id));
tobj->setColor(video::SColor(255,255,255,255));
sceneSelected = -1;
}
id_set = -1;
cnt = 0;
}
else if(tobj!=NULL && cnt>1 && tempobj != tobj)
{
cnt = 1;
if(glob_id>=0 && glob_id<=7)
{
tempobj->setImage(getObjectMenuObject()->getNormalImage(prev_id));
tobj->setImage(getObjectMenuObject()->getClickedImage(glob_id));
getL2MenuObject()->identifyLevel2Menu(glob_id);
getL2MenuObject()->hideLevel2Menu(prev_id);
tempobj->setColor(video::SColor(255,255,255,255));
tobj->setColor(video::SColor(255,204,102,51));
}
else if(glob_id>=101 && glob_id<=106)
{
tempobj->setImage(getMainMenuObject()->getNormalImageMM(prev_id));
tobj->setImage(getMainMenuObject()->getHighlightedImageMM(glob_id));
tempobj->setColor(video::SColor(255,255,255,255));
tobj->setColor(video::SColor(255,0,153,255));
sceneSelected = glob_id;
}
tempobj = tobj;
prev_id=glob_id;
id_set = glob_id;
}
if(glob_id == 107)
{
if(sceneSelected == -1)
Device->getGUIEnvironment()->addMessageBox(Caption.c_str(), MessageText.c_str());
else if(sceneSelected>=101 && sceneSelected<=106)
{
sceneSelected = -1;
getMainMenuObject()->destroyMainMenu();
getObjectMenuObject()->buildObjectMenu(Device->getGUIEnvironment());
this->resetGlobalParameters();
///Load the selected Scene from Main menu.
getManageImportsObject()->InitSceneNodes(900);
getManageImportsObject()->createSkyDome("");
get3rdPersonCamera()->setTVRCamera(getManageImportsObject()->getSelectedSceneHandle());
///particle
getTVRParticleSystemObject()->addParticleNode(-1);
}
}
if(glob_id == 108)
{
exitSeq = !exitSeq;
this->ExitProgram();
}
}
bool TVREventReceiver::isSet(void)
{
if(id_set == -1)
return false;
return true;
}
void TVREventReceiver::resetGlobalParameters(void)
{
cnt =0; prev_id = -1; glob_id = -1;
}
void TVREventReceiver::getCursorAndObjectPosition(void)
{
// check for a node being selected
SelectedNode = CollMan->getSceneNodeFromScreenCoordinatesBB(Device->getCursorControl()->getPosition(),0,true);
// If we selected a node
if(SelectedNode)
{
// Remember where the node and cursor were when it was clicked on
initialCursorPosition = Device->getCursorControl()->getPosition();
initialObjectPosition = CollMan->getScreenCoordinatesFrom3DPosition(SelectedNode->getAbsolutePosition(), get3rdPersonCamera()->getTVRActiveCamera());
}
}
void TVREventReceiver::ExitProgram(void)
{
if(exitSeq == 1)
{
core::dimension2d<s32> resolution = Device->getVideoModeList()->getDesktopResolution();
env->addButton(core::rect<s32>(resolution.Width/2-250,resolution.Height/2-30,resolution.Width/2-250+80,resolution.Height/2-50+40),0,8,L"Quit");
env->addButton(core::rect<s32>(resolution.Width/2+150,resolution.Height/2-30,resolution.Width/2+150+80,resolution.Height/2-50+40),0,9,L"Cancel");
}
else
{
env->getRootGUIElement()->getElementFromId(8)->remove();
env->getRootGUIElement()->getElementFromId(9)->remove();
}
}
int TVREventReceiver::scanAvailableObjectId(int _oid, int mode)
{
int oid = -1;
if(_oid < 1000)
return -1;
switch(mode)
{
case 1:
///add object to scene
oid = _oid;
if(Q.size() != 0)
{
oid = Q.front();
Q.pop();
o_id--;
return oid;
}
break;
case 2:
///Delete object from scene
Q.push(_oid);
return _oid;
break;
}
return oid;
}
TVREventReceiver::~TVREventReceiver()
{
}
I work on "The Best Real-Time 3D Engine"