1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
/*
* file w32_init.c - initialze Win32-graphics engine
*
* $Id: w32_init.c,v 1.4 2006/02/19 13:33:01 lodott 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 "xblast.h"
#include "gui.h"
#include "w32_config.h"
#include "w32_event.h"
#include "w32_joystick.h"
#include "w32_keysym.h"
#include "w32_pixmap.h"
#include "w32_sprite.h"
#include "w32_text.h"
#include "w32_image.h"
#include "w32_tile.h"
#include "version.h"
#include "geom.h"
/*
* local function: InitWindow
* description: create the xblast main window
* parameters: title - title of window
* return value: XBTrue on success, XBFalse on error
*/
static XBBool
InitWindow (const char *title)
{
RECT cRect;
RECT wRect;
int x, y;
int width, height;
static WNDCLASS windowClass;
/* register xblast class */
windowClass.style = 0;
windowClass.lpfnWndProc = WindowProc;
windowClass.cbClsExtra = 0;
windowClass.cbWndExtra = 0;
windowClass.hInstance = instance;
windowClass.hIcon = LoadIcon (instance, xblastClass);
windowClass.hCursor = LoadCursor (NULL, IDC_ARROW);
windowClass.hbrBackground = GetStockObject (BLACK_BRUSH);
windowClass.lpszClassName = xblastClass;
if (0 == RegisterClass (&windowClass)) {
return XBFalse;
}
/* retrieve old geonetry */
RetrieveWindowRect (&wRect);
/* now create the window */
window = CreateWindow (xblastClass, title,
WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX,
CW_USEDEFAULT, CW_USEDEFAULT,
wRect.right - wRect.left,
wRect.bottom - wRect.top, NULL, NULL, instance, NULL);
if (window == NULL) {
return XBFalse;
}
/* now show it (may be moved elsewhere) */
ShowWindow (window, SW_SHOWDEFAULT);
UpdateWindow (window);
/* set window size correctly */
if (GetClientRect (window, &cRect)) {
x = wRect.left;
y = wRect.top;
width = wRect.right - wRect.left;
height = wRect.bottom - wRect.top;
/* adjust width and height, if client region has wrong size */
if (PIXW != cRect.right - cRect.left) {
width -= cRect.right - cRect.left - PIXW;
}
if (PIXH + SCOREH != cRect.bottom - cRect.top) {
height -= cRect.bottom - cRect.top - PIXH - SCOREH;
}
Dbg_Out ("Window geom %dx%d+%d+%d\n", width, height, x, y);
MoveWindow (window, x, y, width, height, TRUE);
}
/* that's all */
Dbg_Out ("InitWindow successful\n");
return XBTrue;
} /* InitWindow */
/*
* local function: FinishWindow
* description: clean up window and its class
*/
static void
FinishWindow (void)
{
RECT rect;
/* store last position */
if (GetWindowRect (window, &rect)) {
StoreWindowRect (&rect);
}
/* delete window */
DestroyWindow (window);
/* unregister window class */
UnregisterClass (xblastClass, instance);
} /* FinishWindow */
/*
* global function: GUI_Init
* description: initializes win32-display
* parameters: title - window caption
* icon_name - ignored
* return value: 0 on success, -1 on failure
*/
XBBool
GUI_Init (int argc, char *argv[])
{
/* get program instance */
instance = GetModuleHandleA (0);
/* create game window */
if (!InitWindow ("XBlast TNT " VERSION_STRING)) {
return XBFalse;
}
/* init image loading */
if (!InitImages ()) {
return XBFalse;
}
/* create bitmap for double buffering */
if (!InitPixmap ()) {
return XBFalse;
}
/* setup text output and fonts */
if (!InitText ()) {
return XBFalse;
}
/* setup tile output */
if (!InitTiles ()) {
return XBFalse;
}
/* create sprites */
if (!InitSprites ()) {
return XBFalse;
}
/* setup keysmbol table */
if (!InitKeysym ()) {
return XBFalse;
}
/* Setup Event handler */
if (!InitEvent ()) {
return XBFalse;
}
/* Setup Joystick Handler */
if (!InitJoystick ()) {
return XBFalse;
}
return XBTrue;
} /* GUI_Init */
/*
* global function: GUI_Finish
* description: shutdown win32 interface
*/
void
GUI_Finish (void)
{
/* cleanup joystick */
FinishJoystick ();
/* clean up event handling */
FinishEvent ();
/* setup keysmbol table */
FinishKeysym ();
/* remove all sprite bitmaps */
FinishSprites ();
/* romve all tiles */
FinishTiles ();
/* unload fonts etc */
FinishText ();
/* clear image conversion data structures */
FinishImages ();
/* remove double buffer */
FinishPixmap ();
/* remove window */
FinishWindow ();
} /* GUI_Finish */
/*
* end of file w32_init.c
*/
|