File: Xpm.cc

package info (click to toggle)
mixer.app 1.8.0-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 204 kB
  • ctags: 68
  • sloc: cpp: 589; makefile: 58
file content (107 lines) | stat: -rw-r--r-- 2,865 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//
//  Mixer.app
// 
//  Copyright (c) 1998-2002 Per Liden
// 
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 
//  USA.
//

#include <X11/Xlib.h>
#include <X11/xpm.h>
#include <X11/extensions/shape.h>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include "Mixer.h"
#include "Xpm.h"

using namespace std;

Xpm::Xpm(Display* display, Window root, char** data) 
{
   int error;

   mDisplay = display;

   mAttributes.valuemask = 0;
   error = XpmCreatePixmapFromData(mDisplay, root, data, &mImage, &mMask, &mAttributes);

   switch (error) {
   case XpmColorError:
      cerr << APPNAME << ": xpm image loaded but did not get all colors needed" << endl;
      break;

   case XpmColorFailed:
      cerr << APPNAME << ": could not load xpm image (not enough colors available)" << endl;
      exit(0);
      break;

   case XpmNoMemory:
      cerr << APPNAME << ": could not load xpm image (not enough memory available)" << endl;
      exit(0);
      break;

   case XpmOpenFailed:
   case XpmFileInvalid:
      cerr << APPNAME << ": could not load xpm image (image broken or corrupt)" << endl;
      exit(0);
      break;

   case XpmSuccess:
   default:
      // Image loaded ok
      break;
   }
}

Xpm::~Xpm() 
{
   if (mImage) {
      XFreePixmap(mDisplay, mImage);
   }

   if (mMask) {
      XFreePixmap(mDisplay, mMask);
   }
}

void Xpm::setWindowPixmap(Window win) 
{
   XResizeWindow(mDisplay, win, mAttributes.width, mAttributes.height);
   XSetWindowBackgroundPixmap(mDisplay, win, mImage);
}

void Xpm::setWindowPixmapShaped(Window win) 
{
   XResizeWindow(mDisplay, win, mAttributes.width, mAttributes.height);
   XSetWindowBackgroundPixmap(mDisplay, win, mImage);
   XShapeCombineMask(mDisplay, win, ShapeBounding, 0, 0, mMask, ShapeSet);
}

void Xpm::drawString(int x, int y, char* text) 
{
   Font      font;
   GC        gc;
   XGCValues gcv;

   font = XLoadFont(mDisplay, LABEL_FONT);
   gcv.font = font;
   gcv.foreground = WhitePixel(mDisplay, DefaultScreen(mDisplay));
   gc = XCreateGC(mDisplay, mImage, GCFont | GCForeground, &gcv);
   XDrawString(mDisplay, mImage, gc, x, y, text, strlen(text));
   XFreeGC(mDisplay, gc);
   XUnloadFont(mDisplay, font);
}