[ÀÌÀü] ¸ñÂ÷ [´ÙÀ½]

Simple DirectMedia Layer API »ç¿ëÇϱâ

À̺¥Æ®(Events)

  • À̺¥Æ® ±â´Ù¸®±â

SDL_WaitEvent() ÇÔ¼ö¸¦ »ç¿ëÇؼ­ À̺¥Æ®¸¦ ±â´Ù¸°´Ù.

ÆÁ:
SDL Àº ±¹Á¦ Å°º¸µå¸¦ Áö¿øÇÑ´Ù. Å° À̺¥Æ®¸¦ À¯´ÏÄÚµå¿Í À¯»çÇÑ ÄÚµå·Î ¹Ù²Ù¾î event.key.keysym.unicode ¿¡ ³Ö´Â´Ù. ÀÌ·¯ÇÑ ÀÛ¾÷Àº ¾à°£ÀÇ ÇÁ·Î¼¼½Ì ¿À¹öÇìµå¸¦ °¨¼öÇØ¾ß Çϱ⠶§¹®¿¡, SDL_EnableUNICODE() °¡ È°¼ºÈ­µÇ¾î¾ß¸¸ »ç¿ëµÈ´Ù.
¿¹Á¦:
{
    SDL_Event event;

    SDL_WaitEvent(&event);

    switch (event.type) {
        case SDL_KEYDOWN:
            printf("The %s key was pressed!\n",
                   SDL_GetKeyName(event.key.keysym.sym));
            break;
        case SDL_QUIT:
            exit(0);
    }
}
  • À̺¥Æ®¸¦ Æú¸µ(Polling)Çϱâ

SDL_PollEvent() ÇÔ¼ö¸¦ »ç¿ëÇؼ­ À̺¥Æ®¸¦ Æú¸µÇÑ´Ù(°Ë»çÇÑ´Ù).

ÆÁ:
SDL_PeepEvents() ÇÔ¼ö¿¡ SDL_PEEKEVENT ¸¦ ³Ñ°Ü À̺¥Æ®¸¦ »èÁ¦ÇÏÁö ¾Ê°íµµ À̺¥Æ® Å¥¿¡¼­ À̺¥Æ®¸¦ È®ÀÎÇÒ ¼ö ÀÖ´Ù.
¿¹Á¦:
{
    SDL_Event event;

    while ( SDL_PollEvent(&event) ) {
        switch (event.type) {
            case SDL_MOUSEMOTION:
                printf("Mouse moved by %d,%d to (%d,%d)\n", 
                       event.motion.xrel, event.motion.yrel,
                       event.motion.x, event.motion.y);
                break;
            case SDL_MOUSEBUTTONDOWN:
                printf("Mouse button %d pressed at (%d,%d)\n",
                       event.button.button, event.button.x, event.button.y);
                break;
            case SDL_QUIT:
                exit(0);
        }
    }
}
  • À̺¥Æ® »óŸ¦ Æú¸µÇϱâ(Polling)

À̺¥Æ®¸¦ Á÷Á¢ÀûÀ¸·Î ó¸®ÇÏ´Â °Í »Ó¸¸ ¾Æ´Ï¶ó, °¢ À̺¥Æ® ŸÀÔÀº ¾ÖÇø®ÄÉÀÌ¼Ç À̺¥Æ® »óŸ¦ üũÇÒ ¼ö ÀÖ´Â ÇÔ¼ö¸¦ Á¦°øÇÑ´Ù. ¸¸¾à ÀÌ ÇÔ¼ö¸¦ µ¶Á¡ÀûÀ¸·Î »ç¿ëÇϸé, SDL_EventState() ÇÔ¼ö·Î ¸ðµç À̺¥Æ®¸¦ ¹«½ÃÇÏ°í, SDL_PumpEvents() ÇÔ¼ö¸¦ ÁÖ±âÀûÀ¸·Î È£ÃâÇÏ¿© ¾ÖÇø®ÄÉÀÌ¼Ç À̺¥Æ® »óŸ¦ °»½ÅÇؾ߸¸ ÇÑ´Ù.

ÆÁ:
SDL_ShowCursor() ¸¦ »ç¿ëÇؼ­ ½Ã½ºÅÛ ¸¶¿ì½º Ä¿¼­¸¦ °¨Ã߰ųª º¸ÀÌ°Ô ÇÒ ¼ö ÀÖ´Ù.
¿¹Á¦:
{
    SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
}

void CheckMouseHover(void)
{
    int mouse_x, mouse_y;

    SDL_PumpEvents();

    SDL_GetMouseState(&mouse_x, &mouse_y);
    if ( (mouse_x < 32) && (mouse_y < 32) ) {
        printf("Mouse in upper left hand corner!\n");
    }
}

[ÀÌÀü] ¸ñÂ÷ [´ÙÀ½]