From c126f279e8489ee6f679f7eebb00f0fe405adef4 Mon Sep 17 00:00:00 2001 From: William McBrine Date: Sun, 7 Jan 2018 14:22:16 -0500 Subject: [PATCH] Same for SDL1. --- sdl1/pdcdisp.c | 30 +++++++++++++++++++++++++++++- sdl1/pdckbd.c | 2 ++ sdl1/pdcsdl.h | 2 ++ sdl1/pdcsetsc.c | 31 +++++++++++++++++++++++++++++-- 4 files changed, 62 insertions(+), 3 deletions(-) diff --git a/sdl1/pdcdisp.c b/sdl1/pdcdisp.c index 896af7be..f5a68ad8 100644 --- a/sdl1/pdcdisp.c +++ b/sdl1/pdcdisp.c @@ -72,6 +72,7 @@ static SDL_Rect uprect[MAXRECT]; /* table of rects to update */ static chtype oldch = (chtype)(-1); /* current attribute */ static int rectcount = 0; /* index into uprect */ static short foregr = -2, backgr = -2; /* current foreground, background */ +static bool blinked_off = FALSE; /* do the real updates on a delay */ @@ -359,6 +360,9 @@ void PDC_transform_line(int lineno, int x, int len, const chtype *srcp) _set_attr(ch); + if (blinked_off && (ch & A_BLINK)) + ch = (ch & A_ATTRIBUTES) | ' '; + #ifdef CHTYPE_LONG if (ch & A_ALTCHARSET && !(ch & 0xff80)) ch = (ch & (A_ATTRIBUTES ^ A_ALTCHARSET)) | acs_map[ch & 0x7f]; @@ -397,9 +401,33 @@ void PDC_transform_line(int lineno, int x, int len, const chtype *srcp) SDL_LowerBlit(pdc_font, &src, pdc_screen, &dest); #endif - if (ch & (A_UNDERLINE|A_LEFTLINE|A_RIGHTLINE)) + if (!(blinked_off && (ch & A_BLINK)) && + (ch & (A_UNDERLINE|A_LEFTLINE|A_RIGHTLINE))) _highlight(&src, &dest, ch); dest.x += pdc_fwidth; } } + +void PDC_blink_text(void) +{ + int i, j, k; + + blinked_off = !blinked_off; + + for (i = 0; i < SP->lines; i++) + { + const chtype *srcp = curscr->_y[i]; + + for (j = 0; j < SP->cols; j++) + if (srcp[j] & A_BLINK) + { + k = j; + while (k < SP->cols && (srcp[k] & A_BLINK)) + k++; + PDC_transform_line(i, j, k - j, srcp + j); + j = k; + } + } + +} diff --git a/sdl1/pdckbd.c b/sdl1/pdckbd.c index c598a4f3..f349f3df 100644 --- a/sdl1/pdckbd.c +++ b/sdl1/pdckbd.c @@ -382,6 +382,8 @@ int PDC_get_key(void) case SDL_KEYDOWN: PDC_mouse_set(); return _process_key_event(); + case SDL_USEREVENT: + PDC_blink_text(); } return -1; diff --git a/sdl1/pdcsdl.h b/sdl1/pdcsdl.h index 4103405e..338902b6 100644 --- a/sdl1/pdcsdl.h +++ b/sdl1/pdcsdl.h @@ -29,3 +29,5 @@ extern Uint32 pdc_lastupdate; /* time of last update, in ticks */ PDCEX void PDC_update_rects(void); PDCEX void PDC_retile(void); + +extern void PDC_blink_text(void); diff --git a/sdl1/pdcsetsc.c b/sdl1/pdcsetsc.c index f05601d3..c93d8a40 100644 --- a/sdl1/pdcsetsc.c +++ b/sdl1/pdcsetsc.c @@ -59,13 +59,40 @@ void PDC_set_title(const char *title) SDL_WM_SetCaption(title, 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) { - SP->termattrs &= ~A_BLINK; + static SDL_TimerID id; + if (pdc_color_started) COLORS = 256; - return blinkon ? ERR : OK; + if (blinkon) + { + if (!(SP->termattrs & A_BLINK)) + { + id = SDL_AddTimer(500, _blink_timer, NULL); + SP->termattrs |= A_BLINK; + } + } + else + { + if (SP->termattrs & A_BLINK) + { + SDL_RemoveTimer(id); + SP->termattrs &= ~A_BLINK; + } + } + + return OK; } int PDC_set_bold(bool boldon)