]>
Dogcows Code - chaz/openbox/blob - otk/texture.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
5 #endif // HAVE_CONFIG_H
17 #include "basedisplay.hh"
20 #include "blackbox.hh"
25 BTexture::BTexture(const BaseDisplay
* const _display
,
26 unsigned int _screen
, BImageControl
* _ctrl
)
27 : c(_display
, _screen
), ct(_display
, _screen
),
28 lc(_display
, _screen
), sc(_display
, _screen
), bc(_display
, _screen
), t(0),
29 dpy(_display
), ctrl(_ctrl
), scrn(_screen
) { }
32 BTexture::BTexture(const string
&d
, const BaseDisplay
* const _display
,
33 unsigned int _screen
, BImageControl
* _ctrl
)
34 : c(_display
, _screen
), ct(_display
, _screen
),
35 lc(_display
, _screen
), sc(_display
, _screen
), bc(_display
, _screen
), t(0),
36 dpy(_display
), ctrl(_ctrl
), scrn(_screen
) {
41 void BTexture::setColor(const BColor
&cc
) {
43 c
.setDisplay(display(), screen());
45 unsigned char r
, g
, b
, rr
, gg
, bb
;
47 // calculate the light color
57 lc
= BColor(rr
, gg
, bb
, display(), screen());
59 // calculate the shadow color
63 rr
= (r
>> 2) + (r
>> 1);
64 gg
= (g
>> 2) + (g
>> 1);
65 bb
= (b
>> 2) + (b
>> 1);
69 sc
= BColor(rr
, gg
, bb
, display(), screen());
73 void BTexture::setDescription(const string
&d
) {
75 descr
.reserve(d
.length());
77 string::const_iterator it
= d
.begin(), end
= d
.end();
78 for (; it
!= end
; ++it
)
79 descr
+= tolower(*it
);
81 if (descr
.find("parentrelative") != string::npos
) {
82 setTexture(BTexture::Parent_Relative
);
86 if (descr
.find("gradient") != string::npos
) {
87 addTexture(BTexture::Gradient
);
88 if (descr
.find("crossdiagonal") != string::npos
)
89 addTexture(BTexture::CrossDiagonal
);
90 else if (descr
.find("rectangle") != string::npos
)
91 addTexture(BTexture::Rectangle
);
92 else if (descr
.find("pyramid") != string::npos
)
93 addTexture(BTexture::Pyramid
);
94 else if (descr
.find("pipecross") != string::npos
)
95 addTexture(BTexture::PipeCross
);
96 else if (descr
.find("elliptic") != string::npos
)
97 addTexture(BTexture::Elliptic
);
98 else if (descr
.find("horizontal") != string::npos
)
99 addTexture(BTexture::Horizontal
);
100 else if (descr
.find("vertical") != string::npos
)
101 addTexture(BTexture::Vertical
);
103 addTexture(BTexture::Diagonal
);
105 addTexture(BTexture::Solid
);
108 if (descr
.find("sunken") != string::npos
)
109 addTexture(BTexture::Sunken
);
110 else if (descr
.find("flat") != string::npos
)
111 addTexture(BTexture::Flat
);
113 addTexture(BTexture::Raised
);
115 if (texture() & BTexture::Flat
) {
116 if (descr
.find("border") != string::npos
)
117 addTexture(BTexture::Border
);
119 if (descr
.find("bevel2") != string::npos
)
120 addTexture(BTexture::Bevel2
);
122 addTexture(BTexture::Bevel1
);
125 if (descr
.find("interlaced") != string::npos
)
126 addTexture(BTexture::Interlaced
);
130 void BTexture::setDisplay(const BaseDisplay
* const _display
,
131 const unsigned int _screen
) {
132 if (_display
== display() && _screen
== screen()) {
139 c
.setDisplay(_display
, _screen
);
140 ct
.setDisplay(_display
, _screen
);
141 lc
.setDisplay(_display
, _screen
);
142 sc
.setDisplay(_display
, _screen
);
143 bc
.setDisplay(_display
, _screen
);
147 BTexture
& BTexture::operator=(const BTexture
&tt
) {
163 Pixmap
BTexture::render(const unsigned int width
, const unsigned int height
,
165 assert(display() != 0);
166 assert(texture() != BTexture::NoTexture
);
168 if (texture() == (BTexture::Flat
| BTexture::Solid
))
170 if (texture() == BTexture::Parent_Relative
)
171 return ParentRelative
;
173 if (screen() == ~(0u))
174 scrn
= DefaultScreen(display()->getXDisplay());
177 Pixmap ret
= ctrl
->renderImage(width
, height
, *this);
180 ctrl
->removeImage(old
);
This page took 0.038676 seconds and 4 git commands to generate.