]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk1/dc.cpp
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
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
)
41 m_mm_to_pix_x
= (double)wxGetDisplaySize().GetWidth() /
42 (double)wxGetDisplaySizeMM().GetWidth();
43 m_mm_to_pix_y
= (double)wxGetDisplaySize().GetHeight() /
44 (double)wxGetDisplaySizeMM().GetHeight();
46 m_needComputeScaleX
= FALSE
; /* not used yet */
47 m_needComputeScaleY
= FALSE
; /* not used yet */
49 m_logicalFunction
= wxCOPY
;
52 m_font
= *wxNORMAL_FONT
;
53 m_brush
= *wxWHITE_BRUSH
;
56 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
62 m_clipY2
= y
+ height
;
65 void wxDC::DestroyClippingRegion()
70 // ---------------------------------------------------------------------------
71 // get DC capabilities
72 // ---------------------------------------------------------------------------
74 void wxDC::DoGetSizeMM( int* width
, int* height
) const
79 if (width
) *width
= int( double(w
) / (m_userScaleX
*m_mm_to_pix_x
) );
80 if (height
) *height
= int( double(h
) / (m_userScaleY
*m_mm_to_pix_y
) );
83 // Resolution in pixels per logical inch
84 wxSize
wxDC::GetPPI() const
86 // TODO (should probably be pure virtual)
90 // ---------------------------------------------------------------------------
91 // set various DC parameters
92 // ---------------------------------------------------------------------------
94 void wxDC::ComputeScaleAndOrigin()
96 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
97 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
100 void wxDC::SetMapMode( int mode
)
105 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
108 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
111 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
114 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
118 SetLogicalScale( 1.0, 1.0 );
121 m_mappingMode
= mode
;
123 /* we don't do this mega optimisation
124 if (mode != wxMM_TEXT)
126 m_needComputeScaleX = TRUE;
127 m_needComputeScaleY = TRUE;
132 void wxDC::SetUserScale( double x
, double y
)
134 // allow negative ? -> no
137 ComputeScaleAndOrigin();
140 void wxDC::SetLogicalScale( double x
, double y
)
145 ComputeScaleAndOrigin();
148 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
150 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
151 m_logicalOriginY
= y
* m_signY
;
152 ComputeScaleAndOrigin();
155 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
157 // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there
160 ComputeScaleAndOrigin();
163 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
165 // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there
166 m_signX
= (xLeftRight
? 1 : -1);
167 m_signY
= (yBottomUp
? -1 : 1);
168 ComputeScaleAndOrigin();
171 // ---------------------------------------------------------------------------
172 // coordinates transformations
173 // ---------------------------------------------------------------------------
175 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
177 return ((wxDC
*)this)->XDEV2LOG(x
);
180 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
182 return ((wxDC
*)this)->YDEV2LOG(y
);
185 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
187 return ((wxDC
*)this)->XDEV2LOGREL(x
);
190 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
192 return ((wxDC
*)this)->YDEV2LOGREL(y
);
195 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
197 return ((wxDC
*)this)->XLOG2DEV(x
);
200 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
202 return ((wxDC
*)this)->YLOG2DEV(y
);
205 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
207 return ((wxDC
*)this)->XLOG2DEVREL(x
);
210 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
212 return ((wxDC
*)this)->YLOG2DEVREL(y
);