Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

otk::RenderColor Class Reference

#include <rendercolor.hh>

List of all members.

Public Methods

 RenderColor (int screen, unsigned char red, unsigned char green, unsigned char blue)
 RenderColor (int screen, RGB rgb)
virtual ~RenderColor ()
int screen () const
unsigned char red () const
unsigned char green () const
unsigned char blue () const
unsigned long pixel () const
GC gc () const

Static Public Methods

void initialize ()
void destroy ()

Private Methods

void create ()

Private Attributes

int _screen
unsigned char _red
unsigned char _green
unsigned char _blue
unsigned long _pixel
GC _gc

Static Private Attributes

std::map< unsigned long, CacheItem * > * _cache = 0


Constructor & Destructor Documentation

otk::RenderColor::RenderColor int    screen,
unsigned char    red,
unsigned char    green,
unsigned char    blue
 

Definition at line 31 of file rendercolor.cc.

References create().

00033   : _screen(screen),
00034     _red(red),
00035     _green(green),
00036     _blue(blue),
00037     _gc(0)
00038 {
00039   create();
00040 }

otk::RenderColor::RenderColor int    screen,
RGB    rgb
 

Definition at line 42 of file rendercolor.cc.

References create().

00043   : _screen(screen),
00044     _red(rgb.r),
00045     _green(rgb.g),
00046     _blue(rgb.b),
00047     _gc(0)
00048 {
00049   create();
00050 }

otk::RenderColor::~RenderColor   [virtual]
 

Definition at line 95 of file rendercolor.cc.

References _blue, _cache, _green, _red, _screen, and otk::RenderColor::CacheItem::count.

00096 {
00097   unsigned long color = _blue | _green << 8 | _red << 16;
00098 
00099   CacheItem *item = _cache[_screen][color];
00100   assert(item); // it better be in the cache ...
00101 
00102   if (--item->count <= 0) {
00103     // remove from the cache
00104     XFreeGC(**display, _gc);
00105     _cache[_screen][color] = 0;
00106     delete item;
00107   }
00108 }


Member Function Documentation

unsigned char otk::RenderColor::blue   const [inline]
 

Definition at line 57 of file rendercolor.hh.

Referenced by otk::TrueRenderControl::crossDiagonalGradient(), otk::TrueRenderControl::diagonalGradient(), otk::TrueRenderControl::drawGradientBackground(), otk::RenderControl::drawString(), otk::RenderTexture::RenderTexture(), and otk::TrueRenderControl::verticalGradient().

00057 { return _blue; }

void otk::RenderColor::create   [private]
 

Definition at line 52 of file rendercolor.cc.

References _blue, _cache, _gc, _green, _pixel, _red, _screen, otk::ScreenInfo::colormap(), otk::RenderColor::CacheItem::count, otk::display, otk::RenderColor::CacheItem::gc, otk::RenderColor::CacheItem::pixel, otk::ScreenInfo::rootWindow(), and otk::Display::screenInfo().

Referenced by RenderColor().

00053 {
00054   unsigned long color = _blue | _green << 8 | _red << 16;
00055   
00056   // try get a gc from the cache
00057   CacheItem *item = _cache[_screen][color];
00058 
00059   if (item) {
00060     _gc = item->gc;
00061     _pixel = item->pixel;
00062     ++item->count;
00063   } else {
00064     XGCValues gcv;
00065 
00066     // allocate a color and GC from the server
00067     const ScreenInfo *info = display->screenInfo(_screen);
00068 
00069     XColor xcol;    // convert from 0-0xff to 0-0xffff
00070     xcol.red = _red; xcol.red |= xcol.red << 8;
00071     xcol.green = _green; xcol.green |= xcol.green << 8;
00072     xcol.blue = _blue; xcol.blue |= xcol.blue << 8;
00073     xcol.pixel = 0;
00074 
00075     if (! XAllocColor(**display, info->colormap(), &xcol)) {
00076       fprintf(stderr, "RenderColor: color alloc error: rgb:%x/%x/%x\n",
00077         _red, _green, _blue);
00078       xcol.pixel = 0;
00079     }
00080 
00081     _pixel = xcol.pixel;
00082     gcv.foreground = _pixel;
00083     gcv.cap_style = CapProjecting;
00084     _gc = XCreateGC(**display, info->rootWindow(),
00085         GCForeground | GCCapStyle, &gcv);
00086     assert(_gc);
00087 
00088     // insert into the cache
00089     item = new CacheItem(_gc, _pixel);
00090     _cache[_screen][color] = item;
00091     ++item->count;
00092   }
00093 }

