Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | pmbaty | 1 | |
2 | /*=========================================================================*\ |
||
3 | |||
4 | Copyright (c) Microsoft Corporation. All rights reserved. |
||
5 | |||
6 | File: D2D1helper.h |
||
7 | |||
8 | Module Name: D2D |
||
9 | |||
10 | Description: Helper files over the D2D interfaces and APIs. |
||
11 | |||
12 | \*=========================================================================*/ |
||
13 | #pragma once |
||
14 | |||
15 | #ifndef _D2D1_HELPER_H_ |
||
16 | #define _D2D1_HELPER_H_ |
||
17 | |||
18 | #ifndef _D2D1_H_ |
||
19 | #include <d2d1.h> |
||
20 | #endif // #ifndef _D2D1_H_ |
||
21 | |||
22 | #ifndef D2D_USE_C_DEFINITIONS |
||
23 | |||
24 | namespace D2D1 |
||
25 | { |
||
26 | // |
||
27 | // Forward declared IdentityMatrix function to allow matrix class to use |
||
28 | // these constructors. |
||
29 | // |
||
30 | D2D1FORCEINLINE |
||
31 | D2D1_MATRIX_3X2_F |
||
32 | IdentityMatrix(); |
||
33 | |||
34 | // |
||
35 | // The default trait type for objects in D2D is float. |
||
36 | // |
||
37 | template<typename Type> |
||
38 | struct TypeTraits |
||
39 | { |
||
40 | typedef D2D1_POINT_2F Point; |
||
41 | typedef D2D1_SIZE_F Size; |
||
42 | typedef D2D1_RECT_F Rect; |
||
43 | }; |
||
44 | |||
45 | template<> |
||
46 | struct TypeTraits<UINT32> |
||
47 | { |
||
48 | typedef D2D1_POINT_2U Point; |
||
49 | typedef D2D1_SIZE_U Size; |
||
50 | typedef D2D1_RECT_U Rect; |
||
51 | }; |
||
52 | |||
53 | static inline |
||
54 | FLOAT FloatMax() |
||
55 | { |
||
56 | #ifdef FLT_MAX |
||
57 | return FLT_MAX; |
||
58 | #else |
||
59 | return 3.402823466e+38F; |
||
60 | #endif |
||
61 | } |
||
62 | |||
63 | // |
||
64 | // Construction helpers |
||
65 | // |
||
66 | template<typename Type> |
||
67 | D2D1FORCEINLINE |
||
68 | typename TypeTraits<Type>::Point |
||
69 | Point2( |
||
70 | Type x, |
||
71 | Type y |
||
72 | ) |
||
73 | { |
||
74 | typename TypeTraits<Type>::Point point = { x, y }; |
||
75 | |||
76 | return point; |
||
77 | } |
||
78 | |||
79 | D2D1FORCEINLINE |
||
80 | D2D1_POINT_2F |
||
81 | Point2F( |
||
82 | FLOAT x = 0.f, |
||
83 | FLOAT y = 0.f |
||
84 | ) |
||
85 | { |
||
86 | return Point2<FLOAT>(x, y); |
||
87 | } |
||
88 | |||
89 | D2D1FORCEINLINE |
||
90 | D2D1_POINT_2U |
||
91 | Point2U( |
||
92 | UINT32 x = 0, |
||
93 | UINT32 y = 0 |
||
94 | ) |
||
95 | { |
||
96 | return Point2<UINT32>(x, y); |
||
97 | } |
||
98 | |||
99 | template<typename Type> |
||
100 | D2D1FORCEINLINE |
||
101 | typename TypeTraits<Type>::Size |
||
102 | Size( |
||
103 | Type width, |
||
104 | Type height |
||
105 | ) |
||
106 | { |
||
107 | typename TypeTraits<Type>::Size size = { width, height }; |
||
108 | |||
109 | return size; |
||
110 | } |
||
111 | |||
112 | D2D1FORCEINLINE |
||
113 | D2D1_SIZE_F |
||
114 | SizeF( |
||
115 | FLOAT width = 0.f, |
||
116 | FLOAT height = 0.f |
||
117 | ) |
||
118 | { |
||
119 | return Size<FLOAT>(width, height); |
||
120 | } |
||
121 | |||
122 | D2D1FORCEINLINE |
||
123 | D2D1_SIZE_U |
||
124 | SizeU( |
||
125 | UINT32 width = 0, |
||
126 | UINT32 height = 0 |
||
127 | ) |
||
128 | { |
||
129 | return Size<UINT32>(width, height); |
||
130 | } |
||
131 | |||
132 | template<typename Type> |
||
133 | D2D1FORCEINLINE |
||
134 | typename TypeTraits<Type>::Rect |
||
135 | Rect( |
||
136 | Type left, |
||
137 | Type top, |
||
138 | Type right, |
||
139 | Type bottom |
||
140 | ) |
||
141 | { |
||
142 | typename TypeTraits<Type>::Rect rect = { left, top, right, bottom }; |
||
143 | |||
144 | return rect; |
||
145 | } |
||
146 | |||
147 | D2D1FORCEINLINE |
||
148 | D2D1_RECT_F |
||
149 | RectF( |
||
150 | FLOAT left = 0.f, |
||
151 | FLOAT top = 0.f, |
||
152 | FLOAT right = 0.f, |
||
153 | FLOAT bottom = 0.f |
||
154 | ) |
||
155 | { |
||
156 | return Rect<FLOAT>(left, top, right, bottom); |
||
157 | } |
||
158 | |||
159 | D2D1FORCEINLINE |
||
160 | D2D1_RECT_U |
||
161 | RectU( |
||
162 | UINT32 left = 0, |
||
163 | UINT32 top = 0, |
||
164 | UINT32 right = 0, |
||
165 | UINT32 bottom = 0 |
||
166 | ) |
||
167 | { |
||
168 | return Rect<UINT32>(left, top, right, bottom); |
||
169 | } |
||
170 | |||
171 | D2D1FORCEINLINE |
||
172 | D2D1_RECT_F |
||
173 | InfiniteRect() |
||
174 | { |
||
175 | D2D1_RECT_F rect = { -FloatMax(), -FloatMax(), FloatMax(), FloatMax() }; |
||
176 | |||
177 | return rect; |
||
178 | } |
||
179 | |||
180 | D2D1FORCEINLINE |
||
181 | D2D1_ARC_SEGMENT |
||
182 | ArcSegment( |
||
183 | __in CONST D2D1_POINT_2F &point, |
||
184 | __in CONST D2D1_SIZE_F &size, |
||
185 | __in FLOAT rotationAngle, |
||
186 | __in D2D1_SWEEP_DIRECTION sweepDirection, |
||
187 | __in D2D1_ARC_SIZE arcSize |
||
188 | ) |
||
189 | { |
||
190 | D2D1_ARC_SEGMENT arcSegment = { point, size, rotationAngle, sweepDirection, arcSize }; |
||
191 | |||
192 | return arcSegment; |
||
193 | } |
||
194 | |||
195 | D2D1FORCEINLINE |
||
196 | D2D1_BEZIER_SEGMENT |
||
197 | BezierSegment( |
||
198 | __in CONST D2D1_POINT_2F &point1, |
||
199 | __in CONST D2D1_POINT_2F &point2, |
||
200 | __in CONST D2D1_POINT_2F &point3 |
||
201 | ) |
||
202 | { |
||
203 | D2D1_BEZIER_SEGMENT bezierSegment = { point1, point2, point3 }; |
||
204 | |||
205 | return bezierSegment; |
||
206 | } |
||
207 | |||
208 | D2D1FORCEINLINE |
||
209 | D2D1_ELLIPSE |
||
210 | Ellipse( |
||
211 | __in CONST D2D1_POINT_2F ¢er, |
||
212 | FLOAT radiusX, |
||
213 | FLOAT radiusY |
||
214 | ) |
||
215 | { |
||
216 | D2D1_ELLIPSE ellipse; |
||
217 | |||
218 | ellipse.point = center; |
||
219 | ellipse.radiusX = radiusX; |
||
220 | ellipse.radiusY = radiusY; |
||
221 | |||
222 | return ellipse; |
||
223 | } |
||
224 | |||
225 | D2D1FORCEINLINE |
||
226 | D2D1_ROUNDED_RECT |
||
227 | RoundedRect( |
||
228 | __in CONST D2D1_RECT_F &rect, |
||
229 | FLOAT radiusX, |
||
230 | FLOAT radiusY |
||
231 | ) |
||
232 | { |
||
233 | D2D1_ROUNDED_RECT roundedRect; |
||
234 | |||
235 | roundedRect.rect = rect; |
||
236 | roundedRect.radiusX = radiusX; |
||
237 | roundedRect.radiusY = radiusY; |
||
238 | |||
239 | return roundedRect; |
||
240 | } |
||
241 | |||
242 | D2D1FORCEINLINE |
||
243 | D2D1_BRUSH_PROPERTIES |
||
244 | BrushProperties( |
||
245 | __in FLOAT opacity = 1.0, |
||
246 | __in CONST D2D1_MATRIX_3X2_F &transform = D2D1::IdentityMatrix() |
||
247 | ) |
||
248 | { |
||
249 | D2D1_BRUSH_PROPERTIES brushProperties; |
||
250 | |||
251 | brushProperties.opacity = opacity; |
||
252 | brushProperties.transform = transform; |
||
253 | |||
254 | return brushProperties; |
||
255 | } |
||
256 | |||
257 | D2D1FORCEINLINE |
||
258 | D2D1_GRADIENT_STOP |
||
259 | GradientStop( |
||
260 | FLOAT position, |
||
261 | __in CONST D2D1_COLOR_F &color |
||
262 | ) |
||
263 | { |
||
264 | D2D1_GRADIENT_STOP gradientStop = { position, color }; |
||
265 | |||
266 | return gradientStop; |
||
267 | } |
||
268 | |||
269 | D2D1FORCEINLINE |
||
270 | D2D1_QUADRATIC_BEZIER_SEGMENT |
||
271 | QuadraticBezierSegment( |
||
272 | __in CONST D2D1_POINT_2F &point1, |
||
273 | __in CONST D2D1_POINT_2F &point2 |
||
274 | ) |
||
275 | { |
||
276 | D2D1_QUADRATIC_BEZIER_SEGMENT quadraticBezier = { point1, point2 }; |
||
277 | |||
278 | return quadraticBezier; |
||
279 | } |
||
280 | |||
281 | D2D1FORCEINLINE |
||
282 | D2D1_STROKE_STYLE_PROPERTIES |
||
283 | StrokeStyleProperties( |
||
284 | D2D1_CAP_STYLE startCap = D2D1_CAP_STYLE_FLAT, |
||
285 | D2D1_CAP_STYLE endCap = D2D1_CAP_STYLE_FLAT, |
||
286 | D2D1_CAP_STYLE dashCap = D2D1_CAP_STYLE_FLAT, |
||
287 | D2D1_LINE_JOIN lineJoin = D2D1_LINE_JOIN_MITER, |
||
288 | FLOAT miterLimit = 10.0f, |
||
289 | D2D1_DASH_STYLE dashStyle = D2D1_DASH_STYLE_SOLID, |
||
290 | FLOAT dashOffset = 0.0f |
||
291 | ) |
||
292 | { |
||
293 | D2D1_STROKE_STYLE_PROPERTIES strokeStyleProperties; |
||
294 | |||
295 | strokeStyleProperties.startCap = startCap; |
||
296 | strokeStyleProperties.endCap = endCap; |
||
297 | strokeStyleProperties.dashCap = dashCap; |
||
298 | strokeStyleProperties.lineJoin = lineJoin; |
||
299 | strokeStyleProperties.miterLimit = miterLimit; |
||
300 | strokeStyleProperties.dashStyle = dashStyle; |
||
301 | strokeStyleProperties.dashOffset = dashOffset; |
||
302 | |||
303 | return strokeStyleProperties; |
||
304 | } |
||
305 | |||
306 | D2D1FORCEINLINE |
||
307 | D2D1_BITMAP_BRUSH_PROPERTIES |
||
308 | BitmapBrushProperties( |
||
309 | D2D1_EXTEND_MODE extendModeX = D2D1_EXTEND_MODE_CLAMP, |
||
310 | D2D1_EXTEND_MODE extendModeY = D2D1_EXTEND_MODE_CLAMP, |
||
311 | D2D1_BITMAP_INTERPOLATION_MODE interpolationMode = D2D1_BITMAP_INTERPOLATION_MODE_LINEAR |
||
312 | ) |
||
313 | { |
||
314 | D2D1_BITMAP_BRUSH_PROPERTIES bitmapBrushProperties; |
||
315 | |||
316 | bitmapBrushProperties.extendModeX = extendModeX; |
||
317 | bitmapBrushProperties.extendModeY = extendModeY; |
||
318 | bitmapBrushProperties.interpolationMode = interpolationMode; |
||
319 | |||
320 | return bitmapBrushProperties; |
||
321 | } |
||
322 | |||
323 | D2D1FORCEINLINE |
||
324 | D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES |
||
325 | LinearGradientBrushProperties( |
||
326 | __in CONST D2D1_POINT_2F &startPoint, |
||
327 | __in CONST D2D1_POINT_2F &endPoint |
||
328 | ) |
||
329 | { |
||
330 | D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES linearGradientBrushProperties; |
||
331 | |||
332 | linearGradientBrushProperties.startPoint = startPoint; |
||
333 | linearGradientBrushProperties.endPoint = endPoint; |
||
334 | |||
335 | return linearGradientBrushProperties; |
||
336 | } |
||
337 | |||
338 | D2D1FORCEINLINE |
||
339 | D2D1_RADIAL_GRADIENT_BRUSH_PROPERTIES |
||
340 | RadialGradientBrushProperties( |
||
341 | __in CONST D2D1_POINT_2F ¢er, |
||
342 | __in CONST D2D1_POINT_2F &gradientOriginOffset, |
||
343 | FLOAT radiusX, |
||
344 | FLOAT radiusY |
||
345 | ) |
||
346 | { |
||
347 | D2D1_RADIAL_GRADIENT_BRUSH_PROPERTIES radialGradientBrushProperties; |
||
348 | |||
349 | radialGradientBrushProperties.center = center; |
||
350 | radialGradientBrushProperties.gradientOriginOffset = gradientOriginOffset; |
||
351 | radialGradientBrushProperties.radiusX = radiusX; |
||
352 | radialGradientBrushProperties.radiusY = radiusY; |
||
353 | |||
354 | return radialGradientBrushProperties; |
||
355 | } |
||
356 | |||
357 | // |
||
358 | // PixelFormat |
||
359 | // |
||
360 | D2D1FORCEINLINE |
||
361 | D2D1_PIXEL_FORMAT |
||
362 | PixelFormat( |
||
363 | __in DXGI_FORMAT dxgiFormat = DXGI_FORMAT_UNKNOWN, |
||
364 | __in D2D1_ALPHA_MODE alphaMode = D2D1_ALPHA_MODE_UNKNOWN |
||
365 | ) |
||
366 | { |
||
367 | D2D1_PIXEL_FORMAT pixelFormat; |
||
368 | |||
369 | pixelFormat.format = dxgiFormat; |
||
370 | pixelFormat.alphaMode = alphaMode; |
||
371 | |||
372 | return pixelFormat; |
||
373 | } |
||
374 | |||
375 | // |
||
376 | // Bitmaps |
||
377 | // |
||
378 | D2D1FORCEINLINE |
||
379 | D2D1_BITMAP_PROPERTIES |
||
380 | BitmapProperties( |
||
381 | CONST D2D1_PIXEL_FORMAT &pixelFormat = D2D1::PixelFormat(), |
||
382 | FLOAT dpiX = 96.0f, |
||
383 | FLOAT dpiY = 96.0f |
||
384 | ) |
||
385 | { |
||
386 | D2D1_BITMAP_PROPERTIES bitmapProperties; |
||
387 | |||
388 | bitmapProperties.pixelFormat = pixelFormat; |
||
389 | bitmapProperties.dpiX = dpiX; |
||
390 | bitmapProperties.dpiY = dpiY; |
||
391 | |||
392 | return bitmapProperties; |
||
393 | } |
||
394 | |||
395 | // |
||
396 | // Render Targets |
||
397 | // |
||
398 | D2D1FORCEINLINE |
||
399 | D2D1_RENDER_TARGET_PROPERTIES |
||
400 | RenderTargetProperties( |
||
401 | D2D1_RENDER_TARGET_TYPE type = D2D1_RENDER_TARGET_TYPE_DEFAULT, |
||
402 | __in CONST D2D1_PIXEL_FORMAT &pixelFormat = D2D1::PixelFormat(), |
||
403 | FLOAT dpiX = 0.0, |
||
404 | FLOAT dpiY = 0.0, |
||
405 | D2D1_RENDER_TARGET_USAGE usage = D2D1_RENDER_TARGET_USAGE_NONE, |
||
406 | D2D1_FEATURE_LEVEL minLevel = D2D1_FEATURE_LEVEL_DEFAULT |
||
407 | ) |
||
408 | { |
||
409 | D2D1_RENDER_TARGET_PROPERTIES renderTargetProperties; |
||
410 | |||
411 | renderTargetProperties.type = type; |
||
412 | renderTargetProperties.pixelFormat = pixelFormat; |
||
413 | renderTargetProperties.dpiX = dpiX; |
||
414 | renderTargetProperties.dpiY = dpiY; |
||
415 | renderTargetProperties.usage = usage; |
||
416 | renderTargetProperties.minLevel = minLevel; |
||
417 | |||
418 | return renderTargetProperties; |
||
419 | } |
||
420 | |||
421 | D2D1FORCEINLINE |
||
422 | D2D1_HWND_RENDER_TARGET_PROPERTIES |
||
423 | HwndRenderTargetProperties( |
||
424 | __in HWND hwnd, |
||
425 | __in D2D1_SIZE_U pixelSize = D2D1::Size(static_cast<UINT>(0), static_cast<UINT>(0)), |
||
426 | __in D2D1_PRESENT_OPTIONS presentOptions = D2D1_PRESENT_OPTIONS_NONE |
||
427 | ) |
||
428 | { |
||
429 | D2D1_HWND_RENDER_TARGET_PROPERTIES hwndRenderTargetProperties; |
||
430 | |||
431 | hwndRenderTargetProperties.hwnd = hwnd; |
||
432 | hwndRenderTargetProperties.pixelSize = pixelSize; |
||
433 | hwndRenderTargetProperties.presentOptions = presentOptions; |
||
434 | |||
435 | return hwndRenderTargetProperties; |
||
436 | } |
||
437 | |||
438 | D2D1FORCEINLINE |
||
439 | D2D1_LAYER_PARAMETERS |
||
440 | LayerParameters( |
||
441 | __in CONST D2D1_RECT_F &contentBounds = D2D1::InfiniteRect(), |
||
442 | __in_opt ID2D1Geometry *geometricMask = NULL, |
||
443 | D2D1_ANTIALIAS_MODE maskAntialiasMode = D2D1_ANTIALIAS_MODE_PER_PRIMITIVE, |
||
444 | D2D1_MATRIX_3X2_F maskTransform = D2D1::IdentityMatrix(), |
||
445 | FLOAT opacity = 1.0, |
||
446 | __in_opt ID2D1Brush *opacityBrush = NULL, |
||
447 | D2D1_LAYER_OPTIONS layerOptions = D2D1_LAYER_OPTIONS_NONE |
||
448 | ) |
||
449 | { |
||
450 | D2D1_LAYER_PARAMETERS layerParameters = { 0 }; |
||
451 | |||
452 | layerParameters.contentBounds = contentBounds; |
||
453 | layerParameters.geometricMask = geometricMask; |
||
454 | layerParameters.maskAntialiasMode = maskAntialiasMode; |
||
455 | layerParameters.maskTransform = maskTransform; |
||
456 | layerParameters.opacity = opacity; |
||
457 | layerParameters.opacityBrush = opacityBrush; |
||
458 | layerParameters.layerOptions = layerOptions; |
||
459 | |||
460 | return layerParameters; |
||
461 | } |
||
462 | |||
463 | D2D1FORCEINLINE |
||
464 | D2D1_DRAWING_STATE_DESCRIPTION |
||
465 | DrawingStateDescription( |
||
466 | D2D1_ANTIALIAS_MODE antialiasMode = D2D1_ANTIALIAS_MODE_PER_PRIMITIVE, |
||
467 | D2D1_TEXT_ANTIALIAS_MODE textAntialiasMode = D2D1_TEXT_ANTIALIAS_MODE_DEFAULT, |
||
468 | D2D1_TAG tag1 = 0, |
||
469 | D2D1_TAG tag2 = 0, |
||
470 | __in const D2D1_MATRIX_3X2_F &transform = D2D1::IdentityMatrix() |
||
471 | ) |
||
472 | { |
||
473 | D2D1_DRAWING_STATE_DESCRIPTION drawingStateDescription; |
||
474 | |||
475 | drawingStateDescription.antialiasMode = antialiasMode; |
||
476 | drawingStateDescription.textAntialiasMode = textAntialiasMode; |
||
477 | drawingStateDescription.tag1 = tag1; |
||
478 | drawingStateDescription.tag2 = tag2; |
||
479 | drawingStateDescription.transform = transform; |
||
480 | |||
481 | return drawingStateDescription; |
||
482 | } |
||
483 | |||
484 | // |
||
485 | // Colors, this enum defines a set of predefined colors. |
||
486 | // |
||
487 | class ColorF : public D2D1_COLOR_F |
||
488 | { |
||
489 | public: |
||
490 | |||
491 | enum Enum |
||
492 | { |
||
493 | AliceBlue = 0xF0F8FF, |
||
494 | AntiqueWhite = 0xFAEBD7, |
||
495 | Aqua = 0x00FFFF, |
||
496 | Aquamarine = 0x7FFFD4, |
||
497 | Azure = 0xF0FFFF, |
||
498 | Beige = 0xF5F5DC, |
||
499 | Bisque = 0xFFE4C4, |
||
500 | Black = 0x000000, |
||
501 | BlanchedAlmond = 0xFFEBCD, |
||
502 | Blue = 0x0000FF, |
||
503 | BlueViolet = 0x8A2BE2, |
||
504 | Brown = 0xA52A2A, |
||
505 | BurlyWood = 0xDEB887, |
||
506 | CadetBlue = 0x5F9EA0, |
||
507 | Chartreuse = 0x7FFF00, |
||
508 | Chocolate = 0xD2691E, |
||
509 | Coral = 0xFF7F50, |
||
510 | CornflowerBlue = 0x6495ED, |
||
511 | Cornsilk = 0xFFF8DC, |
||
512 | Crimson = 0xDC143C, |
||
513 | Cyan = 0x00FFFF, |
||
514 | DarkBlue = 0x00008B, |
||
515 | DarkCyan = 0x008B8B, |
||
516 | DarkGoldenrod = 0xB8860B, |
||
517 | DarkGray = 0xA9A9A9, |
||
518 | DarkGreen = 0x006400, |
||
519 | DarkKhaki = 0xBDB76B, |
||
520 | DarkMagenta = 0x8B008B, |
||
521 | DarkOliveGreen = 0x556B2F, |
||
522 | DarkOrange = 0xFF8C00, |
||
523 | DarkOrchid = 0x9932CC, |
||
524 | DarkRed = 0x8B0000, |
||
525 | DarkSalmon = 0xE9967A, |
||
526 | DarkSeaGreen = 0x8FBC8F, |
||
527 | DarkSlateBlue = 0x483D8B, |
||
528 | DarkSlateGray = 0x2F4F4F, |
||
529 | DarkTurquoise = 0x00CED1, |
||
530 | DarkViolet = 0x9400D3, |
||
531 | DeepPink = 0xFF1493, |
||
532 | DeepSkyBlue = 0x00BFFF, |
||
533 | DimGray = 0x696969, |
||
534 | DodgerBlue = 0x1E90FF, |
||
535 | Firebrick = 0xB22222, |
||
536 | FloralWhite = 0xFFFAF0, |
||
537 | ForestGreen = 0x228B22, |
||
538 | Fuchsia = 0xFF00FF, |
||
539 | Gainsboro = 0xDCDCDC, |
||
540 | GhostWhite = 0xF8F8FF, |
||
541 | Gold = 0xFFD700, |
||
542 | Goldenrod = 0xDAA520, |
||
543 | Gray = 0x808080, |
||
544 | Green = 0x008000, |
||
545 | GreenYellow = 0xADFF2F, |
||
546 | Honeydew = 0xF0FFF0, |
||
547 | HotPink = 0xFF69B4, |
||
548 | IndianRed = 0xCD5C5C, |
||
549 | Indigo = 0x4B0082, |
||
550 | Ivory = 0xFFFFF0, |
||
551 | Khaki = 0xF0E68C, |
||
552 | Lavender = 0xE6E6FA, |
||
553 | LavenderBlush = 0xFFF0F5, |
||
554 | LawnGreen = 0x7CFC00, |
||
555 | LemonChiffon = 0xFFFACD, |
||
556 | LightBlue = 0xADD8E6, |
||
557 | LightCoral = 0xF08080, |
||
558 | LightCyan = 0xE0FFFF, |
||
559 | LightGoldenrodYellow = 0xFAFAD2, |
||
560 | LightGreen = 0x90EE90, |
||
561 | LightGray = 0xD3D3D3, |
||
562 | LightPink = 0xFFB6C1, |
||
563 | LightSalmon = 0xFFA07A, |
||
564 | LightSeaGreen = 0x20B2AA, |
||
565 | LightSkyBlue = 0x87CEFA, |
||
566 | LightSlateGray = 0x778899, |
||
567 | LightSteelBlue = 0xB0C4DE, |
||
568 | LightYellow = 0xFFFFE0, |
||
569 | Lime = 0x00FF00, |
||
570 | LimeGreen = 0x32CD32, |
||
571 | Linen = 0xFAF0E6, |
||
572 | Magenta = 0xFF00FF, |
||
573 | Maroon = 0x800000, |
||
574 | MediumAquamarine = 0x66CDAA, |
||
575 | MediumBlue = 0x0000CD, |
||
576 | MediumOrchid = 0xBA55D3, |
||
577 | MediumPurple = 0x9370DB, |
||
578 | MediumSeaGreen = 0x3CB371, |
||
579 | MediumSlateBlue = 0x7B68EE, |
||
580 | MediumSpringGreen = 0x00FA9A, |
||
581 | MediumTurquoise = 0x48D1CC, |
||
582 | MediumVioletRed = 0xC71585, |
||
583 | MidnightBlue = 0x191970, |
||
584 | MintCream = 0xF5FFFA, |
||
585 | MistyRose = 0xFFE4E1, |
||
586 | Moccasin = 0xFFE4B5, |
||
587 | NavajoWhite = 0xFFDEAD, |
||
588 | Navy = 0x000080, |
||
589 | OldLace = 0xFDF5E6, |
||
590 | Olive = 0x808000, |
||
591 | OliveDrab = 0x6B8E23, |
||
592 | Orange = 0xFFA500, |
||
593 | OrangeRed = 0xFF4500, |
||
594 | Orchid = 0xDA70D6, |
||
595 | PaleGoldenrod = 0xEEE8AA, |
||
596 | PaleGreen = 0x98FB98, |
||
597 | PaleTurquoise = 0xAFEEEE, |
||
598 | PaleVioletRed = 0xDB7093, |
||
599 | PapayaWhip = 0xFFEFD5, |
||
600 | PeachPuff = 0xFFDAB9, |
||
601 | Peru = 0xCD853F, |
||
602 | Pink = 0xFFC0CB, |
||
603 | Plum = 0xDDA0DD, |
||
604 | PowderBlue = 0xB0E0E6, |
||
605 | Purple = 0x800080, |
||
606 | Red = 0xFF0000, |
||
607 | RosyBrown = 0xBC8F8F, |
||
608 | RoyalBlue = 0x4169E1, |
||
609 | SaddleBrown = 0x8B4513, |
||
610 | Salmon = 0xFA8072, |
||
611 | SandyBrown = 0xF4A460, |
||
612 | SeaGreen = 0x2E8B57, |
||
613 | SeaShell = 0xFFF5EE, |
||
614 | Sienna = 0xA0522D, |
||
615 | Silver = 0xC0C0C0, |
||
616 | SkyBlue = 0x87CEEB, |
||
617 | SlateBlue = 0x6A5ACD, |
||
618 | SlateGray = 0x708090, |
||
619 | Snow = 0xFFFAFA, |
||
620 | SpringGreen = 0x00FF7F, |
||
621 | SteelBlue = 0x4682B4, |
||
622 | Tan = 0xD2B48C, |
||
623 | Teal = 0x008080, |
||
624 | Thistle = 0xD8BFD8, |
||
625 | Tomato = 0xFF6347, |
||
626 | Turquoise = 0x40E0D0, |
||
627 | Violet = 0xEE82EE, |
||
628 | Wheat = 0xF5DEB3, |
||
629 | White = 0xFFFFFF, |
||
630 | WhiteSmoke = 0xF5F5F5, |
||
631 | Yellow = 0xFFFF00, |
||
632 | YellowGreen = 0x9ACD32, |
||
633 | }; |
||
634 | |||
635 | // |
||
636 | // Construct a color, note that the alpha value from the "rgb" component |
||
637 | // is never used. |
||
638 | // |
||
639 | D2D1FORCEINLINE |
||
640 | ColorF( |
||
641 | UINT32 rgb, |
||
642 | FLOAT a = 1.0 |
||
643 | ) |
||
644 | { |
||
645 | Init(rgb, a); |
||
646 | } |
||
647 | |||
648 | D2D1FORCEINLINE |
||
649 | ColorF( |
||
650 | Enum knownColor, |
||
651 | FLOAT a = 1.0 |
||
652 | ) |
||
653 | { |
||
654 | Init(knownColor, a); |
||
655 | } |
||
656 | |||
657 | D2D1FORCEINLINE |
||
658 | ColorF( |
||
659 | FLOAT r, |
||
660 | FLOAT g, |
||
661 | FLOAT b, |
||
662 | FLOAT a = 1.0 |
||
663 | ) |
||
664 | { |
||
665 | this->r = r; |
||
666 | this->g = g; |
||
667 | this->b = b; |
||
668 | this->a = a; |
||
669 | } |
||
670 | |||
671 | private: |
||
672 | |||
673 | D2D1FORCEINLINE |
||
674 | void |
||
675 | Init( |
||
676 | UINT32 rgb, |
||
677 | FLOAT a |
||
678 | ) |
||
679 | { |
||
680 | this->r = static_cast<FLOAT>((rgb & sc_redMask) >> sc_redShift) / 255.f; |
||
681 | this->g = static_cast<FLOAT>((rgb & sc_greenMask) >> sc_greenShift) / 255.f; |
||
682 | this->b = static_cast<FLOAT>((rgb & sc_blueMask) >> sc_blueShift) / 255.f; |
||
683 | this->a = a; |
||
684 | } |
||
685 | |||
686 | static const UINT32 sc_redShift = 16; |
||
687 | static const UINT32 sc_greenShift = 8; |
||
688 | static const UINT32 sc_blueShift = 0; |
||
689 | |||
690 | static const UINT32 sc_redMask = 0xff << sc_redShift; |
||
691 | static const UINT32 sc_greenMask = 0xff << sc_greenShift; |
||
692 | static const UINT32 sc_blueMask = 0xff << sc_blueShift; |
||
693 | }; |
||
694 | |||
695 | class Matrix3x2F : public D2D1_MATRIX_3X2_F |
||
696 | { |
||
697 | public: |
||
698 | |||
699 | D2D1FORCEINLINE |
||
700 | Matrix3x2F( |
||
701 | FLOAT _11, |
||
702 | FLOAT _12, |
||
703 | FLOAT _21, |
||
704 | FLOAT _22, |
||
705 | FLOAT _31, |
||
706 | FLOAT _32 |
||
707 | ) |
||
708 | { |
||
709 | this->_11 = _11; |
||
710 | this->_12 = _12; |
||
711 | this->_21 = _21; |
||
712 | this->_22 = _22; |
||
713 | this->_31 = _31; |
||
714 | this->_32 = _32; |
||
715 | } |
||
716 | |||
717 | // |
||
718 | // Creates an identity matrix |
||
719 | // |
||
720 | D2D1FORCEINLINE |
||
721 | Matrix3x2F( |
||
722 | ) |
||
723 | { |
||
724 | } |
||
725 | |||
726 | // |
||
727 | // Named quasi-constructors |
||
728 | // |
||
729 | static D2D1FORCEINLINE |
||
730 | Matrix3x2F |
||
731 | Identity() |
||
732 | { |
||
733 | Matrix3x2F identity; |
||
734 | |||
735 | identity._11 = 1.f; |
||
736 | identity._12 = 0.f; |
||
737 | identity._21 = 0.f; |
||
738 | identity._22 = 1.f; |
||
739 | identity._31 = 0.f; |
||
740 | identity._32 = 0.f; |
||
741 | |||
742 | return identity; |
||
743 | } |
||
744 | |||
745 | static D2D1FORCEINLINE |
||
746 | Matrix3x2F |
||
747 | Translation( |
||
748 | D2D1_SIZE_F size |
||
749 | ) |
||
750 | { |
||
751 | Matrix3x2F translation; |
||
752 | |||
753 | translation._11 = 1.0; translation._12 = 0.0; |
||
754 | translation._21 = 0.0; translation._22 = 1.0; |
||
755 | translation._31 = size.width; translation._32 = size.height; |
||
756 | |||
757 | return translation; |
||
758 | } |
||
759 | |||
760 | static D2D1FORCEINLINE |
||
761 | Matrix3x2F |
||
762 | Translation( |
||
763 | FLOAT x, |
||
764 | FLOAT y |
||
765 | ) |
||
766 | { |
||
767 | return Translation(SizeF(x, y)); |
||
768 | } |
||
769 | |||
770 | |||
771 | static D2D1FORCEINLINE |
||
772 | Matrix3x2F |
||
773 | Scale( |
||
774 | D2D1_SIZE_F size, |
||
775 | D2D1_POINT_2F center = D2D1::Point2F() |
||
776 | ) |
||
777 | { |
||
778 | Matrix3x2F scale; |
||
779 | |||
780 | scale._11 = size.width; scale._12 = 0.0; |
||
781 | scale._21 = 0.0; scale._22 = size.height; |
||
782 | scale._31 = center.x - size.width * center.x; |
||
783 | scale._32 = center.y - size.height * center.y; |
||
784 | |||
785 | return scale; |
||
786 | } |
||
787 | |||
788 | static D2D1FORCEINLINE |
||
789 | Matrix3x2F |
||
790 | Scale( |
||
791 | FLOAT x, |
||
792 | FLOAT y, |
||
793 | D2D1_POINT_2F center = D2D1::Point2F() |
||
794 | ) |
||
795 | { |
||
796 | return Scale(SizeF(x, y), center); |
||
797 | } |
||
798 | |||
799 | static D2D1FORCEINLINE |
||
800 | Matrix3x2F |
||
801 | Rotation( |
||
802 | FLOAT angle, |
||
803 | D2D1_POINT_2F center = D2D1::Point2F() |
||
804 | ) |
||
805 | { |
||
806 | Matrix3x2F rotation; |
||
807 | |||
808 | D2D1MakeRotateMatrix(angle, center, &rotation); |
||
809 | |||
810 | return rotation; |
||
811 | } |
||
812 | |||
813 | static D2D1FORCEINLINE |
||
814 | Matrix3x2F |
||
815 | Skew( |
||
816 | FLOAT angleX, |
||
817 | FLOAT angleY, |
||
818 | D2D1_POINT_2F center = D2D1::Point2F() |
||
819 | ) |
||
820 | { |
||
821 | Matrix3x2F skew; |
||
822 | |||
823 | D2D1MakeSkewMatrix(angleX, angleY, center, &skew); |
||
824 | |||
825 | return skew; |
||
826 | } |
||
827 | |||
828 | // |
||
829 | // Functions for convertion from the base D2D1_MATRIX_3X2_F to this type |
||
830 | // without making a copy |
||
831 | // |
||
832 | static inline const Matrix3x2F* ReinterpretBaseType(const D2D1_MATRIX_3X2_F *pMatrix) |
||
833 | { |
||
834 | return static_cast<const Matrix3x2F *>(pMatrix); |
||
835 | } |
||
836 | |||
837 | static inline Matrix3x2F* ReinterpretBaseType(D2D1_MATRIX_3X2_F *pMatrix) |
||
838 | { |
||
839 | return static_cast<Matrix3x2F *>(pMatrix); |
||
840 | } |
||
841 | |||
842 | inline |
||
843 | FLOAT |
||
844 | Determinant() const |
||
845 | { |
||
846 | return (_11 * _22) - (_12 * _21); |
||
847 | } |
||
848 | |||
849 | inline |
||
850 | bool |
||
851 | IsInvertible() const |
||
852 | { |
||
853 | return !!D2D1IsMatrixInvertible(this); |
||
854 | } |
||
855 | |||
856 | inline |
||
857 | bool |
||
858 | Invert() |
||
859 | { |
||
860 | return !!D2D1InvertMatrix(this); |
||
861 | } |
||
862 | |||
863 | inline |
||
864 | bool |
||
865 | IsIdentity() const |
||
866 | { |
||
867 | return _11 == 1.f && _12 == 0.f |
||
868 | && _21 == 0.f && _22 == 1.f |
||
869 | && _31 == 0.f && _32 == 0.f; |
||
870 | } |
||
871 | |||
872 | inline |
||
873 | void SetProduct( |
||
874 | const Matrix3x2F &a, |
||
875 | const Matrix3x2F &b |
||
876 | ) |
||
877 | { |
||
878 | _11 = a._11 * b._11 + a._12 * b._21; |
||
879 | _12 = a._11 * b._12 + a._12 * b._22; |
||
880 | _21 = a._21 * b._11 + a._22 * b._21; |
||
881 | _22 = a._21 * b._12 + a._22 * b._22; |
||
882 | _31 = a._31 * b._11 + a._32 * b._21 + b._31; |
||
883 | _32 = a._31 * b._12 + a._32 * b._22 + b._32; |
||
884 | } |
||
885 | |||
886 | D2D1FORCEINLINE |
||
887 | Matrix3x2F |
||
888 | operator*( |
||
889 | const Matrix3x2F &matrix |
||
890 | ) const |
||
891 | { |
||
892 | Matrix3x2F result; |
||
893 | |||
894 | result.SetProduct(*this, matrix); |
||
895 | |||
896 | return result; |
||
897 | } |
||
898 | |||
899 | D2D1FORCEINLINE |
||
900 | D2D1_POINT_2F |
||
901 | TransformPoint( |
||
902 | D2D1_POINT_2F point |
||
903 | ) const |
||
904 | { |
||
905 | D2D1_POINT_2F result = |
||
906 | { |
||
907 | point.x * _11 + point.y * _21 + _31, |
||
908 | point.x * _12 + point.y * _22 + _32 |
||
909 | }; |
||
910 | |||
911 | return result; |
||
912 | } |
||
913 | }; |
||
914 | |||
915 | D2D1FORCEINLINE |
||
916 | D2D1_POINT_2F |
||
917 | operator*( |
||
918 | const D2D1_POINT_2F &point, |
||
919 | const D2D1_MATRIX_3X2_F &matrix |
||
920 | ) |
||
921 | { |
||
922 | return Matrix3x2F::ReinterpretBaseType(&matrix)->TransformPoint(point); |
||
923 | } |
||
924 | |||
925 | D2D1_MATRIX_3X2_F |
||
926 | IdentityMatrix() |
||
927 | { |
||
928 | return Matrix3x2F::Identity(); |
||
929 | } |
||
930 | |||
931 | } // namespace D2D1 |
||
932 | |||
933 | D2D1FORCEINLINE |
||
934 | D2D1_MATRIX_3X2_F |
||
935 | operator*( |
||
936 | const D2D1_MATRIX_3X2_F &matrix1, |
||
937 | const D2D1_MATRIX_3X2_F &matrix2 |
||
938 | ) |
||
939 | { |
||
940 | return |
||
941 | (*D2D1::Matrix3x2F::ReinterpretBaseType(&matrix1)) * |
||
942 | (*D2D1::Matrix3x2F::ReinterpretBaseType(&matrix2)); |
||
943 | } |
||
944 | |||
945 | #endif // #ifndef D2D_USE_C_DEFINITIONS |
||
946 | |||
947 | #endif // #ifndef _D2D1_HELPER_H_ |
||
948 |