You can subscribe to this list here.
2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
(153) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
(48) |
Feb
(46) |
Mar
(12) |
Apr
(4) |
May
(4) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2007 |
Jan
|
Feb
(263) |
Mar
(235) |
Apr
(66) |
May
(42) |
Jun
(270) |
Jul
(65) |
Aug
(2) |
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: yao L. <xua...@gm...> - 2013-01-25 13:04:44
|
Hello! I wish to post the mail list -- 嘿嘿,试试gamil........ |
From: Markus R. <rol...@us...> - 2007-08-16 19:08:59
|
Update of /cvsroot/simspark/simspark/spark/zeitgeist In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv7378 Modified Files: parameterlist.cpp parameterlist.h Log Message: - check if the provided iterator reached the parameter list end (applied patch by Ben from Apollo3D, NJUPT, CHINA) Index: parameterlist.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/zeitgeist/parameterlist.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** parameterlist.cpp 5 Dec 2005 20:59:18 -0000 1.1 --- parameterlist.cpp 16 Aug 2007 19:08:54 -0000 1.2 *************** *** 224,227 **** --- 224,232 ---- } + if (iter == mList.end()) + { + return false; + } + const any& param = (*iter); string str; Index: parameterlist.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/zeitgeist/parameterlist.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** parameterlist.h 5 Dec 2005 20:59:18 -0000 1.1 --- parameterlist.h 16 Aug 2007 19:08:54 -0000 1.2 *************** *** 228,231 **** --- 228,236 ---- ConvertStringValue(TVector::const_iterator& iter, TYPE& value) const { + if (iter == mList.end()) + { + return false; + } + const boost::any& param = (*iter); *************** *** 263,266 **** --- 268,276 ---- GetValueInternal(TVector::const_iterator& iter, TTo& value) const { + if (iter == mList.end()) + { + return false; + } + const boost::any& param = (*iter); |
From: Markus R. <rol...@us...> - 2007-08-16 19:05:37
|
Update of /cvsroot/simspark/simspark/spark/salt In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv6173 Modified Files: tvector.h Log Message: - fixed operator/= (thanks to Ben from Apollo3D, NJUPT, CHINA for spotting this) Index: tvector.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/salt/tvector.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** tvector.h 17 Jun 2007 13:38:39 -0000 1.2 --- tvector.h 16 Aug 2007 19:05:29 -0000 1.3 *************** *** 424,428 **** { for (int c=0; c<ELEMENTS; c++) ! mData[c] *= v; return *static_cast<TYPE*>(this); } --- 424,428 ---- { for (int c=0; c<ELEMENTS; c++) ! mData[c] /= v; return *static_cast<TYPE*>(this); } |
From: Oliver O. <fr...@us...> - 2007-07-24 05:04:15
|
Update of /cvsroot/simspark/simspark/spark In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv14520 Modified Files: Tag: projectx ChangeLog Log Message: *** empty log message *** Index: ChangeLog =================================================================== RCS file: /cvsroot/simspark/simspark/spark/ChangeLog,v retrieving revision 1.1.2.2.2.7 retrieving revision 1.1.2.2.2.8 diff -C2 -d -r1.1.2.2.2.7 -r1.1.2.2.2.8 *** ChangeLog 22 Jun 2007 14:22:34 -0000 1.1.2.2.2.7 --- ChangeLog 24 Jul 2007 05:03:58 -0000 1.1.2.2.2.8 *************** *** 1,2 **** --- 1,26 ---- + 2007-07-24 Oliver Obst <fr...@cs...> + 2007-07-24 Oliver Obst <oli...@ne...> + + * configure.ac: + changes for new subdirs, version numbers updated (from rcssserver3D), + MacOS stuff included + * oxygen/simulationserver/simulationserver.cpp: + * oxygen/simulationserver/simulationserver_c.cpp: + * oxygen/simulationserver/simulationserver.h: + - backport from rcssserver3D + + * plugin/Makefile.am: + added various new subdirs (newly created plugins and some from rcssserver3D) + + * plugin/inputois/Makefile.am: + using installed version of libOIS instead of a precompiled object/archive file + + * utility/Makefile.am: added OIS library to utilities + + 2007-07-19 Oliver Obst <oli...@ne...> + + * plugin/rubysceneimporter/rubysceneimporter.cpp: + added abbrevs. from rcssserver3D + 2007-06-23 Oliver Obst <oli...@ne...> *************** *** 21,26 **** * kerosin/openglserver/openglwrapper.h: ! include GLU on a Mac as well ! 2007-06-22 Oliver Obst <oli...@ne...> --- 45,49 ---- * kerosin/openglserver/openglwrapper.h: ! include GLU on a Mac as well 2007-06-22 Oliver Obst <oli...@ne...> |
From: Oliver O. <fr...@us...> - 2007-07-24 05:03:25
|
Update of /cvsroot/simspark/simspark/spark In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv14499 Modified Files: Tag: projectx configure.ac Log Message: changes for new subdirs, version numbers updated (rcssserver3D), MacOS stuff included Index: configure.ac =================================================================== RCS file: /cvsroot/simspark/simspark/spark/configure.ac,v retrieving revision 1.5.2.2.2.1 retrieving revision 1.5.2.2.2.2 diff -C2 -d -r1.5.2.2.2.1 -r1.5.2.2.2.2 *** configure.ac 30 Mar 2007 03:56:17 -0000 1.5.2.2.2.1 --- configure.ac 24 Jul 2007 05:03:21 -0000 1.5.2.2.2.2 *************** *** 1,4 **** # Process this file with autoconf to produce a configure script. ! AC_INIT([simspark], 0.1, [sim...@li...]) AC_CONFIG_SRCDIR([salt/salt.h]) AC_CONFIG_HEADER([sparkconfig.h]) --- 1,4 ---- # Process this file with autoconf to produce a configure script. ! AC_INIT([simspark], 0.1-projectx, [sim...@li...]) AC_CONFIG_SRCDIR([salt/salt.h]) AC_CONFIG_HEADER([sparkconfig.h]) *************** *** 12,18 **** ## Here are the version numbers of our libraries. They should be updated (only) ## immediately before a release of the package. See libtool manual for details. ! RCSS_LIBRARY_VERSION_INFO(salt_version_info,salt_version,'3:0:3') RCSS_LIBRARY_VERSION_INFO(zeitgeist_version_info,zeitgeist_version,'3:1:0') ! RCSS_LIBRARY_VERSION_INFO(oxygen_version_info,oxygen_version,'3:0:1') RCSS_LIBRARY_VERSION_INFO(kerosin_version_info,kerosin_version,'1:0:0') RCSS_LIBRARY_VERSION_INFO(spark_version_info,spark_version,'0:0:0') --- 12,18 ---- ## Here are the version numbers of our libraries. They should be updated (only) ## immediately before a release of the package. See libtool manual for details. ! RCSS_LIBRARY_VERSION_INFO(salt_version_info,salt_version,'3:1:3') RCSS_LIBRARY_VERSION_INFO(zeitgeist_version_info,zeitgeist_version,'3:1:0') ! RCSS_LIBRARY_VERSION_INFO(oxygen_version_info,oxygen_version,'5:1:2') RCSS_LIBRARY_VERSION_INFO(kerosin_version_info,kerosin_version,'1:0:0') RCSS_LIBRARY_VERSION_INFO(spark_version_info,spark_version,'0:0:0') *************** *** 33,37 **** AC_PROG_AWK AC_CHECK_PROG([DOXYGEN], [doxygen], [yes], [no]) ! AC_CHECK_PROG([PDFLATEX], [pdflatex]) AM_CONDITIONAL(DOXYGEN, test x$DOXYGEN = xyes ) AM_CONDITIONAL(COND_PDFLATEX, test x$PDFLATEX != x) --- 33,37 ---- AC_PROG_AWK AC_CHECK_PROG([DOXYGEN], [doxygen], [yes], [no]) ! AC_CHECK_PROG([PDFLATEX], [pdflatex], [yes], [no]) AM_CONDITIONAL(DOXYGEN, test x$DOXYGEN = xyes ) AM_CONDITIONAL(COND_PDFLATEX, test x$PDFLATEX != x) *************** *** 131,134 **** --- 131,135 ---- utility/Makefile \ utility/libobj/Makefile \ + utility/ois/Makefile \ utility/sfsexp/Makefile \ utility/rcssnet/Makefile \ *************** *** 147,153 **** --- 148,160 ---- test/coretest/Makefile \ plugin/Makefile \ + plugin/collisionperceptor/Makefile \ plugin/filesystemstd/Makefile \ + plugin/gyrorateperceptor/Makefile \ plugin/sceneeffector/Makefile \ + plugin/inputois/Makefile \ plugin/inputsdl/Makefile \ + plugin/movieff/Makefile \ + plugin/objimporter/Makefile \ + plugin/openglsysogre/Makefile \ plugin/openglsyssdl/Makefile \ plugin/sexpparser/Makefile \ *************** *** 155,163 **** plugin/rosimporter/Makefile \ plugin/sparkmonitor/Makefile \ ! plugin/sparkagent/Makefile ], [test -f salt/salt-config && chmod a+x salt/salt-config && \ test -f zeitgeist/zeitgeist-config && chmod a+x zeitgeist/zeitgeist-config && \ test -f oxygen/oxygen-config && chmod a+x oxygen/oxygen-config && \ test -f kerosin/kerosin-config && chmod a+x kerosin/kerosin-config && \ ! test -f spark/spark-config && chmod +x spark/spark-config ]) AC_OUTPUT --- 162,171 ---- plugin/rosimporter/Makefile \ plugin/sparkmonitor/Makefile \ ! plugin/sparkagent/Makefile \ ! plugin/voidmeshimporter/Makefile ], [test -f salt/salt-config && chmod a+x salt/salt-config && \ test -f zeitgeist/zeitgeist-config && chmod a+x zeitgeist/zeitgeist-config && \ test -f oxygen/oxygen-config && chmod a+x oxygen/oxygen-config && \ test -f kerosin/kerosin-config && chmod a+x kerosin/kerosin-config && \ ! test -f spark/spark-config && chmod +x spark/spark-config]) AC_OUTPUT |
From: Oliver O. <fr...@us...> - 2007-07-24 05:00:45
|
Update of /cvsroot/simspark/simspark/spark In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv13245 Modified Files: Tag: projectx acinclude.m4 Log Message: some checks for the MacOS platform Index: acinclude.m4 =================================================================== RCS file: /cvsroot/simspark/simspark/spark/acinclude.m4,v retrieving revision 1.4.2.2.2.2 retrieving revision 1.4.2.2.2.3 diff -C2 -d -r1.4.2.2.2.2 -r1.4.2.2.2.3 *** acinclude.m4 17 Jun 2007 12:08:34 -0000 1.4.2.2.2.2 --- acinclude.m4 24 Jul 2007 05:00:35 -0000 1.4.2.2.2.3 *************** *** 146,149 **** --- 146,151 ---- AC_CHECK_HEADERS([OpenGL/gl.h GLUT/glut.h], [rcss_iamamac=yes], [rcss_iamamac=no]) AC_MSG_CHECKING([if I am a Mac]) + AM_CONDITIONAL(BUNDLE_SUPPORT, test x$rcss_iamamac = xyes) + AC_SUBST(bundle_support, $rcss_iamamac) if test "$rcss_iamamac" = "yes"; then AC_MSG_RESULT([yes]) *************** *** 209,212 **** --- 211,216 ---- #----------------------------------------------------------------------------- AC_DEFUN([RCSS_CHECK_DEVIL], [ + rcss_IL_LIBADD="" + rcss_IL_LDFLAGS="" AC_ARG_VAR(DEVIL, [location of DevIL installation]) if test $DEVIL; then *************** *** 223,226 **** --- 227,231 ---- if test "$rcss_tmp" != "no"; then if test "$rcss_iamamac" = "yes"; then + IL_LIBADD="-framework IL" rcss_ld="-framework IL" else *************** *** 362,368 **** AC_ARG_ENABLE(kerosin, AC_HELP_STRING([--enable-kerosin=@<:@yes|no@:>@], ! [whether to compile libkerosin (default is no)]), [rcss_build_kerosin="$enableval"], ! [rcss_build_kerosin=no] ) if test "$rcss_build_kerosin" = yes; then --- 367,373 ---- AC_ARG_ENABLE(kerosin, AC_HELP_STRING([--enable-kerosin=@<:@yes|no@:>@], ! [whether to compile libkerosin (default is yes)]), [rcss_build_kerosin="$enableval"], ! [rcss_build_kerosin=yes] ) if test "$rcss_build_kerosin" = yes; then |
From: Oliver O. <fr...@us...> - 2007-07-24 04:58:56
|
Update of /cvsroot/simspark/simspark/spark/oxygen/simulationserver In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv12432 Modified Files: Tag: projectx simulationserver.cpp Log Message: backport from rcssserver3D Index: simulationserver.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/oxygen/simulationserver/simulationserver.cpp,v retrieving revision 1.3.2.2.2.2 retrieving revision 1.3.2.2.2.3 diff -C2 -d -r1.3.2.2.2.2 -r1.3.2.2.2.3 *** simulationserver.cpp 17 Jun 2007 07:53:25 -0000 1.3.2.2.2.2 --- simulationserver.cpp 24 Jul 2007 04:58:53 -0000 1.3.2.2.2.3 *************** *** 52,55 **** --- 52,56 ---- mArgC = 0; mArgV = 0; + mMultiThreads = true; signal(SIGINT, CatchSignal); *************** *** 178,182 **** void SimulationServer::AdvanceTime(float deltaTime) { - mSumDeltaTime += deltaTime; } --- 179,182 ---- *************** *** 324,325 **** --- 324,329 ---- + void SimulationServer::SetMultiThreads(bool isMThreas) + { + mMultiThreads = isMThreas; + } |
From: Oliver O. <fr...@us...> - 2007-07-24 04:58:22
|
Update of /cvsroot/simspark/simspark/spark/oxygen/simulationserver In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv12415 Modified Files: Tag: projectx simulationserver_c.cpp Log Message: backport from rcssserver3D Index: simulationserver_c.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/oxygen/simulationserver/simulationserver_c.cpp,v retrieving revision 1.1.4.3 retrieving revision 1.1.4.4 diff -C2 -d -r1.1.4.3 -r1.1.4.4 *** simulationserver_c.cpp 17 Jun 2007 07:54:26 -0000 1.1.4.3 --- simulationserver_c.cpp 24 Jul 2007 04:58:19 -0000 1.1.4.4 *************** *** 104,107 **** --- 104,123 ---- } + FUNCTION(SimulationServer, setMultiThreads) + { + bool inSet; + + if ( + (in.GetSize() != 1) || + (! in.GetValue(in[0], inSet)) + ) + { + return false; + } + + obj->SetMultiThreads(inSet); + return true; + } + void CLASS(SimulationServer)::DefineClass() { *************** *** 115,117 **** --- 131,134 ---- DEFINE_FUNCTION(setAutoTimeMode); DEFINE_FUNCTION(getAutoTimeMode); + DEFINE_FUNCTION(setMultiThreads); } |
From: Oliver O. <fr...@us...> - 2007-07-24 04:57:54
|
Update of /cvsroot/simspark/simspark/spark/oxygen/simulationserver In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv12033 Modified Files: Tag: projectx simulationserver.h Log Message: backport from rcssserver3D Index: simulationserver.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/oxygen/simulationserver/simulationserver.h,v retrieving revision 1.2.2.1.2.1 retrieving revision 1.2.2.1.2.2 diff -C2 -d -r1.2.2.1.2.1 -r1.2.2.1.2.2 *** simulationserver.h 17 Jun 2007 07:53:55 -0000 1.2.2.1.2.1 --- simulationserver.h 24 Jul 2007 04:57:46 -0000 1.2.2.1.2.2 *************** *** 129,132 **** --- 129,139 ---- int GetCycle(); + bool isExit() const { return mExit; } + + float GetSumDeltaTime() const { return mSumDeltaTime; } + + /** set the simulation run in multi-threads or in a signal thread */ + void SetMultiThreads(bool isMThreas); + protected: virtual void OnLink(); *************** *** 180,183 **** --- 187,193 ---- /** a cached reference to the SceneServer */ CachedPath<SceneServer> mSceneServer; + + /** indicates the simulation run in multi-threads or single thread */ + bool mMultiThreads; }; |
From: Oliver O. <fr...@us...> - 2007-07-24 04:54:09
|
Update of /cvsroot/simspark/simspark/spark/plugin In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv10644 Modified Files: Tag: projectx Makefile.am Log Message: added various new subdirs (newly created plugins and some from rcssserver3D) Index: Makefile.am =================================================================== RCS file: /cvsroot/simspark/simspark/spark/plugin/Makefile.am,v retrieving revision 1.3 retrieving revision 1.3.4.1 diff -C2 -d -r1.3 -r1.3.4.1 *** Makefile.am 24 Jan 2006 19:16:32 -0000 1.3 --- Makefile.am 24 Jul 2007 04:54:04 -0000 1.3.4.1 *************** *** 1,5 **** --- 1,11 ---- SUBDIRS = \ + collisionperceptor \ filesystemstd \ + gyrorateperceptor \ + inputois \ inputsdl \ + movieff \ + objimporter \ + openglsysogre \ openglsyssdl \ sexpparser \ *************** *** 8,12 **** sparkmonitor\ sparkagent\ ! sceneeffector --- 14,19 ---- sparkmonitor\ sparkagent\ ! sceneeffector \ ! voidmeshimporter |
From: Oliver O. <fr...@us...> - 2007-07-24 04:52:08
|
Update of /cvsroot/simspark/simspark/spark/plugin/inputois In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv9991 Modified Files: Tag: projectx Makefile.am Log Message: using installed version of libOIS instead of a precompiled object/archive file Index: Makefile.am =================================================================== RCS file: /cvsroot/simspark/simspark/spark/plugin/inputois/Attic/Makefile.am,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** Makefile.am 24 Jul 2007 01:13:16 -0000 1.1.2.1 --- Makefile.am 24 Jul 2007 04:52:05 -0000 1.1.2.2 *************** *** 19,23 **** # -module tells automake we're not building a library but a loadable module # so we don't need the "lib" prefix in the module name ! inputois_la_LDFLAGS = -module -avoid-version libois.a AM_CPPFLAGS = -I${top_srcdir}/lib @RUBY_CPPFLAGS@ -I/Users/fruit/Code/ogrenew/Dependencies/include --- 19,24 ---- # -module tells automake we're not building a library but a loadable module # so we don't need the "lib" prefix in the module name ! inputois_la_LDFLAGS = -module -avoid-version ! inputois_la_LIBADD = -lOIS AM_CPPFLAGS = -I${top_srcdir}/lib @RUBY_CPPFLAGS@ -I/Users/fruit/Code/ogrenew/Dependencies/include |
From: Oliver O. <fr...@us...> - 2007-07-24 04:48:39
|
Update of /cvsroot/simspark/simspark/spark/spark In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv8415 Modified Files: Tag: projectx spark.rb Log Message: whitespace Index: spark.rb =================================================================== RCS file: /cvsroot/simspark/simspark/spark/spark/spark.rb,v retrieving revision 1.5.2.4.2.2 retrieving revision 1.5.2.4.2.3 diff -C2 -d -r1.5.2.4.2.2 -r1.5.2.4.2.3 *** spark.rb 22 Jun 2007 14:09:57 -0000 1.5.2.4.2.2 --- spark.rb 24 Jul 2007 04:48:23 -0000 1.5.2.4.2.3 *************** *** 421,427 **** sceneServer.initSceneImporter("RosImporter"); - # prepare scene - sparkResetScene() - # # setup the MaterialServer --- 421,424 ---- *************** *** 455,456 **** --- 452,457 ---- # import the spark perceptors and effector set importBundle "sparkagent" + + # prepare scene + sparkResetScene() + |
From: Oliver O. <fr...@us...> - 2007-07-24 04:46:46
|
Update of /cvsroot/simspark/simspark/spark/utility In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv7486 Modified Files: Tag: projectx Makefile.am Log Message: added OIS library to utilities Index: Makefile.am =================================================================== RCS file: /cvsroot/simspark/simspark/spark/utility/Makefile.am,v retrieving revision 1.2.2.1 retrieving revision 1.2.2.1.2.1 diff -C2 -d -r1.2.2.1 -r1.2.2.1.2.1 *** Makefile.am 12 Feb 2007 23:59:02 -0000 1.2.2.1 --- Makefile.am 24 Jul 2007 04:46:33 -0000 1.2.2.1.2.1 *************** *** 1,5 **** SUBDIRS = libobj \ rcssnet \ ! sfsexp\ tinyxml --- 1,6 ---- SUBDIRS = libobj \ + ois \ rcssnet \ ! sfsexp \ tinyxml |
Update of /cvsroot/simspark/simspark/spark/plugin/inputois In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv17660 Added Files: Tag: projectx .cvsignore Makefile.am export.cpp inputdeviceois.h inputdeviceois_c.cpp inputsystemois.cpp inputsystemois.h inputsystemois_c.cpp keyboardois.cpp keyboardois.h keyboardois_c.cpp mouseois.cpp mouseois.h mouseois_c.cpp timerois.cpp timerois.h timerois_c.cpp Log Message: added ois input system --- NEW FILE: .cvsignore --- .deps .libs Makefile Makefile.in *.la *.lo --- NEW FILE: timerois.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Wed May 9 2007 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2007 RoboCup Soccer Server 3D Maintenance Group $Id: timerois.h,v 1.1.2.1 2007/07/24 01:13:16 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. TimerOIS HISTORY: 17.05.07 - OO - Initial version */ #ifndef TIMEROIS_H #define TIMEROIS_H #include "inputdeviceois.h" #include <sys/time.h> /** \class TimerOIS returns the elapsed time since the last call in milliseconds. */ class TimerOIS : public InputDeviceOIS { // // functions // public: TimerOIS(); virtual ~TimerOIS(); //! init the device virtual bool Init(kerosin::InputSystem* inputSystem); //! this filters an SDL specific input virtual int EventFilter(const OIS::EventArg* event); //! return an Input void GetInput(kerosin::Input &input); protected: unsigned long int TimevalSubtract(const timeval* x, const timeval* y) const; protected: timeval mLastTimeVal; }; DECLARE_CLASS(TimerOIS); #endif //MOUSESDL_H__ --- NEW FILE: inputdeviceois.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: inputdeviceois.h,v 1.1.2.1 2007/07/24 01:13:16 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. InputDeviceOIS HISTORY: 16/03/07 - OO - Initial version */ #ifndef INPUTDEVICEOIS_H__ #define INPUTDEVICEOIS_H__ #include <kerosin/inputserver/inputdevice.h> #include <kerosin/inputserver/inputserver.h> namespace OIS { class EventArg; } /** \class InputDeviceOIS This class introduces OIS-specific callback functions for the event filtering. */ class InputDeviceOIS : public kerosin::InputDevice { // // functions // public: //! this filters an OIS specific input // virtual int EventFilter(const OIS::EventArg* event) = 0; virtual void Capture() {} }; DECLARE_ABSTRACTCLASS(InputDeviceOIS); #endif //INPUTDEVICEOIS_H__ --- NEW FILE: keyboardois_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: keyboardois_c.cpp,v 1.1.2.1 2007/07/24 01:13:16 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "keyboardois.h" void CLASS(KeyboardOIS)::DefineClass() { DEFINE_BASECLASS(InputDeviceOIS); } --- NEW FILE: inputsystemois.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: inputsystemois.cpp,v 1.1.2.1 2007/07/24 01:13:16 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "inputsystemois.h" #include "inputdeviceois.h" #include <zeitgeist/logserver/logserver.h> #include <kerosin/inputserver/inputserver.h> #include <kerosin/openglserver/openglserver.h> #include <sstream> #include <OIS/OIS.h> using namespace boost; using namespace kerosin; using namespace zeitgeist; using namespace OIS; /*! This function is used to filter OIS Events and delegate them to the input device which registered for the event type. NOTE: This function may run in a different thread, so care has to be taken when accessing the global object. Things to watch out for: - gDeviceList changes (done by individual devices (construction/destruction)) handled - Events are pushed into a device (done by EventFilter) - Events are taken out of a device (this is done by the inputserver) */ InputSystemOIS *gInputSystem; InputSystemOIS::InputSystemOIS() : InputSystem(), mOIS(0) { } InputSystemOIS::~InputSystemOIS() { InputManager::destroyInputSystem(mOIS); } bool InputSystemOIS::Init(InputServer *inputServer) { if (!InputSystem::Init(inputServer)) return false; mOpenGLServer = shared_dynamic_cast<OpenGLServer> (GetCore()->Get("/sys/server/opengl")); if (mOpenGLServer.get() == 0) { GetLog()->Error() << "(InputSystemOIS) ERROR: OpenGLServer not found\n"; return false; } // set up an OIS parameter list ParamList pl; std::ostringstream ss; ss << mOpenGLServer->GetWindowHandle(); pl.insert(ParamList::value_type("WINDOW", ss.str())); mOIS = InputManager::createInputSystem(pl); return true; } bool InputSystemOIS::CreateDevice(const std::string& deviceName) { // first, we mangle the deviceName to avoid nameclashes std::string mangledName = deviceName + "OIS"; shared_ptr<InputDevice> device = shared_static_cast<InputDevice>(GetCore()->New(mangledName)); if (device.get() == 0) { GetLog()->Error() << "ERROR: (InputSystemOIS) Creating device '" << mangledName << "'\n"; return false; } // initialize the device if (device->Init(this) == false) { GetLog()->Error() << "ERROR: (InputSystemOIS) Initializing device '" << mangledName << "'\n"; return false; } // try to link the device into the inputserver // some special case handling for the timer (FIXME) if (mangledName.compare("TimerOIS") == 0) { mTimer = shared_static_cast<TimerOIS>(device); } else { if (AddChildReference(device) == false) { GetLog()->Error() << "ERROR: (InputSystemOIS) Linking device '" << mangledName << "'\n"; return false; } } return true; } void InputSystemOIS::Capture() { // loop through all children for (TLeafList::iterator i = mChildren.begin(); i!=mChildren.end(); ++i) { shared_ptr<InputDeviceOIS> device = shared_static_cast<InputDeviceOIS>(*i); device->Capture(); } } void InputSystemOIS::AddInput(const Input& input) { InputSystem::AddInput(input); } bool InputSystemOIS::GetInput(Input& input) { Capture(); return InputSystem::GetInput(input); } bool InputSystemOIS::UpdateTimerInput(Input &input) { if (mTimer.get() == 0) { return false; } mTimer->GetInput(input); return true; } OIS::InputManager* InputSystemOIS::GetInputManager() { return mOIS; } --- NEW FILE: keyboardois.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: keyboardois.cpp,v 1.1.2.1 2007/07/24 01:13:16 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "keyboardois.h" #include "inputsystemois.h" #include <kerosin/inputserver/inputserver.h> #include <zeitgeist/logserver/logserver.h> using namespace kerosin; using namespace OIS; KeyboardOIS::KeyboardOIS() { SetupSymMap(); } KeyboardOIS::~KeyboardOIS() { } void KeyboardOIS::SetupSymMap() { mSymbols.clear(); // KC_UNASSIGNED mSymbols[KC_ESCAPE] = Input::IC_ESCAPE; mSymbols[KC_0] = Input::IC_0; mSymbols[KC_1] = Input::IC_1; mSymbols[KC_2] = Input::IC_2; mSymbols[KC_3] = Input::IC_3; mSymbols[KC_4] = Input::IC_4; mSymbols[KC_5] = Input::IC_5; mSymbols[KC_6] = Input::IC_6; mSymbols[KC_7] = Input::IC_7; mSymbols[KC_8] = Input::IC_8; mSymbols[KC_9] = Input::IC_9; mSymbols[KC_MINUS] = Input::IC_MINUS; mSymbols[KC_EQUALS] = Input::IC_EQUALS; mSymbols[KC_BACK] = Input::IC_BACKSPACE; mSymbols[KC_TAB] = Input::IC_TAB; mSymbols[KC_Q] = Input::IC_Q; mSymbols[KC_W] = Input::IC_W; mSymbols[KC_E] = Input::IC_E; mSymbols[KC_R] = Input::IC_R; mSymbols[KC_T] = Input::IC_T; mSymbols[KC_Y] = Input::IC_Y; mSymbols[KC_U] = Input::IC_U; mSymbols[KC_I] = Input::IC_I; mSymbols[KC_O] = Input::IC_O; mSymbols[KC_P] = Input::IC_P; mSymbols[KC_LBRACKET] = Input::IC_LBRACKET; mSymbols[KC_RBRACKET] = Input::IC_RBRACKET; mSymbols[KC_RETURN] = Input::IC_RETURN; mSymbols[KC_LCONTROL] = Input::IC_LCTRL; mSymbols[KC_A] = Input::IC_A; mSymbols[KC_S] = Input::IC_S; mSymbols[KC_D] = Input::IC_D; mSymbols[KC_F] = Input::IC_F; mSymbols[KC_G] = Input::IC_G; mSymbols[KC_H] = Input::IC_H; mSymbols[KC_J] = Input::IC_J; mSymbols[KC_K] = Input::IC_K; mSymbols[KC_L] = Input::IC_L; mSymbols[KC_SEMICOLON] = Input::IC_SEMICOLON; // KC_APOSTROPHE // KC_GRAVE mSymbols[KC_LSHIFT] = Input::IC_LSHIFT; mSymbols[KC_BACKSLASH] = Input::IC_BACKSLASH; mSymbols[KC_Z] = Input::IC_Z; mSymbols[KC_X] = Input::IC_X; mSymbols[KC_C] = Input::IC_C; mSymbols[KC_V] = Input::IC_V; mSymbols[KC_B] = Input::IC_B; mSymbols[KC_N] = Input::IC_N; mSymbols[KC_M] = Input::IC_M; mSymbols[KC_COMMA] = Input::IC_COMMA; mSymbols[KC_PERIOD] = Input::IC_PERIOD; mSymbols[KC_SLASH] = Input::IC_SLASH; mSymbols[KC_RSHIFT] = Input::IC_RSHIFT; // KC_MULTIPLY // KC_LMENU mSymbols[KC_SPACE] = Input::IC_SPACE; // KC_CAPITAL mSymbols[KC_F1] = Input::IC_F1; mSymbols[KC_F2] = Input::IC_F2; mSymbols[KC_F3] = Input::IC_F3; mSymbols[KC_F4] = Input::IC_F4; mSymbols[KC_F5] = Input::IC_F5; mSymbols[KC_F6] = Input::IC_F6; mSymbols[KC_F7] = Input::IC_F7; mSymbols[KC_F8] = Input::IC_F8; mSymbols[KC_F9] = Input::IC_F9; mSymbols[KC_F10] = Input::IC_F10; mSymbols[KC_NUMLOCK] = Input::IC_NUMLOCK; mSymbols[KC_SCROLL] = Input::IC_SCROLLOCK; mSymbols[KC_NUMPAD7] = Input::IC_KP7; mSymbols[KC_NUMPAD8] = Input::IC_KP8; mSymbols[KC_NUMPAD9] = Input::IC_KP9; // KC_SUBTRACT mSymbols[KC_NUMPAD4] = Input::IC_KP4; mSymbols[KC_NUMPAD5] = Input::IC_KP5; mSymbols[KC_NUMPAD6] = Input::IC_KP6; // KC_ADD mSymbols[KC_NUMPAD1] = Input::IC_KP1; mSymbols[KC_NUMPAD2] = Input::IC_KP2; mSymbols[KC_NUMPAD3] = Input::IC_KP3; mSymbols[KC_NUMPAD0] = Input::IC_KP0; // is this the numad decimal? we map to it, at least mSymbols[KC_DECIMAL] = Input::IC_KP_DECIMAL; // KC_OEM_102 mSymbols[KC_F11] = Input::IC_F11; mSymbols[KC_F12] = Input::IC_F12; // KC_F13 // KC_F14 // KC_F15 // KC_KANA // KC_ABNT_C1 // KC_CONVERT // KC_NOCONVERT // KC_YEN // KC_ABNT_C2 // KC_NUMPADEQUALS // KC_PREVTRACK // KC_AT // KC_COLON // KC_UNDERLINE // KC_KANJI // KC_STOP // KC_AX // KC_UNLABELED // KC_NEXTTRACK mSymbols[KC_NUMPADENTER] = Input::IC_KP_ENTER; mSymbols[KC_RCONTROL] = Input::IC_RCTRL; // KC_MUTE // KC_CALCULATOR // KC_PLAYPAUSE // KC_MEDIASTOP // KC_VOLUMEDOWN // KC_VOLUMEUP // KC_WEBHOME mSymbols[KC_NUMPADCOMMA] = Input::IC_KP_DECIMAL; // KC_DIVIDE // KC_SYSRQ // KC_RMENU mSymbols[KC_PAUSE] = Input::IC_PAUSE; mSymbols[KC_HOME] = Input::IC_HOME; mSymbols[KC_UP] = Input::IC_UP; mSymbols[KC_PGUP] = Input::IC_PAGEUP; mSymbols[KC_LEFT] = Input::IC_LEFT; mSymbols[KC_RIGHT] = Input::IC_RIGHT; mSymbols[KC_END] = Input::IC_END; mSymbols[KC_DOWN] = Input::IC_DOWN; mSymbols[KC_PGDOWN] = Input::IC_PAGEDOWN; mSymbols[KC_INSERT] = Input::IC_INSERT; mSymbols[KC_DELETE] = Input::IC_DELETE; // KC_LWIN // KC_RWIN // KC_APPS // KC_POWER // KC_SLEEP // KC_WAKE // KC_WEBSEARCH // KC_WEBFAVORITES // KC_WEBREFRESH // KC_WEBSTOP // KC_WEBFORWARD // KC_WEBBACK // KC_MYCOMPUTER // KC_MAIL // KC_MEDIASELECT } bool KeyboardOIS::Init(kerosin::InputSystem *inputSystem) { InputSystemOIS* iois = dynamic_cast<InputSystemOIS*>(inputSystem); if (iois == 0) { GetLog()->Error() << "(KeyboardOIS) should be used with InputSystemOIS only\n"; return false; } OIS::InputManager* im = iois->GetInputManager(); mKeyboard = boost::shared_ptr<OIS::Keyboard>(static_cast<OIS::Keyboard*>(im->createInputObject(OIS::OISKeyboard, true))); mKeyboard.get()->setEventCallback(this); return InputDeviceOIS::Init(inputSystem); } bool KeyboardOIS::TranslateSymbol(KeyCode sym, int& tsym) const { TSymMap::const_iterator iter = mSymbols.find(sym); if (iter == mSymbols.end()) { return false; } tsym = (*iter).second; return true; } int KeyboardOIS::EventFilter(const EventArg* event, bool keyDown) { const KeyEvent* ke = dynamic_cast<const KeyEvent*>(event); // we only want keyboard events if (ke == 0) { return 1; } unsigned int& modState = mInputSystem->GetInputServer()->GetModifierState(); if (ke->key == KC_LSHIFT) { modState |= Input::eLShift; } if (ke->key == KC_RSHIFT) { modState |= Input::eRShift; } #if 0 if (ke->key.keysym.mod & KMOD_LALT) { modState |= Input::eLAlt; } if (ke->key.keysym.mod & KMOD_RALT) { modState |= Input::eRAlt; } #endif if (ke->key == 0) { return 1; } int tsym; // we could also use the event->text to get the mapping directly if (! TranslateSymbol(ke->key,tsym)) { GetLog()->Warning() << "(KeyboardOIS) WARNING: encountered unknown OIS key symbol " << ke->key << "\n"; return 1; } Input input(Input::eButton, tsym); input.mData.l = keyDown; mInputSystem->AddInputInternal(input); return 0; } void KeyboardOIS::Capture() { if (mKeyboard.get() != 0) { mKeyboard->capture(); } } bool KeyboardOIS::keyPressed(const OIS::KeyEvent& arg) { return (EventFilter(&arg,true) == 0); } bool KeyboardOIS::keyReleased(const OIS::KeyEvent& arg) { return (EventFilter(&arg,false) == 0); } --- NEW FILE: keyboardois.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: keyboardois.h,v 1.1.2.1 2007/07/24 01:13:16 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. KeyboardOIS HISTORY: 16/03/07 - OO - Initial version */ #ifndef KEYBOARDOIS_H__ #define KEYBOARDOIS_H__ #include "inputdeviceois.h" #include <OIS/OIS.h> class KeyboardOIS : public InputDeviceOIS, OIS::KeyListener { // // functions // public: KeyboardOIS(); virtual ~KeyboardOIS(); //! init the device virtual bool Init(kerosin::InputSystem* inputSystem); //! this filters an OIS specific input virtual int EventFilter(const OIS::EventArg* event, bool keyDown); //! get the keyboard input void Capture(); protected: /** sets up the mapping from OIS key constants to InputServer key constants */ void SetupSymMap(); /** translates a OIS key constant to an InputServer key constant. returns true on success */ bool TranslateSymbol(OIS::KeyCode sym, int& tsym) const; /** This method is called for buffered input from OIS. keyPressed is inherited from the OIS Keylistener baseclass. */ virtual bool keyPressed(const OIS::KeyEvent& arg ); /** This method is called for buffered input from OIS. keyPressed is inherited from the OIS Keylistener baseclass. */ virtual bool keyReleased(const OIS::KeyEvent& arg); protected: typedef std::map<OIS::KeyCode,int> TSymMap; //! mapping from OIS key constants to InputServer key constants TSymMap mSymbols; //! the OIS keyboard device boost::shared_ptr<OIS::Keyboard> mKeyboard; }; DECLARE_CLASS(KeyboardOIS); #endif //KEYBOARDOIS_H__ --- NEW FILE: inputdeviceois_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2004 RoboCup Soccer Server 3D Maintenance Group $Id: inputdeviceois_c.cpp,v 1.1.2.1 2007/07/24 01:13:16 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "inputdeviceois.h" void CLASS(InputDeviceOIS)::DefineClass() { DEFINE_BASECLASS(kerosin/InputDevice); } --- NEW FILE: mouseois.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: mouseois.h,v 1.1.2.1 2007/07/24 01:13:16 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. MouseOIS HISTORY: 16/03/07 - OO - Initial version */ #ifndef MOUSEOIS_H__ #define MOUSEOIS_H__ #include "inputdeviceois.h" #include <OIS/OIS.h> class MouseOIS : public InputDeviceOIS, OIS::MouseListener { // // functions // public: MouseOIS(); virtual ~MouseOIS(); //! init the device virtual bool Init(kerosin::InputSystem* inputSystem); //! this filters an OIS specific input virtual int EventFilter(const OIS::MouseEvent* me); //! this filters an OIS specific input virtual int EventFilter(const OIS::MouseEvent* me, bool pressed, OIS::MouseButtonID id); virtual void Capture(); /** This method os called for buffered input from OIS. mouseMoved is inherited from OIS Mouselistener baseclass. */ bool mouseMoved(const OIS::MouseEvent &e); /** This method os called for buffered input from OIS. mousePressed is inherited from OIS Mouselistener baseclass. */ bool mousePressed( const OIS::MouseEvent &e, OIS::MouseButtonID id ); /** This method os called for buffered input from OIS. mouseReleased is inherited from OIS Mouselistener baseclass. */ bool mouseReleased( const OIS::MouseEvent &e, OIS::MouseButtonID id ); protected: //! the OIS mouse device boost::shared_ptr<OIS::Mouse> mMouse; //! flag if we want to emulate dragging by using the middle mouse button bool mEmulateDrag; //! if we emulate dragging: flag if we currently drag or not bool mDragMode; }; DECLARE_CLASS(MouseOIS); #endif //MOUSEOIS_H__ --- NEW FILE: inputsystemois.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: inputsystemois.h,v 1.1.2.1 2007/07/24 01:13:16 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. InputSystemOIS HISTORY: 16/03/07 - OO - Initial version */ #ifndef INPUTSYSTEMOIS_H__ #define INPUTSYSTEMOIS_H__ #include "timerois.h" #include <deque> #include <kerosin/inputserver/inputsystem.h> #include <kerosin/inputserver/inputserver.h> #include <kerosin/openglserver/openglserver.h> namespace OIS { class InputManager; class EventArg; } class InputSystemOIS : public kerosin::InputSystem { // // functions // public: InputSystemOIS(); virtual ~InputSystemOIS(); virtual bool Init(kerosin::InputServer* inputServer); virtual bool CreateDevice(const std::string& deviceName); void Capture(); //! add the input to the queue virtual void AddInput(const kerosin::Input::Input& input); //! retrieve an input from the queue virtual bool GetInput(kerosin::Input::Input& input); //! get a pointer to the OIS input manager OIS::InputManager* GetInputManager(); protected: virtual bool UpdateTimerInput(kerosin::Input& input); private: boost::shared_ptr<kerosin::OpenGLServer> mOpenGLServer; boost::shared_ptr<TimerOIS> mTimer; OIS::InputManager* mOIS; }; DECLARE_CLASS(InputSystemOIS); #endif //INPUTSYSTEMOIS_H__ --- NEW FILE: timerois_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Wed May 9 2007 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: timerois_c.cpp,v 1.1.2.1 2007/07/24 01:13:16 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "timerois.h" void CLASS(TimerOIS)::DefineClass() { DEFINE_BASECLASS(InputDeviceOIS); } --- NEW FILE: inputsystemois_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: inputsystemois_c.cpp,v 1.1.2.1 2007/07/24 01:13:16 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "inputsystemois.h" void CLASS(InputSystemOIS)::DefineClass() { DEFINE_BASECLASS(kerosin/InputSystem); } --- NEW FILE: Makefile.am --- if BUILD_KEROSIN pkglib_LTLIBRARIES = inputois.la endif inputois_la_SOURCES = \ inputsystemois.cpp \ inputsystemois.h \ inputsystemois_c.cpp \ inputdeviceois.h \ inputdeviceois_c.cpp \ keyboardois.cpp \ keyboardois.h \ keyboardois_c.cpp \ export.cpp mouseois.cpp mouseois.h mouseois_c.cpp \ timerois.cpp \ timerois.h \ timerois_c.cpp # -module tells automake we're not building a library but a loadable module # so we don't need the "lib" prefix in the module name inputois_la_LDFLAGS = -module -avoid-version libois.a AM_CPPFLAGS = -I${top_srcdir}/lib @RUBY_CPPFLAGS@ -I/Users/fruit/Code/ogrenew/Dependencies/include --- NEW FILE: timerois.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Wed May 9 2007 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2007 RoboCup Soccer Server 3D Maintenance Group $Id: timerois.cpp,v 1.1.2.1 2007/07/24 01:13:16 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "timerois.h" #include <zeitgeist/logserver/logserver.h> using namespace kerosin; TimerOIS::TimerOIS() { mLastTimeVal.tv_sec = 0; mLastTimeVal.tv_usec = 0; } TimerOIS::~TimerOIS() { } bool TimerOIS::Init(kerosin::InputSystem* inputSystem) { if (InputDevice::Init(inputSystem) == false) { return false; } gettimeofday(&mLastTimeVal,0); return true; } int TimerOIS::EventFilter(const OIS::EventArg* event) { return 1; } void TimerOIS::GetInput(Input& input) { input.mType = Input::eAxis; input.mCode = Input::IC_AXIST; timeval tv; gettimeofday(&tv,0); unsigned int ticks = TimevalSubtract(&tv,&mLastTimeVal); input.mData.l = ticks; mLastTimeVal = tv; } unsigned long int TimerOIS::TimevalSubtract(const timeval* x, const timeval* z) const { timeval y,result; y.tv_usec = z->tv_usec; y.tv_sec = z->tv_sec; // Perform the carry for the later subtraction by updating y. if (x->tv_usec < y.tv_usec) { int nsec = (y.tv_usec - x->tv_usec) / 1000000 + 1; y.tv_usec -= 1000000 * nsec; y.tv_sec += nsec; } if (x->tv_usec - y.tv_usec > 1000000) { int nsec = (x->tv_usec - y.tv_usec) / 1000000; y.tv_usec += 1000000 * nsec; y.tv_sec -= nsec; } /* Compute the time remaining to wait. tv_usec is certainly positive. */ result.tv_sec = x->tv_sec - y.tv_sec; result.tv_usec = x->tv_usec - y.tv_usec; /* Return 0 if result is negative. */ if (x->tv_sec < y.tv_sec) { std::cerr << "(TimerOIS) went negative\n"; return 0; } else { return (1000000 * result.tv_sec + result.tv_usec) / 1000.0; } } --- NEW FILE: mouseois.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: mouseois.cpp,v 1.1.2.1 2007/07/24 01:13:16 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "mouseois.h" #include "inputsystemois.h" #include <kerosin/inputserver/inputserver.h> #include <zeitgeist/logserver/logserver.h> using namespace kerosin; using namespace OIS; MouseOIS::MouseOIS() : mEmulateDrag(true), mDragMode(false) { } MouseOIS::~MouseOIS() { } bool MouseOIS::Init(kerosin::InputSystem* inputSystem) { InputSystemOIS* iois = dynamic_cast<InputSystemOIS*>(inputSystem); if (iois == 0) { GetLog()->Error() << "(MouseOIS) should be used with InputSystemOIS only\n"; return false; } OIS::InputManager* im = iois->GetInputManager(); mMouse = boost::shared_ptr<OIS::Mouse> (static_cast<OIS::Mouse*>(im->createInputObject(OIS::OISMouse, true))); mMouse.get()->setEventCallback(this); return InputDevice::Init(inputSystem); } int MouseOIS::EventFilter(const OIS::MouseEvent* me) { Input input(Input::eAxis,Input::IC_AXISX); if (me->state.X.rel != 0) { input.mData.l = me->state.X.rel; mInputSystem->AddInputInternal(input); } if (me->state.Y.rel != 0) { input.mCode = Input::IC_AXISY; input.mData.l = me->state.Y.rel; mInputSystem->AddInputInternal(input); } return 0; } int MouseOIS::EventFilter(const OIS::MouseEvent* me, bool pressed, OIS::MouseButtonID id) { Input input(Input::eButton); if (id == MB_Left) input.mCode = Input::IC_MOUSE_LEFT; else if (id == MB_Middle) { if (mEmulateDrag) { if (!pressed) { mDragMode = !mDragMode; input.mCode = Input::IC_MOUSE_LEFT; pressed = mDragMode; std::cerr << "Switched drag mode (" << pressed << ")\n"; } else return 0; } else input.mCode = Input::IC_MOUSE_MIDDLE; } else if (id == MB_Right) input.mCode = Input::IC_MOUSE_RIGHT; else return 0; input.mData.l = pressed; mInputSystem->AddInputInternal(input); return 0; } void MouseOIS::Capture() { if (mMouse.get() != 0) { mMouse->capture(); } } bool MouseOIS::mouseMoved(const OIS::MouseEvent& e) { return (EventFilter(&e) == 0); } bool MouseOIS::mousePressed(const OIS::MouseEvent& e, OIS::MouseButtonID id) { std::cerr << "mousePressed\n"; return (EventFilter(&e,true,id) == 0); } bool MouseOIS::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id) { std::cerr << "mouseReleased\n"; return (EventFilter(&e,false,id) == 0); } --- NEW FILE: mouseois_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: mouseois_c.cpp,v 1.1.2.1 2007/07/24 01:13:16 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "mouseois.h" void CLASS(MouseOIS)::DefineClass() { DEFINE_BASECLASS(InputDeviceOIS); } --- NEW FILE: export.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: export.cpp,v 1.1.2.1 2007/07/24 01:13:16 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "inputsystemois.h" #include "inputdeviceois.h" #include "keyboardois.h" #include "mouseois.h" #include "timerois.h" #include <zeitgeist/zeitgeist.h> ZEITGEIST_EXPORT_BEGIN() ZEITGEIST_EXPORT(InputSystemOIS); ZEITGEIST_EXPORT(InputDeviceOIS); ZEITGEIST_EXPORT(KeyboardOIS); ZEITGEIST_EXPORT(MouseOIS); ZEITGEIST_EXPORT(TimerOIS); ZEITGEIST_EXPORT_END() |
From: Oliver O. <fr...@us...> - 2007-07-24 01:07:27
|
Update of /cvsroot/simspark/simspark/spark/utility/ois/SDL In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv15613/SDL Added Files: Tag: projectx .cvsignore Log Message: --- NEW FILE: .cvsignore --- *.la *.lo .deps .libs Makefile Makefile.in |
From: Oliver O. <fr...@us...> - 2007-07-24 01:07:26
|
Update of /cvsroot/simspark/simspark/spark/utility/ois/mac In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv15613/mac Added Files: Tag: projectx .cvsignore Log Message: --- NEW FILE: .cvsignore --- *.la *.lo .deps .dirstamp .libs Makefile Makefile.in |
From: Oliver O. <fr...@us...> - 2007-07-24 01:07:26
|
Update of /cvsroot/simspark/simspark/spark/utility/ois/linux In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv15613/linux Added Files: Tag: projectx .cvsignore Log Message: --- NEW FILE: .cvsignore --- *.la *.lo .deps .libs Makefile Makefile.in |
From: Oliver O. <fr...@us...> - 2007-07-24 01:07:26
|
Update of /cvsroot/simspark/simspark/spark/utility/ois/win32 In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv15613/win32 Added Files: Tag: projectx .cvsignore Log Message: --- NEW FILE: .cvsignore --- *.la *.lo .deps .libs Makefile Makefile.in |
From: Oliver O. <fr...@us...> - 2007-07-24 01:07:26
|
Update of /cvsroot/simspark/simspark/spark/utility/ois In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv15613 Added Files: Tag: projectx .cvsignore Log Message: --- NEW FILE: .cvsignore --- *.la *.lo .deps .libs Makefile Makefile.in |
From: Oliver O. <fr...@us...> - 2007-07-24 01:00:42
|
Update of /cvsroot/simspark/simspark/spark/utility/ois/mac In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv13856/mac Added Files: Tag: projectx MacHelpers.cpp MacHelpers.h MacInputManager.cpp MacInputManager.h MacKeyboard.cpp MacKeyboard.h MacMouse.cpp MacMouse.h MacPrereqs.h Log Message: added OIS Library sources --- NEW FILE: MacHelpers.h --- /* The zlib/libpng License Copyright (c) 2006 Chris Snyder This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_MacHelpers_H #define OIS_MacHelpers_H #include "mac/MacPrereqs.h" #include "OISEvents.h" #include "OISKeyboard.h" #include "OISMouse.h" #include <Carbon/Carbon.h> // This is a hack needed to get the event handler working. // The carbon lib expects a "OSStatus (*)(EventHandlerCallRef, EventRef, void*)", // so I cannot give it a class member function (unless it is static which is pointless) // Instead, I just pass the class* through the last paramter that gets passed to the // callback every time an event occurs. Then I dereference it and call the member function. OSStatus KeyDownWrapper( EventHandlerCallRef nextHandler, EventRef theEvent, void* callClass ); OSStatus KeyUpWrapper( EventHandlerCallRef nextHandler, EventRef theEvent, void* callClass ); OSStatus KeyModWrapper( EventHandlerCallRef nextHandler, EventRef theEvent, void* callClass ); OSStatus MouseMoveWrapper( EventHandlerCallRef nextHandler, EventRef theEvent, void* callClass ); OSStatus MouseButtonWrapper( EventHandlerCallRef nextHandler, EventRef theEvent, void* callClass ); OSStatus MouseScrollWrapper( EventHandlerCallRef nextHandler, EventRef theEvent, void* callClass ); // This is needed for keeping an event stack for keyboard and mouse namespace OIS { // used in the eventStack to store the type enum Mac_EventType { MAC_KEYUP = 0, MAC_KEYDOWN = 1, MAC_KEYREPEAT, MAC_MOUSEDOWN, MAC_MOUSEUP, MAC_MOUSEMOVED, MAC_MOUSESCROLL}; typedef enum Mac_EventType MacEventType; // only used by MacKeyboard typedef class Mac_KeyStackEvent { friend class MacKeyboard; private: Mac_KeyStackEvent( KeyEvent event, MacEventType type ) : Event(event), Type(type) {} MacEventType Type; KeyEvent Event; } MacKeyStackEvent; // only used by MacMouse typedef class Mac_MouseStackEvent { friend class MacMouse; private: Mac_MouseStackEvent( MacEventType type, unsigned int time ) : Type(type), Time(time) {} unsigned int Time; MacEventType Type; MouseButtonID button; Axis axis; } MacMouseStackEvent; } #endif --- NEW FILE: MacInputManager.h --- /* The zlib/libpng License Copyright (c) 2006 Chris Snyder This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_MacInputManager_H #define OIS_MacInputManager_H #include "OISInputManager.h" #include "mac/MacPrereqs.h" #include <Carbon/Carbon.h> namespace OIS { class MacInputManager : public InputManager { public: MacInputManager(); virtual ~MacInputManager(); virtual const std::string& inputSystemName() { return iName; } virtual int numJoysticks(); virtual int numMice(); virtual int numKeyBoards(); Object* createInputObject( Type iType, bool bufferMode ); void destroyInputObject( Object* obj ); // method for getting window WindowRef _getWindow() {return window;} protected: void _initialize( ParamList& paramList ); void _parseConfigSettings( ParamList& paramList ); void _enumerateDevices(); static const std::string iName; // Mac stuff WindowRef window; // settings bool hideMouse; bool useRepeat; }; } #endif --- NEW FILE: MacKeyboard.cpp --- /* The zlib/libpng License Copyright (c) 2006 Chris Snyder This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "mac/MacKeyboard.h" #include "mac/MacInputManager.h" #include "mac/MacHelpers.h" #include "OISException.h" #include "OISEvents.h" #include <Carbon/Carbon.h> #include <list> #include <string> //#include <iostream> //using namespace std; using namespace OIS; //-------------------------------------------------------------------// MacKeyboard::MacKeyboard( InputManager* creator, bool buffered, bool repeat ) { mCreator = creator; keyDownEventRef = NULL; keyUpEventRef = NULL; keyModEventRef = NULL; mBuffered = buffered; useRepeat = repeat; // Get a so-called "Univeral procedure pointer" for our callback keyDownUPP = NewEventHandlerUPP( KeyDownWrapper ); keyUpUPP = NewEventHandlerUPP( KeyUpWrapper ); keyModUPP = NewEventHandlerUPP( KeyModWrapper ); // populate the conversion map populateKeyConversion(); } //-------------------------------------------------------------------// MacKeyboard::~MacKeyboard() { // Remove our handlers so that this instance doesn't get called // after it is deleted if ( keyDownEventRef != NULL ) RemoveEventHandler( keyDownEventRef ); if ( keyUpEventRef != NULL ) RemoveEventHandler( keyUpEventRef ); if ( keyModEventRef != NULL ) RemoveEventHandler( keyUpEventRef ); // dispose of our UPPs DisposeEventHandlerUPP( keyDownUPP ); DisposeEventHandlerUPP( keyUpUPP ); DisposeEventHandlerUPP( keyModUPP ); } //-------------------------------------------------------------------// void MacKeyboard::_initialize() { OSStatus status; WindowRef window = ( (MacInputManager*)mCreator)->_getWindow(); memset( &KeyBuffer, 0, 256 ); mModifiers = 0; prevModMask = 0; // just in case this gets called after the first time.. better safe if ( keyDownEventRef != NULL ) RemoveEventHandler( keyDownEventRef ); if ( keyUpEventRef != NULL ) RemoveEventHandler( keyUpEventRef ); if ( keyModEventRef != NULL ) RemoveEventHandler( keyUpEventRef ); keyDownEventRef = NULL; keyUpEventRef = NULL; keyModEventRef = NULL; EventTypeSpec DownSpec[2]; EventTypeSpec UpSpec, ModSpec, RepeatSpec; // Set the type of events we wish to handle DownSpec[0].eventClass = kEventClassKeyboard; DownSpec[0].eventKind = kEventRawKeyDown; DownSpec[1].eventClass = kEventClassKeyboard; DownSpec[1].eventKind = kEventRawKeyRepeat; UpSpec.eventClass = kEventClassKeyboard; UpSpec.eventKind = kEventRawKeyUp; // Separate events for modifiers change, because they aren't reported normally ModSpec.eventClass = kEventClassKeyboard; ModSpec.eventKind = kEventRawKeyModifiersChanged; if ( useRepeat ) { // send both elements of downspec array... second index is for repeat events status = InstallWindowEventHandler( window, keyDownUPP, 2, DownSpec, this, &keyDownEventRef ); } else { status = InstallWindowEventHandler( window, keyDownUPP, 1, DownSpec, this, &keyDownEventRef ); } if ( status != noErr ) { OIS_EXCEPT( E_General, "MacKeyboard::_initialize >> Error loading KeyDown event handler" ); } status = InstallWindowEventHandler( window, keyUpUPP, 1, &UpSpec, this, &keyUpEventRef ); if ( status != noErr ) { OIS_EXCEPT( E_General, "MacKeyboard::_initialize >> Error loading KeyUp event handler" ); } status = InstallWindowEventHandler( window, keyModUPP, 1, &ModSpec, this, &keyModEventRef ); if ( status != noErr ) { OIS_EXCEPT( E_General, "MacKeyboard::_initialize >> Error loading Keymods event handler" ); } } //-------------------------------------------------------------------// bool MacKeyboard::isKeyDown( KeyCode key ) { return (bool)KeyBuffer[key]; } //-------------------------------------------------------------------// void MacKeyboard::capture() { // if not buffered just return, we update the unbuffered automatically if ( !mBuffered || !listener ) return; // run through our event stack eventStack::iterator cur_it; for (cur_it = pendingEvents.begin(); cur_it != pendingEvents.end(); cur_it++) { if ( (*cur_it).Type == MAC_KEYDOWN || (*cur_it).Type == MAC_KEYREPEAT) { listener->keyPressed( (*cur_it).Event ); } else if ( (*cur_it).Type == MAC_KEYUP ) { listener->keyReleased( (*cur_it).Event ); } } pendingEvents.clear(); } //-------------------------------------------------------------------// std::string& MacKeyboard::getAsString( KeyCode key ) { getString = ""; return getString; } //-------------------------------------------------------------------// void MacKeyboard::setBuffered( bool buffered ) { mBuffered = buffered; } //-------------------------------------------------------------------// void MacKeyboard::_keyDownCallback( EventRef theEvent ) { UInt32 virtualKey; OSStatus status; unsigned int time = (unsigned int)GetEventTime(theEvent); status = GetEventParameter( theEvent, 'kcod', // get it in virtual keycode typeUInt32, NULL, // desired return type sizeof(UInt32), NULL, // bufsize &virtualKey ); KeyCode kc = keyConversion[virtualKey]; // record what kind of text we should pass the KeyEvent UniChar text[10]; char macChar; // TODO clean this up if (mTextMode == Unicode) { //get string size UInt32 stringsize; status = GetEventParameter( theEvent, 'kuni', typeUnicodeText, NULL, 0, &stringsize, NULL); //cout << "String length: " << stringsize << endl; status = GetEventParameter( theEvent, 'kuni', typeUnicodeText, NULL, sizeof(UniChar)*10, NULL, &text ); //wstring unitext; //for (int i=0;i<10;i++) unitext += (wchar_t)text[i]; //wcout << "Unicode out: " << unitext << endl; // for each unicode char, send an event stringsize--; // no termination char for ( int i = 0; i < stringsize; i++ ) { injectEvent( kc, time, MAC_KEYDOWN, (unsigned int)text[i] ); } } else if (mTextMode == Ascii) { status = GetEventParameter( theEvent, 'kchr', typeChar, NULL, sizeof(char), NULL, &macChar ); injectEvent( kc, time, MAC_KEYDOWN, (unsigned int)macChar ); } else { injectEvent( kc, time, MAC_KEYDOWN ); } } //-------------------------------------------------------------------// void MacKeyboard::_keyUpCallback( EventRef theEvent ) { UInt32 virtualKey; OSStatus status; status = GetEventParameter( theEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &virtualKey ); KeyCode kc = keyConversion[virtualKey]; injectEvent( kc, (int)GetEventTime(theEvent), MAC_KEYUP ); } //-------------------------------------------------------------------// void MacKeyboard::_modChangeCallback( EventRef theEvent ) { UInt32 mods; OSStatus status; status = GetEventParameter( theEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &mods ); // find the changed bit UInt32 change = prevModMask ^ mods; MacEventType newstate = ((change & prevModMask) > 0) ? MAC_KEYUP : MAC_KEYDOWN; unsigned int time = (int)GetEventTime( theEvent ); //cout << "preMask: " << hex << prevModMask << endl; //cout << "ModMask: " << hex << mods << endl; //cout << "Change: " << hex << (change & prevModMask) << endl << endl; // TODO test modifiers on a full keyboard to check if different mask for left/right switch (change) { case (shiftKey): // shift mModifiers &= (newstate == MAC_KEYDOWN) ? Shift : ~Shift; injectEvent( KC_LSHIFT, time, newstate ); //injectEvent( KC_RSHIFT, time, newstate ); break; case (optionKey): // option (alt) mModifiers &= (newstate == MAC_KEYDOWN) ? Alt : -Alt; //injectEvent( KC_RMENU, time, newstate ); injectEvent( KC_LMENU, time, newstate ); break; case (controlKey): // Ctrl mModifiers += (newstate == MAC_KEYDOWN) ? Ctrl : -Ctrl; //injectEvent( KC_RCONTROL, time, newstate ); injectEvent( KC_LCONTROL, time, newstate ); break; case (cmdKey): // apple //injectEvent( KC_RWIN, time, newstate ); injectEvent( KC_LWIN, time, newstate ); break; case (kEventKeyModifierFnMask): // fn key injectEvent( KC_APPS, time, newstate ); break; case (kEventKeyModifierNumLockMask): // numlock injectEvent( KC_NUMLOCK, time, newstate ); break; case (alphaLock): // caps lock injectEvent( KC_CAPITAL, time, newstate ); break; } prevModMask = mods; } //-------------------------------------------------------------------// void MacKeyboard::injectEvent( KeyCode kc, unsigned int time, MacEventType type, unsigned int txt ) { // set to 1 if this is either a keydown or repeat KeyBuffer[kc] = ( type == MAC_KEYUP ) ? 0 : 1; if ( mBuffered && listener ) { pendingEvents.push_back( MacKeyStackEvent( KeyEvent(this, kc, txt), type) ); } } //-------------------------------------------------------------------// void MacKeyboard::copyKeyStates( char keys[256] ) { memcpy( keys, KeyBuffer, 256 ); } //-------------------------------------------------------------------// void MacKeyboard::populateKeyConversion() { // TODO finish the key mapping // Virtual Key Map to KeyCode keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x12, KC_1)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x13, KC_2)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x14, KC_3)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x15, KC_4)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x17, KC_5)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x16, KC_6)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x1A, KC_7)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x1C, KC_8)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x19, KC_9)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x1D, KC_0)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x33, KC_BACK)); // might be wrong keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x1B, KC_MINUS)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x18, KC_EQUALS)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x31, KC_SPACE)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x2B, KC_COMMA)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x2F, KC_PERIOD)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x2A, KC_BACKSLASH)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x2C, KC_SLASH)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x21, KC_LBRACKET)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x1E, KC_RBRACKET)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x35, KC_ESCAPE)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x39, KC_CAPITAL)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x30, KC_TAB)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x24, KC_RETURN)); // double check return/enter //keyConversion.insert(VirtualtoOIS_KeyMap::value_type(XK_colon, KC_COLON)); // no colon? keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x29, KC_SEMICOLON)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x27, KC_APOSTROPHE)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x32, KC_GRAVE)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x0B, KC_B)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x00, KC_A)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x08, KC_C)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x02, KC_D)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x0E, KC_E)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x03, KC_F)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x05, KC_G)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x04, KC_H)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x22, KC_I)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x26, KC_J)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x28, KC_K)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x25, KC_L)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x2E, KC_M)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x2D, KC_N)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x1F, KC_O)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x23, KC_P)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x0C, KC_Q)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x0F, KC_R)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x01, KC_S)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x11, KC_T)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x20, KC_U)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x09, KC_V)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x0D, KC_W)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x07, KC_X)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x10, KC_Y)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x06, KC_Z)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x7A, KC_F1)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x78, KC_F2)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x63, KC_F3)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x76, KC_F4)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x60, KC_F5)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x61, KC_F6)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x62, KC_F7)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x64, KC_F8)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x65, KC_F9)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x6D, KC_F10)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x67, KC_F11)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x6F, KC_F12)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x69, KC_F13)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x6B, KC_F14)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x71, KC_F15)); //Keypad keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x52, KC_NUMPAD0)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x53, KC_NUMPAD1)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x54, KC_NUMPAD2)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x55, KC_NUMPAD3)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x56, KC_NUMPAD4)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x57, KC_NUMPAD5)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x58, KC_NUMPAD6)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x59, KC_NUMPAD7)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x5B, KC_NUMPAD8)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x5C, KC_NUMPAD9)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x45, KC_ADD)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x4E, KC_SUBTRACT)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x41, KC_DECIMAL)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x51, KC_NUMPADEQUALS)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x4B, KC_DIVIDE)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x43, KC_MULTIPLY)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x4C, KC_NUMPADENTER)); //Keypad with numlock off //keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x73, KC_NUMPAD7)); // not sure of these //keyConversion.insert(VirtualtoOIS_KeyMap::value_type(XK_KP_Up, KC_NUMPAD8)); // check on a non-laptop //keyConversion.insert(VirtualtoOIS_KeyMap::value_type(XK_KP_Page_Up, KC_NUMPAD9)); //keyConversion.insert(VirtualtoOIS_KeyMap::value_type(XK_KP_Left, KC_NUMPAD4)); //keyConversion.insert(VirtualtoOIS_KeyMap::value_type(XK_KP_Begin, KC_NUMPAD5)); //keyConversion.insert(VirtualtoOIS_KeyMap::value_type(XK_KP_Right, KC_NUMPAD6)); //keyConversion.insert(VirtualtoOIS_KeyMap::value_type(XK_KP_End, KC_NUMPAD1)); //keyConversion.insert(VirtualtoOIS_KeyMap::value_type(XK_KP_Down, KC_NUMPAD2)); //keyConversion.insert(VirtualtoOIS_KeyMap::value_type(XK_KP_Page_Down, KC_NUMPAD3)); //keyConversion.insert(VirtualtoOIS_KeyMap::value_type(XK_KP_Insert, KC_NUMPAD0)); //keyConversion.insert(VirtualtoOIS_KeyMap::value_type(XK_KP_Delete, KC_DECIMAL)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x7E, KC_UP)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x7D, KC_DOWN)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x7B, KC_LEFT)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x7C, KC_RIGHT)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x74, KC_PGUP)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x79, KC_PGDOWN)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x73, KC_HOME)); keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x77, KC_END)); //keyConversion.insert(VirtualtoOIS_KeyMap::value_type(XK_Print, KC_SYSRQ)); // ?? //keyConversion.insert(VirtualtoOIS_KeyMap::value_type(XK_Scroll_Lock, KC_SCROLL)); // ?? //keyConversion.insert(VirtualtoOIS_KeyMap::value_type(XK_Pause, KC_PAUSE)); // ?? //keyConversion.insert(VirtualtoOIS_KeyMap::value_type(XK_Insert, KC_INSERT)); // ?? keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x75, KC_DELETE)); // del under help key? } --- NEW FILE: MacKeyboard.h --- /* The zlib/libpng License Copyright (c) 2006 Chris Snyder This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_MacKeyboard_H #define OIS_MacKeyboard_H #include "OISKeyboard.h" #include "mac/MacHelpers.h" #include "mac/MacPrereqs.h" #include <Carbon/Carbon.h> namespace OIS { class MacKeyboard : public Keyboard { public: MacKeyboard( InputManager* creator, bool buffered, bool repeat ); virtual ~MacKeyboard(); // Sets buffered mode virtual void setBuffered( bool buffered ); // unbuffered keydown check virtual bool isKeyDown( KeyCode key ); // This will send listener events if buffered is on. // Note that in the mac implementation, unbuffered input is // automatically updated without calling this. virtual void capture(); // Copies the current key buffer virtual void copyKeyStates( char keys[256] ); // Returns a description of the given key virtual std::string& getAsString( KeyCode key ); virtual Interface* queryInterface( Interface::IType type ) { return 0; } // Public but reserved for internal use: virtual void _initialize(); void _keyDownCallback( EventRef theEvent ); void _keyUpCallback( EventRef theEvent ); void _modChangeCallback( EventRef theEvent ); protected: // just to get this out of the way void populateKeyConversion(); // updates the keybuffer and optionally the eventStack void injectEvent(KeyCode kc, unsigned int time, MacEventType type, unsigned int txt = 0 ); typedef std::map<UInt32, KeyCode> VirtualtoOIS_KeyMap; VirtualtoOIS_KeyMap keyConversion; std::string getString; char KeyBuffer[256]; UInt32 prevModMask; // "universal procedure pointers" - required reference for callbacks EventHandlerUPP keyDownUPP; EventHandlerUPP keyUpUPP; EventHandlerUPP keyModUPP; // so we can delete the handlers on destruction EventHandlerRef keyDownEventRef; EventHandlerRef keyUpEventRef; EventHandlerRef keyModEventRef; // buffered events, fifo stack typedef std::list<MacKeyStackEvent> eventStack; eventStack pendingEvents; bool useRepeat; }; } #endif --- NEW FILE: MacInputManager.cpp --- /* The zlib/libpng License Copyright (c) 2006 Chris Snyder This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "mac/MacInputManager.h" #include "mac/MacKeyboard.h" #include "mac/MacMouse.h" #include "OISException.h" #include <Carbon/Carbon.h> #include <string> //#include <iostream> //using namespace std; using namespace OIS; const std::string MacInputManager::iName = "Mac OSX Input Manager"; //--------------------------------------------------------------------------------// MacInputManager::MacInputManager() { hideMouse = true; useRepeat = false; } //--------------------------------------------------------------------------------// MacInputManager::~MacInputManager() { } //--------------------------------------------------------------------------------// void MacInputManager::_initialize( ParamList ¶mList ) { _parseConfigSettings( paramList ); //Enumerate all devices attached _enumerateDevices(); } //--------------------------------------------------------------------------------// void MacInputManager::_parseConfigSettings( ParamList ¶mList ) { ParamList::iterator i = paramList.find("WINDOW"); if( i != paramList.end() ) { //TODO 64 bit proof this little conversion xxx wip window = (WindowRef) strtoul(i->second.c_str(), 0, 10); } // else get the main active window.. user might not have access to it through some // graphics libraries. else { window = ActiveNonFloatingWindow(); } // Keyboard i = paramList.find("MacAutoRepeatOn"); if ( i != paramList.end() ) { if ( i->second == "true" ) { useRepeat = true; } } } //--------------------------------------------------------------------------------// void MacInputManager::_enumerateDevices() { } //--------------------------------------------------------------------------------// int MacInputManager::numJoysticks() { return 0; } //--------------------------------------------------------------------------------// int MacInputManager::numMice() { return 1; } //--------------------------------------------------------------------------------// int MacInputManager::numKeyBoards() { return 1; } //----------------------------------------------------------------------------// Object* MacInputManager::createInputObject( Type iType, bool bufferMode ) { Object* obj = 0; switch( iType ) { case OISKeyboard: obj = new MacKeyboard(this, bufferMode, useRepeat); break; case OISMouse: obj = new MacMouse(this, bufferMode ); break; case OISJoyStick: return obj; break; default: return obj; break; } //Seperate initialization from construction.. as bad things happen when //throwing exceptions from constructors try { obj->_initialize(); } catch(...) { delete obj; throw; //rethrow the exception } return obj; } //----------------------------------------------------------------------------// void MacInputManager::destroyInputObject( Object* obj ) { if( obj ) { delete obj; } } --- NEW FILE: MacHelpers.cpp --- /* The zlib/libpng License Copyright (c) 2006 Chris Snyder This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "mac/MacHelpers.h" #include "mac/MacKeyboard.h" #include "mac/MacMouse.h" #include "OISException.h" #include <Carbon/Carbon.h> using namespace OIS; //-------------------------------------------------------------------// OSStatus KeyDownWrapper( EventHandlerCallRef nextHandler, EventRef theEvent, void* callClass ) { // TODO find a better way. This cast isn't very safe if (callClass != NULL) { ((MacKeyboard*)callClass)->_keyDownCallback( theEvent ); // propagate the event down the chain return CallNextEventHandler( nextHandler, theEvent ); } else { OIS_EXCEPT(E_General, "KeyDownWrapper >> Being called by something other than our event handler!"); return noErr; } } //-------------------------------------------------------------------// OSStatus KeyUpWrapper( EventHandlerCallRef nextHandler, EventRef theEvent, void* callClass ) { if (callClass != NULL) { ((MacKeyboard*)callClass)->_keyUpCallback( theEvent ); // propagate the event down the chain return CallNextEventHandler( nextHandler, theEvent ); } else { OIS_EXCEPT(E_General, "KeyUpWrapper >> Being called by something other than our event handler!"); return noErr; } } //-------------------------------------------------------------------// OSStatus KeyModWrapper( EventHandlerCallRef nextHandler, EventRef theEvent, void* callClass ) { if (callClass != NULL) { ((MacKeyboard*)callClass)->_modChangeCallback( theEvent ); // propagate the event down the chain return CallNextEventHandler( nextHandler, theEvent ); } else { OIS_EXCEPT(E_General, "KeyModWrapper >> Being called by something other than our event handler!"); return noErr; } } //-------------------------------------------------------------------// OSStatus MouseMoveWrapper( EventHandlerCallRef nextHandler, EventRef theEvent, void* callClass ) { if (callClass != NULL) { ((MacMouse*)callClass)->_mouseMoveCallback( theEvent ); // propagate the event down the chain return CallNextEventHandler( nextHandler, theEvent ); } else { OIS_EXCEPT(E_General, "MouseMoveWrapper >> Being called by something other than our event handler!"); return noErr; } } //-------------------------------------------------------------------// OSStatus MouseScrollWrapper( EventHandlerCallRef nextHandler, EventRef theEvent, void* callClass ) { if (callClass != NULL) { ((MacMouse*)callClass)->_mouseScrollCallback( theEvent ); // propagate the event down the chain return CallNextEventHandler( nextHandler, theEvent ); } else { OIS_EXCEPT(E_General, "MouseScrollWrapper >> Being called by something other than our event handler!"); return noErr; } } //-------------------------------------------------------------------// OSStatus MouseButtonWrapper( EventHandlerCallRef nextHandler, EventRef theEvent, void* callClass ) { if (callClass != NULL) { ((MacMouse*)callClass)->_mouseButtonCallback( theEvent ); // propagate the event down the chain return CallNextEventHandler( nextHandler, theEvent ); } else { OIS_EXCEPT(E_General, "MouseButtonWrapper >> Being called by something other than our event handler!"); return noErr; } } --- NEW FILE: MacPrereqs.h --- /* The zlib/libpng License Copyright (c) 2006 Chris Snyder This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_MacPrereqs_H #define OIS_MacPrereqs_H #include <string> #include <list> namespace OIS { class MacInputManager; class MacKeyboard; } #endif --- NEW FILE: MacMouse.h --- #ifndef OIS_MacMouse_H #define OIS_MacMouse_H #include "OISMouse.h" #include "mac/MacHelpers.h" #include "mac/MacPrereqs.h" #include <Carbon/Carbon.h> namespace OIS { class MacMouse : public Mouse { public: MacMouse( InputManager* creator, bool buffered ); virtual ~MacMouse(); /** @copydoc Object::setBuffered */ virtual void setBuffered(bool buffered); /** @copydoc Object::capture */ virtual void capture(); /** @copydoc Object::queryInterface */ virtual Interface* queryInterface(Interface::IType type) {return 0;} /** @copydoc Object::_initialize */ virtual void _initialize(); public: void _mouseButtonCallback( EventRef theEvent ); void _mouseMoveCallback( EventRef theEvent ); void _mouseScrollCallback( EventRef theEvent ); protected: MacMouse() {} // "universal procedure pointers" - required reference for callbacks EventHandlerUPP mouseButtonUPP; EventHandlerUPP mouseMoveUPP; EventHandlerUPP mouseScrollUPP; // so we can delete the handlers on destruction EventHandlerRef mouseButtonEventRef; EventHandlerRef mouseMoveEventRef; EventHandlerRef mouseScrollEventRef; bool mRegainFocus; }; } #endif // OIS_MacMouse_H --- NEW FILE: MacMouse.cpp --- #include "mac/MacMouse.h" #include "mac/MacInputManager.h" #include "mac/MacHelpers.h" #include "OISException.h" #include "OISEvents.h" #include <Carbon/Carbon.h> #include <list> #include <string> using namespace OIS; //-------------------------------------------------------------------// MacMouse::MacMouse( InputManager* creator, bool buffered ) : mRegainFocus( false ) { mCreator = creator; mouseButtonEventRef = NULL; mouseMoveEventRef = NULL; mouseScrollEventRef = NULL; mBuffered = buffered; mType = OISMouse; listener = 0; mouseButtonUPP = NewEventHandlerUPP( MouseButtonWrapper ); mouseMoveUPP = NewEventHandlerUPP( MouseMoveWrapper ); mouseScrollUPP = NewEventHandlerUPP( MouseScrollWrapper ); } MacMouse::~MacMouse() { if( mouseButtonEventRef != NULL ) RemoveEventHandler( mouseButtonEventRef ); if( mouseMoveEventRef != NULL ) RemoveEventHandler( mouseMoveEventRef ); if( mouseScrollEventRef != NULL ) RemoveEventHandler( mouseScrollEventRef ); DisposeEventHandlerUPP( mouseButtonUPP ); DisposeEventHandlerUPP( mouseMoveUPP ); DisposeEventHandlerUPP( mouseScrollUPP ); } void MacMouse::_initialize() { mState.clear(); mRegainFocus = false; OSStatus status; WindowRef window = (( MacInputManager* )mCreator)->_getWindow(); if( mouseButtonEventRef != NULL ) RemoveEventHandler( mouseButtonEventRef ); if( mouseMoveEventRef != NULL ) RemoveEventHandler( mouseMoveEventRef ); if( mouseScrollEventRef != NULL ) RemoveEventHandler( mouseScrollEventRef ); mouseButtonEventRef = NULL; mouseMoveEventRef = NULL; mouseScrollEventRef = NULL; const EventTypeSpec mouseButtonEvents[] = { { kEventClassMouse, kEventMouseDown }, { kEventClassMouse, kEventMouseUp } }; const EventTypeSpec mouseMoveEvents[] = { { kEventClassMouse, kEventMouseMoved } }; const EventTypeSpec mouseScrollEvents[] = { { kEventClassMouse, kEventMouseWheelMoved } }; status = InstallWindowEventHandler( window, mouseButtonUPP, GetEventTypeCount( mouseButtonEvents ), mouseButtonEvents, this, &mouseButtonEventRef ); if( status != noErr ) { OIS_EXCEPT( E_General, "MacMouse::_initialize >> Error loading MouseButton event handler" ); } status = InstallWindowEventHandler( window, mouseMoveUPP, GetEventTypeCount( mouseMoveEvents ), mouseMoveEvents, this, &mouseMoveEventRef ); if( status != noErr ) { OIS_EXCEPT( E_General, "MacMouse::_initialize >> Error loading MouseMove event handler" ); } status = InstallWindowEventHandler( window, mouseScrollUPP, GetEventTypeCount( mouseScrollEvents ), mouseScrollEvents, this, &mouseScrollEventRef ); if( status != noErr ) { OIS_EXCEPT( E_General, "MacMouse::_initialize >> Error loading MouseScroll event handler" ); } } void MacMouse::setBuffered( bool buffered ) { mBuffered = buffered; } void MacMouse::capture() { if( !mBuffered ) return; // eventStack::iterator cur_it; } void MacMouse::_mouseButtonCallback( EventRef theEvent ) { } void MacMouse::_mouseMoveCallback( EventRef theEvent ) { } void MacMouse::_mouseScrollCallback( EventRef theEvent ) { } |
From: Oliver O. <fr...@us...> - 2007-07-24 01:00:42
|
Update of /cvsroot/simspark/simspark/spark/utility/ois/win32 In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv13856/win32 Added Files: Tag: projectx Win32ForceFeedback.cpp Win32ForceFeedback.h Win32InputManager.cpp Win32InputManager.h Win32JoyStick.cpp Win32JoyStick.h Win32KeyBoard.cpp Win32KeyBoard.h Win32Mouse.cpp Win32Mouse.h Win32Prereqs.h Log Message: added OIS Library sources --- NEW FILE: Win32InputManager.cpp --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "Win32/Win32InputManager.h" #include "Win32/Win32Keyboard.h" #include "Win32/Win32Mouse.h" #include "Win32/Win32JoyStick.h" #include "OISException.h" using namespace OIS; const std::string Win32InputManager::iName = "Win32"; //--------------------------------------------------------------------------------// Win32InputManager::Win32InputManager() { hWnd = 0; mDirectInput = 0; kbSettings = 0; mouseSettings = 0; joySettings = 0; joySticks = 0; } //--------------------------------------------------------------------------------// Win32InputManager::~Win32InputManager() { if( mDirectInput ) { mDirectInput->Release(); mDirectInput = 0; } } //--------------------------------------------------------------------------------// void Win32InputManager::_initialize( ParamList ¶mList ) { HINSTANCE hInst = 0; HRESULT hr; //TODO 64 bit proof this little conversion xxx wip //First of all, get the Windows Handle and Instance ParamList::iterator i = paramList.find("WINDOW"); if( i == paramList.end() ) OIS_EXCEPT( E_InvalidParam, "Win32InputManager::Win32InputManager >> No HWND found!" ); hWnd = (HWND)strtoul(i->second.c_str(), 0, 10); if( IsWindow(hWnd) == 0 ) OIS_EXCEPT( E_General, "Win32InputManager::Win32InputManager >> The sent HWND is not valid!"); hInst = GetModuleHandle(0); //Create the device hr = DirectInput8Create( hInst, DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&mDirectInput, NULL ); if (FAILED(hr)) OIS_EXCEPT( E_General, "Win32InputManager::Win32InputManager >> Not able to init DirectX8 Input!"); //Ok, now we have DirectInput, parse whatever extra settings were sent to us _parseConfigSettings( paramList ); _enumerateDevices(); } //--------------------------------------------------------------------------------// void Win32InputManager::_parseConfigSettings( ParamList ¶mList ) { //Here we pick up settings such as a device's cooperation mode std::map<std::string, DWORD> temp; temp["DISCL_BACKGROUND"] = DISCL_BACKGROUND; temp["DISCL_EXCLUSIVE"] = DISCL_EXCLUSIVE; temp["DISCL_FOREGROUND"] = DISCL_FOREGROUND; temp["DISCL_NONEXCLUSIVE"] = DISCL_NONEXCLUSIVE; temp["DISCL_NOWINKEY"] = DISCL_NOWINKEY; //Check for pairs: ie. ("w32_keyboard","DISCL_NOWINKEY")("w32_keyboard","DISCL_FOREGROUND") ParamList::iterator i = paramList.begin(), e = paramList.end(); for( ; i != e; ++i ) { if( i->first == "w32_keyboard" ) kbSettings |= temp[i->second]; else if( i->first == "w32_mouse" ) mouseSettings |= temp[i->second]; else if( i->first == "w32_joystick" ) joySettings |= temp[i->second]; } if( kbSettings == 0 ) kbSettings = DISCL_FOREGROUND | DISCL_NONEXCLUSIVE | DISCL_NOWINKEY; if( mouseSettings == 0 ) mouseSettings = DISCL_FOREGROUND | DISCL_EXCLUSIVE; if( joySettings == 0 ) joySettings = DISCL_FOREGROUND | DISCL_EXCLUSIVE; } //--------------------------------------------------------------------------------// void Win32InputManager::_enumerateDevices() { //Enumerate all attached devices mDirectInput->EnumDevices(NULL, _DIEnumKbdCallback, this, DIEDFL_ATTACHEDONLY); } //--------------------------------------------------------------------------------// BOOL CALLBACK Win32InputManager::_DIEnumKbdCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef) { Win32InputManager *_this_ = static_cast<Win32InputManager*>(pvRef); if( GET_DIDEVICE_TYPE(lpddi->dwDevType) == DI8DEVTYPE_JOYSTICK || GET_DIDEVICE_TYPE(lpddi->dwDevType) == DI8DEVTYPE_GAMEPAD || GET_DIDEVICE_TYPE(lpddi->dwDevType) == DI8DEVTYPE_1STPERSON || GET_DIDEVICE_TYPE(lpddi->dwDevType) == DI8DEVTYPE_DRIVING || GET_DIDEVICE_TYPE(lpddi->dwDevType) == DI8DEVTYPE_FLIGHT) { JoyStickInfo jsInfo; jsInfo.deviceID = lpddi->guidInstance; jsInfo.vendor = lpddi->tszInstanceName; jsInfo.devId = _this_->joySticks; _this_->joySticks++; _this_->unusedJoyStickList.push_back( jsInfo ); } return DIENUM_CONTINUE; } //--------------------------------------------------------------------------------// int Win32InputManager::numJoysticks() { return joySticks; } //--------------------------------------------------------------------------------// int Win32InputManager::numMice() { return 1; } //--------------------------------------------------------------------------------// int Win32InputManager::numKeyBoards() { return 1; } //----------------------------------------------------------------------------// Object* Win32InputManager::createInputObject( Type iType, bool bufferMode ) { Object* obj = 0; switch( iType ) { case OISKeyboard: obj = new Win32Keyboard( this, mDirectInput, bufferMode, kbSettings ); break; case OISMouse: obj = new Win32Mouse( this, mDirectInput, bufferMode, mouseSettings ); break; case OISJoyStick: { //Find a JoyStick not in use JoyStickInfoList::iterator i = unusedJoyStickList.begin(); if( i != unusedJoyStickList.end() ) { obj = new Win32JoyStick( this, mDirectInput, bufferMode, joySettings, (*i) ); unusedJoyStickList.erase(i); break; } OIS_EXCEPT(E_InputDeviceNonExistant, "No Unused JoyStick could be found!"); } default: OIS_EXCEPT( E_InputDeviceNotSupported, "Type not implemented"); } try { obj->_initialize(); } catch(...) { delete obj; throw; //rethrow } return obj; } //----------------------------------------------------------------------------// void Win32InputManager::destroyInputObject( Object* obj ) { if( obj == 0 ) return; //If it was a numbered device... add it back to availiable list if( obj->type() == OISJoyStick ) { unusedJoyStickList.push_back(((Win32JoyStick*)obj)->_getJoyInfo()); } delete obj; } --- NEW FILE: Win32JoyStick.cpp --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "Win32/Win32JoyStick.h" #include "Win32/Win32InputManager.h" #include "Win32/Win32ForceFeedback.h" #include "OISEvents.h" #include "OISException.h" #include <cassert> using namespace OIS; //--------------------------------------------------------------------------------------------------// Win32JoyStick::Win32JoyStick( InputManager* creator, IDirectInput8* pDI, bool buffered, DWORD coopSettings, const JoyStickInfo &info ) { mCreator = creator; mBuffered = buffered; mDirectInput = pDI; coopSetting = coopSettings; mJoyStick = 0; mType = OISJoyStick; deviceGuid = info.deviceID; mVendor = info.vendor; mDevID = info.devId; listener = 0; ff_device = 0; } //--------------------------------------------------------------------------------------------------// Win32JoyStick::~Win32JoyStick() { delete ff_device; if(mJoyStick) { mJoyStick->Unacquire(); mJoyStick->Release(); mJoyStick = 0; } } //--------------------------------------------------------------------------------------------------// void Win32JoyStick::_initialize() { //Clear old state mState.mAxes.clear(); delete ff_device; ff_device = 0; DIPROPDWORD dipdw; dipdw.diph.dwSize = sizeof(DIPROPDWORD); dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); dipdw.diph.dwObj = 0; dipdw.diph.dwHow = DIPH_DEVICE; dipdw.dwData = JOYSTICK_DX_BUFFERSIZE; if(FAILED(mDirectInput->CreateDevice(deviceGuid, &mJoyStick, NULL))) OIS_EXCEPT( E_General, "Win32JoyStick::_initialize() >> Could not initialize joy device!"); if(FAILED(mJoyStick->SetDataFormat(&c_dfDIJoystick2))) OIS_EXCEPT( E_General, "Win32JoyStick::_initialize() >> data format error!"); HWND hwin = ((Win32InputManager*)mCreator)->getWindowHandle(); if(FAILED(mJoyStick->SetCooperativeLevel( hwin, coopSetting))) OIS_EXCEPT( E_General, "Win32JoyStick::_initialize() >> failed to set cooperation level!"); if( FAILED(mJoyStick->SetProperty(DIPROP_BUFFERSIZE, &dipdw.diph)) ) OIS_EXCEPT( E_General, "Win32Mouse::Win32Mouse >> Failed to set buffer size property" ); //Enumerate all axes/buttons/sliders/etc before aquiring _enumerate(); mState.clear(); capture(); } //--------------------------------------------------------------------------------------------------// void Win32JoyStick::_enumerate() { //We can check force feedback here too DIDEVCAPS DIJoyCaps; DIJoyCaps.dwSize = sizeof(DIDEVCAPS); mJoyStick->GetCapabilities(&DIJoyCaps); numAxes = (short)DIJoyCaps.dwAxes; numButtons = (short)DIJoyCaps.dwButtons; numHats = (short)DIJoyCaps.dwPOVs; mState.mAxes.resize(numAxes); //Reset the axis mapping enumeration value _AxisNumber = 0; //Enumerate Force Feedback (if any) mJoyStick->EnumEffects(DIEnumEffectsCallback, this, DIEFT_ALL); //Enumerate and set axis constraints (and check FF Axes) mJoyStick->EnumObjects(DIEnumDeviceObjectsCallback, this, DIDFT_AXIS); } //--------------------------------------------------------------------------------------------------// BOOL CALLBACK Win32JoyStick::DIEnumDeviceObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef) { Win32JoyStick* _this = (Win32JoyStick*)pvRef; //Setup mappings DIPROPPOINTER diptr; diptr.diph.dwSize = sizeof(DIPROPPOINTER); diptr.diph.dwHeaderSize = sizeof(DIPROPHEADER); diptr.diph.dwHow = DIPH_BYID; diptr.diph.dwObj = lpddoi->dwType; //Add the high bit in so that an axis value of zero does not mean a null userdata diptr.uData = 0x80000000 | _this->_AxisNumber++; if (FAILED(_this->mJoyStick->SetProperty(DIPROP_APPDATA, &diptr.diph))) OIS_EXCEPT( E_General, "Win32JoyStick::_DIEnumDeviceObjectsCallback >> Failed to set mapping ptr property" ); //Set range DIPROPRANGE diprg; diprg.diph.dwSize = sizeof(DIPROPRANGE); diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER); diprg.diph.dwHow = DIPH_BYID; diprg.diph.dwObj = lpddoi->dwType; diprg.lMin = MIN_AXIS; diprg.lMax = MAX_AXIS; if (FAILED(_this->mJoyStick->SetProperty(DIPROP_RANGE, &diprg.diph))) OIS_EXCEPT( E_General, "Win32JoyStick::_DIEnumDeviceObjectsCallback >> Failed to set min/max range property" ); //Check if FF Axes if((lpddoi->dwFlags & DIDOI_FFACTUATOR) != 0 ) { assert( _this->ff_device && "Force Feedback axis found, but this device did not report any effects?"); if( _this->ff_device ) { //todo - increment force feedback axis count } } return DIENUM_CONTINUE; } //--------------------------------------------------------------------------------------------------// BOOL CALLBACK Win32JoyStick::DIEnumEffectsCallback(LPCDIEFFECTINFO pdei, LPVOID pvRef) { Win32JoyStick* _this = (Win32JoyStick*)pvRef; //Create the FF class after we know there is at least one effect type if( _this->ff_device == 0 ) _this->ff_device = new Win32ForceFeedback(_this->mJoyStick); _this->ff_device->_addEffectSupport( pdei ); return DIENUM_CONTINUE; } //--------------------------------------------------------------------------------------------------// void Win32JoyStick::capture() { DIDEVICEOBJECTDATA diBuff[JOYSTICK_DX_BUFFERSIZE]; DWORD entries = JOYSTICK_DX_BUFFERSIZE; // Poll the device to read the current state HRESULT hr = mJoyStick->Poll(); if( hr == DI_OK ) hr = mJoyStick->GetDeviceData( sizeof(DIDEVICEOBJECTDATA), diBuff, &entries, 0 ); if( hr != DI_OK ) { hr = mJoyStick->Acquire(); while( hr == DIERR_INPUTLOST ) hr = mJoyStick->Acquire(); // Poll the device to read the current state mJoyStick->Poll(); hr = mJoyStick->GetDeviceData( sizeof(DIDEVICEOBJECTDATA), diBuff, &entries, 0 ); //Perhaps the user just tabbed away if( FAILED(hr) ) return; } bool axisMoved[24] = {false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false, false,false,false,false,false,false,false,false}; bool sliderMoved[4] = {false,false,false,false}; //Loop through all the events for(unsigned int i = 0; i < entries; ++i) { //First check to see if event entry is a Axis we enumerated earlier if( diBuff[i].uAppData != 0xFFFFFFFF && diBuff[i].uAppData > 0 ) { int axis = 0x7FFFFFFF & diBuff[i].uAppData; //Mask out the high bit assert( axis >= 0 && axis < mState.mAxes.size() && "Axis out of range!"); mState.mAxes[axis].abs = diBuff[i].dwData; axisMoved[axis] = true; } else { //DX Only defines macros for the JOYSTICK not JOYSTICK2, so we redeclare them to match what we are using #undef DIJOFS_BUTTON #undef DIJOFS_POV #define DIJOFS_BUTTON(n) (FIELD_OFFSET(DIJOYSTATE2, rgbButtons) + (n)) #define DIJOFS_POV(n) (FIELD_OFFSET(DIJOYSTATE2, rgdwPOV)+(n)*sizeof(DWORD)) #define DIJOFS_SLIDER0(n) (FIELD_OFFSET(DIJOYSTATE2, rglSlider)+(n) * sizeof(LONG)) #define DIJOFS_SLIDER1(n) (FIELD_OFFSET(DIJOYSTATE2, rglVSlider)+(n) * sizeof(LONG)) #define DIJOFS_SLIDER2(n) (FIELD_OFFSET(DIJOYSTATE2, rglASlider)+(n) * sizeof(LONG)) #define DIJOFS_SLIDER3(n) (FIELD_OFFSET(DIJOYSTATE2, rglFSlider)+(n) * sizeof(LONG)) //This may seem outof order, but is in order of the way these variables //are declared in the JoyStick State 2 structure. switch(diBuff[i].dwOfs) { //------ slider -// case DIJOFS_SLIDER0(0): sliderMoved[0] = true; mState.mSliders[0].abX = diBuff[i].dwData; break; case DIJOFS_SLIDER0(1): sliderMoved[0] = true; mState.mSliders[0].abY = diBuff[i].dwData; break; //----- Max 4 POVs Next ---------------// case DIJOFS_POV(0): if(!_changePOV(0,diBuff[i])) return; break; case DIJOFS_POV(1): if(!_changePOV(1,diBuff[i])) return; break; case DIJOFS_POV(2): if(!_changePOV(2,diBuff[i])) return; break; case DIJOFS_POV(3): if(!_changePOV(3,diBuff[i])) return; break; case DIJOFS_SLIDER1(0): sliderMoved[1] = true; mState.mSliders[1].abX = diBuff[i].dwData; break; case DIJOFS_SLIDER1(1): sliderMoved[1] = true; mState.mSliders[1].abY = diBuff[i].dwData; break; case DIJOFS_SLIDER2(0): sliderMoved[2] = true; mState.mSliders[2].abX = diBuff[i].dwData; break; case DIJOFS_SLIDER2(1): sliderMoved[2] = true; mState.mSliders[2].abY = diBuff[i].dwData; break; case DIJOFS_SLIDER3(0): sliderMoved[3] = true; mState.mSliders[3].abX = diBuff[i].dwData; break; case DIJOFS_SLIDER3(1): sliderMoved[3] = true; mState.mSliders[3].abY = diBuff[i].dwData; break; //-----------------------------------------// default: //Handle Button Events Easily using the DX Offset Macros if( diBuff[i].dwOfs >= DIJOFS_BUTTON(0) && diBuff[i].dwOfs <= DIJOFS_BUTTON(30) ) { if(!_doButtonClick((diBuff[i].dwOfs - DIJOFS_BUTTON(0)), diBuff[i])) return; } break; } //end case } //End else } //end for //Check to see if any of the axes values have changed.. if so send events if( mBuffered && listener && entries > 0 ) { JoyStickEvent temp(this, mState); //Update axes for( int i = 0; i < 24; ++i ) if( axisMoved[i] ) if( listener->axisMoved( temp, i ) == false ) return; //Now update sliders for( int i = 0; i < 4; ++i ) if( sliderMoved[i] ) if( listener->sliderMoved( temp, i ) == false ) return; } } //--------------------------------------------------------------------------------------------------// bool Win32JoyStick::_doButtonClick( int button, DIDEVICEOBJECTDATA& di ) { if( di.dwData & 0x80 ) { mState.buttons |= 1 << button; //turn the bit flag on if( mBuffered && listener ) return listener->buttonPressed( JoyStickEvent( this, mState ), button ); } else { mState.buttons &= ~(1 << button); //turn the bit flag off if( mBuffered && listener ) return listener->buttonReleased( JoyStickEvent( this, mState ), button ); } return true; } //--------------------------------------------------------------------------------------------------// bool Win32JoyStick::_changePOV( int pov, DIDEVICEOBJECTDATA& di ) { //Some drivers report a value of 65,535, instead of 1, //for the center position if(LOWORD(di.dwData) == 0xFFFF) { mState.mPOV[pov].direction = Pov::Centered; } else { switch(di.dwData) { case 0: mState.mPOV[pov].direction = Pov::North; break; case 4500: mState.mPOV[pov].direction = Pov::NorthEast; break; case 9000: mState.mPOV[pov].direction = Pov::East; break; case 13500: mState.mPOV[pov].direction = Pov::SouthEast; break; case 18000: mState.mPOV[pov].direction = Pov::South; break; case 22500: mState.mPOV[pov].direction = Pov::SouthWest; break; case 27000: mState.mPOV[pov].direction = Pov::West; break; case 31500: mState.mPOV[pov].direction = Pov::NorthWest; break; } } if( mBuffered && listener ) return listener->povMoved( JoyStickEvent( this, mState ), pov ); return true; } //--------------------------------------------------------------------------------------------------// void Win32JoyStick::setBuffered(bool buffered) { mBuffered = buffered; } //--------------------------------------------------------------------------------------------------// JoyStickInfo Win32JoyStick::_getJoyInfo() { JoyStickInfo js; js.deviceID = deviceGuid; js.devId = mDevID; js.vendor = mVendor; return js; } //--------------------------------------------------------------------------------------------------// Interface* Win32JoyStick::queryInterface(Interface::IType type) { //Thought about using covariant return type here.. however, //some devices may allow LED light changing, or other interface stuff if( ff_device && type == Interface::ForceFeedback ) return ff_device; else return 0; } --- NEW FILE: Win32ForceFeedback.cpp --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "Win32/Win32ForceFeedback.h" #include "OISException.h" #include <Math.h> #if defined (_DEBUG) #include <sstream> #endif using namespace OIS; //--------------------------------------------------------------// Win32ForceFeedback::Win32ForceFeedback(IDirectInputDevice8* joy) : mHandles(0), mJoyStick(joy) { } //--------------------------------------------------------------// Win32ForceFeedback::~Win32ForceFeedback() { //Get the effect - if it exists for(EffectList::iterator i = mEffectList.begin(); i != mEffectList.end(); ++i ) { LPDIRECTINPUTEFFECT dxEffect = i->second; if( dxEffect ) dxEffect->Unload(); } mEffectList.clear(); } //--------------------------------------------------------------// void Win32ForceFeedback::upload( const Effect* effect ) { switch( effect->force ) { case OIS::Effect::ConstantForce: _updateConstantEffect(effect); break; case OIS::Effect::RampForce: _updateRampEffect(effect); break; case OIS::Effect::PeriodicForce: _updatePeriodicEffect(effect); break; case OIS::Effect::ConditionalForce: _updateConditionalEffect(effect); break; //case OIS::Effect::CustomForce: _updateCustomEffect(effect); break; default: OIS_EXCEPT(E_NotImplemented, "Requested Force not Implemented yet, sorry!"); break; } } //--------------------------------------------------------------// void Win32ForceFeedback::modify( const Effect* eff ) { //Modifying is essentially the same as an upload, so, just reuse that function upload(eff); } //--------------------------------------------------------------// void Win32ForceFeedback::remove( const Effect* eff ) { //Get the effect - if it exists EffectList::iterator i = mEffectList.find(eff->_handle); if( i != mEffectList.end() ) { LPDIRECTINPUTEFFECT dxEffect = i->second; if( dxEffect ) { dxEffect->Stop(); //We care about the return value - as the effect might not //have been unlaoded if( SUCCEEDED(dxEffect->Unload()) ) mEffectList.erase(i); } else mEffectList.erase(i); } } //--------------------------------------------------------------// void Win32ForceFeedback::setMasterGain( float level ) { //Between 0 - 10,000 int gain_level = (int)(10000.0f * level); if( gain_level > 10000 ) gain_level = 10000; else if( gain_level < 0 ) gain_level = 0; DIPROPDWORD DIPropGain; DIPropGain.diph.dwSize = sizeof(DIPropGain); DIPropGain.diph.dwHeaderSize = sizeof(DIPROPHEADER); DIPropGain.diph.dwObj = 0; DIPropGain.diph.dwHow = DIPH_DEVICE; DIPropGain.dwData = gain_level; mJoyStick->SetProperty(DIPROP_FFGAIN, &DIPropGain.diph); } //--------------------------------------------------------------// void Win32ForceFeedback::setAutoCenterMode( bool auto_on ) { //DI Property DIPROPAUTOCENTER_OFF = 0, 1 is on DIPROPDWORD DIPropAutoCenter; DIPropAutoCenter.diph.dwSize = sizeof(DIPropAutoCenter); DIPropAutoCenter.diph.dwHeaderSize = sizeof(DIPROPHEADER); DIPropAutoCenter.diph.dwObj = 0; DIPropAutoCenter.diph.dwHow = DIPH_DEVICE; DIPropAutoCenter.dwData = auto_on; //hr = mJoyStick->SetProperty(DIPROP_AUTOCENTER, &DIPropAutoCenter.diph); } //--------------------------------------------------------------// void Win32ForceFeedback::_updateConstantEffect( const Effect* effect ) { DWORD rgdwAxes[2] = { DIJOFS_X, DIJOFS_Y }; LONG rglDirection[2] = { 0, 0 }; DICONSTANTFORCE cf; DIEFFECT diEffect; //Currently only support 1 axis //if( effect->getNumAxes() == 1 ) cf.lMagnitude = static_cast<ConstantEffect*>(effect->getForceEffect())->level; _setCommonProperties(&diEffect, rgdwAxes, rglDirection, sizeof(DICONSTANTFORCE), &cf, effect); _upload(GUID_ConstantForce, &diEffect, effect); } //--------------------------------------------------------------// void Win32ForceFeedback::_updateRampEffect( const Effect* effect ) { DWORD rgdwAxes[2] = { DIJOFS_X, DIJOFS_Y }; LONG rglDirection[2] = { 0, 0 }; DIRAMPFORCE rf; DIEFFECT diEffect; //Currently only support 1 axis rf.lStart = static_cast<RampEffect*>(effect->getForceEffect())->startLevel; rf.lEnd = static_cast<RampEffect*>(effect->getForceEffect())->endLevel; _setCommonProperties(&diEffect, rgdwAxes, rglDirection, sizeof(DIRAMPFORCE), &rf, effect); _upload(GUID_RampForce, &diEffect, effect); } //--------------------------------------------------------------// void Win32ForceFeedback::_updatePeriodicEffect( const Effect* effect ) { DWORD rgdwAxes[2] = { DIJOFS_X, DIJOFS_Y }; LONG rglDirection[2] = { 0, 0 }; DIPERIODIC pf; DIEFFECT diEffect; //Currently only support 1 axis pf.dwMagnitude = static_cast<PeriodicEffect*>(effect->getForceEffect())->magnitude; pf.lOffset = static_cast<PeriodicEffect*>(effect->getForceEffect())->offset; pf.dwPhase = static_cast<PeriodicEffect*>(effect->getForceEffect())->phase; pf.dwPeriod = static_cast<PeriodicEffect*>(effect->getForceEffect())->period; _setCommonProperties(&diEffect, rgdwAxes, rglDirection, sizeof(DIPERIODIC), &pf, effect); switch( effect->type ) { case OIS::Effect::Square: _upload(GUID_Square, &diEffect, effect); break; case OIS::Effect::Triangle: _upload(GUID_Triangle, &diEffect, effect); break; case OIS::Effect::Sine: _upload(GUID_Sine, &diEffect, effect); break; case OIS::Effect::SawToothUp: _upload(GUID_SawtoothUp, &diEffect, effect); break; case OIS::Effect::SawToothDown: _upload(GUID_SawtoothDown, &diEffect, effect); break; default: break; } } //--------------------------------------------------------------// void Win32ForceFeedback::_updateConditionalEffect( const Effect* effect ) { DWORD rgdwAxes[2] = { DIJOFS_X, DIJOFS_Y }; LONG rglDirection[2] = { 0, 0 }; DICONDITION cf; DIEFFECT diEffect; cf.lOffset = static_cast<ConditionalEffect*>(effect->getForceEffect())->deadband; cf.lPositiveCoefficient = static_cast<ConditionalEffect*>(effect->getForceEffect())->rightCoeff; cf.lNegativeCoefficient = static_cast<ConditionalEffect*>(effect->getForceEffect())->leftCoeff; cf.dwPositiveSaturation = static_cast<ConditionalEffect*>(effect->getForceEffect())->rightSaturation; cf.dwNegativeSaturation = static_cast<ConditionalEffect*>(effect->getForceEffect())->leftSaturation; cf.lDeadBand = static_cast<ConditionalEffect*>(effect->getForceEffect())->deadband; _setCommonProperties(&diEffect, rgdwAxes, rglDirection, sizeof(DICONDITION), &cf, effect); switch( effect->type ) { case OIS::Effect::Friction: _upload(GUID_Friction, &diEffect, effect); break; case OIS::Effect::Damper: _upload(GUID_Damper, &diEffect, effect); break; case OIS::Effect::Inertia: _upload(GUID_Inertia, &diEffect, effect); break; case OIS::Effect::Spring: _upload(GUID_Spring, &diEffect, effect); break; default: break; } } //--------------------------------------------------------------// void Win32ForceFeedback::_updateCustomEffect( const Effect* /*effect*/ ) { //DWORD rgdwAxes[2] = { DIJOFS_X, DIJOFS_Y }; //LONG rglDirection[2] = { 0, 0 }; //DICUSTOMFORCE cf; //DIEFFECT diEffect; //cf.cChannels = 0; //cf.dwSamplePeriod = 0; //cf.cSamples = 0; //cf.rglForceData = 0; //_setCommonProperties(&diEffect, rgdwAxes, rglDirection, sizeof(DICUSTOMFORCE), &cf, effect); //_upload(GUID_CustomForce, &diEffect, effect); } //--------------------------------------------------------------// void Win32ForceFeedback::_setCommonProperties( DIEFFECT* diEffect, DWORD* rgdwAxes, LONG* rglDirection, DWORD struct_size, LPVOID struct_type, const Effect* effect ) { ZeroMemory(diEffect, sizeof(DIEFFECT)); diEffect->dwSize = sizeof(DIEFFECT); diEffect->dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS; diEffect->dwDuration = effect->replay_length; diEffect->dwSamplePeriod = 0; diEffect->dwGain = DI_FFNOMINALMAX; diEffect->dwTriggerButton = DIEB_NOTRIGGER; diEffect->dwTriggerRepeatInterval = 0; diEffect->cAxes = effect->getNumAxes(); diEffect->rgdwAxes = rgdwAxes; diEffect->rglDirection = rglDirection; diEffect->lpEnvelope = 0; diEffect->cbTypeSpecificParams = struct_size; diEffect->lpvTypeSpecificParams = struct_type; diEffect->dwStartDelay = effect->replay_delay; } //--------------------------------------------------------------// void Win32ForceFeedback::_upload( GUID guid, DIEFFECT* diEffect, const Effect* effect) { LPDIRECTINPUTEFFECT dxEffect = 0; //Get the effect - if it exists EffectList::iterator i = mEffectList.find(effect->_handle); //It has been created already if( i != mEffectList.end() ) dxEffect = i->second; else //This effect has not yet been created - generate a handle effect->_handle = mHandles++; if( dxEffect == 0 ) { //This effect has not yet been created, so create it HRESULT hr = mJoyStick->CreateEffect(guid, diEffect, &dxEffect, NULL); if(SUCCEEDED(hr)) { mEffectList[effect->_handle] = dxEffect; dxEffect->Start(INFINITE,0); } else if( hr == DIERR_DEVICEFULL ) OIS_EXCEPT(E_DeviceFull, "Remove an effect before adding more!"); else OIS_EXCEPT(E_General, "Unknown error creating effect->.."); } else { //ToDo -- Update the Effect HRESULT hr = dxEffect->SetParameters( diEffect, DIEP_DIRECTION | DIEP_DURATION | DIEP_ENVELOPE | DIEP_STARTDELAY | DIEP_TRIGGERBUTTON | DIEP_TRIGGERREPEATINTERVAL | DIEP_TYPESPECIFICPARAMS | DIEP_START ); if(FAILED(hr)) OIS_EXCEPT(E_InvalidParam, "Error updating device!"); } } //--------------------------------------------------------------// void Win32ForceFeedback::_addEffectSupport( LPCDIEFFECTINFO pdei ) { //Determine what the effect is and how it corresponds to our OIS's Enums //We could save the GUIDs too, however, we will just use the predefined //ones later if( pdei->guid == GUID_ConstantForce ) _addEffectTypes((Effect::EForce)DIEFT_GETTYPE(pdei->dwEffType), Effect::Constant ); else if( pdei->guid == GUID_Triangle ) _addEffectTypes((Effect::EForce)DIEFT_GETTYPE(pdei->dwEffType), Effect::Triangle ); else if( pdei->guid == GUID_Spring ) _addEffectTypes((Effect::EForce)DIEFT_GETTYPE(pdei->dwEffType), Effect::Spring ); else if( pdei->guid == GUID_Friction ) _addEffectTypes((Effect::EForce)DIEFT_GETTYPE(pdei->dwEffType), Effect::Friction ); else if( pdei->guid == GUID_Square ) _addEffectTypes((Effect::EForce)DIEFT_GETTYPE(pdei->dwEffType), Effect::Square ); else if( pdei->guid == GUID_Sine ) _addEffectTypes((Effect::EForce)DIEFT_GETTYPE(pdei->dwEffType), Effect::Sine ); else if( pdei->guid == GUID_SawtoothUp ) _addEffectTypes((Effect::EForce)DIEFT_GETTYPE(pdei->dwEffType), Effect::SawToothUp ); else if( pdei->guid == GUID_SawtoothDown ) _addEffectTypes((Effect::EForce)DIEFT_GETTYPE(pdei->dwEffType), Effect::SawToothDown ); else if( pdei->guid == GUID_Damper ) _addEffectTypes((Effect::EForce)DIEFT_GETTYPE(pdei->dwEffType), Effect::Damper ); else if( pdei->guid == GUID_Inertia ) _addEffectTypes((Effect::EForce)DIEFT_GETTYPE(pdei->dwEffType), Effect::Inertia ); else if( pdei->guid == GUID_CustomForce ) _addEffectTypes((Effect::EForce)DIEFT_GETTYPE(pdei->dwEffType), Effect::Custom ); else if( pdei->guid == GUID_RampForce ) _addEffectTypes((Effect::EForce)DIEFT_GETTYPE(pdei->dwEffType), Effect::Ramp ); #if defined (_DEBUG) //Only care about this for Debugging Purposes //else //{ // std::ostringstream ss; // ss << "Win32ForceFeedback, DirectInput8 Effect not found. Reported as: " // << pdei->tszName; // OIS_EXCEPT( E_General, ss.str().c_str()); //} #endif } --- NEW FILE: Win32ForceFeedback.h --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_Win32ForceFeedBack_H #define OIS_Win32ForceFeedBack_H #include "OISPrereqs.h" #include "OISForceFeedback.h" #include "Win32/Win32Prereqs.h" namespace OIS { class Win32ForceFeedback : public ForceFeedback { Win32ForceFeedback() {} public: Win32ForceFeedback(IDirectInputDevice8* joy); ~Win32ForceFeedback(); /** @copydoc ForceFeedback::upload */ void upload( const Effect* effect ); /** @copydoc ForceFeedback::modify */ void modify( const Effect* effect ); /** @copydoc ForceFeedback::remove */ void remove( const Effect* effect ); /** @copydoc ForceFeedback::setMasterGain */ void setMasterGain( float level ); /** @copydoc ForceFeedback::setAutoCenterMode */ void setAutoCenterMode( bool auto_on ); /** @copydoc ForceFeedback::getFFAxesNumber xxx todo - Actually return correct number */ short getFFAxesNumber() {return 1;} /** @remarks Internal use.. Used during enumeration to build a list of a devices support effects. */ void _addEffectSupport( LPCDIEFFECTINFO pdei ); protected: //Specific Effect Settings void _updateConstantEffect( const Effect* effect ); void _updateRampEffect( const Effect* effect ); void _updatePeriodicEffect( const Effect* effect ); void _updateConditionalEffect( const Effect* effect ); void _updateCustomEffect( const Effect* effect ); //Sets the common properties to all effects void _setCommonProperties( DIEFFECT* diEffect, DWORD* rgdwAxes, LONG* rglDirection, DWORD struct_size, LPVOID struct_type, const Effect* effect ); //Actually do the upload void _upload( GUID, DIEFFECT*, const Effect* ); typedef std::map<int,LPDIRECTINPUTEFFECT> EffectList; EffectList mEffectList; //Simple unique handle creation - allows for upto 2+ million effects //during the lifetime of application. Hopefully, that is enough. int mHandles; IDirectInputDevice8* mJoyStick; }; } #endif //OIS_Win32ForceFeedBack_H --- NEW FILE: Win32Prereqs.h --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef _WIN32_INPUTSYSTEM_PREREQS_H #define _WIN32_INPUTSYSTEM_PREREQS_H //Some WIndows Defines #define WIN32_LEAN_AND_MEAN //Using DirectInput8 #define DIRECTINPUT_VERSION 0x0800 #include <windows.h> #include <dinput.h> //! Max number of elements to collect from buffered input #define KEYBOARD_DX_BUFFERSIZE 17 #define MOUSE_DX_BUFFERSIZE 64 #define JOYSTICK_DX_BUFFERSIZE 124 #if defined(OIS_MINGW_COMPILER) # undef FIELD_OFFSET # define FIELD_OFFSET offsetof #endif namespace OIS { class Win32InputManager; class Win32Keyboard; class Win32JoyStick; class Win32Mouse; class Win32ForceFeedback; struct JoyStickInfo { int devId; GUID deviceID; std::string vendor; }; typedef std::vector< JoyStickInfo > JoyStickInfoList; } #endif //_WIN32_INPUTSYSTEM_PREREQS_H --- NEW FILE: Win32InputManager.h --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_Win32InputManager_H #define OIS_Win32InputManager_H #include "OISInputManager.h" #include "Win32/Win32Prereqs.h" namespace OIS { /** "Win32" InputManager specialization - Using DirectInput8 */ class Win32InputManager : public InputManager { public: Win32InputManager(); virtual ~Win32InputManager(); /** @copydoc InputManager::inputSystemName */ virtual const std::string& inputSystemName() { return iName; } /** @copydoc InputManager::numJoysticks */ virtual int numJoysticks(); /** @copydoc InputManager::numMice */ virtual int numMice(); /** @copydoc InputManager::numKeyBoards */ virtual int numKeyBoards(); /** @copydoc InputManager::createInputObject */ Object* createInputObject( Type iType, bool bufferMode ); /** @copydoc InputManager::destroyInputObject */ void destroyInputObject( Object* obj ); //! Returns HWND needed by DirectInput Device Object HWND getWindowHandle() { return hWnd; } /** @copydoc InputManager::_initialize */ void _initialize( ParamList ¶mList ); protected: //! internal class method for dealing with param list void _parseConfigSettings( ParamList ¶mList ); //! internal class method for finding attached devices void _enumerateDevices(); static BOOL CALLBACK _DIEnumKbdCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef); JoyStickInfoList unusedJoyStickList; static const std::string iName; HWND hWnd; //Direct Input Interface IDirectInput8* mDirectInput; //Used for setting device properties - as read in from paramlist DWORD kbSettings; DWORD mouseSettings; DWORD joySettings; char joySticks; }; } #endif --- NEW FILE: Win32JoyStick.h --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef _WIN32_JOYSTICK_H_EADER_ #define _WIN32_JOYSTICK_H_EADER_ #include "OISJoyStick.h" #include "Win32/Win32Prereqs.h" namespace OIS { class Win32JoyStick : public JoyStick { public: Win32JoyStick( InputManager* creator, IDirectInput8* pDI, bool buffered, DWORD coopSettings, const JoyStickInfo &info ); virtual ~Win32JoyStick(); /** @copydoc Object::setBuffered */ virtual void setBuffered(bool buffered); /** @copydoc Object::capture */ virtual void capture(); /** @copydoc Object::queryInterface */ virtual Interface* queryInterface(Interface::IType type); /** @copydoc Object::_initialize */ virtual void _initialize(); /** @remarks For internal use only... Returns a strucure to the manager, to make the device availiable for use again */ JoyStickInfo _getJoyInfo(); protected: Win32JoyStick() {} //! Enumerates all things void _enumerate(); //! Enumerate axis callback static BOOL CALLBACK DIEnumDeviceObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef); //! Enumerate Force Feedback callback static BOOL CALLBACK DIEnumEffectsCallback(LPCDIEFFECTINFO pdei, LPVOID pvRef); bool _doButtonClick( int button, DIDEVICEOBJECTDATA& di ); bool _changePOV( int pov, DIDEVICEOBJECTDATA& di ); IDirectInput8* mDirectInput; IDirectInputDevice8* mJoyStick; DWORD coopSetting; GUID deviceGuid; //! A force feedback device Win32ForceFeedback* ff_device; //! Mapping int _AxisNumber; }; } #endif //_WIN32_JOYSTICK_H_EADER_ --- NEW FILE: Win32KeyBoard.h --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef _WIN32_KEYBOARD_H_EADER_ #define _WIN32_KEYBOARD_H_EADER_ #include "OISKeyboard.h" #include "Win32/Win32Prereqs.h" namespace OIS { class Win32Keyboard : public Keyboard { public: /** @remarks Constructor @param pDI Valid DirectInput8 Interface @param buffered True for buffered input mode @param coopSettings A combination of DI Flags (see DX Help for info on input device settings) */ Win32Keyboard( InputManager* creator, IDirectInput8* pDI, bool buffered, DWORD coopSettings ); virtual ~Win32Keyboard(); /** @copydoc Keyboard::isKeyDown */ virtual bool isKeyDown( KeyCode key ); /** @copydoc Keyboard::getAsString */ virtual const std::string& getAsString( KeyCode kc ); /** @copydoc Keyboard::copyKeyStates */ virtual void copyKeyStates( char keys[256] ); /** @copydoc Object::setBuffered */ virtual void setBuffered(bool buffered); /** @copydoc Object::capture */ virtual void capture(); /** @copydoc Object::queryInterface */ virtual Interface* queryInterface(Interface::IType type) {return 0;} /** @copydoc Object::_initialize */ virtual void _initialize(); protected: Win32Keyboard() {} void _readBuffered(); void _read(); IDirectInput8* mDirectInput; IDirectInputDevice8* mKeyboard; DWORD coopSetting; unsigned char KeyBuffer[256]; //! Internal method for translating KeyCodes to Text int _translateText( KeyCode kc ); //! Stored dead key from last translation WCHAR deadKey; //! used for getAsString std::string mGetString; }; } #endif //_WIN32_KEYBOARD_H_EADER_ --- NEW FILE: Win32Mouse.h --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef _WIN32_MOUSE_H_EADER_ #define _WIN32_MOUSE_H_EADER_ #include "OISMouse.h" #include "Win32/Win32Prereqs.h" namespace OIS { class Win32Mouse : public Mouse { public: Win32Mouse( InputManager* creator, IDirectInput8* pDI, bool buffered, DWORD coopSettings ); virtual ~Win32Mouse(); /** @copydoc Object::setBuffered */ virtual void setBuffered(bool buffered); /** @copydoc Object::capture */ virtual void capture(); /** @copydoc Object::queryInterface */ virtual Interface* queryInterface(Interface::IType type) {return 0;} /** @copydoc Object::_initialize */ virtual void _initialize(); protected: Win32Mouse() {} bool _doMouseClick( int mouseButton, DIDEVICEOBJECTDATA& di ); IDirectInput8* mDirectInput; IDirectInputDevice8* mMouse; DWORD coopSetting; HWND mHwnd; }; } #endif //_WIN32_MOUSE_H_EADER_ --- NEW FILE: Win32Mouse.cpp --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "Win32/Win32Mouse.h" #include "Win32/Win32InputManager.h" #include "OISException.h" #include "OISEvents.h" using namespace OIS; //--------------------------------------------------------------------------------------------------// Win32Mouse::Win32Mouse( InputManager* creator, IDirectInput8* pDI, bool buffered, DWORD coopSettings ) { mCreator = creator; mBuffered = buffered; mMouse = 0; mDirectInput = pDI; coopSetting = coopSettings; mType = OISMouse; listener = 0; mHwnd = 0; } //--------------------------------------------------------------------------------------------------// void Win32Mouse::_initialize() { DIPROPDWORD dipdw; //Clear old state mState.clear(); dipdw.diph.dwSize = sizeof(DIPROPDWORD); dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); dipdw.diph.dwObj = 0; dipdw.diph.dwHow = DIPH_DEVICE; dipdw.dwData = MOUSE_DX_BUFFERSIZE; if( FAILED(mDirectInput->CreateDevice(GUID_SysMouse, &mMouse, NULL)) ) OIS_EXCEPT( E_General, "Win32Mouse::Win32Mouse >> Failed to create device" ); if( FAILED(mMouse->SetDataFormat(&c_dfDIMouse2)) ) OIS_EXCEPT( E_General, "Win32Mouse::Win32Mouse >> Failed to set format" ); mHwnd = ((Win32InputManager*)mCreator)->getWindowHandle(); if( FAILED(mMouse->SetCooperativeLevel(mHwnd, coopSetting)) ) OIS_EXCEPT( E_General, "Win32Mouse::Win32Mouse >> Failed to set coop level" ); if( FAILED(mMouse->SetProperty(DIPROP_BUFFERSIZE, &dipdw.diph )) ) OIS_EXCEPT( E_General, "Win32Mouse::Win32Mouse >> Failed to set property" ); HRESULT hr = mMouse->Acquire(); if (FAILED(hr) && hr != DIERR_OTHERAPPHASPRIO) OIS_EXCEPT( E_General, "Win32Mouse::Win32Mouse >> Failed to aquire mouse!" ); } //--------------------------------------------------------------------------------------------------// Win32Mouse::~Win32Mouse() { if (mMouse) { mMouse->Unacquire(); mMouse->Release(); mMouse = 0; } } //--------------------------------------------------------------------------------------------------// void Win32Mouse::capture() { //Clear old relative values mState.X.rel = mState.Y.rel = mState.Z.rel = 0; DIDEVICEOBJECTDATA diBuff[MOUSE_DX_BUFFERSIZE]; DWORD entries = MOUSE_DX_BUFFERSIZE; HRESULT hr = mMouse->GetDeviceData( sizeof(DIDEVICEOBJECTDATA), diBuff, &entries, 0 ); if( hr != DI_OK ) { hr = mMouse->Acquire(); while( hr == DIERR_INPUTLOST ) hr = mMouse->Acquire(); hr = mMouse->GetDeviceData( sizeof(DIDEVICEOBJECTDATA), diBuff, &entries, 0 ); //Perhaps the user just tabbed away, and coop settings //are nonexclusive..so just ignore if( FAILED(hr) ) return; } bool axesMoved = false; //Accumulate all axis movements for one axesMove message.. //Buttons are fired off as they are found for(unsigned int i = 0; i < entries; ++i ) { switch( diBuff[i].dwOfs ) { case DIMOFS_BUTTON0: if(!_doMouseClick(0, diBuff[i])) return; break; case DIMOFS_BUTTON1: if(!_doMouseClick(1, diBuff[i])) return; break; case DIMOFS_BUTTON2: if(!_doMouseClick(2, diBuff[i])) return; break; case DIMOFS_BUTTON3: if(!_doMouseClick(3, diBuff[i])) return; break; case DIMOFS_BUTTON4: if(!_doMouseClick(4, diBuff[i])) return; break; case DIMOFS_BUTTON5: if(!_doMouseClick(5, diBuff[i])) return; break; case DIMOFS_BUTTON6: if(!_doMouseClick(6, diBuff[i])) return; break; case DIMOFS_BUTTON7: if(!_doMouseClick(7, diBuff[i])) return; break; case DIMOFS_X: mState.X.rel += diBuff[i].dwData; axesMoved = true; break; case DIMOFS_Y: mState.Y.rel += diBuff[i].dwData; axesMoved = true; break; case DIMOFS_Z: mState.Z.rel += diBuff[i].dwData; axesMoved = true; break; default: break; } //end switch }//end for if( axesMoved ) { if( coopSetting & DISCL_NONEXCLUSIVE ) { //DirectInput provides us with meaningless values, so correct that POINT point; GetCursorPos(&point); ScreenToClient(mHwnd, &point); mState.X.abs = point.x; mState.Y.abs = point.y; } else { mState.X.abs += mState.X.rel; mState.Y.abs += mState.Y.rel; } mState.Z.abs += mState.Z.rel; //Clip values to window if( mState.X.abs < 0 ) mState.X.abs = 0; else if( mState.X.abs > mState.width ) mState.X.abs = mState.width; if( mState.Y.abs < 0 ) mState.Y.abs = 0; else if( mState.Y.abs > mState.height ) mState.Y.abs = mState.height; //Do the move if( listener && mBuffered ) listener->mouseMoved( MouseEvent( this, mState ) ); } } //--------------------------------------------------------------------------------------------------// bool Win32Mouse::_doMouseClick( int mouseButton, DIDEVICEOBJECTDATA& di ) { if( di.dwData & 0x80 ) { mState.buttons |= 1 << mouseButton; //turn the bit flag on if( listener && mBuffered ) return listener->mousePressed( MouseEvent( this, mState ), (MouseButtonID)mouseButton ); } else { mState.buttons &= ~(1 << mouseButton); //turn the bit flag off if( listener && mBuffered ) return listener->mouseReleased( MouseEvent( this, mState ), (MouseButtonID)mouseButton ); } return true; } //--------------------------------------------------------------------------------------------------// void Win32Mouse::setBuffered(bool buffered) { mBuffered = buffered; } --- NEW FILE: Win32KeyBoard.cpp --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "Win32/Win32InputManager.h" #include "Win32/Win32KeyBoard.h" #include "OISException.h" #include "OISEvents.h" #include <sstream> using namespace OIS; //--------------------------------------------------------------------------------------------------// Win32Keyboard::Win32Keyboard( InputManager* creator, IDirectInput8* pDI, bool buffered, DWORD coopSettings ) { mCreator = creator; mBuffered = buffered; mKeyboard = 0; mDirectInput = pDI; coopSetting = coopSettings; mType = OISKeyboard; listener = 0; //Clear our keyboard state buffer memset( &KeyBuffer, 0, 256 ); deadKey = '\0'; } //--------------------------------------------------------------------------------------------------// void Win32Keyboard::_initialize() { mModifiers = 0; deadKey = '\0'; if(FAILED(mDirectInput->CreateDevice(GUID_SysKeyboard, &mKeyboard, NULL))) OIS_EXCEPT( E_General, "Win32Keyboard::Win32Keyboard >> Could not init device!"); if(FAILED(mKeyboard->SetDataFormat(&c_dfDIKeyboard))) OIS_EXCEPT( E_General, "Win32Keyboard::Win32Keyboard >> format error!"); HWND hwin = ((Win32InputManager*)mCreator)->getWindowHandle(); if(FAILED(mKeyboard->SetCooperativeLevel( hwin, coopSetting))) OIS_EXCEPT( E_General, "Win32Keyboard::Win32Keyboard >> coop error!"); if( mBuffered ) { DIPROPDWORD dipdw; dipdw.diph.dwSize = sizeof(DIPROPDWORD); dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); dipdw.diph.dwObj = 0; dipdw.diph.dwHow = DIPH_DEVICE; dipdw.dwData = KEYBOARD_DX_BUFFERSIZE; if (FAILED(mKeyboard->SetProperty( DIPROP_BUFFERSIZE, &dipdw.diph ))) OIS_EXCEPT( E_General, "Win32Keyboard::Win32Keyboard >> buffer error!"); } HRESULT hr = mKeyboard->Acquire(); if(FAILED(hr) && hr != DIERR_OTHERAPPHASPRIO) OIS_EXCEPT( E_General, "Win32Keyboard::Win32Keyboard >> aquire error!"); } //--------------------------------------------------------------------------------------------------// Win32Keyboard::~Win32Keyboard() { if(mKeyboard) { mKeyboard->Unacquire(); mKeyboard->Release(); mKeyboard = 0; } } //--------------------------------------------------------------------------------------------------// void Win32Keyboard::capture() { if( mBuffered ) _readBuffered(); else _read(); } //--------------------------------------------------------------------------------------------------// void Win32Keyboard::_readBuffered() { DIDEVICEOBJECTDATA diBuff[KEYBOARD_DX_BUFFERSIZE]; DWORD entries = KEYBOARD_DX_BUFFERSIZE; HRESULT hr; hr = mKeyboard->GetDeviceData( sizeof(DIDEVICEOBJECTDATA), diBuff, &entries, 0 ); if( hr != DI_OK ) { hr = mKeyboard->Acquire(); while( hr == DIERR_INPUTLOST ) hr = mKeyboard->Acquire(); return; } if( FAILED(hr) ) OIS_EXCEPT( E_General, "Win32Keyboard::_readBuffered() >> Problem with Device!" ); //Update keyboard and modifier states.. And, if listener, fire events for(unsigned int i = 0; i < entries; ++i ) { //If the listener returns false, that means that we are probably deleted... //send no more events and just leave as the this pointer is invalid now... bool ret = true; KeyCode kc = (KeyCode)diBuff[ i ].dwOfs; //Store result in our keyBuffer too KeyBuffer[kc] = static_cast<unsigned char>(diBuff[ i ].dwData); if( diBuff[ i ].dwData & 0x80 ) { //Turn on modifier if( kc == KC_LCONTROL || kc == KC_RCONTROL ) mModifiers |= Ctrl; else if( kc == KC_LSHIFT || kc == KC_RSHIFT ) mModifiers |= Shift; else if( kc == KC_LMENU || kc == KC_RMENU ) mModifiers |= Alt; if( listener ) ret = listener->keyPressed( KeyEvent( this, kc, _translateText(kc) ) ); } else { //Turn off modifier if( kc == KC_LCONTROL || kc == KC_RCONTROL ) mModifiers &= ~Ctrl; else if( kc == KC_LSHIFT || kc == KC_RSHIFT ) mModifiers &= ~Shift; else if( kc == KC_LMENU || kc == KC_RMENU ) mModifiers &= ~Alt; //Fire off event if( listener ) ret = listener->keyReleased( KeyEvent( this, kc, 0 ) ); } if(ret == false) break; } } //--------------------------------------------------------------------------------------------------// void Win32Keyboard::_read() { HRESULT hr = mKeyboard->GetDeviceState( sizeof(KeyBuffer), &KeyBuffer ); if( hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED ) { hr = mKeyboard->Acquire(); if (hr != DIERR_OTHERAPPHASPRIO) mKeyboard->GetDeviceState(sizeof(KeyBuffer), &KeyBuffer); } //Set Shift, Ctrl, Alt mModifiers = 0; if( isKeyDown(KC_LCONTROL) || isKeyDown(KC_RCONTROL) ) mModifiers |= Ctrl; if( isKeyDown(KC_LSHIFT) || isKeyDown(KC_RSHIFT) ) mModifiers |= Shift; if( isKeyDown(KC_LMENU) || isKeyDown(KC_RMENU) ) mModifiers |= Alt; } //--------------------------------------------------------------------------------------------------// int Win32Keyboard::_translateText( KeyCode kc ) { if( mTextMode == Off ) return 0; BYTE keyState[256]; HKL layout = GetKeyboardLayout(0); if( GetKeyboardState(keyState) == 0 ) return 0; unsigned int vk = MapVirtualKeyEx(kc, 3, layout); if( vk == 0 ) return 0; unsigned char buff[3] = {0,0,0}; int ascii = ToAsciiEx(vk, kc, keyState, (LPWORD) buff, 0, layout); //WCHAR wide[3]; //int ascii = ToUnicodeEx(vk, kc, keyState, wide, 3, 0, layout); if(ascii == 1 && deadKey != '\0' ) { // A dead key is stored and we have just converted a character key // Combine the two into a single character WCHAR wcBuff[3] = {buff[0], deadKey, '\0'}; WCHAR out[3]; deadKey = '\0'; if(FoldStringW(MAP_PRECOMPOSED, (LPWSTR)wcBuff, 3, (LPWSTR)out, 3)) return out[0]; } else if (ascii == 1) { // We have a single character deadKey = '\0'; return buff[0]; } else if(ascii == 2) { // Convert a non-combining diacritical mark into a combining diacritical mark // Combining versions range from 0x300 to 0x36F; only 5 (for French) have been mapped below // http://www.fileformat.info/info/unicode/block/combining_diacritical_marks/images.htm switch(buff[0]) { case 0x5E: // Circumflex accent: â deadKey = 0x302; break; case 0x60: // Grave accent: à deadKey = 0x300; break; case 0xA8: // Diaeresis: ü deadKey = 0x308; break; case 0xB4: // Acute accent: é deadKey = 0x301; break; case 0xB8: // Cedilla: ç deadKey = 0x327; break; default: deadKey = buff[0]; break; } } return 0; } //--------------------------------------------------------------------------------------------------// bool Win32Keyboard::isKeyDown( KeyCode key ) { return (KeyBuffer[key] & 0x80) != 0; } //--------------------------------------------------------------------------------------------------// const std::string& Win32Keyboard::getAsString( KeyCode kc ) { char temp[256]; DIPROPSTRING prop; prop.diph.dwSize = sizeof(DIPROP... [truncated message content] |
Update of /cvsroot/simspark/simspark/spark/utility/ois/linux In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv13856/linux Added Files: Tag: projectx EventHelpers.cpp EventHelpers.h LinuxForceFeedback.cpp LinuxForceFeedback.h LinuxInputManager.cpp LinuxInputManager.h LinuxJoyStick.h LinuxJoyStickEvents.cpp LinuxJoyStickEvents.h LinuxKeyboard.cpp LinuxKeyboard.h LinuxMouse.cpp LinuxMouse.h LinuxPrereqs.h Log Message: added OIS Library sources --- NEW FILE: LinuxJoyStickEvents.cpp --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "OISConfig.h" #include "linux/LinuxJoyStickEvents.h" #include "linux/LinuxInputManager.h" #include "linux/LinuxForceFeedback.h" #include "linux/EventHelpers.h" #include "OISEvents.h" #include "OISException.h" #include <fcntl.h> //Needed to Open a file descriptor #include <cassert> #include <linux/input.h> #include <sstream> using namespace OIS; //#define OIS_LINUX_JOY_DEBUG #ifdef OIS_LINUX_JOY_DEBUG # include <iostream> using namespace std; #endif //-------------------------------------------------------------------// LinuxJoyStick::LinuxJoyStick(bool buffered, const JoyStickInfo& js) { mBuffered = buffered; mType = OISJoyStick; mDevID = js.devId; mJoyStick = js.joyFileD; mVendor = js.vendor; numAxes = js.axes; numButtons = js.buttons; numHats = js.hats; mButtonMap = js.button_map; mAxisMap = js.axis_map; mRanges = js.axis_range; ff_effect = 0; } //-------------------------------------------------------------------// LinuxJoyStick::~LinuxJoyStick() { EventUtils::removeForceFeedback( &ff_effect ); } //-------------------------------------------------------------------// void LinuxJoyStick::_initialize() { //Clear old joy state mState.mAxes.resize(mAxisMap.size()); mState.clear(); //This will create and new us a force feedback structure if it exists EventUtils::enumerateForceFeedback( mJoyStick, &ff_effect ); if( mJoyStick == -1 ) OIS_EXCEPT(E_InputDeviceNonExistant, "LinuxJoyStick::_initialize() >> JoyStick Not Found!"); } //-------------------------------------------------------------------// void LinuxJoyStick::capture() { static const short POV_MASK[8] = {0,0,1,1,2,2,3,3}; //Used to determine if an axis has been changed and needs an event bool axisMoved[32] = {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}; //We are in non blocking mode - we just read once, and try to fill up buffer input_event js[JOY_BUFFERSIZE]; int ret = read(mJoyStick, &js, sizeof(struct input_event) * JOY_BUFFERSIZE); if( ret <= 0 ) return; //Determine how many whole events re read up ret /= sizeof(struct input_event); for(int i = 0; i < ret; ++i) { switch(js[i].type) { case EV_KEY: //Button { int button = mButtonMap[js[i].code]; #ifdef OIS_LINUX_JOY_DEBUG std::cout << "\nButton Code: " << js[i].code << ", OIS Value: " << button << std::endl; #endif //Check to see whether push or released event... if(js[i].value) { mState.buttons |= (1 << button); if( mBuffered && listener ) if(!listener->buttonPressed(JoyStickEvent(this,mState), button)) return; } else { mState.buttons &= ~(1 << button); if( mBuffered && listener ) if(!listener->buttonReleased(JoyStickEvent(this,mState), button)) return; } break; } case EV_ABS: //Absoulte Axis { //A Stick (BrakeDefine is the highest possible Axis) if( js[i].code <= ABS_BRAKE ) { int axis = mAxisMap[js[i].code]; assert( axis < 32 && "Too many axes, not supported. Report this to OIS forums!" ); axisMoved[axis] = true; //check for rescaling: if( mRanges[axis].min == JoyStick::MIN_AXIS && mRanges[axis].max != JoyStick::MAX_AXIS ) { //Scale is perfect mState.mAxes[axis].abs = js[i].value; } else { //Rescale float proportion = (float)(js[i].value-mRanges[axis].max)/(float)(mRanges[axis].min-mRanges[axis].max); mState.mAxes[axis].abs = (int)(32767.0f - (65535.0f * proportion)); } } else if( js[i].code <= ABS_HAT3Y ) //A POV - Max four POVs allowed { //Normalise the POV to between 0-7 //Even is X Axis, Odd is Y Axis unsigned char LinuxPovNumber = js[i].code - 16; short OIS_POVIndex = POV_MASK[LinuxPovNumber]; //Handle X Axis first (Even) (left right) if((LinuxPovNumber & 0x0001) == 0) { //Why do this? Because, we use a bit field, and when this axis is east, //it can't possibly be west too. So clear out the two X axes, then refil //it in with the new direction bit. //Clear the East/West Bit Flags first mState.mPOV[OIS_POVIndex].direction &= 0x11110011; if( js[i].value == -1 ) //Left mState.mPOV[OIS_POVIndex].direction |= Pov::West; else if( js[i].value == 1 ) //Right mState.mPOV[OIS_POVIndex].direction |= Pov::East; } //Handle Y Axis (Odd) (up down) else { //Clear the North/South Bit Flags first mState.mPOV[OIS_POVIndex].direction &= 0x11111100; if( js[i].value == -1 ) //Up mState.mPOV[OIS_POVIndex].direction |= Pov::North; else if( js[i].value == 1 ) //Down mState.mPOV[OIS_POVIndex].direction |= Pov::South; } if( mBuffered && listener ) if( listener->povMoved( JoyStickEvent(this,mState), OIS_POVIndex) == false ) return; } break; } //Relative Axes (Do any joysticks actually have a relative axis?) case EV_REL: default: break; } } //All axes and POVs are combined into one movement per pair per captured frame if( mBuffered && listener ) { for( int i = 0; i < 32; ++i ) if( axisMoved[i] ) if( listener->axisMoved( JoyStickEvent(this,mState), i) == false ) return; } } //-------------------------------------------------------------------// void LinuxJoyStick::setBuffered(bool buffered) { if( buffered != mBuffered ) { mBuffered = buffered; _initialize(); } } //-------------------------------------------------------------------// JoyStickInfo LinuxJoyStick::_getJoyInfo() { JoyStickInfo js; js.devId = mDevID; js.joyFileD = mJoyStick; js.vendor = mVendor; js.axes = numAxes; js.buttons = numButtons; js.hats = numHats; js.button_map = mButtonMap; js.axis_map = mAxisMap; js.axis_range = mRanges; return js; } //-------------------------------------------------------------------// JoyStickInfoList LinuxJoyStick::_scanJoys() { JoyStickInfoList joys; //Search through all of the event devices.. and identify which ones are joysticks //xxx move this to InputManager, as it can also scan all other events for(int i = 0; i < 32; ++i ) { std::stringstream s; s << "/dev/input/event" << i; int fd = open( s.str().c_str(), O_RDONLY |O_NONBLOCK ); #ifdef OIS_LINUX_JOY_DEBUG std::cout << "\nOpening " << s.str() << "..."; #endif try { JoyStickInfo js; if( EventUtils::isJoyStick(fd, js) ) { joys.push_back(js); #ifdef OIS_LINUX_JOY_DEBUG std::cout << "\n__Joystick added to list"; #endif } else { #ifdef OIS_LINUX_JOY_DEBUG std::cout << "\n__Not a joystick!!"; #endif close(fd); } } catch(...) { #ifdef OIS_LINUX_JOY_DEBUG std::cout << "\nException caught!!"; #endif close(fd); } } return joys; } //-------------------------------------------------------------------// void LinuxJoyStick::_clearJoys(JoyStickInfoList &joys) { for(JoyStickInfoList::iterator i = joys.begin(); i != joys.end(); ++i) close(i->joyFileD); joys.clear(); } //-------------------------------------------------------------------// Interface* LinuxJoyStick::queryInterface(Interface::IType type) { if( ff_effect && type == Interface::ForceFeedback ) return ff_effect; return 0; } --- NEW FILE: LinuxMouse.cpp --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered friosom any source distribution. */ #include "linux/LinuxMouse.h" #include "linux/LinuxInputManager.h" #include "OISException.h" #include "OISEvents.h" using namespace OIS; //-------------------------------------------------------------------// LinuxMouse::LinuxMouse(InputManager* creator, bool buffered, bool grab, bool hide) { mCreator = creator; mBuffered = buffered; mType = OISMouse; listener = 0; display = 0; window = 0; cursor = 0; grabMouse = grab; hideMouse = hide; } //-------------------------------------------------------------------// void LinuxMouse::_initialize() { //Clear old state mState.clear(); mMoved = false; mWarped = false; oldXMouseX = oldXMouseY = XMouseX = XMouseY = 6; oldXMouseZ = 0; if( display ) XCloseDisplay(display); display = 0; window = static_cast<LinuxInputManager*>(mCreator)->_getWindow(); //Create our local X listener connection if( !(display = XOpenDisplay(0)) ) OIS_EXCEPT(E_General, "LinuxMouse::_initialize >> Error opening X!"); //Set it to recieve Mouse Input events if( XSelectInput(display, window, ButtonPressMask | ButtonReleaseMask | PointerMotionMask) == BadWindow ) OIS_EXCEPT(E_General, "LinuxMouse::_initialize >> X error!"); //Warp mouse inside window XWarpPointer(display,None,window,0,0,0,0, 6,6); //Create a blank cursor: Pixmap bm_no; XColor black, dummy; Colormap colormap; static char no_data[] = { 0,0,0,0,0,0,0,0 }; colormap = DefaultColormap( display, DefaultScreen(display) ); XAllocNamedColor( display, colormap, "black", &black, &dummy ); bm_no = XCreateBitmapFromData( display, window, no_data, 8, 8 ); cursor = XCreatePixmapCursor( display, bm_no, bm_no, &black, &black, 0, 0 ); grab( grabMouse ); hide( hideMouse ); mouseFocusLost = false; } //-------------------------------------------------------------------// LinuxMouse::~LinuxMouse() { if( display ) { grab(false); hide(false); XFreeCursor(display, cursor); XCloseDisplay(display); } } //-------------------------------------------------------------------// void LinuxMouse::setBuffered(bool buffered) { mBuffered = buffered; } //-------------------------------------------------------------------// void LinuxMouse::capture() { //Clear out last frames values mState.X.rel = 0; mState.Y.rel = 0; mState.Z.rel = 0; _processXEvents(); mWarped = false; if( mMoved == true ) { //Compute this frames Relative X & Y motion mState.X.rel = XMouseX - oldXMouseX; mState.Y.rel = XMouseY - oldXMouseY; //Store old values for next time to compute relative motion oldXMouseX = XMouseX; oldXMouseY = XMouseY; mState.X.abs += mState.X.rel; mState.Y.abs += mState.Y.rel; mState.Z.abs += mState.Z.rel; if( grabMouse ) { //We only need to clip when we are warping mouse around if( mState.X.abs < 0 ) mState.X.abs = 0; else if( mState.X.abs > mState.width ) mState.X.abs = mState.width; if( mState.Y.abs < 0 ) mState.Y.abs = 0; else if( mState.Y.abs > mState.height ) mState.Y.abs = mState.height; if( mouseFocusLost == false ) { //Keep mouse in window (fudge factor) if(XMouseX<5 || XMouseX>mState.width-5 || XMouseY<5 || XMouseY>mState.height-5 ) { oldXMouseX = XMouseX = mState.width >> 1; oldXMouseY = XMouseY = mState.height >> 1; XWarpPointer(display,None,window,0,0,0,0,XMouseX, XMouseY); mWarped = true; } } } if( mBuffered && listener ) listener->mouseMoved( MouseEvent( this, mState ) ); mMoved = false; } //Check for losing/gaining mouse grab focus (alt-tab, etc) if( grabMouse ) { if( static_cast<LinuxInputManager*>(mCreator)->_getGrabState() ) { if( mouseFocusLost ) { //We just regained mouse grab focus grab( true ); hide( hideMouse ); mouseFocusLost = false; } } else { if( mouseFocusLost == false ) {//We just lost mouse grab focus grab( false ); hide( false ); mouseFocusLost = true; } } } } //-------------------------------------------------------------------// void LinuxMouse::_processXEvents() { //X11 Button Events: 1=left 2=middle 3=right; Our Bit Postion: 1=Left 2=Right 3=Middle char mask[4] = {0,1,4,2}; XEvent event; //Poll x11 for events mouse events while( XPending(display) > 0 ) { XNextEvent(display, &event); if( event.type == MotionNotify ) { XMouseX = event.xmotion.x; XMouseY = event.xmotion.y; //Mouse can sometimes get bad data when warping, // so compensate (kindof a hack.. happens with long delays between capture's) if( mWarped && grabMouse ) { if(XMouseX<5 || XMouseX>mState.width-5) { XMouseX = oldXMouseX; continue; } else if(XMouseY<5 || XMouseY>mState.height-5) { XMouseY = oldXMouseY; continue; } } mMoved = true; } else if( event.type == ButtonPress ) { static_cast<LinuxInputManager*>(mCreator)->_setGrabState(true); if( event.xbutton.button < 4 ) { mState.buttons |= mask[event.xbutton.button]; if( mBuffered && listener ) if( listener->mousePressed( MouseEvent( this, mState ), (MouseButtonID)(mask[event.xbutton.button] >> 1)) == false ) return; } } else if( event.type == ButtonRelease ) { if( event.xbutton.button < 4 ) { mState.buttons &= ~mask[event.xbutton.button]; if( mBuffered && listener ) if( listener->mouseReleased( MouseEvent( this, mState ), (MouseButtonID)(mask[event.xbutton.button] >> 1)) == false ) return; } //The Z axis gets pushed/released pair message (this is up) else if( event.xbutton.button == 4 ) { mState.Z.rel += 120; mMoved = true; } //The Z axis gets pushed/released pair message (this is down) else if( event.xbutton.button == 5 ) { mState.Z.rel -= 120; mMoved = true; } } } } //-------------------------------------------------------------------// void LinuxMouse::grab(bool grab) { if( grab ) XGrabPointer(display, window, True, 0, GrabModeAsync, GrabModeAsync, window, None, CurrentTime); else XUngrabPointer(display, CurrentTime); } //-------------------------------------------------------------------// void LinuxMouse::hide(bool hide) { if( hide ) XDefineCursor(display, window, cursor); else XUndefineCursor(display, window); } --- NEW FILE: LinuxKeyboard.cpp --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "linux/LinuxInputManager.h" #include "linux/LinuxKeyboard.h" #include "OISException.h" #include "OISEvents.h" #include <X11/keysym.h> #include <X11/Xutil.h> using namespace OIS; #include <iostream> //-------------------------------------------------------------------// LinuxKeyboard::LinuxKeyboard(InputManager* creator, bool buffered, bool grab, bool useXRepeat) { mCreator = creator; mBuffered = buffered; mType = OISKeyboard; listener = 0; display = 0; window = 0; grabKeyboard = grab; keyFocusLost = false; xAutoRepeat = useXRepeat; oldXAutoRepeat = false; //X Key Map to KeyCode keyConversion.insert(XtoOIS_KeyMap::value_type(XK_1, KC_1)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_2, KC_2)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_3, KC_3)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_4, KC_4)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_5, KC_5)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_6, KC_6)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_7, KC_7)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_8, KC_8)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_9, KC_9)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_0, KC_0)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_BackSpace, KC_BACK)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_minus, KC_MINUS)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_equal, KC_EQUALS)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_space, KC_SPACE)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_comma, KC_COMMA)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_period, KC_PERIOD)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_backslash, KC_BACKSLASH)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_slash, KC_SLASH)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_bracketleft, KC_LBRACKET)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_bracketright, KC_RBRACKET)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Escape,KC_ESCAPE)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Caps_Lock, KC_CAPITAL)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Tab, KC_TAB)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Return, KC_RETURN)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Control_L, KC_LCONTROL)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Control_R, KC_RCONTROL)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_colon, KC_COLON)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_semicolon, KC_SEMICOLON)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_apostrophe, KC_APOSTROPHE)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_grave, KC_GRAVE)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_b, KC_B)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_a, KC_A)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_c, KC_C)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_d, KC_D)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_e, KC_E)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_f, KC_F)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_g, KC_G)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_h, KC_H)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_i, KC_I)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_j, KC_J)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_k, KC_K)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_l, KC_L)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_m, KC_M)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_n, KC_N)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_o, KC_O)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_p, KC_P)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_q, KC_Q)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_r, KC_R)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_s, KC_S)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_t, KC_T)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_u, KC_U)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_v, KC_V)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_w, KC_W)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_x, KC_X)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_y, KC_Y)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_z, KC_Z)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F1, KC_F1)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F2, KC_F2)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F3, KC_F3)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F4, KC_F4)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F5, KC_F5)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F6, KC_F6)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F7, KC_F7)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F8, KC_F8)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F9, KC_F9)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F10, KC_F10)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F11, KC_F11)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F12, KC_F12)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F13, KC_F13)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F14, KC_F14)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F15, KC_F15)); //Keypad keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_0, KC_NUMPAD0)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_1, KC_NUMPAD1)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_2, KC_NUMPAD2)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_3, KC_NUMPAD3)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_4, KC_NUMPAD4)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_5, KC_NUMPAD5)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_6, KC_NUMPAD6)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_7, KC_NUMPAD7)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_8, KC_NUMPAD8)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_9, KC_NUMPAD9)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Add, KC_ADD)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Subtract, KC_SUBTRACT)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Decimal, KC_DECIMAL)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Equal, KC_NUMPADEQUALS)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Divide, KC_DIVIDE)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Multiply, KC_MULTIPLY)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Enter, KC_NUMPADENTER)); //Keypad with numlock off keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Home, KC_NUMPAD7)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Up, KC_NUMPAD8)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Page_Up, KC_NUMPAD9)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Left, KC_NUMPAD4)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Begin, KC_NUMPAD5)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Right, KC_NUMPAD6)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_End, KC_NUMPAD1)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Down, KC_NUMPAD2)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Page_Down, KC_NUMPAD3)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Insert, KC_NUMPAD0)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Delete, KC_DECIMAL)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Up, KC_UP)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Down, KC_DOWN)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Left, KC_LEFT)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Right, KC_RIGHT)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Page_Up, KC_PGUP)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Page_Down, KC_PGDOWN)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Home, KC_HOME)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_End, KC_END)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Num_Lock, KC_NUMLOCK)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Print, KC_SYSRQ)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Scroll_Lock, KC_SCROLL)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Pause, KC_PAUSE)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Shift_R, KC_RSHIFT)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Shift_L, KC_LSHIFT)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Alt_R, KC_RMENU)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Alt_L, KC_LMENU)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Insert, KC_INSERT)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Delete, KC_DELETE)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Super_L, KC_LWIN)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Super_R, KC_RWIN)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Menu, KC_APPS)); } //-------------------------------------------------------------------// void LinuxKeyboard::_initialize() { //Clear our keyboard state buffer memset( &KeyBuffer, 0, 256 ); mModifiers = 0; if( display ) XCloseDisplay(display); display = 0; window = static_cast<LinuxInputManager*>(mCreator)->_getWindow(); //Create our local X listener connection if( !(display = XOpenDisplay(0)) ) OIS_EXCEPT(E_General, "LinuxKeyboard::_initialize >> Error opening X!"); //Set it to recieve Input events if( XSelectInput(display, window, KeyPressMask | KeyReleaseMask) == BadWindow ) OIS_EXCEPT(E_General, "LinuxKeyboard::_initialize: X error!"); if( grabKeyboard ) XGrabKeyboard(display,window,True,GrabModeAsync,GrabModeAsync,CurrentTime); keyFocusLost = false; if( xAutoRepeat == false ) { //We do not want to blindly turn on autorepeat later when quiting if //it was not on to begin with.. So, let us check and see first XKeyboardState old; XGetKeyboardControl( display, &old ); oldXAutoRepeat = false; if( old.global_auto_repeat == AutoRepeatModeOn ) oldXAutoRepeat = true; XAutoRepeatOff( display ); } } //-------------------------------------------------------------------// LinuxKeyboard::~LinuxKeyboard() { if( display ) { if( oldXAutoRepeat ) XAutoRepeatOn(display); if( grabKeyboard ) XUngrabKeyboard(display, CurrentTime); XCloseDisplay(display); } } //-------------------------------------------------------------------// bool LinuxKeyboard::isKeyDown( KeyCode key ) { return (KeyBuffer[key]); } //-------------------------------------------------------------------// void LinuxKeyboard::capture() { KeySym key; XEvent event; LinuxInputManager* linMan = static_cast<LinuxInputManager*>(mCreator); while( XPending(display) > 0 ) { XNextEvent(display, &event); if( KeyPress == event.type ) { char buffer[3] = {0,0,0}; if( mTextMode != Off ) /*int bytes =*/ XLookupString(&event.xkey, buffer, 3, &key, 0); //Mask out the modifier states X11 sets and read again event.xkey.state &= ~ShiftMask; event.xkey.state &= ~LockMask; XLookupString(&event.xkey, 0, 0,&key, 0); _injectKeyDown(key, buffer[0]); //Just printing out some debugging info.. to verify all chars are mapped //std::cout << "KEY PRESSED X=" << event.xkey.keycode; //std::cout << "\n KeySym=" << key << std::endl; //Check for Alt-Tab if( event.xkey.state & Mod1Mask && key == XK_Tab ) linMan->_setGrabState(false); } else if( KeyRelease == event.type ) { //Mask out the modifier states X sets.. or we will get improper values event.xkey.state &= ~ShiftMask; event.xkey.state &= ~LockMask; //Else, it is a valid key release XLookupString(&event.xkey,NULL,0,&key,NULL); _injectKeyUp(key); } } //If grabbing mode is on.. Handle focus lost/gained via Alt-Tab and mouse clicks if( grabKeyboard ) { if( linMan->_getGrabState() == false ) { // are no longer grabbing if( keyFocusLost == false ) { //UnGrab KeyBoard XUngrabKeyboard(display, CurrentTime); keyFocusLost = true; } } else { //We are grabbing - and regained focus if( keyFocusLost == true ) { //ReGrab KeyBoard XGrabKeyboard(display, window, True, GrabModeAsync, GrabModeAsync, CurrentTime); keyFocusLost = false; } } } } //-------------------------------------------------------------------// void LinuxKeyboard::setBuffered(bool buffered) { mBuffered = buffered; } //-------------------------------------------------------------------// bool LinuxKeyboard::_injectKeyDown( KeySym key, int text ) { KeyCode kc = keyConversion[key]; KeyBuffer[kc] = 1; //Turn on modifier flags if( kc == KC_LCONTROL || kc == KC_RCONTROL) mModifiers |= Ctrl; else if( kc == KC_LSHIFT || kc == KC_RSHIFT ) mModifiers |= Shift; else if( kc == KC_LMENU || kc == KC_RMENU ) mModifiers |= Alt; if( mBuffered && listener ) return listener->keyPressed(KeyEvent(this,kc,text)); return true; } //-------------------------------------------------------------------// bool LinuxKeyboard::_injectKeyUp( KeySym key ) { KeyCode kc = keyConversion[key]; KeyBuffer[kc] = 0; //Turn off modifier flags if( kc == KC_LCONTROL || kc == KC_RCONTROL) mModifiers &= ~Ctrl; else if( kc == KC_LSHIFT || kc == KC_RSHIFT ) mModifiers &= ~Shift; else if( kc == KC_LMENU || kc == KC_RMENU ) mModifiers &= ~Alt; if( mBuffered && listener ) return listener->keyReleased(KeyEvent(this, kc, 0)); return true; } //-------------------------------------------------------------------// const std::string& LinuxKeyboard::getAsString( KeyCode kc ) { mGetString = "Unknown"; char *temp = 0; XtoOIS_KeyMap::iterator i = keyConversion.begin(), e = keyConversion.end(); for( ; i != e; ++i ) { if( i->second == kc ) { temp = XKeysymToString(i->first); if( temp ) mGetString = temp; break; } } return mGetString; } //-------------------------------------------------------------------// void LinuxKeyboard::copyKeyStates( char keys[256] ) { memcpy( keys, KeyBuffer, 256 ); } --- NEW FILE: LinuxForceFeedback.h --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_LinuxForceFeedBack_H #define OIS_LinuxForceFeedBack_H #include "linux/LinuxPrereqs.h" #include "OISForceFeedback.h" namespace OIS { class LinuxForceFeedback : public ForceFeedback { public: LinuxForceFeedback(); ~LinuxForceFeedback(); /** @copydoc ForceFeedback::setMasterGain */ void setMasterGain(float); /** @copydoc ForceFeedback::setAutoCenterMode */ void setAutoCenterMode(bool); /** @copydoc ForceFeedback::upload */ void upload( const Effect* effect ); /** @copydoc ForceFeedback::modify */ void modify( const Effect* effect ); /** @copydoc ForceFeedback::remove */ void remove( const Effect* effect ); /** FF is not yet implemented fully on Linux.. just retun 0 for now. todo, xxx */ short int getFFAxesNumber() { return 0; } }; } #endif //OIS_LinuxForceFeedBack_H --- NEW FILE: LinuxInputManager.cpp --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "linux/LinuxInputManager.h" #include "linux/LinuxKeyboard.h" #include "linux/LinuxJoyStickEvents.h" #include "linux/LinuxMouse.h" #include "OISException.h" using namespace OIS; const std::string LinuxInputManager::iName = "X11 Linux Input Manager"; //--------------------------------------------------------------------------------// LinuxInputManager::LinuxInputManager() { window = 0; //Default settings grabMouse = true; grabKeyboard = true; hideMouse = true; mGrabs = true; useXRepeat = false; } //--------------------------------------------------------------------------------// LinuxInputManager::~LinuxInputManager() { LinuxJoyStick::_clearJoys(unusedJoyStickList); } //--------------------------------------------------------------------------------// void LinuxInputManager::_initialize( ParamList ¶mList ) { _parseConfigSettings( paramList ); //Enumerate all devices attached _enumerateDevices(); } //--------------------------------------------------------------------------------// void LinuxInputManager::_parseConfigSettings( ParamList ¶mList ) { ParamList::iterator i = paramList.find("WINDOW"); if( i == paramList.end() ) OIS_EXCEPT( E_InvalidParam, "LinuxInputManager >> No WINDOW!" ); //TODO 64 bit proof this little conversion xxx wip window = strtoul(i->second.c_str(), 0, 10); //--------- Keyboard Settings ------------// i = paramList.find("XAutoRepeatOn"); if( i != paramList.end() ) if( i->second == "true" ) useXRepeat = true; i = paramList.find("x11_keyboard_grab"); if( i != paramList.end() ) if( i->second == "false" ) grabKeyboard = false; //--------- Mouse Settings ------------// i = paramList.find("x11_mouse_grab"); if( i != paramList.end() ) if( i->second == "false" ) grabMouse = false; i = paramList.find("x11_mouse_hide"); if( i != paramList.end() ) if( i->second == "false" ) hideMouse = false; } //--------------------------------------------------------------------------------// void LinuxInputManager::_enumerateDevices() { //Enumerate all attached devices unusedJoyStickList = LinuxJoyStick::_scanJoys(); joySticks = unusedJoyStickList.size(); } //--------------------------------------------------------------------------------// int LinuxInputManager::numJoysticks() { return joySticks; } //--------------------------------------------------------------------------------// int LinuxInputManager::numMice() { return 1; } //--------------------------------------------------------------------------------// int LinuxInputManager::numKeyBoards() { return 1; } //----------------------------------------------------------------------------// Object* LinuxInputManager::createInputObject( Type iType, bool bufferMode ) { Object* obj = 0; switch( iType ) { case OISKeyboard: obj = new LinuxKeyboard(this, bufferMode, grabKeyboard, useXRepeat); break; case OISMouse: obj = new LinuxMouse(this, bufferMode, grabMouse, hideMouse); break; case OISJoyStick: { //Find a JoyStick not in use JoyStickInfoList::iterator i = unusedJoyStickList.begin(); if( i != unusedJoyStickList.end() ) { obj = new LinuxJoyStick(bufferMode, *i); unusedJoyStickList.erase(i); break; } OIS_EXCEPT(E_InputDeviceNonExistant, "No JoySticks Available!"); } default: OIS_EXCEPT( E_InputDeviceNotSupported, "Device Not Supported!"); } //Seperate initialization from construction.. as bad things happen when //throwing exceptions from constructors try { obj->_initialize(); } catch(...) { delete obj; throw; //rethrow the exception } return obj; } //----------------------------------------------------------------------------// void LinuxInputManager::destroyInputObject( Object* obj ) { if( obj ) { //We put joys back into unused list if( obj->type() == OISJoyStick ) unusedJoyStickList.push_back(((LinuxJoyStick*)obj)->_getJoyInfo()); delete obj; } } --- NEW FILE: LinuxKeyboard.h --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef _LINUX_KEYBOARD_H_EADER_ #define _LINUX_KEYBOARD_H_EADER_ #include "linux/LinuxPrereqs.h" #include "OISKeyboard.h" #include <X11/Xlib.h> namespace OIS { /** Linux implementation of Keyboard object - uses x11 */ class LinuxKeyboard : public Keyboard { public: LinuxKeyboard(InputManager* creator, bool buffered, bool grab, bool useXRepeat ); virtual ~LinuxKeyboard(); /** @copydoc Keyboard::isKeyDown */ virtual bool isKeyDown( KeyCode key ); /** @copydoc Keyboard::getAsString */ virtual const std::string& getAsString( KeyCode kc ); /** @copydoc Keyboard::copyKeyStates */ virtual void copyKeyStates( char keys[256] ); /** @copydoc Object::setBuffered */ virtual void setBuffered(bool buffered); /** @copydoc Object::capture */ virtual void capture(); /** @copydoc Object::queryInterface */ virtual Interface* queryInterface(Interface::IType) {return 0;} /** @copydoc Object::_initialize */ virtual void _initialize(); protected: bool _injectKeyDown( KeySym key, int text ); bool _injectKeyUp( KeySym key ); //! 1:1 Conversion Map between X Key Events and OIS KeyCodes typedef std::map<KeySym, KeyCode> XtoOIS_KeyMap; XtoOIS_KeyMap keyConversion; //! Depressed Key List char KeyBuffer[256]; //! X11 Stuff Window window; Display *display; bool grabKeyboard; bool keyFocusLost; bool xAutoRepeat; bool oldXAutoRepeat; std::string mGetString; }; } #endif //_LINUX_KEYBOARD_H_EADER_ --- NEW FILE: LinuxForceFeedback.cpp --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "linux/LinuxForceFeedback.h" #include "OISException.h" using namespace OIS; //--------------------------------------------------------------// LinuxForceFeedback::LinuxForceFeedback() { } //--------------------------------------------------------------// LinuxForceFeedback::~LinuxForceFeedback() { } //--------------------------------------------------------------// void LinuxForceFeedback::setMasterGain(float) { } //--------------------------------------------------------------// void LinuxForceFeedback::setAutoCenterMode(bool) { } //--------------------------------------------------------------// void LinuxForceFeedback::upload( const Effect* /*effect*/ ) { } //--------------------------------------------------------------// void LinuxForceFeedback::modify( const Effect* /*effect*/ ) { } //--------------------------------------------------------------// void LinuxForceFeedback::remove( const Effect* /*effect*/ ) { } --- NEW FILE: LinuxPrereqs.h --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef _LINUX_INPUTSYSTEM_PREREQS_H #define _LINUX_INPUTSYSTEM_PREREQS_H //Bring in any auto generated config files #ifdef HAVE_CONFIG_H # include "config.h" #endif #include "OISPrereqs.h" //! Max number of elements to collect from buffered input #define JOY_BUFFERSIZE 10 namespace OIS { class LinuxInputManager; class LinuxKeyboard; class LinuxJoyStick; class LinuxMouse; class LinuxForceFeedback; struct Range { Range() {}; Range(int _min, int _max) : min(_min), max(_max) {}; int min, max; }; struct JoyStickInfo { JoyStickInfo(): devId(-1),joyFileD(-1),version(0),axes(0),buttons(0),hats(0) {} //! Device number (/dev/input/j#) or /dev/input/event# int devId; //! File descriptor int joyFileD; //! Driver version int version; //! Joy vendor std::string vendor; //! Number of axes unsigned char axes; //! Number of buttons unsigned char buttons; //! Number of hats unsigned char hats; //! Maps Linux button values to OIS buttons values std::map<int, int> button_map; //! Maps Linux axis values to OIS axis std::map<int, int> axis_map; //! Maps OIS axis values to it's range std::map<int, Range> axis_range; }; typedef std::vector< JoyStickInfo > JoyStickInfoList; } #endif //_LINUX_INPUTSYSTEM_PREREQS_H --- NEW FILE: LinuxInputManager.h --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_LinuxInputManager_H #define OIS_LinuxInputManager_H #include "linux/LinuxPrereqs.h" #include "OISInputManager.h" #include <X11/Xlib.h> namespace OIS { /** Linux X11 InputManager specialization - Using lowlevel joys */ class LinuxInputManager : public InputManager { public: LinuxInputManager(); virtual ~LinuxInputManager(); /** @copydoc InputManager::inputSystemName */ virtual const std::string& inputSystemName() { return iName; } /** @copydoc InputManager::numJoysticks */ virtual int numJoysticks(); /** @copydoc InputManager::numMice */ virtual int numMice(); /** @copydoc InputManager::numKeyBoards */ virtual int numKeyBoards(); /** @copydoc InputManager::createInputObject */ Object* createInputObject( Type iType, bool bufferMode ); /** @copydoc InputManager::destroyInputObject */ void destroyInputObject( Object* obj ); //! Method for retrieving the XWindow Handle Window _getWindow() {return window;} //! Internal method for checking if regrabbing is needed void _setGrabState(bool grab) {mGrabs = grab;} bool _getGrabState() {return mGrabs;} protected: /** @copydoc InputManager::_initialize */ void _initialize( ParamList ¶mList ); //! internal class method for dealing with param list void _parseConfigSettings( ParamList ¶mList ); //! internal class method for finding attached devices void _enumerateDevices(); //! List of unused joysticks ready to be used JoyStickInfoList unusedJoyStickList; //! Number of joysticks found char joySticks; //! Input manager string name static const std::string iName; //! X11 Stuff Window window; /// Keyboard, Mouse Settings bool grabMouse, grabKeyboard; bool mGrabs; bool hideMouse; //! By default, keyboard disables XRepeatRate bool useXRepeat; }; } #endif --- NEW FILE: LinuxJoyStickEvents.h --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef _LINUX_JOYSTICK_H_EADER_ #define _LINUX_JOYSTICK_H_EADER_ #include "linux/LinuxPrereqs.h" #include "OISJoyStick.h" namespace OIS { /** Linux specialization of JoyStick class.. This version is favored over the other.. and has the *possibility* of Force Feedback.. notice I say possibility, i make no gaurantees under linux, as FF support is sketchy at best AFAIK. */ class LinuxJoyStick : public JoyStick { public: LinuxJoyStick(bool buffered, const JoyStickInfo& js); virtual ~LinuxJoyStick(); /** @copydoc Object::setBuffered */ virtual void setBuffered(bool buffered); /** @copydoc Object::capture */ virtual void capture(); /** @copydoc Object::queryInterface */ virtual Interface* queryInterface(Interface::IType type); /** @copydoc Object::_initialize */ virtual void _initialize(); /** @remarks For internal use only... Returns a structure to the manager, to make the device availiable for use again */ JoyStickInfo _getJoyInfo(); static JoyStickInfoList _scanJoys(); static void _clearJoys(JoyStickInfoList &joys); protected: int mJoyStick; LinuxForceFeedback* ff_effect; std::map <int, int> mButtonMap; std::map <int, int> mAxisMap; std::map <int, Range> mRanges; }; } #endif //_LINUX_JOYSTICK_H_EADER_ --- NEW FILE: EventHelpers.h --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef _LINUX_OISEVENT_HEADER_ #define _LINUX_OISEVENT_HEADER_ #include "linux/LinuxPrereqs.h" #define OIS_MAX_DEVICES 32 #define OIS_DEVICE_NAME 128 namespace OIS { class EventUtils { public: static bool isJoyStick( int deviceID, JoyStickInfo &js ); static bool isMouse( int ) {return false;} static bool isKeyboard( int ) {return false;} //Double pointer is so that we can set the value of the sent pointer static void enumerateForceFeedback( int deviceID, LinuxForceFeedback** ff ); static void removeForceFeedback( LinuxForceFeedback** ff ); static std::string getName( int deviceID ); }; } #endif --- NEW FILE: LinuxMouse.h --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef _LINUX_MOUSE_H_EADER_ #define _LINUX_MOUSE_H_EADER_ #include "linux/LinuxPrereqs.h" #include "OISMouse.h" #include <X11/Xlib.h> namespace OIS { class LinuxMouse : public Mouse { public: LinuxMouse(InputManager* creator, bool buffered, bool grab, bool hide); virtual ~LinuxMouse(); /** @copydoc Object::setBuffered */ virtual void setBuffered(bool buffered); /** @remarks Note: Calling this will also update the keyboard (X11 updates in a single event queue). Updates State and/or raises event for buffered mode.. */ virtual void capture(); /** @copydoc Object::queryInterface */ virtual Interface* queryInterface(Interface::IType) {return 0;} /** @copydoc Object::_initialize */ virtual void _initialize(); void grab(bool grab); void hide(bool hide); protected: void _processXEvents(); bool mMoved, mWarped; //Since X11 provides us with absolute values, we need to keep track of //relative values long oldXMouseX, oldXMouseY, oldXMouseZ; //We use these to keep track of the cuurent absolute X Mouse position long XMouseX, XMouseY; //! X11 Stuff Window window; Display *display; Cursor cursor; //A blank cursor bool grabMouse; bool hideMouse; bool mouseFocusLost; }; } #endif //_LINUX_MOUSE_H_EADER_ --- NEW FILE: EventHelpers.cpp --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "linux/EventHelpers.h" #include "linux/LinuxPrereqs.h" #include "linux/LinuxForceFeedback.h" #include "OISException.h" #include "OISJoyStick.h" #include <linux/input.h> //#define OIS_LINUX_JOY_DEBUG #ifdef OIS_LINUX_JOY_DEBUG # include <iostream> using namespace std; #endif using namespace OIS; struct DeviceComponentInfo { std::vector<int> buttons, relAxes, absAxes, hats; }; bool inline isBitSet(unsigned long bits[], unsigned int bit) { return (bits[bit/(sizeof(long)*8)] >> ((bit)%(sizeof(long)*8))) & 1; } //-----------------------------------------------------------------------------// DeviceComponentInfo getComponentInfo( int deviceID ) { unsigned long info[2][((KEY_MAX-1)/(sizeof(long)*8)) +1]; memset( info, 0, sizeof(info) ); DeviceComponentInfo components; //Read "all" (hence 0) components of the device - read into first entry ioctl(deviceID, EVIOCGBIT(0, EV_MAX), info[0]); for (int i = 0; i < EV_MAX; i++) { if( isBitSet(info[0], i) ) { memset( info[1], 0, sizeof(info) / 2 ); ioctl(deviceID, EVIOCGBIT(i, KEY_MAX), info[1]); for (int j = 0; j < KEY_MAX; j++) { if( isBitSet(info[1], j) ) { if(i == EV_ABS) { //input_absinfo abInfo; //ioctl( fd, EVIOCGABS(j), abInfo ); if( j >= ABS_HAT0X && j <= ABS_HAT3Y ) { components.hats.push_back(j); } else { components.absAxes.push_back(j); //input_absinfo absinfo; //ioctl(deviceID, EVIOCGABS(j), &absinfo); //We cannot actually change these values :| //absinfo.minimum = JoyStick::MIN_AXIS; //absinfo.maximum = JoyStick::MAX_AXIS; //ioctl(deviceID, EVIOCSABS(j), &absinfo); } } else if(i == EV_REL) { components.relAxes.push_back(j); } else if(i == EV_KEY) { components.buttons.push_back(j); } } } } } return components; } //-----------------------------------------------------------------------------// bool EventUtils::isJoyStick( int deviceID, JoyStickInfo &js ) { if( deviceID == -1 ) OIS_EXCEPT( E_General, "Error with File Descriptor" ); DeviceComponentInfo info = getComponentInfo( deviceID ); int buttons = 0; bool joyButtonFound = false; js.button_map.clear(); #ifdef OIS_LINUX_JOY_DEBUG cout << "\n\nDisplaying ButtonMapping Status:"; #endif for(std::vector<int>::iterator i = info.buttons.begin(), e = info.buttons.end(); i != e; ++i ) { //Check to ensure we find at least one joy only button if( (*i >= BTN_JOYSTICK && *i <= BTN_THUMBR) || (*i >= BTN_WHEEL && *i <= BTN_GEAR_UP ) ) joyButtonFound = true; js.button_map[*i] = buttons++; #ifdef OIS_LINUX_JOY_DEBUG cout << "\nButton Mapping ID (hex): " << hex << *i << " OIS Button Num: " << dec << (buttons-1); #endif } //Joy Buttons found, so it must be a joystick or pad if( joyButtonFound ) { js.joyFileD = deviceID; js.vendor = getName(deviceID); js.buttons = buttons; js.axes = info.relAxes.size() + info.absAxes.size(); js.hats = info.hats.size(); //Map the Axes #ifdef OIS_LINUX_JOY_DEBUG cout << "\n\nDisplaying AxisMapping Status:"; #endif int axes = 0; for(std::vector<int>::iterator i = info.absAxes.begin(), e = info.absAxes.end(); i != e; ++i ) { js.axis_map[*i] = axes; input_absinfo absinfo; ioctl(deviceID, EVIOCGABS(*i), &absinfo); js.axis_range[axes] = Range(absinfo.minimum, absinfo.maximum); #ifdef OIS_LINUX_JOY_DEBUG cout << "\nAxis Mapping ID (hex): " << hex << *i << " OIS Axis Num: " << dec << axes; #endif ++axes; } } return joyButtonFound; } //-----------------------------------------------------------------------------// std::string EventUtils::getName( int deviceID ) { char name[OIS_DEVICE_NAME]; ioctl(deviceID, EVIOCGNAME(OIS_DEVICE_NAME), name); return std::string(name); } //-----------------------------------------------------------------------------// void EventUtils::enumerateForceFeedback( int deviceID, LinuxForceFeedback** ff ) { //Linux Event to OIS Event Mappings std::map<int, Effect::EType> typeMap; typeMap[FF_CONSTANT] = Effect::Constant; typeMap[FF_RAMP] = Effect::Ramp; typeMap[FF_SPRING] = Effect::Spring; typeMap[FF_FRICTION] = Effect::Friction; typeMap[FF_SQUARE] = Effect::Square; typeMap[FF_TRIANGLE] = Effect::Triangle; typeMap[FF_SINE] = Effect::Sine; typeMap[FF_SAW_UP] = Effect::SawToothUp; typeMap[FF_SAW_DOWN] = Effect::SawToothDown; typeMap[FF_DAMPER] = Effect::Damper; typeMap[FF_INERTIA] = Effect::Inertia; typeMap[FF_CUSTOM] = Effect::Custom; std::map<int, Effect::EForce> forceMap; forceMap[FF_CONSTANT] = Effect::ConstantForce; forceMap[FF_RAMP] = Effect::RampForce; forceMap[FF_PERIODIC] = Effect::PeriodicForce; forceMap[FF_CUSTOM] = Effect::CustomForce; //Remove any previously existing memory and create fresh removeForceFeedback( ff ); *ff = new LinuxForceFeedback(); unsigned long info[4] = {0,0,0,0}; unsigned long subinfo[4]= {0,0,0,0}; //Read overall force feedback components of the device ioctl(deviceID, EVIOCGBIT(EV_FF, sizeof(long)*4), info); //FF Axes //if( isBitSet(info, ABS_X) ) //X Axis //if( isBitSet(info, ABS_Y) ) //Y Axis //if( isBitSet(info, ABS_WHEEL) ) //Wheel //FF Effects for( int effect = ABS_WHEEL+1; effect < FF_MAX; effect++ ) { if(isBitSet(info, effect)) { //std::cout << "\tEffect Type: " << effect << std::endl; memset(subinfo, 0, sizeof(subinfo)); //Read any info about this supported effect ioctl(deviceID, EVIOCGBIT(effect, sizeof(long)*4), subinfo); for( int force = 0; force < FF_MAX; force++ ) { if(isBitSet(subinfo, force)) (*ff)->_addEffectTypes( forceMap[force], typeMap[effect] ); } } } //Check to see if any effects were added, else destroy the pointer const ForceFeedback::SupportedEffectList &list = (*ff)->getSupportedEffects(); if( list.size() == 0 ) removeForceFeedback( ff ); } //-----------------------------------------------------------------------------// void EventUtils::removeForceFeedback( LinuxForceFeedback** ff ) { delete *ff; *ff = 0; } --- NEW FILE: LinuxJoyStick.h --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any ... [truncated message content] |
From: Oliver O. <fr...@us...> - 2007-07-24 01:00:40
|
Update of /cvsroot/simspark/simspark/spark/utility/ois/SDL In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv13856/SDL Added Files: Tag: projectx SDLInputManager.cpp SDLInputManager.h SDLJoyStick.cpp SDLJoyStick.h SDLKeyboard.cpp SDLKeyboard.h SDLMouse.cpp SDLMouse.h SDLPrereqs.h Log Message: added OIS Library sources --- NEW FILE: SDLKeyboard.cpp --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "SDL/SDLKeyBoard.h" #include "SDL/SDLInputManager.h" #include "OISException.h" #include "OISEvents.h" #include <sstream> using namespace OIS; //-------------------------------------------------------------------// SDLKeyboard::SDLKeyboard( bool buffered ) { mBuffered = buffered; mType = OISKeyboard; listener = 0; //Clear our keyboard state buffer memset( &KeyBuffer, 0, 256 ); } //-------------------------------------------------------------------// void SDLKeyboard::_initialize() { mModifiers = 0; mSDLBuff = 0; mKeyMap.insert( KeyMap::value_type(SDLK_ESCAPE,KC_ESCAPE) ); mKeyMap.insert( KeyMap::value_type(SDLK_1, KC_1) ); mKeyMap.insert( KeyMap::value_type(SDLK_2, KC_2) ); mKeyMap.insert( KeyMap::value_type(SDLK_3, KC_3) ); mKeyMap.insert( KeyMap::value_type(SDLK_4, KC_4) ); mKeyMap.insert( KeyMap::value_type(SDLK_5, KC_5) ); mKeyMap.insert( KeyMap::value_type(SDLK_6, KC_6) ); mKeyMap.insert( KeyMap::value_type(SDLK_7, KC_7) ); mKeyMap.insert( KeyMap::value_type(SDLK_8, KC_8) ); mKeyMap.insert( KeyMap::value_type(SDLK_9, KC_9) ); mKeyMap.insert( KeyMap::value_type(SDLK_0, KC_0) ); mKeyMap.insert( KeyMap::value_type(SDLK_MINUS, KC_MINUS) ); mKeyMap.insert( KeyMap::value_type(SDLK_EQUALS, KC_EQUALS) ); mKeyMap.insert( KeyMap::value_type(SDLK_BACKSPACE, KC_BACK) ); mKeyMap.insert( KeyMap::value_type(SDLK_TAB, KC_TAB) ); mKeyMap.insert( KeyMap::value_type(SDLK_q, KC_Q) ); mKeyMap.insert( KeyMap::value_type(SDLK_w, KC_W) ); mKeyMap.insert( KeyMap::value_type(SDLK_e, KC_E) ); mKeyMap.insert( KeyMap::value_type(SDLK_r, KC_R) ); mKeyMap.insert( KeyMap::value_type(SDLK_t, KC_T) ); mKeyMap.insert( KeyMap::value_type(SDLK_y, KC_Y) ); mKeyMap.insert( KeyMap::value_type(SDLK_u, KC_U) ); mKeyMap.insert( KeyMap::value_type(SDLK_i, KC_I) ); mKeyMap.insert( KeyMap::value_type(SDLK_o, KC_O) ); mKeyMap.insert( KeyMap::value_type(SDLK_p, KC_P) ); mKeyMap.insert( KeyMap::value_type(SDLK_RETURN, KC_RETURN) ); mKeyMap.insert( KeyMap::value_type(SDLK_LCTRL, KC_LCONTROL)); mKeyMap.insert( KeyMap::value_type(SDLK_a, KC_A) ); mKeyMap.insert( KeyMap::value_type(SDLK_s, KC_S) ); mKeyMap.insert( KeyMap::value_type(SDLK_d, KC_D) ); mKeyMap.insert( KeyMap::value_type(SDLK_f, KC_F) ); mKeyMap.insert( KeyMap::value_type(SDLK_g, KC_G) ); mKeyMap.insert( KeyMap::value_type(SDLK_h, KC_H) ); mKeyMap.insert( KeyMap::value_type(SDLK_j, KC_J) ); mKeyMap.insert( KeyMap::value_type(SDLK_k, KC_K) ); mKeyMap.insert( KeyMap::value_type(SDLK_l, KC_L) ); mKeyMap.insert( KeyMap::value_type(SDLK_SEMICOLON, KC_SEMICOLON) ); mKeyMap.insert( KeyMap::value_type(SDLK_COLON, KC_COLON) ); mKeyMap.insert( KeyMap::value_type(SDLK_QUOTE, KC_APOSTROPHE) ); mKeyMap.insert( KeyMap::value_type(SDLK_BACKQUOTE, KC_GRAVE) ); mKeyMap.insert( KeyMap::value_type(SDLK_LSHIFT, KC_LSHIFT) ); mKeyMap.insert( KeyMap::value_type(SDLK_BACKSLASH, KC_BACKSLASH) ); mKeyMap.insert( KeyMap::value_type(SDLK_SLASH, KC_SLASH) ); mKeyMap.insert( KeyMap::value_type(SDLK_z, KC_Z) ); mKeyMap.insert( KeyMap::value_type(SDLK_x, KC_X) ); mKeyMap.insert( KeyMap::value_type(SDLK_c, KC_C) ); mKeyMap.insert( KeyMap::value_type(SDLK_v, KC_V) ); mKeyMap.insert( KeyMap::value_type(SDLK_b, KC_B) ); mKeyMap.insert( KeyMap::value_type(SDLK_n, KC_N) ); mKeyMap.insert( KeyMap::value_type(SDLK_m, KC_M) ); mKeyMap.insert( KeyMap::value_type(SDLK_COMMA, KC_COMMA) ); mKeyMap.insert( KeyMap::value_type(SDLK_PERIOD, KC_PERIOD)); mKeyMap.insert( KeyMap::value_type(SDLK_RSHIFT, KC_RSHIFT)); mKeyMap.insert( KeyMap::value_type(SDLK_KP_MULTIPLY, KC_MULTIPLY) ); mKeyMap.insert( KeyMap::value_type(SDLK_LALT, KC_LMENU) ); mKeyMap.insert( KeyMap::value_type(SDLK_SPACE, KC_SPACE)); mKeyMap.insert( KeyMap::value_type(SDLK_CAPSLOCK, KC_CAPITAL) ); mKeyMap.insert( KeyMap::value_type(SDLK_F1, KC_F1) ); mKeyMap.insert( KeyMap::value_type(SDLK_F2, KC_F2) ); mKeyMap.insert( KeyMap::value_type(SDLK_F3, KC_F3) ); mKeyMap.insert( KeyMap::value_type(SDLK_F4, KC_F4) ); mKeyMap.insert( KeyMap::value_type(SDLK_F5, KC_F5) ); mKeyMap.insert( KeyMap::value_type(SDLK_F6, KC_F6) ); mKeyMap.insert( KeyMap::value_type(SDLK_F7, KC_F7) ); mKeyMap.insert( KeyMap::value_type(SDLK_F8, KC_F8) ); mKeyMap.insert( KeyMap::value_type(SDLK_F9, KC_F9) ); mKeyMap.insert( KeyMap::value_type(SDLK_F10, KC_F10) ); mKeyMap.insert( KeyMap::value_type(SDLK_NUMLOCK, KC_NUMLOCK) ); mKeyMap.insert( KeyMap::value_type(SDLK_SCROLLOCK, KC_SCROLL)); mKeyMap.insert( KeyMap::value_type(SDLK_KP7, KC_NUMPAD7) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP8, KC_NUMPAD8) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP9, KC_NUMPAD9) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP_MINUS, KC_SUBTRACT) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP4, KC_NUMPAD4) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP5, KC_NUMPAD5) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP6, KC_NUMPAD6) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP_PLUS, KC_ADD) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP1, KC_NUMPAD1) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP2, KC_NUMPAD2) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP3, KC_NUMPAD3) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP0, KC_NUMPAD0) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP_PERIOD, KC_DECIMAL) ); mKeyMap.insert( KeyMap::value_type(SDLK_F11, KC_F11) ); mKeyMap.insert( KeyMap::value_type(SDLK_F12, KC_F12) ); mKeyMap.insert( KeyMap::value_type(SDLK_F13, KC_F13) ); mKeyMap.insert( KeyMap::value_type(SDLK_F14, KC_F14) ); mKeyMap.insert( KeyMap::value_type(SDLK_F15, KC_F15) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP_EQUALS, KC_NUMPADEQUALS) ); mKeyMap.insert( KeyMap::value_type(SDLK_KP_DIVIDE, KC_DIVIDE) ); mKeyMap.insert( KeyMap::value_type(SDLK_SYSREQ, KC_SYSRQ) ); mKeyMap.insert( KeyMap::value_type(SDLK_RALT, KC_RMENU) ); mKeyMap.insert( KeyMap::value_type(SDLK_HOME, KC_HOME) ); mKeyMap.insert( KeyMap::value_type(SDLK_UP, KC_UP) ); mKeyMap.insert( KeyMap::value_type(SDLK_PAGEUP, KC_PGUP) ); mKeyMap.insert( KeyMap::value_type(SDLK_LEFT, KC_LEFT) ); mKeyMap.insert( KeyMap::value_type(SDLK_RIGHT, KC_RIGHT) ); mKeyMap.insert( KeyMap::value_type(SDLK_END, KC_END) ); mKeyMap.insert( KeyMap::value_type(SDLK_DOWN, KC_DOWN) ); mKeyMap.insert( KeyMap::value_type(SDLK_PAGEDOWN, KC_PGDOWN) ); mKeyMap.insert( KeyMap::value_type(SDLK_INSERT, KC_INSERT) ); mKeyMap.insert( KeyMap::value_type(SDLK_DELETE, KC_DELETE) ); mKeyMap.insert( KeyMap::value_type(SDLK_LSUPER, KC_LWIN) ); mKeyMap.insert( KeyMap::value_type(SDLK_RSUPER, KC_RWIN) ); SDL_EnableUNICODE(1); } //-------------------------------------------------------------------// SDLKeyboard::~SDLKeyboard() { } //-------------------------------------------------------------------// void SDLKeyboard::capture() { SDL_Event events[OIS_SDL_KEY_BUFF]; int count = SDL_PeepEvents(events, OIS_SDL_KEY_BUFF, SDL_GETEVENT, SDL_EVENTMASK(SDL_KEYDOWN) | SDL_EVENTMASK(SDL_KEYUP)); for( int i = 0; i < count; ++i ) { KeyCode kc = mKeyMap[events[i].key.keysym.sym]; KeyBuffer[kc] = events[i].key.state; if( mBuffered && listener ) { if( events[i].key.state == SDL_PRESSED ) { if( listener->keyPressed(KeyEvent(this, 0, kc, events[i].key.keysym.unicode)) == false ) break; } else { if( listener->keyReleased(KeyEvent(this, 0, kc, events[i].key.keysym.unicode)) == false ) break; } } } //Release Grab mode on Alt-Tab combinations (for non-window systems) if( KeyBuffer[KC_RMENU] || KeyBuffer[KC_LMENU]) { if( KeyBuffer[KC_TAB] ) static_cast<SDLInputManager*>(InputManager::getSingletonPtr())->_setGrabMode(false); } } //-------------------------------------------------------------------// bool SDLKeyboard::isKeyDown( KeyCode key ) { return KeyBuffer[key] == 1 ? true : false; } //-------------------------------------------------------------------// const std::string& SDLKeyboard::getAsString( KeyCode kc ) { switch(kc) { case KC_ESCAPE: mGetString = SDL_GetKeyName(SDLK_ESCAPE); break; case KC_1: mGetString = SDL_GetKeyName(SDLK_1); break; case KC_2: mGetString = SDL_GetKeyName(SDLK_2); break; case KC_3: mGetString = SDL_GetKeyName(SDLK_3); break; case KC_4: mGetString = SDL_GetKeyName(SDLK_4); break; case KC_5: mGetString = SDL_GetKeyName(SDLK_5); break; case KC_6: mGetString = SDL_GetKeyName(SDLK_6); break; case KC_7: mGetString = SDL_GetKeyName(SDLK_7); break; case KC_8: mGetString = SDL_GetKeyName(SDLK_8); break; case KC_9: mGetString = SDL_GetKeyName(SDLK_9); break; case KC_0: mGetString = SDL_GetKeyName(SDLK_0); break; case KC_MINUS: mGetString = SDL_GetKeyName(SDLK_MINUS); break; case KC_EQUALS: mGetString = SDL_GetKeyName(SDLK_EQUALS); break; case KC_BACK: mGetString = SDL_GetKeyName(SDLK_BACKSPACE); break; case KC_TAB: mGetString = SDL_GetKeyName(SDLK_TAB); break; case KC_Q: mGetString = SDL_GetKeyName(SDLK_q); break; case KC_W: mGetString = SDL_GetKeyName(SDLK_w); break; case KC_E: mGetString = SDL_GetKeyName(SDLK_e); break; case KC_R: mGetString = SDL_GetKeyName(SDLK_r); break; case KC_T: mGetString = SDL_GetKeyName(SDLK_t); break; case KC_Y: mGetString = SDL_GetKeyName(SDLK_y); break; case KC_U: mGetString = SDL_GetKeyName(SDLK_u); break; case KC_I: mGetString = SDL_GetKeyName(SDLK_i); break; case KC_O: mGetString = SDL_GetKeyName(SDLK_o); break; case KC_P: mGetString = SDL_GetKeyName(SDLK_p); break; case KC_LBRACKET: mGetString = "["; break; case KC_RBRACKET: mGetString = "]"; break; case KC_RETURN: mGetString = SDL_GetKeyName(SDLK_RETURN); break; case KC_LCONTROL: mGetString = SDL_GetKeyName(SDLK_LCTRL); break; case KC_A: mGetString = SDL_GetKeyName(SDLK_a); break; case KC_S: mGetString = SDL_GetKeyName(SDLK_s); break; case KC_D: mGetString = SDL_GetKeyName(SDLK_d); break; case KC_F: mGetString = SDL_GetKeyName(SDLK_f); break; case KC_G: mGetString = SDL_GetKeyName(SDLK_g); break; case KC_H: mGetString = SDL_GetKeyName(SDLK_h); break; case KC_J: mGetString = SDL_GetKeyName(SDLK_j); break; case KC_K: mGetString = SDL_GetKeyName(SDLK_k); break; case KC_L: mGetString = SDL_GetKeyName(SDLK_l); break; case KC_SEMICOLON: mGetString = SDL_GetKeyName(SDLK_SEMICOLON); break; case KC_APOSTROPHE: mGetString = SDL_GetKeyName(SDLK_QUOTE); break; case KC_GRAVE: mGetString = SDL_GetKeyName(SDLK_BACKQUOTE); break; case KC_LSHIFT: mGetString = SDL_GetKeyName(SDLK_LSHIFT); break; case KC_BACKSLASH: mGetString = SDL_GetKeyName(SDLK_BACKSLASH); break; case KC_Z: mGetString = SDL_GetKeyName(SDLK_z); break; case KC_X: mGetString = SDL_GetKeyName(SDLK_x); break; case KC_C: mGetString = SDL_GetKeyName(SDLK_c); break; case KC_V: mGetString = SDL_GetKeyName(SDLK_v); break; case KC_B: mGetString = SDL_GetKeyName(SDLK_b); break; case KC_N: mGetString = SDL_GetKeyName(SDLK_n); break; case KC_M: mGetString = SDL_GetKeyName(SDLK_m); break; case KC_COMMA: mGetString = SDL_GetKeyName(SDLK_COMMA); break; case KC_PERIOD: mGetString = SDL_GetKeyName(SDLK_PERIOD); break; case KC_SLASH: mGetString = SDL_GetKeyName(SDLK_SLASH); break; case KC_RSHIFT: mGetString = SDL_GetKeyName(SDLK_RSHIFT); break; case KC_MULTIPLY: mGetString = SDL_GetKeyName(SDLK_KP_MULTIPLY); break; case KC_LMENU: mGetString = SDL_GetKeyName(SDLK_LALT); break; case KC_SPACE: mGetString = SDL_GetKeyName(SDLK_SPACE); break; case KC_CAPITAL: mGetString = SDL_GetKeyName(SDLK_CAPSLOCK); break; case KC_F1: mGetString = SDL_GetKeyName(SDLK_F1); break; case KC_F2: mGetString = SDL_GetKeyName(SDLK_F2); break; case KC_F3: mGetString = SDL_GetKeyName(SDLK_F3); break; case KC_F4: mGetString = SDL_GetKeyName(SDLK_F4); break; case KC_F5: mGetString = SDL_GetKeyName(SDLK_F5); break; case KC_F6: mGetString = SDL_GetKeyName(SDLK_F6); break; case KC_F7: mGetString = SDL_GetKeyName(SDLK_F7); break; case KC_F8: mGetString = SDL_GetKeyName(SDLK_F8); break; case KC_F9: mGetString = SDL_GetKeyName(SDLK_F9); break; case KC_F10: mGetString = SDL_GetKeyName(SDLK_F10); break; case KC_NUMLOCK: mGetString = SDL_GetKeyName(SDLK_NUMLOCK); break; case KC_SCROLL: mGetString = SDL_GetKeyName(SDLK_SCROLLOCK); break; case KC_NUMPAD7: mGetString = SDL_GetKeyName(SDLK_KP7); break; case KC_NUMPAD8: mGetString = SDL_GetKeyName(SDLK_KP8); break; case KC_NUMPAD9: mGetString = SDL_GetKeyName(SDLK_KP9); break; case KC_SUBTRACT: mGetString = SDL_GetKeyName(SDLK_KP_MINUS); break; case KC_NUMPAD4: mGetString = SDL_GetKeyName(SDLK_KP4); break; case KC_NUMPAD5: mGetString = SDL_GetKeyName(SDLK_KP5); break; case KC_NUMPAD6: mGetString = SDL_GetKeyName(SDLK_KP6); break; case KC_ADD: mGetString = SDL_GetKeyName(SDLK_KP_PLUS); break; case KC_NUMPAD1: mGetString = SDL_GetKeyName(SDLK_KP1); break; case KC_NUMPAD2: mGetString = SDL_GetKeyName(SDLK_KP2); break; case KC_NUMPAD3: mGetString = SDL_GetKeyName(SDLK_KP3); break; case KC_NUMPAD0: mGetString = SDL_GetKeyName(SDLK_KP0); break; case KC_DECIMAL: mGetString = SDL_GetKeyName(SDLK_KP_PERIOD); break; case KC_OEM_102: mGetString = "OEM_102"; break; case KC_F11: mGetString = SDL_GetKeyName(SDLK_F11); break; case KC_F12: mGetString = SDL_GetKeyName(SDLK_F12); break; case KC_F13: mGetString = SDL_GetKeyName(SDLK_F13); break; case KC_F14: mGetString = SDL_GetKeyName(SDLK_F14); break; case KC_F15: mGetString = SDL_GetKeyName(SDLK_F15); break; case KC_KANA: mGetString = "Kana"; break; case KC_ABNT_C1: mGetString = "ABNT_C1"; break; case KC_CONVERT: mGetString = "CONVERT"; break; case KC_NOCONVERT: mGetString = "NOCONVERT"; break; case KC_YEN: mGetString = "YEN"; break; case KC_ABNT_C2: mGetString = "ABNT_C2"; break; case KC_NUMPADEQUALS: mGetString = SDL_GetKeyName(SDLK_KP_EQUALS); break; case KC_PREVTRACK: mGetString = "KC_PREVTRACK"; break; case KC_AT: mGetString = "KC_AT"; break; case KC_COLON: mGetString = SDL_GetKeyName(SDLK_COLON); break; case KC_UNDERLINE: mGetString = "KC_UNDERLINE"; break; case KC_KANJI: mGetString = "KC_KANJI"; break; case KC_STOP: mGetString = "KC_STOP"; break; case KC_AX: mGetString = "KC_AX"; break; case KC_UNLABELED: mGetString = "KC_UNLABELED"; break; case KC_NEXTTRACK: mGetString = "KC_NEXTTRACK"; break; case KC_NUMPADENTER: mGetString = "KC_NUMPADENTER"; break; case KC_RCONTROL: mGetString = "KC_RCONTROL"; break; case KC_MUTE: mGetString = "KC_MUTE"; break; case KC_CALCULATOR: mGetString = "KC_CALCULATOR"; break; case KC_PLAYPAUSE: mGetString = "KC_PLAYPAUSE"; break; case KC_MEDIASTOP: mGetString = "KC_MEDIASTOP"; break; case KC_VOLUMEDOWN: mGetString = "KC_VOLUMEDOWN"; break; case KC_VOLUMEUP: mGetString = "KC_VOLUMEUP"; break; case KC_WEBHOME: mGetString = "KC_WEBHOME"; break; case KC_NUMPADCOMMA: mGetString = "KC_NUMPADCOMMA"; break; case KC_DIVIDE: mGetString = SDL_GetKeyName(SDLK_KP_DIVIDE); break; case KC_SYSRQ: mGetString = SDL_GetKeyName(SDLK_SYSREQ); break; case KC_RMENU: mGetString = SDL_GetKeyName(SDLK_RALT); break; case KC_PAUSE: mGetString = "Pause"; break; case KC_HOME: mGetString = SDL_GetKeyName(SDLK_HOME); break; case KC_UP: mGetString = SDL_GetKeyName(SDLK_UP); break; case KC_PGUP: mGetString = SDL_GetKeyName(SDLK_PAGEUP); break; case KC_LEFT: mGetString = SDL_GetKeyName(SDLK_LEFT); break; case KC_RIGHT: mGetString = SDL_GetKeyName(SDLK_RIGHT); break; case KC_END: mGetString = SDL_GetKeyName(SDLK_END); break; case KC_DOWN: mGetString = SDL_GetKeyName(SDLK_DOWN); break; case KC_PGDOWN: mGetString = SDL_GetKeyName(SDLK_PAGEDOWN); break; case KC_INSERT: mGetString = SDL_GetKeyName(SDLK_INSERT); break; case KC_DELETE: mGetString = SDL_GetKeyName(SDLK_DELETE); break; case KC_LWIN: mGetString = SDL_GetKeyName(SDLK_LSUPER); break; case KC_RWIN: mGetString = SDL_GetKeyName(SDLK_RSUPER); break; case KC_APPS: mGetString = "KC_APPS"; break; case KC_POWER: mGetString = "KC_POWER"; break; case KC_SLEEP: mGetString = "KC_SLEEP"; break; case KC_WAKE: mGetString = "KC_WAKE"; break; case KC_WEBSEARCH: mGetString = "KC_WEBSEARCH"; break; case KC_WEBFAVORITES: mGetString = "KC_WEBFAVORITES"; break; case KC_WEBREFRESH: mGetString = "KC_WEBREFRESH"; break; case KC_WEBSTOP: mGetString = "KC_WEBSTOP"; break; case KC_WEBFORWARD: mGetString = "KC_WEBFORWARD"; break; case KC_WEBBACK: mGetString = "KC_WEBBACK"; break; case KC_MYCOMPUTER: mGetString = "KC_MYCOMPUTER"; break; case KC_MAIL: mGetString = "KC_MAIL"; break; case KC_MEDIASELECT: mGetString = "KC_MEDIASELECT"; break; default: mGetString = "Unknown"; break; }; return mGetString; } //-------------------------------------------------------------------// void SDLKeyboard::copyKeyStates( char keys[256] ) { for(int i = 0; i < 256; ++i) keys[i] = KeyBuffer[i]; } //-------------------------------------------------------------------// void SDLKeyboard::setBuffered(bool buffered) { mBuffered = buffered; } //-------------------------------------------------------------------// void SDLKeyboard::setTextTranslation( TextTranslationMode mode ) { mTextMode = mode; if( mode == Off || mode == Ascii ) SDL_EnableUNICODE(0); else if( mode == Unicode ) SDL_EnableUNICODE(1); } --- NEW FILE: SDLKeyboard.h --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef _OIS_SDLKEYBOARD_H #define _OIS_SDLKEYBOARD_H #include "OISKeyboard.h" #include "SDL/SDLPrereqs.h" namespace OIS { class SDLKeyboard : public Keyboard { public: /** @remarks Constructor @param buffered True for buffered input mode */ SDLKeyboard( bool buffered ); virtual ~SDLKeyboard(); /** @copydoc Keyboard::isKeyDown */ virtual bool isKeyDown( KeyCode key ); /** @copydoc Keyboard::getAsString */ virtual const std::string& getAsString( KeyCode kc ); /** @copydoc Keyboard::copyKeyStates */ virtual void copyKeyStates( char keys[256] ); /** @copydoc Object::setBuffered */ virtual void setBuffered(bool buffered); /** @copydoc Object::capture */ virtual void capture(); /** @copydoc Object::queryInterface */ virtual Interface* queryInterface(Interface::IType type) {return 0;} /** @copydoc Object::_initialize */ virtual void _initialize(); /** @copydoc Object::setTextTranslation */ virtual void setTextTranslation( TextTranslationMode mode ); protected: SDLKeyboard() {} typedef std::map<SDLKey, KeyCode> KeyMap; KeyMap mKeyMap; unsigned char KeyBuffer[256]; Uint8* mSDLBuff; std::string mGetString; }; } #endif --- NEW FILE: SDLInputManager.h --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_SDLInputManager_H #define OIS_SDLInputManager_H #include "OISInputManager.h" #include "SDL/SDLPrereqs.h" namespace OIS { /** SDL Input Manager wrapper */ class SDLInputManager : public InputManager { public: SDLInputManager(); virtual ~SDLInputManager(); /** @copydoc InputManager::inputSystemName */ virtual const std::string& inputSystemName() { return iName; } /** @copydoc InputManager::numJoysticks */ virtual int numJoysticks(); /** @copydoc InputManager::numMice */ virtual int numMice(); /** @copydoc InputManager::numKeyBoards */ virtual int numKeyBoards(); /** @copydoc InputManager::createInputObject */ Object* createInputObject( Type iType, bool bufferMode ); /** @copydoc InputManager::destroyInputObject */ void destroyInputObject( Object* obj ); /** @copydoc InputManager::_initialize */ void _initialize( ParamList ¶mList ); //Utility methods to coordinate between mouse and keyboard grabbing bool _getGrabMode() {return mGrabbed;}; void _setGrabMode(bool grabbed) {mGrabbed = grabbed;} protected: //! internal class method for dealing with param list void _parseConfigSettings( ParamList ¶mList ); //! internal class method for finding attached devices void _enumerateDevices(); static const std::string iName; bool mGrabbed; }; } #endif --- NEW FILE: SDLPrereqs.h --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_SDLPrereqs_H #define OIS_SDLPrereqs_H #include "OISPrereqs.h" #ifdef OIS_APPLE_PLATFORM # include <SDL/SDL.h> #else # include <SDL.h> #endif #define OIS_SDL_KEY_BUFF 16 #define OIS_SDL_MOUSE_BUFF 50 #define OIS_SDL_JOY_BUFF 80 #endif --- NEW FILE: SDLMouse.h --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef _OIS_SDLMOUSE_H #define _OIS_SDLMOUSE_H #include "OISMouse.h" #include "SDL/SDLPrereqs.h" namespace OIS { class SDLMouse : public Mouse { public: SDLMouse( bool buffered ); virtual ~SDLMouse(); /** @copydoc Object::setBuffered */ virtual void setBuffered(bool buffered); /** @copydoc Object::capture */ virtual void capture(); /** @copydoc Object::queryInterface */ virtual Interface* queryInterface(Interface::IType type) {return 0;} /** @copydoc Object::_initialize */ virtual void _initialize(); void _setGrab(bool grabbed); void _setVisible(bool visible); protected: SDLMouse() {} bool mGrabbed; bool mRegainFocus; }; } #endif --- NEW FILE: SDLJoyStick.cpp --- --- NEW FILE: SDLMouse.cpp --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "SDL/SDLMouse.h" #include "SDL/SDLInputManager.h" #include "OISException.h" #include "OISEvents.h" using namespace OIS; //-------------------------------------------------------------------// SDLMouse::SDLMouse( bool buffered ) : mGrabbed(false), mRegainFocus(false) { mBuffered = buffered; mType = OISMouse; listener = 0; } //-------------------------------------------------------------------// void SDLMouse::_initialize() { //Clear old state mState.clear(); mRegainFocus = false; _setGrab(true); _setVisible(false); static_cast<SDLInputManager*>(InputManager::getSingletonPtr())->_setGrabMode(true); } //-------------------------------------------------------------------// SDLMouse::~SDLMouse() { _setGrab(true); _setVisible(true); static_cast<SDLInputManager*>(InputManager::getSingletonPtr())->_setGrabMode(false); } //-------------------------------------------------------------------// void SDLMouse::capture() { //Used for going from SDL Button to OIS button static const MouseButtonID ButtonMask[4] = {MB_Left, MB_Left, MB_Middle, MB_Right}; //Clear old relative values mState.relX = mState.relY = mState.relZ = 0; SDL_Event events[OIS_SDL_MOUSE_BUFF]; int count = SDL_PeepEvents(events, OIS_SDL_MOUSE_BUFF, SDL_GETEVENT, SDL_MOUSEEVENTMASK); bool mouseXYMoved = false; bool mouseZMoved = false; for( int i = 0; i < count; ++i ) { switch( events[i].type ) { case SDL_MOUSEMOTION: mouseXYMoved = true; break; case SDL_MOUSEBUTTONDOWN: { mRegainFocus = true; int sdlButton = events[i].button.button; if( sdlButton <= SDL_BUTTON_RIGHT ) { //Left, Right, or Middle mState.buttons |= (1 << ButtonMask[sdlButton]); if( mBuffered && listener ) if( listener->mousePressed(MouseEvent(this,0,mState), ButtonMask[sdlButton]) == false ) return; } else { //mouse Wheel mouseZMoved = true; if( sdlButton == SDL_BUTTON_WHEELUP ) mState.relZ += 120; else if( sdlButton == SDL_BUTTON_WHEELDOWN ) mState.relZ -= 120; } break; } case SDL_MOUSEBUTTONUP: { int sdlButton = events[i].button.button; if( sdlButton <= SDL_BUTTON_RIGHT ) { //Left, Right, or Middle mState.buttons &= ~(1 << ButtonMask[sdlButton]); if( mBuffered && listener ) if( listener->mouseReleased(MouseEvent(this,0,mState), ButtonMask[sdlButton]) == false ) return; } break; } } } //Handle X/Y axis move if( mouseXYMoved ) { SDL_GetMouseState( &mState.abX, &mState.abY ); SDL_GetRelativeMouseState( &mState.relX, &mState.relY ); if( mBuffered && listener ) listener->mouseMoved(MouseEvent(this, 0, mState)); } //Handle Z Motion if( mouseZMoved ) { mState.abZ += mState.relZ; if( mBuffered && listener ) listener->mouseMoved(MouseEvent(this, 0, mState)); } //Handle Alt-Tabbing SDLInputManager* man = static_cast<SDLInputManager*>(InputManager::getSingletonPtr()); if( man->_getGrabMode() == false ) { if( mRegainFocus == false && mGrabbed == true ) { //We had focus, but must release it now _setGrab(false); _setVisible(true); } else if( mRegainFocus == true && mGrabbed == false ) { //We are gaining focus back (mouse clicked in window) _setGrab(true); _setVisible(false); man->_setGrabMode(true); //Notify manager } } } //-------------------------------------------------------------------// void SDLMouse::setBuffered(bool buffered) { mBuffered = buffered; } //-------------------------------------------------------------------// void SDLMouse::_setGrab(bool grabbed) { if( grabbed ) SDL_WM_GrabInput(SDL_GRAB_ON); else SDL_WM_GrabInput(SDL_GRAB_OFF); mGrabbed = grabbed; } //-------------------------------------------------------------------// void SDLMouse::_setVisible(bool visible) { if( visible ) SDL_ShowCursor(SDL_ENABLE); else SDL_ShowCursor(SDL_DISABLE); } --- NEW FILE: SDLInputManager.cpp --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "SDL/SDLInputManager.h" #include "SDL/SDLKeyboard.h" #include "SDL/SDLMouse.h" #include "SDL/SDLJoyStick.h" #include "OISException.h" #include "OISObject.h" using namespace OIS; const std::string SDLInputManager::iName = "SDL Input Wrapper"; //--------------------------------------------------------------------------------// SDLInputManager::SDLInputManager() : mGrabbed(false) { } //--------------------------------------------------------------------------------// SDLInputManager::~SDLInputManager() { } //--------------------------------------------------------------------------------// void SDLInputManager::_initialize( ParamList ¶mList ) { Uint32 flags = SDL_WasInit(0); if( flags == 0 ) OIS_EXCEPT( E_General, "SDLInputManager::SDLInputManager >> SDL Not Initialized already!"); //Ok, now we have DirectInput, parse whatever extra settings were sent to us _parseConfigSettings( paramList ); _enumerateDevices(); } //--------------------------------------------------------------------------------// void SDLInputManager::_parseConfigSettings( ParamList ¶mList ) { } //--------------------------------------------------------------------------------// void SDLInputManager::_enumerateDevices() { } //--------------------------------------------------------------------------------// int SDLInputManager::numJoysticks() { return 0; } //--------------------------------------------------------------------------------// int SDLInputManager::numMice() { return 1; } //--------------------------------------------------------------------------------// int SDLInputManager::numKeyBoards() { return 1; } //----------------------------------------------------------------------------// Object* SDLInputManager::createInputObject( Type iType, bool bufferMode ) { Object* obj = 0; switch( iType ) { case OISKeyboard: obj = new SDLKeyboard( bufferMode ); break; case OISMouse: obj = new SDLMouse( bufferMode ); break; case OISJoyStick: default: OIS_EXCEPT( E_InputDeviceNotSupported, "Type not implemented"); } try { obj->_initialize(); } catch(...) { delete obj; throw; //rethrow } return obj; } //----------------------------------------------------------------------------// void SDLInputManager::destroyInputObject( Object* obj ) { if( obj == 0 ) return; delete obj; } --- NEW FILE: SDLJoyStick.h --- |
Update of /cvsroot/simspark/simspark/spark/utility/ois In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv13856 Added Files: Tag: projectx Makefile.am OIS.h OIS.pc.in OISConfig.h OISEffect.cpp OISEffect.h OISEvents.h OISException.h OISForceFeedback.cpp OISForceFeedback.h OISInputManager.cpp OISInputManager.h OISInterface.h OISJoyStick.cpp OISJoyStick.h OISKeyboard.cpp OISKeyboard.h OISMouse.h OISObject.cpp OISObject.h OISPrereqs.h README Log Message: added OIS Library sources --- NEW FILE: OISJoyStick.cpp --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "OISJoyStick.h" //VC7.1 had a problem with these not getting included.. //Perhaps a case of a crazy extreme optimizer :/ (moved to header) // The minimal axis value //const int OIS::JoyStick::MIN_AXIS = -32767; // The maximum axis value //const int OIS::JoyStick::MAX_AXIS = 32768; --- NEW FILE: OIS.h --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_OISALL_H #define OIS_OISALL_H #include "OISPrereqs.h" #include "OISObject.h" #include "OISMouse.h" #include "OISKeyboard.h" #include "OISJoyStick.h" #include "OISInterface.h" #include "OISInputManager.h" #include "OISForceFeedback.h" #include "OISException.h" #include "OISEvents.h" #include "OISEffect.h" #endif --- NEW FILE: OISConfig.h --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_CONFIG_HEADER #define OIS_CONFIG_HEADER //----------------------------------------------------------------------------// //* This file contains defines for building certain parts of this Lib //* This file is not meant for External inclusion. However, you can edit this //* file before a build to effect what features are used internally //----------------------------------------------------------------------------// /** @remarks These lines have no bearing on internal build of OIS. This is here for external build settings. Meaning, changing this does not require a rebuild of OIS. This just affects VC dll import settings, as the DLL build already defines this during its build for setting dll exports. The undefine here is here just incase you decide to only use DLL, and want to set it permently and recompile OIS too.. Avoid redefinition from DLL build of OIS. So, if wanting to link against DLL version, just uncomment these lines. */ //#ifdef OIS_DYNAMIC_LIB //# undef OIS_DYNAMIC_LIB //#endif //#define OIS_DYNAMIC_LIB #endif --- NEW FILE: OISObject.cpp --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ //#include "OISObject.h" --- NEW FILE: Makefile.am --- lib_LTLIBRARIES=libOIS.la if BUNDLE_SUPPORT sources = \ mac/MacHelpers.cpp mac/MacHelpers.h \ mac/MacInputManager.cpp mac/MacInputManager.h \ mac/MacKeyboard.cpp mac/MacKeyboard.h \ mac/MacMouse.cpp mac/MacMouse.h \ mac/MacPrereqs.h else sources = \ linux/EventHelpers.cpp linux/EventHelpers.h\ linux/LinuxInputManager.cpp linux/LinuxInputManager.h \ linux/LinuxJoyStickEvents.cpp linux/LinuxJoyStickEvents.h linux/LinuxJoyStick.h \ linux/LinuxForceFeedback.cpp linux/LinuxForceFeedback.h \ linux/LinuxKeyboard.cpp linux/LinuxKeyboard.h \ linux/LinuxMouse.cpp linux/LinuxMouse.h \ linux/LinuxPrereqs.h endif libOIS_la_SOURCES = OISInputManager.cpp \ OISObject.cpp \ OISEffect.cpp \ OISJoyStick.cpp \ OISKeyboard.cpp \ OISForceFeedback.cpp \ OIS.h \ OISConfig.h \ OISEffect.h \ OISEvents.h \ OISException.h \ OISForceFeedback.h \ OISInputManager.h \ OISInterface.h \ OISJoystick.h \ OISKeyboard.h \ OISMouse.h \ OISObject.h \ OISPrereqs.h \ $(sources) libOIS_la_LDFLAGS = -release 1.0.0 libOIS_la_LIBADD = -L/usr/X11R6/lib -lX11 -lXaw --- NEW FILE: OISException.h --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef _OIS_EXCEPTION_HEADER_ #define _OIS_EXCEPTION_HEADER_ namespace OIS { //! Simple enum's for dealing with exceptions enum _OISExport OIS_ERROR { E_InputDisconnected, E_InputDeviceNonExistant, E_InputDeviceNotSupported, E_DeviceFull, E_NotSupported, E_NotImplemented, E_Duplicate, E_InvalidParam, E_General }; /** @remarks Class for handling OIS exceptions. Much cleaner than checking every method for reurn value. */ class _OISExport Exception { //! Hidden default Exception() : eType(E_General), eLine(0), eFile(0) {} public: //! Creates exception object Exception( OIS_ERROR err, const char* str, int line, const char *file ) : eType(err), eLine(line), eFile(file) ,eText(str) {} //! The type of exception raised const OIS_ERROR eType; //! The line number it occurred on const int eLine; //! The source file const char* eFile; //! A message passed along when the exception was raised const char* eText; }; } //! Use this macro to handle exceptions easily #define OIS_EXCEPT( err, str ) throw( OIS::Exception(err, str, __LINE__, __FILE__) ) #endif //_OIS_EXCEPTION_HEADER_ --- NEW FILE: README --- ====================================================================================== ================ LICENSE ============================================================= ====================================================================================== The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. ====================================================================================== ================ LICENSE EXPLAINED =================================================== ====================================================================================== In case the license was not clear enough... Basically, you can link with this lib which puts no restrictions on what you have to license your code as. You can modify this lib, and not have release your changes. Though, as explained above, <bold> Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software </bold> This is to allow users the greatest flexibility in what you can use this lib for. ====================================================================================== ================ INFO ================================================================ ====================================================================================== Cross Platform Object Oriented Input Lib System. Meant to be very robust and compatiable with many systems and operating systems Win32/ Contains Visual Studio .Net Solution Files Contains CodeBlocks + MinGW + StlPort project files for OIS ---- Dependencies ------------------------------------------------------ DirectInput 8 Ogre & CEGUI 0.4.0 If building CEGUIOgre OIS Demo SDL/ A test bed for an OIS InputManager with SDL as the backend. Not recommended; however, useful for platforms with non-native OIS ports for temporary use. Linux/ ---- Dependencies ------------------------------------------------------ X11 Ogre (GLX Platform) & CEGUI 0.4.0 If building CEGUIOgre OIS Demo Newer Linux Kernel (2.6+ ?) for Event API - else, use --disable-joyevents Steps to build on Linux: ./bootstrap ./configure ./make && make install ---- Configure build options -------------------------------------------- ./configure --help --- List all configure options ./configure --disable-ogre --- Disables CEGUIOgre ActionMapping Demo ./configure --disable-joyevents --- Uses /dev/input/jsX instead of /dev/input/eventX LinuxCB/ Contains CodeBlock files for building OIS and Demos with codeblocks This project file looks for Ogre and other dependencies in /usr/local/lib and /usr/local/include. If installed elsewhere, modify the project settings. It also installs libOIS to ~/libs Mac/ XCode-1.5/ Non-complete native OIS port. XCode-2.2/ Working, complete, OIS port to OSX using SDL as a backend. --- NEW FILE: OISInputManager.h --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_InputManager_H #define OIS_InputManager_H #include "OISPrereqs.h" namespace OIS { /** Base Manager class. No longer a Singleton; so feel free to create as many InputManager's as you have windows. */ class _OISExport InputManager { public: /** @remarks Returns version number (useful in DLL/SO libs) @returns Bits: 1-8 Patch number, 9-16 Minor version, 17-32 Major version */ static unsigned int getVersionNumber(); /** @remarks Returns version string (useful in DLL/SO libs) @returns Version name */ static const char* getVersionName(); /** @remarks Creates appropriate input system dependent on platform. @param winHandle Contains OS specific window handle (such as HWND or X11 Window) @returns A pointer to the created manager, or raises Exception */ static InputManager* createInputSystem( std::size_t winHandle ); /** @remarks Creates appropriate input system dependent on platform. @param paramList ParamList contains OS specific info (such as HWND and HINSTANCE for window apps), and access mode. @returns A pointer to the created manager, or raises Exception */ static InputManager* createInputSystem( ParamList ¶mList ); /** @remarks Gets the name of the current input system.. eg. "Win32", "Linux", "XBox", etc */ virtual const std::string& inputSystemName() = 0; /** @remarks Destroys the InputManager @param manager Manager to destroy */ static void destroyInputSystem(InputManager* manager); /** @remarks Returns the number of joysticks found */ virtual int numJoysticks() = 0; /** @remarks Returns the number of mice found */ virtual int numMice() = 0; /** @remarks Returns the number of keyboards found */ virtual int numKeyBoards() = 0; /** @remarks Returns the type of input requested or raises Exception */ virtual Object* createInputObject( Type iType, bool bufferMode ) = 0; /** @remarks Destroys Input Object */ virtual void destroyInputObject( Object* obj ) = 0; protected: //! Internal... Called from createInputSystem virtual void _initialize(ParamList ¶mList) = 0; //These are hidden to prevent app from directly instantiating/deleting an InputManager class InputManager() {} virtual ~InputManager() {} }; } #endif --- NEW FILE: OISInterface.h --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_Interface_H #define OIS_Interface_H #include "OISPrereqs.h" namespace OIS { /** An Object's interface is a way to gain write access to devices which support it. For example, force feedack. */ class _OISExport Interface { public: virtual ~Interface() {}; //! Type of Interface enum IType { ForceFeedback, Reserved }; }; } #endif //OIS_Interface_H --- NEW FILE: OISJoyStick.h --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_Joystick_H #define OIS_Joystick_H #include "OISObject.h" #include "OISEvents.h" namespace OIS { //! POV / HAT Joystick component struct _OISExport Pov : Component { Pov() : Component(OIS_POV), direction(0) {} static const int Centered = 0x00000000; static const int North = 0x00000001; static const int South = 0x00000010; static const int East = 0x00000100; static const int West = 0x00001000; static const int NorthEast = 0x00000101; static const int SouthEast = 0x00000110; static const int NorthWest = 0x00001001; static const int SouthWest = 0x00001010; int direction; }; //! A sliding axis - only used in Win32 Right Now struct _OISExport Slider : Component { Slider() : Component(OIS_Slider), abX(0), abY(0) {}; //! true if pushed, false otherwise int abX, abY; }; /** Represents the state of the joystick All members are valid for both buffered and non buffered mode Sticks with zero values are not present on the device */ struct _OISExport JoyStickState { JoyStickState() : buttons(0) { clear(); } //! Represents all the single axes on the device std::vector<Axis> mAxes; //! Represents the value of a POV. Maximum of 4 Pov mPOV[4]; //! Represent the max sliders Slider mSliders[4]; //! Represents All Buttons By Bit (max buttons = 32) int buttons; //! Button Bit Test - returns true if down inline int buttonDown( int button ) const { return ((buttons & ( 1L << button )) == 0) ? false : true; } //! internal method void clear() { buttons = 0; for( std::vector<Axis>::iterator i = mAxes.begin(), e = mAxes.end(); i != e; ++i ) { (*i).absOnly = true; //Currently, joysticks only report Abs (*i).clear(); } } }; /** Specialised for joystick events */ class _OISExport JoyStickEvent : public EventArg { public: JoyStickEvent( Object* obj, const JoyStickState &st ) : EventArg(obj), state(st) {} virtual ~JoyStickEvent() {} const JoyStickState &state; }; /** To recieve buffered joystick input, derive a class from this, and implement the methods here. Then set the call back to your JoyStick instance with JoyStick::setEventCallback Each JoyStick instance can use the same callback class, as a devID number will be provided to differentiate between connected joysticks. Of course, each can have a seperate callback instead. */ class _OISExport JoyStickListener { public: virtual ~JoyStickListener() {} virtual bool buttonPressed( const JoyStickEvent &arg, int button ) = 0; virtual bool buttonReleased( const JoyStickEvent &arg, int button ) = 0; virtual bool axisMoved( const JoyStickEvent &arg, int axis ) = 0; //Joystick Event, amd sliderID virtual bool sliderMoved( const JoyStickEvent &, int ) {return true;} //Joystick Event, amd povID virtual bool povMoved( const JoyStickEvent &, int ) {return true;} }; /** Joystick base class. To be implemented by specific system (ie. DirectX joystick) This class is useful as you remain OS independent using this common interface. */ class _OISExport JoyStick : public Object { public: virtual ~JoyStick() {} /** @remarks Returns the number of buttons */ short buttons() {return numButtons;} /** @remarks Returns the number of axes */ short axes() {return numAxes;} /** @remarks Returns the number of hats */ short hats() {return numHats;} /** @remarks Register/unregister a JoyStick Listener - Only one allowed for simplicity. If broadcasting is neccessary, just broadcast from the callback you registered. @param joyListener Send a pointer to a class derived from JoyStickListener or 0 to clear the callback */ virtual void setEventCallback( JoyStickListener *joyListener ) {listener = joyListener;} /** @remarks Returns currently set callback.. or null */ JoyStickListener* getEventCallback() {return listener;} /** @remarks Returns the state of the joystick - is valid for both buffered and non buffered mode */ const JoyStickState& getJoyStickState() const { return mState; } //! The minimal axis value static const int MIN_AXIS = -32768; //! The maximum axis value static const int MAX_AXIS = 32767; protected: JoyStick() : numButtons(0), numAxes(0), numHats(0), listener(0) {} short numButtons; short numAxes; short numHats; JoyStickState mState; JoyStickListener *listener; }; } #endif --- NEW FILE: OISEffect.cpp --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "OISEffect.h" #include "OISException.h" using namespace OIS; //VC7.1 had a problem with these not getting included.. //Perhaps a case of a crazy extreme optimizer :/ (moved to header) //const unsigned int Effect::OIS_INFINITE = 0xFFFFFFFF; //------------------------------------------------------------------------------// Effect::Effect() : force(UnknownForce), type(Unknown), effect(0), axes(1) { } //------------------------------------------------------------------------------// Effect::Effect(EForce ef, EType et) : force(ef), type(et), direction(North), trigger_button(-1), trigger_interval(0), replay_length(Effect::OIS_INFINITE), replay_delay(0), _handle(-1), axes(1) { effect = 0; switch( ef ) { case ConstantForce: effect = new ConstantEffect(); break; case RampForce: effect = new RampEffect(); break; case PeriodicForce: effect = new PeriodicEffect(); break; case ConditionalForce: effect = new ConditionalEffect(); break; default: break; } } //------------------------------------------------------------------------------// Effect::~Effect() { delete effect; } //------------------------------------------------------------------------------// ForceEffect* Effect::getForceEffect() const { //If no effect was created in constructor, then we raise an error here if( effect == 0 ) OIS_EXCEPT( E_NotSupported, "Requested ForceEffect is null!" ); return effect; } //------------------------------------------------------------------------------// void Effect::setNumAxes(short nAxes) { //Can only be set before a handle was assigned (effect created) if( _handle != -1 ) axes = nAxes; } //------------------------------------------------------------------------------// short Effect::getNumAxes() const { return axes; } --- NEW FILE: OISKeyboard.cpp --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "OISKeyboard.h" #include "OISException.h" using namespace OIS; //----------------------------------------------------------------------// Keyboard::Keyboard() : mModifiers(0), listener(0), mTextMode(Unicode) { } //----------------------------------------------------------------------// void Keyboard::setTextTranslation( TextTranslationMode mode ) { mTextMode = mode; } //----------------------------------------------------------------------// bool Keyboard::isModifierDown( Modifier mod ) { #if defined(OIS_MSVC_COMPILER) #pragma warning (push) #pragma warning (disable : 4800) #endif return (mModifiers & mod); #if defined(OIS_MSVC_COMPILER) #pragma warning (pop) #endif } --- NEW FILE: OISKeyboard.h --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_Keyboard_H #define OIS_Keyboard_H #include "OISObject.h" #include "OISEvents.h" namespace OIS { //! Keyboard scan codes enum KeyCode { KC_UNASSIGNED = 0x00, KC_ESCAPE = 0x01, KC_1 = 0x02, KC_2 = 0x03, KC_3 = 0x04, KC_4 = 0x05, KC_5 = 0x06, KC_6 = 0x07, KC_7 = 0x08, KC_8 = 0x09, KC_9 = 0x0A, KC_0 = 0x0B, KC_MINUS = 0x0C, // - on main keyboard KC_EQUALS = 0x0D, KC_BACK = 0x0E, // backspace KC_TAB = 0x0F, KC_Q = 0x10, KC_W = 0x11, KC_E = 0x12, KC_R = 0x13, KC_T = 0x14, KC_Y = 0x15, KC_U = 0x16, KC_I = 0x17, KC_O = 0x18, KC_P = 0x19, KC_LBRACKET = 0x1A, KC_RBRACKET = 0x1B, KC_RETURN = 0x1C, // Enter on main keyboard KC_LCONTROL = 0x1D, KC_A = 0x1E, KC_S = 0x1F, KC_D = 0x20, KC_F = 0x21, KC_G = 0x22, KC_H = 0x23, KC_J = 0x24, KC_K = 0x25, KC_L = 0x26, KC_SEMICOLON = 0x27, KC_APOSTROPHE = 0x28, KC_GRAVE = 0x29, // accent KC_LSHIFT = 0x2A, KC_BACKSLASH = 0x2B, KC_Z = 0x2C, KC_X = 0x2D, KC_C = 0x2E, KC_V = 0x2F, KC_B = 0x30, KC_N = 0x31, KC_M = 0x32, KC_COMMA = 0x33, KC_PERIOD = 0x34, // . on main keyboard KC_SLASH = 0x35, // / on main keyboard KC_RSHIFT = 0x36, KC_MULTIPLY = 0x37, // * on numeric keypad KC_LMENU = 0x38, // left Alt KC_SPACE = 0x39, KC_CAPITAL = 0x3A, KC_F1 = 0x3B, KC_F2 = 0x3C, KC_F3 = 0x3D, KC_F4 = 0x3E, KC_F5 = 0x3F, KC_F6 = 0x40, KC_F7 = 0x41, KC_F8 = 0x42, KC_F9 = 0x43, KC_F10 = 0x44, KC_NUMLOCK = 0x45, KC_SCROLL = 0x46, // Scroll Lock KC_NUMPAD7 = 0x47, KC_NUMPAD8 = 0x48, KC_NUMPAD9 = 0x49, KC_SUBTRACT = 0x4A, // - on numeric keypad KC_NUMPAD4 = 0x4B, KC_NUMPAD5 = 0x4C, KC_NUMPAD6 = 0x4D, KC_ADD = 0x4E, // + on numeric keypad KC_NUMPAD1 = 0x4F, KC_NUMPAD2 = 0x50, KC_NUMPAD3 = 0x51, KC_NUMPAD0 = 0x52, KC_DECIMAL = 0x53, // . on numeric keypad KC_OEM_102 = 0x56, // < > | on UK/Germany keyboards KC_F11 = 0x57, KC_F12 = 0x58, KC_F13 = 0x64, // (NEC PC98) KC_F14 = 0x65, // (NEC PC98) KC_F15 = 0x66, // (NEC PC98) KC_KANA = 0x70, // (Japanese keyboard) KC_ABNT_C1 = 0x73, // / ? on Portugese (Brazilian) keyboards KC_CONVERT = 0x79, // (Japanese keyboard) KC_NOCONVERT = 0x7B, // (Japanese keyboard) KC_YEN = 0x7D, // (Japanese keyboard) KC_ABNT_C2 = 0x7E, // Numpad . on Portugese (Brazilian) keyboards KC_NUMPADEQUALS= 0x8D, // = on numeric keypad (NEC PC98) KC_PREVTRACK = 0x90, // Previous Track (KC_CIRCUMFLEX on Japanese keyboard) KC_AT = 0x91, // (NEC PC98) KC_COLON = 0x92, // (NEC PC98) KC_UNDERLINE = 0x93, // (NEC PC98) KC_KANJI = 0x94, // (Japanese keyboard) KC_STOP = 0x95, // (NEC PC98) KC_AX = 0x96, // (Japan AX) KC_UNLABELED = 0x97, // (J3100) KC_NEXTTRACK = 0x99, // Next Track KC_NUMPADENTER = 0x9C, // Enter on numeric keypad KC_RCONTROL = 0x9D, KC_MUTE = 0xA0, // Mute KC_CALCULATOR = 0xA1, // Calculator KC_PLAYPAUSE = 0xA2, // Play / Pause KC_MEDIASTOP = 0xA4, // Media Stop KC_VOLUMEDOWN = 0xAE, // Volume - KC_VOLUMEUP = 0xB0, // Volume + KC_WEBHOME = 0xB2, // Web home KC_NUMPADCOMMA = 0xB3, // , on numeric keypad (NEC PC98) KC_DIVIDE = 0xB5, // / on numeric keypad KC_SYSRQ = 0xB7, KC_RMENU = 0xB8, // right Alt KC_PAUSE = 0xC5, // Pause KC_HOME = 0xC7, // Home on arrow keypad KC_UP = 0xC8, // UpArrow on arrow keypad KC_PGUP = 0xC9, // PgUp on arrow keypad KC_LEFT = 0xCB, // LeftArrow on arrow keypad KC_RIGHT = 0xCD, // RightArrow on arrow keypad KC_END = 0xCF, // End on arrow keypad KC_DOWN = 0xD0, // DownArrow on arrow keypad KC_PGDOWN = 0xD1, // PgDn on arrow keypad KC_INSERT = 0xD2, // Insert on arrow keypad KC_DELETE = 0xD3, // Delete on arrow keypad KC_LWIN = 0xDB, // Left Windows key KC_RWIN = 0xDC, // Right Windows key KC_APPS = 0xDD, // AppMenu key KC_POWER = 0xDE, // System Power KC_SLEEP = 0xDF, // System Sleep KC_WAKE = 0xE3, // System Wake KC_WEBSEARCH = 0xE5, // Web Search KC_WEBFAVORITES= 0xE6, // Web Favorites KC_WEBREFRESH = 0xE7, // Web Refresh KC_WEBSTOP = 0xE8, // Web Stop KC_WEBFORWARD = 0xE9, // Web Forward KC_WEBBACK = 0xEA, // Web Back KC_MYCOMPUTER = 0xEB, // My Computer KC_MAIL = 0xEC, // Mail KC_MEDIASELECT = 0xED // Media Select }; /** Specialised for key events */ class _OISExport KeyEvent : public EventArg { public: KeyEvent( Object* obj, KeyCode kc, unsigned int txt ) : EventArg(obj), key(kc), text(txt) {} virtual ~KeyEvent() {} //! KeyCode of event const KeyCode key; //! Text character, depends on current TextTranslationMode unsigned int text; }; /** To recieve buffered keyboard input, derive a class from this, and implement the methods here. Then set the call back to your Keyboard instance with Keyboard::setEventCallback */ class _OISExport KeyListener { public: virtual ~KeyListener() {} virtual bool keyPressed( const KeyEvent &arg ) = 0; virtual bool keyReleased( const KeyEvent &arg ) = 0; }; /** Keyboard base class. To be implemented by specific system (ie. DirectX Keyboard) This class is useful as you remain OS independent using this common interface. */ class _OISExport Keyboard : public Object { public: virtual ~Keyboard() {}; /** @remarks Returns true if key is donwn @param key A KeyCode to check */ virtual bool isKeyDown( KeyCode key ) = 0; /** @remarks Register/unregister a Keyboard Listener - Only one allowed for simplicity. If broadcasting is neccessary, just broadcast from the callback you registered. @param keyListener Send a pointer to a class derived from KeyListener or 0 to clear the callback */ virtual void setEventCallback( KeyListener *keyListener ) {listener=keyListener;} /** @remarks Returns currently set callback.. or 0 */ KeyListener* getEventCallback() {return listener;} //! TextTranslation Mode enum TextTranslationMode { Off, Unicode, Ascii }; /** @remarks Enable extra processing to translate KC_*** to an actual text character based off of locale. Different managers may implement none or all. Check the translation mode after setting to be sure @param mode Off, Unicode, Ascii */ virtual void setTextTranslation( TextTranslationMode mode ); /** @remarks Returns current translation mode */ TextTranslationMode getTextTranslation(){return mTextMode;} /** @remarks Translates KeyCode to string representation. For example, KC_ENTER will be "Enter" - Locale specific of course. @param kc KeyCode to convert @returns The string as determined from the current locale */ virtual const std::string& getAsString( KeyCode kc ) = 0; //! Enum of bit position of modifer enum Modifier { Shift = 0x0000001, Ctrl = 0x0000010, Alt = 0x0000100 }; /** @remarks Check modifier status */ bool isModifierDown( Modifier mod ); /** @remarks Copies the state of the keys into the sent buffer (in the form of 1 is down and 0 is up) */ virtual void copyKeyStates( char keys[256] ) = 0; protected: Keyboard(); //! Bit field that holds status of Alt, Ctrl, Shift unsigned int mModifiers; //! Used for buffered/actionmapping callback KeyListener *listener; //! The current translation mode TextTranslationMode mTextMode; }; } #endif --- NEW FILE: OISEvents.h --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef _OIS_EVENTHEADERS_ #define _OIS_EVENTHEADERS_ #include "OISPrereqs.h" namespace OIS { /** Base class of all events */ class _OISExport EventArg { public: EventArg( Object* obj ) : device(obj) {} virtual ~EventArg() {} //! Pointer to the Input Device const Object* device; }; } #endif //_OIS_EVENTHEADERS_ --- NEW FILE: OIS.pc.in --- prefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ Name: OIS Description: Crossplatform C++ Input Framework Version: @VERSION@ Libs: -L${libdir} -lOIS Cflags: -I${includedir}/@PACKAGE@ -I${includedir} --- NEW FILE: OISPrereqs.h --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_Prereqs_H #define OIS_Prereqs_H //----------------------------------------------------------------------------// //* This Header File contains forward declared classes *// //* Also, common properties for the keyboard and mouse *// //* There is also preprocessor defines to determine type of OS *// //----------------------------------------------------------------------------// //-------------- Common STL Containers ---------------------------------------// #include <vector> #include <string> #include <map> #include "OISConfig.h" // Default is blank for most OS's #define _OISExport //-------------- Determine Compiler --------------------------------- #if defined( _MSC_VER ) # define OIS_MSVC_COMPILER #elif defined( __GNUC__ ) # if defined( __WIN32__ ) || defined( _WIN32 ) # define OIS_MINGW_COMPILER # else # define OIS_GCC_COMPILER # endif #elif defined( __BORLANDC__ ) # define OIS_BORLAND_COMPILER #else # error No Recognized Compiler! #endif // --------------- Determine Operating System Platform --------------- #if defined( __WIN32__ ) || defined( _WIN32 ) // Windows 2000, XP, ETC # if defined ( _XBOX ) # define OIS_XBOX_PLATFORM # else # define OIS_WIN32_PLATFORM # if defined( OIS_DYNAMIC_LIB ) && !defined(OIS_MINGW_COMPILER) # undef _OISExport //Ignorable Dll interface warning... # pragma warning (disable : 4251) # if defined( OIS_NONCLIENT_BUILD ) # define _OISExport __declspec( dllexport ) # else # define _OISExport __declspec( dllimport ) # endif # endif # endif #elif defined( __APPLE_CC__ ) // Apple OS X # define OIS_APPLE_PLATFORM #else //Probably Linux # define OIS_LINUX_PLATFORM #endif //Is Processor 32 or 64 bits... #if defined(__x86_64__) # define OIS_ARCH_64 #else # define OIS_ARCH_32 #endif //-------------- Common Classes, Enums, and Typdef's -------------------------// #define OIS_VERSION_MAJOR 1 #define OIS_VERSION_MINOR 0 #define OIS_VERSION_PATCH 0 #define OIS_VERSION_NAME "Nitro" #define OIS_VERSION ((OIS_VERSION_MAJOR << 16) | (OIS_VERSION_MINOR << 8) | OIS_VERSION_PATCH) namespace OIS { //Device Types class InputManager; class Object; class Keyboard; class Mouse; class JoyStick; class KeyListener; class MouseListener; class JoyStickListener; class Interface; class ForceFeedback; class Effect; //! Way to send OS nuetral parameters.. ie OS Window handles, modes, flags typedef _OISExport std::multimap<std::string, std::string> ParamList; //! Each Input class has a General Type variable, a form of RTTI enum _OISExport Type { OISUnknown = 0, OISKeyboard = 1, OISMouse = 2, OISJoyStick = 3, OISTablet = 4 }; //-------- Shared common components ------------------------// //! Base type for all device components (button, axis, etc) enum _OISExport ComponentType { OIS_Unknown = 0, OIS_Button = 1, //Key, mouse button, joy button, etc OIS_Axis = 2, OIS_Slider = 3, OIS_POV = 4 }; //! Base of all device components (button, axis, etc) struct _OISExport Component { Component() : cType(OIS_Unknown) {}; Component(ComponentType type) : cType(type) {}; //! Indicates what type of coponent this is ComponentType cType; }; //! Button can be a keyboard key, mouse button, etc struct _OISExport Button : Component { Button() {} Button(bool bPushed) : Component(OIS_Button), pushed(bPushed) {}; //! true if pushed, false otherwise bool pushed; }; //! Axis component struct _OISExport Axis : Component { Axis() : Component(OIS_Axis), abs(0), rel(0), absOnly(false) {}; //! Absoulte and Relative value components int abs, rel; //! Indicates if this Axis only supports Absoulte (ie JoyStick) bool absOnly; //! Used internally by OIS void clear() { abs = rel = 0; } }; } #endif //end if prereq header defined --- NEW FILE: OISMouse.h --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_Mouse_H #define OIS_Mouse_H #include "OISObject.h" #include "OISEvents.h" namespace OIS { //! Button ID for mouse devices enum MouseButtonID { MB_Left = 0, MB_Right, MB_Middle, MB_Button3, MB_Button4, MB_Button5, MB_Button6, MB_Button7 }; /** Represents the state of the mouse All members are valid for both buffered and non buffered mode */ struct _OISExport MouseState { MouseState() : width(50), height(50), buttons(0) {}; /** Represents the height/width of your display area.. used if mouse clipping or mouse grabbed in case of X11 - defaults to 50.. Make sure to set this and change when your size changes.. */ mutable int width, height; //! X Axis component Axis X; //! Y Axis Component Axis Y; //! Z Axis Component Axis Z; //! represents all buttons - bit position indicates button down int buttons; //! Button down test inline bool buttonDown( MouseButtonID button ) const { return ((buttons & ( 1L << button )) == 0) ? false : true; } //! Clear all the values void clear() { X.clear(); Y.clear(); Z.clear(); buttons = 0; } }; /** Specialised for mouse events */ class _OISExport MouseEvent : public EventArg { public: MouseEvent( Object *obj, const MouseState &ms ) : EventArg(obj), state(ms) {} virtual ~MouseEvent() {} //! The state of the mouse - including buttons and axes const MouseState &state; }; /** To recieve buffered mouse input, derive a class from this, and implement the methods here. Then set the call back to your Mouse instance with Mouse::setEventCallback */ class _OISExport MouseListener { public: virtual ~MouseListener() {} virtual bool mouseMoved( const MouseEvent &arg ) = 0; virtual bool mousePressed( const MouseEvent &arg, MouseButtonID id ) = 0; virtual bool mouseReleased( const MouseEvent &arg, MouseButtonID id ) = 0; }; /** Mouse base class. To be implemented by specific system (ie. DirectX Mouse) This class is useful as you remain OS independent using this common interface. */ class _OISExport Mouse : public Object { public: virtual ~Mouse() {} /** @remarks Register/unregister a Mouse Listener - Only one allowed for simplicity. If broadcasting is neccessary, just broadcast from the callback you registered. @param mouseListener Send a pointer to a class derived from MouseListener or 0 to clear the callback */ virtual void setEventCallback( MouseListener *mouseListener ) {listener = mouseListener;} /** @remarks Returns currently set callback.. or 0 */ MouseListener* getEventCallback() {return listener;} /** @remarks Returns the state of the mouse - is valid for both buffered and non buffered mode */ const MouseState& getMouseState() const { return mState; } protected: Mouse() : listener(0) {} //! The state of the mouse MouseState mState; //! Used for buffered/actionmapping callback MouseListener *listener; }; } #endif --- NEW FILE: OISObject.h --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_Object_H #define OIS_Object_H #include "OISPrereqs.h" #include "OISInterface.h" namespace OIS { /** The base class of all input types. */ class _OISExport Object { public: virtual ~Object() {} /** @remarks Get the type of device */ Type type() const { return mType; } /** @remarks Get the vender string name */ const std::string& vendor() const { return mVendor; } /** @remarks Get buffered mode - true is buffered, false otherwise */ virtual bool buffered() const { return mBuffered; } /** @remarks Returns this input object's creator */ InputManager* getCreator() { return mCreator; } /** @remarks Sets buffered mode */ virtual void setBuffered(bool buffered) = 0; /** @remarks Used for updating call once per frame before checking state or to update events */ virtual void capture() = 0; /** @remarks Not fully implemented yet */ virtual int getID() const {return mDevID;} /** @remarks If available, get an interface to write to some devices. Examples include, turning on and off LEDs, ForceFeedback, etc @param type The type of interface you are looking for */ virtual Interface* queryInterface(Interface::IType type) = 0; /** @remarks Internal... Do not call this directly. */ virtual void _initialize() = 0; protected: Object() : mType(OISUnknown), mBuffered(false), mDevID(-1), mCreator(0) {} //! Vendor name if applicable/known std::string mVendor; //! Type of controller object Type mType; //! Buffered flag bool mBuffered; //! Not fully implemented yet int mDevID; //! The creator who created this object InputManager* mCreator; }; } #endif --- NEW FILE: OISInputManager.cpp --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "OISInputManager.h" #include "OISException.h" #include <sstream> //Bring in correct Header / InputManager for current build platform #if defined OIS_SDL_PLATFORM # include "SDL/SDLInputManager.h" #elif defined OIS_WIN32_PLATFORM # include "win32/Win32InputManager.h" #elif defined OIS_LINUX_PLATFORM # include "linux/LinuxInputManager.h" #elif defined OIS_APPLE_PLATFORM # include "mac/MacInputManager.h" #elif defined OIS_XBOX_PLATFORM # include "xbox/XBoxInputManager.h" #endif using namespace OIS; const char* gVersionName = OIS_VERSION_NAME; //----------------------------------------------------------------------------// unsigned int InputManager::getVersionNumber() { return OIS_VERSION; } //----------------------------------------------------------------------------// const char* InputManager::getVersionName() { return gVersionName; } //----------------------------------------------------------------------------// InputManager* InputManager::createInputSystem( std::size_t windowhandle ) { ParamList pl; std::ostringstream wnd; wnd << windowhandle; pl.insert(std::make_pair( std::string("WINDOW"), wnd.str() )); return createInputSystem( pl ); } //----------------------------------------------------------------------------// InputManager* InputManager::createInputSystem( ParamList ¶mList ) { InputManager* im = 0; #if defined OIS_SDL_PLATFORM im = new SDLInputManager(); #elif defined OIS_WIN32_PLATFORM im = new Win32InputManager(); #elif defined OIS_XBOX_PLATFORM im = new XBoxInputManager(); #elif defined OIS_LINUX_PLATFORM im = new LinuxInputManager(); #elif defined OIS_APPLE_PLATFORM im = new MacInputManager(); #else OIS_EXCEPT(E_General, "No platform library.. check build platform defines!"); #endif try { im->_initialize(paramList); } catch(...) { delete im; throw; //rethrow } return im; } //----------------------------------------------------------------------------// void InputManager::destroyInputSystem(InputManager* manager) { delete manager; } --- NEW FILE: OISForceFeedback.cpp --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "OISForceFeedback.h" #include "OISException.h" using namespace OIS; //-------------------------------------------------------------// void ForceFeedback::_addEffectTypes( Effect::EForce force, Effect::EType type ) { if( force == Effect::UnknownForce || type == Effect::Unknown ) OIS_EXCEPT( E_General, "Unknown Force||Type was added too effect list..." ); mSupportedEffects[force] = type; } //-------------------------------------------------------------// const ForceFeedback::SupportedEffectList& ForceFeedback::getSupportedEffects() const { return mSupportedEffects; } --- NEW FILE: OISForceFeedback.h --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_ForceFeedBack_H #define OIS_ForceFeedBack_H #include "OISPrereqs.h" #include "OISInterface.h" #include "OISEffect.h" namespace OIS { /** Interface class for dealing with Force Feedback devices */ class _OISExport ForceFeedback : public Interface { public: ForceFeedback() {} virtual ~ForceFeedback() {} /** @remarks This is like setting the master volume of an audio device. Individual effects have gain levels; however, this affects all effects at once. @param level A value between 0.0 and 1.0 represent the percentage of gain. 1.0 being the highest possible force level (means no scaling). */ virtual void setMasterGain( float level ) = 0; /** @remarks If using Force Feedback effects, this should be turned off before uploading any effects. Auto centering is the motor moving the joystick back to center. DirectInput only has an on/off setting, whereas linux has levels.. Though, we go with DI's on/off mode only @param auto_on true to turn auto centering on, false to turn off. */ virtual void setAutoCenterMode( bool auto_on ) = 0; /** @remarks Creates and Plays the effect immediately. If the device is full of effects, it will fail to be uploaded. You will know this by an invalid Effect Handle */ virtual void upload( const Effect* effect ) = 0; /** @remarks Modifies an effect that is currently playing */ virtual void modify( const Effect* effect ) = 0; /** @remarks Remove the effect from the device */ virtual void remove( const Effect* effect ) = 0; /** @remarks Get the number of supported Axes for FF usage */ virtual short getFFAxesNumber() = 0; typedef std::map<Effect::EForce, Effect::EType> SupportedEffectList; /** @remarks Get a list of all supported effects */ const SupportedEffectList& getSupportedEffects() const; void _addEffectTypes( Effect::EForce force, Effect::EType type ); protected: SupportedEffectList mSupportedEffects; }; } #endif //OIS_ForceFeedBack_H --- NEW FILE: OISEffect.h --- /* The zlib/libpng License Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef OIS_Effect_H #define OIS_Effect_H #include "OISPrereqs.h" namespace OIS { //Predeclare some Effect Property structs struct ForceEffect; struct ConstantEffect; struct RampEffect; struct PeriodicEffect; struct ConditionalEffect; /** Force Feedback is a relatively complex set of properties to upload to a device. The best place for information on the different properties, effects, etc is in the DX Documentation and MSDN - there are even pretty graphs ther =) As this class is modeled on the the DX interface you can apply that same knowledge to creating effects via this class on any OS supported by OIS. In anycase, this is the main class you will be using. There is *absolutely* no need to instance any of the supporting ForceEffect classes yourself. */ class _OISExport Effect { /** hidden so this class cannot be instanced with default constructor */ Effect(); public: //! Type of force enum EForce { UnknownForce = 0, ConstantForce, RampForce, PeriodicForce, ConditionalForce, CustomForce }; //! Type of effect enum EType { //Type ----- Pairs with force: Unknown = 0, //UnknownForce Constant, //ConstantForce Ramp, //RampForce Square, //PeriodicForce Triangle, //PeriodicForce Sine, //PeriodicForce SawToothUp, //PeriodicForce SawToothDown,//PeriodicForce Friction, //ConditionalForce Damper, //ConditionalForce Inertia, //ConditionalForce Spring, //ConditionalForce Custom //CustomForce }; //! Direction of the Force enum EDirection { NorthWest, North, NorthEast, East, SouthEast, South, SouthWest, West }; /** This constructor allows you to set the force type and effect. */ Effect(EForce ef, EType et); virtual ~Effect(); co... [truncated message content] |
From: Oliver O. <fr...@us...> - 2007-07-24 00:57:30
|
Update of /cvsroot/simspark/simspark/spark/utility/ois/mac In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv12593/mac Log Message: Directory /cvsroot/simspark/simspark/spark/utility/ois/mac added to the repository --> Using per-directory sticky tag `projectx' |