/*=========================================================================*\
Copyright (c) Microsoft Corporation. All rights reserved.
File: D2D1helper.h
Module Name: D2D
Description: Helper files over the D2D interfaces and APIs.
\*=========================================================================*/
#pragma once
#ifndef _D2D1_HELPER_H_
#define _D2D1_HELPER_H_
#ifndef _D2D1_H_
#include <d2d1.h>
#endif // #ifndef _D2D1_H_
#ifndef D2D_USE_C_DEFINITIONS
namespace
{
();
template
<
typename
>
struct
{
typedef
;
typedef
;
typedef
;
};
template
<>
struct
<
>
{
typedef
;
typedef
;
typedef
;
};
static
inline
()
{
#ifdef FLT_MAX
#else
return 3.402823466e+38F;
#endif
}
template
<
typename
>
typename
<
>::
(
,
)
{
typename
<
>::
= {
,
};
return
point
;
}
(
=
0.f
,
=
0.f
)
{
return
<
>(
,
);
}
(
=
0
,
=
0
)
{
return
<
>(
,
);
}
template
<
typename
>
typename
<
>::
(
,
)
{
typename
<
>::
= {
,
};
return
size
;
}
(
=
0.f
,
=
0.f
)
{
return
<
>(
,
);
}
(
=
0
,
=
0
)
{
return
<
>(
,
);
}
template
<
typename
>
typename
<
>::
(
,
,
,
)
{
typename
<
>::
= {
,
,
,
};
return
rect
;
}
(
=
0.f
,
=
0.f
,
=
0.f
,
=
0.f
)
{
return
<
>(
,
,
,
);
}
(
=
0
,
=
0
,
=
0
,
=
0
)
{
return
<
>(
,
,
,
);
}
()
{
= { -
(), -
(),
(),
() };
return
rect
;
}
(
_In_ CONST D2D1_POINT_2F &point,
_In_ CONST D2D1_SIZE_F &size,
_In_ FLOAT rotationAngle,
_In_ D2D1_SWEEP_DIRECTION sweepDirection,
_In_ D2D1_ARC_SIZE arcSize
)
{
= {
,
,
,
,
};
return
arcSegment
;
}
(
_In_ CONST D2D1_POINT_2F &point1,
_In_ CONST D2D1_POINT_2F &point2,
_In_ CONST D2D1_POINT_2F &point3
)
{
= {
,
,
};
return
bezierSegment
;
}
(
_In_ CONST D2D1_POINT_2F ¢er,
,
)
{
;
ellipse
.
;
ellipse
.
=
;
ellipse
.
=
;
return
ellipse
;
}
(
_In_ CONST D2D1_RECT_F &rect,
,
)
{
;
roundedRect
.
;
roundedRect
.
=
;
roundedRect
.
=
;
return
roundedRect
;
}
(
_In_ FLOAT opacity = 1.0,
_In_ CONST D2D1_MATRIX_3X2_F &transform = D2D1::IdentityMatrix()
)
{
;
brushProperties
.
=
;
brushProperties
.
;
return
brushProperties
;
}
(
,
_In_ CONST D2D1_COLOR_F &color
)
{
= {
,
};
return
gradientStop
;
}
D2D1_QUADRATIC_BEZIER_SEGMENT
(
_In_ CONST D2D1_POINT_2F &point1,
_In_ CONST D2D1_POINT_2F &point2
)
{
D2D1_QUADRATIC_BEZIER_SEGMENT
= {
,
};
return
quadraticBezier
;
}
D2D1_STROKE_STYLE_PROPERTIES
(
=
,
=
,
=
,
=
,
=
10.0f
,
=
,
=
0.0f
)
{
D2D1_STROKE_STYLE_PROPERTIES
;
strokeStyleProperties
.
=
;
strokeStyleProperties
.
=
;
strokeStyleProperties
.
=
;
strokeStyleProperties
.
=
;
strokeStyleProperties
.
=
;
strokeStyleProperties
.
=
;
strokeStyleProperties
.
=
;
return
strokeStyleProperties
;
}
D2D1_BITMAP_BRUSH_PROPERTIES
(
=
,
=
,
D2D1_BITMAP_INTERPOLATION_MODE
=
D2D1_BITMAP_INTERPOLATION_MODE_LINEAR
)
{
D2D1_BITMAP_BRUSH_PROPERTIES
;
bitmapBrushProperties
.
=
;
bitmapBrushProperties
.
=
;
bitmapBrushProperties
.
=
;
return
bitmapBrushProperties
;
}
D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES
LinearGradientBrushProperties
(
_In_ CONST D2D1_POINT_2F &startPoint,
_In_ CONST D2D1_POINT_2F &endPoint
)
{
D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES
linearGradientBrushProperties
;
linearGradientBrushProperties
.
;
linearGradientBrushProperties
.
;
return
linearGradientBrushProperties
;
}
D2D1_RADIAL_GRADIENT_BRUSH_PROPERTIES
RadialGradientBrushProperties
(
_In_ CONST D2D1_POINT_2F ¢er,
_In_ CONST D2D1_POINT_2F &gradientOriginOffset,
,
)
{
D2D1_RADIAL_GRADIENT_BRUSH_PROPERTIES
radialGradientBrushProperties
;
radialGradientBrushProperties
.
;
radialGradientBrushProperties
.
;
radialGradientBrushProperties
.
=
;
radialGradientBrushProperties
.
=
;
return
radialGradientBrushProperties
;
}
(
_In_ DXGI_FORMAT dxgiFormat = DXGI_FORMAT_UNKNOWN,
_In_ D2D1_ALPHA_MODE alphaMode = D2D1_ALPHA_MODE_UNKNOWN
)
{
;
pixelFormat
.
=
;
pixelFormat
.
=
;
return
pixelFormat
;
}
(
CONST D2D1_PIXEL_FORMAT &pixelFormat = D2D1::PixelFormat(),
=
96.0f
,
=
96.0f
)
{
;
bitmapProperties
.
;
bitmapProperties
.
=
;
bitmapProperties
.
=
;
return
bitmapProperties
;
}
D2D1_RENDER_TARGET_PROPERTIES
(
=
D2D1_RENDER_TARGET_TYPE_DEFAULT
,
_In_ CONST D2D1_PIXEL_FORMAT &pixelFormat = D2D1::PixelFormat(),
=
0.0
,
=
0.0
,
=
D2D1_RENDER_TARGET_USAGE_NONE
,
=
D2D1_FEATURE_LEVEL_DEFAULT
)
{
D2D1_RENDER_TARGET_PROPERTIES
;
renderTargetProperties
.
=
;
renderTargetProperties
.
;
renderTargetProperties
.
=
;
renderTargetProperties
.
=
;
renderTargetProperties
.
=
;
renderTargetProperties
.
=
;
return
renderTargetProperties
;
}
D2D1_HWND_RENDER_TARGET_PROPERTIES
HwndRenderTargetProperties
(
_In_ D2D1_SIZE_U pixelSize = D2D1::Size(static_cast<UINT32>(0), static_cast<UINT32>(0)),
=
D2D1
::
(
static_cast
<
>(
0
),
static_cast
<
>(
0
)),
_In_ D2D1_PRESENT_OPTIONS presentOptions = D2D1_PRESENT_OPTIONS_NONE
=
D2D1_PRESENT_OPTIONS_NONE
)
{
D2D1_HWND_RENDER_TARGET_PROPERTIES
hwndRenderTargetProperties
;
hwndRenderTargetProperties
.
=
;
hwndRenderTargetProperties
.
;
hwndRenderTargetProperties
.
=
;
return
hwndRenderTargetProperties
;
}
(
_In_ CONST D2D1_RECT_F &contentBounds = D2D1::InfiniteRect(),
_In_opt_ ID2D1Geometry *geometricMask = NULL,
=
D2D1_ANTIALIAS_MODE_PER_PRIMITIVE
,
=
D2D1
::
(),
=
1.0
,
_In_opt_ ID2D1Brush *opacityBrush = NULL,
=
)
{
= {
0
};
layerParameters
.
;
layerParameters
.
=
;
layerParameters
.
=
;
layerParameters
.
;
layerParameters
.
=
;
layerParameters
.
=
;
layerParameters
.
=
;
return
layerParameters
;
}
D2D1_DRAWING_STATE_DESCRIPTION
(
=
D2D1_ANTIALIAS_MODE_PER_PRIMITIVE
,
=
D2D1_TEXT_ANTIALIAS_MODE_DEFAULT
,
=
0
,
=
0
,
_In_ const D2D1_MATRIX_3X2_F &transform = D2D1::IdentityMatrix()
)
{
D2D1_DRAWING_STATE_DESCRIPTION
;
drawingStateDescription
.
=
;
drawingStateDescription
.
=
;
drawingStateDescription
.
=
;
drawingStateDescription
.
=
;
drawingStateDescription
.
;
return
drawingStateDescription
;
}
class
:
public
{
public
:
enum
{
=
0xF0F8FF
,
=
0xFAEBD7
,
=
0x00FFFF
,
=
0x7FFFD4
,
=
0xF0FFFF
,
=
0xF5F5DC
,
=
0xFFE4C4
,
=
0x000000
,
=
0xFFEBCD
,
=
0x0000FF
,
=
0x8A2BE2
,
=
0xA52A2A
,
=
0xDEB887
,
=
0x5F9EA0
,
=
0x7FFF00
,
=
0xD2691E
,
=
0xFF7F50
,
=
0x6495ED
,
=
0xFFF8DC
,
=
0xDC143C
,
=
0x00FFFF
,
=
0x00008B
,
=
0x008B8B
,
=
0xB8860B
,
=
0xA9A9A9
,
=
0x006400
,
=
0xBDB76B
,
=
0x8B008B
,
=
0x556B2F
,
=
0xFF8C00
,
=
0x9932CC
,
=
0x8B0000
,
=
0xE9967A
,
=
0x8FBC8F
,
=
0x483D8B
,
=
0x2F4F4F
,
=
0x00CED1
,
=
0x9400D3
,
=
0xFF1493
,
=
0x00BFFF
,
=
0x696969
,
=
0x1E90FF
,
=
0xB22222
,
=
0xFFFAF0
,
=
0x228B22
,
=
0xFF00FF
,
=
0xDCDCDC
,
=
0xF8F8FF
,
=
0xFFD700
,
=
0xDAA520
,
=
0x808080
,
=
0x008000
,
=
0xADFF2F
,
=
0xF0FFF0
,
=
0xFF69B4
,
=
0xCD5C5C
,
=
0x4B0082
,
=
0xFFFFF0
,
=
0xF0E68C
,
=
0xE6E6FA
,
=
0xFFF0F5
,
=
0x7CFC00
,
=
0xFFFACD
,
=
0xADD8E6
,
=
0xF08080
,
=
0xE0FFFF
,
=
0xFAFAD2
,
=
0x90EE90
,
=
0xD3D3D3
,
=
0xFFB6C1
,
=
0xFFA07A
,
=
0x20B2AA
,
=
0x87CEFA
,
=
0x778899
,
=
0xB0C4DE
,
=
0xFFFFE0
,
=
0x00FF00
,
=
0x32CD32
,
=
0xFAF0E6
,
=
0xFF00FF
,
=
0x800000
,
=
0x66CDAA
,
=
0x0000CD
,
=
0xBA55D3
,
=
0x9370DB
,
=
0x3CB371
,
=
0x7B68EE
,
=
0x00FA9A
,
=
0x48D1CC
,
=
0xC71585
,
=
0x191970
,
=
0xF5FFFA
,
=
0xFFE4E1
,
=
0xFFE4B5
,
=
0xFFDEAD
,
=
0x000080
,
=
0xFDF5E6
,
=
0x808000
,
=
0x6B8E23
,
=
0xFFA500
,
=
0xFF4500
,
=
0xDA70D6
,
=
0xEEE8AA
,
=
0x98FB98
,
=
0xAFEEEE
,
=
0xDB7093
,
=
0xFFEFD5
,
=
0xFFDAB9
,
=
0xCD853F
,
=
0xFFC0CB
,
=
0xDDA0DD
,
=
0xB0E0E6
,
=
0x800080
,
=
0xFF0000
,
=
0xBC8F8F
,
=
0x4169E1
,
=
0x8B4513
,
=
0xFA8072
,
=
0xF4A460
,
=
0x2E8B57
,
=
0xFFF5EE
,
=
0xA0522D
,
=
0xC0C0C0
,
=
0x87CEEB
,
=
0x6A5ACD
,
=
0x708090
,
=
0xFFFAFA
,
=
0x00FF7F
,
=
0x4682B4
,
=
0xD2B48C
,
=
0x008080
,
=
0xD8BFD8
,
=
0xFF6347
,
=
0x40E0D0
,
=
0xEE82EE
,
=
0xF5DEB3
,
=
0xFFFFFF
,
=
0xF5F5F5
,
=
0xFFFF00
,
=
0x9ACD32
,
};
(
,
=
1.0
)
{
(
,
);
}
(
,
=
1.0
)
{
(
,
);
}
(
,
,
,
=
1.0
)
{
=
;
=
;
=
;
=
;
}
private
:
void
(
,
)
{
=
static_cast
<
>((
&
) >>
) /
255.f
;
=
static_cast
<
>((
&
) >>
) /
255.f
;
=
static_cast
<
>((
&
) >>
) /
255.f
;
=
;
}
static
const
=
16
;
static
const
=
8
;
static
const
=
0
;
static
const
=
0xff
<<
;
static
const
=
0xff
<<
;
static
const
=
0xff
<<
;
};
class
:
public
{
public
:
(
,
,
,
,
,
)
{
=
;
=
;
=
;
=
;
=
;
=
;
}
(
)
{
}
static
()
{
;
identity
.
=
1.f
;
identity
.
=
0.f
;
identity
.
=
0.f
;
identity
.
=
1.f
;
identity
.
=
0.f
;
identity
.
=
0.f
;
return
identity
;
}
static
(
)
{
;
translation
.
=
1.0
;
translation
.
=
0.0
;
translation
.
=
0.0
;
translation
.
=
1.0
;
translation
.
=
.
;
translation
.
=
.
;
return
translation
;
}
static
(
,
)
{
return
(
(
,
));
}
static
(
,
=
D2D1
::
()
)
{
;
scale
.
=
.
;
scale
.
=
0.0
;
scale
.
=
0.0
;
scale
.
=
.
;
scale
.
=
.
-
.
*
.
;
scale
.
=
.
-
.
*
.
;
return
scale
;
}
static
(
,
,
=
D2D1
::
()
)
{
return
(
(
,
),
);
}
static
(
,
=
D2D1
::
()
)
{
;
(
,
, &
rotation
);
return
rotation
;
}
static
(
,
,
=
D2D1
::
()
)
{
;
(
,
,
, &
skew
);
return
skew
;
}
static
inline
const
*
(
const
*
)
{
return
static_cast
<
const
*>(
);
}
static
inline
*
(
*
)
{
return
static_cast
<
*>(
);
}
inline
()
const
{
return
(
*
) - (
*
);
}
inline
bool
()
const
{
return
!!
(
this
);
}
inline
bool
()
{
return
!!
(
this
);
}
inline
bool
()
const
{
return
==
1.f
&&
==
0.f
&&
==
0.f
&&
==
1.f
&&
==
0.f
&&
==
0.f
;
}
inline
void
(
const
&
,
const
&
)
{
=
.
*
.
+
.
*
.
;
=
.
*
.
+
.
*
.
;
=
.
*
.
+
.
*
.
;
=
.
*
.
+
.
*
.
;
=
.
*
.
+
.
*
.
+
.
;
=
.
*
.
+
.
*
.
+
.
;
}
(
const
&
)
const
{
;
result
.
(*
this
,
);
return
result
;
}
(
)
const
{
=
{
.
*
+
.
*
+
,
.
*
+
.
*
+
};
return
result
;
}
};
(
const
&
,
const
&
)
{
return
::
(&
)->
(
);
}
()
{
return
::
();
}
}
(
const
&
,
const
&
)
{
return
(*
D2D1
::
::
(&
))
(*
D2D1
::
::
(&
));
}
inline
bool
(
const
&
,
const
&
)
{
return
(
.
==
.
) && (
.
==
.
);
}
inline
bool
(
const
&
,
const
&
)
{
return
(
.
==
.
) && (
.
==
.
) &&
(
.
==
.
) && (
.
==
.
);
}
#endif // #ifndef D2D_USE_C_DEFINITIONS
#endif // #ifndef _D2D1_HELPER_H_