]> git.saurik.com Git - wxWidgets.git/commitdiff
Separate NSAffineTransform creation out of wxDC::CocoaApplyTransform into
authorDavid Elliott <dfe@tgwbd.org>
Fri, 14 Jan 2005 14:22:03 +0000 (14:22 +0000)
committerDavid Elliott <dfe@tgwbd.org>
Fri, 14 Jan 2005 14:22:03 +0000 (14:22 +0000)
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
src/cocoa/dc.mm
src/cocoa/dcclient.mm
src/cocoa/dcmemory.mm
src/cocoa/window.mm

index ccf45da7984895b1e2a532c2f00e3cbd7a7a1517..ed39d574e9ba394cfea941e393fb40cf34d4de4d 100644 (file)
@@ -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,
index 66702e5abc0194c37f90b79b6bfc2281954e4fe5..4b42b2be3adbd623e86fe938424bbf63fa51120a 100644 (file)
@@ -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)
index cbeed000b59117119b2ff935e78ff906af35e614..bcf82d7aab6e5a75b4bf930da8b08d40e0c72865 100644 (file)
@@ -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();
 };
 
index ff5882d9955c878cadb36957a92011cf40c6cf4a..f3f2d3e2d0d23829b8556384762023d9d7282de7 100644 (file)
@@ -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;
     }
index 4f9af646e0aa7bfbdf06bc20516e93b7e6b152b6..de7edc583b0e26b56b78ebaa8466686b4e174b50 100644 (file)
@@ -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"));