00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00025 #ifndef TECOMMON_H
00026 #define TECOMMON_H
00027
00028 #include <tqcolor.h>
00029
00030 #ifndef UINT8
00031 typedef unsigned char UINT8;
00032 #endif
00033
00034 #ifndef UINT16
00035 typedef unsigned short UINT16;
00036 #endif
00037
00038
00039
00042 struct ColorEntry
00043 {
00044 ColorEntry(TQColor c, bool tr, bool b) : color(c), transparent(tr), bold(b) {}
00045 ColorEntry() : transparent(false), bold(false) {}
00046 void operator=(const ColorEntry& rhs) {
00047 color = rhs.color;
00048 transparent = rhs.transparent;
00049 bold = rhs.bold;
00050 }
00051 TQColor color;
00052 bool transparent;
00053 bool bold;
00054 };
00055
00056
00057
00058
00059
00060 #define BASE_COLORS (2+8)
00061 #define INTENSITIES 2
00062 #define TABLE_COLORS (INTENSITIES*BASE_COLORS)
00063
00064 #define DEFAULT_FORE_COLOR 0
00065 #define DEFAULT_BACK_COLOR 1
00066
00067 #define DEFAULT_RENDITION 0
00068 #define RE_BOLD (1 << 0)
00069 #define RE_BLINK (1 << 1)
00070 #define RE_UNDERLINE (1 << 2)
00071 #define RE_REVERSE (1 << 3) // Screen only
00072 #define RE_INTENSIVE (1 << 3) // Widget only
00073 #define RE_CURSOR (1 << 4)
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 #define CO_UND 0
00093 #define CO_DFT 1
00094 #define CO_SYS 2
00095 #define CO_256 3
00096 #define CO_RGB 4
00097
00098 class cacol
00099 {
00100 public:
00101 cacol();
00102 cacol(UINT8 space, int color);
00103 UINT8 t;
00104 UINT8 u;
00105 UINT8 v;
00106 UINT8 w;
00107 void toggleIntensive();
00108 TQColor color(const ColorEntry* base) const;
00109 friend bool operator == (cacol a, cacol b);
00110 friend bool operator != (cacol a, cacol b);
00111 };
00112
00113 #if 0
00114 inline cacol::cacol(UINT8 _t, UINT8 _u, UINT8 _v, UINT8 _w)
00115 : t(_t), u(_u), v(_v), w(_w)
00116 {
00117 }
00118 #else
00119 inline cacol::cacol(UINT8 ty, int co)
00120 : t(ty), u(0), v(0), w(0)
00121 {
00122 switch (t)
00123 {
00124 case CO_UND: break;
00125 case CO_DFT: u = co& 1; break;
00126 case CO_SYS: u = co& 7; v = (co>>3)&1; break;
00127 case CO_256: u = co&255; break;
00128 case CO_RGB: u = co>>16; v = co>>8; w = co; break;
00129 default : t = 0; break;
00130 }
00131 }
00132 #endif
00133
00134 inline cacol::cacol()
00135 : t(CO_UND), u(0), v(0), w(0)
00136 {
00137 }
00138
00139 inline bool operator == (cacol a, cacol b)
00140 {
00141 return a.t == b.t && a.u == b.u && a.v == b.v && a.w == b.w;
00142 }
00143
00144 inline bool operator != (cacol a, cacol b)
00145 {
00146 return a.t != b.t || a.u != b.u || a.v != b.v || a.w != b.w;
00147 }
00148
00149 inline const TQColor color256(UINT8 u, const ColorEntry* base)
00150 {
00151
00152 if (u < 8) return base[u+2 ].color; u -= 8;
00153 if (u < 8) return base[u+2+BASE_COLORS].color; u -= 8;
00154
00155
00156 if (u < 216) return TQColor(255*((u/36)%6)/5,
00157 255*((u/ 6)%6)/5,
00158 255*((u/ 1)%6)/5); u -= 216;
00159
00160
00161 int gray = u*10+8; return TQColor(gray,gray,gray);
00162 }
00163
00164 inline TQColor cacol::color(const ColorEntry* base) const
00165 {
00166 switch (t)
00167 {
00168 case CO_DFT: return base[u+0+(v?BASE_COLORS:0)].color;
00169 case CO_SYS: return base[u+2+(v?BASE_COLORS:0)].color;
00170 case CO_256: return color256(u,base);
00171 case CO_RGB: return TQColor(u,v,w);
00172 default : return TQColor(255,0,0);
00173 }
00174 }
00175
00176 inline void cacol::toggleIntensive()
00177 {
00178 if (t == CO_SYS || t == CO_DFT)
00179 {
00180 v = !v;
00181 }
00182 }
00183
00188 class ca
00189 {
00190 public:
00191 inline ca(UINT16 _c = ' ',
00192 cacol _f = cacol(CO_DFT,DEFAULT_FORE_COLOR),
00193 cacol _b = cacol(CO_DFT,DEFAULT_BACK_COLOR),
00194 UINT8 _r = DEFAULT_RENDITION)
00195 : c(_c), r(_r), f(_f), b(_b) {}
00196 public:
00197 UINT16 c;
00198 UINT8 r;
00199 cacol f;
00200 cacol b;
00201 public:
00202
00203
00204
00205 bool isTransparent(const ColorEntry* base) const;
00206 bool isBold(const ColorEntry* base) const;
00207 public:
00208 friend bool operator == (ca a, ca b);
00209 friend bool operator != (ca a, ca b);
00210 };
00211
00212 inline bool operator == (ca a, ca b)
00213 {
00214 return a.c == b.c && a.f == b.f && a.b == b.b && a.r == b.r;
00215 }
00216
00217 inline bool operator != (ca a, ca b)
00218 {
00219 return a.c != b.c || a.f != b.f || a.b != b.b || a.r != b.r;
00220 }
00221
00222 inline bool ca::isTransparent(const ColorEntry* base) const
00223 {
00224 return (b.t == CO_DFT) && base[b.u+0+(b.v?BASE_COLORS:0)].transparent
00225 || (b.t == CO_SYS) && base[b.u+2+(b.v?BASE_COLORS:0)].transparent;
00226 }
00227
00228 inline bool ca::isBold(const ColorEntry* base) const
00229 {
00230 return (f.t == CO_DFT) && base[f.u+0+(f.v?BASE_COLORS:0)].bold
00231 || (f.t == CO_SYS) && base[f.u+2+(f.v?BASE_COLORS:0)].bold;
00232 }
00233
00234 #endif // TECOMMON_H