// -*- mode: C++; tab-width: 4; indent-tabs-mode: t; -*- vim:ts=4:sw=4 // // Copyright (C) 2004-2005 David Lau (skunix) // Chong Kai Xiong (descender) // // This file is part of The Plains of Usata. // // The Plains of Usata is licensed under the GNU General Public // License (GPL) version 2. For details, please see the COPYING file // included in the software distribution, or visit // http://www.fsf.org/licenses/gpl.html. // // $Id: input.cpp,v 1.1 2005/01/25 08:28:27 skunix Exp $ #include "../input-system.hpp" #include #include namespace usata { namespace input{ namespace { using namespace input; class SDLDriver: public input::Driver { bool mKbEnabled, mMouseEnabled, mJoystickEnabled; SDL_Event mSDL_ev; public: SDLDriver(); virtual void update(){} virtual void configure (); virtual bool supports(DeviceType type); virtual bool enable(DeviceType type, bool); Event* process(); virtual Event* next(); }; SDLDriver::SDLDriver() : input::Driver("sdl"), mKbEnabled(true), mMouseEnabled(true), mJoystickEnabled(true) { } bool SDLDriver::supports(DeviceType dt) { return true; }; bool SDLDriver::enable(DeviceType type, bool e) { bool retval = false; switch (type) { case KEYBOARD: case JOYSTICK: case MOUSE: break; default: break; } return retval; } void SDLDriver::configure() { return; } Event* SDLDriver::process() { switch (mSDL_ev.type) { case SDL_KEYDOWN: case SDL_KEYUP: case SDL_QUIT: return new SystemEvent(SystemEvent::QUIT); break; }; return 0; } Event* SDLDriver::next() { Event*retval(0); while (1) { if (!SDL_PollEvent(&mSDL_ev)) break; retval = process(); if (retval) break; } return retval; } } Driver * default_driver() { return new SDLDriver; } } }