- Timestamp:
- 07/08/08 12:54:34 (5 months ago)
- Location:
- lang/c/SDL_textmanager
- Files:
-
- 2 modified
-
SDL_textmanager.h (modified) (2 diffs)
-
test/main.c (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/c/SDL_textmanager/SDL_textmanager.h
r14719 r15449 86 86 TEXT_MANAGER_ERROR_INVALID_BOOTSTRAP 87 87 } TextManager_Result; 88 89 extern DECLSPEC TextManager_Result SDLCALL TextManager_Init(void); 90 91 extern DECLSPEC int SDLCALL TextManager_GetEventNumber(void); 92 extern DECLSPEC void SDLCALL TextManager_MoveNextEvent(void); 93 extern DECLSPEC TextManager_Message SDLCALL TextManager_GetCurrentMessage(void); 94 extern DECLSPEC Uint16 * SDLCALL TextManager_GetCurrentEditingString(void); 95 extern DECLSPEC Uint16 SDLCALL TextManager_GetCurrentChar(void); 96 extern DECLSPEC int SDLCALL TextManager_GetCurrentCursorPosition(void); 97 extern DECLSPEC int SDLCALL TextManager_GetCurrentCompositionPosition(void); 98 extern DECLSPEC int SDLCALL TextManager_GetCurrentCompositionLength(void); 99 extern DECLSPEC void SDLCALL TextManager_Reset(void); 100 extern DECLSPEC TextManager_Result SDLCALL TextManager_Validate(void); 101 extern DECLSPEC TextManager_Result SDLCALL TextManager_Invalidate(void); 102 extern DECLSPEC Uint16 * SDLCALL TextManager_GetTextManagerName(void); 103 104 extern DECLSPEC void SDLCALL TextManager_Quit(void); 105 106 107 108 109 110 /* protected? ... for add other Input Methods */ 111 112 #define INPUT_METHOD_NAME_STRING_LENGTH 256 88 113 89 114 typedef enum … … 110 135 DEAD_CHAR_HORN 111 136 } TextManager_DeadChar; 112 113 extern DECLSPEC TextManager_Result SDLCALL TextManager_Init(void);114 115 extern DECLSPEC int SDLCALL TextManager_GetEventNumber(void);116 extern DECLSPEC void SDLCALL TextManager_MoveNextEvent(void);117 extern DECLSPEC TextManager_Message SDLCALL TextManager_GetCurrentMessage(void);118 extern DECLSPEC Uint16 * SDLCALL TextManager_GetCurrentEditingString(void);119 extern DECLSPEC Uint16 SDLCALL TextManager_GetCurrentChar(void);120 extern DECLSPEC int SDLCALL TextManager_GetCurrentCursorPosition(void);121 extern DECLSPEC int SDLCALL TextManager_GetCurrentCompositionPosition(void);122 extern DECLSPEC int SDLCALL TextManager_GetCurrentCompositionLength(void);123 extern DECLSPEC void SDLCALL TextManager_Reset(void);124 extern DECLSPEC TextManager_Result SDLCALL TextManager_Validate(void);125 extern DECLSPEC TextManager_Result SDLCALL TextManager_Invalidate(void);126 extern DECLSPEC Uint16 * SDLCALL TextManager_GetTextManagerName(void);127 128 extern DECLSPEC void SDLCALL TextManager_Quit(void);129 130 131 132 133 134 /* protected? ... for add other Input Methods */135 136 #define INPUT_METHOD_NAME_STRING_LENGTH 256137 137 138 138 typedef struct _SDL_TextManager -
lang/c/SDL_textmanager/test/main.c
r14713 r15449 31 31 32 32 33 SDL_Color INPUTED_COLOR = {0xFF, 0x66, 0x66}; 34 SDL_Color CURSOR_COLOR = {0x66, 0xFF, 0x66}; 35 SDL_Color INPUTTING_COLOR = {0x66, 0x66, 0xFF}; 36 SDL_Color BACKGROUND_COLOR = {0x00, 0x00, 0x00}; 37 38 39 #define INPUTED_STRING_LENGTH_MAX 1024 40 41 33 42 int GetUnicodeStringLength(Uint16 *unicodeString) 34 43 { … … 105 114 { 106 115 SDL_Rect rect; 107 SDL_Color bg = {0x00, 0x00, 0x00};108 SDL_Color cfg = {0x66, 0xFF, 0x66};109 116 int cursorWidth; 110 117 SDL_Surface *surface; … … 114 121 rect.w = 640 - cursorPosition; 115 122 rect.h = 100; 116 surface = TTF_RenderUTF8_Shaded(font, "|", cfg, bg); 123 surface = TTF_RenderUTF8_Shaded( 124 font, "|", CURSOR_COLOR, BACKGROUND_COLOR); 117 125 SDL_BlitSurface(surface, NULL, back, &rect); 118 126 cursorWidth = surface->w; … … 140 148 rect.w = 640 - drawStartWidth; 141 149 rect.h = 100; 142 surface = TTF_RenderUNICODE_Shaded(font, string, fg, bg); 150 surface = TTF_RenderUNICODE_Shaded( 151 font, string, INPUTTING_COLOR, BACKGROUND_COLOR); 143 152 144 153 SDL_BlitSurface(surface, NULL, back, &rect); … … 155 164 nowWidth = 0; 156 165 needSize = (cursorPosition + 1) * sizeof(Uint16); 157 splitString = (Uint16*) calloc(needSize, 1);166 splitString = (Uint16*)malloc(needSize); 158 167 if (splitString == NULL) { 159 168 return -1; 160 169 } 161 170 memcpy(splitString, string, cursorPosition * sizeof(Uint16)); 171 splitString[cursorPosition] = 0x0000; 162 172 rect.x = drawStartWidth + nowWidth; 163 173 rect.y = 0; 164 174 rect.w = 640 - (drawStartWidth + nowWidth); 165 175 rect.h = 100; 166 surface = TTF_RenderUNICODE_Shaded(font, splitString, fg, bg); 176 surface = TTF_RenderUNICODE_Shaded( 177 font, splitString, INPUTTING_COLOR, BACKGROUND_COLOR); 167 178 free(splitString); 168 179 … … 178 189 if (stringLength > 0) { 179 190 needSize = (stringLength + 1) * sizeof(Uint16); 180 splitString = (Uint16*) calloc(needSize, 1);191 splitString = (Uint16*)malloc(needSize); 181 192 if (splitString == NULL) { 182 193 return -1; … … 187 198 rect.w = 640 - drawStartWidth + nowWidth; 188 199 rect.h = 100; 189 surface = TTF_RenderUNICODE_Shaded(font, splitString, fg, bg); 200 surface = TTF_RenderUNICODE_Shaded( 201 font, splitString, INPUTTING_COLOR, BACKGROUND_COLOR); 190 202 SDL_BlitSurface(surface, NULL, back, &rect); 191 203 nowWidth += surface->w; 192 204 SDL_FreeSurface(surface); 205 free(splitString); 193 206 } 194 207 … … 402 415 403 416 417 void ProcessMessage( 418 SDL_Surface *back, TTF_Font *font, 419 Uint16 *inputedString, int *inputedWidth) 420 { 421 Uint16 inputedChar; 422 SDL_Event eventExpose; 423 SDL_Rect rect; 424 SDL_Surface *surface; 425 int stringLength; 426 427 rect.x = *inputedWidth; 428 rect.y = 0; 429 rect.w = 640 - *inputedWidth; 430 rect.h = 99; 431 SDL_FillRect(back, &rect, 0x00000000); 432 433 switch (TextManager_GetCurrentMessage()) { 434 case TEXT_MANAGER_MESSAGE_IM_ON: 435 rect.x = 0; 436 rect.y = 100; 437 rect.w = 640; 438 rect.h = 100; 439 SDL_FillRect(back, &rect, 0x00000000); 440 surface = TTF_RenderUTF8_Shaded( 441 font, "IME: ON", INPUTTING_COLOR, BACKGROUND_COLOR); 442 SDL_BlitSurface(surface, NULL, back, &rect); 443 SDL_FreeSurface(surface); 444 DrawCursor(back, font, *inputedWidth); 445 break; 446 case TEXT_MANAGER_MESSAGE_IM_CHANGE: 447 MessageChange(back, font, *inputedWidth); 448 break; 449 case TEXT_MANAGER_MESSAGE_IM_RESULT: 450 stringLength = 451 GetUnicodeStringLength(inputedString) + 452 GetUnicodeStringLength(TextManager_GetCurrentEditingString()); 453 if ((stringLength + 1) >= INPUTED_STRING_LENGTH_MAX) { 454 break; 455 } 456 CatUnicodeString( 457 inputedString, 458 TextManager_GetCurrentEditingString()); 459 460 surface = TTF_RenderUNICODE_Shaded( 461 font, inputedString, INPUTED_COLOR, BACKGROUND_COLOR); 462 *inputedWidth = surface->w; 463 SDL_BlitSurface(surface, NULL, back, NULL); 464 SDL_FreeSurface(surface); 465 DrawCursor(back, font, *inputedWidth); 466 break; 467 case TEXT_MANAGER_MESSAGE_CHAR: 468 stringLength = 469 GetUnicodeStringLength(inputedString) + 1; 470 if ((stringLength + 1) >= INPUTED_STRING_LENGTH_MAX) { 471 break; 472 } 473 inputedChar = TextManager_GetCurrentChar(); 474 inputedString[stringLength - 1] = inputedChar; 475 printf("SHIT: %x\n", inputedChar); 476 inputedString[stringLength] = 0x0000; 477 478 surface = TTF_RenderUNICODE_Shaded( 479 font, inputedString, INPUTED_COLOR, BACKGROUND_COLOR); 480 *inputedWidth = surface->w; 481 SDL_BlitSurface(surface, NULL, back, NULL); 482 SDL_FreeSurface(surface); 483 DrawCursor(back, font, *inputedWidth); 484 break; 485 case TEXT_MANAGER_MESSAGE_IM_OFF: 486 rect.x = 0; 487 rect.y = 100; 488 rect.w = 640; 489 rect.h = 100; 490 SDL_FillRect(back, &rect, 0x00000000); 491 surface = TTF_RenderUTF8_Shaded( 492 font, "IME: OFF", INPUTTING_COLOR, BACKGROUND_COLOR); 493 SDL_BlitSurface(surface, NULL, back, &rect); 494 SDL_FreeSurface(surface); 495 break; 496 default: 497 break; 498 } 499 switch (TextManager_GetCurrentMessage()) { 500 default: 501 break; 502 } 503 TextManager_MoveNextEvent(); 504 eventExpose.type = SDL_VIDEOEXPOSE; 505 SDL_PushEvent(&eventExpose); 506 } 507 508 404 509 int main(int argc, char *argv[]) 405 510 { … … 407 512 SDL_Surface *screen; 408 513 SDL_Surface *back; 409 410 514 SDL_Surface *surface; 411 515 TTF_Font *font; 412 SDL_Color fg = {0x66, 0x66, 0xFF};413 SDL_Color rfg = {0xFF, 0x66, 0x66};414 SDL_Color bg = {0x00, 0x00, 0x00};415 516 SDL_Event eventExpose; 416 517 SDL_Rect rect; 417 518 int inputedWidth; 418 Uint16 *inputedString; 419 int needSize; 420 int stringLength; 519 Uint16 inputedString[INPUTED_STRING_LENGTH_MAX]; 421 520 int result; 422 521 FILE *testFp; 423 Uint16 inputedChar;424 522 425 523 if (SDL_Init(SDL_INIT_VIDEO) < 0) { … … 481 579 rect.h = 100; 482 580 surface = TTF_RenderUTF8_Shaded( 483 font, "IME: OFF", fg, bg);581 font, "IME: OFF", INPUTTING_COLOR, BACKGROUND_COLOR); 484 582 SDL_BlitSurface(surface, NULL, back, &rect); 485 583 rect.x = 0; … … 488 586 rect.h = 100; 489 587 surface = TTF_RenderUTF8_Shaded( 490 font, "Valid", fg, bg);588 font, "Valid", INPUTTING_COLOR, BACKGROUND_COLOR); 491 589 SDL_BlitSurface(surface, NULL, back, &rect); 492 590 rect.x = 0; … … 495 593 rect.h = 100; 496 594 surface = TTF_RenderUNICODE_Shaded( 497 font, TextManager_GetTextManagerName(), fg, bg); 595 font, TextManager_GetTextManagerName(), 596 INPUTTING_COLOR, BACKGROUND_COLOR); 498 597 SDL_BlitSurface(surface, NULL, back, &rect); 499 598 SDL_FreeSurface(surface); … … 501 600 SDL_PushEvent(&eventExpose); 502 601 503 inputedString = malloc(sizeof(Uint16));504 602 inputedString[0] = 0x0000; 505 603 inputedWidth = 0; … … 514 612 } else { 515 613 if (TextManager_GetEventNumber() > 0) { 516 rect.x = inputedWidth; 517 rect.y = 0; 518 rect.w = 640 - inputedWidth; 519 rect.h = 99; 520 SDL_FillRect(back, &rect, 0x00000000); 521 522 switch (TextManager_GetCurrentMessage()) { 523 case TEXT_MANAGER_MESSAGE_IM_ON: 524 rect.x = 0; 525 rect.y = 100; 526 rect.w = 640; 527 rect.h = 100; 528 SDL_FillRect(back, &rect, 0x00000000); 529 surface = TTF_RenderUTF8_Shaded( 530 font, "IME: ON", fg, bg); 531 SDL_BlitSurface(surface, NULL, back, &rect); 532 SDL_FreeSurface(surface); 533 DrawCursor(back, font, inputedWidth); 534 break; 535 case TEXT_MANAGER_MESSAGE_IM_CHANGE: 536 MessageChange(back, font, inputedWidth); 537 break; 538 case TEXT_MANAGER_MESSAGE_IM_RESULT: 539 stringLength = 540 GetUnicodeStringLength(inputedString) + 541 GetUnicodeStringLength( 542 TextManager_GetCurrentEditingString()); 543 needSize = stringLength * sizeof(Uint16) + sizeof(Uint16); 544 inputedString = realloc(inputedString, needSize); 545 CatUnicodeString( 546 inputedString, 547 TextManager_GetCurrentEditingString()); 548 549 surface = TTF_RenderUNICODE_Shaded( 550 font, inputedString, rfg, bg); 551 inputedWidth = surface->w; 552 SDL_BlitSurface(surface, NULL, back, NULL); 553 SDL_FreeSurface(surface); 554 DrawCursor(back, font, inputedWidth); 555 break; 556 case TEXT_MANAGER_MESSAGE_CHAR: 557 stringLength = 558 GetUnicodeStringLength(inputedString) + 1; 559 needSize = stringLength * sizeof(Uint16) + sizeof(Uint16); 560 inputedString = realloc(inputedString, needSize); 561 inputedChar = TextManager_GetCurrentChar(); 562 inputedString[stringLength - 1] = inputedChar; 563 printf("SHIT: %x\n", inputedChar); 564 inputedString[stringLength] = 0x0000; 565 566 surface = TTF_RenderUNICODE_Shaded( 567 font, inputedString, rfg, bg); 568 inputedWidth = surface->w; 569 SDL_BlitSurface(surface, NULL, back, NULL); 570 SDL_FreeSurface(surface); 571 DrawCursor(back, font, inputedWidth); 572 break; 573 case TEXT_MANAGER_MESSAGE_IM_OFF: 574 rect.x = 0; 575 rect.y = 100; 576 rect.w = 640; 577 rect.h = 100; 578 SDL_FillRect(back, &rect, 0x00000000); 579 surface = TTF_RenderUTF8_Shaded( 580 font, "IME: OFF", fg, bg); 581 SDL_BlitSurface(surface, NULL, back, &rect); 582 SDL_FreeSurface(surface); 583 break; 584 default: 585 break; 586 } 587 switch (TextManager_GetCurrentMessage()) { 588 default: 589 break; 590 } 591 TextManager_MoveNextEvent(); 592 eventExpose.type = SDL_VIDEOEXPOSE; 593 SDL_PushEvent(&eventExpose); 614 ProcessMessage(back, font, inputedString, &inputedWidth); 594 615 } 595 616 SDL_Delay(5);
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)