From: ouv Date: Wed, 1 Sep 2010 14:32:54 +0000 (+0000) Subject: Background and foreground X-Git-Tag: DIAGRAM_0_1~37 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f02e8106caf179a16083651683773edf4fce6e53;p=modules%2Fgui.git Background and foreground --- diff --git a/src/GLViewer/GLViewer_ViewPort2d.cxx b/src/GLViewer/GLViewer_ViewPort2d.cxx index 6048bcb06..5fc5cd59a 100644 --- a/src/GLViewer/GLViewer_ViewPort2d.cxx +++ b/src/GLViewer/GLViewer_ViewPort2d.cxx @@ -504,6 +504,69 @@ void GLViewer_ViewPort2d::setGridColor( const QColor gridColor, const QColor axi } } +/*! + Gets foreground enable state +*/ +bool GLViewer_ViewPort2d::isForegroundEnabled() const +{ + return myGLWidget->isForegroundEnabled(); +} + +/*! + Sets foreground enable state + \param theIsEnabled - enable state +*/ +void GLViewer_ViewPort2d::setForegroundEnabled( const bool theIsEnabled ) +{ + myGLWidget->setForegroundEnabled( theIsEnabled ); +} + +/*! + Sets foreground size + \param theWidth - foreground width + \param theHeight - foreground height +*/ +void GLViewer_ViewPort2d::setForegroundSize( const GLfloat theWidth, const GLfloat theHeight ) +{ + myGLWidget->setForegroundSize( theWidth, theHeight ); +} + +/*! + Sets foreground margin + \param theMargin - foreground margin +*/ +void GLViewer_ViewPort2d::setForegroundMargin( const GLfloat theMargin ) +{ + myGLWidget->setForegroundMargin( theMargin ); +} + +/*! + Sets foreground color + \param theColor - foreground color +*/ +void GLViewer_ViewPort2d::setForegroundColor( const QColor& theColor ) +{ + myGLWidget->setForegroundColor( theColor ); +} + +/*! + Sets foreground frame color + \param theColor - foreground frame color +*/ +void GLViewer_ViewPort2d::setForegroundFrameColor( const QColor& theColor ) +{ + myGLWidget->setForegroundFrameColor( theColor ); +} + +/*! + Sets foreground frame line width + \theLineWidth theColor - foreground frame line width +*/ +void GLViewer_ViewPort2d::setForegroundFrameLineWidth( const GLfloat theLineWidth ) +{ + myGLWidget->setForegroundFrameLineWidth( theLineWidth ); +} + /*! Changes background color \param color - new background color @@ -511,8 +574,7 @@ void GLViewer_ViewPort2d::setGridColor( const QColor gridColor, const QColor axi void GLViewer_ViewPort2d::setBackgroundColor( const QColor& color ) { GLViewer_ViewPort::setBackgroundColor( color ); - myGLWidget->makeCurrent(); - glClearColor( color.redF(), color.greenF(), color.blueF(), 1.0 ); + myGLWidget->setBackgroundColor( color ); myGLWidget->repaint(); } diff --git a/src/GLViewer/GLViewer_ViewPort2d.h b/src/GLViewer/GLViewer_ViewPort2d.h index cb5bfc7a3..688927d45 100644 --- a/src/GLViewer/GLViewer_ViewPort2d.h +++ b/src/GLViewer/GLViewer_ViewPort2d.h @@ -85,6 +85,27 @@ public: GLViewer_Widget* getGLWidget() const { return myGLWidget; } virtual QPaintDevice* getPaintDevice() { return myGLWidget; } + //! Gets foreground enable state + bool isForegroundEnabled() const; + + //! Sets foreground enable state + void setForegroundEnabled( const bool theIsEnabled ); + + //! Sets foreground size + void setForegroundSize( const GLfloat theWidth, const GLfloat theHeight ); + + //! Sets foreground margin + void setForegroundMargin( const GLfloat theMargin ); + + //! Sets foreground color + void setForegroundColor( const QColor& theColor ); + + //! Sets foreground frame color + void setForegroundFrameColor( const QColor& theColor ); + + //! Sets foreground frame line width + void setForegroundFrameLineWidth( const GLfloat theLineWidth ); + //! Sets background color void setBackgroundColor( const QColor& color); //! Returns background color diff --git a/src/GLViewer/GLViewer_Viewer2d.cxx b/src/GLViewer/GLViewer_Viewer2d.cxx index f6e7f7005..9fe45257b 100644 --- a/src/GLViewer/GLViewer_Viewer2d.cxx +++ b/src/GLViewer/GLViewer_Viewer2d.cxx @@ -104,7 +104,10 @@ void GLViewer_Viewer2d::onChangeBgColor() QColor selColor = QColorDialog::getColor( vp->backgroundColor(), vp ); if ( selColor.isValid() ) { - vp->setBackgroundColor( selColor ); + if( vp->isForegroundEnabled() ) + vp->setForegroundColor( selColor ); + else + vp->setBackgroundColor( selColor ); } } diff --git a/src/GLViewer/GLViewer_Widget.cxx b/src/GLViewer/GLViewer_Widget.cxx index 1322ff49d..f46d2b5fa 100644 --- a/src/GLViewer/GLViewer_Widget.cxx +++ b/src/GLViewer/GLViewer_Widget.cxx @@ -56,6 +56,15 @@ QGLWidget( parent, 0/*, WRepaintNoErase | WResizeNoErase*/ ) { myViewPort = ( GLViewer_ViewPort2d* )parent; + myIsForegroundEnabled = false; + myForegroundWidth = 100.0; + myForegroundHeight = 30.0; + myForegroundMargin = 1.0; + myForegroundColor = Qt::white; + myForegroundFrameColor = Qt::black; + myForegroundFrameLineWidth = 1.0; + myBackgroundColor = Qt::darkGray; + myXPan = 0.0; myYPan = 0.0; myZPan = 0.0; @@ -83,6 +92,71 @@ GLViewer_Widget::~GLViewer_Widget() { } +/*! + Sets foreground enable state + \param theIsEnabled - enable state +*/ +void GLViewer_Widget::setForegroundEnabled( const bool theIsEnabled ) +{ + myIsForegroundEnabled = theIsEnabled; +} + +/*! + Sets foreground size + \param theWidth - foreground width + \param theHeight - foreground height +*/ +void GLViewer_Widget::setForegroundSize( const GLfloat theWidth, const GLfloat theHeight ) +{ + myForegroundWidth = theWidth; + myForegroundHeight = theHeight; +} + +/*! + Sets foreground margin + \param theMargin - foreground margin +*/ +void GLViewer_Widget::setForegroundMargin( const GLfloat theMargin ) +{ + myForegroundMargin = theMargin; +} + +/*! + Sets foreground color + \param theColor - foreground color +*/ +void GLViewer_Widget::setForegroundColor( const QColor& theColor ) +{ + myForegroundColor = theColor; +} + +/*! + Sets foreground frame color + \param theColor - foreground frame color +*/ +void GLViewer_Widget::setForegroundFrameColor( const QColor& theColor ) +{ + myForegroundFrameColor = theColor; +} + +/*! + Sets foreground frame line width + \theLineWidth theColor - foreground frame line width +*/ +void GLViewer_Widget::setForegroundFrameLineWidth( const GLfloat theLineWidth ) +{ + myForegroundFrameLineWidth = theLineWidth; +} + +/*! + Sets foreground color + \param theColor - background color +*/ +void GLViewer_Widget::setBackgroundColor( const QColor& theColor ) +{ + myBackgroundColor = theColor; +} + /*! \return offset parameters of Window in OpenGL global scene */ @@ -321,6 +395,38 @@ void GLViewer_Widget::paintGL() glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); } + // background + glClearColor( myBackgroundColor.redF(), + myBackgroundColor.greenF(), + myBackgroundColor.blueF(), + 1.0 ); + + // foreground + if( myIsForegroundEnabled ) + { + glColor3f( myForegroundColor.redF(), + myForegroundColor.greenF(), + myForegroundColor.blueF() ); + + glBegin( GL_POLYGON ); + glVertex2f( - myForegroundMargin, - myForegroundMargin ); + glVertex2f( myForegroundWidth + myForegroundMargin, - myForegroundMargin ); + glVertex2f( myForegroundWidth + myForegroundMargin, myForegroundHeight + myForegroundMargin ); + glVertex2f( - myForegroundMargin, myForegroundHeight + myForegroundMargin ); + glEnd(); + + glColor3f( myForegroundFrameColor.redF(), + myForegroundFrameColor.greenF(), + myForegroundFrameColor.blueF() ); + glLineWidth( myForegroundFrameLineWidth ); + + glBegin( GL_LINE_LOOP ); + glVertex2f( - myForegroundMargin, - myForegroundMargin ); + glVertex2f( myForegroundWidth + myForegroundMargin, - myForegroundMargin ); + glVertex2f( myForegroundWidth + myForegroundMargin, myForegroundHeight + myForegroundMargin ); + glVertex2f( - myForegroundMargin, myForegroundHeight + myForegroundMargin ); + glEnd(); + } GLViewer_Grid* grid = myViewPort->getGrid(); if( grid ) diff --git a/src/GLViewer/GLViewer_Widget.h b/src/GLViewer/GLViewer_Widget.h index fba0aa381..9eab50ff6 100644 --- a/src/GLViewer/GLViewer_Widget.h +++ b/src/GLViewer/GLViewer_Widget.h @@ -54,6 +54,30 @@ public: //! A destructor ~GLViewer_Widget(); + //! Gets foreground enable state + bool isForegroundEnabled() const { return myIsForegroundEnabled; } + + //! Sets foreground enable state + void setForegroundEnabled( const bool theIsEnabled ); + + //! Sets foreground size + void setForegroundSize( const GLfloat theWidth, const GLfloat theHeight ); + + //! Sets foreground margin + void setForegroundMargin( const GLfloat theMargin ); + + //! Sets foreground color + void setForegroundColor( const QColor& theColor ); + + //! Sets foreground frame color + void setForegroundFrameColor( const QColor& theColor ); + + //! Sets foreground frame line width + void setForegroundFrameLineWidth( const GLfloat theLineWidth ); + + //! Sets background color + void setBackgroundColor( const QColor& theColor ); + //! Returns parent GLViewer_ViewPort2d /*! ViewPort2d because this class is not use for 3D Viewer */ GLViewer_ViewPort2d* getViewPort() const { return myViewPort; } @@ -161,6 +185,30 @@ protected: virtual bool event ( QEvent* ); private: + //! foreground enable state + bool myIsForegroundEnabled; + + //! foreground width + GLfloat myForegroundWidth; + + //! foreground height + GLfloat myForegroundHeight; + + //! foreground margin + GLfloat myForegroundMargin; + + //! foreground color + QColor myForegroundColor; + + //! foreground frame color + QColor myForegroundFrameColor; + + //! foreground frame line width + GLfloat myForegroundFrameLineWidth; + + //! background color + QColor myBackgroundColor; + //! width of window GLint myWidth; //! height of window