rGradient Class Reference

Gradient class, able to store a gradient and perform basic render functions with it. More...

#include <rGradient.h>

Collaboration diagram for rGradient:

Collaboration graph
[legend]

List of all members.

Public Types

enum  direction { horizontal, vertical, value }
 Enum for describing the direction of the gradient. More...

Public Member Functions

 rGradient ()
 Constructor.
 ~rGradient ()
 Destructor.
void SetDir (direction dir)
void SetValue (float at)
void SetGradientEdges (tCoord const &edge1, tCoord const edge2)
 set the boundaries of the gradient
void DrawAt (tCoord const &where)
void SetValues (tCoord const &where, float *position, float *color, float *texcoords)
 set the values you'd use for glDrawElements()
void DrawAtomicRect (tCoord const &edge1, tCoord const &edge2)
 Draw a rectangle using only the colors of the edges.
void DrawRect (tCoord const &edge1, tCoord const &edge2)
 Draw a rectangle, but split it up into multiple rectangles if necessary.
void DrawPoint (tCoord const &where)
 Send a single vertex with the correct color and texture information to OpenGL.
void BeginDraw ()
 Initialize OpenGL for drawing with this gradient.
void SetTexture (rResourceTexture const &tex)
 Set the texture to be overlaid with the gradient.
void SetTextureScale (tCoord const &scale)

Private Member Functions

float GetGradientPt (tCoord const &where)
 return the relevant value (x, y or m_at) depending on m_dir
rColor GetColor (float where)

Private Attributes

int m_dir
 the direction the gardient is laid in
float m_at
 current value, used when m_dir == value
tCoord m_origin
 bottom-left point of the gradient
tCoord m_dimensions
 width and height of it
tCoord m_texScale
 scale factor of the texture
rResourceTexture m_tex


Detailed Description

Gradient class, able to store a gradient and perform basic render functions with it.

Definition at line 40 of file rGradient.h.


Member Enumeration Documentation

enum rGradient::direction

Enum for describing the direction of the gradient.

Enumerator:
horizontal  For a gradient going from the left to the right.
vertical  For a gradient going from the bottom to the top.
value  For a soild area changing its color based on some other condition.

Definition at line 59 of file rGradient.h.

00059                    {
00060         horizontal, 
00061         vertical, 
00062         value 
00063     };


Constructor & Destructor Documentation

rGradient::rGradient (  ) 

Constructor.

Definition at line 34 of file rGradient.cpp.

00034                      : m_dir(value), m_texScale(1,1), m_tex() {
00035     //(*this)[0.]=rColor(); //make sure the beginning and end are defined
00036     //(*this)[1.]=rColor();
00037 }

rGradient::~rGradient (  ) 

Destructor.

Definition at line 38 of file rGradient.cpp.

00038                       {
00039 }


Member Function Documentation

float rGradient::GetGradientPt ( tCoord const &  where  )  [private]

return the relevant value (x, y or m_at) depending on m_dir

Definition at line 60 of file rGradient.cpp.

References horizontal, m_at, m_dimensions, m_dir, m_origin, tASSERT, value, vertical, tCoord::x, and tCoord::y.

Referenced by DrawAt(), and SetValues().

00060                                                   {
00061     float ret = 0;
00062     switch (m_dir) {
00063     case horizontal:
00064         ret=(where.x-m_origin.x)/m_dimensions.x;
00065         break;
00066     case vertical:
00067         ret=(where.y-m_origin.y)/m_dimensions.y;
00068         break;
00069     case value:
00070         ret=m_at;
00071         break;
00072     default: tASSERT(0);
00073     }
00074     if(ret<0.) ret=0.;
00075     if(ret>1.) ret=1.;
00076     return ret;
00077 }

Here is the caller graph for this function:

rColor rGradient::GetColor ( float  where  )  [private]

get the color for a given point on the gradient, using only the relevant coordinate (as returned by GetGradientPt)

