2010-11-24 3 views
3

SDL에서 마우스 위치에 이상한 동작이 나타납니다. 창 크기를 다시 조정하면 두 마우스 이벤트의 x, y 위치가 원본 창 너비와 높이로 제한됩니다.SDL 마우스 위치 변경 후 잘림

내가 SDL에게 마우스 포인터의 크기가 커 졌음을 알리는 일부 함수 호출이있는 경우. 응용 프로그램의

관련 부품 :

void Resize(int width, int height) 
{ 
    WindowWidth = width; 
    WindowHeight = height; 
    /* update OpenGL */ 
} 

void Init() 
{ 
    glClearColor(0.f, 0.f, 0.f, 1.f); 
    Resize(WindowWidth, WindowHeight); 
} 

void MouseClick(int button, int state, int x, int y) 
{ 
    unsigned int MouseButton = unsigned(Mouse.z); 
    unsigned int b = (1 << (button-1)); 
    if (state) 
     MouseButton = MouseButton | b; 
    else 
     MouseButton = MouseButton & (~b); 
    Mouse.z = MouseButton; 
    Mouse.x = x; 
    Mouse.y = y; 
} 

void MouseMove(int x, int y) 
{ 
    MouseRel.x = x - Mouse.x; 
    MouseRel.y = y - Mouse.y; 
    Mouse.x = x; 
    Mouse.y = y; 
} 

int main(int agrc, char *argv[]) 
{ 
    bool quit = false; 
    SDL_Event event; 

    if (SDL_Init(SDL_INIT_VIDEO) < 0) 
     return 1; 

    if (SDL_SetVideoMode(WindowWidth, WindowHeight, 0, SDL_OPENGL | SDL_RESIZABLE) == NULL) 
     return 2; 

    Init(); 

    while (!quit) 
    { 
     DrawScene(); 
     while (SDL_PollEvent(&event)) 
     { 
      if (event.type == SDL_VIDEORESIZE) 
      { 
       Resize(event.resize.w, event.resize.h); 
      } 
      else if (event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_MOUSEBUTTONUP) 
      { 
       MouseClick(event.button.button, event.button.state, event.button.x, WindowHeight - event.button.y); 
       printf("event.button (%i, %i)\n", event.button.x, event.button.y); 
       MouseHandler(); 
      } 
      else if (event.type == SDL_MOUSEMOTION) 
      { 
       MouseMove(event.motion.x, WindowHeight - event.motion.y); 
       printf("event.motion (%i, %i)\n", event.motion.x, event.motion.y); 
       MouseHandler(); 
      } 
      else if (event.type == SDL_QUIT) 
       quit |= true; 
     } 
     quit |= KeyboardHandler(); 
     SDL_Delay(10); 
    } 
    SDL_Quit(); 
    return 0; 
} 
+0

OS? SDL 버전? – genpfault

+0

[SDL_VIDEORESIZE-triggered 'SDL_SetVideoMode()'] (http://www.libsdl.org/cgi/docwiki.cgi/SDL_ResizeEvent) 호출은 어디에 있습니까? – genpfault

+2

Windows XP 및 SDL 버전 1.2.13. OpenGL 컨텍스트를 다시 설정하기 때문에 SDL_SetVideoMode()가 실제로 필요하다는 것은 약간 이상하게 보입니다. 필자의 프로토 타입에서는 커다란 문제는 아니지만 더 나아가서는 모든 OpenGL 객체를 다시로드한다는 의미입니다. – thing2k

답변

0

시도는 SDL_VIDEORESIZE 핸들러에서 SDL_SetVideoMode()를 다시 호출.

+1

http://hg.libsdl.org/SDL에서 SDL의 소스를 살펴본 후 클리핑 된 부분을 확인할 수 있습니다. SDL_mouse.c는 135-146 행으로 SDL_VideoSurface 너비와 높이로 자릅니다. SDL_SetVideoMode에 대한 호출에 의해서만 설정됩니다. SDL_PrivateResize (SDL_resize.c)에서 SDL_VideoSurface 크기가 업데이트 된 경우 작동했을 것입니다. – thing2k