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

1.1       root        1: //
                      2: // nono
                      3: // Copyright (C) 2021 nono project
                      4: // Licensed under nono-license.txt
                      5: //
                      6: 
                      7: //
1.1.1.4   root        8: // バックバッファが BitmapRGBX なパネル
1.1       root        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 なし)
1.1.1.3   root       21: WXBitmapPanel::WXBitmapPanel(wxWindow *parent,
                     22:        const wxPoint& position, const wxSize& size, long style)
                     23:        : WXBitmapPanel(parent, wxID_ANY, position, size, style)        // 移譲
1.1       root       24: {
                     25: }
                     26: 
                     27: // コンストラクタ (ID あり)
                     28: WXBitmapPanel::WXBitmapPanel(wxWindow *parent, wxWindowID id,
1.1.1.3   root       29:        const wxPoint& position, const wxSize& size, long style)
                     30:        : inherited(parent, id, position, size, style)
1.1       root       31: {
1.1.1.5   root       32:        SetName("WXBitmapPanel");
                     33: 
1.1       root       34:        bitmap_bgcolor = BGPANEL;
                     35: }
                     36: 
                     37: // デストラクタ
                     38: WXBitmapPanel::~WXBitmapPanel()
                     39: {
                     40: }
                     41: 
1.1.1.3   root       42: // 背景色を設定する
1.1       root       43: void
                     44: WXBitmapPanel::SetBitmapBGColor(Color c)
                     45: {
                     46:        bitmap_bgcolor = c;
1.1.1.3   root       47: }
                     48: 
                     49: // 背景色で塗りつぶす
                     50: void
                     51: WXBitmapPanel::Fill()
                     52: {
1.1       root       53:        if (bitmap.GetBuf()) {
                     54:                bitmap.Fill(bitmap_bgcolor);
                     55:        }
                     56: }
                     57: 
1.1.1.6 ! root       58: // 最小サイズ指定
1.1.1.3   root       59: void
1.1.1.6 ! root       60: WXBitmapPanel::SetMinBitmapSize(const wxSize& size_)
1.1.1.3   root       61: {
                     62:        fixedsize = size_;
                     63: }
                     64: 
1.1       root       65: // サイズ変更イベント
                     66: void
                     67: WXBitmapPanel::OnSize(wxSizeEvent& event)
                     68: {
1.1.1.3   root       69:        wxSize size = event.GetSize();
1.1.1.6 ! root       70:        if (size.x < 1 || size.y < 1) {
1.1       root       71:                return;
                     72:        }
                     73: 
1.1.1.6 ! root       74:        // 最小サイズ指定がある場合。
1.1.1.3   root       75:        if (fixedsize.x != 0 && size.x < fixedsize.x) {
                     76:                size.x = fixedsize.x;
                     77:        }
                     78:        if (fixedsize.y != 0 && size.y < fixedsize.y) {
                     79:                size.y = fixedsize.y;
                     80:        }
                     81: 
                     82:        // バックバッファの大きさが変われば変更。
1.1       root       83:        wxSize oldsize(bitmap.GetWidth(), bitmap.GetHeight());
                     84:        if (size != oldsize) {
                     85:                bitmap.Create(size.x, size.y);
                     86:                bitmap.Fill(bitmap_bgcolor);
1.1.1.4   root       87: 
                     88:                bitmap24.Create(size.x, size.y);
1.1       root       89:        }
1.1.1.6 ! root       90: 
        !            91:        Refresh();
        !            92:        event.Skip();
1.1       root       93: }
                     94: 
                     95: // 描画イベント (UI スレッドから呼ばれる)
                     96: void
                     97: WXBitmapPanel::OnPaint(wxPaintEvent& event)
                     98: {
1.1.1.2   root       99:        if (__predict_false(bitmap.GetBuf() == NULL)) {
                    100:                return;
                    101:        }
                    102: 
1.1       root      103:        // 継承クラスによる描画
                    104:        Draw();
                    105: 
1.1.1.4   root      106:        bitmap.ConvertToRGB(bitmap24);
                    107: 
                    108:        wxImage image(bitmap24.GetWidth(), bitmap24.GetHeight(),
                    109:                bitmap24.GetBuf(), true);
1.1       root      110:        wxBitmap bmp(image);
                    111: 
1.1.1.3   root      112:        // 実画面 DC にコピー。
                    113:        // バックバッファのほうが大きくても気にしない。
1.1       root      114:        wxPaintDC dstDC(this);
                    115:        dstDC.DrawBitmap(bmp, 0, 0);
                    116: }
                    117: 
                    118: // 描画処理
                    119: void
                    120: WXBitmapPanel::Draw()
                    121: {
                    122:        // 通常は継承クラスが記述する。
                    123:        // ここで用意している Draw() は何もしないことで、全域を背景色で
                    124:        // 塗りつぶしただけの状態が表示できる。空き地や下地表示用。
                    125: }

unix.superglobalmegacorp.com

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