1
// Texture.hh for Fluxbox Window Manager
2
// Copyright (c) 2002 - 2005 Henrik Kinnunen (fluxgen at fluxbox dot org)
4
// from Image.cc for Blackbox - an X11 Window manager
5
// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
7
// Permission is hereby granted, free of charge, to any person obtaining a
8
// copy of this software and associated documentation files (the "Software"),
9
// to deal in the Software without restriction, including without limitation
10
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
11
// and/or sell copies of the Software, and to permit persons to whom the
12
// Software is furnished to do so, subject to the following conditions:
14
// The above copyright notice and this permission notice shall be included in
15
// all copies or substantial portions of the Software.
17
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23
// DEALINGS IN THE SOFTWARE.
25
// $Id: Texture.cc 4043 2005-06-03 07:25:48Z mathias $
44
void Texture::setFromString(const char * const texture_str) {
47
int t_len = strlen(texture_str) + 1;
48
char *ts = new char[t_len];
49
strcpy(ts, texture_str);
52
for (size_t byte_pos = 0; byte_pos < strlen(ts); ++byte_pos)
53
ts[byte_pos] = tolower(ts[byte_pos]);
55
if (strstr(ts, "parentrelative")) {
56
setType(Texture::PARENTRELATIVE);
58
setType(Texture::NONE);
60
if (strstr(ts, "gradient")) {
61
addType(Texture::GRADIENT);
62
if (strstr(ts, "crossdiagonal"))
63
addType(Texture::CROSSDIAGONAL);
64
else if (strstr(ts, "rectangle"))
65
addType(Texture::RECTANGLE);
66
else if (strstr(ts, "pyramid"))
67
addType(Texture::PYRAMID);
68
else if (strstr(ts, "pipecross"))
69
addType(Texture::PIPECROSS);
70
else if (strstr(ts, "elliptic"))
71
addType(Texture::ELLIPTIC);
72
else if (strstr(ts, "diagonal"))
73
addType(Texture::DIAGONAL);
74
else if (strstr(ts, "horizontal"))
75
addType(Texture::HORIZONTAL);
76
else if (strstr(ts, "vertical"))
77
addType(Texture::VERTICAL);
79
addType(Texture::DIAGONAL);
80
} else // default is "solid", according to ThemeItems.cc
81
addType(Texture::SOLID);
83
if (strstr(ts, "raised"))
84
addType(Texture::RAISED);
85
else if (strstr(ts, "sunken"))
86
addType(Texture::SUNKEN);
87
else // default us "flat", according to ThemeItems.cc
88
addType(Texture::FLAT);
90
if (! (type() & Texture::FLAT))
91
if (strstr(ts, "bevel2"))
92
addType(Texture::BEVEL2);
94
addType(Texture::BEVEL1);
96
if (strstr(ts, "invert"))
97
addType(Texture::INVERT);
99
if (strstr(ts, "interlaced"))
100
addType(Texture::INTERLACED);
102
if (strstr(ts, "tiled"))
103
addType(Texture::TILED);
109
void Texture::calcHiLoColors(int screen_num) {
110
Display *disp = FbTk::App::instance()->display();
112
Colormap colm = DefaultColormap(disp, screen_num);
114
xcol.red = (unsigned int) (m_color.red() +
115
(m_color.red() >> 1));
116
if (xcol.red >= 0xff) xcol.red = 0xffff;
117
else xcol.red *= 0xff;
118
xcol.green = (unsigned int) (m_color.green() +
119
(m_color.green() >> 1));
120
if (xcol.green >= 0xff) xcol.green = 0xffff;
121
else xcol.green *= 0xff;
122
xcol.blue = (unsigned int) (m_color.blue() +
123
(m_color.blue() >> 1));
124
if (xcol.blue >= 0xff) xcol.blue = 0xffff;
125
else xcol.blue *= 0xff;
127
if (! XAllocColor(disp, colm, &xcol))
130
m_hicolor.setPixel(xcol.pixel);
133
(unsigned int) ((m_color.red() >> 2) +
134
(m_color.red() >> 1)) * 0xff;
136
(unsigned int) ((m_color.green() >> 2) +
137
(m_color.green() >> 1)) * 0xff;
139
(unsigned int) ((m_color.blue() >> 2) +
140
(m_color.blue() >> 1)) * 0xff;
142
if (! XAllocColor(disp, colm, &xcol))
145
m_locolor.setPixel(xcol.pixel);
148
}; // end namespace FbTk