|
PieDock 1.6.0
|
00001 /* 00002 * O ,- 00003 * ° o . -´ ' ,- 00004 * ° .´ ` . ´,´ 00005 * ( ° )) . ( 00006 * `-;_ . -´ `.`. 00007 * `._' ´ 00008 * 00009 * Copyright (c) 2007-2012 Markus Fisch <mf@markusfisch.de> 00010 * 00011 * Licensed under the MIT license: 00012 * http://www.opensource.org/licenses/mit-license.php 00013 */ 00014 #ifndef _PieDock_Text_ 00015 #define _PieDock_Text_ 00016 00017 #include <X11/Xlib.h> 00018 00019 #ifdef HAVE_XFT 00020 #include <X11/Xft/Xft.h> 00021 #endif 00022 00023 #include <string> 00024 00025 namespace PieDock 00026 { 00032 class Text 00033 { 00034 public: 00038 class Color 00039 { 00040 public: 00041 Color() : 00042 alpha( 0 ), 00043 red( 0 ), 00044 green( 0 ), 00045 blue( 0 ) {} 00046 Color( int r, int g, int b, int a = 0xff ) : 00047 alpha( a ), 00048 red( r ), 00049 green( g ), 00050 blue( b ) {} 00051 Color( const char * ); 00052 virtual ~Color() {} 00053 inline const int &getAlpha() const { return alpha; } 00054 inline const int &getRed() const { return red; } 00055 inline const int &getGreen() const { return green; } 00056 inline const int &getBlue() const { return blue; } 00057 inline const unsigned int getColor() const { return 00058 alpha<<24 | 00059 red<<16 | 00060 green<<8 | 00061 blue; } 00062 00063 private: 00064 int alpha; 00065 int red; 00066 int green; 00067 int blue; 00068 }; 00069 00073 class Font 00074 { 00075 public: 00076 Font() { reset(); } 00077 Font( const std::string f, const double s, const Color c ) : 00078 family( f ), 00079 size( s ), 00080 color( c ) {} 00081 virtual ~Font() {} 00082 inline const std::string &getFamily() const { 00083 return family; } 00084 inline void setFamily( const std::string &s ) { 00085 family = s; } 00086 inline const double &getSize() const { return size; } 00087 inline void setSize( const double s ) { size = s; } 00088 inline const Color &getColor() const { return color; } 00089 inline void setColor( const Color c ) { color = c; } 00090 inline void reset() 00091 { 00092 #ifdef HAVE_XFT 00093 family = "Sans"; 00094 #else 00095 family = "6x10"; 00096 #endif 00097 size = 9.0; 00098 color = Color( 0xff, 0xff, 0xff, 0xff ); 00099 } 00100 00101 private: 00102 std::string family; 00103 double size; 00104 Color color; 00105 }; 00106 00110 class Metrics 00111 { 00112 public: 00113 Metrics() : x( 0 ), y( 0 ), width( 0 ), height( 0 ) {} 00114 Metrics( int xx, int yy, int w, int h ) : 00115 x( xx ), 00116 y( yy ), 00117 width( w ), 00118 height( h ) {} 00119 virtual ~Metrics() {} 00120 inline const int &getX() const { return x; } 00121 inline void setX( int xx ) { x = xx; } 00122 inline const int &getY() const { return y; } 00123 inline void setY( int yy ) { y = yy; } 00124 inline const int &getWidth() const { return width; } 00125 inline void setWidth( int w ) { width = w; } 00126 inline const int &getHeight() const { return height; } 00127 inline void setHeight( int h ) { height = h; } 00128 00129 private: 00130 int x; 00131 int y; 00132 int width; 00133 int height; 00134 }; 00135 00136 Text( Display *, Drawable, Visual *, Font ); 00137 virtual ~Text() {} 00138 virtual void setColor( const Color ); 00139 virtual void draw( const int, const int, const std::string ) const; 00140 virtual Metrics getMetrics( const std::string ) const; 00141 00142 private: 00143 Display *display; 00144 #ifdef HAVE_XFT 00145 XftFont *xftFont; 00146 XftDraw *xftDraw; 00147 XftColor xftColor; 00148 #else 00149 Drawable drawable; 00150 XFontStruct *fontInfo; 00151 XColor xColor; 00152 GC gc; 00153 #endif 00154 00155 #ifdef HAVE_XFT 00156 void translateColor( const Color &, XftColor * ); 00157 #else 00158 void translateColor( const Color &, XColor * ); 00159 #endif 00160 }; 00161 } 00162 00163 #endif
1.7.3