protected static extern bool SF_SetViewport(long MovieID, SFViewport vp);
protected static extern bool SF_GetViewport(long MovieID, [Out] SFViewport vp);
/// <summary> /// Returns the viewport as calculated by internal C++ code. /// </summary> /// <param name="vp">stores the internal viewport.</param> /// <returns>True if viewport is successfully returned, false otherwise.</returns> public bool GetViewport(out SFViewport vp) { SFViewport result = new SFViewport(); #if UNITY_WP8 if(sf_getViewport(MovieID, result)) #else if(SF_GetViewport(MovieID, result)) #endif { ViewPort = result; vp = ViewPort; return true; } vp = null; return false; }
protected static extern bool SF_SetViewport(long MovieID, SFViewport vp);
/// <summary> /// Used to convert Stage coordinates to Unity screen coordinates /// </summary> /// <param name="stagePoint"> A point in Stage coordinates (z is ignored)</param> /// <returns>A point in Unity Screen Space.</returns> /// <remarks> Sample usage: /// <code> /// double x = stageX, y = stageY; /// Vector3 stagePoint = new Vector3((float)x, (float)y, 0.0f); /// Vector3 screenPoint = StagePointToScreenPoint(stagePoint);</code></remarks> public Vector3 StagePointToScreenPoint(Vector3 stagePoint) { float x = stagePoint.x; float y = stagePoint.y; // fetch the viewport for this movie SFViewport vp = new SFViewport(); GetViewport(out vp); float movieWidth = GetMovieDef().GetWidth(); float movieHeight = GetMovieDef().GetHeight(); float stageX = x; float stageY = y; float scaleX = (vp.Width / movieWidth); float scaleY = (vp.Height / movieHeight); float deltaX = (vp.Width - movieWidth); float deltaY = (vp.Height - movieHeight); x = (int)(stageX * scaleX); y = (int)(stageY * scaleY); float stageAspectRatio = (movieHeight / movieWidth); float screenAspectRatio = (Screen.height / (float)Screen.width); // NOTE: It is intentional that the SM_NoBorder and SM_ShowAll cases have similar, // yet opposite handling based on the aspect ratio differences. switch (TheScaleModeType) { case ScaleModeType.SM_ExactFit: { // Do nothing. break; } case ScaleModeType.SM_NoBorder: { // The original aspect ratio is kept, but content may be scaled and clipped. if (screenAspectRatio < stageAspectRatio) { y = RescaleValueWithOffset(y, (Screen.width * stageAspectRatio), Screen.height); } else if (screenAspectRatio > stageAspectRatio) { x = RescaleValueWithOffset(x, (Screen.height / stageAspectRatio), Screen.width); } break; } case ScaleModeType.SM_NoScale: { // The size of the content is fixed to the native resolution of the movie clip. x = stageX; x += (deltaX * 0.5f); y = stageY; y += (deltaY * 0.5f); break; } case ScaleModeType.SM_ShowAll: { // Scales the content to the viewport while maintaining the original aspect ratio. (default) if (screenAspectRatio < stageAspectRatio) { x = RescaleValueWithOffset(x, (Screen.height / stageAspectRatio), Screen.width); } else if (screenAspectRatio > stageAspectRatio) { y = RescaleValueWithOffset(y, (Screen.width * stageAspectRatio), Screen.height); } break; } } // Match Unity's Screen space origin (lower left) y = Screen.height - y; return new Vector3(x, y, 0F); }