Created
April 17, 2016 03:39
-
-
Save buckle2000/6b6000e3c6fcce8e893906d27d05a631 to your computer and use it in GitHub Desktop.
IME Test of SDL 2.0.4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SDL.h> | |
#include <string.h> | |
#include <stdio.h> | |
#include <string> | |
char text[1000]; | |
char *composition; | |
Sint32 cursor; | |
Sint32 selection_len; | |
int main(int argc, char *argv[]) | |
{ | |
SDL_Window* window = NULL; | |
SDL_Surface* screenSurface = NULL; | |
if (SDL_Init(SDL_INIT_VIDEO) < 0) { | |
printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError()); | |
} | |
else { | |
window = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN); | |
if (window == NULL) { | |
printf("Window could not be created! SDL_Error: %s\n", SDL_GetError()); | |
} | |
else { | |
screenSurface = SDL_GetWindowSurface(window); | |
SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xFF, 0xFF, 0xFF)); | |
SDL_UpdateWindowSurface(window); | |
} | |
} | |
SDL_bool done = SDL_FALSE; | |
/* ... */ | |
composition = ""; // prevert null | |
std::string title; | |
SDL_StartTextInput(); | |
while (!done) { | |
SDL_Event event; | |
if (SDL_PollEvent(&event)) { | |
switch (event.type) { | |
case SDL_QUIT: | |
done = SDL_TRUE; | |
break; | |
case SDL_TEXTINPUT: | |
strcat(text, event.text.text); | |
title = text; | |
break; | |
case SDL_TEXTEDITING: | |
composition = event.edit.text; | |
title = std::string() + text + "[" + composition + "]"; | |
cursor = event.edit.start; | |
selection_len = event.edit.length; | |
break; | |
} | |
} | |
SDL_SetWindowTitle(window, title.data()); | |
SDL_UpdateWindowSurface(window); | |
} | |
SDL_Quit(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment