1 /***********************************************************
2 * Artsoft Retro-Game Library *
3 *----------------------------------------------------------*
4 * (c) 1994-2000 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
19 #if defined(TARGET_X11)
21 static void X11InitDisplay();
22 static DrawWindow *X11InitWindow();
24 inline void X11InitVideoDisplay(void)
26 /* initialize X11 video */
29 /* set default X11 depth */
30 video.default_depth = XDefaultDepth(display, screen);
33 inline void X11InitVideoBuffer(DrawBuffer **backbuffer, DrawWindow **window)
35 *window = X11InitWindow();
37 XMapWindow(display, (*window)->drawable);
40 /* create additional (off-screen) buffer for double-buffering */
41 *backbuffer = CreateBitmap(video.width, video.height, video.depth);
44 static void X11InitDisplay()
46 #if !defined(PLATFORM_MSDOS)
47 XVisualInfo vinfo_template, *vinfo;
52 /* connect to X server */
53 if (!(display = XOpenDisplay(options.display_name)))
54 Error(ERR_EXIT, "cannot connect to X server %s",
55 XDisplayName(options.display_name));
57 screen = DefaultScreen(display);
58 visual = DefaultVisual(display, screen);
59 depth = DefaultDepth(display, screen);
60 cmap = DefaultColormap(display, screen);
62 #if !defined(PLATFORM_MSDOS)
63 /* look for good enough visual */
64 vinfo_template.screen = screen;
65 vinfo_template.class = (depth == 8 ? PseudoColor : TrueColor);
66 vinfo_template.depth = depth;
67 if ((vinfo = XGetVisualInfo(display, VisualScreenMask | VisualClassMask |
68 VisualDepthMask, &vinfo_template, &num_visuals)))
70 visual = vinfo->visual;
74 /* got appropriate visual? */
77 printf("Sorry, displays with less than 8 bits per pixel not supported.\n");
80 else if ((depth ==8 && visual->class != PseudoColor) ||
81 (depth > 8 && visual->class != TrueColor &&
82 visual->class != DirectColor))
84 printf("Sorry, cannot get appropriate visual.\n");
87 #endif /* !PLATFORM_MSDOS */
90 static DrawWindow *X11InitWindow()
92 DrawWindow *new_window = CreateBitmapStruct();
93 unsigned int border_width = 4;
95 unsigned long gc_valuemask;
96 #if !defined(PLATFORM_MSDOS)
97 XTextProperty windowName, iconName;
98 Pixmap icon_pixmap, iconmask_pixmap;
99 unsigned int icon_width, icon_height;
100 int icon_hot_x, icon_hot_y;
102 char icon_filename[256];
104 XSizeHints size_hints;
106 XClassHint class_hints;
107 char *window_name = program.window_title;
108 char *icon_name = program.window_title;
109 long window_event_mask;
110 Atom proto_atom = None, delete_atom = None;
112 int screen_width, screen_height;
113 int win_xpos, win_ypos;
114 unsigned long pen_fg = WhitePixel(display,screen);
115 unsigned long pen_bg = BlackPixel(display,screen);
116 const int width = video.width, height = video.height;
120 #if !defined(PLATFORM_MSDOS)
121 static struct IconFileInfo icon_pic =
129 screen_width = XDisplayWidth(display, screen);
130 screen_height = XDisplayHeight(display, screen);
132 win_xpos = (screen_width - width) / 2;
133 win_ypos = (screen_height - height) / 2;
135 new_window->drawable = XCreateSimpleWindow(display,
136 RootWindow(display, screen),
138 width, height, border_width,
141 #if !defined(PLATFORM_MSDOS)
142 proto_atom = XInternAtom(display, "WM_PROTOCOLS", FALSE);
143 delete_atom = XInternAtom(display, "WM_DELETE_WINDOW", FALSE);
144 if ((proto_atom != None) && (delete_atom != None))
145 XChangeProperty(display, new_window->drawable, proto_atom, XA_ATOM, 32,
146 PropModePrepend, (unsigned char *) &delete_atom, 1);
149 sprintf(icon_filename, "%s/%s/%s",
150 options.ro_base_directory, GRAPHICS_DIRECTORY,
151 icon_pic.picture_filename);
153 if (XReadBitmapFile(display, new_window->drawable,
154 program.x11_icon_filename,
155 &icon_width, &icon_height, &icon_pixmap,
156 &icon_hot_x, &icon_hot_y) != BitmapSuccess)
157 Error(ERR_EXIT, "cannot read icon bitmap file '%s'",
158 program.x11_icon_filename);
161 sprintf(icon_filename, "%s/%s/%s",
162 options.ro_base_directory, GRAPHICS_DIRECTORY,
163 icon_pic.picturemask_filename);
165 if (XReadBitmapFile(display, new_window->drawable,
166 program.x11_iconmask_filename,
167 &icon_width, &icon_height, &iconmask_pixmap,
168 &icon_hot_x, &icon_hot_y) != BitmapSuccess)
169 Error(ERR_EXIT, "cannot read icon bitmap file '%s'",
170 program.x11_iconmask_filename);
172 size_hints.width = size_hints.min_width = size_hints.max_width = width;
173 size_hints.height = size_hints.min_height = size_hints.max_height = height;
174 size_hints.flags = PSize | PMinSize | PMaxSize;
176 if (win_xpos || win_ypos)
178 size_hints.x = win_xpos;
179 size_hints.y = win_ypos;
180 size_hints.flags |= PPosition;
183 if (!XStringListToTextProperty(&window_name, 1, &windowName))
184 Error(ERR_EXIT, "structure allocation for windowName failed");
186 if (!XStringListToTextProperty(&icon_name, 1, &iconName))
187 Error(ERR_EXIT, "structure allocation for iconName failed");
189 wm_hints.initial_state = NormalState;
190 wm_hints.input = True;
191 wm_hints.icon_pixmap = icon_pixmap;
192 wm_hints.icon_mask = iconmask_pixmap;
193 wm_hints.flags = StateHint | IconPixmapHint | IconMaskHint | InputHint;
195 class_hints.res_name = program.command_basename;
196 class_hints.res_class = program.program_title;
198 XSetWMProperties(display, new_window->drawable, &windowName, &iconName,
199 NULL, 0, &size_hints, &wm_hints,
202 XFree(windowName.value);
203 XFree(iconName.value);
205 /* Select event types wanted */
207 ExposureMask | StructureNotifyMask | FocusChangeMask |
208 ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
209 PointerMotionHintMask | KeyPressMask | KeyReleaseMask;
211 XSelectInput(display, new_window->drawable, window_event_mask);
214 /* create GC for drawing with window depth and background color (black) */
215 gc_values.graphics_exposures = False;
216 gc_values.foreground = pen_bg;
217 gc_values.background = pen_bg;
218 gc_valuemask = GCGraphicsExposures | GCForeground | GCBackground;
220 XCreateGC(display, new_window->drawable, gc_valuemask, &gc_values);
222 /* create GCs for line drawing (black and white) */
225 gc_values.graphics_exposures = False;
226 gc_values.foreground = (i ? pen_fg : pen_bg);
227 gc_values.background = pen_bg;
228 gc_values.line_width = 4;
229 gc_values.line_style = LineSolid;
230 gc_values.cap_style = CapRound;
231 gc_values.join_style = JoinRound;
233 gc_valuemask = GCGraphicsExposures | GCForeground | GCBackground |
234 GCLineWidth | GCLineStyle | GCCapStyle | GCJoinStyle;
235 new_window->line_gc[i] =
236 XCreateGC(display, new_window->drawable, gc_valuemask, &gc_values);
242 Bitmap *X11LoadImage(char *filename)
244 Bitmap *new_bitmap = CreateBitmapStruct();
247 #if defined(PLATFORM_MSDOS)
251 pcx_err = Read_PCX_to_Pixmap(display, window->drawable, window->gc, filename,
252 &new_bitmap->drawable, &new_bitmap->clip_mask);
258 Error(ERR_EXIT, "cannot open PCX file '%s'", filename);
260 Error(ERR_EXIT, "cannot read PCX file '%s'", filename);
261 case PCX_FileInvalid:
262 Error(ERR_EXIT, "invalid PCX file '%s'", filename);
264 Error(ERR_EXIT, "not enough memory for PCX file '%s'", filename);
265 case PCX_ColorFailed:
266 Error(ERR_EXIT, "cannot get colors for PCX file '%s'", filename);
271 if (!new_bitmap->drawable)
272 Error(ERR_EXIT, "cannot get graphics for '%s'", filename);
274 if (!new_bitmap->clip_mask)
275 Error(ERR_EXIT, "cannot get clipmask for '%s'", filename);
277 /* set GraphicContext inheritated from Window */
278 new_bitmap->gc = window->gc;
283 #endif /* TARGET_X11 */