~ubuntu-branches/debian/squeeze/warzone2100/squeeze

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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/*
	This file is part of Warzone 2100.
	Copyright (C) 1999-2004  Eidos Interactive
	Copyright (C) 2005-2010  Warzone 2100 Project

	Warzone 2100 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 of the License, or
	(at your option) any later version.

	Warzone 2100 is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY 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 Warzone 2100; if not, write to the Free Software
	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
 * Image.c
 *
 * Image definitions and related functions.
 *
 */

#include "lib/framework/frame.h"
#include "lib/framework/frameresource.h"
#include "lib/ivis_common/piestate.h"
#include "lib/ivis_common/rendmode.h"

#include "intimage.h"

#define INCEND	(0)

enum {
	FR_SOLID,	//< Bitmap drawn solid.
	FR_KEYED,	//< Bitmap drawn with colour 0 transparent.
};

typedef enum {
	FR_IGNORE,	//< Fill rect is ignored.
	FR_FRAME,	//< Fill rect drawn relative to frame.
	FR_LEFT,	//< Fill rect drawn relative to left of frame.
	FR_RIGHT,	//< Fill rect drawn relative to right of frame.
	FR_TOP,		//< Fill rect drawn relative to top of frame.
	FR_BOTTOM,	//< Fill rect drawn relative to bottom of frame.
} FRAMERECTTYPE;

typedef struct {
	FRAMERECTTYPE Type;		//< One of the FR_... values.
	int TLXOffset, TLYOffset;	//< Offsets for the rect fill.
	int BRXOffset, BRYOffset;
	int ColourIndex;		//< Hackish index into the WZCOLOR palette
} FRAMERECT;

// Frame definition structure.
typedef struct {
	SWORD OffsetX0,OffsetY0;	//< Offset top left of frame.
	SWORD OffsetX1,OffsetY1;	//< Offset bottom right of frame.
	SWORD TopLeft;			//< Image indecies for the corners ( -1 = don't draw).
	SWORD TopRight;
	SWORD BottomLeft;
	SWORD BottomRight;
	SWORD TopEdge,TopType;		//< Image indecies for the edges ( -1 = don't draw). Type ie FR_SOLID or FR_KEYED.
	SWORD RightEdge,RightType;
	SWORD BottomEdge,BottomType;
	SWORD LeftEdge,LeftType;
	FRAMERECT FRect[5];		//< Fill rectangles.
} IMAGEFRAME;

IMAGEFILE *IntImages;	// All the 2d graphics for the user interface.

static const uint16_t MousePointerImageIDs[CURSOR_MAX] =
{
	IMAGE_CURSOR_DEFAULT,	// CURSOR_ARROW
	IMAGE_CURSOR_DEST,	// CURSOR_DEST
	IMAGE_CURSOR_DEFAULT,	// CURSOR_SIGHT
	IMAGE_CURSOR_DEFAULT,	// CURSOR_TARGET
	IMAGE_CURSOR_DEFAULT,	// CURSOR_LARROW      
	IMAGE_CURSOR_DEFAULT,	// CURSOR_RARROW      
	IMAGE_CURSOR_DEFAULT,	// CURSOR_DARROW      
	IMAGE_CURSOR_DEFAULT,	// CURSOR_UARROW      
	IMAGE_CURSOR_DEFAULT,	// CURSOR_DEFAULT     
	IMAGE_CURSOR_DEFAULT,	// CURSOR_EDGEOFMAP   
	IMAGE_CURSOR_ATTACH,	// CURSOR_ATTACH      
	IMAGE_CURSOR_ATTACK,	// CURSOR_ATTACK      
	IMAGE_CURSOR_BOMB,	// CURSOR_BOMB        
	IMAGE_CURSOR_BRIDGE,	// CURSOR_BRIDGE      
	IMAGE_CURSOR_BUILD,	// CURSOR_BUILD       
	IMAGE_CURSOR_EMBARK,	// CURSOR_EMBARK      
	IMAGE_CURSOR_DISEMBARK,	// CURSOR_DISEMBARK      
	IMAGE_CURSOR_FIX,	// CURSOR_FIX         
	IMAGE_CURSOR_GUARD,	// CURSOR_GUARD       
	IMAGE_CURSOR_ECM,	// CURSOR_JAM         
	IMAGE_CURSOR_LOCKON,	// CURSOR_LOCKON      
	IMAGE_CURSOR_SCOUT,	// CURSOR_SCOUT      
	IMAGE_CURSOR_DEFAULT,	// CURSOR_MENU        
	IMAGE_CURSOR_MOVE,	// CURSOR_MOVE        
	IMAGE_CURSOR_NOTPOS,	// CURSOR_NOTPOSSIBLE 
	IMAGE_CURSOR_PICKUP,	// CURSOR_PICKUP      
	IMAGE_CURSOR_REPAIR,	// CURSOR_SEEKREPAIR  
	IMAGE_CURSOR_SELECT,	// CURSOR_SELECT      
};

