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