home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v1.2 / amidev_cd_12.iso / reference / amiga_mail_vol2 / iv-69 / jumpy.c < prev    next >
C/C++ Source or Header  |  1996-01-30  |  9KB  |  204 lines

  1. ;/* Jumpy.c - Execute me to compile me with SAS/C 6.56
  2. sc DATA=NEAR NMINC STRMERGE STREQ NOSTKCHK SAVEDS IGNORE=73 Jumpy.c
  3. slink FROM LIB:c.o,Jumpy.o TO Jumpy LIBRARY LIB:sc.lib,LIB:amiga.lib
  4. quit
  5. */
  6. /*
  7. Copyright (c) 1991 Commodore-Amiga, Inc.
  8.  
  9. This example is provided in electronic form by Commodore-Amiga,
  10. Inc. for use with the Amiga Mail Volume II technical publication.
  11. Amiga Mail Volume II contains additional information on the correct
  12. usage of the techniques and operating system functions presented in
  13. these examples.  The source and executable code of these examples may
  14. only be distributed in free electronic form, via bulletin board or
  15. as part of a fully non-commercial and freely redistributable
  16. diskette.  Both the source and executable code (including comments)
  17. must be included, without modification, in any copy.  This example
  18. may not be published in printed form or distributed with any
  19. commercial product. However, the programming techniques and support
  20. routines set forth in these examples may be used in the development
  21. of original executable software products for Commodore Amiga
  22. computers.
  23.  
  24. All other rights reserved.
  25.  
  26. This example is provided "as-is" and is subject to change; no
  27. warranties are made.  All use is at your own risk. No liability or
  28. responsibility is assumed.
  29. */
  30.  
  31. #include <intuition/intuition.h>
  32. #include <intuition/screens.h>
  33. #include <graphics/text.h>
  34. #include <libraries/gadtools.h>
  35.  
  36. #ifdef LATTICE
  37. #include <string.h>
  38. #include <clib/alib_protos.h>
  39. #include <clib/exec_protos.h>
  40. #include <clib/intuition_protos.h>
  41. #include <clib/gadtools_protos.h>
  42. #include <clib/graphics_protos.h>
  43. /* disable SAS/C CTRL-C handing */
  44. int             CXBRK(void)
  45. {
  46.     return (0);
  47. }
  48. int             chkabort(void)
  49. {
  50.     return (0);
  51. }
  52.  
  53. #endif
  54.  
  55. struct IntuitionBase *IntuitionBase;
  56. struct GfxBase *GfxBase;
  57. struct Library *GadToolsBase;
  58. struct Library *IconBase;
  59. struct Library *CxBase;
  60.  
  61. LONG            main(LONG, UBYTE **);
  62.  
  63. LONG
  64. main(LONG argc, UBYTE ** argv)
  65. {
  66.     struct Window       *window;
  67.     struct IntuiMessage *imsg;
  68.     struct Gadget       *gadgetcontext;
  69.     struct Gadget       *gadget, *nextscreengadget;
  70.     struct NewGadget     ng;
  71.     struct TextExtent    textextent;
  72.     UWORD                left, top;
  73.     void                *visualinfo;
  74.     UBYTE               *startupname;
  75.     UBYTE                namebuffer[MAXPUBSCREENNAME];
  76.     UBYTE              **tooltypes;
  77.     BOOL                 ABORT = FALSE;
  78.  
  79.     if (IntuitionBase = OpenLibrary("intuition.library", 37))
  80.     {
  81.         /* Open GfxBase to use TextExtent() so we can handle proportional fonts */
  82.         if (GfxBase = OpenLibrary("graphics.library", 37))
  83.         {
  84.             if (GadToolsBase = OpenLibrary("gadtools.library", 37))
  85.             {
  86.  
  87.                 /*
  88.                  * Open commodities & icon.library so we can use ArgArray
  89.                  * functions
  90.                  */
  91.                 if (CxBase = OpenLibrary("commodities.library", 37))
  92.                 {
  93.                     if (IconBase = OpenLibrary("icon.library", 37))
  94.                     {
  95.                         left = 50;
  96.                         top = 50;                /* Initial offset */
  97.                         /* Note that these are functions in amiga.lib */
  98.                         if (tooltypes = ArgArrayInit(argc, argv))
  99.                         {
  100.                             startupname =
  101.                                 ArgString(tooltypes, "PUBSCREEN", "Workbench");
  102.                             strcpy(namebuffer, startupname);
  103.                             ArgArrayDone();
  104.                         }
  105.                         else
  106.                             strcpy(namebuffer, "Workbench");
  107.                         do
  108.                         {
  109.                             /* open a window with tags */
  110.                             /* no NewWindow structure, tags only */
  111.                             if (window = OpenWindowTags(NULL,
  112.                                         /* Open at far left corner */
  113.                                         WA_Left,  left,
  114.                                         WA_Top,   top,
  115.                                         WA_Width, 150,
  116.                                         WA_Height, 80,
  117.                                         WA_Title, (LONG) "jumpy",
  118.                                         WA_PubScreenName, (LONG) namebuffer,
  119.                                         /* if no pubscreen with this name exists... */
  120.                                         WA_PubScreenFallBack, TRUE,
  121.                                         /* ...fall back on default pubscreen */
  122.                                         WA_Flags, WFLG_DRAGBAR | WFLG_DEPTHGADGET |
  123.                                             WFLG_CLOSEGADGET | WFLG_ACTIVATE |
  124.                                             WFLG_SMART_REFRESH | WFLG_NOCAREREFRESH,
  125.                                         WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_GADGETUP,
  126.                                         TAG_DONE))
  127.                             {
  128.  
  129.                                 /*
  130.                                  * Get the visual info gadtools needs for the
  131.                                  * screen we opened on
  132.                                  */
  133.                                 if (visualinfo = GetVisualInfoA(window->WScreen, NULL))
  134.                                 {
  135.  
  136.                                     /*
  137.                                      * Create a simple gadtools button and sort
  138.                                      * of lay it out. Note this doesn't do any
  139.                                      * checking for legal (window) dimensions.
  140.                                      */
  141.                                     if (gadget = CreateContext(&gadgetcontext))
  142.                                     {
  143.  
  144.                                         /*
  145.                                          * Use TextExtent to handle
  146.                                          * proportional fonts
  147.                                          */
  148.                                         TextExtent(&(window->WScreen->RastPort),
  149.                                                    "Jump", 4, &textextent);
  150.                                         ng.ng_Width = textextent.te_Width + 8;
  151.                                         ng.ng_LeftEdge = (window->Width / 2) -
  152.                                                           (ng.ng_Width / 2);
  153.                                         ng.ng_Height = textextent.te_Height + 4;
  154.                                         ng.ng_TopEdge = (
  155.                                             (window->Height - window->BorderTop -
  156.                                                 window->BorderBottom) / 2) +
  157.                                             (ng.ng_Height / 2);
  158.                                         ng.ng_TextAttr = window->WScreen->Font;
  159.                                         ng.ng_GadgetText = "Jump";
  160.                                         ng.ng_VisualInfo = visualinfo;
  161.                                         ng.ng_GadgetID = 1;
  162.                                         ng.ng_Flags = PLACETEXT_IN;
  163.                                         nextscreengadget = gadget =
  164.                                             CreateGadget(BUTTON_KIND, gadget, &ng,
  165.                                                          TAG_END);
  166.                                         AddGList(window, gadget, -1, -1, NULL);
  167.                                         RefreshGList(gadget, window, NULL, -1);
  168.                                         GT_RefreshWindow(window, NULL);
  169.  
  170.                                         WaitPort(window->UserPort);
  171.                                         while (imsg = (struct IntuiMessage *)
  172.                                             GetMsg(window->UserPort))
  173.                                         {
  174.                                             if (imsg->Class == IDCMP_CLOSEWINDOW)
  175.                                                 ABORT = TRUE;
  176.                                             else if (imsg->Class = IDCMP_GADGETUP)
  177.                                                 NextPubScreen(window->WScreen,
  178.                                                               namebuffer);
  179.                                             ReplyMsg((struct Message *) imsg);
  180.                                         }
  181.                                         RemoveGadget(window, nextscreengadget);
  182.                                         FreeGadgets(gadgetcontext);
  183.                                     }
  184.                                     FreeVisualInfo(visualinfo);
  185.                                 }
  186.                                 left = window->LeftEdge;
  187.                                 top = window->TopEdge;
  188.                                 CloseWindow(window);
  189.                             }
  190.                         } while (ABORT == FALSE);
  191.  
  192.                         CloseLibrary(IconBase);
  193.                     }
  194.                     CloseLibrary(CxBase);
  195.                 }
  196.                 CloseLibrary(GadToolsBase);
  197.             }
  198.             CloseLibrary(GfxBase);
  199.         }
  200.         CloseLibrary(IntuitionBase);
  201.     }
  202.     return (0);
  203. }
  204.