|
|
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 "sjis.h"
1.1.1.5 root 14:
1.1.1.8 root 15: // コンストラクタ
1.1.1.9 root 16: WXTextPanel::WXTextPanel(wxWindow *parent, wxWindowID id,
17: const wxPoint& position, const wxSize& size, long style)
18: : inherited(parent, id, position, 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: // 全角
1.1.1.11 root 84: uint code;
1.1 root 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 で描画する。
1.1.1.11 root 94: // code は ASCII または半角カナ。attr のうち反応するのは Bold のみ。
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.5 root 99: assertmsg(code < 0x100, "code=0x%x", code);
1.1 root 100:
1.1.1.11 root 101: const uint8 *glyph = gFontManager->AsciiGlyph(code);
1.1.1.8 root 102: BitmapI1 src(glyph, font_width, font_height);
1.1.1.11 root 103: if (__predict_false((attr & TA::Bold))) {
104: src = src.ConvertToBold();
105: }
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.1.11 root 110: // sjiscode は Shift_JIS。attr のうち反応するのは Bold のみ。
1.1 root 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.11 root 115: const uint8 *glyph = gFontManager->KanjiGlyph(sjiscode);
116: BitmapI1 src(glyph, font_width * 2, font_height);
117: if (__predict_false((attr & TA::Bold))) {
118: src = src.ConvertToBold();
119: }
1.1.1.10 root 120: bitmap.DrawBitmapI1(px, py, src, palette);
1.1.1.3 root 121: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.