home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / g / gina15.zip / demos / sleuth / CardView.C < prev    next >
C/C++ Source or Header  |  1992-02-27  |  2KB  |  106 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2.  
  3. //   Module      : CardView.C   Version 1.2
  4. //   LastSCCS    : 2/26/92  16:37:51
  5. //   LastEdit    : "Thu Nov  7 16:34:55 1991"
  6. //   Description : 
  7. //   Author      : 
  8. //   Copyright   : GMD Schloss Birlinghoven
  9.  
  10. CardView::
  11. CardView(SleuthDocument* doc)
  12. : SleuthView( doc )
  13. {
  14. }
  15.  
  16. void CardView ::
  17. button_press(int , int , int x, int y)
  18. {
  19.     int f_color, f_shape, f_value;
  20.     
  21.     //cout << "You hit ";
  22.     switch( WhatsUnder(x, y, f_shape, f_color, f_value) ) {
  23.       case eTableNothing:
  24.     break;
  25.       case ePlayer:
  26.     //cout << "the player label";
  27.     break;
  28.       case eShapeRow:
  29.     //cout << "shape " << f_shape;
  30.     break;
  31.       case eValueRow:
  32.     //cout << "value " << f_value << " for shape " << f_shape;
  33.     break;
  34.       case eColorColumn:
  35.     //cout << "color " << f_color;
  36.     break;
  37.       case eField:
  38.     //cout << "field " << f_shape << " " << f_color << " " << f_value;
  39.     break;
  40.     }
  41. }
  42.  
  43. void CardView::
  44. draw(int, int, int, Dimension, Dimension)
  45. {
  46.     REQUIRE(DrawingIsPossible(), "Drawing into X Window is possible");
  47.  
  48.     Update();
  49. }
  50.  
  51. void CardView::
  52. UpdateCard(Card *card)
  53. {
  54.     REQUIRE(DrawingIsPossible(), "Drawing into X Window is possible");
  55.  
  56.     char *str = card->GetPlayer() != 0 ? card->GetPlayer()->GetName() : "";
  57.     
  58.     DrawFilledString(str, strlen(str),
  59.              foreground, background,
  60.              InnerX(FieldX(card->GetShape(), card->GetValue())),
  61.              InnerY(FieldY(card->GetColor())),
  62.              InnerWidth(TableFieldWidth()),
  63.              InnerHeight(TableFieldHeight()));
  64. }
  65.  
  66. void CardView::
  67. DrawGameName()
  68. {
  69.     REQUIRE(DrawingIsPossible(), "Drawing into X Window is possible");
  70.  
  71.     DrawFilledString(document->GetGameName(),
  72.              strlen(document->GetGameName()),
  73.              foreground, background,
  74.              InnerX(TableX()), InnerY(TableY()),
  75.              InnerWidth(CardColorColumnWidth()),
  76.              InnerHeight(2*TableFieldHeight()));
  77. }
  78.  
  79. void CardView::
  80. Update()
  81. {
  82.     REQUIRE(DrawingIsPossible(), "Drawing into X Window is possible");
  83.     
  84.     int i, j, k;
  85.  
  86.     DrawEmptyTable();
  87.     DrawGameName();
  88.     for( i = 0; i < 3; i++)
  89.     for( j = 0; j < 4; j++)
  90.         for( k = 0; k < 3; k++)
  91.         UpdateCard(document->GetCard(i, j, k));
  92. }
  93.  
  94. void CardView::
  95. UpdateGameName()
  96. {
  97.     if( DrawingIsPossible() )
  98.     DrawGameName();
  99. }
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.