From c4333aeda129cb65d891808859bdc1a369d49766 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Thu, 10 Jul 2003 12:04:46 +0000 Subject: for round corners --- src/Shape.cc | 184 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/Shape.hh | 60 +++++++++++++++++++ 2 files changed, 244 insertions(+) create mode 100644 src/Shape.cc create mode 100644 src/Shape.hh 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 @@ +// Shape.cc +// Copyright (c) 2003 Henrik Kinnunen (fluxgen(at)users.sourceforge.net) +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +// $Id: Shape.cc,v 1.1 2003/07/10 12:04:46 fluxgen Exp $ + +#include "Shape.hh" +#include "FbWindow.hh" +#include "App.hh" + +#include + +#ifdef SHAPE +#include +#endif // SHAPE + +#include +#include +using namespace std; + +namespace { + +Pixmap createShape(FbTk::FbWindow &win, int place) { + if (win.window() == 0 || place == 0 || + win.width() < 3 || win.height() < 3) + return 0; + + static char left_bits[] = { 0xc0, 0xf8, 0xfc, 0xfe, 0xfe, 0xfe, 0xff, 0xff }; + static char right_bits[] = { 0x03, 0x1f, 0x3f, 0x7f, 0x7f, 0x7f, 0xff, 0xff}; + static char bottom_left_bits[] = { 0xff, 0xff, 0xfe, 0xfe, 0xfe, 0xfc, 0xf8, 0xc0 }; + static char bottom_right_bits[] = { 0xff, 0xff, 0x7f, 0x7f, 0x7f, 0x3f, 0x1f, 0x03 }; + + const int win_width = win.width() + 2*win.borderWidth(); + const int win_height = win.height() + 2*win.borderWidth(); + const int pixmap_width = min(8, win_width); + const int pixmap_height = min(8, win_height); + + Display *disp = FbTk::App::instance()->display(); + const size_t data_size = win_width * win_height; + char *data = new char[data_size]; + memset(data, 0xFF, data_size); + + XImage *ximage = XCreateImage(disp, + DefaultVisual(disp, DefaultScreen(disp)), + 1, + XYPixmap, 0, + data, + win_width, win_height, + 32, 0); + if (ximage == 0) + return 0; + + XInitImage(ximage); + + // shape corners + + if (place & Shape::TOPLEFT) { + for (int y=0; ydisplay(), m_shape); +} + +void Shape::setPlaces(int shapeplaces) { + m_shapeplaces = shapeplaces; +} + +void Shape::update() { + if (m_win == 0 || m_win->window() == 0) + return; +#ifdef SHAPE + if (m_win->width() != m_width || + m_win->height() != m_height) { + if (m_shape != 0) + XFreePixmap(FbTk::App::instance()->display(), m_shape); + m_shape = createShape(*m_win, m_shapeplaces); + m_width = m_win->width(); + m_height = m_win->height(); + + } + + if (m_shape == 0) + return; + + XShapeCombineMask(FbTk::App::instance()->display(), + m_win->window(), + ShapeBounding, + -1, 0, + m_shape, + ShapeSet); + +#endif // SHAPE + +} + +void Shape::setWindow(FbTk::FbWindow &win) { + m_win = &win; + update(); +} diff --git a/src/Shape.hh b/src/Shape.hh new file mode 100644 index 0000000..59c3722 --- /dev/null +++ b/src/Shape.hh @@ -0,0 +1,60 @@ +// Shape.hh +// Copyright (c) 2003 Henrik Kinnunen (fluxgen(at)users.sourceforge.net) +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +// $Id: Shape.hh,v 1.1 2003/07/10 12:04:46 fluxgen Exp $ + +#ifndef SHAPE_HH +#define SHAPE_HH + +#include + +namespace FbTk { +class FbWindow; +}; + +/// creates round corners on windows +class Shape { +public: + enum ShapePlace { + NONE = 0, + BOTTOMRIGHT = 0x01, + TOPRIGHT = 0x02, + BOTTOMLEFT = 0x04, + TOPLEFT = 0x08, + }; + + Shape(FbTk::FbWindow &win, int shapeplaces); + ~Shape(); + /// set new shape places + void setPlaces(int shapeplaces); + /// update our shape + void update(); + /// assign a new window + void setWindow(FbTk::FbWindow &win); +private: + FbTk::FbWindow *m_win; ///< window to be shaped + Pixmap m_shape; ///< our shape pixmap + int m_shapeplaces; ///< places to shape + unsigned int m_width; ///< width of window (the "old" size), if width != window width then shape resizes + unsigned int m_height; ///< height of window (the "old" size), if height != window height then shape resizes +}; + +#endif // SHAPE_HH -- cgit v0.11.2