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