#ifndef __WX_COCOA_DC_H__
#define __WX_COCOA_DC_H__
+DECLARE_WXCOCOA_OBJC_CLASS(NSAffineTransform);
+
class WXDLLEXPORT wxDC;
WX_DECLARE_LIST(wxDC, wxCocoaDCStack);
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;
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,
wxDC::wxDC(void)
{
- m_cocoaFlipped = false;
- m_cocoaHeight = 0.0;
+ m_cocoaWxToBoundsTransform;
m_pen = *wxBLACK_PEN;
}
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)
if([nsview lockFocusIfCanDraw])
{
sm_cocoaDCStack.Insert(this);
- m_cocoaFlipped = [nsview isFlipped];
- m_cocoaHeight = [nsview bounds].size.height;
CocoaApplyTransformations();
m_lockedNSView = nsview;
return true;
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());
}
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());
}
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();
};
{
[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;
}
#ifndef WX_PRECOMP
#include "wx/log.h"
#include "wx/window.h"
+ #include "wx/dc.h"
#endif //WX_PRECOMP
#include "wx/tooltip.h"
);
}
+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"));