home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Extras / BOOPSI / GI1 / Examples / LED_Test.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-27  |  4.2 KB  |  164 lines

  1. /*****************************************************************************
  2.  *
  3.  * COPYRIGHT: Unless otherwise noted, all files are Copyright (c) 1992-1999
  4.  * Amiga, Inc. All rights reserved.
  5.  *
  6.  * DISCLAIMER: This software is provided "as is".  No representations or
  7.  * warranties are made with respect to the accuracy, reliability,
  8.  * performance, currentness, or operation of this software, and all use is at
  9.  * your own risk. Neither Amiga nor the authors assume any responsibility
  10.  * or liability whatsoever with respect to your use of this software.
  11.  *
  12.  *****************************************************************************
  13.  * led_test.c
  14.  * test program for the led.image
  15.  * Written by David N. Junod
  16.  *
  17.  */
  18.  
  19. #include <dos/dos.h>
  20. #include <exec/types.h>
  21. #include <exec/libraries.h>
  22. #include <intuition/intuition.h>
  23. #include <intuition/imageclass.h>
  24. #include <intuition/intuitionbase.h>
  25. #include <stdlib.h>
  26. #include <stdio.h>
  27.  
  28. #include <clib/macros.h>
  29. #include <clib/dos_protos.h>
  30. #include <clib/exec_protos.h>
  31. #include <clib/intuition_protos.h>
  32.  
  33. #include <pragmas/dos_pragmas.h>
  34. #include <pragmas/exec_pragmas.h>
  35. #include <pragmas/intuition_pragmas.h>
  36.  
  37. /*****************************************************************************/
  38.  
  39. #define    IDCMP_FLAGS    IDCMP_CLOSEWINDOW | IDCMP_VANILLAKEY | IDCMP_GADGETUP | IDCMP_GADGETDOWN \
  40.             | IDCMP_MOUSEMOVE | IDCMP_INTUITICKS | IDCMP_MOUSEBUTTONS
  41.  
  42. /*****************************************************************************/
  43.  
  44. extern struct Library *SysBase, *DOSBase;
  45. struct Library *IntuitionBase;
  46.  
  47. /*****************************************************************************/
  48.  
  49. struct ClassLibrary *openclass (STRPTR name, ULONG version);
  50.  
  51. /*****************************************************************************/
  52.  
  53. void main (int argc, char **argv)
  54. {
  55.     struct ClassLibrary *imageLib;
  56.     struct IntuiMessage *imsg;
  57.     struct Screen *scr;
  58.     struct Window *win;
  59.     struct Image *im;
  60.     BOOL going = TRUE;
  61.     ULONG sigr;
  62.  
  63.     if (IntuitionBase = OpenLibrary ("intuition.library", 37))
  64.     {
  65.     scr = ((struct IntuitionBase *)IntuitionBase)->FirstScreen;
  66.  
  67.     if (imageLib = openclass ("images/led.image", 37))
  68.     {
  69.         if (win = OpenWindowTags (NULL,
  70.                       WA_Title,        "led.image Test",
  71.                       WA_InnerWidth,    320,
  72.                       WA_InnerHeight,    200,
  73.                       WA_IDCMP,        IDCMP_FLAGS,
  74.                       WA_DragBar,    TRUE,
  75.                       WA_DepthGadget,    TRUE,
  76.                       WA_CloseGadget,    TRUE,
  77.                       WA_SimpleRefresh,    TRUE,
  78.                       WA_NoCareRefresh,    TRUE,
  79.                       WA_Activate,    TRUE,
  80.                       WA_CustomScreen,    scr,
  81.                       TAG_DONE))
  82.         {
  83.         /* Create the led image */
  84.         if (im = NewObject (NULL, "led.image",
  85.  
  86.                     IA_FGPen,    1,
  87.                     IA_BGPen,    0,
  88.                     IA_Width,    200,
  89.                     IA_Height,    100,
  90.                     TAG_DONE))
  91.         {
  92.             /* Draw the image */
  93.             DrawImage (win->RPort, im, win->BorderLeft + 20, win->BorderTop + 20);
  94.  
  95.             while (going)
  96.             {
  97.             sigr = Wait ((1L << win->UserPort->mp_SigBit | SIGBREAKF_CTRL_C));
  98.  
  99.             if (sigr & SIGBREAKF_CTRL_C)
  100.                 going = FALSE;
  101.  
  102.             while (imsg = (struct IntuiMessage *) GetMsg (win->UserPort))
  103.             {
  104.                 switch (imsg->Class)
  105.                 {
  106.                 case IDCMP_CLOSEWINDOW:
  107.                     going = FALSE;
  108.                     break;
  109.  
  110.                 case IDCMP_VANILLAKEY:
  111.                     switch (imsg->Code)
  112.                     {
  113.                     case  27:
  114.                     case 'q':
  115.                     case 'Q':
  116.                         going = FALSE;
  117.                         break;
  118.                     }
  119.                     break;
  120.  
  121.                 }
  122.  
  123.                 ReplyMsg ((struct Message *) imsg);
  124.             }
  125.             }
  126.             DisposeObject (im);
  127.         }
  128.  
  129.         CloseWindow (win);
  130.         }
  131.         else
  132.         Printf ("couldn't open the window\n");
  133.  
  134.         CloseLibrary ((struct Library *) imageLib);
  135.     }
  136.     else
  137.         Printf ("couldn't open classes:images/led.image\n");
  138.  
  139.     CloseLibrary (IntuitionBase);
  140.     }
  141. }
  142.  
  143.  
  144. /*****************************************************************************/
  145.  
  146. /* Try opening the class library from a number of common places */
  147. struct ClassLibrary *openclass (STRPTR name, ULONG version)
  148. {
  149.     struct ExecBase *SysBase = (*((struct ExecBase **) 4));
  150.     struct Library *retval;
  151.     UBYTE buffer[256];
  152.  
  153.     if ((retval = OpenLibrary (name, version)) == NULL)
  154.     {
  155.     sprintf (buffer, ":classes/%s", name);
  156.     if ((retval = OpenLibrary (buffer, version)) == NULL)
  157.     {
  158.         sprintf (buffer, "classes/%s", name);
  159.         retval = OpenLibrary (buffer, version);
  160.     }
  161.     }
  162.     return (struct ClassLibrary *) retval;
  163. }
  164.