/usr/include/crystalspace-2.0/ivaria/gradient.h is in libcrystalspace-dev 2.0+dfsg-1build1.
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 | /*
Copyright (C) 2003 by Jorrit Tyberghein
(C) 2003 by Frank Richter
(C) 2006 by Christopher Nelson
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __CS_IVARIA_GRADIENT_H__
#define __CS_IVARIA_GRADIENT_H__
/**\file
* Simple color gradient interfaces
*/
#include "iutil/array.h"
#include "csutil/cscolor.h"
#include "csgfx/rgbpixel.h"
/**
* An entry in an iGradient gradient.
*/
struct csGradientShade
{
/// Color of the left side
csColor4 left;
/// Color of the right side
csColor4 right;
/// Position in the gradient
float position;
/// Construct with all values set to 0
csGradientShade () : left (0, 0, 0, 1.0f), right (0, 0, 0, 1.0f),
position (0) {}
/// Construct supplying all values
csGradientShade (const csColor4& left_color, const csColor4& right_color,
float pos) : left (left_color), right (right_color), position (pos) {}
/// Construct supplying all values
explicit csGradientShade (const csColor& left_color,
const csColor& right_color, float pos) : left (left_color),
right (right_color), position (pos) {}
/**
* Construct using a color and position. Both left and right will have the
* value of color.
*/
csGradientShade (const csColor4& color, float pos) : left (color),
right (color), position (pos) {}
/**
* Construct using a color and position. Both left and right will have the
* value of color.
*/
explicit csGradientShade (const csColor& color, float pos) :
left (color), right (color), position (pos) {}
bool operator== (const csGradientShade& other)
{
return (left == other.left) && (right == other.right)
&& (position == other.position);
}
};
/**
* An array of gradient shades.
*/
struct iGradientShades : public iArrayReadOnly<csGradientShade>
{
SCF_IARRAYREADONLY_INTERFACE(iGradientShades);
};
/**
* A simple color gradient.
* If you ever have worked with an image creation/manipulation program with
* a slightly higher niveau than Windows Paint then you probably know what
* this is.
*
* Colors(here called 'shades') can be placed at arbitrary positions; although
* commonly a range of [0;1] is used, negative positions and positions larger
* than 1 are supported.
*
* Shades contain actually two colors, a 'left' and 'right' one. You can think
* of this as, when approaching from one side, you'll get closer and closer to
* the respective color. If you step over a shade, you have the other color,
* but you're getting farther and farther from it (and towards the next color)
* when moving on. This feature can be used for sharp transitions; for smooth
* ones they are simply set to the same value.
*
* This interface is implemented by csGradient.
*
* Examples:
* \code
* csRef<iGradient> grad;
* // Rainbow-ish
* grad->AddShade (csColor4 (1.0f, 0.0f, 0.0f, 1.0f), 0.0f);
* grad->AddShade (csColor4 (1.0f, 1.0f, 0.0f, 1.0f), 0.2f);
* grad->AddShade (csColor4 (0.0f, 1.0f, 0.0f, 1.0f), 0.4f);
* grad->AddShade (csColor4 (0.0f, 1.0f, 1.0f, 1.0f), 0.6f);
* grad->AddShade (csColor4 (0.0f, 0.0f, 1.0f, 1.0f), 0.8f);
* grad->AddShade (csColor4 (1.0f, 0.0f, 1.0f, 1.0f), 1.0f);
*
* // German flag
* grad->Clear ();
* grad->AddShade (csColor4 (0.0f, 0.0f, 0.0f, 1.0f), 0.0f);
* grad->AddShade (csColor4 (0.0f, 0.0f, 0.0f, 1.0f),
* csColor4 (1.0f, 0.0f, 0.0f, 1.0f), 0.33f);
* grad->AddShade (csColor4 (1.0f, 0.0f, 0.0f, 1.0f),
* csColor4 (1.0f, 1.0f, 0.0f, 1.0f),
* 0.66f);
* grad->AddShade (csColor4 (1.0f, 1.0f, 0.0f, 1.0f), 1.0f);
* \endcode
* \todo More shade management (e.g. getting, deleting of single shades.)
*/
struct iGradient : public virtual iBase
{
SCF_INTERFACE(iGradient, 0, 0, 1);
//@{
/// Add a shade
virtual void AddShade (const csGradientShade& shade) = 0;
virtual void AddShade (const csColor4& color, float position) = 0;
virtual void AddShade (const csColor4& left, const csColor4& right,
float position) = 0;
//@}
/// Clear all shades
virtual void Clear () = 0;
/**
* Interpolate the colors over a part of the gradient.
* \param pal Array of csRGBcolor the gradient should be rendered to.
* \param count Number of \p palette entries to render.
* \param begin Start position. Can be anywhere in the gradient.
* \param end End position. Can be anywhere in the gradient.
*
* \remark At least 1 shade has to be present in the gradient to
* have this function succeed.
* \remark Makes heavy use of floating point calculations, so you
* might want to use this function in a precalc phase.
* \remark \p begin doesn't have to be smaller than \p end.
* \remark \p begin and \p end can both lie completely 'outside'
* the gradient (i.e. both smaller/large than the first resp. last
* shade's position.)
*/
virtual bool Render (csRGBcolor* pal, size_t count, float begin = 0.0f,
float end = 1.0f) const = 0;
/**
* Interpolate the colors over a part of the gradient.
* \param pal Array of csRGBpixel the gradient should be rendered to.
* \param count Number of \p palette entries to render.
* \param begin Start position. Can be anywhere in the gradient.
* \param end End position. Can be anywhere in the gradient.
*
* \remark At least 1 shade has to be present in the gradient to
* have this function succeed.
* \remark Makes heavy use of floating point calculations, so you
* might want to use this function in a precalc phase.
* \remark \p begin doesn't have to be smaller than \p end.
* \remark \p begin and \p end can both lie completely 'outside'
* the gradient (i.e. both smaller/large than the first resp. last
* shade's position.)
*/
virtual bool Render (csRGBpixel* pal, size_t count, float begin = 0.0f,
float end = 1.0f) const = 0;
/// Get the array of shades
virtual csPtr<iGradientShades> GetShades () = 0;
};
#endif // __CS_IVARIA_GRADIENT_H__
|