Annotation of nono/lib/textscreen.h, 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: #pragma once
                      8: 
1.1.1.3 ! root        9: #include "header.h"
        !            10: 
1.1       root       11: // 属性
1.1.1.3 ! root       12: class TA
        !            13: {
        !            14:  public:
        !            15:        enum TextAttr : uint {
        !            16:                Normal  = 0x00 << 8,
        !            17:                // On, Off, Disable は3ビットを使った状態値。
        !            18:                // これらが実際どう表現されるかはデバイスによる。
        !            19:                On              = 0x01 << 8,    // ビットとかがオンであることを示す
        !            20:                Off             = 0x02 << 8,    // ビットとかがオフであることを示す
        !            21:                Disable = 0x03 << 8,    // 機能などが無効であることを示す
        !            22:                Em              = 0x04 << 8,    // 値の変化など強調することを示す
        !            23:        } attr {};
        !            24: 
        !            25:        TA() { }
        !            26:        TA(TextAttr attr_) : attr(attr_) { }
        !            27: 
        !            28:        // uint へのキャスト
        !            29:        operator uint() const {
        !            30:                return (uint)attr;
        !            31:        }
        !            32: 
        !            33:        // val によって On か Off を返す
        !            34:        static const TA OnOff(bool val) {
        !            35:                return (val) ? TA::On : TA::Off;
        !            36:        }
1.1       root       37: };
                     38: 
                     39: //
                     40: // テキストスクリーン
                     41: //
                     42: // col × row で指定されるテキスト画面。
                     43: // 表示可能なのは 0x20..0x7e の printable 文字。
                     44: // 0x20 未満と 0x7f の動作は未定。
                     45: // 漢字は 2桁占有する。文字列として指定する時は UTF-8 だが、内部コードは
                     46: // Shift_JIS なので、第一水準、第二水準の文字だけを指定すること。
                     47: //
                     48: // TextScreen() コンストラクタで作成して Init(col, row) するか、
                     49: // TextScreen(col, row) コンストラクタを呼ぶかどちらか選択。
                     50: // チェックとかはしていないので併用しないこと。
                     51: //
                     52: class TextScreen
                     53: {
                     54:  public:
                     55:        TextScreen();
                     56:        TextScreen(int col, int row);
                     57:        virtual ~TextScreen();
                     58: 
                     59:        // 初期化
                     60:        void Init(int col, int row);
                     61: 
1.1.1.2   root       62:        // 折り返しモードかどうか
                     63:        bool foldmode {};
                     64: 
1.1       root       65:        // クリア
                     66:        void Clear();
                     67: 
1.1.1.2   root       68:        // 現在位置を移動
1.1.1.3 ! root       69:        void Locate(int x, int y) {
        !            70:                X = x;
        !            71:                Y = y;
        !            72:        }
1.1.1.2   root       73: 
1.1       root       74:        // 現在位置に1文字出力 (上位バイトは属性)
                     75:        void Putc(uint16 ch);
                     76: 
1.1.1.3 ! root       77:        // 現在位置に文字列を出力
1.1       root       78:        void Puts(const char *str);
                     79: 
                     80:        // 現在位置に指定の属性で文字列を出力
1.1.1.3 ! root       81:        void Puts(TA attr, const char *str);
        !            82: 
        !            83:        // 座標を指定して文字列を出力
        !            84:        void Puts(int x, int y, const char *str) {
        !            85:                Locate(x, y);
        !            86:                Puts(str);
        !            87:        }
        !            88: 
        !            89:        // 座標と属性を指定して、文字列を出力
        !            90:        void Puts(int x, int y, TA attr, const char *str) {
        !            91:                Locate(x, y);
        !            92:                Puts(attr, str);
        !            93:        }
1.1       root       94: 
1.1.1.2   root       95:        // 現在位置に属性なしで書式付き文字列を出力
                     96:        void Print(const char *fmt, ...) __printflike(2, 3);
                     97: 
1.1       root       98:        // 座標を指定して属性なしで書式付き文字列を出力
                     99:        void Print(int x, int y, const char *fmt, ...) __printflike(4, 5);
                    100: 
                    101:        // 座標と属性を指定して、書式付き文字列を出力
1.1.1.3 ! root      102:        void Print(int x, int y, TA attr, const char *fmt, ...)
1.1       root      103:                __printflike(5, 6);
                    104: 
                    105:        // バッファアドレスを取得。(描画デバイス向け)
1.1.1.2   root      106:        const uint16 *GetBuf() const { return textbuf.get(); }
1.1       root      107: 
                    108:        // XXX 生バッファを取得
                    109:        // バッファの内部構造を変えた場合はこれを呼んでる人については
                    110:        // 見直しをすること。そのうちなんとかするかも
1.1.1.2   root      111:        uint16 *GetRawBuf() { return textbuf.get(); }
                    112: 
                    113:        // 現在の X 座標を取得
                    114:        int GetX() const { return X; }
                    115:        // 現在の Y 座標を取得
                    116:        int GetY() const { return Y; }
1.1       root      117: 
                    118:        // 桁数を取得
                    119:        int GetCol() const { return col; }
                    120: 
                    121:        // 行数を取得
                    122:        int GetRow() const { return row; }
                    123: 
                    124:  private:
1.1.1.2   root      125:        // 改行(次の行の左端に移動)
                    126:        void CRLF();
                    127: 
1.1       root      128:        // バッファ (幅x高さちょうどの長さ、ゼロ終端文字列ではない)
                    129:        // 上位8ビットは属性、下位8ビットが文字コード。
1.1.1.2   root      130:        std::unique_ptr<uint16[]> textbuf {};
1.1       root      131: 
                    132:        // 幅
                    133:        int col = 0;
                    134: 
                    135:        // 高さ
                    136:        int row = 0;
                    137: 
                    138:        // カーソル X 座標
                    139:        int X = 0;
                    140: 
                    141:        // カーソル Y 座標
                    142:        int Y = 0;
                    143: };

unix.superglobalmegacorp.com

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