From 7a2c74e4ddedaa0b3e8660fa3ba1045fcc4384ca Mon Sep 17 00:00:00 2001 From: William McBrine Date: Sun, 7 Jan 2018 18:29:51 -0500 Subject: [PATCH] SDL blink refinement -- as in X11, ensure start on solid, and re-render after shutdown. --- sdl2/pdcdisp.c | 30 +++++++++++++++++++++++++++--- sdl2/pdcsetsc.c | 15 ++------------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/sdl2/pdcdisp.c b/sdl2/pdcdisp.c index 602ba670..f7c5e86d 100644 --- a/sdl2/pdcdisp.c +++ b/sdl2/pdcdisp.c @@ -315,8 +315,8 @@ void PDC_transform_line(int lineno, int x, int len, const chtype *srcp) int j; #ifdef PDC_WIDE Uint16 chstr[2] = {0, 0}; - attr_t sysattrs = SP->termattrs; #endif + attr_t sysattrs = SP->termattrs; PDC_LOG(("PDC_transform_line() - called: lineno=%d\n", lineno)); @@ -362,7 +362,7 @@ void PDC_transform_line(int lineno, int x, int len, const chtype *srcp) _set_attr(ch); - if (blinked_off && (ch & A_BLINK)) + if (blinked_off && (ch & A_BLINK) && (sysattrs & A_BLINK)) ch = (ch & A_ATTRIBUTES) | ' '; #ifdef CHTYPE_LONG @@ -403,7 +403,7 @@ void PDC_transform_line(int lineno, int x, int len, const chtype *srcp) SDL_LowerBlit(pdc_font, &src, pdc_screen, &dest); #endif - if (!(blinked_off && (ch & A_BLINK)) && + if (!(blinked_off && (ch & A_BLINK) && (sysattrs & A_BLINK)) && (ch & (A_UNDERLINE|A_LEFTLINE|A_RIGHTLINE))) _highlight(&src, &dest, ch); @@ -411,10 +411,33 @@ void PDC_transform_line(int lineno, int x, int len, const chtype *srcp) } } +static Uint32 _blink_timer(Uint32 interval, void *param) +{ + SDL_Event event; + + event.type = SDL_USEREVENT; + SDL_PushEvent(&event); + return(interval); +} + void PDC_blink_text(void) { + static SDL_TimerID blinker_id = 0; int i, j, k; + oldch = (chtype)(-1); + + if (!(SP->termattrs & A_BLINK)) + { + SDL_RemoveTimer(blinker_id); + blinker_id = 0; + } + else if (!blinker_id) + { + blinker_id = SDL_AddTimer(500, _blink_timer, NULL); + blinked_off = TRUE; + } + blinked_off = !blinked_off; for (i = 0; i < SP->lines; i++) @@ -432,4 +455,5 @@ void PDC_blink_text(void) } } + oldch = (chtype)(-1); } diff --git a/sdl2/pdcsetsc.c b/sdl2/pdcsetsc.c index 934fcf2f..506efb7b 100644 --- a/sdl2/pdcsetsc.c +++ b/sdl2/pdcsetsc.c @@ -59,19 +59,8 @@ void PDC_set_title(const char *title) SDL_SetWindowTitle(pdc_window, title); } -static Uint32 _blink_timer(Uint32 interval, void *param) -{ - SDL_Event event; - - event.type = SDL_USEREVENT; - SDL_PushEvent(&event); - return(interval); -} - int PDC_set_blink(bool blinkon) { - static SDL_TimerID id; - if (pdc_color_started) COLORS = 256; @@ -79,16 +68,16 @@ int PDC_set_blink(bool blinkon) { if (!(SP->termattrs & A_BLINK)) { - id = SDL_AddTimer(500, _blink_timer, NULL); SP->termattrs |= A_BLINK; + PDC_blink_text(); } } else { if (SP->termattrs & A_BLINK) { - SDL_RemoveTimer(id); SP->termattrs &= ~A_BLINK; + PDC_blink_text(); } }