event.cpp

00001 
00002 /* Copyright (c) 2007-2009, Stefan Eilemann <eile@equalizergraphics.com> 
00003  *
00004  * This library is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Lesser General Public License version 2.1 as published
00006  * by the Free Software Foundation.
00007  *  
00008  * This library is distributed in the hope that it will be useful, but WITHOUT
00009  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00010  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00011  * details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this library; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016  */
00017 
00018 #include "event.h"
00019 
00020 #include <eq/base/idPool.h>
00021 
00022 #ifdef WIN32
00023 #  define bzero( ptr, size ) memset( ptr, 0, size );
00024 #else
00025 #  include <strings.h>
00026 #endif
00027 
00028 namespace eq
00029 {
00030 namespace
00031 {
00033 static std::string _eventTypeNames[ Event::ALL ] =
00034 {
00035     "window expose",
00036     "window resize",
00037     "window close",
00038     "window show",
00039     "window hide",
00040     "pointer motion",
00041     "pointer button press",
00042     "pointer button release",
00043     "key press",
00044     "key release",
00045     "channel resize",
00046     "statistic",
00047     "view resize",
00048     "magellan axis",
00049     "unknown",
00050     "user-specific"
00051 };
00052 }
00053 
00054 Event::Event()
00055         : type( UNKNOWN )
00056         , originator( EQ_ID_INVALID )
00057 {
00058 }
00059 
00060 EQ_EXPORT std::ostream& operator << ( std::ostream& os, const Event& event )
00061 {
00062     os << event.type << ':' << event.originator << ' ';
00063     switch( event.type )
00064     {
00065         case Event::WINDOW_EXPOSE:
00066         case Event::WINDOW_CLOSE:
00067             break;
00068 
00069         case Event::WINDOW_RESIZE:
00070         case Event::WINDOW_SHOW:
00071         case Event::WINDOW_HIDE:
00072         case Event::CHANNEL_RESIZE:
00073         case Event::VIEW_RESIZE:
00074             os << event.resize;
00075             break;
00076 
00077         case Event::POINTER_MOTION:
00078         case Event::POINTER_BUTTON_PRESS:
00079         case Event::POINTER_BUTTON_RELEASE:
00080             os << event.pointer;
00081             break;
00082 
00083         case Event::KEY_PRESS:
00084         case Event::KEY_RELEASE:
00085             os << event.key;
00086             break;
00087 
00088         case Event::STATISTIC:
00089             os << event.statistic;
00090 
00091         case Event::MAGELLAN_AXIS:
00092             os << event.magellan;
00093 
00094         default:
00095             break;
00096     }
00097     
00098     //os << ", context " << event.context <<;
00099     return os;
00100 }
00101 
00102 EQ_EXPORT std::ostream& operator << ( std::ostream& os, const Event::Type& type)
00103 {
00104     if( type >= Event::ALL )
00105         os << "unknown (" << static_cast<unsigned>( type ) << ')';
00106     else 
00107         os << _eventTypeNames[ type ];
00108 
00109     return os;
00110 }
00111 
00112 std::ostream& operator << ( std::ostream& os, const ResizeEvent& event )
00113 {
00114     os << event.x << 'x' << event.y << '+' << event.w << '+' << event.h << ' ';
00115     return os;
00116 }
00117 
00118 std::ostream& operator << ( std::ostream& os, const PointerEvent& event )
00119 {
00120     os << '[' << event.x << "], [" << event.y << "] d(" << event.dx << ", "
00121        << event.dy << ')' << " buttons ";
00122 
00123     if( event.buttons == PTR_BUTTON_NONE ) os << "none";
00124     if( event.buttons & PTR_BUTTON1 ) os << "1";
00125     if( event.buttons & PTR_BUTTON2 ) os << "2";
00126     if( event.buttons & PTR_BUTTON3 ) os << "3";
00127     if( event.buttons & PTR_BUTTON4 ) os << "4";
00128     if( event.buttons & PTR_BUTTON5 ) os << "5";
00129 
00130     os << " fired ";
00131     if( event.button == PTR_BUTTON_NONE ) os << "none";
00132     if( event.button & PTR_BUTTON1 ) os << "1";
00133     if( event.button & PTR_BUTTON2 ) os << "2";
00134     if( event.button & PTR_BUTTON3 ) os << "3";
00135     if( event.button & PTR_BUTTON4 ) os << "4";
00136     if( event.button & PTR_BUTTON5 ) os << "5";
00137 
00138     os << ' ';
00139     return os;
00140 }
00141 
00142 std::ostream& operator << ( std::ostream& os, const KeyEvent& event )
00143 {
00144     os << "key " << event.key << ' ';
00145     return os;
00146 }
00147 
00148 std::ostream& operator << ( std::ostream& os, const MagellanEvent& event )
00149 {
00150     os << " buttons " << event.buttons << " trans " << event.xAxis << ", "
00151        << event.yAxis << ", " << event.zAxis << " rot " << event.xRotation
00152        << ", " << event.yRotation << ", " << event.zRotation;
00153     return os;
00154 }
00155 
00156 }
Generated on Mon Aug 10 18:58:32 2009 for Equalizer 0.9 by  doxygen 1.5.8