ID2D1RenderTarget::FillRectangle メソッド

指定された四角形の内部を描画します。

構文

void FillRectangle(
  [ref]  const D2D1_RECT_F &rect,
  [in]   ID2D1Brush *brush
);

パラメーター

  • rect
    D2D1_RECT_F 描画する四角形の寸法 (デバイス非依存のピクセル単位)。
  • brush [in]
    ID2D1Brush 四角形の内部の描画に使用するブラシ。

戻り値

This は値を返しません。

解説

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

次の例では、ID2D1HwndRenderTarget を使用して、複数の四角形を描画して塗りつぶします。完全な例については、「四角形を描画する例」を参照してください。この例では、次の出力が生成されます。

 

グリッドの背景上の 2 つの四角形

 

  // This method discards device-specific
// resources if the Direct3D device dissapears 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 7, Windows Vista SP2 および Windows Vista 用のプラットフォーム更新プログラム

サーバーの最小要件

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

ヘッダー

D2d1.h

ライブラリ

D2d1.lib

DLL

D2d1.dll

参照

ID2D1RenderTarget

単純な Direct2D アプリケーションの作成

四角形を描画する例