]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/dc.cpp
resize fun
[wxWidgets.git] / src / gtk / dc.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: dc.cpp
3// Purpose:
4// Author: Robert Roebling
6f65e337 5// RCS-ID: $Id$
dbf858b5 6// Copyright: (c) 1998 Robert Roebling, Markus Holzem
c801d85f
KB
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10
11#ifdef __GNUG__
12#pragma implementation "dc.h"
13#endif
14
15#include "wx/dc.h"
16
83624f79
RR
17#include "gdk/gdk.h"
18#include "gtk/gtk.h"
19
c801d85f
KB
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
35IMPLEMENT_ABSTRACT_CLASS(wxDC,wxObject)
36
4bc67cc5 37wxDC::wxDC()
c801d85f 38{
4bc67cc5
RR
39 m_ok = FALSE;
40 m_optimize = FALSE;
41 m_autoSetting = FALSE;
42 m_colour = TRUE;
43 m_clipping = FALSE;
c801d85f 44
4bc67cc5
RR
45 m_mm_to_pix_x = 1.0;
46 m_mm_to_pix_y = 1.0;
c801d85f 47
4bc67cc5
RR
48 m_logicalOriginX = 0;
49 m_logicalOriginY = 0;
50 m_deviceOriginX = 0;
51 m_deviceOriginY = 0;
c801d85f 52
4bc67cc5
RR
53 m_logicalScaleX = 1.0;
54 m_logicalScaleY = 1.0;
55 m_userScaleX = 1.0;
56 m_userScaleY = 1.0;
57 m_scaleX = 1.0;
58 m_scaleY = 1.0;
c801d85f 59
e3065973 60 m_mappingMode = wxMM_TEXT;
ea6f44b5
RR
61 m_needComputeScaleX = FALSE; /* not used yet */
62 m_needComputeScaleY = FALSE; /* not used yet */
c801d85f 63
ea6f44b5
RR
64 m_signX = 1; /* default x-axis left to right */
65 m_signY = 1; /* default y-axis top down. -1 in postscript. */
c801d85f 66
ea6f44b5
RR
67 m_maxX = 0;
68 m_maxY = 0;
69 m_minX = 0;
70 m_minY = 0;
c801d85f 71
4bc67cc5 72 m_logicalFunction = wxCOPY;
c801d85f 73// m_textAlignment = wxALIGN_TOP_LEFT;
4bc67cc5 74 m_backgroundMode = wxTRANSPARENT;
c801d85f 75
4bc67cc5
RR
76 m_textForegroundColour = *wxBLACK;
77 m_textBackgroundColour = *wxWHITE;
78 m_pen = *wxBLACK_PEN;
79 m_font = *wxNORMAL_FONT;
80 m_brush = *wxTRANSPARENT_BRUSH;
81 m_backgroundBrush = *wxWHITE_BRUSH;
c801d85f 82
ea6f44b5 83// m_palette = wxAPP_COLOURMAP; /* I'll learn to handle palettes later in my life */
ff7b1510 84}
c801d85f 85
4bc67cc5 86wxDC::~wxDC()
c801d85f 87{
ff7b1510 88}
c801d85f 89
4bc67cc5 90bool wxDC::Ok() const
cf7a7e13 91{
4bc67cc5 92 return m_ok;
cf7a7e13
RR
93}
94
c801d85f
KB
95void wxDC::DrawArc( long WXUNUSED(x1), long WXUNUSED(y1), long WXUNUSED(x2), long WXUNUSED(y2),
96 double WXUNUSED(xc), double WXUNUSED(yc) )
97{
ff7b1510 98}
c801d85f 99
c801d85f
KB
100void wxDC::DrawPoint( wxPoint& point )
101{
4bc67cc5 102 DrawPoint( point.x, point.y );
ff7b1510 103}
c801d85f
KB
104
105void wxDC::DrawPolygon( wxList *list, long xoffset, long yoffset, int fillStyle )
106{
4bc67cc5
RR
107 int n = list->Number();
108 wxPoint *points = new wxPoint[n];
c801d85f 109
4bc67cc5
RR
110 int i = 0;
111 for( wxNode *node = list->First(); node; node = node->Next() )
112 {
113 wxPoint *point = (wxPoint *)node->Data();
114 points[i].x = point->x;
115 points[i++].y = point->y;
116 }
117
118 DrawPolygon( n, points, xoffset, yoffset, fillStyle );
119 delete[] points;
ff7b1510 120}
c801d85f
KB
121
122void wxDC::DrawLines( wxList *list, long xoffset, long yoffset )
123{
4bc67cc5
RR
124 int n = list->Number();
125 wxPoint *points = new wxPoint[n];
c801d85f 126
4bc67cc5
RR
127 int i = 0;
128 for( wxNode *node = list->First(); node; node = node->Next() )
129 {
130 wxPoint *point = (wxPoint *)node->Data();
131 points[i].x = point->x;
132 points[i++].y = point->y;
133 }
134
135 DrawLines( n, points, xoffset, yoffset );
136 delete []points;
ff7b1510 137}
c801d85f
KB
138
139void wxDC::DrawSpline( long x1, long y1, long x2, long y2, long x3, long y3 )
140{
4bc67cc5
RR
141 wxList list;
142 list.Append( (wxObject*)new wxPoint(x1, y1) );
143 list.Append( (wxObject*)new wxPoint(x2, y2) );
144 list.Append( (wxObject*)new wxPoint(x3, y3) );
145 DrawSpline(&list);
146 wxNode *node = list.First();
147 while (node)
148 {
149 wxPoint *p = (wxPoint*)node->Data();
150 delete p;
151 node = node->Next();
152 }
ff7b1510 153}
c801d85f 154
c801d85f
KB
155void wxDC::DrawSpline( int n, wxPoint points[] )
156{
4bc67cc5
RR
157 wxList list;
158 for (int i = 0; i < n; i++) list.Append( (wxObject*)&points[i] );
159 DrawSpline( &list );
ff7b1510 160}
c801d85f
KB
161
162void wxDC::SetClippingRegion( long x, long y, long width, long height )
163{
4bc67cc5
RR
164 m_clipping = TRUE;
165 m_clipX1 = x;
166 m_clipY1 = y;
167 m_clipX2 = x + width;
168 m_clipY2 = y + height;
ff7b1510 169}
c801d85f 170
4bc67cc5 171void wxDC::DestroyClippingRegion()
c801d85f 172{
4bc67cc5 173 m_clipping = FALSE;
ff7b1510 174}
c801d85f
KB
175
176void wxDC::GetClippingBox( long *x, long *y, long *width, long *height ) const
177{
4bc67cc5
RR
178 if (m_clipping)
179 {
180 if (x) *x = m_clipX1;
181 if (y) *y = m_clipY1;
182 if (width) *width = (m_clipX2 - m_clipX1);
183 if (height) *height = (m_clipY2 - m_clipY1);
184 }
185 else
186 {
187 *x = *y = *width = *height = 0;
188 }
ff7b1510 189}
c801d85f
KB
190
191void wxDC::GetSize( int* width, int* height ) const
192{
4bc67cc5
RR
193 if (width) *width = m_maxX-m_minX;
194 if (height) *height = m_maxY-m_minY;
ff7b1510 195}
c801d85f
KB
196
197void wxDC::GetSizeMM( long* width, long* height ) const
198{
4bc67cc5
RR
199 int w = 0;
200 int h = 0;
201 GetSize( &w, &h );
202 if (width) *width = long( double(w) / (m_scaleX*m_mm_to_pix_x) );
203 if (height) *height = long( double(h) / (m_scaleY*m_mm_to_pix_y) );
ff7b1510 204}
c801d85f
KB
205
206void wxDC::SetTextForeground( const wxColour &col )
207{
4bc67cc5 208 m_textForegroundColour = col;
ff7b1510 209}
c801d85f
KB
210
211void wxDC::SetTextBackground( const wxColour &col )
212{
4bc67cc5 213 m_textBackgroundColour = col;
ff7b1510 214}
c801d85f
KB
215
216void wxDC::SetMapMode( int mode )
217{
4bc67cc5
RR
218 switch (mode)
219 {
e3065973 220 case wxMM_TWIPS:
4bc67cc5
RR
221 SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y );
222 break;
e3065973 223 case wxMM_POINTS:
4bc67cc5
RR
224 SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y );
225 break;
e3065973 226 case wxMM_METRIC:
4bc67cc5
RR
227 SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y );
228 break;
e3065973 229 case wxMM_LOMETRIC:
4bc67cc5
RR
230 SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 );
231 break;
232 default:
e3065973 233 case wxMM_TEXT:
4bc67cc5
RR
234 SetLogicalScale( 1.0, 1.0 );
235 break;
236 }
237/* we don't do this mega optimisation
e3065973 238 if (mode != wxMM_TEXT)
4bc67cc5
RR
239 {
240 m_needComputeScaleX = TRUE;
241 m_needComputeScaleY = TRUE;
242 }
243*/
ff7b1510 244}
c801d85f
KB
245
246void wxDC::SetUserScale( double x, double y )
247{
4bc67cc5
RR
248 // allow negative ? -> no
249 m_userScaleX = x;
250 m_userScaleY = y;
251 ComputeScaleAndOrigin();
ff7b1510 252}
c801d85f
KB
253
254void wxDC::GetUserScale( double *x, double *y )
255{
4bc67cc5
RR
256 if (x) *x = m_userScaleX;
257 if (y) *y = m_userScaleY;
ff7b1510 258}
c801d85f
KB
259
260void wxDC::SetLogicalScale( double x, double y )
261{
4bc67cc5
RR
262 // allow negative ?
263 m_logicalScaleX = x;
264 m_logicalScaleY = y;
265 ComputeScaleAndOrigin();
ff7b1510 266}
c801d85f
KB
267
268void wxDC::GetLogicalScale( double *x, double *y )
269{
4bc67cc5
RR
270 if (x) *x = m_logicalScaleX;
271 if (y) *y = m_logicalScaleY;
ff7b1510 272}
c801d85f
KB
273
274void wxDC::SetLogicalOrigin( long x, long y )
275{
4bc67cc5
RR
276 m_logicalOriginX = x * m_signX; // is this still correct ?
277 m_logicalOriginY = y * m_signY;
278 ComputeScaleAndOrigin();
ff7b1510 279}
c801d85f
KB
280
281void wxDC::GetLogicalOrigin( long *x, long *y )
282{
4bc67cc5
RR
283 if (x) *x = m_logicalOriginX;
284 if (y) *y = m_logicalOriginY;
ff7b1510 285}
c801d85f
KB
286
287void wxDC::SetDeviceOrigin( long x, long y )
288{
4bc67cc5
RR
289 // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there
290 m_deviceOriginX = x;
291 m_deviceOriginY = y;
292 ComputeScaleAndOrigin();
ff7b1510 293}
c801d85f
KB
294
295void wxDC::GetDeviceOrigin( long *x, long *y )
296{
4bc67cc5
RR
297 if (x) *x = m_deviceOriginX;
298 if (y) *y = m_deviceOriginY;
ff7b1510 299}
c801d85f 300
c801d85f
KB
301void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
302{
4bc67cc5
RR
303 // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there
304 m_signX = (xLeftRight ? 1 : -1);
305 m_signY = (yBottomUp ? -1 : 1);
306 ComputeScaleAndOrigin();
ff7b1510 307}
c801d85f
KB
308
309long wxDC::DeviceToLogicalX(long x) const
310{
4bc67cc5 311 return XDEV2LOG(x);
ff7b1510 312}
c801d85f
KB
313
314long wxDC::DeviceToLogicalY(long y) const
315{
4bc67cc5 316 return YDEV2LOG(y);
ff7b1510 317}
c801d85f
KB
318
319long wxDC::DeviceToLogicalXRel(long x) const
320{
4bc67cc5 321 return XDEV2LOGREL(x);
ff7b1510 322}
c801d85f
KB
323
324long wxDC::DeviceToLogicalYRel(long y) const
325{
4bc67cc5 326 return YDEV2LOGREL(y);
ff7b1510 327}
c801d85f
KB
328
329long wxDC::LogicalToDeviceX(long x) const
330{
4bc67cc5 331 return XLOG2DEV(x);
ff7b1510 332}
c801d85f
KB
333
334long wxDC::LogicalToDeviceY(long y) const
335{
4bc67cc5 336 return YLOG2DEV(y);
ff7b1510 337}
c801d85f
KB
338
339long wxDC::LogicalToDeviceXRel(long x) const
340{
4bc67cc5 341 return XLOG2DEVREL(x);
ff7b1510 342}
c801d85f
KB
343
344long wxDC::LogicalToDeviceYRel(long y) const
345{
4bc67cc5 346 return YLOG2DEVREL(y);
ff7b1510 347}
c801d85f
KB
348
349void wxDC::CalcBoundingBox( long x, long y )
350{
4bc67cc5
RR
351 if (x < m_minX) m_minX = x;
352 if (y < m_minY) m_minY = y;
353 if (x > m_maxX) m_maxX = x;
354 if (y > m_maxY) m_maxY = y;
ff7b1510 355}
c801d85f 356
4bc67cc5 357void wxDC::ComputeScaleAndOrigin()
c801d85f 358{
4bc67cc5
RR
359 // CMB: copy scale to see if it changes
360 double origScaleX = m_scaleX;
361 double origScaleY = m_scaleY;
6f65e337 362
4bc67cc5
RR
363 m_scaleX = m_logicalScaleX * m_userScaleX;
364 m_scaleY = m_logicalScaleY * m_userScaleY;
c801d85f 365
4bc67cc5
RR
366 // CMB: if scale has changed call SetPen to recalulate the line width
367 if (m_scaleX != origScaleX || m_scaleY != origScaleY)
368 {
369 // this is a bit artificial, but we need to force wxDC to think
370 // the pen has changed
371 // It gives an Assert, Robert Roebling
5b6ec980 372/*
4bc67cc5
RR
373 wxPen pen = m_pen;
374 m_pen = wxNullPen;
375 SetPen( pen );
5b6ec980 376*/
6f65e337 377 }
ff7b1510 378}
c801d85f 379