]> Dogcows Code - chaz/openbox/blob - src/texture.cc
add comment for later
[chaz/openbox] / src / texture.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // Texture.cc for Blackbox - an X11 Window manager
3 // Copyright (c) 2001 - 2002 Sean 'Shaleh' Perry <shaleh at debian.org>
4 // Copyright (c) 1997 - 2000, 2002 Bradley T Hughes <bhughes at trolltech.com>
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a
7 // copy of this software and associated documentation files (the "Software"),
8 // to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 // and/or sell copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 // DEALINGS IN THE SOFTWARE.
23
24 #ifdef HAVE_CONFIG_H
25 # include "../config.h"
26 #endif // HAVE_CONFIG_H
27
28 extern "C" {
29 #include <stdio.h>
30 #ifdef HAVE_CTYPE_H
31 #include <ctype.h>
32 #endif
33 }
34
35 #include <assert.h>
36
37 #include "texture.hh"
38 #include "basedisplay.hh"
39 #include "image.hh"
40 #include "screen.hh"
41 #include "blackbox.hh"
42
43 using std::string;
44
45
46 BTexture::BTexture(const BaseDisplay * const _display,
47 unsigned int _screen, BImageControl* _ctrl)
48 : c(_display, _screen), ct(_display, _screen),
49 lc(_display, _screen), sc(_display, _screen), bc(_display, _screen), t(0),
50 dpy(_display), ctrl(_ctrl), scrn(_screen) { }
51
52
53 BTexture::BTexture(const string &d, const BaseDisplay * const _display,
54 unsigned int _screen, BImageControl* _ctrl)
55 : c(_display, _screen), ct(_display, _screen),
56 lc(_display, _screen), sc(_display, _screen), bc(_display, _screen), t(0),
57 dpy(_display), ctrl(_ctrl), scrn(_screen) {
58 setDescription(d);
59 }
60
61
62 void BTexture::setColor(const BColor &cc) {
63 c = cc;
64 c.setDisplay(display(), screen());
65
66 unsigned char r, g, b, rr, gg, bb;
67
68 // calculate the light color
69 r = c.red();
70 g = c.green();
71 b = c.blue();
72 rr = r + (r >> 1);
73 gg = g + (g >> 1);
74 bb = b + (b >> 1);
75 if (rr < r) rr = ~0;
76 if (gg < g) gg = ~0;
77 if (bb < b) bb = ~0;
78 lc = BColor(rr, gg, bb, display(), screen());
79
80 // calculate the shadow color
81 r = c.red();
82 g = c.green();
83 b = c.blue();
84 rr = (r >> 2) + (r >> 1);
85 gg = (g >> 2) + (g >> 1);
86 bb = (b >> 2) + (b >> 1);
87 if (rr > r) rr = 0;
88 if (gg > g) gg = 0;
89 if (bb > b) bb = 0;
90 sc = BColor(rr, gg, bb, display(), screen());
91 }
92
93
94 void BTexture::setDescription(const string &d) {
95 descr.erase();
96 descr.reserve(d.length());
97
98 string::const_iterator it = d.begin(), end = d.end();
99 for (; it != end; ++it)
100 descr += tolower(*it);
101
102 if (descr.find("parentrelative") != string::npos) {
103 setTexture(BTexture::Parent_Relative);
104 } else {
105 setTexture(0);
106
107 if (descr.find("gradient") != string::npos) {
108 addTexture(BTexture::Gradient);
109 if (descr.find("crossdiagonal") != string::npos)
110 addTexture(BTexture::CrossDiagonal);
111 else if (descr.find("rectangle") != string::npos)
112 addTexture(BTexture::Rectangle);
113 else if (descr.find("pyramid") != string::npos)
114 addTexture(BTexture::Pyramid);
115 else if (descr.find("pipecross") != string::npos)
116 addTexture(BTexture::PipeCross);
117 else if (descr.find("elliptic") != string::npos)
118 addTexture(BTexture::Elliptic);
119 else if (descr.find("horizontal") != string::npos)
120 addTexture(BTexture::Horizontal);
121 else if (descr.find("vertical") != string::npos)
122 addTexture(BTexture::Vertical);
123 else
124 addTexture(BTexture::Diagonal);
125 } else {
126 addTexture(BTexture::Solid);
127 }
128
129 if (descr.find("sunken") != string::npos)
130 addTexture(BTexture::Sunken);
131 else if (descr.find("flat") != string::npos)
132 addTexture(BTexture::Flat);
133 else
134 addTexture(BTexture::Raised);
135
136 if (texture() & BTexture::Flat) {
137 if (descr.find("border") != string::npos)
138 addTexture(BTexture::Border);
139 } else {
140 if (descr.find("bevel2") != string::npos)
141 addTexture(BTexture::Bevel2);
142 else
143 addTexture(BTexture::Bevel1);
144 }
145
146 if (descr.find("interlaced") != string::npos)
147 addTexture(BTexture::Interlaced);
148 }
149 }
150
151 void BTexture::setDisplay(const BaseDisplay * const _display,
152 const unsigned int _screen) {
153 if (_display == display() && _screen == screen()) {
154 // nothing to do
155 return;
156 }
157
158 dpy = _display;
159 scrn = _screen;
160 c.setDisplay(_display, _screen);
161 ct.setDisplay(_display, _screen);
162 lc.setDisplay(_display, _screen);
163 sc.setDisplay(_display, _screen);
164 bc.setDisplay(_display, _screen);
165 }
166
167
168 BTexture& BTexture::operator=(const BTexture &tt) {
169 c = tt.c;
170 ct = tt.ct;
171 lc = tt.lc;
172 sc = tt.sc;
173 bc = tt.bc;
174 descr = tt.descr;
175 t = tt.t;
176 dpy = tt.dpy;
177 scrn = tt.scrn;
178 ctrl = tt.ctrl;
179
180 return *this;
181 }
182
183
184 Pixmap BTexture::render(const unsigned int width, const unsigned int height,
185 const Pixmap old) {
186 assert(display() != 0);
187 assert(texture() != BTexture::NoTexture);
188
189 if (texture() == (BTexture::Flat | BTexture::Solid))
190 return None;
191 if (texture() == BTexture::Parent_Relative)
192 return ParentRelative;
193
194 if (screen() == ~(0u))
195 scrn = DefaultScreen(display()->getXDisplay());
196
197 assert(ctrl != 0);
198 Pixmap ret = ctrl->renderImage(width, height, *this);
199
200 if (old)
201 ctrl->removeImage(old);
202
203 return ret;
204 }
This page took 0.041542 seconds and 4 git commands to generate.