]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: dc.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
5 | // RCS-ID: $Id$ | |
6 | // Copyright: (c) 1998 Robert Roebling, Markus Holzem | |
7 | // Licence: wxWindows licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | ||
11 | #ifdef __GNUG__ | |
12 | #pragma implementation "dc.h" | |
13 | #endif | |
14 | ||
15 | #include "wx/dc.h" | |
16 | ||
17 | #include "gdk/gdk.h" | |
18 | #include "gtk/gtk.h" | |
19 | ||
20 | //----------------------------------------------------------------------------- | |
21 | // constants | |
22 | //----------------------------------------------------------------------------- | |
23 | ||
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 | |
30 | ||
31 | //----------------------------------------------------------------------------- | |
32 | // wxDC | |
33 | //----------------------------------------------------------------------------- | |
34 | ||
35 | IMPLEMENT_ABSTRACT_CLASS(wxDC, wxDCBase) | |
36 | ||
37 | wxDC::wxDC() | |
38 | { | |
39 | m_ok = FALSE; | |
40 | ||
41 | m_mm_to_pix_x = 1.0; | |
42 | m_mm_to_pix_y = 1.0; | |
43 | ||
44 | m_needComputeScaleX = FALSE; /* not used yet */ | |
45 | m_needComputeScaleY = FALSE; /* not used yet */ | |
46 | ||
47 | m_logicalFunction = wxCOPY; | |
48 | ||
49 | m_pen = *wxBLACK_PEN; | |
50 | m_font = *wxNORMAL_FONT; | |
51 | m_brush = *wxTRANSPARENT_BRUSH; | |
52 | } | |
53 | ||
54 | void wxDC::DoSetClippingRegion( long x, long y, long width, long 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::DestroyClippingRegion() | |
64 | { | |
65 | m_clipping = FALSE; | |
66 | } | |
67 | ||
68 | // --------------------------------------------------------------------------- | |
69 | // get DC capabilities | |
70 | // --------------------------------------------------------------------------- | |
71 | ||
72 | void wxDC::DoGetSize( int* width, int* height ) const | |
73 | { | |
74 | if (width) *width = m_maxX-m_minX; | |
75 | if (height) *height = m_maxY-m_minY; | |
76 | } | |
77 | ||
78 | void wxDC::DoGetSizeMM( int* width, int* height ) const | |
79 | { | |
80 | int w = 0; | |
81 | int h = 0; | |
82 | GetSize( &w, &h ); | |
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) ); | |
85 | } | |
86 | ||
87 | // Resolution in pixels per logical inch | |
88 | wxSize wxDC::GetPPI() const | |
89 | { | |
90 | // TODO (should probably be pure virtual) | |
91 | return wxSize(0, 0); | |
92 | } | |
93 | ||
94 | // --------------------------------------------------------------------------- | |
95 | // set various DC parameters | |
96 | // --------------------------------------------------------------------------- | |
97 | ||
98 | void wxDC::ComputeScaleAndOrigin() | |
99 | { | |
100 | /* CMB: copy scale to see if it changes */ | |
101 | double origScaleX = m_scaleX; | |
102 | double origScaleY = m_scaleY; | |
103 | ||
104 | m_scaleX = m_logicalScaleX * m_userScaleX; | |
105 | m_scaleY = m_logicalScaleY * m_userScaleY; | |
106 | ||
107 | /* CMB: if scale has changed call SetPen to recalulate the line width */ | |
108 | if (m_scaleX != origScaleX || m_scaleY != origScaleY) | |
109 | { | |
110 | /* this is a bit artificial, but we need to force wxDC to think | |
111 | the pen has changed */ | |
112 | wxPen pen = m_pen; | |
113 | m_pen = wxNullPen; | |
114 | SetPen( pen ); | |
115 | } | |
116 | } | |
117 | ||
118 | void wxDC::SetMapMode( int mode ) | |
119 | { | |
120 | switch (mode) | |
121 | { | |
122 | case wxMM_TWIPS: | |
123 | SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y ); | |
124 | break; | |
125 | case wxMM_POINTS: | |
126 | SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y ); | |
127 | break; | |
128 | case wxMM_METRIC: | |
129 | SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y ); | |
130 | break; | |
131 | case wxMM_LOMETRIC: | |
132 | SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 ); | |
133 | break; | |
134 | default: | |
135 | case wxMM_TEXT: | |
136 | SetLogicalScale( 1.0, 1.0 ); | |
137 | break; | |
138 | } | |
139 | m_mappingMode = mode; | |
140 | ||
141 | /* we don't do this mega optimisation | |
142 | if (mode != wxMM_TEXT) | |
143 | { | |
144 | m_needComputeScaleX = TRUE; | |
145 | m_needComputeScaleY = TRUE; | |
146 | } | |
147 | */ | |
148 | } | |
149 | ||
150 | void wxDC::SetUserScale( double x, double y ) | |
151 | { | |
152 | // allow negative ? -> no | |
153 | m_userScaleX = x; | |
154 | m_userScaleY = y; | |
155 | ComputeScaleAndOrigin(); | |
156 | } | |
157 | ||
158 | void wxDC::SetLogicalScale( double x, double y ) | |
159 | { | |
160 | // allow negative ? | |
161 | m_logicalScaleX = x; | |
162 | m_logicalScaleY = y; | |
163 | ComputeScaleAndOrigin(); | |
164 | } | |
165 | ||
166 | void wxDC::SetLogicalOrigin( long x, long y ) | |
167 | { | |
168 | m_logicalOriginX = x * m_signX; // is this still correct ? | |
169 | m_logicalOriginY = y * m_signY; | |
170 | ComputeScaleAndOrigin(); | |
171 | } | |
172 | ||
173 | void wxDC::SetDeviceOrigin( long x, long y ) | |
174 | { | |
175 | // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there | |
176 | m_deviceOriginX = x; | |
177 | m_deviceOriginY = y; | |
178 | ComputeScaleAndOrigin(); | |
179 | } | |
180 | ||
181 | void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) | |
182 | { | |
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(); | |
187 | } | |
188 | ||
189 | // --------------------------------------------------------------------------- | |
190 | // coordinates transformations | |
191 | // --------------------------------------------------------------------------- | |
192 | ||
193 | long wxDCBase::DeviceToLogicalX(long x) const | |
194 | { | |
195 | return ((wxDC *)this)->XDEV2LOG(x); | |
196 | } | |
197 | ||
198 | long wxDCBase::DeviceToLogicalY(long y) const | |
199 | { | |
200 | return ((wxDC *)this)->YDEV2LOG(y); | |
201 | } | |
202 | ||
203 | long wxDCBase::DeviceToLogicalXRel(long x) const | |
204 | { | |
205 | return ((wxDC *)this)->XDEV2LOGREL(x); | |
206 | } | |
207 | ||
208 | long wxDCBase::DeviceToLogicalYRel(long y) const | |
209 | { | |
210 | return ((wxDC *)this)->YDEV2LOGREL(y); | |
211 | } | |
212 | ||
213 | long wxDCBase::LogicalToDeviceX(long x) const | |
214 | { | |
215 | return ((wxDC *)this)->XLOG2DEV(x); | |
216 | } | |
217 | ||
218 | long wxDCBase::LogicalToDeviceY(long y) const | |
219 | { | |
220 | return ((wxDC *)this)->YLOG2DEV(y); | |
221 | } | |
222 | ||
223 | long wxDCBase::LogicalToDeviceXRel(long x) const | |
224 | { | |
225 | return ((wxDC *)this)->XLOG2DEVREL(x); | |
226 | } | |
227 | ||
228 | long wxDCBase::LogicalToDeviceYRel(long y) const | |
229 | { | |
230 | return ((wxDC *)this)->YLOG2DEVREL(y); | |
231 | } | |
232 |