]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/dc.cpp
Typo fix
[wxWidgets.git] / src / gtk / dc.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dc.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // RCS-ID: $Id$
6 // Copyright: (c) 1998 Robert Roebling, Markus Holzem
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10
11 #ifdef __GNUG__
12 #pragma implementation "dc.h"
13 #endif
14
15 #include "wx/dc.h"
16
17 #include <gdk/gdk.h>
18 #include <gtk/gtk.h>
19
20 //-----------------------------------------------------------------------------
21 // constants
22 //-----------------------------------------------------------------------------
23
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
30
31 //-----------------------------------------------------------------------------
32 // wxDC
33 //-----------------------------------------------------------------------------
34
35 IMPLEMENT_ABSTRACT_CLASS(wxDC, wxDCBase)
36
37 wxDC::wxDC()
38 {
39 m_ok = FALSE;
40
41 m_mm_to_pix_x = (double)wxGetDisplaySize().GetWidth() /
42 (double)wxGetDisplaySizeMM().GetWidth();
43 m_mm_to_pix_y = (double)wxGetDisplaySize().GetHeight() /
44 (double)wxGetDisplaySizeMM().GetHeight();
45
46 m_needComputeScaleX = FALSE; /* not used yet */
47 m_needComputeScaleY = FALSE; /* not used yet */
48
49 m_logicalFunction = wxCOPY;
50
51 m_pen = *wxBLACK_PEN;
52 m_font = *wxNORMAL_FONT;
53 m_brush = *wxWHITE_BRUSH;
54 }
55
56 void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height )
57 {
58 m_clipping = TRUE;
59 m_clipX1 = x;
60 m_clipY1 = y;
61 m_clipX2 = x + width;
62 m_clipY2 = y + height;
63 }
64
65 void wxDC::DestroyClippingRegion()
66 {
67 m_clipping = FALSE;
68 }
69
70 // ---------------------------------------------------------------------------
71 // get DC capabilities
72 // ---------------------------------------------------------------------------
73
74 void wxDC::DoGetSizeMM( int* width, int* height ) const
75 {
76 int w = 0;
77 int h = 0;
78 GetSize( &w, &h );
79 if (width) *width = int( double(w) / (m_userScaleX*m_mm_to_pix_x) );
80 if (height) *height = int( double(h) / (m_userScaleY*m_mm_to_pix_y) );
81 }
82
83 // Resolution in pixels per logical inch
84 wxSize wxDC::GetPPI() const
85 {
86 // TODO (should probably be pure virtual)
87 return wxSize(0, 0);
88 }
89
90 // ---------------------------------------------------------------------------
91 // set various DC parameters
92 // ---------------------------------------------------------------------------
93
94 void wxDC::ComputeScaleAndOrigin()
95 {
96 m_scaleX = m_logicalScaleX * m_userScaleX;
97 m_scaleY = m_logicalScaleY * m_userScaleY;
98 }
99
100 void wxDC::SetMapMode( int mode )
101 {
102 switch (mode)
103 {
104 case wxMM_TWIPS:
105 SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y );
106 break;
107 case wxMM_POINTS:
108 SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y );
109 break;
110 case wxMM_METRIC:
111 SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y );
112 break;
113 case wxMM_LOMETRIC:
114 SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 );
115 break;
116 default:
117 case wxMM_TEXT:
118 SetLogicalScale( 1.0, 1.0 );
119 break;
120 }
121 m_mappingMode = mode;
122
123 /* we don't do this mega optimisation
124 if (mode != wxMM_TEXT)
125 {
126 m_needComputeScaleX = TRUE;
127 m_needComputeScaleY = TRUE;
128 }
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 // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there
166 m_signX = (xLeftRight ? 1 : -1);
167 m_signY = (yBottomUp ? -1 : 1);
168 ComputeScaleAndOrigin();
169 }
170
171 // ---------------------------------------------------------------------------
172 // coordinates transformations
173 // ---------------------------------------------------------------------------
174
175 wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
176 {
177 return ((wxDC *)this)->XDEV2LOG(x);
178 }
179
180 wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
181 {
182 return ((wxDC *)this)->YDEV2LOG(y);
183 }
184
185 wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
186 {
187 return ((wxDC *)this)->XDEV2LOGREL(x);
188 }
189
190 wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
191 {
192 return ((wxDC *)this)->YDEV2LOGREL(y);
193 }
194
195 wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
196 {
197 return ((wxDC *)this)->XLOG2DEV(x);
198 }
199
200 wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
201 {
202 return ((wxDC *)this)->YLOG2DEV(y);
203 }
204
205 wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
206 {
207 return ((wxDC *)this)->XLOG2DEVREL(x);
208 }
209
210 wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
211 {
212 return ((wxDC *)this)->YLOG2DEVREL(y);
213 }
214