--- nono/wx/wxlcdwindow.cpp 2026/04/29 17:05:31 1.1.1.9 +++ nono/wx/wxlcdwindow.cpp 2026/04/29 17:05:58 1.1.1.11 @@ -9,7 +9,6 @@ // #include "wxlcdwindow.h" -#include "wxcolor.h" #include "wxuimessage.h" #include "lcd.h" #include "monitor.h" @@ -36,6 +35,8 @@ WXLCDPanel::WXLCDPanel(wxWindow *parent) : inherited(parent) { + SetName("LCDPanel"); + u_width = 5 * 16 + 17; u_height = 8 * 2 + 3; @@ -67,11 +68,14 @@ WXLCDPanel::FontChanged() // このパネル内の描画の基本単位。 // 12, 16, 24 を 2, 3, 4 にする。 unit = (font_height + 5) / 6; - - // コントロールの大きさを変更 wxSize size(u_width * unit, u_height * unit); - SetClientSize(size); - SetMinClientSize(size); + + // バックバッファのサイズを固定。 + SetMinBitmapSize(size); + + // コントロールの大きさを変更。 + SetSize(size); + SetMinSize(size); } // LCD 状態変更イベント (UIMessage) @@ -117,9 +121,8 @@ WXLCDPanel::DrawChar(int x, int y, uint8 WXLCDWindow::WXLCDWindow(wxWindow *parent) : inherited(parent, wxID_ANY, _("Front LCD")) { - panel = new WXLCDPanel(this); - - DoSize(); + new WXLCDPanel(this); + Fit(); } // デストラクタ @@ -150,6 +153,8 @@ WXLCDWindow::~WXLCDWindow() WXLCDCharPanel::WXLCDCharPanel(wxWindow *parent) : inherited(parent) { + SetName("LCDCharPanel"); + lcd = GetLCDDevice(); u_width = 5 * 33 + 32; // 横 5px * (32+1)文字、余白が計 32 @@ -172,11 +177,14 @@ WXLCDCharPanel::FontChanged() // このパネル内の描画の基本単位。 // 12, 16, 24 を 2, 3, 4 にする。 unit = (font_height + 5) / 6; - - // コントロールの大きさを変更 wxSize size(u_width * unit, u_height * unit); - SetClientSize(size); - SetMinClientSize(size); + + // バックバッファのサイズを固定。 + SetMinBitmapSize(size); + + // コントロールの大きさを変更。 + SetSize(size); + SetMinSize(size); } // バックグラウンドバッファに描画 @@ -228,25 +236,65 @@ WXLCDMonitor::WXLCDMonitor(wxWindow *par // +------------+ // | CharPanel | // +------------+ - auto *topsizer = new wxBoxSizer(wxVERTICAL); // 上段、テキストスクリーン monpanel = new WXMonitorPanel(this, gMonitorManager->Get(ID_MONITOR_LCD)); // 下辺は CharPanel の上余白が隣接しているため、自分のほうは付けない。 monpanel->SetPadding(-1, -1, -1, 0); - topsizer->Add(monpanel, 0, wxEXPAND); // 下段、キャラクタパネル chrpanel = new WXLCDCharPanel(this); - topsizer->Add(chrpanel, 0, wxEXPAND); - SetSizer(topsizer); + // 空き地用。 + space = new WXBitmapPanel(this); - // 大きさをそれに固定 - SetClientSize(GetSizer()->GetMinSize()); + SetAutoLayout(true); + FontChanged(); } // デストラクタ WXLCDMonitor::~WXLCDMonitor() { } + +void +WXLCDMonitor::FontChanged() +{ + monpanel->FontChanged(); + chrpanel->FontChanged(); + + const wxSize& monsize = monpanel->GetSize(); + const wxSize& chrsize = chrpanel->GetSize(); + wxSize size(std::max(monsize.x, chrsize.x), monsize.y + chrsize.y); + SetClientSize(size); +} + +bool +WXLCDMonitor::Layout() +{ + // inherited::Layout() は(実質何もしないので)、呼ばずに自力で行う。 + + wxSize client = GetClientSize(); + const wxSize& monsize = monpanel->GetSize(); + const wxSize& chrsize = chrpanel->GetSize(); + + // コントロールを配置。 + monpanel->SetSize(0, 0, monsize.x, monsize.y); + chrpanel->SetSize(0, monsize.y, chrsize.x, chrsize.y); + + // monpanel と chrpanel はフォントサイズによる拡大倍率が違うため + // フォントサイズを変更した時に相似にならず、現状では必ずどちらかが + // 大きい (がどちらかは固定されない) という状態になる。 + // そこで小さい方のコントロールの右に空き地が出来てしまう。そのままだと + // GTK3 のウィンドウ下地色が見えてしまうため、BGPANEL 色のパネルを敷く。 + + if (monsize.x < chrsize.x) { + // 上が小さいので、右上に空き地を置く。 + space->SetSize(monsize.x, 0, client.x - monsize.x, monsize.y); + } else { + // 下が小さいので、左下に空き地を置く。 + space->SetSize(chrsize.x, monsize.y, client.x - chrsize.x, chrsize.y); + } + + return true; +}