]>
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 /////////////////////////////////////////////////////////////////////////////
11 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
12 #pragma implementation "dc.h"
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
23 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
27 #define mm2inches 0.0393700787402
28 #define inches2mm 25.4
29 #define mm2twips 56.6929133859
30 #define twips2mm 0.0176388888889
31 #define mm2pt 2.83464566929
32 #define pt2mm 0.352777777778
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
38 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxDCBase
)
44 m_mm_to_pix_x
= (double)wxGetDisplaySize().GetWidth() /
45 (double)wxGetDisplaySizeMM().GetWidth();
46 m_mm_to_pix_y
= (double)wxGetDisplaySize().GetHeight() /
47 (double)wxGetDisplaySizeMM().GetHeight();
49 m_needComputeScaleX
= FALSE
; /* not used yet */
50 m_needComputeScaleY
= FALSE
; /* not used yet */
52 m_logicalFunction
= wxCOPY
;
55 m_font
= *wxNORMAL_FONT
;
56 m_brush
= *wxWHITE_BRUSH
;
59 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
65 m_clipY2
= y
+ height
;
68 void wxDC::DestroyClippingRegion()
73 // ---------------------------------------------------------------------------
74 // get DC capabilities
75 // ---------------------------------------------------------------------------
77 void wxDC::DoGetSizeMM( int* width
, int* height
) const
82 if (width
) *width
= int( double(w
) / (m_userScaleX
*m_mm_to_pix_x
) );
83 if (height
) *height
= int( double(h
) / (m_userScaleY
*m_mm_to_pix_y
) );
86 // Resolution in pixels per logical inch
87 wxSize
wxDC::GetPPI() const
89 // TODO (should probably be pure virtual)
93 // ---------------------------------------------------------------------------
94 // set various DC parameters
95 // ---------------------------------------------------------------------------
97 void wxDC::ComputeScaleAndOrigin()
99 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
100 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
103 void wxDC::SetMapMode( int mode
)
108 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
111 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
114 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
117 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
121 SetLogicalScale( 1.0, 1.0 );
124 m_mappingMode
= mode
;
126 /* we don't do this mega optimisation
127 if (mode != wxMM_TEXT)
129 m_needComputeScaleX = TRUE;
130 m_needComputeScaleY = TRUE;
135 void wxDC::SetUserScale( double x
, double y
)
137 // allow negative ? -> no
140 ComputeScaleAndOrigin();
143 void wxDC::SetLogicalScale( double x
, double y
)
148 ComputeScaleAndOrigin();
151 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
153 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
154 m_logicalOriginY
= y
* m_signY
;
155 ComputeScaleAndOrigin();
158 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
160 // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there
163 ComputeScaleAndOrigin();
166 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
168 // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there
169 m_signX
= (xLeftRight
? 1 : -1);
170 m_signY
= (yBottomUp
? -1 : 1);
171 ComputeScaleAndOrigin();
174 // ---------------------------------------------------------------------------
175 // coordinates transformations
176 // ---------------------------------------------------------------------------
178 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
180 return ((wxDC
*)this)->XDEV2LOG(x
);
183 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
185 return ((wxDC
*)this)->YDEV2LOG(y
);
188 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
190 return ((wxDC
*)this)->XDEV2LOGREL(x
);
193 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
195 return ((wxDC
*)this)->YDEV2LOGREL(y
);
198 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
200 return ((wxDC
*)this)->XLOG2DEV(x
);
203 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
205 return ((wxDC
*)this)->YLOG2DEV(y
);
208 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
210 return ((wxDC
*)this)->XLOG2DEVREL(x
);
213 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
215 return ((wxDC
*)this)->YLOG2DEVREL(y
);