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.
jimmyh
Posts: 12 Joined: Sun Feb 19, 2012 8:40 pm
Post
by jimmyh » Sun Feb 19, 2012 9:29 pm
I'm having a weird problem with irrlicht and wxwidgets.
I've added all the code below, but basically some times when I click on the irrlicht View it then locks the mouse out of the rest of the window and I'm unable to use any wxwidgets controls. Alt-tabbing to another application and back some times fixes the problem. We'll until I click on the irrlicht view again.
Main.cpp
Code: Select all
#include "Main.h"
DECLARE_APP(MyApp)
IMPLEMENT_APP(MyApp)
bool MyApp::OnInit ( void )
{
if ( wxApp::OnInit() == false )
return false;
MyFrame *frame = new MyFrame( "Editor",
wxPoint(50,50), wxSize(800,600) );
frame->Show(TRUE);
SetTopWindow(frame);
return true;
}
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_SHOW(MyFrame::OnShow)
END_EVENT_TABLE()
MyFrame::MyFrame ( const wxString& title, const wxPoint& pos, const wxSize& size ) : wxFrame ( ( wxFrame * ) NULL, -1, title, pos, size )
{
wxMenuItem* pMenuItem = NULL;
mMenuBar = new wxMenuBar;
wxMenu *menuFile = new wxMenu;
menuFile->Append( ID_Quit, "E&xit" );
mMenuBar->Append( menuFile, "&File" );
SetMenuBar( mMenuBar );
CreateStatusBar();
SetStatusText( "Welcome to wxWindows!" );
m_mgr.SetManagedWindow(this);
mView = new View(this, wxID_ANY);
new CGlobals();
new CInput();
CInput::getSingletonPtr()->init();
m_mgr.AddPane ( mView, wxAuiPaneInfo().CenterPane() );
m_mgr.Update();
mView->SetFocus();
}
MyFrame::~MyFrame ( void )
{
delete mView;
m_mgr.UnInit();
}
void MyFrame::OnShow ( wxShowEvent& event )
{
((View*)mView)->ViewInit();
}
void MyFrame::OnQuit ( wxCommandEvent& WXUNUSED(event) )
{
Close(TRUE);
}
Main.h
Code: Select all
#ifndef _MAIN_H_
#define _MAIN_H_
#define _CRT_SECURE_NO_DEPRECATE
//#include <vld.h>
#include <wx/wx.h>
#include <wx/artprov.h>
#include <wx/aui/aui.h>
#include <wx/propgrid/propgrid.h>
#include <wx/propgrid/editors.h>
#include <vector>
#include <irrlicht.h>
#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#endif
#include "../../source/CSingleton.h"
#include "../../source/Globals.h"
#include "../../source/CInput.h"
#include "../../source/CEventHandler.h"
#include "View.h"
class MyApp : public wxApp
{
virtual bool OnInit ( void );
};
class MyFrame: public wxFrame
{
public:
enum
{
ID_Load = wxID_HIGHEST+1,
ID_Save,
ID_SaveAs,
};
MyFrame ( const wxString& title, const wxPoint& pos, const wxSize& size );
~MyFrame ( void );
void OnShow ( wxShowEvent& event );
void OnQuit ( wxCommandEvent& event );
void OnLoad ( wxCommandEvent& event );
void OnSave ( wxCommandEvent& event );
void OnSaveAs ( wxCommandEvent& event );
DECLARE_EVENT_TABLE()
wxAuiManager m_mgr;
wxMenuBar* mMenuBar;
View* mView;
};
#endif
Last edited by
jimmyh on Sun Feb 19, 2012 9:40 pm, edited 1 time in total.
jimmyh
Posts: 12 Joined: Sun Feb 19, 2012 8:40 pm
Post
by jimmyh » Sun Feb 19, 2012 9:29 pm
View.cpp
Code: Select all
#include "Main.h"
BEGIN_EVENT_TABLE(View, wxWindow)
EVT_IDLE(View::OnIdle)
EVT_SIZE(View::OnSize)
EVT_MOTION(View::OnMouseMove)
EVT_LEFT_DOWN(View::OnMouseLeftDown)
EVT_LEFT_UP(View::OnMouseLeftUp)
EVT_RIGHT_DOWN(View::OnMouseRightDown)
EVT_RIGHT_UP(View::OnMouseRightUp)
EVT_MOUSEWHEEL(View::OnMouseWheel)
EVT_LEFT_DOWN(View::OnLeftDown)
EVT_LEFT_UP(View::OnLeftUp)
EVT_KEY_DOWN(View::OnKeyDown)
EVT_KEY_UP(View::OnKeyUp)
EVT_ENTER_WINDOW(View::OnEnterWindow)
EVT_LEAVE_WINDOW(View::OnLeaveWindow)
END_EVENT_TABLE()
View::View ( wxWindow* parent, wxWindowID id, long style ) : wxWindow (parent, id, wxDefaultPosition, wxDefaultSize, style)
{
mInitialised = false;
}
View::~View ( void )
{
delete CInput::getSingletonPtr();
CGlobals::getSingletonPtr()->mIrrDriver->removeAllTextures();
CGlobals::getSingletonPtr()->mIrrDevice->closeDevice();
CGlobals::getSingletonPtr()->mIrrDevice->drop();
delete CGlobals::getSingletonPtr();
}
void View::ViewInit ( void )
{
irr::SIrrlichtCreationParameters param;
param.WindowId = (void*)(HWND)this->GetHandle();
param.DriverType = irr::video::EDT_DIRECT3D9;
irr::core::dimension2d<irr::u32> irrSize(GetClientSize().GetX(), GetClientSize().GetY());
param.WindowSize = irrSize;
CGlobals::getSingletonPtr()->mIrrDevice = irr::createDeviceEx(param);
CGlobals::getSingletonPtr()->mIrrDriver = CGlobals::getSingletonPtr()->mIrrDevice->getVideoDriver();
// initialise the driver with the window size
CGlobals::getSingletonPtr()->mIrrDriver->OnResize(irrSize);
CGlobals::getSingletonPtr()->mScreenWidth = GetClientSize().GetX();
CGlobals::getSingletonPtr()->mScreenHeight = GetClientSize().GetY();
mEventHandler.init();
CGlobals::getSingletonPtr()->mIrrDevice->setEventReceiver(&mEventHandler);
mInitialised = true;
this->SetCanFocus(false);
}
void View::OnKeyDown ( wxKeyEvent& event )
{
irr::SEvent irrEvt;
irrEvt.EventType = irr::EET_KEY_INPUT_EVENT;
irrEvt.KeyInput.Key = (irr::EKEY_CODE)event.GetRawKeyCode();
irrEvt.KeyInput.Char = (char)event.GetRawKeyCode();
irrEvt.KeyInput.PressedDown = true;
irrEvt.KeyInput.Control = ((event.GetModifiers() & wxMOD_CONTROL ) != 0);
irrEvt.KeyInput.Shift = ((event.GetModifiers() & wxMOD_SHIFT) != 0);
CGlobals::getSingletonPtr()->mIrrDevice->postEventFromUser(irrEvt);
}
void View::OnKeyUp ( wxKeyEvent& event )
{
irr::SEvent irrEvt;
irrEvt.EventType = irr::EET_KEY_INPUT_EVENT;
irrEvt.KeyInput.Key = (irr::EKEY_CODE)event.GetRawKeyCode();
irrEvt.KeyInput.Char = (char)event.GetRawKeyCode();
irrEvt.KeyInput.PressedDown = false;
irrEvt.KeyInput.Control = ((event.GetModifiers() & wxMOD_CONTROL ) != 0);
irrEvt.KeyInput.Shift = ((event.GetModifiers() & wxMOD_SHIFT) != 0);
CGlobals::getSingletonPtr()->mIrrDevice->postEventFromUser(irrEvt);
}
void View::OnLeftDown ( wxMouseEvent &event )
{
irr::SEvent irrEvt;
irrEvt.EventType = irr::EET_MOUSE_INPUT_EVENT;
irrEvt.MouseInput.Event = irr::EMIE_LMOUSE_PRESSED_DOWN;
irrEvt.MouseInput.X =event.GetPosition().x;
irrEvt.MouseInput.Y =event.GetPosition().y;
CGlobals::getSingletonPtr()->mIrrDevice->postEventFromUser(irrEvt);
WCHAR tmp[4096];
wsprintf(tmp, L"OnLeftDown\n" );
OutputDebugString ( tmp );
}
void View::OnLeftUp ( wxMouseEvent &event )
{
irr::SEvent irrEvt;
irrEvt.EventType = irr::EET_MOUSE_INPUT_EVENT;
irrEvt.MouseInput.Event = irr::EMIE_LMOUSE_LEFT_UP;
irrEvt.MouseInput.X =event.GetPosition().x;
irrEvt.MouseInput.Y =event.GetPosition().y;
CGlobals::getSingletonPtr()->mIrrDevice->postEventFromUser(irrEvt);
WCHAR tmp[4096];
wsprintf(tmp, L"OnLeftUp\n" );
OutputDebugString ( tmp );
}
void View::OnMouseLeftDown ( wxMouseEvent &event )
{
irr::SEvent irrEvt;
irrEvt.EventType = irr::EET_MOUSE_INPUT_EVENT;
irrEvt.MouseInput.X =event.GetPosition().x;
irrEvt.MouseInput.Y =event.GetPosition().y;
irrEvt.MouseInput.Wheel = 0.0f;
irrEvt.MouseInput.Event = irr::EMIE_LMOUSE_PRESSED_DOWN;
CGlobals::getSingletonPtr()->mIrrDevice->postEventFromUser(irrEvt);
}
void View::OnMouseLeftUp ( wxMouseEvent &event )
{
irr::SEvent irrEvt;
irrEvt.EventType = irr::EET_MOUSE_INPUT_EVENT;
irrEvt.MouseInput.X =event.GetPosition().x;
irrEvt.MouseInput.Y =event.GetPosition().y;
irrEvt.MouseInput.Wheel = 0.0f;
irrEvt.MouseInput.Event = irr::EMIE_LMOUSE_LEFT_UP;
CGlobals::getSingletonPtr()->mIrrDevice->postEventFromUser(irrEvt);
}
void View::OnMouseRightDown ( wxMouseEvent &event )
{
irr::SEvent irrEvt;
irrEvt.EventType = irr::EET_MOUSE_INPUT_EVENT;
irrEvt.MouseInput.X =event.GetPosition().x;
irrEvt.MouseInput.Y =event.GetPosition().y;
irrEvt.MouseInput.Wheel = 0.0f;
irrEvt.MouseInput.Event = irr::EMIE_RMOUSE_PRESSED_DOWN;
CGlobals::getSingletonPtr()->mIrrDevice->postEventFromUser(irrEvt);
}
void View::OnMouseRightUp ( wxMouseEvent &event )
{
irr::SEvent irrEvt;
irrEvt.EventType = irr::EET_MOUSE_INPUT_EVENT;
irrEvt.MouseInput.X =event.GetPosition().x;
irrEvt.MouseInput.Y =event.GetPosition().y;
irrEvt.MouseInput.Wheel = 0.0f;
irrEvt.MouseInput.Event = irr::EMIE_RMOUSE_LEFT_UP;
CGlobals::getSingletonPtr()->mIrrDevice->postEventFromUser(irrEvt);
}
void View::OnMouseWheel ( wxMouseEvent &event )
{
irr::SEvent irrEvt;
irrEvt.EventType = irr::EET_MOUSE_INPUT_EVENT;
irrEvt.MouseInput.Event = irr::EMIE_MOUSE_WHEEL;
irrEvt.MouseInput.X =event.GetPosition().x;
irrEvt.MouseInput.Y =event.GetPosition().y;
irrEvt.MouseInput.Wheel = event.GetWheelRotation();
CGlobals::getSingletonPtr()->mIrrDevice->postEventFromUser(irrEvt);
}
void View::OnMouseMove ( wxMouseEvent &event )
{
irr::SEvent irrEvt;
irrEvt.EventType = irr::EET_MOUSE_INPUT_EVENT;
irrEvt.MouseInput.Event = irr::EMIE_MOUSE_MOVED;
irrEvt.MouseInput.X =event.GetPosition().x;
irrEvt.MouseInput.Y =event.GetPosition().y;
irrEvt.MouseInput.Wheel = 0.0f;
WCHAR tmp[4096];
wsprintf(tmp, L"%d, %d\n", event.GetPosition().x, event.GetPosition().y );
OutputDebugString ( tmp );
CGlobals::getSingletonPtr()->mIrrDevice->postEventFromUser(irrEvt);
if ( event.m_rightDown == true )
{
irrEvt.EventType = irr::EET_MOUSE_INPUT_EVENT;
irrEvt.MouseInput.Event = irr::EMIE_RMOUSE_PRESSED_DOWN;
CGlobals::getSingletonPtr()->mIrrDevice->postEventFromUser(irrEvt);
}
else if ( CInput::getSingletonPtr()->rightMouseDown() )
{
irrEvt.EventType = irr::EET_MOUSE_INPUT_EVENT;
irrEvt.MouseInput.Event = irr::EMIE_RMOUSE_LEFT_UP;
CGlobals::getSingletonPtr()->mIrrDevice->postEventFromUser(irrEvt);
}
if ( event.m_leftDown == true )
{
irrEvt.EventType = irr::EET_MOUSE_INPUT_EVENT;
irrEvt.MouseInput.Event = irr::EMIE_LMOUSE_PRESSED_DOWN;
CGlobals::getSingletonPtr()->mIrrDevice->postEventFromUser(irrEvt);
}
else if ( CInput::getSingletonPtr()->leftMouseDown() )
{
irrEvt.EventType = irr::EET_MOUSE_INPUT_EVENT;
irrEvt.MouseInput.Event = irr::EMIE_LMOUSE_LEFT_UP;
CGlobals::getSingletonPtr()->mIrrDevice->postEventFromUser(irrEvt);
}
}
void View::OnEnterWindow ( wxMouseEvent& event)
{
this->SetFocus();
}
void View::OnLeaveWindow ( wxMouseEvent& event)
{
this->GetParent()->SetFocus();
}
void View::OnSize ( wxSizeEvent &WXUNUSED(event) )
{
if ( mInitialised == true )
{
irr::core::dimension2d<irr::u32> irrSize(this->GetClientSize().GetX(), GetClientSize().GetY());
// initialise the driver with the window size
CGlobals::getSingletonPtr()->mIrrDriver->OnResize(irrSize);
CGlobals::getSingletonPtr()->mScreenWidth = GetClientSize().GetX();
CGlobals::getSingletonPtr()->mScreenHeight = GetClientSize().GetY();
}
}
void View::OnIdle ( wxIdleEvent& e )
{
if ( mInitialised == true && this->HasFocus() )
{
CInput::getSingletonPtr()->endEventProcess();
irr::core::position2d<irr::s32> m = CGlobals::getSingletonPtr()->mIrrDevice->getCursorControl()->getPosition();
CGlobals::getSingletonPtr()->mMouseX = m.X;
CGlobals::getSingletonPtr()->mMouseY = m.Y;
CGlobals::getSingletonPtr()->mIrrDevice->run();
CGlobals::getSingletonPtr()->mIrrDriver->beginScene(true, true, 0);
CGlobals::getSingletonPtr()->mIrrDriver->endScene();
CInput::getSingletonPtr()->startEventProcess();
}
e.RequestMore();
}
View.h
Code: Select all
#ifndef _VIEW_H_
#define _VIEW_H_
class View : public wxWindow
{
public:
View ( wxWindow* parent, wxWindowID id, long style=wxTAB_TRAVERSAL );
~View ( void );
void OnIdle ( wxIdleEvent& e );
void OnSize ( wxSizeEvent& e );
void OnKeyDown ( wxKeyEvent& e );
void OnKeyUp ( wxKeyEvent& e );
void OnLeftDown ( wxMouseEvent& e );
void OnLeftUp ( wxMouseEvent& e );
void OnMouseLeftDown ( wxMouseEvent &event );
void OnMouseLeftUp ( wxMouseEvent &event );
void OnMouseRightDown ( wxMouseEvent &e );
void OnMouseRightUp ( wxMouseEvent &e );
void OnMouseMove ( wxMouseEvent& e );
void OnMouseWheel ( wxMouseEvent& e );
void OnEnterWindow ( wxMouseEvent& event);
void OnLeaveWindow ( wxMouseEvent& event);
void ViewInit ( void );
DECLARE_EVENT_TABLE()
bool mInitialised;
CEventHandler mEventHandler;
};
#endif
jimmyh
Posts: 12 Joined: Sun Feb 19, 2012 8:40 pm
Post
by jimmyh » Sun Feb 19, 2012 9:31 pm
CEventHandler.cpp
Code: Select all
#include <Main.h>
CEventHandler::CEventHandler ( /*SAppContext & context*/)/* : Context(context)*/
{
}
CEventHandler::~CEventHandler(void)
{
}
void CEventHandler::init ( void )
{
}
bool CEventHandler::OnEvent ( const irr::SEvent& event )
{
bool eventprocessed = false;
CInput* pInput = CInput::getSingletonPtr();
//////////////////////////////
// Keyboard Input Event
//////////////////////////////
if ( event.EventType == irr::EET_GUI_EVENT )
{
/*irr::s32 id = event.GUIEvent.Caller->getID();
if ( event.GUIEvent.EventType == irr::gui::EGET_COMBO_BOX_CHANGED )
{
if ( id == GUI_ID_TRANSPARENCY_SCROLL_BAR )
}*/
}
if (event.EventType == irr::EET_KEY_INPUT_EVENT)
{
if (pInput->processState == pInput->STARTED)
{
// if key is Pressed Down
if (event.KeyInput.PressedDown == true)
{
// If key was not down before
if (pInput->keyState[event.KeyInput.Key] != pInput->DOWN)
{
pInput->keyState[event.KeyInput.Key] = pInput->PRESSED; // Set to Pressed
}
else
{
// if key was down before
pInput->keyState[event.KeyInput.Key] = pInput->DOWN; // Set to Down
}
}
else
{
// if the key is down
if (pInput->keyState[event.KeyInput.Key] != pInput->UP)
{
pInput->keyState[event.KeyInput.Key] = pInput->RELEASED; // Set to Released
}
}
}
eventprocessed = true;
}
//////////////////////////////
// Mouse Input Event
//////////////////////////////
if (event.EventType == irr::EET_MOUSE_INPUT_EVENT)
{
if (pInput->processState == pInput->STARTED)
{
//Mouse changed position
if (event.MouseInput.Event == irr::EMIE_MOUSE_MOVED)
{
pInput->mouse.Y = event.MouseInput.Y;
pInput->mouse.X = event.MouseInput.X;
pInput->mouse.movedX = pInput->mouse.X - pInput->mouse.prevX;
pInput->mouse.movedY = pInput->mouse.Y - pInput->mouse.prevY;
pInput->mouse.prevX = pInput->mouse.X;
pInput->mouse.prevY = pInput->mouse.Y;
}
//Wheel moved.
if (event.MouseInput.Event == irr::EMIE_MOUSE_WHEEL)
{
pInput->mouse.wheel += event.MouseInput.Wheel;
}
//Left Mouse Button Pressed
if (event.MouseInput.Event == irr::EMIE_LMOUSE_PRESSED_DOWN)
{
//
if (pInput->mouseButtonState[0] == pInput->UP || pInput->mouseButtonState[0] == pInput->RELEASED)
{
pInput->mouseButtonState[0] = pInput->PRESSED;
}
else
{
pInput->mouseButtonState[0] = pInput->DOWN;
}
}
//Left Mouse Button Rleased
if (event.MouseInput.Event == irr::EMIE_LMOUSE_LEFT_UP)
{
//
if (pInput->mouseButtonState[0] != pInput->UP)
{
pInput->mouseButtonState[0] = pInput->RELEASED;
}
}
//Middle Mouse Button Pressed
if (event.MouseInput.Event == irr::EMIE_MMOUSE_PRESSED_DOWN)
{
//
if (pInput->mouseButtonState[1] == pInput->UP || pInput->mouseButtonState[1] == pInput->RELEASED)
{
pInput->mouseButtonState[1] = pInput->PRESSED;
}
else
{
pInput->mouseButtonState[1] = pInput->DOWN;
}
}
//Middle Mouse Button Rleased
if (event.MouseInput.Event == irr::EMIE_MMOUSE_LEFT_UP)
{
//
if (pInput->mouseButtonState[1] != pInput->UP)
{
pInput->mouseButtonState[1] = pInput->RELEASED;
}
}
//Right Mouse Button Pressed
if (event.MouseInput.Event == irr::EMIE_RMOUSE_PRESSED_DOWN)
{
//
if (pInput->mouseButtonState[2] == pInput->UP || pInput->mouseButtonState[2] == pInput->RELEASED)
{
pInput->mouseButtonState[2] = pInput->PRESSED;
}
else
{
pInput->mouseButtonState[2] = pInput->DOWN;
}
}
//Right Mouse Button Rleased
if (event.MouseInput.Event == irr::EMIE_RMOUSE_LEFT_UP)
{
//
if (pInput->mouseButtonState[2] != pInput->UP)
{
pInput->mouseButtonState[2] = pInput->RELEASED;
}
}
}
eventprocessed = true;
}
return false;
}
CEventHandler.h
Code: Select all
#ifndef _CEVENTHANDLER_H_
#define _CEVENTHANDLER_H_
struct SGuiEvent
{
//! IGUIElement who called the event
//CGuiElement* Caller;
//! Type of GUI Event
irr::gui::EGUI_EVENT_TYPE EventType;
};
class CEventHandler : public irr::IEventReceiver
{
protected:
public:
CEventHandler();
virtual ~CEventHandler(void);
virtual void init ( void );
virtual void OnGuiEvent ( const SGuiEvent& event ) {}
// This is the one method that we have to implement
virtual bool OnEvent ( const irr::SEvent& event );
};
#endif
jimmyh
Posts: 12 Joined: Sun Feb 19, 2012 8:40 pm
Post
by jimmyh » Sun Feb 19, 2012 9:34 pm
CInput.cpp
Code: Select all
///////////////////////////////////////////////////////////////////////////////////
// File : CInput.cpp
///////////////////////////////////////////////////////////////////////////////////
// Includes ///////////////////////////////////////////////////////////////////////
#include <Main.h>
// Externs ////////////////////////////////////////////////////////////////////////
template<> CInput* CSingleton<CInput>::mSingleton = 0;
//---------------------------------------------------------------------------------
// Function : CInput::CInput
//---------------------------------------------------------------------------------
CInput::CInput()
{
}
//---------------------------------------------------------------------------------
// Function : CInput::~CInput
//---------------------------------------------------------------------------------
CInput::~CInput(void)
{
}
float CInput::mouseWheel()
{
return mouse.wheel;
}
int CInput::mouseX()
{
return mouse.X;
}
int CInput::mouseY()
{
return mouse.Y;
}
bool CInput::leftMouseReleased()
{
if (mouseButtonState[0] == RELEASED)
{
return true;
}
else
{
return false;
}
}
bool CInput::leftMouseUp()
{
if (mouseButtonState[0] == RELEASED || mouseButtonState[0] == UP)
{
return true;
}
else
{
return false;
}
}
bool CInput::leftMousePressed()
{
if (mouseButtonState[0] == PRESSED)
{
return true;
}
else
{
return false;
}
}
bool CInput::leftMouseDown()
{
if (mouseButtonState[0] == PRESSED || mouseButtonState[0] == DOWN)
{
return true;
}
else
{
return false;
}
}
bool CInput::middleMouseReleased()
{
if (mouseButtonState[1] == RELEASED)
{
return true;
}
else
{
return false;
}
}
bool CInput::middleMouseUp()
{
if (mouseButtonState[1] == RELEASED || mouseButtonState[1] == UP)
{
return true;
}
else
{
return false;
}
}
bool CInput::middleMousePressed()
{
if (mouseButtonState[1] == PRESSED)
{
return true;
}
else
{
return false;
}
}
bool CInput::middleMouseDown()
{
if (mouseButtonState[1] == PRESSED || mouseButtonState[1] == DOWN)
{
return true;
}
else
{
return false;
}
}
bool CInput::rightMouseReleased()
{
if (mouseButtonState[2] == RELEASED)
{
return true;
}
else
{
return false;
}
}
bool CInput::rightMouseUp()
{
if (mouseButtonState[2] == RELEASED || mouseButtonState[2] == UP)
{
return true;
}
else
{
return false;
}
}
bool CInput::rightMousePressed()
{
if (mouseButtonState[2] == PRESSED)
{
return true;
}
else
{
return false;
}
}
bool CInput::rightMouseDown()
{
if (mouseButtonState[2] == PRESSED || mouseButtonState[2] == DOWN)
{
return true;
}
else
{
return false;
}
}//
bool CInput::keyPressed(irr::EKEY_CODE keycode)
{
if (keyState[keycode] == PRESSED)
{
return true;
}
else
{
return false;
}
}
bool CInput::keyDown(irr::EKEY_CODE keycode)
{
if (keyState[keycode] == DOWN || keyState[keycode] == PRESSED)
{
return true;
}
else
{
return false;
}
}
bool CInput::keyUp(irr::EKEY_CODE keycode)
{
if (keyState[keycode] == UP || keyState[keycode] == RELEASED)
{
return true;
}
else
{
return false;
}
}
bool CInput::keyReleased(irr::EKEY_CODE keycode)
{
if (keyState[keycode] == RELEASED)
{
return true;
}
else
{
return false;
}
}
// This is used so that the Key States will not be changed during execution of your Main game loop.
// Place this at the very START of your Main Loop
void CInput::endEventProcess()
{
processState = ENDED;
}
// This is used so that the Key States will not be changed during execution of your Main game loop.
// Place this function at the END of your Main Loop.
void CInput::startEventProcess()
{
processState = STARTED;
//Keyboard Key States
for (int i = 0; i < irr::KEY_KEY_CODES_COUNT; i++)
{
if (keyState[i] == RELEASED)
{
keyState[i] = UP;
}
if (keyState[i] == PRESSED)
{
keyState[i] = DOWN;
}
}
//Mouse Button States
for (int i = 0; i <= 2; i++)
{
if (mouseButtonState[i] == RELEASED)
{
mouseButtonState[i] = UP;
}
if (mouseButtonState[i] == PRESSED)
{
mouseButtonState[i] = DOWN;
}
}
//Mouse Wheel state
mouse.wheel = 0.0f;
mouse.movedX = 0;
mouse.movedY = 0;
}
void CInput::init()
{
//KeyBoard States.
for (int i = 0; i <= irr::KEY_KEY_CODES_COUNT; i++)
{
keyState[i] = UP;
}
//Mouse states
for (int i = 0; i <= 2; i++)
{
mouseButtonState[i] = UP;
}
//Mouse X/Y coordenates.
mouse.X = 0;
mouse.Y = 0;
mouse.movedX = 0;
mouse.movedY = 0;
mouse.prevX = 0;
mouse.prevY = 0;
mouse.wheel = 0.0f;
}
CInput.h
Code: Select all
///////////////////////////////////////////////////////////////////////////////////
// File : CInput.h
///////////////////////////////////////////////////////////////////////////////////
// Include Check //////////////////////////////////////////////////////////////////
#ifndef _CINPUT_H_
#define _CINPUT_H_
// Enums //////////////////////////////////////////////////////////////////////////
// Classes ////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
// Input Class
///////////////////////////////////////////////////////////////////////////////////
class CInput : public CSingleton<CInput>
{
public:
enum keyStatesENUM {UP, DOWN, PRESSED, RELEASED};
enum processStateENUM {STARTED, ENDED};
keyStatesENUM mouseButtonState[2];
keyStatesENUM keyState[irr::KEY_KEY_CODES_COUNT];
struct mouseData
{
int X;
int Y;
int prevX;
int prevY;
int movedX;
int movedY;
float wheel; //wheel is how far the wheel has moved
};
struct mouseData mouse;
processStateENUM processState; // STARTED = handling events, ENDED = not handling events
public:
CInput();
~CInput(void);
void init ( void );
void startEventProcess ( void );
void endEventProcess ( void );
bool keyReleased ( irr::EKEY_CODE keycode );
bool keyUp ( irr::EKEY_CODE keycode );
bool keyDown ( irr::EKEY_CODE keycode );
bool keyPressed ( irr::EKEY_CODE keycode );
bool rightMouseDown ( void );
bool rightMousePressed ( void );
bool rightMouseUp ( void );
bool rightMouseReleased ( void );
bool middleMouseDown ( void );
bool middleMousePressed ( void );
bool middleMouseUp ( void );
bool middleMouseReleased( void );
bool leftMouseReleased ( void );
bool leftMouseUp ( void );
bool leftMousePressed ( void );
bool leftMouseDown ( void );
float mouseWheel ( void );
int mouseX ( void );
int mouseY ( void );
int mouseMovedX ( void ) { return mouse.movedX; }
int mouseMovedY ( void ) { return mouse.movedY; }
};
#endif
jimmyh
Posts: 12 Joined: Sun Feb 19, 2012 8:40 pm
Post
by jimmyh » Sun Feb 19, 2012 9:34 pm
I think that's every thing
Opps missed a file.
CSingleton.h
Code: Select all
#ifndef _CSINGLETON_H_INCLUDE_
#define _CSINGLETON_H_INCLUDE_
/** Template class for creating single-instance global classes.
*/
template <typename T>
class CSingleton
{
protected:
static T* mSingleton;
public:
CSingleton( void )
{
assert( !mSingleton );
mSingleton = static_cast< T* >( this );
}
~CSingleton( void )
{
assert( mSingleton ); mSingleton = 0;
}
static T& getSingleton( void )
{
assert( mSingleton );
return ( *mSingleton );
}
static T* getSingletonPtr( void )
{
return mSingleton;
}
};
#endif
smso
Posts: 246 Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong
Post
by smso » Mon Feb 20, 2012 1:24 pm
I tried a workaround by toggling the mouse grabbing of irrlicht in the event receiver:
Code: Select all
else if (event.KeyInput.Key == irr::KEY_F3)
{
bool enabled = camera->isInputReceiverEnabled();
camera->setInputReceiverEnabled(!enabled);
device->getCursorControl()->setVisible(enabled);
}
Regards
smso