]>
git.saurik.com Git - wxWidgets.git/blob - src/motif/dc.cpp
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 // allow negative ? -> no
155 ComputeScaleAndOrigin();
158 void wxDC::SetLogicalScale( double x
, double y
)
163 ComputeScaleAndOrigin();
166 void wxDC::SetLogicalOrigin( long x
, long y
)
168 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
169 m_logicalOriginY
= y
* m_signY
;
170 ComputeScaleAndOrigin();
173 void wxDC::SetDeviceOrigin( long x
, long y
)
175 m_externalDeviceOriginX
= x
;
176 m_externalDeviceOriginY
= y
;
177 ComputeScaleAndOrigin();
180 void wxDC::SetInternalDeviceOrigin( long x
, long y
)
182 m_internalDeviceOriginX
= x
;
183 m_internalDeviceOriginY
= y
;
184 ComputeScaleAndOrigin();
187 void wxDC::GetInternalDeviceOrigin( long *x
, long *y
)
189 if (x
) *x
= m_internalDeviceOriginX
;
190 if (y
) *y
= m_internalDeviceOriginY
;
193 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
195 m_signX
= xLeftRight
? 1 : -1;
196 m_signY
= yBottomUp
? -1 : 1;
197 ComputeScaleAndOrigin();
200 long wxDCBase::DeviceToLogicalX(long x
) const
202 return ((wxDC
*)this)->XDEV2LOG(x
);
205 long wxDCBase::DeviceToLogicalY(long y
) const
207 return ((wxDC
*)this)->YDEV2LOG(y
);
210 long wxDCBase::DeviceToLogicalXRel(long x
) const
212 return ((wxDC
*)this)->XDEV2LOGREL(x
);
215 long wxDCBase::DeviceToLogicalYRel(long y
) const
217 return ((wxDC
*)this)->YDEV2LOGREL(y
);
220 long wxDCBase::LogicalToDeviceX(long x
) const
222 return ((wxDC
*)this)->XLOG2DEV(x
);
225 long wxDCBase::LogicalToDeviceY(long y
) const
227 return ((wxDC
*)this)->YLOG2DEV(y
);
230 long wxDCBase::LogicalToDeviceXRel(long x
) const
232 return ((wxDC
*)this)->XLOG2DEVREL(x
);
235 long wxDCBase::LogicalToDeviceYRel(long y
) const
237 return ((wxDC
*)this)->YLOG2DEVREL(y
);
240 void wxDC::ComputeScaleAndOrigin()
242 // CMB: copy scale to see if it changes
243 double origScaleX
= m_scaleX
;
244 double origScaleY
= m_scaleY
;
246 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
247 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
249 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
250 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
252 // CMB: if scale has changed call SetPen to recalulate the line width
253 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
255 // this is a bit artificial, but we need to force wxDC to think
256 // the pen has changed
257 wxPen
* pen
= & GetPen();