forwarding a radium compilation fix.
[AROS-Contrib.git] / fish / input / test.c
blob3d0afbdc0e54e73e58049aa63740fb219125b7b6
1 /**************************************
2 * TEST.C 08/04/90
3 * Written by Timm Martin
4 * This source code is public domain.
5 ***************************************/
7 #include <aros/oldprograms.h>
9 #include <exec/types.h>
10 #include <intuition/intuition.h>
11 #include <intuition/intuitionbase.h>
12 #include <stdio.h>
13 #include "input.h"
15 /********************
16 * SHARED VARIABLES
17 *********************/
19 struct IntuitionBase *IntuitionBase = NULL;
20 struct Window *win = NULL;
22 /************************
23 * NEW WINDOW STRUCTURE
24 *************************/
26 struct NewWindow new_window =
28 /* SHORT LeftEdge */ 0,
29 /* SHORT TopEdge */ 0,
30 /* SHORT Width */ 640,
31 /* SHORT Height */ 40,
32 /* UBYTE DetailPen */ 0,
33 /* UBYTE BlockPen */ 1,
34 /* ULONG IDCMPFlags */ CLOSEWINDOW|RAWKEY,
35 /* ULONG Flags */ ACTIVATE|NOCAREREFRESH|SIMPLE_REFRESH|WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG|WINDOWSIZING,
36 /* struct Gadget * FirstGadget */ NULL,
37 /* struct Image * CheckMark */ NULL,
38 /* UBYTE * Title */ (STRPTR)"Input Test Program",
39 /* struct Screen * Screen */ NULL,
40 /* struct BitMap * BitMap */ NULL,
41 /* SHORT MinWidth */ 230,
42 /* SHORT MinHeight */ 20,
43 /* USHORT MaxWidth */ 640,
44 /* USHORT MaxHeight */ 200,
45 /* USHORT Type */ WBENCHSCREEN,
48 /*************
49 * FUNCTIONS
50 **************/
52 int main( int argc, char *argv[] );
53 void print_key( USHORT key );
54 void program_end( char *error );
55 void program_begin( void );
56 void window_input( void );
58 /***********
59 * M A I N
60 ************/
62 int main( int argc, char *argv[] )
64 /* quit if not run from the CLI -- nowhere to send output */
65 if (argc)
67 program_begin();
68 window_input();
70 program_end( NULL );
71 return 0;
74 /*****************
75 * PROGRAM BEGIN
76 ******************/
79 This procedure opens the Intuition library, the window, and the console
80 device. If any of these things fail, the program ends.
83 void program_begin( void )
85 if (!(IntuitionBase = (struct IntuitionBase *)
86 OpenLibrary( "intuition.library", 0L )))
87 program_end( "intuition" );
89 if (!(win = OpenWindow( &new_window )))
90 program_end( "window" );
92 if (!console_open())
93 program_end( "console" );
96 /***************
97 * PROGRAM END
98 ****************/
101 This procedure closes the console device, the window, and the Intuition
102 library. It also prints an error message (if any) to the CLI.
105 void program_end( char *error )
107 if (error) printf( "FAILED: %s\n", error );
109 console_close();
111 if (win) CloseWindow( win );
112 if (IntuitionBase) CloseLibrary((struct Library*) IntuitionBase );
115 /****************
116 * WINDOW INPUT
117 *****************/
120 This procedure monitors for window input. It returns when the user clicks on
121 the window close gadget.
124 void window_input( void )
126 BOOL finished;
127 struct IntuiMessage *imessage;
128 USHORT key;
130 finished = FALSE;
131 while (!finished)
133 /* wait for input from the window */
134 Wait( 1L<<win->UserPort->mp_SigBit );
136 /* for each input message */
137 while ((imessage = (struct IntuiMessage *)GetMsg( win->UserPort )))
139 switch (imessage->Class)
141 case CLOSEWINDOW:
142 finished = TRUE; /* end the program */
143 break;
144 case RAWKEY:
145 if ((key = input_key( imessage ))) /* if a key was pressed */
146 print_key( key ); /* print it */
147 break;
149 /* reply to the message to free its memory */
150 ReplyMsg( (struct Message *)imessage );
155 /*************
156 * PRINT KEY
157 **************/
160 This procedure prints an English description of the key that was pressed and
161 any qualifiers.
164 char *command_keys[] =
166 NULL, "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "TAB",
167 "DELETE", "ESCAPE", "BACKSPACE", "HELP", "RETURN", "UP_ARROW",
168 "DOWN_ARROW", "LEFT_ARROW", "RIGHT_ARROW",
171 void print_key( USHORT key )
173 int c;
175 /* check for qualifiers */
176 if (key & QUAL_LSHIFT)
177 printf( "LSHIFT " );
178 if (key & QUAL_RSHIFT)
179 printf( "RSHIFT " );
180 if (key & QUAL_CONTROL)
181 printf( "CONTROL " );
182 if (key & QUAL_LALT)
183 printf( "LALT " );
184 if (key & QUAL_RALT)
185 printf( "RALT " );
186 if (key & QUAL_LAMIGA)
187 printf( "LAMIGA " );
188 if (key & QUAL_RAMIGA)
189 printf( "RAMIGA " );
191 /* which key was pressed? */
192 c = KEY_VALUE( key );
194 /* if this was a command key */
195 if (KEY_COMMAND( key ))
196 printf( "%s\n", command_keys[c] );
197 /* else just normal ASCII character */
198 else
199 printf( "'%c'\n", c );