1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2006 REA Elektronik GmbH
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
15 #include "wx/region.h"
16 #include "wx/dfb/ifacehelpers.h"
18 wxDFB_DECLARE_INTERFACE(IDirectFBSurface
);
20 //-----------------------------------------------------------------------------
22 //-----------------------------------------------------------------------------
24 class WXDLLIMPEXP_CORE wxDC
: public wxDCBase
30 // Takes ownership of the surface, i.e. does not call AddRef() on it
31 // but calls Release() on it from dtor.
32 wxDC(const IDirectFBSurfacePtr
& surface
);
35 // implement base class pure virtuals
36 // ----------------------------------
40 virtual bool StartDoc(const wxString
& message
);
41 virtual void EndDoc();
43 virtual void StartPage();
44 virtual void EndPage();
46 virtual void SetFont(const wxFont
& font
);
47 virtual void SetPen(const wxPen
& pen
);
48 virtual void SetBrush(const wxBrush
& brush
);
49 virtual void SetBackground(const wxBrush
& brush
);
50 virtual void SetBackgroundMode(int mode
);
52 virtual void SetPalette(const wxPalette
& palette
);
55 virtual void DestroyClippingRegion();
57 virtual wxCoord
GetCharHeight() const;
58 virtual wxCoord
GetCharWidth() const;
59 virtual void DoGetTextExtent(const wxString
& string
,
60 wxCoord
*x
, wxCoord
*y
,
61 wxCoord
*descent
= NULL
,
62 wxCoord
*externalLeading
= NULL
,
63 wxFont
*theFont
= NULL
) const;
65 virtual bool CanDrawBitmap() const { return true; }
66 virtual bool CanGetTextExtent() const { return true; }
67 virtual int GetDepth() const;
68 virtual wxSize
GetPPI() const;
70 virtual void SetMapMode(int mode
);
71 virtual void SetUserScale(double x
, double y
);
72 virtual void SetLogicalScale(double x
, double y
);
73 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
);
74 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
);
75 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
76 virtual void SetLogicalFunction(int function
);
78 // implementation from now on
79 // --------------------------
81 virtual void ComputeScaleAndOrigin();
83 wxCoord
XDEV2LOG(wxCoord x
) const
85 wxCoord new_x
= x
- m_deviceOriginX
;
87 return (wxCoord
)((double)(new_x
) / m_scaleX
+ 0.5) * m_signX
+ m_logicalOriginX
;
89 return (wxCoord
)((double)(new_x
) / m_scaleX
- 0.5) * m_signX
+ m_logicalOriginX
;
91 wxCoord
XDEV2LOGREL(wxCoord x
) const
94 return (wxCoord
)((double)(x
) / m_scaleX
+ 0.5);
96 return (wxCoord
)((double)(x
) / m_scaleX
- 0.5);
98 wxCoord
YDEV2LOG(wxCoord y
) const
100 wxCoord new_y
= y
- m_deviceOriginY
;
102 return (wxCoord
)((double)(new_y
) / m_scaleY
+ 0.5) * m_signY
+ m_logicalOriginY
;
104 return (wxCoord
)((double)(new_y
) / m_scaleY
- 0.5) * m_signY
+ m_logicalOriginY
;
106 wxCoord
YDEV2LOGREL(wxCoord y
) const
109 return (wxCoord
)((double)(y
) / m_scaleY
+ 0.5);
111 return (wxCoord
)((double)(y
) / m_scaleY
- 0.5);
113 wxCoord
XLOG2DEV(wxCoord x
) const
115 wxCoord new_x
= x
- m_logicalOriginX
;
117 return (wxCoord
)((double)(new_x
) * m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
;
119 return (wxCoord
)((double)(new_x
) * m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
;
121 wxCoord
XLOG2DEVREL(wxCoord x
) const
124 return (wxCoord
)((double)(x
) * m_scaleX
+ 0.5);
126 return (wxCoord
)((double)(x
) * m_scaleX
- 0.5);
128 wxCoord
YLOG2DEV(wxCoord y
) const
130 wxCoord new_y
= y
- m_logicalOriginY
;
132 return (wxCoord
)((double)(new_y
) * m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
;
134 return (wxCoord
)((double)(new_y
) * m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
;
136 wxCoord
YLOG2DEVREL(wxCoord y
) const
139 return (wxCoord
)((double)(y
) * m_scaleY
+ 0.5);
141 return (wxCoord
)((double)(y
) * m_scaleY
- 0.5);
144 // Returns the surface (and increases its ref count)
145 IDirectFBSurfacePtr
GetDirectFBSurface() const { return m_surface
; }
148 // initializes the DC from a surface, must be called if default ctor
150 void Init(const IDirectFBSurfacePtr
& surface
);
152 virtual bool DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
153 int style
= wxFLOOD_SURFACE
);
155 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const;
157 virtual void DoDrawPoint(wxCoord x
, wxCoord y
);
158 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
160 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
161 wxCoord x2
, wxCoord y2
,
162 wxCoord xc
, wxCoord yc
);
163 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
164 double sa
, double ea
);
166 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
167 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
168 wxCoord width
, wxCoord height
,
170 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
172 virtual void DoCrossHair(wxCoord x
, wxCoord y
);
174 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
);
175 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
176 bool useMask
= false);
178 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
179 virtual void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
182 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
183 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
184 int rop
= wxCOPY
, bool useMask
= false, wxCoord xsrcMask
= -1, wxCoord ysrcMask
= -1);
186 // this is gnarly - we can't even call this function DoSetClippingRegion()
187 // because of virtual function hiding
188 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
);
189 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
190 wxCoord width
, wxCoord height
);
192 virtual void DoGetSize(int *width
, int *height
) const;
193 virtual void DoGetSizeMM(int* width
, int* height
) const;
195 virtual void DoDrawLines(int n
, wxPoint points
[],
196 wxCoord xoffset
, wxCoord yoffset
);
197 virtual void DoDrawPolygon(int n
, wxPoint points
[],
198 wxCoord xoffset
, wxCoord yoffset
,
199 int fillStyle
= wxODDEVEN_RULE
);
201 // implementation from now on:
204 // Unified implementation of DrawIcon, DrawBitmap and Blit:
205 void DoDrawSubBitmap(const wxBitmap
&bmp
,
206 wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
207 wxCoord destx
, wxCoord desty
, int rop
, bool useMask
);
209 // selects colour into surface's state
210 void SelectColour(const wxColour
& clr
);
213 IDirectFBSurfacePtr m_surface
;
215 double m_mm_to_pix_x
, m_mm_to_pix_y
;
217 DECLARE_DYNAMIC_CLASS(wxDC
)
220 #endif // _WX_DFB_DC_H_