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