Make SDL2 more responsive to expose/restore events -- see part 2 of #71.

This commit is contained in:
William McBrine
2019-12-08 10:52:38 -05:00
parent 67060f16b7
commit c85d95aebe
5 changed files with 24 additions and 8 deletions

View File

@@ -556,6 +556,5 @@ void PDC_blink_text(void)
void PDC_doupdate(void)
{
PDC_update_rects();
SDL_Delay(1);
PDC_napms(1);
}

View File

@@ -400,6 +400,19 @@ static int _process_mouse_event(void)
return KEY_MOUSE;
}
int PDC_event_filter(void *userdata, SDL_Event *event)
{
if (SDL_WINDOWEVENT == event->type &&
(SDL_WINDOWEVENT_RESTORED == event->window.event ||
SDL_WINDOWEVENT_EXPOSED == event->window.event))
{
SDL_UpdateWindowSurface(pdc_window);
return 0;
}
return 1;
}
/* return the next available key or mouse event */
int PDC_get_key(void)
@@ -409,9 +422,8 @@ int PDC_get_key(void)
case SDL_QUIT:
exit(1);
case SDL_WINDOWEVENT:
switch (event.window.event)
if (SDL_WINDOWEVENT_SIZE_CHANGED == event.window.event)
{
case SDL_WINDOWEVENT_SIZE_CHANGED:
pdc_screen = SDL_GetWindowSurface(pdc_window);
pdc_sheight = pdc_screen->h - pdc_xoffset;
pdc_swidth = pdc_screen->w - pdc_yoffset;
@@ -424,10 +436,6 @@ int PDC_get_key(void)
SP->key_code = TRUE;
return KEY_RESIZE;
}
break;
case SDL_WINDOWEVENT_RESTORED:
case SDL_WINDOWEVENT_EXPOSED:
SDL_UpdateWindowSurface(pdc_window);
}
break;
case SDL_MOUSEMOTION:

View File

@@ -311,6 +311,8 @@ int PDC_scr_open(void)
PDC_reset_prog_mode();
SDL_SetEventFilter(PDC_event_filter, NULL);
return OK;
}

View File

@@ -32,4 +32,5 @@ extern bool pdc_own_window; /* if pdc_window was not set
PDCEX void PDC_update_rects(void);
PDCEX void PDC_retile(void);
extern int PDC_event_filter(void *, SDL_Event *);
extern void PDC_blink_text(void);

View File

@@ -12,6 +12,12 @@ void PDC_napms(int ms)
PDC_LOG(("PDC_napms() - called: ms=%d\n", ms));
PDC_update_rects();
while (ms > 50)
{
SDL_PumpEvents();
SDL_Delay(50);
ms -= 50;
}
SDL_PumpEvents();
SDL_Delay(ms);
}