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