Share via


IXRRotateTransform (Windows Embedded CE 6.0)

1/6/2010

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

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.

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.

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

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.

Inheritance Hierarchy

IXRDependencyObject

    IXRGeneralTransform

        IXRTransform

            IXRRotateTransform

.NET Framework Equivalent

System.Windows.Media.RotateTransform

Requirements

Header XamlRuntime.h
sysgen SYSGEN_XAML_RUNTIME
Windows Embedded CE Windows Embedded CE 6.0 R3

See Also

Reference

Classes for Visual Appearance and Behavior

Other Resources