/home/jpf/code/cc/project/cmil/demo/demo.cpp

Go to the documentation of this file.
00001 #include <SDL/SDL.h>
00002 #include <SDLSystem.h> 
00003 
00004 #include <InputSequencer.h>
00005 #include <InputNode.h>
00006 #include <InputContext.h>
00007 #include <ContextActor.h>
00008 
00009 using namespace cmil;
00010 
00011 class helloAction: public ModAction, CoordAction {
00012   public:
00013     helloAction(const std::string& name) : InputAction(name), ModAction(name), CoordAction(name) {}
00014 
00015     void doPress() { 
00016       std::cout << "hello! pressed " << std::endl;
00017       std::cout << std::endl;
00018     }
00019     void doRelease() { 
00020       std::cout << "hello! released " << std::endl;
00021       std::cout << std::endl;
00022     }
00023 
00024     void runCoord(unsigned long int x, unsigned long int y, int xrel, int yrel) {
00025       std::cout << "hello! x: " << x << " y: " << y << " xrel: " << xrel <<" yrel: " << yrel << std::endl;
00026     }; 
00027 };
00028 
00030 class WidgetMouse : public SDL::DefaultMouse {
00031   public:
00032     WidgetMouse() : DefaultMouse("WidgetMouse") {
00033       setInput( "LeftButton", "WidgetLeftButton"  );
00034       setInput( "MiddleButton", "WidgetMiddleButton");
00035       setInput( "RightButton", "WidgetRightButton" );
00036       setInput( "WheelUp", "WidgetWheelUp"     );
00037       setInput( "WheelDown", "WidgetWheelDown"   );
00038       setInput( "Motion" , "WidgetMotion");
00039     }; 
00040 };
00041 
00042 class Application {
00043   public:
00044     Application() :
00045       m_actor(NULL),
00046       m_hello(new helloAction("hello action")), 
00047       m_system(NULL),
00048       m_quit(false) {
00049         init();
00050     }
00051 
00052     ~Application() {
00053       if(m_actor)  delete m_actor;
00054       if(m_hello)  delete m_hello;
00055       if(m_system) delete m_system;
00056     }
00057 
00058     void quit() { m_quit = true; }
00059 
00060     bool getQuit() const {
00061       return m_quit; 
00062     }
00063 
00064     void run() { 
00065       while(!m_actor->getQuit()) { 
00066         m_system->poll(); 
00067         SDL_Delay(1); 
00068       }
00069 
00070       SDL_Quit();
00071     }
00072 
00073   private:
00074     void init() { 
00075       if( SDL_Init( SDL_INIT_VIDEO ) < 0){
00076           fprintf( stderr, "Could not initialise SDL: %s\n", SDL_GetError() );
00077           exit( -1 );
00078       }
00079 
00080       if( !SDL_SetVideoMode( 0, 0, 0, SDL_HWSURFACE | SDL_RESIZABLE ) ) {
00081           fprintf( stderr, "Could not set video mode: %s\n", SDL_GetError() );
00082           SDL_Quit();
00083           exit( -1 );
00084       }
00085 
00086       SDL_WM_SetCaption("demoing cmil alpha 0.91", "demo"); 
00087       SDL_EnableUNICODE(1);
00088 
00089       std::cout << "SDL initialized." << std::endl;
00090       std::cout << std::endl;
00091 
00092       SDL::SDLSystem::Parameters params;
00093 
00095 
00096       params.add(SDL::Mice, new WidgetMouse());
00097       params.add(SDL::Keyboards);
00098 
00099       m_system = new SDL::SDLSystem(params);
00100 
00103       
00104       m_actor  = new ContextActor(m_system);
00105 
00106       m_system -> attach(m_actor);
00107 
00108       m_actor->addNormal( Ev("Keyboard", "F") << m_hello );
00109       m_actor->addNormal( Ev("Keyboard", "Ctrl") << Ev("Keyboard", "F") << m_hello );
00110       m_actor->addNormal( Ev("WidgetMouse", "WidgetMotion") << m_hello );
00111       m_actor->addNormal( Ev("WidgetMouse", "WidgetLeftButton") << m_hello );
00112     }
00113 
00114     ContextActor* m_actor;
00115     helloAction*  m_hello;
00116     System*       m_system;
00117 
00118     bool m_quit;
00119 };
00120 
00121 int main() {
00122   Application myApp;
00123   myApp.run();
00124 
00125   return 0;
00126 }

(c) 2006-2007 John P. Feltz
Generated on Wed Jul 25 16:08:02 2007 for Common Media Input Layer by doxygen 1.4.7

SourceForge.net Logo