25 #define DEFAULT_PTSIZE 30 26 #define DEFAULT_FONT "/System/Library/Fonts/华文细黑.ttf" 27 #define MAX_TEXT_LENGTH 256 37 static TTF_Font *font;
42 c = (
unsigned char)(0xff & c);
45 else if ((c >> 5) ==0x6)
47 else if ((c >> 4) == 0xe)
49 else if ((c >> 3) == 0x1e)
74 for (; i < distance &&
p; ++
i)
83 SDL_Log(
"usage: testime [--font fontfile]\n");
91 textRect.
x = textRect.
y = 100;
113 int w = 0,
h = textRect.
h;
123 SDL_Rect dest = {textRect.
x, textRect.
y, textSur->
w, textSur->
h };
130 TTF_SizeUTF8(font,
text, &w, &
h);
134 markedRect.
x = textRect.
x +
w;
135 markedRect.
w = textRect.
w -
w;
136 if (markedRect.
w < 0)
171 SDL_Rect dest = {markedRect.
x, markedRect.
y, textSur->
w, textSur->
h };
181 underlineRect.
y += (
h - 2);
210 int main(
int argc,
char *argv[]) {
223 for (i = 1; i < argc;i++) {
226 for (argc--, argv++; argc > 0; argc--, argv++)
228 if (strcmp(argv[0],
"--help") == 0) {
233 else if (strcmp(argv[0],
"--font") == 0)
264 SDL_Log(
"Using font: %s\n", fontname);
299 if ((
text[textlen-1] & 0x80) == 0x00)
302 text[textlen-1]=0x00;
305 if ((
text[textlen-1] & 0xC0) == 0x80)
308 text[textlen-1]=0x00;
311 if ((
text[textlen-1] & 0xC0) == 0xC0)
314 text[textlen-1]=0x00;
329 SDL_Log(
"Keyboard: scancode 0x%08X = %s, keycode 0x%08X = %s\n",
354 SDL_Log(
"text editing \"%s\", selected range (%d, %d)\n",
358 cursor =
event.edit.start;
static SDL_Color backColor
SDLTest_CommonState * SDLTest_CommonCreateState(char **argv, Uint32 flags)
Parse command line parameters and create common state.
#define SDL_RenderFillRect
GLenum GLenum GLuint texture
char * utf8_next(char *p)
int SDLTest_CommonArg(SDLTest_CommonState *state, int index)
Process one common argument.
A collection of pixels used in software blitting.
#define SDL_SetRenderDrawBlendMode
SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state)
Open test window.
static SDL_Color lineColor
GLsizei GLsizei GLfloat distance
char * utf8_advance(char *p, size_t distance)
#define SDL_StopTextInput
char text[SDL_TEXTINPUTEVENT_TEXT_SIZE]
#define SDL_CreateTextureFromSurface
void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done)
Common event handler for test windows.
char text[SDL_TEXTEDITINGEVENT_TEXT_SIZE]
int main(int argc, char *argv[])
static SDLTest_CommonState * state
#define SDL_StartTextInput
SDL_Renderer ** renderers
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
#define SDL_LogSetPriority
SDL_TextEditingEvent edit
static char text[MAX_TEXT_LENGTH]
#define SDL_GetScancodeName
#define SDL_SetTextInputRect
static char markedText[SDL_TEXTEDITINGEVENT_TEXT_SIZE]
#define SDL_DestroyTexture
size_t utf8_length(unsigned char c)
#define SDL_SetRenderDrawColor
GLubyte GLubyte GLubyte GLubyte w
void _Redraw(SDL_Renderer *renderer)
#define DEFAULT_WINDOW_WIDTH
static SDL_Rect markedRect
void SDLTest_CommonQuit(SDLTest_CommonState *state)
Close test window.
GLfloat GLfloat GLfloat GLfloat h
static SDL_Color textColor
A rectangle, with the origin at the upper left.
#define SDL_RenderPresent
#define SDL_TEXTEDITINGEVENT_TEXT_SIZE