]>
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 | |
942d5e2d | 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: | |
2c820406 SC |
292 | wxGDIPlusFontData( wxGraphicsRenderer* renderer, const wxFont &font, const wxColour& col ); |
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: |
81e0b3d9 | 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: | |
399 | HDC m_hdc ; | |
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 | { | |
519 | m_penImage = Bitmap::FromHBITMAP((HBITMAP)bmp->GetHBITMAP(),(HPALETTE)bmp->GetPalette()->GetHPALETTE()); | |
520 | m_penBrush = new TextureBrush(m_penImage); | |
521 | m_pen->SetBrush( m_penBrush ); | |
522 | } | |
523 | ||
524 | } | |
525 | break; | |
526 | default : | |
527 | if ( pen.GetStyle() >= wxFIRST_HATCH && pen.GetStyle() <= wxLAST_HATCH ) | |
528 | { | |
529 | HatchStyle style = HatchStyleHorizontal; | |
530 | switch( pen.GetStyle() ) | |
531 | { | |
532 | case wxBDIAGONAL_HATCH : | |
533 | style = HatchStyleBackwardDiagonal; | |
534 | break ; | |
535 | case wxCROSSDIAG_HATCH : | |
536 | style = HatchStyleDiagonalCross; | |
537 | break ; | |
538 | case wxFDIAGONAL_HATCH : | |
539 | style = HatchStyleForwardDiagonal; | |
540 | break ; | |
541 | case wxCROSS_HATCH : | |
542 | style = HatchStyleCross; | |
543 | break ; | |
544 | case wxHORIZONTAL_HATCH : | |
545 | style = HatchStyleHorizontal; | |
546 | break ; | |
547 | case wxVERTICAL_HATCH : | |
548 | style = HatchStyleVertical; | |
549 | break ; | |
550 | ||
551 | } | |
f49c80c1 VZ |
552 | m_penBrush = new HatchBrush |
553 | ( | |
554 | style, | |
555 | wxColourToColor(pen.GetColour()), | |
556 | Color::Transparent | |
557 | ); | |
83576e68 SC |
558 | m_pen->SetBrush( m_penBrush ); |
559 | } | |
560 | break; | |
cb3a0d42 | 561 | } |
83576e68 SC |
562 | if ( dashStyle != DashStyleSolid ) |
563 | m_pen->SetDashStyle(dashStyle); | |
564 | } | |
565 | ||
83576e68 SC |
566 | //----------------------------------------------------------------------------- |
567 | // wxGDIPlusBrush implementation | |
568 | //----------------------------------------------------------------------------- | |
569 | ||
2c820406 SC |
570 | wxGDIPlusBrushData::wxGDIPlusBrushData( wxGraphicsRenderer* renderer ) |
571 | : wxGraphicsObjectRefData(renderer) | |
83576e68 SC |
572 | { |
573 | Init(); | |
574 | } | |
575 | ||
2c820406 SC |
576 | wxGDIPlusBrushData::wxGDIPlusBrushData( wxGraphicsRenderer* renderer , const wxBrush &brush ) |
577 | : wxGraphicsObjectRefData(renderer) | |
83576e68 SC |
578 | { |
579 | Init(); | |
580 | if ( brush.GetStyle() == wxSOLID) | |
581 | { | |
f49c80c1 | 582 | m_brush = new SolidBrush(wxColourToColor( brush.GetColour())); |
83576e68 SC |
583 | } |
584 | else if ( brush.IsHatch() ) | |
585 | { | |
586 | HatchStyle style = HatchStyleHorizontal; | |
587 | switch( brush.GetStyle() ) | |
588 | { | |
589 | case wxBDIAGONAL_HATCH : | |
590 | style = HatchStyleBackwardDiagonal; | |
591 | break ; | |
592 | case wxCROSSDIAG_HATCH : | |
593 | style = HatchStyleDiagonalCross; | |
594 | break ; | |
595 | case wxFDIAGONAL_HATCH : | |
596 | style = HatchStyleForwardDiagonal; | |
597 | break ; | |
598 | case wxCROSS_HATCH : | |
599 | style = HatchStyleCross; | |
600 | break ; | |
601 | case wxHORIZONTAL_HATCH : | |
602 | style = HatchStyleHorizontal; | |
603 | break ; | |
604 | case wxVERTICAL_HATCH : | |
605 | style = HatchStyleVertical; | |
606 | break ; | |
607 | ||
608 | } | |
f49c80c1 VZ |
609 | m_brush = new HatchBrush |
610 | ( | |
611 | style, | |
612 | wxColourToColor(brush.GetColour()), | |
613 | Color::Transparent | |
614 | ); | |
83576e68 | 615 | } |
cb3a0d42 | 616 | else |
83576e68 SC |
617 | { |
618 | wxBitmap* bmp = brush.GetStipple(); | |
619 | if ( bmp && bmp->Ok() ) | |
620 | { | |
621 | wxDELETE( m_brushImage ); | |
622 | m_brushImage = Bitmap::FromHBITMAP((HBITMAP)bmp->GetHBITMAP(),(HPALETTE)bmp->GetPalette()->GetHPALETTE()); | |
623 | m_brush = new TextureBrush(m_brushImage); | |
624 | } | |
625 | } | |
626 | } | |
627 | ||
2c820406 | 628 | wxGDIPlusBrushData::~wxGDIPlusBrushData() |
83576e68 SC |
629 | { |
630 | delete m_brush; | |
631 | delete m_brushImage; | |
632 | delete m_brushPath; | |
633 | }; | |
634 | ||
2c820406 | 635 | void wxGDIPlusBrushData::Init() |
83576e68 SC |
636 | { |
637 | m_brush = NULL; | |
638 | m_brushImage= NULL; | |
639 | m_brushPath= NULL; | |
640 | } | |
641 | ||
4ee4c7b9 VZ |
642 | template <typename T> |
643 | void | |
644 | wxGDIPlusBrushData::SetGradientStops(T *brush, | |
645 | const wxGraphicsGradientStops& stops) | |
646 | { | |
647 | const unsigned numStops = stops.GetCount(); | |
648 | if ( numStops <= 2 ) | |
649 | { | |
650 | // initial and final colours are set during the brush creation, nothing | |
651 | // more to do | |
652 | return; | |
653 | } | |
654 | ||
655 | wxVector<Color> colors(numStops); | |
656 | wxVector<REAL> positions(numStops); | |
657 | ||
658 | for ( unsigned i = 0; i < numStops; i++ ) | |
659 | { | |
660 | wxGraphicsGradientStop stop = stops.Item(i); | |
661 | ||
662 | colors[i] = wxColourToColor(stop.GetColour()); | |
663 | positions[i] = stop.GetPosition(); | |
664 | } | |
665 | ||
666 | brush->SetInterpolationColors(&colors[0], &positions[0], numStops); | |
667 | } | |
668 | ||
669 | void | |
670 | wxGDIPlusBrushData::CreateLinearGradientBrush(wxDouble x1, wxDouble y1, | |
671 | wxDouble x2, wxDouble y2, | |
672 | const wxGraphicsGradientStops& stops) | |
83576e68 | 673 | { |
4ee4c7b9 VZ |
674 | LinearGradientBrush * const |
675 | brush = new LinearGradientBrush(PointF(x1, y1) , PointF(x2, y2), | |
676 | wxColourToColor(stops.GetStartColour()), | |
677 | wxColourToColor(stops.GetEndColour())); | |
678 | m_brush = brush; | |
679 | ||
680 | SetGradientStops(brush, stops); | |
83576e68 SC |
681 | } |
682 | ||
4ee4c7b9 VZ |
683 | void |
684 | wxGDIPlusBrushData::CreateRadialGradientBrush(wxDouble xo, wxDouble yo, | |
685 | wxDouble xc, wxDouble yc, | |
686 | wxDouble radius, | |
687 | const wxGraphicsGradientStops& stops) | |
83576e68 | 688 | { |
83576e68 | 689 | m_brushPath = new GraphicsPath(); |
4ee4c7b9 VZ |
690 | m_brushPath->AddEllipse( (REAL)(xc-radius), (REAL)(yc-radius), |
691 | (REAL)(2*radius), (REAL)(2*radius)); | |
83576e68 | 692 | |
4ee4c7b9 VZ |
693 | PathGradientBrush * const brush = new PathGradientBrush(m_brushPath); |
694 | m_brush = brush; | |
695 | brush->SetCenterPoint(PointF(xo, yo)); | |
696 | brush->SetCenterColor(wxColourToColor(stops.GetStartColour())); | |
83576e68 | 697 | |
4ee4c7b9 | 698 | const Color col(wxColourToColor(stops.GetEndColour())); |
83576e68 | 699 | int count = 1; |
4ee4c7b9 VZ |
700 | brush->SetSurroundColors(&col, &count); |
701 | ||
702 | SetGradientStops(brush, stops); | |
83576e68 SC |
703 | } |
704 | ||
83576e68 SC |
705 | //----------------------------------------------------------------------------- |
706 | // wxGDIPlusFont implementation | |
707 | //----------------------------------------------------------------------------- | |
708 | ||
cb3a0d42 | 709 | wxGDIPlusFontData::wxGDIPlusFontData( wxGraphicsRenderer* renderer, const wxFont &font, |
2c820406 | 710 | const wxColour& col ) : wxGraphicsObjectRefData( renderer ) |
83576e68 SC |
711 | { |
712 | m_textBrush = NULL; | |
713 | m_font = NULL; | |
714 | ||
715 | wxWCharBuffer s = font.GetFaceName().wc_str( *wxConvUI ); | |
716 | int size = font.GetPointSize(); | |
717 | int style = FontStyleRegular; | |
718 | if ( font.GetStyle() == wxFONTSTYLE_ITALIC ) | |
719 | style |= FontStyleItalic; | |
720 | if ( font.GetUnderlined() ) | |
721 | style |= FontStyleUnderline; | |
722 | if ( font.GetWeight() == wxFONTWEIGHT_BOLD ) | |
723 | style |= FontStyleBold; | |
724 | m_font = new Font( s , size , style ); | |
f49c80c1 | 725 | m_textBrush = new SolidBrush(wxColourToColor(col)); |
83576e68 | 726 | } |
6fea499c | 727 | |
2c820406 | 728 | wxGDIPlusFontData::~wxGDIPlusFontData() |
83576e68 SC |
729 | { |
730 | delete m_textBrush; | |
731 | delete m_font; | |
732 | } | |
6fea499c | 733 | |
bce28872 SC |
734 | // the built-in conversions functions create non-premultiplied bitmaps, while GDIPlus needs them in the |
735 | // premultiplied format, therefore in the failing cases we create a new bitmap using the non-premultiplied | |
736 | // bytes as parameter, since there is no real copying of the data going in, only references are stored | |
737 | // m_helper has to be kept alive as well | |
738 | ||
739 | //----------------------------------------------------------------------------- | |
740 | // wxGDIPlusBitmapData implementation | |
741 | //----------------------------------------------------------------------------- | |
742 | ||
743 | wxGDIPlusBitmapData::wxGDIPlusBitmapData( wxGraphicsRenderer* renderer, Bitmap* bitmap ) : | |
744 | wxGraphicsObjectRefData( renderer ), m_bitmap( bitmap ) | |
745 | { | |
746 | m_helper = NULL; | |
747 | } | |
748 | ||
0b7dce54 | 749 | wxGDIPlusBitmapData::wxGDIPlusBitmapData( wxGraphicsRenderer* renderer, |
bce28872 SC |
750 | const wxBitmap &bmp) : wxGraphicsObjectRefData( renderer ) |
751 | { | |
752 | m_bitmap = NULL; | |
753 | m_helper = NULL; | |
754 | ||
755 | Bitmap* image = NULL; | |
756 | if ( bmp.GetMask() ) | |
757 | { | |
758 | Bitmap interim((HBITMAP)bmp.GetHBITMAP(),(HPALETTE)bmp.GetPalette()->GetHPALETTE()) ; | |
759 | ||
760 | size_t width = interim.GetWidth(); | |
761 | size_t height = interim.GetHeight(); | |
762 | Rect bounds(0,0,width,height); | |
763 | ||
764 | image = new Bitmap(width,height,PixelFormat32bppPARGB) ; | |
765 | ||
766 | Bitmap interimMask((HBITMAP)bmp.GetMask()->GetMaskBitmap(),NULL); | |
767 | wxASSERT(interimMask.GetPixelFormat() == PixelFormat1bppIndexed); | |
768 | ||
769 | BitmapData dataMask ; | |
770 | interimMask.LockBits(&bounds,ImageLockModeRead, | |
771 | interimMask.GetPixelFormat(),&dataMask); | |
772 | ||
773 | ||
774 | BitmapData imageData ; | |
775 | image->LockBits(&bounds,ImageLockModeWrite, PixelFormat32bppPARGB, &imageData); | |
776 | ||
777 | BYTE maskPattern = 0 ; | |
778 | BYTE maskByte = 0; | |
779 | size_t maskIndex ; | |
780 | ||
781 | for ( size_t y = 0 ; y < height ; ++y) | |
782 | { | |
783 | maskIndex = 0 ; | |
784 | for( size_t x = 0 ; x < width; ++x) | |
785 | { | |
786 | if ( x % 8 == 0) | |
787 | { | |
788 | maskPattern = 0x80; | |
789 | maskByte = *((BYTE*)dataMask.Scan0 + dataMask.Stride*y + maskIndex); | |
790 | maskIndex++; | |
791 | } | |
792 | else | |
793 | maskPattern = maskPattern >> 1; | |
794 | ||
795 | ARGB *dest = (ARGB*)((BYTE*)imageData.Scan0 + imageData.Stride*y + x*4); | |
796 | if ( (maskByte & maskPattern) == 0 ) | |
797 | *dest = 0x00000000; | |
798 | else | |
799 | { | |
800 | Color c ; | |
801 | interim.GetPixel(x,y,&c) ; | |
802 | *dest = (c.GetValue() | Color::AlphaMask); | |
803 | } | |
804 | } | |
805 | } | |
806 | ||
807 | image->UnlockBits(&imageData); | |
808 | ||
809 | interimMask.UnlockBits(&dataMask); | |
810 | interim.UnlockBits(&dataMask); | |
811 | } | |
812 | else | |
813 | { | |
814 | image = Bitmap::FromHBITMAP((HBITMAP)bmp.GetHBITMAP(),(HPALETTE)bmp.GetPalette()->GetHPALETTE()); | |
815 | if ( bmp.HasAlpha() && GetPixelFormatSize(image->GetPixelFormat()) == 32 ) | |
816 | { | |
817 | size_t width = image->GetWidth(); | |
818 | size_t height = image->GetHeight(); | |
819 | Rect bounds(0,0,width,height); | |
820 | static BitmapData data ; | |
821 | ||
822 | m_helper = image ; | |
823 | image = NULL ; | |
824 | m_helper->LockBits(&bounds, ImageLockModeRead, | |
825 | m_helper->GetPixelFormat(),&data); | |
826 | ||
827 | image = new Bitmap(data.Width, data.Height, data.Stride, | |
828 | PixelFormat32bppPARGB , (BYTE*) data.Scan0); | |
829 | ||
830 | m_helper->UnlockBits(&data); | |
831 | } | |
832 | } | |
833 | if ( image ) | |
834 | m_bitmap = image; | |
835 | } | |
836 | ||
837 | wxGDIPlusBitmapData::~wxGDIPlusBitmapData() | |
838 | { | |
839 | delete m_bitmap; | |
840 | delete m_helper; | |
841 | } | |
842 | ||
83576e68 SC |
843 | //----------------------------------------------------------------------------- |
844 | // wxGDIPlusPath implementation | |
845 | //----------------------------------------------------------------------------- | |
6fea499c | 846 | |
a4e73390 | 847 | wxGDIPlusPathData::wxGDIPlusPathData(wxGraphicsRenderer* renderer, GraphicsPath* path ) : wxGraphicsPathData(renderer) |
83576e68 SC |
848 | { |
849 | if ( path ) | |
850 | m_path = path; | |
851 | else | |
852 | m_path = new GraphicsPath(); | |
853 | } | |
854 | ||
a4e73390 | 855 | wxGDIPlusPathData::~wxGDIPlusPathData() |
6fea499c SC |
856 | { |
857 | delete m_path; | |
858 | } | |
859 | ||
a4e73390 | 860 | wxGraphicsObjectRefData* wxGDIPlusPathData::Clone() const |
83576e68 | 861 | { |
a4e73390 | 862 | return new wxGDIPlusPathData( GetRenderer() , m_path->Clone()); |
83576e68 SC |
863 | } |
864 | ||
6fea499c SC |
865 | // |
866 | // The Primitives | |
867 | // | |
868 | ||
a4e73390 | 869 | void wxGDIPlusPathData::MoveToPoint( wxDouble x , wxDouble y ) |
6fea499c SC |
870 | { |
871 | m_path->StartFigure(); | |
872 | m_path->AddLine((REAL) x,(REAL) y,(REAL) x,(REAL) y); | |
873 | } | |
874 | ||
a4e73390 | 875 | void wxGDIPlusPathData::AddLineToPoint( wxDouble x , wxDouble y ) |
6fea499c SC |
876 | { |
877 | m_path->AddLine((REAL) x,(REAL) y,(REAL) x,(REAL) y); | |
878 | } | |
879 | ||
a4e73390 | 880 | void wxGDIPlusPathData::CloseSubpath() |
6fea499c SC |
881 | { |
882 | m_path->CloseFigure(); | |
883 | } | |
884 | ||
a4e73390 | 885 | void wxGDIPlusPathData::AddCurveToPoint( wxDouble cx1, wxDouble cy1, wxDouble cx2, wxDouble cy2, wxDouble x, wxDouble y ) |
6fea499c SC |
886 | { |
887 | PointF c1(cx1,cy1); | |
888 | PointF c2(cx2,cy2); | |
889 | PointF end(x,y); | |
890 | PointF start; | |
891 | m_path->GetLastPoint(&start); | |
892 | m_path->AddBezier(start,c1,c2,end); | |
893 | } | |
894 | ||
895 | // gets the last point of the current path, (0,0) if not yet set | |
a4e73390 | 896 | void wxGDIPlusPathData::GetCurrentPoint( wxDouble* x, wxDouble* y) const |
6fea499c SC |
897 | { |
898 | PointF start; | |
899 | m_path->GetLastPoint(&start); | |
a4e73390 SC |
900 | *x = start.X ; |
901 | *y = start.Y ; | |
6fea499c SC |
902 | } |
903 | ||
cb3a0d42 | 904 | void wxGDIPlusPathData::AddArc( wxDouble x, wxDouble y, wxDouble r, double startAngle, double endAngle, bool clockwise ) |
6fea499c SC |
905 | { |
906 | double sweepAngle = endAngle - startAngle ; | |
c5b8c66a | 907 | if( fabs(sweepAngle) >= 2*M_PI) |
6fea499c SC |
908 | { |
909 | sweepAngle = 2 * M_PI; | |
910 | } | |
911 | else | |
912 | { | |
913 | if ( clockwise ) | |
914 | { | |
915 | if( sweepAngle < 0 ) | |
916 | sweepAngle += 2 * M_PI; | |
917 | } | |
918 | else | |
919 | { | |
920 | if( sweepAngle > 0 ) | |
921 | sweepAngle -= 2 * M_PI; | |
922 | ||
923 | } | |
924 | } | |
cb3a0d42 | 925 | m_path->AddArc((REAL) (x-r),(REAL) (y-r),(REAL) (2*r),(REAL) (2*r),RadToDeg(startAngle),RadToDeg(sweepAngle)); |
6fea499c SC |
926 | } |
927 | ||
a4e73390 | 928 | void wxGDIPlusPathData::AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h ) |
6fea499c SC |
929 | { |
930 | m_path->AddRectangle(RectF(x,y,w,h)); | |
931 | } | |
932 | ||
a4e73390 | 933 | void wxGDIPlusPathData::AddPath( const wxGraphicsPathData* path ) |
6fea499c | 934 | { |
83576e68 | 935 | m_path->AddPath( (GraphicsPath*) path->GetNativePath(), FALSE); |
6fea499c SC |
936 | } |
937 | ||
6fea499c | 938 | |
83576e68 | 939 | // transforms each point of this path by the matrix |
cb3a0d42 | 940 | void wxGDIPlusPathData::Transform( const wxGraphicsMatrixData* matrix ) |
9f339b18 | 941 | { |
83576e68 | 942 | m_path->Transform( (Matrix*) matrix->GetNativeMatrix() ); |
9f339b18 | 943 | } |
6fea499c | 944 | |
83576e68 | 945 | // gets the bounding box enclosing all points (possibly including control points) |
a4e73390 | 946 | void wxGDIPlusPathData::GetBox(wxDouble *x, wxDouble *y, wxDouble *w, wxDouble *h) const |
e49c065d | 947 | { |
83576e68 SC |
948 | RectF bounds; |
949 | m_path->GetBounds( &bounds, NULL, NULL) ; | |
950 | *x = bounds.X; | |
951 | *y = bounds.Y; | |
952 | *w = bounds.Width; | |
953 | *h = bounds.Height; | |
e49c065d RD |
954 | } |
955 | ||
94a007ec | 956 | bool wxGDIPlusPathData::Contains( wxDouble x, wxDouble y, wxPolygonFillMode fillStyle ) const |
6fea499c | 957 | { |
83576e68 SC |
958 | m_path->SetFillMode( fillStyle == wxODDEVEN_RULE ? FillModeAlternate : FillModeWinding); |
959 | return m_path->IsVisible( (FLOAT) x,(FLOAT) y) == TRUE ; | |
960 | } | |
9f339b18 | 961 | |
83576e68 | 962 | //----------------------------------------------------------------------------- |
a4e73390 | 963 | // wxGDIPlusMatrixData implementation |
83576e68 | 964 | //----------------------------------------------------------------------------- |
9f339b18 | 965 | |
a4e73390 SC |
966 | wxGDIPlusMatrixData::wxGDIPlusMatrixData(wxGraphicsRenderer* renderer, Matrix* matrix ) |
967 | : wxGraphicsMatrixData(renderer) | |
9f339b18 | 968 | { |
83576e68 SC |
969 | if ( matrix ) |
970 | m_matrix = matrix ; | |
971 | else | |
972 | m_matrix = new Matrix(); | |
6fea499c SC |
973 | } |
974 | ||
cb3a0d42 | 975 | wxGDIPlusMatrixData::~wxGDIPlusMatrixData() |
6fea499c | 976 | { |
83576e68 | 977 | delete m_matrix; |
6fea499c SC |
978 | } |
979 | ||
cb3a0d42 | 980 | wxGraphicsObjectRefData *wxGDIPlusMatrixData::Clone() const |
6fea499c | 981 | { |
a4e73390 | 982 | return new wxGDIPlusMatrixData( GetRenderer(), m_matrix->Clone()); |
539e2795 SC |
983 | } |
984 | ||
83576e68 | 985 | // concatenates the matrix |
a4e73390 | 986 | void wxGDIPlusMatrixData::Concat( const wxGraphicsMatrixData *t ) |
539e2795 | 987 | { |
83576e68 | 988 | m_matrix->Multiply( (Matrix*) t->GetNativeMatrix()); |
539e2795 | 989 | } |
83576e68 | 990 | |
83576e68 | 991 | // sets the matrix to the respective values |
cb3a0d42 | 992 | void wxGDIPlusMatrixData::Set(wxDouble a, wxDouble b, wxDouble c, wxDouble d, |
83576e68 | 993 | wxDouble tx, wxDouble ty) |
6fea499c | 994 | { |
83576e68 | 995 | m_matrix->SetElements(a,b,c,d,tx,ty); |
6fea499c SC |
996 | } |
997 | ||
248802d0 RD |
998 | // gets the component valuess of the matrix |
999 | void wxGDIPlusMatrixData::Get(wxDouble* a, wxDouble* b, wxDouble* c, | |
1000 | wxDouble* d, wxDouble* tx, wxDouble* ty) const | |
1001 | { | |
1002 | REAL elements[6]; | |
1003 | m_matrix->GetElements(elements); | |
1004 | if (a) *a = elements[0]; | |
1005 | if (b) *b = elements[1]; | |
1006 | if (c) *c = elements[2]; | |
1007 | if (d) *d = elements[3]; | |
1008 | if (tx) *tx= elements[4]; | |
1009 | if (ty) *ty= elements[5]; | |
1010 | } | |
1011 | ||
83576e68 | 1012 | // makes this the inverse matrix |
a4e73390 | 1013 | void wxGDIPlusMatrixData::Invert() |
6fea499c | 1014 | { |
83576e68 | 1015 | m_matrix->Invert(); |
6fea499c SC |
1016 | } |
1017 | ||
83576e68 | 1018 | // returns true if the elements of the transformation matrix are equal ? |
cb3a0d42 | 1019 | bool wxGDIPlusMatrixData::IsEqual( const wxGraphicsMatrixData* t) const |
6fea499c | 1020 | { |
83576e68 | 1021 | return m_matrix->Equals((Matrix*) t->GetNativeMatrix())== TRUE ; |
6fea499c SC |
1022 | } |
1023 | ||
83576e68 | 1024 | // return true if this is the identity matrix |
a4e73390 | 1025 | bool wxGDIPlusMatrixData::IsIdentity() const |
6fea499c | 1026 | { |
83576e68 | 1027 | return m_matrix->IsIdentity() == TRUE ; |
6fea499c SC |
1028 | } |
1029 | ||
83576e68 SC |
1030 | // |
1031 | // transformation | |
1032 | // | |
1033 | ||
1034 | // add the translation to this matrix | |
a4e73390 | 1035 | void wxGDIPlusMatrixData::Translate( wxDouble dx , wxDouble dy ) |
6fea499c | 1036 | { |
83576e68 | 1037 | m_matrix->Translate(dx,dy); |
6fea499c SC |
1038 | } |
1039 | ||
83576e68 | 1040 | // add the scale to this matrix |
a4e73390 | 1041 | void wxGDIPlusMatrixData::Scale( wxDouble xScale , wxDouble yScale ) |
6fea499c | 1042 | { |
83576e68 | 1043 | m_matrix->Scale(xScale,yScale); |
6fea499c SC |
1044 | } |
1045 | ||
83576e68 | 1046 | // add the rotation to this matrix (radians) |
a4e73390 | 1047 | void wxGDIPlusMatrixData::Rotate( wxDouble angle ) |
6fea499c | 1048 | { |
6f32f3ce | 1049 | m_matrix->Rotate( RadToDeg(angle) ); |
6fea499c SC |
1050 | } |
1051 | ||
83576e68 SC |
1052 | // |
1053 | // apply the transforms | |
1054 | // | |
1055 | ||
1056 | // applies that matrix to the point | |
a4e73390 | 1057 | void wxGDIPlusMatrixData::TransformPoint( wxDouble *x, wxDouble *y ) const |
6fea499c | 1058 | { |
83576e68 SC |
1059 | PointF pt(*x,*y); |
1060 | m_matrix->TransformPoints(&pt); | |
1061 | *x = pt.X; | |
1062 | *y = pt.Y; | |
6fea499c SC |
1063 | } |
1064 | ||
83576e68 | 1065 | // applies the matrix except for translations |
a4e73390 | 1066 | void wxGDIPlusMatrixData::TransformDistance( wxDouble *dx, wxDouble *dy ) const |
6fea499c | 1067 | { |
83576e68 SC |
1068 | PointF pt(*dx,*dy); |
1069 | m_matrix->TransformVectors(&pt); | |
1070 | *dx = pt.X; | |
1071 | *dy = pt.Y; | |
6fea499c SC |
1072 | } |
1073 | ||
83576e68 | 1074 | // returns the native representation |
a4e73390 | 1075 | void * wxGDIPlusMatrixData::GetNativeMatrix() const |
6fea499c | 1076 | { |
83576e68 SC |
1077 | return m_matrix; |
1078 | } | |
6fea499c | 1079 | |
83576e68 SC |
1080 | //----------------------------------------------------------------------------- |
1081 | // wxGDIPlusContext implementation | |
1082 | //----------------------------------------------------------------------------- | |
1083 | ||
1084 | IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusContext,wxGraphicsContext) | |
0c7bd159 SC |
1085 | IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusMeasuringContext,wxGDIPlusContext) |
1086 | ||
1087 | class wxGDIPlusOffsetHelper | |
1088 | { | |
1089 | public : | |
1090 | wxGDIPlusOffsetHelper( Graphics* gr , bool offset ) | |
1091 | { | |
1092 | m_gr = gr; | |
1093 | m_offset = offset; | |
1094 | if ( m_offset ) | |
1095 | m_gr->TranslateTransform( 0.5, 0.5 ); | |
1096 | } | |
1097 | ~wxGDIPlusOffsetHelper( ) | |
1098 | { | |
1099 | if ( m_offset ) | |
1100 | m_gr->TranslateTransform( -0.5, -0.5 ); | |
1101 | } | |
1102 | public : | |
1103 | Graphics* m_gr; | |
1104 | bool m_offset; | |
1105 | } ; | |
83576e68 | 1106 | |
81e0b3d9 | 1107 | wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer* renderer, HDC hdc, wxDouble width, wxDouble height ) |
83576e68 SC |
1108 | : wxGraphicsContext(renderer) |
1109 | { | |
1110 | Init(); | |
1111 | m_context = new Graphics( hdc); | |
81e0b3d9 SC |
1112 | m_width = width; |
1113 | m_height = height; | |
83576e68 | 1114 | SetDefaults(); |
6fea499c SC |
1115 | } |
1116 | ||
83576e68 SC |
1117 | wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer* renderer, HWND hwnd ) |
1118 | : wxGraphicsContext(renderer) | |
6fea499c | 1119 | { |
83576e68 SC |
1120 | Init(); |
1121 | m_context = new Graphics( hwnd); | |
81e0b3d9 SC |
1122 | RECT rect = wxGetWindowRect(hwnd); |
1123 | m_width = rect.right - rect.left; | |
1124 | m_height = rect.bottom - rect.top; | |
83576e68 SC |
1125 | SetDefaults(); |
1126 | } | |
6fea499c | 1127 | |
83576e68 SC |
1128 | wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer* renderer, Graphics* gr ) |
1129 | : wxGraphicsContext(renderer) | |
1130 | { | |
1131 | Init(); | |
1132 | m_context = gr; | |
1133 | SetDefaults(); | |
1134 | } | |
6fea499c | 1135 | |
83576e68 SC |
1136 | wxGDIPlusContext::wxGDIPlusContext() : wxGraphicsContext(NULL) |
1137 | { | |
1138 | Init(); | |
1139 | } | |
6fea499c | 1140 | |
83576e68 SC |
1141 | void wxGDIPlusContext::Init() |
1142 | { | |
1143 | m_context = NULL; | |
1144 | m_state1 = 0; | |
1145 | m_state2= 0; | |
81e0b3d9 SC |
1146 | m_height = 0; |
1147 | m_width = 0; | |
83576e68 | 1148 | } |
6fea499c | 1149 | |
83576e68 SC |
1150 | void wxGDIPlusContext::SetDefaults() |
1151 | { | |
0c7bd159 SC |
1152 | m_context->SetTextRenderingHint(TextRenderingHintSystemDefault); |
1153 | m_context->SetPixelOffsetMode(PixelOffsetModeHalf); | |
83576e68 SC |
1154 | m_context->SetSmoothingMode(SmoothingModeHighQuality); |
1155 | m_state1 = m_context->Save(); | |
1156 | m_state2 = m_context->Save(); | |
a53b5e86 JS |
1157 | |
1158 | // Setup page scale, based on DPI ratio. | |
1159 | // Antecedent should be 100dpi when the default page unit (UnitDisplay) | |
1160 | // is used. Page unit UnitDocument would require 300dpi instead. | |
1161 | // Note that calling SetPageScale() does not have effect on non-printing | |
1162 | // DCs (that is, any other than wxPrinterDC or wxEnhMetaFileDC). | |
1163 | REAL dpiRatio = 100.0 / m_context->GetDpiY(); | |
1164 | m_context->SetPageScale(dpiRatio); | |
83576e68 | 1165 | } |
6fea499c | 1166 | |
83576e68 SC |
1167 | wxGDIPlusContext::~wxGDIPlusContext() |
1168 | { | |
83576e68 | 1169 | if ( m_context ) |
6fea499c | 1170 | { |
83576e68 SC |
1171 | m_context->Restore( m_state2 ); |
1172 | m_context->Restore( m_state1 ); | |
1173 | delete m_context; | |
6fea499c SC |
1174 | } |
1175 | } | |
1176 | ||
83576e68 SC |
1177 | |
1178 | void wxGDIPlusContext::Clip( const wxRegion ®ion ) | |
6fea499c | 1179 | { |
93f72bae SC |
1180 | Region rgn((HRGN)region.GetHRGN()); |
1181 | m_context->SetClip(&rgn,CombineModeIntersect); | |
83576e68 | 1182 | } |
6fea499c | 1183 | |
83576e68 SC |
1184 | void wxGDIPlusContext::Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h ) |
1185 | { | |
1186 | m_context->SetClip(RectF(x,y,w,h),CombineModeIntersect); | |
1187 | } | |
cb3a0d42 | 1188 | |
83576e68 SC |
1189 | void wxGDIPlusContext::ResetClip() |
1190 | { | |
1191 | m_context->ResetClip(); | |
1192 | } | |
6fea499c | 1193 | |
0c7bd159 SC |
1194 | void wxGDIPlusContext::StrokeLines( size_t n, const wxPoint2DDouble *points) |
1195 | { | |
bf02a7f9 SC |
1196 | if (m_composition == wxCOMPOSITION_DEST) |
1197 | return; | |
1198 | ||
03647350 VZ |
1199 | if ( !m_pen.IsNull() ) |
1200 | { | |
1201 | wxGDIPlusOffsetHelper helper( m_context , ShouldOffset() ); | |
1202 | Point *cpoints = new Point[n]; | |
1203 | for (size_t i = 0; i < n; i++) | |
1204 | { | |
1205 | cpoints[i].X = (int)(points[i].m_x ); | |
1206 | cpoints[i].Y = (int)(points[i].m_y ); | |
1207 | ||
1208 | } // for (size_t i = 0; i < n; i++) | |
1209 | m_context->DrawLines( ((wxGDIPlusPenData*)m_pen.GetGraphicsData())->GetGDIPlusPen() , cpoints , n ) ; | |
1210 | delete[] cpoints; | |
1211 | } | |
0c7bd159 SC |
1212 | } |
1213 | ||
94a007ec | 1214 | void wxGDIPlusContext::DrawLines( size_t n, const wxPoint2DDouble *points, wxPolygonFillMode WXUNUSED(fillStyle) ) |
0c7bd159 | 1215 | { |
bf02a7f9 SC |
1216 | if (m_composition == wxCOMPOSITION_DEST) |
1217 | return; | |
1218 | ||
0c7bd159 | 1219 | wxGDIPlusOffsetHelper helper( m_context , ShouldOffset() ); |
03647350 VZ |
1220 | Point *cpoints = new Point[n]; |
1221 | for (size_t i = 0; i < n; i++) | |
1222 | { | |
1223 | cpoints[i].X = (int)(points[i].m_x ); | |
1224 | cpoints[i].Y = (int)(points[i].m_y ); | |
1225 | ||
1226 | } // for (int i = 0; i < n; i++) | |
1227 | if ( !m_brush.IsNull() ) | |
1228 | m_context->FillPolygon( ((wxGDIPlusBrushData*)m_brush.GetRefData())->GetGDIPlusBrush() , cpoints , n ) ; | |
1229 | if ( !m_pen.IsNull() ) | |
1230 | m_context->DrawLines( ((wxGDIPlusPenData*)m_pen.GetGraphicsData())->GetGDIPlusPen() , cpoints , n ) ; | |
1231 | delete[] cpoints; | |
0c7bd159 SC |
1232 | } |
1233 | ||
a4e73390 | 1234 | void wxGDIPlusContext::StrokePath( const wxGraphicsPath& path ) |
83576e68 | 1235 | { |
bf02a7f9 SC |
1236 | if (m_composition == wxCOMPOSITION_DEST) |
1237 | return; | |
1238 | ||
2c820406 | 1239 | if ( !m_pen.IsNull() ) |
83576e68 | 1240 | { |
0c7bd159 | 1241 | wxGDIPlusOffsetHelper helper( m_context , ShouldOffset() ); |
a4e73390 | 1242 | m_context->DrawPath( ((wxGDIPlusPenData*)m_pen.GetGraphicsData())->GetGDIPlusPen() , (GraphicsPath*) path.GetNativePath() ); |
83576e68 | 1243 | } |
6fea499c SC |
1244 | } |
1245 | ||
94a007ec | 1246 | void wxGDIPlusContext::FillPath( const wxGraphicsPath& path , wxPolygonFillMode fillStyle ) |
6fea499c | 1247 | { |
bf02a7f9 SC |
1248 | if (m_composition == wxCOMPOSITION_DEST) |
1249 | return; | |
1250 | ||
2c820406 | 1251 | if ( !m_brush.IsNull() ) |
83576e68 | 1252 | { |
0c7bd159 | 1253 | wxGDIPlusOffsetHelper helper( m_context , ShouldOffset() ); |
a4e73390 | 1254 | ((GraphicsPath*) path.GetNativePath())->SetFillMode( fillStyle == wxODDEVEN_RULE ? FillModeAlternate : FillModeWinding); |
cb3a0d42 | 1255 | m_context->FillPath( ((wxGDIPlusBrushData*)m_brush.GetRefData())->GetGDIPlusBrush() , |
a4e73390 | 1256 | (GraphicsPath*) path.GetNativePath()); |
83576e68 SC |
1257 | } |
1258 | } | |
6fea499c | 1259 | |
bf02a7f9 SC |
1260 | bool wxGDIPlusContext::SetAntialiasMode(wxAntialiasMode antialias) |
1261 | { | |
1262 | if (m_antialias == antialias) | |
1263 | return true; | |
03647350 | 1264 | |
bf02a7f9 | 1265 | m_antialias = antialias; |
03647350 | 1266 | |
bf02a7f9 SC |
1267 | SmoothingMode antialiasMode; |
1268 | switch (antialias) | |
1269 | { | |
1270 | case wxANTIALIAS_DEFAULT: | |
1271 | antialiasMode = SmoothingModeHighQuality; | |
1272 | break; | |
1273 | case wxANTIALIAS_NONE: | |
1274 | antialiasMode = SmoothingModeNone; | |
1275 | break; | |
1276 | default: | |
1277 | return false; | |
1278 | } | |
1279 | m_context->SetSmoothingMode(antialiasMode); | |
1280 | return true; | |
1281 | } | |
1282 | ||
1283 | bool wxGDIPlusContext::SetCompositionMode(wxCompositionMode op) | |
1284 | { | |
1285 | if ( m_composition == op ) | |
1286 | return true; | |
03647350 | 1287 | |
bf02a7f9 | 1288 | m_composition = op; |
03647350 | 1289 | |
bf02a7f9 SC |
1290 | if (m_composition == wxCOMPOSITION_DEST) |
1291 | return true; | |
1292 | ||
1293 | CompositingMode cop; | |
1294 | switch (op) | |
1295 | { | |
1296 | case wxCOMPOSITION_SOURCE: | |
1297 | cop = CompositingModeSourceCopy; | |
1298 | break; | |
1299 | case wxCOMPOSITION_OVER: | |
1300 | cop = CompositingModeSourceOver; | |
1301 | break; | |
1302 | default: | |
1303 | return false; | |
1304 | } | |
1305 | ||
1306 | m_context->SetCompositingMode(cop); | |
1307 | return true; | |
1308 | } | |
1309 | ||
c496d8fa | 1310 | void wxGDIPlusContext::BeginLayer(wxDouble /* opacity */) |
bf02a7f9 SC |
1311 | { |
1312 | // TODO | |
1313 | } | |
1314 | ||
1315 | void wxGDIPlusContext::EndLayer() | |
1316 | { | |
1317 | // TODO | |
03647350 | 1318 | } |
bf02a7f9 | 1319 | |
cb3a0d42 | 1320 | void wxGDIPlusContext::Rotate( wxDouble angle ) |
83576e68 SC |
1321 | { |
1322 | m_context->RotateTransform( RadToDeg(angle) ); | |
1323 | } | |
6fea499c | 1324 | |
cb3a0d42 | 1325 | void wxGDIPlusContext::Translate( wxDouble dx , wxDouble dy ) |
83576e68 SC |
1326 | { |
1327 | m_context->TranslateTransform( dx , dy ); | |
1328 | } | |
6fea499c | 1329 | |
83576e68 SC |
1330 | void wxGDIPlusContext::Scale( wxDouble xScale , wxDouble yScale ) |
1331 | { | |
1332 | m_context->ScaleTransform(xScale,yScale); | |
1333 | } | |
6fea499c | 1334 | |
83576e68 SC |
1335 | void wxGDIPlusContext::PushState() |
1336 | { | |
1337 | GraphicsState state = m_context->Save(); | |
bdba6fdc | 1338 | m_stateStack.push(state); |
83576e68 SC |
1339 | } |
1340 | ||
cb3a0d42 | 1341 | void wxGDIPlusContext::PopState() |
83576e68 | 1342 | { |
bdba6fdc VZ |
1343 | GraphicsState state = m_stateStack.top(); |
1344 | m_stateStack.pop(); | |
83576e68 | 1345 | m_context->Restore(state); |
6fea499c SC |
1346 | } |
1347 | ||
bce28872 | 1348 | void wxGDIPlusContext::DrawBitmap( const wxGraphicsBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) |
6fea499c | 1349 | { |
bf02a7f9 SC |
1350 | if (m_composition == wxCOMPOSITION_DEST) |
1351 | return; | |
1352 | ||
bce28872 SC |
1353 | Bitmap* image = static_cast<wxGDIPlusBitmapData*>(bmp.GetRefData())->GetGDIPlusBitmap(); |
1354 | if ( image ) | |
cb3a0d42 | 1355 | { |
bce28872 | 1356 | if( image->GetWidth() != (UINT) w || image->GetHeight() != (UINT) h ) |
fe31db81 | 1357 | { |
bce28872 SC |
1358 | Rect drawRect((REAL) x, (REAL)y, (REAL)w, (REAL)h); |
1359 | m_context->SetPixelOffsetMode( PixelOffsetModeNone ); | |
1360 | m_context->DrawImage(image, drawRect, 0 , 0 , image->GetWidth()-1, image->GetHeight()-1, UnitPixel ) ; | |
1361 | m_context->SetPixelOffsetMode( PixelOffsetModeHalf ); | |
fe31db81 | 1362 | } |
bce28872 SC |
1363 | else |
1364 | m_context->DrawImage(image,(REAL) x,(REAL) y,(REAL) w,(REAL) h) ; | |
fe31db81 | 1365 | } |
bce28872 | 1366 | } |
fe31db81 | 1367 | |
bce28872 SC |
1368 | void wxGDIPlusContext::DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) |
1369 | { | |
1370 | wxGraphicsBitmap bitmap = GetRenderer()->CreateBitmap(bmp); | |
1371 | DrawBitmap(bitmap, x, y, w, h); | |
6fea499c SC |
1372 | } |
1373 | ||
cb3a0d42 | 1374 | void wxGDIPlusContext::DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) |
6fea499c | 1375 | { |
bf02a7f9 SC |
1376 | if (m_composition == wxCOMPOSITION_DEST) |
1377 | return; | |
1378 | ||
0c7bd159 SC |
1379 | // the built-in conversion fails when there is alpha in the HICON (eg XP style icons), we can only |
1380 | // find out by looking at the bitmap data whether there really was alpha in it | |
fe31db81 SC |
1381 | HICON hIcon = (HICON)icon.GetHICON(); |
1382 | ICONINFO iconInfo ; | |
1383 | // IconInfo creates the bitmaps for color and mask, we must dispose of them after use | |
1384 | if (!GetIconInfo(hIcon,&iconInfo)) | |
1385 | return; | |
1386 | ||
fe31db81 SC |
1387 | Bitmap interim(iconInfo.hbmColor,NULL); |
1388 | ||
1389 | Bitmap* image = NULL ; | |
1390 | ||
0c7bd159 SC |
1391 | // if it's not 32 bit, it doesn't have an alpha channel, note that since the conversion doesn't |
1392 | // work correctly, asking IsAlphaPixelFormat at this point fails as well | |
fe31db81 SC |
1393 | if( GetPixelFormatSize(interim.GetPixelFormat())!= 32 ) |
1394 | { | |
1395 | image = Bitmap::FromHICON(hIcon); | |
1396 | } | |
1397 | else | |
1398 | { | |
1399 | size_t width = interim.GetWidth(); | |
1400 | size_t height = interim.GetHeight(); | |
1401 | Rect bounds(0,0,width,height); | |
1402 | BitmapData data ; | |
1403 | ||
1404 | interim.LockBits(&bounds, ImageLockModeRead, | |
1405 | interim.GetPixelFormat(),&data); | |
0b7dce54 | 1406 | |
0c7bd159 SC |
1407 | bool hasAlpha = false; |
1408 | for ( size_t y = 0 ; y < height && !hasAlpha ; ++y) | |
1409 | { | |
1410 | for( size_t x = 0 ; x < width && !hasAlpha; ++x) | |
1411 | { | |
1412 | ARGB *dest = (ARGB*)((BYTE*)data.Scan0 + data.Stride*y + x*4); | |
1413 | if ( ( *dest & Color::AlphaMask ) != 0 ) | |
1414 | hasAlpha = true; | |
1415 | } | |
1416 | } | |
1417 | ||
1418 | if ( hasAlpha ) | |
1419 | { | |
cb3a0d42 | 1420 | image = new Bitmap(data.Width, data.Height, data.Stride, |
fe31db81 | 1421 | PixelFormat32bppARGB , (BYTE*) data.Scan0); |
0c7bd159 SC |
1422 | } |
1423 | else | |
1424 | { | |
1425 | image = Bitmap::FromHICON(hIcon); | |
1426 | } | |
1427 | ||
fe31db81 SC |
1428 | interim.UnlockBits(&data); |
1429 | } | |
1430 | ||
6fea499c | 1431 | m_context->DrawImage(image,(REAL) x,(REAL) y,(REAL) w,(REAL) h) ; |
fe31db81 | 1432 | |
6fea499c | 1433 | delete image ; |
fe31db81 SC |
1434 | DeleteObject(iconInfo.hbmColor); |
1435 | DeleteObject(iconInfo.hbmMask); | |
6fea499c SC |
1436 | } |
1437 | ||
0b7dce54 VZ |
1438 | void wxGDIPlusContext::DoDrawFilledText(const wxString& str, |
1439 | wxDouble x, wxDouble y, | |
1440 | const wxGraphicsBrush& brush) | |
6fea499c | 1441 | { |
bf02a7f9 SC |
1442 | if (m_composition == wxCOMPOSITION_DEST) |
1443 | return; | |
1444 | ||
0b7dce54 VZ |
1445 | wxCHECK_RET( !m_font.IsNull(), |
1446 | wxT("wxGDIPlusContext::DrawText - no valid font set") ); | |
1011fbeb SC |
1447 | |
1448 | if ( str.IsEmpty()) | |
6fea499c SC |
1449 | return ; |
1450 | ||
091111d6 | 1451 | wxGDIPlusFontData * const |
0b7dce54 | 1452 | fontData = (wxGDIPlusFontData *)m_font.GetRefData(); |
091111d6 VZ |
1453 | wxGDIPlusBrushData * const |
1454 | brushData = (wxGDIPlusBrushData *)brush.GetRefData(); | |
0b7dce54 VZ |
1455 | |
1456 | m_context->DrawString | |
1457 | ( | |
1458 | str.wc_str(*wxConvUI), // string to draw, always Unicode | |
1459 | -1, // length: string is NUL-terminated | |
1460 | fontData->GetGDIPlusFont(), | |
1461 | PointF(x, y), | |
1462 | StringFormat::GenericTypographic(), | |
1463 | brushData ? brushData->GetGDIPlusBrush() | |
1464 | : fontData->GetGDIPlusBrush() | |
1465 | ); | |
6fea499c SC |
1466 | } |
1467 | ||
1468 | void wxGDIPlusContext::GetTextExtent( const wxString &str, wxDouble *width, wxDouble *height, | |
1469 | wxDouble *descent, wxDouble *externalLeading ) const | |
1470 | { | |
1011fbeb SC |
1471 | wxCHECK_RET( !m_font.IsNull(), wxT("wxGDIPlusContext::GetTextExtent - no valid font set") ); |
1472 | ||
6fea499c SC |
1473 | wxWCharBuffer s = str.wc_str( *wxConvUI ); |
1474 | FontFamily ffamily ; | |
2c820406 | 1475 | Font* f = ((wxGDIPlusFontData*)m_font.GetRefData())->GetGDIPlusFont(); |
cb3a0d42 | 1476 | |
83576e68 | 1477 | f->GetFamily(&ffamily) ; |
6fea499c SC |
1478 | |
1479 | REAL factorY = m_context->GetDpiY() / 72.0 ; | |
1480 | ||
1481 | REAL rDescent = ffamily.GetCellDescent(FontStyleRegular) * | |
83576e68 | 1482 | f->GetSize() / ffamily.GetEmHeight(FontStyleRegular); |
6fea499c | 1483 | REAL rAscent = ffamily.GetCellAscent(FontStyleRegular) * |
83576e68 | 1484 | f->GetSize() / ffamily.GetEmHeight(FontStyleRegular); |
6fea499c | 1485 | REAL rHeight = ffamily.GetLineSpacing(FontStyleRegular) * |
83576e68 | 1486 | f->GetSize() / ffamily.GetEmHeight(FontStyleRegular); |
6fea499c SC |
1487 | |
1488 | if ( height ) | |
595fda6f | 1489 | *height = rHeight * factorY; |
6fea499c | 1490 | if ( descent ) |
595fda6f | 1491 | *descent = rDescent * factorY; |
6fea499c | 1492 | if ( externalLeading ) |
595fda6f | 1493 | *externalLeading = (rHeight - rAscent - rDescent) * factorY; |
6fea499c | 1494 | // measuring empty strings is not guaranteed, so do it by hand |
cb3a0d42 | 1495 | if ( str.IsEmpty()) |
6fea499c SC |
1496 | { |
1497 | if ( width ) | |
1498 | *width = 0 ; | |
1499 | } | |
1500 | else | |
1501 | { | |
6fea499c | 1502 | RectF layoutRect(0,0, 100000.0f, 100000.0f); |
0c7bd159 | 1503 | StringFormat strFormat( StringFormat::GenericTypographic() ); |
0b7dce54 | 1504 | strFormat.SetFormatFlags( StringFormatFlagsMeasureTrailingSpaces | strFormat.GetFormatFlags() ); |
0c7bd159 SC |
1505 | |
1506 | RectF bounds ; | |
1507 | m_context->MeasureString((const wchar_t *) s , wcslen(s) , f, layoutRect, &strFormat, &bounds ) ; | |
6fea499c | 1508 | if ( width ) |
0c7bd159 | 1509 | *width = bounds.Width; |
465642da JS |
1510 | if ( height ) |
1511 | *height = bounds.Height; | |
6fea499c SC |
1512 | } |
1513 | } | |
1514 | ||
cb3a0d42 | 1515 | void wxGDIPlusContext::GetPartialTextExtents(const wxString& text, wxArrayDouble& widths) const |
6fea499c SC |
1516 | { |
1517 | widths.Empty(); | |
1518 | widths.Add(0, text.length()); | |
1519 | ||
1011fbeb SC |
1520 | wxCHECK_RET( !m_font.IsNull(), wxT("wxGDIPlusContext::GetPartialTextExtents - no valid font set") ); |
1521 | ||
6fea499c SC |
1522 | if (text.empty()) |
1523 | return; | |
1524 | ||
2c820406 | 1525 | Font* f = ((wxGDIPlusFontData*)m_font.GetRefData())->GetGDIPlusFont(); |
6fea499c SC |
1526 | wxWCharBuffer ws = text.wc_str( *wxConvUI ); |
1527 | size_t len = wcslen( ws ) ; | |
1528 | wxASSERT_MSG(text.length() == len , wxT("GetPartialTextExtents not yet implemented for multichar situations")); | |
1529 | ||
1530 | RectF layoutRect(0,0, 100000.0f, 100000.0f); | |
0c7bd159 | 1531 | StringFormat strFormat( StringFormat::GenericTypographic() ); |
6fea499c | 1532 | |
c315587c | 1533 | size_t startPosition = 0; |
918df9d2 | 1534 | size_t remainder = len; |
c315587c SC |
1535 | const size_t maxSpan = 32; |
1536 | CharacterRange* ranges = new CharacterRange[maxSpan] ; | |
1537 | Region* regions = new Region[maxSpan]; | |
6fea499c | 1538 | |
918df9d2 | 1539 | while( remainder > 0 ) |
6fea499c | 1540 | { |
918df9d2 | 1541 | size_t span = wxMin( maxSpan, remainder ); |
c315587c SC |
1542 | |
1543 | for( size_t i = 0 ; i < span ; ++i) | |
1544 | { | |
1545 | ranges[i].First = 0 ; | |
1546 | ranges[i].Length = startPosition+i+1 ; | |
1547 | } | |
1548 | strFormat.SetMeasurableCharacterRanges(span,ranges); | |
1549 | strFormat.SetFormatFlags( StringFormatFlagsMeasureTrailingSpaces | strFormat.GetFormatFlags() ); | |
1550 | m_context->MeasureCharacterRanges(ws, -1 , f,layoutRect, &strFormat,span,regions) ; | |
1551 | ||
1552 | RectF bbox ; | |
1553 | for ( size_t i = 0 ; i < span ; ++i) | |
1554 | { | |
1555 | regions[i].GetBounds(&bbox,m_context); | |
1556 | widths[startPosition+i] = bbox.Width; | |
1557 | } | |
918df9d2 | 1558 | remainder -= span; |
c315587c | 1559 | startPosition += span; |
6fea499c | 1560 | } |
c315587c SC |
1561 | |
1562 | delete[] ranges; | |
1563 | delete[] regions; | |
6fea499c SC |
1564 | } |
1565 | ||
d9485f89 | 1566 | bool wxGDIPlusContext::ShouldOffset() const |
0b7dce54 | 1567 | { |
d9485f89 RD |
1568 | int penwidth = 0 ; |
1569 | if ( !m_pen.IsNull() ) | |
1570 | { | |
1571 | penwidth = (int)((wxGDIPlusPenData*)m_pen.GetRefData())->GetWidth(); | |
1572 | if ( penwidth == 0 ) | |
1573 | penwidth = 1; | |
1574 | } | |
1575 | return ( penwidth % 2 ) == 1; | |
1576 | } | |
1577 | ||
cb3a0d42 | 1578 | void* wxGDIPlusContext::GetNativeContext() |
6fea499c | 1579 | { |
cb3a0d42 | 1580 | return m_context; |
6fea499c SC |
1581 | } |
1582 | ||
83576e68 | 1583 | // concatenates this transform with the current transform of this context |
a4e73390 | 1584 | void wxGDIPlusContext::ConcatTransform( const wxGraphicsMatrix& matrix ) |
539e2795 | 1585 | { |
a4e73390 | 1586 | m_context->MultiplyTransform((Matrix*) matrix.GetNativeMatrix()); |
83576e68 SC |
1587 | } |
1588 | ||
1589 | // sets the transform of this context | |
a4e73390 | 1590 | void wxGDIPlusContext::SetTransform( const wxGraphicsMatrix& matrix ) |
83576e68 | 1591 | { |
a4e73390 | 1592 | m_context->SetTransform((Matrix*) matrix.GetNativeMatrix()); |
83576e68 SC |
1593 | } |
1594 | ||
1595 | // gets the matrix of this context | |
a4e73390 | 1596 | wxGraphicsMatrix wxGDIPlusContext::GetTransform() const |
83576e68 | 1597 | { |
a4e73390 SC |
1598 | wxGraphicsMatrix matrix = CreateMatrix(); |
1599 | m_context->GetTransform((Matrix*) matrix.GetNativeMatrix()); | |
1600 | return matrix; | |
83576e68 | 1601 | } |
fbd5416f SC |
1602 | |
1603 | void wxGDIPlusContext::GetSize( wxDouble* width, wxDouble *height ) | |
1604 | { | |
81e0b3d9 SC |
1605 | *width = m_width; |
1606 | *height = m_height; | |
fbd5416f | 1607 | } |
83576e68 SC |
1608 | //----------------------------------------------------------------------------- |
1609 | // wxGDIPlusRenderer declaration | |
1610 | //----------------------------------------------------------------------------- | |
1611 | ||
eb4083ef | 1612 | class wxGDIPlusRenderer : public wxGraphicsRenderer |
83576e68 SC |
1613 | { |
1614 | public : | |
cb3a0d42 | 1615 | wxGDIPlusRenderer() |
83576e68 | 1616 | { |
bce82a75 | 1617 | m_loaded = -1; |
cb3a0d42 | 1618 | m_gditoken = 0; |
83576e68 SC |
1619 | } |
1620 | ||
cb3a0d42 | 1621 | virtual ~wxGDIPlusRenderer() |
83576e68 | 1622 | { |
bce82a75 | 1623 | if ( m_loaded == 1 ) |
83576e68 SC |
1624 | { |
1625 | Unload(); | |
1626 | } | |
1627 | } | |
1628 | ||
1629 | // Context | |
1630 | ||
1631 | virtual wxGraphicsContext * CreateContext( const wxWindowDC& dc); | |
1632 | ||
773ccc31 SC |
1633 | virtual wxGraphicsContext * CreateContext( const wxMemoryDC& dc); |
1634 | ||
c929ad91 | 1635 | #if wxUSE_PRINTING_ARCHITECTURE |
0b822969 | 1636 | virtual wxGraphicsContext * CreateContext( const wxPrinterDC& dc); |
c929ad91 | 1637 | #endif |
0b7dce54 | 1638 | |
c929ad91 | 1639 | #if wxUSE_ENH_METAFILE |
8371a353 | 1640 | virtual wxGraphicsContext * CreateContext( const wxEnhMetaFileDC& dc); |
c929ad91 | 1641 | #endif |
8371a353 | 1642 | |
83576e68 SC |
1643 | virtual wxGraphicsContext * CreateContextFromNativeContext( void * context ); |
1644 | ||
1645 | virtual wxGraphicsContext * CreateContextFromNativeWindow( void * window ); | |
1646 | ||
1647 | virtual wxGraphicsContext * CreateContext( wxWindow* window ); | |
1648 | ||
091ef146 SC |
1649 | virtual wxGraphicsContext * CreateMeasuringContext(); |
1650 | ||
83576e68 SC |
1651 | // Path |
1652 | ||
a4e73390 | 1653 | virtual wxGraphicsPath CreatePath(); |
83576e68 SC |
1654 | |
1655 | // Matrix | |
1656 | ||
cb3a0d42 | 1657 | virtual wxGraphicsMatrix CreateMatrix( wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0, |
83576e68 SC |
1658 | wxDouble tx=0.0, wxDouble ty=0.0); |
1659 | ||
1660 | ||
2c820406 | 1661 | virtual wxGraphicsPen CreatePen(const wxPen& pen) ; |
83576e68 | 1662 | |
2c820406 | 1663 | virtual wxGraphicsBrush CreateBrush(const wxBrush& brush ) ; |
83576e68 | 1664 | |
4ee4c7b9 VZ |
1665 | virtual wxGraphicsBrush |
1666 | CreateLinearGradientBrush(wxDouble x1, wxDouble y1, | |
1667 | wxDouble x2, wxDouble y2, | |
1668 | const wxGraphicsGradientStops& stops); | |
83576e68 | 1669 | |
4ee4c7b9 VZ |
1670 | virtual wxGraphicsBrush |
1671 | CreateRadialGradientBrush(wxDouble xo, wxDouble yo, | |
1672 | wxDouble xc, wxDouble yc, | |
1673 | wxDouble radius, | |
1674 | const wxGraphicsGradientStops& stops); | |
83576e68 | 1675 | // sets the font |
2c820406 | 1676 | virtual wxGraphicsFont CreateFont( const wxFont &font , const wxColour &col = *wxBLACK ) ; |
bce28872 SC |
1677 | |
1678 | // create a native bitmap representation | |
1679 | virtual wxGraphicsBitmap CreateBitmap( const wxBitmap &bitmap ); | |
0b7dce54 | 1680 | |
2986eb86 SC |
1681 | // create a graphics bitmap from a native bitmap |
1682 | virtual wxGraphicsBitmap CreateBitmapFromNativeBitmap( void* bitmap ); | |
4ee4c7b9 | 1683 | |
bce28872 SC |
1684 | // create a subimage from a native image representation |
1685 | virtual wxGraphicsBitmap CreateSubBitmap( const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h ); | |
1686 | ||
83576e68 | 1687 | protected : |
bce82a75 | 1688 | bool EnsureIsLoaded(); |
83576e68 SC |
1689 | void Load(); |
1690 | void Unload(); | |
385addaf | 1691 | friend class wxGDIPlusRendererModule; |
83576e68 SC |
1692 | |
1693 | private : | |
bce82a75 | 1694 | int m_loaded; |
cb3a0d42 | 1695 | ULONG_PTR m_gditoken; |
83576e68 SC |
1696 | |
1697 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxGDIPlusRenderer) | |
1698 | } ; | |
1699 | ||
1700 | //----------------------------------------------------------------------------- | |
1701 | // wxGDIPlusRenderer implementation | |
1702 | //----------------------------------------------------------------------------- | |
1703 | ||
1704 | IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusRenderer,wxGraphicsRenderer) | |
1705 | ||
1706 | static wxGDIPlusRenderer gs_GDIPlusRenderer; | |
1707 | ||
1708 | wxGraphicsRenderer* wxGraphicsRenderer::GetDefaultRenderer() | |
1709 | { | |
1710 | return &gs_GDIPlusRenderer; | |
1711 | } | |
1712 | ||
bce82a75 | 1713 | bool wxGDIPlusRenderer::EnsureIsLoaded() |
83576e68 | 1714 | { |
bce82a75 VS |
1715 | // load gdiplus.dll if not yet loaded, but don't bother doing it again |
1716 | // if we already tried and failed (we don't want to spend lot of time | |
1717 | // returning NULL from wxGraphicsContext::Create(), which may be called | |
1718 | // relatively frequently): | |
1719 | if ( m_loaded == -1 ) | |
83576e68 SC |
1720 | { |
1721 | Load(); | |
1722 | } | |
bce82a75 VS |
1723 | |
1724 | return m_loaded == 1; | |
83576e68 SC |
1725 | } |
1726 | ||
bce82a75 VS |
1727 | // call EnsureIsLoaded() and return returnOnFail value if it fails |
1728 | #define ENSURE_LOADED_OR_RETURN(returnOnFail) \ | |
1729 | if ( !EnsureIsLoaded() ) \ | |
1730 | return (returnOnFail) | |
1731 | ||
1732 | ||
83576e68 SC |
1733 | void wxGDIPlusRenderer::Load() |
1734 | { | |
1735 | GdiplusStartupInput input; | |
1736 | GdiplusStartupOutput output; | |
bce82a75 VS |
1737 | if ( GdiplusStartup(&m_gditoken,&input,&output) == Gdiplus::Ok ) |
1738 | { | |
1739 | wxLogTrace("gdiplus", "successfully initialized GDI+"); | |
1740 | m_loaded = 1; | |
1741 | } | |
1742 | else | |
1743 | { | |
1744 | wxLogTrace("gdiplus", "failed to initialize GDI+, missing gdiplus.dll?"); | |
1745 | m_loaded = 0; | |
1746 | } | |
83576e68 SC |
1747 | } |
1748 | ||
1749 | void wxGDIPlusRenderer::Unload() | |
1750 | { | |
1751 | if ( m_gditoken ) | |
385addaf | 1752 | { |
83576e68 | 1753 | GdiplusShutdown(m_gditoken); |
385addaf VZ |
1754 | m_gditoken = NULL; |
1755 | } | |
bce82a75 | 1756 | m_loaded = -1; // next Load() will try again |
83576e68 SC |
1757 | } |
1758 | ||
1759 | wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxWindowDC& dc) | |
1760 | { | |
bce82a75 | 1761 | ENSURE_LOADED_OR_RETURN(NULL); |
52018692 | 1762 | wxMSWDCImpl *msw = wxDynamicCast( dc.GetImpl() , wxMSWDCImpl ); |
81e0b3d9 SC |
1763 | wxSize sz = dc.GetSize(); |
1764 | return new wxGDIPlusContext(this,(HDC) msw->GetHDC(), sz.x, sz.y); | |
83576e68 SC |
1765 | } |
1766 | ||
c929ad91 | 1767 | #if wxUSE_PRINTING_ARCHITECTURE |
0b822969 | 1768 | wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxPrinterDC& dc) |
8371a353 JS |
1769 | { |
1770 | ENSURE_LOADED_OR_RETURN(NULL); | |
1771 | wxMSWDCImpl *msw = wxDynamicCast( dc.GetImpl() , wxMSWDCImpl ); | |
1772 | wxSize sz = dc.GetSize(); | |
1773 | return new wxGDIPlusContext(this,(HDC) msw->GetHDC(), sz.x, sz.y); | |
1774 | } | |
c929ad91 | 1775 | #endif |
8371a353 | 1776 | |
c929ad91 | 1777 | #if wxUSE_ENH_METAFILE |
8371a353 | 1778 | wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxEnhMetaFileDC& dc) |
0b822969 | 1779 | { |
bce82a75 | 1780 | ENSURE_LOADED_OR_RETURN(NULL); |
0b822969 | 1781 | wxMSWDCImpl *msw = wxDynamicCast( dc.GetImpl() , wxMSWDCImpl ); |
81e0b3d9 SC |
1782 | wxSize sz = dc.GetSize(); |
1783 | return new wxGDIPlusContext(this,(HDC) msw->GetHDC(), sz.x, sz.y); | |
0b822969 | 1784 | } |
c929ad91 | 1785 | #endif |
0b822969 | 1786 | |
773ccc31 SC |
1787 | wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxMemoryDC& dc) |
1788 | { | |
bce82a75 | 1789 | ENSURE_LOADED_OR_RETURN(NULL); |
52018692 | 1790 | wxMSWDCImpl *msw = wxDynamicCast( dc.GetImpl() , wxMSWDCImpl ); |
81e0b3d9 SC |
1791 | wxSize sz = dc.GetSize(); |
1792 | return new wxGDIPlusContext(this,(HDC) msw->GetHDC(), sz.x, sz.y); | |
773ccc31 SC |
1793 | } |
1794 | ||
091ef146 SC |
1795 | wxGraphicsContext * wxGDIPlusRenderer::CreateMeasuringContext() |
1796 | { | |
bce82a75 | 1797 | ENSURE_LOADED_OR_RETURN(NULL); |
0c7bd159 | 1798 | return new wxGDIPlusMeasuringContext(this); |
091ef146 SC |
1799 | } |
1800 | ||
83576e68 SC |
1801 | wxGraphicsContext * wxGDIPlusRenderer::CreateContextFromNativeContext( void * context ) |
1802 | { | |
bce82a75 | 1803 | ENSURE_LOADED_OR_RETURN(NULL); |
83576e68 SC |
1804 | return new wxGDIPlusContext(this,(Graphics*) context); |
1805 | } | |
1806 | ||
1807 | ||
1808 | wxGraphicsContext * wxGDIPlusRenderer::CreateContextFromNativeWindow( void * window ) | |
1809 | { | |
bce82a75 | 1810 | ENSURE_LOADED_OR_RETURN(NULL); |
83576e68 SC |
1811 | return new wxGDIPlusContext(this,(HWND) window); |
1812 | } | |
1813 | ||
1814 | wxGraphicsContext * wxGDIPlusRenderer::CreateContext( wxWindow* window ) | |
1815 | { | |
bce82a75 | 1816 | ENSURE_LOADED_OR_RETURN(NULL); |
83576e68 SC |
1817 | return new wxGDIPlusContext(this, (HWND) window->GetHWND() ); |
1818 | } | |
1819 | ||
1820 | // Path | |
1821 | ||
a4e73390 | 1822 | wxGraphicsPath wxGDIPlusRenderer::CreatePath() |
83576e68 | 1823 | { |
bce82a75 | 1824 | ENSURE_LOADED_OR_RETURN(wxNullGraphicsPath); |
a4e73390 SC |
1825 | wxGraphicsPath m; |
1826 | m.SetRefData( new wxGDIPlusPathData(this)); | |
1827 | return m; | |
83576e68 SC |
1828 | } |
1829 | ||
1830 | ||
1831 | // Matrix | |
1832 | ||
cb3a0d42 | 1833 | wxGraphicsMatrix wxGDIPlusRenderer::CreateMatrix( wxDouble a, wxDouble b, wxDouble c, wxDouble d, |
83576e68 SC |
1834 | wxDouble tx, wxDouble ty) |
1835 | ||
1836 | { | |
bce82a75 | 1837 | ENSURE_LOADED_OR_RETURN(wxNullGraphicsMatrix); |
a4e73390 SC |
1838 | wxGraphicsMatrix m; |
1839 | wxGDIPlusMatrixData* data = new wxGDIPlusMatrixData( this ); | |
1840 | data->Set( a,b,c,d,tx,ty ) ; | |
1841 | m.SetRefData(data); | |
83576e68 | 1842 | return m; |
539e2795 SC |
1843 | } |
1844 | ||
cb3a0d42 | 1845 | wxGraphicsPen wxGDIPlusRenderer::CreatePen(const wxPen& pen) |
6fea499c | 1846 | { |
bce82a75 | 1847 | ENSURE_LOADED_OR_RETURN(wxNullGraphicsPen); |
83576e68 | 1848 | if ( !pen.Ok() || pen.GetStyle() == wxTRANSPARENT ) |
2c820406 | 1849 | return wxNullGraphicsPen; |
83576e68 | 1850 | else |
2c820406 SC |
1851 | { |
1852 | wxGraphicsPen p; | |
1853 | p.SetRefData(new wxGDIPlusPenData( this, pen )); | |
1854 | return p; | |
1855 | } | |
6fea499c | 1856 | } |
7ba86d93 | 1857 | |
cb3a0d42 | 1858 | wxGraphicsBrush wxGDIPlusRenderer::CreateBrush(const wxBrush& brush ) |
539e2795 | 1859 | { |
bce82a75 | 1860 | ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush); |
83576e68 | 1861 | if ( !brush.Ok() || brush.GetStyle() == wxTRANSPARENT ) |
2c820406 | 1862 | return wxNullGraphicsBrush; |
83576e68 | 1863 | else |
2c820406 SC |
1864 | { |
1865 | wxGraphicsBrush p; | |
1866 | p.SetRefData(new wxGDIPlusBrushData( this, brush )); | |
1867 | return p; | |
1868 | } | |
539e2795 SC |
1869 | } |
1870 | ||
4ee4c7b9 VZ |
1871 | wxGraphicsBrush |
1872 | wxGDIPlusRenderer::CreateLinearGradientBrush(wxDouble x1, wxDouble y1, | |
1873 | wxDouble x2, wxDouble y2, | |
1874 | const wxGraphicsGradientStops& stops) | |
539e2795 | 1875 | { |
bce82a75 | 1876 | ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush); |
2c820406 SC |
1877 | wxGraphicsBrush p; |
1878 | wxGDIPlusBrushData* d = new wxGDIPlusBrushData( this ); | |
4ee4c7b9 | 1879 | d->CreateLinearGradientBrush(x1, y1, x2, y2, stops); |
2c820406 SC |
1880 | p.SetRefData(d); |
1881 | return p; | |
1882 | } | |
539e2795 | 1883 | |
4ee4c7b9 VZ |
1884 | wxGraphicsBrush |
1885 | wxGDIPlusRenderer::CreateRadialGradientBrush(wxDouble xo, wxDouble yo, | |
1886 | wxDouble xc, wxDouble yc, | |
1887 | wxDouble radius, | |
1888 | const wxGraphicsGradientStops& stops) | |
83576e68 | 1889 | { |
bce82a75 | 1890 | ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush); |
2c820406 SC |
1891 | wxGraphicsBrush p; |
1892 | wxGDIPlusBrushData* d = new wxGDIPlusBrushData( this ); | |
4ee4c7b9 | 1893 | d->CreateRadialGradientBrush(xo,yo,xc,yc,radius,stops); |
2c820406 SC |
1894 | p.SetRefData(d); |
1895 | return p; | |
83576e68 | 1896 | } |
539e2795 | 1897 | |
83576e68 | 1898 | // sets the font |
cb3a0d42 | 1899 | wxGraphicsFont wxGDIPlusRenderer::CreateFont( const wxFont &font , const wxColour &col ) |
83576e68 | 1900 | { |
bce82a75 | 1901 | ENSURE_LOADED_OR_RETURN(wxNullGraphicsFont); |
83576e68 | 1902 | if ( font.Ok() ) |
cb3a0d42 | 1903 | { |
2c820406 SC |
1904 | wxGraphicsFont p; |
1905 | p.SetRefData(new wxGDIPlusFontData( this , font, col )); | |
1906 | return p; | |
1907 | } | |
83576e68 | 1908 | else |
2c820406 | 1909 | return wxNullGraphicsFont; |
83576e68 | 1910 | } |
7ba86d93 | 1911 | |
bce28872 SC |
1912 | wxGraphicsBitmap wxGDIPlusRenderer::CreateBitmap( const wxBitmap &bitmap ) |
1913 | { | |
bce82a75 | 1914 | ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap); |
bce28872 SC |
1915 | if ( bitmap.Ok() ) |
1916 | { | |
1917 | wxGraphicsBitmap p; | |
1918 | p.SetRefData(new wxGDIPlusBitmapData( this , bitmap )); | |
1919 | return p; | |
1920 | } | |
1921 | else | |
1922 | return wxNullGraphicsBitmap; | |
1923 | } | |
1924 | ||
2986eb86 SC |
1925 | wxGraphicsBitmap wxGDIPlusRenderer::CreateBitmapFromNativeBitmap( void *bitmap ) |
1926 | { | |
1927 | ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap); | |
1928 | if ( bitmap != NULL ) | |
1929 | { | |
1930 | wxGraphicsBitmap p; | |
1931 | p.SetRefData(new wxGDIPlusBitmapData( this , (Bitmap*) bitmap )); | |
1932 | return p; | |
1933 | } | |
1934 | else | |
1935 | return wxNullGraphicsBitmap; | |
1936 | } | |
1937 | ||
bce28872 SC |
1938 | wxGraphicsBitmap wxGDIPlusRenderer::CreateSubBitmap( const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) |
1939 | { | |
bce82a75 | 1940 | ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap); |
bce28872 SC |
1941 | Bitmap* image = static_cast<wxGDIPlusBitmapData*>(bitmap.GetRefData())->GetGDIPlusBitmap(); |
1942 | if ( image ) | |
1943 | { | |
1944 | wxGraphicsBitmap p; | |
1945 | p.SetRefData(new wxGDIPlusBitmapData( this , image->Clone( (REAL) x , (REAL) y , (REAL) w , (REAL) h , PixelFormat32bppPARGB) )); | |
1946 | return p; | |
1947 | } | |
1948 | else | |
1949 | return wxNullGraphicsBitmap; | |
1950 | } | |
1951 | ||
385addaf VZ |
1952 | // Shutdown GDI+ at app exit, before possible dll unload |
1953 | class wxGDIPlusRendererModule : public wxModule | |
1954 | { | |
1955 | public: | |
1956 | virtual bool OnInit() { return true; } | |
1957 | virtual void OnExit() { gs_GDIPlusRenderer.Unload(); } | |
1958 | ||
1959 | private: | |
1960 | DECLARE_DYNAMIC_CLASS(wxGDIPlusRendererModule) | |
1961 | }; | |
1962 | ||
1963 | IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusRendererModule, wxModule) | |
1964 | ||
942d5e2d VZ |
1965 | // ---------------------------------------------------------------------------- |
1966 | // wxMSW-specific parts of wxGCDC | |
1967 | // ---------------------------------------------------------------------------- | |
1968 | ||
1969 | WXHDC wxGCDC::AcquireHDC() | |
1970 | { | |
1971 | wxGraphicsContext * const gc = GetGraphicsContext(); | |
1972 | if ( !gc ) | |
1973 | return NULL; | |
1974 | ||
1975 | Graphics * const g = static_cast<Graphics *>(gc->GetNativeContext()); | |
1976 | return g ? g->GetHDC() : NULL; | |
1977 | } | |
1978 | ||
1979 | void wxGCDC::ReleaseHDC(WXHDC hdc) | |
1980 | { | |
1981 | if ( !hdc ) | |
1982 | return; | |
1983 | ||
1984 | wxGraphicsContext * const gc = GetGraphicsContext(); | |
1985 | wxCHECK_RET( gc, "can't release HDC because there is no wxGraphicsContext" ); | |
1986 | ||
1987 | Graphics * const g = static_cast<Graphics *>(gc->GetNativeContext()); | |
1988 | wxCHECK_RET( g, "can't release HDC because there is no Graphics" ); | |
1989 | ||
1990 | g->ReleaseHDC((HDC)hdc); | |
1991 | } | |
1992 | ||
7ba86d93 | 1993 | #endif // wxUSE_GRAPHICS_CONTEXT |