Use proper namespace for iostream classes
[AXE.git] / src / pixmap.h
1 /**************************************************************************
2 **  (c) Copyright 1998, Andromeda Technology & Automation
3 ***************************************************************************
4 ** MODULE INFORMATION *
5 ***********************
6 **      FILE NAME      : pixmap.h
7 **      SYSTEM NAME    : AXE - Andromeda X-windows Encapsulation
8 **      VERSION NUMBER : $Revision: 1.2 $
9 **
10 **  DESCRIPTION      : Definition of pixmap classes: pixmap, bitmap
11 **
12 **  EXPORTED OBJECTS : class pixmap
13 **  LOCAL    OBJECTS : 
14 **  MODULES  USED    :
15 ***************************************************************************
16 **  ADMINISTRATIVE INFORMATION *
17 ********************************
18 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
19 **      CREATION DATE   : Jul 13, 2000
20 **      MODIFICATIONS   : 
21 **************************************************************************/
22
23 /*****************************
24    $Log: pixmap.h,v $
25    Revision 1.2  2002-11-04 07:24:31  arjen
26    Use proper namespace for iostream classes
27
28    Revision 1.1  2002/07/25 08:01:27  arjen
29    First checkin, AXE release 0.2
30
31 *****************************/
32
33 /* static const char *RCSID = "$Id: pixmap.h,v 1.2 2002-11-04 07:24:31 arjen Exp $"; */
34
35 #ifndef AXE_PIXMAP_H
36 #define AXE_PIXMAP_H
37
38 #include <X11/Xlib.h>
39 #include <X11/xpm.h>
40 #include "display.h"
41
42 /*
43 ///////////////////////////////////////////////////////////////////////////
44 //  NAME           : pixmap
45 //  BASECLASS      :
46 //  MEMBERS        : Pixmap pixm;
47 //  OPERATORS      :
48 //  METHODS        :
49 //
50 //  DESCRIPTION    :
51 //
52 //  RELATIONS      :
53 //  SEE ALSO       :
54 //  LAST MODIFIED  : Jul 13, 2000
55 ///////////////////////////////////////////////////////////////////////////
56 */
57
58 class pixmap
59 {
60    Pixmap pixm;
61    unsigned   w, h;   //  Size of the pixmap
62
63 public:
64
65    pixmap()
66    {
67       pixm = 0;
68    }
69
70    pixmap(char *data, unsigned int w, unsigned int h)
71    {
72       pixm = XCreateBitmapFromData(stddpy, stddpy.Root(), data, w, h);
73    }
74
75    pixmap(char *filename)
76    {
77       XpmAttributes    attr;
78
79       attr.valuemask = 0;
80
81       XpmReadFileToPixmap(stddpy, stddpy.Root(), filename, &pixm, NULL, &attr);
82       w = attr.width;
83       h = attr.height;
84    }
85
86    pixmap(char *data[])
87    {
88       XpmAttributes    attr;
89
90       attr.valuemask = 0;
91
92       XpmCreatePixmapFromData(stddpy, stddpy.Root(), data, &pixm, NULL, &attr);
93       w = attr.width;
94       h = attr.height;
95    }
96
97    ~pixmap()
98    {
99       if (pixm != 0)
100       {
101          XFreePixmap(stddpy, pixm);
102       }
103    }
104
105    void read(char *filename)
106    {
107 extern pixmap nopicture;
108       XpmAttributes    attr;
109       int              error;
110
111       if (pixm != 0)
112       {
113          XFreePixmap(stddpy, pixm);
114       }
115
116       attr.valuemask = 0;
117       error = XpmReadFileToPixmap(stddpy, stddpy.Root(), filename, &pixm, NULL, &attr);
118       if (error != XpmSuccess)
119       {
120          std::cerr << "Error " << error << " reading XPM file " << filename << "\n";
121          pixm = nopicture.pixm;
122          w = nopicture.w;
123          h = nopicture.h;
124       }
125       else
126       {
127          w = attr.width;
128          h = attr.height;
129       }
130    }
131
132    void create(char *data[])
133    {
134       XpmAttributes    attr;
135
136       if (pixm != 0)
137       {
138          XFreePixmap(stddpy, pixm);
139       }
140
141       attr.valuemask = 0;
142
143       XpmCreatePixmapFromData(stddpy, stddpy.Root(), data, &pixm, NULL, &attr);
144       w = attr.width;
145       h = attr.height;
146    }
147
148    operator Pixmap() const
149    {
150       return pixm;
151    }
152
153    size Size() const
154    {
155       return size(w, h);
156    }
157 };
158
159
160 #endif /* AXE_PIXMAP_H  */