~ubuntu-branches/ubuntu/trusty/fluxbox/trusty-proposed

« back to all changes in this revision

Viewing changes to src/FbTk/Texture.cc

  • Committer: Bazaar Package Importer
  • Author(s): Dmitry E. Oboukhov
  • Date: 2008-07-01 10:38:14 UTC
  • mfrom: (2.1.12 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080701103814-khx2b6il152x9p93
Tags: 1.0.0+deb1-8
* x-dev has been removed from build-depends (out-of-date package).
* Standards-Version bumped to 3.8.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Texture.hh for Fluxbox Window Manager 
2
 
// Copyright (c) 2002 - 2005 Henrik Kinnunen (fluxgen at fluxbox dot org)
3
 
//
4
 
// from Image.cc for Blackbox - an X11 Window manager
5
 
// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
6
 
//
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:
13
 
//
14
 
// The above copyright notice and this permission notice shall be included in
15
 
// all copies or substantial portions of the Software.
16
 
//
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.
24
 
 
25
 
// $Id: Texture.cc 4043 2005-06-03 07:25:48Z mathias $
26
 
 
27
 
#include "App.hh"
28
 
#include "Texture.hh"
29
 
 
30
 
#include <X11/Xlib.h>
31
 
#ifdef HAVE_CSTRING
32
 
  #include <cstring>
33
 
#else
34
 
  #include <string.h>
35
 
#endif
36
 
#ifdef HAVE_CCTYPE
37
 
  #include <cctype>
38
 
#else
39
 
  #include <ctype.h>
40
 
#endif
41
 
 
42
 
namespace FbTk {
43
 
 
44
 
void Texture::setFromString(const char * const texture_str) {
45
 
    if (texture_str == 0)
46
 
        return;
47
 
    int t_len = strlen(texture_str) + 1;
48
 
    char *ts = new char[t_len];
49
 
    strcpy(ts, texture_str);
50
 
 
51
 
    // to lower
52
 
    for (size_t byte_pos = 0; byte_pos < strlen(ts); ++byte_pos)
53
 
        ts[byte_pos] = tolower(ts[byte_pos]);
54
 
 
55
 
    if (strstr(ts, "parentrelative")) {
56
 
        setType(Texture::PARENTRELATIVE);
57
 
    } else {
58
 
        setType(Texture::NONE);
59
 
 
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);
78
 
            else
79
 
                addType(Texture::DIAGONAL);
80
 
        } else // default is "solid", according to ThemeItems.cc
81
 
            addType(Texture::SOLID);
82
 
 
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);
89
 
 
90
 
        if (! (type() & Texture::FLAT))
91
 
            if (strstr(ts, "bevel2"))
92
 
                addType(Texture::BEVEL2);
93
 
            else
94
 
                addType(Texture::BEVEL1);
95
 
 
96
 
        if (strstr(ts, "invert"))
97
 
            addType(Texture::INVERT);
98
 
 
99
 
        if (strstr(ts, "interlaced"))
100
 
            addType(Texture::INTERLACED);
101
 
 
102
 
        if (strstr(ts, "tiled"))
103
 
            addType(Texture::TILED);
104
 
    }
105
 
 
106
 
    delete [] ts;
107
 
}
108
 
 
109
 
void Texture::calcHiLoColors(int screen_num) {
110
 
    Display *disp = FbTk::App::instance()->display();
111
 
    XColor xcol;
112
 
    Colormap colm = DefaultColormap(disp, screen_num);
113
 
 
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;
126
 
 
127
 
    if (! XAllocColor(disp, colm, &xcol))
128
 
        xcol.pixel = 0;
129
 
 
130
 
    m_hicolor.setPixel(xcol.pixel);
131
 
 
132
 
    xcol.red =
133
 
        (unsigned int) ((m_color.red() >> 2) +
134
 
                        (m_color.red() >> 1)) * 0xff;
135
 
    xcol.green =
136
 
        (unsigned int) ((m_color.green() >> 2) +
137
 
                        (m_color.green() >> 1)) * 0xff;
138
 
    xcol.blue =
139
 
        (unsigned int) ((m_color.blue() >> 2) +
140
 
                        (m_color.blue() >> 1)) * 0xff;
141
 
 
142
 
    if (! XAllocColor(disp, colm, &xcol))
143
 
        xcol.pixel = 0;
144
 
 
145
 
    m_locolor.setPixel(xcol.pixel);
146
 
}
147
 
 
148
 
}; // end namespace FbTk