D2D1_GRADIENT_STOP 構造体

グラデーション境界の位置と色を格納します。

構文

struct D2D1_GRADIENT_STOP {
  FLOAT        position;
  D2D1_COLOR_F color;
};

メンバー

  • position
    FLOAT ブラシのグラデーション境界の相対位置を示す値。グラデーション境界が明示的に表示される場合、この値は [0.0f, 1.0f] の範囲に含まれる必要があります。
  • color
    D2D1_COLOR_F グラデーション境界の色。

解説

グラデーション境界は、位置が異なる場合、任意の順序で指定できます。2 つの境界で 1 つの位置を共有することもできます。この場合、最初に指定された境界が "下" (0.0f に近い) と見なされ、後続の境界が "上" (1.0f に近い) と見なされます。この動作は、呼び出し元が境界の中央で瞬時に切り替える場合に便利です。

通常、1 つのコレクションには少なくとも 2 つの点がありますが、作成できるのは境界が 1 つのみのコレクションです。たとえば、ある点の位置が 0.0f、もう 1 つの点の位置が 1.0f、その他の点が [0, 1] の範囲内に分散されているとします。グラデーションが [0, 1] の範囲を超えた場合、境界は保存されますが、グラデーションに影響する可能性があります。

描画時に、ブラシを使用した方法で、[0, 1] の範囲の位置がブラシにマップされます。詳細については、「ID2D1LinearGradientBrush」および「ID2D1RadialGradientBrush」を参照してください。

位置が [0, 1] の範囲外にあるグラデーション境界は明示的に表示されませんが、[0, 1] の範囲で生成される色に影響を与える場合があります。たとえば、2 つの境界のグラデーション {{0.0f, Black}, {2.0f, White}} は {{0.0f, Black}, {1.0f, Mid-level gray}} と視覚的に区別できません。また、色は補間の前にクランプされます。

次の例では、グラデーション境界の配列を作成してから、そのグラデーション境界を使用して ID2D1GradientStopCollection を作成します。

  // Create an array of gradient stops to put in the gradient stop
// collection that will be used in the gradient brush.
ID2D1GradientStopCollection *pGradientStops = NULL;

D2D1_GRADIENT_STOP gradientStops[2];
gradientStops[0].color = D2D1::ColorF(D2D1::ColorF::Yellow, 1);
gradientStops[0].position = 0.0f;
gradientStops[1].color = D2D1::ColorF(D2D1::ColorF::ForestGreen, 1);
gradientStops[1].position = 1.0f;
// Create the ID2D1GradientStopCollection from a previously
// declared array of D2D1_GRADIENT_STOP structs.
hr = m_pRenderTarget->CreateGradientStopCollection(
    gradientStops,
    2,
    D2D1_GAMMA_2_2,
    D2D1_EXTEND_MODE_CLAMP,
    &pGradientStops
    );

次のコード例では、ID2D1GradientStopCollection を使用して、ID2D1LinearGradientBrush を作成します。

  // The line that determines the direction of the gradient starts at
// the upper-left corner of the square and ends at the lower-right corner.

if (SUCCEEDED(hr))
{
    hr = m_pRenderTarget->CreateLinearGradientBrush(
        D2D1::LinearGradientBrushProperties(
            D2D1::Point2F(0, 0),
            D2D1::Point2F(150, 150)),
        pGradientStops,
        &m_pLinearGradientBrush
        );
}

完全なコードについては、「ブラシの種類の例」を参照してください。

要件

クライアントの最小要件

Windows 7, Windows Vista SP2 および Windows Vista 用のプラットフォーム更新プログラム

サーバーの最小要件

Windows Server 2008 R2, Windows Server 2008 SP2 および Windows Server 2008 用のプラットフォーム更新プログラム

ヘッダー

D2d1.h

参照

CreateGradientStopCollection

ID2D1GradientStopCollection

ID2D1LinearGradientBrush

ID2D1RadialGradientBrush

線状グラデーション ブラシを作成する方法

放射状グラデーション ブラシを作成する方法

ブラシの概要

ブラシの種類の例