1

Here is the slightly modified Direct Manipulation Sample app from windows 8 classic samples. I removed all elements except the single Viewport and it's Content (checkered texture). When I set IDirectManipulationVewport::SetViewportRect() with offset to the origin (e.g. SetViewportRect(100, 100, client_rect.right, client_rect.bottom) I expect the content to be aligned at 100, 100. However the content is always aligned at the window (parent IDirectCompositionVisual) origin.

enter image description here

I also tried IDirectManipulationViewport::SetViewportTransform() with translation matrix, but the result is the same.

What is the correct way of positioning the viewport in the visual not at the origin? Is it possible? Or I should create another child IDirectCompositionVisual with viewport, position it with SetOffsetX/Y and add content to it?

Here is a link to documentation

UPD after Rita Han's answer: If you make just the following modifications to the sample:

//modify viewport rectangle in CAppWindow::_SizeDependentChanges()
_viewportOuterRect.left = 100;
_viewportOuterRect.top = 100;

//align content at the center in HRESULT CAppWindow::_InitializeManagerAndViewport()
primaryContentOuter->SetHorizontalAlignment(DIRECTMANIPULATION_HORIZONTALALIGNMENT_CENTER);
primaryContentOuter->SetVerticalAlignment(DIRECTMANIPULATION_VERTICALALIGNMENT_CENTER);

//change zoom boundaries to enable zoom out
hr = primaryContentOuter->SetZoomBoundaries(0.1f, 5.0f);

If you zoom out, you will see the following: enter image description here red - actual incorrect viewport rectangle (_viewportOuterRect.left and top coordinates are ignored, however the size is changed).

green - expected viewport rectangle.

blue - expected content aligned position.

cos
  • 940
  • 1
  • 10
  • 25
  • Hi cos, "red - actual incorrect viewport rectangle (_viewportOuterRect.left and top coordinates are ignored, however the size is changed)." how do you determine viewport and content rectangle position? I use `_viewportOuter->GetViewportRect` after `_viewportOuter->SetViewportRect` and get expected _viewportOuterRect.left and top are both 100. – Rita Han Feb 13 '19 at 06:39
  • Content position - is basically the checkered texture (it is the content). It should be aligned at the center of it's viewport (because of SetHorizontalAlignment()/SetVerticalAlignment() calls). If you draw an imaginary rectangle around it - it would be the red one. GetViewportRect() just reports back the values set by SetViewportRect(), but they are not applied as expected. – cos Feb 13 '19 at 18:41

1 Answers1

1

This sample works for me you can have a try. The related code I modified for your case:

    ::GetClientRect(_hWnd, &_viewportOuterRect);
    _viewportOuterRect.left = 100;
    _viewportOuterRect.top = 100;
    if(SUCCEEDED(hr))
    {
        hr = _viewportOuter->SetViewportRect(&_viewportOuterRect);
    }

The output:

enter image description here

Rita Han
  • 9,574
  • 1
  • 11
  • 24
  • Unfortunately the content is still not aligned within the viewport (you can see that the button and the text label are clipped even if you try to drag them to the right). It is just clipped with a clip rectangle later in _SizeDependentChanges() function: _dcompVisualOuterParent->SetClip(clipRect.Get()); – cos Feb 12 '19 at 10:43
  • Clipping is a part of DirectComposition API (Visuals and stuff) and it works as expected, but aligning and manipulating content inside a viewport is a DirectManipulation API. – cos Feb 12 '19 at 11:18