home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 408.lha / StarBlankers / blankerLO.c < prev    next >
C/C++ Source or Header  |  1990-09-02  |  7KB  |  271 lines

  1.  
  2.    /***********************************************************************
  3.    *                                                                      *
  4.    *                            COPYRIGHTS                                *
  5.    *                                                                      *
  6.    *   Copyright (c) 1990  Commodore-Amiga, Inc.  All Rights Reserved.    *
  7.    *                                                                      *
  8.    ***********************************************************************/
  9.  
  10. #include "app.h"
  11. #include <graphics/gfxmacros.h>
  12. #include <hardware/custom.h>
  13. #include <hardware/dmabits.h>
  14. #include <intuition/gadgetclass.h>
  15.  
  16. #include <stdlib.h>
  17. #include <exec/types.h>
  18. #include <intuition/intuition.h>
  19. #include <intuition/intuitionbase.h>
  20. #include <intuition/screens.h>
  21. #include <utility/tagitem.h>
  22.  
  23. extern struct Custom custom;
  24.  
  25. ULONG timeout = 0L;
  26. ULONG blanked = 0L;
  27. ULONG seconds = 10L;
  28. short rangex, rangey;
  29. short hlfrngx, hlfrngy;
  30.  
  31. struct Gadget *secgad;
  32. struct Screen *s = NULL;
  33. struct Window *w = NULL;
  34. struct RastPort *rp;
  35.  
  36. #define NSTARS    128
  37.  
  38. short x[NSTARS],y[NSTARS],z[NSTARS];
  39. short xo[NSTARS],yo[NSTARS];
  40.  
  41. USHORT chip SpriteData[] = {
  42.                0,0,
  43.                0,0,
  44.                0,0 };
  45.  
  46. int  rand(void);
  47. BOOL setupBlanker(void);
  48. VOID BlankerAction(struct CxMsg *cxm,CxObj *co);
  49. VOID mkpoint(short);
  50. VOID mysetupCustomGadgets(struct Gadget **gad);
  51. VOID myHandleGadget(ULONG gad,ULONG code);
  52. VOID MyHandleCustomSignal(VOID);
  53.  
  54. BOOL setupBlanker(VOID)
  55. {
  56.    CxObj   *objectlist;
  57.  
  58.    seconds = ArgInt( ttypes, "SECONDS", 300 );
  59.  
  60.    objectlist=CxCustom( BlankerAction, 0L);
  61.  
  62.    if (CxObjError(objectlist))
  63.    {
  64.       D( printf("blanker: filter error %lx\n", CxObjError(objectlist) ) );
  65.       DeleteCxObjAll(objectlist);
  66.       return(0);
  67.    }
  68.  
  69.    AttachCxObj(broker, objectlist);
  70.    return(TRUE);
  71. }
  72.  
  73. VOID BlankerAction(struct CxMsg *cxm,CxObj *co)
  74. {
  75.    register struct InputEvent *ie;
  76.  
  77.    /* D( kprintf("BlankerAction\n") ); */
  78.  
  79.    /* i KNOW that all messages getting this far are CXM_IEVENT   */
  80.    ie = (struct InputEvent *) CxMsgData(cxm);
  81.  
  82.  
  83.    if(ie->ie_Class==IECLASS_TIMER)
  84.    {
  85.       /* D( printf("IECLASS_TIMER\n"); ) */
  86.       if(! blanked)
  87.       {
  88.          if ((IntuitionBase->FirstScreen->MouseX >= 
  89.                 IntuitionBase->FirstScreen->Width - 5) &&
  90.              (IntuitionBase->FirstScreen->MouseY >=
  91.                 IntuitionBase->FirstScreen->Height - 5) &&
  92.              (timeout >= 5)) 
  93.          {
  94.             D( printf("########Blank Screen\n"); )
  95.             /* Blank(); */
  96.             Signal(maintask,csigflag);
  97.             blanked=TRUE;
  98.          }
  99.          if ((!((IntuitionBase->FirstScreen->MouseX >= 
  100.                                    IntuitionBase->FirstScreen->Width - 5) &&
  101.              (IntuitionBase->FirstScreen->MouseY < 5))) && (! blanked))
  102.          {
  103.             D( printf("blanked=0x%lx Bump timeout=%ld\n",blanked,timeout);)
  104.             if(++timeout >= ((ULONG)(seconds*10L)))
  105.             {
  106.                D( printf("########Blank Screen\n"); )
  107.                /* Blank(); */
  108.                Signal(maintask,csigflag);
  109.                blanked=TRUE;
  110.             }
  111.          }
  112.      }
  113.    } else {
  114.       if(ie->ie_Class!=IECLASS_TIMER)
  115.       {
  116.          D( printf("########UnBlank\n"); )
  117.          /* UnBlank(); */
  118.          timeout=0L;
  119.          blanked=FALSE;
  120.       }
  121.    }
  122.  
  123. }
  124. VOID mkpoint (i)
  125. register short i;
  126. {
  127.         x[i] = rand() % rangex - hlfrngx;
  128.         y[i] = rand() % rangey - hlfrngy;
  129.         z[i] = 255;
  130. }
  131.  
  132. VOID mysetupCustomGadgets(struct Gadget **gad)
  133. {
  134.    struct NewGadget ng;
  135.  
  136.    ng.ng_VisualInfo=vi;
  137.  
  138.    ng.ng_TopEdge    = topborder+27;
  139.    ng.ng_LeftEdge   = 10;
  140.    ng.ng_Width      = 40;
  141.    ng.ng_Height     = 12;
  142.    ng.ng_GadgetText = "Hide";
  143.    ng.ng_TextAttr   = &mydesiredfont;
  144.    ng.ng_GadgetID   = GAD_HIDE;
  145.    ng.ng_Flags      = NULL;
  146.    ng.ng_VisualInfo = vi;
  147.    *gad = CreateGadget(BUTTON_KIND,*gad, &ng,TAG_DONE);
  148.  
  149.    ng.ng_TopEdge    = topborder+27;
  150.    ng.ng_LeftEdge   = 60;
  151.    ng.ng_Width      = 40;
  152.    ng.ng_Height     = 12;
  153.    ng.ng_GadgetText = "Quit";
  154.    ng.ng_TextAttr   = &mydesiredfont;
  155.    ng.ng_GadgetID   = GAD_DIE;
  156.    ng.ng_Flags      = NULL;
  157.    ng.ng_VisualInfo = vi;
  158.    *gad = CreateGadget(BUTTON_KIND,*gad, &ng,TAG_DONE);
  159.  
  160.    ng.ng_TopEdge    = topborder+5;
  161.    ng.ng_LeftEdge   = 80;
  162.    ng.ng_Width      = 60;
  163.    ng.ng_Height     = 14;
  164.    ng.ng_GadgetText = "Seconds";
  165.    ng.ng_TextAttr   = &mydesiredfont;
  166.    ng.ng_GadgetID   = GAD_SECS;
  167.    ng.ng_Flags      = NULL;
  168.    ng.ng_VisualInfo = vi;
  169.    secgad = *gad = CreateGadget(INTEGER_KIND,*gad, &ng,GTIN_Number,seconds,GTIN_MaxChars,4,STRINGA_Justification,STRINGRIGHT,TAG_DONE);
  170. }
  171. VOID myHandleGadget(ULONG gad,ULONG code)
  172. {
  173.    D( kprintf("custom: HandleGadget(%lx)\n",gad); )
  174.    switch(gad)
  175.    {
  176.       case GAD_HIDE:
  177.             D( kprintf("custom: HandleGadget() GAD_HIDE\n"); )
  178.             shutdownWindow();
  179.             break;
  180.       case GAD_DIE:
  181.             D( kprintf("custom: HandleGadget() GAD_DIE\n"); )
  182.             terminate();
  183.       case GAD_SECS:
  184.             D( kprintf("custom: HandleGadget() GAD_SECS\n"); )
  185.             seconds=((struct StringInfo *)secgad->SpecialInfo)->LongInt;
  186.    }
  187. }
  188. VOID MyHandleCustomSignal(VOID)
  189. {
  190.    struct NewWindow nw = {
  191.       0,0,
  192.       0,0,
  193.       -1,-1,
  194.       0,
  195.       SIMPLE_REFRESH | RMBTRAP | BACKDROP | BORDERLESS | ACTIVATE,
  196.       0,
  197.       0,
  198.       0,
  199.       0,
  200.       0,
  201.       0,0,0,0,
  202.       CUSTOMSCREEN
  203.       };
  204.  
  205. long xs, ys;
  206. short magic = 256;
  207. register short i, inc = 3;
  208. short wide, high;
  209.  
  210.    if( ! s)
  211.    {
  212.       s=OpenScreenTags(NULL, SA_DisplayID, LORES_KEY, SA_Depth, 4,
  213.                               SA_Overscan, OSCAN_STANDARD, TAG_END);
  214.       rp = &(s -> RastPort);
  215.       if( ! w)
  216.       {
  217.          nw.Width = wide = s->Width;
  218.          nw.Height= high = s->Height;
  219.          nw.Screen=s;
  220.          w = OpenWindow(&nw);
  221.       }
  222.       if(w)
  223.       {
  224.          SetPointer(w,SpriteData,1,1,0,0);
  225.          SetRast (rp, 0L);
  226.          for (xs=0; xs<16; xs++)
  227.             SetRGB4 (&(s -> ViewPort), xs, xs, xs, xs);
  228.          rangex = (wide/5)*4;
  229.          hlfrngx = rangex/2;
  230.          rangey = (high/5)*4;
  231.          hlfrngy = rangey/2;
  232.       }
  233.  
  234.       for (i=0; i<NSTARS; i++)
  235.                 mkpoint (i);
  236.  
  237.       FOREVER {
  238.          for (i=0; i<NSTARS; i++) {
  239.             if ((z[i] -= inc) <= 0)
  240.                mkpoint (i);
  241.             xs = x[i] * magic / z[i] + wide / 2;
  242.             ys = y[i] * magic / z[i] + high / 2;
  243.             SetAPen (rp, 0L);
  244.             WritePixel (rp, (long) xo[i], (long) yo[i]);
  245.             if (xs < 1 || xs > wide - 2 || ys < 1 || ys > high - 2)
  246.                mkpoint (i);
  247.             else {
  248.                SetAPen (rp, (long) (256-z[i] >> 4));
  249.                WritePixel (rp, xs, ys);
  250.                xo[i] = xs;  yo[i] = ys;
  251.             }
  252.          }
  253.          if (blanked==FALSE)
  254.          {
  255.             if(w)
  256.             {
  257.                ClearPointer(w);
  258.                CloseWindow(w);
  259.                w=NULL;
  260.             }
  261.             if(s)
  262.             {
  263.                CloseScreen(s);
  264.                s=NULL;
  265.                }
  266.             break;
  267.          }
  268.       }      
  269.    }
  270. }
  271.