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