public static List<Transition>CreateTransitionObjectsFromLayer(LayerInfo layerItem, int frameID) { List<Transition> toReturn = new List<Transition> (); TransitionInfo trItem = null; if (layerItem.Transitions.TryGetValue (1, out trItem)) { double startsAt = (frameID - 1) * trItem.Duration; RectangleF layerBox = layerItem.GetBoundingBox (); System.Drawing.PointF startLocation = AnimationUtils.ConvertToPercentagePoint (layerBox.Location, layerItem.CanvasSize); System.Drawing.PointF endLocation = AnimationUtils.ConvertToPercentagePoint (trItem.EndLocation, layerItem.CanvasSize); double degAngle = trItem.RotationAngle; foreach (KeyValuePair<TransitionEffectType, TransitionEffectSettings> eachSetting in trItem.Settings) { if (eachSetting.Key == TransitionEffectType.Move) { Transition playTransition = new Transition ((float)startsAt, (float)eachSetting.Value.Duration, TransitionTypes.Move, startLocation, endLocation); toReturn.Add (playTransition); } else if (eachSetting.Key == TransitionEffectType.Scale) { Transition playTransition = new Transition ((float)startsAt, (float)eachSetting.Value.Duration, TransitionTypes.Scale, startLocation, endLocation); toReturn.Add (playTransition); } else if (eachSetting.Key == TransitionEffectType.Rotate) { Transition playTransition = new Transition ((float)startsAt, (float)eachSetting.Value.Duration, (float)trItem.RotationAngle); toReturn.Add (playTransition); } else if (eachSetting.Key == TransitionEffectType.FadeIn || eachSetting.Key == TransitionEffectType.FadeOut) { Transition playTransition = new Transition ((float)startsAt, (float)eachSetting.Value.Duration, 0f, (float)trItem.FadeOpacity); toReturn.Add (playTransition); } } } return toReturn; }
public static LayerInfo Clone(LayerInfo layerInfo, bool withoutTransitions) { Dictionary<int, TransitionInfo> transitions = new Dictionary<int, TransitionInfo> (); if (!withoutTransitions) { foreach (KeyValuePair<int, TransitionInfo> eachTransition in layerInfo.Transitions) { TransitionInfo trObj = new TransitionInfo (eachTransition.Value.ID); trObj.SetEndFadeValue (eachTransition.Value.FadeOpacity); trObj.SetEndLocation (eachTransition.Value.EndLocation); trObj.SetEndScaleValue (eachTransition.Value.EndSize); trObj.SetRotationValue (eachTransition.Value.RotationAngle); // trObj.EffectType = eachTransition.Value.EffectType; foreach (KeyValuePair<TransitionEffectType, TransitionEffectSettings> eachItem in eachTransition.Value.Settings) { trObj.Settings [eachItem.Key] = eachItem.Value; }//end foreach transitions.Add (trObj.ID, trObj); }//end foreach }//end if LayerInfo toReturn = new LayerInfo (layerInfo.ID, layerInfo.CanvasSize, transitions); foreach (KeyValuePair<int, DrawingInfo> eachDrawingItem in layerInfo.DrawingItems) { DrawingInfo drawingItem = null; if (eachDrawingItem.Value.DrawingType == DrawingLayerType.Drawing) { drawingItem = new DrawingInfo (eachDrawingItem.Key, new List<PointF> (eachDrawingItem.Value.PathPoints), eachDrawingItem.Value.Brush, eachDrawingItem.Value.LineColor); } else { drawingItem = new DrawingInfo (eachDrawingItem.Key, eachDrawingItem.Value.Image, eachDrawingItem.Value.ImageFrame); }//end if else switch (eachDrawingItem.Value.DrawingType) { case DrawingLayerType.Drawing: drawingItem = new DrawingInfo (eachDrawingItem.Key, new List<PointF> (eachDrawingItem.Value.PathPoints), eachDrawingItem.Value.Brush, eachDrawingItem.Value.LineColor); break; case DrawingLayerType.Image: drawingItem = new DrawingInfo (eachDrawingItem.Key, eachDrawingItem.Value.Image, eachDrawingItem.Value.ImageFrame); drawingItem.RotationAngle = eachDrawingItem.Value.RotationAngle; drawingItem.RotatedImageBox = eachDrawingItem.Value.RotatedImageBox; break; case DrawingLayerType.Callout: case DrawingLayerType.Comix: case DrawingLayerType.Stamp: drawingItem = new DrawingInfo (eachDrawingItem.Key, eachDrawingItem.Value.ContentPackItemID, eachDrawingItem.Value.DrawingType, eachDrawingItem.Value.Image, eachDrawingItem.Value.ImageFrame, eachDrawingItem.Value.LineColor); drawingItem.RotationAngle = eachDrawingItem.Value.RotationAngle; drawingItem.RotatedImageBox = eachDrawingItem.Value.RotatedImageBox; drawingItem.CalloutText = eachDrawingItem.Value.CalloutText; drawingItem.CalloutTextRect = eachDrawingItem.Value.CalloutTextRect; break; }//end switch toReturn.AddDrawingInfo (drawingItem); }//end foreach return toReturn; }
public void AddLayer(LayerInfo layer) { this.Layers [layer.ID] = layer; }
public static void ScaleGraphicsObject(System.Drawing.PointF touchLocation, System.Drawing.PointF prevTouchLocation, LayerInfo layerItem, CanvasControlPoint controlPoint, bool aspectRatioLocked, ContentPackItem.ItemSize itemSize = ContentPackItem.ItemSize.Small) { RectangleF boundingBox = layerItem.GetBoundingBox (); bool scaleUpOnly = boundingBox.Width < 10f || boundingBox.Height < 10f; float sx = 0; float sy = 0; System.Drawing.PointF fixedPoint = System.Drawing.PointF.Empty; switch (controlPoint) { case CanvasControlPoint.TopLeft: // Fixed point is bottom-right fixedPoint = new System.Drawing.PointF (boundingBox.Right, boundingBox.Bottom); sx = boundingBox.Width / (boundingBox.Width + (touchLocation.X - prevTouchLocation.X)); sy = aspectRatioLocked ? sx : boundingBox.Height / (boundingBox.Height + (touchLocation.Y - prevTouchLocation.Y)); break; case CanvasControlPoint.TopRight: // Fixed point is bottom-left fixedPoint = new System.Drawing.PointF (boundingBox.Left, boundingBox.Bottom); sx = boundingBox.Width / (boundingBox.Width - (touchLocation.X - prevTouchLocation.X)); sy = aspectRatioLocked ? sx : boundingBox.Height / (boundingBox.Height + (touchLocation.Y - prevTouchLocation.Y)); break; case CanvasControlPoint.BottomRight: // Fixed point is top-left fixedPoint = boundingBox.Location; sx = boundingBox.Width / (boundingBox.Width - (touchLocation.X - prevTouchLocation.X)); sy = aspectRatioLocked ? sx : boundingBox.Height / (boundingBox.Height - (touchLocation.Y - prevTouchLocation.Y)); break; case CanvasControlPoint.BottomLeft: // Fixed point is top-right fixedPoint = new System.Drawing.PointF (boundingBox.Right, boundingBox.Top); sx = boundingBox.Width / (boundingBox.Width + (touchLocation.X - prevTouchLocation.X)); sy = aspectRatioLocked ? sx : boundingBox.Height / (boundingBox.Height - (touchLocation.Y - prevTouchLocation.Y)); break; }//end switch if (scaleUpOnly && sx < 1) { sx = 1; }//end if if (scaleUpOnly && sy < 1) { sy = 1; }//end if foreach (DrawingInfo eachDrawingInfo in layerItem.DrawingItems.Values) { if (eachDrawingInfo.DrawingType == DrawingLayerType.Drawing) { for (int i = 0; i < eachDrawingInfo.PathPoints.Count; i++) { System.Drawing.PointF point = eachDrawingInfo.PathPoints [i]; point.X = sx * (point.X + (-fixedPoint.X)) + fixedPoint.X; point.Y = sy * (point.Y + (-fixedPoint.Y)) + fixedPoint.Y; eachDrawingInfo.PathPoints [i] = point; }//end for } else if (eachDrawingInfo.DrawingType == DrawingLayerType.Image || eachDrawingInfo.DrawingType == DrawingLayerType.Comix || eachDrawingInfo.DrawingType == DrawingLayerType.Stamp || eachDrawingInfo.DrawingType == DrawingLayerType.Callout) { RectangleF imgFrame = eachDrawingInfo.ImageFrame; imgFrame.Width *= sx; imgFrame.Height *= sy; switch (controlPoint) { case CanvasControlPoint.BottomLeft: imgFrame.X += touchLocation.X - prevTouchLocation.X; break; case CanvasControlPoint.BottomRight: //NOTE: Location is ok, when the only item in the layer is the image. break; case CanvasControlPoint.TopLeft: imgFrame.X += touchLocation.X - prevTouchLocation.X; imgFrame.Y += touchLocation.Y - prevTouchLocation.Y; break; case CanvasControlPoint.TopRight: imgFrame.Y += touchLocation.Y - prevTouchLocation.Y; break; }//end switch eachDrawingInfo.ImageFrame = imgFrame; eachDrawingInfo.RotatedImageBox = eachDrawingInfo.ImageFrame.Rotate (eachDrawingInfo.RotationAngle); if (eachDrawingInfo.DrawingType == DrawingLayerType.Callout) { eachDrawingInfo.CalloutTextRect = GetCalloutTextRect (eachDrawingInfo.ImageFrame, itemSize); }//end if }//end if else }//end foreach }
public static void RotateGraphicsObjectByAngle(double degAngle, LayerInfo layerItem) { RectangleF boundingBox = layerItem.GetBoundingBox (); System.Drawing.PointF center = new System.Drawing.PointF (boundingBox.Width / 2, boundingBox.Height / 2); double radAngle = degAngle * LOLConstants.DegToRad; float angleCos = (float)Math.Cos (radAngle); float angleSin = (float)Math.Sin (radAngle); foreach (DrawingInfo eachDrawingInfo in layerItem.DrawingItems.Values) { if (eachDrawingInfo.DrawingType == DrawingLayerType.Drawing) { for (int i = 0; i < eachDrawingInfo.PathPoints.Count; i++) { System.Drawing.PointF point = eachDrawingInfo.PathPoints [i]; // Translate point float tx = point.X - center.X; float ty = point.Y - center.Y; // Rotate it float rx = (tx * angleCos) - (ty * angleSin); float ry = (ty * angleCos) + (tx * angleSin); // Translate back rx += center.X; ry += center.Y; point.X = rx; point.Y = ry; eachDrawingInfo.PathPoints [i] = point; }//end for } else if (eachDrawingInfo.DrawingType == DrawingLayerType.Image || eachDrawingInfo.DrawingType == DrawingLayerType.Comix || eachDrawingInfo.DrawingType == DrawingLayerType.Stamp) { RectangleF imgFrame = eachDrawingInfo.ImageFrame; eachDrawingInfo.RotatedImageBox = imgFrame.Rotate (degAngle); eachDrawingInfo.RotationAngle = degAngle; } else if (eachDrawingInfo.DrawingType == DrawingLayerType.Callout) { throw new NotImplementedException ("Implement Callouts in AnimationUtils.RotateGraphicsObjectByAngle!"); }//end if else if }//end foreach }
public static void RotateGraphicsObject(System.Drawing.PointF touchLocation, LayerInfo layerItem, ref double prevRadAngle) { RectangleF boundingRect = layerItem.GetBoundingBox (); System.Drawing.PointF center = new System.Drawing.PointF (boundingRect.Width / 2, boundingRect.Height / 2); double deltaX = touchLocation.X - center.X; double deltaY = touchLocation.Y - center.Y; double radAngle = Math.Atan2 (deltaY, deltaX); double angleDiff = radAngle - prevRadAngle; float angleCos = (float)Math.Cos (angleDiff); float angleSin = (float)Math.Sin (angleDiff); foreach (DrawingInfo eachDrawingInfo in layerItem.DrawingItems.Values) { if (eachDrawingInfo.DrawingType == DrawingLayerType.Drawing) { for (int i = 0; i < eachDrawingInfo.PathPoints.Count; i++) { System.Drawing.PointF point = eachDrawingInfo.PathPoints [i]; // Translate point float tx = point.X - center.X; float ty = point.Y - center.Y; // Rotate it float rx = (tx * angleCos) - (ty * angleSin); float ry = (ty * angleCos) + (tx * angleSin); // Translate back rx += center.X; ry += center.Y; point.X = rx; point.Y = ry; eachDrawingInfo.PathPoints [i] = point; }//end for } else if (eachDrawingInfo.DrawingType == DrawingLayerType.Image || eachDrawingInfo.DrawingType == DrawingLayerType.Comix || eachDrawingInfo.DrawingType == DrawingLayerType.Stamp || eachDrawingInfo.DrawingType == DrawingLayerType.Callout) { double degAngle = radAngle * LOLConstants.RadToDeg; RectangleF imgFrame = eachDrawingInfo.ImageFrame; eachDrawingInfo.RotatedImageBox = imgFrame.Rotate (degAngle); }//end if else if eachDrawingInfo.RotationAngle = radAngle * LOLConstants.RadToDeg; }//end foreach prevRadAngle = radAngle; }
public static void MoveGraphicsObject(System.Drawing.PointF touchLocation, System.Drawing.PointF prevTouchLocation, LayerInfo layerItem) { foreach (DrawingInfo eachDrawingInfo in layerItem.DrawingItems.Values) { if (eachDrawingInfo.DrawingType == DrawingLayerType.Drawing) { for (int i = 0; i < eachDrawingInfo.PathPoints.Count; i++) { System.Drawing.PointF point = eachDrawingInfo.PathPoints [i]; float xDiff = touchLocation.X - prevTouchLocation.X; float yDiff = touchLocation.Y - prevTouchLocation.Y; point.X += xDiff; point.Y += yDiff; eachDrawingInfo.PathPoints [i] = point; }//end for } else if (eachDrawingInfo.DrawingType == DrawingLayerType.Image || eachDrawingInfo.DrawingType == DrawingLayerType.Comix || eachDrawingInfo.DrawingType == DrawingLayerType.Stamp || eachDrawingInfo.DrawingType == DrawingLayerType.Callout) { RectangleF imgFrame = eachDrawingInfo.ImageFrame; float xDiff = touchLocation.X - prevTouchLocation.X; float yDiff = touchLocation.Y - prevTouchLocation.Y; imgFrame.X += xDiff; imgFrame.Y += yDiff; eachDrawingInfo.ImageFrame = imgFrame; eachDrawingInfo.RotatedImageBox = eachDrawingInfo.ImageFrame.Rotate (eachDrawingInfo.RotationAngle); if (eachDrawingInfo.DrawingType == DrawingLayerType.Callout) { RectangleF calloutTextRect = eachDrawingInfo.CalloutTextRect; calloutTextRect.X += xDiff; calloutTextRect.Y += yDiff; eachDrawingInfo.CalloutTextRect = calloutTextRect; }//end if }//end if else if }//end foreach }
public static TransitionEffectType CreateTransitionEffect(LayerInfo guideLayer, TransitionInfo transitionItem) { TransitionEffectType toReturn = TransitionEffectType.None; RectangleF layerBox = guideLayer.GetBoundingBox (); // Check for Move transition if (layerBox.Location != transitionItem.EndLocation) { toReturn = TransitionEffectType.Move; }//end if // Check for Rotation transition double guideRotationAngle = guideLayer.DrawingItems.Select (s => s.Value.RotationAngle).Max (); if (guideRotationAngle != transitionItem.RotationAngle) { if (toReturn == TransitionEffectType.None) { toReturn = TransitionEffectType.Rotate; } else { toReturn |= TransitionEffectType.Rotate; }//end if else }//end if // Check for Scale transition if (layerBox.Size != transitionItem.EndSize) { if (toReturn == TransitionEffectType.None) { toReturn = TransitionEffectType.Scale; } else { toReturn |= TransitionEffectType.Scale; }//end if else }//end if return toReturn; }
public static ScreenObject CreateScreenObjectFromLayer(LayerInfo layerItem, int frameID) { ScreenObject toReturn = null; List<List<System.Drawing.PointF>> pathPoints = new List<List<System.Drawing.PointF>> (); List<float> lineWidths = new List<float> (); List<string> lineColors = new List<string> (); RectangleF layerBox = layerItem.GetBoundingBox (); byte [] imgBuffer = null; if (layerItem.HasDrawingItems) { switch (layerItem.DrawingItems [1].DrawingType) { case DrawingLayerType.Drawing: foreach (DrawingInfo eachDrawingInfo in layerItem.DrawingItems.Values) { pathPoints.Add (ConvertToPercentageList (eachDrawingInfo.PathPoints, layerItem.CanvasSize)); lineWidths.Add (eachDrawingInfo.Brush.Thickness); lineColors.Add (GetColorHexStr (eachDrawingInfo.LineColor)); } toReturn = new ScreenObject (pathPoints, lineWidths, lineColors, 0f, layerItem.ID); toReturn.InitialPosition = ConvertToPercentagePoint (layerBox.Location, layerItem.CanvasSize); toReturn.Size = ConvertToPercentagePoint (new System.Drawing.PointF (layerBox.Size.Width, layerBox.Size.Height), layerItem.CanvasSize); break; case DrawingLayerType.Comix: case DrawingLayerType.Image: case DrawingLayerType.Stamp: /*using (Bitmap imgData = layerItem.DrawingItems[1].Image) { using (MemoryStream mem = new MemoryStream ()) { imgData.Compress (Bitmap.CompressFormat.Png, 100, mem); } }*/ System.Drawing.PointF initialPosition = ConvertToPercentagePoint (layerBox.Location, layerItem.CanvasSize); System.Drawing.PointF size = ConvertToPercentagePoint (new System.Drawing.PointF (layerBox.Width, layerBox.Height), layerItem.CanvasSize); toReturn = new ScreenObject (initialPosition, size, imgBuffer, 0, layerItem.ID); break; default: throw new InvalidOperationException (string.Format ("Not known drawing layer type {0}", layerItem.DrawingItems [1].DrawingType)); } } return toReturn; }
public static void ApplyScaleTransformToObject(System.Drawing.PointF fixedPoint, float scaleX, float scaleY, LayerInfo layerItem) { foreach (DrawingInfo eachDrawingInfo in layerItem.DrawingItems.Values) { for (int i = 0; i < eachDrawingInfo.PathPoints.Count; i++) { System.Drawing.PointF point = eachDrawingInfo.PathPoints [i]; point.X = scaleX * (point.X + (-fixedPoint.X)) + fixedPoint.X; point.Y = scaleY * (point.Y + (-fixedPoint.Y)) + fixedPoint.Y; eachDrawingInfo.PathPoints [i] = point; }//end for }//end foreach }