]> git.saurik.com Git - wxWidgets.git/blob - src/osx/core/dcmemory.cpp
support for scaled bitmaps in wxMemoryDC
[wxWidgets.git] / src / osx / core / dcmemory.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/core/dcmemory.cpp
3 // Purpose: wxMemoryDC class
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #include "wx/dcmemory.h"
15 #include "wx/graphics.h"
16 #include "wx/osx/dcmemory.h"
17
18 #include "wx/osx/private.h"
19
20 //-----------------------------------------------------------------------------
21 // wxMemoryDCImpl
22 //-----------------------------------------------------------------------------
23
24 IMPLEMENT_ABSTRACT_CLASS(wxMemoryDCImpl,wxPaintDCImpl)
25
26
27 wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner )
28 : wxPaintDCImpl( owner )
29 {
30 Init();
31 }
32
33 wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner, wxBitmap& bitmap )
34 : wxPaintDCImpl( owner )
35 {
36 Init();
37 DoSelect(bitmap);
38 }
39
40 wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner, wxDC * WXUNUSED(dc) )
41 : wxPaintDCImpl( owner )
42 {
43 Init();
44 }
45
46 void wxMemoryDCImpl::Init()
47 {
48 m_ok = true;
49 SetBackground(*wxWHITE_BRUSH);
50 SetBrush(*wxWHITE_BRUSH);
51 SetPen(*wxBLACK_PEN);
52 SetFont(*wxNORMAL_FONT);
53 m_ok = false;
54 }
55
56 wxMemoryDCImpl::~wxMemoryDCImpl()
57 {
58 if ( m_selected.IsOk() )
59 {
60 m_selected.EndRawAccess() ;
61 wxDELETE(m_graphicContext);
62 }
63 }
64
65 void wxMemoryDCImpl::DoSelect( const wxBitmap& bitmap )
66 {
67 if ( m_selected.IsOk() )
68 {
69 m_selected.EndRawAccess() ;
70 wxDELETE(m_graphicContext);
71 }
72
73 m_selected = bitmap;
74 if (m_selected.IsOk())
75 {
76 if ( m_selected.GetDepth() != 1 )
77 m_selected.UseAlpha() ;
78 m_selected.BeginRawAccess() ;
79 m_width = bitmap.GetScaledWidth();
80 m_height = bitmap.GetScaledHeight();
81 m_contentScaleFactor = bitmap.GetScaleFactor();
82 CGColorSpaceRef genericColorSpace = wxMacGetGenericRGBColorSpace();
83 CGContextRef bmCtx = (CGContextRef) m_selected.GetHBITMAP();
84
85 if ( bmCtx )
86 {
87 CGContextSetFillColorSpace( bmCtx, genericColorSpace );
88 CGContextSetStrokeColorSpace( bmCtx, genericColorSpace );
89 SetGraphicsContext( wxGraphicsContext::CreateFromNative( bmCtx ) );
90 }
91 m_ok = (m_graphicContext != NULL) ;
92 }
93 else
94 {
95 m_ok = false;
96 }
97 }
98
99 void wxMemoryDCImpl::DoGetSize( int *width, int *height ) const
100 {
101 if (m_selected.IsOk())
102 {
103 if (width)
104 (*width) = m_selected.GetScaledWidth();
105 if (height)
106 (*height) = m_selected.GetScaledHeight();
107 }
108 else
109 {
110 if (width)
111 (*width) = 0;
112 if (height)
113 (*height) = 0;
114 }
115 }