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

  1.  
  2. #import "qedefs.h"
  3.  
  4. id    texturepalette_i;
  5.  
  6.  
  7. #define    TYP_MIPTEX    67
  8.  
  9. int                    tex_count;
  10. qtexture_t             qtextures[MAX_TEXTURES];
  11.  
  12. typedef struct
  13. {
  14.     char        name[16];
  15.     unsigned    width, height;
  16.     unsigned    offsets[4];        // four mip maps stored
  17. } miptex_t;
  18.  
  19. unsigned    tex_palette[256];
  20.  
  21. unsigned badtex_d[] = 
  22. {
  23. 0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,
  24. 0,0,0,0,0,0,0,0,
  25. 0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,
  26. 0,0,0,0,0,0,0,0,
  27. 0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,
  28. 0,0,0,0,0,0,0,0,
  29. 0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,
  30. 0,0,0,0,0,0,0,0,
  31. 0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,
  32. 0,0,0,0,0,0,0,0,
  33. 0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,
  34. 0,0,0,0,0,0,0,0,
  35. 0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,
  36. 0,0,0,0,0,0,0,0,
  37. 0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,
  38. 0,0,0,0,0,0,0,0,
  39.  
  40. 0,0,0,0,0,0,0,0,
  41. 0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,
  42. 0,0,0,0,0,0,0,0,
  43. 0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,
  44. 0,0,0,0,0,0,0,0,
  45. 0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,
  46. 0,0,0,0,0,0,0,0,
  47. 0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,
  48. 0,0,0,0,0,0,0,0,
  49. 0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,
  50. 0,0,0,0,0,0,0,0,
  51. 0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,
  52. 0,0,0,0,0,0,0,0,
  53. 0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,
  54. 0,0,0,0,0,0,0,0,
  55. 0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff
  56. };
  57.  
  58. qtexture_t    badtex = {"notexture",16,16,NULL, badtex_d, {0,0,255,255}};
  59.  
  60. /*
  61. ==============
  62. TEX_InitPalette
  63. ==============
  64. */
  65. void TEX_InitPalette (byte *pal)
  66. {
  67.     int        r,g,b,v;
  68.     int        i;
  69.  
  70.     for (i=0 ; i<256 ; i++)
  71.     {
  72.         r = pal[0];
  73.         g = pal[1];
  74.         b = pal[2];
  75.         pal += 3;
  76.         
  77.         v = (r<<24) + (g<<16) + (b<<8) + 255;
  78.         v = BigLong (v);
  79.         
  80.         tex_palette[i] = v;
  81.     }
  82. }
  83.  
  84.  
  85. /*
  86. =================
  87. TEX_ImageFromMiptex
  88. =================
  89. */
  90. void TEX_ImageFromMiptex (miptex_t *qtex)
  91. {
  92.     NXBitmapImageRep    *bm;
  93.     byte        *source;
  94.     unsigned    *dest;
  95.     int            width, height, i, count;
  96.     qtexture_t    *q;
  97.     int            tr, tg, tb;
  98.     
  99.     width = LittleLong(qtex->width);
  100.     height = LittleLong(qtex->height);
  101.  
  102.     bm = [[NXBitmapImageRep alloc]    
  103.             initData:        NULL 
  104.             pixelsWide:        width 
  105.             pixelsHigh:        height 
  106.             bitsPerSample:    8 
  107.             samplesPerPixel:3 
  108.             hasAlpha:        NO
  109.             isPlanar:        NO 
  110.             colorSpace:        NX_RGBColorSpace 
  111.             bytesPerRow:    width*4 
  112.             bitsPerPixel:    32];
  113.     
  114.     dest = (unsigned *)[bm data];
  115.     count = width*height;
  116.     source = (byte *)qtex + LittleLong(qtex->offsets[0]);
  117.     
  118.     q = &qtextures[tex_count];
  119.     tex_count++;
  120.     
  121.     q->width = width;
  122.     q->height = height;
  123.     q->rep = bm;
  124.     q->data = dest;
  125.  
  126.     tr = tg = tb = 0;
  127.     
  128.     for (i=0 ; i<count ; i++)
  129.     {
  130.         dest[i] = tex_palette[source[i]];
  131.         tr += ((pixel32_t *)&dest[i])->chan[0];
  132.         tg += ((pixel32_t *)&dest[i])->chan[1];
  133.         tb += ((pixel32_t *)&dest[i])->chan[2];
  134.     }
  135.     
  136.     q->flatcolor.chan[0] = tr / count;
  137.     q->flatcolor.chan[1] = tg / count;
  138.     q->flatcolor.chan[2] = tb / count;
  139.     q->flatcolor.chan[3] = 0xff;    
  140. }
  141.  
  142. //=============================================================================
  143.  
  144. typedef struct
  145. {
  146.     char        identification[4];        // should be WAD2 or 2DAW
  147.     int            numlumps;
  148.     int            infotableofs;
  149. } wadinfo_t;
  150.  
  151.  
  152. typedef struct
  153. {
  154.     int            filepos;
  155.     int            disksize;
  156.     int            size;                    // uncompressed
  157.     char        type;
  158.     char        compression;
  159.     char        pad1, pad2;
  160.     char        name[16];                // must be null terminated
  161. } lumpinfo_t;
  162.  
  163. /*
  164. =================
  165. TEX_InitFromWad
  166. =================
  167. */
  168. void    TEX_InitFromWad (char *path)
  169. {
  170.     int            i;
  171.     char        local[1024];
  172.     char        newpath[1024];
  173.     byte        *wadfile;
  174.     wadinfo_t    *wadinfo;
  175.     lumpinfo_t    *lumpinfo;
  176.     int            numlumps;
  177.     float        start, stop;
  178.     
  179.     start = I_FloatTime ();
  180.     
  181.     strcpy(newpath, [preferences_i getProjectPath]);
  182.     strcat(newpath,"/");
  183.     strcat(newpath, path);
  184.     
  185. // free any textures
  186.     for (i=0 ; i<tex_count ; i++)
  187.         [qtextures[i].rep free];
  188.     tex_count = 0;
  189.  
  190. // try and use the cached wadfile    
  191.     sprintf (local, "/qcache%s", newpath);    
  192.  
  193.     Sys_UpdateFile (local, newpath);
  194.     
  195.     LoadFile (local, (void **)&wadfile);
  196.     wadinfo = (wadinfo_t *)wadfile;
  197.     
  198.     if (strncmp (wadfile, "WAD2", 4))
  199.     {
  200.         unlink (local);
  201.         Error ("TEX_InitFromWad: %s isn't a wadfile", newpath);
  202.     }
  203.     
  204.     numlumps = LittleLong (wadinfo->numlumps);
  205.     lumpinfo = (lumpinfo_t *)(wadfile + LittleLong (wadinfo->infotableofs));
  206.     
  207.     if (strcmp (lumpinfo->name, "PALETTE"))
  208.     {
  209.         unlink (local);
  210.         Error ("TEX_InitFromWad: %s doesn't have palette as 0",path);
  211.     }
  212.     
  213.     TEX_InitPalette (wadfile + LittleLong(lumpinfo->filepos));
  214.  
  215.     lumpinfo++;    
  216.     for (i=1 ; i<numlumps ; i++, lumpinfo++)
  217.     {
  218.         if (lumpinfo->type != TYP_MIPTEX)
  219.             Error ("TEX_InitFromWad: %s is not a miptex!",lumpinfo->name);
  220.         CleanupName (lumpinfo->name,qtextures[tex_count].name);
  221.         TEX_ImageFromMiptex ( (miptex_t *)(wadfile + 
  222.             LittleLong(lumpinfo->filepos) ));
  223.     }
  224.  
  225.     free (wadfile);
  226.  
  227.     stop = I_FloatTime ();
  228.     
  229.     qprintf ("loaded %s (%5.1f)", local, stop - start);
  230. }
  231.  
  232. /*
  233. =================
  234. TEX_NumForName
  235. =================
  236. */
  237. qtexture_t *TEX_ForName (char *name)
  238. {
  239.     char    newname[16];
  240.     int        i;
  241.     qtexture_t    *q;
  242.     
  243.     CleanupName (name, newname);
  244.     
  245.     for (i=0,q = qtextures ; i< tex_count ; i++, q++)
  246.     {
  247.         if (!strcmp(name, q->name))
  248.             return q;
  249.     }
  250.     
  251.     return &badtex;
  252. }
  253.  
  254.  
  255.  
  256. //===========================================================================
  257.  
  258. @implementation TexturePalette
  259.  
  260. - init
  261. {
  262.     [super init];
  263.     texturepalette_i = self;
  264.     selectedTexture = -1;
  265.     return self;
  266. }
  267.  
  268. - display
  269. {
  270.     [[textureView_i superview] display];
  271.     return self;
  272. }
  273.  
  274.  
  275. - (char *)currentWad
  276. {
  277.     return currentwad;
  278. }
  279.  
  280. - initPaletteFromWadfile:(char *)wf
  281. {
  282.     int            i;
  283.     texpal_t    t;
  284.     qtexture_t    *q;
  285.     
  286.     strcpy (currentwad, wf);
  287.     [map_i makeGlobalPerform: @selector(flushTextures)];    
  288.     selectedTexture = -1;
  289.     
  290.     // Init textures WAD
  291.     TEX_InitFromWad(wf);
  292.     
  293.     // Create STORAGE
  294.     if (textureList_i)
  295.         [textureList_i empty];
  296.     else
  297.         textureList_i = [[Storage alloc]
  298.             initCount:0
  299.             elementSize:sizeof(texpal_t)
  300.             description:NULL];
  301.                 
  302.     // Init STORAGE
  303.     
  304.     for (i = 0,q=qtextures;i < tex_count; i++,q++)
  305.     {
  306.         t.image = q->rep;
  307.         t.r.size.width = [t.image pixelsWide];
  308.         if (t.r.size.width < 64)
  309.             t.r.size.width = 64;
  310.         t.r.size.height = [t.image pixelsHigh] + TEX_SPACING;
  311.         t.name = q->name;
  312.         t.index = i;
  313.         t.display = 1;
  314.         [textureList_i    addElement:&t];
  315.     }
  316.  
  317.     // Calculate size of TextureView
  318.     [self alphabetize];
  319.     [self computeTextureViewSize];
  320.     [textureView_i setParent:self];
  321.     [self setSelectedTexture:0];
  322.  
  323.     return self;
  324. }
  325.  
  326.  
  327.  
  328. //    Return texture STORAGE list
  329. - getList
  330. {
  331.     return textureList_i;
  332. }
  333.  
  334. //    Alphabetize texture list - reverse order!
  335. - alphabetize
  336. {
  337.     int        i;
  338.     int        max;
  339.     texpal_t    *t1p;
  340.     texpal_t    *t2p;
  341.     texpal_t    t1;
  342.     texpal_t    t2;
  343.     int        found;
  344.     
  345.     max = [textureList_i count];
  346.     found = 1;
  347.     while(found)
  348.     {
  349.         found = 0;
  350.         for (i = 0;i < max-1;i++)
  351.         {
  352.             t1p = [textureList_i elementAt:i];
  353.             t2p = [textureList_i elementAt:i+1];
  354.             if (strcmp(t1p->name,t2p->name) < 0)
  355.             {
  356.                 t1 = *t1p;
  357.                 t2 = *t2p;
  358.                 [textureList_i replaceElementAt:i with:&t2];
  359.                 [textureList_i replaceElementAt:i+1 with:&t1];
  360.                 found = 1;
  361.             }
  362.         }
  363.     }
  364.     return self;
  365. }
  366.  
  367. - computeTextureViewSize
  368. {
  369.     int        i;
  370.     int        max;
  371.     int        x;
  372.     texpal_t *t;
  373.     int        y;
  374.     id        view;
  375.     NXRect    b;
  376.     int        maxwidth;
  377.     int        maxheight;
  378.     NXPoint    pt;
  379.     
  380.     max = [textureList_i count];
  381.     y = 0;
  382.     maxheight = 0;
  383.     x = TEX_INDENT;
  384.  
  385.     view = [textureView_i superview];
  386.     [view getBounds:&b];
  387.     maxwidth = b.size.width;
  388.  
  389.     for (i = 0;i < max; i++)
  390.     {
  391.         t = [textureList_i elementAt:i];
  392.         if (x + t->r.size.width + TEX_INDENT > maxwidth)
  393.         {
  394.             x = TEX_INDENT;
  395.             y += maxheight;
  396.             maxheight = 0;
  397.         }
  398.         if (t->r.size.height > maxheight)
  399.             maxheight = t->r.size.height;
  400.         t->r.origin.x = x;
  401.         t->r.origin.y = y;
  402.         x += t->r.size.width + TEX_INDENT;
  403.         if (i == max - 1)
  404.             y += t->r.size.height;
  405.     }
  406.  
  407.     viewWidth = maxwidth;
  408.     viewHeight = y + TEX_SPACING;
  409.     [textureView_i sizeTo:viewWidth :viewHeight];
  410.     pt.x = pt.y = 0;
  411.     [textureView_i scrollPoint:&pt];
  412.  
  413.     return self;
  414. }
  415.  
  416. - windowResized
  417. {
  418.     [self computeTextureViewSize];
  419.     return self;
  420. }
  421.  
  422. - texturedefChanged: sender
  423. {
  424.     if ([map_i numSelected])
  425.     {
  426.         if ( [[map_i currentEntity] modifiable] )
  427.         {
  428.             [map_i makeSelectedPerform: @selector(takeCurrentTexture)];
  429.             [quakeed_i updateAll];
  430.         }
  431.         else
  432.             qprintf ("can't modify spawned entities");
  433.     }
  434.     [quakeed_i makeFirstResponder: quakeed_i];
  435.     return self;
  436. }
  437.  
  438. - clearTexinfo: sender
  439. {
  440.     [field_Xshift_i    setFloatValue:0];
  441.     [field_Yshift_i    setFloatValue:0];
  442.     [field_Xscale_i    setFloatValue:1];
  443.     [field_Yscale_i    setFloatValue:1];
  444.     [field_Rotate_i    setFloatValue:0];
  445.     
  446.     [self texturedefChanged: self];
  447.  
  448.     return self;
  449. }
  450.  
  451. //
  452. //    Set the selected texture
  453. //
  454. - setSelectedTexture:(int)which
  455. {
  456.     texpal_t *t;
  457.     NXRect    r;
  458.     char    string[16];
  459.  
  460. // wipe the fields
  461.     [self clearTexinfo: self];
  462.     
  463.     if (which != selectedTexture)
  464.     {
  465.         [textureView_i deselect];
  466.         selectedTexture = which;
  467.         t = [textureList_i elementAt:which];
  468.         r = t->r;
  469.         r.size.width += TEX_INDENT*2;
  470.         r.size.height += TEX_INDENT*2;
  471.         r.origin.x -= TEX_INDENT;
  472.         r.origin.y -= TEX_INDENT;
  473.         [textureView_i scrollRectToVisible:&r];
  474.         [textureView_i display];
  475.         sprintf(string,"%d x %d",(int)t->r.size.width,
  476.             (int)t->r.size.height - TEX_SPACING);
  477.         [sizeField_i setStringValue:string];
  478.     }
  479.  
  480.     [self texturedefChanged:self];
  481.  
  482.     return self;
  483. }
  484.  
  485. //
  486. //    Return the selected texture index
  487. //
  488. - (int)getSelectedTexture
  489. {
  490.     return selectedTexture;
  491. }
  492.  
  493. //
  494. //    Return the original tex_ index of the selected texture
  495. //    so the texture info can be indexed from tex_images, etc.
  496. //
  497. - (int)getSelectedTexIndex
  498. {
  499.     texpal_t *t;
  500.     
  501.     if (selectedTexture == -1)
  502.         return -1;
  503.     t = [textureList_i elementAt:selectedTexture];
  504.     return t->index;
  505. }
  506.  
  507. //
  508. //    Return the name of the selected texture
  509. //
  510. - (char *)getSelTextureName
  511. {
  512.     texpal_t *t;
  513.     
  514.     if (selectedTexture == -1)
  515.         return NULL;
  516.     t = [textureList_i elementAt:selectedTexture];
  517.     return t->name;
  518. }
  519.  
  520. //
  521. //    Set selected texture by texture name
  522. //
  523. - setTextureByName:(char *)name
  524. {
  525.     texpal_t    *t;
  526.     int        i;
  527.     int        max;
  528.     
  529.     max = [textureList_i count];
  530.     CleanupName(name,name);
  531.     for (i = 0;i < max;i++)
  532.     {
  533.         t = [textureList_i elementAt:i];
  534.         if (!strcmp(t->name,name))
  535.         {
  536.             [self setSelectedTexture: i];
  537.             return self;
  538.         }
  539.     }
  540.     return self;
  541. }
  542.  
  543. //===================================================
  544. //
  545. //    Action methods
  546. //
  547. //===================================================
  548.  
  549.  
  550. //
  551. //    Search for texture named in searchField
  552. //
  553. - searchForTexture:sender
  554. {
  555.     int        i;
  556.     int        max;
  557.     int        len;
  558.     char    name[32];
  559.     texpal_t    *t;
  560.     
  561.     if (selectedTexture == -1)
  562.         return self;
  563.  
  564.     max = [textureList_i count];
  565.     strcpy(name,(const char *)[sender stringValue]);
  566.     [sender setStringValue:strupr(name)];
  567.     len = strlen(name);
  568.     
  569.     for (i = selectedTexture-1;i >= 0; i--)
  570.     {
  571.         t = [textureList_i elementAt:i];
  572.         if (!strncmp(t->name,name,len))
  573.         {
  574.             [self setTextureByName:t->name];
  575.             [sender selectText:sender];
  576.             [self texturedefChanged:self];
  577.             return self;
  578.         }
  579.     }
  580.     
  581.     for (i = max-1;i >= selectedTexture; i--)
  582.     {
  583.         t = [textureList_i elementAt:i];
  584.         if (!strncmp(t->name,name,len))
  585.         {
  586.             [self setTextureByName:t->name];
  587.             [sender selectText:sender];
  588.             [self texturedefChanged:self];
  589.             return self;
  590.         }
  591.     }
  592.     
  593.     [self texturedefChanged:self];
  594.     return self;
  595. }
  596.  
  597. //
  598. //    Set texture def from outside TexturePalette
  599. //
  600. - setTextureDef:(texturedef_t *)td
  601. {
  602.     [self setTextureByName:td->texture];
  603.  
  604.     [field_Xshift_i    setFloatValue:td->shift[0]];
  605.     [field_Yshift_i    setFloatValue:td->shift[1]];
  606.     [field_Xscale_i    setFloatValue:td->scale[0]];
  607.     [field_Yscale_i    setFloatValue:td->scale[1]];
  608.     [field_Rotate_i    setFloatValue:td->rotate];
  609.  
  610.     [self texturedefChanged:self];
  611.     
  612.     return self;
  613. }
  614.  
  615. //
  616. //    Return the current texture def to passed *
  617. //
  618. - getTextureDef:(texturedef_t *)td
  619. {
  620.     if (selectedTexture == -1)
  621.     {
  622.         memset (td, 0, sizeof(*td));
  623.         strcpy (td->texture, "notexture");
  624.         return self;
  625.     }
  626.     
  627.     strncpy(td->texture,[self getSelTextureName],16);
  628.  
  629.     td->shift[0] = [field_Xshift_i floatValue];
  630.     td->shift[1] = [field_Yshift_i floatValue];
  631.     td->scale[0] = [field_Xscale_i floatValue];
  632.     td->scale[1] = [field_Yscale_i floatValue];
  633.     td->rotate = [field_Rotate_i floatValue];
  634.     
  635.     return self;
  636. }
  637.  
  638. //============================================================================
  639.  
  640. //
  641. //    Change value in a field
  642. //
  643. - changeField:(id)field by:(int)amount
  644. {
  645.     int        val;
  646.     
  647.     val = [field intValue];
  648.     val += amount;
  649.     [field setIntValue:val];
  650.  
  651.     [self texturedefChanged:self];
  652.  
  653.     return self;
  654. }
  655.  
  656. //
  657. //    Inc/Dec the XShift field
  658. //
  659. - incXShift:sender
  660. {
  661.     [self changeField:field_Xshift_i by:8];
  662.     return self;
  663. }
  664. - decXShift:sender
  665. {
  666.     [self changeField:field_Xshift_i by:-8];
  667.     return self;
  668. }
  669.  
  670. //
  671. //    Inc/Dec the YShift field
  672. //
  673. - incYShift:sender
  674. {
  675.     [self changeField:field_Yshift_i by:8];
  676.     return self;
  677. }
  678. - decYShift:sender
  679. {
  680.     [self changeField:field_Yshift_i by:-8];
  681.     return self;
  682. }
  683.  
  684. //
  685. //    Inc/Dec the Rotate field
  686. //
  687. - incRotate:sender
  688. {
  689.     [self changeField:field_Rotate_i by:90];
  690.     return self;
  691. }
  692. - decRotate:sender
  693. {
  694.     [self changeField:field_Rotate_i by:-90];
  695.     return self;
  696. }
  697.  
  698. //
  699. //    Inc/Dec the Xscale field
  700. //
  701. - incXScale:sender
  702. {
  703.     [field_Xscale_i setIntValue: 1];
  704.     [self texturedefChanged:self];
  705.     return self;
  706. }
  707. - decXScale:sender
  708. {
  709.     [field_Xscale_i setIntValue: -1];
  710.     [self texturedefChanged:self];
  711.     return self;
  712. }
  713.  
  714. //
  715. //    Inc/Dec the Yscale field
  716. //
  717. - incYScale:sender
  718. {
  719.     [field_Yscale_i setIntValue: 1];
  720.     [self texturedefChanged:self];
  721.     return self;
  722. }
  723. - decYScale:sender
  724. {
  725.     [field_Yscale_i setIntValue: -1];
  726.     [self texturedefChanged:self];
  727.     return self;
  728. }
  729.  
  730.  
  731. //============================================================================
  732.  
  733.  
  734. //
  735. //    Search for texture in entire palette
  736. //    Return index of texturedef, or -1 if unsuccessful
  737. //
  738. - (int) searchForTextureInPalette:(char *)texture
  739. {
  740.     int        i;
  741.     int        max;
  742.     char    name[32];
  743.     texpal_t    *t;
  744.     
  745.     if (selectedTexture == -1)
  746.         return -1;
  747.  
  748.     max = [textureList_i count];
  749.     strcpy(name,texture);
  750.     
  751.     for (i = 0; i < max; i++)
  752.     {
  753.         t = [textureList_i elementAt:i];
  754.         if (!strcmp(t->name,name))
  755.             return i;
  756.     }
  757.     return -1;
  758. };
  759.  
  760. //
  761. // Scan thru map & only display textures that are in map
  762. //
  763. - onlyShowMapTextures:sender
  764. {
  765.     int        max;
  766.     int        i;
  767.     int        j;
  768.     id        brushes;
  769.     SetBrush    *b;
  770.     int        numfaces;
  771.     face_t    *f;
  772.     int        index;
  773.     
  774.     // Turn 'em off
  775.     if ([sender intValue])
  776.     {
  777.         max = [textureList_i count];
  778.         for (i = 0;i < max; i++)
  779.             [self setDisplayFlag:i to:0];
  780.  
  781.         brushes = [map_i objectAt:0];
  782.         max = [brushes count];
  783.         for (i = 0;i < max; i++)
  784.         {
  785.             b = (SetBrush *)[brushes objectAt:i];
  786.             numfaces = [b getNumBrushFaces];
  787.             for (j = 0; j < numfaces; j++)
  788.             {
  789.                 f = [b getBrushFace:j];
  790.                 index = [self searchForTextureInPalette:f->texture.texture];
  791.                 if (index >= 0)
  792.                     [self setDisplayFlag:index to:1];
  793.             }
  794.         }
  795.     }
  796.     // Turn 'em on
  797.     else
  798.     {
  799.         max = [textureList_i count];
  800.         for (i = 0;i < max; i++)
  801.             [self setDisplayFlag:i to:1];
  802.     }
  803.     
  804.     [textureView_i display];
  805.     
  806.     return self;
  807. }
  808.  
  809. - setDisplayFlag:(int)index to:(int)value
  810. {
  811.     texpal_t    *tp;
  812.     
  813.     tp = [textureList_i elementAt:index];
  814.     tp->display = value;
  815.     return self;
  816. };
  817.  
  818. @end
  819.