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;
101 char icon_filename[256];
102 XSizeHints size_hints;
104 XClassHint class_hints;
105 char *window_name = program.window_title;
106 char *icon_name = program.window_title;
107 long window_event_mask;
108 Atom proto_atom = None, delete_atom = None;
110 int screen_width, screen_height;
111 int win_xpos, win_ypos;
112 unsigned long pen_fg = WhitePixel(display,screen);
113 unsigned long pen_bg = BlackPixel(display,screen);
114 const int width = video.width, height = video.height;
118 #if !defined(PLATFORM_MSDOS)
119 static struct IconFileInfo icon_pic =
127 screen_width = XDisplayWidth(display, screen);
128 screen_height = XDisplayHeight(display, screen);
130 win_xpos = (screen_width - width) / 2;
131 win_ypos = (screen_height - height) / 2;
133 new_window->drawable = XCreateSimpleWindow(display,
134 RootWindow(display, screen),
136 width, height, border_width,
139 #if !defined(PLATFORM_MSDOS)
140 proto_atom = XInternAtom(display, "WM_PROTOCOLS", FALSE);
141 delete_atom = XInternAtom(display, "WM_DELETE_WINDOW", FALSE);
142 if ((proto_atom != None) && (delete_atom != None))
143 XChangeProperty(display, new_window->drawable, proto_atom, XA_ATOM, 32,
144 PropModePrepend, (unsigned char *) &delete_atom, 1);
147 sprintf(icon_filename, "%s/%s/%s",
148 options.ro_base_directory, GRAPHICS_DIRECTORY,
149 icon_pic.picture_filename);
151 XReadBitmapFile(display, new_window->drawable, program.x11_icon_filename,
152 &icon_width, &icon_height,
153 &icon_pixmap, &icon_hot_x, &icon_hot_y);
155 Error(ERR_EXIT, "cannot read icon bitmap file '%s'", icon_filename);
158 sprintf(icon_filename, "%s/%s/%s",
159 options.ro_base_directory, GRAPHICS_DIRECTORY,
160 icon_pic.picturemask_filename);
162 XReadBitmapFile(display, new_window->drawable, program.x11_iconmask_filename,
163 &icon_width, &icon_height,
164 &iconmask_pixmap, &icon_hot_x, &icon_hot_y);
165 if (!iconmask_pixmap)
166 Error(ERR_EXIT, "cannot read icon bitmap file '%s'", icon_filename);
168 size_hints.width = size_hints.min_width = size_hints.max_width = width;
169 size_hints.height = size_hints.min_height = size_hints.max_height = height;
170 size_hints.flags = PSize | PMinSize | PMaxSize;
172 if (win_xpos || win_ypos)
174 size_hints.x = win_xpos;
175 size_hints.y = win_ypos;
176 size_hints.flags |= PPosition;
179 if (!XStringListToTextProperty(&window_name, 1, &windowName))
180 Error(ERR_EXIT, "structure allocation for windowName failed");
182 if (!XStringListToTextProperty(&icon_name, 1, &iconName))
183 Error(ERR_EXIT, "structure allocation for iconName failed");
185 wm_hints.initial_state = NormalState;
186 wm_hints.input = True;
187 wm_hints.icon_pixmap = icon_pixmap;
188 wm_hints.icon_mask = iconmask_pixmap;
189 wm_hints.flags = StateHint | IconPixmapHint | IconMaskHint | InputHint;
191 class_hints.res_name = program.command_basename;
192 class_hints.res_class = program.program_title;
194 XSetWMProperties(display, new_window->drawable, &windowName, &iconName,
195 NULL, 0, &size_hints, &wm_hints,
198 XFree(windowName.value);
199 XFree(iconName.value);
201 /* Select event types wanted */
203 ExposureMask | StructureNotifyMask | FocusChangeMask |
204 ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
205 PointerMotionHintMask | KeyPressMask | KeyReleaseMask;
207 XSelectInput(display, new_window->drawable, window_event_mask);
210 /* create GC for drawing with window depth and background color (black) */
211 gc_values.graphics_exposures = False;
212 gc_values.foreground = pen_bg;
213 gc_values.background = pen_bg;
214 gc_valuemask = GCGraphicsExposures | GCForeground | GCBackground;
216 XCreateGC(display, new_window->drawable, gc_valuemask, &gc_values);
218 /* create GCs for line drawing (black and white) */
221 gc_values.graphics_exposures = False;
222 gc_values.foreground = (i ? pen_fg : pen_bg);
223 gc_values.background = pen_bg;
224 gc_values.line_width = 4;
225 gc_values.line_style = LineSolid;
226 gc_values.cap_style = CapRound;
227 gc_values.join_style = JoinRound;
229 gc_valuemask = GCGraphicsExposures | GCForeground | GCBackground |
230 GCLineWidth | GCLineStyle | GCCapStyle | GCJoinStyle;
231 new_window->line_gc[i] =
232 XCreateGC(display, new_window->drawable, gc_valuemask, &gc_values);
238 Bitmap *X11LoadImage(char *filename)
240 Bitmap *new_bitmap = CreateBitmapStruct();
243 #if defined(PLATFORM_MSDOS)
247 pcx_err = Read_PCX_to_Pixmap(display, window->drawable, window->gc, filename,
248 &new_bitmap->drawable, &new_bitmap->clip_mask);
254 Error(ERR_EXIT, "cannot open PCX file '%s'", filename);
256 Error(ERR_EXIT, "cannot read PCX file '%s'", filename);
257 case PCX_FileInvalid:
258 Error(ERR_EXIT, "invalid PCX file '%s'", filename);
260 Error(ERR_EXIT, "not enough memory for PCX file '%s'", filename);
261 case PCX_ColorFailed:
262 Error(ERR_EXIT, "cannot get colors for PCX file '%s'", filename);
267 if (!new_bitmap->drawable)
268 Error(ERR_EXIT, "cannot get graphics for '%s'", filename);
270 if (!new_bitmap->clip_mask)
271 Error(ERR_EXIT, "cannot get clipmask for '%s'", filename);
273 /* set GraphicContext inheritated from Window */
274 new_bitmap->gc = window->gc;
279 #endif /* TARGET_X11 */