home *** CD-ROM | disk | FTP | other *** search
/ World of A1200 / World_Of_A1200.iso / datafiles / text / c_manual / graphics / fonts / example1.c < prev    next >
C/C++ Source or Header  |  1995-02-27  |  7KB  |  208 lines

  1. /***********************************************************/
  2. /*                                                         */
  3. /* Amiga C Encyclopedia (ACE) V3.0      Amiga C Club (ACC) */
  4. /* -------------------------------      ------------------ */
  5. /*                                                         */
  6. /* Book:    ACM Graphics                Amiga C Club       */
  7. /* Chapter: Fonts                       Tulevagen 22       */
  8. /* File:    Example1.c                  181 41  LIDINGO    */
  9. /* Author:  Anders Bjerin               SWEDEN             */
  10. /* Date:    92-04-28                                       */
  11. /* Version: 1.00                                           */
  12. /*                                                         */
  13. /*   Copyright 1992, Anders Bjerin - Amiga C Club (ACC)    */
  14. /*                                                         */
  15. /* Registered members may use this program freely in their */
  16. /*     own commercial/noncommercial programs/articles.     */
  17. /*                                                         */
  18. /***********************************************************/
  19.  
  20. /* This example demonstrates how to open the ROM font "Topaz". (Topaz is */
  21. /* the standard system font, and is placed in ROM on all Amigas. If you  */
  22. /* have told preferences to use a 60-character display the 9 pixel size  */
  23. /* will be used, else (80-character display) the 8 pixel size will be    */
  24. /* used. This example prints some text in both sizes.                    */
  25.  
  26.  
  27.  
  28. #include <intuition/intuitionbase.h>
  29.  
  30.  
  31.  
  32. struct Intuition *IntuitionBase; /* Running under Intuition. */
  33. struct GfxBase *GfxBase;         /* Move() and Text().       */
  34.  
  35.  
  36.  
  37. /* The new font's attributes: */
  38. struct TextAttr my_font_attr=
  39. {
  40.   "topaz.font", /* Name of the font.  */
  41.   9,            /* Height (in pixels) */
  42.   FS_NORMAL,    /* Style              */
  43.   FPF_ROMFONT   /* Exist in ROM.      */
  44. };
  45.  
  46. /* Pointer to our new font: */
  47. struct TextFont *my_font;
  48.  
  49.  
  50.  
  51. /* Declare a pointer to a Window structure: */ 
  52. struct Window *my_window;
  53.  
  54. /* Declare and initialize your NewWindow structure: */
  55. struct NewWindow my_new_window=
  56. {
  57.   0,             /* LeftEdge    x position of the window. */
  58.   12,            /* TopEdge     y positio of the window. */
  59.   640,           /* Width       640 pixels wide. */
  60.   100,           /* Height      100 lines high. */
  61.   0,             /* DetailPen   Text should be drawn with colour reg. 0 */
  62.   1,             /* BlockPen    Blocks should be drawn with colour reg. 1 */
  63.   CLOSEWINDOW,   /* IDCMPFlags  The window will give us a message if the */
  64.                  /*             user has selected the Close window gad. */
  65.   SMART_REFRESH| /* Flags       Intuition should refresh the window. */
  66.   WINDOWCLOSE|   /*             Close Gadget. */
  67.   WINDOWDRAG|    /*             Drag gadget. */
  68.   WINDOWDEPTH|   /*             Depth arrange Gadgets. */
  69.   ACTIVATE,      /*             The window should be Active when opened. */
  70.   NULL,          /* FirstGadget No Custom gadgets. */
  71.   NULL,          /* CheckMark   Use Intuition's default CheckMark. */
  72.   "FONT EXAMPLE (TOPAZ)",       /* Title       Title of the window. */
  73.   NULL,          /* Screen      Connected to the Workbench Screen. */
  74.   NULL,          /* BitMap      No Custom BitMap. */
  75.   0,             /* MinWidth    No sizing gadget. */
  76.   0,             /* MinHeight          -"-        */
  77.   0,             /* MaxWidth           -"-        */
  78.   0,             /* MaxHeight          -"-        */
  79.   WBENCHSCREEN   /* Type        Connected to the Workbench Screen. */
  80. };
  81.  
  82.  
  83.  
  84. void main();
  85. void clean_up();
  86.  
  87. void main()
  88. {
  89.   BOOL close_me;                   /* Used in the loop.       */
  90.   ULONG class;                     /* IDCMP flag.             */
  91.   struct IntuiMessage *my_message; /* IntuiMessage structure. */
  92.  
  93.  
  94.   /* Open the necessary libraries: */
  95.   IntuitionBase = (struct IntuitionBase *)
  96.     OpenLibrary( "intuition.library", 0 );
  97.   if( !IntuitionBase )
  98.     clean_up( "Could not open Intuition library!" );
  99.  
  100.   GfxBase = (struct GfxBase *)
  101.     OpenLibrary( "graphics.library", 0 );
  102.   if( !GfxBase )
  103.     clean_up( "Could not open Graphics library!" );
  104.  
  105.  
  106.   /* Open a window in which we will display the new font: */
  107.   my_window = (struct Window *) OpenWindow( &my_new_window );
  108.   
  109.   /* Have we opened the window succesfully? */
  110.   if(my_window == NULL)
  111.     clean_up( "Could not open the window!" );
  112.  
  113.  
  114.   /* Set colour and draw mode: */
  115.   SetAPen( my_window->RPort, 1 );
  116.   SetDrMd( my_window->RPort, JAM1 );
  117.  
  118.  
  119.   /* Try to open a ROM font: */
  120.   my_font = (struct TextFont *)
  121.     OpenFont( &my_font_attr );
  122.  
  123.   /* Have we opened the font successfully? */
  124.   if( !my_font )
  125.     clean_up( "Could not open the font \"Topaz 9\"!" );
  126.  
  127.  
  128.   /* Change the window's default font: */
  129.   SetFont( my_window->RPort, my_font );
  130.  
  131.  
  132.   /* Position the cursor, and print some characters: */
  133.   Move( my_window->RPort, 5, 25 );
  134.   Text( my_window->RPort, "Topaz, 9 pixels high.", 21 );
  135.  
  136.  
  137.   /* Change the size to 8 pixels high: */
  138.   my_font_attr.ta_YSize = 8;
  139.  
  140.  
  141.   /* Try to open another ROM font: */
  142.   my_font = (struct TextFont *)
  143.     OpenFont( &my_font_attr );
  144.  
  145.   /* Have we opened the font successfully? */
  146.   if( !my_font )
  147.     clean_up( "Could not open the font \"Topaz 8\"!" );
  148.  
  149.  
  150.   /* Change the window's default font: */
  151.   SetFont( my_window->RPort, my_font );
  152.  
  153.  
  154.   /* Position the cursor, and print some characters: */
  155.   Move( my_window->RPort, 5, 35 );
  156.   Text( my_window->RPort, "Topaz, 8 pixels high.", 21 );
  157.  
  158.  
  159.   /* Wait until the user closes the window: */
  160.   close_me = FALSE;
  161.   while( close_me == FALSE )
  162.   {
  163.     /* Wait until we have recieved a message: */
  164.     Wait( 1 << my_window->UserPort->mp_SigBit );
  165.  
  166.     /* Collect the message: */
  167.     while( (my_message = (struct IntuiMessage *) GetMsg( my_window->UserPort )) )
  168.     {
  169.       /* After we have collected the message we can read it, and save any */
  170.       /* important values which we maybe want to check later: */
  171.       class = my_message->Class;
  172.  
  173.       /* After we have read it we reply as fast as possible: */
  174.       /* REMEMBER! Do never try to read a message after you have replied! */
  175.       /* Some other process has maybe changed it. */
  176.       ReplyMsg( my_message );
  177.  
  178.       /* Check which IDCMP flag was sent: */
  179.       if( class == CLOSEWINDOW )
  180.         close_me=TRUE; /* The user selected the Close window gadget! */  
  181.     }
  182.   }
  183.  
  184.  
  185.   clean_up( "The End" );
  186. }
  187.  
  188. void clean_up( message )
  189. STRPTR message;
  190. {
  191.   if( my_window )
  192.     CloseWindow( my_window );
  193.  
  194.   if( my_font )
  195.     CloseFont( my_font );
  196.  
  197.   if( GfxBase )
  198.     CloseLibrary( GfxBase );
  199.  
  200.   if( IntuitionBase )
  201.     CloseLibrary( IntuitionBase );
  202.   
  203.   printf( "%s\n", message );
  204.  
  205.   exit();
  206. }
  207.  
  208.