asbeats: Add format string to fprintf().
[dockapps.git] / AlsaMixer.app / Xpm.cc
blob86be0635492187b812edff32db7d32b173ad7a42
1 //
2 // Mixer.app
3 //
4 // Copyright (c) 1998-2002 Per Liden
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307,
19 // USA.
22 #include <X11/Xlib.h>
23 #include <X11/xpm.h>
24 #include <X11/extensions/shape.h>
25 #include <iostream>
26 #include <cstdlib>
27 #include <cstring>
28 #include "Mixer.h"
29 #include "Xpm.h"
31 using namespace std;
33 Xpm::Xpm(Display* display, Window root, char** data)
35 int error;
37 mDisplay = display;
39 mAttributes.valuemask = 0;
40 error = XpmCreatePixmapFromData(mDisplay, root, data, &mImage, &mMask, &mAttributes);
42 switch (error) {
43 case XpmColorError:
44 cerr << APPNAME << ": xpm image loaded but did not get all colors needed" << endl;
45 break;
47 case XpmColorFailed:
48 cerr << APPNAME << ": could not load xpm image (not enough colors available)" << endl;
49 exit(0);
50 break;
52 case XpmNoMemory:
53 cerr << APPNAME << ": could not load xpm image (not enough memory available)" << endl;
54 exit(0);
55 break;
57 case XpmOpenFailed:
58 case XpmFileInvalid:
59 cerr << APPNAME << ": could not load xpm image (image broken or corrupt)" << endl;
60 exit(0);
61 break;
63 case XpmSuccess:
64 default:
65 // Image loaded ok
66 break;
70 Xpm::~Xpm()
72 if (mImage) {
73 XFreePixmap(mDisplay, mImage);
76 if (mMask) {
77 XFreePixmap(mDisplay, mMask);
81 void Xpm::setWindowPixmap(Window win)
83 XResizeWindow(mDisplay, win, mAttributes.width, mAttributes.height);
84 XSetWindowBackgroundPixmap(mDisplay, win, mImage);
87 void Xpm::setWindowPixmapShaped(Window win)
89 XResizeWindow(mDisplay, win, mAttributes.width, mAttributes.height);
90 XSetWindowBackgroundPixmap(mDisplay, win, mImage);
91 XShapeCombineMask(mDisplay, win, ShapeBounding, 0, 0, mMask, ShapeSet);
94 void Xpm::drawString(int x, int y, char* text)
96 Font font;
97 GC gc;
98 XGCValues gcv;
100 font = XLoadFont(mDisplay, LABEL_FONT);
101 gcv.font = font;
102 gcv.foreground = WhitePixel(mDisplay, DefaultScreen(mDisplay));
103 gc = XCreateGC(mDisplay, mImage, GCFont | GCForeground, &gcv);
104 XDrawString(mDisplay, mImage, gc, x, y, text, strlen(text));
105 XFreeGC(mDisplay, gc);
106 XUnloadFont(mDisplay, font);