From 4db3c8ac631546f9b695e7590eaa4cb2805a1145 Mon Sep 17 00:00:00 2001 From: David Elliott Date: Fri, 14 Jan 2005 14:22:03 +0000 Subject: [PATCH] Separate NSAffineTransform creation out of wxDC::CocoaApplyTransform into static wxDC::CocoaGetWxToBoundsTransform. Create the transform and store it as a member variable in wxDC when focus is locked on the DC. For wxClientDC and wxPaintDC call a new wxWindow::CocoaGetWxToBoundsTransform which will eventually handle scrolling. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31360 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/cocoa/dc.h | 7 +++++-- src/cocoa/dc.mm | 22 +++++++++++++--------- src/cocoa/dcclient.mm | 7 +++---- src/cocoa/dcmemory.mm | 3 +-- src/cocoa/window.mm | 8 ++++++++ 5 files changed, 30 insertions(+), 17 deletions(-) diff --git a/include/wx/cocoa/dc.h b/include/wx/cocoa/dc.h index ccf45da798..ed39d574e9 100644 --- a/include/wx/cocoa/dc.h +++ b/include/wx/cocoa/dc.h @@ -12,6 +12,8 @@ #ifndef __WX_COCOA_DC_H__ #define __WX_COCOA_DC_H__ +DECLARE_WXCOCOA_OBJC_CLASS(NSAffineTransform); + class WXDLLEXPORT wxDC; WX_DECLARE_LIST(wxDC, wxCocoaDCStack); @@ -38,6 +40,8 @@ public: static WX_NSTextStorage sm_cocoaNSTextStorage; static WX_NSLayoutManager sm_cocoaNSLayoutManager; static WX_NSTextContainer sm_cocoaNSTextContainer; + // Create a simple Wx to Bounds transform (just flip the coordinate system) + static WX_NSAffineTransform CocoaGetWxToBoundsTransform(bool isFlipped, float height); protected: // DC stack static wxCocoaDCStack sm_cocoaDCStack; @@ -54,8 +58,7 @@ protected: void CocoaUnwindStackAndLoseFocus(); // DC flipping/transformation void CocoaApplyTransformations(); - float m_cocoaHeight; - bool m_cocoaFlipped; + WX_NSAffineTransform m_cocoaWxToBoundsTransform; // Blitting virtual bool CocoaDoBlitOnFocusedDC(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, wxCoord xsrc, wxCoord ysrc, diff --git a/src/cocoa/dc.mm b/src/cocoa/dc.mm index 66702e5abc..4b42b2be3a 100644 --- a/src/cocoa/dc.mm +++ b/src/cocoa/dc.mm @@ -140,8 +140,7 @@ bool wxDC::CocoaUnwindStackAndTakeFocus() wxDC::wxDC(void) { - m_cocoaFlipped = false; - m_cocoaHeight = 0.0; + m_cocoaWxToBoundsTransform; m_pen = *wxBLACK_PEN; } @@ -159,26 +158,31 @@ bool wxDC::CocoaUnlockFocus() return false; } -void wxDC::CocoaApplyTransformations() +/*static*/ WX_NSAffineTransform wxDC::CocoaGetWxToBoundsTransform(bool isFlipped, float height) { + NSAffineTransform *transform = nil; // This transform flips the graphics since wxDC uses top-left origin - if(!m_cocoaFlipped) + if(!isFlipped) { // The transform is auto released - NSAffineTransform *transform = [NSAffineTransform transform]; + transform = [NSAffineTransform transform]; /* x' = 1x + 0y + 0 y' = 0x + -1y + window's height */ NSAffineTransformStruct matrix = { 1, 0 , 0, -1 - , 0, m_cocoaHeight + , 0, height }; [transform setTransformStruct: matrix]; - // Apply the transform - [transform concat]; } - // TODO: Apply scaling transformation + return transform; +} + +void wxDC::CocoaApplyTransformations() +{ + [m_cocoaWxToBoundsTransform concat]; + // TODO: Apply device/logical/user position/scaling transformations } void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) diff --git a/src/cocoa/dcclient.mm b/src/cocoa/dcclient.mm index cbeed000b5..bcf82d7aab 100644 --- a/src/cocoa/dcclient.mm +++ b/src/cocoa/dcclient.mm @@ -51,8 +51,6 @@ bool wxWindowDC::CocoaLockFocusOnNSView(WX_NSView nsview) if([nsview lockFocusIfCanDraw]) { sm_cocoaDCStack.Insert(this); - m_cocoaFlipped = [nsview isFlipped]; - m_cocoaHeight = [nsview bounds].size.height; CocoaApplyTransformations(); m_lockedNSView = nsview; return true; @@ -72,6 +70,7 @@ bool wxWindowDC::CocoaUnlockFocusOnNSView() bool wxWindowDC::CocoaLockFocus() { wxLogTrace(wxTRACE_COCOA,wxT("Locking focus on wxWindowDC=%p, NSView=%p"),this, m_window->GetNonClientNSView()); + m_cocoaWxToBoundsTransform = CocoaGetWxToBoundsTransform([m_window->GetNonClientNSView() isFlipped], [m_window->GetNonClientNSView() bounds].size.height); return CocoaLockFocusOnNSView(m_window->GetNonClientNSView()); } @@ -116,6 +115,7 @@ wxClientDC::~wxClientDC(void) bool wxClientDC::CocoaLockFocus() { wxLogTrace(wxTRACE_COCOA,wxT("Locking focus on wxClientDC=%p, NSView=%p"),this, m_window->GetNSView()); + m_cocoaWxToBoundsTransform = m_window->CocoaGetWxToBoundsTransform(); return CocoaLockFocusOnNSView(m_window->GetNSView()); } @@ -140,8 +140,7 @@ wxPaintDC::wxPaintDC( wxWindow *window ) wxASSERT_MSG([NSView focusView]==window->GetNSView(), wxT("PaintDC's NSView does not have focus. Please use wxPaintDC only as the first DC created in a paint handler")); sm_cocoaDCStack.Insert(this); m_lockedNSView = window->GetNSView(); - m_cocoaFlipped = [window->GetNSView() isFlipped]; - m_cocoaHeight = [window->GetNSView() bounds].size.height; + m_cocoaWxToBoundsTransform = window->CocoaGetWxToBoundsTransform(); CocoaApplyTransformations(); }; diff --git a/src/cocoa/dcmemory.mm b/src/cocoa/dcmemory.mm index ff5882d995..f3f2d3e2d0 100644 --- a/src/cocoa/dcmemory.mm +++ b/src/cocoa/dcmemory.mm @@ -53,8 +53,7 @@ bool wxMemoryDC::CocoaLockFocus() { [m_cocoaNSImage lockFocus]; sm_cocoaDCStack.Insert(this); - m_cocoaFlipped = [m_cocoaNSImage isFlipped]; - m_cocoaHeight = [m_cocoaNSImage size].height; + m_cocoaWxToBoundsTransform = CocoaGetWxToBoundsTransform([m_cocoaNSImage isFlipped], [m_cocoaNSImage size].height); CocoaApplyTransformations(); return true; } diff --git a/src/cocoa/window.mm b/src/cocoa/window.mm index 4f9af646e0..de7edc583b 100644 --- a/src/cocoa/window.mm +++ b/src/cocoa/window.mm @@ -13,6 +13,7 @@ #ifndef WX_PRECOMP #include "wx/log.h" #include "wx/window.h" + #include "wx/dc.h" #endif //WX_PRECOMP #include "wx/tooltip.h" @@ -400,6 +401,13 @@ NSRect wxWindowCocoa::CocoaTransformWxToBounds(NSRect rectWx) ); } +WX_NSAffineTransform wxWindowCocoa::CocoaGetWxToBoundsTransform() +{ + // TODO: Handle scrolling offset + NSAffineTransform *transform = wxDC::CocoaGetWxToBoundsTransform([GetNSView() isFlipped], [GetNSView() bounds].size.height); + return transform; +} + bool wxWindowCocoa::Cocoa_drawRect(const NSRect &rect) { wxLogTrace(wxTRACE_COCOA,wxT("Cocoa_drawRect"));