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