Moved Clear() implementation into wxDC using a new virtual CocoaGetBounds()
to determine the rect to clear. Also added CocoaUnapplyTransformations() to bring the coordinate system back into Cocoa coordinates for those cases such as Clear() where it makes more sense. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31440 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -58,7 +58,12 @@ protected:
|
|||||||
void CocoaUnwindStackAndLoseFocus();
|
void CocoaUnwindStackAndLoseFocus();
|
||||||
// DC flipping/transformation
|
// DC flipping/transformation
|
||||||
void CocoaApplyTransformations();
|
void CocoaApplyTransformations();
|
||||||
|
void CocoaUnapplyTransformations();
|
||||||
WX_NSAffineTransform m_cocoaWxToBoundsTransform;
|
WX_NSAffineTransform m_cocoaWxToBoundsTransform;
|
||||||
|
// Get bounds rect (for Clear())
|
||||||
|
// note: we use void * to mean NSRect * so that we can avoid
|
||||||
|
// putting NSRect in the headers.
|
||||||
|
virtual bool CocoaGetBounds(void *rectData);
|
||||||
// Blitting
|
// Blitting
|
||||||
virtual bool CocoaDoBlitOnFocusedDC(wxCoord xdest, wxCoord ydest,
|
virtual bool CocoaDoBlitOnFocusedDC(wxCoord xdest, wxCoord ydest,
|
||||||
wxCoord width, wxCoord height, wxCoord xsrc, wxCoord ysrc,
|
wxCoord width, wxCoord height, wxCoord xsrc, wxCoord ysrc,
|
||||||
|
@@ -27,8 +27,6 @@ public:
|
|||||||
wxWindowDC(wxWindow *win);
|
wxWindowDC(wxWindow *win);
|
||||||
~wxWindowDC(void);
|
~wxWindowDC(void);
|
||||||
|
|
||||||
// NSView specific functions
|
|
||||||
virtual void Clear();
|
|
||||||
protected:
|
protected:
|
||||||
wxWindow *m_window;
|
wxWindow *m_window;
|
||||||
WX_NSView m_lockedNSView;
|
WX_NSView m_lockedNSView;
|
||||||
@@ -37,6 +35,7 @@ protected:
|
|||||||
virtual bool CocoaUnlockFocus();
|
virtual bool CocoaUnlockFocus();
|
||||||
bool CocoaLockFocusOnNSView(WX_NSView nsview);
|
bool CocoaLockFocusOnNSView(WX_NSView nsview);
|
||||||
bool CocoaUnlockFocusOnNSView();
|
bool CocoaUnlockFocusOnNSView();
|
||||||
|
virtual bool CocoaGetBounds(void *rectData);
|
||||||
};
|
};
|
||||||
|
|
||||||
class wxClientDC: public wxWindowDC
|
class wxClientDC: public wxWindowDC
|
||||||
|
@@ -23,14 +23,13 @@ public:
|
|||||||
~wxMemoryDC(void);
|
~wxMemoryDC(void);
|
||||||
virtual void SelectObject(const wxBitmap& bitmap);
|
virtual void SelectObject(const wxBitmap& bitmap);
|
||||||
virtual void DoGetSize(int *width, int *height) const;
|
virtual void DoGetSize(int *width, int *height) const;
|
||||||
|
|
||||||
virtual void Clear();
|
|
||||||
protected:
|
protected:
|
||||||
wxBitmap m_selectedBitmap;
|
wxBitmap m_selectedBitmap;
|
||||||
WX_NSImage m_cocoaNSImage;
|
WX_NSImage m_cocoaNSImage;
|
||||||
// DC stack
|
// DC stack
|
||||||
virtual bool CocoaLockFocus();
|
virtual bool CocoaLockFocus();
|
||||||
virtual bool CocoaUnlockFocus();
|
virtual bool CocoaUnlockFocus();
|
||||||
|
virtual bool CocoaGetBounds(void *rectData);
|
||||||
// Blitting
|
// Blitting
|
||||||
virtual bool CocoaDoBlitOnFocusedDC(wxCoord xdest, wxCoord ydest,
|
virtual bool CocoaDoBlitOnFocusedDC(wxCoord xdest, wxCoord ydest,
|
||||||
wxCoord width, wxCoord height, wxCoord xsrc, wxCoord ysrc,
|
wxCoord width, wxCoord height, wxCoord xsrc, wxCoord ysrc,
|
||||||
|
@@ -185,6 +185,23 @@ void wxDC::CocoaApplyTransformations()
|
|||||||
// TODO: Apply device/logical/user position/scaling transformations
|
// TODO: Apply device/logical/user position/scaling transformations
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxDC::CocoaUnapplyTransformations()
|
||||||
|
{
|
||||||
|
// NOTE: You *must* call this with focus held.
|
||||||
|
// Undo all transforms so we're back in true Cocoa coords with
|
||||||
|
// no scaling or flipping.
|
||||||
|
NSAffineTransform *invertTransform;
|
||||||
|
invertTransform = [m_cocoaWxToBoundsTransform copy];
|
||||||
|
[invertTransform invert];
|
||||||
|
[invertTransform concat];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxDC::CocoaGetBounds(void *rectData)
|
||||||
|
{
|
||||||
|
// We don't know what we are so we can't return anything.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
|
void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
|
||||||
{
|
{
|
||||||
wxAutoNSAutoreleasePool pool;
|
wxAutoNSAutoreleasePool pool;
|
||||||
@@ -553,6 +570,22 @@ void wxDC::SetTextBackground( const wxColour &col )
|
|||||||
|
|
||||||
void wxDC::Clear()
|
void wxDC::Clear()
|
||||||
{
|
{
|
||||||
|
if(!CocoaTakeFocus()) return;
|
||||||
|
|
||||||
|
NSRect boundsRect;
|
||||||
|
if(!CocoaGetBounds(&boundsRect)) return;
|
||||||
|
|
||||||
|
NSGraphicsContext *context = [NSGraphicsContext currentContext];
|
||||||
|
[context saveGraphicsState];
|
||||||
|
|
||||||
|
// Undo all transforms so when we draw our bounds rect we
|
||||||
|
// really overwrite our bounds rect.
|
||||||
|
CocoaUnapplyTransformations();
|
||||||
|
|
||||||
|
[m_backgroundBrush.GetNSColor() set];
|
||||||
|
[NSBezierPath fillRect:boundsRect];
|
||||||
|
|
||||||
|
[context restoreGraphicsState];
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxDC::SetBackground(const wxBrush& brush)
|
void wxDC::SetBackground(const wxBrush& brush)
|
||||||
|
@@ -80,17 +80,15 @@ bool wxWindowDC::CocoaUnlockFocus()
|
|||||||
return CocoaUnlockFocusOnNSView();
|
return CocoaUnlockFocusOnNSView();
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxWindowDC::Clear()
|
bool wxWindowDC::CocoaGetBounds(void *rectData)
|
||||||
{
|
{
|
||||||
if(!CocoaTakeFocus()) return;
|
if(!rectData)
|
||||||
|
return false;
|
||||||
NSGraphicsContext *context = [NSGraphicsContext currentContext];
|
if(!m_lockedNSView)
|
||||||
[context saveGraphicsState];
|
return false;
|
||||||
|
NSRect *pRect = (NSRect*)rectData;
|
||||||
[m_backgroundBrush.GetNSColor() set];
|
*pRect = [m_lockedNSView bounds];
|
||||||
[NSBezierPath fillRect:[m_lockedNSView bounds]];
|
return true;
|
||||||
|
|
||||||
[context restoreGraphicsState];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -151,20 +151,16 @@ bool wxMemoryDC::CocoaDoBlitOnFocusedDC(wxCoord xdest, wxCoord ydest,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxMemoryDC::Clear()
|
bool wxMemoryDC::CocoaGetBounds(void *rectData)
|
||||||
{
|
{
|
||||||
if(!CocoaTakeFocus()) return;
|
if(!rectData)
|
||||||
|
return false;
|
||||||
NSGraphicsContext *context = [NSGraphicsContext currentContext];
|
if(!m_cocoaNSImage)
|
||||||
[context saveGraphicsState];
|
return false;
|
||||||
|
NSRect *pRect = (NSRect*)rectData;
|
||||||
[m_backgroundBrush.GetNSColor() set];
|
pRect->origin.x = 0.0;
|
||||||
NSRect rect;
|
pRect->origin.y = 0.0;
|
||||||
rect.origin.x = 0;
|
pRect->size = [m_cocoaNSImage size];
|
||||||
rect.origin.y = 0;
|
return true;
|
||||||
rect.size = [m_cocoaNSImage size];
|
|
||||||
[NSBezierPath fillRect:rect];
|
|
||||||
|
|
||||||
[context restoreGraphicsState];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user