home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C++ / Snippets / Cluts / Cluts.c++ next >
Encoding:
C/C++ Source or Header  |  1994-05-04  |  2.0 KB  |  82 lines  |  [TEXT/KAHL]

  1. #include <Palettes.h>
  2.  
  3. /*
  4.         What this demo does:
  5.             How to draw a picture using a custom "CLUT" resource;
  6.             i.e. drawing a picture not using the system clut.
  7.             No clut animation is done here.
  8.         Last update: April 25 1994
  9.         
  10.         by: Hiep Dam, 3G Software
  11.         Public Domain
  12.         Contacting author: AOL:      starlabs
  13.                            Delphi:   starlabs
  14.                            Internet: starlabs@aol.com
  15. */
  16.  
  17.  
  18. enum {
  19.     kPicID = 516,            // Resource id of picture
  20.     kClutID = kPicID        // Resource id of clut (color lookup table)
  21. };
  22.  
  23. // ----------------------------------------------------------------
  24.  
  25. void InitMac();
  26. void DoClutThing(WindowPtr theWindow);
  27.  
  28. // ----------------------------------------------------------------
  29.  
  30. void main() {
  31.     InitMac();
  32.  
  33.     GDHandle saveDevice = GetGDevice();
  34.  
  35.     // Note: works only with a color window, not a normal b&w window...
  36.     WindowPtr theWindow = (WindowPtr)NewCWindow(nil, &screenBits.bounds, "\pCluts", true, plainDBox, (WindowPtr)-1, false, 0);
  37.     SetPort(theWindow);
  38.  
  39.     DoClutThing(theWindow);
  40.  
  41.     RestoreDeviceClut(saveDevice);    // Cheap but easy...
  42. } // END main
  43.  
  44. // ----------------------------------------------------------------
  45.  
  46. void InitMac() {
  47.     InitGraf(&thePort);
  48.     InitFonts();
  49.     InitWindows();
  50.     TEInit();
  51.     InitDialogs(nil);
  52.     InitCursor();
  53.     FlushEvents(everyEvent, 0);
  54. } // END InitMac
  55.  
  56. // ----------------------------------------------------------------
  57.  
  58. void DoClutThing(WindowPtr theWindow) {
  59.     SetPort(theWindow);
  60.     FillRect(&theWindow->portRect, black);
  61.  
  62.     PicHandle thePic = (PicHandle)Get1Resource('PICT', kPicID);
  63.     HLockHi((Handle)thePic);
  64.  
  65.     // **** Juicy part begins here... ****
  66.     CTabHandle theClut = GetCTable(kClutID);
  67.  
  68.     PaletteHandle thePalette = NewPalette((**theClut).ctSize, theClut, pmTolerant, 0);
  69.     NSetPalette(theWindow, thePalette, pmAllUpdates);
  70.     ActivatePalette(theWindow);
  71.     // **** End of juicy part... ****
  72.     
  73.     SetPort(theWindow);
  74.     Rect destR = (**thePic).picFrame;
  75.     OffsetRect(&destR, 100, 100);
  76.     DrawPicture(thePic, &destR);
  77.     HUnlock((Handle)thePic);
  78.  
  79.     do {} while (!Button());
  80.  
  81.     FillRect(&theWindow->portRect, black);
  82. } // END DoClutThing