home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 152.lha / Fade_srcs / nbackgnd.c < prev    next >
C/C++ Source or Header  |  1988-04-26  |  5KB  |  169 lines

  1. /*
  2.  
  3.  
  4. ****************************************************************************
  5.     SCREEN   COLOR   ROUTINES
  6.  
  7.         CREATED BY:
  8.             HAROLD WALPERT 
  9.             6224 BERKELEY AVE
  10.             BALTIMORE, MD. 21209
  11.                 for
  12.             BALTIMORE AMIGA USER'S DEVELOPERS(BAUD) LTD.
  13.             (AN AMIGA USER GROUP)
  14.             P.O.BOX 2432
  15.             BALTIMORE, MARYLAND 21203-2432
  16.  
  17. All copyrights are retained by Harold Walpert but the code described is
  18. freely distributable in the public domain.
  19.  
  20. NO warranty is implied--use at your own risk. As far as I know they do work.
  21. ***************************************************************************
  22.  
  23.  
  24.  
  25.  
  26.  
  27. PURPOSE: The reason a person might want to use these routines is to make
  28. switching pallettes, screens, windows, programs more professional looking.
  29. These routines will allow you to gently fade from one set of colors to 
  30. another set or to turn the screen black for a while and then to bring it
  31. back, etc. The members of BAUD seem to like them and we use them in our 
  32. club magazine (which is on disk-if you would like to get a copy they aren't too 
  33. expensive-drop us a line).
  34.   
  35. A FULL SET OF CODE INCLUDES
  36. :
  37.     backgnd.c
  38.     fade.c
  39.     nbackgnd.c
  40.     restore1.c
  41.     solidcolor.c
  42.     
  43. FUNCTIONS: The following functions are contained in the above code. I've also 
  44. indicated after each function the proper declarations for the variables con-
  45. tained in the function call. The functions are very similar to each other and
  46. you could probably build on them.
  47.        
  48.     (1) backgnd_colors(vp,nColors)             [Contained in backgnd.c]
  49.         struct ViewPort *vp;
  50.         LONG nColors;
  51.  
  52.     (2) fade_colors(vp,nColors)                  [Contained in fade.c]
  53.         struct ViewPort *vp;
  54.         LONG nColors;
  55.  
  56.     (3) nbackgnd_colors(vp,colortable,nColors) [Contained in nbackgnd.c]
  57.               struct ViewPort *vp;
  58.         LONG nColors;
  59.         WORD *colortable;
  60.     
  61.     (4) restore_colors(vp,colortable,nColors)  [Contained in restore1.c]
  62.          struct ViewPort *vp;
  63.         LONG nColors;
  64.         WORD *colortable;
  65.  
  66.     (5) solid_colors(vp,colortable,nColors,k)  [Contained in solidcolor.c]
  67.         struct ViewPort *vp;
  68.         LONG nColors,k;
  69.         WORD *colortable;
  70.  
  71. WHAT THEY DO:
  72.  
  73.     (1) fade_colors() is passed the address of the current viewport and 
  74. the number of colors in the viewport color table i.e. 4,8,16, or 32. The 
  75. function then sets them all to black. The screen then slowly fades out.
  76.  
  77.     (2) restore_colors() is passed the address of the viewport you are 
  78. planning to use, the address of the colortable you want to use and the 
  79. number of colors in the color table. The function then restores the screen 
  80. to these colors and, voila, the screen slowly comes back in the new colors.
  81.  
  82.     (3) backgnd_colors() is similar to fade_colors() but instead fades 
  83. the screen to the current color #0 of the viewport color table.
  84.  
  85.     (4) nbackgnd_colors() is similar to backgnd_colors() but instead
  86. of fading to the current viewport color #0 , it fades all of the screen colors 
  87. to a designated colortable color #0.
  88.  
  89.     (5) solid_colors() is similar to nbackgnd_colors() but instead of 
  90. fading the screen colors to the designated colortable #0 it will fade the 
  91. screen colors to any chosen color from those in a designated colortable(i.e.
  92. color "k").
  93.  
  94. YOU SHOULD BE ABLE TO COMPILE THESE IN MANX--HAVE FUN!
  95.  
  96.                     Harold
  97.     
  98. */
  99.  
  100. #include <stdio.h>
  101. #include <exec/io.h>
  102. #include <exec/types.h>
  103. #include <exec/nodes.h>
  104. #include <exec/libraries.h>
  105. #include <ctype.h>
  106. #include <functions.h>
  107. #include <exec/memory.h>
  108. #include <graphics/gfx.h>
  109. #include <hardware/dmabits.h>
  110. #include <hardware/custom.h>
  111. #include <hardware/blit.h>
  112. #include <graphics/rastport.h>
  113. #include <graphics/gfxmacros.h>
  114. #include <graphics/view.h>
  115. #include <graphics/gels.h>
  116. #include <graphics/regions.h>
  117. #include <graphics/clip.h>
  118. #include <graphics/display.h>
  119. #include <exec/exec.h>
  120. #include <graphics/text.h>
  121. #include <graphics/gfxbase.h>
  122. #include <devices/console.h>
  123. #include <devices/keymap.h>
  124. #include <libraries/dos.h>
  125. #include <libraries/dosextens.h>
  126. #include <libraries/diskfont.h>
  127. #include <intuition/intuition.h>
  128. #include <intuition/intuitionbase.h>
  129.  
  130. nbackgnd_colors(vp,colortable,nColors) 
  131. struct ViewPort *vp;
  132. LONG nColors;
  133. WORD *colortable;
  134. {
  135.  
  136. WORD col[32];
  137. long i,more;
  138.  
  139. for (i=0;i<nColors;i++)
  140.     col[i] = GetRGB4(vp->ColorMap,i);
  141.  
  142. more = TRUE;
  143. while (more == TRUE)
  144.  {
  145.     more = FALSE;
  146.     
  147.     for (i=0;i<nColors;i++)
  148.     {
  149.     if ((col[i] & 0x0f00) < (colortable[0] & 0x0f00 ))
  150.          { col[i] += 0x0100; more = TRUE; }
  151.     if ((col[i] & 0x00f0) < (colortable[0] & 0x00f0))
  152.          { col[i] += 0x0010; more = TRUE; }
  153.     if ((col[i] & 0x000f) < (colortable[0] & 0x000f))
  154.          { col[i] += 0x0001; more = TRUE; }
  155.     if ((col[i] & 0x0f00) > (colortable[0] & 0x0f00 ))
  156.          { col[i] -= 0x0100; more = TRUE; }
  157.     if ((col[i] & 0x00f0) > (colortable[0] & 0x00f0))
  158.          { col[i] -= 0x0010; more = TRUE; }
  159.     if ((col[i] & 0x000f) > (colortable[0] & 0x000f))
  160.          { col[i] -= 0x0001; more = TRUE; }
  161.     }
  162.  
  163.     LoadRGB4(vp, &col[0], nColors);
  164.     Delay(2);
  165.  }
  166. }
  167.  
  168.  
  169.