Add wxGTKCairoDCImpl::SetSize() helper
Avoid repeating gdk_window_get_{width,height}() calls in several places.
This commit is contained in:
@@ -35,10 +35,10 @@ public:
|
|||||||
virtual wxSize GetPPI() const wxOVERRIDE;
|
virtual wxSize GetPPI() const wxOVERRIDE;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int m_width, m_height;
|
// Set m_width and m_height from the given (valid) GdkWindow.
|
||||||
|
void InitSize(GdkWindow* window);
|
||||||
|
|
||||||
private:
|
int m_width, m_height;
|
||||||
bool TryGetWindowSize(wxSize& size, wxSize& sizeMM) const;
|
|
||||||
|
|
||||||
wxDECLARE_NO_COPY_CLASS(wxGTKCairoDCImpl);
|
wxDECLARE_NO_COPY_CLASS(wxGTKCairoDCImpl);
|
||||||
};
|
};
|
||||||
|
@@ -55,6 +55,12 @@ wxGTKCairoDCImpl::wxGTKCairoDCImpl(wxDC* owner, wxWindow* window)
|
|||||||
m_contentScaleFactor = window->GetContentScaleFactor();
|
m_contentScaleFactor = window->GetContentScaleFactor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxGTKCairoDCImpl::InitSize(GdkWindow* window)
|
||||||
|
{
|
||||||
|
m_width = gdk_window_get_width(window);
|
||||||
|
m_height = gdk_window_get_height(window);
|
||||||
|
}
|
||||||
|
|
||||||
void wxGTKCairoDCImpl::DoDrawBitmap(const wxBitmap& bitmap, int x, int y, bool useMask)
|
void wxGTKCairoDCImpl::DoDrawBitmap(const wxBitmap& bitmap, int x, int y, bool useMask)
|
||||||
{
|
{
|
||||||
wxCHECK_RET(IsOk(), "invalid DC");
|
wxCHECK_RET(IsOk(), "invalid DC");
|
||||||
@@ -343,9 +349,7 @@ wxPaintDCImpl::wxPaintDCImpl(wxPaintDC* owner, wxWindow* window)
|
|||||||
{
|
{
|
||||||
cairo_t* cr = window->GTKPaintContext();
|
cairo_t* cr = window->GTKPaintContext();
|
||||||
wxCHECK_RET(cr, "using wxPaintDC without being in a native paint event");
|
wxCHECK_RET(cr, "using wxPaintDC without being in a native paint event");
|
||||||
GdkWindow* gdkWindow = gtk_widget_get_window(window->m_wxwindow);
|
InitSize(gtk_widget_get_window(window->m_wxwindow));
|
||||||
m_width = gdk_window_get_width(gdkWindow);
|
|
||||||
m_height = gdk_window_get_height(gdkWindow);
|
|
||||||
wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr);
|
wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr);
|
||||||
gc->EnableOffset(m_contentScaleFactor <= 1);
|
gc->EnableOffset(m_contentScaleFactor <= 1);
|
||||||
SetGraphicsContext(gc);
|
SetGraphicsContext(gc);
|
||||||
@@ -356,8 +360,8 @@ wxScreenDCImpl::wxScreenDCImpl(wxScreenDC* owner)
|
|||||||
: wxGTKCairoDCImpl(owner, 0)
|
: wxGTKCairoDCImpl(owner, 0)
|
||||||
{
|
{
|
||||||
GdkWindow* window = gdk_get_default_root_window();
|
GdkWindow* window = gdk_get_default_root_window();
|
||||||
m_width = gdk_window_get_width(window);
|
InitSize(window);
|
||||||
m_height = gdk_window_get_height(window);
|
|
||||||
cairo_t* cr = gdk_cairo_create(window);
|
cairo_t* cr = gdk_cairo_create(window);
|
||||||
wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr);
|
wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr);
|
||||||
cairo_destroy(cr);
|
cairo_destroy(cr);
|
||||||
|
Reference in New Issue
Block a user