1 /* -*- c++ -*-
2 FILE: MachineX.h
3 RCS REVISION: $Revision: 1.12 $
4 
5 COPYRIGHT: (c) 1999 -- 2003 Melinda Green, Don Hatch, and Jay Berkenbilt - Superliminal Software
6 
7 LICENSE: Free to use and modify for non-commercial purposes as long as the
8     following conditions are adhered to:
9     1) Obvious credit for the source of this code and the designs it embodies
10        are clearly made, and
11     2) Ports and derived versions of 4D Magic Cube programs are not distributed
12        without the express written permission of the authors.
13 
14 DESCRIPTION:
15     This is the Xlib/Xt Machine interface.
16 */
17 
18 #ifndef MACHINEX_H
19 #define MACHINEX_H
20 
21 #include "Machine.h"
22 
23 #include <X11/Intrinsic.h>
24 #include <X11/StringDefs.h>
25 #include <X11/Shell.h>
26 #include <X11/cursorfont.h>
27 
28 class PuzzleState;
29 class MachineX;
30 class WidgetsX;
31 class EventHandler;
32 
33 class MachineX: public Machine
34 {
35 public:
36     MachineX(EventHandler*,
37              int& argc, char *argv[], Preferences& prefs);
38     virtual ~MachineX();
39 
40     virtual void init(PuzzleState*);
41     virtual void drawFrame(struct frame *);
42     virtual void frontBuffer();
43     virtual void backBuffer();
44     virtual void swapBuffers();
45     virtual void addEventHandler(unsigned int eventmask,
46                                  Machine::event_handler handler,
47                                  void *arg = 0);
48     virtual void eventLoop();
49     virtual void setColors();
50     virtual void toggleOutline();
51     virtual void turnBackgroundBlack();
52     virtual void turnBackgroundWhite();
53     virtual void bell();
54     virtual bool getEventIfThereIsOne(int eventmask,
55                                       EventHandler::Event* event);
56     virtual Widgets* getWidgets();
57 
58     static void dispatchEvent(Widget, XtPointer arg,
59                               XEvent* xevent, Boolean *);
60 
61 private:
62 
63     struct AppRes
64     {
65         Boolean     outline;
66         Boolean     redraw;
67         Boolean     rightmacros;
68         Boolean     fastautomoves;
69         Boolean     nobuttons;
70         String      faceshrink;
71         String      degrees;
72         String      nframes180;
73         String      nframes120;
74         String      nframes90;
75         String      eyew;
76         String      eyez;
77         String      nshades;
78         String      tilt;
79         String      twirl;
80         String      nscramblechen;
81         String      logfile;
82         String      stickershrink;
83         String      face_colors[8];
84     };
85 
86     class EventClosure
87     {
88     public:
EventClosure(MachineX * m,Machine::event_handler h,void * arg)89         EventClosure(MachineX* m, Machine::event_handler h, void *arg) :
90             machine(m), handler(h), arg(arg)
91         {
92         };
93         MachineX* machine;
94         Machine::event_handler handler;
95         void *arg;
96     };
97 
98     char *expandTwiddles(char* s);
99     void putenvFromString(char* variable, char* val);
100     void putenvFromBool(char* variable, Boolean val);
101     void resourcesToEnvironment();
102     int getFileLength(char *filename);
103     void makeSureTheGCsExistAndEverything();
104     int numberOfAvailableColormapEntries();
105     void makeNewBackbuffer();
106     bool xeventToEvent(XEvent *, EventHandler::Event *);
107     EventMask eventMaskToXEventMask(unsigned int eventmask);
108     void XtFPrintWidgetName(FILE* fp, Widget wid);
109     void XtPrintWidgetName(Widget wid);
110 
111     static char *default_face_colors[];
112     static XrmOptionDescRec options[];
113     static XtResource resources[];
114 
115     static int const MAXSHADES = 32;
116     int nshades;
117     unsigned long colormap_entries[NFACES][MAXSHADES];
118 
119     Preferences& preferences;
120     EventHandler* event_handler;
121     PuzzleState* puzzle_state;
122     WidgetsX* widgets_x;
123     char* window_title;
124 
125     bool Xverbose;
126     bool do_outline;
127     AppRes app_res;
128     Widget toplevel;
129     Widget widget;              // drawing window
130     GC   gc, bggc, outlinegc;
131     Pixel black_pixel, white_pixel;
132     Pixmap backbuffer;
133     Drawable current;           // the window or the backbuffer
134     unsigned int window_width;
135     unsigned int window_height;
136     unsigned int window_depth;
137 };
138 
139 #endif
140 
141 // Local Variables:
142 // c-basic-offset: 4
143 // c-comment-only-line-offset: 0
144 // c-file-offsets: ((defun-block-intro . +) (block-open . 0) (substatement-open . 0) (statement-cont . +) (statement-case-open . +4) (arglist-intro . +) (arglist-close . +) (inline-open . 0))
145 // indent-tabs-mode: nil
146 // End:
147