]> git.saurik.com Git - wxWidgets.git/blob - src/x11/dc.cpp
uninitialized variable warning fixed (modified patch 1434065)
[wxWidgets.git] / src / x11 / 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 #include "wx/dc.h"
13 #include "wx/dcmemory.h"
14 #include "wx/defs.h"
15
16 IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject)
17
18 //-----------------------------------------------------------------------------
19 // wxDC
20 //-----------------------------------------------------------------------------
21
22 wxDC::wxDC()
23 {
24 m_ok = FALSE;
25
26 #if 1
27 m_mm_to_pix_x = 1.0;
28 m_mm_to_pix_y = 1.0;
29 #else
30 m_mm_to_pix_x = (double)wxGetDisplaySize().GetWidth() /
31 (double)wxGetDisplaySizeMM().GetWidth();
32 m_mm_to_pix_y = (double)wxGetDisplaySize().GetHeight() /
33 (double)wxGetDisplaySizeMM().GetHeight();
34 #endif
35
36 m_needComputeScaleX = FALSE; /* not used yet */
37 m_needComputeScaleY = FALSE; /* not used yet */
38
39 m_logicalFunction = wxCOPY;
40
41 m_pen = *wxBLACK_PEN;
42 m_font = *wxNORMAL_FONT;
43 m_brush = *wxWHITE_BRUSH;
44
45 m_backgroundMode = wxTRANSPARENT;
46
47 m_isInteractive = FALSE; // ???
48 }
49
50 void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height )
51 {
52 m_clipping = TRUE;
53 m_clipX1 = x;
54 m_clipY1 = y;
55 m_clipX2 = x + width;
56 m_clipY2 = y + height;
57 }
58
59 void wxDC::DoGetSizeMM( int* width, int* height ) const
60 {
61 int w, h;
62 GetSize( &w, &h );
63
64 if ( width )
65 *width = int( double(w) / (m_scaleX*m_mm_to_pix_x) );
66 if ( height )
67 *height = int( double(h) / (m_scaleY*m_mm_to_pix_y) );
68 }
69
70 // Resolution in pixels per logical inch
71 wxSize wxDC::GetPPI() const
72 {
73 // TODO (should probably be pure virtual)
74 return wxSize(0, 0);
75 }
76
77 void wxDC::SetMapMode( int mode )
78 {
79 switch (mode)
80 {
81 case wxMM_TWIPS:
82 SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y );
83 break;
84 case wxMM_POINTS:
85 SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y );
86 break;
87 case wxMM_METRIC:
88 SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y );
89 break;
90 case wxMM_LOMETRIC:
91 SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 );
92 break;
93 default:
94 case wxMM_TEXT:
95 SetLogicalScale( 1.0, 1.0 );
96 break;
97 }
98 if (mode != wxMM_TEXT)
99 {
100 m_needComputeScaleX = TRUE;
101 m_needComputeScaleY = TRUE;
102 }
103 }
104
105 void wxDC::SetUserScale( double x, double y )
106 {
107 // allow negative ? -> no
108 m_userScaleX = x;
109 m_userScaleY = y;
110 ComputeScaleAndOrigin();
111 }
112
113 void wxDC::SetLogicalScale( double x, double y )
114 {
115 // allow negative ?
116 m_logicalScaleX = x;
117 m_logicalScaleY = y;
118 ComputeScaleAndOrigin();
119 }
120
121 void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y )
122 {
123 m_logicalOriginX = x * m_signX; // is this still correct ?
124 m_logicalOriginY = y * m_signY;
125 ComputeScaleAndOrigin();
126 }
127
128 void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y )
129 {
130 // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there
131 m_deviceOriginX = x;
132 m_deviceOriginY = y;
133 ComputeScaleAndOrigin();
134 }
135
136 void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
137 {
138 m_signX = xLeftRight ? 1 : -1;
139 m_signY = yBottomUp ? -1 : 1;
140 ComputeScaleAndOrigin();
141 }
142
143 wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
144 {
145 return ((wxDC *)this)->XDEV2LOG(x);
146 }
147
148 wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
149 {
150 return ((wxDC *)this)->YDEV2LOG(y);
151 }
152
153 wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
154 {
155 return ((wxDC *)this)->XDEV2LOGREL(x);
156 }
157
158 wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
159 {
160 return ((wxDC *)this)->YDEV2LOGREL(y);
161 }
162
163 wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
164 {
165 return ((wxDC *)this)->XLOG2DEV(x);
166 }
167
168 wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
169 {
170 return ((wxDC *)this)->YLOG2DEV(y);
171 }
172
173 wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
174 {
175 return ((wxDC *)this)->XLOG2DEVREL(x);
176 }
177
178 wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
179 {
180 return ((wxDC *)this)->YLOG2DEVREL(y);
181 }
182
183 void wxDC::ComputeScaleAndOrigin()
184 {
185 m_scaleX = m_logicalScaleX * m_userScaleX;
186 m_scaleY = m_logicalScaleY * m_userScaleY;
187 }
188