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

1.1       root        1: //
                      2: // nono
                      3: // Copyright (C) 2018 [email protected]
                      4: //
                      5: 
                      6: #include "header.h"
                      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:        if (textbuf) {
                     28:                delete[] textbuf;
                     29:        }
                     30: }
                     31: 
                     32: // 初期化
                     33: void
                     34: TextScreen::Init(int arg_col, int arg_row)
                     35: {
                     36:        col = arg_col;
                     37:        row = arg_row;
                     38: 
                     39:        textbuf = new uint16 [col * row];
                     40:        X = 0;
                     41:        Y = 0;
                     42: 
                     43:        Clear();
                     44: }
                     45: 
                     46: // クリア
                     47: void
                     48: TextScreen::Clear()
                     49: {
                     50:        for (int i = 0; i < col * row; i++) {
                     51:                textbuf[i] = 0x0020;
                     52:        }
                     53: }
                     54: 
                     55: // 現在のカーソル位置に1文字出力する。
                     56: // カーソルは一つ移動する。
                     57: // 右もしくは下にはみ出した場合は無視する。
                     58: // XXX どっかで拾えてもいいような
                     59: void
                     60: TextScreen::Putc(uint16 ch)
                     61: {
                     62:        if (X >= col || Y >= row) {
                     63:                return;
                     64:        }
                     65: 
                     66:        textbuf[(Y * col) + X] = ch;
                     67:        X++;
                     68: }
                     69: 
                     70: // テキストスクリーンに文字列を出力する。
                     71: // 右もしくは下にはみ出した場合は無視する。
                     72: // XXX どっかで拾えてもいいような
                     73: void
                     74: TextScreen::Puts(const char *str)
                     75: {
                     76:        while (*str != '\0') {
                     77:                Putc(*str++);
                     78:        }
                     79: }
                     80: 
                     81: // テキストスクリーンに文字列を出力する。
                     82: // 右もしくは下にはみ出した場合は無視する。
                     83: void
                     84: TextScreen::Puts(uint attr, const char *str)
                     85: {
                     86:        while (*str != '\0') {
                     87:                Putc(attr | *str++);
                     88:        }
                     89: }
                     90: 
                     91: // テキストスクリーンに座標を指定して書式付き文字列を出力する。
                     92: void
                     93: TextScreen::Print(int x, int y, const char *fmt, ...)
                     94: {
                     95:        char buf[1024];
                     96:        va_list ap;
                     97: 
                     98:        va_start(ap, fmt);
                     99:        vsnprintf(buf, sizeof(buf), fmt, ap);
                    100:        va_end(ap);
                    101: 
                    102:        X = x;
                    103:        Y = y;
                    104:        Puts(buf);
                    105: }
                    106: 
                    107: // テキストスクリーンに座標と属性を指定して、書式付き文字列を出力する。
                    108: void
                    109: TextScreen::Print(int x, int y, uint attr, const char *fmt, ...)
                    110: {
                    111:        char buf[1024];
                    112:        va_list ap;
                    113: 
                    114:        va_start(ap, fmt);
                    115:        vsnprintf(buf, sizeof(buf), fmt, ap);
                    116:        va_end(ap);
                    117: 
                    118:        X = x;
                    119:        Y = y;
                    120:        Puts(attr, buf);
                    121: }

unix.superglobalmegacorp.com

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