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