]>
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::DestroyClippingRegion()
98 void wxDC::DoGetSize( int* width
, int* height
) const
101 *width
= m_maxX
- m_minX
;
103 *height
= m_maxY
- m_minY
;
106 void wxDC::DoGetSizeMM( int* width
, int* height
) const
112 *width
= int( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
114 *height
= int( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
117 // Resolution in pixels per logical inch
118 wxSize
wxDC::GetPPI() const
120 // TODO (should probably be pure virtual)
124 void wxDC::SetMapMode( int mode
)
129 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
132 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
135 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
138 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
142 SetLogicalScale( 1.0, 1.0 );
145 if (mode
!= wxMM_TEXT
)
147 m_needComputeScaleX
= TRUE
;
148 m_needComputeScaleY
= TRUE
;
152 void wxDC::SetUserScale( double x
, double y
)
154 // allow negative ? -> no
157 ComputeScaleAndOrigin();
160 void wxDC::SetLogicalScale( double x
, double y
)
165 ComputeScaleAndOrigin();
168 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
170 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
171 m_logicalOriginY
= y
* m_signY
;
172 ComputeScaleAndOrigin();
175 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
177 // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there
180 ComputeScaleAndOrigin();
183 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
185 m_signX
= xLeftRight
? 1 : -1;
186 m_signY
= yBottomUp
? -1 : 1;
187 ComputeScaleAndOrigin();
190 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
192 return ((wxDC
*)this)->XDEV2LOG(x
);
195 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
197 return ((wxDC
*)this)->YDEV2LOG(y
);
200 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
202 return ((wxDC
*)this)->XDEV2LOGREL(x
);
205 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
207 return ((wxDC
*)this)->YDEV2LOGREL(y
);
210 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
212 return ((wxDC
*)this)->XLOG2DEV(x
);
215 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
217 return ((wxDC
*)this)->YLOG2DEV(y
);
220 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
222 return ((wxDC
*)this)->XLOG2DEVREL(x
);
225 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
227 return ((wxDC
*)this)->YLOG2DEVREL(y
);
230 void wxDC::ComputeScaleAndOrigin()
232 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
233 m_scaleY
= m_logicalScaleY
* m_userScaleY
;