direct2d resizing the geometry without scale, how to?

Code Wanderer 396 Reputation points
2020-08-17T16:03:31.787+00:00

Hello

I am playing with Direct2D, I was read tutorials (or how to) and documentation from microsoft site, but I still can't find info, how to resize a geometry.

For example in this sample is show how is ellipse created and resized with mouse. I want change ellipse in to geometry and resize it. Problem is, I don't know how. Only scale transformation is comes to mind, but this is not resized geometry but scaled.

Here is my code how I create and draw ellipse

// MyEllipse struct
void Draw(ID2D1RenderTarget* rt, ID2D1SolidColorBrush* cb)
{
    cb->SetColor(color);
    //rt->FillEllipse(ellipse, cb);
    rt->FillGeometry(m_eGeo, cb);
    cb->SetColor(D2D1::ColorF(D2D1::ColorF::Black));
    //rt->DrawEllipse(ellipse, cb, 1.0f);
    rt->DrawGeometry(m_eGeo, cb, 1.0f);
}

// MainWindow
HRESULT MainWindow::InsertEllipse(float x, float y)
{
    try
    {
        selection = ellipses.insert(ellipses.end(), std::shared_ptr<MyEllipse>(new MyEllipse()));
        Selection()->ellipse.point = ptMouse = D2D1::Point2F(x, y);
        Selection()->ellipse.radiusX = Selection()->ellipse.radiusY = 2.0f;
        Selection()->color = D2D1::ColorF(colors[nextColor]);
        nextColor = (nextColor + 1) % ARRAYSIZE(colors);

        HRESULT hr = pFactory->CreateEllipseGeometry(Selection()->ellipse, &Selection()->m_eGeo);
        if (SUCCEEDED(hr))
        {
            std::cout << "Ellipse Geo Created\n";
        }
        else
        {
            std::cout << "Ellipse Geo Failed\n";
        }
    }
    catch (std::bad_alloc)
    {
        return E_OUTOFMEMORY;
    }
    return S_OK;
}
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,652 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Darran Rowe 1,041 Reputation points
    2020-08-17T18:45:40.973+00:00

    Remember that Direct2D is vector graphics. What this means is that if you create a geometry and scale it, it only really scales the drawing commands.
    So using ID2D1Factory::CreateTransformedGeometry to create an ID2D1TransformedGeometry should do what you want. The example that it shows in both of these shows that the render target scale does scale up everything, but the geometry transform doesn't.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.