Metric conversion constants not doubled in each port code.
[wxWidgets.git] / src / x11 / dc.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dc.cpp
3 // Purpose: wxDC class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "dc.h"
14 #endif
15
16 #include "wx/dc.h"
17 #include "wx/dcmemory.h"
18 #include "wx/defs.h"
19
20 IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject)
21
22 //-----------------------------------------------------------------------------
23 // wxDC
24 //-----------------------------------------------------------------------------
25
26 wxDC::wxDC()
27 {
28 m_ok = FALSE;
29
30 #if 1
31 m_mm_to_pix_x = 1.0;
32 m_mm_to_pix_y = 1.0;
33 #else
34 m_mm_to_pix_x = (double)wxGetDisplaySize().GetWidth() /
35 (double)wxGetDisplaySizeMM().GetWidth();
36 m_mm_to_pix_y = (double)wxGetDisplaySize().GetHeight() /
37 (double)wxGetDisplaySizeMM().GetHeight();
38 #endif
39
40 m_needComputeScaleX = FALSE; /* not used yet */
41 m_needComputeScaleY = FALSE; /* not used yet */
42
43 m_logicalFunction = wxCOPY;
44
45 m_pen = *wxBLACK_PEN;
46 m_font = *wxNORMAL_FONT;
47 m_brush = *wxWHITE_BRUSH;
48
49 m_backgroundMode = wxTRANSPARENT;
50
51 m_isInteractive = FALSE; // ???
52 }
53
54 void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height )
55 {
56 m_clipping = TRUE;
57 m_clipX1 = x;
58 m_clipY1 = y;
59 m_clipX2 = x + width;
60 m_clipY2 = y + height;
61 }
62
63 void wxDC::DoGetSizeMM( int* width, int* height ) const
64 {
65 int w, h;
66 GetSize( &w, &h );
67
68 if ( width )
69 *width = int( double(w) / (m_scaleX*m_mm_to_pix_x) );
70 if ( height )
71 *height = int( double(h) / (m_scaleY*m_mm_to_pix_y) );
72 }
73
74 // Resolution in pixels per logical inch
75 wxSize wxDC::GetPPI() const
76 {
77 // TODO (should probably be pure virtual)
78 return wxSize(0, 0);
79 }
80
81 void wxDC::SetMapMode( int mode )
82 {
83 switch (mode)
84 {
85 case wxMM_TWIPS:
86 SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y );
87 break;
88 case wxMM_POINTS:
89 SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y );
90 break;
91 case wxMM_METRIC:
92 SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y );
93 break;
94 case wxMM_LOMETRIC:
95 SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 );
96 break;
97 default:
98 case wxMM_TEXT:
99 SetLogicalScale( 1.0, 1.0 );
100 break;
101 }
102 if (mode != wxMM_TEXT)
103 {
104 m_needComputeScaleX = TRUE;
105 m_needComputeScaleY = TRUE;
106 }
107 }
108
109 void wxDC::SetUserScale( double x, double y )
110 {
111 // allow negative ? -> no
112 m_userScaleX = x;
113 m_userScaleY = y;
114 ComputeScaleAndOrigin();
115 }
116
117 void wxDC::SetLogicalScale( double x, double y )
118 {
119 // allow negative ?
120 m_logicalScaleX = x;
121 m_logicalScaleY = y;
122 ComputeScaleAndOrigin();
123 }
124
125 void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y )
126 {
127 m_logicalOriginX = x * m_signX; // is this still correct ?
128 m_logicalOriginY = y * m_signY;
129 ComputeScaleAndOrigin();
130 }
131
132 void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y )
133 {
134 // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there
135 m_deviceOriginX = x;
136 m_deviceOriginY = y;
137 ComputeScaleAndOrigin();
138 }
139
140 void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
141 {
142 m_signX = xLeftRight ? 1 : -1;
143 m_signY = yBottomUp ? -1 : 1;
144 ComputeScaleAndOrigin();
145 }
146
147 wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
148 {
149 return ((wxDC *)this)->XDEV2LOG(x);
150 }
151
152 wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
153 {
154 return ((wxDC *)this)->YDEV2LOG(y);
155 }
156
157 wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
158 {
159 return ((wxDC *)this)->XDEV2LOGREL(x);
160 }
161
162 wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
163 {
164 return ((wxDC *)this)->YDEV2LOGREL(y);
165 }
166
167 wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
168 {
169 return ((wxDC *)this)->XLOG2DEV(x);
170 }
171
172 wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
173 {
174 return ((wxDC *)this)->YLOG2DEV(y);
175 }
176
177 wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
178 {
179 return ((wxDC *)this)->XLOG2DEVREL(x);
180 }
181
182 wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
183 {
184 return ((wxDC *)this)->YLOG2DEVREL(y);
185 }
186
187 void wxDC::ComputeScaleAndOrigin()
188 {
189 m_scaleX = m_logicalScaleX * m_userScaleX;
190 m_scaleY = m_logicalScaleY * m_userScaleY;
191 }
192