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

/otk/rendercontrol.cc

Go to the documentation of this file.
00001 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
00002 
00003 #ifdef    HAVE_CONFIG_H
00004 #  include "../config.h"
00005 #endif // HAVE_CONFIG_H
00006 
00007 #include "rendercontrol.hh"
00008 #include "truerendercontrol.hh"
00009 #include "pseudorendercontrol.hh"
00010 #include "rendertexture.hh"
00011 #include "rendercolor.hh"
00012 #include "display.hh"
00013 #include "screeninfo.hh"
00014 #include "surface.hh"
00015 #include "font.hh"
00016 #include "ustring.hh"
00017 
00018 extern "C" {
00019 #ifdef    HAVE_STDLIB_H
00020 #  include <stdlib.h>
00021 #endif // HAVE_STDLIB_H
00022 
00023 #include "../src/gettext.h"
00024 #define _(str) gettext(str)
00025 }
00026 
00027 namespace otk {
00028 
00029 RenderControl *RenderControl::getRenderControl(int screen)
00030 {
00031   // get the visual on the screen and return the correct type of RenderControl
00032   int vclass = display->screenInfo(screen)->visual()->c_class;
00033   switch (vclass) {
00034   case TrueColor:
00035     return new TrueRenderControl(screen);
00036   case PseudoColor:
00037   case StaticColor:
00038     return new PseudoRenderControl(screen);
00039   case GrayScale:
00040   case StaticGray:
00041     return new PseudoRenderControl(screen);
00042   default:
00043     printf(_("RenderControl: Unsupported visual %d specified. Aborting.\n"),
00044      vclass);
00045     ::exit(1);
00046   }
00047 }
00048 
00049 RenderControl::RenderControl(int screen)
00050   : _screen(screen)
00051 {
00052   printf("Initializing RenderControl\n");
00053 
00054   
00055 }
00056 
00057 RenderControl::~RenderControl()
00058 {
00059   printf("Destroying RenderControl\n");
00060 
00061 
00062 }
00063 
00064 void RenderControl::drawRoot(const RenderColor &color) const
00065 {
00066   Window root = display->screenInfo(_screen)->rootWindow();
00067   XSetWindowBackground(**display, root, color.pixel());
00068   XClearWindow(**display, root);
00069 }
00070 
00071 void RenderControl::drawString(Surface& sf, const Font &font, int x, int y,
00072              const RenderColor &color,
00073                                const ustring &string) const
00074 {
00075   assert(sf._screen == _screen);
00076   XftDraw *d = sf._xftdraw;
00077   assert(d); // this means that the background hasn't been rendered yet!
00078   
00079   if (font._shadow) {
00080     XftColor c;
00081     c.color.red = 0;
00082     c.color.green = 0;
00083     c.color.blue = 0;
00084     c.color.alpha = font._tint | font._tint << 8; // transparent shadow
00085     c.pixel = BlackPixel(**display, _screen);
00086 
00087     if (string.utf8())
00088       XftDrawStringUtf8(d, &c, font._xftfont, x + font._offset,
00089                         font._xftfont->ascent + y + font._offset,
00090                         (FcChar8*)string.c_str(), string.bytes());
00091     else
00092       XftDrawString8(d, &c, font._xftfont, x + font._offset,
00093                      font._xftfont->ascent + y + font._offset,
00094                      (FcChar8*)string.c_str(), string.bytes());
00095   }
00096     
00097   XftColor c;
00098   c.color.red = color.red() | color.red() << 8;
00099   c.color.green = color.green() | color.green() << 8;
00100   c.color.blue = color.blue() | color.blue() << 8;
00101   c.pixel = color.pixel();
00102   c.color.alpha = 0xff | 0xff << 8; // no transparency in Color yet
00103 
00104   if (string.utf8())
00105     XftDrawStringUtf8(d, &c, font._xftfont, x, font._xftfont->ascent + y,
00106                       (FcChar8*)string.c_str(), string.bytes());
00107   else
00108     XftDrawString8(d, &c, font._xftfont, x, font._xftfont->ascent + y,
00109                    (FcChar8*)string.c_str(), string.bytes());
00110   return;
00111 }
00112 
00113 void RenderControl::drawSolidBackground(Surface& sf,
00114                                         const RenderTexture& texture) const
00115 {
00116   assert(_screen == sf._screen);
00117   assert(_screen == texture.color().screen());
00118   
00119   if (texture.parentRelative()) return;
00120   
00121   sf.setPixmap(texture.color());
00122 
00123   int width = sf.width(), height = sf.height();
00124   int left = 0, top = 0, right = width - 1, bottom = height - 1;
00125 
00126   if (texture.interlaced())
00127     for (int i = 0; i < height; i += 2)
00128       XDrawLine(**display, sf.pixmap(), texture.interlaceColor().gc(),
00129                 0, i, width, i);
00130 
00131   switch (texture.relief()) {
00132   case RenderTexture::Raised:
00133     switch (texture.bevel()) {
00134     case RenderTexture::Bevel1:
00135       XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
00136                 left, bottom, right, bottom);
00137       XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
00138                 right, bottom, right, top);
00139 
00140       XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
00141                 left, top, right, top);
00142       XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
00143                 left, bottom, left, top);
00144       break;
00145     case RenderTexture::Bevel2:
00146       XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
00147                 left + 1, bottom - 2, right - 2, bottom - 2);
00148       XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
00149                 right - 2, bottom - 2, right - 2, top + 1);
00150 
00151       XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
00152                 left + 1, top + 1, right - 2, top + 1);
00153       XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
00154                 left + 1, bottom - 2, left + 1, top + 1);
00155       break;
00156     default:
00157       assert(false); // unhandled RenderTexture::BevelType
00158     }
00159     break;
00160   case RenderTexture::Sunken:
00161     switch (texture.bevel()) {
00162     case RenderTexture::Bevel1:
00163       XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
00164                 left, bottom, right, bottom);
00165       XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
00166                 right, bottom, right, top);
00167 
00168       XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
00169                 left, top, right, top);
00170       XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
00171                 left, bottom, left, top);
00172       break;
00173     case RenderTexture::Bevel2:
00174       XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
00175                 left + 1, bottom - 2, right - 2, bottom - 2);
00176       XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
00177                 right - 2, bottom - 2, right - 2, top + 1);
00178 
00179       XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
00180                 left + 1, top + 1, right - 2, top + 1);
00181       XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
00182                 left + 1, bottom - 2, left + 1, top + 1);
00183       break;
00184     default:
00185       assert(false); // unhandled RenderTexture::BevelType
00186     }
00187     break;
00188   case RenderTexture::Flat:
00189     if (texture.border())
00190       XDrawRectangle(**display, sf.pixmap(), texture.borderColor().gc(),
00191                      left, top, right, bottom);
00192     break;
00193   default:
00194     assert(false); // unhandled RenderTexture::ReliefType
00195   }
00196 }
00197 
00198 }

Generated on Tue Feb 4 22:58:56 2003 for Openbox by doxygen1.3-rc2