저는 Xlib을 사용하는 C 프로그램에서 애니메이션을 만들려고했는데 이벤트가 발생할 때 뭔가하고 싶습니다. 그렇지 않으면 계속 애니메이트하고 싶습니다. 여기에 현재 뭐하는 거지의 예제 코드는 다음과 같습니다Xlib에서 이벤트가 발생할 때까지 어떻게 애니메이트 할 수 있습니까?
while(1)
{
// If an event occurs, stop and do whatever is needed.
// If no event occurs, skip this if statement.
if (XEventsQueued(display, QueuedAlready) > 0)
{
XNextEvent(display, &event)
switch (event.type)
{
// Don't do anything
case Expose:
while (event.xexpose.count != 0)
break;
// Do something, when a button is pressed
case ButtonPress:
...
break;
// Do something, when a key is pressed
case KeyPress:
...
break;
}
}
animate(); // Do animation step i.e. change any drawings...
repaint(); // Paint again with the new changes from animation...
}
을 그러니까 기본적으로, 나는 사용자가 마우스를 클릭하거나 아직 키보드의 키를 눌렀을하지 않을 경우 반복 계속 싶어요. 사용자가 키를 누르거나 마우스를 클릭하면 특정 작업을 중단하고 수행하고 싶습니다. 위의 코드에서 문제는 동작을 수행 할 때마다 멈추지 않는다는 것입니다. if 문을 제거하면 애니메이션이 이벤트가 발생할 때까지 차단되지만 나는 이것을 원하지 않습니다. 이것은 간단한 문제이지만 Xlib/애니메이션에 익숙하지 않아 도움이 될 것입니다. 감사.