--- nono/lib/textscreen.h 2026/04/29 17:05:22 1.1.1.13 +++ nono/lib/textscreen.h 2026/04/29 17:05:48 1.1.1.16 @@ -10,7 +10,7 @@ #pragma once -#include "header.h" +#include "nono.h" #include // 属性 @@ -27,15 +27,15 @@ class TA // // B はボールド。 // Color Code は 4bit の前景色・背景色ペアの固定パレット。 - Normal = 0x00 << 8, // 通常描画色 - Reverse = 0x01 << 8, // 反転、背景黒 - Off = 0x02 << 8, // オフを示す - Disable = 0x03 << 8, // 無効を示す - ReverseRed = 0x04 << 8, // 反転、背景赤 - ReverseGreen = 0x05 << 8, // 反転、背景緑 - ReverseOrange = 0x06 << 8, // 反転、背景オレンジ + Normal = 0x00U << 8, // 通常描画色 + Reverse = 0x01U << 8, // 反転、背景黒 + Off = 0x02U << 8, // オフを示す + Disable = 0x03U << 8, // 無効を示す + ReverseRed = 0x04U << 8, // 反転、背景赤 + ReverseGreen = 0x05U << 8, // 反転、背景緑 + ReverseOrange = 0x06U << 8, // 反転、背景オレンジ - Bold = 0x80 << 8, // ボールド + Bold = 0x80U << 8, // ボールド // エイリアス On = Reverse, // オンは反転で表現している @@ -75,7 +75,7 @@ class TA // // Locate などにより範囲外にカーソルを移動することはできる。 // ただしその位置を始点としての文字出力は無視される。 -class TextScreen +class TextScreen final { public: // 文字の送りモード @@ -90,7 +90,7 @@ class TextScreen TextScreen(); TextScreen(int col, int row); - virtual ~TextScreen(); + ~TextScreen(); // 初期化 void Init(int col, int row, ModeKind mode = ModeKind::Fixed); @@ -104,46 +104,30 @@ class TextScreen Y = y; OutOfScreen = (X < 0 || X >= col || Y < 0 || Y >= row); } + void SetX(int x) { + X = x; + OutOfScreen = (X < 0 || X >= col); + } + void SetY(int y) { + Y = y; + OutOfScreen = (Y < 0 || Y >= row); + } // 文字出力後の右移動 - void Ascend() { - X++; - if (X >= col) { - switch (Mode) { - case Fixed: - OutOfScreen = true; - break; - case Console: - case Ring: - CRLF(); - break; - } - } + void Ascend(); + + // 復帰 + void CR() noexcept { + X = 0; } + // 改行 + void LF(); + // 復帰改行 - void CRLF() - { - X = 0; - Y++; - switch (Mode) { - case Fixed: - break; - case Console: - if (Y >= row) { - ScrollUp(); - Y = row - 1; - } - break; - case Ring: - if (Y >= row) { - Y = 0; - } - break; - } - // どのモードであっても OutOfScreen を更新 - // (Y=-1 から CRLF したら表示可能になるべき) - OutOfScreen = (Y < 0 || Y >= row); + void CRLF() { + CR(); + LF(); } // 1行の上スクロール @@ -198,9 +182,17 @@ class TextScreen __printflike(5, 6); // 現在のカーソル位置の文字を取得 - // カーソルは移動する。 + // カーソルは移動しない。 uint16 Getc(); + // 現在のカーソル位置に文字を出力。 + // カーソルは移動しない。ch がカーソル移動を伴う制御文字なら動作不定。 + void Setc(uint16 ch); + + // 指定のカーソル位置に文字を出力。 + // カーソルは移動しない。ch がカーソル移動を伴う制御文字なら動作不定。 + void Setc(int x, int y, uint16 ch); + // 現在位置の属性を取得 TA GetAttr() const; @@ -212,15 +204,15 @@ class TextScreen const std::vector& GetBuf() const { return textbuf; } // 現在の X 座標を取得 - int GetX() const { return X; } + int GetX() const noexcept { return X; } // 現在の Y 座標を取得 - int GetY() const { return Y; } + int GetY() const noexcept { return Y; } // 桁数を取得 - int GetCol() const { return col; } + int GetCol() const noexcept { return col; } // 行数を取得 - int GetRow() const { return row; } + int GetRow() const noexcept { return row; } // 行単位のコピー void CopyRowsFrom(int dst_y, int row, const TextScreen& src, int src_y); @@ -231,7 +223,7 @@ class TextScreen // ような用途。 uint64 userdata {}; - protected: + private: // バッファ (幅x高さちょうどの長さ、ゼロ終端文字列ではない) // 上位8ビットは属性、下位8ビットが文字コード。 std::vector textbuf {};