From 61762232f78deb4b40db510689b5e536e7b20363 Mon Sep 17 00:00:00 2001 From: ouv Date: Tue, 23 Jan 2007 16:40:28 +0000 Subject: [PATCH] Added XZoom and YZoom parameters for GLObjects instead of simple Zoom. YZoom is changing by mouse wheel moving, XZoom - by ctrl+wheel --- src/GLViewer/GLViewer_Group.cxx | 23 +++++++++-- src/GLViewer/GLViewer_Group.h | 4 +- src/GLViewer/GLViewer_Object.cxx | 61 ++++++++++++++++++++++++------ src/GLViewer/GLViewer_Object.h | 17 +++++++-- src/GLViewer/GLViewer_Viewer2d.cxx | 5 ++- 5 files changed, 89 insertions(+), 21 deletions(-) diff --git a/src/GLViewer/GLViewer_Group.cxx b/src/GLViewer/GLViewer_Group.cxx index 646750490..8b13a3615 100644 --- a/src/GLViewer/GLViewer_Group.cxx +++ b/src/GLViewer/GLViewer_Group.cxx @@ -142,11 +142,11 @@ void GLViewer_Group::dragingObjects( float x, float y, bool once ) } /*! - Updates zoom of object + Updates horizontal zoom of object \param sender - object to be updated \param zoom - zoom coefficient */ -void GLViewer_Group::updateZoom( GLViewer_Object* sender, float zoom ) +void GLViewer_Group::updateXZoom( GLViewer_Object* sender, float zoom ) { OGIterator it = myList.begin(); OGIterator end_it = myList.end(); @@ -154,6 +154,23 @@ void GLViewer_Group::updateZoom( GLViewer_Object* sender, float zoom ) { GLViewer_Object* anObject = *it; if( anObject != sender ) - anObject->setZoom( zoom, true, true ); + anObject->setXZoom( zoom, true, true ); + } +} + +/*! + Updates horizontal zoom of object + \param sender - object to be updated + \param zoom - zoom coefficient +*/ +void GLViewer_Group::updateYZoom( GLViewer_Object* sender, float zoom ) +{ + OGIterator it = myList.begin(); + OGIterator end_it = myList.end(); + for( int i = 0; it != end_it; ++it, i++ ) + { + GLViewer_Object* anObject = *it; + if( anObject != sender ) + anObject->setYZoom( zoom, true, true ); } } diff --git a/src/GLViewer/GLViewer_Group.h b/src/GLViewer/GLViewer_Group.h index 4382b06c9..0731ca415 100644 --- a/src/GLViewer/GLViewer_Group.h +++ b/src/GLViewer/GLViewer_Group.h @@ -64,7 +64,9 @@ public: /*! Once = true, if this operation calls only one time for all object*/ void dragingObjects( float x, float y, bool once = false ); //!\warning it is for ouv - void updateZoom( GLViewer_Object* sender, float zoom ); + void updateXZoom( GLViewer_Object* sender, float zoom ); + //!\warning it is for ouv + void updateYZoom( GLViewer_Object* sender, float zoom ); private: //! List of objects diff --git a/src/GLViewer/GLViewer_Object.cxx b/src/GLViewer/GLViewer_Object.cxx index 7de98ed37..eb6b48ff0 100644 --- a/src/GLViewer/GLViewer_Object.cxx +++ b/src/GLViewer/GLViewer_Object.cxx @@ -39,7 +39,8 @@ GLViewer_Object::GLViewer_Object() myYScale = 1.0; myXGap = 0; myYGap = 0; - myZoom = 1.0; + myXZoom = 1.0; + myYZoom = 1.0; myIsHigh = GL_FALSE; myIsSel = GL_FALSE; @@ -97,39 +98,75 @@ GLboolean GLViewer_Object::isInside( GLViewer_Rect theRect ) } /*! - Sets zoom factor + Sets horizontal zoom factor \param zoom - zoom factor */ -GLboolean GLViewer_Object::setZoom( GLfloat zoom, bool, bool ) +GLboolean GLViewer_Object::setXZoom( GLfloat zoom, bool, bool ) { - if( myZoom == zoom ) + if( myXZoom == zoom ) return GL_FALSE; - myZoom = zoom; + myXZoom = zoom; return GL_TRUE; } /*! - Performs zoom change by step + Performs horizontal zoom change by step \param zoomIn - to increase to decrease zoom */ -GLboolean GLViewer_Object::updateZoom( bool zoomIn ) +GLboolean GLViewer_Object::updateXZoom( bool zoomIn ) { float newZoom; float step = zoomIn ? 1 : -1; double epsilon = 0.001; - if( myZoom - 1 > epsilon ) - newZoom = ( myZoom * 2 + step ) / 2; - else if( 1 - myZoom > epsilon ) - newZoom = 2 / ( 2 / myZoom - step ); + if( myXZoom - 1 > epsilon ) + newZoom = ( myXZoom * 2 + step ) / 2; + else if( 1 - myXZoom > epsilon ) + newZoom = 2 / ( 2 / myXZoom - step ); else newZoom = zoomIn ? 3./2. : 2./3.; if( newZoom < 0.01 || newZoom > 100.0 ) return GL_FALSE; - return setZoom( newZoom, true ); + return setXZoom( newZoom, true ); +} + +/*! + Sets vertical zoom factor + \param zoom - zoom factor +*/ +GLboolean GLViewer_Object::setYZoom( GLfloat zoom, bool, bool ) +{ + if( myYZoom == zoom ) + return GL_FALSE; + + myYZoom = zoom; + return GL_TRUE; +} + +/*! + Performs vertical zoom change by step + \param zoomIn - to increase to decrease zoom +*/ +GLboolean GLViewer_Object::updateYZoom( bool zoomIn ) +{ + float newZoom; + float step = zoomIn ? 1 : -1; + double epsilon = 0.001; + + if( myYZoom - 1 > epsilon ) + newZoom = ( myYZoom * 2 + step ) / 2; + else if( 1 - myYZoom > epsilon ) + newZoom = 2 / ( 2 / myYZoom - step ); + else + newZoom = zoomIn ? 3./2. : 2./3.; + + if( newZoom < 0.01 || newZoom > 100.0 ) + return GL_FALSE; + + return setYZoom( newZoom, true ); } /*! diff --git a/src/GLViewer/GLViewer_Object.h b/src/GLViewer/GLViewer_Object.h index 2384bb440..7bc1dfc68 100644 --- a/src/GLViewer/GLViewer_Object.h +++ b/src/GLViewer/GLViewer_Object.h @@ -139,11 +139,18 @@ public: virtual void getScale( GLfloat& xScale, GLfloat& yScale ) const { xScale = myXScale; yScale = myYScale;} //!\warning It is for ouv - virtual GLboolean setZoom( GLfloat zoom, bool recompute, bool fromGroup = false ); + virtual GLboolean setXZoom( GLfloat zoom, bool recompute, bool fromGroup = false ); //!\warning It is for ouv - virtual GLfloat getZoom() const { return myZoom; } + virtual GLfloat getXZoom() const { return myXZoom; } //!\warning It is for ouv - virtual GLboolean updateZoom( bool zoomIn ); + virtual GLboolean updateXZoom( bool zoomIn ); + + //!\warning It is for ouv + virtual GLboolean setYZoom( GLfloat yoom, bool recompute, bool fromGroup = false ); + //!\warning It is for ouv + virtual GLfloat getYZoom() const { return myYZoom; } + //!\warning It is for ouv + virtual GLboolean updateYZoom( bool zoomIn ); //! Returns true if object is highlighted virtual GLboolean isHighlighted() const { return myIsHigh; } @@ -273,7 +280,9 @@ protected: GLfloat myYGap; //!\warning It is for ouv - GLfloat myZoom; + GLfloat myXZoom; + //!\warning It is for ouv + GLfloat myYZoom; //! Highlight status /*! = true after right highlighting*/ diff --git a/src/GLViewer/GLViewer_Viewer2d.cxx b/src/GLViewer/GLViewer_Viewer2d.cxx index 7d03218ba..5884d07a4 100644 --- a/src/GLViewer/GLViewer_Viewer2d.cxx +++ b/src/GLViewer/GLViewer_Viewer2d.cxx @@ -1007,7 +1007,10 @@ void GLViewer_Viewer2d::startOperations( QWheelEvent* e ) for( myGLContext->InitSelected(); myGLContext->MoreSelected(); myGLContext->NextSelected() ) { GLViewer_Object* anObject = myGLContext->SelectedObject(); - update = anObject->updateZoom( zoomIn ) || update; + if( e->state() & ControlButton ) + update = anObject->updateXZoom( zoomIn ) || update; + else + update = anObject->updateYZoom( zoomIn ) || update; } emit wheelZoomChange( zoomIn ); -- 2.39.2