home *** CD-ROM | disk | FTP | other *** search
- /***********************************************************/
- /* */
- /* Amiga C Encyclopedia (ACE) V3.0 Amiga C Club (ACC) */
- /* ------------------------------- ------------------ */
- /* */
- /* Book: ACM Graphics Amiga C Club */
- /* Chapter: Fonts Tulevagen 22 */
- /* File: Example2.c 181 41 LIDINGO */
- /* Author: Anders Bjerin SWEDEN */
- /* Date: 92-04-28 */
- /* Version: 1.00 */
- /* */
- /* Copyright 1992, Anders Bjerin - Amiga C Club (ACC) */
- /* */
- /* Registered members may use this program freely in their */
- /* own commercial/noncommercial programs/articles. */
- /* */
- /***********************************************************/
-
- /* This example demonstrates how to change the style of */
- /* a font. We will open the ROM font "Topaz" and change */
- /* the style to underlined, bold and italic. Well, we */
- /* try to use all mentioned styles, but it may happen */
- /* that we are not allowed to use some styles. */
-
-
-
- #include <intuition/intuitionbase.h>
-
-
- struct Intuition *IntuitionBase; /* Running under Intuition. */
- struct GfxBase *GfxBase; /* Move() and Text(). */
-
-
- /* The new font's attributes: */
- struct TextAttr my_font_attr=
- {
- "topaz.font", /* Name of the font. */
- 8, /* Height (in pixels) */
- FS_NORMAL, /* Style */
- FPF_ROMFONT /* Exist in ROM. */
- };
-
- /* Pointer to our new font: */
- struct TextFont *my_font;
-
-
-
- /* Declare a pointer to a Window structure: */
- struct Window *my_window;
-
- /* Declare and initialize your NewWindow structure: */
- struct NewWindow my_new_window=
- {
- 0, /* LeftEdge x position of the window. */
- 12, /* TopEdge y positio of the window. */
- 640, /* Width 640 pixels wide. */
- 100, /* Height 100 lines high. */
- 0, /* DetailPen Text should be drawn with colour reg. 0 */
- 1, /* BlockPen Blocks should be drawn with colour reg. 1 */
- CLOSEWINDOW, /* IDCMPFlags The window will give us a message if the */
- /* user has selected the Close window gad. */
- SMART_REFRESH| /* Flags Intuition should refresh the window. */
- WINDOWCLOSE| /* Close Gadget. */
- WINDOWDRAG| /* Drag gadget. */
- WINDOWDEPTH| /* Depth arrange Gadgets. */
- ACTIVATE, /* The window should be Active when opened. */
- NULL, /* FirstGadget No Custom gadgets. */
- NULL, /* CheckMark Use Intuition's default CheckMark. */
- "Nice Style!", /* Title Title of the window. */
- NULL, /* Screen Connected to the Workbench Screen. */
- NULL, /* BitMap No Custom BitMap. */
- 0, /* MinWidth No sizing gadget. */
- 0, /* MinHeight -"- */
- 0, /* MaxWidth -"- */
- 0, /* MaxHeight -"- */
- WBENCHSCREEN /* Type Connected to the Workbench Screen. */
- };
-
-
-
- void main();
- void clean_up();
-
- void main()
- {
- BOOL close_me; /* Used in the loop. */
- ULONG class; /* IDCMP flag. */
- struct IntuiMessage *my_message; /* IntuiMessage structure. */
-
-
- UWORD style; /* Desired style. */
- UWORD a_style; /* Styles allowed. */
- UWORD new_style; /* Style we got. */
-
-
- /* Open the necessary libraries: */
- IntuitionBase = (struct IntuitionBase *)
- OpenLibrary( "intuition.library", 0 );
- if( !IntuitionBase )
- clean_up( "Could not open Intuition library!" );
-
- GfxBase = (struct GfxBase *)
- OpenLibrary( "graphics.library", 0 );
- if( !GfxBase )
- clean_up( "Could not open Graphics library!" );
-
-
- /* Open a window in which we will display the new font: */
- my_window = (struct Window *) OpenWindow( &my_new_window );
-
- /* Have we opened the window succesfully? */
- if(my_window == NULL)
- clean_up( "Could not open the window!" );
-
-
-
- /* Set colour and draw mode: */
- SetAPen( my_window->RPort, 1 );
- SetDrMd( my_window->RPort, JAM1 );
-
- /* Try to open a ROM font: */
- my_font = (struct TextFont *)
- OpenFont( &my_font_attr );
-
- /* Have we opened the font successfully? */
- if( !my_font )
- clean_up( "Could not open the font \"Topaz 9\"!" );
-
- /* Change the window's default font: */
- SetFont( my_window->RPort, my_font );
-
- /* Set the desired style: */
- style = FSF_UNDERLINED | FSF_BOLD | FSF_ITALIC;
-
- /* Check which styles we may use: */
- a_style = AskSoftStyle( my_window->RPort );
-
- /* Change the window's font style: */
- new_style = SetSoftStyle( my_window->RPort, style, a_style );
-
- /* Tell the user what style we will use: */
- printf( "Style:" );
- if( new_style )
- printf( "%s%s%s!\n",
- new_style & FSF_UNDERLINED ? " Underlined" : "",
- new_style & FSF_BOLD ? " Bold" : "",
- new_style & FSF_ITALIC ? " Italic" : "" );
- else
- printf( " normal\n!" );
-
- /* Position the cursor, and print some characters: */
- Move( my_window->RPort, 5, 35 );
- Text( my_window->RPort, "ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890", 37 );
- Move( my_window->RPort, 5, 50 );
- Text( my_window->RPort, "abcdefghijklmnopqrstuvwxyz !@#$%^&*()", 37 );
-
-
-
- /* Wait until the user closes the window: */
- close_me = FALSE;
- while( close_me == FALSE )
- {
- /* Wait until we have recieved a message: */
- Wait( 1 << my_window->UserPort->mp_SigBit );
-
- /* Collect the message: */
- while( (my_message = (struct IntuiMessage *) GetMsg( my_window->UserPort )) )
- {
- /* After we have collected the message we can read it, and save any */
- /* important values which we maybe want to check later: */
- class = my_message->Class;
-
- /* After we have read it we reply as fast as possible: */
- /* REMEMBER! Do never try to read a message after you have replied! */
- /* Some other process has maybe changed it. */
- ReplyMsg( my_message );
-
- /* Check which IDCMP flag was sent: */
- if( class == CLOSEWINDOW )
- close_me=TRUE; /* The user selected the Close window gadget! */
- }
- }
-
-
- clean_up( "The End" );
- }
-
- void clean_up( message )
- STRPTR message;
- {
- if( my_window )
- CloseWindow( my_window );
-
- if( my_font )
- CloseFont( my_font );
-
- if( GfxBase )
- CloseLibrary( GfxBase );
-
- if( IntuitionBase )
- CloseLibrary( IntuitionBase );
-
- printf( "%s\n", message );
-
- exit();
- }
-
-