forked from audacity/audacity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackedPanel.cpp
More file actions
84 lines (70 loc) · 1.86 KB
/
Copy pathBackedPanel.cpp
File metadata and controls
84 lines (70 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//
// BackedPanel.cpp
// Audacity
//
// Created by Paul Licameli on 5/7/16.
//
//
#include "../Audacity.h"
#include "BackedPanel.h"
BackedPanel::BackedPanel(wxWindow * parent, wxWindowID id,
const wxPoint & pos,
const wxSize & size,
long style)
: wxPanelWrapper(parent, id, pos, size, style)
, mBacking{ std::make_unique<wxBitmap>(1, 1, 24) }
{
// Preinit the backing DC and bitmap so routines that require it will
// not cause a crash if they run before the panel is fully initialized.
mBackingDC.SelectObject(*mBacking);
}
BackedPanel::~BackedPanel()
{
if (mBacking)
mBackingDC.SelectObject( wxNullBitmap );
}
wxDC &BackedPanel::GetBackingDC()
{
return mBackingDC;
}
wxDC &BackedPanel::GetBackingDCForRepaint()
{
if (mResizeBacking)
{
// Reset
mResizeBacking = false;
ResizeBacking();
}
return mBackingDC;
}
void BackedPanel::ResizeBacking()
{
if (mBacking)
mBackingDC.SelectObject(wxNullBitmap);
wxSize sz = GetClientSize();
mBacking = std::make_unique<wxBitmap>();
// Bug 2040 - Avoid 0 x 0 bitmap when minimized.
mBacking->Create(std::max(sz.x,1), std::max(sz.y,1),24); //, *dc);
mBackingDC.SelectObject(*mBacking);
}
void BackedPanel::RepairBitmap(wxDC &dc, wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{
dc.Blit(x, y, width, height, &mBackingDC, x, y);
}
void BackedPanel::DisplayBitmap(wxDC &dc)
{
if( mBacking )
RepairBitmap(dc, 0, 0, mBacking->GetWidth(), mBacking->GetHeight());
}
void BackedPanel::OnSize(wxSizeEvent & event)
{
// Tell OnPaint() to recreate the backing bitmap
mResizeBacking = true;
event.Skip();
// Refresh the entire area. Really only need to refresh when
// expanding...is it worth the trouble?
Refresh();
}
BEGIN_EVENT_TABLE(BackedPanel, wxPanelWrapper)
EVT_SIZE(BackedPanel::OnSize)
END_EVENT_TABLE()