home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 543a.lha / Nebula / source.LZH / source / player.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-10  |  6.7 KB  |  197 lines

  1. /*
  2.  
  3. ------------------------------------------------------------------
  4.  
  5. Black Nebula
  6.  
  7. File :                player.c
  8. Programmer:        Colin Adams / C Manual
  9. Date:                30/5/91
  10. Last Modified :    10/6/91
  11.  
  12. Description:
  13.  
  14. Puts up a string gadget and gets the player to type their name
  15. into it.  Loosely based on an example in the C Manual.
  16.  
  17. ------------------------------------------------------------------
  18.  
  19. */
  20.  
  21.  
  22. #include <intuition/intuition.h>
  23.  
  24. extern struct IntuitionBase *IntuitionBase;
  25. extern struct Screen *screen;
  26.  
  27. /* data structures, generated with Power Windows interface generation
  28. program */
  29.  
  30. SHORT my_points[]=
  31. {
  32.    -7, -4, /* Start at position (-7, -4) */
  33.   200, -4, /* Draw a line to the right to position (200,-4) */
  34.   200, 11, /* Draw a line down to position (200,11) */
  35.    -7, 11, /* Draw a line to the right to position (-7,11) */
  36.    -7, -4  /* Finish of by drawing a line up to position (-7,-4) */ 
  37. };
  38.  
  39. struct Border my_border=
  40. {
  41.   0, 0,        /* LeftEdge, TopEdge. */
  42.   1,           /* FrontPen, colour register 1. */
  43.   0,           /* BackPen, for the moment unused. */
  44.   JAM1,        /* DrawMode, draw the lines with colour 1. */
  45.   5,           /* Count, 5 pair of coordinates in the array. */
  46.   my_points,   /* XY, pointer to the array with the coordinates. */
  47.   NULL,        /* NextBorder, no other Border structures are connected. */
  48. };
  49.  
  50. struct IntuiText my_text=
  51. {
  52.   1,         /* FrontPen, colour register 1. */
  53.   0,         /* BackPen, colour register 0. */
  54.   JAM1,      /* DrawMode, draw the characters with colour 1, do not */
  55.              /* change the background. */ 
  56.   -53, 0,    /* LeftEdge, TopEdge. */
  57.   NULL,      /* ITextFont, use default font. */
  58.   "Name:",   /* IText, the text that will be printed. */
  59.   NULL,      /* NextText, no other IntuiText structures. */
  60. };
  61.  
  62.  
  63. UBYTE my_buffer[50]; /* 50 characters including the NULL-sign. */
  64. UBYTE my_undo_buffer[50]; /* Must be at least as big as my_buffer. */
  65.  
  66. struct StringInfo my_string_info=
  67. {
  68.   my_buffer,       /* Buffer, pointer to a null-terminated string. */
  69.   my_undo_buffer,  /* UndoBuffer, pointer to a null-terminated string. */
  70.                    /* (Remember my_buffer is equal to &my_buffer[0]) */
  71.   0,               /* BufferPos, initial position of the cursor. */
  72.   50,              /* MaxChars, 50 characters + null-sign ('\0'). */
  73.   0,               /* DispPos, first character in the string should be */
  74.                    /* first character in the display. */
  75.  
  76.   /* Intuition initializes and maintaines these variables: */
  77.  
  78.   0,               /* UndoPos */
  79.   0,               /* NumChars */
  80.   0,               /* DispCount */
  81.   0, 0,            /* CLeft, CTop */
  82.   NULL,            /* LayerPtr */
  83.   NULL,            /* LongInt */
  84.   NULL,            /* AltKeyMap */
  85. };
  86.  
  87.  
  88. struct Gadget my_gadget=
  89. {
  90.   NULL,          /* NextGadget, no more gadgets in the list. */
  91.   68,            /* LeftEdge, 68 pixels out. */
  92.   30,            /* TopEdge, 30 lines down. */
  93.   198,           /* Width, 198 pixels wide. */
  94.   8,             /* Height, 8 pixels lines heigh. */
  95.   GADGHCOMP,     /* Flags, draw the select box in the complement */
  96.                  /* colours. Note: it actually only the cursor which */
  97.                  /* will be drawn in the complement colours (yellow). */
  98.                  /* If you set the flag GADGHNONE the cursor will not be */
  99.                  /* highlighted, and the user will therefore not be able */
  100.                  /* to see it. */
  101.   GADGIMMEDIATE| /* Activation, our program will recieve a message when */
  102.   RELVERIFY,     /* the user has selected this gadget, and when the user */
  103.                  /* has released it. */ 
  104.   STRGADGET,     /* GadgetType, a String gadget. */
  105.   (APTR) &my_border, /* GadgetRender, a pointer to our Border structure. */
  106.   NULL,          /* SelectRender, NULL since we do not supply the gadget */
  107.                  /* with an alternative image. */
  108.   &my_text,      /* GadgetText, a pointer to our IntuiText structure. */
  109.   NULL,          /* MutualExclude, no mutual exclude. */
  110.   (APTR) &my_string_info, /* SpecialInfo, a pointer to a StringInfo str. */
  111.   0,             /* GadgetID, no id. */
  112.   NULL           /* UserData, no user data connected to the gadget. */
  113. };
  114.  
  115. struct Window *my_window;
  116.  
  117. struct NewWindow my_new_window=
  118. {
  119.   50,            /* LeftEdge    x position of the window. */
  120.   25,            /* TopEdge     y positio of the window. */
  121.   320,           /* Width       320 pixels wide. */
  122.   100,           /* Height      100 lines high. */
  123.   0,             /* DetailPen   Text should be drawn with colour reg. 0 */
  124.   1,             /* BlockPen    Blocks should be drawn with colour reg. 1 */
  125.   CLOSEWINDOW|   /* IDCMPFlags  The window will give us a message if the */
  126.                  /*             user has selected the Close window gad, */
  127.   GADGETDOWN|    /*             or a gadget has been pressed on, or */
  128.   GADGETUP,      /*             a gadge has been released. */
  129.   SMART_REFRESH| /* Flags       Intuition should refresh the window. */
  130.   WINDOWCLOSE|   /*             Close Gadget. */
  131.   WINDOWDRAG|    /*             Drag gadget. */
  132.   WINDOWDEPTH|   /*             Depth arrange Gadgets. */
  133.   WINDOWSIZING|  /*             Sizing Gadget. */
  134.   ACTIVATE,      /*             The window should be Active when opened. */
  135.   &my_gadget,    /* FirstGadget A pointer to the String gadget. */
  136.   NULL,          /* CheckMark   Use Intuition's default CheckMark. */
  137.   "Enter your name:",/* Title       Title of the window. */
  138.   NULL,          /* Screen      Connected to the Workbench Screen. */
  139.   NULL,          /* BitMap      No Custom BitMap. */
  140.   320,           /* MinWidth    We will not allow the window to become */
  141.   50,            /* MinHeight   smaller than 320 x 50, and not bigger */
  142.   640,           /* MaxWidth    than 640 x 200. */
  143.   200,           /* MaxHeight */
  144.   CUSTOMSCREEN   /* Type        Connected to the Workbench Screen. */
  145. };
  146.  
  147.  
  148. /* start of my code (end of power windows stuff) */
  149.  
  150. char *EnterName(void)
  151. {
  152.   BOOL close_me;
  153.   ULONG class;
  154.  
  155.   struct IntuiMessage *my_message;
  156.  
  157.   strcpy(my_buffer, "");
  158.     my_new_window.Screen = screen;
  159.   my_window = (struct Window *) OpenWindow( &my_new_window );
  160.   
  161.   if(my_window == NULL)
  162.   {
  163.     DisplayBeep(NULL);
  164.       return (char *) my_string_info.Buffer;
  165.   }
  166.  
  167.   close_me = FALSE;
  168.  
  169.   while(!close_me)
  170.   {
  171.     Wait(1 << my_window->UserPort->mp_SigBit);
  172.  
  173.     my_message = (struct IntuiMessage *) GetMsg( my_window->UserPort);
  174.  
  175.     if(my_message)
  176.     {
  177.       class = my_message->Class;
  178.       ReplyMsg(my_message);
  179.   
  180.       switch( class )
  181.       {
  182.         case CLOSEWINDOW:
  183.                close_me=TRUE;
  184.                break;
  185.                
  186.         case GADGETUP:
  187.                     close_me = TRUE;
  188.                break;
  189.       }
  190.     }
  191.   }
  192.  
  193.   CloseWindow(my_window);
  194.     return (char *) my_string_info.Buffer;
  195. }
  196.  
  197. /* end of module */