|
|
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: //
8: // テキストスクリーン
9: //
10:
1.1.1.9 ! root 11: #include "textscreen.h"
! 12:
1.1 root 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
1.1.1.7 root 31: TextScreen::Init(int arg_col, int arg_row, ModeKind mode)
1.1 root 32: {
1.1.1.6 root 33: assert(arg_col > 0);
34: assert(arg_row > 0);
35:
1.1 root 36: col = arg_col;
37: row = arg_row;
1.1.1.7 root 38: Mode = mode;
1.1 root 39:
1.1.1.6 root 40: textbuf.resize(col * row);
1.1 root 41: X = 0;
42: Y = 0;
43:
44: Clear();
45: }
46:
47: // クリア
48: void
49: TextScreen::Clear()
50: {
51: for (int i = 0; i < col * row; i++) {
52: textbuf[i] = 0x0020;
53: }
1.1.1.2 root 54:
1.1.1.4 root 55: // ホームポジション
56: Locate(0, 0);
1.1.1.2 root 57: }
58:
1.1.1.6 root 59: // 1 行上スクロール
60: void
61: TextScreen::ScrollUp()
62: {
63: memmove(&textbuf[0], &textbuf[col],
64: (row - 1) * col * sizeof(textbuf[0]));
65: for (int i = 0; i < col; i++) {
66: textbuf[(row - 1) * col + i] = 0x0020;
67: }
68: }
69:
70:
1.1 root 71: // 現在のカーソル位置に1文字出力する。
72: void
73: TextScreen::Putc(uint16 ch)
74: {
1.1.1.8 root 75: if (ch == '\n') {
76: CRLF();
1.1 root 77: return;
78: }
79:
1.1.1.8 root 80: if (OutOfScreen) {
81: return;
1.1.1.6 root 82: }
1.1.1.8 root 83:
84: textbuf[(Y * col) + X] = ch;
85: Ascend();
1.1.1.6 root 86: }
87:
88: // 現在のカーソル位置の文字を取得
89: // カーソルは移動する。
90: // カーソルが範囲外だったときは 0 を返す。
91: uint16
92: TextScreen::Getc()
93: {
94: if (OutOfScreen) {
95: return 0;
96: }
97:
98: uint16 ch = textbuf[(Y * col) + X];
99: Ascend();
100: return ch;
1.1 root 101: }
102:
103: // テキストスクリーンに文字列を出力する。
104: void
105: TextScreen::Puts(const char *str)
106: {
107: while (*str != '\0') {
108: Putc(*str++);
109: }
110: }
111:
112: // テキストスクリーンに文字列を出力する。
113: void
1.1.1.3 root 114: TextScreen::Puts(TA attr, const char *str)
1.1 root 115: {
116: while (*str != '\0') {
1.1.1.3 root 117: Putc(((uint)attr) | *str++);
1.1 root 118: }
119: }
120:
1.1.1.2 root 121: // テキストスクリーンの現在位置から書式付き文字列を出力する。
122: void
123: TextScreen::Print(const char *fmt, ...)
124: {
125: char buf[1024];
126: va_list ap;
127:
128: va_start(ap, fmt);
129: vsnprintf(buf, sizeof(buf), fmt, ap);
130: va_end(ap);
131:
132: Puts(buf);
133: }
134:
1.1 root 135: // テキストスクリーンに座標を指定して書式付き文字列を出力する。
136: void
137: TextScreen::Print(int x, int y, const char *fmt, ...)
138: {
139: char buf[1024];
140: va_list ap;
141:
142: va_start(ap, fmt);
143: vsnprintf(buf, sizeof(buf), fmt, ap);
144: va_end(ap);
145:
1.1.1.2 root 146: Locate(x, y);
1.1 root 147: Puts(buf);
148: }
149:
150: // テキストスクリーンに座標と属性を指定して、書式付き文字列を出力する。
151: void
1.1.1.3 root 152: TextScreen::Print(int x, int y, TA attr, const char *fmt, ...)
1.1 root 153: {
154: char buf[1024];
155: va_list ap;
156:
157: va_start(ap, fmt);
158: vsnprintf(buf, sizeof(buf), fmt, ap);
159: va_end(ap);
160:
1.1.1.2 root 161: Locate(x, y);
1.1 root 162: Puts(attr, buf);
163: }
1.1.1.2 root 164:
1.1.1.6 root 165: // 現在位置の属性を取得
166: // カーソルが画面外の場合は TA::Normal を返す。
167: TA
168: TextScreen::GetAttr() const
1.1.1.4 root 169: {
1.1.1.6 root 170: if (OutOfScreen) {
171: return TA::Normal;
172: }
1.1.1.4 root 173:
1.1.1.6 root 174: return TA(textbuf[(Y * col) + X] & 0xff00);
1.1.1.4 root 175: }
176:
1.1.1.6 root 177: // 現在位置の属性を attr に設定する。
178: // カーソルは移動しない。
1.1.1.4 root 179: void
1.1.1.6 root 180: TextScreen::SetAttr(TA attr)
1.1.1.4 root 181: {
1.1.1.6 root 182: if (OutOfScreen) {
1.1.1.4 root 183: return;
184: }
185:
1.1.1.6 root 186: auto& ch = textbuf[(Y * col) + X];
187: ch = (ch & 0xff) | (uint)attr;
1.1.1.4 root 188: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.