home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume9 / othello2 / part03 / items.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-27  |  4.6 KB  |  174 lines

  1. /*LINTLIBRARY*/
  2.  
  3. /*  @(#)items.c 1.4 90/04/05
  4.  *
  5.  *  Procedures for manipulating the othello game panel items.
  6.  *
  7.  *  Original SunView version by Ed Falk - Sun Microsystems Inc.
  8.  *
  9.  *  Rewritten for independent use by
  10.  *          Rich Burridge, Sun Microsystems, Australia
  11.  *
  12.  *  Copyright (c) Ed Falk & Rich Burridge - Sun Microsystems.
  13.  *                                          All rights reserved.
  14.  *
  15.  *  Permission is given to distribute these sources, as long as the
  16.  *  introductory messages are not removed, and no monies are exchanged.
  17.  *
  18.  *  No responsibility is taken for any errors on inaccuracies inherent
  19.  *  either to the comments or the code of this program, but if reported
  20.  *  to me, then an attempt will be made to fix them.
  21.  */
  22.  
  23. #include "color.h"
  24. #include "othello.h"
  25. #include "extern.h"
  26.  
  27.  
  28. draw_button(item, color, image)      /* Draw a panel button. */
  29. enum panel_type item ;
  30. int color ;
  31. enum image_type image ;
  32. {
  33.   char *label ;
  34.   int x, y ;
  35.  
  36.   x = items[(int) item].x ;
  37.   y = items[(int) item].y ;
  38.   if (iscolor)
  39.     {
  40.       draw_stencil(x, y, BWIDTH, BHEIGHT, RSRC, color,
  41.                    BUT_STENCIL, BUT_STENCIL) ;
  42.       draw_image(x, y, BWIDTH, BHEIGHT, image) ;
  43.     }
  44.   else draw_stencil(x, y, BWIDTH, BHEIGHT, RSRC, C_WHITE, BUT_STENCIL, image) ;
  45.   label = items[(int) item].text ;
  46.   if (image == BUT_INVERT) color = C_WHITE ;
  47.   else                   color = C_BLACK ;
  48.   x += ((BWIDTH - get_strwidth(NFONT, label)) / 2) ;
  49.   y += (nfont_height + (BHEIGHT - nfont_height) / 2) - 5 ;
  50.   draw_text(x, y, NFONT, color, label) ;
  51. }
  52.  
  53.  
  54. draw_cycle(item, color, image)
  55. enum panel_type item ;
  56. int color ;
  57. enum image_type image ;
  58. {
  59.   int x, y ;
  60.  
  61.   x = items[(int) item].x + (3 * BWIDTH) + (2 * BGAP) - CWIDTH ;
  62.   y = items[(int) item].y ;
  63.   if (iscolor)
  64.     {
  65.       draw_stencil(x, y, CWIDTH, CHEIGHT, RSRC, color, CY_STENCIL, CY_STENCIL) ;
  66.       draw_image(x, y, CWIDTH, CHEIGHT, image) ;
  67.     }
  68.   else draw_stencil(x, y, CWIDTH, CHEIGHT, RSRC, C_WHITE, CY_STENCIL, image) ;
  69. }
  70.  
  71.  
  72. draw_cycle_item(item, choices, color, image)  /* Display cycle panel item. */
  73. enum panel_type item ;
  74. char *choices[] ;
  75. int color ;
  76. enum image_type image ;
  77. {
  78.   char *label ;
  79.   int n, x, y ;
  80.  
  81.   n = (int) item ;
  82.   label = items[n].text ;
  83.   x = items[n].x ;
  84.   y = items[n].y ;
  85.   draw_text(x, y + bfont_height, BFONT, C_BLACK, label) ;
  86.   set_cycle(item, choices[items[n].value]) ;
  87.   draw_cycle(item, color, image) ;
  88. }
  89.  
  90.  
  91. draw_piece(piece, x, y, op)    /* Draw an othello piece on the board. */
  92. int piece, x, y ;
  93. enum optype op ;
  94. {
  95.   switch (piece)
  96.     {
  97.       case BLACK : draw_stencil(x, y, PSIZE, PSIZE, op, C_BLACK,
  98.                                 P_BLACK, P_BLACK) ;
  99.                    break ;
  100.       case WHITE : draw_stencil(x, y, PSIZE, PSIZE, op, C_BLACK,
  101.                                 P_BLACK, P_WHITE) ;
  102.     }
  103. }
  104.  
  105.  
  106. make_message(item)         /* Display a message panel. */
  107. enum panel_type item ;
  108. {
  109.   char *message ;
  110.   int x, y ;
  111.  
  112.   message = items[(int) item].text ;
  113.   x = items[(int) item].x ;
  114.   y = items[(int) item].y ;
  115.   color = (iscolor) ? C_BEIGE : C_WHITE ;
  116.   color_area(x, y, TOTAL_WIDTH, 15, color) ;
  117.   draw_text(x, y+nfont_height, NFONT, C_BLACK, message) ;
  118. }
  119.  
  120.  
  121. make_panel()
  122. {
  123.   draw_button(DONE_BUT,     C_LGREY, BUT_NORMAL) ;
  124.   draw_button(LAST_BUT,     C_LGREY, BUT_NORMAL) ;
  125.   draw_button(NEW_GAME_BUT, C_LGREY, BUT_NORMAL) ;
  126.   draw_button(SUGGEST_BUT,  C_LGREY, BUT_NORMAL) ;
  127.   draw_button(UNDO_BUT,     C_LGREY, BUT_NORMAL) ;
  128.   draw_button(QUIT_BUT,     C_LGREY, BUT_NORMAL) ;
  129.  
  130.   draw_cycle_item(ASPIRATION,     asp_values,  C_LGREY, CY_NORMAL) ;
  131.   draw_cycle_item(DIFFICULTY,     diff_values, C_LGREY, CY_NORMAL) ;
  132.   draw_cycle_item(COMPUTER_PLAYS, comp_values, C_LGREY, CY_NORMAL) ;
  133.   draw_cycle_item(REMARK,         rem_values,  C_LGREY, CY_NORMAL) ;
  134.  
  135.   make_message(REMARK_MES) ;
  136.   make_message(PANEL_MES) ;
  137.   make_message(SCORE_MES) ;
  138. }
  139.  
  140.  
  141. message(mtype, str)
  142. enum panel_type mtype ;
  143. char *str ;
  144. {
  145.   int n ;
  146.  
  147.   n = (int) mtype ;
  148.   color = (iscolor) ? C_BEIGE : C_WHITE ;
  149.   color_area(items[n].x, items[n].y,
  150.              get_strwidth(NFONT, items[n].text), nfont_height + 5, color) ;
  151.   draw_text(items[n].x, items[n].y + nfont_height, NFONT, C_BLACK, str) ;
  152.   STRCPY(items[n].text, str) ;
  153. }
  154.  
  155.  
  156. set_cycle(mtype, str)
  157. enum panel_type mtype ;
  158. char *str ;
  159. {
  160.   int n, width, x ;
  161.  
  162.   n = (int) mtype ;
  163.   color = (iscolor) ? C_BEIGE : C_WHITE ;
  164.  
  165.   width = (3 * BWIDTH) + (2 * BGAP) -
  166.            get_strwidth(BFONT, items[n].text) - CWIDTH ;
  167.   x = items[n].x + get_strwidth(BFONT, items[n].text) ;
  168.   color_area(x, items[n].y, width, items[n].height, color) ;
  169.  
  170.   width = get_strwidth(NFONT, str) ;
  171.   x = items[n].x + (3 * BWIDTH) + (2 * BGAP) - CWIDTH - width ;
  172.   draw_text(x - 5, items[n].y + nfont_height, NFONT, C_BLACK, str) ;
  173. }
  174.