cc65b942101df3f55021be71a5de6e8510adad62
[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.1 $
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.1  2002-07-25 08:01:26  arjen
27    First checkin, AXE release 0.2
28
29 *****************************/
30
31 /* static const char *RCSID = "$Id: display.h,v 1.1 2002-07-25 08:01:26 arjen Exp $"; */
32
33 #ifndef _DISPLAY_H
34 #define _DISPLAY_H
35
36 #include <iostream.h>
37 #include <X11/Xlib.h>
38
39 /*
40 ///////////////////////////////////////////////////////////////////////////
41 //  NAME           : display
42 //  BASECLASS      :
43 //  MEMBERS        : dpy   : Pointer to the Xlib Display
44 //  OPERATORS      : >> XEvent  - Read next event from the queue
45 //  METHODS        : display()       - Connect the default display
46 //                   display(char *) - Connect a specific display.
47 //                   ~display()      - Close the display connection
48 //
49 //                   Root()          - The root window.
50 //                   Black()         - Black pixel value.
51 //                   White()         - White pixel value.
52 //  DESCRIPTION    : A display object maintains the connection to the X
53 //                   workstation. The library contains one such object, stddpy
54 //                   which is connected to the default display.
55 //
56 //  RELATIONS      :
57 //  SEE ALSO       :
58 //  LAST MODIFIED  :
59 ///////////////////////////////////////////////////////////////////////////
60 */
61
62 class display
63 {
64    Display  *dpy;
65
66    GC       default_gc;
67
68 public:
69
70    display()
71    {
72       Status s;
73       s = XInitThreads();
74       dpy = XOpenDisplay("");
75       default_gc = XCreateGC(dpy, DefaultRootWindow(dpy), 0, 0);
76    }
77
78    //  contructor with char* argument opens named display.
79    display(char *display_name)
80    {
81       dpy = XOpenDisplay(display_name);
82       default_gc = XCreateGC(dpy, DefaultRootWindow(dpy), 0, 0);
83    }
84
85    ~display()
86    {
87       XFreeGC(dpy, default_gc);
88       XCloseDisplay(dpy);
89    }
90
91    display & operator>> (XEvent &ev)
92    {
93       XNextEvent(dpy, &ev);
94       return *this;
95    }
96
97    //  return display pointer.
98    Display *Dpy()
99    {
100       return dpy;
101    }
102
103    operator Display *()
104    {
105       return dpy;
106    }
107
108    Window Root()
109    {
110       return DefaultRootWindow(dpy);
111    }
112
113    //  Obtain the color index value for a white pixel.
114    unsigned long White()
115    {
116       return WhitePixel(dpy, DefaultScreen(dpy));
117    }
118
119    //  Obtain the color index value for a black pixel.
120    unsigned long Black()
121    {
122       return BlackPixel(dpy, DefaultScreen(dpy));
123    }
124
125    GC  gc()
126    {
127       return default_gc;
128    }
129
130    Colormap ColMap()
131    {
132       return DefaultColormap(dpy, DefaultScreen(dpy));
133    }
134 };
135
136 extern display stddpy;
137
138 #endif /* _DISPLAY_H */