]>
Commit | Line | Data |
---|---|---|
4bb6408c JS |
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 | |
af0bb3b1 | 9 | // Licence: wxWindows licence |
4bb6408c JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
14f355c2 | 12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
af0bb3b1 | 13 | #pragma implementation "dc.h" |
4bb6408c JS |
14 | #endif |
15 | ||
1248b41f MB |
16 | // For compilers that support precompilation, includes "wx.h". |
17 | #include "wx/wxprec.h" | |
18 | ||
4bb6408c | 19 | #include "wx/dc.h" |
a367b9b3 | 20 | #include "wx/dcmemory.h" |
7b65ea1a | 21 | #include "wx/defs.h" |
4bb6408c | 22 | |
af0bb3b1 | 23 | IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject) |
4bb6408c JS |
24 | |
25 | //----------------------------------------------------------------------------- | |
26 | // constants | |
27 | //----------------------------------------------------------------------------- | |
28 | ||
af0bb3b1 VZ |
29 | #define mm2inches 0.0393700787402 |
30 | #define inches2mm 25.4 | |
31 | #define mm2twips 56.6929133859 | |
32 | #define twips2mm 0.0176388888889 | |
33 | #define mm2pt 2.83464566929 | |
34 | #define pt2mm 0.352777777778 | |
4bb6408c JS |
35 | |
36 | //----------------------------------------------------------------------------- | |
37 | // wxDC | |
38 | //----------------------------------------------------------------------------- | |
39 | ||
af0bb3b1 | 40 | wxDC::wxDC() |
4bb6408c | 41 | { |
2d120f83 | 42 | m_ok = FALSE; |
af0bb3b1 | 43 | |
2d120f83 JS |
44 | m_mm_to_pix_x = 1.0; |
45 | m_mm_to_pix_y = 1.0; | |
af0bb3b1 | 46 | |
2d120f83 | 47 | m_backgroundMode = wxTRANSPARENT; |
af0bb3b1 | 48 | |
2d120f83 | 49 | m_isInteractive = FALSE; |
af0bb3b1 | 50 | } |
4bb6408c | 51 | |
7b65ea1a | 52 | void wxDC::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y) |
4bb6408c | 53 | { |
af0bb3b1 VZ |
54 | wxCHECK_RET( Ok(), "invalid dc" ); |
55 | wxCHECK_RET( icon.Ok(), "invalid icon" ); | |
4bb6408c | 56 | |
af0bb3b1 VZ |
57 | DoDrawBitmap(icon, x, y, TRUE); |
58 | } | |
4bb6408c | 59 | |
7b65ea1a | 60 | void wxDC::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, bool useMask ) |
a367b9b3 | 61 | { |
af0bb3b1 VZ |
62 | wxCHECK_RET( bitmap.Ok(), "invalid bitmap" ); |
63 | ||
a367b9b3 JS |
64 | wxMemoryDC memDC; |
65 | memDC.SelectObject(bitmap); | |
af0bb3b1 VZ |
66 | |
67 | #if 0 | |
68 | // Not sure if we need this. The mask should leave the masked areas as per | |
69 | // the original background of this DC. | |
a367b9b3 JS |
70 | if (useMask) |
71 | { | |
af0bb3b1 VZ |
72 | // There might be transparent areas, so make these the same colour as this |
73 | // DC | |
74 | memDC.SetBackground(* GetBackground()); | |
75 | memDC.Clear(); | |
a367b9b3 | 76 | } |
af0bb3b1 | 77 | #endif // 0 |
a367b9b3 | 78 | |
af0bb3b1 | 79 | Blit(x, y, bitmap.GetWidth(), bitmap.GetHeight(), &memDC, 0, 0, wxCOPY, useMask); |
4bb6408c | 80 | |
af0bb3b1 VZ |
81 | memDC.SelectObject(wxNullBitmap); |
82 | } | |
4bb6408c | 83 | |
7b65ea1a | 84 | void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) |
4bb6408c | 85 | { |
2d120f83 JS |
86 | m_clipping = TRUE; |
87 | m_clipX1 = x; | |
88 | m_clipY1 = y; | |
89 | m_clipX2 = x + width; | |
90 | m_clipY2 = y + height; | |
af0bb3b1 | 91 | } |
4bb6408c | 92 | |
af0bb3b1 | 93 | void wxDC::DestroyClippingRegion() |
4bb6408c | 94 | { |
2d120f83 | 95 | m_clipping = FALSE; |
af0bb3b1 | 96 | } |
4bb6408c | 97 | |
af0bb3b1 | 98 | void wxDC::DoGetSize( int* width, int* height ) const |
4bb6408c | 99 | { |
af0bb3b1 VZ |
100 | if ( width ) |
101 | *width = m_maxX - m_minX; | |
102 | if ( height ) | |
103 | *height = m_maxY - m_minY; | |
104 | } | |
4bb6408c | 105 | |
af0bb3b1 | 106 | void wxDC::DoGetSizeMM( int* width, int* height ) const |
4bb6408c | 107 | { |
af0bb3b1 | 108 | int w, h; |
2d120f83 | 109 | GetSize( &w, &h ); |
af0bb3b1 VZ |
110 | |
111 | if ( width ) | |
112 | *width = int( double(w) / (m_scaleX*m_mm_to_pix_x) ); | |
113 | if ( height ) | |
114 | *height = int( double(h) / (m_scaleY*m_mm_to_pix_y) ); | |
115 | } | |
4bb6408c | 116 | |
7bcb11d3 | 117 | // Resolution in pixels per logical inch |
af0bb3b1 | 118 | wxSize wxDC::GetPPI() const |
7bcb11d3 JS |
119 | { |
120 | // TODO (should probably be pure virtual) | |
121 | return wxSize(0, 0); | |
122 | } | |
123 | ||
4bb6408c JS |
124 | void wxDC::SetMapMode( int mode ) |
125 | { | |
af0bb3b1 | 126 | switch (mode) |
2d120f83 | 127 | { |
e3065973 | 128 | case wxMM_TWIPS: |
2d120f83 JS |
129 | SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y ); |
130 | break; | |
e3065973 | 131 | case wxMM_POINTS: |
2d120f83 JS |
132 | SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y ); |
133 | break; | |
e3065973 | 134 | case wxMM_METRIC: |
2d120f83 JS |
135 | SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y ); |
136 | break; | |
e3065973 | 137 | case wxMM_LOMETRIC: |
2d120f83 JS |
138 | SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 ); |
139 | break; | |
4bb6408c | 140 | default: |
e3065973 | 141 | case wxMM_TEXT: |
2d120f83 JS |
142 | SetLogicalScale( 1.0, 1.0 ); |
143 | break; | |
af0bb3b1 | 144 | } |
e3065973 | 145 | if (mode != wxMM_TEXT) |
2d120f83 JS |
146 | { |
147 | m_needComputeScaleX = TRUE; | |
148 | m_needComputeScaleY = TRUE; | |
af0bb3b1 VZ |
149 | } |
150 | } | |
4bb6408c JS |
151 | |
152 | void wxDC::SetUserScale( double x, double y ) | |
153 | { | |
96f201da RR |
154 | // allow negative ? -> no |
155 | m_userScaleX = x; | |
156 | m_userScaleY = y; | |
2d120f83 | 157 | ComputeScaleAndOrigin(); |
af0bb3b1 | 158 | } |
4bb6408c JS |
159 | |
160 | void wxDC::SetLogicalScale( double x, double y ) | |
161 | { | |
96f201da RR |
162 | // allow negative ? |
163 | m_logicalScaleX = x; | |
164 | m_logicalScaleY = y; | |
2d120f83 | 165 | ComputeScaleAndOrigin(); |
af0bb3b1 | 166 | } |
4bb6408c | 167 | |
7b65ea1a | 168 | void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y ) |
4bb6408c | 169 | { |
2d120f83 JS |
170 | m_logicalOriginX = x * m_signX; // is this still correct ? |
171 | m_logicalOriginY = y * m_signY; | |
172 | ComputeScaleAndOrigin(); | |
af0bb3b1 | 173 | } |
4bb6408c | 174 | |
7b65ea1a | 175 | void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y ) |
4bb6408c | 176 | { |
76db86e7 RR |
177 | // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there |
178 | m_deviceOriginX = x; | |
179 | m_deviceOriginY = y; | |
2d120f83 | 180 | ComputeScaleAndOrigin(); |
af0bb3b1 | 181 | } |
4bb6408c | 182 | |
4bb6408c JS |
183 | void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) |
184 | { | |
af0bb3b1 VZ |
185 | m_signX = xLeftRight ? 1 : -1; |
186 | m_signY = yBottomUp ? -1 : 1; | |
2d120f83 | 187 | ComputeScaleAndOrigin(); |
af0bb3b1 | 188 | } |
4bb6408c | 189 | |
7b65ea1a | 190 | wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const |
4bb6408c | 191 | { |
af0bb3b1 VZ |
192 | return ((wxDC *)this)->XDEV2LOG(x); |
193 | } | |
4bb6408c | 194 | |
7b65ea1a | 195 | wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const |
4bb6408c | 196 | { |
af0bb3b1 VZ |
197 | return ((wxDC *)this)->YDEV2LOG(y); |
198 | } | |
4bb6408c | 199 | |
7b65ea1a | 200 | wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const |
4bb6408c | 201 | { |
af0bb3b1 VZ |
202 | return ((wxDC *)this)->XDEV2LOGREL(x); |
203 | } | |
4bb6408c | 204 | |
7b65ea1a | 205 | wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const |
4bb6408c | 206 | { |
af0bb3b1 VZ |
207 | return ((wxDC *)this)->YDEV2LOGREL(y); |
208 | } | |
4bb6408c | 209 | |
7b65ea1a | 210 | wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const |
4bb6408c | 211 | { |
af0bb3b1 VZ |
212 | return ((wxDC *)this)->XLOG2DEV(x); |
213 | } | |
4bb6408c | 214 | |
7b65ea1a | 215 | wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const |
4bb6408c | 216 | { |
af0bb3b1 VZ |
217 | return ((wxDC *)this)->YLOG2DEV(y); |
218 | } | |
4bb6408c | 219 | |
7b65ea1a | 220 | wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const |
4bb6408c | 221 | { |
af0bb3b1 VZ |
222 | return ((wxDC *)this)->XLOG2DEVREL(x); |
223 | } | |
2d120f83 | 224 | |
7b65ea1a | 225 | wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const |
4bb6408c | 226 | { |
af0bb3b1 VZ |
227 | return ((wxDC *)this)->YLOG2DEVREL(y); |
228 | } | |
4bb6408c | 229 | |
af0bb3b1 | 230 | void wxDC::ComputeScaleAndOrigin() |
4bb6408c | 231 | { |
2d120f83 JS |
232 | m_scaleX = m_logicalScaleX * m_userScaleX; |
233 | m_scaleY = m_logicalScaleY * m_userScaleY; | |
af0bb3b1 | 234 | } |
4bb6408c | 235 |