/* * file x11c_init.c - initialite x11 graphics engine * * $Id: x11c_init.c,v 1.3 2004/05/14 10:00:36 alfie Exp $ * * Program XBLAST * (C) by Oliver Vogel (e-mail: m.vogel@ndh.net) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published * by the Free Software Foundation; either version 2; or (at your option) * any later version * * This program is distributed in the hope that it will be entertaining, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILTY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "gui.h" #include "x11_common.h" #include "x11_event.h" #include "x11c_image.h" #include "x11c_text.h" #include "x11c_tile.h" #include "x11c_sprite.h" #include "x11c_pixmap.h" #include "x11_joystick.h" #include "image.h" #include "geom.h" #include "version.h" /* * local variables */ static XBQuitFunction quitFunc = NULL; /* * local function: GetBitsPerPixel * description: get memory bits for color depth * return value: bits per pixel (in memroy) * parameters: depth - color depth bits bits */ static int GetBitsPerPixel (int depth) { XPixmapFormatValues *xpfv; int npfv, result; result = depth; if (NULL != (xpfv = XListPixmapFormats (dpy, &npfv) ) ) { int i; for (i=0; ires_name = xblastResName; xch->res_class = xblastResClass; XSetClassHint(dpy, win, xch); /* set min and max geometry */ if (NULL == (xsh = XAllocSizeHints())) { fprintf (stderr, "alloc failed\n"); return XBFalse; } xsh->flags = PPosition | PSize | PMinSize | PMaxSize; xsh->min_width = PIXW; xsh->max_width = PIXW; xsh->min_height = PIXH+SCOREH; xsh->max_height = PIXH+SCOREH; XSetWMSizeHints (dpy, win, xsh, XA_WM_NORMAL_HINTS); /* create graphics context for window */ xgcv.foreground = blackPixel; xgcv.background = whitePixel; gcWindow = XCreateGC (dpy, win, GCForeground | GCBackground, &xgcv); /* Set Cursor */ XDefineCursor (dpy, win, XCreateFontCursor(dpy, XC_trek) ); /* Map the Window */ XMapRaised (dpy, win); /* wait for an expose event */ do { XNextEvent(dpy, &xev); } while (xev.type != Expose ); /* get actual window size */ if (! XGetWindowAttributes(dpy, win , &xwa)) { fprintf (stderr, "could not get window size\n"); return XBFalse; } if ( (xwa.width < PIXW) || (xwa.height < PIXH) ) { fprintf (stderr, "display is to small for window\n"); return XBFalse; } return XBTrue; } /* InitWindow */ /* * local function: InitIcon * description: Setup icon for XBlast window * return value: none * parameters: none */ static void SetIcon (void) { XWMHints *wmh = XAllocWMHints (); assert (NULL != wmh); /* set icon pixmap and mask */ wmh->flags = IconPixmapHint | IconMaskHint; wmh->icon_pixmap = ReadRgbPixmap (imgPathMisc, "xblast"); wmh->icon_mask = ReadPbmBitmap (imgPathMisc, "xblast"); XSetWMHints (dpy, win, wmh); /* clean up */ XFree (wmh); } /* InitIcon */ /* * global function: GUI_Init * description: Initialize the X11 graphics engine * return value: XBTrue on success * parameters: argc - number commandline arguments * argv - array with commandline arguments */ XBBool GUI_Init (int argc, char *argv[]) { int visualClass; /* init x11 display */ if (! InitDisplay (NULL, &visualClass)) { return XBFalse; } /* now initialize the window */ if (! InitWindow ("XBlast TNT " VERSION_STRING, "XBlast TNT") ) { return XBFalse; } /* now setup image loading */ if (! InitImage (visualClass) ) { return XBFalse; } /* create our own icon */ SetIcon (); /* now create pixmap for double bufferung */ if (! InitPixmap () ) { return XBFalse; } /* initalisize fonst for text output */ if (! InitFonts ()) { return XBFalse; } /* initalisize tile drawing and scoreboard */ if (! InitTiles () ) { return XBFalse; } /* Initialsize Sprites */ if (! InitSprites ()) { return XBFalse; } /* Setup Event handler */ if (! InitEvent () ) { return XBFalse; } /* init joystick support */ if (! InitJoystick ()) { return XBFalse; } /* that's all */ return XBTrue; } /* init_display */ /* * global function: GUI_Finish * description: Shutdown x11 graphics engine * return value: none * parameters: none */ void GUI_Finish (void) { /* finish joystick support */ FinishJoystick (); /* some cleaning up */ FinishEvent (); /* shutdown connection to x-server */ if (dpy != NULL) { XCloseDisplay (dpy); } } /* GUI_Finish */ /* * */ static int IoErrorHandler (Display *_dpy) { assert (NULL != quitFunc); Dbg_Out ("connection to display %s lost.\n" "shutting down xblast.\n", DisplayString (_dpy)); (*quitFunc) (); return 0; } /* IoErrorHandler */ /* * */ void GUI_OnQuit (XBQuitFunction _quitFunc) { assert (NULL != _quitFunc); quitFunc = _quitFunc; XSetIOErrorHandler (IoErrorHandler); } /* GUI_OnQuit */ /* * end of file x11c_init.c */