--- nono/wx/wxtextscreen.h 2026/04/29 17:04:37 1.1.1.2 +++ nono/wx/wxtextscreen.h 2026/04/29 17:05:08 1.1.1.7 @@ -4,49 +4,96 @@ // Licensed under nono-license.txt // -#pragma once - -#include "wxtextpanel.h" - // -// テキストスクリーン風コントロール +// テキストスクリーンを描画するパネル // + // wxPanel // ↓ -// WXTextPanel テキストフォントを管理するクラス +// WXTextPanel テキストフォントを描画するクラス // ↓ -// WXTextScreen テキストフォントを使ったテキストスクリーン -// +// WXTextScreen テキストスクリーンを表示するパネル + +#pragma once + +#include "wxtextpanel.h" +#include "monitor.h" + class WXTextScreen : public WXTextPanel { using inherited = WXTextPanel; - public: - WXTextScreen(wxWindow *parent, int col, int row, const uint16 *textbuf); - virtual ~WXTextScreen(); + // テキストスクリーンは本来単純なキャラクタビットマップ構造のため、 + // クライアント領域の端の1ピクセルまでふんだんに使用している。 + // ウィンドウマネージャ側でこのウィンドウに枠などをつけてくれる場合は + // あまり問題にならないが、枠などを一切つけないタイプのウィンドウ + // マネージャでこのウィンドウを表示するとウィンドウの縁に接する文字の + // 視認性が(文字とウィンドウ外の背景の組み合わせによっては)すこぶる + // 悪くなる。そのため、テキストスクリーンの周囲に余白をもたせる。 + static const int DefaultPadding = 3; - // XXX - void SetTextSize(int col, int row); + public: + WXTextScreen(wxWindow *parent, Monitor& monitor); + virtual ~WXTextScreen() override; - void OnPaint(wxPaintEvent&); - void OnSize(wxSizeEvent&); + // 画面を更新して再描画する。 + void DoRefresh(); // フォントサイズ変更 - void SetFontSize(fontsize_t fontsize); + void FontChanged() override; + + // 更新頻度設定 + void SetRate(int hz); + + // パディングサイズ変更 + 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 ts.GetCol(); } + int GetRow() const { return ts.GetRow(); } + + // クライアント座標 pos をテキスト座標(桁、行)に変換して返す + // (パディング領域では戻り値が負数になることに注意) + wxPoint GetTextPosition(const wxPoint& pos) const; + + // TextScreen のユーザデータ取得、設定 + uint64 GetUserData() const { return ts.userdata; } + void SetUserData(uint64 value) { ts.userdata = value; } + + // コンテキストメニューイベントを解除 + // (ここのコンテキストメニューを使いたくない人が呼ぶ) + void DisconnectContextMenu(); private: - void Draw(wxDC& dc); + void OnSize(wxSizeEvent&); + void OnTimer(wxTimerEvent&); + void OnContextMenu(wxContextMenuEvent&); + void OnCopy(wxCommandEvent&); + + void Init(int col, int row); + void DoSize(); + void InvalidateText(); + void Draw() override; + + // コンテキストメニューを接続 + void ConnectContextMenu(); + + std::vector prevbuf {}; + + Monitor& monitor; + TextScreen ts {}; + + int pad_left {}; + int pad_top {}; + int pad_right {}; + int pad_bottom {}; - const uint16 *textbuf {}; - std::unique_ptr prevbuf {}; - std::unique_ptr bmpbuf {}; - std::unique_ptr image {}; - std::unique_ptr bitmap {}; - - int col = 0; - int row = 0; - int view_width = 0; - int view_height = 0; + wxTimer timer {}; wxDECLARE_EVENT_TABLE(); };