Definition at line 79 of file rGradient.cpp.

References a, tColor::a_, b, tColor::b_, tColor::g_, pos, and tColor::r_.

Referenced by DrawAt(), and SetValues().

00079                                       {
00080 #ifndef DEDICATED
00081     if(empty()) return rColor();
00082     if(begin()->first >= where) return begin()->second;
00083     iterator upper, lower;
00084     iterator i=begin();
00085     iterator j=begin();
00086     ++j;
00087     bool finished = false;
00088     for(; j!=end(); ++i, ++j) {
00089         if(j->first >= where) {
00090             lower = i;
00091             upper = j;
00092             finished = true;
00093             break;
00094         }
00095     }
00096     if (!finished) return rbegin()->second;
00097     float diff = upper->first - lower->first;
00098     float pos = where - lower->first;
00099     rColor &c1 = lower->second;
00100     rColor &c2 = upper->second;
00101     float r = c1.r_*(diff-pos)/diff + c2.r_*pos/diff;
00102     float g = c1.g_*(diff-pos)/diff + c2.g_*pos/diff;
00103     float b = c1.b_*(diff-pos)/diff + c2.b_*pos/diff;
00104     float a = c1.a_*(diff-pos)/diff + c2.a_*pos/diff;
00105     return rColor(r,g,b,a);
00106 #else
00107     return rColor(0.,0.,0.,0.);
00108 #endif

Here is the caller graph for this function:

void rGradient::SetDir ( direction  dir  )  [inline]

Sets the type/direction of the gradient

Parameters:
dir the desired type/direction

Definition at line 66 of file rGradient.h.

References m_dir.

Referenced by cWidget::WithColorFunctions::ProcessGradient().

00066 { m_dir = dir; }

Here is the caller graph for this function:

void rGradient::SetValue ( float  at  )  [inline]

set the value, only used when the type is "value"

Parameters:
at the value, 1 should be the maximum and 0 the minimum

Definition at line 69 of file rGradient.h.

References m_at.

Referenced by cWidget::Rectangle::Render(), cWidget::NeedleGauge::RenderGraph(), cWidget::VerticalBarGauge::RenderGraph(), and cWidget::BarGauge::RenderGraph().

00069 { m_at = at; }

Here is the caller graph for this function:

void rGradient::SetGradientEdges ( tCoord const &  edge1,
tCoord const   edge2 
)

set the boundaries of the gradient

Parameters:
edge1 the first edge of the gradient (preferably bottom- left)
edge2 the second edge of the gradient (preferably top- right)

Definition at line 43 of file rGradient.cpp.

References m_dimensions, m_origin, tCoord::x, and tCoord::y.

Referenced by cWidget::Map::ClipperCircle::Begin(), cWidget::Map::ClipperRect::Begin(), cWidget::Map::DrawRimWalls(), cWidget::Rectangle::Render(), cWidget::VerticalBarGauge::RenderGraph(), and cWidget::BarGauge::RenderGraph().

00043                                                                         {
00044     if(edge1.x < edge2.x) {
00045         m_origin.x = edge1.x;
00046         m_dimensions.x = edge2.x - edge1.x;
00047     } else {
00048         m_origin.x = edge2.x;
00049         m_dimensions.x = edge1.x - edge2.x;
00050     }
00051     if(edge1.y < edge2.y) {
00052         m_origin.y = edge1.y;
00053         m_dimensions.y = edge2.y - edge1.y;
00054     } else {
00055         m_origin.y = edge2.y;
00056         m_dimensions.y = edge1.y - edge2.y;
00057     }
00058 }

Here is the caller graph for this function:

void rGradient::DrawAt ( tCoord const &  where  ) 

set the color and texture coordinate at the given point

Parameters:
where the point in the gradient. If it lies outside the edges of the gradient the nearest possible point will be used

Definition at line 121 of file rGradient.cpp.

References rColor::Apply(), GetColor(), GetGradientPt(), m_dimensions, m_origin, m_tex, m_texScale, rResourceTexture::Valid(), tCoord::x, and tCoord::y.

Referenced by cWidget::NeedleGauge::RenderGraph().

00122                                           {
00123 #ifndef DEDICATED
00124     GetColor(GetGradientPt(where)).Apply();
00125     if(m_tex.Valid()) {
00126         glTexCoord2f((where.x-m_origin.x)/m_dimensions.x/m_texScale.x, (m_origin.y-where.y)/m_dimensions.y/m_texScale.y);
00127     }
00128 #endif

Here is the call graph for this function:

Here is the caller graph for this function:

void rGradient::SetValues ( tCoord const &  where,
float *  position,
float *  color,
float *  texcoords 
)

set the values you'd use for glDrawElements()

Definition at line 110 of file rGradient.cpp.

References tColor::b_, c, tColor::g_, GetColor(), GetGradientPt(), m_dimensions, m_origin, m_texScale, tColor::r_, tCoord::x, and tCoord::y.

00111                                                                                               {
00112     position[0] = where.x;
00113     position[1] = where.y;
00114     rColor c = GetColor(GetGradientPt(where));
00115     color[0] = c.r_;
00116     color[1] = c.g_;
00117     color[2] = c.b_;
00118     texcoords[0] = (where.x-m_origin.x)/m_dimensions.x/m_texScale.x,
00119     texcoords[1] = (where.y-m_origin.y)/m_dimensions.y/m_texScale.y;

Here is the call graph for this function:

void rGradient::DrawAtomicRect ( tCoord const &  edge1,
tCoord const &  edge2 
)

Draw a rectangle using only the colors of the edges.

Parameters:
edge1 one edge of the rectangle
edge2 the opposite edge

Definition at line 132 of file rGradient.cpp.

00133                                                                        {
00134 #ifndef DEDICATED
00135     DrawPoint(edge1);
00136     DrawPoint(tCoord(edge1.x, edge2.y));
00137     DrawPoint(edge2);
00138     DrawPoint(tCoord(edge2.x, edge1.y));
00139 #endif

void rGradient::DrawRect ( tCoord const &  edge1,
tCoord const &  edge2 
)

Draw a rectangle, but split it up into multiple rectangles if necessary.

Parameters:
edge1 one edge of the rectangle
edge2 the opposite edge

Definition at line 143 of file rGradient.cpp.

Referenced by cWidget::Map::ClipperRect::Begin(), cWidget::Rectangle::Render(), cWidget::VerticalBarGauge::RenderGraph(), and cWidget::BarGauge::RenderGraph().

00144                                                                  {
00145 #ifndef DEDICATED
00146     float tCoord::*x; //those are correct for horizontal gradients,
00147     float tCoord::*y; //vertical ones just get turned around
00148     BeginDraw();
00149     BeginQuads();
00150     switch(m_dir) {
00151     case horizontal:
00152         x = &tCoord::x;
00153         y = &tCoord::y;
00154         break;
00155     case vertical:
00156         x = &tCoord::y;
00157         y = &tCoord::x;
00158         break;
00159     default:
00160         DrawAtomicRect(edge1, edge2);
00161         RenderEnd();
00162         return;
00163     }
00164     tCoord const &left = (edge1.*x < edge2.*x) ? edge1 : edge2;
00165     tCoord const &right = (edge1.*x < edge2.*x) ? edge2 : edge1;
00166     float min = GetGradientPt(left);
00167     float max = GetGradientPt(right);
00168     iterator i = upper_bound(min);
00169     float last = left.*x;
00170     for(; i != end() && i->first < max; ++i) {
00171         float newpt=i->first - min;
00172         float newx=newpt*m_dimensions.*x+m_origin.*x;
00173         tCoord todraw1;
00174         tCoord todraw2;
00175         todraw1.*x = last;
00176         todraw2.*x = newx;
00177         todraw1.*y = left.*y;
00178         todraw2.*y = right.*y;
00179         DrawAtomicRect(todraw1, todraw2);
00180         last = newx;
00181     }
00182     tCoord todraw;
00183     todraw.*x = last;
00184     todraw.*y = left.*y;
00185     DrawAtomicRect(todraw, right);
00186     RenderEnd();
00187 #endif

Here is the caller graph for this function:

void rGradient::DrawPoint ( tCoord const &  where  ) 

Send a single vertex with the correct color and texture information to OpenGL.

Parameters:
where the point the color should be taken from and drawn

Definition at line 200 of file rGradient.cpp.

Referenced by cWidget::Map::ClipperCircle::Begin(), cWidget::Map::ClipperRect::Begin(), cWidget::Map::DrawRimWalls(), cWidget::VerticalBarGauge::RenderGraph(), and cWidget::BarGauge::RenderGraph().

00201                                              {
00202 #ifndef DEDICATED
00203     DrawAt(where);
00204     Vertex(where.x, where.y);
00205 #endif

Here is the caller graph for this function:

void rGradient::BeginDraw (  ) 

Initialize OpenGL for drawing with this gradient.

Definition at line 189 of file rGradient.cpp.

References m_tex, rResourceTexture::Select(), and rResourceTexture::Valid().

Referenced by cWidget::Map::ClipperCircle::Begin(), cWidget::Map::ClipperRect::Begin(), cWidget::Map::DrawRimWalls(), cWidget::Rectangle::Render(), cWidget::VerticalBarGauge::RenderGraph(), and cWidget::BarGauge::RenderGraph().

00190                           {
00191 #ifndef DEDICATED
00192     if(m_tex.Valid()) {
00193         m_tex.Select();
00194     } else {
00195         glDisable(GL_TEXTURE_2D);
00196     }
00197 #endif

Here is the call graph for this function:

Here is the caller graph for this function:

void rGradient::SetTexture ( rResourceTexture const &  tex  )  [inline]

Set the texture to be overlaid with the gradient.

Definition at line 91 of file rGradient.h.

References m_tex.

Referenced by cWidget::WithColorFunctions::ProcessImage().

00091 {m_tex = tex;}

Here is the caller graph for this function:

void rGradient::SetTextureScale ( tCoord const &  scale  )  [inline]

Definition at line 92 of file rGradient.h.

References m_texScale.

Referenced by cWidget::WithColorFunctions::ProcessGradient().

00092 {m_texScale = scale;}

Here is the caller graph for this function:


Member Data Documentation

int rGradient::m_dir [private]

the direction the gardient is laid in

Definition at line 41 of file rGradient.h.

Referenced by GetGradientPt(), and SetDir().

float rGradient::m_at [private]

current value, used when m_dir == value

Definition at line 42 of file rGradient.h.

Referenced by GetGradientPt(), and SetValue().

tCoord rGradient::m_origin [private]

bottom-left point of the gradient

Definition at line 43 of file rGradient.h.

Referenced by DrawAt(), GetGradientPt(), SetGradientEdges(), and SetValues().

tCoord rGradient::m_dimensions [private]

width and height of it

Definition at line 44 of file rGradient.h.

Referenced by DrawAt(), GetGradientPt(), SetGradientEdges(), and SetValues().

tCoord rGradient::m_texScale [private]

scale factor of the texture

Definition at line 45 of file rGradient.h.

Referenced by DrawAt(), SetTextureScale(), and SetValues().

rResourceTexture rGradient::m_tex [private]

Definition at line 53 of file rGradient.h.

Referenced by BeginDraw(), DrawAt(), and SetTexture().


The documentation for this class was generated from the following files:
Generated on Sat Mar 15 23:52:46 2008 for Armagetron Advanced by  doxygen 1.5.4