Audacity  3.0.3
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 
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, 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 {
37  if (mResizeBacking)
38  {
39  // Reset
40  mResizeBacking = false;
41 
42  ResizeBacking();
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 
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  if( mBacking )
68  RepairBitmap(dc, 0, 0, mBacking->GetWidth(), mBacking->GetHeight());
69 }
70 
71 void 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 
81 BEGIN_EVENT_TABLE(BackedPanel, wxPanelWrapper)
82  EVT_SIZE(BackedPanel::OnSize)
84 
size
size_t size
Definition: ffmpeg-2.3.6-single-header.h:412
BackedPanel::DisplayBitmap
void DisplayBitmap(wxDC &dc)
Definition: BackedPanel.cpp:65
BackedPanel::RepairBitmap
void RepairBitmap(wxDC &dc, wxCoord x, wxCoord y, wxCoord width, wxCoord height)
Definition: BackedPanel.cpp:60
BackedPanel::GetBackingDC
wxDC & GetBackingDC()
Definition: BackedPanel.cpp:30
wxPanelWrapper
Definition: wxPanelWrapper.h:41
BackedPanel::~BackedPanel
~BackedPanel()
Definition: BackedPanel.cpp:24
BackedPanel::OnSize
void OnSize(wxSizeEvent &event)
Definition: BackedPanel.cpp:71
BackedPanel::mBackingDC
wxMemoryDC mBackingDC
Definition: BackedPanel.h:37
BackedPanel::GetBackingDCForRepaint
wxDC & GetBackingDCForRepaint()
Definition: BackedPanel.cpp:35
BackedPanel::ResizeBacking
void ResizeBacking()
Definition: BackedPanel.cpp:48
BackedPanel::mResizeBacking
bool mResizeBacking
Definition: BackedPanel.h:38
id
int id
Definition: WaveTrackControls.cpp:577
BackedPanel::mBacking
std::unique_ptr< wxBitmap > mBacking
Definition: BackedPanel.h:36
BackedPanel::BackedPanel
BackedPanel(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, long style)
Definition: BackedPanel.cpp:12
BackedPanel.h
BackedPanel
BackedPanel is for a panel that consists of a bitmap with something drawn over it....
Definition: BackedPanel.h:19
END_EVENT_TABLE
END_EVENT_TABLE()