Changeset 15449 for lang/c

Show
Ignore:
Timestamp:
07/08/08 12:54:34 (5 months ago)
Author:
itkz
Message:

fixed win32

Location:
lang/c/SDL_textmanager
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/c/SDL_textmanager/SDL_textmanager.h

    r14719 r15449  
    8686        TEXT_MANAGER_ERROR_INVALID_BOOTSTRAP 
    8787} TextManager_Result; 
     88 
     89extern DECLSPEC TextManager_Result SDLCALL TextManager_Init(void); 
     90 
     91extern DECLSPEC int SDLCALL TextManager_GetEventNumber(void); 
     92extern DECLSPEC void SDLCALL TextManager_MoveNextEvent(void); 
     93extern DECLSPEC TextManager_Message SDLCALL TextManager_GetCurrentMessage(void); 
     94extern DECLSPEC Uint16 * SDLCALL TextManager_GetCurrentEditingString(void); 
     95extern DECLSPEC Uint16 SDLCALL TextManager_GetCurrentChar(void); 
     96extern DECLSPEC int SDLCALL TextManager_GetCurrentCursorPosition(void); 
     97extern DECLSPEC int SDLCALL TextManager_GetCurrentCompositionPosition(void); 
     98extern DECLSPEC int SDLCALL TextManager_GetCurrentCompositionLength(void); 
     99extern DECLSPEC void SDLCALL TextManager_Reset(void); 
     100extern DECLSPEC TextManager_Result SDLCALL TextManager_Validate(void); 
     101extern DECLSPEC TextManager_Result SDLCALL TextManager_Invalidate(void); 
     102extern DECLSPEC Uint16 * SDLCALL TextManager_GetTextManagerName(void); 
     103 
     104extern 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 
    88113 
    89114typedef enum 
     
    110135        DEAD_CHAR_HORN 
    111136} 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 256 
    137137 
    138138typedef struct _SDL_TextManager 
  • lang/c/SDL_textmanager/test/main.c

    r14713 r15449  
    3131 
    3232 
     33SDL_Color INPUTED_COLOR = {0xFF, 0x66, 0x66}; 
     34SDL_Color CURSOR_COLOR = {0x66, 0xFF, 0x66}; 
     35SDL_Color INPUTTING_COLOR = {0x66, 0x66, 0xFF}; 
     36SDL_Color BACKGROUND_COLOR = {0x00, 0x00, 0x00}; 
     37 
     38 
     39#define INPUTED_STRING_LENGTH_MAX 1024 
     40 
     41 
    3342int GetUnicodeStringLength(Uint16 *unicodeString) 
    3443{ 
     
    105114{ 
    106115        SDL_Rect rect; 
    107         SDL_Color bg = {0x00, 0x00, 0x00}; 
    108         SDL_Color cfg = {0x66, 0xFF, 0x66}; 
    109116        int cursorWidth; 
    110117        SDL_Surface *surface; 
     
    114121        rect.w = 640 - cursorPosition; 
    115122        rect.h = 100; 
    116         surface = TTF_RenderUTF8_Shaded(font, "|", cfg, bg); 
     123        surface = TTF_RenderUTF8_Shaded( 
     124                font, "|", CURSOR_COLOR, BACKGROUND_COLOR); 
    117125        SDL_BlitSurface(surface, NULL, back, &rect); 
    118126        cursorWidth = surface->w; 
     
    140148                rect.w = 640 - drawStartWidth; 
    141149                rect.h = 100; 
    142                 surface = TTF_RenderUNICODE_Shaded(font, string, fg, bg); 
     150                surface = TTF_RenderUNICODE_Shaded( 
     151                        font, string, INPUTTING_COLOR, BACKGROUND_COLOR); 
    143152                 
    144153                SDL_BlitSurface(surface, NULL, back, &rect); 
     
    155164                nowWidth = 0; 
    156165                needSize = (cursorPosition + 1) * sizeof(Uint16); 
    157                 splitString = (Uint16*)calloc(needSize, 1); 
     166                splitString = (Uint16*)malloc(needSize); 
    158167                if (splitString == NULL) { 
    159168                        return -1; 
    160169                } 
    161170                memcpy(splitString, string, cursorPosition * sizeof(Uint16)); 
     171                splitString[cursorPosition] = 0x0000; 
    162172                rect.x = drawStartWidth + nowWidth; 
    163173                rect.y = 0; 
    164174                rect.w = 640 - (drawStartWidth + nowWidth); 
    165175                rect.h = 100; 
    166                 surface = TTF_RenderUNICODE_Shaded(font, splitString, fg, bg); 
     176                surface = TTF_RenderUNICODE_Shaded( 
     177                        font, splitString, INPUTTING_COLOR, BACKGROUND_COLOR); 
    167178                free(splitString); 
    168179                 
     
    178189        if (stringLength > 0) { 
    179190                needSize = (stringLength + 1) * sizeof(Uint16); 
    180                 splitString = (Uint16*)calloc(needSize, 1); 
     191                splitString = (Uint16*)malloc(needSize); 
    181192                if (splitString == NULL) { 
    182193                        return -1; 
     
    187198                rect.w = 640 - drawStartWidth + nowWidth; 
    188199                rect.h = 100; 
    189                 surface = TTF_RenderUNICODE_Shaded(font, splitString, fg, bg); 
     200                surface = TTF_RenderUNICODE_Shaded( 
     201                        font, splitString, INPUTTING_COLOR, BACKGROUND_COLOR); 
    190202                SDL_BlitSurface(surface, NULL, back, &rect); 
    191203                nowWidth += surface->w; 
    192204                SDL_FreeSurface(surface); 
     205                free(splitString); 
    193206        } 
    194207         
     
    402415 
    403416 
     417void 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; 
     475printf("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 
    404509int main(int argc, char *argv[]) 
    405510{ 
     
    407512        SDL_Surface *screen; 
    408513        SDL_Surface *back; 
    409          
    410514        SDL_Surface *surface; 
    411515        TTF_Font *font; 
    412         SDL_Color fg = {0x66, 0x66, 0xFF}; 
    413         SDL_Color rfg = {0xFF, 0x66, 0x66}; 
    414         SDL_Color bg = {0x00, 0x00, 0x00}; 
    415516        SDL_Event eventExpose; 
    416517        SDL_Rect rect; 
    417518        int inputedWidth; 
    418         Uint16 *inputedString; 
    419         int needSize; 
    420         int stringLength; 
     519        Uint16 inputedString[INPUTED_STRING_LENGTH_MAX]; 
    421520        int result; 
    422521        FILE *testFp; 
    423         Uint16 inputedChar; 
    424522         
    425523        if (SDL_Init(SDL_INIT_VIDEO) < 0) { 
     
    481579        rect.h = 100; 
    482580        surface = TTF_RenderUTF8_Shaded( 
    483                 font, "IME: OFF", fg, bg); 
     581                font, "IME: OFF", INPUTTING_COLOR, BACKGROUND_COLOR); 
    484582        SDL_BlitSurface(surface, NULL, back, &rect); 
    485583        rect.x = 0; 
     
    488586        rect.h = 100; 
    489587        surface = TTF_RenderUTF8_Shaded( 
    490                 font, "Valid", fg, bg); 
     588                font, "Valid", INPUTTING_COLOR, BACKGROUND_COLOR); 
    491589        SDL_BlitSurface(surface, NULL, back, &rect); 
    492590        rect.x = 0; 
     
    495593        rect.h = 100; 
    496594        surface = TTF_RenderUNICODE_Shaded( 
    497                 font, TextManager_GetTextManagerName(), fg, bg); 
     595                font, TextManager_GetTextManagerName(), 
     596                INPUTTING_COLOR, BACKGROUND_COLOR); 
    498597        SDL_BlitSurface(surface, NULL, back, &rect); 
    499598        SDL_FreeSurface(surface); 
     
    501600        SDL_PushEvent(&eventExpose); 
    502601         
    503         inputedString = malloc(sizeof(Uint16)); 
    504602        inputedString[0] = 0x0000; 
    505603        inputedWidth = 0; 
     
    514612                } else { 
    515613                        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); 
    594615                        } 
    595616                        SDL_Delay(5);