]>
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 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
18 //-----------------------------------------------------------------------------
20 //-----------------------------------------------------------------------------
22 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxDCBase
)
28 m_mm_to_pix_x
= (double)wxGetDisplaySize().GetWidth() /
29 (double)wxGetDisplaySizeMM().GetWidth();
30 m_mm_to_pix_y
= (double)wxGetDisplaySize().GetHeight() /
31 (double)wxGetDisplaySizeMM().GetHeight();
33 m_needComputeScaleX
= FALSE
; /* not used yet */
34 m_needComputeScaleY
= FALSE
; /* not used yet */
36 m_logicalFunction
= wxCOPY
;
39 m_font
= *wxNORMAL_FONT
;
40 m_brush
= *wxWHITE_BRUSH
;
43 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
49 m_clipY2
= y
+ height
;
52 // ---------------------------------------------------------------------------
53 // get DC capabilities
54 // ---------------------------------------------------------------------------
56 void wxDC::DoGetSizeMM( int* width
, int* height
) const
61 if (width
) *width
= int( double(w
) / (m_userScaleX
*m_mm_to_pix_x
) );
62 if (height
) *height
= int( double(h
) / (m_userScaleY
*m_mm_to_pix_y
) );
65 // Resolution in pixels per logical inch
66 wxSize
wxDC::GetPPI() const
68 // TODO (should probably be pure virtual)
72 // ---------------------------------------------------------------------------
73 // set various DC parameters
74 // ---------------------------------------------------------------------------
76 wxCoord
wxDC::DeviceToLogicalX(wxCoord x
) const
78 return wxRound((x
- m_deviceOriginX
) / m_scaleX
) * m_signX
+ m_logicalOriginX
;
81 wxCoord
wxDC::DeviceToLogicalY(wxCoord y
) const
83 return wxRound((y
- m_deviceOriginY
) / m_scaleY
) * m_signY
+ m_logicalOriginY
;
86 wxCoord
wxDC::DeviceToLogicalXRel(wxCoord x
) const
88 return wxRound(x
/ m_scaleX
);
91 wxCoord
wxDC::DeviceToLogicalYRel(wxCoord y
) const
93 return wxRound(y
/ m_scaleY
);
96 wxCoord
wxDC::LogicalToDeviceX(wxCoord x
) const
98 return wxRound((x
- m_logicalOriginX
) * m_scaleX
) * m_signX
+ m_deviceOriginX
;
101 wxCoord
wxDC::LogicalToDeviceY(wxCoord y
) const
103 return wxRound((y
- m_logicalOriginY
) * m_scaleY
) * m_signY
+ m_deviceOriginY
;
106 wxCoord
wxDC::LogicalToDeviceXRel(wxCoord x
) const
108 return wxRound(x
* m_scaleX
);
111 wxCoord
wxDC::LogicalToDeviceYRel(wxCoord y
) const
113 return wxRound(y
* m_scaleY
);
116 void wxDC::ComputeScaleAndOrigin()
118 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
119 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
122 void wxDC::SetMapMode( int mode
)
127 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
130 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
133 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
136 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
140 SetLogicalScale( 1.0, 1.0 );
143 m_mappingMode
= mode
;
145 /* we don't do this mega optimisation
146 if (mode != wxMM_TEXT)
148 m_needComputeScaleX = TRUE;
149 m_needComputeScaleY = TRUE;
154 void wxDC::SetUserScale( double x
, double y
)
156 // allow negative ? -> no
159 ComputeScaleAndOrigin();
162 void wxDC::SetLogicalScale( double x
, double y
)
167 ComputeScaleAndOrigin();
170 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
172 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
173 m_logicalOriginY
= y
* m_signY
;
174 ComputeScaleAndOrigin();
177 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
179 // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there
182 ComputeScaleAndOrigin();
185 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
187 // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there
188 m_signX
= (xLeftRight
? 1 : -1);
189 m_signY
= (yBottomUp
? -1 : 1);
190 ComputeScaleAndOrigin();
193 // ---------------------------------------------------------------------------
194 // coordinates transformations
195 // ---------------------------------------------------------------------------
197 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
199 return ((wxDC
*)this)->XDEV2LOG(x
);
202 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
204 return ((wxDC
*)this)->YDEV2LOG(y
);
207 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
209 return ((wxDC
*)this)->XDEV2LOGREL(x
);
212 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
214 return ((wxDC
*)this)->YDEV2LOGREL(y
);
217 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
219 return ((wxDC
*)this)->XLOG2DEV(x
);
222 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
224 return ((wxDC
*)this)->YLOG2DEV(y
);
227 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
229 return ((wxDC
*)this)->XLOG2DEVREL(x
);
232 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
234 return ((wxDC
*)this)->YLOG2DEVREL(y
);