|
|
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: {
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);
1.1.1.4 ! root 87:
! 88: bitmap24.Create(size.x, size.y);
1.1 root 89: }
90: }
91:
92: // 描画イベント (UI スレッドから呼ばれる)
93: void
94: WXBitmapPanel::OnPaint(wxPaintEvent& event)
95: {
1.1.1.2 root 96: if (__predict_false(bitmap.GetBuf() == NULL)) {
97: return;
98: }
99:
1.1 root 100: // 継承クラスによる描画
101: Draw();
102:
1.1.1.4 ! root 103: bitmap.ConvertToRGB(bitmap24);
! 104:
! 105: wxImage image(bitmap24.GetWidth(), bitmap24.GetHeight(),
! 106: bitmap24.GetBuf(), true);
1.1 root 107: wxBitmap bmp(image);
108:
1.1.1.3 root 109: // 実画面 DC にコピー。
110: // バックバッファのほうが大きくても気にしない。
1.1 root 111: wxPaintDC dstDC(this);
112: dstDC.DrawBitmap(bmp, 0, 0);
113: }
114:
115: // 描画処理
116: void
117: WXBitmapPanel::Draw()
118: {
119: // 通常は継承クラスが記述する。
120: // ここで用意している Draw() は何もしないことで、全域を背景色で
121: // 塗りつぶしただけの状態が表示できる。空き地や下地表示用。
122: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.