]>
Commit | Line | Data |
---|---|---|
6fea499c | 1 | ///////////////////////////////////////////////////////////////////////////// |
e0876d73 | 2 | // Name: src/msw/graphics.cpp |
6fea499c SC |
3 | // Purpose: wxGCDC class |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
e0876d73 | 6 | // Created: 2006-09-30 |
6fea499c | 7 | // RCS-ID: $Id$ |
e0876d73 | 8 | // Copyright: (c) 2006 Stefan Csomor |
6fea499c SC |
9 | // Licence: wxWindows licence |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #include "wx/wxprec.h" | |
13 | ||
6fea499c | 14 | #ifdef __BORLANDC__ |
b4715d08 | 15 | #pragma hdrstop |
6fea499c SC |
16 | #endif |
17 | ||
b4715d08 VZ |
18 | #include "wx/dc.h" |
19 | ||
0024ec50 VZ |
20 | #if wxUSE_GRAPHICS_CONTEXT |
21 | ||
6fea499c | 22 | #ifndef WX_PRECOMP |
bdba6fdc VZ |
23 | #include "wx/msw/wrapcdlg.h" |
24 | #include "wx/image.h" | |
25 | #include "wx/window.h" | |
bdba6fdc VZ |
26 | #include "wx/utils.h" |
27 | #include "wx/dialog.h" | |
28 | #include "wx/app.h" | |
29 | #include "wx/bitmap.h" | |
bdba6fdc VZ |
30 | #include "wx/log.h" |
31 | #include "wx/icon.h" | |
bdba6fdc | 32 | #include "wx/module.h" |
f772729b SC |
33 | // include all dc types that are used as a param |
34 | #include "wx/dc.h" | |
35 | #include "wx/dcclient.h" | |
36 | #include "wx/dcmemory.h" | |
37 | #include "wx/dcprint.h" | |
6fea499c SC |
38 | #endif |
39 | ||
623cf1fa | 40 | #include "wx/private/graphics.h" |
bdba6fdc | 41 | #include "wx/msw/wrapgdip.h" |
bce28872 | 42 | #include "wx/msw/dc.h" |
c929ad91 VZ |
43 | #if wxUSE_ENH_METAFILE |
44 | #include "wx/msw/enhmeta.h" | |
45 | #endif | |
7fa3cf6a | 46 | #include "wx/dcgraph.h" |
6fea499c | 47 | |
f49c80c1 VZ |
48 | #include "wx/msw/private.h" // needs to be before #include <commdlg.h> |
49 | ||
50 | #if wxUSE_COMMON_DIALOGS && !defined(__WXMICROWIN__) | |
51 | #include <commdlg.h> | |
52 | #endif | |
53 | ||
bdba6fdc | 54 | #include "wx/stack.h" |
6fea499c | 55 | |
bdba6fdc | 56 | WX_DECLARE_STACK(GraphicsState, GraphicsStates); |
0024ec50 | 57 | |
f49c80c1 VZ |
58 | namespace |
59 | { | |
60 | ||
6fea499c SC |
61 | //----------------------------------------------------------------------------- |
62 | // constants | |
63 | //----------------------------------------------------------------------------- | |
64 | ||
65 | const double RAD2DEG = 180.0 / M_PI; | |
66 | ||
67 | //----------------------------------------------------------------------------- | |
68 | // Local functions | |
69 | //----------------------------------------------------------------------------- | |
70 | ||
f49c80c1 VZ |
71 | inline double dmin(double a, double b) { return a < b ? a : b; } |
72 | inline double dmax(double a, double b) { return a > b ? a : b; } | |
73 | ||
74 | inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; } | |
75 | inline double RadToDeg(double deg) { return (deg * 180.0) / M_PI; } | |
6fea499c | 76 | |
f49c80c1 VZ |
77 | // translate a wxColour to a Color |
78 | inline Color wxColourToColor(const wxColour& col) | |
79 | { | |
80 | return Color(col.Alpha(), col.Red(), col.Green(), col.Blue()); | |
81 | } | |
82 | ||
83 | } // anonymous namespace | |
6fea499c SC |
84 | |
85 | //----------------------------------------------------------------------------- | |
86 | // device context implementation | |
87 | // | |
88 | // more and more of the dc functionality should be implemented by calling | |
89 | // the appropricate wxGDIPlusContext, but we will have to do that step by step | |
90 | // also coordinate conversions should be moved to native matrix ops | |
91 | //----------------------------------------------------------------------------- | |
92 | ||
93 | // we always stock two context states, one at entry, to be able to preserve the | |
94 | // state we were called with, the other one after changing to HI Graphics orientation | |
95 | // (this one is used for getting back clippings etc) | |
96 | ||
97 | //----------------------------------------------------------------------------- | |
98 | // wxGraphicsPath implementation | |
99 | //----------------------------------------------------------------------------- | |
100 | ||
eb4083ef | 101 | class wxGDIPlusPathData : public wxGraphicsPathData |
6fea499c | 102 | { |
6fea499c | 103 | public : |
a4e73390 SC |
104 | wxGDIPlusPathData(wxGraphicsRenderer* renderer, GraphicsPath* path = NULL); |
105 | ~wxGDIPlusPathData(); | |
6fea499c | 106 | |
a4e73390 | 107 | virtual wxGraphicsObjectRefData *Clone() const; |
6fea499c SC |
108 | |
109 | // | |
110 | // These are the path primitives from which everything else can be constructed | |
111 | // | |
112 | ||
113 | // begins a new subpath at (x,y) | |
114 | virtual void MoveToPoint( wxDouble x, wxDouble y ); | |
115 | ||
cb3a0d42 | 116 | // adds a straight line from the current point to (x,y) |
6fea499c SC |
117 | virtual void AddLineToPoint( wxDouble x, wxDouble y ); |
118 | ||
119 | // adds a cubic Bezier curve from the current point, using two control points and an end point | |
120 | virtual void AddCurveToPoint( wxDouble cx1, wxDouble cy1, wxDouble cx2, wxDouble cy2, wxDouble x, wxDouble y ); | |
121 | ||
122 | ||
cb3a0d42 | 123 | // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle |
6fea499c SC |
124 | virtual void AddArc( wxDouble x, wxDouble y, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise ) ; |
125 | ||
126 | // gets the last point of the current path, (0,0) if not yet set | |
a4e73390 | 127 | virtual void GetCurrentPoint( wxDouble* x, wxDouble* y) const; |
6fea499c | 128 | |
83576e68 | 129 | // adds another path |
a4e73390 | 130 | virtual void AddPath( const wxGraphicsPathData* path ); |
83576e68 | 131 | |
6fea499c SC |
132 | // closes the current sub-path |
133 | virtual void CloseSubpath(); | |
134 | ||
135 | // | |
cb3a0d42 | 136 | // These are convenience functions which - if not available natively will be assembled |
6fea499c SC |
137 | // using the primitives from above |
138 | // | |
139 | ||
cb3a0d42 | 140 | // appends a rectangle as a new closed subpath |
6fea499c SC |
141 | virtual void AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h ) ; |
142 | /* | |
143 | ||
144 | // appends an ellipsis as a new closed subpath fitting the passed rectangle | |
145 | virtual void AddEllipsis( wxDouble x, wxDouble y, wxDouble w , wxDouble h ) ; | |
146 | ||
147 | // draws a an arc to two tangents connecting (current) to (x1,y1) and (x1,y1) to (x2,y2), also a straight line from (current) to (x1,y1) | |
148 | virtual void AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) ; | |
149 | */ | |
150 | ||
cb3a0d42 VZ |
151 | // returns the native path |
152 | virtual void * GetNativePath() const { return m_path; } | |
153 | ||
154 | // give the native path returned by GetNativePath() back (there might be some deallocations necessary) | |
155 | virtual void UnGetNativePath(void * WXUNUSED(path)) const {} | |
f540e5bd | 156 | |
83576e68 | 157 | // transforms each point of this path by the matrix |
a4e73390 | 158 | virtual void Transform( const wxGraphicsMatrixData* matrix ) ; |
83576e68 SC |
159 | |
160 | // gets the bounding box enclosing all points (possibly including control points) | |
a4e73390 | 161 | virtual void GetBox(wxDouble *x, wxDouble *y, wxDouble *w, wxDouble *h) const; |
83576e68 | 162 | |
94a007ec | 163 | virtual bool Contains( wxDouble x, wxDouble y, wxPolygonFillMode fillStyle = wxODDEVEN_RULE) const; |
83576e68 | 164 | |
6fea499c SC |
165 | private : |
166 | GraphicsPath* m_path; | |
167 | }; | |
168 | ||
eb4083ef | 169 | class wxGDIPlusMatrixData : public wxGraphicsMatrixData |
83576e68 SC |
170 | { |
171 | public : | |
a4e73390 SC |
172 | wxGDIPlusMatrixData(wxGraphicsRenderer* renderer, Matrix* matrix = NULL) ; |
173 | virtual ~wxGDIPlusMatrixData() ; | |
83576e68 | 174 | |
a4e73390 | 175 | virtual wxGraphicsObjectRefData* Clone() const ; |
83576e68 SC |
176 | |
177 | // concatenates the matrix | |
a4e73390 | 178 | virtual void Concat( const wxGraphicsMatrixData *t ); |
83576e68 SC |
179 | |
180 | // sets the matrix to the respective values | |
cb3a0d42 | 181 | virtual void Set(wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0, |
83576e68 SC |
182 | wxDouble tx=0.0, wxDouble ty=0.0); |
183 | ||
248802d0 RD |
184 | // gets the component valuess of the matrix |
185 | virtual void Get(wxDouble* a=NULL, wxDouble* b=NULL, wxDouble* c=NULL, | |
186 | wxDouble* d=NULL, wxDouble* tx=NULL, wxDouble* ty=NULL) const; | |
f4322df6 | 187 | |
83576e68 SC |
188 | // makes this the inverse matrix |
189 | virtual void Invert(); | |
190 | ||
191 | // returns true if the elements of the transformation matrix are equal ? | |
a4e73390 | 192 | virtual bool IsEqual( const wxGraphicsMatrixData* t) const ; |
83576e68 SC |
193 | |
194 | // return true if this is the identity matrix | |
a4e73390 | 195 | virtual bool IsIdentity() const; |
83576e68 SC |
196 | |
197 | // | |
198 | // transformation | |
199 | // | |
200 | ||
201 | // add the translation to this matrix | |
202 | virtual void Translate( wxDouble dx , wxDouble dy ); | |
203 | ||
204 | // add the scale to this matrix | |
205 | virtual void Scale( wxDouble xScale , wxDouble yScale ); | |
206 | ||
207 | // add the rotation to this matrix (radians) | |
cb3a0d42 | 208 | virtual void Rotate( wxDouble angle ); |
83576e68 SC |
209 | |
210 | // | |
211 | // apply the transforms | |
212 | // | |
213 | ||
214 | // applies that matrix to the point | |
a4e73390 | 215 | virtual void TransformPoint( wxDouble *x, wxDouble *y ) const; |
83576e68 SC |
216 | |
217 | // applies the matrix except for translations | |
a4e73390 | 218 | virtual void TransformDistance( wxDouble *dx, wxDouble *dy ) const; |
83576e68 SC |
219 | |
220 | // returns the native representation | |
221 | virtual void * GetNativeMatrix() const; | |
222 | private: | |
223 | Matrix* m_matrix ; | |
83576e68 SC |
224 | } ; |
225 | ||
eb4083ef | 226 | class wxGDIPlusPenData : public wxGraphicsObjectRefData |
83576e68 SC |
227 | { |
228 | public: | |
2c820406 SC |
229 | wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxPen &pen ); |
230 | ~wxGDIPlusPenData(); | |
83576e68 SC |
231 | |
232 | void Init(); | |
233 | ||
83576e68 SC |
234 | virtual wxDouble GetWidth() { return m_width; } |
235 | virtual Pen* GetGDIPlusPen() { return m_pen; } | |
236 | ||
237 | protected : | |
238 | Pen* m_pen; | |
239 | Image* m_penImage; | |
240 | Brush* m_penBrush; | |
241 | ||
242 | wxDouble m_width; | |
83576e68 SC |
243 | }; |
244 | ||
eb4083ef | 245 | class wxGDIPlusBrushData : public wxGraphicsObjectRefData |
83576e68 SC |
246 | { |
247 | public: | |
2c820406 SC |
248 | wxGDIPlusBrushData( wxGraphicsRenderer* renderer ); |
249 | wxGDIPlusBrushData( wxGraphicsRenderer* renderer, const wxBrush &brush ); | |
250 | ~wxGDIPlusBrushData (); | |
83576e68 | 251 | |
4ee4c7b9 VZ |
252 | void CreateLinearGradientBrush(wxDouble x1, wxDouble y1, |
253 | wxDouble x2, wxDouble y2, | |
254 | const wxGraphicsGradientStops& stops); | |
255 | void CreateRadialGradientBrush(wxDouble xo, wxDouble yo, | |
256 | wxDouble xc, wxDouble yc, | |
257 | wxDouble radius, | |
258 | const wxGraphicsGradientStops& stops); | |
259 | ||
83576e68 SC |
260 | virtual Brush* GetGDIPlusBrush() { return m_brush; } |
261 | ||
262 | protected: | |
263 | virtual void Init(); | |
264 | ||
4ee4c7b9 VZ |
265 | private: |
266 | // common part of Create{Linear,Radial}GradientBrush() | |
267 | template <typename T> | |
268 | void SetGradientStops(T *brush, const wxGraphicsGradientStops& stops); | |
269 | ||
83576e68 SC |
270 | Brush* m_brush; |
271 | Image* m_brushImage; | |
272 | GraphicsPath* m_brushPath; | |
83576e68 SC |
273 | }; |
274 | ||
bce28872 SC |
275 | class WXDLLIMPEXP_CORE wxGDIPlusBitmapData : public wxGraphicsObjectRefData |
276 | { | |
277 | public: | |
278 | wxGDIPlusBitmapData( wxGraphicsRenderer* renderer, Bitmap* bitmap ); | |
279 | wxGDIPlusBitmapData( wxGraphicsRenderer* renderer, const wxBitmap &bmp ); | |
280 | ~wxGDIPlusBitmapData (); | |
281 | ||
282 | virtual Bitmap* GetGDIPlusBitmap() { return m_bitmap; } | |
283 | ||
284 | private : | |
285 | Bitmap* m_bitmap; | |
286 | Bitmap* m_helper; | |
287 | }; | |
288 | ||
eb4083ef | 289 | class wxGDIPlusFontData : public wxGraphicsObjectRefData |
83576e68 SC |
290 | { |
291 | public: | |
7fa3cf6a | 292 | wxGDIPlusFontData( wxGraphicsRenderer* renderer, const wxFont &font, const wxColour& col ); |
2c820406 | 293 | ~wxGDIPlusFontData(); |
83576e68 | 294 | |
83576e68 SC |
295 | virtual Brush* GetGDIPlusBrush() { return m_textBrush; } |
296 | virtual Font* GetGDIPlusFont() { return m_font; } | |
297 | private : | |
298 | Brush* m_textBrush; | |
299 | Font* m_font; | |
83576e68 SC |
300 | }; |
301 | ||
eb4083ef | 302 | class wxGDIPlusContext : public wxGraphicsContext |
6fea499c | 303 | { |
6fea499c | 304 | public: |
7fa3cf6a | 305 | wxGDIPlusContext( wxGraphicsRenderer* renderer, HDC hdc , wxDouble width, wxDouble height ); |
83576e68 SC |
306 | wxGDIPlusContext( wxGraphicsRenderer* renderer, HWND hwnd ); |
307 | wxGDIPlusContext( wxGraphicsRenderer* renderer, Graphics* gr); | |
6fea499c | 308 | wxGDIPlusContext(); |
9f339b18 | 309 | |
6fea499c SC |
310 | virtual ~wxGDIPlusContext(); |
311 | ||
312 | virtual void Clip( const wxRegion ®ion ); | |
539e2795 SC |
313 | // clips drawings to the rect |
314 | virtual void Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h ); | |
539e2795 | 315 | |
cb3a0d42 VZ |
316 | // resets the clipping to original extent |
317 | virtual void ResetClip(); | |
318 | ||
319 | virtual void * GetNativeContext(); | |
320 | ||
a4e73390 | 321 | virtual void StrokePath( const wxGraphicsPath& p ); |
94a007ec | 322 | virtual void FillPath( const wxGraphicsPath& p , wxPolygonFillMode fillStyle = wxODDEVEN_RULE ); |
6fea499c | 323 | |
03647350 | 324 | // stroke lines connecting each of the points |
0c7bd159 SC |
325 | virtual void StrokeLines( size_t n, const wxPoint2DDouble *points); |
326 | ||
327 | // draws a polygon | |
94a007ec | 328 | virtual void DrawLines( size_t n, const wxPoint2DDouble *points, wxPolygonFillMode fillStyle = wxODDEVEN_RULE ); |
0c7bd159 | 329 | |
bf02a7f9 SC |
330 | virtual bool SetAntialiasMode(wxAntialiasMode antialias); |
331 | ||
332 | virtual bool SetCompositionMode(wxCompositionMode op); | |
333 | ||
334 | virtual void BeginLayer(wxDouble opacity); | |
335 | ||
336 | virtual void EndLayer(); | |
03647350 | 337 | |
cb3a0d42 VZ |
338 | virtual void Translate( wxDouble dx , wxDouble dy ); |
339 | virtual void Scale( wxDouble xScale , wxDouble yScale ); | |
340 | virtual void Rotate( wxDouble angle ); | |
6fea499c | 341 | |
83576e68 | 342 | // concatenates this transform with the current transform of this context |
a4e73390 | 343 | virtual void ConcatTransform( const wxGraphicsMatrix& matrix ); |
83576e68 SC |
344 | |
345 | // sets the transform of this context | |
a4e73390 | 346 | virtual void SetTransform( const wxGraphicsMatrix& matrix ); |
83576e68 SC |
347 | |
348 | // gets the matrix of this context | |
a4e73390 | 349 | virtual wxGraphicsMatrix GetTransform() const; |
83576e68 | 350 | |
bce28872 | 351 | virtual void DrawBitmap( const wxGraphicsBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ); |
6fea499c SC |
352 | virtual void DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ); |
353 | virtual void DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h ); | |
cb3a0d42 | 354 | virtual void PushState(); |
6fea499c SC |
355 | virtual void PopState(); |
356 | ||
6fea499c SC |
357 | virtual void GetTextExtent( const wxString &str, wxDouble *width, wxDouble *height, |
358 | wxDouble *descent, wxDouble *externalLeading ) const; | |
359 | virtual void GetPartialTextExtents(const wxString& text, wxArrayDouble& widths) const; | |
d9485f89 | 360 | virtual bool ShouldOffset() const; |
fbd5416f | 361 | virtual void GetSize( wxDouble* width, wxDouble *height ); |
6fea499c SC |
362 | |
363 | private: | |
9f339b18 SC |
364 | void Init(); |
365 | void SetDefaults(); | |
366 | ||
0b7dce54 VZ |
367 | virtual void DoDrawText(const wxString& str, wxDouble x, wxDouble y) |
368 | { DoDrawFilledText(str, x, y, wxNullGraphicsBrush); } | |
369 | virtual void DoDrawFilledText(const wxString& str, wxDouble x, wxDouble y, | |
370 | const wxGraphicsBrush& backgroundBrush); | |
371 | ||
83576e68 | 372 | Graphics* m_context; |
bdba6fdc | 373 | GraphicsStates m_stateStack; |
83576e68 SC |
374 | GraphicsState m_state1; |
375 | GraphicsState m_state2; | |
376 | ||
81e0b3d9 SC |
377 | wxDouble m_width; |
378 | wxDouble m_height; | |
379 | ||
83576e68 SC |
380 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxGDIPlusContext) |
381 | }; | |
382 | ||
5aac6f3f | 383 | class wxGDIPlusMeasuringContext : public wxGDIPlusContext |
0c7bd159 SC |
384 | { |
385 | public: | |
81e0b3d9 | 386 | wxGDIPlusMeasuringContext( wxGraphicsRenderer* renderer ) : wxGDIPlusContext( renderer , m_hdc = GetDC(NULL), 1000, 1000 ) |
0c7bd159 SC |
387 | { |
388 | } | |
389 | wxGDIPlusMeasuringContext() | |
390 | { | |
391 | } | |
392 | ||
393 | virtual ~wxGDIPlusMeasuringContext() | |
394 | { | |
395 | ReleaseDC( NULL, m_hdc ); | |
396 | } | |
397 | ||
398 | private: | |
7fa3cf6a | 399 | HDC m_hdc ; |
0c7bd159 SC |
400 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxGDIPlusMeasuringContext) |
401 | } ; | |
402 | ||
83576e68 SC |
403 | //----------------------------------------------------------------------------- |
404 | // wxGDIPlusPen implementation | |
405 | //----------------------------------------------------------------------------- | |
406 | ||
2c820406 | 407 | wxGDIPlusPenData::~wxGDIPlusPenData() |
83576e68 SC |
408 | { |
409 | delete m_pen; | |
410 | delete m_penImage; | |
411 | delete m_penBrush; | |
412 | } | |
413 | ||
2c820406 | 414 | void wxGDIPlusPenData::Init() |
83576e68 SC |
415 | { |
416 | m_pen = NULL ; | |
417 | m_penImage = NULL; | |
418 | m_penBrush = NULL; | |
419 | } | |
420 | ||
2c820406 SC |
421 | wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxPen &pen ) |
422 | : wxGraphicsObjectRefData(renderer) | |
cb3a0d42 | 423 | { |
83576e68 SC |
424 | Init(); |
425 | m_width = pen.GetWidth(); | |
426 | if (m_width <= 0.0) | |
427 | m_width = 0.1; | |
428 | ||
f49c80c1 | 429 | m_pen = new Pen(wxColourToColor(pen.GetColour()), m_width ); |
83576e68 SC |
430 | |
431 | LineCap cap; | |
432 | switch ( pen.GetCap() ) | |
433 | { | |
434 | case wxCAP_ROUND : | |
435 | cap = LineCapRound; | |
436 | break; | |
437 | ||
438 | case wxCAP_PROJECTING : | |
439 | cap = LineCapSquare; | |
440 | break; | |
441 | ||
442 | case wxCAP_BUTT : | |
443 | cap = LineCapFlat; // TODO verify | |
444 | break; | |
445 | ||
446 | default : | |
447 | cap = LineCapFlat; | |
448 | break; | |
449 | } | |
450 | m_pen->SetLineCap(cap,cap, DashCapFlat); | |
451 | ||
452 | LineJoin join; | |
453 | switch ( pen.GetJoin() ) | |
454 | { | |
455 | case wxJOIN_BEVEL : | |
456 | join = LineJoinBevel; | |
457 | break; | |
458 | ||
459 | case wxJOIN_MITER : | |
460 | join = LineJoinMiter; | |
461 | break; | |
462 | ||
463 | case wxJOIN_ROUND : | |
464 | join = LineJoinRound; | |
465 | break; | |
466 | ||
467 | default : | |
468 | join = LineJoinMiter; | |
469 | break; | |
470 | } | |
471 | ||
472 | m_pen->SetLineJoin(join); | |
473 | ||
474 | m_pen->SetDashStyle(DashStyleSolid); | |
475 | ||
476 | DashStyle dashStyle = DashStyleSolid; | |
477 | switch ( pen.GetStyle() ) | |
478 | { | |
479 | case wxSOLID : | |
480 | break; | |
481 | ||
482 | case wxDOT : | |
483 | dashStyle = DashStyleDot; | |
484 | break; | |
485 | ||
486 | case wxLONG_DASH : | |
487 | dashStyle = DashStyleDash; // TODO verify | |
488 | break; | |
489 | ||
490 | case wxSHORT_DASH : | |
491 | dashStyle = DashStyleDash; | |
492 | break; | |
493 | ||
494 | case wxDOT_DASH : | |
495 | dashStyle = DashStyleDashDot; | |
496 | break; | |
497 | case wxUSER_DASH : | |
498 | { | |
499 | dashStyle = DashStyleCustom; | |
500 | wxDash *dashes; | |
501 | int count = pen.GetDashes( &dashes ); | |
502 | if ((dashes != NULL) && (count > 0)) | |
503 | { | |
504 | REAL *userLengths = new REAL[count]; | |
505 | for ( int i = 0; i < count; ++i ) | |
506 | { | |
507 | userLengths[i] = dashes[i]; | |
508 | } | |
509 | m_pen->SetDashPattern( userLengths, count); | |
510 | delete[] userLengths; | |
511 | } | |
512 | } | |
513 | break; | |
514 | case wxSTIPPLE : | |
515 | { | |
516 | wxBitmap* bmp = pen.GetStipple(); | |
517 | if ( bmp && bmp->Ok() ) | |
518 | { | |
e38f5435 DS |
519 | m_penImage = Bitmap::FromHBITMAP((HBITMAP)bmp->GetHBITMAP(), |
520 | #if wxUSE_PALETTE | |
521 | (HPALETTE)bmp->GetPalette()->GetHPALETTE() | |
522 | #else | |
523 | NULL | |
524 | #endif | |
525 | ); | |
83576e68 SC |
526 | m_penBrush = new TextureBrush(m_penImage); |
527 | m_pen->SetBrush( m_penBrush ); | |
528 | } | |
529 | ||
530 | } | |
531 | break; | |
532 | default : | |
533 | if ( pen.GetStyle() >= wxFIRST_HATCH && pen.GetStyle() <= wxLAST_HATCH ) | |
534 | { | |
535 | HatchStyle style = HatchStyleHorizontal; | |
536 | switch( pen.GetStyle() ) | |
537 | { | |
538 | case wxBDIAGONAL_HATCH : | |
539 | style = HatchStyleBackwardDiagonal; | |
540 | break ; | |
541 | case wxCROSSDIAG_HATCH : | |
542 | style = HatchStyleDiagonalCross; | |
543 | break ; | |
544 | case wxFDIAGONAL_HATCH : | |
545 | style = HatchStyleForwardDiagonal; | |
546 | break ; | |
547 | case wxCROSS_HATCH : | |
548 | style = HatchStyleCross; | |
549 | break ; | |
550 | case wxHORIZONTAL_HATCH : | |
551 | style = HatchStyleHorizontal; | |
552 | break ; | |
553 | case wxVERTICAL_HATCH : | |
554 | style = HatchStyleVertical; | |
555 | break ; | |
556 | ||
557 | } | |
f49c80c1 VZ |
558 | m_penBrush = new HatchBrush |
559 | ( | |
560 | style, | |
561 | wxColourToColor(pen.GetColour()), | |
562 | Color::Transparent | |
563 | ); | |
83576e68 SC |
564 | m_pen->SetBrush( m_penBrush ); |
565 | } | |
566 | break; | |
cb3a0d42 | 567 | } |
83576e68 SC |
568 | if ( dashStyle != DashStyleSolid ) |
569 | m_pen->SetDashStyle(dashStyle); | |
570 | } | |
571 | ||
83576e68 SC |
572 | //----------------------------------------------------------------------------- |
573 | // wxGDIPlusBrush implementation | |
574 | //----------------------------------------------------------------------------- | |
575 | ||
2c820406 SC |
576 | wxGDIPlusBrushData::wxGDIPlusBrushData( wxGraphicsRenderer* renderer ) |
577 | : wxGraphicsObjectRefData(renderer) | |
83576e68 SC |
578 | { |
579 | Init(); | |
580 | } | |
581 | ||
2c820406 SC |
582 | wxGDIPlusBrushData::wxGDIPlusBrushData( wxGraphicsRenderer* renderer , const wxBrush &brush ) |
583 | : wxGraphicsObjectRefData(renderer) | |
83576e68 SC |
584 | { |
585 | Init(); | |
586 | if ( brush.GetStyle() == wxSOLID) | |
587 | { | |
f49c80c1 | 588 | m_brush = new SolidBrush(wxColourToColor( brush.GetColour())); |
83576e68 SC |
589 | } |
590 | else if ( brush.IsHatch() ) | |
591 | { | |
592 | HatchStyle style = HatchStyleHorizontal; | |
593 | switch( brush.GetStyle() ) | |
594 | { | |
595 | case wxBDIAGONAL_HATCH : | |
596 | style = HatchStyleBackwardDiagonal; | |
597 | break ; | |
598 | case wxCROSSDIAG_HATCH : | |
599 | style = HatchStyleDiagonalCross; | |
600 | break ; | |
601 | case wxFDIAGONAL_HATCH : | |
602 | style = HatchStyleForwardDiagonal; | |
603 | break ; | |
604 | case wxCROSS_HATCH : | |
605 | style = HatchStyleCross; | |
606 | break ; | |
607 | case wxHORIZONTAL_HATCH : | |
608 | style = HatchStyleHorizontal; | |
609 | break ; | |
610 | case wxVERTICAL_HATCH : | |
611 | style = HatchStyleVertical; | |
612 | break ; | |
613 | ||
614 | } | |
f49c80c1 VZ |
615 | m_brush = new HatchBrush |
616 | ( | |
617 | style, | |
618 | wxColourToColor(brush.GetColour()), | |
619 | Color::Transparent | |
620 | ); | |
83576e68 | 621 | } |
cb3a0d42 | 622 | else |
83576e68 SC |
623 | { |
624 | wxBitmap* bmp = brush.GetStipple(); | |
625 | if ( bmp && bmp->Ok() ) | |
626 | { | |
627 | wxDELETE( m_brushImage ); | |
e38f5435 DS |
628 | m_brushImage = Bitmap::FromHBITMAP((HBITMAP)bmp->GetHBITMAP(), |
629 | #if wxUSE_PALETTE | |
630 | (HPALETTE)bmp->GetPalette()->GetHPALETTE() | |
631 | #else | |
632 | NULL | |
633 | #endif | |
634 | ); | |
83576e68 SC |
635 | m_brush = new TextureBrush(m_brushImage); |
636 | } | |
637 | } | |
638 | } | |
639 | ||
2c820406 | 640 | wxGDIPlusBrushData::~wxGDIPlusBrushData() |
83576e68 SC |
641 | { |
642 | delete m_brush; | |
643 | delete m_brushImage; | |
644 | delete m_brushPath; | |
645 | }; | |
646 | ||
2c820406 | 647 | void wxGDIPlusBrushData::Init() |
83576e68 SC |
648 | { |
649 | m_brush = NULL; | |
650 | m_brushImage= NULL; | |
651 | m_brushPath= NULL; | |
652 | } | |
653 | ||
4ee4c7b9 VZ |
654 | template <typename T> |
655 | void | |
656 | wxGDIPlusBrushData::SetGradientStops(T *brush, | |
657 | const wxGraphicsGradientStops& stops) | |
658 | { | |
659 | const unsigned numStops = stops.GetCount(); | |
660 | if ( numStops <= 2 ) | |
661 | { | |
662 | // initial and final colours are set during the brush creation, nothing | |
663 | // more to do | |
664 | return; | |
665 | } | |
666 | ||
667 | wxVector<Color> colors(numStops); | |
668 | wxVector<REAL> positions(numStops); | |
669 | ||
670 | for ( unsigned i = 0; i < numStops; i++ ) | |
671 | { | |
672 | wxGraphicsGradientStop stop = stops.Item(i); | |
673 | ||
674 | colors[i] = wxColourToColor(stop.GetColour()); | |
675 | positions[i] = stop.GetPosition(); | |
676 | } | |
677 | ||
678 | brush->SetInterpolationColors(&colors[0], &positions[0], numStops); | |
679 | } | |
680 | ||
681 | void | |
682 | wxGDIPlusBrushData::CreateLinearGradientBrush(wxDouble x1, wxDouble y1, | |
683 | wxDouble x2, wxDouble y2, | |
684 | const wxGraphicsGradientStops& stops) | |
83576e68 | 685 | { |
4ee4c7b9 VZ |
686 | LinearGradientBrush * const |
687 | brush = new LinearGradientBrush(PointF(x1, y1) , PointF(x2, y2), | |
688 | wxColourToColor(stops.GetStartColour()), | |
689 | wxColourToColor(stops.GetEndColour())); | |
690 | m_brush = brush; | |
691 | ||
692 | SetGradientStops(brush, stops); | |
83576e68 SC |
693 | } |
694 | ||
4ee4c7b9 VZ |
695 | void |
696 | wxGDIPlusBrushData::CreateRadialGradientBrush(wxDouble xo, wxDouble yo, | |
697 | wxDouble xc, wxDouble yc, | |
698 | wxDouble radius, | |
699 | const wxGraphicsGradientStops& stops) | |
83576e68 | 700 | { |
83576e68 | 701 | m_brushPath = new GraphicsPath(); |
4ee4c7b9 VZ |
702 | m_brushPath->AddEllipse( (REAL)(xc-radius), (REAL)(yc-radius), |
703 | (REAL)(2*radius), (REAL)(2*radius)); | |
83576e68 | 704 | |
4ee4c7b9 VZ |
705 | PathGradientBrush * const brush = new PathGradientBrush(m_brushPath); |
706 | m_brush = brush; | |
707 | brush->SetCenterPoint(PointF(xo, yo)); | |
708 | brush->SetCenterColor(wxColourToColor(stops.GetStartColour())); | |
83576e68 | 709 | |
4ee4c7b9 | 710 | const Color col(wxColourToColor(stops.GetEndColour())); |
83576e68 | 711 | int count = 1; |
4ee4c7b9 VZ |
712 | brush->SetSurroundColors(&col, &count); |
713 | ||
714 | SetGradientStops(brush, stops); | |
83576e68 SC |
715 | } |
716 | ||
83576e68 SC |
717 | //----------------------------------------------------------------------------- |
718 | // wxGDIPlusFont implementation | |
719 | //----------------------------------------------------------------------------- | |
720 | ||
7fa3cf6a JS |
721 | wxGDIPlusFontData::wxGDIPlusFontData( wxGraphicsRenderer* renderer, const wxFont &font, |
722 | const wxColour& col ) : wxGraphicsObjectRefData( renderer ) | |
83576e68 | 723 | { |
7fa3cf6a JS |
724 | m_textBrush = NULL; |
725 | m_font = NULL; | |
726 | ||
83576e68 | 727 | wxWCharBuffer s = font.GetFaceName().wc_str( *wxConvUI ); |
7fa3cf6a | 728 | int size = font.GetPointSize(); |
83576e68 SC |
729 | int style = FontStyleRegular; |
730 | if ( font.GetStyle() == wxFONTSTYLE_ITALIC ) | |
731 | style |= FontStyleItalic; | |
732 | if ( font.GetUnderlined() ) | |
733 | style |= FontStyleUnderline; | |
734 | if ( font.GetWeight() == wxFONTWEIGHT_BOLD ) | |
735 | style |= FontStyleBold; | |
7fa3cf6a | 736 | m_font = new Font( s , size , style ); |
f49c80c1 | 737 | m_textBrush = new SolidBrush(wxColourToColor(col)); |
83576e68 | 738 | } |
6fea499c | 739 | |
2c820406 | 740 | wxGDIPlusFontData::~wxGDIPlusFontData() |
83576e68 SC |
741 | { |
742 | delete m_textBrush; | |
743 | delete m_font; | |
744 | } | |
6fea499c | 745 | |
bce28872 SC |
746 | // the built-in conversions functions create non-premultiplied bitmaps, while GDIPlus needs them in the |
747 | // premultiplied format, therefore in the failing cases we create a new bitmap using the non-premultiplied | |
748 | // bytes as parameter, since there is no real copying of the data going in, only references are stored | |
749 | // m_helper has to be kept alive as well | |
750 | ||
751 | //----------------------------------------------------------------------------- | |
752 | // wxGDIPlusBitmapData implementation | |
753 | //----------------------------------------------------------------------------- | |
754 | ||
755 | wxGDIPlusBitmapData::wxGDIPlusBitmapData( wxGraphicsRenderer* renderer, Bitmap* bitmap ) : | |
756 | wxGraphicsObjectRefData( renderer ), m_bitmap( bitmap ) | |
757 | { | |
758 | m_helper = NULL; | |
759 | } | |
760 | ||
0b7dce54 | 761 | wxGDIPlusBitmapData::wxGDIPlusBitmapData( wxGraphicsRenderer* renderer, |
bce28872 SC |
762 | const wxBitmap &bmp) : wxGraphicsObjectRefData( renderer ) |
763 | { | |
764 | m_bitmap = NULL; | |
765 | m_helper = NULL; | |
766 | ||
767 | Bitmap* image = NULL; | |
768 | if ( bmp.GetMask() ) | |
769 | { | |
e38f5435 DS |
770 | Bitmap interim((HBITMAP)bmp.GetHBITMAP(), |
771 | #if wxUSE_PALETTE | |
772 | (HPALETTE)bmp.GetPalette()->GetHPALETTE() | |
773 | #else | |
774 | NULL | |
775 | #endif | |
776 | ); | |
bce28872 SC |
777 | |
778 | size_t width = interim.GetWidth(); | |
779 | size_t height = interim.GetHeight(); | |
780 | Rect bounds(0,0,width,height); | |
781 | ||
782 | image = new Bitmap(width,height,PixelFormat32bppPARGB) ; | |
783 | ||
784 | Bitmap interimMask((HBITMAP)bmp.GetMask()->GetMaskBitmap(),NULL); | |
785 | wxASSERT(interimMask.GetPixelFormat() == PixelFormat1bppIndexed); | |
786 | ||
787 | BitmapData dataMask ; | |
788 | interimMask.LockBits(&bounds,ImageLockModeRead, | |
789 | interimMask.GetPixelFormat(),&dataMask); | |
790 | ||
791 | ||
792 | BitmapData imageData ; | |
793 | image->LockBits(&bounds,ImageLockModeWrite, PixelFormat32bppPARGB, &imageData); | |
794 | ||
795 | BYTE maskPattern = 0 ; | |
796 | BYTE maskByte = 0; | |
797 | size_t maskIndex ; | |
798 | ||
799 | for ( size_t y = 0 ; y < height ; ++y) | |
800 | { | |
801 | maskIndex = 0 ; | |
802 | for( size_t x = 0 ; x < width; ++x) | |
803 | { | |
804 | if ( x % 8 == 0) | |
805 | { | |
806 | maskPattern = 0x80; | |
807 | maskByte = *((BYTE*)dataMask.Scan0 + dataMask.Stride*y + maskIndex); | |
808 | maskIndex++; | |
809 | } | |
810 | else | |
811 | maskPattern = maskPattern >> 1; | |
812 | ||
813 | ARGB *dest = (ARGB*)((BYTE*)imageData.Scan0 + imageData.Stride*y + x*4); | |
814 | if ( (maskByte & maskPattern) == 0 ) | |
815 | *dest = 0x00000000; | |
816 | else | |
817 | { | |
818 | Color c ; | |
819 | interim.GetPixel(x,y,&c) ; | |
820 | *dest = (c.GetValue() | Color::AlphaMask); | |
821 | } | |
822 | } | |
823 | } | |
824 | ||
825 | image->UnlockBits(&imageData); | |
826 | ||
827 | interimMask.UnlockBits(&dataMask); | |
828 | interim.UnlockBits(&dataMask); | |
829 | } | |
830 | else | |
831 | { | |
e38f5435 DS |
832 | image = Bitmap::FromHBITMAP((HBITMAP)bmp.GetHBITMAP(), |
833 | #if wxUSE_PALETTE | |
834 | (HPALETTE)bmp.GetPalette()->GetHPALETTE() | |
835 | #else | |
836 | NULL | |
837 | #endif | |
838 | ); | |
bce28872 SC |
839 | if ( bmp.HasAlpha() && GetPixelFormatSize(image->GetPixelFormat()) == 32 ) |
840 | { | |
841 | size_t width = image->GetWidth(); | |
842 | size_t height = image->GetHeight(); | |
843 | Rect bounds(0,0,width,height); | |
844 | static BitmapData data ; | |
845 | ||
846 | m_helper = image ; | |
847 | image = NULL ; | |
848 | m_helper->LockBits(&bounds, ImageLockModeRead, | |
849 | m_helper->GetPixelFormat(),&data); | |
850 | ||
851 | image = new Bitmap(data.Width, data.Height, data.Stride, | |
852 | PixelFormat32bppPARGB , (BYTE*) data.Scan0); | |
853 | ||
854 | m_helper->UnlockBits(&data); | |
855 | } | |
856 | } | |
857 | if ( image ) | |
858 | m_bitmap = image; | |
859 | } | |
860 | ||
861 | wxGDIPlusBitmapData::~wxGDIPlusBitmapData() | |
862 | { | |
863 | delete m_bitmap; | |
864 | delete m_helper; | |
865 | } | |
866 | ||
83576e68 SC |
867 | //----------------------------------------------------------------------------- |
868 | // wxGDIPlusPath implementation | |
869 | //----------------------------------------------------------------------------- | |
6fea499c | 870 | |
a4e73390 | 871 | wxGDIPlusPathData::wxGDIPlusPathData(wxGraphicsRenderer* renderer, GraphicsPath* path ) : wxGraphicsPathData(renderer) |
83576e68 SC |
872 | { |
873 | if ( path ) | |
874 | m_path = path; | |
875 | else | |
876 | m_path = new GraphicsPath(); | |
877 | } | |
878 | ||
a4e73390 | 879 | wxGDIPlusPathData::~wxGDIPlusPathData() |
6fea499c SC |
880 | { |
881 | delete m_path; | |
882 | } | |
883 | ||
a4e73390 | 884 | wxGraphicsObjectRefData* wxGDIPlusPathData::Clone() const |
83576e68 | 885 | { |
a4e73390 | 886 | return new wxGDIPlusPathData( GetRenderer() , m_path->Clone()); |
83576e68 SC |
887 | } |
888 | ||
6fea499c SC |
889 | // |
890 | // The Primitives | |
891 | // | |
892 | ||
a4e73390 | 893 | void wxGDIPlusPathData::MoveToPoint( wxDouble x , wxDouble y ) |
6fea499c SC |
894 | { |
895 | m_path->StartFigure(); | |
896 | m_path->AddLine((REAL) x,(REAL) y,(REAL) x,(REAL) y); | |
897 | } | |
898 | ||
a4e73390 | 899 | void wxGDIPlusPathData::AddLineToPoint( wxDouble x , wxDouble y ) |
6fea499c SC |
900 | { |
901 | m_path->AddLine((REAL) x,(REAL) y,(REAL) x,(REAL) y); | |
902 | } | |
903 | ||
a4e73390 | 904 | void wxGDIPlusPathData::CloseSubpath() |
6fea499c SC |
905 | { |
906 | m_path->CloseFigure(); | |
907 | } | |
908 | ||
a4e73390 | 909 | void wxGDIPlusPathData::AddCurveToPoint( wxDouble cx1, wxDouble cy1, wxDouble cx2, wxDouble cy2, wxDouble x, wxDouble y ) |
6fea499c SC |
910 | { |
911 | PointF c1(cx1,cy1); | |
912 | PointF c2(cx2,cy2); | |
913 | PointF end(x,y); | |
914 | PointF start; | |
915 | m_path->GetLastPoint(&start); | |
916 | m_path->AddBezier(start,c1,c2,end); | |
917 | } | |
918 | ||
919 | // gets the last point of the current path, (0,0) if not yet set | |
a4e73390 | 920 | void wxGDIPlusPathData::GetCurrentPoint( wxDouble* x, wxDouble* y) const |
6fea499c SC |
921 | { |
922 | PointF start; | |
923 | m_path->GetLastPoint(&start); | |
a4e73390 SC |
924 | *x = start.X ; |
925 | *y = start.Y ; | |
6fea499c SC |
926 | } |
927 | ||
cb3a0d42 | 928 | void wxGDIPlusPathData::AddArc( wxDouble x, wxDouble y, wxDouble r, double startAngle, double endAngle, bool clockwise ) |
6fea499c SC |
929 | { |
930 | double sweepAngle = endAngle - startAngle ; | |
c5b8c66a | 931 | if( fabs(sweepAngle) >= 2*M_PI) |
6fea499c SC |
932 | { |
933 | sweepAngle = 2 * M_PI; | |
934 | } | |
935 | else | |
936 | { | |
937 | if ( clockwise ) | |
938 | { | |
939 | if( sweepAngle < 0 ) | |
940 | sweepAngle += 2 * M_PI; | |
941 | } | |
942 | else | |
943 | { | |
944 | if( sweepAngle > 0 ) | |
945 | sweepAngle -= 2 * M_PI; | |
946 | ||
947 | } | |
948 | } | |
cb3a0d42 | 949 | m_path->AddArc((REAL) (x-r),(REAL) (y-r),(REAL) (2*r),(REAL) (2*r),RadToDeg(startAngle),RadToDeg(sweepAngle)); |
6fea499c SC |
950 | } |
951 | ||
a4e73390 | 952 | void wxGDIPlusPathData::AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h ) |
6fea499c SC |
953 | { |
954 | m_path->AddRectangle(RectF(x,y,w,h)); | |
955 | } | |
956 | ||
a4e73390 | 957 | void wxGDIPlusPathData::AddPath( const wxGraphicsPathData* path ) |
6fea499c | 958 | { |
83576e68 | 959 | m_path->AddPath( (GraphicsPath*) path->GetNativePath(), FALSE); |
6fea499c SC |
960 | } |
961 | ||
6fea499c | 962 | |
83576e68 | 963 | // transforms each point of this path by the matrix |
cb3a0d42 | 964 | void wxGDIPlusPathData::Transform( const wxGraphicsMatrixData* matrix ) |
9f339b18 | 965 | { |
83576e68 | 966 | m_path->Transform( (Matrix*) matrix->GetNativeMatrix() ); |
9f339b18 | 967 | } |
6fea499c | 968 | |
83576e68 | 969 | // gets the bounding box enclosing all points (possibly including control points) |
a4e73390 | 970 | void wxGDIPlusPathData::GetBox(wxDouble *x, wxDouble *y, wxDouble *w, wxDouble *h) const |
e49c065d | 971 | { |
83576e68 SC |
972 | RectF bounds; |
973 | m_path->GetBounds( &bounds, NULL, NULL) ; | |
974 | *x = bounds.X; | |
975 | *y = bounds.Y; | |
976 | *w = bounds.Width; | |
977 | *h = bounds.Height; | |
e49c065d RD |
978 | } |
979 | ||
94a007ec | 980 | bool wxGDIPlusPathData::Contains( wxDouble x, wxDouble y, wxPolygonFillMode fillStyle ) const |
6fea499c | 981 | { |
83576e68 SC |
982 | m_path->SetFillMode( fillStyle == wxODDEVEN_RULE ? FillModeAlternate : FillModeWinding); |
983 | return m_path->IsVisible( (FLOAT) x,(FLOAT) y) == TRUE ; | |
984 | } | |
9f339b18 | 985 | |
83576e68 | 986 | //----------------------------------------------------------------------------- |
a4e73390 | 987 | // wxGDIPlusMatrixData implementation |
83576e68 | 988 | //----------------------------------------------------------------------------- |
9f339b18 | 989 | |
a4e73390 SC |
990 | wxGDIPlusMatrixData::wxGDIPlusMatrixData(wxGraphicsRenderer* renderer, Matrix* matrix ) |
991 | : wxGraphicsMatrixData(renderer) | |
9f339b18 | 992 | { |
83576e68 SC |
993 | if ( matrix ) |
994 | m_matrix = matrix ; | |
995 | else | |
996 | m_matrix = new Matrix(); | |
6fea499c SC |
997 | } |
998 | ||
cb3a0d42 | 999 | wxGDIPlusMatrixData::~wxGDIPlusMatrixData() |
6fea499c | 1000 | { |
83576e68 | 1001 | delete m_matrix; |
6fea499c SC |
1002 | } |
1003 | ||
cb3a0d42 | 1004 | wxGraphicsObjectRefData *wxGDIPlusMatrixData::Clone() const |
6fea499c | 1005 | { |
a4e73390 | 1006 | return new wxGDIPlusMatrixData( GetRenderer(), m_matrix->Clone()); |
539e2795 SC |
1007 | } |
1008 | ||
83576e68 | 1009 | // concatenates the matrix |
a4e73390 | 1010 | void wxGDIPlusMatrixData::Concat( const wxGraphicsMatrixData *t ) |
539e2795 | 1011 | { |
83576e68 | 1012 | m_matrix->Multiply( (Matrix*) t->GetNativeMatrix()); |
539e2795 | 1013 | } |
83576e68 | 1014 | |
83576e68 | 1015 | // sets the matrix to the respective values |
cb3a0d42 | 1016 | void wxGDIPlusMatrixData::Set(wxDouble a, wxDouble b, wxDouble c, wxDouble d, |
83576e68 | 1017 | wxDouble tx, wxDouble ty) |
6fea499c | 1018 | { |
83576e68 | 1019 | m_matrix->SetElements(a,b,c,d,tx,ty); |
6fea499c SC |
1020 | } |
1021 | ||
248802d0 RD |
1022 | // gets the component valuess of the matrix |
1023 | void wxGDIPlusMatrixData::Get(wxDouble* a, wxDouble* b, wxDouble* c, | |
1024 | wxDouble* d, wxDouble* tx, wxDouble* ty) const | |
1025 | { | |
1026 | REAL elements[6]; | |
1027 | m_matrix->GetElements(elements); | |
1028 | if (a) *a = elements[0]; | |
1029 | if (b) *b = elements[1]; | |
1030 | if (c) *c = elements[2]; | |
1031 | if (d) *d = elements[3]; | |
1032 | if (tx) *tx= elements[4]; | |
1033 | if (ty) *ty= elements[5]; | |
1034 | } | |
1035 | ||
83576e68 | 1036 | // makes this the inverse matrix |
a4e73390 | 1037 | void wxGDIPlusMatrixData::Invert() |
6fea499c | 1038 | { |
83576e68 | 1039 | m_matrix->Invert(); |
6fea499c SC |
1040 | } |
1041 | ||
83576e68 | 1042 | // returns true if the elements of the transformation matrix are equal ? |
cb3a0d42 | 1043 | bool wxGDIPlusMatrixData::IsEqual( const wxGraphicsMatrixData* t) const |
6fea499c | 1044 | { |
83576e68 | 1045 | return m_matrix->Equals((Matrix*) t->GetNativeMatrix())== TRUE ; |
6fea499c SC |
1046 | } |
1047 | ||
83576e68 | 1048 | // return true if this is the identity matrix |
a4e73390 | 1049 | bool wxGDIPlusMatrixData::IsIdentity() const |
6fea499c | 1050 | { |
83576e68 | 1051 | return m_matrix->IsIdentity() == TRUE ; |
6fea499c SC |
1052 | } |
1053 | ||
83576e68 SC |
1054 | // |
1055 | // transformation | |
1056 | // | |
1057 | ||
1058 | // add the translation to this matrix | |
a4e73390 | 1059 | void wxGDIPlusMatrixData::Translate( wxDouble dx , wxDouble dy ) |
6fea499c | 1060 | { |
83576e68 | 1061 | m_matrix->Translate(dx,dy); |
6fea499c SC |
1062 | } |
1063 | ||
83576e68 | 1064 | // add the scale to this matrix |
a4e73390 | 1065 | void wxGDIPlusMatrixData::Scale( wxDouble xScale , wxDouble yScale ) |
6fea499c | 1066 | { |
83576e68 | 1067 | m_matrix->Scale(xScale,yScale); |
6fea499c SC |
1068 | } |
1069 | ||
83576e68 | 1070 | // add the rotation to this matrix (radians) |
a4e73390 | 1071 | void wxGDIPlusMatrixData::Rotate( wxDouble angle ) |
6fea499c | 1072 | { |
6f32f3ce | 1073 | m_matrix->Rotate( RadToDeg(angle) ); |
6fea499c SC |
1074 | } |
1075 | ||
83576e68 SC |
1076 | // |
1077 | // apply the transforms | |
1078 | // | |
1079 | ||
1080 | // applies that matrix to the point | |
a4e73390 | 1081 | void wxGDIPlusMatrixData::TransformPoint( wxDouble *x, wxDouble *y ) const |
6fea499c | 1082 | { |
83576e68 SC |
1083 | PointF pt(*x,*y); |
1084 | m_matrix->TransformPoints(&pt); | |
1085 | *x = pt.X; | |
1086 | *y = pt.Y; | |
6fea499c SC |
1087 | } |
1088 | ||
83576e68 | 1089 | // applies the matrix except for translations |
a4e73390 | 1090 | void wxGDIPlusMatrixData::TransformDistance( wxDouble *dx, wxDouble *dy ) const |
6fea499c | 1091 | { |
83576e68 SC |
1092 | PointF pt(*dx,*dy); |
1093 | m_matrix->TransformVectors(&pt); | |
1094 | *dx = pt.X; | |
1095 | *dy = pt.Y; | |
6fea499c SC |
1096 | } |
1097 | ||
83576e68 | 1098 | // returns the native representation |
a4e73390 | 1099 | void * wxGDIPlusMatrixData::GetNativeMatrix() const |
6fea499c | 1100 | { |
83576e68 SC |
1101 | return m_matrix; |
1102 | } | |
6fea499c | 1103 | |
83576e68 SC |
1104 | //----------------------------------------------------------------------------- |
1105 | // wxGDIPlusContext implementation | |
1106 | //----------------------------------------------------------------------------- | |
1107 | ||
1108 | IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusContext,wxGraphicsContext) | |
0c7bd159 SC |
1109 | IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusMeasuringContext,wxGDIPlusContext) |
1110 | ||
1111 | class wxGDIPlusOffsetHelper | |
1112 | { | |
1113 | public : | |
1114 | wxGDIPlusOffsetHelper( Graphics* gr , bool offset ) | |
1115 | { | |
1116 | m_gr = gr; | |
1117 | m_offset = offset; | |
1118 | if ( m_offset ) | |
1119 | m_gr->TranslateTransform( 0.5, 0.5 ); | |
1120 | } | |
1121 | ~wxGDIPlusOffsetHelper( ) | |
1122 | { | |
1123 | if ( m_offset ) | |
1124 | m_gr->TranslateTransform( -0.5, -0.5 ); | |
1125 | } | |
1126 | public : | |
1127 | Graphics* m_gr; | |
1128 | bool m_offset; | |
1129 | } ; | |
83576e68 | 1130 | |
7fa3cf6a | 1131 | wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer* renderer, HDC hdc, wxDouble width, wxDouble height ) |
83576e68 SC |
1132 | : wxGraphicsContext(renderer) |
1133 | { | |
1134 | Init(); | |
7fa3cf6a | 1135 | m_context = new Graphics( hdc); |
81e0b3d9 SC |
1136 | m_width = width; |
1137 | m_height = height; | |
83576e68 | 1138 | SetDefaults(); |
6fea499c SC |
1139 | } |
1140 | ||
83576e68 SC |
1141 | wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer* renderer, HWND hwnd ) |
1142 | : wxGraphicsContext(renderer) | |
6fea499c | 1143 | { |
83576e68 SC |
1144 | Init(); |
1145 | m_context = new Graphics( hwnd); | |
81e0b3d9 SC |
1146 | RECT rect = wxGetWindowRect(hwnd); |
1147 | m_width = rect.right - rect.left; | |
1148 | m_height = rect.bottom - rect.top; | |
83576e68 SC |
1149 | SetDefaults(); |
1150 | } | |
6fea499c | 1151 | |
83576e68 SC |
1152 | wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer* renderer, Graphics* gr ) |
1153 | : wxGraphicsContext(renderer) | |
1154 | { | |
1155 | Init(); | |
1156 | m_context = gr; | |
1157 | SetDefaults(); | |
1158 | } | |
6fea499c | 1159 | |
83576e68 SC |
1160 | wxGDIPlusContext::wxGDIPlusContext() : wxGraphicsContext(NULL) |
1161 | { | |
1162 | Init(); | |
1163 | } | |
6fea499c | 1164 | |
83576e68 SC |
1165 | void wxGDIPlusContext::Init() |
1166 | { | |
1167 | m_context = NULL; | |
1168 | m_state1 = 0; | |
1169 | m_state2= 0; | |
81e0b3d9 SC |
1170 | m_height = 0; |
1171 | m_width = 0; | |
83576e68 | 1172 | } |
6fea499c | 1173 | |
83576e68 SC |
1174 | void wxGDIPlusContext::SetDefaults() |
1175 | { | |
0c7bd159 SC |
1176 | m_context->SetTextRenderingHint(TextRenderingHintSystemDefault); |
1177 | m_context->SetPixelOffsetMode(PixelOffsetModeHalf); | |
83576e68 SC |
1178 | m_context->SetSmoothingMode(SmoothingModeHighQuality); |
1179 | m_state1 = m_context->Save(); | |
1180 | m_state2 = m_context->Save(); | |
a53b5e86 JS |
1181 | |
1182 | // Setup page scale, based on DPI ratio. | |
1183 | // Antecedent should be 100dpi when the default page unit (UnitDisplay) | |
1184 | // is used. Page unit UnitDocument would require 300dpi instead. | |
1185 | // Note that calling SetPageScale() does not have effect on non-printing | |
1186 | // DCs (that is, any other than wxPrinterDC or wxEnhMetaFileDC). | |
1187 | REAL dpiRatio = 100.0 / m_context->GetDpiY(); | |
1188 | m_context->SetPageScale(dpiRatio); | |
83576e68 | 1189 | } |
6fea499c | 1190 | |
83576e68 SC |
1191 | wxGDIPlusContext::~wxGDIPlusContext() |
1192 | { | |
83576e68 | 1193 | if ( m_context ) |
6fea499c | 1194 | { |
83576e68 SC |
1195 | m_context->Restore( m_state2 ); |
1196 | m_context->Restore( m_state1 ); | |
1197 | delete m_context; | |
6fea499c SC |
1198 | } |
1199 | } | |
1200 | ||
83576e68 SC |
1201 | |
1202 | void wxGDIPlusContext::Clip( const wxRegion ®ion ) | |
6fea499c | 1203 | { |
93f72bae SC |
1204 | Region rgn((HRGN)region.GetHRGN()); |
1205 | m_context->SetClip(&rgn,CombineModeIntersect); | |
83576e68 | 1206 | } |
6fea499c | 1207 | |
83576e68 SC |
1208 | void wxGDIPlusContext::Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h ) |
1209 | { | |
1210 | m_context->SetClip(RectF(x,y,w,h),CombineModeIntersect); | |
1211 | } | |
cb3a0d42 | 1212 | |
83576e68 SC |
1213 | void wxGDIPlusContext::ResetClip() |
1214 | { | |
1215 | m_context->ResetClip(); | |
1216 | } | |
6fea499c | 1217 | |
0c7bd159 SC |
1218 | void wxGDIPlusContext::StrokeLines( size_t n, const wxPoint2DDouble *points) |
1219 | { | |
bf02a7f9 SC |
1220 | if (m_composition == wxCOMPOSITION_DEST) |
1221 | return; | |
1222 | ||
03647350 VZ |
1223 | if ( !m_pen.IsNull() ) |
1224 | { | |
1225 | wxGDIPlusOffsetHelper helper( m_context , ShouldOffset() ); | |
1226 | Point *cpoints = new Point[n]; | |
1227 | for (size_t i = 0; i < n; i++) | |
1228 | { | |
1229 | cpoints[i].X = (int)(points[i].m_x ); | |
1230 | cpoints[i].Y = (int)(points[i].m_y ); | |
1231 | ||
1232 | } // for (size_t i = 0; i < n; i++) | |
1233 | m_context->DrawLines( ((wxGDIPlusPenData*)m_pen.GetGraphicsData())->GetGDIPlusPen() , cpoints , n ) ; | |
1234 | delete[] cpoints; | |
1235 | } | |
0c7bd159 SC |
1236 | } |
1237 | ||
94a007ec | 1238 | void wxGDIPlusContext::DrawLines( size_t n, const wxPoint2DDouble *points, wxPolygonFillMode WXUNUSED(fillStyle) ) |
0c7bd159 | 1239 | { |
bf02a7f9 SC |
1240 | if (m_composition == wxCOMPOSITION_DEST) |
1241 | return; | |
1242 | ||
0c7bd159 | 1243 | wxGDIPlusOffsetHelper helper( m_context , ShouldOffset() ); |
03647350 VZ |
1244 | Point *cpoints = new Point[n]; |
1245 | for (size_t i = 0; i < n; i++) | |
1246 | { | |
1247 | cpoints[i].X = (int)(points[i].m_x ); | |
1248 | cpoints[i].Y = (int)(points[i].m_y ); | |
1249 | ||
1250 | } // for (int i = 0; i < n; i++) | |
1251 | if ( !m_brush.IsNull() ) | |
1252 | m_context->FillPolygon( ((wxGDIPlusBrushData*)m_brush.GetRefData())->GetGDIPlusBrush() , cpoints , n ) ; | |
1253 | if ( !m_pen.IsNull() ) | |
1254 | m_context->DrawLines( ((wxGDIPlusPenData*)m_pen.GetGraphicsData())->GetGDIPlusPen() , cpoints , n ) ; | |
1255 | delete[] cpoints; | |
0c7bd159 SC |
1256 | } |
1257 | ||
a4e73390 | 1258 | void wxGDIPlusContext::StrokePath( const wxGraphicsPath& path ) |
83576e68 | 1259 | { |
bf02a7f9 SC |
1260 | if (m_composition == wxCOMPOSITION_DEST) |
1261 | return; | |
1262 | ||
2c820406 | 1263 | if ( !m_pen.IsNull() ) |
83576e68 | 1264 | { |
0c7bd159 | 1265 | wxGDIPlusOffsetHelper helper( m_context , ShouldOffset() ); |
a4e73390 | 1266 | m_context->DrawPath( ((wxGDIPlusPenData*)m_pen.GetGraphicsData())->GetGDIPlusPen() , (GraphicsPath*) path.GetNativePath() ); |
83576e68 | 1267 | } |
6fea499c SC |
1268 | } |
1269 | ||
94a007ec | 1270 | void wxGDIPlusContext::FillPath( const wxGraphicsPath& path , wxPolygonFillMode fillStyle ) |
6fea499c | 1271 | { |
bf02a7f9 SC |
1272 | if (m_composition == wxCOMPOSITION_DEST) |
1273 | return; | |
1274 | ||
2c820406 | 1275 | if ( !m_brush.IsNull() ) |
83576e68 | 1276 | { |
0c7bd159 | 1277 | wxGDIPlusOffsetHelper helper( m_context , ShouldOffset() ); |
a4e73390 | 1278 | ((GraphicsPath*) path.GetNativePath())->SetFillMode( fillStyle == wxODDEVEN_RULE ? FillModeAlternate : FillModeWinding); |
cb3a0d42 | 1279 | m_context->FillPath( ((wxGDIPlusBrushData*)m_brush.GetRefData())->GetGDIPlusBrush() , |
a4e73390 | 1280 | (GraphicsPath*) path.GetNativePath()); |
83576e68 SC |
1281 | } |
1282 | } | |
6fea499c | 1283 | |
bf02a7f9 SC |
1284 | bool wxGDIPlusContext::SetAntialiasMode(wxAntialiasMode antialias) |
1285 | { | |
1286 | if (m_antialias == antialias) | |
1287 | return true; | |
03647350 | 1288 | |
bf02a7f9 | 1289 | m_antialias = antialias; |
03647350 | 1290 | |
bf02a7f9 SC |
1291 | SmoothingMode antialiasMode; |
1292 | switch (antialias) | |
1293 | { | |
1294 | case wxANTIALIAS_DEFAULT: | |
1295 | antialiasMode = SmoothingModeHighQuality; | |
1296 | break; | |
1297 | case wxANTIALIAS_NONE: | |
1298 | antialiasMode = SmoothingModeNone; | |
1299 | break; | |
1300 | default: | |
1301 | return false; | |
1302 | } | |
1303 | m_context->SetSmoothingMode(antialiasMode); | |
1304 | return true; | |
1305 | } | |
1306 | ||
1307 | bool wxGDIPlusContext::SetCompositionMode(wxCompositionMode op) | |
1308 | { | |
1309 | if ( m_composition == op ) | |
1310 | return true; | |
03647350 | 1311 | |
bf02a7f9 | 1312 | m_composition = op; |
03647350 | 1313 | |
bf02a7f9 SC |
1314 | if (m_composition == wxCOMPOSITION_DEST) |
1315 | return true; | |
1316 | ||
1317 | CompositingMode cop; | |
1318 | switch (op) | |
1319 | { | |
1320 | case wxCOMPOSITION_SOURCE: | |
1321 | cop = CompositingModeSourceCopy; | |
1322 | break; | |
1323 | case wxCOMPOSITION_OVER: | |
1324 | cop = CompositingModeSourceOver; | |
1325 | break; | |
1326 | default: | |
1327 | return false; | |
1328 | } | |
1329 | ||
1330 | m_context->SetCompositingMode(cop); | |
1331 | return true; | |
1332 | } | |
1333 | ||
c496d8fa | 1334 | void wxGDIPlusContext::BeginLayer(wxDouble /* opacity */) |
bf02a7f9 SC |
1335 | { |
1336 | // TODO | |
1337 | } | |
1338 | ||
1339 | void wxGDIPlusContext::EndLayer() | |
1340 | { | |
1341 | // TODO | |
03647350 | 1342 | } |
bf02a7f9 | 1343 | |
cb3a0d42 | 1344 | void wxGDIPlusContext::Rotate( wxDouble angle ) |
83576e68 SC |
1345 | { |
1346 | m_context->RotateTransform( RadToDeg(angle) ); | |
1347 | } | |
6fea499c | 1348 | |
cb3a0d42 | 1349 | void wxGDIPlusContext::Translate( wxDouble dx , wxDouble dy ) |
83576e68 SC |
1350 | { |
1351 | m_context->TranslateTransform( dx , dy ); | |
1352 | } | |
6fea499c | 1353 | |
83576e68 SC |
1354 | void wxGDIPlusContext::Scale( wxDouble xScale , wxDouble yScale ) |
1355 | { | |
1356 | m_context->ScaleTransform(xScale,yScale); | |
1357 | } | |
6fea499c | 1358 | |
83576e68 SC |
1359 | void wxGDIPlusContext::PushState() |
1360 | { | |
1361 | GraphicsState state = m_context->Save(); | |
bdba6fdc | 1362 | m_stateStack.push(state); |
83576e68 SC |
1363 | } |
1364 | ||
cb3a0d42 | 1365 | void wxGDIPlusContext::PopState() |
83576e68 | 1366 | { |
bdba6fdc VZ |
1367 | GraphicsState state = m_stateStack.top(); |
1368 | m_stateStack.pop(); | |
83576e68 | 1369 | m_context->Restore(state); |
6fea499c SC |
1370 | } |
1371 | ||
bce28872 | 1372 | void wxGDIPlusContext::DrawBitmap( const wxGraphicsBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) |
6fea499c | 1373 | { |
bf02a7f9 SC |
1374 | if (m_composition == wxCOMPOSITION_DEST) |
1375 | return; | |
1376 | ||
bce28872 SC |
1377 | Bitmap* image = static_cast<wxGDIPlusBitmapData*>(bmp.GetRefData())->GetGDIPlusBitmap(); |
1378 | if ( image ) | |
cb3a0d42 | 1379 | { |
bce28872 | 1380 | if( image->GetWidth() != (UINT) w || image->GetHeight() != (UINT) h ) |
fe31db81 | 1381 | { |
bce28872 SC |
1382 | Rect drawRect((REAL) x, (REAL)y, (REAL)w, (REAL)h); |
1383 | m_context->SetPixelOffsetMode( PixelOffsetModeNone ); | |
1384 | m_context->DrawImage(image, drawRect, 0 , 0 , image->GetWidth()-1, image->GetHeight()-1, UnitPixel ) ; | |
1385 | m_context->SetPixelOffsetMode( PixelOffsetModeHalf ); | |
fe31db81 | 1386 | } |
bce28872 SC |
1387 | else |
1388 | m_context->DrawImage(image,(REAL) x,(REAL) y,(REAL) w,(REAL) h) ; | |
fe31db81 | 1389 | } |
bce28872 | 1390 | } |
fe31db81 | 1391 | |
bce28872 SC |
1392 | void wxGDIPlusContext::DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) |
1393 | { | |
1394 | wxGraphicsBitmap bitmap = GetRenderer()->CreateBitmap(bmp); | |
1395 | DrawBitmap(bitmap, x, y, w, h); | |
6fea499c SC |
1396 | } |
1397 | ||
cb3a0d42 | 1398 | void wxGDIPlusContext::DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) |
6fea499c | 1399 | { |
bf02a7f9 SC |
1400 | if (m_composition == wxCOMPOSITION_DEST) |
1401 | return; | |
1402 | ||
0c7bd159 SC |
1403 | // the built-in conversion fails when there is alpha in the HICON (eg XP style icons), we can only |
1404 | // find out by looking at the bitmap data whether there really was alpha in it | |
fe31db81 SC |
1405 | HICON hIcon = (HICON)icon.GetHICON(); |
1406 | ICONINFO iconInfo ; | |
1407 | // IconInfo creates the bitmaps for color and mask, we must dispose of them after use | |
1408 | if (!GetIconInfo(hIcon,&iconInfo)) | |
1409 | return; | |
1410 | ||
fe31db81 SC |
1411 | Bitmap interim(iconInfo.hbmColor,NULL); |
1412 | ||
1413 | Bitmap* image = NULL ; | |
1414 | ||
0c7bd159 SC |
1415 | // if it's not 32 bit, it doesn't have an alpha channel, note that since the conversion doesn't |
1416 | // work correctly, asking IsAlphaPixelFormat at this point fails as well | |
fe31db81 SC |
1417 | if( GetPixelFormatSize(interim.GetPixelFormat())!= 32 ) |
1418 | { | |
1419 | image = Bitmap::FromHICON(hIcon); | |
1420 | } | |
1421 | else | |
1422 | { | |
1423 | size_t width = interim.GetWidth(); | |
1424 | size_t height = interim.GetHeight(); | |
1425 | Rect bounds(0,0,width,height); | |
1426 | BitmapData data ; | |
1427 | ||
1428 | interim.LockBits(&bounds, ImageLockModeRead, | |
1429 | interim.GetPixelFormat(),&data); | |
0b7dce54 | 1430 | |
0c7bd159 SC |
1431 | bool hasAlpha = false; |
1432 | for ( size_t y = 0 ; y < height && !hasAlpha ; ++y) | |
1433 | { | |
1434 | for( size_t x = 0 ; x < width && !hasAlpha; ++x) | |
1435 | { | |
1436 | ARGB *dest = (ARGB*)((BYTE*)data.Scan0 + data.Stride*y + x*4); | |
1437 | if ( ( *dest & Color::AlphaMask ) != 0 ) | |
1438 | hasAlpha = true; | |
1439 | } | |
1440 | } | |
1441 | ||
1442 | if ( hasAlpha ) | |
1443 | { | |
cb3a0d42 | 1444 | image = new Bitmap(data.Width, data.Height, data.Stride, |
fe31db81 | 1445 | PixelFormat32bppARGB , (BYTE*) data.Scan0); |
0c7bd159 SC |
1446 | } |
1447 | else | |
1448 | { | |
1449 | image = Bitmap::FromHICON(hIcon); | |
1450 | } | |
1451 | ||
fe31db81 SC |
1452 | interim.UnlockBits(&data); |
1453 | } | |
1454 | ||
6fea499c | 1455 | m_context->DrawImage(image,(REAL) x,(REAL) y,(REAL) w,(REAL) h) ; |
fe31db81 | 1456 | |
6fea499c | 1457 | delete image ; |
fe31db81 SC |
1458 | DeleteObject(iconInfo.hbmColor); |
1459 | DeleteObject(iconInfo.hbmMask); | |
6fea499c SC |
1460 | } |
1461 | ||
0b7dce54 VZ |
1462 | void wxGDIPlusContext::DoDrawFilledText(const wxString& str, |
1463 | wxDouble x, wxDouble y, | |
1464 | const wxGraphicsBrush& brush) | |
6fea499c | 1465 | { |
bf02a7f9 SC |
1466 | if (m_composition == wxCOMPOSITION_DEST) |
1467 | return; | |
1468 | ||
0b7dce54 VZ |
1469 | wxCHECK_RET( !m_font.IsNull(), |
1470 | wxT("wxGDIPlusContext::DrawText - no valid font set") ); | |
1011fbeb SC |
1471 | |
1472 | if ( str.IsEmpty()) | |
6fea499c SC |
1473 | return ; |
1474 | ||
091111d6 | 1475 | wxGDIPlusFontData * const |
0b7dce54 | 1476 | fontData = (wxGDIPlusFontData *)m_font.GetRefData(); |
091111d6 VZ |
1477 | wxGDIPlusBrushData * const |
1478 | brushData = (wxGDIPlusBrushData *)brush.GetRefData(); | |
0b7dce54 VZ |
1479 | |
1480 | m_context->DrawString | |
1481 | ( | |
1482 | str.wc_str(*wxConvUI), // string to draw, always Unicode | |
1483 | -1, // length: string is NUL-terminated | |
1484 | fontData->GetGDIPlusFont(), | |
1485 | PointF(x, y), | |
1486 | StringFormat::GenericTypographic(), | |
1487 | brushData ? brushData->GetGDIPlusBrush() | |
1488 | : fontData->GetGDIPlusBrush() | |
1489 | ); | |
6fea499c SC |
1490 | } |
1491 | ||
1492 | void wxGDIPlusContext::GetTextExtent( const wxString &str, wxDouble *width, wxDouble *height, | |
1493 | wxDouble *descent, wxDouble *externalLeading ) const | |
1494 | { | |
1011fbeb SC |
1495 | wxCHECK_RET( !m_font.IsNull(), wxT("wxGDIPlusContext::GetTextExtent - no valid font set") ); |
1496 | ||
6fea499c SC |
1497 | wxWCharBuffer s = str.wc_str( *wxConvUI ); |
1498 | FontFamily ffamily ; | |
2c820406 | 1499 | Font* f = ((wxGDIPlusFontData*)m_font.GetRefData())->GetGDIPlusFont(); |
cb3a0d42 | 1500 | |
83576e68 | 1501 | f->GetFamily(&ffamily) ; |
6fea499c | 1502 | |
7fa3cf6a | 1503 | REAL factorY = m_context->GetDpiY() / 72.0 ; |
6fea499c SC |
1504 | |
1505 | REAL rDescent = ffamily.GetCellDescent(FontStyleRegular) * | |
83576e68 | 1506 | f->GetSize() / ffamily.GetEmHeight(FontStyleRegular); |
6fea499c | 1507 | REAL rAscent = ffamily.GetCellAscent(FontStyleRegular) * |
83576e68 | 1508 | f->GetSize() / ffamily.GetEmHeight(FontStyleRegular); |
6fea499c | 1509 | REAL rHeight = ffamily.GetLineSpacing(FontStyleRegular) * |
83576e68 | 1510 | f->GetSize() / ffamily.GetEmHeight(FontStyleRegular); |
6fea499c SC |
1511 | |
1512 | if ( height ) | |
595fda6f | 1513 | *height = rHeight * factorY; |
6fea499c | 1514 | if ( descent ) |
595fda6f | 1515 | *descent = rDescent * factorY; |
6fea499c | 1516 | if ( externalLeading ) |
595fda6f | 1517 | *externalLeading = (rHeight - rAscent - rDescent) * factorY; |
6fea499c | 1518 | // measuring empty strings is not guaranteed, so do it by hand |
cb3a0d42 | 1519 | if ( str.IsEmpty()) |
6fea499c SC |
1520 | { |
1521 | if ( width ) | |
1522 | *width = 0 ; | |
1523 | } | |
1524 | else | |
1525 | { | |
6fea499c | 1526 | RectF layoutRect(0,0, 100000.0f, 100000.0f); |
0c7bd159 | 1527 | StringFormat strFormat( StringFormat::GenericTypographic() ); |
0b7dce54 | 1528 | strFormat.SetFormatFlags( StringFormatFlagsMeasureTrailingSpaces | strFormat.GetFormatFlags() ); |
0c7bd159 SC |
1529 | |
1530 | RectF bounds ; | |
1531 | m_context->MeasureString((const wchar_t *) s , wcslen(s) , f, layoutRect, &strFormat, &bounds ) ; | |
6fea499c | 1532 | if ( width ) |
0c7bd159 | 1533 | *width = bounds.Width; |
465642da JS |
1534 | if ( height ) |
1535 | *height = bounds.Height; | |
6fea499c SC |
1536 | } |
1537 | } | |
1538 | ||
cb3a0d42 | 1539 | void wxGDIPlusContext::GetPartialTextExtents(const wxString& text, wxArrayDouble& widths) const |
6fea499c SC |
1540 | { |
1541 | widths.Empty(); | |
1542 | widths.Add(0, text.length()); | |
1543 | ||
1011fbeb SC |
1544 | wxCHECK_RET( !m_font.IsNull(), wxT("wxGDIPlusContext::GetPartialTextExtents - no valid font set") ); |
1545 | ||
6fea499c SC |
1546 | if (text.empty()) |
1547 | return; | |
1548 | ||
2c820406 | 1549 | Font* f = ((wxGDIPlusFontData*)m_font.GetRefData())->GetGDIPlusFont(); |
6fea499c SC |
1550 | wxWCharBuffer ws = text.wc_str( *wxConvUI ); |
1551 | size_t len = wcslen( ws ) ; | |
1552 | wxASSERT_MSG(text.length() == len , wxT("GetPartialTextExtents not yet implemented for multichar situations")); | |
1553 | ||
1554 | RectF layoutRect(0,0, 100000.0f, 100000.0f); | |
0c7bd159 | 1555 | StringFormat strFormat( StringFormat::GenericTypographic() ); |
6fea499c | 1556 | |
c315587c | 1557 | size_t startPosition = 0; |
918df9d2 | 1558 | size_t remainder = len; |
c315587c SC |
1559 | const size_t maxSpan = 32; |
1560 | CharacterRange* ranges = new CharacterRange[maxSpan] ; | |
1561 | Region* regions = new Region[maxSpan]; | |
6fea499c | 1562 | |
918df9d2 | 1563 | while( remainder > 0 ) |
6fea499c | 1564 | { |
918df9d2 | 1565 | size_t span = wxMin( maxSpan, remainder ); |
c315587c SC |
1566 | |
1567 | for( size_t i = 0 ; i < span ; ++i) | |
1568 | { | |
1569 | ranges[i].First = 0 ; | |
1570 | ranges[i].Length = startPosition+i+1 ; | |
1571 | } | |
1572 | strFormat.SetMeasurableCharacterRanges(span,ranges); | |
1573 | strFormat.SetFormatFlags( StringFormatFlagsMeasureTrailingSpaces | strFormat.GetFormatFlags() ); | |
1574 | m_context->MeasureCharacterRanges(ws, -1 , f,layoutRect, &strFormat,span,regions) ; | |
1575 | ||
1576 | RectF bbox ; | |
1577 | for ( size_t i = 0 ; i < span ; ++i) | |
1578 | { | |
1579 | regions[i].GetBounds(&bbox,m_context); | |
1580 | widths[startPosition+i] = bbox.Width; | |
1581 | } | |
918df9d2 | 1582 | remainder -= span; |
c315587c | 1583 | startPosition += span; |
6fea499c | 1584 | } |
c315587c SC |
1585 | |
1586 | delete[] ranges; | |
1587 | delete[] regions; | |
6fea499c SC |
1588 | } |
1589 | ||
d9485f89 | 1590 | bool wxGDIPlusContext::ShouldOffset() const |
0b7dce54 | 1591 | { |
d9485f89 RD |
1592 | int penwidth = 0 ; |
1593 | if ( !m_pen.IsNull() ) | |
1594 | { | |
1595 | penwidth = (int)((wxGDIPlusPenData*)m_pen.GetRefData())->GetWidth(); | |
1596 | if ( penwidth == 0 ) | |
1597 | penwidth = 1; | |
1598 | } | |
1599 | return ( penwidth % 2 ) == 1; | |
1600 | } | |
1601 | ||
cb3a0d42 | 1602 | void* wxGDIPlusContext::GetNativeContext() |
6fea499c | 1603 | { |
cb3a0d42 | 1604 | return m_context; |
6fea499c SC |
1605 | } |
1606 | ||
83576e68 | 1607 | // concatenates this transform with the current transform of this context |
a4e73390 | 1608 | void wxGDIPlusContext::ConcatTransform( const wxGraphicsMatrix& matrix ) |
539e2795 | 1609 | { |
a4e73390 | 1610 | m_context->MultiplyTransform((Matrix*) matrix.GetNativeMatrix()); |
83576e68 SC |
1611 | } |
1612 | ||
1613 | // sets the transform of this context | |
a4e73390 | 1614 | void wxGDIPlusContext::SetTransform( const wxGraphicsMatrix& matrix ) |
83576e68 | 1615 | { |
a4e73390 | 1616 | m_context->SetTransform((Matrix*) matrix.GetNativeMatrix()); |
83576e68 SC |
1617 | } |
1618 | ||
1619 | // gets the matrix of this context | |
a4e73390 | 1620 | wxGraphicsMatrix wxGDIPlusContext::GetTransform() const |
83576e68 | 1621 | { |
a4e73390 SC |
1622 | wxGraphicsMatrix matrix = CreateMatrix(); |
1623 | m_context->GetTransform((Matrix*) matrix.GetNativeMatrix()); | |
1624 | return matrix; | |
83576e68 | 1625 | } |
fbd5416f SC |
1626 | |
1627 | void wxGDIPlusContext::GetSize( wxDouble* width, wxDouble *height ) | |
1628 | { | |
81e0b3d9 SC |
1629 | *width = m_width; |
1630 | *height = m_height; | |
fbd5416f | 1631 | } |
7fa3cf6a JS |
1632 | //----------------------------------------------------------------------------- |
1633 | // wxGDIPlusRenderer declaration | |
1634 | //----------------------------------------------------------------------------- | |
1635 | ||
1636 | class wxGDIPlusRenderer : public wxGraphicsRenderer | |
1637 | { | |
1638 | public : | |
1639 | wxGDIPlusRenderer() | |
1640 | { | |
1641 | m_loaded = -1; | |
1642 | m_gditoken = 0; | |
1643 | } | |
1644 | ||
1645 | virtual ~wxGDIPlusRenderer() | |
1646 | { | |
1647 | if ( m_loaded == 1 ) | |
1648 | { | |
1649 | Unload(); | |
1650 | } | |
1651 | } | |
1652 | ||
1653 | // Context | |
1654 | ||
1655 | virtual wxGraphicsContext * CreateContext( const wxWindowDC& dc); | |
1656 | ||
1657 | virtual wxGraphicsContext * CreateContext( const wxMemoryDC& dc); | |
1658 | ||
1659 | #if wxUSE_PRINTING_ARCHITECTURE | |
1660 | virtual wxGraphicsContext * CreateContext( const wxPrinterDC& dc); | |
1661 | #endif | |
1662 | ||
1663 | #if wxUSE_ENH_METAFILE | |
1664 | virtual wxGraphicsContext * CreateContext( const wxEnhMetaFileDC& dc); | |
1665 | #endif | |
1666 | ||
1667 | virtual wxGraphicsContext * CreateContextFromNativeContext( void * context ); | |
1668 | ||
1669 | virtual wxGraphicsContext * CreateContextFromNativeWindow( void * window ); | |
1670 | ||
1671 | virtual wxGraphicsContext * CreateContext( wxWindow* window ); | |
1672 | ||
1673 | virtual wxGraphicsContext * CreateMeasuringContext(); | |
1674 | ||
1675 | // Path | |
1676 | ||
1677 | virtual wxGraphicsPath CreatePath(); | |
1678 | ||
1679 | // Matrix | |
1680 | ||
1681 | virtual wxGraphicsMatrix CreateMatrix( wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0, | |
1682 | wxDouble tx=0.0, wxDouble ty=0.0); | |
1683 | ||
1684 | ||
1685 | virtual wxGraphicsPen CreatePen(const wxPen& pen) ; | |
1686 | ||
1687 | virtual wxGraphicsBrush CreateBrush(const wxBrush& brush ) ; | |
1688 | ||
1689 | virtual wxGraphicsBrush | |
1690 | CreateLinearGradientBrush(wxDouble x1, wxDouble y1, | |
1691 | wxDouble x2, wxDouble y2, | |
1692 | const wxGraphicsGradientStops& stops); | |
1693 | ||
1694 | virtual wxGraphicsBrush | |
1695 | CreateRadialGradientBrush(wxDouble xo, wxDouble yo, | |
1696 | wxDouble xc, wxDouble yc, | |
1697 | wxDouble radius, | |
1698 | const wxGraphicsGradientStops& stops); | |
1699 | // sets the font | |
1700 | virtual wxGraphicsFont CreateFont( const wxFont &font , const wxColour &col = *wxBLACK ) ; | |
1701 | ||
1702 | // create a native bitmap representation | |
1703 | virtual wxGraphicsBitmap CreateBitmap( const wxBitmap &bitmap ); | |
1704 | ||
1705 | // create a graphics bitmap from a native bitmap | |
1706 | virtual wxGraphicsBitmap CreateBitmapFromNativeBitmap( void* bitmap ); | |
1707 | ||
1708 | // create a subimage from a native image representation | |
1709 | virtual wxGraphicsBitmap CreateSubBitmap( const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h ); | |
1710 | ||
1711 | protected : | |
1712 | bool EnsureIsLoaded(); | |
1713 | void Load(); | |
1714 | void Unload(); | |
1715 | friend class wxGDIPlusRendererModule; | |
1716 | ||
1717 | private : | |
1718 | int m_loaded; | |
1719 | ULONG_PTR m_gditoken; | |
1720 | ||
1721 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxGDIPlusRenderer) | |
1722 | } ; | |
83576e68 SC |
1723 | |
1724 | //----------------------------------------------------------------------------- | |
1725 | // wxGDIPlusRenderer implementation | |
1726 | //----------------------------------------------------------------------------- | |
1727 | ||
1728 | IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusRenderer,wxGraphicsRenderer) | |
1729 | ||
1730 | static wxGDIPlusRenderer gs_GDIPlusRenderer; | |
1731 | ||
1732 | wxGraphicsRenderer* wxGraphicsRenderer::GetDefaultRenderer() | |
1733 | { | |
1734 | return &gs_GDIPlusRenderer; | |
1735 | } | |
1736 | ||
bce82a75 | 1737 | bool wxGDIPlusRenderer::EnsureIsLoaded() |
83576e68 | 1738 | { |
bce82a75 VS |
1739 | // load gdiplus.dll if not yet loaded, but don't bother doing it again |
1740 | // if we already tried and failed (we don't want to spend lot of time | |
1741 | // returning NULL from wxGraphicsContext::Create(), which may be called | |
1742 | // relatively frequently): | |
1743 | if ( m_loaded == -1 ) | |
83576e68 SC |
1744 | { |
1745 | Load(); | |
1746 | } | |
bce82a75 VS |
1747 | |
1748 | return m_loaded == 1; | |
83576e68 SC |
1749 | } |
1750 | ||
bce82a75 VS |
1751 | // call EnsureIsLoaded() and return returnOnFail value if it fails |
1752 | #define ENSURE_LOADED_OR_RETURN(returnOnFail) \ | |
1753 | if ( !EnsureIsLoaded() ) \ | |
1754 | return (returnOnFail) | |
1755 | ||
1756 | ||
83576e68 SC |
1757 | void wxGDIPlusRenderer::Load() |
1758 | { | |
1759 | GdiplusStartupInput input; | |
1760 | GdiplusStartupOutput output; | |
bce82a75 VS |
1761 | if ( GdiplusStartup(&m_gditoken,&input,&output) == Gdiplus::Ok ) |
1762 | { | |
1763 | wxLogTrace("gdiplus", "successfully initialized GDI+"); | |
1764 | m_loaded = 1; | |
1765 | } | |
1766 | else | |
1767 | { | |
1768 | wxLogTrace("gdiplus", "failed to initialize GDI+, missing gdiplus.dll?"); | |
1769 | m_loaded = 0; | |
1770 | } | |
83576e68 SC |
1771 | } |
1772 | ||
1773 | void wxGDIPlusRenderer::Unload() | |
1774 | { | |
1775 | if ( m_gditoken ) | |
385addaf | 1776 | { |
83576e68 | 1777 | GdiplusShutdown(m_gditoken); |
385addaf VZ |
1778 | m_gditoken = NULL; |
1779 | } | |
bce82a75 | 1780 | m_loaded = -1; // next Load() will try again |
83576e68 SC |
1781 | } |
1782 | ||
1783 | wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxWindowDC& dc) | |
1784 | { | |
bce82a75 | 1785 | ENSURE_LOADED_OR_RETURN(NULL); |
7fa3cf6a JS |
1786 | wxMSWDCImpl *msw = wxDynamicCast( dc.GetImpl() , wxMSWDCImpl ); |
1787 | wxSize sz = dc.GetSize(); | |
1788 | return new wxGDIPlusContext(this,(HDC) msw->GetHDC(), sz.x, sz.y); | |
83576e68 SC |
1789 | } |
1790 | ||
c929ad91 | 1791 | #if wxUSE_PRINTING_ARCHITECTURE |
0b822969 | 1792 | wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxPrinterDC& dc) |
8371a353 JS |
1793 | { |
1794 | ENSURE_LOADED_OR_RETURN(NULL); | |
7fa3cf6a JS |
1795 | wxMSWDCImpl *msw = wxDynamicCast( dc.GetImpl() , wxMSWDCImpl ); |
1796 | wxSize sz = dc.GetSize(); | |
1797 | return new wxGDIPlusContext(this,(HDC) msw->GetHDC(), sz.x, sz.y); | |
8371a353 | 1798 | } |
c929ad91 | 1799 | #endif |
8371a353 | 1800 | |
c929ad91 | 1801 | #if wxUSE_ENH_METAFILE |
8371a353 | 1802 | wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxEnhMetaFileDC& dc) |
0b822969 | 1803 | { |
bce82a75 | 1804 | ENSURE_LOADED_OR_RETURN(NULL); |
7fa3cf6a JS |
1805 | wxMSWDCImpl *msw = wxDynamicCast( dc.GetImpl() , wxMSWDCImpl ); |
1806 | wxSize sz = dc.GetSize(); | |
1807 | return new wxGDIPlusContext(this,(HDC) msw->GetHDC(), sz.x, sz.y); | |
0b822969 | 1808 | } |
c929ad91 | 1809 | #endif |
0b822969 | 1810 | |
773ccc31 SC |
1811 | wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxMemoryDC& dc) |
1812 | { | |
bce82a75 | 1813 | ENSURE_LOADED_OR_RETURN(NULL); |
7fa3cf6a JS |
1814 | wxMSWDCImpl *msw = wxDynamicCast( dc.GetImpl() , wxMSWDCImpl ); |
1815 | wxSize sz = dc.GetSize(); | |
1816 | return new wxGDIPlusContext(this,(HDC) msw->GetHDC(), sz.x, sz.y); | |
773ccc31 SC |
1817 | } |
1818 | ||
091ef146 SC |
1819 | wxGraphicsContext * wxGDIPlusRenderer::CreateMeasuringContext() |
1820 | { | |
bce82a75 | 1821 | ENSURE_LOADED_OR_RETURN(NULL); |
0c7bd159 | 1822 | return new wxGDIPlusMeasuringContext(this); |
091ef146 SC |
1823 | } |
1824 | ||
83576e68 SC |
1825 | wxGraphicsContext * wxGDIPlusRenderer::CreateContextFromNativeContext( void * context ) |
1826 | { | |
bce82a75 | 1827 | ENSURE_LOADED_OR_RETURN(NULL); |
83576e68 SC |
1828 | return new wxGDIPlusContext(this,(Graphics*) context); |
1829 | } | |
1830 | ||
1831 | ||
1832 | wxGraphicsContext * wxGDIPlusRenderer::CreateContextFromNativeWindow( void * window ) | |
1833 | { | |
bce82a75 | 1834 | ENSURE_LOADED_OR_RETURN(NULL); |
83576e68 SC |
1835 | return new wxGDIPlusContext(this,(HWND) window); |
1836 | } | |
1837 | ||
1838 | wxGraphicsContext * wxGDIPlusRenderer::CreateContext( wxWindow* window ) | |
1839 | { | |
bce82a75 | 1840 | ENSURE_LOADED_OR_RETURN(NULL); |
83576e68 SC |
1841 | return new wxGDIPlusContext(this, (HWND) window->GetHWND() ); |
1842 | } | |
1843 | ||
1844 | // Path | |
1845 | ||
a4e73390 | 1846 | wxGraphicsPath wxGDIPlusRenderer::CreatePath() |
83576e68 | 1847 | { |
bce82a75 | 1848 | ENSURE_LOADED_OR_RETURN(wxNullGraphicsPath); |
a4e73390 SC |
1849 | wxGraphicsPath m; |
1850 | m.SetRefData( new wxGDIPlusPathData(this)); | |
1851 | return m; | |
83576e68 SC |
1852 | } |
1853 | ||
1854 | ||
1855 | // Matrix | |
1856 | ||
cb3a0d42 | 1857 | wxGraphicsMatrix wxGDIPlusRenderer::CreateMatrix( wxDouble a, wxDouble b, wxDouble c, wxDouble d, |
83576e68 SC |
1858 | wxDouble tx, wxDouble ty) |
1859 | ||
1860 | { | |
bce82a75 | 1861 | ENSURE_LOADED_OR_RETURN(wxNullGraphicsMatrix); |
a4e73390 SC |
1862 | wxGraphicsMatrix m; |
1863 | wxGDIPlusMatrixData* data = new wxGDIPlusMatrixData( this ); | |
1864 | data->Set( a,b,c,d,tx,ty ) ; | |
1865 | m.SetRefData(data); | |
83576e68 | 1866 | return m; |
539e2795 SC |
1867 | } |
1868 | ||
cb3a0d42 | 1869 | wxGraphicsPen wxGDIPlusRenderer::CreatePen(const wxPen& pen) |
6fea499c | 1870 | { |
bce82a75 | 1871 | ENSURE_LOADED_OR_RETURN(wxNullGraphicsPen); |
83576e68 | 1872 | if ( !pen.Ok() || pen.GetStyle() == wxTRANSPARENT ) |
2c820406 | 1873 | return wxNullGraphicsPen; |
83576e68 | 1874 | else |
2c820406 SC |
1875 | { |
1876 | wxGraphicsPen p; | |
1877 | p.SetRefData(new wxGDIPlusPenData( this, pen )); | |
1878 | return p; | |
1879 | } | |
6fea499c | 1880 | } |
7ba86d93 | 1881 | |
cb3a0d42 | 1882 | wxGraphicsBrush wxGDIPlusRenderer::CreateBrush(const wxBrush& brush ) |
539e2795 | 1883 | { |
bce82a75 | 1884 | ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush); |
83576e68 | 1885 | if ( !brush.Ok() || brush.GetStyle() == wxTRANSPARENT ) |
2c820406 | 1886 | return wxNullGraphicsBrush; |
83576e68 | 1887 | else |
2c820406 SC |
1888 | { |
1889 | wxGraphicsBrush p; | |
1890 | p.SetRefData(new wxGDIPlusBrushData( this, brush )); | |
1891 | return p; | |
1892 | } | |
539e2795 SC |
1893 | } |
1894 | ||
4ee4c7b9 VZ |
1895 | wxGraphicsBrush |
1896 | wxGDIPlusRenderer::CreateLinearGradientBrush(wxDouble x1, wxDouble y1, | |
1897 | wxDouble x2, wxDouble y2, | |
1898 | const wxGraphicsGradientStops& stops) | |
539e2795 | 1899 | { |
bce82a75 | 1900 | ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush); |
2c820406 SC |
1901 | wxGraphicsBrush p; |
1902 | wxGDIPlusBrushData* d = new wxGDIPlusBrushData( this ); | |
4ee4c7b9 | 1903 | d->CreateLinearGradientBrush(x1, y1, x2, y2, stops); |
2c820406 SC |
1904 | p.SetRefData(d); |
1905 | return p; | |
1906 | } | |
539e2795 | 1907 | |
4ee4c7b9 VZ |
1908 | wxGraphicsBrush |
1909 | wxGDIPlusRenderer::CreateRadialGradientBrush(wxDouble xo, wxDouble yo, | |
1910 | wxDouble xc, wxDouble yc, | |
1911 | wxDouble radius, | |
1912 | const wxGraphicsGradientStops& stops) | |
83576e68 | 1913 | { |
bce82a75 | 1914 | ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush); |
2c820406 SC |
1915 | wxGraphicsBrush p; |
1916 | wxGDIPlusBrushData* d = new wxGDIPlusBrushData( this ); | |
4ee4c7b9 | 1917 | d->CreateRadialGradientBrush(xo,yo,xc,yc,radius,stops); |
2c820406 SC |
1918 | p.SetRefData(d); |
1919 | return p; | |
83576e68 | 1920 | } |
539e2795 | 1921 | |
7fa3cf6a JS |
1922 | // sets the font |
1923 | wxGraphicsFont wxGDIPlusRenderer::CreateFont( const wxFont &font , const wxColour &col ) | |
83576e68 | 1924 | { |
bce82a75 | 1925 | ENSURE_LOADED_OR_RETURN(wxNullGraphicsFont); |
83576e68 | 1926 | if ( font.Ok() ) |
cb3a0d42 | 1927 | { |
2c820406 | 1928 | wxGraphicsFont p; |
7fa3cf6a | 1929 | p.SetRefData(new wxGDIPlusFontData( this , font, col )); |
2c820406 SC |
1930 | return p; |
1931 | } | |
83576e68 | 1932 | else |
2c820406 | 1933 | return wxNullGraphicsFont; |
83576e68 | 1934 | } |
7ba86d93 | 1935 | |
bce28872 SC |
1936 | wxGraphicsBitmap wxGDIPlusRenderer::CreateBitmap( const wxBitmap &bitmap ) |
1937 | { | |
bce82a75 | 1938 | ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap); |
bce28872 SC |
1939 | if ( bitmap.Ok() ) |
1940 | { | |
1941 | wxGraphicsBitmap p; | |
1942 | p.SetRefData(new wxGDIPlusBitmapData( this , bitmap )); | |
1943 | return p; | |
1944 | } | |
1945 | else | |
1946 | return wxNullGraphicsBitmap; | |
1947 | } | |
1948 | ||
2986eb86 SC |
1949 | wxGraphicsBitmap wxGDIPlusRenderer::CreateBitmapFromNativeBitmap( void *bitmap ) |
1950 | { | |
1951 | ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap); | |
1952 | if ( bitmap != NULL ) | |
1953 | { | |
1954 | wxGraphicsBitmap p; | |
1955 | p.SetRefData(new wxGDIPlusBitmapData( this , (Bitmap*) bitmap )); | |
1956 | return p; | |
1957 | } | |
1958 | else | |
1959 | return wxNullGraphicsBitmap; | |
1960 | } | |
1961 | ||
bce28872 SC |
1962 | wxGraphicsBitmap wxGDIPlusRenderer::CreateSubBitmap( const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) |
1963 | { | |
bce82a75 | 1964 | ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap); |
bce28872 SC |
1965 | Bitmap* image = static_cast<wxGDIPlusBitmapData*>(bitmap.GetRefData())->GetGDIPlusBitmap(); |
1966 | if ( image ) | |
1967 | { | |
1968 | wxGraphicsBitmap p; | |
1969 | p.SetRefData(new wxGDIPlusBitmapData( this , image->Clone( (REAL) x , (REAL) y , (REAL) w , (REAL) h , PixelFormat32bppPARGB) )); | |
1970 | return p; | |
1971 | } | |
1972 | else | |
1973 | return wxNullGraphicsBitmap; | |
1974 | } | |
1975 | ||
385addaf VZ |
1976 | // Shutdown GDI+ at app exit, before possible dll unload |
1977 | class wxGDIPlusRendererModule : public wxModule | |
1978 | { | |
1979 | public: | |
1980 | virtual bool OnInit() { return true; } | |
1981 | virtual void OnExit() { gs_GDIPlusRenderer.Unload(); } | |
1982 | ||
1983 | private: | |
1984 | DECLARE_DYNAMIC_CLASS(wxGDIPlusRendererModule) | |
1985 | }; | |
1986 | ||
1987 | IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusRendererModule, wxModule) | |
1988 | ||
942d5e2d VZ |
1989 | // ---------------------------------------------------------------------------- |
1990 | // wxMSW-specific parts of wxGCDC | |
1991 | // ---------------------------------------------------------------------------- | |
1992 | ||
1993 | WXHDC wxGCDC::AcquireHDC() | |
1994 | { | |
1995 | wxGraphicsContext * const gc = GetGraphicsContext(); | |
1996 | if ( !gc ) | |
1997 | return NULL; | |
1998 | ||
1999 | Graphics * const g = static_cast<Graphics *>(gc->GetNativeContext()); | |
2000 | return g ? g->GetHDC() : NULL; | |
2001 | } | |
2002 | ||
2003 | void wxGCDC::ReleaseHDC(WXHDC hdc) | |
2004 | { | |
2005 | if ( !hdc ) | |
2006 | return; | |
2007 | ||
2008 | wxGraphicsContext * const gc = GetGraphicsContext(); | |
2009 | wxCHECK_RET( gc, "can't release HDC because there is no wxGraphicsContext" ); | |
2010 | ||
2011 | Graphics * const g = static_cast<Graphics *>(gc->GetNativeContext()); | |
2012 | wxCHECK_RET( g, "can't release HDC because there is no Graphics" ); | |
2013 | ||
2014 | g->ReleaseHDC((HDC)hdc); | |
2015 | } | |
2016 | ||
7ba86d93 | 2017 | #endif // wxUSE_GRAPHICS_CONTEXT |