ID2D1RenderTarget::D rawRectangle(constD2D1_RECT_F*,ID2D1Brush*,FLOAT,ID2D1StrokeStyle*) メソッド (d2d1.h)

指定した寸法とストローク スタイルを持つ四角形のアウトラインを描画します。

構文

void DrawRectangle(
  const D2D1_RECT_F *rect,
  ID2D1Brush        *brush,
  FLOAT             strokeWidth,
  ID2D1StrokeStyle  *strokeStyle
);

パラメーター

rect

型: [in] const D2D1_RECT_F*

描画する四角形の寸法 (デバイスに依存しないピクセル単位)。

brush

種類: [in] ID2D1Brush*

四角形のストロークを描画するために使用されるブラシ。

strokeWidth

型: [in] FLOAT

ストロークの幅 (デバイスに依存しないピクセル単位)。 値は 0.0f 以上である必要があります。 このパラメーターが指定されていない場合、既定値は 1.0f になります。 ストロークは線の中央に配置されます。

strokeStyle

型: [in, optional] ID2D1StrokeStyle*

塗りつぶすストロークのスタイル。塗りつぶす場合は NULL

戻り値

なし

解説

このメソッドが失敗しても、エラー コードは返されません。 描画メソッド (DrawRectangle など) が失敗したかどうかを判断するには、ID2D1RenderTarget::EndDraw メソッドまたは ID2D1RenderTarget::Flush メソッドによって返される結果チェックします。

次の例では、 ID2D1HwndRenderTarget を 使用して、複数の四角形を描画して塗りつぶします。 次の使用例は、次の図に示す出力を生成します。

グリッド背景上の 2 つの四角形の図
// This method discards device-specific
// resources if the Direct3D device disappears during execution and
// recreates the resources the next time it's invoked.
HRESULT DemoApp::OnRender()
{
    HRESULT hr = S_OK;

    hr = CreateDeviceResources();

    if (SUCCEEDED(hr))
    {
        m_pRenderTarget->BeginDraw();

        m_pRenderTarget->SetTransform(D2D1::Matrix3x2F::Identity());

        m_pRenderTarget->Clear(D2D1::ColorF(D2D1::ColorF::White));

        D2D1_SIZE_F rtSize = m_pRenderTarget->GetSize();

        // Draw a grid background.
        int width = static_cast<int>(rtSize.width);
        int height = static_cast<int>(rtSize.height);

        for (int x = 0; x < width; x += 10)
        {
            m_pRenderTarget->DrawLine(
                D2D1::Point2F(static_cast<FLOAT>(x), 0.0f),
                D2D1::Point2F(static_cast<FLOAT>(x), rtSize.height),
                m_pLightSlateGrayBrush,
                0.5f
                );
        }

        for (int y = 0; y < height; y += 10)
        {
            m_pRenderTarget->DrawLine(
                D2D1::Point2F(0.0f, static_cast<FLOAT>(y)),
                D2D1::Point2F(rtSize.width, static_cast<FLOAT>(y)),
                m_pLightSlateGrayBrush,
                0.5f
                );
        }

        // Draw two rectangles.
        D2D1_RECT_F rectangle1 = D2D1::RectF(
            rtSize.width/2 - 50.0f,
            rtSize.height/2 - 50.0f,
            rtSize.width/2 + 50.0f,
            rtSize.height/2 + 50.0f
            );

        D2D1_RECT_F rectangle2 = D2D1::RectF(
            rtSize.width/2 - 100.0f,
            rtSize.height/2 - 100.0f,
            rtSize.width/2 + 100.0f,
            rtSize.height/2 + 100.0f
            );


        // Draw a filled rectangle.
        m_pRenderTarget->FillRectangle(&rectangle1, m_pLightSlateGrayBrush);

        // Draw the outline of a rectangle.
        m_pRenderTarget->DrawRectangle(&rectangle2, m_pCornflowerBlueBrush);

        hr = m_pRenderTarget->EndDraw();
    }

    if (hr == D2DERR_RECREATE_TARGET)
    {
        hr = S_OK;
        DiscardDeviceResources();
    }

    return hr;
}

関連するチュートリアルについては、「 単純な Direct2D アプリケーションを作成する」を参照してください。

要件

要件
対象プラットフォーム Windows
ヘッダー d2d1.h (D2d1.h を含む)
Library D2d1.lib
[DLL] D2d1.dll

こちらもご覧ください

簡単な Direct2D アプリケーションを作成する

基本的な図形を描画して塗りつぶす方法

ID2D1RenderTarget