Annotation of nono/wx/wxbitmappanel.cpp, revision 1.1.1.1

1.1       root        1: //
                      2: // nono
                      3: // Copyright (C) 2021 nono project
                      4: // Licensed under nono-license.txt
                      5: //
                      6: 
                      7: //
                      8: // バックバッファが BitmapRGB なパネル
                      9: //
                     10: 
                     11: #include "wxbitmappanel.h"
                     12: #include "wxcolor.h"
                     13: 
                     14: // イベントテーブル
                     15: wxBEGIN_EVENT_TABLE(WXBitmapPanel, inherited)
                     16:        EVT_SIZE(WXBitmapPanel::OnSize)
                     17:        EVT_PAINT(WXBitmapPanel::OnPaint)
                     18: wxEND_EVENT_TABLE()
                     19: 
                     20: // コンストラクタ (ID なし)
                     21: WXBitmapPanel::WXBitmapPanel(wxWindow *parent, const wxSize& size, long style)
                     22:        : WXBitmapPanel(parent, wxID_ANY, size, style)  // 移譲
                     23: {
                     24: }
                     25: 
                     26: // コンストラクタ (ID あり)
                     27: WXBitmapPanel::WXBitmapPanel(wxWindow *parent, wxWindowID id,
                     28:        const wxSize& size, long style)
                     29:        : inherited(parent, id, wxDefaultPosition, size, style)
                     30: {
                     31:        bitmap_bgcolor = BGPANEL;
                     32: }
                     33: 
                     34: // デストラクタ
                     35: WXBitmapPanel::~WXBitmapPanel()
                     36: {
                     37: }
                     38: 
                     39: // 背景色
                     40: void
                     41: WXBitmapPanel::SetBitmapBGColor(Color c)
                     42: {
                     43:        bitmap_bgcolor = c;
                     44:        if (bitmap.GetBuf()) {
                     45:                bitmap.Fill(bitmap_bgcolor);
                     46:        }
                     47: }
                     48: 
                     49: // サイズ変更イベント
                     50: void
                     51: WXBitmapPanel::OnSize(wxSizeEvent& event)
                     52: {
                     53:        const wxSize& size = event.GetSize();
                     54:        if (size.x <= 1 || size.y <= 1) {
                     55:                return;
                     56:        }
                     57: 
                     58:        event.Skip();
                     59: 
                     60:        // バックバッファの大きさも変更
                     61:        wxSize oldsize(bitmap.GetWidth(), bitmap.GetHeight());
                     62:        if (size != oldsize) {
                     63:                bitmap.Create(size.x, size.y);
                     64:                bitmap.Fill(bitmap_bgcolor);
                     65:        }
                     66: }
                     67: 
                     68: // 描画イベント (UI スレッドから呼ばれる)
                     69: void
                     70: WXBitmapPanel::OnPaint(wxPaintEvent& event)
                     71: {
                     72:        // 継承クラスによる描画
                     73:        Draw();
                     74: 
                     75:        wxImage image(bitmap.GetWidth(), bitmap.GetHeight(), bitmap.GetBuf(), true);
                     76:        wxBitmap bmp(image);
                     77: 
                     78:        // 実画面 DC にコピー
                     79:        wxPaintDC dstDC(this);
                     80:        dstDC.DrawBitmap(bmp, 0, 0);
                     81: }
                     82: 
                     83: // 描画処理
                     84: void
                     85: WXBitmapPanel::Draw()
                     86: {
                     87:        // 通常は継承クラスが記述する。
                     88:        // ここで用意している Draw() は何もしないことで、全域を背景色で
                     89:        // 塗りつぶしただけの状態が表示できる。空き地や下地表示用。
                     90: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.