home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Reader's Corner / Reader's Contibutions / David Hart / Source Code / SystemInfo 2.0 / SystemInfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-21  |  5.9 KB  |  213 lines  |  [TEXT/KAHL]

  1. /*
  2.     Filename    SystemInfo.c
  3.     Copyright © 1993 David Hart. All rights reserved.
  4.     Author        David Hart
  5.     Description    SystemInfo module for After Dark
  6.     
  7.     Version      Date        Comments
  8.     2.00    18/03/93    Original Version for After Dark 2.0
  9.     2.01    22/03/93    To display the Blank Region enclosing rect
  10. */
  11.  
  12. #include <QuickDraw.h>
  13. #include <Memory.h>
  14. #include <OSUtils.h>
  15. #include "GraphicsModule_Types.h"
  16.  
  17. /* Function prototypes */
  18. void    ShowBoolean(int h, int v, int bool, Str255 str);
  19. void    ShowRect(int h, int v, Rect rect);
  20.  
  21. /* Specific graphics module data structures */
  22. typedef struct MyStorage
  23.     {
  24.     int    dummy;
  25.     } MyStorage, *MyStoragePtr, **MyStorageHandle;
  26.  
  27. /*
  28.     DoInitialize is the first function called from After Dark.
  29.     Memory for the structure is allocated and the variables are initialized.
  30.     The allocated memory is assigned to "storage"
  31.     and the function returns "noErr" if there are no problems.
  32. */
  33. OSErr    DoInitialize(Handle *storage, RgnHandle blankRgn, GMParamBlockPtr params)
  34.     {
  35.     MyStorageHandle myStorage;
  36.     
  37.     /* allocate handle to my storage */
  38.     myStorage = (MyStorageHandle)NewHandle(sizeof(MyStorage));
  39.     
  40.     if (!myStorage)
  41.         return MemError();
  42.     
  43.     MoveHHi(myStorage);
  44.     HLock(myStorage);                    /* Lock it down */
  45.     
  46.     *storage = (Handle)myStorage;        /* Assign myStorage to passed handle */
  47.  
  48.     HUnlock(myStorage);
  49.     return noErr;
  50.     }
  51.  
  52. /*  
  53.     DoBlank is the next function called.
  54.     It is used to simply blank the screen.
  55. */ 
  56. OSErr    DoBlank(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params)
  57.     {
  58.     FillRgn(blankRgn, params->qdGlobalsCopy->qdWhite); /* fill white */
  59.     return noErr;
  60.     }
  61.  
  62. /*
  63.     DoDrawFrame does almost all of the work.
  64. */
  65. OSErr    DoDrawFrame(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params)
  66.     {
  67.     OSErr err = noErr;
  68.     MyStoragePtr myStorage;                /* to hold dereferenced storage handle */
  69.     int    h = 10;
  70.     int    v = 0;
  71.     Str255    str;
  72.     int    monitor;
  73.  
  74.     /* Lock our storage down so we can dereference it once for faster access */
  75.     MoveHHi(storage);
  76.     HLock(storage);
  77.     myStorage = (MyStoragePtr)*storage;
  78.     
  79.     TextFont(monaco);
  80.     TextSize(9);
  81.     
  82.     /* Blank Region Enclosing Rect */
  83.     MoveTo(h, v+=12);
  84.     DrawString("\pBlank Region Rect:");
  85.     ShowRect(h+h, v+=12, (**blankRgn).rgnBBox);
  86.     
  87.     /* Monitors */            
  88.     MoveTo(h, v+=12);
  89.     DrawString("\pNumber of Monitors: ");
  90.     NumToString(params->monitors->monitorCount, str);
  91.     DrawString(str);
  92.     
  93.     /* For each monitor */
  94.     for (monitor = 0; monitor < params->monitors->monitorCount; monitor++)
  95.         {
  96.         MoveTo(h, v+=12);
  97.         DrawString("\pMonitor: ");
  98.         NumToString(monitor+1, str);
  99.         DrawString(str);
  100.         ShowRect(h+h, v+=12, params->monitors->monitorList[monitor].bounds);
  101.         DrawString("\p Current depth: ");
  102.         NumToString(params->monitors->monitorList[monitor].curDepth, str);
  103.         DrawString(str);
  104.         }
  105.     
  106.     /* Color QuickDraw Available */
  107.     ShowBoolean(h+h, v+=12, params->colorQDAvail, "\pColor QuickDraw Available: ");
  108.     
  109.     /* System Config */
  110.     MoveTo(h, v+=12);
  111.     DrawString("\pSystem Config: ");
  112.     ShowBoolean(h+h, v+=12, params->systemConfig & 1L,         "\pMac has Color QuickDraw: ");
  113.     ShowBoolean(h+h, v+=12, params->systemConfig & (1L << 1),  "\pA monitor set to greater than 1 bit: ");
  114.     ShowBoolean(h+h, v+=12, params->systemConfig & (1L << 2),  "\pAll monitors set to greater than 1 bit: ");
  115.     ShowBoolean(h+h, v+=12, params->systemConfig & (1L << 3),  "\pA monitor in color mode: ");
  116.     ShowBoolean(h+h, v+=12, params->systemConfig & (1L << 4),  "\pAll monitors in color mode: ");
  117.     ShowBoolean(h+h, v+=12, params->systemConfig & (1L << 5),  "\pA monitor is a CLUT device: ");
  118.     ShowBoolean(h+h, v+=12, params->systemConfig & (1L << 6),  "\pAll monitors are CLUT devices: ");
  119.     ShowBoolean(h+h, v+=12, params->systemConfig & (1L << 7),  "\pAll monitors can dim: ");
  120.     ShowBoolean(h+h, v+=12, params->systemConfig & (1L << 8),  "\pThe main monitor can dim: ");
  121.     ShowBoolean(h+h, v+=12, params->systemConfig & (1L << 9),  "\pModule may not animate the color table: ");
  122.     ShowBoolean(h+h, v+=12, params->systemConfig & (1L << 10), "\pMulti module running: ");
  123.     ShowBoolean(h+h, v+=12, params->systemConfig & (1L << 14), "\pModule is running under version 2.0u or later: ");
  124.     ShowBoolean(h+h, v+=12, params->systemConfig & (1L << 15), "\pThis version of After Dark supports sound: ");
  125.     
  126.     /* QuickDraw Globals */
  127.     MoveTo(h, v+=12);
  128.     DrawString("\pQuickDraw Globals:");
  129.     ShowRect(h+h, v+=12, params->qdGlobalsCopy->qdThePort->portRect);
  130.     
  131.     /* Demo Rect */
  132.     MoveTo(h, v+=12);
  133.     DrawString("\pDemo Rect:");
  134.     ShowRect(h+h, v+=12, params->demoRect);
  135.     
  136.     /* After Dark Version */
  137.     MoveTo(h, v+=12);
  138.     DrawString("\pAfter Dark Version: ");
  139.     NumToString((params->adVersion & 0xFF00) >> 8, str);
  140.     DrawString(str);
  141.     DrawString("\p.");
  142.     NumToString((params->adVersion & 0x00FF), str);
  143.     DrawString(str);
  144.     
  145.     HUnlock(storage);
  146.     return noErr;
  147.     }
  148.  
  149. /*
  150.     DoClose is called when the user quits the screen saver.
  151.     The memory is deallocated and the function returns "MemError"
  152.     which will tell After Dark if there was a problem
  153. */
  154. OSErr    DoClose(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params)
  155.     {
  156.     MyStorageHandle myStorage = (MyStorageHandle)storage;
  157.         
  158.     /* Deallocate our storage */
  159.     if (myStorage)
  160.         {
  161.         MoveHHi(myStorage);
  162.         HLock(myStorage);
  163.         DisposHandle(storage);
  164.         }
  165.     
  166.     /* check for memory errors */
  167.     return MemError();
  168.     }
  169.  
  170. /*
  171.     DoSetUp is called if the user clicks on a button in the Control Panel.
  172. */
  173. OSErr    DoSetUp(RgnHandle blankRgn, short message, GMParamBlockPtr params)
  174.     {
  175.     return noErr;
  176.     }
  177.  
  178. /*
  179.     ShowBoolean displays boolean value as Yes or No
  180. */
  181. void    ShowBoolean(int h, int v, int bool, Str255 str)
  182.     {
  183.     MoveTo(h, v);
  184.     DrawString(str);
  185.     MoveTo(h+300, v);
  186.     if (bool)
  187.         DrawString("\pYes");
  188.     else
  189.         DrawString("\pNo");
  190.     }
  191.  
  192. /*
  193.     ShowRect displays rect coords
  194. */
  195. void    ShowRect(int h, int v, Rect rect)
  196.     {
  197.     Str255    str;
  198.     
  199.     MoveTo(h, v);
  200.     DrawString("\pLeft: ");
  201.     NumToString(rect.left, str);
  202.     DrawString(str);
  203.     DrawString("\p  Top: ");
  204.     NumToString(rect.top, str);
  205.     DrawString(str);
  206.     DrawString("\p  Right: ");
  207.     NumToString(rect.right, str);
  208.     DrawString(str);
  209.     DrawString("\p  Bottom: ");
  210.     NumToString(rect.bottom, str);
  211.     DrawString(str);
  212.     }
  213.