|
|
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 なし)
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: {
32: bitmap_bgcolor = BGPANEL;
33: }
34:
35: // デストラクタ
36: WXBitmapPanel::~WXBitmapPanel()
37: {
38: }
39:
1.1.1.3 ! root 40: // 背景色を設定する
1.1 root 41: void
42: WXBitmapPanel::SetBitmapBGColor(Color c)
43: {
44: bitmap_bgcolor = c;
1.1.1.3 ! root 45: }
! 46:
! 47: // 背景色で塗りつぶす
! 48: void
! 49: WXBitmapPanel::Fill()
! 50: {
1.1 root 51: if (bitmap.GetBuf()) {
52: bitmap.Fill(bitmap_bgcolor);
53: }
54: }
55:
1.1.1.3 ! root 56: // 固定サイズ指定
! 57: void
! 58: WXBitmapPanel::SetFixedSize(const wxSize& size_)
! 59: {
! 60: fixedsize = size_;
! 61: }
! 62:
1.1 root 63: // サイズ変更イベント
64: void
65: WXBitmapPanel::OnSize(wxSizeEvent& event)
66: {
1.1.1.3 ! root 67: wxSize size = event.GetSize();
1.1 root 68: if (size.x <= 1 || size.y <= 1) {
69: return;
70: }
71:
72: event.Skip();
73:
1.1.1.3 ! root 74: // 固定サイズ指定がある場合。
! 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);
87: }
88: }
89:
90: // 描画イベント (UI スレッドから呼ばれる)
91: void
92: WXBitmapPanel::OnPaint(wxPaintEvent& event)
93: {
1.1.1.2 root 94: if (__predict_false(bitmap.GetBuf() == NULL)) {
95: return;
96: }
97:
1.1 root 98: // 継承クラスによる描画
99: Draw();
100:
101: wxImage image(bitmap.GetWidth(), bitmap.GetHeight(), bitmap.GetBuf(), true);
102: wxBitmap bmp(image);
103:
1.1.1.3 ! root 104: // 実画面 DC にコピー。
! 105: // バックバッファのほうが大きくても気にしない。
1.1 root 106: wxPaintDC dstDC(this);
107: dstDC.DrawBitmap(bmp, 0, 0);
108: }
109:
110: // 描画処理
111: void
112: WXBitmapPanel::Draw()
113: {
114: // 通常は継承クラスが記述する。
115: // ここで用意している Draw() は何もしないことで、全域を背景色で
116: // 塗りつぶしただけの状態が表示できる。空き地や下地表示用。
117: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.