Use proper namespace for iostream classes
[AXE.git] / src / display.h
1 /**************************************************************************
2 **  (c) Copyright 1998, Andromeda Technology & Automation
3 ***************************************************************************
4 ** MODULE INFORMATION *
5 ***********************
6 **      FILE NAME      : display.h
7 **      SYSTEM NAME    : AXE - Andromeda X-windows Encapsulation
8 **      VERSION NUMBER : $Revision: 1.2 $
9 **
10 **  DESCRIPTION      : Definition of display class 
11 **
12 **  EXPORTED OBJECTS : class display
13 **  LOCAL    OBJECTS : 
14 **  MODULES  USED    :
15 ***************************************************************************
16 **  ADMINISTRATIVE INFORMATION *
17 ********************************
18 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
19 **      CREATION DATE   : Feb 06, 1998
20 **      LAST UPDATE     : Feb 07, 1998
21 **      MODIFICATIONS   : 
22 **************************************************************************/
23
24 /*****************************
25    $Log: display.h,v $
26    Revision 1.2  2002-11-04 07:24:31  arjen
27    Use proper namespace for iostream classes
28
29    Revision 1.1  2002/07/25 08:01:26  arjen
30    First checkin, AXE release 0.2
31
32 *****************************/
33
34 /* static const char *RCSID = "$Id: display.h,v 1.2 2002-11-04 07:24:31 arjen Exp $"; */
35
36 #ifndef _DISPLAY_H
37 #define _DISPLAY_H
38
39 #include <iostream>
40 #include <X11/Xlib.h>
41
42 /*
43 ///////////////////////////////////////////////////////////////////////////
44 //  NAME           : display
45 //  BASECLASS      :
46 //  MEMBERS        : dpy   : Pointer to the Xlib Display
47 //  OPERATORS      : >> XEvent  - Read next event from the queue
48 //  METHODS        : display()       - Connect the default display
49 //                   display(char *) - Connect a specific display.
50 //                   ~display()      - Close the display connection
51 //
52 //                   Root()          - The root window.
53 //                   Black()         - Black pixel value.
54 //                   White()         - White pixel value.
55 //  DESCRIPTION    : A display object maintains the connection to the X
56 //                   workstation. The library contains one such object, stddpy
57 //                   which is connected to the default display.
58 //
59 //  RELATIONS      :
60 //  SEE ALSO       :
61 //  LAST MODIFIED  :
62 ///////////////////////////////////////////////////////////////////////////
63 */
64
65 class display
66 {
67    Display  *dpy;
68
69    GC       default_gc;
70
71 public:
72
73    display()
74    {
75       Status s;
76       s = XInitThreads();
77       dpy = XOpenDisplay("");
78       default_gc = XCreateGC(dpy, DefaultRootWindow(dpy), 0, 0);
79    }
80
81    //  contructor with char* argument opens named display.
82    display(char *display_name)
83    {
84       dpy = XOpenDisplay(display_name);
85       default_gc = XCreateGC(dpy, DefaultRootWindow(dpy), 0, 0);
86    }
87
88    ~display()
89    {
90       XFreeGC(dpy, default_gc);
91       XCloseDisplay(dpy);
92    }
93
94    display & operator>> (XEvent &ev)
95    {
96       XNextEvent(dpy, &ev);
97       return *this;
98    }
99
100    //  return display pointer.
101    Display *Dpy()
102    {
103       return dpy;
104    }
105
106    operator Display *()
107    {
108       return dpy;
109    }
110
111    Window Root()
112    {
113       return DefaultRootWindow(dpy);
114    }
115
116    //  Obtain the color index value for a white pixel.
117    unsigned long White()
118    {
119       return WhitePixel(dpy, DefaultScreen(dpy));
120    }
121
122    //  Obtain the color index value for a black pixel.
123    unsigned long Black()
124    {
125       return BlackPixel(dpy, DefaultScreen(dpy));
126    }
127
128    GC  gc()
129    {
130       return default_gc;
131    }
132
133    Colormap ColMap()
134    {
135       return DefaultColormap(dpy, DefaultScreen(dpy));
136    }
137 };
138
139 extern display stddpy;
140
141 #endif /* _DISPLAY_H */