9 static SDL_Surface *screen;
10 static TTF_Font* font;
11 static char text[100] = { '\0' };
12 static char editing[100] = { '\0' };
13 static char temp[100];
14 static int cursor = 0;
15 static SDL_Color back_color = { 255, 255, 255 };
16 static SDL_Color text_color = { 0, 0, 0 };
17 static SDL_Color editing_color = { 125, 125, 125 };
18 unsigned int him_flags = HIM_MODE_FULL | HIM_MODE_MULTILINE | HIM_MODE_AUTOCAP | HIM_MODE_DICTIONARY;
20 #define HIM_EVENT (SDL_USEREVENT + 1)
24 SDL_Surface *text_surface;
27 unsigned int cursor_x, cursor_h, after_x;
29 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format,
30 back_color.r, back_color.g, back_color.b));
32 cursor_h = 22; /* Sane default */
34 /* Render everything before cursor */
35 in_cursor = text[cursor];
38 text_surface = TTF_RenderUTF8_Shaded(font, text, text_color, back_color);
39 assert(text_surface != NULL);
40 res = SDL_BlitSurface(text_surface, NULL, screen, NULL);
42 cursor_x = text_surface->w;
43 cursor_h = text_surface->h;
44 SDL_FreeSurface(text_surface);
48 text[cursor] = in_cursor;
50 /* Render editing text, if any */
52 SDL_Rect rect = {cursor_x, 0, 0, 0};
53 text_surface = TTF_RenderUTF8_Shaded(font, editing, editing_color, back_color);
54 assert(text_surface != NULL);
55 res = SDL_BlitSurface(text_surface, NULL, screen, &rect);
57 after_x = cursor_x + text_surface->w;
58 cursor_h = text_surface->h;
59 SDL_FreeSurface(text_surface);
64 /* Render everything after the cursor */
66 SDL_Rect rect = {after_x, 0, 0, 0};
67 text_surface = TTF_RenderUTF8_Shaded(font, &text[cursor], text_color, back_color);
68 assert(text_surface != NULL);
69 res = SDL_BlitSurface(text_surface, NULL, screen, &rect);
71 cursor_h = text_surface->h;
72 SDL_FreeSurface(text_surface);
77 SDL_Rect rect = {cursor_x, 0, 4, cursor_h};
78 SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format,
79 text_color.r, text_color.g, text_color.b));
85 static void toggle_fullscreen()
89 if (screen->flags & SDL_FULLSCREEN) {
90 flags = screen->flags & ~SDL_FULLSCREEN;
93 flags = screen->flags | SDL_FULLSCREEN;
98 screen = SDL_SetVideoMode(x, y, 16, flags);
99 HIM_Enable(him_flags);
104 static void handle_special_key(SDLKey key) {
109 strcpy(&text[cursor], &text[cursor+1]);
114 text[cursor++] = ' ';
123 if (cursor < strlen(text)) {
140 res = SDL_Init(SDL_INIT_VIDEO);
143 screen = SDL_SetVideoMode(720, 420, 16, SDL_SWSURFACE | SDL_RESIZABLE);
144 assert(screen != NULL);
146 res = HIM_Init(0, HIM_EVENT);
152 font = TTF_OpenFont("/usr/share/fonts/nokia/nosnr.ttf", 26);
153 assert(font != NULL);
157 HIM_Enable(him_flags);
160 while (SDL_WaitEvent(&event)) {
161 if (HIM_FilterEvent(&event)) continue;
162 switch (event.type) {
165 case SDL_VIDEOEXPOSE:
168 case SDL_VIDEORESIZE:
169 printf("New screen size %dx%d\n", event.resize.w, event.resize.h);
170 screen = SDL_SetVideoMode(event.resize.w, event.resize.h, 16, screen->flags);
173 case SDL_MOUSEBUTTONDOWN:
174 HIM_ShowKeyboard(HIM_TRIGGER_FINGER);
177 printf("Key Down: %s (unicode=%x)\n",
178 SDL_GetKeyName(event.key.keysym.sym),
179 event.key.keysym.unicode);
180 handle_special_key(event.key.keysym.sym);
183 printf("Key Up: %s\n", SDL_GetKeyName(event.key.keysym.sym));
186 switch (((HIM_TextEvent*)&event)->code) {
187 case HIM_TEXTINPUTEVENT:
188 printf("Text Input Event: %s\n",
189 ((HIM_TextInputEvent*)&event)->text);
190 strcpy(temp, &text[cursor]);
191 strcpy(&text[cursor], ((HIM_TextInputEvent*)&event)->text);
192 strcat(&text[cursor], temp);
193 cursor+=strlen(((HIM_TextInputEvent*)&event)->text);
194 editing[0] = '\0'; /* On input, clear the preedit area. */
197 case HIM_TEXTEDITINGEVENT:
198 printf("Text Editing Event: %s\n",
199 ((HIM_TextEditingEvent*)&event)->text);
200 strcpy(editing, ((HIM_TextEditingEvent*)&event)->text);
203 case HIM_SPECIALKEYEVENT:
204 printf("Special Key: %s\n", SDL_GetKeyName(
205 ((HIM_SpecialKeyEvent*)&event)->sym));
206 handle_special_key(((HIM_SpecialKeyEvent*)&event)->sym);
208 case HIM_CURSORMOVEEVENT:
209 printf("Cursor Move (%s): %d\n",
210 ((HIM_CursorMoveEvent*)&event)->relative ? "relative" : "absolute",
211 ((HIM_CursorMoveEvent*)&event)->offset);
212 if (((HIM_CursorMoveEvent*)&event)->relative) {
213 cursor += ((HIM_CursorMoveEvent*)&event)->offset;
217 case HIM_REQUESTSURROUNDINGEVENT:
218 printf("Surrounding Request\n");
219 HIM_SendSurrounding(text, cursor);
221 case HIM_CLIPBOARDEVENT:
222 switch (((HIM_ClipboardEvent*)&event)->action) {
223 case HIM_CLIPBOARD_CUT:
224 printf("Clipboard Cut\n");
226 case HIM_CLIPBOARD_COPY:
227 printf("Clipboard Copy\n");
229 case HIM_CLIPBOARD_PASTE:
230 printf("Clipboard Paste\n");
232 case HIM_CLIPBOARD_REQUEST_SELECTION:
233 printf("Clipboard Request Selection\n");
234 HIM_SendSelection("Selected");