--- nono/wx/wxbitmappanel.cpp 2026/04/29 17:05:08 1.1 +++ nono/wx/wxbitmappanel.cpp 2026/04/29 17:05:57 1.1.1.7 @@ -5,11 +5,10 @@ // // -// バックバッファが BitmapRGB なパネル +// バックバッファが BitmapRGBX なパネル // #include "wxbitmappanel.h" -#include "wxcolor.h" // イベントテーブル wxBEGIN_EVENT_TABLE(WXBitmapPanel, inherited) @@ -18,16 +17,19 @@ wxBEGIN_EVENT_TABLE(WXBitmapPanel, inher wxEND_EVENT_TABLE() // コンストラクタ (ID なし) -WXBitmapPanel::WXBitmapPanel(wxWindow *parent, const wxSize& size, long style) - : WXBitmapPanel(parent, wxID_ANY, size, style) // 移譲 +WXBitmapPanel::WXBitmapPanel(wxWindow *parent, + const wxPoint& position, const wxSize& size, long style) + : WXBitmapPanel(parent, wxID_ANY, position, size, style) // 移譲 { } // コンストラクタ (ID あり) WXBitmapPanel::WXBitmapPanel(wxWindow *parent, wxWindowID id, - const wxSize& size, long style) - : inherited(parent, id, wxDefaultPosition, size, style) + const wxPoint& position, const wxSize& size, long style) + : inherited(parent, id, position, size, style) { + SetName("WXBitmapPanel"); + bitmap_bgcolor = BGPANEL; } @@ -36,46 +38,78 @@ WXBitmapPanel::~WXBitmapPanel() { } -// 背景色 +// 背景色を設定する void WXBitmapPanel::SetBitmapBGColor(Color c) { bitmap_bgcolor = c; +} + +// 背景色で塗りつぶす +void +WXBitmapPanel::Fill() +{ if (bitmap.GetBuf()) { bitmap.Fill(bitmap_bgcolor); } } +// 最小サイズ指定 +void +WXBitmapPanel::SetMinBitmapSize(const wxSize& size_) +{ + fixedsize = size_; +} + // サイズ変更イベント void WXBitmapPanel::OnSize(wxSizeEvent& event) { - const wxSize& size = event.GetSize(); - if (size.x <= 1 || size.y <= 1) { + wxSize size = event.GetSize(); + if (size.x < 1 || size.y < 1) { return; } - event.Skip(); + // 最小サイズ指定がある場合。 + if (fixedsize.x != 0 && size.x < fixedsize.x) { + size.x = fixedsize.x; + } + if (fixedsize.y != 0 && size.y < fixedsize.y) { + size.y = fixedsize.y; + } - // バックバッファの大きさも変更 + // バックバッファの大きさが変われば変更。 wxSize oldsize(bitmap.GetWidth(), bitmap.GetHeight()); if (size != oldsize) { bitmap.Create(size.x, size.y); bitmap.Fill(bitmap_bgcolor); + + bitmap24.Create(size.x, size.y); } + + Refresh(); + event.Skip(); } // 描画イベント (UI スレッドから呼ばれる) void WXBitmapPanel::OnPaint(wxPaintEvent& event) { + if (__predict_false(bitmap.GetBuf() == NULL)) { + return; + } + // 継承クラスによる描画 Draw(); - wxImage image(bitmap.GetWidth(), bitmap.GetHeight(), bitmap.GetBuf(), true); + bitmap.ConvertToRGB(bitmap24); + + wxImage image(bitmap24.GetWidth(), bitmap24.GetHeight(), + bitmap24.GetBuf(), true); wxBitmap bmp(image); - // 実画面 DC にコピー + // 実画面 DC にコピー。 + // バックバッファのほうが大きくても気にしない。 wxPaintDC dstDC(this); dstDC.DrawBitmap(bmp, 0, 0); }