]> Dogcows Code - chaz/openbox/blob - otk/texture.cc
fix indenting
[chaz/openbox] / otk / texture.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2
3 #ifdef HAVE_CONFIG_H
4 # include "../config.h"
5 #endif // HAVE_CONFIG_H
6
7 extern "C" {
8 #include <stdio.h>
9 #ifdef HAVE_CTYPE_H
10 #include <ctype.h>
11 #endif
12 }
13
14 #include <assert.h>
15
16 #include "texture.hh"
17 #include "display.hh"
18 #include "image.hh"
19
20 using std::string;
21
22 namespace otk {
23
24 Texture::Texture(unsigned int _screen, ImageControl* _ctrl)
25 : c(_screen), ct(_screen),
26 lc(_screen), sc(_screen), bc(_screen), t(0),
27 ctrl(_ctrl), scrn(_screen) { }
28
29
30 Texture::Texture(const string &d,unsigned int _screen, ImageControl* _ctrl)
31 : c(_screen), ct(_screen),
32 lc(_screen), sc(_screen), bc(_screen), t(0),
33 ctrl(_ctrl), scrn(_screen) {
34 setDescription(d);
35 }
36
37
38 void Texture::setColor(const Color &cc) {
39 c = cc;
40 c.setScreen(screen());
41
42 unsigned char r, g, b, rr, gg, bb;
43
44 // calculate the light color
45 r = c.red();
46 g = c.green();
47 b = c.blue();
48 rr = r + (r >> 1);
49 gg = g + (g >> 1);
50 bb = b + (b >> 1);
51 if (rr < r) rr = ~0;
52 if (gg < g) gg = ~0;
53 if (bb < b) bb = ~0;
54 lc = Color(rr, gg, bb, screen());
55
56 // calculate the shadow color
57 r = c.red();
58 g = c.green();
59 b = c.blue();
60 rr = (r >> 2) + (r >> 1);
61 gg = (g >> 2) + (g >> 1);
62 bb = (b >> 2) + (b >> 1);
63 if (rr > r) rr = 0;
64 if (gg > g) gg = 0;
65 if (bb > b) bb = 0;
66 sc = Color(rr, gg, bb, screen());
67 }
68
69
70 void Texture::setDescription(const string &d) {
71 descr.erase();
72 descr.reserve(d.length());
73
74 string::const_iterator it = d.begin(), end = d.end();
75 for (; it != end; ++it)
76 descr += tolower(*it);
77
78 if (descr.find("parentrelative") != string::npos) {
79 setTexture(Texture::Parent_Relative);
80 } else {
81 setTexture(0);
82
83 if (descr.find("gradient") != string::npos) {
84 addTexture(Texture::Gradient);
85 if (descr.find("crossdiagonal") != string::npos)
86 addTexture(Texture::CrossDiagonal);
87 else if (descr.find("rectangle") != string::npos)
88 addTexture(Texture::Rectangle);
89 else if (descr.find("pyramid") != string::npos)
90 addTexture(Texture::Pyramid);
91 else if (descr.find("pipecross") != string::npos)
92 addTexture(Texture::PipeCross);
93 else if (descr.find("elliptic") != string::npos)
94 addTexture(Texture::Elliptic);
95 else if (descr.find("horizontal") != string::npos)
96 addTexture(Texture::Horizontal);
97 else if (descr.find("vertical") != string::npos)
98 addTexture(Texture::Vertical);
99 else
100 addTexture(Texture::Diagonal);
101 } else {
102 addTexture(Texture::Solid);
103 }
104
105 if (descr.find("sunken") != string::npos)
106 addTexture(Texture::Sunken);
107 else if (descr.find("flat") != string::npos)
108 addTexture(Texture::Flat);
109 else
110 addTexture(Texture::Raised);
111
112 if (texture() & Texture::Flat) {
113 if (descr.find("border") != string::npos)
114 addTexture(Texture::Border);
115 } else {
116 if (descr.find("bevel2") != string::npos)
117 addTexture(Texture::Bevel2);
118 else
119 addTexture(Texture::Bevel1);
120 }
121
122 if (descr.find("interlaced") != string::npos)
123 addTexture(Texture::Interlaced);
124 }
125 }
126
127 void Texture::setScreen(const unsigned int _screen) {
128 if (_screen == screen()) {
129 // nothing to do
130 return;
131 }
132
133 scrn = _screen;
134 c.setScreen(_screen);
135 ct.setScreen(_screen);
136 lc.setScreen(_screen);
137 sc.setScreen(_screen);
138 bc.setScreen(_screen);
139 }
140
141
142 Texture& Texture::operator=(const Texture &tt) {
143 c = tt.c;
144 ct = tt.ct;
145 lc = tt.lc;
146 sc = tt.sc;
147 bc = tt.bc;
148 descr = tt.descr;
149 t = tt.t;
150 scrn = tt.scrn;
151 ctrl = tt.ctrl;
152
153 return *this;
154 }
155
156
157 Pixmap Texture::render(const unsigned int width, const unsigned int height,
158 const Pixmap old) {
159 assert(texture() != Texture::NoTexture);
160
161 // if (texture() == (Texture::Flat | Texture::Solid))
162 // return None;
163 if (texture() == Texture::Parent_Relative)
164 return ParentRelative;
165
166 if (screen() == ~(0u))
167 scrn = DefaultScreen(**display);
168
169 assert(ctrl != 0);
170 Pixmap ret = ctrl->renderImage(width, height, *this);
171
172 if (old)
173 ctrl->removeImage(old);
174
175 return ret;
176 }
177
178 }
This page took 0.039417 seconds and 4 git commands to generate.