]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk1/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::DoGetSize( int* width
, int* height
) const
74 if (width
) *width
= m_maxX
-m_minX
;
75 if (height
) *height
= m_maxY
-m_minY
;
78 void wxDC::DoGetSizeMM( int* width
, int* height
) const
83 if (width
) *width
= int( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
84 if (height
) *height
= int( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
87 // Resolution in pixels per logical inch
88 wxSize
wxDC::GetPPI() const
90 // TODO (should probably be pure virtual)
94 // ---------------------------------------------------------------------------
95 // set various DC parameters
96 // ---------------------------------------------------------------------------
98 void wxDC::ComputeScaleAndOrigin()
100 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
101 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
104 void wxDC::SetMapMode( int mode
)
109 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
112 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
115 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
118 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
122 SetLogicalScale( 1.0, 1.0 );
125 m_mappingMode
= mode
;
127 /* we don't do this mega optimisation
128 if (mode != wxMM_TEXT)
130 m_needComputeScaleX = TRUE;
131 m_needComputeScaleY = TRUE;
136 void wxDC::SetUserScale( double x
, double y
)
138 // allow negative ? -> no
141 ComputeScaleAndOrigin();
144 void wxDC::SetLogicalScale( double x
, double y
)
149 ComputeScaleAndOrigin();
152 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
154 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
155 m_logicalOriginY
= y
* m_signY
;
156 ComputeScaleAndOrigin();
159 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
161 // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there
164 ComputeScaleAndOrigin();
167 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
169 // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there
170 m_signX
= (xLeftRight
? 1 : -1);
171 m_signY
= (yBottomUp
? -1 : 1);
172 ComputeScaleAndOrigin();
175 // ---------------------------------------------------------------------------
176 // coordinates transformations
177 // ---------------------------------------------------------------------------
179 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
181 return ((wxDC
*)this)->XDEV2LOG(x
);
184 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
186 return ((wxDC
*)this)->YDEV2LOG(y
);
189 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
191 return ((wxDC
*)this)->XDEV2LOGREL(x
);
194 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
196 return ((wxDC
*)this)->YDEV2LOGREL(y
);
199 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
201 return ((wxDC
*)this)->XLOG2DEV(x
);
204 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
206 return ((wxDC
*)this)->YLOG2DEV(y
);
209 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
211 return ((wxDC
*)this)->XLOG2DEVREL(x
);
214 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
216 return ((wxDC
*)this)->YLOG2DEVREL(y
);