]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/dc.cpp
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling, Markus Holzem
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "dc.h"
20 //-----------------------------------------------------------------------------
22 //-----------------------------------------------------------------------------
24 #define mm2inches 0.0393700787402
25 #define inches2mm 25.4
26 #define mm2twips 56.6929133859
27 #define twips2mm 0.0176388888889
28 #define mm2pt 2.83464566929
29 #define pt2mm 0.352777777778
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxDCBase
)
44 m_needComputeScaleX
= FALSE
; /* not used yet */
45 m_needComputeScaleY
= FALSE
; /* not used yet */
47 m_logicalFunction
= wxCOPY
;
50 m_font
= *wxNORMAL_FONT
;
51 m_brush
= *wxWHITE_BRUSH
;
54 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
60 m_clipY2
= y
+ height
;
63 void wxDC::DestroyClippingRegion()
68 // ---------------------------------------------------------------------------
69 // get DC capabilities
70 // ---------------------------------------------------------------------------
72 void wxDC::DoGetSizeMM( int* width
, int* height
) const
77 if (width
) *width
= int( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
78 if (height
) *height
= int( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
81 // Resolution in pixels per logical inch
82 wxSize
wxDC::GetPPI() const
84 // TODO (should probably be pure virtual)
88 // ---------------------------------------------------------------------------
89 // set various DC parameters
90 // ---------------------------------------------------------------------------
92 void wxDC::ComputeScaleAndOrigin()
94 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
95 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
98 void wxDC::SetMapMode( int mode
)
103 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
106 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
109 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
112 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
116 SetLogicalScale( 1.0, 1.0 );
119 m_mappingMode
= mode
;
121 /* we don't do this mega optimisation
122 if (mode != wxMM_TEXT)
124 m_needComputeScaleX = TRUE;
125 m_needComputeScaleY = TRUE;
130 void wxDC::SetUserScale( double x
, double y
)
132 // allow negative ? -> no
135 ComputeScaleAndOrigin();
138 void wxDC::SetLogicalScale( double x
, double y
)
143 ComputeScaleAndOrigin();
146 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
148 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
149 m_logicalOriginY
= y
* m_signY
;
150 ComputeScaleAndOrigin();
153 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
155 // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there
158 ComputeScaleAndOrigin();
161 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
163 // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there
164 m_signX
= (xLeftRight
? 1 : -1);
165 m_signY
= (yBottomUp
? -1 : 1);
166 ComputeScaleAndOrigin();
169 // ---------------------------------------------------------------------------
170 // coordinates transformations
171 // ---------------------------------------------------------------------------
173 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
175 return ((wxDC
*)this)->XDEV2LOG(x
);
178 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
180 return ((wxDC
*)this)->YDEV2LOG(y
);
183 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
185 return ((wxDC
*)this)->XDEV2LOGREL(x
);
188 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
190 return ((wxDC
*)this)->YDEV2LOGREL(y
);
193 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
195 return ((wxDC
*)this)->XLOG2DEV(x
);
198 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
200 return ((wxDC
*)this)->YLOG2DEV(y
);
203 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
205 return ((wxDC
*)this)->XLOG2DEVREL(x
);
208 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
210 return ((wxDC
*)this)->YLOG2DEVREL(y
);