|
|
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.3 root 58: // 固定サイズ指定
59: void
60: WXBitmapPanel::SetFixedSize(const wxSize& size_)
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 root 70: if (size.x <= 1 || size.y <= 1) {
71: return;
72: }
73:
74: event.Skip();
75:
1.1.1.3 root 76: // 固定サイズ指定がある場合。
77: if (fixedsize.x != 0 && size.x < fixedsize.x) {
78: size.x = fixedsize.x;
79: }
80: if (fixedsize.y != 0 && size.y < fixedsize.y) {
81: size.y = fixedsize.y;
82: }
83:
84: // バックバッファの大きさが変われば変更。
1.1 root 85: wxSize oldsize(bitmap.GetWidth(), bitmap.GetHeight());
86: if (size != oldsize) {
87: bitmap.Create(size.x, size.y);
88: bitmap.Fill(bitmap_bgcolor);
1.1.1.4 root 89:
90: bitmap24.Create(size.x, size.y);
1.1 root 91: }
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: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.