]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Background and foreground
authorouv <ouv@opencascade.com>
Wed, 1 Sep 2010 14:32:54 +0000 (14:32 +0000)
committerouv <ouv@opencascade.com>
Wed, 1 Sep 2010 14:32:54 +0000 (14:32 +0000)
src/GLViewer/GLViewer_ViewPort2d.cxx
src/GLViewer/GLViewer_ViewPort2d.h
src/GLViewer/GLViewer_Viewer2d.cxx
src/GLViewer/GLViewer_Widget.cxx
src/GLViewer/GLViewer_Widget.h

index 6048bcb0631ab0babb82044aa0023eaa942ea911..5fc5cd59a1e018a8798c9a1ab8d2d0be6e3ff97e 100644 (file)
@@ -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();
 }
 
index cb5bfc7a3d7ee3a4273f328f263ba6f471d07a80..688927d45fbd1a44d6a97def5294d4bfd0790751 100644 (file)
@@ -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
index f6e7f7005e1656a6237d430d00573d343b526027..9fe45257b4f01b2279d08e7a30be5b3edefa12a1 100644 (file)
@@ -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 );
   }
 }
 
index 1322ff49dd886a484ba7680f6a579c66ec88fe8b..f46d2b5fa0fcb0bf90d82c75f28678d542116c54 100644 (file)
@@ -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 )
index fba0aa38125125b9aa287b9eb66156f98c235cf2..9eab50ff67c77c4d75e41fc5a908220b835ee896 100644 (file)
@@ -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