--- nono/lib/textscreen.h 2026/04/29 17:04:31 1.1.1.2 +++ nono/lib/textscreen.h 2026/04/29 17:04:34 1.1.1.3 @@ -1,19 +1,39 @@ // // nono -// Copyright (C) 2018 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt // #pragma once +#include "header.h" + // 属性 -enum TA { - Normal = 0x00 << 8, - // On, Off, Disable は3ビットを使った状態値。 - // これらが実際どう表現されるかはデバイスによる。 - On = 0x01 << 8, // ビットとかがオンであることを示す - Off = 0x02 << 8, // ビットとかがオフであることを示す - Disable = 0x03 << 8, // 機能などが無効であることを示す - Em = 0x04 << 8, // 値の変化など強調することを示す +class TA +{ + public: + enum TextAttr : uint { + Normal = 0x00 << 8, + // On, Off, Disable は3ビットを使った状態値。 + // これらが実際どう表現されるかはデバイスによる。 + On = 0x01 << 8, // ビットとかがオンであることを示す + Off = 0x02 << 8, // ビットとかがオフであることを示す + Disable = 0x03 << 8, // 機能などが無効であることを示す + Em = 0x04 << 8, // 値の変化など強調することを示す + } attr {}; + + TA() { } + TA(TextAttr attr_) : attr(attr_) { } + + // uint へのキャスト + operator uint() const { + return (uint)attr; + } + + // val によって On か Off を返す + static const TA OnOff(bool val) { + return (val) ? TA::On : TA::Off; + } }; // @@ -46,16 +66,31 @@ class TextScreen void Clear(); // 現在位置を移動 - void Locate(int x, int y); + void Locate(int x, int y) { + X = x; + Y = y; + } // 現在位置に1文字出力 (上位バイトは属性) void Putc(uint16 ch); - // 現在位置に字列を出力 + // 現在位置に文字列を出力 void Puts(const char *str); // 現在位置に指定の属性で文字列を出力 - void Puts(uint attr, const char *str); + void Puts(TA attr, const char *str); + + // 座標を指定して文字列を出力 + void Puts(int x, int y, const char *str) { + Locate(x, y); + Puts(str); + } + + // 座標と属性を指定して、文字列を出力 + void Puts(int x, int y, TA attr, const char *str) { + Locate(x, y); + Puts(attr, str); + } // 現在位置に属性なしで書式付き文字列を出力 void Print(const char *fmt, ...) __printflike(2, 3); @@ -64,7 +99,7 @@ class TextScreen void Print(int x, int y, const char *fmt, ...) __printflike(4, 5); // 座標と属性を指定して、書式付き文字列を出力 - void Print(int x, int y, uint attr, const char *fmt, ...) + void Print(int x, int y, TA attr, const char *fmt, ...) __printflike(5, 6); // バッファアドレスを取得。(描画デバイス向け)