]>
git.saurik.com Git - wxWidgets.git/blob - src/motif/dc.cpp
ef06e450a4f95c1c2f4151a728d5d70e16d5972d
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "dc.h"
17 #include "wx/dcmemory.h"
19 #if !USE_SHARED_LIBRARY
20 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
23 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
27 #define mm2inches 0.0393700787402
28 #define inches2mm 25.4
29 #define mm2twips 56.6929133859
30 #define twips2mm 0.0176388888889
31 #define mm2pt 2.83464566929
32 #define pt2mm 0.352777777778
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
45 m_backgroundMode
= wxTRANSPARENT
;
47 m_isInteractive
= FALSE
;
50 void wxDC::DoDrawIcon( const wxIcon
&icon
, long x
, long y
)
52 wxCHECK_RET( Ok(), "invalid dc" );
53 wxCHECK_RET( icon
.Ok(), "invalid icon" );
55 DoDrawBitmap(icon
, x
, y
, TRUE
);
58 void wxDC::DoDrawBitmap( const wxBitmap
& bitmap
, long x
, long y
, bool useMask
)
60 wxCHECK_RET( bitmap
.Ok(), "invalid bitmap" );
63 memDC
.SelectObject(bitmap
);
66 // Not sure if we need this. The mask should leave the masked areas as per
67 // the original background of this DC.
70 // There might be transparent areas, so make these the same colour as this
72 memDC
.SetBackground(* GetBackground());
77 Blit(x
, y
, bitmap
.GetWidth(), bitmap
.GetHeight(), &memDC
, 0, 0, wxCOPY
, useMask
);
79 memDC
.SelectObject(wxNullBitmap
);
82 void wxDC::DoSetClippingRegion( long x
, long y
, long width
, long height
)
88 m_clipY2
= y
+ height
;
91 void wxDC::DestroyClippingRegion()
96 void wxDC::DoGetSize( int* width
, int* height
) const
99 *width
= m_maxX
- m_minX
;
101 *height
= m_maxY
- m_minY
;
104 void wxDC::DoGetSizeMM( int* width
, int* height
) const
110 *width
= int( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
112 *height
= int( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
115 // Resolution in pixels per logical inch
116 wxSize
wxDC::GetPPI() const
118 // TODO (should probably be pure virtual)
122 void wxDC::SetMapMode( int mode
)
127 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
130 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
133 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
136 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
140 SetLogicalScale( 1.0, 1.0 );
143 if (mode
!= wxMM_TEXT
)
145 m_needComputeScaleX
= TRUE
;
146 m_needComputeScaleY
= TRUE
;
150 void wxDC::SetUserScale( double x
, double y
)
152 wxDCBase::SetUserScale(x
, y
);
153 ComputeScaleAndOrigin();
156 void wxDC::SetLogicalScale( double x
, double y
)
158 wxDCBase::SetLogicalScale(x
, y
);
159 ComputeScaleAndOrigin();
162 void wxDC::SetLogicalOrigin( long x
, long y
)
164 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
165 m_logicalOriginY
= y
* m_signY
;
166 ComputeScaleAndOrigin();
169 void wxDC::SetDeviceOrigin( long x
, long y
)
171 m_externalDeviceOriginX
= x
;
172 m_externalDeviceOriginY
= y
;
173 ComputeScaleAndOrigin();
176 void wxDC::SetInternalDeviceOrigin( long x
, long y
)
178 m_internalDeviceOriginX
= x
;
179 m_internalDeviceOriginY
= y
;
180 ComputeScaleAndOrigin();
183 void wxDC::GetInternalDeviceOrigin( long *x
, long *y
)
185 if (x
) *x
= m_internalDeviceOriginX
;
186 if (y
) *y
= m_internalDeviceOriginY
;
189 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
191 m_signX
= xLeftRight
? 1 : -1;
192 m_signY
= yBottomUp
? -1 : 1;
193 ComputeScaleAndOrigin();
196 long wxDCBase::DeviceToLogicalX(long x
) const
198 return ((wxDC
*)this)->XDEV2LOG(x
);
201 long wxDCBase::DeviceToLogicalY(long y
) const
203 return ((wxDC
*)this)->YDEV2LOG(y
);
206 long wxDCBase::DeviceToLogicalXRel(long x
) const
208 return ((wxDC
*)this)->XDEV2LOGREL(x
);
211 long wxDCBase::DeviceToLogicalYRel(long y
) const
213 return ((wxDC
*)this)->YDEV2LOGREL(y
);
216 long wxDCBase::LogicalToDeviceX(long x
) const
218 return ((wxDC
*)this)->XLOG2DEV(x
);
221 long wxDCBase::LogicalToDeviceY(long y
) const
223 return ((wxDC
*)this)->YLOG2DEV(y
);
226 long wxDCBase::LogicalToDeviceXRel(long x
) const
228 return ((wxDC
*)this)->XLOG2DEVREL(x
);
231 long wxDCBase::LogicalToDeviceYRel(long y
) const
233 return ((wxDC
*)this)->YLOG2DEVREL(y
);
236 void wxDC::ComputeScaleAndOrigin()
238 // CMB: copy scale to see if it changes
239 double origScaleX
= m_scaleX
;
240 double origScaleY
= m_scaleY
;
242 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
243 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
245 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
246 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
248 // CMB: if scale has changed call SetPen to recalulate the line width
249 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
251 // this is a bit artificial, but we need to force wxDC to think
252 // the pen has changed
253 wxPen
* pen
= & GetPen();