4 // Copyright (c) 2000-2002 Per Liden
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,
24 #include <X11/extensions/shape.h>
28 #include "Temperature.h"
31 Xpm::Xpm(Display
* display
, Window root
, char** data
)
37 mAttributes
.valuemask
= 0;
38 error
= XpmCreatePixmapFromData(mDisplay
, root
, data
, &mImage
, &mMask
, &mAttributes
);
42 std::cerr
<< APPNAME
<< ": xpm image loaded but did not get all colors needed" << std::endl
;
46 std::cerr
<< APPNAME
<< ": could not load xpm image (not enough colors available)" << std::endl
;
51 std::cerr
<< APPNAME
<< ": could not load xpm image (not enough memory available)" << std::endl
;
57 std::cerr
<< APPNAME
<< ": could not load xpm image (image broken or corrupt)" << std::endl
;
71 XFreePixmap(mDisplay
, mImage
);
75 XFreePixmap(mDisplay
, mMask
);
79 void Xpm::setWindowPixmap(Window win
)
81 XResizeWindow(mDisplay
, win
, mAttributes
.width
, mAttributes
.height
);
82 XSetWindowBackgroundPixmap(mDisplay
, win
, mImage
);
83 XClearWindow(mDisplay
, win
);
86 void Xpm::setWindowPixmapShaped(Window win
)
88 XResizeWindow(mDisplay
, win
, mAttributes
.width
, mAttributes
.height
);
89 XSetWindowBackgroundPixmap(mDisplay
, win
, mImage
);
90 XShapeCombineMask(mDisplay
, win
, ShapeBounding
, 0, 0, mMask
, ShapeSet
);
91 XClearWindow(mDisplay
, win
);
94 void Xpm::drawString(int pos
, char* font
, char* str
)
96 XFontStruct
* fontStruct
;
100 if ((fontStruct
= XLoadQueryFont(mDisplay
, font
)) == 0) {
101 cerr
<< APPNAME
<< ": could not load font '" << font
<< "'" << endl
;
105 gcv
.foreground
= WhitePixel(mDisplay
, DefaultScreen(mDisplay
));
106 gc
= XCreateGC(mDisplay
, mImage
, GCForeground
, &gcv
);
108 int strLength
= strlen(str
);
109 int strWidth
= XTextWidth(fontStruct
, str
, strLength
);
111 int x
= (64 / 2) - (strWidth
/ 2);
112 XSetFont(mDisplay
, gc
, fontStruct
->fid
);
113 XDrawString(mDisplay
, mImage
, gc
, x
, pos
, str
, strLength
);
115 XFreeGC(mDisplay
, gc
);
116 XFreeFont(mDisplay
, fontStruct
);
119 void Xpm::drawComposedString(int pos
, char* font1
, char* str1
, char* font2
, char* str2
)
121 XFontStruct
* fontStruct1
;
122 XFontStruct
* fontStruct2
;
126 if ((fontStruct1
= XLoadQueryFont(mDisplay
, font1
)) == 0) {
127 cerr
<< APPNAME
<< ": could not load font '" << font1
<< "'" << endl
;
131 if ((fontStruct2
= XLoadQueryFont(mDisplay
, font2
)) == 0) {
132 cerr
<< APPNAME
<< ": could not load font '" << font2
<< "'" << endl
;
136 gcv
.foreground
= WhitePixel(mDisplay
, DefaultScreen(mDisplay
));
137 gc
= XCreateGC(mDisplay
, mImage
, GCForeground
, &gcv
);
139 int str1Length
= strlen(str1
);
140 int str1Width
= XTextWidth(fontStruct1
, str1
, str1Length
);
141 int str2Length
= strlen(str2
);
142 int str2Width
= XTextWidth(fontStruct2
, str2
, str2Length
);
144 int x
= (64 / 2) - ((str1Width
+ str2Width
) / 2);
145 XSetFont(mDisplay
, gc
, fontStruct1
->fid
);
146 XDrawString(mDisplay
, mImage
, gc
, x
, pos
, str1
, str1Length
);
149 XSetFont(mDisplay
, gc
, fontStruct2
->fid
);
150 XDrawString(mDisplay
, mImage
, gc
, x
, pos
, str2
, str2Length
);
152 XFreeGC(mDisplay
, gc
);
153 XFreeFont(mDisplay
, fontStruct1
);
154 XFreeFont(mDisplay
, fontStruct2
);