How to inject un-buffered input?

mrmclovin

17-08-2008 18:24:59

As far as I know the inject methods takes OIS::MouseEvents as param. But what if I have buffered input. Is it possible to inject in some way buffered input? In previous versions there were absolut-pos injection?

Thanks in advance!

~[L]~

17-08-2008 19:36:23

Yes, absolutly !

Take a look :

For example, a loading screen that I use (of course,the code it's cropped, a lot xD)


#pragma once
#include "Core.h"

class LoadingListener :
public OIS::MouseListener,public Ogre::FrameListener, public OIS::KeyListener,public Ogre::WindowEventListener{ // cropped ..
LoadingListener(Ogre::RenderWindow* RenderTarget);
~LoadingListener(void);

////////////////////
// Callbacks ....
bool frameStarted(const Ogre::FrameEvent& evt);
bool frameEnded(const Ogre::FrameEvent& evt);
bool mouseMoved( const OIS::MouseEvent &arg );
bool mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id );
bool mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id );
bool keyPressed( const OIS::KeyEvent &arg );
bool keyReleased( const OIS::KeyEvent &arg );

void windowResized(Ogre::RenderWindow* rw);
void windowClosed(Ogre::RenderWindow* rw);

///////////

private:
unsigned int ScreenWidth,ScreenHeight,ScreenDepth;

};


an then....


bool CoreGraphics::initializeGUI(Ogre::RenderWindow* UniqueWindow,Ogre::String CoreFile,Ogre::String ResourceGroup){
if (Internal::getSingletonPtr()->bitCheck(maskSubSystems,SUBSYSTEM_GUI)) return false;
Core::getSingletonPtr()->_MyGUI->initialise(UniqueWindow,CoreFile,ResourceGroup);
//OIS ...
Ogre::LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***");
try{
size_t hWnd = 0;

UniqueWindow->getCustomAttribute("WINDOW",&hWnd);

Core::getSingletonPtr()->InputManager = OIS::InputManager::createInputSystem(hWnd);
Core::getSingletonPtr()->Keyboard = static_cast<OIS::Keyboard*>(Core::getSingletonPtr()->InputManager->createInputObject(OIS::OISKeyboard,true));
Core::getSingletonPtr()->Mouse = static_cast<OIS::Mouse*>(Core::getSingletonPtr()->InputManager->createInputObject(OIS::OISMouse,true));
}catch(OIS::Exception& Except){
Internal::getSingletonPtr()->Exception((char*)Except.eText,(char*)Except.eFile); // the program termination depends on configuration
return false;
}


return true;
}


that's the way I initialize the GUI Subsystem..
now, let's go deeper ..

this is the implementation of the frame listener methods ..



bool LoadingListener::frameStarted(const Ogre::FrameEvent& evt){ Core::getSingletonPtr()->_MyGUI->injectFrameEntered(evt.timeSinceLastFrame);
return true;
}

/////////////////////////////////////////////////////////
bool LoadingListener::frameEnded(const Ogre::FrameEvent& evt){
return true;
}
/////////////////////////////////////////////////////////
bool LoadingListener::mouseMoved( const OIS::MouseEvent &arg ){
Core::getSingletonPtr()->_MyGUI->injectMouseMove(arg);
return true;
}
/////////////////////////////////////////////////////////
bool LoadingListener::mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id ){
Core::getSingletonPtr()->_MyGUI->injectMousePress(arg,id);
return true;
}
/////////////////////////////////////////////////////////
bool LoadingListener::mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id ){
Core::getSingletonPtr()->_MyGUI->injectMouseRelease(arg,id);
return true;
}
/////////////////////////////////////////////////////////
bool LoadingListener::keyPressed( const OIS::KeyEvent &arg ){
Core::getSingletonPtr()->_MyGUI->injectKeyPress(arg);
return true;
}
/////////////////////////////////////////////////////////
bool LoadingListener::keyReleased( const OIS::KeyEvent &arg ){
Core::getSingletonPtr()->_MyGUI->injectKeyRelease(arg);
return true;
}

/////////////////////////////////////////////////////////

void LoadingListener::windowResized(Ogre::RenderWindow* rw){
ScreenWidth = rw->getWidth();
ScreenHeight = rw->getHeight();

if (Core::getSingletonPtr()->Mouse){
const OIS::MouseState & ms = Core::getSingletonPtr()->Mouse->getMouseState();
ms.width = (int) ScreenWidth;
ms.height = (int) ScreenHeight;
}
}

/////////////////////////////////////////////////////////
LoadingListener::LoadingListener(){
// Render Window ...
this->RenderWindow = Core::getSingletonPtr()->RenderWindow;
Core::getSingletonPtr()->Mouse->setEventCallback(this);
Core::getSingletonPtr()->Keyboard->setEventCallback(this);
this->windowResized(this->RenderWindow);

}


for the listener, the only thing that matter it's that you implement the methods that they require and ..

public OIS::MouseListener,public Ogre::FrameListener, public OIS::KeyListener,public Ogre::WindowEventListener

That'z All =)
and ..



// assuming that Loading is an instance of that class =)
Core::getSingletonPtr()->OgreRoot->addFrameListener(Loading);
Ogre::WindowEventUtilities::addWindowEventListener(Window,Loading);


That's all, sorry for that messy code :$
if you don't understand something, tell me n_n

Adieu !

mrmclovin

17-08-2008 20:33:24

Hey! Thanks for your answer. Im sorry but I got it wrong. What I meant is if it's possible to inject unbuffered input?

Im sorry for the trouble of your previous answer :)