]>
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 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "dc.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
20 #include "wx/dcmemory.h"
23 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
29 #define mm2inches 0.0393700787402
30 #define inches2mm 25.4
31 #define mm2twips 56.6929133859
32 #define twips2mm 0.0176388888889
33 #define mm2pt 2.83464566929
34 #define pt2mm 0.352777777778
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
47 m_backgroundMode
= wxTRANSPARENT
;
49 m_isInteractive
= FALSE
;
52 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
54 wxCHECK_RET( Ok(), "invalid dc" );
55 wxCHECK_RET( icon
.Ok(), "invalid icon" );
57 DoDrawBitmap(icon
, x
, y
, TRUE
);
60 void wxDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
62 wxCHECK_RET( bitmap
.Ok(), "invalid bitmap" );
65 memDC
.SelectObject(bitmap
);
68 // Not sure if we need this. The mask should leave the masked areas as per
69 // the original background of this DC.
72 // There might be transparent areas, so make these the same colour as this
74 memDC
.SetBackground(* GetBackground());
79 Blit(x
, y
, bitmap
.GetWidth(), bitmap
.GetHeight(), &memDC
, 0, 0, wxCOPY
, useMask
);
81 memDC
.SelectObject(wxNullBitmap
);
84 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
90 m_clipY2
= y
+ height
;
93 void wxDC::DoGetSize( int* width
, int* height
) const
96 *width
= m_maxX
- m_minX
;
98 *height
= m_maxY
- m_minY
;
101 void wxDC::DoGetSizeMM( int* width
, int* height
) const
107 *width
= int( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
109 *height
= int( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
112 // Resolution in pixels per logical inch
113 wxSize
wxDC::GetPPI() const
115 // TODO (should probably be pure virtual)
119 void wxDC::SetMapMode( int mode
)
124 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
127 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
130 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
133 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
137 SetLogicalScale( 1.0, 1.0 );
140 if (mode
!= wxMM_TEXT
)
142 m_needComputeScaleX
= TRUE
;
143 m_needComputeScaleY
= TRUE
;
147 void wxDC::SetUserScale( double x
, double y
)
149 // allow negative ? -> no
152 ComputeScaleAndOrigin();
155 void wxDC::SetLogicalScale( double x
, double y
)
160 ComputeScaleAndOrigin();
163 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
165 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
166 m_logicalOriginY
= y
* m_signY
;
167 ComputeScaleAndOrigin();
170 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
172 // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there
175 ComputeScaleAndOrigin();
178 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
180 m_signX
= xLeftRight
? 1 : -1;
181 m_signY
= yBottomUp
? -1 : 1;
182 ComputeScaleAndOrigin();
185 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
187 return ((wxDC
*)this)->XDEV2LOG(x
);
190 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
192 return ((wxDC
*)this)->YDEV2LOG(y
);
195 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
197 return ((wxDC
*)this)->XDEV2LOGREL(x
);
200 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
202 return ((wxDC
*)this)->YDEV2LOGREL(y
);
205 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
207 return ((wxDC
*)this)->XLOG2DEV(x
);
210 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
212 return ((wxDC
*)this)->YLOG2DEV(y
);
215 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
217 return ((wxDC
*)this)->XLOG2DEVREL(x
);
220 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
222 return ((wxDC
*)this)->YLOG2DEVREL(y
);
225 void wxDC::ComputeScaleAndOrigin()
227 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
228 m_scaleY
= m_logicalScaleY
* m_userScaleY
;