IXRRotateTransform (Compact 2013)

3/28/2014

This object can be used to rotate an object clockwise around a specified point in a two-dimensional coordinate system.

Syntax

class IXRRotateTransform : public IXRTransform

Inheritance Hierarchy

IXRDependencyObject

    IXRGeneralTransform

        IXRTransform

            IXRRotateTransform

Methods

Method

Description

IXRRotateTransform::GetAngle

Retrieves the angle, in degrees, of clockwise rotation.

IXRRotateTransform::GetCenterX

Retrieves the x-coordinate of the rotation center point.

IXRRotateTransform::GetCenterY

Retrieves the y-coordinate of the rotation center point.

IXRRotateTransform::SetAngle

Sets the angle, in degrees, of clockwise rotation.

IXRRotateTransform::SetCenterX

Sets the x-coordinate of the rotation center point.

IXRRotateTransform::SetCenterY

Sets the y-coordinate of the rotation center point.

Thread Safety

Members of this class are thread-safe if you previously called IXRApplication::CreateHostFromXaml and supplied it with an XRWindowCreateParams structure that has AllowsMultipleThreadAccess set to true.

Remarks

  • To animate this rotation-transformation, you could create an IXRDoubleAnimation object, and use its inherited method IXRDependencyObject::SetAttachedProperty to set its attached property Storyboard.TargetName to the name of the IXRRotateTransform object instance and set Storyboard.TargetProperty to one of the properties set by methods in the previous list, such as Angle.

When you use an IXRRotateTransform, the transformation rotates the coordinate system for a particular object around the origin point for its frame of reference. The object is not necessarily rotated around its center. For example, if an object is positioned 200 units from 0 along the x-axis, rotating it 30 degrees will swing the object 30 degrees along a circle that has a radius of 200 centered at the origin.

To rotate an object in place, pass in the coordinates of the center of the object into IXRRotateTransform::SetCenterX and IXRRotateTransform::SetCenterY.

When you create a class instance, use an IXRRotateTransformPtr smart pointer instead of a raw interface pointer. For more information, see XRPtr<Interface>.

You can also define a rotate transformation in Microsoft Silverlight 3 XAML. For information about the differences in Silverlight 3 implementations in XAML for Windows Embedded and Silverlight 3, see Differences Between Microsoft Silverlight 3 and XAML for Windows Embedded. For more information about how to define this element in the source XAML for your application, see the RotateTransform Class on MSDN.

Example

The following code example creates a rotation-transformation that rotates an IXRRectangle object in response to a mouse-down event. For it to run properly, you must already have loaded the rectangle into an object tree. It uses a storyboard to animate the value of the angle of rotation over a specified duration of time.

Important

For readability, the following code example does not contain security checking or error handling. Do not use the following code in a production environment.

#include <windows.h>
#include <XamlRuntime.h>
#include <XRDelegate.h>
#include <XRPtr.h>

class CustomEventHandlers 
{
 public:
    IXRVisualHost* g_pHost;
 
   HRESULT  SetHost(IXRVisualHost* pHost)
       {
            HRESULT hr;
            ASSERT(! g_pHost);
            if(NULL == pHost)
            {
                 hr = S_FALSE;
                 return hr;
            
            }
            
            g_pHost = pHost;
            g_pHost->AddRef();
           hr = S_OK;
            return hr;
       }


   HRESULT OnMouseLeftButtonDown(IXRDependencyObject* pSender, XRMouseEventArgs* pArgs)
   {
       IXRFrameworkElementPtr pRoot;
   IXRStoryboardPtr pStoryboard;
       g_pHost->GetRootElement(&pRoot);
   pRoot->FindName(L"RectangleAnimation", &pStoryboard);

   // First make sure that the storyboard is not playing
   pStoryboard->Stop();
       
       // Begin to play the animation storyboard
       pStoryboard->Begin();
   }


};

void CreateRotateTransform(IXRApplication* pApplication, IXRFrameworkElement* pVisualRoot, XRRepeatBehavior* myForeverRepeatStruct, IXRUIElement* pRectangle, CustomEventHandlers* myHandlerObject)
{
  IXRRotateTransform* myRTransform;
  float startAngle = 45; // angle to rotate to is at first 45°
  float centerX = 50;   // x-coordinate
  float centerY = 50;   // y-coordinate

  pApplication->CreateObject(IID_IXRRotateTransform, &myRTransform);

  myRTransform->SetAngle(startAngle);
  myRTransform->SetCenterX(centerX);
  myRTransform->SetCenterY(centerY);
  myRTransform->SetName(L"myRTransform");

  pRectangle->SetRenderTransform(myRTransform);

  // Create an animation and storyboard to animate a rectangle's angle value
  IXRDoubleAnimation* pAnimation;
  IXRStoryboard* pStoryboard;
  IXRTimelineCollection* childAnimations;
  float originalAngle = 0;
  float newAngle = 360;

  pApplication->CreateObject(IID_IXRDoubleAnimation, &pAnimation);
  pApplication->CreateObject(IID_IXRStoryboard, &pStoryboard);

  pAnimation->SetAttachedProperty(L"Storyboard.TargetName", L"myRTransform");
  pAnimation->SetAttachedProperty(L"Storyboard.TargetProperty", L"Angle");
  pAnimation->SetFrom(originalAngle);
  pAnimation->SetTo(newAngle);
  pAnimation->SetRepeatBehavior(myForeverRepeatStruct);

  pStoryboard->SetName(L"RectangleAnimation");
  pStoryboard->GetChildren(&childAnimations);
  childAnimations->Add(pAnimation, NULL);


  // Get a pointer to the canvas on which the rectangle is positioned
  IXRCanvas* pCanvas;
  IXRResourceDictionary* canvasResources;
  UINT* index;

  pVisualRoot->FindName(L"MyCanvas", &pCanvas);
  pCanvas->GetResources(&canvasResources);
  canvasResources->Add(pStoryboard, &index);

  // Attach a delegate to an event in the rectangle object that   //represents the animation event handler


  pRectangle->AddMouseLeftButtonDownEventHandler(CreateDelegate(&myHandlerObject, &CustomEventHandlers::OnMouseLeftButtonDown));
}

To run this code example, you must already have created an application instance, parsed the XAML, generated an object tree, and obtained the visual root. You must also have defined an XRRepeatBehavior structure and have a pointer to the rectangle object to animate. For more information about these programming elements, see IXRApplication, IXRVisualHost, IXRFrameworkElement, XRRepeatBehavior, XRPtr<Interface>, and IXRRectangle.

.NET Framework Equivalent

System.Windows.Media.RotateTransform

Requirements

Header

XamlRuntime.h

sysgen

SYSGEN_XAML_RUNTIME

See Also

Reference

Classes for Visual Appearance