1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #include "SDL.h"
6
7 #include "fixer.h"
8
9 #include "strtab.hpp"
10
11 #include "3dc.h"
12 #include "inline.h"
13 #include "awtexld.h"
14 #include "chnktexi.h"
15 #include "hud_layout.h"
16
17 #include "avp_menus.h"
18
19 #define UseLocalAssert Yes
20 #include "ourasert.h"
21 #include "ffstdio.h"
22
23 char AAFontWidths[256];
24
25 extern SDL_Surface *surface;
26 extern SCREENDESCRIPTORBLOCK ScreenDescriptorBlock;
27
28 extern int CloudTable[128][128];
29 extern int CloakingPhase;
30
31 AVPMENUGFX AvPMenuGfxStorage[MAX_NO_OF_AVPMENUGFXS] =
32 {
33 {"Menus\\fractal.rim"},
34 {"Common\\aa_font.rim"},// Warning! Texture from common used
35
36 {"Menus\\copyright.rim"},
37
38 {"Menus\\FIandRD.rim"},
39 {"Menus\\presents.rim"},
40 {"Menus\\AliensVPredator.rim"},
41
42 {"Menus\\sliderbar.rim"},//AVPMENUGFX_SLIDERBAR,
43 {"Menus\\slider.rim"},//AVPMENUGFX_SLIDER,
44
45 {"Menus\\starfield.rim"},
46 {"Menus\\aliens.rim"},
47 {"Menus\\Alien.rim"},
48 {"Menus\\Marine.rim"},
49 {"Menus\\Predator.rim"},
50
51 {"Menus\\glowy_left.rim"},
52 {"Menus\\glowy_middle.rim"},
53 {"Menus\\glowy_right.rim"},
54
55 // Marine level
56 {"Menus\\MarineEpisode1.rim"},
57 {"Menus\\MarineEpisode2.rim"},
58 {"Menus\\MarineEpisode3.rim"},
59 {"Menus\\MarineEpisode4.rim"},
60 {"Menus\\MarineEpisode5.rim"},
61 {"Menus\\MarineEpisode6.rim"},
62 {"Menus\\bonus.rim"},
63 {"Menus\\bonus.rim"},
64 {"Menus\\bonus.rim"},
65 {"Menus\\bonus.rim"},
66 {"Menus\\bonus.rim"},
67
68 // Predator level
69 {"Menus\\PredatorEpisode1.rim"},
70 {"Menus\\PredatorEpisode2.rim"},
71 {"Menus\\PredatorEpisode3.rim"},
72 {"Menus\\PredatorEpisode4.rim"},
73 {"Menus\\PredatorEpisode5.rim"},
74 {"Menus\\PredatorEpisode5.rim"},
75 {"Menus\\bonus.rim"},
76 {"Menus\\bonus.rim"},
77 {"Menus\\bonus.rim"},
78 {"Menus\\bonus.rim"},
79 {"Menus\\bonus.rim"},
80
81 // Alien level
82 {"Menus\\AlienEpisode2.rim"},
83 {"Menus\\AlienEpisode4.rim"},
84 {"Menus\\AlienEpisode1.rim"},
85 {"Menus\\AlienEpisode3.rim"},
86 {"Menus\\AlienEpisode5.rim"},
87 {"Menus\\bonus.rim"},
88 {"Menus\\bonus.rim"},
89 {"Menus\\bonus.rim"},
90 {"Menus\\bonus.rim"},
91 {"Menus\\bonus.rim"},
92
93 // Splash screens
94 #if MARINE_DEMO
95 {"MarineSplash\\splash00.rim"},
96 {"MarineSplash\\splash01.rim"},
97 {"MarineSplash\\splash02.rim"},
98 {"MarineSplash\\splash03.rim"},
99 {"MarineSplash\\splash04.rim"},
100 {"MarineSplash\\splash05.rim"},
101 #elif ALIEN_DEMO
102 {"AlienSplash\\splash00.rim"},
103 {"AlienSplash\\splash01.rim"},
104 {"AlienSplash\\splash02.rim"},
105 {"AlienSplash\\splash03.rim"},
106 {"AlienSplash\\splash04.rim"},
107 {"AlienSplash\\splash05.rim"},
108 #else
109 {"PredatorSplash\\splash00.rim"},
110 {"PredatorSplash\\splash01.rim"},
111 {"PredatorSplash\\splash02.rim"},
112 {"PredatorSplash\\splash03.rim"},
113 {"PredatorSplash\\splash04.rim"},
114 {"PredatorSplash\\splash05.rim"},
115 #endif
116 };
117
DrawAvPMenuGlowyBar(int topleftX,int topleftY,int alpha,int length)118 static void DrawAvPMenuGlowyBar(int topleftX, int topleftY, int alpha, int length)
119 {
120 enum AVPMENUGFX_ID menuGfxID = AVPMENUGFX_GLOWY_MIDDLE;
121 unsigned char *srcPtr;
122 unsigned short *destPtr;
123 AVPMENUGFX *gfxPtr;
124 D3DTexture *image;
125
126 gfxPtr = &AvPMenuGfxStorage[menuGfxID];
127 image = gfxPtr->ImagePtr;
128 srcPtr = image->buf;
129
130 if (ScreenDescriptorBlock.SDB_Width - topleftX < length) {
131 length = ScreenDescriptorBlock.SDB_Width - topleftX;
132 }
133 if (length<0) length = 0;
134
135 if (SDL_MUSTLOCK(surface)) {
136 if (SDL_LockSurface(surface) < 0) {
137 return; /* ... */
138 }
139 }
140
141 if (alpha>ONE_FIXED) {
142 int x, y;
143
144 for (y=topleftY; y<gfxPtr->Height+topleftY; y++) {
145 destPtr = (unsigned short *)(((unsigned char *)surface->pixels) + y*surface->pitch) + topleftX;
146
147 for (x=0; x<length; x++) {
148 *destPtr = ((srcPtr[0]>>3)<<11) |
149 ((srcPtr[1]>>2)<<5 ) |
150 ((srcPtr[2]>>3));
151 destPtr++;
152 }
153
154 srcPtr += image->w * 4;
155 }
156 } else {
157 int x, y;
158
159 for (y=topleftY; y<gfxPtr->Height+topleftY; y++) {
160 destPtr = ((unsigned short *)(((unsigned char *)surface->pixels) + y*surface->pitch)) + topleftX;
161
162 for (x=0; x<length; x++) {
163 if (srcPtr[0] || srcPtr[1] || srcPtr[2]) {
164 unsigned int destR, destG, destB;
165
166 destR = (*destPtr & 0xF800)>>8;
167 destG = (*destPtr & 0x07E0)>>3;
168 destB = (*destPtr & 0x001F)<<3;
169
170 destR += MUL_FIXED(alpha, srcPtr[0]);
171 destG += MUL_FIXED(alpha, srcPtr[1]);
172 destB += MUL_FIXED(alpha, srcPtr[2]);
173 if (destR > 0x00FF) destR = 0x00FF;
174 if (destG > 0x00FF) destG = 0x00FF;
175 if (destB > 0x00FF) destB = 0x00FF;
176
177 *destPtr = ((destR>>3)<<11) |
178 ((destG>>2)<<5 ) |
179 ((destB>>3));
180 }
181
182 destPtr++;
183 }
184
185 srcPtr += image->w * 4;
186 }
187 }
188
189 if (SDL_MUSTLOCK(surface)) {
190 SDL_UnlockSurface(surface);
191 }
192 }
193
DrawAvPMenuGlowyBar_Clipped(int topleftX,int topleftY,int alpha,int length,int topY,int bottomY)194 static void DrawAvPMenuGlowyBar_Clipped(int topleftX, int topleftY, int alpha, int length, int topY, int bottomY)
195 {
196 enum AVPMENUGFX_ID menuGfxID = AVPMENUGFX_GLOWY_MIDDLE;
197 unsigned char *srcPtr;
198 unsigned short *destPtr;
199 AVPMENUGFX *gfxPtr;
200 D3DTexture *image;
201
202 gfxPtr = &AvPMenuGfxStorage[menuGfxID];
203 image = gfxPtr->ImagePtr;
204 srcPtr = image->buf;
205
206 if (length<0) length = 0;
207
208 if (SDL_MUSTLOCK(surface)) {
209 if (SDL_LockSurface(surface) < 0) {
210 return; /* ... */
211 }
212 }
213
214 if (alpha>ONE_FIXED) {
215 int x, y;
216
217 for (y=topleftY; y<gfxPtr->Height+topleftY; y++) {
218 if(y>=topY && y<=bottomY) {
219 destPtr = (unsigned short *)(((unsigned char *)surface->pixels) + y*surface->pitch) + topleftX;
220
221 for (x=0; x<length; x++) {
222 *destPtr = ((srcPtr[0]>>3)<<11) |
223 ((srcPtr[1]>>2)<<5 ) |
224 ((srcPtr[2]>>3));
225 destPtr++;
226 }
227 }
228 srcPtr += image->w * 4;
229 }
230 } else {
231 int x, y;
232
233 for (y=topleftY; y<gfxPtr->Height+topleftY; y++) {
234 if(y>=topY && y<=bottomY) {
235 destPtr = ((unsigned short *)(((unsigned char *)surface->pixels) + y*surface->pitch)) + topleftX;
236
237 for (x=0; x<length; x++) {
238 if (srcPtr[0] || srcPtr[1] || srcPtr[2]) {
239 unsigned int destR, destG, destB;
240
241 destR = (*destPtr & 0xF800)>>8;
242 destG = (*destPtr & 0x07E0)>>3;
243 destB = (*destPtr & 0x001F)<<3;
244
245 destR += MUL_FIXED(alpha, srcPtr[0]);
246 destG += MUL_FIXED(alpha, srcPtr[1]);
247 destB += MUL_FIXED(alpha, srcPtr[2]);
248 if (destR > 0x00FF) destR = 0x00FF;
249 if (destG > 0x00FF) destG = 0x00FF;
250 if (destB > 0x00FF) destB = 0x00FF;
251
252 *destPtr = ((destR>>3)<<11) |
253 ((destG>>2)<<5 ) |
254 ((destB>>3));
255 }
256
257 destPtr++;
258 }
259 }
260 srcPtr += image->w * 4;
261 }
262 }
263
264 if (SDL_MUSTLOCK(surface)) {
265 SDL_UnlockSurface(surface);
266 }
267 }
268
269 typedef struct AVPIndexedFont
270 {
271 AVPMENUGFX info; /* graphic info */
272 int swidth; /* width for space */
273 int ascii; /* ascii code for initial character */
274 int height; /* height per character */
275
276 int numchars;
277 int FontWidth[256];
278 } AVPIndexedFont;
279
280 AVPIndexedFont IntroFont_Light;
281
LoadMenuFont()282 static void LoadMenuFont()
283 {
284 AVPMENUGFX *gfxPtr;
285 char buffer[100];
286 size_t fastFileLength;
287 void const *pFastFileData;
288
289 IntroFont_Light.height = 33;
290 IntroFont_Light.swidth = 5;
291 IntroFont_Light.ascii = 32;
292
293 gfxPtr = &IntroFont_Light.info;
294
295 CL_GetImageFileName(buffer, 100, "Menus\\IntroFont.rim", LIO_RELATIVEPATH);
296
297 pFastFileData = ffreadbuf(buffer, &fastFileLength);
298
299 if (pFastFileData) {
300 gfxPtr->ImagePtr = AwCreateSurface(
301 "pxfXY",
302 pFastFileData,
303 fastFileLength,
304 AW_TLF_TRANSP|AW_TLF_CHROMAKEY,
305 &(gfxPtr->Width),
306 &(gfxPtr->Height)
307 );
308 } else {
309 gfxPtr->ImagePtr = AwCreateSurface(
310 "sfXY",
311 buffer,
312 AW_TLF_TRANSP|AW_TLF_CHROMAKEY,
313 &(gfxPtr->Width),
314 &(gfxPtr->Height)
315 );
316 }
317
318 GLOBALASSERT(gfxPtr->ImagePtr);
319 GLOBALASSERT(gfxPtr->Width>0);
320 GLOBALASSERT(gfxPtr->Height>0);
321
322 gfxPtr->hBackup = 0;
323
324 {
325 D3DTexture *image = gfxPtr->ImagePtr;
326 unsigned char *srcPtr = image->buf;
327 int c;
328
329 if ((image->w != 30) || ((image->h % 33) != 0)) {
330 fprintf(stderr, "ERROR: I am going to give up now, because I don't like your font!\n");
331 fprintf(stderr, "Font Size: %d x %d\n", image->w, image->h);
332 exit(EXIT_FAILURE);
333 }
334
335 IntroFont_Light.numchars = image->h / 33;
336 IntroFont_Light.FontWidth[32] = 5;
337
338 for (c=33; c<(32+IntroFont_Light.numchars); c++) {
339 int x,y;
340 int y1 = 1+(c-32)*33;
341
342 IntroFont_Light.FontWidth[c]=31;
343
344 for (x=29; x>0; x--) {
345 int blank = 1;
346
347 for (y=y1; y<y1+31; y++) {
348 unsigned char *s = &srcPtr[(x + y*image->w) * 4];
349 if (s[2]) {
350 blank = 0;
351 break;
352 }
353 }
354
355 if (blank) {
356 IntroFont_Light.FontWidth[c]--;
357 } else {
358 break;
359 }
360 }
361 }
362 }
363
364 }
365
UnloadMenuFont()366 static void UnloadMenuFont()
367 {
368 ReleaseDDSurface(IntroFont_Light.info.ImagePtr);
369 IntroFont_Light.info.ImagePtr = NULL;
370 }
371
LengthOfMenuText(const char * textPtr)372 int LengthOfMenuText(const char *textPtr)
373 {
374 int width = 0;
375
376 while (textPtr && *textPtr) {
377 width += IntroFont_Light.FontWidth[(unsigned char) *textPtr];
378
379 textPtr++;
380 }
381 return width;
382 }
383
LengthOfSmallMenuText(char * textPtr)384 int LengthOfSmallMenuText(char *textPtr)
385 {
386 int width = 0;
387
388 while (textPtr && *textPtr) {
389 width += AAFontWidths[(unsigned char) *textPtr];
390
391 textPtr++;
392 }
393 return width;
394 }
395
RenderMenuText(const char * textPtr,int sx,int sy,int alpha,enum AVPMENUFORMAT_ID format)396 int RenderMenuText(const char *textPtr, int sx, int sy, int alpha, enum AVPMENUFORMAT_ID format)
397 {
398 int width;
399
400 width = LengthOfMenuText(textPtr);
401
402 switch(format) {
403 default:
404 GLOBALASSERT("UNKNOWN TEXT FORMAT"==0);
405 return 0;
406 case AVPMENUFORMAT_LEFTJUSTIFIED:
407 break;
408 case AVPMENUFORMAT_RIGHTJUSTIFIED:
409 sx -= width;
410 break;
411 case AVPMENUFORMAT_CENTREJUSTIFIED:
412 sx -= width / 2;
413 break;
414 }
415
416 LOCALASSERT(x>0);
417
418 if (alpha >BRIGHTNESS_OF_DARKENED_ELEMENT) {
419 int size = width - 18;
420 if (size<18) size = 18;
421
422 DrawAvPMenuGfx(AVPMENUGFX_GLOWY_LEFT,sx+18,sy-8,alpha,AVPMENUFORMAT_RIGHTJUSTIFIED);
423 DrawAvPMenuGlowyBar(sx+18,sy-8,alpha,size-18);
424 DrawAvPMenuGfx(AVPMENUGFX_GLOWY_RIGHT,sx+size,sy-8,alpha,AVPMENUFORMAT_LEFTJUSTIFIED);
425 }
426 {
427 unsigned char *srcPtr;
428 unsigned short *destPtr;
429 AVPMENUGFX *gfxPtr;
430 D3DTexture *image;
431
432 gfxPtr = &IntroFont_Light.info;
433 image = gfxPtr->ImagePtr;
434
435 if (SDL_MUSTLOCK(surface)) {
436 if (SDL_LockSurface(surface) < 0) {
437 return 0; /* ... */
438 }
439 }
440
441 while( *textPtr ) {
442 char c = *textPtr++;
443
444 if (c>=' ') {
445 unsigned int topLeftU = 0;
446 unsigned int topLeftV = 1+(c-32)*33;
447 unsigned int x, y;
448 unsigned int width = IntroFont_Light.FontWidth[(unsigned char) c];
449 unsigned int remainder = 0;
450 unsigned int stride = width;
451
452 if (image->w > width) {
453 remainder = image->w - width;
454 } else {
455 stride = image->w;
456 }
457
458 srcPtr = &image->buf[(topLeftU+topLeftV*image->w)*4];
459
460 for (y=sy; y<33+sy; y++) {
461 destPtr = (unsigned short *)(((unsigned char *)surface->pixels)+y*surface->pitch) + sx;
462
463 for (x=stride; x>0; x--) {
464 if (srcPtr[0] || srcPtr[1] || srcPtr[2]) {
465 unsigned int destR, destG, destB;
466
467 int r = CloudTable[(x+sx+CloakingPhase/64)&127][(y+CloakingPhase/128)&127];
468 r = MUL_FIXED(alpha, r);
469
470 destR = (*destPtr & 0xF800)>>8;
471 destG = (*destPtr & 0x07E0)>>3;
472 destB = (*destPtr & 0x001F)<<3;
473
474 destR += MUL_FIXED(r, srcPtr[0]);
475 destG += MUL_FIXED(r, srcPtr[1]);
476 destB += MUL_FIXED(r, srcPtr[2]);
477 if (destR > 0x00FF) destR = 0x00FF;
478 if (destG > 0x00FF) destG = 0x00FF;
479 if (destB > 0x00FF) destB = 0x00FF;
480
481 *destPtr = ((destR>>3)<<11) |
482 ((destG>>2)<<5 ) |
483 ((destB>>3));
484 }
485 srcPtr += 4;
486 destPtr++;
487 }
488 srcPtr += remainder * 4;
489 }
490 sx += width;
491 }
492 }
493
494 if (SDL_MUSTLOCK(surface)) {
495 SDL_UnlockSurface(surface);
496 }
497
498 return sx;
499 }
500
501 }
502
RenderMenuText_Clipped(char * textPtr,int sx,int sy,int alpha,enum AVPMENUFORMAT_ID format,int topY,int bottomY)503 int RenderMenuText_Clipped(char *textPtr, int sx, int sy, int alpha, enum AVPMENUFORMAT_ID format, int topY, int bottomY)
504 {
505 int width = LengthOfMenuText(textPtr);
506
507 switch(format) {
508 default:
509 GLOBALASSERT("UNKNOWN TEXT FORMAT"==0);
510 return 0;
511 case AVPMENUFORMAT_LEFTJUSTIFIED:
512 break;
513 case AVPMENUFORMAT_RIGHTJUSTIFIED:
514 sx -= width;
515 break;
516 case AVPMENUFORMAT_CENTREJUSTIFIED:
517 sx -= width / 2;
518 break;
519 }
520
521 LOCALASSERT(x>0);
522
523 if (alpha > BRIGHTNESS_OF_DARKENED_ELEMENT) {
524 int size = width - 18;
525 if (size<18) size = 18;
526
527 DrawAvPMenuGfx_Clipped(AVPMENUGFX_GLOWY_LEFT,sx+18,sy-8,alpha,AVPMENUFORMAT_RIGHTJUSTIFIED,topY,bottomY);
528 DrawAvPMenuGlowyBar_Clipped(sx+18,sy-8,alpha,size-18,topY,bottomY);
529 DrawAvPMenuGfx_Clipped(AVPMENUGFX_GLOWY_RIGHT,sx+size,sy-8,alpha,AVPMENUFORMAT_LEFTJUSTIFIED,topY,bottomY);
530 }
531 {
532 unsigned char *srcPtr;
533 unsigned short *destPtr;
534 AVPMENUGFX *gfxPtr;
535 D3DTexture *image;
536
537 gfxPtr = &IntroFont_Light.info;
538 image = gfxPtr->ImagePtr;
539
540 if (SDL_MUSTLOCK(surface)) {
541 if (SDL_LockSurface(surface) < 0) {
542 return 0; /* ... */
543 }
544 }
545
546 while( *textPtr ) {
547 char c = *textPtr++;
548
549 if (c>=' ') {
550 unsigned int topLeftU = 0;
551 unsigned int topLeftV = 1+(c-32)*33;
552 unsigned int x, y;
553 unsigned int width = IntroFont_Light.FontWidth[(unsigned char) c];
554 unsigned int remainder = 0;
555 unsigned int stride = width;
556
557 if (image->w > width) {
558 remainder = image->w - width;
559 } else {
560 stride = image->w;
561 }
562
563 srcPtr = &image->buf[(topLeftU+topLeftV*image->w)*4];
564
565 for (y=sy; y<33+sy; y++) {
566 if(y>=topY && y<=bottomY) {
567 destPtr = (unsigned short *)(((unsigned char *)surface->pixels)+y*surface->pitch) + sx;
568
569 for (x=stride; x>0; x--) {
570 if (srcPtr[0] || srcPtr[1] || srcPtr[2]) {
571 unsigned int destR, destG, destB;
572
573 int r = CloudTable[(x+sx+CloakingPhase/64)&127][(y+CloakingPhase/128)&127];
574 r = MUL_FIXED(alpha, r);
575
576 destR = (*destPtr & 0xF800)>>8;
577 destG = (*destPtr & 0x07E0)>>3;
578 destB = (*destPtr & 0x001F)<<3;
579
580 destR += MUL_FIXED(r, srcPtr[0]);
581 destG += MUL_FIXED(r, srcPtr[1]);
582 destB += MUL_FIXED(r, srcPtr[2]);
583 if (destR > 0x00FF) destR = 0x00FF;
584 if (destG > 0x00FF) destG = 0x00FF;
585 if (destB > 0x00FF) destB = 0x00FF;
586
587 *destPtr = ((destR>>3)<<11) |
588 ((destG>>2)<<5 ) |
589 ((destB>>3));
590 }
591 srcPtr += 4;
592 destPtr++;
593 }
594 srcPtr += remainder * 4;
595 } else {
596 srcPtr += image->w * 4;
597 }
598 }
599 sx += width;
600 }
601 }
602
603 if (SDL_MUSTLOCK(surface)) {
604 SDL_UnlockSurface(surface);
605 }
606
607 return sx;
608 }
609
610 }
611
RenderSmallFontString(char * textPtr,int sx,int sy,int alpha,int red,int green,int blue)612 static int RenderSmallFontString(char *textPtr,int sx,int sy,int alpha, int red, int green, int blue)
613 {
614 unsigned char *srcPtr;
615 unsigned short *destPtr;
616 int alphaR = MUL_FIXED(alpha,red);
617 int alphaG = MUL_FIXED(alpha,green);
618 int alphaB = MUL_FIXED(alpha,blue);
619 AVPMENUGFX *gfxPtr;
620 D3DTexture *image;
621
622 gfxPtr = &AvPMenuGfxStorage[AVPMENUGFX_SMALL_FONT];
623 image = gfxPtr->ImagePtr;
624
625 if (SDL_MUSTLOCK(surface)) {
626 if (SDL_LockSurface(surface) < 0) {
627 return 0; /* ... */
628 }
629 }
630
631 while( *textPtr ) {
632 char c = *textPtr++;
633
634 if (c>=' ') {
635 int topLeftU = 1+((c-32)&15)*16;
636 int topLeftV = 1+((c-32)>>4)*16;
637 int x, y;
638
639 srcPtr = &image->buf[(topLeftU+topLeftV*image->w)*4];
640
641 for (y=sy; y<HUD_FONT_HEIGHT+sy; y++) {
642 destPtr = (unsigned short *)(((unsigned char *)surface->pixels)+y*surface->pitch) + sx;
643
644 for (x=0; x<HUD_FONT_WIDTH; x++) {
645 if (srcPtr[0] || srcPtr[1] || srcPtr[2]) {
646 unsigned int destR, destG, destB;
647
648 destR = (*destPtr & 0xF800)>>8;
649 destG = (*destPtr & 0x07E0)>>3;
650 destB = (*destPtr & 0x001F)<<3;
651
652 destR += MUL_FIXED(alphaR, srcPtr[0]);
653 destG += MUL_FIXED(alphaG, srcPtr[1]);
654 destB += MUL_FIXED(alphaB, srcPtr[2]);
655 if (destR > 0x00FF) destR = 0x00FF;
656 if (destG > 0x00FF) destG = 0x00FF;
657 if (destB > 0x00FF) destB = 0x00FF;
658
659 *destPtr = ((destR>>3)<<11) |
660 ((destG>>2)<<5 ) |
661 ((destB>>3));
662 }
663 srcPtr += 4;
664 destPtr++;
665 }
666 srcPtr += (image->w - HUD_FONT_WIDTH) * 4;
667 }
668 sx += AAFontWidths[(unsigned char) c];
669 }
670 }
671
672 if (SDL_MUSTLOCK(surface)) {
673 SDL_UnlockSurface(surface);
674 }
675
676 return sx;
677 }
678
RenderSmallFontString_Wrapped(const char * textPtr,RECT * area,int alpha,int * output_x,int * output_y)679 void RenderSmallFontString_Wrapped(const char *textPtr,RECT* area,int alpha,int* output_x,int* output_y)
680 {
681 unsigned char *srcPtr;
682 unsigned short *destPtr;
683 AVPMENUGFX *gfxPtr;
684 D3DTexture *image;
685 int wordWidth;
686 int sx=area->left;
687 int sy=area->top;
688
689 gfxPtr = &AvPMenuGfxStorage[AVPMENUGFX_SMALL_FONT];
690 image = gfxPtr->ImagePtr;
691
692 /*
693 Determine area used by text , so we can draw it centrally
694 */
695 {
696 const char *textPtr2=textPtr;
697 while (*textPtr2) {
698 int widthFromSpaces=0;
699 int widthFromChars=0;
700
701 while(*textPtr2 && *textPtr2==' ') {
702 widthFromSpaces+=AAFontWidths[(unsigned char) *textPtr2++];
703 }
704
705 while(*textPtr2 && *textPtr2!=' ') {
706 widthFromChars+=AAFontWidths[(unsigned char) *textPtr2++];
707 }
708
709 wordWidth=widthFromSpaces+widthFromChars;
710
711 if(wordWidth> area->right-sx) {
712 if(wordWidth >area->right-area->left) {
713 int extraLinesNeeded=0;
714
715 wordWidth-=(area->right-sx);
716
717 sy+=HUD_FONT_HEIGHT;
718 sx=area->left;
719
720 extraLinesNeeded=wordWidth/(area->right-area->left);
721
722 sy+=HUD_FONT_HEIGHT*extraLinesNeeded;
723 wordWidth %= (area->right-area->left);
724
725 if(sy+HUD_FONT_HEIGHT> area->bottom) break;
726 } else {
727 sy+=HUD_FONT_HEIGHT;
728 sx=area->left;
729
730 if(sy+HUD_FONT_HEIGHT> area->bottom) break;
731
732 if(wordWidth> area->right-sx) break;
733
734 wordWidth-=widthFromSpaces;
735 }
736 }
737 sx+=wordWidth;
738 }
739
740 if(sy==area->top) {
741 sx=area->left+ (area->right-sx)/2;
742 } else {
743 sx=area->left;
744 }
745
746 sy+=HUD_FONT_HEIGHT;
747 if(sy<area->bottom) {
748 sy=area->top + (area->bottom-sy)/2;
749 } else {
750 sy=area->top;
751 }
752 }
753
754 if (SDL_MUSTLOCK(surface)) {
755 if (SDL_LockSurface(surface) < 0) {
756 return; /* ... */
757 }
758 }
759
760 while ( *textPtr ) {
761 const char* textPtr2=textPtr;
762 wordWidth=0;
763
764 while(*textPtr2 && *textPtr2==' ') {
765 wordWidth+=AAFontWidths[(unsigned char) *textPtr2++];
766 }
767
768 while(*textPtr2 && *textPtr2!=' ') {
769 wordWidth+=AAFontWidths[(unsigned char) *textPtr2++];
770 }
771
772 if(wordWidth> area->right-sx) {
773 if(wordWidth>area->right - area->left) {
774 /*
775 word is too long too fit on one line
776 so we'll just have to allow it to be split
777 */
778 } else {
779 sy+=HUD_FONT_HEIGHT;
780 sx=area->left;
781
782 if(sy+HUD_FONT_HEIGHT> area->bottom) break;
783
784 if(wordWidth> area->right-sx) break;
785
786 while(*textPtr && *textPtr==' ') {
787 textPtr++;
788 }
789 }
790 }
791
792 while(*textPtr && *textPtr==' ') {
793 sx+=AAFontWidths[(unsigned char) *textPtr++];
794 }
795
796 if(sx>area->right) {
797 while(sx>area->right) {
798 sx-=(area->right-area->left);
799 sy+=HUD_FONT_HEIGHT;
800 }
801
802 if(sy+HUD_FONT_HEIGHT> area->bottom) break;
803 }
804
805 while(*textPtr && *textPtr!=' ') {
806 char c = *textPtr++;
807 int letterWidth = AAFontWidths[(unsigned char) c];
808
809 if(sx+letterWidth>area->right) {
810 sx=area->left;
811 sy+=HUD_FONT_HEIGHT;
812
813 if(sy+HUD_FONT_HEIGHT> area->bottom) break;
814 }
815
816 if (c>=' ' || c<='z') {
817 int topLeftU = 1+((c-32)&15)*16;
818 int topLeftV = 1+((c-32)>>4)*16;
819 int x, y;
820
821 srcPtr = &image->buf[(topLeftU+topLeftV*image->w)*4];
822
823 for (y=sy; y<HUD_FONT_HEIGHT+sy; y++) {
824 destPtr = (unsigned short *)(((unsigned char *)surface->pixels) + y*surface->pitch) + sx;
825
826 for (x=0; x<HUD_FONT_WIDTH; x++) {
827 if (srcPtr[0] || srcPtr[1] || srcPtr[2]) {
828 unsigned int destR, destG, destB;
829
830 destR = (*destPtr & 0xF800)>>8;
831 destG = (*destPtr & 0x07E0)>>3;
832 destB = (*destPtr & 0x001F)<<3;
833
834 destR += MUL_FIXED(alpha, srcPtr[0]);
835 destG += MUL_FIXED(alpha, srcPtr[1]);
836 destB += MUL_FIXED(alpha, srcPtr[2]);
837 if (destR > 0x00FF) destR = 0x00FF;
838 if (destG > 0x00FF) destG = 0x00FF;
839 if (destB > 0x00FF) destB = 0x00FF;
840
841 *destPtr = ((destR>>3)<<11) |
842 ((destG>>2)<<5 ) |
843 ((destB>>3));
844 }
845 srcPtr += 4;
846 destPtr++;
847 }
848 srcPtr += (image->w - HUD_FONT_WIDTH) * 4;
849 }
850 sx += AAFontWidths[(unsigned char) c];
851 }
852 }
853 }
854
855 if (SDL_MUSTLOCK(surface)) {
856 SDL_UnlockSurface(surface);
857 }
858
859 if(output_x) *output_x=sx;
860 if(output_y) *output_y=sy;
861 }
862
RenderSmallMenuText(char * textPtr,int x,int y,int alpha,enum AVPMENUFORMAT_ID format)863 int RenderSmallMenuText(char *textPtr, int x, int y, int alpha, enum AVPMENUFORMAT_ID format)
864 {
865 int length;
866 char *ptr;
867
868 switch(format) {
869 default:
870 GLOBALASSERT("UNKNOWN TEXT FORMAT"==0);
871 return 0;
872 case AVPMENUFORMAT_LEFTJUSTIFIED:
873 break;
874 case AVPMENUFORMAT_RIGHTJUSTIFIED:
875 length = 0;
876 ptr = textPtr;
877
878 while (*ptr) {
879 length+=AAFontWidths[(unsigned char) *ptr++];
880 }
881
882 x -= length;
883 break;
884 case AVPMENUFORMAT_CENTREJUSTIFIED:
885 length = 0;
886 ptr = textPtr;
887
888 while (*ptr) {
889 length+=AAFontWidths[(unsigned char) *ptr++];
890 }
891
892 x -= length / 2;
893 break;
894 }
895
896 LOCALASSERT(x>0);
897
898 return RenderSmallFontString(textPtr,x,y,alpha,ONE_FIXED,ONE_FIXED,ONE_FIXED);
899 }
900
RenderSmallMenuText_Coloured(char * textPtr,int x,int y,int alpha,enum AVPMENUFORMAT_ID format,int red,int green,int blue)901 int RenderSmallMenuText_Coloured(char *textPtr, int x, int y, int alpha, enum AVPMENUFORMAT_ID format, int red, int green, int blue)
902 {
903 int length;
904 char *ptr;
905
906 switch(format) {
907 default:
908 GLOBALASSERT("UNKNOWN TEXT FORMAT"==0);
909 return 0;
910 case AVPMENUFORMAT_LEFTJUSTIFIED:
911 break;
912 case AVPMENUFORMAT_RIGHTJUSTIFIED:
913 length = 0;
914 ptr = textPtr;
915
916 while (*ptr) {
917 length+=AAFontWidths[(unsigned char) *ptr++];
918 }
919
920 x -= length;
921 break;
922 case AVPMENUFORMAT_CENTREJUSTIFIED:
923 length = 0;
924 ptr = textPtr;
925
926 while (*ptr) {
927 length+=AAFontWidths[(unsigned char) *ptr++];
928 }
929
930 x -= length / 2;
931 break;
932 }
933
934 LOCALASSERT(x>0);
935
936 return RenderSmallFontString(textPtr,x,y,alpha,red,green,blue);
937 }
938
CalculateWidthsOfAAFont()939 static void CalculateWidthsOfAAFont()
940 {
941 unsigned char *srcPtr;
942 AVPMENUGFX *gfxPtr;
943 D3DTexture *image;
944 int c;
945
946 gfxPtr = &AvPMenuGfxStorage[AVPMENUGFX_SMALL_FONT];
947 image = gfxPtr->ImagePtr;
948
949 srcPtr = image->buf;
950
951 AAFontWidths[32]=3;
952
953 for (c=33; c<255; c++) {
954 int x,y;
955 int x1 = 1+((c-32)&15)*16;
956 int y1 = 1+((c-32)>>4)*16;
957
958 AAFontWidths[c]=17;
959
960 for (x=x1+HUD_FONT_WIDTH; x>x1; x--) {
961 int blank = 1;
962
963 for (y=y1; y<y1+HUD_FONT_HEIGHT; y++) {
964 unsigned char *s = &srcPtr[(x + y*image->w) * 4];
965 if (s[2] >= 0x80) {
966 blank = 0;
967 break;
968 }
969 }
970
971 if (blank) {
972 AAFontWidths[c]--;
973 } else {
974 break;
975 }
976 }
977 }
978 }
979
RenderKeyConfigRectangle(int alpha)980 void RenderKeyConfigRectangle(int alpha)
981 {
982 int x1 = 10;
983 int x2 = ScreenDescriptorBlock.SDB_Width-10;
984 int y1 = ScreenDescriptorBlock.SDB_Height/2+25-115;
985 int y2 = ScreenDescriptorBlock.SDB_Height/2+25-115+250;
986 int x,y;
987 unsigned short c, *destPtr;
988
989 c = ((MUL_FIXED(0xFF,alpha)>>3)<<11) |
990 ((MUL_FIXED(0xFF,alpha)>>2)<<5 ) |
991 ((MUL_FIXED(0xFF,alpha)>>3));
992
993 if (SDL_MUSTLOCK(surface)) {
994 if (SDL_LockSurface(surface) < 0) {
995 return; /* ... */
996 }
997 }
998
999 y = y1;
1000 destPtr = (unsigned short *)(((unsigned char *)surface->pixels) + y*surface->pitch) + x1;
1001 for (x=x1; x<=x2; x++) {
1002 *destPtr |= c;
1003 destPtr++;
1004 }
1005
1006 y = y2;
1007 destPtr = (unsigned short *)(((unsigned char *)surface->pixels) + y*surface->pitch) + x1;
1008 for (x=x1; x<=x2; x++) {
1009 *destPtr |= c;
1010 destPtr++;
1011 }
1012
1013 for (y=y1+1; y<y2; y++) {
1014 destPtr = (unsigned short *)(((unsigned char *)surface->pixels) + y*surface->pitch) + x1;
1015 *destPtr |= c;
1016 }
1017
1018 for (y=y1+1; y<y2; y++) {
1019 destPtr = (unsigned short *)(((unsigned char *)surface->pixels) + y*surface->pitch) + x2;
1020 *destPtr |= c;
1021 }
1022
1023 if (SDL_MUSTLOCK(surface)) {
1024 SDL_UnlockSurface(surface);
1025 }
1026 }
1027
RenderHighlightRectangle(int x1,int y1,int x2,int y2,int r,int g,int b)1028 void RenderHighlightRectangle(int x1, int y1, int x2, int y2, int r, int g, int b)
1029 {
1030 int x, y;
1031 unsigned short c;
1032
1033 c = ((r>>3)<<11) |
1034 ((g>>2)<<5 ) |
1035 ((b>>3));
1036
1037 if (SDL_MUSTLOCK(surface)) {
1038 if (SDL_LockSurface(surface) < 0) {
1039 return; /* ... */
1040 }
1041 }
1042
1043 for (y=y1; y<=y2; y++) {
1044 unsigned short *destPtr = (unsigned short *)(((unsigned char *)surface->pixels) + y*surface->pitch) + x1;
1045
1046 for (x = x1; x <= x2; x++) {
1047 *destPtr |= c;
1048
1049 destPtr++;
1050 }
1051 }
1052
1053 if (SDL_MUSTLOCK(surface)) {
1054 SDL_UnlockSurface(surface);
1055 }
1056 }
1057
LoadAvPMenuGfx(enum AVPMENUGFX_ID menuGfxID)1058 void LoadAvPMenuGfx(enum AVPMENUGFX_ID menuGfxID)
1059 {
1060 AVPMENUGFX *gfxPtr;
1061 char buffer[100];
1062 size_t fastFileLength;
1063 void const *pFastFileData;
1064
1065 GLOBALASSERT(menuGfxID < MAX_NO_OF_AVPMENUGFXS);
1066
1067 gfxPtr = &AvPMenuGfxStorage[menuGfxID];
1068
1069 CL_GetImageFileName(buffer, 100, gfxPtr->FilenamePtr, LIO_RELATIVEPATH);
1070
1071 pFastFileData = ffreadbuf(buffer, &fastFileLength);
1072
1073 if (pFastFileData) {
1074 gfxPtr->ImagePtr = AwCreateSurface(
1075 "pxfXY",
1076 pFastFileData,
1077 fastFileLength,
1078 AW_TLF_TRANSP|AW_TLF_CHROMAKEY,
1079 &(gfxPtr->Width),
1080 &(gfxPtr->Height)
1081 );
1082 } else {
1083 gfxPtr->ImagePtr = AwCreateSurface(
1084 "sfXY",
1085 buffer,
1086 AW_TLF_TRANSP|AW_TLF_CHROMAKEY,
1087 &(gfxPtr->Width),
1088 &(gfxPtr->Height)
1089 );
1090 }
1091
1092 GLOBALASSERT(gfxPtr->ImagePtr);
1093 GLOBALASSERT(gfxPtr->Width>0);
1094 GLOBALASSERT(gfxPtr->Height>0);
1095
1096 gfxPtr->hBackup = 0;
1097 }
1098
ReleaseAvPMenuGfx(enum AVPMENUGFX_ID menuGfxID)1099 static void ReleaseAvPMenuGfx(enum AVPMENUGFX_ID menuGfxID)
1100 {
1101 AVPMENUGFX *gfxPtr;
1102
1103 GLOBALASSERT(menuGfxID < MAX_NO_OF_AVPMENUGFXS);
1104
1105
1106 gfxPtr = &AvPMenuGfxStorage[menuGfxID];
1107
1108 GLOBALASSERT(gfxPtr);
1109 GLOBALASSERT(gfxPtr->ImagePtr);
1110
1111 ReleaseDDSurface(gfxPtr->ImagePtr);
1112
1113 gfxPtr->ImagePtr = NULL;
1114 }
1115
LoadAllAvPMenuGfx()1116 void LoadAllAvPMenuGfx()
1117 {
1118 int i;
1119
1120 for (i = 0; i < AVPMENUGFX_WINNER_SCREEN; i++) {
1121 LoadAvPMenuGfx(i);
1122 }
1123
1124 LoadMenuFont();
1125 {
1126 unsigned char *srcPtr;
1127 AVPMENUGFX *gfxPtr = &AvPMenuGfxStorage[AVPMENUGFX_CLOUDY];
1128 D3DTexture *image;
1129
1130 int x, y;
1131
1132 image = gfxPtr->ImagePtr;
1133 srcPtr = image->buf;
1134
1135 for (y=0; y<gfxPtr->Height; y++) {
1136 for (x=0; x<gfxPtr->Width; x++) {
1137
1138 int r = srcPtr[0];
1139
1140 r = DIV_FIXED(r, 0xFF);
1141 CloudTable[x][y]=r;
1142
1143 srcPtr += 4;
1144 }
1145 }
1146 }
1147
1148 CalculateWidthsOfAAFont();
1149 }
1150
LoadAllSplashScreenGfx()1151 void LoadAllSplashScreenGfx()
1152 {
1153 int i;
1154
1155 for (i = AVPMENUGFX_SPLASH_SCREEN1; i < MAX_NO_OF_AVPMENUGFXS; i++) {
1156 LoadAvPMenuGfx(i);
1157 }
1158 }
1159
InitialiseMenuGfx()1160 void InitialiseMenuGfx()
1161 {
1162 int i;
1163
1164 for (i = 0; i < MAX_NO_OF_AVPMENUGFXS; i++) {
1165 AvPMenuGfxStorage[i].ImagePtr = NULL;
1166 }
1167 }
1168
ReleaseAllAvPMenuGfx()1169 void ReleaseAllAvPMenuGfx()
1170 {
1171 int i;
1172
1173 for (i = 0; i < MAX_NO_OF_AVPMENUGFXS; i++) {
1174 if (AvPMenuGfxStorage[i].ImagePtr) {
1175 ReleaseAvPMenuGfx(i);
1176 }
1177 }
1178
1179 UnloadMenuFont();
1180 }
1181
DrawAvPMenuGfx(enum AVPMENUGFX_ID menuGfxID,int topleftX,int topleftY,int alpha,enum AVPMENUFORMAT_ID format)1182 void DrawAvPMenuGfx(enum AVPMENUGFX_ID menuGfxID, int topleftX, int topleftY, int alpha,enum AVPMENUFORMAT_ID format)
1183 {
1184 AVPMENUGFX *gfxPtr;
1185 D3DTexture *image;
1186 unsigned char *srcPtr;
1187 unsigned short *destPtr;
1188 int length;
1189
1190 GLOBALASSERT(menuGfxID < MAX_NO_OF_AVPMENUGFXS);
1191
1192 gfxPtr = &AvPMenuGfxStorage[menuGfxID];
1193 image = gfxPtr->ImagePtr;
1194
1195 switch(format) {
1196 default:
1197 GLOBALASSERT("UNKNOWN TEXT FORMAT"==0);
1198 return;
1199 case AVPMENUFORMAT_LEFTJUSTIFIED:
1200 break;
1201 case AVPMENUFORMAT_RIGHTJUSTIFIED:
1202 topleftX -= gfxPtr->Width;
1203 break;
1204 case AVPMENUFORMAT_CENTREJUSTIFIED:
1205 topleftX -= gfxPtr->Width/2;
1206 break;
1207 }
1208
1209 srcPtr = (unsigned char *)image->buf;
1210 length = gfxPtr->Width;
1211
1212 if (ScreenDescriptorBlock.SDB_Width - topleftX < length) {
1213 length = ScreenDescriptorBlock.SDB_Width - topleftX;
1214 }
1215 if (length <= 0) return;
1216
1217 if (SDL_MUSTLOCK(surface)) {
1218 if (SDL_LockSurface(surface) < 0) {
1219 return; /* ... */
1220 }
1221 }
1222
1223 if (alpha > ONE_FIXED) {
1224 int x, y;
1225
1226 for (y=topleftY; y<gfxPtr->Height+topleftY; y++) {
1227 destPtr = ((unsigned short *)(((unsigned char *)surface->pixels) + y*surface->pitch)) + topleftX;
1228
1229 for (x=0; x<length; x++) {
1230 *destPtr = ((srcPtr[0]>>3)<<11) |
1231 ((srcPtr[1]>>2)<<5 ) |
1232 ((srcPtr[2]>>3));
1233 srcPtr += 4;
1234 destPtr++;
1235 }
1236
1237 srcPtr += (image->w - length) * 4;
1238 }
1239 } else {
1240 int x, y;
1241
1242 for (y=topleftY; y<gfxPtr->Height+topleftY; y++) {
1243 destPtr = ((unsigned short *)(((unsigned char *)surface->pixels) + y*surface->pitch)) + topleftX;
1244
1245 for (x=0; x<length; x++) {
1246 if (srcPtr[0] || srcPtr[1] || srcPtr[2]) {
1247 unsigned int destR, destG, destB;
1248
1249 destR = (*destPtr & 0xF800)>>8;
1250 destG = (*destPtr & 0x07E0)>>3;
1251 destB = (*destPtr & 0x001F)<<3;
1252
1253 destR += MUL_FIXED(alpha, srcPtr[0]);
1254 destG += MUL_FIXED(alpha, srcPtr[1]);
1255 destB += MUL_FIXED(alpha, srcPtr[2]);
1256 if (destR > 0x00FF) destR = 0x00FF;
1257 if (destG > 0x00FF) destG = 0x00FF;
1258 if (destB > 0x00FF) destB = 0x00FF;
1259
1260 *destPtr = ((destR>>3)<<11) |
1261 ((destG>>2)<<5 ) |
1262 ((destB>>3));
1263 }
1264
1265 srcPtr += 4;
1266 destPtr++;
1267 }
1268
1269 srcPtr += (image->w - length) * 4;
1270 }
1271 }
1272
1273 if (SDL_MUSTLOCK(surface)) {
1274 SDL_UnlockSurface(surface);
1275 }
1276 }
1277
DrawAvPMenuGfx_CrossFade(enum AVPMENUGFX_ID menuGfxID,enum AVPMENUGFX_ID menuGfxID2,int alpha)1278 void DrawAvPMenuGfx_CrossFade(enum AVPMENUGFX_ID menuGfxID,enum AVPMENUGFX_ID menuGfxID2,int alpha)
1279 {
1280 AVPMENUGFX *gfxPtr, *gfxPtr2;
1281 D3DTexture *image, *image2;
1282 unsigned char *srcPtr, *srcPtr2;
1283 unsigned short *destPtr;
1284 int length;
1285
1286 GLOBALASSERT(menuGfxID < MAX_NO_OF_AVPMENUGFXS);
1287 GLOBALASSERT(menuGfxID2 < MAX_NO_OF_AVPMENUGFXS);
1288
1289 gfxPtr = &AvPMenuGfxStorage[menuGfxID];
1290 image = gfxPtr->ImagePtr;
1291 gfxPtr2 = &AvPMenuGfxStorage[menuGfxID2];
1292 image2 = gfxPtr2->ImagePtr;
1293
1294 srcPtr = image->buf;
1295 srcPtr2 = image2->buf;
1296
1297 if (SDL_MUSTLOCK(surface)) {
1298 if (SDL_LockSurface(surface) < 0) {
1299 return; /* ... */
1300 }
1301 }
1302
1303 length = 640;
1304
1305 if (alpha == ONE_FIXED) {
1306 int x, y;
1307
1308 for (y=0; y<480; y++) {
1309 destPtr = ((unsigned short *)(((unsigned char *)surface->pixels) + y*surface->pitch));
1310
1311 for (x=0; x<640; x++) {
1312 *destPtr = ((srcPtr[0]>>3)<<11) |
1313 ((srcPtr[1]>>2)<<5 ) |
1314 ((srcPtr[2]>>3));
1315 srcPtr += 4;
1316 destPtr++;
1317 }
1318 srcPtr += (image->w - length) * 4;
1319 }
1320 } else {
1321 int x, y;
1322
1323 for (y=0; y<480; y++) {
1324 destPtr = ((unsigned short *)(((unsigned char *)surface->pixels) + y*surface->pitch));
1325
1326 for (x=0; x<640; x++) {
1327 unsigned int srcR1, srcR2;
1328 unsigned int srcG1, srcG2;
1329 unsigned int srcB1, srcB2;
1330
1331 srcR1 = srcPtr[0];
1332 srcR2 = srcPtr2[0];
1333 srcG1 = srcPtr[1];
1334 srcG2 = srcPtr2[1];
1335 srcB1 = srcPtr[2];
1336 srcB2 = srcPtr2[2];
1337
1338 srcR2 = MUL_FIXED(ONE_FIXED-alpha,srcR2)+MUL_FIXED(alpha,srcR1);
1339 srcG2 = MUL_FIXED(ONE_FIXED-alpha,srcG2)+MUL_FIXED(alpha,srcG1);
1340 srcB2 = MUL_FIXED(ONE_FIXED-alpha,srcB2)+MUL_FIXED(alpha,srcB1);
1341
1342 *destPtr = ((srcR2>>3)<<11) |
1343 ((srcG2>>2)<<5 ) |
1344 ((srcB2>>3));
1345 srcPtr += 4;
1346 srcPtr2 += 4;
1347 destPtr++;
1348 }
1349 }
1350 }
1351
1352 if (SDL_MUSTLOCK(surface)) {
1353 SDL_UnlockSurface(surface);
1354 }
1355
1356 }
1357
DrawAvPMenuGfx_Faded(enum AVPMENUGFX_ID menuGfxID,int topleftX,int topleftY,int alpha,enum AVPMENUFORMAT_ID format)1358 void DrawAvPMenuGfx_Faded(enum AVPMENUGFX_ID menuGfxID, int topleftX, int topleftY, int alpha,enum AVPMENUFORMAT_ID format)
1359 {
1360 AVPMENUGFX *gfxPtr;
1361 D3DTexture *image;
1362 unsigned char *srcPtr;
1363 unsigned short *destPtr;
1364 int length;
1365
1366 GLOBALASSERT(menuGfxID < MAX_NO_OF_AVPMENUGFXS);
1367
1368 gfxPtr = &AvPMenuGfxStorage[menuGfxID];
1369 image = gfxPtr->ImagePtr;
1370
1371 switch(format) {
1372 default:
1373 GLOBALASSERT("UNKNOWN TEXT FORMAT"==0);
1374 return;
1375 case AVPMENUFORMAT_LEFTJUSTIFIED:
1376 break;
1377 case AVPMENUFORMAT_RIGHTJUSTIFIED:
1378 topleftX -= gfxPtr->Width;
1379 break;
1380 case AVPMENUFORMAT_CENTREJUSTIFIED:
1381 topleftX -= gfxPtr->Width/2;
1382 break;
1383 }
1384
1385 srcPtr = (unsigned char *)image->buf;
1386 length = gfxPtr->Width;
1387
1388 if (ScreenDescriptorBlock.SDB_Width - topleftX < length) {
1389 length = ScreenDescriptorBlock.SDB_Width - topleftX;
1390 }
1391 if (length <= 0) return;
1392
1393 if (SDL_MUSTLOCK(surface)) {
1394 if (SDL_LockSurface(surface) < 0) {
1395 return; /* ... */
1396 }
1397 }
1398
1399 {
1400 int x, y;
1401
1402 for (y=topleftY; y<gfxPtr->Height+topleftY; y++) {
1403 destPtr = ((unsigned short *)(((unsigned char *)surface->pixels) + y*surface->pitch)) + topleftX;
1404
1405 for (x=0; x<length; x++) {
1406 unsigned int srcR,srcG,srcB;
1407
1408 if (srcPtr[0] || srcPtr[1] || srcPtr[2]) {
1409 srcR = MUL_FIXED(srcPtr[0], alpha);
1410 srcG = MUL_FIXED(srcPtr[1], alpha);
1411 srcB = MUL_FIXED(srcPtr[2], alpha);
1412 *destPtr = ((srcR>>3)<<11) |
1413 ((srcG>>2)<<5 ) |
1414 ((srcB>>3));
1415 }
1416
1417 srcPtr += 4;
1418 destPtr++;
1419 }
1420
1421 srcPtr += (image->w - length) * 4;
1422 }
1423 }
1424
1425 if (SDL_MUSTLOCK(surface)) {
1426 SDL_UnlockSurface(surface);
1427 }
1428 }
1429
DrawAvPMenuGfx_Clipped(enum AVPMENUGFX_ID menuGfxID,int topleftX,int topleftY,int alpha,enum AVPMENUFORMAT_ID format,int topY,int bottomY)1430 void DrawAvPMenuGfx_Clipped(enum AVPMENUGFX_ID menuGfxID, int topleftX, int topleftY, int alpha,enum AVPMENUFORMAT_ID format, int topY, int bottomY)
1431 {
1432 AVPMENUGFX *gfxPtr;
1433 D3DTexture *image;
1434 unsigned char *srcPtr;
1435 unsigned short *destPtr;
1436 int length;
1437
1438 GLOBALASSERT(menuGfxID < MAX_NO_OF_AVPMENUGFXS);
1439
1440 gfxPtr = &AvPMenuGfxStorage[menuGfxID];
1441 image = gfxPtr->ImagePtr;
1442
1443 switch(format) {
1444 default:
1445 GLOBALASSERT("UNKNOWN TEXT FORMAT"==0);
1446 return;
1447 case AVPMENUFORMAT_LEFTJUSTIFIED:
1448 break;
1449 case AVPMENUFORMAT_RIGHTJUSTIFIED:
1450 topleftX -= gfxPtr->Width;
1451 break;
1452 case AVPMENUFORMAT_CENTREJUSTIFIED:
1453 topleftX -= gfxPtr->Width/2;
1454 break;
1455 }
1456
1457 srcPtr = (unsigned char *)image->buf;
1458 length = gfxPtr->Width;
1459
1460 if (ScreenDescriptorBlock.SDB_Width - topleftX < length) {
1461 length = ScreenDescriptorBlock.SDB_Width - topleftX;
1462 }
1463 if (length <= 0) return;
1464
1465 if (SDL_MUSTLOCK(surface)) {
1466 if (SDL_LockSurface(surface) < 0) {
1467 return; /* ... */
1468 }
1469 }
1470
1471 if (alpha > ONE_FIXED) {
1472 int x, y;
1473
1474 for (y=topleftY; y<gfxPtr->Height+topleftY; y++) {
1475 destPtr = ((unsigned short *)(((unsigned char *)surface->pixels) + y*surface->pitch)) + topleftX;
1476
1477 if(y>=topY && y<=bottomY) {
1478 for (x=0; x<length; x++) {
1479 *destPtr = ((srcPtr[0]>>3)<<11) |
1480 ((srcPtr[1]>>2)<<5 ) |
1481 ((srcPtr[2]>>3));
1482 srcPtr += 4;
1483 destPtr++;
1484 }
1485 srcPtr += (image->w - length) * 4;
1486 } else {
1487 srcPtr += image->w * 4;
1488 }
1489 }
1490 } else {
1491 int x, y;
1492
1493 for (y=topleftY; y<gfxPtr->Height+topleftY; y++) {
1494 destPtr = ((unsigned short *)(((unsigned char *)surface->pixels) + y*surface->pitch)) + topleftX;
1495
1496 if(y>=topY && y<=bottomY) {
1497 for (x=0; x<length; x++) {
1498 if (srcPtr[0] || srcPtr[1] || srcPtr[2]) {
1499 unsigned int destR, destG, destB;
1500
1501 destR = (*destPtr & 0xF800)>>8;
1502 destG = (*destPtr & 0x07E0)>>3;
1503 destB = (*destPtr & 0x001F)<<3;
1504
1505 destR += MUL_FIXED(alpha, srcPtr[0]);
1506 destG += MUL_FIXED(alpha, srcPtr[1]);
1507 destB += MUL_FIXED(alpha, srcPtr[2]);
1508 if (destR > 0x00FF) destR = 0x00FF;
1509 if (destG > 0x00FF) destG = 0x00FF;
1510 if (destB > 0x00FF) destB = 0x00FF;
1511
1512 *destPtr = ((destR>>3)<<11) |
1513 ((destG>>2)<<5 ) |
1514 ((destB>>3));
1515 }
1516 srcPtr += 4;
1517 destPtr++;
1518 }
1519 srcPtr += (image->w - length) * 4;
1520 } else {
1521 srcPtr += image->w * 4;
1522 }
1523 }
1524 }
1525
1526 if (SDL_MUSTLOCK(surface)) {
1527 SDL_UnlockSurface(surface);
1528 }
1529 }
1530
HeightOfMenuGfx(enum AVPMENUGFX_ID menuGfxID)1531 int HeightOfMenuGfx(enum AVPMENUGFX_ID menuGfxID)
1532 {
1533 return AvPMenuGfxStorage[menuGfxID].Height;
1534 }
1535
FadedScreen(int alpha)1536 void FadedScreen(int alpha)
1537 {
1538 int x, y;
1539 unsigned short *ptr;
1540
1541 if (SDL_MUSTLOCK(surface)) {
1542 if (SDL_LockSurface(surface) < 0) {
1543 return; /* ... */
1544 }
1545 }
1546
1547 for (y = 60; y < surface->h-60; y++) {
1548 ptr = (unsigned short *)(((unsigned char *)surface->pixels)+y*surface->pitch);
1549 for (x = 0; x < surface->w; x++) {
1550 unsigned int srcR, srcG, srcB;
1551
1552 srcR = (*ptr & 0xF800) >> 11;
1553 srcG = (*ptr & 0x07E0) >> 5;
1554 srcB = (*ptr & 0x001F);
1555
1556 srcR = MUL_FIXED(srcR, alpha);
1557 srcG = MUL_FIXED(srcG, alpha);
1558 srcB = MUL_FIXED(srcB, alpha);
1559 *ptr = ((srcR>>3)<<11) |
1560 ((srcG>>2)<<5 ) |
1561 ((srcB>>3));
1562 ptr++;
1563 }
1564 }
1565
1566 if (SDL_MUSTLOCK(surface)) {
1567 SDL_UnlockSurface(surface);
1568 }
1569 }
1570
ClearScreenToBlack()1571 void ClearScreenToBlack()
1572 {
1573 int x, y;
1574 unsigned short *ptr;
1575
1576 if (SDL_MUSTLOCK(surface)) {
1577 if (SDL_LockSurface(surface) < 0) {
1578 return; /* ... */
1579 }
1580 }
1581
1582 for (y = 0; y < surface->h; y++) {
1583 ptr = (unsigned short *)(((unsigned char *)surface->pixels)+y*surface->pitch);
1584 for (x = 0; x < surface->w; x++) {
1585 *ptr = 0;
1586
1587 ptr++;
1588 }
1589 }
1590
1591 if (SDL_MUSTLOCK(surface)) {
1592 SDL_UnlockSurface(surface);
1593 }
1594 }
1595