osgEarth 2.1.1
Public Types | Public Member Functions | Static Public Attributes

osgEarth::Symbology::Color Struct Reference

Collaboration diagram for osgEarth::Symbology::Color:

List of all members.

Public Types

enum  Format { RGBA, ABGR }

Public Member Functions

 Color ()
 Color (const Color &rhs)
 Color (const osg::Vec4f &rgba)
 Color (const Color &rhs, float a)
 Color (float r, float g, float b, float a=1.0f)
 Color (unsigned rgba)
 Color (const std::string &html, Format format=RGBA)
std::string toHTML (Format format=RGBA) const
Color brightness (float factor) const

Static Public Attributes

static Color White
static Color Silver
static Color Gray
static Color Black
static Color Red
static Color Maroon
static Color Yellow
static Color Olive
static Color Lime
static Color Green
static Color Aqua
static Color Teal
static Color Blue
static Color Navy
static Color Fuchsia
static Color Purple
static Color Orange
static Color Cyan
static Color DarkGray

Detailed Description

Pre-set colors (convenience class).

Definition at line 31 of file Color.


Member Enumeration Documentation

Enumerator:
RGBA 
ABGR 

Definition at line 33 of file Color.

                    {
            RGBA,
            ABGR
        };

Constructor & Destructor Documentation

osgEarth::Symbology::Color::Color ( ) [inline]

Creates a new default color

Definition at line 39 of file Color.

: osg::Vec4f(1,1,1,1) { }
osgEarth::Symbology::Color::Color ( const Color rhs) [inline]

Copy constructor

Definition at line 42 of file Color.

: osg::Vec4f(rhs) { }
osgEarth::Symbology::Color::Color ( const osg::Vec4f &  rgba) [inline]

Make from vec4

Definition at line 45 of file Color.

: osg::Vec4f(rgba) { }
Color::Color ( const Color rhs,
float  a 
)

Copy constructor with modified alpha value

Definition at line 104 of file Color.cpp.

                                        :
osg::Vec4f( rhs )
{
    (*this)[3] = a;
}
osgEarth::Symbology::Color::Color ( float  r,
float  g,
float  b,
float  a = 1.0f 
) [inline]

Component constructor

Definition at line 51 of file Color.

            : osg::Vec4f(r, g, b, a) { }
Color::Color ( unsigned  rgba)

RGBA constructor

Definition at line 95 of file Color.cpp.

{
    set(
        (float)(rgba>>24)/255.0f, 
        (float)((rgba&0xFF0000)>>16)/255.0f, 
        (float)((rgba&0xFF00)>>8)/255.0f,
        (float)(rgba&0xFF)/255.0f );
}
Color::Color ( const std::string &  html,
Format  format = RGBA 
)

Construct a color from an HTML string (e.g., "#FF0004F")

Parses an HTML color ("#rrggbb" or "#rrggbbaa") into an OSG color.

Definition at line 111 of file Color.cpp.

{
    std::string t = html;
    std::transform( t.begin(), t.end(), t.begin(), ::tolower );
    osg::Vec4ub c(0,0,0,255);
    if ( t.length() >= 7 ) {
        c.r() |= t[1]<='9' ? (t[1]-'0')<<4 : (10+(t[1]-'a'))<<4;
        c.r() |= t[2]<='9' ? (t[2]-'0')    : (10+(t[2]-'a'));
        c.g() |= t[3]<='9' ? (t[3]-'0')<<4 : (10+(t[3]-'a'))<<4;
        c.g() |= t[4]<='9' ? (t[4]-'0')    : (10+(t[4]-'a'));
        c.b() |= t[5]<='9' ? (t[5]-'0')<<4 : (10+(t[5]-'a'))<<4;
        c.b() |= t[6]<='9' ? (t[6]-'0')    : (10+(t[6]-'a'));
        if ( t.length() == 9 ) {
            c.a() = 0;
            c.a() |= t[7]<='9' ? (t[7]-'0')<<4 : (10+(t[7]-'a'))<<4;
            c.a() |= t[8]<='9' ? (t[8]-'0')    : (10+(t[8]-'a'));
        }
    }
    float w = ((float)c.r())/255.0f;
    float x = ((float)c.g())/255.0f;
    float y = ((float)c.b())/255.0f;
    float z = ((float)c.a())/255.0f;

    if ( format == RGBA )
        set( w, x, y, z );
    else // ABGR
        set( z, y, x, w );
}

Member Function Documentation

Color Color::brightness ( float  factor) const

Lighten/darken the color by factor

Definition at line 163 of file Color.cpp.

{
    Color c( *this );
    rgb2hsv( c );
    c.b() = osg::clampBetween( perc * c.b(), 0.0f, 1.0f );
    hsv2rgb( c );
    return c;
}

Here is the call graph for this function:

std::string Color::toHTML ( Format  format = RGBA) const

Encode the color at an HTML color string (e.g., "#FF004F78")

Makes an HTML color ("#rrggbb" or "#rrggbbaa") from an OSG color.

Definition at line 142 of file Color.cpp.

{
    float w, x, y, z;
    if ( format == RGBA ) {
        w = r(), x = g(), y = b(), z = a();
    }
    else { // ABGR
        w = a(), x = b(), y = g(), z = r();
    }

    std::stringstream buf;
    buf << "#";
    buf << std::hex << std::setw(2) << std::setfill('0') << (int)(w*255.0f);
    buf << std::hex << std::setw(2) << std::setfill('0') << (int)(x*255.0f);
    buf << std::hex << std::setw(2) << std::setfill('0') << (int)(y*255.0f);
    buf << std::hex << std::setw(2) << std::setfill('0') << (int)(z*255.0f);
    std::string ssStr = buf.str();
    return ssStr;
}

Member Data Documentation

Color Color::Aqua [static]

Definition at line 79 of file Color.

Color Color::Black [static]

Definition at line 72 of file Color.

Color Color::Blue [static]

Definition at line 81 of file Color.

Color Color::Cyan [static]

Definition at line 86 of file Color.

Definition at line 88 of file Color.

Definition at line 83 of file Color.

Color Color::Gray [static]

Definition at line 71 of file Color.

Color Color::Green [static]

Definition at line 78 of file Color.

Color Color::Lime [static]

Definition at line 77 of file Color.

Color Color::Maroon [static]

Definition at line 74 of file Color.

Color Color::Navy [static]

Definition at line 82 of file Color.

Color Color::Olive [static]

Definition at line 76 of file Color.

Color Color::Orange [static]

Definition at line 85 of file Color.

Color Color::Purple [static]

Definition at line 84 of file Color.

Color Color::Red [static]

Definition at line 73 of file Color.

Color Color::Silver [static]

Definition at line 70 of file Color.

Color Color::Teal [static]

Definition at line 80 of file Color.

Color Color::White [static]

Definition at line 69 of file Color.

Color Color::Yellow [static]

Definition at line 75 of file Color.


The documentation for this struct was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines