home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 377a.lha / libraries / graphics / text / Wrapper.c < prev   
Encoding:
C/C++ Source or Header  |  1980-02-04  |  5.1 KB  |  182 lines

  1. /* Wrapper
  2.    Support routines needed by Text chapter examples.
  3.    Insert routine(s) where indicated below, then compile, link, and run.
  4.    For Lattice, compile and link with:  LC -b1 -cfist -L -v -y Wrapper.c
  5.  
  6.    Copyright (c) 1990 Commodore-Amiga, Inc.
  7.   
  8.    This example is provided in electronic form by Commodore-Amiga, Inc. for
  9.    use with the 1.3 revisions of the Addison-Wesley Amiga reference manuals. 
  10.    The 1.3 Addison-Wesley Amiga Reference Manual series contains additional
  11.    information on the correct usage of the techniques and operating system
  12.    functions presented in this example.  The source and executable code of
  13.    this example may only be distributed in free electronic form, via bulletin
  14.    board or as part of a fully non-commercial and freely redistributable
  15.    diskette.  Both the source and executable code (including comments) must
  16.    be included, without modification, in any copy.  This example may not be
  17.    published in printed form or distributed with any commercial product.
  18.    However, the programming techniques and support routines set forth in
  19.    this example may be used in the development of original executable
  20.    software products for Commodore Amiga computers.
  21.    All other rights reserved.
  22.    This example is provided "as-is" and is subject to change; no warranties
  23.    are made.  All use is at your own risk.  No liability or responsibility
  24.    is assumed.
  25. */
  26.  
  27. #include <exec/types.h>
  28. #include <exec/memory.h>
  29. #include <exec/ports.h>
  30. #include <exec/nodes.h>
  31. #include <graphics/text.h>
  32. #include <graphics/rastport.h>
  33. #include <graphics/gfxbase.h>
  34. #include <intuition/intuitionbase.h>
  35. #include <libraries/dos.h>
  36. #include <libraries/diskfont.h>
  37. #include <proto/all.h>
  38. #include <stdlib.h>
  39. #include <stdio.h>
  40. #include <string.h>
  41.  
  42. /* Library pointers.
  43.    Pointers are initialized to NULL so that the Close...()
  44.    and Free...() routines can tell whether the pointers were used.
  45. */
  46.  
  47. struct GfxBase *GfxBase = NULL;
  48. struct IntuitionBase *IntuitionBase = NULL;
  49. struct Library *DiskfontBase = NULL;
  50.  
  51. /*  The Workbench pen color registers.  */
  52. #define COLOR0 0
  53. #define COLOR1 1
  54. #define COLOR2 2
  55. #define COLOR3 3
  56.  
  57. /*  do/don't wait for the user to click the close gadget before exiting.  */
  58. #define WAIT_FOR_CLOSE  FALSE
  59. #define DONT_WAIT       TRUE
  60.  
  61. /*
  62.    Set the titlebar of the specified Window (w) to the specified string (s).
  63. */
  64. #define TITLE(w, s) (SetWindowTitles((w), (UBYTE *)(s), (UBYTE *)~0))
  65.  
  66.  
  67. /*
  68.     ======================================================================
  69.                       INSERT EXAMPLE CODE AFTER HERE
  70.     ======================================================================
  71. */
  72.  
  73.  
  74. /*
  75.     ======================================================================
  76.                       INSERT EXAMPLE CODE BEFORE HERE
  77.     ======================================================================
  78. */
  79.  
  80.  
  81. /*
  82.    Open the graphics, intuition, and diskfont libraries.
  83.    Return TRUE if completely successful, FALSE otherwise.
  84. */
  85. BOOL openLibs(VOID)
  86. {
  87. GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 33L);
  88. if (GfxBase)
  89.     {
  90.     IntuitionBase =
  91.         (struct IntuitionBase *)OpenLibrary("intuition.library", 33L);
  92.     if (IntuitionBase)
  93.         {
  94.         DiskfontBase = OpenLibrary("diskfont.library", 33L);
  95.         if (DiskfontBase)
  96.             return(TRUE);
  97.         }
  98.     }
  99. return(FALSE);
  100. }
  101.  
  102.  
  103. /*
  104.    Open a half-height, full-width window on the Workbench screen.
  105.    Return a Window pointer if successful, NULL otherwise.
  106. */
  107. struct Window *doWindow(VOID)
  108. {
  109. static struct NewWindow nw =
  110.     {
  111.     0, 0, 0, 0, -1, -1, CLOSEWINDOW,
  112.     WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG|SMART_REFRESH|ACTIVATE|GIMMEZEROZERO,
  113.     NULL, NULL, NULL, NULL, NULL, ~0, ~0, ~0, ~0, WBENCHSCREEN
  114.     };
  115. struct Window *window;
  116.  
  117. nw.Height = GfxBase->NormalDisplayRows / 2;
  118. nw.Width  = GfxBase->NormalDisplayColumns;
  119. window = OpenWindow(&nw);
  120. return(window);
  121. }
  122.  
  123.  
  124. /*
  125.    If requested, wait for the user to click on the Window's close gadget.
  126.    Reply to any messages which may have accumulated, and close the Window.
  127. */
  128. VOID undoWindow(struct Window *window, BOOL immediate)
  129. {
  130. struct IntuiMessage *intuiMessage;
  131. if (window)
  132.     {
  133.     if (! immediate)
  134.         (VOID) Wait(1<<window->UserPort->mp_SigBit);
  135.     while (intuiMessage = (struct IntuiMessage *)GetMsg(window->UserPort))
  136.         ReplyMsg((struct Message *)intuiMessage);
  137.     CloseWindow(window);
  138.     }
  139. }
  140.  
  141.  
  142. /*
  143.    Close any libraries opened in openLibs().
  144. */
  145. VOID closeLibs(VOID)
  146. {
  147. if (DiskfontBase)
  148.     CloseLibrary(DiskfontBase);
  149. if (IntuitionBase)
  150.     CloseLibrary((struct Library *)IntuitionBase);
  151. if (GfxBase)
  152.     CloseLibrary((struct Library *)GfxBase);
  153. }
  154.  
  155.  
  156. /*
  157.    Open the libraries, open a window, and call the example routine.
  158.    Returns one of several values to the calling environment:
  159.    RETURN_OK if successful, RETURN_ERROR if unable to open a window,
  160.    and RETURN_FAIL if unable to open the needed libraries.
  161. */
  162. VOID main(int argc, char *argv[])
  163. {
  164. int exitVal = RETURN_OK;
  165. BOOL immediate = TRUE;
  166. struct Window *window = NULL;
  167.  
  168. if (openLibs())
  169.     {
  170.     if (window = doWindow())
  171.         immediate = example(window);
  172.     else
  173.         exitVal = RETURN_ERROR;
  174.     undoWindow(window, immediate);
  175.     }
  176. else
  177.     exitVal = RETURN_FAIL;
  178. closeLibs();
  179. exit(exitVal);
  180. }
  181.  
  182.