implement wxDC::GetContentScaleFactor() for GTK3

This commit is contained in:
Paul Cornett
2016-02-22 09:52:26 -08:00
parent e5c93ad674
commit 6674ca57da
5 changed files with 23 additions and 10 deletions

View File

@@ -19,6 +19,7 @@ class wxGTKCairoDCImpl: public wxGCDCImpl
public:
wxGTKCairoDCImpl(wxDC* owner);
wxGTKCairoDCImpl(wxDC* owner, int);
wxGTKCairoDCImpl(wxDC* owner, double scaleFactor);
wxGTKCairoDCImpl(wxDC* owner, wxWindow* window);
virtual void DoDrawBitmap(const wxBitmap& bitmap, int x, int y, bool useMask) wxOVERRIDE;
@@ -103,7 +104,7 @@ class WXDLLIMPEXP_CORE wxGTKCairoDC: public wxDC
{
typedef wxDC base_type;
public:
wxGTKCairoDC(cairo_t* cr);
wxGTKCairoDC(cairo_t* cr, wxWindow* window);
wxDECLARE_NO_COPY_CLASS(wxGTKCairoDC);
};

View File

@@ -2492,17 +2492,19 @@ wxDC *wxDataViewCustomRenderer::GetDC()
{
if (m_dc == NULL)
{
wxDataViewCtrl* ctrl = NULL;
wxDataViewColumn* column = GetOwner();
if (column)
ctrl = column->GetOwner();
#ifdef __WXGTK3__
wxASSERT(m_renderParams);
cairo_t* cr = m_renderParams->cr;
wxASSERT(cr && cairo_status(cr) == 0);
m_dc = new wxGTKCairoDC(cr);
m_dc = new wxGTKCairoDC(cr, ctrl);
#else
if (GetOwner() == NULL)
if (ctrl == NULL)
return NULL;
if (GetOwner()->GetOwner() == NULL)
return NULL;
m_dc = new wxDataViewCtrlDC( GetOwner()->GetOwner() );
m_dc = new wxDataViewCtrlDC(ctrl);
#endif
}

View File

@@ -34,6 +34,14 @@ wxGTKCairoDCImpl::wxGTKCairoDCImpl(wxDC* owner, int)
m_height = 0;
}
wxGTKCairoDCImpl::wxGTKCairoDCImpl(wxDC* owner, double scaleFactor)
: base_type(owner, 0)
{
m_width = 0;
m_height = 0;
m_contentScaleFactor = scaleFactor;
}
wxGTKCairoDCImpl::wxGTKCairoDCImpl(wxDC* owner, wxWindow* window)
: base_type(owner, 0)
{
@@ -43,6 +51,7 @@ wxGTKCairoDCImpl::wxGTKCairoDCImpl(wxDC* owner, wxWindow* window)
m_textBackgroundColour = window->GetBackgroundColour();
m_width = 0;
m_height = 0;
m_contentScaleFactor = window->GetContentScaleFactor();
}
void wxGTKCairoDCImpl::DoDrawBitmap(const wxBitmap& bitmap, int x, int y, bool useMask)
@@ -345,6 +354,7 @@ void wxMemoryDCImpl::Setup()
{
m_width = int(m_bitmap.GetScaledWidth());
m_height = int(m_bitmap.GetScaledHeight());
m_contentScaleFactor = m_bitmap.GetScaleFactor();
cairo_t* cr = m_bitmap.CairoCreate();
gc = wxGraphicsContext::CreateFromNative(cr);
gc->EnableOffset(true);
@@ -353,8 +363,8 @@ void wxMemoryDCImpl::Setup()
}
//-----------------------------------------------------------------------------
wxGTKCairoDC::wxGTKCairoDC(cairo_t* cr)
: base_type(new wxGTKCairoDCImpl(this, 0))
wxGTKCairoDC::wxGTKCairoDC(cairo_t* cr, wxWindow* window)
: base_type(new wxGTKCairoDCImpl(this, window->GetContentScaleFactor()))
{
cairo_reference(cr);
wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr);

View File

@@ -56,7 +56,7 @@ static gboolean expose_event(GtkWidget* widget, GdkEventExpose* gdk_event, wxMin
gtk_render_frame(sc, cr, 0, 0, win->m_width, win->m_height);
gtk_style_context_restore(sc);
wxGTKCairoDC dc(cr);
wxGTKCairoDC dc(cr, win);
#else
if (gdk_event->count > 0 ||
gdk_event->window != gtk_widget_get_window(widget))

View File

@@ -4222,7 +4222,7 @@ void wxWindowGTK::GTKSendPaintEvents(const GdkRegion* region)
case wxBG_STYLE_ERASE:
{
#ifdef __WXGTK3__
wxGTKCairoDC dc(cr);
wxGTKCairoDC dc(cr, static_cast<wxWindow*>(this));
#else
wxWindowDC dc( (wxWindow*)this );
dc.SetDeviceClippingRegion( m_updateRegion );