home *** CD-ROM | disk | FTP | other *** search
/ Superpower (Alt) / SUPERPOWER.iso / q / source / keypairv.m < prev    next >
Encoding:
Text File  |  1996-08-08  |  1.4 KB  |  97 lines

  1.  
  2. #import "qedefs.h"
  3.  
  4. id    keypairview_i;
  5.  
  6. @implementation KeypairView
  7.  
  8. /*
  9. ==================
  10. initFrame:
  11. ==================
  12. */
  13. - initFrame:(const NXRect *)frameRect
  14. {
  15.     [super initFrame:frameRect];
  16.     keypairview_i = self;
  17.     return self;
  18. }
  19.  
  20.  
  21. - calcViewSize
  22. {
  23.     NXCoord    w;
  24.     NXCoord    h;
  25.     NXRect    b;
  26.     NXPoint    pt;
  27.     int        count;
  28.     id        ent;
  29.     
  30.     ent = [map_i currentEntity];
  31.     count = [ent numPairs];
  32.  
  33.     [superview setFlipped: YES];
  34.     
  35.     [superview getBounds:&b];
  36.     w = b.size.width;
  37.     h = LINEHEIGHT*count + SPACING;
  38.     [self    sizeTo:w :h];
  39.     pt.x = pt.y = 0;
  40.     [self scrollPoint: &pt];
  41.     return self;
  42. }
  43.  
  44. - drawSelf:(const NXRect *)rects :(int)rectCount
  45. {
  46.     epair_t    *pair;
  47.     int        y;
  48.     
  49.     PSsetgray(NXGrayComponent(NX_COLORLTGRAY));
  50.     PSrectfill(0,0,bounds.size.width,bounds.size.height);
  51.         
  52.     PSselectfont("Helvetica-Bold",FONTSIZE);
  53.     PSrotate(0);
  54.     PSsetgray(0);
  55.     
  56.     pair = [[map_i currentEntity] epairs];
  57.     y = bounds.size.height - LINEHEIGHT;
  58.     for ( ; pair ; pair=pair->next)
  59.     {
  60.         PSmoveto(SPACING, y);
  61.         PSshow(pair->key);
  62.         PSmoveto(100, y);
  63.         PSshow(pair->value);
  64.         y -= LINEHEIGHT;
  65.     }
  66.     PSstroke();
  67.     
  68.     return self;
  69. }
  70.  
  71. - mouseDown:(NXEvent *)theEvent
  72. {
  73.     NXPoint    loc;
  74.     int        i;
  75.     epair_t    *p;
  76.  
  77.     loc = theEvent->location;
  78.     [self convertPoint:&loc    fromView:NULL];
  79.     
  80.     i = (bounds.size.height - loc.y - 4) / LINEHEIGHT;
  81.  
  82.     p = [[map_i currentEntity] epairs];
  83.     while (    i )
  84.     {
  85.         p=p->next;
  86.         if (!p)
  87.             return self;
  88.         i--;
  89.     }
  90.     if (p)
  91.         [things_i setSelectedKey: p];
  92.     
  93.     return self;
  94. }
  95.  
  96. @end
  97.