public static void ApplyScaleTransformToObject(PointF fixedPoint, float scaleX, float scaleY, LayerInfo layerItem, ContentPackItem.ItemSize itemSize = ContentPackItem.ItemSize.Small) { foreach (DrawingInfo eachDrawingInfo in layerItem.DrawingItems.Values) { switch (eachDrawingInfo.DrawingType) { case DrawingLayerType.Drawing: for (int i = 0; i < eachDrawingInfo.PathPoints.Count; i++) { 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 break; case DrawingLayerType.Image: case DrawingLayerType.Comix: case DrawingLayerType.Stamp: case DrawingLayerType.Callout: RectangleF imgFrame = eachDrawingInfo.ImageFrame; imgFrame.Width *= scaleX; imgFrame.Height *= scaleY; imgFrame.X = scaleX * (imgFrame.X + (-fixedPoint.X)) + fixedPoint.X; imgFrame.Y = scaleY * (imgFrame.Y + (-fixedPoint.Y)) + fixedPoint.Y; eachDrawingInfo.ImageFrame = imgFrame; eachDrawingInfo.RotatedImageBox = eachDrawingInfo.ImageFrame.Rotate(eachDrawingInfo.RotationAngle); if (eachDrawingInfo.DrawingType == DrawingLayerType.Callout) { eachDrawingInfo.CalloutTextRect = GetCalloutTextRect(imgFrame, itemSize); }//end if break; }//end switch }//end foreach }
public static void ScaleGraphicsObject(PointF touchLocation, 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; PointF fixedPoint = PointF.Empty; switch (controlPoint) { case CanvasControlPoint.TopLeft: // Fixed point is bottom-right fixedPoint = new 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 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 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++) { 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 }
//NOTE: Ella's numbers // 1. // 1024 callouts - vertical-162px; horizontal- 82px; text-box: 800x366px; // 2. // 512 callouts - vertical-82px; horizontal- 42px; text-box: 400x182px; // 3. // 256 callouts - vertical-42px; horizontal- 22px; text-box: 200x90px; // 4. // 160 callouts - vertical-26px; horizontal- 26px; text-box: 124x56px; public static RectangleF GetCalloutTextRectForSize(ContentPackItem.ItemSize itemSize) { switch (itemSize) { case ContentPackItem.ItemSize.Large: return new RectangleF (82f, 162f, 800f, 366f); case ContentPackItem.ItemSize.Medium: return new RectangleF (42f, 82f, 400f, 182f); case ContentPackItem.ItemSize.Small: return new RectangleF (22f, 42f, 200f, 90f); case ContentPackItem.ItemSize.Tiny: return new RectangleF (26f, 26f, 124f, 56f); default: throw new ArgumentException ("Item size must be any of Large, Medium, Small or Tiny!", "itemSize"); }//end switch }
public static RectangleF GetCalloutTextRect(RectangleF imgFrame, ContentPackItem.ItemSize itemSize) { RectangleF calloutTextArea = GetCalloutTextRectForSize (itemSize); SizeF calloutSize = GetCalloutSizeForPackItemSize (itemSize); RectangleF imgRect = imgFrame; float sx = imgRect.Width / calloutSize.Width; float sy = imgRect.Height / calloutSize.Height; return new RectangleF (imgRect.X + (sx * calloutTextArea.X), imgRect.Y + (sy * calloutTextArea.Y), sx * calloutTextArea.Width, sy * calloutTextArea.Height); }
public static SizeF GetCalloutSizeForPackItemSize(ContentPackItem.ItemSize itemSize) { switch (itemSize) { case ContentPackItem.ItemSize.Large: return new SizeF (1024f, 1024f); case ContentPackItem.ItemSize.Medium: return new SizeF (512f, 512f); case ContentPackItem.ItemSize.Small: return new SizeF (256f, 256f); case ContentPackItem.ItemSize.Tiny: return new SizeF (160f, 160f); default: throw new ArgumentException ("Item size must be any of Large, Medium, Small or Tiny!", "itemSize"); }//end switch }
public static ContentPackItemDB ConvertFromContentPackItem(ContentPackItem item) { ContentPackItemDB toReturn = new ContentPackItemDB (); toReturn.ContentItemTitle = item.ContentItemTitle; toReturn.ContentPackData = item.ContentPackData; toReturn.ContentPackID = item.ContentPackID; toReturn.ContentPackItemIcon = item.ContentPackItemIcon; toReturn.ContentPackItemID = item.ContentPackItemID; toReturn.Errors = item.Errors; return toReturn; }