]>
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
112 // It gives an Assert, Robert Roebling
121 void wxDC::SetMapMode( int mode
)
126 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
129 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
132 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
135 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
139 SetLogicalScale( 1.0, 1.0 );
142 /* we don't do this mega optimisation
143 if (mode != wxMM_TEXT)
145 m_needComputeScaleX = TRUE;
146 m_needComputeScaleY = TRUE;
151 void wxDC::SetUserScale( double x
, double y
)
153 // allow negative ? -> no
156 ComputeScaleAndOrigin();
159 void wxDC::SetLogicalScale( double x
, double y
)
164 ComputeScaleAndOrigin();
167 void wxDC::SetLogicalOrigin( long x
, long y
)
169 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
170 m_logicalOriginY
= y
* m_signY
;
171 ComputeScaleAndOrigin();
174 void wxDC::SetDeviceOrigin( long x
, long y
)
176 // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there
179 ComputeScaleAndOrigin();
182 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
184 // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there
185 m_signX
= (xLeftRight
? 1 : -1);
186 m_signY
= (yBottomUp
? -1 : 1);
187 ComputeScaleAndOrigin();
190 // ---------------------------------------------------------------------------
191 // coordinates transformations
192 // ---------------------------------------------------------------------------
194 long wxDCBase::DeviceToLogicalX(long x
) const
196 return ((wxDC
*)this)->XDEV2LOG(x
);
199 long wxDCBase::DeviceToLogicalY(long y
) const
201 return ((wxDC
*)this)->YDEV2LOG(y
);
204 long wxDCBase::DeviceToLogicalXRel(long x
) const
206 return ((wxDC
*)this)->XDEV2LOGREL(x
);
209 long wxDCBase::DeviceToLogicalYRel(long y
) const
211 return ((wxDC
*)this)->YDEV2LOGREL(y
);
214 long wxDCBase::LogicalToDeviceX(long x
) const
216 return ((wxDC
*)this)->XLOG2DEV(x
);
219 long wxDCBase::LogicalToDeviceY(long y
) const
221 return ((wxDC
*)this)->YLOG2DEV(y
);
224 long wxDCBase::LogicalToDeviceXRel(long x
) const
226 return ((wxDC
*)this)->XLOG2DEVREL(x
);
229 long wxDCBase::LogicalToDeviceYRel(long y
) const
231 return ((wxDC
*)this)->YLOG2DEVREL(y
);