/// <summary> /// Ejecuta el cambio de ViewBox de una animación /// </summary> private void ExecuteViewBoxAnimation(FrameworkElement control, BrushViewBoxActionModel action) { if (action.ViewBox != null || action.ViewPort != null) { Brush brushControl = GetBrushFromControl(control); if (brushControl != null && brushControl is TileBrush) { TileBrush brush = brushControl as TileBrush; if (brush != null) { // Anima el viewbox if (action.ViewBox != null) { // Inicializa el viewBox if (brush.Viewbox == null) { brush.Viewbox = new Rect(0, 0, 1, 1); brush.ViewboxUnits = BrushMappingMode.RelativeToBoundingBox; } brush.Viewbox = ViewTools.ConvertToRect(action.ViewBox); } // Anima el viewport if (action.ViewPort != null) { // Inicializa el ViewPort if (brush.Viewport == null) { brush.Viewport = new Rect(0, 0, 1, 1); brush.ViewportUnits = BrushMappingMode.RelativeToBoundingBox; } // Asigna el modo de relleno brush.TileMode = ViewTools.Convert(action.TileMode); brush.Viewport = ViewTools.ConvertToRect(action.ViewPort); } } } } }
/// <summary> /// Crea la animación de rectángulor sobre un control /// </summary> private void CreateRectangleAnimation(DependencyObject control, Rect?from, Rect to, PropertyPath propertyPath, BrushViewBoxActionModel action) { RectAnimation animation = new RectAnimation(); // Asigna las propiedades From y To de la animación if (from != null) { animation.From = from; } if (to != null) { animation.To = to; } // Asigna las funciones animation.EasingFunction = AssignEasingFuntion(action); // Asigna la animación al storyboard AddAnimationToStoryBoard(control, animation, action, propertyPath); }
/// <summary> /// Carga los datos de un timeline /// </summary> internal TimeLineModel LoadTimeLine(PageModel page, MLNode nodeML) { TimeLineModel timeLine = new TimeLineModel(page, nodeML.Attributes[ComicRepositoryConstants.TagMustAnimate].Value.GetBool(true)); // Asigna los atributos AssignAttributesAction(nodeML, timeLine.Parameters, 0, 3); // Carga el contenido del timeLine foreach (MLNode childML in nodeML.Nodes) { ActionBaseModel action = null; // Obtiene la acción switch (childML.Name) { case ComicRepositoryConstants.TagActionShowImage: action = new SetVisibilityActionModel(timeLine, childML.Attributes[ComicRepositoryConstants.TagKey].Value, childML.Attributes[ComicRepositoryConstants.TagVisible].Value.GetBool(true), childML.Attributes[ComicRepositoryConstants.TagOpacity].Value.GetDouble(), childML.Attributes[ComicRepositoryConstants.TagMustAnimate].Value.GetBool(true)); break; case ComicRepositoryConstants.TagActionResize: action = new ResizeActionModel(timeLine, childML.Attributes[ComicRepositoryConstants.TagKey].Value, childML.Attributes[ComicRepositoryConstants.TagWidth].Value.GetDouble(), childML.Attributes[ComicRepositoryConstants.TagHeight].Value.GetDouble(), childML.Attributes[ComicRepositoryConstants.TagMustAnimate].Value.GetBool(true)); break; case ComicRepositoryConstants.TagActionRotate: action = new RotateActionModel(timeLine, childML.Attributes[ComicRepositoryConstants.TagKey].Value, childML.Attributes[ComicRepositoryConstants.TagOriginX].Value.GetDouble(0.5), childML.Attributes[ComicRepositoryConstants.TagOriginY].Value.GetDouble(0.5), childML.Attributes[ComicRepositoryConstants.TagAngle].Value.GetDouble(0), childML.Attributes[ComicRepositoryConstants.TagMustAnimate].Value.GetBool(true)); break; case ComicRepositoryConstants.TagActionZoom: action = new ZoomActionModel(timeLine, childML.Attributes[ComicRepositoryConstants.TagKey].Value, childML.Attributes[ComicRepositoryConstants.TagOriginX].Value.GetDouble(0.5), childML.Attributes[ComicRepositoryConstants.TagOriginY].Value.GetDouble(0.5), childML.Attributes[ComicRepositoryConstants.TagScaleX].Value.GetDouble(1), childML.Attributes[ComicRepositoryConstants.TagScaleY].Value.GetDouble(1), childML.Attributes[ComicRepositoryConstants.TagMustAnimate].Value.GetBool(true)); break; case ComicRepositoryConstants.TagActionTranslate: action = new TranslateActionModel(timeLine, childML.Attributes[ComicRepositoryConstants.TagKey].Value, childML.Attributes[ComicRepositoryConstants.TagTop].Value.GetDouble(), childML.Attributes[ComicRepositoryConstants.TagLeft].Value.GetDouble(), childML.Attributes[ComicRepositoryConstants.TagMustAnimate].Value.GetBool(true)); break; case ComicRepositoryConstants.TagActionSetZIndex: action = new SetZIndexModel(timeLine, childML.Attributes[ComicRepositoryConstants.TagKey].Value, childML.Attributes[ComicRepositoryConstants.TagMustAnimate].Value.GetBool(true), childML.Attributes[ComicRepositoryConstants.TagZIndex].Value.GetInt(1)); break; case ComicRepositoryConstants.TagActionPath: action = new PathActionModel(timeLine, childML.Attributes[ComicRepositoryConstants.TagKey].Value, Mediator.CommonRepository.Normalize(childML.Value), childML.Attributes[ComicRepositoryConstants.TagRotateWithTangent].Value.GetBool(true), childML.Attributes[ComicRepositoryConstants.TagMustAnimate].Value.GetBool(true)); break; case ComicRepositoryConstants.TagSetActionViewBox: action = new BrushViewBoxActionModel(timeLine, childML.Attributes[ComicRepositoryConstants.TagKey].Value, Mediator.CommonRepository.GetRectangle(childML.Attributes[ComicRepositoryConstants.TagViewBox].Value), Mediator.CommonRepository.GetRectangle(childML.Attributes[ComicRepositoryConstants.TagViewPort].Value), Mediator.CommonRepository.ConvertTile(childML.Attributes[ComicRepositoryConstants.TagTileMode].Value), childML.Attributes[ComicRepositoryConstants.TagMustAnimate].Value.GetBool(true)); break; case ComicRepositoryConstants.TagSetActionRadialBrush: action = new BrushRadialActionModel(timeLine, childML.Attributes[ComicRepositoryConstants.TagKey].Value, Mediator.CommonRepository.GetPoint(childML.Attributes[ComicRepositoryConstants.TagCenter].Value), Mediator.CommonRepository.GetPoint(childML.Attributes[ComicRepositoryConstants.TagOrigin].Value), childML.Attributes[ComicRepositoryConstants.TagRadiusX].Value.GetDouble(), childML.Attributes[ComicRepositoryConstants.TagRadiusY].Value.GetDouble(), childML.Attributes[ComicRepositoryConstants.TagMustAnimate].Value.GetBool(true)); break; case ComicRepositoryConstants.TagSetActionLinearBrush: action = new BrushLinearActionModel(timeLine, childML.Attributes[ComicRepositoryConstants.TagKey].Value, Mediator.CommonRepository.GetPoint(childML.Attributes[ComicRepositoryConstants.TagStart].Value), Mediator.CommonRepository.GetPoint(childML.Attributes[ComicRepositoryConstants.TagEnd].Value), Mediator.CommonRepository.GetSpreadMethod(childML.Attributes[ComicRepositoryConstants.TagSpread].Value), childML.Attributes[ComicRepositoryConstants.TagMustAnimate].Value.GetBool(true)); break; } // Si realmente se ha leído alguna acción if (action != null) { // Asigna los atributos AssignAttributesAction(childML, action.Parameters, timeLine.Parameters.Start, timeLine.Parameters.Duration); // Asigna las funciones LoadEases(action, childML); // Añade la acción al timeline timeLine.Actions.Add(action); } } // Devuelve el timeline return(timeLine); }