home *** CD-ROM | disk | FTP | other *** search
/ The Best of Mecomp Multimedia 1 / Mecomp-CD.iso / amiga / grafic / cyberblanker / source-code / cyberblanker.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-05  |  9.5 KB  |  394 lines

  1.  
  2.    /***********************************************************************
  3.    *                                                                      *
  4.    *                            COPYRIGHTS                                *
  5.    *                                                                      *
  6.    *   Copyright (c) 1997  Zinneberg-Soft  All Rights Reserved.           *
  7.    *                                                                      *
  8.    ***********************************************************************/
  9.  
  10. #include "app.h"
  11. #include "local.h"
  12. #define SCREENWUNSH "PUBSCREEN"
  13. #define DEF_SCREEN "Workbench"
  14. #define DPMS_TOOL "DPMS"
  15. #define DEFAULT_DPMS_SETTING "OFF"
  16. #define FONTNAMEWISH "FONTNAME"
  17. #define DEFAULT_FONTNAME "topaz.font"
  18. #define FONTSIZEWISH "FONTSIZE"
  19. #define DEFAULT_FONTSIZE "8"
  20. #define SCREEN_WANTED_WIDTH  320L
  21. #define SCREEN_WANTED_HEIGHT 200L
  22. #define SCREEN_WANTED_DEPTH   8L
  23. #define SCREEN_MIN_DEPTH      8L
  24. #define BLANK   1L
  25. #define UNBLANK 2L
  26. ULONG NextDepth(ULONG );
  27. ULONG DisplayID,Depth;
  28. ULONG timeout = 0L;
  29. ULONG blanked = 0L;
  30. ULONG seconds = 10L;
  31. ULONG SET_DPMS_GADGET = 5L;
  32. LONG BlankerCommand;
  33.        char  start_fontname = NULL;
  34.        char  start_fontsize = NULL;
  35.        char *fontname_tool_type;
  36.        char *fontsize_tool_type;
  37.   extern struct Custom custom;
  38.   extern struct TextAttr *mydesiredfont;
  39.   struct Screen  *cybscreenasked;
  40.   struct Screen  *CyberScreen = NULL;
  41.   struct Gadget *secgad;
  42.   struct Gadget *dpms_cyclegad;
  43. UBYTE  start_on_publicscreen[MAXPUBSCREENNAME];
  44. int menu_number = NULL;
  45. int DPMS_WANTED = NULL;
  46.  
  47.  
  48. /*****************************************/
  49.  
  50. VOID BlankerAction(struct CxMsg *cxm,CxObj *co);
  51. VOID Blank(VOID);
  52. VOID UnBlank(VOID);
  53. VOID mysetupCustomGadgets(struct Gadget **gad);
  54. BOOL setupBlanker(VOID)
  55. {
  56.  
  57.  char   *dpms_tool_type;
  58.  char   *screen_tool_type;
  59.  CxObj  *objectlist;
  60.    
  61.       seconds = ArgInt( ttypes, "SECONDS", 60 );
  62.  
  63.  
  64.    screen_tool_type = ArgString( ttypes,SCREENWUNSH,DEF_SCREEN);
  65.    strcpy(start_on_publicscreen, screen_tool_type);
  66.  
  67. fontname_tool_type = ArgString( ttypes,FONTNAMEWISH,DEFAULT_FONTNAME);
  68. fontsize_tool_type = ArgString( ttypes,FONTSIZEWISH,DEFAULT_FONTSIZE);
  69.  
  70.   
  71.     dpms_tool_type = ArgString( ttypes,DPMS_TOOL,DEFAULT_DPMS_SETTING);
  72.       if(strcmpi(dpms_tool_type,"OFF")==0)
  73.           {
  74.            SSET_DPMS_OFF();
  75.           }
  76.       if(strcmpi(dpms_tool_type,"H")==0)
  77.           {
  78.            SSET_DPMS_STANDBY();
  79.           }
  80.       if(strcmpi(dpms_tool_type,"V")==0)
  81.           {
  82.            SSET_DPMS_SUSPEND();
  83.           }
  84.  
  85.  
  86.    /********************************************************/
  87.  
  88.   
  89.    objectlist=CxCustom( BlankerAction, 0L);
  90.  
  91.    if (CxObjError(objectlist))
  92.   {
  93.    D( printf("nocapslock: filter error %lx\n", CxObjError(objectlist) ) );
  94.     DeleteCxObjAll(objectlist);
  95.     return(0);
  96.   }
  97.  
  98.    AttachCxObj(broker, objectlist);
  99.    return(TRUE);
  100. }
  101. VOID BlankerAction(struct CxMsg *cxm,CxObj *co)
  102. {
  103.    register struct InputEvent *ie;
  104.  
  105.    /* D( kprintf("BlankerAction\n") ); */
  106.  
  107.    /* i KNOW that all messages getting this far are CXM_IEVENT   */
  108.    ie = (struct InputEvent *) CxMsgData((CxMsg *)cxm);
  109.  
  110.  
  111.    if(ie->ie_Class==IECLASS_TIMER)
  112.    {
  113.       /* D( printf("IECLASS_TIMER\n"); ) */
  114.       if(! blanked)
  115.       {
  116.       /*D( printf("blanked=0x%lx Bump timeout=%ld\n",blanked,timeout);)*/
  117.          if(++timeout >= ((ULONG)(seconds*10L)))
  118.          {
  119.             D( printf("########Blank Screen\n"); )
  120.             /* Blank(); */
  121.             BlankerCommand=BLANK;
  122.             Signal(maintask,csigflag);
  123.             blanked=TRUE;
  124.          }
  125.       }
  126.    } else {
  127.       if(ie->ie_Class!=IECLASS_TIMER)
  128.       {
  129.          D( printf("########UnBlank\n"); )
  130.          /* UnBlank(); */
  131.          BlankerCommand=UNBLANK;
  132.          Signal(maintask,csigflag);
  133.          timeout=0L;
  134.          blanked=FALSE;
  135.       }
  136.    }
  137.  
  138. }
  139. VOID Blank(VOID)
  140. {
  141. /* Let CyberGraphX search a display mode for us! */
  142.  
  143.  Depth=SCREEN_WANTED_DEPTH;
  144.  while (Depth)
  145.   {
  146.    if ((DisplayID=BestCModeIDTags(CYBRBIDTG_NominalWidth, SCREEN_WANTED_WIDTH,
  147.                                   CYBRBIDTG_NominalHeight,SCREEN_WANTED_HEIGHT,
  148.                                   CYBRBIDTG_Depth,Depth,
  149.                                   TAG_DONE))!=INVALID_ID)
  150.     {
  151. /* Because older version of the "cybergraphics.library" don't handle */
  152. /* CYBRBIDTG_Depth properly we query the real depth of the mode.     */
  153.  
  154.      Depth=GetCyberIDAttr(CYBRIDATTR_DEPTH,DisplayID);
  155.      break;
  156.     }
  157. /* retry with less bits per pixel */
  158.    Depth=NextDepth(Depth);
  159.   }
  160.  
  161.  if (Depth<SCREEN_MIN_DEPTH)
  162.   {
  163.    
  164.    ErrorF ("Can't find a suitable Cyberscreen.");
  165.  
  166.   terminate();
  167.   }
  168.  
  169. /* open screen, but let Intuition choose the actual dimensions */
  170.  
  171.  if ((CyberScreen=OpenScreenTags(NULL,
  172.                               SA_DisplayID,DisplayID,
  173.                                  SA_Depth,Depth,
  174.                                  TAG_DONE))==NULL)    
  175.   {
  176.   ErrorF ("Can't open a suitable Cyberscreen.");
  177.   terminate();
  178.   }
  179. CVideoCtrlTags (&CyberScreen->ViewPort,SETVC_DPMSLevel,DPMS_WANTED,TAG_DONE);
  180.  }
  181.  
  182. VOID UnBlank(VOID)
  183. {
  184.    if(CyberScreen)
  185.    {
  186.   CVideoCtrlTags (&CyberScreen->ViewPort,SETVC_DPMSLevel,DPMS_ON,TAG_DONE);
  187.       CloseScreen(CyberScreen);
  188.       CyberScreen=NULL;
  189.    }
  190. }
  191.  
  192. STRPTR MonthLabels[] =
  193. {
  194.       "H",
  195.       "V",
  196.       "H/V",           
  197.        NULL,
  198. };
  199.  
  200. VOID mysetupCustomGadgets(struct Gadget **gad)
  201. {
  202.    struct NewGadget ng;
  203.  
  204.    ng.ng_VisualInfo=vi;
  205.  
  206.     ng.ng_TopEdge    = topborder+32;
  207.     ng.ng_LeftEdge = 110;
  208.    ng.ng_Width      = 60;
  209.     ng.ng_Height = 20;
  210.      ng.ng_GadgetText = " ";
  211.      ng.ng_TextAttr   = mydesiredfont;
  212.     ng.ng_GadgetID = GAD_CYCLE;
  213.     ng.ng_Flags = NG_HIGHLABEL;
  214.     ng.ng_VisualInfo = vi;
  215.     dpms_cyclegad = *gad = CreateGadget(CYCLE_KIND, *gad, &ng,
  216.         GTCY_Labels, MonthLabels,
  217.         GTCY_Active, SET_DPMS_GADGET,
  218.         TAG_DONE);
  219.  
  220.    ng.ng_TopEdge    = topborder+32;
  221.    ng.ng_LeftEdge   = 10;
  222.    ng.ng_Width      = 40;
  223.    ng.ng_Height     = 20;
  224.    ng.ng_GadgetText = "Hide";
  225.    ng.ng_TextAttr   = mydesiredfont;
  226.    ng.ng_GadgetID   = GAD_HIDE;
  227.    ng.ng_Flags      = NULL;
  228.    ng.ng_VisualInfo = vi;
  229.    *gad = CreateGadget(BUTTON_KIND,*gad, &ng,TAG_DONE);
  230.    
  231.    ng.ng_TopEdge    = topborder+32;
  232.    ng.ng_LeftEdge   = 60;
  233.    ng.ng_Width      = 40;
  234.    ng.ng_Height     = 20;
  235.    ng.ng_GadgetText = "Quit";
  236.     ng.ng_TextAttr   = mydesiredfont;
  237.    ng.ng_GadgetID   = GAD_DIE;
  238.    ng.ng_Flags      = NULL;
  239.    ng.ng_VisualInfo = vi;
  240.    *gad = CreateGadget(BUTTON_KIND,*gad, &ng,TAG_DONE);
  241.  
  242.    ng.ng_TopEdge    = topborder+5;
  243.    ng.ng_LeftEdge   = 100;
  244.    ng.ng_Width      = 60;
  245.    ng.ng_Height     = 22;
  246.    ng.ng_GadgetText = "Seconds";
  247.     ng.ng_TextAttr   = mydesiredfont;
  248.    ng.ng_GadgetID   = GAD_SECS;
  249.    ng.ng_Flags      = NULL;
  250.    ng.ng_VisualInfo = vi;
  251.    secgad = *gad = CreateGadget(INTEGER_KIND,*gad, &ng,GTIN_Number,seconds,GTIN_MaxChars,4,STRINGA_Justification,STRINGRIGHT,TAG_DONE);
  252. }
  253.  
  254. VOID myHandleGadget(ULONG gad,ULONG code)
  255. {
  256.  /*  D( kprintf("custom: HandleGadget(%lx)\n",gad); )    */
  257.    switch(gad)
  258.    {
  259.  /****************************************************************/
  260.    case GAD_CYCLE:
  261.  
  262.         {  while (code == 0)
  263.            {
  264.            DPMS_WANTED = DPMS_STANDBY;
  265.            break;
  266.            }
  267.            while (code == 1)
  268.            {
  269.            DPMS_WANTED = DPMS_SUSPEND;
  270.            break;
  271.            }
  272.            while (code == 2)
  273.            {
  274.            DPMS_WANTED = DPMS_OFF;
  275.            break;
  276.            }
  277.  
  278.        }
  279.  
  280.      default: break;
  281.  
  282.  
  283.       case GAD_HIDE:
  284.           /*  D( kprintf("custom: HandleGadget() GAD_HIDE\n"); )   */
  285.             shutdownWindow();
  286.             break;
  287.  
  288.  
  289.       case GAD_DIE:
  290.         /*    D( kprintf("custom: HandleGadget() GAD_DIE\n"); ) */
  291.             terminate();
  292.  
  293.  
  294.       case GAD_SECS:
  295.          /*   D( kprintf("custom: HandleGadget() GAD_SECS\n"); )  */
  296.             seconds=((struct StringInfo *)secgad->SpecialInfo)->LongInt;
  297.            
  298.    }
  299. }
  300.  
  301. VOID MyHandleCustomSignal(VOID)
  302. {
  303.  /*  D( kprintf("custom: MyHandleCustomSignal() enter\n"); )   */
  304.    if(BlankerCommand==BLANK)
  305.       Blank();
  306.    else
  307.       if(BlankerCommand==UNBLANK)
  308.          UnBlank();
  309. }
  310.  
  311.  
  312. ULONG NextDepth(ULONG Depth)
  313. {
  314.  switch (Depth)
  315.   {
  316.    case 24L: /* 24Bit not available? Try 16Bit!      */
  317.     return 16L;
  318.    case 16L: /* 15Bit not available? Try 15Bit!      */
  319.     return 15L;
  320.    default:  /* Not even 15Bit available? Forget it! */
  321.     return 0L;
  322.   }
  323. }
  324.  
  325.  
  326.  
  327. VOID SHOWABOUT()
  328. {
  329.  EasyRequest(NULL,
  330.   &aboutcybereasy,NULL);
  331. }
  332.  
  333. VOID SHOWCONFIG()
  334. {
  335.  EasyRequest(NULL,
  336.   &progconfig,NULL);
  337. }
  338.  /*******************************************/
  339. void ErrorF(char *Format,...)
  340.  
  341. {
  342.  void *Data;
  343.  
  344.  Data= &Format+1L;
  345.  if (((struct Process *)FindTask(NULL))->pr_CLI)
  346.   {
  347.    (void)VPrintf(Format,Data);
  348.    (void)FPutC(Output(),'\n');
  349.    (void)Flush(Output());
  350.   }
  351.  else
  352.   {
  353.    struct EasyStruct EasyStruct;
  354.    ULONG IDCMPFlags;
  355.  
  356.    EasyStruct.es_StructSize=sizeof(struct EasyStruct);
  357.    EasyStruct.es_Flags=0L;
  358.    EasyStruct.es_Title="CyberBlanker FatalError";
  359.    EasyStruct.es_TextFormat=Format;
  360.    EasyStruct.es_GadgetFormat="Ok";
  361.  
  362.    IDCMPFlags=0L;
  363.    (void)EasyRequestArgs(NULL,&EasyStruct,&IDCMPFlags,Data);
  364.   }
  365. }
  366.  
  367.  
  368.  
  369.  /*******************************/
  370. VOID SSET_DPMS_STANDBY()
  371. {
  372. SET_DPMS_GADGET = 0;
  373. DPMS_WANTED = DPMS_STANDBY;
  374.     GT_SetGadgetAttrs(dpms_cyclegad, window, NULL,
  375.     GTCY_Active,  SET_DPMS_GADGET, TAG_DONE);
  376. }
  377.  
  378. VOID SSET_DPMS_OFF()
  379. {
  380. SET_DPMS_GADGET = 2;
  381. DPMS_WANTED = DPMS_OFF;
  382.     GT_SetGadgetAttrs(dpms_cyclegad, window, NULL,
  383.     GTCY_Active,  SET_DPMS_GADGET, TAG_DONE);
  384. }
  385.  
  386.  
  387. VOID SSET_DPMS_SUSPEND()
  388. {
  389. SET_DPMS_GADGET = 1;
  390. DPMS_WANTED = DPMS_SUSPEND;
  391.     GT_SetGadgetAttrs(dpms_cyclegad, window, NULL,
  392.     GTCY_Active,  SET_DPMS_GADGET, TAG_DONE);
  393. }
  394.