/** Form frame definition for normal frames. */
IMAGEFRAME FrameNormal = {
	0,0, 0,0,
	IMAGE_FRAME_C0,
	IMAGE_FRAME_C1,
	IMAGE_FRAME_C3,
	IMAGE_FRAME_C2,
	IMAGE_FRAME_HT, FR_SOLID,
	IMAGE_FRAME_VR, FR_SOLID,
	IMAGE_FRAME_HB, FR_SOLID,
	IMAGE_FRAME_VL, FR_SOLID,
	{{FR_FRAME, 0,1, 0,-1, 33},
	{FR_IGNORE, 0,0, 0,0 ,0},
	{FR_IGNORE, 0,0, 0,0 ,0},
	{FR_IGNORE, 0,0, 0,0 ,0},
	{FR_IGNORE, 0,0, 0,0 ,0}},
};

/** Form frame definition for radar frames. */
IMAGEFRAME FrameRadar = {
	0,0, 0,0,
	IMAGE_FRAME_C0,
	IMAGE_FRAME_C1,
	IMAGE_FRAME_C3,
	IMAGE_FRAME_C2,
	IMAGE_FRAME_HT, FR_SOLID,
	IMAGE_FRAME_VR, FR_SOLID,
	IMAGE_FRAME_HB, FR_SOLID,
	IMAGE_FRAME_VL, FR_SOLID,
	{{FR_IGNORE, 0,0, 0,0 ,0},
	{FR_IGNORE, 0,0, 0,0 ,0},
	{FR_IGNORE, 0,0, 0,0 ,0},
	{FR_IGNORE, 0,0, 0,0 ,0},
	{FR_IGNORE, 0,0, 0,0 ,0}},
};

// Tab definitions, defines graphics to use for major and minor tabs.
TABDEF	StandardTab = {
	IMAGE_TAB1,			// Major tab normal.
	IMAGE_TAB1DOWN,		// Major tab clicked.
	IMAGE_TABHILIGHT,	// Major tab hilighted by mouse.
	IMAGE_TABSELECTED,	// Major tab currently selected.

	IMAGE_TAB1,			// Minor tab tab Normal.
	IMAGE_TAB1DOWN,		// Minor tab clicked.
	IMAGE_TABHILIGHT,	// Minor tab hilighted by mouse.
	IMAGE_TABSELECTED,	// Minor tab currently selected.
};

TABDEF	SmallTab = {
	IMAGE_TAB1_SM,			// Major tab normal.
	IMAGE_TAB1DOWN_SM,		// Major tab clicked.
	IMAGE_TABHILIGHT_SM,	// Major tab hilighted by mouse.
	IMAGE_TAB1SELECTED_SM,	// Major tab currently selected.

	IMAGE_TAB1_SM,			// Minor tab tab Normal.
	IMAGE_TAB1DOWN_SM,		// Minor tab clicked.
	IMAGE_TABHILIGHT_SM,	// Minor tab hilighted by mouse.
	IMAGE_TAB1SELECTED_SM,	// Minor tab currently selected.
};

// Read bitmaps used by the interface.
//
BOOL imageInitBitmaps(void)
{
	IntImages = (IMAGEFILE*)resGetData("IMG", "intfac.img");
	pie_InitColourMouse(IntImages, MousePointerImageIDs);

	return true;
}

// Render a window frame.
//
static void RenderWindow(FRAMETYPE frame, UDWORD x, UDWORD y, UDWORD Width, UDWORD Height, BOOL Opaque)
{
	SWORD WTopRight = 0;
	SWORD WTopLeft = 0;
	SWORD WBottomRight = 0;
	SWORD WBottomLeft = 0;
	SWORD HTopRight = 0;
	SWORD HTopLeft = 0;
	SWORD HBottomRight = 0;
	SWORD HBottomLeft = 0;
	UWORD RectI;
	FRAMERECT *Rect;
	BOOL Masked = false;
	IMAGEFRAME *Frame;

	if (frame == 0)
	{
		Frame = &FrameNormal;
	}
	else
	{
		Frame = &FrameRadar;
	}

	x += Frame->OffsetX0;
	y += Frame->OffsetY0;
	Width -= Frame->OffsetX1+Frame->OffsetX0;
	Height -= Frame->OffsetY1+Frame->OffsetY0;

	for(RectI=0; RectI<5; RectI++) {
		Rect = &Frame->FRect[RectI];

		switch(Rect->Type) {
			case FR_FRAME:
				if(Opaque==false)
				{
					if(Masked == false) {
						Width &= 0xfffc;	// Software transboxfill needs to be a multiple of 4 pixels.
						Masked = true;
					}


					iV_TransBoxFill( x+Rect->TLXOffset,
									y+Rect->TLYOffset,
									x+Width-INCEND+Rect->BRXOffset,
									y+Height-INCEND+Rect->BRYOffset);
				}
				else
				{

					pie_BoxFill(x + Rect->TLXOffset, y + Rect->TLYOffset, x + Width - INCEND + Rect->BRXOffset,
					            y + Height - INCEND + Rect->BRYOffset, psPalette[Rect->ColourIndex]);
				}
				break;

			case FR_LEFT:
				if(Opaque==false) {
					if(Masked == false) {
						Width &= 0xfffc;	// Software transboxfill needs to be a multiple of 4 pixels.
						Masked = true;
					}
					iV_TransBoxFill( x+Rect->TLXOffset,
									y+Rect->TLYOffset,
									x+Rect->BRXOffset,
									y+Height-INCEND+Rect->BRYOffset);
				} else {
					pie_BoxFill(x + Rect->TLXOffset, y + Rect->TLYOffset, x + Rect->BRXOffset,
					            y + Height - INCEND + Rect->BRYOffset, psPalette[Rect->ColourIndex]);
				}
				break;

			case FR_RIGHT:
				if(Opaque==false) {
					if(Masked == false) {
						Width &= 0xfffc;	// Software transboxfill needs to be a multiple of 4 pixels.
						Masked = true;
					}
					iV_TransBoxFill( x+Width-INCEND+Rect->TLXOffset,
									y+Rect->TLYOffset,
									x+Width-INCEND+Rect->BRXOffset,
									y+Height-INCEND+Rect->BRYOffset);
				} else {
					pie_BoxFill(x + Width - INCEND + Rect->TLXOffset, y + Rect->TLYOffset,
					            x + Width - INCEND + Rect->BRXOffset, y + Height - INCEND + Rect->BRYOffset,
					            psPalette[Rect->ColourIndex]);
				}
				break;

			case FR_TOP:
				if(Opaque==false) {
					if(Masked == false) {
						Width &= 0xfffc;	// Software transboxfill needs to be a multiple of 4 pixels.
						Masked = true;
					}
					iV_TransBoxFill( x+Rect->TLXOffset,
									y+Rect->TLYOffset,
									x+Width-INCEND+Rect->BRXOffset,
									y+Rect->BRYOffset);
				} else {
					pie_BoxFill(x + Rect->TLXOffset, y + Rect->TLYOffset, x + Width - INCEND + Rect->BRXOffset,
					            y + Rect->BRYOffset, psPalette[Rect->ColourIndex]);
				}
				break;

			case FR_BOTTOM:
				if(Opaque==false)
				{
					if(Masked == false)
					{
						Width &= 0xfffc;	// Software transboxfill needs to be a multiple of 4 pixels.
						Masked = true;
					}
					iV_TransBoxFill( x+Rect->TLXOffset,
									y+Height-INCEND+Rect->TLYOffset,
									x+Width-INCEND+Rect->BRXOffset,
									y+Height-INCEND+Rect->BRYOffset);
				} else {
					pie_BoxFill(x + Rect->TLXOffset, y + Height - INCEND + Rect->TLYOffset,
					            x + Width - INCEND + Rect->BRXOffset, y + Height - INCEND + Rect->BRYOffset,
					            psPalette[Rect->ColourIndex]);
				}
				break;
			case FR_IGNORE:
				break; // ignored
		}
	}

	if(Frame->TopLeft >= 0) {
		WTopLeft = (SWORD)iV_GetImageWidth(IntImages,Frame->TopLeft);
		HTopLeft = (SWORD)iV_GetImageHeight(IntImages,Frame->TopLeft);
		iV_DrawImage(IntImages,Frame->TopLeft,x,y);
	}

	if(Frame->TopRight >= 0) {
		WTopRight = (SWORD)iV_GetImageWidth(IntImages,Frame->TopRight);
		HTopRight = (SWORD)iV_GetImageHeight(IntImages,Frame->TopRight);
		iV_DrawImage(IntImages,Frame->TopRight,x+Width-WTopRight, y);
	}

	if(Frame->BottomRight >= 0) {
		WBottomRight = (SWORD)iV_GetImageWidth(IntImages,Frame->BottomRight);
		HBottomRight = (SWORD)iV_GetImageHeight(IntImages,Frame->BottomRight);
		iV_DrawImage(IntImages,Frame->BottomRight,x+Width-WBottomRight,y+Height-HBottomRight);
	}

	if(Frame->BottomLeft >= 0) {
		WBottomLeft = (SWORD)iV_GetImageWidth(IntImages,Frame->BottomLeft);
		HBottomLeft = (SWORD)iV_GetImageHeight(IntImages,Frame->BottomLeft);
		iV_DrawImage(IntImages,Frame->BottomLeft,x,y+Height-HBottomLeft);
	}

	if(Frame->TopEdge >= 0) {
		iV_DrawImageRect( IntImages, Frame->TopEdge,
							x + iV_GetImageWidth(IntImages, Frame->TopLeft), y,
							Width - WTopLeft - WTopRight, iV_GetImageHeight(IntImages, Frame->TopEdge) );
	}

	if(Frame->BottomEdge >= 0) {
		iV_DrawImageRect( IntImages, Frame->BottomEdge,
							x + WBottomLeft, y + Height - iV_GetImageHeight(IntImages, Frame->BottomEdge),
							Width - WBottomLeft - WBottomRight, iV_GetImageHeight(IntImages, Frame->BottomEdge) );
	}

	if(Frame->LeftEdge >= 0) {
		iV_DrawImageRect( IntImages, Frame->LeftEdge,
							x, y + HTopLeft,
							iV_GetImageWidth(IntImages, Frame->LeftEdge), Height - HTopLeft - HBottomLeft );
	}

	if(Frame->RightEdge >= 0) {
		iV_DrawImageRect( IntImages, Frame->RightEdge,
							x + Width - iV_GetImageWidth(IntImages, Frame->RightEdge), y + HTopRight,
							iV_GetImageWidth(IntImages, Frame->RightEdge), Height - HTopRight - HBottomRight );
	}
}

void RenderWindowFrame(FRAMETYPE frame, UDWORD x, UDWORD y, UDWORD Width, UDWORD Height)
{
	RenderWindow(frame, x, y, Width, Height, false);
}