--- nono/wx/wxtextscreen.h 2026/04/29 17:04:53 1.1.1.5 +++ nono/wx/wxtextscreen.h 2026/04/29 17:05:12 1.1.1.8 @@ -4,62 +4,89 @@ // Licensed under nono-license.txt // -#pragma once - -#include "wxtextpanel.h" -#include "wxbmp.h" - // -// テキストスクリーンを表示するパネル +// テキストスクリーンを描画するパネル // + // wxPanel // ↓ -// WXTextPanel テキストフォントを管理するクラス +// WXTextPanel テキストフォントを描画するクラス // ↓ // WXTextScreen テキストスクリーンを表示するパネル -// + +#pragma once + +#include "wxtextpanel.h" +#include "geometric.h" + class WXTextScreen : public WXTextPanel { using inherited = WXTextPanel; + // テキストスクリーンは本来単純なキャラクタビットマップ構造のため、 + // クライアント領域の端の1ピクセルまでふんだんに使用している。 + // ウィンドウマネージャ側でこのウィンドウに枠などをつけてくれる場合は + // あまり問題にならないが、枠などを一切つけないタイプのウィンドウ + // マネージャでこのウィンドウを表示するとウィンドウの縁に接する文字の + // 視認性が(文字とウィンドウ外の背景の組み合わせによっては)すこぶる + // 悪くなる。そのため、テキストスクリーンの周囲に余白をもたせる。 + static const int DefaultPadding = 3; + public: - WXTextScreen(wxWindow *parent, IMonitor& monitor); + WXTextScreen(wxWindow *parent, const nnSize& screensize); virtual ~WXTextScreen() override; - // 必要なら画面を更新して再描画する。 - // TextScreen が前回描画時から更新されていたら、このパネルを再描画する。 - void RefreshIfUpdated(); - // フォントサイズ変更 - void SetFontSize(FontId fontid) override; + void FontChanged() override; - // 更新頻度設定 - void SetRate(int hz); + // テキストスクリーンを取得 (WXTextScreen を継承せずに更新する人のため) + TextScreen& GetScreen() { return screen; } - // サイズ (桁数×行数) を取得する - const wxSize GetSize() const { return wxSize(ts.GetCol(), ts.GetRow()); } + // パディングサイズ変更 + void SetPadding(int l, int t, int r, int b); + // パディングサイズ取得 + int GetPaddingLeft() const { return pad_left; } + int GetPaddingTop() const { return pad_top; } + int GetPaddingRight() const { return pad_right; } + int GetPaddingBottom() const { return pad_bottom; } + + // 桁数、行数を取得する + int GetCol() const { return screen.GetCol(); } + int GetRow() const { return screen.GetRow(); } + + // クライアント座標 pos をテキスト座標(桁、行)に変換して返す + // (パディング領域では戻り値が負数になることに注意) + wxPoint GetTextPosition(const wxPoint& pos) const; // TextScreen のユーザデータ取得、設定 - uint64 GetUserData() const { return ts.userdata; } - void SetUserData(uint64 value) { ts.userdata = value; } - - private: - void OnPaint(wxPaintEvent&); - void OnSize(wxSizeEvent&); - void OnTimer(wxTimerEvent&); + uint64 GetUserData() const { return screen.userdata; } + void SetUserData(uint64 value) { screen.userdata = value; } - void Init(int col, int row); - void Draw(wxDC& dc); - - // コントロール全域のビットマップ - WXBitmap bitmap {}; + // コンテキストメニューイベントを解除 + // (ここのコンテキストメニューを使いたくない人が呼ぶ) + void DisconnectContextMenu(); + protected: + TextScreen screen {}; std::vector prevbuf {}; - IMonitor& monitor; - TextScreen ts {}; + private: + void OnSize(wxSizeEvent&); + void OnContextMenu(wxContextMenuEvent&); + void OnCopy(wxCommandEvent&); - wxTimer timer {}; + void Init(int col, int row); + void DoSize(); + void InvalidateText(); + void Draw() override; + + // コンテキストメニューを接続 + void ConnectContextMenu(); + + int pad_left {}; + int pad_top {}; + int pad_right {}; + int pad_bottom {}; wxDECLARE_EVENT_TABLE(); };