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