]>
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
24 BTexture::BTexture(unsigned int _screen
, BImageControl
* _ctrl
)
25 : c(_screen
), ct(_screen
),
26 lc(_screen
), sc(_screen
), bc(_screen
), t(0),
27 ctrl(_ctrl
), scrn(_screen
) { }
30 BTexture::BTexture(const string
&d
,unsigned int _screen
, BImageControl
* _ctrl
)
31 : c(_screen
), ct(_screen
),
32 lc(_screen
), sc(_screen
), bc(_screen
), t(0),
33 ctrl(_ctrl
), scrn(_screen
) {
38 void BTexture::setColor(const BColor
&cc
) {
40 c
.setScreen(screen());
42 unsigned char r
, g
, b
, rr
, gg
, bb
;
44 // calculate the light color
54 lc
= BColor(rr
, gg
, bb
, screen());
56 // calculate the shadow color
60 rr
= (r
>> 2) + (r
>> 1);
61 gg
= (g
>> 2) + (g
>> 1);
62 bb
= (b
>> 2) + (b
>> 1);
66 sc
= BColor(rr
, gg
, bb
, screen());
70 void BTexture::setDescription(const string
&d
) {
72 descr
.reserve(d
.length());
74 string::const_iterator it
= d
.begin(), end
= d
.end();
75 for (; it
!= end
; ++it
)
76 descr
+= tolower(*it
);
78 if (descr
.find("parentrelative") != string::npos
) {
79 setTexture(BTexture::Parent_Relative
);
83 if (descr
.find("gradient") != string::npos
) {
84 addTexture(BTexture::Gradient
);
85 if (descr
.find("crossdiagonal") != string::npos
)
86 addTexture(BTexture::CrossDiagonal
);
87 else if (descr
.find("rectangle") != string::npos
)
88 addTexture(BTexture::Rectangle
);
89 else if (descr
.find("pyramid") != string::npos
)
90 addTexture(BTexture::Pyramid
);
91 else if (descr
.find("pipecross") != string::npos
)
92 addTexture(BTexture::PipeCross
);
93 else if (descr
.find("elliptic") != string::npos
)
94 addTexture(BTexture::Elliptic
);
95 else if (descr
.find("horizontal") != string::npos
)
96 addTexture(BTexture::Horizontal
);
97 else if (descr
.find("vertical") != string::npos
)
98 addTexture(BTexture::Vertical
);
100 addTexture(BTexture::Diagonal
);
102 addTexture(BTexture::Solid
);
105 if (descr
.find("sunken") != string::npos
)
106 addTexture(BTexture::Sunken
);
107 else if (descr
.find("flat") != string::npos
)
108 addTexture(BTexture::Flat
);
110 addTexture(BTexture::Raised
);
112 if (texture() & BTexture::Flat
) {
113 if (descr
.find("border") != string::npos
)
114 addTexture(BTexture::Border
);
116 if (descr
.find("bevel2") != string::npos
)
117 addTexture(BTexture::Bevel2
);
119 addTexture(BTexture::Bevel1
);
122 if (descr
.find("interlaced") != string::npos
)
123 addTexture(BTexture::Interlaced
);
127 void BTexture::setScreen(const unsigned int _screen
) {
128 if (_screen
== screen()) {
134 c
.setScreen(_screen
);
135 ct
.setScreen(_screen
);
136 lc
.setScreen(_screen
);
137 sc
.setScreen(_screen
);
138 bc
.setScreen(_screen
);
142 BTexture
& BTexture::operator=(const BTexture
&tt
) {
157 Pixmap
BTexture::render(const unsigned int width
, const unsigned int height
,
159 assert(texture() != BTexture::NoTexture
);
161 // if (texture() == (BTexture::Flat | BTexture::Solid))
163 if (texture() == BTexture::Parent_Relative
)
164 return ParentRelative
;
166 if (screen() == ~(0u))
167 scrn
= DefaultScreen(OBDisplay::display
);
170 Pixmap ret
= ctrl
->renderImage(width
, height
, *this);
173 ctrl
->removeImage(old
);
This page took 0.042406 seconds and 4 git commands to generate.