home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / xgalaga-2_0_tar.gz / xgalaga-2_0_tar / xgalaga-2.0 / libsprite / text.c < prev    next >
C/C++ Source or Header  |  1998-04-12  |  4KB  |  151 lines

  1. #include "allincludes.h"
  2.  
  3. /* W_ShadowText: draw text with a black shadow underneath.  Just calls
  4.    W_WriteText twice 
  5.  */
  6. void W_ShadowText(window, x, y, color, str, len, font)
  7.     W_Window window;
  8.     int     x, y, len;
  9.     W_Color color;
  10.     W_Font  font;
  11.     char   *str;
  12. {
  13.     W_FillArea(window, x, y, len * W_Textwidth, W_Textheight, DARK_GREY);
  14.     W_MaskText(window, x-1, y+1, W_Black, str, len, font);
  15.     W_MaskText(window, x, y, color, str, len, font);
  16. }
  17.  
  18. void
  19. W_WriteText(window, x, y, color, str, len, font)
  20.     W_Window window;
  21.     int     x, y, len;
  22.     W_Color color;
  23.     W_Font  font;
  24.     char   *str;
  25. {
  26.     struct window *win;
  27.     int     addr;
  28.  
  29.     if (!font)
  30.     font = W_RegularFont;
  31. #ifdef DEBUG
  32.     printf("Text for %d @ (%d, %d) in %d: [%s]\n", window, x, y, color, str);
  33. #endif
  34.     win = W_Void2Window(window);
  35.     switch (win->type) {
  36.     case WIN_GRAPH:
  37.     addr = fonts[fontNum(font)].baseline;
  38.     XDrawImageString(W_Display, win->drawable,
  39.       colortable[color].contexts[fontNum(font)], x, y + addr, str, len);
  40.     break;
  41.     case WIN_SCROLL:
  42.     if (y<0) {
  43.       XCopyArea(W_Display, win->drawable, win->drawable,
  44.             colortable[W_White].contexts[0], WIN_EDGE, MENU_PAD,
  45.             win->width * W_Textwidth, (win->height - 1) * W_Textheight,
  46.             WIN_EDGE, MENU_PAD+W_Textheight);
  47.       XClearArea(W_Display, win->window,
  48.              WIN_EDGE, MENU_PAD,
  49.              W_Textwidth * win->width,(unsigned) W_Textheight, False);
  50.       XDrawImageString(W_Display, win->drawable,
  51.                colortable[color].contexts[1],
  52.                WIN_EDGE, MENU_PAD + fonts[1].baseline,
  53.                str, len);
  54.     } else {
  55.       XCopyArea(W_Display, win->drawable, win->drawable,
  56.             colortable[W_White].contexts[0], WIN_EDGE, MENU_PAD + W_Textheight,
  57.             win->width * W_Textwidth, (win->height - 1) * W_Textheight,
  58.             WIN_EDGE, MENU_PAD);
  59.       XClearArea(W_Display, win->window,
  60.              WIN_EDGE,(int)(MENU_PAD+W_Textheight*(win->height-1)),
  61.              W_Textwidth * win->width, (unsigned)W_Textheight, False);
  62.       XDrawImageString(W_Display, win->drawable,
  63.                colortable[color].contexts[1],
  64.                WIN_EDGE, 
  65.                (int)(MENU_PAD + W_Textheight * (win->height-1)
  66.                         + fonts[1].baseline),
  67.                str, len);
  68.     }
  69.     AddToScrolling(win, color, str, len);
  70.     break;
  71.     case WIN_MENU:
  72.     changeMenuItem(win, y, color, str, len, font);
  73.     break;
  74.     default:
  75.     addr = fonts[fontNum(font)].baseline;
  76.     XDrawImageString(W_Display, win->drawable,
  77.              colortable[color].contexts[fontNum(font)],
  78.          x * W_Textwidth + WIN_EDGE, MENU_PAD + y * W_Textheight + addr,
  79.              str, len);
  80.     break;
  81.     }
  82. }
  83.  
  84. void
  85. W_MaskText(window, x, y, color, str, len, font)
  86.     W_Window window;
  87.     int     x, y, len;
  88.     W_Color color;
  89.     W_Font  font;
  90.     char   *str;
  91. {
  92.     struct window *win;
  93.     int     addr;
  94.  
  95.     addr = fonts[fontNum(font)].baseline;
  96. #ifdef DEBUG
  97.     printf("TextMask for %d @ (%d, %d) in %d: [%s]\n", window, x, y, color, str);
  98. #endif
  99.     win = W_Void2Window(window);
  100.     XDrawString(W_Display, win->drawable,
  101.       colortable[color].contexts[fontNum(font)], x, y + addr, str, len);
  102. }
  103.  
  104. /* same as W_MaskText above, except draws directly to the destination window
  105.    and not its drawable.  This bypasses buffering, if any. [BDyess] */
  106. void
  107. W_DirectMaskText(window, x, y, color, str, len, font)
  108.     W_Window window;
  109.     int     x, y, len;
  110.     W_Color color;
  111.     W_Font  font;
  112.     char   *str;
  113. {
  114.     struct window *win;
  115.     int     addr;
  116.  
  117.     addr = fonts[fontNum(font)].baseline;
  118. #ifdef DEBUG
  119.     printf("TextMask for %d @ (%d, %d) in %d: [%s]\n", window, x, y, color, str);
  120. #endif
  121.     win = W_Void2Window(window);
  122.     XDrawString(W_Display, win->window,
  123.       colortable[color].contexts[fontNum(font)], x, y + addr, str, len);
  124. }
  125.  
  126. /* find the width of a font */
  127. #if 1
  128. int
  129. W_StringWidth(string, font)
  130.     char    string[];
  131.     W_Font  font;
  132. {
  133.     int     x, y;
  134.  
  135.     y = strlen(string);
  136.     x = XTextWidth(fonts[fontNum(font)].fontstruct, string, y);
  137.     return (x);            /* just a guess ?? old never returned! WHS
  138.                    4/6/93 */
  139. }
  140. #endif /*0*/
  141.  
  142. void
  143. W_ResizeText(window, neww, newh)/* TSH 2/93 */
  144.     W_Window window;
  145.     int     neww, newh;
  146. {
  147.     W_ResizeWindow(window, neww * W_Textwidth + WIN_EDGE * 2,
  148.            newh * W_Textheight + MENU_PAD * 2);
  149. }
  150.  
  151.