home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2000 March / maximum-cd-2000-03.iso / Quake3 Game Source / Q3AGameSource.exe / Main / cg_drawtools.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-18  |  15.8 KB  |  765 lines

  1. // Copyright (C) 1999-2000 Id Software, Inc.
  2. //
  3. // cg_drawtools.c -- helper functions called by cg_draw, cg_scoreboard, cg_info, etc
  4. #include "cg_local.h"
  5.  
  6. /*
  7. ================
  8. CG_AdjustFrom640
  9.  
  10. Adjusted for resolution and screen aspect ratio
  11. ================
  12. */
  13. void CG_AdjustFrom640( float *x, float *y, float *w, float *h ) {
  14. #if 0
  15.     // adjust for wide screens
  16.     if ( cgs.glconfig.vidWidth * 480 > cgs.glconfig.vidHeight * 640 ) {
  17.         *x += 0.5 * ( cgs.glconfig.vidWidth - ( cgs.glconfig.vidHeight * 640 / 480 ) );
  18.     }
  19. #endif
  20.     // scale for screen sizes
  21.     *x *= cgs.screenXScale;
  22.     *y *= cgs.screenYScale;
  23.     *w *= cgs.screenXScale;
  24.     *h *= cgs.screenYScale;
  25. }
  26.  
  27. /*
  28. ================
  29. CG_FillRect
  30.  
  31. Coordinates are 640*480 virtual values
  32. =================
  33. */
  34. void CG_FillRect( float x, float y, float width, float height, const float *color ) {
  35.     trap_R_SetColor( color );
  36.  
  37.     CG_AdjustFrom640( &x, &y, &width, &height );
  38.     trap_R_DrawStretchPic( x, y, width, height, 0, 0, 0, 0, cgs.media.whiteShader );
  39.  
  40.     trap_R_SetColor( NULL );
  41. }
  42.  
  43.  
  44.  
  45. /*
  46. ================
  47. CG_DrawPic
  48.  
  49. Coordinates are 640*480 virtual values
  50. =================
  51. */
  52. void CG_DrawPic( float x, float y, float width, float height, qhandle_t hShader ) {
  53.     CG_AdjustFrom640( &x, &y, &width, &height );
  54.     trap_R_DrawStretchPic( x, y, width, height, 0, 0, 1, 1, hShader );
  55. }
  56.  
  57.  
  58.  
  59. /*
  60. ===============
  61. CG_DrawChar
  62.  
  63. Coordinates and size in 640*480 virtual screen size
  64. ===============
  65. */
  66. void CG_DrawChar( int x, int y, int width, int height, int ch ) {
  67.     int row, col;
  68.     float frow, fcol;
  69.     float size;
  70.     float    ax, ay, aw, ah;
  71.  
  72.     ch &= 255;
  73.  
  74.     if ( ch == ' ' ) {
  75.         return;
  76.     }
  77.  
  78.     ax = x;
  79.     ay = y;
  80.     aw = width;
  81.     ah = height;
  82.     CG_AdjustFrom640( &ax, &ay, &aw, &ah );
  83.  
  84.     row = ch>>4;
  85.     col = ch&15;
  86.  
  87.     frow = row*0.0625;
  88.     fcol = col*0.0625;
  89.     size = 0.0625;
  90.  
  91.     trap_R_DrawStretchPic( ax, ay, aw, ah,
  92.                        fcol, frow, 
  93.                        fcol + size, frow + size, 
  94.                        cgs.media.charsetShader );
  95. }
  96.  
  97.  
  98. /*
  99. ==================
  100. CG_DrawStringExt
  101.  
  102. Draws a multi-colored string with a drop shadow, optionally forcing
  103. to a fixed color.
  104.  
  105. Coordinates are at 640 by 480 virtual resolution
  106. ==================
  107. */
  108. void CG_DrawStringExt( int x, int y, const char *string, const float *setColor, 
  109.         qboolean forceColor, qboolean shadow, int charWidth, int charHeight, int maxChars ) {
  110.     vec4_t        color;
  111.     const char    *s;
  112.     int            xx;
  113.     int            cnt;
  114.  
  115.     if (maxChars <= 0)
  116.         maxChars = 32767; // do them all!
  117.  
  118.     // draw the drop shadow
  119.     if (shadow) {
  120.         color[0] = color[1] = color[2] = 0;
  121.         color[3] = setColor[3];
  122.         trap_R_SetColor( color );
  123.         s = string;
  124.         xx = x;
  125.         cnt = 0;
  126.         while ( *s && cnt < maxChars) {
  127.             if ( Q_IsColorString( s ) ) {
  128.                 s += 2;
  129.                 continue;
  130.             }
  131.             CG_DrawChar( xx + 2, y + 2, charWidth, charHeight, *s );
  132.             cnt++;
  133.             xx += charWidth;
  134.             s++;
  135.         }
  136.     }
  137.  
  138.     // draw the colored text
  139.     s = string;
  140.     xx = x;
  141.     cnt = 0;
  142.     trap_R_SetColor( setColor );
  143.     while ( *s && cnt < maxChars) {
  144.         if ( Q_IsColorString( s ) ) {
  145.             if ( !forceColor ) {
  146.                 memcpy( color, g_color_table[ColorIndex(*(s+1))], sizeof( color ) );
  147.                 color[3] = setColor[3];
  148.                 trap_R_SetColor( color );
  149.             }
  150.             s += 2;
  151.             continue;
  152.         }
  153.         CG_DrawChar( xx, y, charWidth, charHeight, *s );
  154.         xx += charWidth;
  155.         cnt++;
  156.         s++;
  157.     }
  158.     trap_R_SetColor( NULL );
  159. }
  160.  
  161. void CG_DrawBigString( int x, int y, const char *s, float alpha ) {
  162.     float    color[4];
  163.  
  164.     color[0] = color[1] = color[2] = 1.0;
  165.     color[3] = alpha;
  166.     CG_DrawStringExt( x, y, s, color, qfalse, qtrue, BIGCHAR_WIDTH, BIGCHAR_HEIGHT, 0 );
  167. }
  168.  
  169. void CG_DrawBigStringColor( int x, int y, const char *s, vec4_t color ) {
  170.     CG_DrawStringExt( x, y, s, color, qtrue, qtrue, BIGCHAR_WIDTH, BIGCHAR_HEIGHT, 0 );
  171. }
  172.  
  173. void CG_DrawSmallString( int x, int y, const char *s, float alpha ) {
  174.     float    color[4];
  175.  
  176.     color[0] = color[1] = color[2] = 1.0;
  177.     color[3] = alpha;
  178.     CG_DrawStringExt( x, y, s, color, qfalse, qfalse, SMALLCHAR_WIDTH, SMALLCHAR_HEIGHT, 0 );
  179. }
  180.  
  181. void CG_DrawSmallStringColor( int x, int y, const char *s, vec4_t color ) {
  182.     CG_DrawStringExt( x, y, s, color, qtrue, qfalse, SMALLCHAR_WIDTH, SMALLCHAR_HEIGHT, 0 );
  183. }
  184.  
  185. /*
  186. =================
  187. CG_DrawStrlen
  188.  
  189. Returns character count, skiping color escape codes
  190. =================
  191. */
  192. int CG_DrawStrlen( const char *str ) {
  193.     const char *s = str;
  194.     int count = 0;
  195.  
  196.     while ( *s ) {
  197.         if ( Q_IsColorString( s ) ) {
  198.             s += 2;
  199.         } else {
  200.             count++;
  201.             s++;
  202.         }
  203.     }
  204.  
  205.     return count;
  206. }
  207.  
  208. /*
  209. =============
  210. CG_TileClearBox
  211.  
  212. This repeats a 64*64 tile graphic to fill the screen around a sized down
  213. refresh window.
  214. =============
  215. */
  216. static void CG_TileClearBox( int x, int y, int w, int h, qhandle_t hShader ) {
  217.     float    s1, t1, s2, t2;
  218.  
  219.     s1 = x/64.0;
  220.     t1 = y/64.0;
  221.     s2 = (x+w)/64.0;
  222.     t2 = (y+h)/64.0;
  223.     trap_R_DrawStretchPic( x, y, w, h, s1, t1, s2, t2, hShader );
  224. }
  225.  
  226.  
  227.  
  228. /*
  229. ==============
  230. CG_TileClear
  231.  
  232. Clear around a sized down screen
  233. ==============
  234. */
  235. void CG_TileClear( void ) {
  236.     int        top, bottom, left, right;
  237.     int        w, h;
  238.  
  239.     w = cgs.glconfig.vidWidth;
  240.     h = cgs.glconfig.vidHeight;
  241.  
  242.     if ( cg.refdef.x == 0 && cg.refdef.y == 0 && 
  243.         cg.refdef.width == w && cg.refdef.height == h ) {
  244.         return;        // full screen rendering
  245.     }
  246.  
  247.     top = cg.refdef.y;
  248.     bottom = top + cg.refdef.height-1;
  249.     left = cg.refdef.x;
  250.     right = left + cg.refdef.width-1;
  251.  
  252.     // clear above view screen
  253.     CG_TileClearBox( 0, 0, w, top, cgs.media.backTileShader );
  254.  
  255.     // clear below view screen
  256.     CG_TileClearBox( 0, bottom, w, h - bottom, cgs.media.backTileShader );
  257.  
  258.     // clear left of view screen
  259.     CG_TileClearBox( 0, top, left, bottom - top + 1, cgs.media.backTileShader );
  260.  
  261.     // clear right of view screen
  262.     CG_TileClearBox( right, top, w - right, bottom - top + 1, cgs.media.backTileShader );
  263. }
  264.  
  265.  
  266.  
  267. /*
  268. ================
  269. CG_FadeColor
  270. ================
  271. */
  272. float *CG_FadeColor( int startMsec, int totalMsec ) {
  273.     static vec4_t        color;
  274.     int            t;
  275.  
  276.     if ( startMsec == 0 ) {
  277.         return NULL;
  278.     }
  279.  
  280.     t = cg.time - startMsec;
  281.  
  282.     if ( t >= totalMsec ) {
  283.         return NULL;
  284.     }
  285.  
  286.     // fade out
  287.     if ( totalMsec - t < FADE_TIME ) {
  288.         color[3] = ( totalMsec - t ) * 1.0/FADE_TIME;
  289.     } else {
  290.         color[3] = 1.0;
  291.     }
  292.     color[0] = color[1] = color[2] = 1;
  293.  
  294.     return color;
  295. }
  296.  
  297.  
  298. /*
  299. ================
  300. CG_TeamColor
  301. ================
  302. */
  303. float *CG_TeamColor( int team ) {
  304.     static vec4_t    red = {1, 0.2, 0.2, 1};
  305.     static vec4_t    blue = {0.2, 0.2, 1, 1};
  306.     static vec4_t    other = {1, 1, 1, 1};
  307.     static vec4_t    spectator = {0.7, 0.7, 0.7, 1};
  308.  
  309.     switch ( team ) {
  310.     case TEAM_RED:
  311.         return red;
  312.     case TEAM_BLUE:
  313.         return blue;
  314.     case TEAM_SPECTATOR:
  315.         return spectator;
  316.     default:
  317.         return other;
  318.     }
  319. }
  320.  
  321.  
  322.  
  323. /*
  324. =================
  325. CG_GetColorForHealth
  326. =================
  327. */
  328. void CG_GetColorForHealth( int health, int armor, vec4_t hcolor ) {
  329.     int        count;
  330.     int        max;
  331.  
  332.     // calculate the total points of damage that can
  333.     // be sustained at the current health / armor level
  334.     if ( health <= 0 ) {
  335.         VectorClear( hcolor );    // black
  336.         hcolor[3] = 1;
  337.         return;
  338.     }
  339.     count = armor;
  340.     max = health * ARMOR_PROTECTION / ( 1.0 - ARMOR_PROTECTION );
  341.     if ( max < count ) {
  342.         count = max;
  343.     }
  344.     health += count;
  345.  
  346.     // set the color based on health
  347.     hcolor[0] = 1.0;
  348.     hcolor[3] = 1.0;
  349.     if ( health >= 100 ) {
  350.         hcolor[2] = 1.0;
  351.     } else if ( health < 66 ) {
  352.         hcolor[2] = 0;
  353.     } else {
  354.         hcolor[2] = ( health - 66 ) / 33.0;
  355.     }
  356.  
  357.     if ( health > 60 ) {
  358.         hcolor[1] = 1.0;
  359.     } else if ( health < 30 ) {
  360.         hcolor[1] = 0;
  361.     } else {
  362.         hcolor[1] = ( health - 30 ) / 30.0;
  363.     }
  364. }
  365.  
  366. /*
  367. =================
  368. CG_ColorForHealth
  369. =================
  370. */
  371. void CG_ColorForHealth( vec4_t hcolor ) {
  372.  
  373.     CG_GetColorForHealth( cg.snap->ps.stats[STAT_HEALTH], 
  374.         cg.snap->ps.stats[STAT_ARMOR], hcolor );
  375. }
  376.  
  377.  
  378.  
  379.  
  380. /*
  381. =================
  382. UI_DrawProportionalString2
  383. =================
  384. */
  385. static int    propMap[128][3] = {
  386. {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1},
  387. {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1},
  388.  
  389. {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1},
  390. {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1},
  391.  
  392. {0, 0, PROP_SPACE_WIDTH},        // SPACE
  393. {11, 122, 7},    // !
  394. {154, 181, 14},    // "
  395. {55, 122, 17},    // #
  396. {79, 122, 18},    // $
  397. {101, 122, 23},    // %
  398. {153, 122, 18},    // &
  399. {9, 93, 7},        // '
  400. {207, 122, 8},    // (
  401. {230, 122, 9},    // )
  402. {177, 122, 18},    // *
  403. {30, 152, 18},    // +
  404. {85, 181, 7},    // ,
  405. {34, 93, 11},    // -
  406. {110, 181, 6},    // .
  407. {130, 152, 14},    // /
  408.  
  409. {22, 64, 17},    // 0
  410. {41, 64, 12},    // 1
  411. {58, 64, 17},    // 2
  412. {78, 64, 18},    // 3
  413. {98, 64, 19},    // 4
  414. {120, 64, 18},    // 5
  415. {141, 64, 18},    // 6
  416. {204, 64, 16},    // 7
  417. {162, 64, 17},    // 8
  418. {182, 64, 18},    // 9
  419. {59, 181, 7},    // :
  420. {35,181, 7},    // ;
  421. {203, 152, 14},    // <
  422. {56, 93, 14},    // =
  423. {228, 152, 14},    // >
  424. {177, 181, 18},    // ?
  425.  
  426. {28, 122, 22},    // @
  427. {5, 4, 18},        // A
  428. {27, 4, 18},    // B
  429. {48, 4, 18},    // C
  430. {69, 4, 17},    // D
  431. {90, 4, 13},    // E
  432. {106, 4, 13},    // F
  433. {121, 4, 18},    // G
  434. {143, 4, 17},    // H
  435. {164, 4, 8},    // I
  436. {175, 4, 16},    // J
  437. {195, 4, 18},    // K
  438. {216, 4, 12},    // L
  439. {230, 4, 23},    // M
  440. {6, 34, 18},    // N
  441. {27, 34, 18},    // O
  442.  
  443. {48, 34, 18},    // P
  444. {68, 34, 18},    // Q
  445. {90, 34, 17},    // R
  446. {110, 34, 18},    // S
  447. {130, 34, 14},    // T
  448. {146, 34, 18},    // U
  449. {166, 34, 19},    // V
  450. {185, 34, 29},    // W
  451. {215, 34, 18},    // X
  452. {234, 34, 18},    // Y
  453. {5, 64, 14},    // Z
  454. {60, 152, 7},    // [
  455. {106, 151, 13},    // '\'
  456. {83, 152, 7},    // ]
  457. {128, 122, 17},    // ^
  458. {4, 152, 21},    // _
  459.  
  460. {134, 181, 5},    // '
  461. {5, 4, 18},        // A
  462. {27, 4, 18},    // B
  463. {48, 4, 18},    // C
  464. {69, 4, 17},    // D
  465. {90, 4, 13},    // E
  466. {106, 4, 13},    // F
  467. {121, 4, 18},    // G
  468. {143, 4, 17},    // H
  469. {164, 4, 8},    // I
  470. {175, 4, 16},    // J
  471. {195, 4, 18},    // K
  472. {216, 4, 12},    // L
  473. {230, 4, 23},    // M
  474. {6, 34, 18},    // N
  475. {27, 34, 18},    // O
  476.  
  477. {48, 34, 18},    // P
  478. {68, 34, 18},    // Q
  479. {90, 34, 17},    // R
  480. {110, 34, 18},    // S
  481. {130, 34, 14},    // T
  482. {146, 34, 18},    // U
  483. {166, 34, 19},    // V
  484. {185, 34, 29},    // W
  485. {215, 34, 18},    // X
  486. {234, 34, 18},    // Y
  487. {5, 64, 14},    // Z
  488. {153, 152, 13},    // {
  489. {11, 181, 5},    // |
  490. {180, 152, 13},    // }
  491. {79, 93, 17},    // ~
  492. {0, 0, -1}        // DEL
  493. };
  494.  
  495. static int propMapB[26][3] = {
  496. {11, 12, 33},
  497. {49, 12, 31},
  498. {85, 12, 31},
  499. {120, 12, 30},
  500. {156, 12, 21},
  501. {183, 12, 21},
  502. {207, 12, 32},
  503.  
  504. {13, 55, 30},
  505. {49, 55, 13},
  506. {66, 55, 29},
  507. {101, 55, 31},
  508. {135, 55, 21},
  509. {158, 55, 40},
  510. {204, 55, 32},
  511.  
  512. {12, 97, 31},
  513. {48, 97, 31},
  514. {82, 97, 30},
  515. {118, 97, 30},
  516. {153, 97, 30},
  517. {185, 97, 25},
  518. {213, 97, 30},
  519.  
  520. {11, 139, 32},
  521. {42, 139, 51},
  522. {93, 139, 32},
  523. {126, 139, 31},
  524. {158, 139, 25},
  525. };
  526.  
  527. #define PROPB_GAP_WIDTH        4
  528. #define PROPB_SPACE_WIDTH    12
  529. #define PROPB_HEIGHT        36
  530.  
  531. /*
  532. =================
  533. UI_DrawBannerString
  534. =================
  535. */
  536. static void UI_DrawBannerString2( int x, int y, const char* str, vec4_t color )
  537. {
  538.     const char* s;
  539.     char    ch;
  540.     float    ax;
  541.     float    ay;
  542.     float    aw;
  543.     float    ah;
  544.     float    frow;
  545.     float    fcol;
  546.     float    fwidth;
  547.     float    fheight;
  548.  
  549.     // draw the colored text
  550.     trap_R_SetColor( color );
  551.     
  552.     ax = x * cgs.screenXScale + cgs.screenXBias;
  553.     ay = y * cgs.screenXScale;
  554.  
  555.     s = str;
  556.     while ( *s )
  557.     {
  558.         ch = *s & 127;
  559.         if ( ch == ' ' ) {
  560.             ax += ((float)PROPB_SPACE_WIDTH + (float)PROPB_GAP_WIDTH)* cgs.screenXScale;
  561.         }
  562.         else if ( ch >= 'A' && ch <= 'Z' ) {
  563.             ch -= 'A';
  564.             fcol = (float)propMapB[ch][0] / 256.0f;
  565.             frow = (float)propMapB[ch][1] / 256.0f;
  566.             fwidth = (float)propMapB[ch][2] / 256.0f;
  567.             fheight = (float)PROPB_HEIGHT / 256.0f;
  568.             aw = (float)propMapB[ch][2] * cgs.screenXScale;
  569.             ah = (float)PROPB_HEIGHT * cgs.screenXScale;
  570.             trap_R_DrawStretchPic( ax, ay, aw, ah, fcol, frow, fcol+fwidth, frow+fheight, cgs.media.charsetPropB );
  571.             ax += (aw + (float)PROPB_GAP_WIDTH * cgs.screenXScale);
  572.         }
  573.         s++;
  574.     }
  575.  
  576.     trap_R_SetColor( NULL );
  577. }
  578.  
  579. void UI_DrawBannerString( int x, int y, const char* str, int style, vec4_t color ) {
  580.     const char *    s;
  581.     int                ch;
  582.     int                width;
  583.     vec4_t            drawcolor;
  584.  
  585.     // find the width of the drawn text
  586.     s = str;
  587.     width = 0;
  588.     while ( *s ) {
  589.         ch = *s;
  590.         if ( ch == ' ' ) {
  591.             width += PROPB_SPACE_WIDTH;
  592.         }
  593.         else if ( ch >= 'A' && ch <= 'Z' ) {
  594.             width += propMapB[ch - 'A'][2] + PROPB_GAP_WIDTH;
  595.         }
  596.         s++;
  597.     }
  598.     width -= PROPB_GAP_WIDTH;
  599.  
  600.     switch( style & UI_FORMATMASK ) {
  601.         case UI_CENTER:
  602.             x -= width / 2;
  603.             break;
  604.  
  605.         case UI_RIGHT:
  606.             x -= width;
  607.             break;
  608.  
  609.         case UI_LEFT:
  610.         default:
  611.             break;
  612.     }
  613.  
  614.     if ( style & UI_DROPSHADOW ) {
  615.         drawcolor[0] = drawcolor[1] = drawcolor[2] = 0;
  616.         drawcolor[3] = color[3];
  617.         UI_DrawBannerString2( x+2, y+2, str, drawcolor );
  618.     }
  619.  
  620.     UI_DrawBannerString2( x, y, str, color );
  621. }
  622.  
  623.  
  624. int UI_ProportionalStringWidth( const char* str ) {
  625.     const char *    s;
  626.     int                ch;
  627.     int                charWidth;
  628.     int                width;
  629.  
  630.     s = str;
  631.     width = 0;
  632.     while ( *s ) {
  633.         ch = *s & 127;
  634.         charWidth = propMap[ch][2];
  635.         if ( charWidth != -1 ) {
  636.             width += charWidth;
  637.             width += PROP_GAP_WIDTH;
  638.         }
  639.         s++;
  640.     }
  641.  
  642.     width -= PROP_GAP_WIDTH;
  643.     return width;
  644. }
  645.  
  646. static void UI_DrawProportionalString2( int x, int y, const char* str, vec4_t color, float sizeScale, qhandle_t charset )
  647. {
  648.     const char* s;
  649.     char    ch;
  650.     float    ax;
  651.     float    ay;
  652.     float    aw;
  653.     float    ah;
  654.     float    frow;
  655.     float    fcol;
  656.     float    fwidth;
  657.     float    fheight;
  658.  
  659.     // draw the colored text
  660.     trap_R_SetColor( color );
  661.     
  662.     ax = x * cgs.screenXScale + cgs.screenXBias;
  663.     ay = y * cgs.screenXScale;
  664.  
  665.     s = str;
  666.     while ( *s )
  667.     {
  668.         ch = *s & 127;
  669.         if ( ch == ' ' ) {
  670.             aw = (float)PROP_SPACE_WIDTH * cgs.screenXScale * sizeScale;
  671.         } else if ( propMap[ch][2] != -1 ) {
  672.             fcol = (float)propMap[ch][0] / 256.0f;
  673.             frow = (float)propMap[ch][1] / 256.0f;
  674.             fwidth = (float)propMap[ch][2] / 256.0f;
  675.             fheight = (float)PROP_HEIGHT / 256.0f;
  676.             aw = (float)propMap[ch][2] * cgs.screenXScale * sizeScale;
  677.             ah = (float)PROP_HEIGHT * cgs.screenXScale * sizeScale;
  678.             trap_R_DrawStretchPic( ax, ay, aw, ah, fcol, frow, fcol+fwidth, frow+fheight, charset );
  679.         } else {
  680.             aw = 0;
  681.         }
  682.  
  683.         ax += (aw + (float)PROP_GAP_WIDTH * cgs.screenXScale * sizeScale);
  684.         s++;
  685.     }
  686.  
  687.     trap_R_SetColor( NULL );
  688. }
  689.  
  690. /*
  691. =================
  692. UI_ProportionalSizeScale
  693. =================
  694. */
  695. float UI_ProportionalSizeScale( int style ) {
  696.     if(  style & UI_SMALLFONT ) {
  697.         return 0.75;
  698.     }
  699.  
  700.     return 1.00;
  701. }
  702.  
  703.  
  704. /*
  705. =================
  706. UI_DrawProportionalString
  707. =================
  708. */
  709. void UI_DrawProportionalString( int x, int y, const char* str, int style, vec4_t color ) {
  710.     vec4_t    drawcolor;
  711.     int        width;
  712.     float    sizeScale;
  713.  
  714.     sizeScale = UI_ProportionalSizeScale( style );
  715.  
  716.     switch( style & UI_FORMATMASK ) {
  717.         case UI_CENTER:
  718.             width = UI_ProportionalStringWidth( str ) * sizeScale;
  719.             x -= width / 2;
  720.             break;
  721.  
  722.         case UI_RIGHT:
  723.             width = UI_ProportionalStringWidth( str ) * sizeScale;
  724.             x -= width;
  725.             break;
  726.  
  727.         case UI_LEFT:
  728.         default:
  729.             break;
  730.     }
  731.  
  732.     if ( style & UI_DROPSHADOW ) {
  733.         drawcolor[0] = drawcolor[1] = drawcolor[2] = 0;
  734.         drawcolor[3] = color[3];
  735.         UI_DrawProportionalString2( x+2, y+2, str, drawcolor, sizeScale, cgs.media.charsetProp );
  736.     }
  737.  
  738.     if ( style & UI_INVERSE ) {
  739.         drawcolor[0] = color[0] * 0.8;
  740.         drawcolor[1] = color[1] * 0.8;
  741.         drawcolor[2] = color[2] * 0.8;
  742.         drawcolor[3] = color[3];
  743.         UI_DrawProportionalString2( x, y, str, drawcolor, sizeScale, cgs.media.charsetProp );
  744.         return;
  745.     }
  746.  
  747.     if ( style & UI_PULSE ) {
  748.         drawcolor[0] = color[0] * 0.8;
  749.         drawcolor[1] = color[1] * 0.8;
  750.         drawcolor[2] = color[2] * 0.8;
  751.         drawcolor[3] = color[3];
  752.         UI_DrawProportionalString2( x, y, str, color, sizeScale, cgs.media.charsetProp );
  753.  
  754.         drawcolor[0] = color[0];
  755.         drawcolor[1] = color[1];
  756.         drawcolor[2] = color[2];
  757.         drawcolor[3] = 0.5 + 0.5 * sin( cg.time / PULSE_DIVISOR );
  758.         UI_DrawProportionalString2( x, y, str, drawcolor, sizeScale, cgs.media.charsetPropGlow );
  759.         return;
  760.     }
  761.  
  762.     UI_DrawProportionalString2( x, y, str, color, sizeScale, cgs.media.charsetProp );
  763. }
  764.  
  765.