--- nono/wx/wxtextscreen.cpp 2026/04/29 17:05:31 1.1.1.12 +++ nono/wx/wxtextscreen.cpp 2026/04/29 17:05:48 1.1.1.14 @@ -75,61 +75,62 @@ WXTextScreen::FontChanged() InvalidateText(); // コントロールの大きさを変更 - DoSize(); + Fit(); } -// (自発的な)サイズ変更。 -// screen の行数桁数、font_{width,height}、四方のパディングのいずれかが -// 変わった場合に呼ぶこと。 void -WXTextScreen::DoSize() +WXTextScreen::Fit() { - wxSize size = wxSize( - screen.GetCol() * font_width + pad_left + pad_right, - screen.GetRow() * font_height + pad_top + pad_bottom); - SetClientSize(size); - SetMinClientSize(size); + // 指定の (row, col) にパディングを加味した大きさにする、 + // なので GetSize() ではない。 + wxSize size(GetScreenWidth(GetCol()), GetScreenHeight(GetRow())); + + // バックバッファのサイズを固定。 + SetMinBitmapSize(size); + + SetSize(size); + SetMinSize(size); } -// サイズ変更イベント void WXTextScreen::OnSize(wxSizeEvent& event) { - // Mac ではウィンドウ作成時に 0 以下の値が来ることがある。 - // GTK では 1 で来ることがある。 - const wxSize& size = event.GetSize(); - if (size.x <= 1 || size.y <= 1) { - return; - } - - // 親クラス - inherited::OnSize(event); + const wxSize& size = GetSize(); // テキストサイズが変わった時だけテキストバッファを再構成。 // (フォントサイズを変えると桁数×行数が変わらず画面サイズが変わる // ということは起きることに注意) int sw = size.x - pad_left - pad_right; int sh = size.y - pad_top - pad_bottom; - if (__predict_false(sw < 0)) { - sw = 0; - } - if (__predict_false(sh < 0)) { - sh = 0; + int col = (font_width != 0) ? (sw / font_width) : 0; + int row = (font_height != 0) ? (sh / font_height) : 0; + if (__predict_false(col < 1 || row < 1)) { + return; } - int col = sw / font_width; - int row = sh / font_height; + if (col != screen.GetCol() || row != screen.GetRow()) { Init(col, row); } else { // テキストバッファを再構成しなくても全域を再描画する必要がある InvalidateText(); } + // サイズが変わったらどちらにしてもパディングも塗り直す。 + draw_padding = true; + + event.Skip(); } // テキストバッファの内容をパネルのバックグラウンドバッファに描画する。 void WXTextScreen::Draw() { + if (__predict_false(draw_padding)) { + draw_padding = false; + auto bgcol = GetTextBackColor(); + // パディングを塗るだけでいいのだが手抜き。 + bitmap.Fill(bgcol); + } + auto text = screen.GetBuf().begin(); auto prev = prevbuf.begin(); @@ -213,6 +214,22 @@ WXTextScreen::Draw() } } +// 桁数が col_ の時の横幅 [pixel] を取得。 +int +WXTextScreen::GetScreenWidth(int col_) const +{ + int w = GetFontWidth() * col_ + GetPaddingX(); + return w; +} + +// 行数が row_ の時の高さ [pixel] を取得。 +int +WXTextScreen::GetScreenHeight(int row_) const +{ + int h = GetFontHeight() * row_ + GetPaddingY(); + return h; +} + // パディングサイズ変更。 // 負数なら変更しない。 void @@ -231,16 +248,7 @@ WXTextScreen::SetPadding(int l, int t, i pad_bottom = b; } - DoSize(); -} - -// 全域を表示するのに必要なピクセルサイズを返す。 -wxSize -WXTextScreen::GetDesiredSize() const -{ - int w = GetCol() * GetFontWidth() + GetPaddingLeft() + GetPaddingRight(); - int h = GetRow() * GetFontHeight() + GetPaddingTop() + GetPaddingBottom(); - return wxSize(w, h); + Fit(); } // クライアント座標 pos をテキスト座標(桁、行)に変換して返す @@ -278,7 +286,7 @@ WXTextScreen::OnContextMenu(wxContextMen { wxMenu *menu = new wxMenu(); - menu->Append(wxID_COPY, _T("&Copy")); + menu->Append(wxID_COPY, _("&Copy All")); PopupMenu(menu); }