/usr/include/avogadro/color.h is in libavogadro-dev 1.0.3-10.1+b2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | /**********************************************************************
Color - Base class for handling color changes in OpenGL
Copyright (c) 2006-2008 Benoit Jacob
Copyright (c) 2007-2009 Geoff Hutchison
Copyright (c) 2007-2008 Donald Ephraim Curtis
Copyright (c) 2007 Carsten Niehaus
Copyright (c) 2007-2009 Marcus D. Hanwell
This file is part of the Avogadro molecular editor project.
For more information, see <http://avogadro.openmolecules.net/>
Avogadro is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Avogadro is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
**********************************************************************/
#ifndef COLOR_H
#define COLOR_H
#include <avogadro/global.h>
#include <avogadro/plugin.h>
#ifdef ENABLE_GLSL
#include <GL/glew.h>
#else
#include <QGLWidget>
#endif
#include <QColor> // for returning QColor
#define AVOGADRO_COLOR(i, t, d) \
public: \
static QString staticIdentifier() { return i; } \
QString identifier() const { return i; } \
static QString staticName() { return t; } \
QString name() const { if (m_name.isEmpty()) return t; else return m_name; } \
static QString staticDescription() { return d; } \
QString description() const { return d; }
#define AVOGADRO_COLOR_FACTORY(c) \
public: \
Avogadro::Plugin *createInstance(QObject *parent = 0) { Q_UNUSED(parent); return new c(); } \
Avogadro::Plugin::Type type() const { return Avogadro::Plugin::ColorType; }; \
QString identifier() const { return c::staticIdentifier(); } \
QString name() const { return c::staticName(); } \
QString description() const { return c::staticDescription(); }
namespace Avogadro {
class Primitive;
class ColorPrivate; // for future expansion
/**
* @class Color color.h <avogadro/color.h>
* @brief Map a primitive (atom, bond, etc.) to a OpenGL red, green, blue, alpha color
* @author Benoit Jacob
* @author Geoff Hutchison
*
* Color plugins are used to provide custom coloring for engines -- mapping atoms
* and residues. Provide new plugins based on atomic or residue properties
*/
class A_EXPORT Color : public Plugin
{
Q_OBJECT
public:
Color();
virtual ~Color();
/**
* This constructor sets the four components of the color
* individually. Each one ranges from 0.0 (lowest intensity) to
* 1.0 (highest intensity). For the alpha component, 0.0 means totally
* transparent and 1.0 (the default) means totally opaque.
*
* @param red The red component of the color
* @param green The green component
* @param blue The blue component
* @param alpha The opacity of the color
* \sa set()
*/
Color(float red, float green, float blue, float alpha = 1.0 );
/**
* Set the color based on the supplied Primitive.
* If NULL is passed do nothing.
* @param p the color is derived from this primitive.
*/
Color( const Primitive *p);
/** @name Set Color Methods
* These methods assign a color based on a primitive, index value (int),
* or gradient (float/double). They are the main use of color plugins.
* @{
*/
/**
* Set the color based on the supplied Primitive.
* If NULL is passed do nothing.
* @param p the color is derived from this primitive.
*/
virtual void setFromPrimitive(const Primitive *p);
/**
* Set the color based on the supplied index (e.g., in an indexed color table).
* @param index the color is derived from this value
*/
virtual void setFromIndex(const unsigned int index);
/**
* Set the color based on the supplied floating point value (e.g., a gradient).
* @param value the floating point number to consider
* @param lo the low point of the range
* @param mid the middle point of the range (e.g., 0.0)
* @param hi the high point of the range
*/
virtual void setFromGradient(const double value, const double lo,
const double mid, const double hi);
//@}
/** @name Explicit Color Methods
* These methods assign a color based on explicit assignment.
* @{
*/
/**
* Set the four components of the color
* individually. Each one ranges from 0.0 (lowest intensity) to
* 1.0 (highest intensity). For the alpha component, 0.0 means totally
* transparent and 1.0 (the default) means totally opaque.
*
* @param red The red component of the color
* @param green The green component
* @param blue The blue component
* @param alpha The opacity of the color
*/
virtual void setFromRgba(float red, float green,float blue,
float alpha = 1.0);
/**
* Set the color explicitly based on a QColor, copying RGB and Alpha levels.
*
* @param color The explicit color to use.
*/
virtual void setFromQColor(const QColor &color);
/**
* Set the color to the selection color.
* By default, the selection color is (0.3, 0.6, 1.0, 0.7).
* which is a light transparent blue */
virtual void setToSelectionColor();
/**
* Set the alpha component of the color, 0.0 means totally transparent and
* 1.0 means totally opaque.
*
* @param alpha The opacity of the color
*/
virtual void setAlpha(double alpha);
//@}
/**
* Sets this color to be the one used by OpenGL for rendering
* when lighting is disabled.
*/
virtual void apply()
{
glColor4fv(m_channels);
}
/**
* Applies nice OpenGL materials using this color as the
* diffuse color while using different shades for the ambient and
* specular colors. This is only useful if lighting is enabled.
*/
virtual void applyAsMaterials();
/**
* Applies an OpenGL material more appropriate for flat surfaces.
*/
virtual void applyAsFlatMaterials();
/**
* @return the color as a QColor.
*/
inline QColor color() const
{ QColor returnColor;
returnColor.setRgbF(m_channels[0],
m_channels[1],
m_channels[2],
m_channels[3]);
return returnColor; }
/**
* @return the red component of the color.
*/
inline float red() const { return m_channels[0]; }
/**
* @return the green component of the color.
*/
inline float green() const { return m_channels[1]; }
/**
* @return the blue component of the color.
*/
inline float blue() const { return m_channels[2]; }
/**
* @return the alpha component of the color.
*/
inline float alpha() const { return m_channels[3]; }
/**
* Set the name of this instance of the class.
*/
virtual void setName(const QString& name);
/**
* @return the translated name of this instance of the class.
*/
virtual QString name() const;
/**
* @return the untranslated identifier of this color plugin
*/
virtual QString identifier() const;
/**
* @return the type of the Color class.
*/
virtual Plugin::Type type() const { return Plugin::ColorType; }
Q_SIGNALS:
/**
* Signals that something has been changed and the engine needs to render
* after these changes were made.
*/
void changed();
protected:
/**
* \var m_channels
* The components of the color ranging from 0 to 1.
*/
float m_channels[4];
/**
* The name of the class instance.
*/
QString m_name;
/**
* The d-pointer used to preserve binary compatibility.
*/
ColorPrivate *d;
};
}
#endif
|