Annotation of nono/wx/wxtextpanel.cpp, revision 1.1.1.10

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: //
1.1.1.8   root        8: // テキストフォントを描画するパネル
1.1       root        9: //
                     10: 
1.1.1.8   root       11: #include "wxtextpanel.h"
                     12: #include "fontmanager.h"
                     13: #include "wxcolor.h"
                     14: #include "sjis.h"
1.1.1.5   root       15: 
1.1.1.8   root       16: // コンストラクタ
1.1.1.9   root       17: WXTextPanel::WXTextPanel(wxWindow *parent, wxWindowID id,
                     18:        const wxPoint& position, const wxSize& size, long style)
                     19:        : inherited(parent, id, position, size, style)
1.1       root       20: {
                     21:        // デフォルト色
1.1.1.5   root       22:        ResetTextColor();
1.1       root       23: }
                     24: 
                     25: // デストラクタ
                     26: WXTextPanel::~WXTextPanel()
                     27: {
                     28: }
                     29: 
                     30: void
1.1.1.8   root       31: WXTextPanel::FontChanged()
1.1       root       32: {
1.1.1.8   root       33:        font_width = gFontManager->GetFontWidth();
                     34:        font_height = gFontManager->GetFontHeight();
1.1       root       35: }
                     36: 
1.1.1.5   root       37: // テキスト色をデフォルトに設定する(戻す)
                     38: void
                     39: WXTextPanel::ResetTextColor()
                     40: {
1.1.1.8   root       41:        SetTextColor(UD_BLACK, BGPANEL);
1.1.1.5   root       42: }
                     43: 
1.1       root       44: // テキスト色を指定する
                     45: void
1.1.1.8   root       46: WXTextPanel::SetTextColor(Color fg, Color bg)
                     47: {
                     48:        palette[FG] = fg;
                     49:        palette[BG] = bg;
                     50: }
                     51: 
                     52: // (px, py) を左上とする座標から Shift_JIS 文字列を、前景色 c、属性 attr で
                     53: // 描画する。
                     54: // ただし attr のうちここで参照するのは EM (ボールド) かそうでないかのみ。
                     55: // フォントサイズは現行のフォント。
                     56: // キャンバスをはみ出さないこと。
                     57: void
                     58: WXTextPanel::DrawStringSJIS(Color c, int px, int py, const char *sjis,
                     59:        uint attr)
1.1       root       60: {
1.1.1.8   root       61:        Color backup = palette[FG];
                     62: 
                     63:        palette[FG] = c;
                     64:        DrawStringSJIS(px, py, sjis, attr);
                     65:        palette[FG] = backup;
1.1       root       66: }
                     67: 
                     68: // (px, py) を左上とする座標から Shift_JIS 文字列を属性 attr で描画する。
1.1.1.5   root       69: // ただし attr のうちここで参照するのは EM (ボールド) かそうでないかのみ。
                     70: // 描画色、背景色は事前に SetTextColor() で設定したもの。
1.1       root       71: // フォントサイズは現行のフォント。
1.1.1.8   root       72: // キャンバスをはみ出さないこと。
1.1       root       73: void
1.1.1.8   root       74: WXTextPanel::DrawStringSJIS(int px, int py, const char *sjis, uint attr)
1.1       root       75: {
                     76:        const uint8 *s;
                     77: 
                     78:        for (s = (const uint8 *)sjis; *s; ) {
1.1.1.5   root       79:                if (__predict_true(SJIS::IsHankaku(*s))) {
                     80:                        // 半角
1.1.1.8   root       81:                        DrawChar1(px, py, *s++, attr);
1.1       root       82:                        px += font_width;
                     83:                } else {
                     84:                        // 全角
                     85:                        int code;
                     86:                        code = (*s++ << 8);
                     87:                        code |= *s++;
1.1.1.8   root       88:                        DrawChar2(px, py, code, attr);
1.1       root       89:                        px += font_width * 2;
                     90:                }
                     91:        }
                     92: }
                     93: 
1.1.1.5   root       94: // (px, py) を左上とする座標から半角文字 code を属性 attr で描画する。
                     95: // code は ASCII または半角カナ。
1.1       root       96: // フォントサイズは現行のフォント。
                     97: void
1.1.1.8   root       98: WXTextPanel::DrawChar1(int px, int py, uint code, uint attr)
1.1       root       99: {
1.1.1.8   root      100:        const uint8 *glyph;
1.1       root      101: 
1.1.1.5   root      102:        assertmsg(code < 0x100, "code=0x%x", code);
1.1       root      103: 
1.1.1.8   root      104:        glyph = gFontManager->AsciiGlyph(code, attr);
                    105:        BitmapI1 src(glyph, font_width, font_height);
1.1.1.10! root      106:        bitmap.DrawBitmapI1(px, py, src, palette);
1.1.1.3   root      107: }
                    108: 
1.1.1.8   root      109: // (px, py) を左上とする座標から漢字1文字を属性 attr で描画する。
1.1       root      110: // sjiscode は Shift_JIS。
                    111: // フォントサイズは現行のフォント。
                    112: void
1.1.1.8   root      113: WXTextPanel::DrawChar2(int px, int py, uint sjiscode, uint attr)
1.1       root      114: {
1.1.1.8   root      115:        std::vector<uint8> glyph;
1.1       root      116: 
1.1.1.8   root      117:        glyph = gFontManager->KanjiGlyph(sjiscode, attr);
                    118:        BitmapI1 src(glyph.data(), font_width * 2, font_height);
1.1.1.10! root      119:        bitmap.DrawBitmapI1(px, py, src, palette);
1.1.1.3   root      120: }

unix.superglobalmegacorp.com

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