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