📄 slsmg.c
字号:
SL_Screen[i].old = SL_Screen[i].neew = NULL; } This_Alt_Char = This_Color = 0; Smg_Inited = 0;}static int init_smg (void){ int i, len; SLsmg_Char_Type *old, *neew; Smg_Inited = 0;#ifdef REQUIRES_NON_BCE_SUPPORT Bce_Color_Offset = _SLtt_get_bce_color_offset ();#endif Screen_Rows = *tt_Screen_Rows; if (Screen_Rows > SLTT_MAX_SCREEN_ROWS) Screen_Rows = SLTT_MAX_SCREEN_ROWS; Screen_Cols = *tt_Screen_Cols; This_Col = This_Row = Start_Col = Start_Row = 0; This_Alt_Char = 0; SLsmg_set_color (0); Cls_Flag = 1;#ifndef IBMPC_SYSTEM init_alt_char_set ();#endif len = Screen_Cols + 3; for (i = 0; i < Screen_Rows; i++) { if ((NULL == (old = (SLsmg_Char_Type *) SLmalloc (sizeof(SLsmg_Char_Type) * len))) || ((NULL == (neew = (SLsmg_Char_Type *) SLmalloc (sizeof(SLsmg_Char_Type) * len))))) { SLfree ((char *) old); return -1; } blank_line (old, len, ' '); blank_line (neew, len, ' '); SL_Screen[i].old = old; SL_Screen[i].neew = neew; SL_Screen[i].flags = 0;#ifndef IBMPC_SYSTEM Blank_Hash = compute_hash (old, Screen_Cols); SL_Screen[i].new_hash = SL_Screen[i].old_hash = Blank_Hash;#endif } _SLtt_color_changed_hook = SLsmg_touch_screen; Screen_Trashed = 1; Smg_Inited = 1; return 0;}int SLsmg_init_smg (void){ int ret; BLOCK_SIGNALS; if (Smg_Inited) SLsmg_reset_smg (); if (-1 == (*tt_init_video) ()) { UNBLOCK_SIGNALS; return -1; } if (-1 == (ret = init_smg ())) (void) (*tt_reset_video)(); UNBLOCK_SIGNALS; return ret;}int SLsmg_reinit_smg (void){ int ret; if (Smg_Inited == 0) return SLsmg_init_smg (); BLOCK_SIGNALS; reset_smg (); ret = init_smg (); UNBLOCK_SIGNALS; return ret;}void SLsmg_reset_smg (void){ if (Smg_Inited == 0) return; BLOCK_SIGNALS; reset_smg (); (*tt_reset_video)(); UNBLOCK_SIGNALS;}SLsmg_Char_Type SLsmg_char_at (void){ if (Smg_Inited == 0) return 0; if (point_visible (1)) { return SL_Screen[This_Row - Start_Row].neew[This_Col - Start_Col]; } return 0;}void SLsmg_vprintf (char *fmt, va_list ap){ char buf[1024]; if (Smg_Inited == 0) return; (void) _SLvsnprintf (buf, sizeof (buf), fmt, ap); SLsmg_write_string (buf);}void SLsmg_printf (char *fmt, ...){ va_list ap; unsigned int len; char *f; if (Smg_Inited == 0) return; va_start(ap, fmt); f = fmt; while (*f && (*f != '%')) f++; len = (unsigned int) (f - fmt); if (len) SLsmg_write_nchars (fmt, len); if (*f != 0) SLsmg_vprintf (f, ap); va_end (ap);}void SLsmg_set_screen_start (int *r, int *c){ int orow = Start_Row, oc = Start_Col; if (Smg_Inited == 0) return; if (c == NULL) Start_Col = 0; else { Start_Col = *c; *c = oc; } if (r == NULL) Start_Row = 0; else { Start_Row = *r; *r = orow; }}void SLsmg_draw_object (int r, int c, unsigned char object){ This_Row = r; This_Col = c; if (Smg_Inited == 0) return; if (point_visible (1)) { int color = This_Color; This_Color |= ALT_CHAR_FLAG; SLsmg_write_char (object); This_Color = color; } This_Col = c + 1;}void SLsmg_draw_hline (unsigned int n){ static unsigned char hbuf[16]; int count; int cmin, cmax; int final_col = This_Col + (int) n; int save_color; if (Smg_Inited == 0) return; if ((This_Row < Start_Row) || (This_Row >= Start_Row + Screen_Rows) || (0 == compute_clip (This_Col, n, Start_Col, Start_Col + Screen_Cols, &cmin, &cmax))) { This_Col = final_col; return; } if (hbuf[0] == 0) { SLMEMSET ((char *) hbuf, SLSMG_HLINE_CHAR, 16); } n = (unsigned int)(cmax - cmin); count = n / 16; save_color = This_Color; This_Color |= ALT_CHAR_FLAG; This_Col = cmin; SLsmg_write_nchars ((char *) hbuf, n % 16); while (count-- > 0) { SLsmg_write_nchars ((char *) hbuf, 16); } This_Color = save_color; This_Col = final_col;}void SLsmg_draw_vline (int n){ unsigned char ch = SLSMG_VLINE_CHAR; int c = This_Col, rmin, rmax; int final_row = This_Row + n; int save_color; if (Smg_Inited == 0) return; if (((c < Start_Col) || (c >= Start_Col + Screen_Cols)) || (0 == compute_clip (This_Row, n, Start_Row, Start_Row + Screen_Rows, &rmin, &rmax))) { This_Row = final_row; return; } save_color = This_Color; This_Color |= ALT_CHAR_FLAG; for (This_Row = rmin; This_Row < rmax; This_Row++) { This_Col = c; SLsmg_write_nchars ((char *) &ch, 1); } This_Col = c; This_Row = final_row; This_Color = save_color;}void SLsmg_draw_box (int r, int c, unsigned int dr, unsigned int dc){ if (Smg_Inited == 0) return; if (!dr || !dc) return; This_Row = r; This_Col = c; dr--; dc--; SLsmg_draw_hline (dc); SLsmg_draw_vline (dr); This_Row = r; This_Col = c; SLsmg_draw_vline (dr); SLsmg_draw_hline (dc); SLsmg_draw_object (r, c, SLSMG_ULCORN_CHAR); SLsmg_draw_object (r, c + (int) dc, SLSMG_URCORN_CHAR); SLsmg_draw_object (r + (int) dr, c, SLSMG_LLCORN_CHAR); SLsmg_draw_object (r + (int) dr, c + (int) dc, SLSMG_LRCORN_CHAR); This_Row = r; This_Col = c;}void SLsmg_fill_region (int r, int c, unsigned int dr, unsigned int dc, unsigned char ch){ static unsigned char hbuf[16]; int count; int dcmax, rmax; if (Smg_Inited == 0) return; SLsmg_gotorc (r, c); r = This_Row; c = This_Col; dcmax = Screen_Cols - This_Col; if (dcmax < 0) return; if (dc > (unsigned int) dcmax) dc = (unsigned int) dcmax; rmax = This_Row + dr; if (rmax > Screen_Rows) rmax = Screen_Rows;#if 0 ch = Alt_Char_Set[ch];#endif if (ch != hbuf[0]) SLMEMSET ((char *) hbuf, (char) ch, 16); for (This_Row = r; This_Row < rmax; This_Row++) { This_Col = c; count = dc / 16; SLsmg_write_nchars ((char *) hbuf, dc % 16); while (count-- > 0) { SLsmg_write_nchars ((char *) hbuf, 16); } } This_Row = r;}void SLsmg_forward (int n){ This_Col += n;}void SLsmg_write_color_chars (SLsmg_Char_Type *s, unsigned int len){ SLsmg_Char_Type *smax, sh; char buf[32], *b, *bmax; int color, save_color; if (Smg_Inited == 0) return; smax = s + len; b = buf; bmax = b + sizeof (buf); save_color = This_Color; while (s < smax) { sh = *s++; color = SLSMG_EXTRACT_COLOR(sh);#if REQUIRES_NON_BCE_SUPPORT if (Bce_Color_Offset) { if (color & 0x80) color = ((color & 0x7F) + Bce_Color_Offset) | 0x80; else color = ((color & 0x7F) + Bce_Color_Offset) & 0x7F; }#endif if ((color != This_Color) || (b == bmax)) { if (b != buf) { SLsmg_write_nchars (buf, (int) (b - buf)); b = buf; } This_Color = color; } *b++ = (char) SLSMG_EXTRACT_CHAR(sh); } if (b != buf) SLsmg_write_nchars (buf, (unsigned int) (b - buf)); This_Color = save_color;}unsigned int SLsmg_read_raw (SLsmg_Char_Type *buf, unsigned int len){ unsigned int r, c; if (Smg_Inited == 0) return 0; if (0 == point_visible (1)) return 0; r = (unsigned int) (This_Row - Start_Row); c = (unsigned int) (This_Col - Start_Col); if (c + len > (unsigned int) Screen_Cols) len = (unsigned int) Screen_Cols - c; memcpy ((char *) buf, (char *) (SL_Screen[r].neew + c), len * sizeof (SLsmg_Char_Type)); return len;}unsigned int SLsmg_write_raw (SLsmg_Char_Type *buf, unsigned int len){ unsigned int r, c; SLsmg_Char_Type *dest; if (Smg_Inited == 0) return 0; if (0 == point_visible (1)) return 0; r = (unsigned int) (This_Row - Start_Row); c = (unsigned int) (This_Col - Start_Col); if (c + len > (unsigned int) Screen_Cols) len = (unsigned int) Screen_Cols - c; dest = SL_Screen[r].neew + c; if (0 != memcmp ((char *) dest, (char *) buf, len * sizeof (SLsmg_Char_Type))) { memcpy ((char *) dest, (char *) buf, len * sizeof (SLsmg_Char_Type)); SL_Screen[r].flags |= TOUCHED; } return len;}voidSLsmg_set_color_in_region (int color, int r, int c, unsigned int dr, unsigned int dc){ int cmax, rmax; SLsmg_Char_Type char_mask; if (Smg_Inited == 0) return; c -= Start_Col; r -= Start_Row; cmax = c + (int) dc; rmax = r + (int) dr; if (cmax > Screen_Cols) cmax = Screen_Cols; if (rmax > Screen_Rows) rmax = Screen_Rows; if (c < 0) c = 0; if (r < 0) r = 0;#if REQUIRES_NON_BCE_SUPPORT if (Bce_Color_Offset) { if (color & 0x80) color = ((color & 0x7F) + Bce_Color_Offset) | 0x80; else color = ((color & 0x7F) + Bce_Color_Offset) & 0x7F; }#endif color = color << 8; char_mask = 0xFF;#ifndef IBMPC_SYSTEM if ((tt_Use_Blink_For_ACS == NULL) || (0 == *tt_Use_Blink_For_ACS)) char_mask = 0x80FF;#endif while (r < rmax) { SLsmg_Char_Type *s, *smax; SL_Screen[r].flags |= TOUCHED; s = SL_Screen[r].neew; smax = s + cmax; s += c; while (s < smax) { *s = (*s & char_mask) | color; s++; } r++; }}void SLsmg_set_terminal_info (SLsmg_Term_Type *tt){ if (tt == NULL) /* use default */ return; if ((tt->tt_normal_video == NULL) || (tt->tt_goto_rc == NULL) || (tt->tt_cls == NULL) || (tt->tt_del_eol == NULL) || (tt->tt_smart_puts == NULL) || (tt->tt_flush_output == NULL) || (tt->tt_reset_video == NULL) || (tt->tt_init_video == NULL)#ifndef IBMPC_SYSTEM || (tt->tt_set_scroll_region == NULL) || (tt->tt_reverse_index == NULL) || (tt->tt_reset_scroll_region == NULL) || (tt->tt_delete_nlines == NULL) /* Variables */ || (tt->tt_term_cannot_scroll == NULL) || (tt->tt_has_alt_charset == NULL)#if 0 /* These can be NULL */ || (tt->tt_use_blink_for_acs == NULL) || (tt->tt_graphic_char_pairs == NULL)#endif || (tt->tt_screen_cols == NULL) || (tt->tt_screen_rows == NULL)#endif ) SLang_exit_error ("Terminal not powerful enough for SLsmg"); tt_normal_video = tt->tt_normal_video; tt_goto_rc = tt->tt_goto_rc; tt_cls = tt->tt_cls; tt_del_eol = tt->tt_del_eol; tt_smart_puts = tt->tt_smart_puts; tt_flush_output = tt->tt_flush_output; tt_reset_video = tt->tt_reset_video; tt_init_video = tt->tt_init_video;#ifndef IBMPC_SYSTEM tt_set_scroll_region = tt->tt_set_scroll_region; tt_reverse_index = tt->tt_reverse_index; tt_reset_scroll_region = tt->tt_reset_scroll_region; tt_delete_nlines = tt->tt_delete_nlines; tt_Term_Cannot_Scroll = tt->tt_term_cannot_scroll; tt_Has_Alt_Charset = tt->tt_has_alt_charset; tt_Use_Blink_For_ACS = tt->tt_use_blink_for_acs; tt_Graphics_Char_Pairs = tt->tt_graphic_char_pairs;#endif tt_Screen_Cols = tt->tt_screen_cols; tt_Screen_Rows = tt->tt_screen_rows;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -