Audacity  2.2.2
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 #include "../Audacity.h"
10 #include "BackedPanel.h"
11 
12 BackedPanel::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) }
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 {
37  if (mResizeBacking)
38  {
39  // Reset
40  mResizeBacking = false;
41 
42  ResizeBacking();
43  }
44 
45  return mBackingDC;
46 }
47 
49 {
50  // Delete the backing bitmap
51  if (mBacking)
52  mBackingDC.SelectObject(wxNullBitmap);
53 
54  wxSize sz = GetClientSize();
55  mBacking = std::make_unique<wxBitmap>();
56  mBacking->Create(sz.x, sz.y); //, *dc);
57  mBackingDC.SelectObject(*mBacking);
58 }
59 
60 void 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  RepairBitmap(dc, 0, 0, mBacking->GetWidth(), mBacking->GetHeight());
68 }
69 
70 void BackedPanel::OnSize(wxSizeEvent & /* event */)
71 {
72  // Tell OnPaint() to recreate the backing bitmap
73  mResizeBacking = true;
74 
75  // Refresh the entire area. Really only need to refresh when
76  // expanding...is it worth the trouble?
77  Refresh();
78 }
79 
80 BEGIN_EVENT_TABLE(BackedPanel, wxPanelWrapper)
81  EVT_SIZE(BackedPanel::OnSize)
83 
void OnSize(wxSizeEvent &event)
Definition: BackedPanel.cpp:70
void ResizeBacking()
Definition: BackedPanel.cpp:48
wxDC & GetBackingDC()
Definition: BackedPanel.cpp:30
void DisplayBitmap(wxDC &dc)
Definition: BackedPanel.cpp:65
void RepairBitmap(wxDC &dc, wxCoord x, wxCoord y, wxCoord width, wxCoord height)
Definition: BackedPanel.cpp:60
BackedPanel(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, long style)
Definition: BackedPanel.cpp:12
wxDC & GetBackingDCForRepaint()
Definition: BackedPanel.cpp:35
wxMemoryDC mBackingDC
Definition: BackedPanel.h:39
bool mResizeBacking
Definition: BackedPanel.h:40
END_EVENT_TABLE()
std::unique_ptr< wxBitmap > mBacking
Definition: BackedPanel.h:38