Image Component Library (ICL)
|
00001 /******************************************************************** 00002 ** Image Component Library (ICL) ** 00003 ** ** 00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld ** 00005 ** Neuroinformatics Group ** 00006 ** Website: www.iclcv.org and ** 00007 ** http://opensource.cit-ec.de/projects/icl ** 00008 ** ** 00009 ** File : ICLGeom/src/ICLGeom/SceneMouseHandler.h ** 00010 ** Module : ICLGeom ** 00011 ** Authors: Christof Elbrechter, Erik Weitnauer, Daniel Dornbusch ** 00012 ** ** 00013 ** ** 00014 ** GNU LESSER GENERAL PUBLIC LICENSE ** 00015 ** This file may be used under the terms of the GNU Lesser General ** 00016 ** Public License version 3.0 as published by the ** 00017 ** ** 00018 ** Free Software Foundation and appearing in the file LICENSE.GPL ** 00019 ** included in the packaging of this file. Please review the ** 00020 ** following information to ensure the license requirements will ** 00021 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt ** 00022 ** ** 00023 ** The development of this software was supported by the ** 00024 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. ** 00025 ** The Excellence Cluster EXC 277 is a grant of the Deutsche ** 00026 ** Forschungsgemeinschaft (DFG) in the context of the German ** 00027 ** Excellence Initiative. ** 00028 ** ** 00029 ********************************************************************/ 00030 00031 #pragma once 00032 00033 #if !defined(HAVE_OPENGL) || !defined(HAVE_QT) 00034 #warning "this header must not be included if HAVE_OPENGL or HAVE_QT is not defined" 00035 #else 00036 00037 00038 #include <ICLGeom/Camera.h> 00039 #include <ICLQt/MouseHandler.h> 00040 00041 namespace icl{ 00042 00044 namespace qt{ 00045 class GUI; 00046 } 00049 namespace geom{ 00050 00052 00059 typedef void (*MouseActionCallback)(const qt::MouseEvent&,const utils::Point32f&, 00060 const utils::Point32f&,Camera&,void* ); 00061 00062 00064 class Scene; 00065 00066 00068 struct MouseMappingTableEntry{ 00070 MouseActionCallback mMouseAction; 00071 00073 void* mData; 00074 }; 00075 00076 00078 struct MouseSensitivities{ 00080 float mTranslation; 00081 00083 float mRotation; 00084 00086 float mMouse; 00087 00089 float mWheel; 00090 }; 00091 00092 00094 enum MouseSensitivitiesModifier{ 00095 LowMouseSensitivity = 0, 00096 NormalMouseSensitivity = 1, 00097 HighMouseSensitivity = 2, 00098 MAX_MOUSE_SENSITIVITY = HighMouseSensitivity 00099 }; 00100 00101 00103 00130 class SceneMouseHandler : public qt::MouseHandler{ 00131 protected: 00132 00134 00140 MouseMappingTableEntry mMouseMappingTable[qt::MAX_MOUSE_EVENT + 1][2][2][2][2][2][2]; 00141 00143 MouseSensitivities mMouseSensitivities[MAX_MOUSE_SENSITIVITY + 1]; 00144 00146 Camera mCameraBackup; 00147 00149 utils::Point32f mAnchor; 00150 00152 Scene* mParentScene; 00153 00155 int mCameraIndex; 00156 00158 int mKeyboardModifiersBackup; 00159 00161 qt::GUI *mGUI; 00162 00163 public: 00164 00166 00169 SceneMouseHandler(const int pCameraIndex, Scene* pParentScene ); 00170 00172 00173 SceneMouseHandler(const SceneMouseHandler& pSceneMouseHandler){ 00174 *this = pSceneMouseHandler; 00175 } 00176 00178 ~SceneMouseHandler(); 00179 00181 SceneMouseHandler& operator=(const SceneMouseHandler& pSceneMouseHandler); 00182 00184 void setParentScene(Scene* pParentScene){ 00185 mParentScene = pParentScene; 00186 } 00187 00189 Scene* getParentScene(){ 00190 return mParentScene; 00191 } 00192 00194 00200 void setSensitivities(const float pTranslation, const float pRotation = 1.0, 00201 const float pMouse = 1.0, const float pWheel = 0.001, 00202 const float pModifier = 10.0 ); 00203 00204 00206 00207 MouseSensitivities getSensitivities(MouseSensitivitiesModifier pMouseSensitivitiesModifier){ 00208 return mMouseSensitivities[pMouseSensitivitiesModifier]; 00209 }; 00210 00211 00213 00215 void setCameraIndex(const int pCameraIndex){ 00216 mCameraIndex = pCameraIndex; 00217 } 00218 00219 00221 00222 int getCameraIndex(){ 00223 return mCameraIndex; 00224 } 00225 00226 00228 00229 virtual void setMouseMappings(); 00230 00231 00233 00242 void setMouseMapping(const qt::MouseEventType pMouseEventType, 00243 const bool pLeftMouseButton, 00244 const bool pMiddleMouseButton, 00245 const bool pRightMouseButton, 00246 const bool pShift, 00247 const bool pControl, 00248 const bool pAlt, 00249 MouseActionCallback pMouseActionCallback, 00250 void* pData=0); 00251 00252 00254 00264 static void freeView(const qt::MouseEvent &pMouseEvent, 00265 const utils::Point32f &pCurrentMousePosition, 00266 const utils::Point32f &pDeltaMousePosition, 00267 Camera &pCamera, void *pData, 00268 bool pInverseX, bool pInverseY); 00269 00270 00272 00279 static void freeView(const qt::MouseEvent &pMouseEvent, 00280 const utils::Point32f &pCurrentMousePosition, 00281 const utils::Point32f &pDeltaMousePosition, 00282 Camera &pCamera, void *pData){ 00283 freeView( pMouseEvent, pCurrentMousePosition, pDeltaMousePosition, pCamera, pData, false, false ); 00284 } 00285 00286 00288 00295 static void freeViewInverseMouseX(const qt::MouseEvent &pMouseEvent, 00296 const utils::Point32f &pCurrentMousePosition, 00297 const utils::Point32f &pDeltaMousePosition, 00298 Camera &pCamera, void *pData){ 00299 freeView( pMouseEvent, pCurrentMousePosition, pDeltaMousePosition, pCamera, pData, true, false ); 00300 } 00301 00302 00304 00311 static void freeViewInverseMouseY(const qt::MouseEvent &pMouseEvent, 00312 const utils::Point32f &pCurrentMousePosition, 00313 const utils::Point32f &pDeltaMousePosition, 00314 Camera &pCamera, void *pData){ 00315 freeView( pMouseEvent, pCurrentMousePosition, pDeltaMousePosition, pCamera, pData, false, true ); 00316 } 00317 00318 00320 00328 static void freeViewInverseBoth(const qt::MouseEvent &pMouseEvent, 00329 const utils::Point32f &pCurrentMousePosition, 00330 const utils::Point32f &pDeltaMousePosition, 00331 Camera &pCamera, void *pData){ 00332 freeView( pMouseEvent, pCurrentMousePosition, pDeltaMousePosition, pCamera, pData, true, true ); 00333 } 00334 00335 00337 00344 static void rotateAroundOrigin(const qt::MouseEvent &pMouseEvent, 00345 const utils::Point32f &pCurrentMousePosition, 00346 const utils::Point32f &pDeltaMousePosition, 00347 Camera &pCamera, void *pData); 00348 00350 00357 static void strafe(const qt::MouseEvent &pMouseEvent, 00358 const utils::Point32f &pCurrentMousePosition, 00359 const utils::Point32f &pDeltaMousePosition, 00360 Camera &pCamera, void *pData); 00361 00363 00370 static void rollAndDistance(const qt::MouseEvent &pMouseEvent, 00371 const utils::Point32f &pCurrentMousePosition, 00372 const utils::Point32f &pDeltaMousePosition, 00373 Camera &pCamera, void *pData); 00374 00375 00377 00378 virtual void process(const qt::MouseEvent &pMouseEvent); 00379 }; 00380 00381 } // namespace geom 00382 } 00383 00384 #endif