aboutsummaryrefslogtreecommitdiff
path: root/src/Shape.cc
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2003-07-10 12:04:46 (GMT)
committerfluxgen <fluxgen>2003-07-10 12:04:46 (GMT)
commitc4333aeda129cb65d891808859bdc1a369d49766 (patch)
tree03e38746106b12d7688c6df97fb0cbaf0f0b188b /src/Shape.cc
parentd60a8c715eee17525399c98c30d206a4a2339435 (diff)
downloadfluxbox-c4333aeda129cb65d891808859bdc1a369d49766.zip
fluxbox-c4333aeda129cb65d891808859bdc1a369d49766.tar.bz2
for round corners
Diffstat (limited to 'src/Shape.cc')
-rw-r--r--src/Shape.cc184
1 files changed, 184 insertions, 0 deletions
diff --git a/src/Shape.cc b/src/Shape.cc
new file mode 100644
index 0000000..c176e78
--- /dev/null
+++ b/src/Shape.cc
@@ -0,0 +1,184 @@
1// Shape.cc
2// Copyright (c) 2003 Henrik Kinnunen (fluxgen(at)users.sourceforge.net)
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22// $Id: Shape.cc,v 1.1 2003/07/10 12:04:46 fluxgen Exp $
23
24#include "Shape.hh"
25#include "FbWindow.hh"
26#include "App.hh"
27
28#include <cstring>
29
30#ifdef SHAPE
31#include <X11/extensions/shape.h>
32#endif // SHAPE
33
34#include <iostream>
35#include <algorithm>
36using namespace std;
37
38namespace {
39
40Pixmap createShape(FbTk::FbWindow &win, int place) {
41 if (win.window() == 0 || place == 0 ||
42 win.width() < 3 || win.height() < 3)
43 return 0;
44
45 static char left_bits[] = { 0xc0, 0xf8, 0xfc, 0xfe, 0xfe, 0xfe, 0xff, 0xff };
46 static char right_bits[] = { 0x03, 0x1f, 0x3f, 0x7f, 0x7f, 0x7f, 0xff, 0xff};
47 static char bottom_left_bits[] = { 0xff, 0xff, 0xfe, 0xfe, 0xfe, 0xfc, 0xf8, 0xc0 };
48 static char bottom_right_bits[] = { 0xff, 0xff, 0x7f, 0x7f, 0x7f, 0x3f, 0x1f, 0x03 };
49
50 const int win_width = win.width() + 2*win.borderWidth();
51 const int win_height = win.height() + 2*win.borderWidth();
52 const int pixmap_width = min(8, win_width);
53 const int pixmap_height = min(8, win_height);
54
55 Display *disp = FbTk::App::instance()->display();
56 const size_t data_size = win_width * win_height;
57 char *data = new char[data_size];
58 memset(data, 0xFF, data_size);
59
60 XImage *ximage = XCreateImage(disp,
61 DefaultVisual(disp, DefaultScreen(disp)),
62 1,
63 XYPixmap, 0,
64 data,
65 win_width, win_height,
66 32, 0);
67 if (ximage == 0)
68 return 0;
69
70 XInitImage(ximage);
71
72 // shape corners
73
74 if (place & Shape::TOPLEFT) {
75 for (int y=0; y<pixmap_height; y++) {
76 for (int x=0; x<pixmap_width; x++) {
77 XPutPixel(ximage, x + 1, y, (left_bits[y] & (0x01 << x)) ? 1 : 0);
78 }
79 }
80 }
81
82 if (place & Shape::TOPRIGHT) {
83 for (int y=0; y<pixmap_height; y++) {
84 for (int x=0; x<pixmap_width; x++) {
85 XPutPixel(ximage, x + win_width - pixmap_width, y,
86 (right_bits[y] & (0x01 << x)) ? 1 : 0);
87 }
88 }
89 }
90
91 if (place & Shape::BOTTOMLEFT) {
92 for (int y=0; y<pixmap_height; y++) {
93 for (int x=0; x<pixmap_width; x++) {
94 XPutPixel(ximage, x + 1, y + win_height - pixmap_height,
95 (bottom_left_bits[y] & (0x01 << x)) ? 1 : 0);
96 }
97 }
98 }
99
100 if (place & Shape::BOTTOMRIGHT) {
101 for (int y=0; y<pixmap_height; y++) {
102 for (int x=0; x<pixmap_width; x++) {
103 XPutPixel(ximage, x + win_width - pixmap_width, y + win_height - pixmap_height,
104 (bottom_right_bits[y] & (0x01 << x)) ? 1 : 0);
105 }
106 }
107 }
108
109 for (int y = 0; y<pixmap_height; ++y) {
110 XPutPixel(ximage, 0, y, 1);
111 }
112
113 XGCValues values;
114 values.foreground = 1;
115 values.background = 0;
116 Pixmap pm = XCreatePixmap(disp, win.window(), win_width, win_height, 1);
117 GC gc = XCreateGC(disp, pm,
118 GCForeground | GCBackground, &values);
119
120
121 XPutImage(disp, pm, gc, ximage, 0, 0, 0, 0,
122 win_width, win_height);
123
124 XFreeGC(disp, gc);
125 XDestroyImage(ximage);
126
127 return pm;
128
129
130}
131
132}; // end anonymous namespace
133
134Shape::Shape(FbTk::FbWindow &win, int shapeplaces):
135 m_win(&win),
136 m_shapeplaces(shapeplaces) {
137
138 m_shape = createShape(win, shapeplaces);
139 m_width = win.width();
140 m_height = win.height();
141
142}
143
144Shape::~Shape() {
145 if (m_shape != 0)
146 XFreePixmap(FbTk::App::instance()->display(), m_shape);
147}
148
149void Shape::setPlaces(int shapeplaces) {
150 m_shapeplaces = shapeplaces;
151}
152
153void Shape::update() {
154 if (m_win == 0 || m_win->window() == 0)
155 return;
156#ifdef SHAPE
157 if (m_win->width() != m_width ||
158 m_win->height() != m_height) {
159 if (m_shape != 0)
160 XFreePixmap(FbTk::App::instance()->display(), m_shape);
161 m_shape = createShape(*m_win, m_shapeplaces);
162 m_width = m_win->width();
163 m_height = m_win->height();
164
165 }
166
167 if (m_shape == 0)
168 return;
169
170 XShapeCombineMask(FbTk::App::instance()->display(),
171 m_win->window(),
172 ShapeBounding,
173 -1, 0,
174 m_shape,
175 ShapeSet);
176
177#endif // SHAPE
178
179}
180
181void Shape::setWindow(FbTk::FbWindow &win) {
182 m_win = &win;
183 update();
184}