00001 /*
00002 File: XGraphicsSystem.h
00003
00004 Function: Provides an XWindows-based implementation of the
00005 Renderer object. See Renderer.h
00006
00007 Author(s): Andrew Willmott
00008
00009 Copyright: (c) 1995-2000, Andrew Willmott
00010 */
00011
00012 #ifndef __XGraphicsSystem__
00013 #define __XGraphicsSystem__
00014
00015 #include <iostream.h>
00016 #include <X11/Xlib.h>
00017 #include <X11/Xutil.h>
00018
00019 #undef Bool
00020 // The X cruft #defines Bool to be nothing(!), so we undef it.
00021 // Oh for a world without X Windows.
00022
00023 #include "gcl/GCLConfig.h"
00024 #include "gcl/Image.h"
00025 #include "cl/PtrArray.h"
00026
00027 class XPane;
00028 class XEventPane;
00029 class XOffscreenPane;
00030
00031
00032 // --- Graphics System class --------------------------------------------------
00033
00034 // List of all panes under our control.
00035 typedef PtrArray<XEventPane> PaneList;
00036
00037 class XGraphicsSystem
00038 {
00039 public:
00040 XGraphicsSystem();
00041 virtual ~XGraphicsSystem();
00042
00043 Void CreateWindow(XEventPane *xpane,
00044 StrConst title = "OpenGL window", Int width = 400,
00045 Int height = 400);
00046 Void CreateSubwindow(XEventPane *xpane,
00047 Window parent, Int x = 0,
00048 Int y = 0, Int width = 400, Int height = 400);
00049 Void CreateOffscreen(XOffscreenPane *xpane,
00050 Int width = 400, Int height = 400);
00051
00052 virtual Void Spin();
00053 // non blocking event handler: returns after a pass through
00054 // the event queue
00055 virtual Void Run();
00056 // blocking event handler
00057 virtual Bool RunFor(Float time);
00058 // blocking event handler: returns after 'time' seconds.
00059 // returns true if the handler is done.
00060 virtual Void SignalDone();
00061 // tell blocking event handler to quit.
00062
00063
00064 virtual Void GetMouse(XEventPane *xpane,
00065 Int *x, Int *y, UInt *keyState);
00066
00067 Void DumpVisualInfo();
00068
00069
00070 PaneList paneList;
00071 Display *display;
00072 GC theGC;
00073 #ifdef GCL_XSHM
00074 Bool sharedOn;
00075 Bool remoteChecked;
00076 #endif
00077
00078 protected:
00079 static Bool finished;
00080 Long itsEventsMask;
00081 Bool hasGC;
00082 };
00083
00084
00085 // --- X window panes ---------------------------------------------------------
00086
00087 class XPane
00088 {
00089 public:
00090 XPane();
00091 virtual ~XPane();
00092
00093 virtual Void Init();
00094 virtual XVisualInfo *GetVisualInfo();
00095
00096 Void CopyFrom(XPane &from);
00097 Void PutImage(Image &img, Int x = 0, Int y = 0);
00098
00099 XID paneXID;
00100 Int width, height;
00101 XGraphicsSystem *xgs;
00102 Bool doubleBuffered;
00103
00104 protected:
00105 XImage *ImageToXImage(Image &img);
00106
00107 static XVisualInfo *sVisualInfo;
00108 };
00109
00110 class XOffscreenPane : public XPane
00111 {
00112 public:
00113 XOffscreenPane();
00114 ~XOffscreenPane();
00115 };
00116
00117 enum WM_Modifier
00118 {
00119 wmShift = 0x0001,
00120 wmControl = 0x0002,
00121 wmAlt = 0x0004,
00122 wmUndef1 = 0x0008,
00123 wmButton1 = 0x0010,
00124 wmButton2 = 0x0020,
00125 wmButton3 = 0x0040,
00126 wmButtons = 0x0070,
00127 wmAll = 0x00FF
00128 };
00129
00130 class XEventPane : public XPane
00131 // can handle events...
00132 {
00133 public:
00134
00135 XEventPane(Bool doubleBuffer = 0) :
00136 XPane() {doubleBuffered = doubleBuffer;};
00137
00138 ~XEventPane();
00139
00140 virtual Void XHandleEvent(XEvent *event);
00141 Void XGetMouse(Int *x, Int *y, UInt *keyState);
00142
00143 // nice interface
00144
00145 virtual Void HandleKey(Char key);
00146 virtual Void TrackMouse(Int x, Int y, Int modifiers);
00147 virtual Void HandleExpose();
00148 Void GetMouse(Int &x, Int &y, Int &modifiers);
00149
00150 Void Resize(Int x, Int y);
00151 Void Hide();
00152 Void Show();
00153 Void SetTitle(StrConst title);
00154 };
00155
00156 class XBackedPane : public XEventPane
00157 // mirrors another pane, with screen update when expose events are received.
00158 {
00159 public:
00160 XBackedPane();
00161
00162 Void HandleExpose();
00163
00164 Void Attach(XPane *pane);
00165
00166 protected:
00167 XPane *backPane;
00168 };
00169
00170 #endif