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