* Use SDL_WaitEvent instead of SDL_PollEvent.

* To avoid the program getting 'locked' when there is no user input (sliders, colorspray), we use a timer that queues events to make grafX2 act (and refresh the screen)

TODO :
 * To reduce cpu usage when idle even more, start the timer only when it's needed (colorspray is drawing, or a scrollbar is scrolling)
 * For now everyone uses the same timer, so the same delay. This means there is no fast-scroll and slow-scroll for sliders. Starting the timer with a different speed in each case would solve that
 * The event handling for sliders will currently react to any mouse event. Thismeans the slider will move faster if you slightly move the mouse while keeping in the button. Not what wewant, so weshoud all a timer_expired global and the slider should wait for that (and reset it when acknowledged).

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1556 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Adrien Destugues
2010-08-06 15:40:01 +00:00
parent bce1c9d7ee
commit 5ee0b4943f
5 changed files with 37 additions and 20 deletions

View File

@@ -409,6 +409,30 @@ int Analyze_command_line(int argc, char * argv[], char *main_filename, char *mai
return file_in_command_line;
}
Uint32 putTimerEvent(Uint32 i, void* p)
{
SDL_Event event;
SDL_UserEvent userevent;
/* Dans cet exemple, notre fonction de rappel pousse
un evenement SDL_USEREVENT dans la file... */
userevent.type = SDL_USEREVENT;
userevent.code = 0;
userevent.data1 = NULL;
userevent.data2 = NULL;
event.type = SDL_USEREVENT;
event.user = userevent;
SDL_PushEvent(&event);
return i;
}
// ------------------------ Initialiser le programme -------------------------
// Returns 0 on fail
int Init_program(int argc,char * argv[])
@@ -521,6 +545,7 @@ int Init_program(int argc,char * argv[])
printf("Couldn't initialize SDL.\n");
return(0);
}
SDL_TimerID tid = SDL_AddTimer(10, putTimerEvent, NULL);
Joystick = SDL_JoystickOpen(0);
SDL_EnableKeyRepeat(250, 32);