Mercurial > sdl-ios-xcode
annotate test/checkkeys.c @ 821:30168104389f
Date: Sat, 14 Feb 2004 14:52:40 +0200
From: "Mike Gorchak"
Subject: Batch of the QNX6 fixes for the SDL
1. Updated readme.QNX
2. Fixed crashes during intensive window updating under fast machines (got over 200 rectangles for update).
3. Fixed double-buffered fullscreen modes, now it works as needed.
4. Fixed Photon detection algorithm.
5. Fixed HWSURFACE update function.
6. Added SDL_PHOTON_FULLSCREEN_REFRESH environment variable support for control refresh rates under Photon.
7. Added 640x400 fullscreen mode emulation via 640x480 (if videodriver not supports original 640x400 mode of course) shifted by 40 vertical pixels from begin, to center it. It's needed for some old DOS games which ran in doubled 320x200 mode.
8. Added available video ram amount support.
8. Added hardware surface allocation/deallocation support if current videomode and videodriver supports it.
9. Added hardware filling support.
10. Added hardware blits support (simple and colorkeyed).
And I've added to testvidinfo test color-keyed blits benchmark (maybe need to add alpha blits benchmark too ?). Currently Photon not supporting any alpha hardware blittings (all drivers lack of alpha blitting code support, only software alpha blitting exist in photon, which is hundreds times slowest than the SDL's one). So I've not added the alpha support. I suppose new QNX 6.3 will have the hardware alpha support, so when it will be done, I'll add alpha support.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 14 Feb 2004 20:22:21 +0000 |
parents | 806fcbde0af3 |
children | be9c9c8f6d53 |
rev | line source |
---|---|
0 | 1 |
2 /* Simple program: Loop, watching keystrokes | |
3 Note that you need to call SDL_PollEvent() or SDL_WaitEvent() to | |
4 pump the event loop and catch keystrokes. | |
5 */ | |
6 | |
7 #include <stdio.h> | |
8 #include <stdlib.h> | |
9 #include <string.h> | |
10 | |
11 #include "SDL.h" | |
12 | |
13 static void print_modifiers(void) | |
14 { | |
15 int mod; | |
16 printf(" modifiers:"); | |
17 mod = SDL_GetModState(); | |
18 if(!mod) { | |
19 printf(" (none)"); | |
20 return; | |
21 } | |
22 if(mod & KMOD_LSHIFT) | |
23 printf(" LSHIFT"); | |
24 if(mod & KMOD_RSHIFT) | |
25 printf(" RSHIFT"); | |
26 if(mod & KMOD_LCTRL) | |
27 printf(" LCTRL"); | |
28 if(mod & KMOD_RCTRL) | |
29 printf(" RCTRL"); | |
30 if(mod & KMOD_LALT) | |
31 printf(" LALT"); | |
32 if(mod & KMOD_RALT) | |
33 printf(" RALT"); | |
34 if(mod & KMOD_LMETA) | |
35 printf(" LMETA"); | |
36 if(mod & KMOD_RMETA) | |
37 printf(" RMETA"); | |
38 if(mod & KMOD_NUM) | |
39 printf(" NUM"); | |
40 if(mod & KMOD_CAPS) | |
41 printf(" CAPS"); | |
42 if(mod & KMOD_MODE) | |
43 printf(" MODE"); | |
44 } | |
45 | |
46 static void PrintKey(SDL_keysym *sym, int pressed) | |
47 { | |
48 /* Print the keycode, name and state */ | |
49 if ( sym->sym ) { | |
50 printf("Key %s: %d-%s ", pressed ? "pressed" : "released", | |
51 sym->sym, SDL_GetKeyName(sym->sym)); | |
52 } else { | |
53 printf("Unknown Key (scancode = %d) %s ", sym->scancode, | |
54 pressed ? "pressed" : "released"); | |
55 } | |
56 | |
57 /* Print the translated character, if one exists */ | |
58 if ( sym->unicode ) { | |
59 /* Is it a control-character? */ | |
60 if ( sym->unicode < ' ' ) { | |
61 printf(" (^%c)", sym->unicode+'@'); | |
62 } else { | |
63 #ifdef UNICODE | |
64 printf(" (%c)", sym->unicode); | |
65 #else | |
66 /* This is a Latin-1 program, so only show 8-bits */ | |
67 if ( !(sym->unicode & 0xFF00) ) | |
68 printf(" (%c)", sym->unicode); | |
69 #endif | |
70 } | |
71 } | |
72 print_modifiers(); | |
73 printf("\n"); | |
74 } | |
75 | |
76 int main(int argc, char *argv[]) | |
77 { | |
78 SDL_Event event; | |
79 int done; | |
473 | 80 Uint32 videoflags; |
0 | 81 |
82 /* Initialize SDL */ | |
83 if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { | |
84 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); | |
85 exit(1); | |
86 } | |
87 atexit(SDL_Quit); | |
88 | |
473 | 89 videoflags = SDL_SWSURFACE; |
493
806fcbde0af3
Fixed a crash bug in checkkeys.c (thanks John!)
Sam Lantinga <slouken@libsdl.org>
parents:
473
diff
changeset
|
90 while( argc > 1 ) { |
806fcbde0af3
Fixed a crash bug in checkkeys.c (thanks John!)
Sam Lantinga <slouken@libsdl.org>
parents:
473
diff
changeset
|
91 --argc; |
806fcbde0af3
Fixed a crash bug in checkkeys.c (thanks John!)
Sam Lantinga <slouken@libsdl.org>
parents:
473
diff
changeset
|
92 if ( argv[argc] && !strcmp(argv[argc], "-fullscreen") ) { |
806fcbde0af3
Fixed a crash bug in checkkeys.c (thanks John!)
Sam Lantinga <slouken@libsdl.org>
parents:
473
diff
changeset
|
93 videoflags |= SDL_FULLSCREEN; |
806fcbde0af3
Fixed a crash bug in checkkeys.c (thanks John!)
Sam Lantinga <slouken@libsdl.org>
parents:
473
diff
changeset
|
94 } else { |
806fcbde0af3
Fixed a crash bug in checkkeys.c (thanks John!)
Sam Lantinga <slouken@libsdl.org>
parents:
473
diff
changeset
|
95 fprintf(stderr, "Usage: %s [-fullscreen]\n", argv[0]); |
806fcbde0af3
Fixed a crash bug in checkkeys.c (thanks John!)
Sam Lantinga <slouken@libsdl.org>
parents:
473
diff
changeset
|
96 exit(1); |
806fcbde0af3
Fixed a crash bug in checkkeys.c (thanks John!)
Sam Lantinga <slouken@libsdl.org>
parents:
473
diff
changeset
|
97 } |
473 | 98 } |
99 | |
0 | 100 /* Set 640x480 video mode */ |
473 | 101 if ( SDL_SetVideoMode(640, 480, 0, videoflags) == NULL ) { |
0 | 102 fprintf(stderr, "Couldn't set 640x480 video mode: %s\n", |
103 SDL_GetError()); | |
104 exit(2); | |
105 } | |
106 | |
107 /* Enable UNICODE translation for keyboard input */ | |
108 SDL_EnableUNICODE(1); | |
109 | |
110 /* Enable auto repeat for keyboard input */ | |
111 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, | |
112 SDL_DEFAULT_REPEAT_INTERVAL); | |
113 | |
114 /* Watch keystrokes */ | |
115 done = 0; | |
116 while ( !done ) { | |
117 /* Check for events */ | |
118 SDL_WaitEvent(&event); | |
119 switch (event.type) { | |
120 case SDL_KEYDOWN: | |
121 PrintKey(&event.key.keysym, 1); | |
122 break; | |
123 case SDL_KEYUP: | |
124 PrintKey(&event.key.keysym, 0); | |
125 break; | |
126 case SDL_MOUSEBUTTONDOWN: | |
127 /* Any button press quits the app... */ | |
128 case SDL_QUIT: | |
129 done = 1; | |
130 break; | |
131 default: | |
132 break; | |
133 } | |
134 } | |
135 return(0); | |
136 } |