]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: dc.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
5 | // RCS-ID: $Id$ | |
6 | // Copyright: (c) 1998 Robert Roebling | |
7 | // Licence: wxWindows licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | // For compilers that support precompilation, includes "wx.h". | |
11 | #include "wx/wxprec.h" | |
12 | ||
13 | #include "wx/dc.h" | |
14 | ||
15 | #include <gdk/gdk.h> | |
16 | #include <gtk/gtk.h> | |
17 | ||
18 | //----------------------------------------------------------------------------- | |
19 | // wxDC | |
20 | //----------------------------------------------------------------------------- | |
21 | ||
22 | IMPLEMENT_ABSTRACT_CLASS(wxDC, wxDCBase) | |
23 | ||
24 | wxDC::wxDC() | |
25 | { | |
26 | m_ok = FALSE; | |
27 | ||
28 | m_mm_to_pix_x = (double)wxGetDisplaySize().GetWidth() / | |
29 | (double)wxGetDisplaySizeMM().GetWidth(); | |
30 | m_mm_to_pix_y = (double)wxGetDisplaySize().GetHeight() / | |
31 | (double)wxGetDisplaySizeMM().GetHeight(); | |
32 | ||
33 | m_needComputeScaleX = FALSE; /* not used yet */ | |
34 | m_needComputeScaleY = FALSE; /* not used yet */ | |
35 | ||
36 | m_logicalFunction = wxCOPY; | |
37 | ||
38 | m_pen = *wxBLACK_PEN; | |
39 | m_font = *wxNORMAL_FONT; | |
40 | m_brush = *wxWHITE_BRUSH; | |
41 | } | |
42 | ||
43 | void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) | |
44 | { | |
45 | m_clipping = TRUE; | |
46 | m_clipX1 = x; | |
47 | m_clipY1 = y; | |
48 | m_clipX2 = x + width; | |
49 | m_clipY2 = y + height; | |
50 | } | |
51 | ||
52 | // --------------------------------------------------------------------------- | |
53 | // get DC capabilities | |
54 | // --------------------------------------------------------------------------- | |
55 | ||
56 | void wxDC::DoGetSizeMM( int* width, int* height ) const | |
57 | { | |
58 | int w = 0; | |
59 | int h = 0; | |
60 | GetSize( &w, &h ); | |
61 | if (width) *width = int( double(w) / (m_userScaleX*m_mm_to_pix_x) ); | |
62 | if (height) *height = int( double(h) / (m_userScaleY*m_mm_to_pix_y) ); | |
63 | } | |
64 | ||
65 | // Resolution in pixels per logical inch | |
66 | wxSize wxDC::GetPPI() const | |
67 | { | |
68 | // TODO (should probably be pure virtual) | |
69 | return wxSize(0, 0); | |
70 | } | |
71 | ||
72 | // --------------------------------------------------------------------------- | |
73 | // set various DC parameters | |
74 | // --------------------------------------------------------------------------- | |
75 | ||
76 | void wxDC::ComputeScaleAndOrigin() | |
77 | { | |
78 | m_scaleX = m_logicalScaleX * m_userScaleX; | |
79 | m_scaleY = m_logicalScaleY * m_userScaleY; | |
80 | } | |
81 | ||
82 | void wxDC::SetMapMode( int mode ) | |
83 | { | |
84 | switch (mode) | |
85 | { | |
86 | case wxMM_TWIPS: | |
87 | SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y ); | |
88 | break; | |
89 | case wxMM_POINTS: | |
90 | SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y ); | |
91 | break; | |
92 | case wxMM_METRIC: | |
93 | SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y ); | |
94 | break; | |
95 | case wxMM_LOMETRIC: | |
96 | SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 ); | |
97 | break; | |
98 | default: | |
99 | case wxMM_TEXT: | |
100 | SetLogicalScale( 1.0, 1.0 ); | |
101 | break; | |
102 | } | |
103 | m_mappingMode = mode; | |
104 | ||
105 | /* we don't do this mega optimisation | |
106 | if (mode != wxMM_TEXT) | |
107 | { | |
108 | m_needComputeScaleX = TRUE; | |
109 | m_needComputeScaleY = TRUE; | |
110 | } | |
111 | */ | |
112 | } | |
113 | ||
114 | void wxDC::SetUserScale( double x, double y ) | |
115 | { | |
116 | // allow negative ? -> no | |
117 | m_userScaleX = x; | |
118 | m_userScaleY = y; | |
119 | ComputeScaleAndOrigin(); | |
120 | } | |
121 | ||
122 | void wxDC::SetLogicalScale( double x, double y ) | |
123 | { | |
124 | // allow negative ? | |
125 | m_logicalScaleX = x; | |
126 | m_logicalScaleY = y; | |
127 | ComputeScaleAndOrigin(); | |
128 | } | |
129 | ||
130 | void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y ) | |
131 | { | |
132 | m_logicalOriginX = x * m_signX; // is this still correct ? | |
133 | m_logicalOriginY = y * m_signY; | |
134 | ComputeScaleAndOrigin(); | |
135 | } | |
136 | ||
137 | void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y ) | |
138 | { | |
139 | // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there | |
140 | m_deviceOriginX = x; | |
141 | m_deviceOriginY = y; | |
142 | ComputeScaleAndOrigin(); | |
143 | } | |
144 | ||
145 | void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) | |
146 | { | |
147 | // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there | |
148 | m_signX = (xLeftRight ? 1 : -1); | |
149 | m_signY = (yBottomUp ? -1 : 1); | |
150 | ComputeScaleAndOrigin(); | |
151 | } | |
152 | ||
153 | // --------------------------------------------------------------------------- | |
154 | // coordinates transformations | |
155 | // --------------------------------------------------------------------------- | |
156 | ||
157 | wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const | |
158 | { | |
159 | return ((wxDC *)this)->XDEV2LOG(x); | |
160 | } | |
161 | ||
162 | wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const | |
163 | { | |
164 | return ((wxDC *)this)->YDEV2LOG(y); | |
165 | } | |
166 | ||
167 | wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const | |
168 | { | |
169 | return ((wxDC *)this)->XDEV2LOGREL(x); | |
170 | } | |
171 | ||
172 | wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const | |
173 | { | |
174 | return ((wxDC *)this)->YDEV2LOGREL(y); | |
175 | } | |
176 | ||
177 | wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const | |
178 | { | |
179 | return ((wxDC *)this)->XLOG2DEV(x); | |
180 | } | |
181 | ||
182 | wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const | |
183 | { | |
184 | return ((wxDC *)this)->YLOG2DEV(y); | |
185 | } | |
186 | ||
187 | wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const | |
188 | { | |
189 | return ((wxDC *)this)->XLOG2DEVREL(x); | |
190 | } | |
191 | ||
192 | wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const | |
193 | { | |
194 | return ((wxDC *)this)->YLOG2DEVREL(y); | |
195 | } | |
196 |