]>
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
= *wxTRANSPARENT_BRUSH
;
54 void wxDC::DoSetClippingRegion( long x
, long y
, long width
, long 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 /* CMB: copy scale to see if it changes */
101 double origScaleX
= m_scaleX
;
102 double origScaleY
= m_scaleY
;
104 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
105 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
107 /* CMB: if scale has changed call SetPen to recalulate the line width */
108 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
110 /* this is a bit artificial, but we need to force wxDC to think
111 the pen has changed */
118 void wxDC::SetMapMode( int mode
)
123 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
126 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
129 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
132 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
136 SetLogicalScale( 1.0, 1.0 );
139 m_mappingMode
= mode
;
141 /* we don't do this mega optimisation
142 if (mode != wxMM_TEXT)
144 m_needComputeScaleX = TRUE;
145 m_needComputeScaleY = TRUE;
150 void wxDC::SetUserScale( double x
, double y
)
152 // allow negative ? -> no
155 ComputeScaleAndOrigin();
158 void wxDC::SetLogicalScale( double x
, double y
)
163 ComputeScaleAndOrigin();
166 void wxDC::SetLogicalOrigin( long x
, long y
)
168 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
169 m_logicalOriginY
= y
* m_signY
;
170 ComputeScaleAndOrigin();
173 void wxDC::SetDeviceOrigin( long x
, long y
)
175 // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there
178 ComputeScaleAndOrigin();
181 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
183 // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there
184 m_signX
= (xLeftRight
? 1 : -1);
185 m_signY
= (yBottomUp
? -1 : 1);
186 ComputeScaleAndOrigin();
189 // ---------------------------------------------------------------------------
190 // coordinates transformations
191 // ---------------------------------------------------------------------------
193 long wxDCBase::DeviceToLogicalX(long x
) const
195 return ((wxDC
*)this)->XDEV2LOG(x
);
198 long wxDCBase::DeviceToLogicalY(long y
) const
200 return ((wxDC
*)this)->YDEV2LOG(y
);
203 long wxDCBase::DeviceToLogicalXRel(long x
) const
205 return ((wxDC
*)this)->XDEV2LOGREL(x
);
208 long wxDCBase::DeviceToLogicalYRel(long y
) const
210 return ((wxDC
*)this)->YDEV2LOGREL(y
);
213 long wxDCBase::LogicalToDeviceX(long x
) const
215 return ((wxDC
*)this)->XLOG2DEV(x
);
218 long wxDCBase::LogicalToDeviceY(long y
) const
220 return ((wxDC
*)this)->YLOG2DEV(y
);
223 long wxDCBase::LogicalToDeviceXRel(long x
) const
225 return ((wxDC
*)this)->XLOG2DEVREL(x
);
228 long wxDCBase::LogicalToDeviceYRel(long y
) const
230 return ((wxDC
*)this)->YLOG2DEVREL(y
);