home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 28 / amigaformatcd28.iso / -seriously_amiga- / graphics / flashmandel / sources / modules / cycle.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-05-09  |  3.9 KB  |  166 lines

  1. /*******************************************************************************
  2. **
  3. **  Coded by Claudio Pucci & Dino Papararo     26-Oct-1997
  4. **
  5. **  FUNCTION
  6. **
  7. **    Cycle -- perform screen color cycling.
  8. **
  9. **  SYNOPSIS
  10. **
  11. **    VOID Cycle (struct Window *Win,ULONG TimeDelay,BOOL Left)
  12. **
  13. **  DESCRIPTION
  14. **
  15. **    Function uses a double sized table to manage color cycling.
  16. **
  17. **    So we do not need to save and shift all colors for every cycle,
  18. **
  19. **    but only save and set correct first and last values !
  20. **
  21. **    This function do not load the first four color registers. (Interface pens)
  22. **
  23. *******************************************************************************/
  24.  
  25. #define __USE_SYSBASE
  26.  
  27. #include <exec/types.h>
  28. #include <proto/dos.h>
  29. #include <proto/intuition.h>
  30. #include <proto/graphics.h>
  31. #include <proto/gadtools.h>
  32. #include <intuition/intuition.h>
  33. #include <graphics/gfxbase.h>
  34.  
  35. #define RAW_ESC 0x45
  36.  
  37. BOOL Cycle (struct Window *,ULONG,BOOL);
  38.  
  39. BOOL Cycle (struct Window *Win,ULONG TimeDelay,BOOL Left)
  40. {
  41. DisplayInfoHandle DHandle;
  42.  
  43. struct DisplayInfo DInfo;
  44.  
  45. struct IntuiMessage *Message;
  46.  
  47. static ULONG Palette_Tmp [2L * 3L * 252L + 2L];
  48.  
  49. BOOL Loop = TRUE;
  50.  
  51. UWORD MyCode = 0;
  52.  
  53. ULONG MyClass = NULL,Counter = NULL,OldBlue,OldRed,Tmp_1,Tmp_2,HalfRange;
  54.  
  55. ULONG ModeID,Range = NULL;
  56.  
  57.   if (Win->RPort->BitMap->Depth < 2L) return FALSE;
  58.  
  59.   ModeID = GetVPModeID (ViewPortAddress (Win));
  60.  
  61.   DHandle = FindDisplayInfo (ModeID);
  62.  
  63.   if (GetDisplayInfoData (DHandle,(UBYTE *) &DInfo,sizeof (struct DisplayInfo),DTAG_DISP,ModeID))
  64.   {
  65.      if (DInfo.PropertyFlags & DIPF_IS_EXTRAHALFBRITE)
  66.      {
  67.         Range = (1L << Win->RPort->BitMap->Depth) - 8L;
  68.  
  69.         HalfRange = Range >> 1L;
  70.  
  71.         GetRGB32 (ViewPortAddress (Win)->ColorMap,4L,HalfRange,&Palette_Tmp [1L]);
  72.  
  73.         GetRGB32 (ViewPortAddress (Win)->ColorMap,4L,HalfRange,&Palette_Tmp [3L * HalfRange + 1L]);
  74.  
  75.         GetRGB32 (ViewPortAddress (Win)->ColorMap,4L,HalfRange,&Palette_Tmp [3L * (2L * HalfRange) + 1L]);
  76.  
  77.         GetRGB32 (ViewPortAddress (Win)->ColorMap,4L,HalfRange,&Palette_Tmp [3L * (3L * HalfRange) + 1L]);
  78.  
  79.         Palette_Tmp [3L * 2L * (4L * HalfRange) + 1L] = NULL;
  80.      }
  81.  
  82.      else
  83.      {
  84.         Range = (1L << Win->RPort->BitMap->Depth) - 4L;
  85.  
  86.         GetRGB32 (ViewPortAddress (Win)->ColorMap,4L,Range,&Palette_Tmp [1L]);
  87.  
  88.         GetRGB32 (ViewPortAddress (Win)->ColorMap,4L,Range,&Palette_Tmp [3L * Range + 1L]);
  89.  
  90.         Palette_Tmp [2L * 3L * Range + 1L] = NULL;
  91.      }
  92.   }
  93.  
  94.   Palette_Tmp [0L] = (Range << 16L) + 4L;
  95.  
  96.   if (! Left) Counter = Range + 1L;
  97.  
  98.   while (Loop)
  99.   {
  100.         if (Win->UserPort->mp_SigBit)
  101.         {
  102.            if (Message = (struct IntuiMessage *) GT_GetIMsg (Win->UserPort))
  103.            {
  104.               MyClass = Message->Class;
  105.  
  106.               MyCode  = Message->Code;
  107.  
  108.               GT_ReplyIMsg ((struct IntuiMessage *) Message);
  109.            }
  110.  
  111.            switch (MyClass)
  112.            {
  113.               case IDCMP_MOUSEBUTTONS:  if (MyCode == SELECTDOWN) Loop = FALSE;
  114.  
  115.                                         break;
  116.  
  117.               case IDCMP_MENUPICK    :  Loop = FALSE;
  118.  
  119.                                         break;
  120.  
  121.               case IDCMP_RAWKEY      :  if (MyCode == RAW_ESC) Loop = FALSE;
  122.  
  123.                                         break;
  124.            }
  125.         }
  126.  
  127.         if (Left)
  128.         {
  129.            Counter++;
  130.  
  131.            if (Counter > Range) Counter = 1L;
  132.         }
  133.  
  134.         else
  135.         {
  136.            Counter--;
  137.  
  138.            if (Counter < 1L) Counter = Range;
  139.         }
  140.  
  141.         Tmp_1 = 3L * Counter;
  142.  
  143.         Tmp_2 = 3L * (Counter + Range) + 1L;
  144.  
  145.         OldBlue = Palette_Tmp [Tmp_1];
  146.  
  147.         OldRed  = Palette_Tmp [Tmp_2];
  148.  
  149.         Palette_Tmp [Tmp_1] = (Range << 16L) + 4L;
  150.  
  151.         Palette_Tmp [Tmp_2] = NULL;
  152.  
  153.         Delay (TimeDelay);
  154.  
  155.         WaitTOF ();
  156.  
  157.         LoadRGB32 (ViewPortAddress (Win),&Palette_Tmp [3L * Counter]);
  158.  
  159.         Palette_Tmp [Tmp_1] = OldBlue;
  160.  
  161.         Palette_Tmp [Tmp_2] = OldRed;
  162.   }
  163.  
  164.   return TRUE;
  165. }
  166.