Annotation of nono/lib/textscreen.cpp, revision 1.1.1.3

1.1       root        1: //
                      2: // nono
1.1.1.3 ! root        3: // Copyright (C) 2020 nono project
        !             4: // Licensed under nono-license.txt
1.1       root        5: //
                      6: 
                      7: #include "textscreen.h"
                      8: 
                      9: //
                     10: // テキストスクリーン
                     11: //
                     12: 
                     13: // コンストラクタ
                     14: TextScreen::TextScreen()
                     15: {
                     16: }
                     17: 
                     18: // コンストラクタ
                     19: TextScreen::TextScreen(int arg_col, int arg_row)
                     20: {
                     21:        Init(arg_col, arg_row);
                     22: }
                     23: 
                     24: // デストラクタ
                     25: TextScreen::~TextScreen()
                     26: {
                     27: }
                     28: 
                     29: // 初期化
                     30: void
                     31: TextScreen::Init(int arg_col, int arg_row)
                     32: {
                     33:        col = arg_col;
                     34:        row = arg_row;
                     35: 
1.1.1.2   root       36:        textbuf.reset(new uint16 [col * row]);
1.1       root       37:        X = 0;
                     38:        Y = 0;
                     39: 
                     40:        Clear();
                     41: }
                     42: 
                     43: // クリア
                     44: void
                     45: TextScreen::Clear()
                     46: {
                     47:        for (int i = 0; i < col * row; i++) {
                     48:                textbuf[i] = 0x0020;
                     49:        }
1.1.1.2   root       50: 
                     51:        // 折り返しモードならクリアでホームポジションへ
                     52:        if (foldmode) {
                     53:                Locate(0, 0);
                     54:        }
                     55: }
                     56: 
1.1       root       57: // 現在のカーソル位置に1文字出力する。
                     58: // カーソルは一つ移動する。
1.1.1.2   root       59: // foldmode = false なら、移動後右もしくは下にはみ出しても何もしない。
                     60: // foldmode = true なら、右にはみ出した場合は次行左端に移動、
                     61: // 下にはみ出した場合はカーソル位置はそのままで上に1行スクロールさせる。
1.1       root       62: void
                     63: TextScreen::Putc(uint16 ch)
                     64: {
                     65:        if (X >= col || Y >= row) {
                     66:                return;
                     67:        }
                     68: 
1.1.1.2   root       69:        if (ch == '\n') {
                     70:                CRLF();
                     71:        } else {
                     72:                textbuf[(Y * col) + X] = ch;
                     73:                X++;
                     74: 
                     75:                // 折り返しモード
                     76:                if (foldmode && X >= col) {
                     77:                        CRLF();
                     78:                }
                     79:        }
1.1       root       80: }
                     81: 
                     82: // テキストスクリーンに文字列を出力する。
                     83: // 右もしくは下にはみ出した場合は無視する。
                     84: // XXX どっかで拾えてもいいような
                     85: void
                     86: TextScreen::Puts(const char *str)
                     87: {
                     88:        while (*str != '\0') {
                     89:                Putc(*str++);
                     90:        }
                     91: }
                     92: 
                     93: // テキストスクリーンに文字列を出力する。
                     94: // 右もしくは下にはみ出した場合は無視する。
                     95: void
1.1.1.3 ! root       96: TextScreen::Puts(TA attr, const char *str)
1.1       root       97: {
                     98:        while (*str != '\0') {
1.1.1.3 ! root       99:                Putc(((uint)attr) | *str++);
1.1       root      100:        }
                    101: }
                    102: 
1.1.1.2   root      103: // テキストスクリーンの現在位置から書式付き文字列を出力する。
                    104: void
                    105: TextScreen::Print(const char *fmt, ...)
                    106: {
                    107:        char buf[1024];
                    108:        va_list ap;
                    109: 
                    110:        va_start(ap, fmt);
                    111:        vsnprintf(buf, sizeof(buf), fmt, ap);
                    112:        va_end(ap);
                    113: 
                    114:        Puts(buf);
                    115: }
                    116: 
1.1       root      117: // テキストスクリーンに座標を指定して書式付き文字列を出力する。
                    118: void
                    119: TextScreen::Print(int x, int y, const char *fmt, ...)
                    120: {
                    121:        char buf[1024];
                    122:        va_list ap;
                    123: 
                    124:        va_start(ap, fmt);
                    125:        vsnprintf(buf, sizeof(buf), fmt, ap);
                    126:        va_end(ap);
                    127: 
1.1.1.2   root      128:        Locate(x, y);
1.1       root      129:        Puts(buf);
                    130: }
                    131: 
                    132: // テキストスクリーンに座標と属性を指定して、書式付き文字列を出力する。
                    133: void
1.1.1.3 ! root      134: TextScreen::Print(int x, int y, TA attr, const char *fmt, ...)
1.1       root      135: {
                    136:        char buf[1024];
                    137:        va_list ap;
                    138: 
                    139:        va_start(ap, fmt);
                    140:        vsnprintf(buf, sizeof(buf), fmt, ap);
                    141:        va_end(ap);
                    142: 
1.1.1.2   root      143:        Locate(x, y);
1.1       root      144:        Puts(attr, buf);
                    145: }
1.1.1.2   root      146: 
                    147: // 改行
                    148: void
                    149: TextScreen::CRLF()
                    150: {
                    151:        X = 0;
                    152:        Y++;
                    153: 
                    154:        if (Y >= row) {
                    155:                // スクロール
                    156:                memmove(&textbuf[0], &textbuf[col],
                    157:                        (col - 1) * row * sizeof(textbuf[0]));
                    158:                // カーソル位置は最下行
                    159:                Y = row - 1;
                    160:        }
                    161: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.