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 / SleuthView.C < prev    next >
Text File  |  1992-02-27  |  5KB  |  177 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2.  
  3. //   Module      : SleuthView.C   Version 1.2
  4. //   LastSCCS    : 2/26/92  16:38:21
  5. //   LastEdit    : "Fri Oct 18 09:26:57 1991"
  6. //   Description : 
  7. //   Author      : 
  8. //   Copyright   : GMD Schloss Birlinghoven
  9.  
  10. SleuthView::
  11. SleuthView(SleuthDocument* doc)
  12. : GnView( doc )
  13. {
  14.     setR_width( TableWidth() + 2 * TableHorizontalOffset() );
  15.     setR_height( TableHeight() + 2 * TableVerticalOffset() );
  16.     setR_resizePolicy(XmRESIZE_NONE);
  17.     
  18.     document = doc;
  19. }
  20.  
  21. void SleuthView::
  22. draw(int, int, int, Dimension, Dimension)
  23. {
  24.     DrawEmptyTable();
  25. }
  26.  
  27. TableArea SleuthView::
  28. WhatsUnder(int x, int y, int &shape, int &color, int &value)
  29. {
  30.     if(x < TableX() || y < TableY() ||
  31.        x >= TableMaxX() || y >= TableMaxY())
  32.     return eTableNothing;
  33.  
  34.     if(x < CardShapeX(0)) {
  35.     if(y < CardColorColumnY(0)) {
  36.         return ePlayer;
  37.     } else {
  38.         color = (y - CardColorColumnY(0))/TableFieldHeight();
  39.         return eColorColumn;
  40.     }
  41.     } else {
  42.     if( y < CardColorColumnY(0) ) {
  43.         shape = (x - CardShapeX(0))/CardShapeWidth();
  44.         if( y < CardValueY() ) {
  45.         return eShapeRow;
  46.         } else {
  47.         value = ((x - CardShapeX(0)) % CardShapeWidth())
  48.             / TableFieldWidth();
  49.         return eValueRow;
  50.         }
  51.     } else {
  52.         x -= CardShapeX(0);
  53.         shape = x/CardShapeWidth();
  54.         color = (y - CardColorColumnY(0))/TableFieldHeight();
  55.         value = (x % CardShapeWidth())/TableFieldWidth();
  56.         return eField;
  57.     }
  58.     }
  59. }
  60.  
  61. void SleuthView::
  62. DrawFilledString(char *string, unsigned int length,
  63.          Pixel foreground_color, Pixel background_color,
  64.          int x, int y, Dimension width, Dimension height,
  65.          unsigned char alignment, Dimension offset)
  66. {
  67.     XSetForeground(get_display(), text_gc, background_color);
  68.     XSetBackground(get_display(), text_gc, foreground_color);
  69.     XFillRectangle(get_display(), x_window, text_gc, x, y, width, height);
  70.     
  71.     XSetForeground(get_display(), text_gc, foreground_color);
  72.     XSetBackground(get_display(), text_gc, background_color);
  73.     DrawStringAligned(text_gc, string, length, x, y, width, height,
  74.               alignment, offset);
  75. }
  76.  
  77. void SleuthView::
  78. DrawEmptyTable()
  79. {
  80.     //cout << "DrawEmptyTable " "\n";
  81.  
  82.     int i,j;
  83.  
  84.     XGCValues val;
  85.     val.foreground = foreground;
  86.     val.background = background;
  87.     val.line_width = TableLineWidth() == 1 ? 0 : TableLineWidth();
  88.     change_gc(&val, GCForeground | GCBackground | GCLineWidth );
  89.  
  90.     
  91.     // Horizontal lines
  92.     
  93.     draw_line(CardShapeX(0), CardShapeY(), TableMaxX(), CardShapeY());
  94.     draw_line(CardShapeX(0), CardValueY(), TableMaxX(), CardValueY());
  95.     for( i = 0; i < 5; i++ )
  96.     draw_line(CardColorColumnX(), FieldY( i), TableMaxX(), FieldY( i));
  97.     
  98.     // Vertical lines
  99.     
  100.     draw_line(CardColorColumnX(), CardColorColumnY(0),
  101.           CardColorColumnX(), TableMaxY());
  102.     
  103.     for( i = 0; i < 4; i++)
  104.     draw_line(CardShapeX(i), CardShapeY(), CardShapeX(i), TableMaxY());
  105.     
  106.     for( i = 0; i < 3; i++) {
  107.     draw_line(CardValueX(i, 1), CardValueY(),
  108.           CardValueX(i, 1), TableMaxY());
  109.     draw_line(CardValueX(i, 2), CardValueY(),
  110.           CardValueX(i, 2), TableMaxY());
  111.     }
  112.  
  113.     // Texts
  114.     
  115.     for( i = 0; i < 4; i++ )
  116.     DrawName(i);
  117.     
  118.     for( i = 0; i < 3; i++ ) {
  119.     DrawShape(i);
  120.     for( j = 0; j < 3; j++ )
  121.         DrawValue(i, j);
  122.     }
  123. }
  124.  
  125. void SleuthView::
  126. DrawName(int name, Boolean reverse)
  127. {
  128.     DrawFilledString(document->ColorName(name),
  129.              strlen(document->ColorName(name)),
  130.              reverse ? background : foreground,
  131.              reverse ? foreground : background,
  132.              InnerX(CardColorColumnX()),
  133.              InnerY(CardColorColumnY(name)),
  134.              InnerWidth(CardColorColumnWidth()),
  135.              InnerHeight(TableFieldHeight()),
  136.              XmALIGNMENT_BEGINNING,
  137.              StringLeftOffset());
  138. }
  139.     
  140. void SleuthView::
  141. DrawShape(int shape, Boolean reverse)
  142. {
  143.     DrawFilledString(document->ShapeName(shape),
  144.              strlen(document->ShapeName(shape)),
  145.              reverse ? background : foreground,
  146.              reverse ? foreground : background,
  147.              InnerX(CardShapeX(shape)),
  148.              InnerY(CardShapeY()),
  149.              InnerWidth(CardShapeWidth()),
  150.              InnerHeight(TableFieldHeight()));
  151. }
  152.     
  153. void SleuthView::
  154. DrawValue(int shape, int value, Boolean reverse)
  155. {
  156.     DrawFilledString(document->ValueName(value),
  157.              strlen(document->ValueName(value)),
  158.              reverse ? background : foreground,
  159.              reverse ? foreground : background,
  160.              InnerX(CardValueX(shape, value)),
  161.              InnerY(CardValueY()),
  162.              InnerWidth(TableFieldWidth()),
  163.              InnerHeight(TableFieldHeight()));
  164. }
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.