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

  1.  
  2. #import "qedefs.h"
  3.  
  4. /*
  5.  
  6. NOTE: I am specifically not using cached image reps, because the data is also needed for texturing the views, and a cached rep would waste tons of space.
  7.  
  8. */
  9.  
  10. @implementation TextureView
  11.  
  12. - init
  13. {
  14.     deselectIndex = -1;
  15.     return self;
  16. }
  17.  
  18. - setParent:(id)from
  19. {
  20.     parent_i = from;
  21.     return self;
  22. }
  23.  
  24. - (BOOL)acceptsFirstMouse
  25. {
  26.     return YES;
  27. }
  28.  
  29. - drawSelf:(const NXRect *)rects :(int)rectCount
  30. {
  31.     int        i;
  32.     int        max;
  33.     id        list_i;
  34.     texpal_t *t;
  35.     int        x;
  36.     int        y;
  37.     NXPoint    p;
  38.     NXRect    r;
  39.     int        selected;
  40.     
  41.     selected = [parent_i getSelectedTexture];
  42.     list_i = [parent_i getList];
  43.     PSselectfont("Helvetica-Medium",FONTSIZE);
  44.     PSrotate(0);
  45.     
  46.     PSsetgray(NX_LTGRAY);
  47.     PSrectfill(rects->origin.x, rects->origin.y, 
  48.         rects->size.width, rects->size.height);
  49.  
  50.     if (!list_i)        // WADfile didn't init
  51.         return self;
  52.  
  53.     if (deselectIndex != -1)
  54.     {
  55.         t = [list_i elementAt:deselectIndex];
  56.         r = t->r;
  57.         r.origin.x -= TEX_INDENT;
  58.         r.origin.y -= TEX_INDENT;
  59.         r.size.width += TEX_INDENT*2;
  60.         r.size.height += TEX_INDENT*2;
  61.         
  62.         PSsetgray(NXGrayComponent(NX_COLORLTGRAY));
  63.         PSrectfill(r.origin.x, r.origin.y,
  64.             r.size.width, r.size.height);
  65.         p = t->r.origin;
  66.         p.y += TEX_SPACING;
  67.         [t->image drawAt:&p];
  68.         PSsetgray(0);
  69.         x = t->r.origin.x;
  70.         y = t->r.origin.y + 7;
  71.         PSmoveto(x,y);
  72.         PSshow(t->name);
  73.         PSstroke();
  74.         deselectIndex = -1;
  75.     }
  76.  
  77.     max = [list_i count];
  78.     PSsetgray(0);
  79.  
  80.     for (i = 0;i < max; i++)
  81.     {
  82.         t = [list_i elementAt:i];
  83.         r = t->r;
  84.         r.origin.x -= TEX_INDENT/2;
  85.         r.size.width += TEX_INDENT;
  86.         r.origin.y += 4;
  87.         if (NXIntersectsRect(&rects[0],&r) == YES &&
  88.             t->display)
  89.         {
  90.             if (selected == i)
  91.             {
  92.                 PSsetgray(1);
  93.                 PSrectfill(r.origin.x,r.origin.y,
  94.                     r.size.width,r.size.height);
  95.                 PSsetrgbcolor(1,0,0);
  96.                 PSrectstroke(r.origin.x, r.origin.y,
  97.                      r.size.width, r.size.height);
  98.                 PSsetgray(0);
  99.             }
  100.             
  101.             p = t->r.origin;
  102.             p.y += TEX_SPACING;
  103.             [t->image drawAt:&p];
  104.             x = t->r.origin.x;
  105.             y = t->r.origin.y + 7;
  106.             PSmoveto(x,y);
  107.             PSshow(t->name);
  108.         }
  109.     }
  110.     PSstroke();
  111.     return self;
  112. }
  113.  
  114. - deselect
  115. {
  116.     deselectIndex = [parent_i getSelectedTexture];
  117.     return self;
  118. }
  119.  
  120. - mouseDown:(NXEvent *)theEvent
  121. {
  122.     NXPoint    loc;
  123.     int        i;
  124.     int        max;
  125.     int        oldwindowmask;
  126.     texpal_t *t;
  127.     id        list;
  128.     NXRect    r;
  129.  
  130.     oldwindowmask = [window addToEventMask:NX_LMOUSEDRAGGEDMASK];
  131.     loc = theEvent->location;
  132.     [self convertPoint:&loc    fromView:NULL];
  133.     
  134.     list = [parent_i getList];
  135.     max = [list count];
  136.     for (i = 0;i < max; i++)
  137.     {
  138.         t = [list elementAt:i];
  139.         r = t->r;
  140.         if (NXPointInRect(&loc,&r) == YES)
  141.         {
  142.             [self deselect]; 
  143.             [parent_i    setSelectedTexture:i];
  144.             break;
  145.         }
  146.     }
  147.     
  148.     [window    setEventMask:oldwindowmask];
  149.     return self;
  150. }
  151.  
  152. @end
  153.