]>
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"
20 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
22 //-----------------------------------------------------------------------------
24 //-----------------------------------------------------------------------------
26 #define mm2inches 0.0393700787402
27 #define inches2mm 25.4
28 #define mm2twips 56.6929133859
29 #define twips2mm 0.0176388888889
30 #define mm2pt 2.83464566929
31 #define pt2mm 0.352777777778
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
44 m_backgroundMode
= wxTRANSPARENT
;
46 m_isInteractive
= FALSE
;
49 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
51 wxCHECK_RET( Ok(), "invalid dc" );
52 wxCHECK_RET( icon
.Ok(), "invalid icon" );
54 DoDrawBitmap(icon
, x
, y
, TRUE
);
57 void wxDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
59 wxCHECK_RET( bitmap
.Ok(), "invalid bitmap" );
62 memDC
.SelectObject(bitmap
);
65 // Not sure if we need this. The mask should leave the masked areas as per
66 // the original background of this DC.
69 // There might be transparent areas, so make these the same colour as this
71 memDC
.SetBackground(* GetBackground());
76 Blit(x
, y
, bitmap
.GetWidth(), bitmap
.GetHeight(), &memDC
, 0, 0, wxCOPY
, useMask
);
78 memDC
.SelectObject(wxNullBitmap
);
81 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
87 m_clipY2
= y
+ height
;
90 void wxDC::DestroyClippingRegion()
95 void wxDC::DoGetSize( int* width
, int* height
) const
98 *width
= m_maxX
- m_minX
;
100 *height
= m_maxY
- m_minY
;
103 void wxDC::DoGetSizeMM( int* width
, int* height
) const
109 *width
= int( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
111 *height
= int( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
114 // Resolution in pixels per logical inch
115 wxSize
wxDC::GetPPI() const
117 // TODO (should probably be pure virtual)
121 void wxDC::SetMapMode( int mode
)
126 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
129 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
132 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
135 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
139 SetLogicalScale( 1.0, 1.0 );
142 if (mode
!= wxMM_TEXT
)
144 m_needComputeScaleX
= TRUE
;
145 m_needComputeScaleY
= TRUE
;
149 void wxDC::SetUserScale( double x
, double y
)
151 // allow negative ? -> no
154 ComputeScaleAndOrigin();
157 void wxDC::SetLogicalScale( double x
, double y
)
162 ComputeScaleAndOrigin();
165 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
167 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
168 m_logicalOriginY
= y
* m_signY
;
169 ComputeScaleAndOrigin();
172 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
174 // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there
177 ComputeScaleAndOrigin();
180 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
182 m_signX
= xLeftRight
? 1 : -1;
183 m_signY
= yBottomUp
? -1 : 1;
184 ComputeScaleAndOrigin();
187 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
189 return ((wxDC
*)this)->XDEV2LOG(x
);
192 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
194 return ((wxDC
*)this)->YDEV2LOG(y
);
197 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
199 return ((wxDC
*)this)->XDEV2LOGREL(x
);
202 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
204 return ((wxDC
*)this)->YDEV2LOGREL(y
);
207 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
209 return ((wxDC
*)this)->XLOG2DEV(x
);
212 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
214 return ((wxDC
*)this)->YLOG2DEV(y
);
217 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
219 return ((wxDC
*)this)->XLOG2DEVREL(x
);
222 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
224 return ((wxDC
*)this)->YLOG2DEVREL(y
);
227 void wxDC::ComputeScaleAndOrigin()
229 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
230 m_scaleY
= m_logicalScaleY
* m_userScaleY
;