115
113
struct driver_private
116
unsigned int sigint_event;
119
static void default_sigint (int sig)
121
/* Warn the caller that we got SIGINT. */
122
sigwinch_d->drv.p->sigint_event++;
120
125
static int slang_init_graphics(caca_display_t *dp)
122
127
dp->drv.p = malloc(sizeof(struct driver_private));
128
dp->drv.p->sigint_event = 0;
124
130
#if defined(HAVE_GETENV) && defined(HAVE_PUTENV)
125
131
slang_install_terminal(dp);
221
233
static void slang_display(caca_display_t *dp)
223
uint32_t const *cvchars = (uint32_t const *)caca_get_canvas_chars(dp->cv);
224
uint32_t const *cvattrs = (uint32_t const *)caca_get_canvas_attrs(dp->cv);
225
int width = caca_get_canvas_width(dp->cv);
226
int height = caca_get_canvas_height(dp->cv);
229
for(y = 0; y < (int)height; y++)
237
SLsig_block_signals();
238
for(i = 0; i < caca_get_dirty_rect_count(dp->cv); i++)
232
for(x = width; x--; )
240
uint32_t const *cvchars, *cvattrs;
243
caca_get_dirty_rect(dp->cv, i, &dx, &dy, &dw, &dh);
245
cvchars = caca_get_canvas_chars(dp->cv) + dx + dy * dp->cv->width;
246
cvattrs = caca_get_canvas_attrs(dp->cv) + dx + dy * dp->cv->width;
248
for(y = dy; y < dy + dh; y++)
234
uint32_t ch = *cvchars++;
251
for(x = dx; x < dx + dw; x++)
253
uint32_t ch = *cvchars++;
236
255
#if defined(OPTIMISE_SLANG_PALETTE)
237
/* If foreground == background, just don't use this colour
238
* pair, and print a space instead of the real character.
239
* XXX: disabled, because I can't remember what it was
240
* here for, and in cases where SLang does not render
241
* bright backgrounds, it's just fucked up. */
256
/* If foreground == background, just don't use this colour
257
* pair, and print a space instead of the real character. */
258
/* XXX: disabled, because I can't remember what it was
259
* here for, and in cases where SLang does not render
260
* bright backgrounds, it's just fucked up. */
243
uint8_t fgcolor = caca_attr_to_ansi_fg(*cvattrs);
244
uint8_t bgcolor = caca_attr_to_ansi_bg(*cvattrs);
247
fgcolor = CACA_LIGHTGRAY;
250
bgcolor = CACA_BLACK; /* FIXME: handle transparency */
252
if(fgcolor == bgcolor)
254
if(fgcolor == CACA_BLACK)
255
fgcolor = CACA_WHITE;
256
else if(fgcolor == CACA_WHITE
257
|| fgcolor <= CACA_LIGHTGRAY)
258
fgcolor = CACA_BLACK;
262
uint8_t fgcolor = caca_attr_to_ansi_fg(*cvattrs);
263
uint8_t bgcolor = caca_attr_to_ansi_bg(*cvattrs);
266
fgcolor = CACA_LIGHTGRAY;
269
bgcolor = CACA_BLACK; /* FIXME: handle transparency */
271
if(fgcolor == bgcolor)
273
if(fgcolor == CACA_BLACK)
274
fgcolor = CACA_WHITE;
275
else if(fgcolor == CACA_WHITE
276
|| fgcolor <= CACA_LIGHTGRAY)
277
fgcolor = CACA_BLACK;
279
fgcolor = CACA_WHITE;
280
SLsmg_set_color(slang_assoc[fgcolor + 16 * bgcolor]);
281
SLsmg_write_char(' ');
260
fgcolor = CACA_WHITE;
261
SLsmg_set_color(slang_assoc[fgcolor + 16 * bgcolor]);
262
SLsmg_write_char(' ');
268
SLsmg_set_color(slang_assoc[caca_attr_to_ansi(*cvattrs++)]);
287
SLsmg_set_color(slang_assoc[caca_attr_to_ansi(*cvattrs++)]);
288
slang_write_utf32(ch);
291
SLsmg_set_color(caca_attr_to_ansi(*cvattrs++));
269
292
slang_write_utf32(ch);
272
SLsmg_set_color(caca_attr_to_ansi(*cvattrs++));
273
slang_write_utf32(ch);
296
cvchars += dp->cv->width - dw;
297
cvattrs += dp->cv->width - dw;
277
SLsmg_gotorc(caca_get_cursor_y(dp->cv), caca_get_cursor_x(dp->cv));
300
SLsmg_gotorc(caca_wherey(dp->cv), caca_wherex(dp->cv));
302
SLsig_unblock_signals();
281
305
static void slang_handle_resize(caca_display_t *dp)
284
308
dp->resize.w = SLtt_Screen_Cols;
285
309
dp->resize.h = SLtt_Screen_Rows;
311
SLsig_block_signals();
287
312
if(dp->resize.w != caca_get_canvas_width(dp->cv)
288
313
|| dp->resize.h != caca_get_canvas_height(dp->cv))
289
314
SLsmg_reinit_smg();
315
SLsig_unblock_signals();
292
318
static int slang_get_event(caca_display_t *dp, caca_privevent_t *ev)
322
/* If SIGINT was caught, we pass it to the application as Ctrl-C. */
323
if(dp->drv.p->sigint_event > 0)
325
ev->type = CACA_EVENT_KEY_PRESS;
326
ev->data.key.ch = CACA_KEY_CTRL_C;
327
ev->data.key.utf32 = 0x03;
328
ev->data.key.utf8[0] = 0x03;
329
ev->data.key.utf8[1] = 0;
330
dp->drv.p->sigint_event--;
296
334
if(!SLang_input_pending(0))
298
336
ev->type = CACA_EVENT_NONE;