• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdeedu
  • Sitemap
  • Contact Us
 

kalzium

color.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002   Color - Class for handling color changes in OpenGL
00003 
00004   Copyright (C) 2006 Benoit Jacob
00005   Copyright (C) 2007 Geoffrey R. Hutchison
00006 
00007   This file is part of the Avogadro molecular editor project.
00008   For more information, see <http://avogadro.sourceforge.net/>
00009 
00010   Avogadro is free software; you can redistribute it and/or modify
00011   it under the terms of the GNU General Public License as published by
00012   the Free Software Foundation; either version 2 of the License, or
00013   (at your option) any later version.
00014 
00015   Avogadro is distributed in the hope that it will be useful,
00016   but WITHOUT ANY WARRANTY; without even the implied warranty of
00017   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018   GNU General Public License for more details.
00019 
00020   You should have received a copy of the GNU General Public License
00021   along with this program; if not, write to the Free Software
00022   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00023   02110-1301, USA.
00024  **********************************************************************/
00025 
00026 #include <config.h>
00027 
00028 #include <avogadro/color.h>
00029 #include <math.h> // for fabs()
00030 
00031 namespace Avogadro {
00032 
00033   class ColorPrivate {
00034   public:
00035     ColorPrivate()
00036     {    }
00037 
00038     ~ColorPrivate()
00039     {    }
00040   };
00041 
00042   Color::Color(): d(0) {
00043   }
00044 
00045   Color::~Color() {
00046       //delete d;
00047   }
00048 
00049   Color::Color( GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha ):
00050     m_red(red), m_green(green), m_blue(blue), m_alpha(alpha), d(0)
00051   {  }
00052 
00053   Color::Color( const Primitive *p ): d(0)
00054   {
00055     set(p);
00056   }
00057 
00058   Color& Color::operator=( const QColor& other )
00059   {
00060     m_red = other.red();
00061     m_green = other.green();
00062     m_blue = other.blue();
00063     m_alpha = other.alpha();
00064 
00065     return *this;
00066   }
00067 
00068   void Color::set(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
00069   {
00070     m_red = red;
00071     m_green = green;
00072     m_blue = blue;
00073     m_alpha = alpha;
00074   }
00075 
00076   void Color::setToSelectionColor()
00077   {
00078     m_red = 0.3;
00079     m_green = 0.6;
00080     m_blue = 1.0;
00081     m_alpha = 0.7;
00082   }
00083 
00084   void Color::set(const Primitive *)
00085   {
00086     return;
00087   }
00088 
00089   void Color::setAlpha(double alpha)
00090   {
00091     m_alpha = alpha;
00092   }
00093 
00094   void Color::applyAsMaterials()
00095   {
00096     GLfloat ambientColor [] = { m_red / 3, m_green / 3, m_blue / 3,
00097       m_alpha };
00098     GLfloat diffuseColor [] = { m_red, m_green, m_blue, m_alpha };
00099 
00100     float s = ( 0.5 + fabsf( m_red - m_green )
00101         + fabsf( m_blue - m_green ) + fabsf( m_blue - m_red ) ) / 4.0;
00102 
00103     float t = 1.0 - s;
00104 
00105     GLfloat specularColor [] = { s + t * m_red,
00106       s + t * m_green,
00107       s + t * m_blue,
00108       m_alpha };
00109 
00110     glMaterialfv( GL_FRONT, GL_AMBIENT, ambientColor );
00111     glMaterialfv( GL_FRONT, GL_DIFFUSE, diffuseColor );
00112     glMaterialfv( GL_FRONT, GL_SPECULAR, specularColor );
00113     glMaterialf( GL_FRONT, GL_SHININESS, 50.0 );
00114   }
00115 
00116   void Color::applyAsFlatMaterials()
00117   {
00118     GLfloat diffuseColor [] = { m_red, m_green, m_blue, m_alpha };
00119 
00120     glMaterialfv( GL_FRONT, GL_AMBIENT, diffuseColor );
00121     glMaterialfv( GL_FRONT, GL_DIFFUSE, diffuseColor );
00122     glMaterialfv( GL_FRONT, GL_SPECULAR, diffuseColor );
00123     glMaterialf( GL_FRONT, GL_SHININESS, 1.0 );
00124   }
00125 
00126   void Color::setName(const QString& name)
00127   {
00128     m_name = name;
00129   }
00130 
00131   QString Color::name() const
00132   {
00133    if (m_name.isEmpty())
00134      return type();
00135     else
00136       return m_name;
00137   }
00138 }

kalzium

Skip menu "kalzium"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdeedu

Skip menu "kdeedu"
  • kalzium
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  •   docs
  •   src
  • parley
  •   stepcore
Generated for kdeedu by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal