SoFCBackgroundGradient.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2005 Werner Mayer <wmayer[at]users.sourceforge.net>     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #include "PreCompiled.h"
00025 
00026 #include "SoFCBackgroundGradient.h"
00027 
00028 using namespace Gui;
00029 
00030 SO_NODE_SOURCE(SoFCBackgroundGradient);
00031 
00032 void SoFCBackgroundGradient::finish()
00033 {
00034     atexit_cleanup();
00035 }
00036 
00040 SoFCBackgroundGradient::SoFCBackgroundGradient()
00041 {
00042     SO_NODE_CONSTRUCTOR(SoFCBackgroundGradient);
00043     fCol.setValue(0.5f, 0.5f, 0.8f);
00044     tCol.setValue(0.7f, 0.7f, 0.9f);
00045     mCol.setValue(1.0f, 1.0f, 1.0f);
00046 }
00047 
00051 SoFCBackgroundGradient::~SoFCBackgroundGradient()
00052 {
00053 }
00054 
00055 // doc from parent
00056 void SoFCBackgroundGradient::initClass(void)
00057 {
00058     SO_NODE_INIT_CLASS(SoFCBackgroundGradient,SoNode,"Node");
00059 }
00060 
00061 void SoFCBackgroundGradient::GLRender (SoGLRenderAction *action)
00062 {
00063     glMatrixMode(GL_PROJECTION);
00064     glPushMatrix();
00065     glLoadIdentity();
00066     glOrtho(-1,1,-1,1,-1,1);
00067     glMatrixMode(GL_MODELVIEW);
00068     glPushMatrix();
00069     glLoadIdentity();
00070     glPushAttrib(GL_ENABLE_BIT);
00071     glDisable(GL_DEPTH_TEST);
00072     glDisable(GL_LIGHTING);
00073     glDisable(GL_TEXTURE_2D);
00074 
00075     glBegin(GL_TRIANGLE_STRIP);
00076     if (mCol[0] < 0) {
00077         glColor3f(fCol[0],fCol[1],fCol[2]); glVertex2f(-1, 1);
00078         glColor3f(tCol[0],tCol[1],tCol[2]); glVertex2f(-1,-1);
00079         glColor3f(fCol[0],fCol[1],fCol[2]); glVertex2f( 1, 1);
00080         glColor3f(tCol[0],tCol[1],tCol[2]); glVertex2f( 1,-1);
00081     }
00082     else {
00083         glColor3f(fCol[0],fCol[1],fCol[2]); glVertex2f(-1, 1);
00084         glColor3f(mCol[0],mCol[1],mCol[2]); glVertex2f(-1, 0);
00085         glColor3f(fCol[0],fCol[1],fCol[2]); glVertex2f( 1, 1);
00086         glColor3f(mCol[0],mCol[1],mCol[2]); glVertex2f( 1, 0);
00087         glEnd();
00088         glBegin(GL_TRIANGLE_STRIP);
00089         glColor3f(mCol[0],mCol[1],mCol[2]); glVertex2f(-1, 0);
00090         glColor3f(tCol[0],tCol[1],tCol[2]); glVertex2f(-1,-1);
00091         glColor3f(mCol[0],mCol[1],mCol[2]); glVertex2f( 1, 0);
00092         glColor3f(tCol[0],tCol[1],tCol[2]); glVertex2f( 1,-1);
00093     }
00094     glEnd();
00095 
00096     glPopAttrib();
00097     glPopMatrix(); // restore modelview
00098     glMatrixMode(GL_PROJECTION);
00099     glPopMatrix();
00100     glMatrixMode(GL_MODELVIEW);
00101 }
00102 
00103 void SoFCBackgroundGradient::setColorGradient(const SbColor& fromColor,
00104                                               const SbColor& toColor)
00105 {
00106     fCol = fromColor;
00107     tCol = toColor;
00108     mCol[0] = -1.0f;
00109 }
00110 
00111 void SoFCBackgroundGradient::setColorGradient(const SbColor& fromColor,
00112                                               const SbColor& toColor,
00113                                               const SbColor& midColor)
00114 {
00115     fCol = fromColor;
00116     tCol = toColor;
00117     mCol = midColor;
00118 }

Generated on Wed Nov 23 19:00:39 2011 for FreeCAD by  doxygen 1.6.1