Mercurial > sdl-ios-xcode
annotate test/testime.c @ 4590:1ad70fb49fcb
Fix so many things that there is little place in this column to list them all but the result is that blending modes just work now for drawing primitives.
Fixes involved:
1. Fix handling of alpha channel when SDL_BLENDMODE_NONE is set.
2. Make xrendercolor use floating-point values for color channels and then convert to 16 bit ints.
3. Fix handling of visuals in SDL_x11modes.c so that a 32 bit ARGB visual is used.
4. Fix the background pixel value in SDL_x11window.c so that the window background has an alpha value of 0xFF and not 0.
author | Sunny Sachanandani <sunnysachanandani@gmail.com> |
---|---|
date | Fri, 09 Jul 2010 21:36:41 +0530 |
parents | 15eea7a1fa97 |
children | 3e69e077cb95 |
rev | line source |
---|---|
3280
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 /* A simple program to test the Input Method support in the SDL library (1.3+) */ |
3338 | 2 |
3280
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
3 #include <stdlib.h> |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 #include <stdio.h> |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 #include <string.h> |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 #include "SDL.h" |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 #ifdef HAVE_SDL_TTF |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 #include "SDL_ttf.h" |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 #endif |
3338 | 11 |
3280
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 #define DEFAULT_PTSIZE 30 |
3478
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
13 #ifdef __QNXNTO__ |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
14 #define DEFAULT_FONT "/usr/photon/font_repository/tt0003m_.ttf" |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
15 #else |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
16 #define DEFAULT_FONT "/System/Library/Fonts/华文细黑.ttf" |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
17 #endif |
3280
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 #define MAX_TEXT_LENGTH 256 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 SDL_Surface *screen; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 #ifdef HAVE_SDL_TTF |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 TTF_Font *font; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 #endif |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 SDL_Rect textRect, markedRect; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 Uint32 lineColor, backColor; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 SDL_Color textColor = { 0, 0, 0 }; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 char text[MAX_TEXT_LENGTH], *markedText; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 void usage() |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 { |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 printf("usage: testime [--font fontfile] [--fullscreen]\n"); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 exit(0); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 } |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 void InitVideo(int argc, char *argv[]) |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 { |
3478
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
38 int width = 640, height = 480; |
3280
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 int flags = SDL_HWSURFACE; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
40 const char *fontname = DEFAULT_FONT; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 int fullscreen = 0; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
43 for (argc--, argv++; argc > 0; argc--, argv++) |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 { |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 if (strcmp(argv[0], "--help") == 0) |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 usage(); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
47 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 else if (strcmp(argv[0], "--fullscreen") == 0) |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
49 fullscreen = 1; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
50 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
51 else if (strcmp(argv[0], "--font") == 0) |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
52 { |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
53 argc--; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 argv++; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 if (argc > 0) |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 fontname = argv[0]; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
58 else |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 usage(); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 } |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 } |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 |
3581
15eea7a1fa97
Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents:
3478
diff
changeset
|
63 SDL_setenv("SDL_VIDEO_WINDOW_POS", "center", 1); |
3280
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 if (SDL_Init(SDL_INIT_VIDEO) < 0) |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 { |
3281
2d3a9f229ba1
I'm gussing that this was never compiled where TTF support was missing. As a result a call to SDL_GetError and a call to TTF_GetError were swapped.
Bob Pendleton <bob@pendleton.com>
parents:
3280
diff
changeset
|
66 fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); |
3280
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 exit(-1); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
68 } |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 #ifdef HAVE_SDL_TTF |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 /* Initialize fonts */ |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 TTF_Init(); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 font = TTF_OpenFont(fontname, DEFAULT_PTSIZE); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 if (! font) |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 { |
3281
2d3a9f229ba1
I'm gussing that this was never compiled where TTF support was missing. As a result a call to SDL_GetError and a call to TTF_GetError were swapped.
Bob Pendleton <bob@pendleton.com>
parents:
3280
diff
changeset
|
77 fprintf(stderr, "Failed to find font: %s\n", TTF_GetError()); |
3280
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 exit(-1); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 } |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 #endif |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 printf("Using font: %s\n", fontname); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 atexit(SDL_Quit); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 if (fullscreen) |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 { |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
87 SDL_DisplayMode mode; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 SDL_GetDesktopDisplayMode(&mode); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
89 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
90 width = mode.w; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
91 height = mode.h; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
92 fprintf(stderr, "%dx%d\n", width, height); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
93 flags |= SDL_FULLSCREEN; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
94 } |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
95 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
96 /* Create window */ |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
97 screen = SDL_SetVideoMode(width, height, 32, flags); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
98 if (screen == NULL) |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
99 { |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
100 fprintf(stderr, "Unable to set %dx%d video: %s\n", |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
101 width, height, SDL_GetError()); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
102 exit(-1); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
103 } |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
104 } |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 void CleanupVideo() |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 { |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 SDL_StopTextInput(); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
109 #ifdef HAVE_SDL_TTF |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
110 TTF_CloseFont(font); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 TTF_Quit(); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 #endif |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 } |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
114 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
115 void InitInput() |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
116 { |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
117 backColor = SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
118 lineColor = SDL_MapRGB(screen->format, 0x0, 0x0, 0x0); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 /* Prepare a rect for text input */ |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 textRect.x = textRect.y = 100; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 textRect.w = screen->w - 2 * textRect.x; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
123 textRect.h = 50; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
124 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
125 text[0] = 0; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
126 markedRect = textRect; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
127 markedText = NULL; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
128 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 SDL_StartTextInput(); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 } |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
131 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
132 #ifdef HAVE_SDL_TTF |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
133 static void RenderText(SDL_Surface *sur, |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
134 TTF_Font *font, |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
135 const char *text, |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 int x, int y, |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 SDL_Color color) |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
138 { |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 SDL_Surface *textSur = TTF_RenderUTF8_Blended(font, text, color); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
140 SDL_Rect dest = { x, y, textSur->w, textSur->h }; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
141 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
142 SDL_BlitSurface(textSur, NULL, sur, &dest); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
143 SDL_FreeSurface(textSur); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
144 } |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
145 #endif |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
146 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
147 void Redraw() |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
148 { |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
149 int w = 0, h = textRect.h; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 SDL_Rect cursorRect, underlineRect; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
151 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 SDL_FillRect(screen, &textRect, backColor); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
153 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
154 #ifdef HAVE_SDL_TTF |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
155 if (strlen(text)) |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
156 { |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
157 RenderText(screen, font, text, textRect.x, textRect.y, textColor); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
158 TTF_SizeUTF8(font, text, &w, &h); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
159 } |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
160 #endif |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
161 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
162 markedRect.x = textRect.x + w; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
163 markedRect.w = textRect.w - w; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
164 if (markedRect.w < 0) |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
165 { |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
166 SDL_Flip(screen); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
167 // Stop text input because we cannot hold any more characters |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
168 SDL_StopTextInput(); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
169 return; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
170 } |
3478
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
171 else |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
172 { |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
173 SDL_StartTextInput(); |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
174 } |
3280
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
175 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
176 cursorRect = markedRect; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
177 cursorRect.w = 2; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
178 cursorRect.h = h; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
179 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
180 SDL_FillRect(screen, &markedRect, backColor); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
181 if (markedText) |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
182 { |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
183 #ifdef HAVE_SDL_TTF |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
184 RenderText(screen, font, markedText, markedRect.x, markedRect.y, textColor); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
185 TTF_SizeUTF8(font, markedText, &w, &h); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
186 #endif |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
187 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
188 underlineRect = markedRect; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
189 underlineRect.y += (h - 2); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
190 underlineRect.h = 2; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
191 underlineRect.w = w; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
192 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
193 cursorRect.x += w + 1; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
194 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
195 SDL_FillRect(screen, &underlineRect, lineColor); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
196 } |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
197 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
198 SDL_FillRect(screen, &cursorRect, lineColor); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
199 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
200 SDL_Flip(screen); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
201 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
202 SDL_SetTextInputRect(&markedRect); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
203 } |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
204 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
205 void |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
206 HotKey_ToggleFullScreen(void) |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
207 { |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
208 SDL_Surface *screen; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
209 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
210 screen = SDL_GetVideoSurface(); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
211 if (SDL_WM_ToggleFullScreen(screen)) { |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
212 printf("Toggled fullscreen mode - now %s\n", |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
213 (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed"); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
214 } else { |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
215 printf("Unable to toggle fullscreen mode\n"); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
216 } |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
217 } |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
218 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
219 int main(int argc, char *argv[]) |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
220 { |
3338 | 221 SDL_Event event; |
222 int done = 0; | |
223 | |
3280
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
224 InitVideo(argc, argv); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
225 InitInput(); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
226 Redraw(); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
227 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
228 while (! done && SDL_WaitEvent(&event)) |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
229 { |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
230 switch (event.type) |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
231 { |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
232 case SDL_KEYDOWN: |
3478
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
233 switch (event.key.keysym.sym) |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
234 { |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
235 case SDLK_ESCAPE: |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
236 done = 1; |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
237 break; |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
238 case SDLK_RETURN: |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
239 text[0]=0x00; |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
240 Redraw(); |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
241 break; |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
242 case SDLK_BACKSPACE: |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
243 { |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
244 int textlen=SDL_strlen(text); |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
245 |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
246 do { |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
247 if (textlen==0) |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
248 { |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
249 break; |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
250 } |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
251 if ((text[textlen-1] & 0x80) == 0x00) |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
252 { |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
253 /* One byte */ |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
254 text[textlen-1]=0x00; |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
255 break; |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
256 } |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
257 if ((text[textlen-1] & 0xC0) == 0x80) |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
258 { |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
259 /* Byte from the multibyte sequence */ |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
260 text[textlen-1]=0x00; |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
261 textlen--; |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
262 } |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
263 if ((text[textlen-1] & 0xC0) == 0xC0) |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
264 { |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
265 /* First byte of multibyte sequence */ |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
266 text[textlen-1]=0x00; |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
267 break; |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
268 } |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
269 } while(1); |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
270 |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
271 Redraw(); |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
272 } |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
273 break; |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
274 } |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
275 |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
276 if (done) |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
277 { |
3280
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
278 break; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
279 } |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
280 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
281 fprintf(stderr, |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
282 "Keyboard %d: scancode 0x%08X = %s, keycode 0x%08X = %s\n", |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
283 event.key.which, event.key.keysym.scancode, |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
284 SDL_GetScancodeName(event.key.keysym.scancode), |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
285 event.key.keysym.sym, SDL_GetKeyName(event.key.keysym.sym)); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
286 break; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
287 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
288 case SDL_TEXTINPUT: |
3478
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
289 if (SDL_strlen(event.text.text) == 0 || event.text.text[0] == '\n' || |
3280
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
290 markedRect.w < 0) |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
291 break; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
292 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
293 fprintf(stderr, "Keyboard %d: text input \"%s\"\n", |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
294 event.text.which, event.text.text); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
295 |
3478
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
296 if (SDL_strlen(text) + SDL_strlen(event.text.text) < sizeof(text)) |
f7541260e89c
Added support for QNX default font. Backspace and Return keys now handled.
Mike Gorchak <lestat@i.com.ua>
parents:
3338
diff
changeset
|
297 strcpy(text + SDL_strlen(text), event.text.text); |
3280
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
298 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
299 fprintf(stderr, "text inputed: %s\n", text); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
300 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
301 // After text inputed, we can clear up markedText because it |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
302 // is committed |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
303 markedText = NULL; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
304 Redraw(); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
305 break; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
306 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
307 case SDL_TEXTEDITING: |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
308 fprintf(stderr, "text editing \"%s\", selected range (%d, %d)\n", |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
309 event.edit.text, event.edit.start, event.edit.length); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
310 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
311 markedText = event.edit.text; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
312 Redraw(); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
313 break; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
314 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
315 case SDL_QUIT: |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
316 done = 1; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
317 break; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
318 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
319 default: |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
320 break; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
321 } |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
322 } |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
323 |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
324 CleanupVideo(); |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
325 return 0; |
00cace2d9080
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
326 } |