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