]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/dc.cpp
1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "dc.h"
18 #if !USE_SHARED_LIBRARY
19 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
22 //-----------------------------------------------------------------------------
24 //-----------------------------------------------------------------------------
26 #define mm2inches 0.0393700787402
27 #define inches2mm 25.4
28 #define mm2twips 56.6929133859
29 #define twips2mm 0.0176388888889
30 #define mm2pt 2.83464566929
31 #define pt2mm 0.352777777778
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
37 long wxDCBase::DeviceToLogicalX(long x
) const
42 long wxDCBase::DeviceToLogicalY(long y
) const
47 long wxDCBase::DeviceToLogicalXRel(long x
) const
49 return XDEV2LOGREL(x
);
52 long wxDCBase::DeviceToLogicalYRel(long y
) const
54 return YDEV2LOGREL(y
);
57 long wxDCBase::LogicalToDeviceX(long x
) const
62 long wxDCBase::LogicalToDeviceY(long y
) const
67 long wxDCBase::LogicalToDeviceXRel(long x
) const
69 return XLOG2DEVREL(x
);
72 long wxDCBase::LogicalToDeviceYRel(long y
) const
74 return YLOG2DEVREL(y
);
77 //-----------------------------------------------------------------------------
79 //-----------------------------------------------------------------------------
85 m_autoSetting
= FALSE
;
96 m_internalDeviceOriginX
= 0;
97 m_internalDeviceOriginY
= 0;
98 m_externalDeviceOriginX
= 0;
99 m_externalDeviceOriginY
= 0;
101 m_logicalScaleX
= 1.0;
102 m_logicalScaleY
= 1.0;
108 m_mappingMode
= wxMM_TEXT
;
109 m_needComputeScaleX
= FALSE
;
110 m_needComputeScaleY
= FALSE
;
112 m_signX
= 1; // default x-axis left to right
113 m_signY
= 1; // default y-axis top down
115 m_maxX
= m_maxY
= -100000;
116 m_minY
= m_minY
= 100000;
118 m_logicalFunction
= wxCOPY
;
119 // m_textAlignment = wxALIGN_TOP_LEFT;
120 m_backgroundMode
= wxTRANSPARENT
;
122 m_textForegroundColour
= *wxBLACK
;
123 m_textBackgroundColour
= *wxWHITE
;
124 m_pen
= *wxBLACK_PEN
;
125 m_font
= *wxNORMAL_FONT
;
126 m_brush
= *wxTRANSPARENT_BRUSH
;
127 m_backgroundBrush
= *wxWHITE_BRUSH
;
129 // m_palette = wxAPP_COLOURMAP;
136 void wxDC::DestroyClippingRegion(void)
141 void wxDC::GetSize( int* width
, int* height
) const
143 *width
= m_maxX
-m_minX
;
144 *height
= m_maxY
-m_minY
;
147 void wxDC::GetSizeMM( long* width
, long* height
) const
152 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
153 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
156 void wxDC::SetMapMode( int mode
)
161 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
164 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
167 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
170 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
174 SetLogicalScale( 1.0, 1.0 );
177 if (mode
!= wxMM_TEXT
)
179 m_needComputeScaleX
= TRUE
;
180 m_needComputeScaleY
= TRUE
;
184 void wxDC::SetUserScale( double x
, double y
)
186 // allow negative ? -> no
189 ComputeScaleAndOrigin();
192 void wxDC::GetUserScale( double *x
, double *y
)
194 if (x
) *x
= m_userScaleX
;
195 if (y
) *y
= m_userScaleY
;
198 void wxDC::SetLogicalScale( double x
, double y
)
203 ComputeScaleAndOrigin();
206 void wxDC::SetLogicalOrigin( long x
, long y
)
208 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
209 m_logicalOriginY
= y
* m_signY
;
210 ComputeScaleAndOrigin();
213 void wxDC::SetDeviceOrigin( long x
, long y
)
215 m_externalDeviceOriginX
= x
;
216 m_externalDeviceOriginY
= y
;
217 ComputeScaleAndOrigin();
220 void wxDC::SetInternalDeviceOrigin( long x
, long y
)
222 m_internalDeviceOriginX
= x
;
223 m_internalDeviceOriginY
= y
;
224 ComputeScaleAndOrigin();
227 void wxDC::GetInternalDeviceOrigin( long *x
, long *y
)
229 if (x
) *x
= m_internalDeviceOriginX
;
230 if (y
) *y
= m_internalDeviceOriginY
;
233 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
235 m_signX
= (xLeftRight
? 1 : -1);
236 m_signY
= (yBottomUp
? -1 : 1);
237 ComputeScaleAndOrigin();
241 int wxDC::GetDepth() const
247 wxSize
wxDC::GetPPI() const
252 void wxDC::GetTextExtent( const wxString
& string
256 ,long* externalLeading
263 void wxDC::GetCharWidth() const
269 void wxDC::GetCharHeight() const
280 void wxDC::SetFont(const wxFont
& font
)
285 void wxDC::SetPen(const wxPen
& pen
)
289 void wxDC::SetBrush(const wxBrush
& brush
)
294 void wxDC::SetBackground(const wxBrush
& brush
)
299 void wxDC::SetLogicalFunction(int function
)
304 void wxDC::SetBackgroundMode(int mode
)
309 void wxDC::SetPalette(const wxPalette
& palette
)
314 void wxDC::DoFloodFill( long x
317 ,int style
= wxFLOOD_SURFACE
323 bool wxDC::DoGetPixel(long x
, long y
, wxColour
*col
) const
329 void wxDC::DoDrawPoint(long x
, long y
)
334 void wxDC::DoDrawLine(long x1
, long y1
, long x2
, long y2
)
339 void wxDC::DoDrawArc( long x1
, long y1
347 void wxDC::DoDrawEllipticArc( long x
358 void wxDC::DoDrawRectangle(long x
, long y
, long width
, long height
)
363 void wxDC::DoDrawRoundedRectangle( long x
, long y
364 ,long width
, long height
371 void wxDC::DoDrawEllipse(long x
, long y
, long width
, long height
)
376 void wxDC::DoCrossHair(long x
, long y
)
381 void wxDC::DoDrawIcon(const wxIcon
& icon
, long x
, long y
)
386 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
388 ,bool useMask
= FALSE
394 void wxDC::DoDrawText(const wxString
& text
, long x
, long y
)
399 bool wxDC::DoBlit( long xdest
407 ,bool useMask
= FALSE
414 void wxDC::DoGetSize(int *width
, int *height
) const
419 void wxDC::DoGetSizeMM(int* width
, int* height
) const
424 void wxDC::DoDrawLines( int n
, wxPoint points
[]
425 ,long xoffset
, long yoffset
431 void wxDC::DoDrawPolygon(int n
, wxPoint points
[]
432 ,long xoffset
, long yoffset
433 ,int fillStyle
= wxODDEVEN_RULE
439 void wxDC::DoSetClippingRegionAsRegion(const wxRegion
& region
)
444 void wxDC::DoSetClippingRegion( long x
, long y
445 ,long width
, long height
452 void wxDC::DoDrawSpline(wxList
*points
)
461 long wxDC::XDEV2LOG(long x
) const
463 long new_x
= x
- m_deviceOriginX
;
465 return (long)((double)(new_x
) / m_scaleX
+ 0.5) * m_signX
+ m_logicalOriginX
;
467 return (long)((double)(new_x
) / m_scaleX
- 0.5) * m_signX
+ m_logicalOriginX
;
470 long wxDC::XDEV2LOGREL(long x
) const
473 return (long)((double)(x
) / m_scaleX
+ 0.5);
475 return (long)((double)(x
) / m_scaleX
- 0.5);
478 long wxDC::YDEV2LOG(long y
) const
480 long new_y
= y
- m_deviceOriginY
;
482 return (long)((double)(new_y
) / m_scaleY
+ 0.5) * m_signY
+ m_logicalOriginY
;
484 return (long)((double)(new_y
) / m_scaleY
- 0.5) * m_signY
+ m_logicalOriginY
;
487 long wxDC::YDEV2LOGREL(long y
) const
490 return (long)((double)(y
) / m_scaleY
+ 0.5);
492 return (long)((double)(y
) / m_scaleY
- 0.5);
495 long wxDC::XLOG2DEV(long x
) const
497 long new_x
= x
- m_logicalOriginX
;
499 return (long)((double)(new_x
) * m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
;
501 return (long)((double)(new_x
) * m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
;
504 long wxDC::XLOG2DEVREL(long x
) const
507 return (long)((double)(x
) * m_scaleX
+ 0.5);
509 return (long)((double)(x
) * m_scaleX
- 0.5);
512 long wxDC::YLOG2DEV(long y
) const
514 long new_y
= y
- m_logicalOriginY
;
516 return (long)((double)(new_y
) * m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
;
518 return (long)((double)(new_y
) * m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
;
521 long wxDC::YLOG2DEVREL(long y
) const
524 return (long)((double)(y
) * m_scaleY
+ 0.5);
526 return (long)((double)(y
) * m_scaleY
- 0.5);
529 void wxDC::ComputeScaleAndOrigin(void)
531 // CMB: copy scale to see if it changes
532 double origScaleX
= m_scaleX
;
533 double origScaleY
= m_scaleY
;
535 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
536 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
538 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
539 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
541 // CMB: if scale has changed call SetPen to recalulate the line width
542 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
544 // this is a bit artificial, but we need to force wxDC to think
545 // the pen has changed
546 wxPen
* pen
= & GetPen();