void otk::RenderColor::destroy   [static]
 

Definition at line 26 of file rendercolor.cc.

References _cache.

Referenced by ob::Openbox::~Openbox().

00027 {
00028   delete [] _cache;
00029 }

GC otk::RenderColor::gc   const [inline]
 

Definition at line 59 of file rendercolor.hh.

Referenced by otk::RenderControl::drawSolidBackground(), ob::ButtonWidget::renderForeground(), and otk::Surface::setPixmap().

00059 { return _gc; }

unsigned char otk::RenderColor::green   const [inline]
 

Definition at line 56 of file rendercolor.hh.

Referenced by otk::TrueRenderControl::crossDiagonalGradient(), otk::TrueRenderControl::diagonalGradient(), otk::TrueRenderControl::drawGradientBackground(), otk::RenderControl::drawString(), otk::RenderTexture::RenderTexture(), and otk::TrueRenderControl::verticalGradient().

00056 { return _green; }

void otk::RenderColor::initialize   [static]
 

Definition at line 21 of file rendercolor.cc.

References _cache.

Referenced by ob::Openbox::Openbox().

00022 {
00023   _cache = new std::map<unsigned long, CacheItem*>[ScreenCount(**display)];
00024 }

unsigned long otk::RenderColor::pixel   const [inline]
 

Definition at line 58 of file rendercolor.hh.

Referenced by otk::RenderControl::drawRoot(), and otk::RenderControl::drawString().

00058 { return _pixel; }

unsigned char otk::RenderColor::red   const [inline]
 

Definition at line 55 of file rendercolor.hh.

Referenced by otk::TrueRenderControl::crossDiagonalGradient(), otk::TrueRenderControl::diagonalGradient(), otk::TrueRenderControl::drawGradientBackground(), otk::RenderControl::drawString(), otk::RenderTexture::RenderTexture(), and otk::TrueRenderControl::verticalGradient().

00055 { return _red; }

int otk::RenderColor::screen   const [inline]
 

Definition at line 54 of file rendercolor.hh.

Referenced by otk::TrueRenderControl::drawBackground(), otk::PseudoRenderControl::drawBackground(), and otk::RenderControl::drawSolidBackground().

00054 { return _screen; }


Member Data Documentation

unsigned char otk::RenderColor::_blue [private]
 

Definition at line 38 of file rendercolor.hh.

Referenced by create(), and ~RenderColor().

std::map< unsigned long, RenderColor::CacheItem * > * otk::RenderColor::_cache = 0 [static, private]
 

Definition at line 19 of file rendercolor.cc.

Referenced by create(), destroy(), initialize(), and ~RenderColor().

GC otk::RenderColor::_gc [private]
 

Definition at line 41 of file rendercolor.hh.

Referenced by create().

unsigned char otk::RenderColor::_green [private]
 

Definition at line 37 of file rendercolor.hh.

Referenced by create(), and ~RenderColor().

unsigned long otk::RenderColor::_pixel [private]
 

Definition at line 39 of file rendercolor.hh.

Referenced by create().

unsigned char otk::RenderColor::_red [private]
 

Definition at line 36 of file rendercolor.hh.

Referenced by create(), and ~RenderColor().

int otk::RenderColor::_screen [private]
 

Definition at line 35 of file rendercolor.hh.

Referenced by create(), and ~RenderColor().


The documentation for this class was generated from the following files:
Generated on Tue Feb 4 23:00:28 2003 for Openbox by doxygen1.3-rc2