home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / SAT 2.4.0 / SAT / Demo ƒ / SATCluts ƒ / SATCluts.p < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.1 KB  |  113 lines  |  [TEXT/PJMM]

  1. {This VERY PRELIMINARY demo shows how to use different color tables with SAT,}
  2. {changing even after loading, and making sprite faces work with the changes.}
  3. {}
  4. {Usage: Type any key from 1 to 9 to choose CLUT. All CLUTs except 5 (the system palette)}
  5. {should leave the sprite intact, with the same colors. A small number of colors are used}
  6. {for the sprite face, and the others are changing in all the CLUTs.}
  7. {}
  8. {By Ingemar Ragnemalm 1996}
  9.  
  10. program SATCluts;
  11.     uses
  12. {$IFC UNDEFINED THINK_PASCAL}
  13.         Types, QuickDraw, Menus, Windows, TextEdit, Fonts,
  14.         Dialogs, Memory, Events, ToolUtils,{}
  15. {$ENDC}
  16.         Palettes, QDOffScreen, SAT;
  17.  
  18.     procedure Nop (me: SpritePtr);
  19.     begin
  20.     end;
  21.  
  22.     procedure SATSetClut (theClut: CTabHandle);
  23.         procedure CopyScreenClut (var p: SATPort);
  24.         begin
  25.             BlockMove(@gSAT.wind.device^^.gdPMap^^.pmTable^^, @p.device^^.gdPMap^^.pmTable^^, 8 + (p.device^^.gdPMap^^.pmTable^^.ctSize + 1) * 8);
  26.             CTabChanged(gSAT.offScreen.device^^.gdPMap^^.pmTable);
  27.         end; {CopyScreenClut}
  28.     begin
  29. {Change screen CLUT}
  30.         SATSetPortScreen;
  31.         SetEntries(0, 255, theClut^^.ctTable);
  32.         CTabChanged(gSAT.wind.device^^.gdPMap^^.pmTable);
  33. {Copy to all relevant offscreens}
  34.         CopyScreenClut(gSAT.offScreen);
  35.         CopyScreenClut(gSAT.backScreen);
  36.         CopyScreenClut(gSAT.iconPort);
  37.         CopyScreenClut(gSAT.iconPort2);
  38. {Fool CopyBits into believing that the CLUTs are identical - which they are!}
  39.         CGrafPtr(gSAT.offScreen.port)^.portPixMap^^.pmTable^^.ctSeed := gSAT.wind.device^^.gdPMap^^.pmTable^^.ctSeed;
  40.         CGrafPtr(gSAT.backScreen.port)^.portPixMap^^.pmTable^^.ctSeed := gSAT.wind.device^^.gdPMap^^.pmTable^^.ctSeed;
  41.         CGrafPtr(gSAT.iconPort.port)^.portPixMap^^.pmTable^^.ctSeed := gSAT.wind.device^^.gdPMap^^.pmTable^^.ctSeed;
  42.         CGrafPtr(gSAT.iconPort2.port)^.portPixMap^^.pmTable^^.ctSeed := gSAT.wind.device^^.gdPMap^^.pmTable^^.ctSeed;
  43.     end;
  44.  
  45.     var
  46.         myClut: array[1..10] of CTabHandle;
  47.  
  48.     var
  49.         s: SpritePtr;
  50.         theEvent: EventRecord;
  51.         i: Integer;
  52.         r: Rect;
  53.  
  54. begin
  55. {$ifc UNDEFINED THINK_PASCAL}
  56.     SATInitToolbox;
  57. {$endc}
  58.  
  59. {Get the palettes we will switch between}
  60.     for i := 1 to 10 do
  61.         myClut[i] := GetCTable(127 + i);
  62.  
  63.     SATInit(0, 0, 640, 480);
  64.     SATSetClut(myClut[1]);
  65.     SATSetPortScreen;
  66.     for i := 0 to 640 do
  67.         begin
  68.             RGBForeColor(myClut[1]^^.ctTable[i mod (myClut[1]^^.ctSize + 1)].rgb);
  69.  
  70.             MoveTo(i, 0);
  71.             Line(0, 400);
  72.         end;
  73.     ForeColor(blackColor);
  74.     SATSetPortBackscreen;
  75.     for i := 0 to 640 do
  76.         begin
  77.             RGBForeColor(myClut[1]^^.ctTable[i mod (myClut[1]^^.ctSize + 1)].rgb);
  78.  
  79.             MoveTo(i, 0);
  80.             Line(0, 400);
  81.         end;
  82.     ForeColor(blackColor);
  83.     SATBackChanged(gSAT.wind.bounds);
  84.  
  85.     SATSetPortScreen;
  86.  
  87.     SATSetClut(myClut[10]);            {A palette that inhibits all changing colors!}
  88.  
  89.     s := SATNewSprite(0, 0, 0, nil);
  90.     s^.task := @Nop;
  91.     s^.face := SATGetFace(128);
  92.  
  93. {Set back to a "normal" CLUT}
  94.     SATSetClut(myClut[1]);
  95.  
  96.     HideCursor;
  97.     while not Button do
  98.         begin
  99.             SATRun(true);
  100.             GetMouse(s^.position);
  101.  
  102.             if GetNextEvent(everyEvent, theEvent) then
  103.                 if theEvent.what = keyDown then
  104.                     case BitAnd(theEvent.message, 255) - Ord('0') of
  105.                         1, 2, 3, 4, 5, 6, 7, 8, 9: 
  106.                             SATSetClut(myClut[BitAnd(theEvent.message, 255) - Ord('0')]);
  107.                         otherwise
  108.                     end;
  109.         end;
  110.     ShowCursor;
  111.  
  112.     RestoreDeviceClut(nil);
  113. end.