|
|
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: {
1.1.1.2 ! root 72: if (__predict_false(bitmap.GetBuf() == NULL)) {
! 73: return;
! 74: }
! 75:
1.1 root 76: // 継承クラスによる描画
77: Draw();
78:
79: wxImage image(bitmap.GetWidth(), bitmap.GetHeight(), bitmap.GetBuf(), true);
80: wxBitmap bmp(image);
81:
82: // 実画面 DC にコピー
83: wxPaintDC dstDC(this);
84: dstDC.DrawBitmap(bmp, 0, 0);
85: }
86:
87: // 描画処理
88: void
89: WXBitmapPanel::Draw()
90: {
91: // 通常は継承クラスが記述する。
92: // ここで用意している Draw() は何もしないことで、全域を背景色で
93: // 塗りつぶしただけの状態が表示できる。空き地や下地表示用。
94: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.