]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/dc.cpp
minimize overlay area to avoid eg scrolling artifacts when using a caret
[wxWidgets.git] / src / gtk / dc.cpp
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 //-----------------------------------------------------------------------------
16 // wxDC
17 //-----------------------------------------------------------------------------
18
19 IMPLEMENT_ABSTRACT_CLASS(wxDC, wxDCBase)
20
21 wxDC::wxDC()
22 {
23 m_ok = FALSE;
24
25 m_mm_to_pix_x = (double)wxGetDisplaySize().GetWidth() /
26 (double)wxGetDisplaySizeMM().GetWidth();
27 m_mm_to_pix_y = (double)wxGetDisplaySize().GetHeight() /
28 (double)wxGetDisplaySizeMM().GetHeight();
29
30 m_needComputeScaleX = FALSE; /* not used yet */
31 m_needComputeScaleY = FALSE; /* not used yet */
32
33 m_logicalFunction = wxCOPY;
34
35 m_pen = *wxBLACK_PEN;
36 m_font = *wxNORMAL_FONT;
37 m_brush = *wxWHITE_BRUSH;
38 }
39
40 void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height )
41 {
42 m_clipping = TRUE;
43 m_clipX1 = x;
44 m_clipY1 = y;
45 m_clipX2 = x + width;
46 m_clipY2 = y + height;
47 }
48
49 // ---------------------------------------------------------------------------
50 // get DC capabilities
51 // ---------------------------------------------------------------------------
52
53 void wxDC::DoGetSizeMM( int* width, int* height ) const
54 {
55 int w = 0;
56 int h = 0;
57 GetSize( &w, &h );
58 if (width) *width = int( double(w) / (m_userScaleX*m_mm_to_pix_x) );
59 if (height) *height = int( double(h) / (m_userScaleY*m_mm_to_pix_y) );
60 }
61
62 // Resolution in pixels per logical inch
63 wxSize wxDC::GetPPI() const
64 {
65 // TODO (should probably be pure virtual)
66 return wxSize(0, 0);
67 }
68
69 // ---------------------------------------------------------------------------
70 // set various DC parameters
71 // ---------------------------------------------------------------------------
72
73 void wxDC::ComputeScaleAndOrigin()
74 {
75 m_scaleX = m_logicalScaleX * m_userScaleX;
76 m_scaleY = m_logicalScaleY * m_userScaleY;
77 }
78
79 void wxDC::SetMapMode( int mode )
80 {
81 switch (mode)
82 {
83 case wxMM_TWIPS:
84 SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y );
85 break;
86 case wxMM_POINTS:
87 SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y );
88 break;
89 case wxMM_METRIC:
90 SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y );
91 break;
92 case wxMM_LOMETRIC:
93 SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 );
94 break;
95 default:
96 case wxMM_TEXT:
97 SetLogicalScale( 1.0, 1.0 );
98 break;
99 }
100 m_mappingMode = mode;
101
102 /* we don't do this mega optimisation
103 if (mode != wxMM_TEXT)
104 {
105 m_needComputeScaleX = TRUE;
106 m_needComputeScaleY = TRUE;
107 }
108 */
109 }
110
111 void wxDC::SetUserScale( double x, double y )
112 {
113 // allow negative ? -> no
114 m_userScaleX = x;
115 m_userScaleY = y;
116 ComputeScaleAndOrigin();
117 }
118
119 void wxDC::SetLogicalScale( double x, double y )
120 {
121 // allow negative ?
122 m_logicalScaleX = x;
123 m_logicalScaleY = y;
124 ComputeScaleAndOrigin();
125 }
126
127 void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y )
128 {
129 m_logicalOriginX = x * m_signX; // is this still correct ?
130 m_logicalOriginY = y * m_signY;
131 ComputeScaleAndOrigin();
132 }
133
134 void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y )
135 {
136 // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there
137 m_deviceOriginX = x;
138 m_deviceOriginY = y;
139 ComputeScaleAndOrigin();
140 }
141
142 void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
143 {
144 // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there
145 m_signX = (xLeftRight ? 1 : -1);
146 m_signY = (yBottomUp ? -1 : 1);
147 ComputeScaleAndOrigin();
148 }