home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / dev / cmanual-3.0.lha / CManual / Graphics / Fonts / Example6.c < prev    next >
C/C++ Source or Header  |  1993-10-12  |  12KB  |  341 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:    Example6.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 you can use a font loaded */
  21. /* from a disk in your own Intuition programs.             */
  22.  
  23.  
  24.  
  25. #include <intuition/intuition.h>
  26.  
  27.  
  28. /* Max 50 characters: */
  29. #define MAXCHAR 50
  30.  
  31.  
  32. struct IntuitionBase *IntuitionBase; /* Intuition library. */
  33. struct GfxBase *GfxBase;             /* Graphics library.  */
  34. struct Library *DiskfontBase;        /* DiskFont library.  */
  35.  
  36.  
  37.  
  38. /*****************/
  39. /* THE NEW FONT: */
  40. /*****************/
  41.  
  42. /* The new font's attributes: */
  43. struct TextAttr my_font_attr=
  44. {
  45.   "Helvetica.font", /* Name of the font.  */
  46.   24,               /* Height (in pixels) */
  47.   FS_NORMAL,        /* Style              */
  48.   FPF_DISKFONT      /* Exist on Disk.     */
  49. };
  50.  
  51. /* Pointer to our new font: */
  52. struct TextFont *my_font;
  53.  
  54.  
  55.  
  56. /***********************************/
  57. /* THE STRING GADGET's STRUCTURES: */
  58. /***********************************/
  59.  
  60. /* The coordinates for the box: */
  61. SHORT my_points[]=
  62. {
  63.    -7, -4, /* Start at position (-7, -4) */
  64.   200, -4, /* Draw a line to the right to position (200,-4) */
  65.   200, 11, /* Draw a line down to position (200,11) */
  66.    -7, 11, /* Draw a line to the right to position (-7,11) */
  67.    -7, -4  /* Finish of by drawing a line up to position (-7,-4) */ 
  68. };
  69.  
  70. /* The Border structure: */
  71. struct Border my_border=
  72. {
  73.   0, 0,        /* LeftEdge, TopEdge. */
  74.   1,           /* FrontPen, colour register 1. */
  75.   0,           /* BackPen, for the moment unused. */
  76.   JAM1,        /* DrawMode, draw the lines with colour 1. */
  77.   5,           /* Count, 5 pair of coordinates in the array. */
  78.   my_points,   /* XY, pointer to the array with the coordinates. */
  79.   NULL,        /* NextBorder, no other Border structures are connected. */
  80. };
  81.  
  82. /* The IntuiText structure: */
  83. struct IntuiText my_text=
  84. {
  85.   1,             /* FrontPen, colour register 1. */
  86.   0,             /* BackPen, colour register 0. */
  87.   JAM1,          /* DrawMode, draw the characters with colour 1, do not */
  88.                  /* change the background. */ 
  89.   -65, -8,       /* LeftEdge, TopEdge. */
  90.   &my_font_attr, /* ITextFont, use default font. */
  91.   "Text:",       /* IText, the text that will be printed. */
  92.   NULL,          /* NextText, no other IntuiText structures. */
  93. };
  94. /* Once the font has been loaded you can start to use */
  95. /* the IntuiText structure with a pointer to the new  */
  96. /* font's attributes. Since the text is connected to  */
  97. /* a gadget which is connected to a window, we must   */
  98. /* open the new font BEFORE we open the window!       */
  99.  
  100. UBYTE my_buffer[MAXCHAR];      /* Max nr. characters including the NULL-sign. */
  101. UBYTE my_undo_buffer[MAXCHAR]; /* Must be at least as big as my_buffer.       */
  102.  
  103. struct StringInfo my_string_info=
  104. {
  105.   my_buffer,       /* Buffer, pointer to a null-terminated string. */
  106.   my_undo_buffer,  /* UndoBuffer, pointer to a null-terminated string. */
  107.                    /* (Remember my_buffer is equal to &my_buffer[0]) */
  108.   0,               /* BufferPos, initial position of the cursor. */
  109.   MAXCHAR,         /* MaxChars, (50) characters + null-sign ('\0'). */
  110.   0,               /* DispPos, first character in the string should be */
  111.                    /* first character in the display. */
  112.  
  113.   /* Intuition initializes and maintaines these variables: */
  114.  
  115.   0,               /* UndoPos */
  116.   0,               /* NumChars */
  117.   0,               /* DispCount */
  118.   0, 0,            /* CLeft, CTop */
  119.   NULL,            /* LayerPtr */
  120.   NULL,            /* LongInt */
  121.   NULL,            /* AltKeyMap */
  122. };
  123.  
  124. struct Gadget my_gadget=
  125. {
  126.   NULL,          /* NextGadget, no more gadgets in the list. */
  127.   80,            /* LeftEdge, 80 pixels out. */
  128.   30,            /* TopEdge, 30 lines down. */
  129.   198,           /* Width, 198 pixels wide. */
  130.   8,             /* Height, 8 pixels lines heigh. */
  131.   GADGHCOMP,     /* Flags, draw the select box in the complement */
  132.                  /* colours. Note: it actually only the cursor which */
  133.                  /* will be drawn in the complement colours (yellow). */
  134.                  /* If you set the flag GADGHNONE the cursor will not be */
  135.                  /* highlighted, and the user will therefore not be able */
  136.                  /* to see it. */
  137.   GADGIMMEDIATE| /* Activation, our program will recieve a message when */
  138.   RELVERIFY,     /* the user has selected this gadget, and when the user */
  139.                  /* has released it. */ 
  140.   STRGADGET,     /* GadgetType, a String gadget. */
  141.   (APTR) &my_border, /* GadgetRender, a pointer to our Border structure. */
  142.   NULL,          /* SelectRender, NULL since we do not supply the gadget */
  143.                  /* with an alternative image. */
  144.   &my_text,      /* GadgetText, a pointer to our IntuiText structure. */
  145.   NULL,          /* MutualExclude, no mutual exclude. */
  146.   (APTR) &my_string_info, /* SpecialInfo, a pointer to a StringInfo str. */
  147.   0,             /* GadgetID, no id. */
  148.   NULL           /* UserData, no user data connected to the gadget. */
  149. };
  150.  
  151.  
  152.  
  153. /***************/
  154. /* THE WINDOW: */
  155. /***************/
  156.  
  157. /* Declare a pointer to a Window structure: */ 
  158. struct Window *my_window;
  159.  
  160. /* Declare and initialize your NewWindow structure: */
  161. struct NewWindow my_new_window=
  162. {
  163.   50,              /* LeftEdge    x position of the window. */
  164.   25,              /* TopEdge     y positio of the window. */
  165.   320,             /* Width       320 pixels wide. */
  166.   100,             /* Height      100 lines high. */
  167.   0,               /* DetailPen   Text should be drawn with colour reg. 0 */
  168.   1,               /* BlockPen    Blocks should be drawn with colour reg. 1 */
  169.   CLOSEWINDOW|     /* IDCMPFlags  The window will give us a message if the */
  170.                    /*             user has selected the Close window gad, */
  171.   GADGETDOWN|      /*             or a gadget has been pressed on, or */
  172.   GADGETUP,        /*             a gadge has been released. */
  173.   SMART_REFRESH|   /* Flags       Intuition should refresh the window. */
  174.   WINDOWCLOSE|     /*             Close Gadget. */
  175.   WINDOWDRAG|      /*             Drag gadget. */
  176.   WINDOWDEPTH|     /*             Depth arrange Gadgets. */
  177.   WINDOWSIZING|    /*             Sizing Gadget. */
  178.   ACTIVATE,        /*             The window should be Active when opened. */
  179.   &my_gadget,      /* FirstGadget A pointer to the String gadget. */
  180.   NULL,            /* CheckMark   Use Intuition's default CheckMark. */
  181.   "String Window", /* Title       Title of the window. */
  182.   NULL,            /* Screen      Connected to the Workbench Screen. */
  183.   NULL,            /* BitMap      No Custom BitMap. */
  184.   320,             /* MinWidth    We will not allow the window to become */
  185.   50,              /* MinHeight   smaller than 320 x 50, and not bigger */
  186.   640,             /* MaxWidth    than 640 x 200. */
  187.   200,             /* MaxHeight   */
  188.   WBENCHSCREEN     /* Type        Connected to the Workbench Screen. */
  189. };
  190.  
  191.  
  192. /* Declare our functions: */
  193. void main();
  194. void clean_up();
  195.  
  196.  
  197. /******************************************************************************/
  198.  
  199.  
  200. void main()
  201. {
  202.   /* Boolean variable used for the while loop: */
  203.   BOOL close_m