home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 480.lha / SmartField / Programs / graphic / g.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-06  |  9.1 KB  |  350 lines

  1. /******************************************************
  2. *  SMART FIELDS GRAPHIC RENDITION TEST PROGRAM v1.01
  3. *  © Copyright 1988 Timm Martin - All Rights Reserved
  4. *******************************************************/
  5.  
  6. #include <exec/io.h>
  7. #include <exec/ports.h>
  8. #include <exec/types.h>
  9. #include <graphics/gfxbase.h>
  10. #include <intuition/intuition.h>
  11. #include <intuition/intuitionbase.h>
  12. #include <console/console.h>
  13. #include <console/fields.h>
  14. #include <console/functions.h>
  15. #include <toolkit/toolkit.h>
  16. #include <functions.h>
  17.  
  18. /************************
  19. *  INTUITION STRUCTURES
  20. *************************/
  21.  
  22. struct IntuitionBase *IntuitionBase = NULL;
  23. struct GfxBase       *GfxBase = NULL;
  24. struct Window        *win = NULL;
  25. struct RastPort      *rp;
  26.  
  27. /********************
  28. *  FIELD STRUCTURES
  29. *********************/
  30.  
  31. /*** TITLES ***/
  32.  
  33. #define STRING_TEXT 1,0,JAM1,-3,-11,NULL
  34. struct IntuiText fp_text = { STRING_TEXT, (STRPTR)"Front Pen", NULL };
  35. struct IntuiText bp_text = { STRING_TEXT, (STRPTR)"Back Pen", NULL };
  36. struct IntuiText st_text = { STRING_TEXT, (STRPTR)"Style", NULL };
  37. struct IntuiText te_text = { STRING_TEXT, (STRPTR)"Test Field", NULL };
  38.  
  39. /*** BORDERS ***/
  40.  
  41. SHORT small_pairs2[] = { 2,11, 100,11, 100, 1, 101, 1, 101,11 };
  42. SHORT small_pairs1[] = { 0, 0,  99, 0,  99,10,   0,10,   0, 0 };
  43. SHORT large_pairs2[] = { 2,11, 404,11, 404, 1, 405, 1, 405,11 };
  44. SHORT large_pairs1[] = { 0, 0, 403, 0, 403,10,   0,10,   0, 0 };
  45.  
  46. #define BORDER2 -3,-2,2,0,JAM1,5
  47. #define BORDER1 -3,-2,1,0,JAM1,5
  48. struct Border small_border2 = { BORDER2, small_pairs2, NULL };
  49. struct Border small_border1 = { BORDER1, small_pairs1, &small_border2 };
  50. struct Border large_border2 = { BORDER2, large_pairs2, NULL };
  51. struct Border large_border1 = { BORDER1, large_pairs1, &large_border2 };
  52.  
  53. /*** BUFFERS ***/
  54.  
  55. #define FP_SIZE 2
  56. #define BP_SIZE 2
  57. #define ST_SIZE 3
  58. #define TE_SIZE 50
  59.  
  60. UBYTE fp_input[FP_SIZE];
  61. UBYTE bp_input[BP_SIZE];
  62. UBYTE st_input[ST_SIZE];
  63. UBYTE te_input[TE_SIZE];
  64.  
  65. UBYTE fp_undo[FP_SIZE];
  66. UBYTE bp_undo[BP_SIZE];
  67. UBYTE st_undo[ST_SIZE];
  68. UBYTE te_undo[TE_SIZE];
  69.  
  70. /*** FIELDS ***/
  71.  
  72. #define FP_FIELD 1
  73. #define BP_FIELD 2
  74. #define ST_FIELD 3
  75. #define TE_FIELD 4
  76.  
  77. struct FieldMask color_mask = MASK_ENTIRE_DISABLED;
  78. struct FieldMask style_mask = MASK_ENTIRE_DISABLED;
  79.  
  80. #define LEFT_EDGE 117
  81. #define FP_TOP 60
  82. #define BP_TOP 86
  83. #define ST_TOP 112
  84. #define TE_TOP 138
  85.  
  86. #define FIRST_FIELD fp_field
  87. struct Field fp_field = {
  88.   NULL, LATER, fp_input, fp_undo, NULL, 1, 0, CON_PLAIN,
  89.   FIELD_ENABLED, &color_mask, NULL, LEFT_EDGE, FP_TOP,
  90.   0, 0, FP_SIZE, 0, 0, 0, 0, &fp_text, &small_border1,
  91.   NULL, FP_FIELD, NULL, NULL, NULL
  92. };
  93. struct Field bp_field = {
  94.   &fp_field, LATER, bp_input, bp_undo, NULL, 1, 0, CON_PLAIN,
  95.   FIELD_ENABLED, &color_mask, NULL, LEFT_EDGE, BP_TOP,
  96.   0, 0, BP_SIZE, 0, 0, 0, 0, &bp_text, &small_border1,
  97.   NULL, BP_FIELD, NULL, NULL, NULL
  98. };
  99. struct Field st_field = {
  100.   &bp_field, LATER, st_input, st_undo, NULL, 1, 0, CON_PLAIN,
  101.   FIELD_ENABLED, &style_mask, NULL, LEFT_EDGE, ST_TOP,
  102.   0, 0, ST_SIZE, 0, 0, 0, 0, &st_text, &small_border1,
  103.   NULL, ST_FIELD, NULL, NULL, NULL
  104. };
  105. struct Field te_field = {
  106.   &st_field, NULL, te_input, te_undo, NULL, 1, 0, CON_PLAIN,
  107.   FIELD_ENABLED, NULL, NULL, LEFT_EDGE, TE_TOP,
  108.   0, 0, TE_SIZE, 0, 0, 0, 0, &te_text, &large_border1,
  109.   NULL, TE_FIELD, NULL, NULL, NULL
  110. };
  111. #define FINAL_FIELD te_field
  112.  
  113. struct FieldHeader field_header;
  114. #define CURRENT_FIELD field_header.CurrentField
  115.  
  116. /***************
  117. *  WINDOW TEXT
  118. ****************/
  119.  
  120. UBYTE *color_text[] = {
  121.   (STRPTR)"BLUE  ", (STRPTR)"WHITE ", (STRPTR)"BLACK ", (STRPTR)"ORANGE"
  122. };
  123. #define TEXT_LEFT LEFT_EDGE+118
  124. struct IntuiText fp_wtext = {
  125.   1, 0, JAM2, TEXT_LEFT, FP_TOP, NULL, LATER, NULL
  126. };
  127. struct IntuiText bp_wtext = {
  128.   1, 0, JAM2, TEXT_LEFT, BP_TOP, NULL, LATER, &fp_wtext
  129. };
  130. UBYTE st_string[37];
  131. struct IntuiText st_wtext = {
  132.   1, 0, JAM2, TEXT_LEFT, ST_TOP, NULL, (STRPTR)st_string, &bp_wtext
  133. };
  134. #define WINDOW_TEXT st_wtext
  135.  
  136. /************************
  137. *  NEW WINDOW STRUCTURE
  138. *************************/
  139.  
  140. struct NewWindow new_window = {
  141.   0, 0, 640, 200, 0, 1, CLOSEWINDOW | MOUSEBUTTONS |
  142.   REFRESHWINDOW, ACTIVATE | SMART_REFRESH | WINDOWCLOSE |
  143.   WINDOWDEPTH | WINDOWDRAG | WINDOWSIZING, NULL, NULL,
  144.   (STRPTR)"SmartFields Graphic Rendition Test Program v1.0",
  145.   NULL, NULL, 50, 25, 640, 200, WBENCHSCREEN
  146. };
  147.  
  148. /********************
  149. *  GLOBAL VARIABLES
  150. *********************/
  151.  
  152. #define WAIT_FOR_INPUT Wait(1L<<field_header.ReadPort->mp_SigBit|1L<<win->UserPort->mp_SigBit)
  153. #define CONSOLE_INPUT  message=(struct Message *)GetMsg(field_header.ReadPort)
  154. #define WINDOW_INPUT   imessage=(struct IntuiMessage *)GetMsg(win->UserPort)
  155. UBYTE   con_buffer[CONSOLE_BUFFER_SIZE];
  156.  
  157. /**************************
  158. *  M A I N  P R O G R A M
  159. ***************************/
  160.  
  161. main()
  162. {
  163.   open_all();
  164.   initialize();
  165.   get_inputs();
  166. }
  167.  
  168. /***************
  169. *  DRAW SCREEN
  170. ****************/
  171.  
  172. draw_screen()
  173. {
  174.   PrintIText( rp, &WINDOW_TEXT, 0L, 0L );
  175.   field_refresh( &field_header, &FIRST_FIELD, -1, CURRENT_FIELD );
  176. }
  177.  
  178. /***************
  179. *  END PROGRAM
  180. ****************/
  181.  
  182. end_program( return_code )
  183.   int return_code;
  184. {
  185.   field_close( &field_header );
  186.  
  187.   if (win)             CloseWindow( win );
  188.   if (GfxBase)         CloseLibrary( GfxBase );
  189.   if (IntuitionBase)   CloseLibrary( IntuitionBase );
  190.  
  191.   exit( return_code );
  192. }
  193.  
  194. /**************
  195. *  GET INPUTS
  196. ***************/
  197.  
  198. get_inputs()
  199. {
  200.   struct  IntuiMessage *imessage;
  201.   ULONG   key;
  202.   struct  Message *message;
  203.   struct  Field *where;
  204.  
  205.   FOREVER {
  206.     WAIT_FOR_INPUT;
  207.  
  208.     if (CONSOLE_INPUT) {
  209.       key = field_input( &field_header );
  210.       switch (key) {
  211.         case FIELD_SWALLOW:
  212.           break;
  213.         case FIELD_RETURN:
  214.         case FIELD_NEXT:
  215.           prepare_text();
  216.           if (CURRENT_FIELD == &FINAL_FIELD)
  217.             field_goto( &field_header, &FIRST_FIELD );
  218.           else
  219.             field_goto( &field_header, CURRENT_FIELD->NextField );
  220.           break;
  221.         case FIELD_PREVIOUS:
  222.           if (CURRENT_FIELD == &FIRST_FIELD)
  223.             field_goto( &field_header, &FINAL_FIELD );
  224.           else
  225.             field_goto( &field_header, CURRENT_FIELD->PrevField );
  226.           break;
  227.         case FIELD_FIRST:
  228.           field_goto( &field_header, &FIRST_FIELD ); break;
  229.         case FIELD_FINAL:
  230.           field_goto( &field_header, &FINAL_FIELD ); break;
  231.         case FIELD_HELP:
  232.           help(); break;
  233.       } /* switch key */
  234.     }   /* if keyboard input */
  235.  
  236.     while (WINDOW_INPUT) {
  237.       switch (imessage->Class) {
  238.         case MOUSEBUTTONS:
  239.           if (imessage->Code == LEFT_MOUSE_BUTTON)
  240.             if (where = field_click( &field_header,
  241.                         imessage->MouseX, imessage->MouseY )) {
  242.               where->BufferPos = field_header.BufferPos;
  243.               field_goto( &field_header, where );
  244.             }
  245.           break;
  246.         case REFRESHWINDOW:
  247.           draw_screen();
  248.           BeginRefresh( win );
  249.           EndRefresh( win, TRUE );
  250.           break;
  251.         case CLOSEWINDOW:
  252.           end_program( 0 );
  253.           break;
  254.       } /* switch */
  255.       ReplyMsg( imessage );
  256.     } /* while window messages */
  257.   }   /* forever */
  258. }
  259.  
  260. /********
  261. *  HELP
  262. *********/
  263.  
  264. help()
  265. {
  266.   printf( "HELP!\n" );
  267. }
  268.  
  269. /**************
  270. *  INITIALIZE
  271. ***************/
  272.  
  273. initialize()
  274. {
  275.   /* this will set for bp_field also since it shares mask with fp_field */
  276.   mask_range( &color_mask, '0', '3', MASK_ENABLE );
  277.   mask_range( &style_mask, '0', '9', MASK_ENABLE );
  278.  
  279.   st_string[0] = '\0';  /* to display nothing first time */
  280.   draw_screen();
  281. }
  282.  
  283. /************
  284. *  OPEN ALL
  285. *************/
  286.  
  287. open_all()
  288. {
  289.   int error;
  290.  
  291.   if (!(IntuitionBase = (struct IntuitionBase *)
  292.         OpenLibrary( "intuition.library", LIBRARY_VERSION )))
  293.     end_program( 0x0100 );
  294.   if (!(GfxBase = (struct GfxBase *) OpenLibrary( "graphics.library", 0L )))
  295.     end_program( 0x0101 );
  296.  
  297.   if (!(win = OpenWindow( &new_window )))
  298.     end_program( 0x0102 );
  299.   rp = win->RPort;
  300.  
  301.   if (error = field_open( win, &field_header, &FIRST_FIELD, &FINAL_FIELD, con_buffer ))
  302.     end_program( error );
  303. }
  304.  
  305. /****************
  306. *  PREPARE TEXT
  307. *****************/
  308.  
  309. prepare_text()
  310. {
  311.   te_field.FrontPen = atoi( fp_field.Buffer );
  312.   te_field.BackPen  = atoi( bp_field.Buffer );
  313.   te_field.Style    = atoi( st_field.Buffer );
  314.  
  315.   /* Style should only have values 0-15 */
  316.   te_field.Style   %= 16;
  317.   itoa( st_field.Buffer, te_field.Style );
  318.   field_redisplay( &field_header, &st_field, 1, CURRENT_FIELD );
  319.  
  320.   fp_wtext.IText = color_text[te_field.FrontPen];
  321.   bp_wtext.IText = color_text[te_field.BackPen];
  322.  
  323.   /* using con_buffer to accumulate Style flags */
  324.   con_buffer[0] = '\0';
  325.   if (te_field.Style & CON_BOLD)
  326.     strcpy( con_buffer, "BOLD" );
  327.   if (te_field.Style & CON_ITALIC) {
  328.     if (con_buffer[0])
  329.       strcat( con_buffer, " | ITALIC" );
  330.     else
  331.       strcpy( con_buffer, "ITALIC" );
  332.   }
  333.   if (te_field.Style & CON_UNDERSCORE) {
  334.     if (con_buffer[0])
  335.       strcat( con_buffer, " | UNDERSCORE" );
  336.     else
  337.       strcpy( con_buffer, "UNDERSCORE" );
  338.   }
  339.   if (te_field.Style & CON_INVERSE) {
  340.     if (con_buffer[0])
  341.       strcat( con_buffer, " | INVERSE" );
  342.     else
  343.       strcpy( con_buffer, "INVERSE" );
  344.   }
  345.   if (!con_buffer[0])
  346.     strcpy( con_buffer, "PLAIN" );
  347.   sprintf( st_string, "%-36s", con_buffer );
  348.   PrintIText( rp, &WINDOW_TEXT, 0L, 0L );
  349. }
  350.