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

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

unix.superglobalmegacorp.com

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