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
This commit is contained in:
David Elliott
2005-01-14 14:22:03 +00:00
parent 52f2ad0899
commit 4db3c8ac63
5 changed files with 30 additions and 17 deletions

View File

@@ -12,6 +12,8 @@
#ifndef __WX_COCOA_DC_H__ #ifndef __WX_COCOA_DC_H__
#define __WX_COCOA_DC_H__ #define __WX_COCOA_DC_H__
DECLARE_WXCOCOA_OBJC_CLASS(NSAffineTransform);
class WXDLLEXPORT wxDC; class WXDLLEXPORT wxDC;
WX_DECLARE_LIST(wxDC, wxCocoaDCStack); WX_DECLARE_LIST(wxDC, wxCocoaDCStack);
@@ -38,6 +40,8 @@ public:
static WX_NSTextStorage sm_cocoaNSTextStorage; static WX_NSTextStorage sm_cocoaNSTextStorage;
static WX_NSLayoutManager sm_cocoaNSLayoutManager; static WX_NSLayoutManager sm_cocoaNSLayoutManager;
static WX_NSTextContainer sm_cocoaNSTextContainer; 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: protected:
// DC stack // DC stack
static wxCocoaDCStack sm_cocoaDCStack; static wxCocoaDCStack sm_cocoaDCStack;
@@ -54,8 +58,7 @@ protected:
void CocoaUnwindStackAndLoseFocus(); void CocoaUnwindStackAndLoseFocus();
// DC flipping/transformation // DC flipping/transformation
void CocoaApplyTransformations(); void CocoaApplyTransformations();
float m_cocoaHeight; WX_NSAffineTransform m_cocoaWxToBoundsTransform;
bool m_cocoaFlipped;
// 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,

View File

@@ -140,8 +140,7 @@ bool wxDC::CocoaUnwindStackAndTakeFocus()
wxDC::wxDC(void) wxDC::wxDC(void)
{ {
m_cocoaFlipped = false; m_cocoaWxToBoundsTransform;
m_cocoaHeight = 0.0;
m_pen = *wxBLACK_PEN; m_pen = *wxBLACK_PEN;
} }
@@ -159,26 +158,31 @@ bool wxDC::CocoaUnlockFocus()
return false; 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 // This transform flips the graphics since wxDC uses top-left origin
if(!m_cocoaFlipped) if(!isFlipped)
{ {
// The transform is auto released // The transform is auto released
NSAffineTransform *transform = [NSAffineTransform transform]; transform = [NSAffineTransform transform];
/* x' = 1x + 0y + 0 /* x' = 1x + 0y + 0
y' = 0x + -1y + window's height y' = 0x + -1y + window's height
*/ */
NSAffineTransformStruct matrix = { NSAffineTransformStruct matrix = {
1, 0 1, 0
, 0, -1 , 0, -1
, 0, m_cocoaHeight , 0, height
}; };
[transform setTransformStruct: matrix]; [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) void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)

View File

@@ -51,8 +51,6 @@ bool wxWindowDC::CocoaLockFocusOnNSView(WX_NSView nsview)
if([nsview lockFocusIfCanDraw]) if([nsview lockFocusIfCanDraw])
{ {
sm_cocoaDCStack.Insert(this); sm_cocoaDCStack.Insert(this);
m_cocoaFlipped = [nsview isFlipped];
m_cocoaHeight = [nsview bounds].size.height;
CocoaApplyTransformations(); CocoaApplyTransformations();
m_lockedNSView = nsview; m_lockedNSView = nsview;
return true; return true;
@@ -72,6 +70,7 @@ bool wxWindowDC::CocoaUnlockFocusOnNSView()
bool wxWindowDC::CocoaLockFocus() bool wxWindowDC::CocoaLockFocus()
{ {
wxLogTrace(wxTRACE_COCOA,wxT("Locking focus on wxWindowDC=%p, NSView=%p"),this, m_window->GetNonClientNSView()); 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()); return CocoaLockFocusOnNSView(m_window->GetNonClientNSView());
} }
@@ -116,6 +115,7 @@ wxClientDC::~wxClientDC(void)
bool wxClientDC::CocoaLockFocus() bool wxClientDC::CocoaLockFocus()
{ {
wxLogTrace(wxTRACE_COCOA,wxT("Locking focus on wxClientDC=%p, NSView=%p"),this, m_window->GetNSView()); 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()); 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")); 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); sm_cocoaDCStack.Insert(this);
m_lockedNSView = window->GetNSView(); m_lockedNSView = window->GetNSView();
m_cocoaFlipped = [window->GetNSView() isFlipped]; m_cocoaWxToBoundsTransform = window->CocoaGetWxToBoundsTransform();
m_cocoaHeight = [window->GetNSView() bounds].size.height;
CocoaApplyTransformations(); CocoaApplyTransformations();
}; };

View File

@@ -53,8 +53,7 @@ bool wxMemoryDC::CocoaLockFocus()
{ {
[m_cocoaNSImage lockFocus]; [m_cocoaNSImage lockFocus];
sm_cocoaDCStack.Insert(this); sm_cocoaDCStack.Insert(this);
m_cocoaFlipped = [m_cocoaNSImage isFlipped]; m_cocoaWxToBoundsTransform = CocoaGetWxToBoundsTransform([m_cocoaNSImage isFlipped], [m_cocoaNSImage size].height);
m_cocoaHeight = [m_cocoaNSImage size].height;
CocoaApplyTransformations(); CocoaApplyTransformations();
return true; return true;
} }

View File

@@ -13,6 +13,7 @@
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/log.h" #include "wx/log.h"
#include "wx/window.h" #include "wx/window.h"
#include "wx/dc.h"
#endif //WX_PRECOMP #endif //WX_PRECOMP
#include "wx/tooltip.h" #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) bool wxWindowCocoa::Cocoa_drawRect(const NSRect &rect)
{ {
wxLogTrace(wxTRACE_COCOA,wxT("Cocoa_drawRect")); wxLogTrace(wxTRACE_COCOA,wxT("Cocoa_drawRect"));