--- nono/wx/wxtextpanel.h 2026/04/29 17:04:39 1.1.1.3 +++ nono/wx/wxtextpanel.h 2026/04/29 17:05:27 1.1.1.9 @@ -4,116 +4,68 @@ // Licensed under nono-license.txt // -#pragma once - -#include "wxheader.h" -#include - // -// テキストフォントを管理するクラス +// テキストフォントを描画するパネル // + // wxPanel // ↓ -// WXTextPanel テキストフォントを管理するクラス +// WXTextPanel テキストフォントを描画するパネル // ↓ // WXTextScreen テキストスクリーンを表示するパネル -// -class WXTextPanel : public wxPanel +#pragma once + +#include "wxbitmappanel.h" +#include "textscreen.h" + +class WXTextPanel : public WXBitmapPanel { - using inherited = wxPanel; + using inherited = WXBitmapPanel; + + // パレット番号 + static const int BG = 0; + static const int FG = 1; + public: - WXTextPanel(wxWindow *parent); - virtual ~WXTextPanel() override; + WXTextPanel(wxWindow *parent, wxWindowID id = wxID_ANY, + const wxPoint& position = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxTAB_TRAVERSAL); + ~WXTextPanel() override; - // フォント種別(指定値) - // この値を元に各コントロールに指示を出す - static FontId global_fontid; - - // フォントサイズ変更 (派生クラスで用意する) - virtual void SetFontSize(FontId) = 0; - - // (外部から)フォントサイズを取得。 - // このクラス内および継承クラス内からなら簡便のため、これを呼ばずに - // 直接 font_width, font_height を使ってよい。 - const wxSize& GetFontSize() const { return fontsize; } + // フォント変更通知 + virtual void FontChanged(); - protected: - // このコントロールの現在のフォントサイズ - // (一瞬の過渡期以外は基本的に global_fontid と同じ値のはず) - FontId fontid = FontId::None; - - // フォントの幅と高さ(ピクセル) - // wxSize.{x, y} はマニュアルには載ってなくて、ヘッダにも - // 直接使うな (互換性のために public にしてある) と書いてあるけど、 - // 参照出来て便利なので使っちゃえ。 - wxSize fontsize {}; - int& font_width = fontsize.x; - int& font_height = fontsize.y; - - // フォント関連の内部情報を更新する - void UpdateFont(FontId fontid); - - // グリフを切り替える。 - // 0x5c は false: 円記号 true: バックスラッシュ - // 0x7c は false: パイプ記号 true: パイプ記号(破線) - // 0x7e は false: オーバーライン true: チルダ - void SetGlyph5C(bool value) { glyph_5c = value; } - void SetGlyph7C(bool value) { glyph_7c = value; } - void SetGlyph7E(bool value) { glyph_7e = value; } + int GetFontWidth() const { return font_width; } + int GetFontHeight() const { return font_height; } + protected: // テキスト色を指定 - void SetTextColor(const wxColour& fg, const wxColour& bg, - const wxColour& disable); - void SetTextForeColor(const wxColour& fg) { text_fgcolor = fg; } - void SetTextBackColor(const wxColour& bg) { text_bgcolor = bg; } - void SetTextDisableColor(const wxColour& disable) { - text_disable_color = disable; - } + void ResetTextColor(); + void SetTextColor(Color fg, Color bg); + void SetTextForeColor(Color fg) { palette[FG] = fg; } + void SetTextBackColor(Color bg) { palette[BG] = bg; } + // テキスト色を取得 - const wxColour& GetTextForeColor() const { return text_fgcolor; } - const wxColour& GetTextBackColor() const { return text_bgcolor; } - const wxColour& GetTextDisableColor() const { return text_disable_color; } + Color GetTextForeColor() const { return palette[FG]; } + Color GetTextBackColor() const { return palette[BG]; } // Shift_JIS (正確には CP932) 文字列を描画する。 - void DrawStringSJIS(wxDC&, int px, int py, const char *sjis, + void DrawStringSJIS(Color c, int px, int py, const char *sjis, + uint attr = TA::Normal); + void DrawStringSJIS(int px, int py, const char *sjis, uint attr = TA::Normal); - // ASCII 1文字を描画 - void DrawChar1(wxDC&, int px, int py, uint code, uint attr); - // 半角カナ1文字を描画 - void DrawCharKana(wxDC&, int px, int py, uint code, uint attr); - // 漢字1文字を描画 - void DrawChar2(wxDC&, int px, int py, uint code, uint attr); - - private: - // 指定の文字ビットマップを描画 - void DrawBitmap(wxDC&, int px, int py, const wxBitmap& bitmap, uint attr); - // 半角カナビットマップを生成 - wxBitmap *KanaBitmap(uint16, uint attr); - // 漢字ビットマップを生成 - wxBitmap *KanjiBitmap(uint16, uint attr); - - static void AllocFont(FontId fontid); - static void FreeFont(FontId fontid); - - // 現在のフォントでのフォントデータ - wxBitmap **ascii_glyph = NULL; - wxBitmap **bold_glyph = NULL; - - // 現在のグリフ - bool glyph_5c = false; - bool glyph_7c = false; - bool glyph_7e = false; - - static std::mutex global_font_mutex; - // 以下の3つを書き換える時は global_font_mutex を取ること - static u_int font_refcnt[FontId::Max]; - static wxBitmap *ascii_glyph_table[FontId::Max][0x83]; - static wxBitmap *bold_glyph_table[FontId::Max][0x83]; + // 半角1文字を描画 + void DrawChar1(int px, int py, uint code, uint attr = TA::Normal); + // 全角1文字を描画 + void DrawChar2(int px, int py, uint code, uint attr = TA::Normal); + + // フォントサイズ + int font_width {}; + int font_height {}; // 色 - wxColour text_fgcolor; // 前景色 - wxColour text_bgcolor; // 背景色 - wxColour text_disable_color; // Disable 属性時の前景色 + Color palette[2] {}; };