OpenWalnut 1.3.1
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #ifndef WPICKINFO_H 00026 #define WPICKINFO_H 00027 00028 #include <stdint.h> 00029 00030 #include <string> 00031 #include <utility> 00032 00033 #include "../common/math/linearAlgebra/WLinearAlgebra.h" 00034 #include "../common/WDefines.h" 00035 00036 00037 /** 00038 * Encapsulates info for pick action. 00039 */ 00040 class WPickInfo 00041 { 00042 public: 00043 /** 00044 * Different types of modifier keys. 00045 */ 00046 enum modifierKey 00047 { 00048 NONE, 00049 SHIFT, 00050 STRG, 00051 ALT, 00052 WIN 00053 }; 00054 00055 /** 00056 * Different types of mouse buttons. 00057 */ 00058 typedef enum 00059 { 00060 NOMOUSE, 00061 MOUSE_LEFT, 00062 MOUSE_RIGHT, 00063 MOUSE_MIDDLE, 00064 MOUSE4, 00065 MOUSE5 00066 } 00067 WMouseButton; 00068 00069 /** 00070 * Creates an object with the needed information. 00071 * \param name name of picked object 00072 * \param viewerName name of the viewer 00073 * \param pickPosition position where object was hit 00074 * \param pixelCoords pixel coordinates of the mouse 00075 * \param modKey relevant modifier key pressed during the pick 00076 * \param mButton mouse button that initiated the pick 00077 * \param pickNormal normal at position where object was hit. (0,0,0) means not set. 00078 * \param wheelValue the value of the scroll wheel 00079 */ 00080 inline WPickInfo( std::string name, 00081 std::string viewerName, 00082 WPosition pickPosition, 00083 std::pair< float, float > pixelCoords, 00084 modifierKey modKey, 00085 WMouseButton mButton = WPickInfo::MOUSE_LEFT, 00086 WVector3d pickNormal = WVector3d(), 00087 int32_t wheelValue = 0 ); 00088 00089 /** 00090 * Creates an object with the empty name, zero position and no modkey. 00091 */ 00092 inline WPickInfo(); 00093 00094 /** 00095 * Get the modifier key associated with the pick 00096 * 00097 * \return the mod key 00098 */ 00099 inline modifierKey getModifierKey() const; 00100 00101 /** 00102 * Get the mouse button associated with the pick 00103 * 00104 * \return the mouse button 00105 */ 00106 inline WMouseButton getMouseButton() const; 00107 00108 /** 00109 * Set the modifier key associated with the pick 00110 * \param modKey new modifier key 00111 */ 00112 inline void setModifierKey( const modifierKey& modKey ); 00113 00114 /** 00115 * Set the modifier key associated with the pick 00116 * \param mButton new mouse button 00117 */ 00118 inline void setMouseButton( const WMouseButton& mButton ); 00119 00120 00121 /** 00122 * Get name of picked object. 00123 * 00124 * \return object name 00125 */ 00126 inline std::string getName() const; 00127 00128 /** 00129 * Get name of the viewer. 00130 * 00131 * \return viewer name 00132 */ 00133 inline std::string getViewerName() const; 00134 00135 /** 00136 * Get position where object was hit. 00137 * 00138 * \return the pick position 00139 */ 00140 inline WPosition getPickPosition() const; 00141 00142 /** 00143 * Get normal at position where object was hit. 00144 * 00145 * \return pick normal 00146 */ 00147 inline WVector3d getPickNormal() const; 00148 00149 /** 00150 * Returns the picked pixel coordinates in screen-space. 00151 * 00152 * \return the coordinates 00153 */ 00154 inline WVector2d getPickPixel() const; 00155 00156 /** 00157 * Returns an integer denoting the wheel movement. If the value gets smaller, the wheel scrolled down. 00158 * 00159 * \return the value. 00160 */ 00161 inline int32_t getScrollWheel() const; 00162 00163 /** 00164 * Tests two pick infos for equality 00165 * \param rhs right hand side of comparison 00166 * 00167 * \return true if equal 00168 */ 00169 inline bool operator==( WPickInfo rhs ) const; 00170 00171 /** 00172 * Tests two pick infos for inequality 00173 * 00174 * \param rhs right hand side of comparison 00175 * 00176 * \return true if not equal 00177 */ 00178 inline bool operator!=( WPickInfo rhs ) const; 00179 00180 protected: 00181 private: 00182 std::string m_name; //!< name of picked object. 00183 std::string m_viewerName; //!< name of the viewer 00184 WPosition m_pickPosition; //!< position where object was hit. 00185 std::pair< float, float > m_pixelCoords; //!< Pixel coordinates of the mouse. 00186 modifierKey m_modKey; //!< modifier key associated with the pick 00187 WMouseButton m_mouseButton; //!< which mouse button was used for the pick 00188 WVector3d m_pickNormal; //!< normal at position where object was hit. 00189 int32_t m_scrollValue; //!< the scroll wheel value. 00190 }; 00191 00192 WPickInfo::WPickInfo( std::string name, 00193 std::string viewerName, 00194 WPosition pickPosition, 00195 std::pair< float, float > pixelCoords, 00196 modifierKey modKey, 00197 WMouseButton mButton, 00198 WVector3d pickNormal, 00199 int32_t wheelValue ) : 00200 m_name( name ), 00201 m_viewerName( viewerName ), 00202 m_pickPosition( pickPosition ), 00203 m_pixelCoords( pixelCoords ), 00204 m_modKey( modKey ), 00205 m_mouseButton( mButton ), 00206 m_pickNormal( pickNormal ), 00207 m_scrollValue( wheelValue ) 00208 { 00209 } 00210 00211 WPickInfo::WPickInfo() : 00212 m_name( "" ), 00213 m_viewerName( "" ), 00214 m_pickPosition( WPosition() ), 00215 m_pixelCoords( std::make_pair( 0.0, 0.0 ) ), 00216 m_modKey( WPickInfo::NONE ), 00217 m_mouseButton( WPickInfo::MOUSE_LEFT ), 00218 m_scrollValue( 0 ) 00219 { 00220 } 00221 00222 WPickInfo::modifierKey WPickInfo::getModifierKey() const 00223 { 00224 return m_modKey; 00225 } 00226 00227 void WPickInfo::setModifierKey( const modifierKey& modKey ) 00228 { 00229 m_modKey = modKey; 00230 } 00231 00232 WPickInfo::WMouseButton WPickInfo::getMouseButton() const 00233 { 00234 return m_mouseButton; 00235 } 00236 00237 void WPickInfo::setMouseButton( const WMouseButton& mButton ) 00238 { 00239 m_mouseButton = mButton; 00240 } 00241 00242 std::string WPickInfo::getName() const 00243 { 00244 return m_name; 00245 } 00246 00247 std::string WPickInfo::getViewerName() const 00248 { 00249 return m_viewerName; 00250 } 00251 00252 WPosition WPickInfo::getPickPosition() const 00253 { 00254 return m_pickPosition; 00255 } 00256 00257 WVector3d WPickInfo::getPickNormal() const 00258 { 00259 return m_pickNormal; 00260 } 00261 00262 inline bool WPickInfo::operator==( WPickInfo rhs ) const 00263 { 00264 return ( this->m_name == rhs.m_name 00265 && this->m_pickPosition == rhs.m_pickPosition 00266 && this->m_modKey == rhs.m_modKey ); 00267 } 00268 00269 inline bool WPickInfo::operator!=( WPickInfo rhs ) const 00270 { 00271 return !( *this == rhs ); 00272 } 00273 00274 inline WVector2d WPickInfo::getPickPixel() const 00275 { 00276 WVector2d v; 00277 v[0] = m_pixelCoords.first; 00278 v[1] = m_pixelCoords.second; 00279 return v; 00280 } 00281 00282 inline int32_t WPickInfo::getScrollWheel() const 00283 { 00284 return m_scrollValue; 00285 } 00286 00287 #endif // WPICKINFO_H