Partially account for the shifted origin in wxBufferedDC.

This change slightly improves wxBufferedDC and wxBufferedPaintDC behaviour
when the origin of the DC is shifted, but they still don't work quite right in
this case as they don't use the buffer area of correct size in this case,
which results in cropping the final bitmap (as can be seen in the drawing
sample, which was modified to show wxBufferedPaintDC in action).

Closes #15497.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74951 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2013-10-07 09:58:56 +00:00
parent d32895c5d8
commit 9273033d5a
2 changed files with 26 additions and 3 deletions

View File

@@ -32,6 +32,7 @@
#include "wx/colordlg.h"
#include "wx/image.h"
#include "wx/artprov.h"
#include "wx/dcbuffer.h"
#include "wx/dcgraph.h"
#include "wx/overlay.h"
#include "wx/graphics.h"
@@ -101,6 +102,7 @@ public:
#if wxUSE_GRAPHICS_CONTEXT
void OnGraphicContext(wxCommandEvent& event);
#endif
void OnBuffer(wxCommandEvent& event);
void OnCopy(wxCommandEvent& event);
void OnSave(wxCommandEvent& event);
void OnShow(wxCommandEvent &event);
@@ -148,6 +150,8 @@ public:
#if wxUSE_GRAPHICS_CONTEXT
void UseGraphicContext(bool use) { m_useContext = use; Refresh(); }
#endif
void UseBuffer(bool use) { m_useBuffer = use; Refresh(); }
void Draw(wxDC& dc);
protected:
@@ -189,6 +193,7 @@ private:
#if wxUSE_GRAPHICS_CONTEXT
bool m_useContext ;
#endif
bool m_useBuffer;
DECLARE_EVENT_TABLE()
};
@@ -227,6 +232,7 @@ enum
#if wxUSE_GRAPHICS_CONTEXT
File_GraphicContext,
#endif
File_Buffer,
File_Copy,
File_Save,
@@ -410,6 +416,7 @@ MyCanvas::MyCanvas(MyFrame *parent)
#if wxUSE_GRAPHICS_CONTEXT
m_useContext = false;
#endif
m_useBuffer = false;
}
void MyCanvas::DrawTestBrushes(wxDC& dc)
@@ -1493,10 +1500,18 @@ void MyCanvas::DrawRegionsHelper(wxDC& dc, wxCoord x, bool firstTime)
}
void MyCanvas::OnPaint(wxPaintEvent &WXUNUSED(event))
{
if ( m_useBuffer )
{
wxBufferedPaintDC bpdc(this);
Draw(bpdc);
}
else
{
wxPaintDC pdc(this);
Draw(pdc);
}
}
void MyCanvas::Draw(wxDC& pdc)
{
@@ -1729,6 +1744,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
#if wxUSE_GRAPHICS_CONTEXT
EVT_MENU (File_GraphicContext, MyFrame::OnGraphicContext)
#endif
EVT_MENU (File_Buffer, MyFrame::OnBuffer)
EVT_MENU (File_Copy, MyFrame::OnCopy)
EVT_MENU (File_Save, MyFrame::OnSave)
@@ -1769,6 +1785,7 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
#if wxUSE_GRAPHICS_CONTEXT
menuFile->AppendCheckItem(File_GraphicContext, wxT("&Use GraphicContext\tCtrl-Y"), wxT("Use GraphicContext"));
#endif
menuFile->AppendCheckItem(File_Buffer, wxT("&Use wx&BufferedPaintDC\tCtrl-Z"), wxT("Buffer painting"));
menuFile->AppendSeparator();
#if wxUSE_METAFILE && defined(wxMETAFILE_IS_ENH)
menuFile->Append(File_Copy, wxT("Copy to clipboard"));
@@ -1881,6 +1898,11 @@ void MyFrame::OnGraphicContext(wxCommandEvent& event)
}
#endif
void MyFrame::OnBuffer(wxCommandEvent& event)
{
m_canvas->UseBuffer(event.IsChecked());
}
void MyFrame::OnCopy(wxCommandEvent& WXUNUSED(event))
{
#if wxUSE_METAFILE && defined(wxMETAFILE_IS_ENH)

View File

@@ -157,7 +157,8 @@ void wxBufferedDC::UnMask()
height = wxMin(height, heightDC);
}
m_dc->Blit(0, 0, width, height, this, -x, -y);
const wxPoint origin = GetLogicalOrigin();
m_dc->Blit(-origin.x, -origin.y, width, height, this, -x, -y);
m_dc = NULL;
if ( m_style & wxBUFFER_USES_SHARED_BUFFER )