private void Resize() { double newWidth = Application.Current.Host.Content.ActualWidth; double newHeight = Application.Current.Host.Content.ActualHeight; if ((base.Width != newWidth || base.Height != newHeight) && (newHeight > 100 && newWidth > 100)) { #if SCALABLE_CONTROLS //j double scalex = newWidth / 1024; double scaley = newHeight / 768; double scale = Math.Min(scalex, scaley); ScaleTransform scaleTransform = new ScaleTransform(); scaleTransform.ScaleX = scale; scaleTransform.ScaleY = scale; ApplicationEx.LayoutRoot.RenderTransform = scaleTransform; #endif // Change the size of the UserControl/Page, the LayoutRoot, and the LayoutRoot's main child base.Width = newWidth; base.Height = newHeight; ApplicationEx.LayoutRoot.Width = newWidth; ApplicationEx.LayoutRoot.Height = newHeight; Panel childPanel = null; if (ApplicationEx.LayoutRoot.Children.Count > 0 && (childPanel = ApplicationEx.LayoutRoot.Children[0] as Panel) != null) { childPanel.Width = newWidth; childPanel.Height = newHeight; } } }
static public Texture2D LoadBitmap(string imageName, int w, int h) { // // Load a bitmap image through writeablebitmap so that we can populate our device // texture // StreamResourceInfo sr = Application.GetResourceStream(new Uri(imageName, UriKind.Relative)); BitmapImage bs = new BitmapImage(); bs.SetSource(sr.Stream); var wb = new WriteableBitmap(w, h); ScaleTransform t = new ScaleTransform(); t.ScaleX = (double)w / (double)bs.PixelWidth; t.ScaleY = (double)h / (double)bs.PixelHeight; Image image = new Image(); image.Source = bs; wb.Render(image, t); wb.Invalidate(); Texture2D tex = new Texture2D(GraphicsDeviceManager.Current.GraphicsDevice, wb.PixelWidth, wb.PixelHeight, false, SurfaceFormat.Color); wb.CopyTo(tex); return tex; }
public void Test() { ScaleTransform st = new ScaleTransform(100, 1000); Assert.AreEqual(500, st.AtoB(50)); Assert.AreEqual(50, st.BtoA(500)); }
public void OnPostInit() { var templateRoot = VisualTreeHelper.GetChild(this, 0) as FrameworkElement; this.contentPresenter = (ContentPresenter)templateRoot.FindName("ContentPresenter"); this.contentPresenterScaleTransform = new ScaleTransform(1f, 1f); this.contentPresenter.RenderTransform = this.contentPresenterScaleTransform; this.Loaded += this.OnLoaded; // just for testing Instances.Add(new WeakReference(this)); this.RefreshViewBoxMargins(); }
void UpdateSize() { if (_newSize == null || TextPath == null) { return; } _layoutHasValidSize = true; double xScale = _newSize.Width / TextPath.Bounds.Width; double yScale = _newSize.Height / TextPath.Bounds.Height; if (TextPath.Bounds.Width <= 0) { xScale = 1.0; } if (TextPath.Bounds.Height <= 0) { xScale = 1.0; } if (xScale <= 0 || yScale <= 0) { return; } if (TextPath.Transform is TransformGroup) { TransformGroup grp = TextPath.Transform as TransformGroup; if (grp.Children[0] is ScaleTransform && grp.Children[1] is TranslateTransform) { if (ScaleTextPath) { ScaleTransform scale = grp.Children[0] as ScaleTransform; scale.ScaleX *= xScale; scale.ScaleY *= yScale; } TranslateTransform translate = grp.Children[1] as TranslateTransform; translate.X += -TextPath.Bounds.X; translate.Y += -TextPath.Bounds.Y; } } else { ScaleTransform scale; TranslateTransform translate; if (ScaleTextPath) { scale = new ScaleTransform(xScale, yScale); translate = new TranslateTransform(-TextPath.Bounds.X * xScale, -TextPath.Bounds.Y * yScale); } else { scale = new ScaleTransform(1.0, 1.0); translate = new TranslateTransform(-TextPath.Bounds.X, -TextPath.Bounds.Y); } TransformGroup grp = new TransformGroup(); grp.Children.Add(scale); grp.Children.Add(translate); TextPath.Transform = grp; } }
protected override void Init() { SetBaseView(); ScaleTransform translation = new ScaleTransform(1, 1); dauX = new DoubleAnimationUsingKeyFrames(); dauY = new DoubleAnimationUsingKeyFrames(); #region 基本工作,确定类型和name //是否存在TranslateTransform //动画要的类型是否存在 //动画要的类型的name是否存在,不存在就注册,结束后取消注册,删除动画 var ex = Element.RenderTransform; if (ex == null || (ex as System.Windows.Media.MatrixTransform) != null) { var tg = new TransformGroup(); translation = new ScaleTransform(1, 1); Win.RegisterName(translation.GetHashCode().ToString(), translation); tg.Children.Add(translation); Element.RenderTransform = tg; } else { var tg = ex as TransformGroup; foreach (var item in tg.Children) { translation = item as ScaleTransform; if (translation != null) { break; } } if (translation != null) { var tex = translation.GetValue(FrameworkElement.NameProperty); if (tex != null && tex.ToString() != "") { } else { Win.RegisterName(translation.GetHashCode().ToString(), translation); } } else { translation = new ScaleTransform(1, 1); Win.RegisterName(translation.GetHashCode().ToString(), translation); tg.Children.Add(translation); Element.RenderTransform = tg; } } #endregion Win.RegisterResource(Story); Story = (Storyboard)Story.CloneCurrentValue(); double danqianX = translation.ScaleX; double danqianY = translation.ScaleY; var k2 = new EasingDoubleKeyFrame(1, TimeSpan.FromMilliseconds(0)); var k2_0 = new EasingDoubleKeyFrame(0.9, TimeSpan.FromMilliseconds(AniTime(0.2))); var k2_1 = new EasingDoubleKeyFrame(1.1, TimeSpan.FromMilliseconds(AniTime(0.5))); var k2_2 = new EasingDoubleKeyFrame(1.1, TimeSpan.FromMilliseconds(AniTime(0.55))); var k2_4 = new EasingDoubleKeyFrame(0, TimeSpan.FromMilliseconds(AniTime(1))); dauX.FillBehavior = FillBehavior.Stop; Storyboard.SetTargetName(dauX, Win.GetName(translation)); Storyboard.SetTargetProperty(dauX, new PropertyPath(ScaleTransform.ScaleXProperty)); dauX.KeyFrames.Add(k2); dauX.KeyFrames.Add(k2_0); dauX.KeyFrames.Add(k2_1); dauX.KeyFrames.Add(k2_2); dauX.KeyFrames.Add(k2_4); Story.Children.Add(dauX); dauY.FillBehavior = FillBehavior.Stop; Storyboard.SetTargetName(dauY, Win.GetName(translation)); Storyboard.SetTargetProperty(dauY, new PropertyPath(ScaleTransform.ScaleYProperty)); dauY.KeyFrames.Add(k2); dauY.KeyFrames.Add(k2_0); dauY.KeyFrames.Add(k2_1); dauY.KeyFrames.Add(k2_2); dauY.KeyFrames.Add(k2_4); Story.Children.Add(dauY); dauOpacty = new DoubleAnimationUsingKeyFrames(); var k3 = new EasingDoubleKeyFrame(1, TimeSpan.FromMilliseconds(AniTime(0))); var k3_0 = new EasingDoubleKeyFrame(1, TimeSpan.FromMilliseconds(AniTime(0.5))); var k3_1 = new EasingDoubleKeyFrame(1, TimeSpan.FromMilliseconds(AniTime(0.55))); var k3_2 = new EasingDoubleKeyFrame(0, TimeSpan.FromMilliseconds(AniTime(1))); dauOpacty.KeyFrames.Add(k3); dauOpacty.KeyFrames.Add(k3_0); dauOpacty.KeyFrames.Add(k3_1); dauOpacty.KeyFrames.Add(k3_2); dauOpacty.FillBehavior = FillBehavior.Stop; Storyboard.SetTarget(dauOpacty, Element); Storyboard.SetTargetProperty(dauOpacty, new PropertyPath(UIElement.OpacityProperty)); Story.Children.Add(dauOpacty); Story.Completed += Story_Completed; }
internal static Transform CloneTransform(Transform transform) { ScaleTransform scaleTransform = null; RotateTransform rotateTransform = null; SkewTransform skewTransform = null; TranslateTransform translateTransform = null; MatrixTransform matrixTransform = null; TransformGroup transformGroup = null; if (transform == null) { return(null); } transform.GetType(); if ((scaleTransform = (transform as ScaleTransform)) != null) { ScaleTransform scaleTransform2 = new ScaleTransform(); scaleTransform2.CenterX = scaleTransform.CenterX; scaleTransform2.CenterY = scaleTransform.CenterY; scaleTransform2.ScaleX = scaleTransform.ScaleX; scaleTransform2.ScaleY = scaleTransform.ScaleY; return(scaleTransform2); } if ((rotateTransform = (transform as RotateTransform)) != null) { RotateTransform rotateTransform2 = new RotateTransform(); rotateTransform2.Angle = rotateTransform.Angle; rotateTransform2.CenterX = rotateTransform.CenterX; rotateTransform2.CenterY = rotateTransform.CenterY; return(rotateTransform2); } if ((skewTransform = (transform as SkewTransform)) != null) { SkewTransform skewTransform2 = new SkewTransform(); skewTransform2.AngleX = skewTransform.AngleX; skewTransform2.AngleY = skewTransform.AngleY; skewTransform2.CenterX = skewTransform.CenterX; skewTransform2.CenterY = skewTransform.CenterY; return(skewTransform2); } if ((translateTransform = (transform as TranslateTransform)) != null) { TranslateTransform translateTransform2 = new TranslateTransform(); translateTransform2.X = translateTransform.X; translateTransform2.Y = translateTransform.Y; return(translateTransform2); } if ((matrixTransform = (transform as MatrixTransform)) != null) { MatrixTransform matrixTransform2 = new MatrixTransform(); matrixTransform2.Matrix = matrixTransform.Matrix; return(matrixTransform2); } if ((transformGroup = (transform as TransformGroup)) != null) { TransformGroup transformGroup2 = new TransformGroup(); { foreach (Transform child in transformGroup.Children) { transformGroup2.Children.Add(CloneTransform(child)); } return(transformGroup2); } } return(null); }
private void RouxBackground_Loaded(object sender, RoutedEventArgs e) { for (int i = 0; i < 15; i++) { // Create a NameScope for the page so that // we can use Storyboards. NameScope.SetNameScope(this, new NameScope()); var rotTransform = new RotateTransform(); var transTransform = new TranslateTransform(); var scaleTransform = new ScaleTransform(); // Register the transforms' names with the page // so that they can be targeted by a Storyboard. string rotateName = "AnimatedRotateTransform" + i; this.RegisterName(rotateName, rotTransform); this.RegisterName("AnimatedTranslateTransform" + i, transTransform); var group = new TransformGroup(); group.Children.Add(rotTransform); group.Children.Add(transTransform); group.Children.Add(scaleTransform); var star = new Star(); string fadeName = "Fade" + i; this.RegisterName(fadeName, star); star.Width = star.Height = ran.Next(20, 160); rotTransform.CenterX = star.Width / 2; rotTransform.CenterY = star.Height / 2; star.Opacity = ran.NextDouble(); star.RenderTransform = group; // Create a Canvas to contain the star // and add it to the page. Canvas mainPanel = new Canvas(); mainPanel.Width = 200; mainPanel.Height = 200; mainPanel.Children.Add(star); uGrid1.Children.Add(mainPanel); // Create the animation path. PathGeometry movePath = new PathGeometry(); PathFigure pFigure = new PathFigure(); pFigure.StartPoint = new Point(ran.Next(minPath, maxPath), ran.Next(minPath, maxPath)); PolyBezierSegment pBezierSegment = new PolyBezierSegment(); pBezierSegment.Points.Add(new Point(ran.Next(minPath, maxPath), ran.Next(minPath, maxPath))); pBezierSegment.Points.Add(new Point(ran.Next(minPath, maxPath), ran.Next(minPath, maxPath))); pBezierSegment.Points.Add(new Point(ran.Next(minPath, maxPath), ran.Next(minPath, maxPath))); pFigure.Segments.Add(pBezierSegment); movePath.Figures.Add(pFigure); // Freeze the PathGeometry for performance benefits. movePath.Freeze(); Path p = new Path(); p.Data = movePath; p.Stroke = new SolidColorBrush(Colors.Red); double length = ran.Next(8, 45); DoubleAnimation da = SetupRotationAnimation(i, rotateName); DoubleAnimation da2 = SetupFadeAnimation(i, length, fadeName); // Create a DoubleAnimationUsingPath to move the // rectangle horizontally along the path by animating // its TranslateTransform. DoubleAnimationUsingPath translateXAnimation = new DoubleAnimationUsingPath(); translateXAnimation.PathGeometry = movePath; translateXAnimation.Duration = TimeSpan.FromSeconds(length); translateXAnimation.Source = PathAnimationSource.X; Storyboard.SetTargetName(translateXAnimation, "AnimatedTranslateTransform" + i); Storyboard.SetTargetProperty(translateXAnimation, new PropertyPath(TranslateTransform.XProperty)); DoubleAnimationUsingPath translateYAnimation = new DoubleAnimationUsingPath(); // translateYAnimation.RepeatBehavior = RepeatBehavior.Forever; translateYAnimation.PathGeometry = movePath; translateYAnimation.Duration = TimeSpan.FromSeconds(length); translateYAnimation.Source = PathAnimationSource.Y; Storyboard.SetTargetName(translateYAnimation, "AnimatedTranslateTransform" + i); Storyboard.SetTargetProperty(translateYAnimation, new PropertyPath(TranslateTransform.YProperty)); // Create a Storyboard to contain and apply the animations. Storyboard spinSB = new Storyboard(); spinSB.Children.Add(da); spinSB.Begin(this); // Create a Storyboard to contain and apply the animations. Storyboard fadeSB = new Storyboard(); fadeSB.Duration = TimeSpan.FromSeconds(length); fadeSB.AutoReverse = true; fadeSB.RepeatBehavior = RepeatBehavior.Forever; fadeSB.Children.Add(da2); fadeSB.Begin(this); Storyboard pathAnimationStoryboard = new Storyboard(); pathAnimationStoryboard.RepeatBehavior = RepeatBehavior.Forever; pathAnimationStoryboard.AutoReverse = true; // pathAnimationStoryboard.Children.Add(da2); pathAnimationStoryboard.Children.Add(translateXAnimation); pathAnimationStoryboard.Children.Add(translateYAnimation); pathAnimationStoryboard.Begin(this); } }
internal void GetTransform(out TranslateTransform tt, out RotateTransform rt, out ScaleTransform st) {//获取Transform tt = ttACP; rt = rtACP; st = stACP; }
public override void Render(WpfDrawingRenderer renderer) { WpfDrawingContext context = renderer.Context; SvgRenderingHint hint = _svgElement.RenderingHint; if (hint != SvgRenderingHint.Shape || hint == SvgRenderingHint.Clipping) { return; } // We do not directly render the contents of the clip-path, unless specifically requested... if (string.Equals(_svgElement.ParentNode.LocalName, "clipPath") && !context.RenderingClipRegion) { return; } SvgStyleableElement styleElm = (SvgStyleableElement)_svgElement; string sVisibility = styleElm.GetPropertyValue("visibility"); string sDisplay = styleElm.GetPropertyValue("display"); if (string.Equals(sVisibility, "hidden") || string.Equals(sDisplay, "none")) { return; } DrawingGroup drawGroup = context.Peek(); Debug.Assert(drawGroup != null); Geometry geometry = CreateGeometry(_svgElement, context.OptimizePath); string elementId = this.GetElementName(); if (geometry != null && !geometry.IsEmpty()) { SetClip(context); WpfSvgPaint fillPaint = new WpfSvgPaint(context, styleElm, "fill"); string fileValue = styleElm.GetAttribute("fill"); Brush brush = fillPaint.GetBrush(geometry); WpfSvgPaint strokePaint = new WpfSvgPaint(context, styleElm, "stroke"); Pen pen = strokePaint.GetPen(geometry); if (brush != null || pen != null) { Transform transform = this.Transform; if (transform != null && !transform.Value.IsIdentity) { geometry.Transform = transform; if (brush != null) { Transform brushTransform = brush.Transform; if (brushTransform == null || brushTransform == Transform.Identity) { brush.Transform = transform; } else { TransformGroup groupTransform = new TransformGroup(); groupTransform.Children.Add(brushTransform); groupTransform.Children.Add(transform); brush.Transform = groupTransform; } } if (pen != null && pen.Brush != null) { Transform brushTransform = pen.Brush.Transform; if (brushTransform == null || brushTransform == Transform.Identity) { pen.Brush.Transform = transform; } else { TransformGroup groupTransform = new TransformGroup(); groupTransform.Children.Add(brushTransform); groupTransform.Children.Add(transform); pen.Brush.Transform = groupTransform; } } } else { transform = null; // render any identity transform useless... } GeometryDrawing drawing = new GeometryDrawing(brush, pen, geometry); if (!string.IsNullOrWhiteSpace(elementId) && !context.IsRegisteredId(elementId)) { drawing.SetValue(FrameworkElement.NameProperty, elementId); context.RegisterId(elementId); if (context.IncludeRuntime) { SvgObject.SetId(drawing, elementId); } } Brush maskBrush = this.Masking; Geometry clipGeom = this.ClipGeometry; if (clipGeom != null || maskBrush != null) { //Geometry clipped = Geometry.Combine(geometry, clipGeom, // GeometryCombineMode.Exclude, null); //if (clipped != null && !clipped.IsEmpty()) //{ // geometry = clipped; //} DrawingGroup clipMaskGroup = new DrawingGroup(); Rect geometryBounds = geometry.Bounds; if (clipGeom != null) { clipMaskGroup.ClipGeometry = clipGeom; SvgUnitType clipUnits = this.ClipUnits; if (clipUnits == SvgUnitType.ObjectBoundingBox) { Rect drawingBounds = geometryBounds; if (transform != null) { drawingBounds = transform.TransformBounds(drawingBounds); } TransformGroup transformGroup = new TransformGroup(); // Scale the clip region (at (0, 0)) and translate to the top-left corner of the target. transformGroup.Children.Add(new ScaleTransform(drawingBounds.Width, drawingBounds.Height)); transformGroup.Children.Add(new TranslateTransform(drawingBounds.X, drawingBounds.Y)); clipGeom.Transform = transformGroup; } else { if (transform != null) { clipGeom.Transform = transform; } } } if (maskBrush != null) { DrawingBrush drawingBrush = (DrawingBrush)maskBrush; SvgUnitType maskUnits = this.MaskUnits; SvgUnitType maskContentUnits = this.MaskContentUnits; if (maskUnits == SvgUnitType.ObjectBoundingBox) { Rect drawingBounds = geometryBounds; if (transform != null) { drawingBounds = transform.TransformBounds(drawingBounds); } DrawingGroup maskGroup = drawingBrush.Drawing as DrawingGroup; if (maskGroup != null) { DrawingCollection maskDrawings = maskGroup.Children; for (int i = 0; i < maskDrawings.Count; i++) { Drawing maskDrawing = maskDrawings[i]; GeometryDrawing maskGeomDraw = maskDrawing as GeometryDrawing; if (maskGeomDraw != null) { if (maskGeomDraw.Brush != null) { ConvertColors(maskGeomDraw.Brush); } if (maskGeomDraw.Pen != null) { ConvertColors(maskGeomDraw.Pen.Brush); } } } } if (maskContentUnits == SvgUnitType.ObjectBoundingBox) { TransformGroup transformGroup = new TransformGroup(); // Scale the clip region (at (0, 0)) and translate to the top-left corner of the target. var scaleTransform = new ScaleTransform(drawingBounds.Width, drawingBounds.Height); transformGroup.Children.Add(scaleTransform); var translateTransform = new TranslateTransform(drawingBounds.X, drawingBounds.Y); transformGroup.Children.Add(translateTransform); Matrix matrix = new Matrix(); matrix.Scale(drawingBounds.Width, drawingBounds.Height); matrix.Translate(drawingBounds.X, drawingBounds.Y); //maskBrush.Transform = transformGroup; maskBrush.Transform = new MatrixTransform(matrix); } else { drawingBrush.Viewbox = drawingBounds; drawingBrush.ViewboxUnits = BrushMappingMode.Absolute; drawingBrush.Stretch = Stretch.Uniform; drawingBrush.Viewport = drawingBounds; drawingBrush.ViewportUnits = BrushMappingMode.Absolute; } } else { if (transform != null) { maskBrush.Transform = transform; } } clipMaskGroup.OpacityMask = maskBrush; } clipMaskGroup.Children.Add(drawing); drawGroup.Children.Add(clipMaskGroup); } else { drawGroup.Children.Add(drawing); } } } RenderMarkers(renderer, styleElm, context); }
private void Button1_Click(object sender, RoutedEventArgs e) { MediaLibrary _mediaLibrary = new MediaLibrary(); using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) { try { //TextBlock newTextBox = new TextBlock(); //newTextBox.FontSize = 30; //newTextBox.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.White); //newTextBox.Text = "ScoreSoccer8"; //newTextBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; //newTextBox.VerticalAlignment = System.Windows.VerticalAlignment.Bottom; //newTextBox.FontWeight = FontWeights.Bold; //newTextBox.Opacity = 0.5; //newTextBox.Margin = new Thickness(10); //AwayPlayerGrid.Children.Add(newTextBox); Grid AwayPlayerGrid = new Grid(); var bitmap = new WriteableBitmap(Convert.ToInt32(2000), Convert.ToInt32(400)); // w / h var transform = new TransformGroup(); var st = new ScaleTransform() { ScaleX = 0.5, ScaleY = 0.5, CenterX = (AwayPlayerGrid.ActualWidth / 2.0), CenterY = (AwayPlayerGrid.ActualHeight / 2.0) }; transform.Children.Add(st); bitmap.Render(AwayPlayerGrid, null); bitmap.Invalidate(); String tempJPEG = "logo.jpg"; IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(tempJPEG); // Encode WriteableBitmap object to a JPEG stream. Extensions.SaveJpeg(bitmap, fileStream, bitmap.PixelWidth, bitmap.PixelHeight, 0, 100); fileStream.Close(); fileStream.Dispose(); IsolatedStorageFileStream stream = myIsolatedStorage.OpenFile(tempJPEG, FileMode.Open, FileAccess.Read); Picture picture = _mediaLibrary.SavePictureToCameraRoll("somefile.jpg", stream); ShareMediaTask task = new ShareMediaTask(); task.FilePath = picture.GetPath(); task.Show(); //BorderToSave.Children.Remove(newTextBox); stream.Close(); stream.Dispose(); } catch (Exception ex) { //Debug.WriteLine(ex.ToString()); } } }
//public virtual void Draw (Bitmap pdc, bool bw =false) { // if ( _Slide == null ) // return ; // //pdc.MakeTransparent () ; // Graphics graphics =Graphics.FromImage (pdc) ; // Pen brush =null ; // Point pt1 =new Point (0, 0), pt2 =new Point (0, 0) ; // long j, i =_Version == 0x01 ? 34 : 31 ; // for ( ; i < _Length ; ) { // //----- Read Field Start // ushort val =Read2Bytes (i, _bLowFirst) ; // switch ( HighByte (val) ) { // case 0xff: //----- Color Change // if ( !bw ) { // if ( (j =LowByte (val)) > acadColor.Count () // || ( ~(acadColor [0].R) == acadColor [j].R // && ~(acadColor [0].G) == acadColor [j].G // && ~(acadColor [0].B) == acadColor [j].B) // ) // j =0 ; // brush =new Pen (acadColor [j], 1) ; // } else { // //SolidColorBrush bck =(SolidColorBrush)pdc.Background ; // //brush =new SolidColorBrush (Color.FromRgb ((byte)(bck.Color.R ^ 0xff), (byte)(bck.Color.G ^ 0xff), (byte)(bck.Color.B ^ 0xff))) ; // } // i +=2 ; // break ; // case 0xfe: //----- Common Endpoint Vector // pt2 =pt1 ; // pt1.X +=(sbyte)LowByte (val) ; // pt1.Y +=(sbyte)_Slide [i + 2] ; // i +=3 ; // //----- Draw // graphics.DrawLine (brush, pt1, pt2) ; // break ; // case 0xfd: //----- Solid Fill // j =Read2Bytes (i + 2, _bLowFirst) ; // i +=6 ; // if ( j == 0 ) // break ; // Point [] pts =new Point [j] ; // for ( long k =0 ; k < j ; k++, i +=6 ) // pts [k] =new Point (ReadPoint (i + 2, _bLowFirst), ReadPoint (i + 4, _bLowFirst)) ; // //----- Draw // graphics.DrawPolygon (brush, pts) ; // break ; // case 0xfc: //----- End of File // i +=2 ; // return ; // case 0xfb: //----- Offset Vector // pt2 =pt1 ; // pt1.X +=(sbyte)LowByte (val) ; // pt1.Y +=(sbyte)(_Slide [i + 2]) ; // pt2.X +=(sbyte)(_Slide [i + 3]) ; // pt2.Y +=(sbyte)(_Slide [i + 4]) ; // i +=5 ; // //----- Draw // graphics.DrawLine (brush, pt1, pt2) ; // break ; // default: // if ( HighByte (val) > 0x7f ) //----- Undefined // return ; // //----- Vector // pt1.X =val ; // pt1.Y =ReadPoint (i + 2, _bLowFirst) ; // pt2.X =ReadPoint (i + 4, _bLowFirst) ; // pt2.Y =ReadPoint (i + 6, _bLowFirst) ; // i +=8 ; // //----- Draw // graphics.DrawLine (brush, pt1, pt2) ; // break ; // } // } //} #endregion #region Image Convertion /// <summary>Exports Slide to an image using a Canvas definition.</summary> /// <param name="surface">Canvas to draw into.</param> public BitmapImage Export(Canvas surface) { // Save current canvas transform Transform lyTransform = surface.LayoutTransform; // Reset current transform (in case it is scaled or rotated) surface.LayoutTransform = null; // Get the size of canvas Size size = new Size(surface.Width, surface.Height); // Measure and arrange the surface surface.Measure(size); surface.Arrange(new Rect(size)); // Create a render bitmap and push the surface to it RenderTargetBitmap renderBitmap = new RenderTargetBitmap( (int)size.Width, (int)size.Height, 96d, 96d, PixelFormats.Pbgra32); renderBitmap.Render(surface); // Restore previously saved layout surface.LayoutTransform = lyTransform; // Use png encoder for our data PngBitmapEncoder encoder = new PngBitmapEncoder(); //// Push the rendered bitmap to it //encoder.Frames.Add (BitmapFrame.Create (renderBitmap)) ; //BitmapImage bitmapImage =new BitmapImage () ; //using ( var stream = new MemoryStream () ) { // encoder.Save (stream) ; // stream.Seek (0, SeekOrigin.Begin) ; // bitmapImage.BeginInit () ; // bitmapImage.CacheOption =BitmapCacheOption.OnLoad ; // bitmapImage.StreamSource =stream ; // bitmapImage.EndInit () ; //} var tb = new TransformedBitmap(); tb.BeginInit(); tb.Source = renderBitmap; var transform = new ScaleTransform(1, -1, 0, 0); tb.Transform = transform; tb.EndInit(); BitmapImage bitmapImage = new BitmapImage(); encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(tb)); MemoryStream memoryStream = new MemoryStream(); encoder.Save(memoryStream); bitmapImage.BeginInit(); bitmapImage.StreamSource = new MemoryStream(memoryStream.ToArray()); bitmapImage.EndInit(); memoryStream.Close(); return(bitmapImage); }
private static void AddPointToCanvas(double ellipseNormalSize, Canvas canvas, ScaleTransform trans, PointsListItem point) { var el = new Ellipse() { Width = ellipseNormalSize, Height = ellipseNormalSize, //MinWidth = point.Diameter.Value, //MaxWidth = point.Diameter.Value, Fill = Brushes.Gold, Stroke = Brushes.Gray, Tag = "point", RenderTransform = trans, RenderTransformOrigin = new Point(0.5, 0.5), DataContext = point, }; Panel.SetZIndex(el, counterLevel); canvas.Children.Add(el); Canvas.SetLeft(el, point.Coord.X - el.Width / 2); Canvas.SetTop(el, point.Coord.Y - el.Height / 2); }
private static void AddSectionsToCanvas(double ellipseNormalSize, Canvas canvas, ScaleTransform trans, SectionListItem section) { var el = new Ellipse() { Width = ellipseNormalSize, Height = ellipseNormalSize, Fill = Brushes.Red, Stroke = Brushes.Gray, Tag = "section", RenderTransform = trans, RenderTransformOrigin = new Point(0.5, 0.5), DataContext = section, }; Panel.SetZIndex(el, counterLevel); canvas.Children.Add(el); Canvas.SetLeft(el, section.FromCoord.X - el.Width / 2); Canvas.SetTop(el, section.FromCoord.Y - el.Height / 2); //--------------------------------------------------------------- el = new Ellipse() { Width = ellipseNormalSize, Height = ellipseNormalSize, Fill = Brushes.Green, Stroke = Brushes.Gray, Tag = "section", RenderTransform = trans, RenderTransformOrigin = new Point(0.5, 0.5), DataContext = section, }; Panel.SetZIndex(el, counterLevel); canvas.Children.Add(el); Canvas.SetLeft(el, section.ToCoord.X - el.Width / 2); Canvas.SetTop(el, section.ToCoord.Y - el.Height / 2); }
private static Texture2D LoadBitmapAndMip(Stream stream) { var bs = new BitmapImage(); bs.SetSource(stream); // Get dimensions int w = bs.PixelWidth; int h = bs.PixelHeight; if ((w % 2 != 0 && w != 1) || (h % 2 != 0 && h != 1)) throw new InvalidOperationException("Bitmap must be power of 2."); // Calculate mip levels int mipLevels = 1; int maxDimension = Math.Max(w, h); while (maxDimension > 1) { mipLevels++; maxDimension /= 2; } // Create the chain Texture2D tex = new Texture2D(GraphicsDeviceManager.Current.GraphicsDevice, w, h, true, SurfaceFormat.Color); // Put bitmap into a renderable image Image image = new Image(); image.Source = bs; // Generate mip level data for (int level = 0; level < mipLevels; level++) { var wb = new WriteableBitmap(w, h); // Scale to current mip level ScaleTransform t = new ScaleTransform(); t.ScaleX = (double)w / (double)bs.PixelWidth; t.ScaleY = (double)h / (double)bs.PixelHeight; // Black out the image for (int c = 0; c < w * h; c++) wb.Pixels[c] = 0; // Small mip levels are rendering as white, so don't render if (w > 1 && h > 1) wb.Render(image, t); // Update WB wb.Invalidate(); // Grab pixel data wb.CopyTo(tex, level, null, 0, 0); // Shrink for the next level if (w != 1) w /= 2; if (h != 1) h /= 2; } return tex; }
private void RenderPath(WpfDrawingRenderer renderer) { WpfDrawingContext context = renderer.Context; SvgRenderingHint hint = _svgElement.RenderingHint; if (hint != SvgRenderingHint.Shape || hint == SvgRenderingHint.Clipping) { return; } var parentNode = _svgElement.ParentNode; // We do not directly render the contents of the clip-path, unless specifically requested... if (string.Equals(parentNode.LocalName, "clipPath") && !context.RenderingClipRegion) { return; } SvgStyleableElement styleElm = (SvgStyleableElement)_svgElement; //string sVisibility = styleElm.GetPropertyValue("visibility"); //string sDisplay = styleElm.GetPropertyValue("display"); //if (string.Equals(sVisibility, "hidden") || string.Equals(sDisplay, "none")) //{ // return; //} DrawingGroup drawGroup = context.Peek(); Debug.Assert(drawGroup != null); Geometry geometry = CreateGeometry(_svgElement, context.OptimizePath); string elementId = this.GetElementName(); string elementClass = this.GetElementClass(); if (geometry != null && !geometry.IsEmpty()) { context.UpdateBounds(geometry.Bounds); // SetClip(context); WpfSvgPaint fillPaint = new WpfSvgPaint(context, styleElm, "fill"); string fileValue = styleElm.GetAttribute("fill"); Brush brush = fillPaint.GetBrush(geometry, _setBrushOpacity); bool isFillTransmable = fillPaint.IsFillTransformable; WpfSvgPaint strokePaint = new WpfSvgPaint(context, styleElm, "stroke"); Pen pen = strokePaint.GetPen(geometry, _setBrushOpacity); // By the SVG Specifications: // Keyword 'objectBoundingBox' should not be used when the geometry of the applicable // element has no width or no height, such as the case of a horizontal or vertical line, // even when the line has actual thickness when viewed due to having a non-zero stroke // width since stroke width is ignored for bounding box calculations. When the geometry // of the applicable element has no width or height and 'objectBoundingBox' is specified, // then the given effect (e.g., a gradient) will be ignored. if (pen != null && _isLineSegment && strokePaint.FillType == WpfFillType.Gradient) { LineGeometry lineGeometry = geometry as LineGeometry; WpfGradientFill gradientFill = (WpfGradientFill)strokePaint.PaintServer; if (gradientFill.IsUserSpace == false && lineGeometry != null) { bool invalidGrad = SvgObject.IsEqual(lineGeometry.EndPoint.X, lineGeometry.StartPoint.X) || SvgObject.IsEqual(lineGeometry.EndPoint.Y, lineGeometry.StartPoint.Y); if (invalidGrad) { // Brush is not likely inherited, we need to support fallback too WpfSvgPaint fallbackPaint = strokePaint.WpfFallback; if (fallbackPaint != null) { pen.Brush = fallbackPaint.GetBrush(geometry, _setBrushOpacity); } else { var scopePaint = strokePaint.GetScopeStroke(); if (scopePaint != null) { if (scopePaint != strokePaint) { pen.Brush = scopePaint.GetBrush(geometry, _setBrushOpacity); } else { pen.Brush = null; } } else { pen.Brush = null; } } } } } if (_paintContext != null) { _paintContext.Fill = fillPaint; _paintContext.Stroke = strokePaint; _paintContext.Tag = geometry; } if (brush != null || pen != null) { Transform transform = this.Transform; if (transform != null && !transform.Value.IsIdentity) { geometry.Transform = transform; if (brush != null && isFillTransmable) { Transform brushTransform = brush.Transform; if (brushTransform == null || brushTransform == Transform.Identity) { brush.Transform = transform; } else { TransformGroup groupTransform = new TransformGroup(); groupTransform.Children.Add(brushTransform); groupTransform.Children.Add(transform); brush.Transform = groupTransform; } } if (pen != null && pen.Brush != null) { Transform brushTransform = pen.Brush.Transform; if (brushTransform == null || brushTransform == Transform.Identity) { pen.Brush.Transform = transform; } else { TransformGroup groupTransform = new TransformGroup(); groupTransform.Children.Add(brushTransform); groupTransform.Children.Add(transform); pen.Brush.Transform = groupTransform; } } } else { transform = null; // render any identity transform useless... } GeometryDrawing drawing = new GeometryDrawing(brush, pen, geometry); if (!string.IsNullOrWhiteSpace(elementId) && !context.IsRegisteredId(elementId)) { SvgObject.SetName(drawing, elementId); context.RegisterId(elementId); if (context.IncludeRuntime) { SvgObject.SetId(drawing, elementId); } } if (!string.IsNullOrWhiteSpace(elementClass) && context.IncludeRuntime) { SvgObject.SetClass(drawing, elementClass); } Brush maskBrush = this.Masking; Geometry clipGeom = this.ClipGeometry; if (clipGeom != null || maskBrush != null) { //Geometry clipped = Geometry.Combine(geometry, clipGeom, // GeometryCombineMode.Exclude, null); //if (clipped != null && !clipped.IsEmpty()) //{ // geometry = clipped; //} DrawingGroup clipMaskGroup = new DrawingGroup(); Rect geometryBounds = geometry.Bounds; if (clipGeom != null) { clipMaskGroup.ClipGeometry = clipGeom; SvgUnitType clipUnits = this.ClipUnits; if (clipUnits == SvgUnitType.ObjectBoundingBox) { Rect drawingBounds = geometryBounds; if (transform != null) { drawingBounds = transform.TransformBounds(drawingBounds); } TransformGroup transformGroup = new TransformGroup(); // Scale the clip region (at (0, 0)) and translate to the top-left corner of the target. transformGroup.Children.Add(new ScaleTransform(drawingBounds.Width, drawingBounds.Height)); transformGroup.Children.Add(new TranslateTransform(drawingBounds.X, drawingBounds.Y)); clipGeom.Transform = transformGroup; } else { if (transform != null) { clipGeom.Transform = transform; } } } if (maskBrush != null) { DrawingBrush drawingBrush = (DrawingBrush)maskBrush; SvgUnitType maskUnits = this.MaskUnits; SvgUnitType maskContentUnits = this.MaskContentUnits; if (maskUnits == SvgUnitType.ObjectBoundingBox) { Rect drawingBounds = geometryBounds; if (transform != null) { drawingBounds = transform.TransformBounds(drawingBounds); } DrawingGroup maskGroup = drawingBrush.Drawing as DrawingGroup; if (maskGroup != null) { DrawingCollection maskDrawings = maskGroup.Children; for (int i = 0; i < maskDrawings.Count; i++) { Drawing maskDrawing = maskDrawings[i]; GeometryDrawing maskGeomDraw = maskDrawing as GeometryDrawing; if (maskGeomDraw != null) { if (maskGeomDraw.Brush != null) { ConvertColors(maskGeomDraw.Brush); } if (maskGeomDraw.Pen != null) { ConvertColors(maskGeomDraw.Pen.Brush); } } } } if (maskContentUnits == SvgUnitType.ObjectBoundingBox) { TransformGroup transformGroup = new TransformGroup(); // Scale the clip region (at (0, 0)) and translate to the top-left corner of the target. var scaleTransform = new ScaleTransform(drawingBounds.Width, drawingBounds.Height); transformGroup.Children.Add(scaleTransform); var translateTransform = new TranslateTransform(drawingBounds.X, drawingBounds.Y); transformGroup.Children.Add(translateTransform); Matrix scaleMatrix = new Matrix(); Matrix translateMatrix = new Matrix(); scaleMatrix.Scale(drawingBounds.Width, drawingBounds.Height); translateMatrix.Translate(drawingBounds.X, drawingBounds.Y); Matrix matrix = Matrix.Multiply(scaleMatrix, translateMatrix); //maskBrush.Transform = transformGroup; maskBrush.Transform = new MatrixTransform(matrix); } else { drawingBrush.Viewbox = drawingBounds; drawingBrush.ViewboxUnits = BrushMappingMode.Absolute; drawingBrush.Stretch = Stretch.Uniform; drawingBrush.Viewport = drawingBounds; drawingBrush.ViewportUnits = BrushMappingMode.Absolute; } } else { if (transform != null) { maskBrush.Transform = transform; } } clipMaskGroup.OpacityMask = maskBrush; } clipMaskGroup.Children.Add(drawing); drawGroup.Children.Add(clipMaskGroup); } else { drawGroup.Children.Add(drawing); } } } // If this is not the child of a "marker", then try rendering a marker... if (!string.Equals(parentNode.LocalName, "marker")) { RenderMarkers(renderer, styleElm, context); } }
public void ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e) { var point = new Point(Convert.ToInt32(e.Position.X), Convert.ToInt32(e.Position.Y)); // TODO some bubbling? issue here, fast multiple applicationbartop undos result in triggering this event if (point.X < 0 || point.Y < 0 || Spinner.SpinnerActive || e.Handled) { return; } object movezoom = null; RotateTransform rotate = new RotateTransform(); Point rotateCenterPoint = new Point(); if (PocketPaintApplication.GetInstance().ToolCurrent.GetToolType() == ToolType.Rect) { // TODO: @Karl: implement rotation for the rectangle tool //rotateCenterPoint.X = PocketPaintApplication.GetInstance().RectangleSelectionControl.MainGrid.Width / 2.0; //rotateCenterPoint.Y = PocketPaintApplication.GetInstance().RectangleSelectionControl.MainGrid.Height / 2.0; //rotate.CenterX = rotateCenterPoint.X; //rotate.CenterY = rotateCenterPoint.Y; //Point centerPoint = PocketPaintApplication.GetInstance().RectangleSelectionControl.getCenterCoordinateOfGridMain(); //if (!(lastPoint.X == 0.0 && lastPoint.Y == 0.0) && // (lastPoint.X != point.X || lastPoint.Y != point.Y)) //{ // double currentXLength = point.X - centerPoint.X; // double currentYLength = point.Y - centerPoint.Y; // double normalCurrentX = currentXLength / (Math.Sqrt(currentXLength * currentXLength + currentYLength * currentYLength)); // double normalCurrentY = currentYLength / (Math.Sqrt(currentXLength * currentXLength + currentYLength * currentYLength)); // double previousXLength = lastPoint.X - centerPoint.X; // double previousYLength = lastPoint.Y - centerPoint.Y; // double normalPreviousX = previousXLength / (Math.Sqrt(previousXLength * previousXLength + previousYLength * previousYLength)); // double normalPreviousY = previousYLength / (Math.Sqrt(previousXLength * previousXLength + previousYLength * previousYLength)); // double deltaAngle = (Math.Atan(normalPreviousX / normalPreviousY) - Math.Atan(normalCurrentX / normalCurrentY)); // double rotationAngle = deltaAngle * 360.0 / Math.PI; // rotate.Angle = rotationAngle; //} lastPoint = point; } else if (PocketPaintApplication.GetInstance().ToolCurrent.GetToolType() == ToolType.Ellipse) { // TODO: @Karl: implement rotation for the ellipse tool //rotateCenterPoint.X = PocketPaintApplication.GetInstance().EllipseSelectionControl.gridMain.Width / 2.0; //rotateCenterPoint.Y = PocketPaintApplication.GetInstance().EllipseSelectionControl.gridMain.Height / 2.0; //rotate.CenterX = rotateCenterPoint.X; //rotate.CenterY = rotateCenterPoint.Y; //Point centerPoint = PocketPaintApplication.GetInstance().EllipseSelectionControl.getCenterCoordinateOfGridMain(); //if (!(lastPoint.X == 0.0 && lastPoint.Y == 0.0) && // (lastPoint.X != point.X || lastPoint.Y != point.Y)) //{ // double currentXLength = point.X - centerPoint.X; // double currentYLength = point.Y - centerPoint.Y; // double normalCurrentX = currentXLength / (Math.Sqrt(currentXLength * currentXLength + currentYLength * currentYLength)); // double normalCurrentY = currentYLength / (Math.Sqrt(currentXLength * currentXLength + currentYLength * currentYLength)); // double previousXLength = lastPoint.X - centerPoint.X; // double previousYLength = lastPoint.Y - centerPoint.Y; // double normalPreviousX = previousXLength / (Math.Sqrt(previousXLength * previousXLength + previousYLength * previousYLength)); // double normalPreviousY = previousYLength / (Math.Sqrt(previousXLength * previousXLength + previousYLength * previousYLength)); // double deltaAngle = (Math.Atan(normalPreviousX / normalPreviousY) - Math.Atan(normalCurrentX / normalCurrentY)); // double rotationAngle = deltaAngle * 180.0 / Math.PI; // rotate.Angle = rotationAngle; //} //lastPoint = point; } else if (PocketPaintApplication.GetInstance().ToolCurrent.GetToolType() == ToolType.ImportPng) { // TODO: @Karl: implement rotation for the import picture tool //rotateCenterPoint.X = PocketPaintApplication.GetInstance().RectangleSelectionControl.gridMain.Width / 2.0; //rotateCenterPoint.Y = PocketPaintApplication.GetInstance().RectangleSelectionControl.gridMain.Height / 2.0; //rotate.CenterX = rotateCenterPoint.X; //rotate.CenterY = rotateCenterPoint.Y; //Point centerPoint = PocketPaintApplication.GetInstance().ImportImageSelectionControl.getCenterPointOfSelectionControl(); //if (!(lastPoint.X == 0.0 && lastPoint.Y == 0.0) && // (lastPoint.X != point.X || lastPoint.Y != point.Y)) //{ // double currentXLength = point.X - centerPoint.X; // double currentYLength = point.Y - centerPoint.Y; // double normalCurrentX = currentXLength / (Math.Sqrt(currentXLength * currentXLength + currentYLength * currentYLength)); // double normalCurrentY = currentYLength / (Math.Sqrt(currentXLength * currentXLength + currentYLength * currentYLength)); // double previousXLength = lastPoint.X - centerPoint.X; // double previousYLength = lastPoint.Y - centerPoint.Y; // double normalPreviousX = previousXLength / (Math.Sqrt(previousXLength * previousXLength + previousYLength * previousYLength)); // double normalPreviousY = previousYLength / (Math.Sqrt(previousXLength * previousXLength + previousYLength * previousYLength)); // double deltaAngle = (Math.Atan(normalPreviousX / normalPreviousY) - Math.Atan(normalCurrentX / normalCurrentY)); // double rotationAngle = deltaAngle * 360.0 / Math.PI; // rotate.Angle = rotationAngle; //} //lastPoint = point; } // TODO: @Karl: implement rotation for the stamp tool else { if (e.Delta.Scale != 1.0) { movezoom = new ScaleTransform(); if (e.Delta.Scale > 0) { System.Diagnostics.Debug.WriteLine("Scale " + e.Delta.Scale); ((ScaleTransform)movezoom).ScaleX *= e.Delta.Scale; ((ScaleTransform)movezoom).ScaleY *= e.Delta.Scale; } } else { movezoom = new TranslateTransform(); ((TranslateTransform)movezoom).X += e.Delta.Translation.X; ((TranslateTransform)movezoom).Y += e.Delta.Translation.Y; } } switch (PocketPaintApplication.GetInstance().ToolCurrent.GetToolType()) { case ToolType.Brush: PocketPaintApplication.GetInstance().ToolCurrent.HandleMove(point); break; case ToolType.Cursor: PocketPaintApplication.GetInstance().ToolCurrent.HandleMove(movezoom); PocketPaintApplication.GetInstance().ToolCurrent.HandleMove(point); break; case ToolType.Ellipse: if (rotate.Angle != 0.0) { PocketPaintApplication.GetInstance().ToolCurrent.HandleMove(rotate); } break; case ToolType.Eraser: PocketPaintApplication.GetInstance().ToolCurrent.HandleMove(point); break; case ToolType.ImportPng: if (rotate.Angle != 0.0) { PocketPaintApplication.GetInstance().ToolCurrent.HandleMove(rotate); } break; case ToolType.Line: PocketPaintApplication.GetInstance().ToolCurrent.HandleMove(point); break; case ToolType.Move: PocketPaintApplication.GetInstance().ToolCurrent.HandleMove(movezoom); break; case ToolType.Rect: if (rotate.Angle != 0.0) { PocketPaintApplication.GetInstance().ToolCurrent.HandleMove(rotate); } break; case ToolType.Zoom: PocketPaintApplication.GetInstance().ToolCurrent.HandleMove(movezoom); break; } }
private void OnValueChanged(double oldValue, double value) { if (!IsLoaded) { return; } // resetting if (double.IsNaN(value)) { if (_flash != null) { _flash.Stop(); } _root.Background = new SolidColorBrush(Colors.Transparent); _arrow.Fill = null; _txtChange.Foreground = _txtValue.Foreground; return; } // get historical data var data = Tag as FinancialData; var list = BindingSource != null?data.GetHistory(BindingSource) : new System.Collections.Generic.List <decimal>(); if (list != null && list.Count > 1) { oldValue = (double)list[list.Count - 2]; } // calculate percentage change var change = oldValue == 0 || double.IsNaN(oldValue) ? 0 : (value - oldValue) / oldValue; // update text _txtValue.Text = value.ToString(_format); _txtChange.Text = string.Format("({0:0.0}%)", change * 100); // update flash color ColorAnimation ca; // update symbol if (change == 0) { _arrow.Fill = null; _txtChange.Foreground = _txtValue.Foreground; } else if (change < 0) { var tr = new ScaleTransform(1, -1, 0, 4); _arrow.RenderTransform = tr; _txtChange.Foreground = _arrow.Fill = _brNegative; ca = Flash.Children[0] as ColorAnimation; ca.From = _clrNegative; } else { var tr = new ScaleTransform(1, 1, 0, 4); _arrow.RenderTransform = tr; _txtChange.Foreground = _arrow.Fill = _brPositive; ca = Flash.Children[0] as ColorAnimation; ca.From = _clrPositive; } // update sparkline if (list != null) { var points = _sparkLine.Points; points.Clear(); for (int x = 0; x < list.Count; x++) { points.Add(new Point(x, (double)list[x])); } } // flash new value (but not right after the control was created) if (!_firstTime && change != 0) { _flash.Begin(); } _firstTime = false; }
public override MyAnimateBase Animate() { IsAnimateCompleted = false; Element.RenderTransformOrigin = new Point(0.5, 0.5); Element.Visibility = Visibility.Visible; ScaleTransform translation = new ScaleTransform(1, 1); TranslateTransform translationTranslate = new TranslateTransform(0, 0); string translationName = ""; string translationTranslateName = ""; Storyboard story = new Storyboard(); DoubleAnimationUsingKeyFrames dauX = new DoubleAnimationUsingKeyFrames(); DoubleAnimationUsingKeyFrames dauY = new DoubleAnimationUsingKeyFrames(); #region 基本工作,确定类型和name //是否存在TranslateTransform //动画要的类型是否存在 //动画要的类型的name是否存在,不存在就注册,结束后取消注册,删除动画 var ex = Element.RenderTransform; if (ex == null || (ex as System.Windows.Media.MatrixTransform) != null) { var tg = new TransformGroup(); translation = new ScaleTransform(1, 1); translationName = "ayTranslation" + translation.GetHashCode(); Win.RegisterName(translationName, translation); tg.Children.Add(translation); translationTranslateName = "ayTranslation" + translationTranslate.GetHashCode(); Win.RegisterName(translationTranslateName, translationTranslate); tg.Children.Add(translationTranslate); Element.RenderTransform = tg; } else { var tg = ex as TransformGroup; foreach (var item in tg.Children) { translation = item as ScaleTransform; if (translation != null) { break; } } foreach (var item in tg.Children) { translationTranslate = item as TranslateTransform; if (translationTranslate != null) { break; } } if (translation != null) { var tex = translation.GetValue(FrameworkElement.NameProperty); if (tex != null && tex.ToString() != "") { translationName = tex.ToString(); } else { translationName = "ayTranslation" + translation.GetHashCode(); Win.RegisterName(translationName, translation); } } else { translation = new ScaleTransform(1, 1); translationName = "ayTranslation" + translation.GetHashCode(); Win.RegisterName(translationName, translation); tg.Children.Add(translation); Element.RenderTransform = tg; } if (translationTranslate != null) { var tex = translationTranslate.GetValue(FrameworkElement.NameProperty); if (tex != null && tex.ToString() != "") { translationTranslateName = tex.ToString(); } else { translationTranslateName = "ayTranslation" + translationTranslate.GetHashCode(); Win.RegisterName(translationTranslateName, translationTranslate); } } else { translationTranslate = new TranslateTransform(0, 0); translationTranslateName = "ayTranslation" + translationTranslate.GetHashCode(); Win.RegisterName(translationTranslateName, translationTranslate); tg.Children.Add(translationTranslate); Element.RenderTransform = tg; } } #endregion var storyboardName = "aystory" + story.GetHashCode(); Win.Resources.Add(storyboardName, story); double danqianX = translation.ScaleX; double danqianY = translation.ScaleY; var keyspline = new KeySpline(0.55, 0.055, 0.675, 0.19); var keyspline2 = new KeySpline(0.175, 0.885, 0.320, 1); var k3_0 = new SplineDoubleKeyFrame(); k3_0.KeySpline = keyspline; k3_0.Value = 0.1; k3_0.KeyTime = TimeSpan.FromMilliseconds(0); var k3_1 = new SplineDoubleKeyFrame(); k3_1.KeySpline = keyspline2; k3_1.Value = 0.475; k3_1.KeyTime = TimeSpan.FromMilliseconds(AniTime(0.6)); var k3_2 = new EasingDoubleKeyFrame(1, TimeSpan.FromMilliseconds(AniTime(1))); Storyboard.SetTargetName(dauX, translationName); Storyboard.SetTargetProperty(dauX, new PropertyPath(ScaleTransform.ScaleXProperty)); dauX.KeyFrames.Add(k3_0); dauX.KeyFrames.Add(k3_1); dauX.KeyFrames.Add(k3_2); story.Children.Add(dauX); var k4_0 = new SplineDoubleKeyFrame(); k4_0.KeySpline = keyspline; k4_0.Value = 0.1; k4_0.KeyTime = TimeSpan.FromMilliseconds(0); var k4_1 = new SplineDoubleKeyFrame(); k4_1.KeySpline = keyspline2; k4_1.Value = 0.475; k4_1.KeyTime = TimeSpan.FromMilliseconds(AniTime(0.6)); var k4_2 = new EasingDoubleKeyFrame(1, TimeSpan.FromMilliseconds(AniTime(1))); Storyboard.SetTargetName(dauY, translationName); Storyboard.SetTargetProperty(dauY, new PropertyPath(ScaleTransform.ScaleYProperty)); dauY.KeyFrames.Add(k4_0); dauY.KeyFrames.Add(k4_1); dauY.KeyFrames.Add(k4_2); story.Children.Add(dauY); DoubleAnimationUsingKeyFrames dauTranslateY = new DoubleAnimationUsingKeyFrames(); var k5_0 = new SplineDoubleKeyFrame(); k5_0.KeySpline = keyspline; k5_0.Value = 1000; k5_0.KeyTime = TimeSpan.FromMilliseconds(0); var k5_1 = new SplineDoubleKeyFrame(); k5_1.KeySpline = keyspline2; k5_1.Value = -10; k5_1.KeyTime = TimeSpan.FromMilliseconds(AniTime(0.6)); var k5_2 = new EasingDoubleKeyFrame(0, TimeSpan.FromMilliseconds(AniTime(1))); Storyboard.SetTargetName(dauTranslateY, translationTranslateName); Storyboard.SetTargetProperty(dauTranslateY, new PropertyPath(TranslateTransform.XProperty)); dauTranslateY.KeyFrames.Add(k5_0); dauTranslateY.KeyFrames.Add(k5_1); dauTranslateY.KeyFrames.Add(k5_2); story.Children.Add(dauTranslateY); DoubleAnimationUsingKeyFrames dauOpacty = new DoubleAnimationUsingKeyFrames(); var k6 = new EasingDoubleKeyFrame(0, TimeSpan.FromMilliseconds(AniTime(0))); var k6_1 = new EasingDoubleKeyFrame(1, TimeSpan.FromMilliseconds(AniTime(0.6))); dauOpacty.KeyFrames.Add(k6); dauOpacty.KeyFrames.Add(k6_1); Storyboard.SetTarget(dauOpacty, Element); dauOpacty.FillBehavior = FillBehavior.Stop; Storyboard.SetTargetProperty(dauOpacty, new PropertyPath(UIElement.OpacityProperty)); story.Children.Add(dauOpacty); story.Completed += (sndr, evtArgs) => { try { Element.Opacity = 1; Win.Resources.Remove(storyboardName); Win.UnregisterName(translationName); dauX.KeyFrames.Clear(); dauX = null; dauY.KeyFrames.Clear(); dauY = null; story = null; base.CallClientCompleted(); } catch { } }; story.Begin(); return(this); }
private void UpdaterForBat(object sender, EventArgs e) { var mousePosX = Mouse.GetPosition(MyCanvas).X; var mousePosY = Mouse.GetPosition(MyCanvas).Y - 80; var batPosX = turns.Peek().CanvasXPos + 15; var batPosY = turns.Peek().CanvasYPos - 30; #region Angulo de ataque var controller = ImageBehavior.GetAnimationController(turns.Peek().icon); var angle = Math.Atan((mousePosY - batPosY) / (mousePosX - batPosX)) + (Math.PI / 2); // va de 0 a Pi var frame = 0.0; if (mousePosX < batPosX) { frame = (angle * 31) / (Math.PI); ScaleTransform scale = new ScaleTransform(); scale.ScaleX = 1; scale.CenterX = 45; TransformGroup myTransformGroup = new TransformGroup(); myTransformGroup.Children.Add(scale); turns.Peek().icon.RenderTransform = myTransformGroup; try { controller.GotoFrame((int)frame); } catch { } } else { ScaleTransform scale = new ScaleTransform(); scale.ScaleX = -1; scale.CenterX = 45; TransformGroup myTransformGroup = new TransformGroup(); myTransformGroup.Children.Add(scale); turns.Peek().icon.RenderTransform = myTransformGroup; frame = -1 * (((angle * 31) / (Math.PI)) - 14) + 17; controller.GotoFrame((int)frame); } #endregion #region Barra de Potencia var speedx = mousePosX - batPosX; var speedy = mousePosY - batPosY; var speed = Math.Sqrt(Math.Pow(speedx, 2) + Math.Pow(speedy, 2)); var barraPotencia = (160.0 / speed) * 950; //lb.Content = barraPotencia; if (barraPotencia >= 33) { potencia.Margin = new Thickness(33, 600, barraPotencia, 10); } #endregion #region Batear if (Mouse.LeftButton == MouseButtonState.Pressed) { potencia.Visibility = System.Windows.Visibility.Hidden; potencia2.Visibility = System.Windows.Visibility.Hidden; //Dañar worms cercanos foreach (UserControlWorms w in worms) { if (w == turns.Peek()) { continue; } if (Math.Sqrt(Math.Pow(w.CanvasXPos - batPosX, 2) + Math.Pow(w.CanvasYPos - batPosY, 2)) < 60) { w.worm.hp -= 20; var xspeed = (mousePosX - batPosX) * 10; var yspeed = (mousePosY - batPosY) * 10; var maxspeed = 6000; if (Math.Sqrt(Math.Pow(xspeed, 2) + Math.Pow(yspeed, 2)) > maxspeed) { xspeed = (xspeed / Math.Sqrt(Math.Pow(xspeed, 2) + Math.Pow(yspeed, 2))) * maxspeed; yspeed = (yspeed / Math.Sqrt(Math.Pow(xspeed, 2) + Math.Pow(yspeed, 2))) * maxspeed; } w.xspeed = xspeed; w.yspeed = yspeed; } } BatControl.Stop(); ChangeOfShift(); } #endregion }
/// <summary> /// Removes any property modifications, applied to the specified element by this instance. /// </summary> /// <param name="target">The element which property values are to be cleared.</param> /// <remarks> /// It is assumed that the element has been previously animated by this animation. /// </remarks> public override void ClearAnimation(UIElement target) { ScaleTransform transform = target.GetScaleTransform(); transform.ClearValue(ScaleTransform.ScaleYProperty); }
private void UpdaterForBazooka(object sender, EventArgs e) { var mousePosX = Mouse.GetPosition(MyCanvas).X; var mousePosY = Mouse.GetPosition(MyCanvas).Y - 80; var bazookaPosX = turns.Peek().CanvasXPos + 15; var bazookaPosY = turns.Peek().CanvasYPos - 30; // Angulo de ataque var controller = ImageBehavior.GetAnimationController(turns.Peek().icon); var angle = Math.Atan((mousePosY - bazookaPosY) / (mousePosX - bazookaPosX)) + (Math.PI / 2); // va de 0 a Pi var frame = 0.0; if (mousePosX < bazookaPosX) { frame = (angle * 31) / (Math.PI); ScaleTransform scale = new ScaleTransform(); scale.ScaleX = 1; scale.CenterX = 45; TransformGroup myTransformGroup = new TransformGroup(); myTransformGroup.Children.Add(scale); turns.Peek().icon.RenderTransform = myTransformGroup; controller.GotoFrame((int)frame); } else { ScaleTransform scale = new ScaleTransform(); scale.ScaleX = -1; scale.CenterX = 45; TransformGroup myTransformGroup = new TransformGroup(); myTransformGroup.Children.Add(scale); turns.Peek().icon.RenderTransform = myTransformGroup; frame = -1 * (((angle * 31) / (Math.PI)) - 14) + 17; controller.GotoFrame((int)frame); } //Barra de potencia var speedx = mousePosX - bazookaPosX; var speedy = mousePosY - bazookaPosY; var speed = Math.Sqrt(Math.Pow(speedx, 2) + Math.Pow(speedy, 2)); var barraPotencia = (160.0 / speed) * 950; //lb.Content = barraPotencia; if (barraPotencia >= 33) { potencia.Margin = new Thickness(33, 600, barraPotencia, 10); } //lb.Content = "frame = " + frame; if (Mouse.LeftButton == MouseButtonState.Pressed && wraper.Count == 0) { potencia.Visibility = System.Windows.Visibility.Hidden; potencia2.Visibility = System.Windows.Visibility.Hidden; Wrap p = new Wrap(speedx, speedy, turns.Peek().CanvasXPos, turns.Peek().CanvasYPos, 90, 40); Image img = new Image(); var image = new BitmapImage(); image.BeginInit(); image.UriSource = new Uri(@"D:\repos\Die_And_KILL\Die_And_Kill\Resources\bazooka.gif"); image.EndInit(); ImageBehavior.SetAnimatedSource(img, image); Canvas.SetTop(img, p.CanvasPosY); Canvas.SetLeft(img, p.CanvasPosX); MyCanvas.Children.Add(img); wraper.Add(new Tuple <Image, Wrap>(img, p)); BazookaControl.Stop(); } }
protected override void Init() { SetBaseView(); RotateTransform translation = new RotateTransform(); ScaleTransform translationScale = new ScaleTransform(1, 1); dau = new DoubleAnimationUsingKeyFrames(); #region 基本工作,确定类型和name //是否存在TranslateTransform //动画要的类型是否存在 //动画要的类型的name是否存在,不存在就注册,结束后取消注册,删除动画 var ex = Element.RenderTransform; if (ex == null || (ex as System.Windows.Media.MatrixTransform) != null) { var tg = new TransformGroup(); translation = new RotateTransform(); Win.RegisterName(translation); tg.Children.Add(translation); Win.RegisterName(translationScale); tg.Children.Add(translationScale); Element.RenderTransform = tg; } else { var tg = ex as TransformGroup; foreach (var item in tg.Children) { translation = item as RotateTransform; if (translation != null) { break; } } foreach (var item in tg.Children) { translationScale = item as ScaleTransform; if (translationScale != null) { break; } } if (translation != null) { //当前Y值 var tex = translation.GetValue(FrameworkElement.NameProperty); if (tex != null && tex.ToString() != "") { } else { Win.RegisterName(translation); } } else { translation = new RotateTransform(); Win.RegisterName(translation); tg.Children.Add(translation); Element.RenderTransform = tg; } if (translationScale != null) { var tex = translationScale.GetValue(FrameworkElement.NameProperty); if (tex != null && tex.ToString() != "") { } else { Win.RegisterName(translationScale); } } else { translationScale = new ScaleTransform(1, 1); Win.RegisterName(translationScale); tg.Children.Add(translationScale); Element.RenderTransform = tg; } } #endregion translation.CenterX = 0.5; translation.CenterY = 0; double angle = translation.Angle; var k2 = new EasingDoubleKeyFrame(angle - 3, TimeSpan.FromMilliseconds(AniTime(0.1))); var k2_1 = new EasingDoubleKeyFrame(angle - 3, TimeSpan.FromMilliseconds(AniTime(0.2))); var k2_2 = new EasingDoubleKeyFrame(angle + 3, TimeSpan.FromMilliseconds(AniTime(0.3))); var k2_3 = new EasingDoubleKeyFrame(angle + 3, TimeSpan.FromMilliseconds(AniTime(0.5))); var k2_4 = new EasingDoubleKeyFrame(angle + 3, TimeSpan.FromMilliseconds(AniTime(0.7))); var k2_5 = new EasingDoubleKeyFrame(angle + 3, TimeSpan.FromMilliseconds(AniTime(0.9))); var k2_6 = new EasingDoubleKeyFrame(angle - 3, TimeSpan.FromMilliseconds(AniTime(0.4))); var k2_7 = new EasingDoubleKeyFrame(angle - 3, TimeSpan.FromMilliseconds(AniTime(0.6))); var k2_8 = new EasingDoubleKeyFrame(angle - 3, TimeSpan.FromMilliseconds(AniTime(0.8))); var k2_9 = new EasingDoubleKeyFrame(angle, TimeSpan.FromMilliseconds(AnimateSpeed)); Story = (Storyboard)Story.Clone(); Storyboard.SetTargetName(dau, Win.GetName(translation)); Storyboard.SetTargetProperty(dau, new PropertyPath(RotateTransform.AngleProperty)); Win.RegisterResource(Story); dau.KeyFrames.Add(k2); dau.KeyFrames.Add(k2_1); dau.KeyFrames.Add(k2_2); dau.KeyFrames.Add(k2_3); dau.KeyFrames.Add(k2_4); dau.KeyFrames.Add(k2_5); dau.KeyFrames.Add(k2_6); dau.KeyFrames.Add(k2_7); dau.KeyFrames.Add(k2_8); dau.KeyFrames.Add(k2_9); Story.Children.Add(dau); dauScaleX = new DoubleAnimationUsingKeyFrames(); dauScaleY = new DoubleAnimationUsingKeyFrames(); double scaleX = translationScale.ScaleX; double scaleY = translationScale.ScaleY; double s1 = scaleX + tadaScale; double s2 = scaleX - tadaScale; double s3 = scaleY + tadaScale; double s4 = scaleY - tadaScale; var k3 = new EasingDoubleKeyFrame(s2, TimeSpan.FromMilliseconds(AniTime(0.1))); var k3_1 = new EasingDoubleKeyFrame(s2, TimeSpan.FromMilliseconds(AniTime(0.2))); var k3_2 = new EasingDoubleKeyFrame(s1, TimeSpan.FromMilliseconds(AniTime(0.3))); var k3_3 = new EasingDoubleKeyFrame(s1, TimeSpan.FromMilliseconds(AniTime(0.5))); var k3_4 = new EasingDoubleKeyFrame(s1, TimeSpan.FromMilliseconds(AniTime(0.7))); var k3_5 = new EasingDoubleKeyFrame(s1, TimeSpan.FromMilliseconds(AniTime(0.9))); var k3_6 = new EasingDoubleKeyFrame(s1, TimeSpan.FromMilliseconds(AniTime(0.4))); var k3_7 = new EasingDoubleKeyFrame(s1, TimeSpan.FromMilliseconds(AniTime(0.6))); var k3_8 = new EasingDoubleKeyFrame(s1, TimeSpan.FromMilliseconds(AniTime(0.8))); var k3_9 = new EasingDoubleKeyFrame(scaleX, TimeSpan.FromMilliseconds(AnimateSpeed)); var k4 = new EasingDoubleKeyFrame(s4, TimeSpan.FromMilliseconds(AniTime(0.1))); var k4_1 = new EasingDoubleKeyFrame(s4, TimeSpan.FromMilliseconds(AniTime(0.2))); var k4_2 = new EasingDoubleKeyFrame(s3, TimeSpan.FromMilliseconds(AniTime(0.3))); var k4_3 = new EasingDoubleKeyFrame(s3, TimeSpan.FromMilliseconds(AniTime(0.5))); var k4_4 = new EasingDoubleKeyFrame(s3, TimeSpan.FromMilliseconds(AniTime(0.7))); var k4_5 = new EasingDoubleKeyFrame(s3, TimeSpan.FromMilliseconds(AniTime(0.9))); var k4_6 = new EasingDoubleKeyFrame(s3, TimeSpan.FromMilliseconds(AniTime(0.4))); var k4_7 = new EasingDoubleKeyFrame(s3, TimeSpan.FromMilliseconds(AniTime(0.6))); var k4_8 = new EasingDoubleKeyFrame(s3, TimeSpan.FromMilliseconds(AniTime(0.8))); var k4_9 = new EasingDoubleKeyFrame(scaleY, TimeSpan.FromMilliseconds(AnimateSpeed)); Storyboard.SetTargetName(dauScaleX, Win.GetName(translationScale)); Storyboard.SetTargetProperty(dauScaleX, new PropertyPath(ScaleTransform.ScaleXProperty)); Storyboard.SetTargetName(dauScaleY, Win.GetName(translationScale)); Storyboard.SetTargetProperty(dauScaleY, new PropertyPath(ScaleTransform.ScaleYProperty)); dauScaleX.KeyFrames.Add(k3); dauScaleX.KeyFrames.Add(k3_1); dauScaleX.KeyFrames.Add(k3_2); dauScaleX.KeyFrames.Add(k3_3); dauScaleX.KeyFrames.Add(k3_4); dauScaleX.KeyFrames.Add(k3_5); dauScaleX.KeyFrames.Add(k3_6); dauScaleX.KeyFrames.Add(k3_7); dauScaleX.KeyFrames.Add(k3_8); dauScaleX.KeyFrames.Add(k3_9); Story.Children.Add(dauScaleX); dauScaleY.KeyFrames.Add(k4); dauScaleY.KeyFrames.Add(k4_1); dauScaleY.KeyFrames.Add(k4_2); dauScaleY.KeyFrames.Add(k4_3); dauScaleY.KeyFrames.Add(k4_4); dauScaleY.KeyFrames.Add(k4_5); dauScaleY.KeyFrames.Add(k4_6); dauScaleY.KeyFrames.Add(k4_7); dauScaleY.KeyFrames.Add(k4_8); dauScaleY.KeyFrames.Add(k4_9); Story.Children.Add(dauScaleY); Story.Completed -= Story_Completed; Story.Completed += Story_Completed; }
protected override void Start() { Route.InitPoints(); ScaleTransform = new ScaleTransform(1d, 1d); SceneObject.RenderTransform.Children.Add(ScaleTransform); }
private void AddStrokeAsPoints(Stroke stroke, PenSize size) { int count = 0; StylusPointCollection spc = new StylusPointCollection(); foreach (StylusPoint sp in stroke.StylusPoints) { int scale = 1; if (size == PenSize.Medium) { scale = 2; } if (size == PenSize.Large) { scale = 4; } double x = sp.X - (sp.X % scale) + 0.5; double y = sp.Y - (sp.Y % scale) + 0.5; StylusPoint point = new StylusPoint(x, y); if (!spc.Contains(point)) { spc.Add(point); } if ((size == PenSize.Medium) || (size == PenSize.Large)) { point = new StylusPoint(x + 1, y); if (!spc.Contains(point)) { spc.Add(point); } point = new StylusPoint(x, y + 1); if (!spc.Contains(point)) { spc.Add(point); } point = new StylusPoint(x + 1, y + 1); if (!spc.Contains(point)) { spc.Add(point); } if (size == PenSize.Large) { point = new StylusPoint(x + 2, y); if (!spc.Contains(point)) { spc.Add(point); } point = new StylusPoint(x + 3, y); if (!spc.Contains(point)) { spc.Add(point); } point = new StylusPoint(x + 2, y + 1); if (!spc.Contains(point)) { spc.Add(point); } point = new StylusPoint(x + 3, y + 1); if (!spc.Contains(point)) { spc.Add(point); } point = new StylusPoint(x, y + 2); if (!spc.Contains(point)) { spc.Add(point); } point = new StylusPoint(x + 1, y + 2); if (!spc.Contains(point)) { spc.Add(point); } point = new StylusPoint(x + 2, y + 2); if (!spc.Contains(point)) { spc.Add(point); } point = new StylusPoint(x + 3, y + 2); if (!spc.Contains(point)) { spc.Add(point); } point = new StylusPoint(x, y + 3); if (!spc.Contains(point)) { spc.Add(point); } point = new StylusPoint(x + 1, y + 3); if (!spc.Contains(point)) { spc.Add(point); } point = new StylusPoint(x + 2, y + 3); if (!spc.Contains(point)) { spc.Add(point); } point = new StylusPoint(x + 3, y + 3); if (!spc.Contains(point)) { spc.Add(point); } } } if (!spc.Contains(point)) { spc.Add(point); } Stroke st = new Stroke(spc); st.DrawingAttributes = inkDA; if (!canvas.Strokes.Contains(st)) { canvas.Strokes.Add(st); count++; } spc = new StylusPointCollection(); } ActionHistory.Add(Actions.AddStroke); UndoPoints.Add(count); dirty = true; }
private async void Ocr_OnClick(object sender, RoutedEventArgs e) { _drawTool?.Close(); ClearResults(); Rectangle itemsRectangle = _viewModel.ItemsRectangle; Rectangle quantityRectangle = _viewModel.QuantityRectangle; BitmapSource bitmapSource = _viewModel.ImgSource; if (bitmapSource == null || itemsRectangle == null || quantityRectangle == null) { return; } // Check if OcrEngine supports image resoulution. if (bitmapSource.PixelWidth > OcrEngine.MaxImageDimension || bitmapSource.PixelHeight > OcrEngine.MaxImageDimension) { return; } OcrEngine ocrEngine = OcrEngine.TryCreateFromUserProfileLanguages(); if (ocrEngine == null) { // Display message to user! return; } OcrResult ocrResult = await ocrEngine.RecognizeAsync(_viewModel.Bitmap); // Display recognized text. //ExtractedTextBox.Text = ocrResult.Text; if (ocrResult.TextAngle != null) { // If text is detected under some angle in this sample scenario we want to // overlay word boxes over original image, so we rotate overlay boxes. OverlayCanvas.RenderTransform = new RotateTransform { Angle = (double)ocrResult.TextAngle, CenterX = PreviewImage.ActualWidth / 2, CenterY = PreviewImage.ActualHeight / 2 }; } ScaleTransform scaleTrasform = ScaleTrasform(); var itemsRect = new Rect(Canvas.GetLeft(itemsRectangle), Canvas.GetTop(itemsRectangle), itemsRectangle.Width, itemsRectangle.Height); var quantityRect = new Rect(Canvas.GetLeft(quantityRectangle), Canvas.GetTop(quantityRectangle), quantityRectangle.Width, quantityRectangle.Height); var items = new List <OcrWord>(); var quantities = new List <OcrWord>(); foreach (OcrLine line in ocrResult.Lines) { //bool isHorizontal = IsHorizontal(line); foreach (OcrWord word in line.Words) { Rect rect = scaleTrasform.TransformBounds(word.BoundingRect); Rect intersectRect1 = itemsRect; intersectRect1.Intersect(rect); Rect intersectRect2 = quantityRect; intersectRect2.Intersect(rect); bool itemsWord = intersectRect1 == rect; bool quantityWord = intersectRect2 == rect; if (!itemsWord && !quantityWord) { continue; } var overlay = new Rectangle { Fill = new SolidColorBrush(Color.FromArgb(125, 0, 0, 255)), Width = rect.Width, Height = rect.Height, Tag = word }; Canvas.SetTop(overlay, rect.Top); Canvas.SetLeft(overlay, rect.Left); OverlayCanvas.Children.Add(overlay); if (itemsWord) { items.Add(word); } else { quantities.Add(word); } } _lines.Add(line); } _viewModel.Items = items; _viewModel.Quantities = quantities; }
/* * 加载所有动画效果 * * @param currElement 当前控件 * * @param currDControl 当前控件数据 * * @param list 动画列表 */ public static void loadAllAnimation(FrameworkElement currElement, DControl currDControl, List <DControlAnimation> list, Cfg cfg) { double currOpacity = currDControl.opacity / 100.0; TransformGroup group = (TransformGroup)currElement.RenderTransform; // group.Children.Clear(); 多次加载动画需要归零 foreach (DControlAnimation animation in list) { if (animation.type == 1001) { //淡入 currElement.RenderTransformOrigin = new Point(0.5, 0.5); currElement.Opacity = 0; IEasingFunction easingFunction = new CubicEase() { EasingMode = EasingMode.EaseIn }; DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 0, currOpacity, easingFunction); currElement.BeginAnimation(UIElement.OpacityProperty, da); } else if (animation.type == 1002) { //从左移入 currElement.RenderTransformOrigin = new Point(0.5, 0.5); TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, -currDControl.left - currDControl.width, 0); translateTransform.BeginAnimation(TranslateTransform.XProperty, da); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1003) { //从右移入 currElement.RenderTransformOrigin = new Point(0.5, 0.5); TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, cfg.screenWidth - currDControl.left, 0); translateTransform.BeginAnimation(TranslateTransform.XProperty, da); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1004) { //从上移入 currElement.RenderTransformOrigin = new Point(0.5, 0.5); TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, -currDControl.top - currDControl.height, 0); translateTransform.BeginAnimation(TranslateTransform.YProperty, da); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1005) { //从下移入 currElement.RenderTransformOrigin = new Point(0.5, 0.5); TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, cfg.screenHeight - currDControl.top, 0); translateTransform.BeginAnimation(TranslateTransform.YProperty, da); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1006) { //放大 currElement.RenderTransformOrigin = new Point(0.5, 0.5); ScaleTransform scaleTransform = TransformGroupUtil.GetScaleTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 0.5, 1.0); scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1007) { //缩小 currElement.RenderTransformOrigin = new Point(0.5, 0.5); ScaleTransform scaleTransform = TransformGroupUtil.GetScaleTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 1.5, 1.0); scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1101) { //从左旋转 currElement.RenderTransformOrigin = new Point(0.5, 0.5); RotateTransform rotateTransform = TransformGroupUtil.GetRotateTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 180 + currDControl.rotateAngle, 360 + currDControl.rotateAngle); rotateTransform.BeginAnimation(RotateTransform.AngleProperty, da); TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); DoubleAnimation da2 = DoubleAnimationUtil.initDoubleAnimation(animation, -currDControl.width * 1, 0); translateTransform.BeginAnimation(TranslateTransform.XProperty, da2); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1102) { //从右旋转 currElement.RenderTransformOrigin = new Point(0.5, 0.5); RotateTransform rotateTransform = TransformGroupUtil.GetRotateTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 180 + currDControl.rotateAngle, 360 + currDControl.rotateAngle); rotateTransform.BeginAnimation(RotateTransform.AngleProperty, da); TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); DoubleAnimation da2 = DoubleAnimationUtil.initDoubleAnimation(animation, currDControl.width * 1, 0); translateTransform.BeginAnimation(TranslateTransform.XProperty, da2); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1103) { //从上旋转 currElement.RenderTransformOrigin = new Point(0.5, 0.5); RotateTransform rotateTransform = TransformGroupUtil.GetRotateTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 180 + currDControl.rotateAngle, 360 + currDControl.rotateAngle); rotateTransform.BeginAnimation(RotateTransform.AngleProperty, da); TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); DoubleAnimation da2 = DoubleAnimationUtil.initDoubleAnimation(animation, -currDControl.height * 1, 0); translateTransform.BeginAnimation(TranslateTransform.YProperty, da2); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1104) { //从下旋转 currElement.RenderTransformOrigin = new Point(0.5, 0.5); RotateTransform rotateTransform = TransformGroupUtil.GetRotateTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 180 + currDControl.rotateAngle, 360 + currDControl.rotateAngle); rotateTransform.BeginAnimation(RotateTransform.AngleProperty, da); TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); DoubleAnimation da2 = DoubleAnimationUtil.initDoubleAnimation(animation, currDControl.height * 1, 0); translateTransform.BeginAnimation(TranslateTransform.YProperty, da2); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1201) { //从左弹入 currElement.RenderTransformOrigin = new Point(0.5, 0.5); TranslateTransform translateTransform12 = TransformGroupUtil.GetTranslateTransform(group); IEasingFunction easingFunction = new BackEase() { EasingMode = EasingMode.EaseInOut }; DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, -currDControl.left - currDControl.width, 0, easingFunction); translateTransform12.BeginAnimation(TranslateTransform.XProperty, da); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1202) { //从右弹入 currElement.RenderTransformOrigin = new Point(0.5, 0.5); TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); IEasingFunction easingFunction = new BackEase() { EasingMode = EasingMode.EaseInOut }; DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, cfg.screenWidth - currDControl.left, 0, easingFunction); translateTransform.BeginAnimation(TranslateTransform.XProperty, da); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1203) { //从上弹入 currElement.RenderTransformOrigin = new Point(0.5, 0.5); TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); IEasingFunction easingFunction = new BackEase() { EasingMode = EasingMode.EaseInOut }; DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, -currDControl.top - currDControl.height, 0, easingFunction); translateTransform.BeginAnimation(TranslateTransform.YProperty, da); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1204) { //从下弹入 currElement.RenderTransformOrigin = new Point(0.5, 0.5); TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); IEasingFunction easingFunction = new BackEase() { EasingMode = EasingMode.EaseInOut }; DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, cfg.screenHeight - currDControl.top, 0, easingFunction); translateTransform.BeginAnimation(TranslateTransform.YProperty, da); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1205) { //中心弹入 currElement.RenderTransformOrigin = new Point(0.5, 0.5); ScaleTransform scaleTransform = TransformGroupUtil.GetScaleTransform(group); IEasingFunction easingFunction = new BackEase() { EasingMode = EasingMode.EaseInOut }; DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 0.5, 1.0, easingFunction); scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1301) { //从左斜入 currElement.RenderTransformOrigin = new Point(0.5, 0.5); SkewTransform skewTransform = TransformGroupUtil.GetSkewTransform(group); IEasingFunction easingFunction = new BackEase() { EasingMode = EasingMode.EaseInOut }; DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 140, 180, easingFunction); skewTransform.BeginAnimation(SkewTransform.AngleXProperty, da); TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); DoubleAnimation da1 = DoubleAnimationUtil.initDoubleAnimation(animation, -currDControl.width * 1, 0, easingFunction); translateTransform.BeginAnimation(TranslateTransform.XProperty, da1); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1302) { //从右斜入 currElement.RenderTransformOrigin = new Point(0.5, 0.5); SkewTransform skewTransform = TransformGroupUtil.GetSkewTransform(group); IEasingFunction easingFunction = new BackEase() { EasingMode = EasingMode.EaseInOut }; DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 40, 0, easingFunction); skewTransform.BeginAnimation(SkewTransform.AngleXProperty, da); TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); DoubleAnimation da1 = DoubleAnimationUtil.initDoubleAnimation(animation, currDControl.width, 0, easingFunction); translateTransform.BeginAnimation(TranslateTransform.XProperty, da1); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1303) { //从上斜入 currElement.RenderTransformOrigin = new Point(0.5, 0.5); ScaleTransform scaleTransform = TransformGroupUtil.GetScaleTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 0.1, 1.0); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da); SkewTransform skewTransform = TransformGroupUtil.GetSkewTransform(group); IEasingFunction easingFunction = new BackEase() { EasingMode = EasingMode.EaseInOut }; DoubleAnimation da1 = DoubleAnimationUtil.initDoubleAnimation(animation, 60, 0, easingFunction); skewTransform.BeginAnimation(SkewTransform.AngleXProperty, da1); TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); DoubleAnimation da2 = DoubleAnimationUtil.initDoubleAnimation(animation, -currDControl.height, 0); translateTransform.BeginAnimation(TranslateTransform.YProperty, da2); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1304) { //从下斜入 currElement.RenderTransformOrigin = new Point(0.5, 0.5); ScaleTransform scaleTransform = TransformGroupUtil.GetScaleTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 0.1, 1.0); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da); SkewTransform skewTransform = TransformGroupUtil.GetSkewTransform(group); IEasingFunction easingFunction = new BackEase() { EasingMode = EasingMode.EaseInOut }; DoubleAnimation da1 = DoubleAnimationUtil.initDoubleAnimation(animation, 60, 0, easingFunction); skewTransform.BeginAnimation(SkewTransform.AngleXProperty, da1); TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); DoubleAnimation da2 = DoubleAnimationUtil.initDoubleAnimation(animation, currDControl.height, 0); translateTransform.BeginAnimation(TranslateTransform.YProperty, da2); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1401) { //从左绕入 currElement.RenderTransformOrigin = new Point(0, 0); RotateTransform rotateTransform = TransformGroupUtil.GetRotateTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 360 + currDControl.rotateAngle, 0 + currDControl.rotateAngle); rotateTransform.BeginAnimation(RotateTransform.AngleProperty, da); ScaleTransform scaleTransform = TransformGroupUtil.GetScaleTransform(group); DoubleAnimation da1 = DoubleAnimationUtil.initDoubleAnimation(animation, 0, 1.0); scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da1); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da1); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1402) { //从右绕入 currElement.RenderTransformOrigin = new Point(1, 1); RotateTransform rotateTransform = TransformGroupUtil.GetRotateTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 360 + currDControl.rotateAngle, 0 + currDControl.rotateAngle); rotateTransform.BeginAnimation(RotateTransform.AngleProperty, da); ScaleTransform scaleTransform = TransformGroupUtil.GetScaleTransform(group); DoubleAnimation da1 = DoubleAnimationUtil.initDoubleAnimation(animation, 0, 1.0); scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da1); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da1); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1403) { //从上绕入 currElement.RenderTransformOrigin = new Point(1, 0); RotateTransform rotateTransform = TransformGroupUtil.GetRotateTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 360 + currDControl.rotateAngle, 0 + currDControl.rotateAngle); rotateTransform.BeginAnimation(RotateTransform.AngleProperty, da); ScaleTransform scaleTransform = TransformGroupUtil.GetScaleTransform(group); DoubleAnimation da1 = DoubleAnimationUtil.initDoubleAnimation(animation, 0, 1.0); scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da1); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da1); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1404) { //从下绕入 currElement.RenderTransformOrigin = new Point(0, 1); RotateTransform rotateTransform = TransformGroupUtil.GetRotateTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 0 + currDControl.rotateAngle, 360 + currDControl.rotateAngle); rotateTransform.BeginAnimation(RotateTransform.AngleProperty, da); ScaleTransform scaleTransform = TransformGroupUtil.GetScaleTransform(group); DoubleAnimation da1 = DoubleAnimationUtil.initDoubleAnimation(animation, 0, 1.0); scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da1); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da1); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1501) { //翻开 currElement.RenderTransformOrigin = new Point(0.5, 0.5); SkewTransform skewTransform = TransformGroupUtil.GetSkewTransform(group); IEasingFunction easingFunction = new BackEase() { EasingMode = EasingMode.EaseInOut, Amplitude = 0.1 }; DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 10, 0, easingFunction); skewTransform.BeginAnimation(SkewTransform.AngleXProperty, da); ScaleTransform scaleTransform = TransformGroupUtil.GetScaleTransform(group); IEasingFunction easingFunction1 = new BackEase() { EasingMode = EasingMode.EaseInOut }; DoubleAnimation da1 = DoubleAnimationUtil.initDoubleAnimation(animation, 0.4, 1.0, easingFunction1); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da1); IEasingFunction easingFunction2 = new CubicEase() { EasingMode = EasingMode.EaseIn }; DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity, easingFunction2); } else if (animation.type == 1502) { //旋转 currElement.RenderTransformOrigin = new Point(0.5, 0.5); RotateTransform rotateTransform = TransformGroupUtil.GetRotateTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 0 + currDControl.rotateAngle, 360 + currDControl.rotateAngle); rotateTransform.BeginAnimation(RotateTransform.AngleProperty, da); IEasingFunction easingFunction2 = new CubicEase() { EasingMode = EasingMode.EaseIn }; DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity, easingFunction2); } else if (animation.type == 1601) { //光晕 来回缩放 currElement.RenderTransformOrigin = new Point(0.5, 0.5); double halfSeconds = animation.durationSeconds / 2.0; DoubleAnimationUsingKeyFrames da = new DoubleAnimationUsingKeyFrames(); if (animation.playTimes <= 0) { da.RepeatBehavior = RepeatBehavior.Forever; } else { da.RepeatBehavior = new RepeatBehavior(animation.playTimes); } ScaleTransform scaleTransform = TransformGroupUtil.GetScaleTransform(group); var keyFrames = da.KeyFrames; IEasingFunction easingFunction = new CubicEase() { EasingMode = EasingMode.EaseIn }; keyFrames.Add(new LinearDoubleKeyFrame(1.0, TimeSpan.FromMilliseconds(0))); keyFrames.Add(new LinearDoubleKeyFrame(0.78, TimeSpan.FromMilliseconds(halfSeconds))); keyFrames.Add(new LinearDoubleKeyFrame(1.0, TimeSpan.FromMilliseconds(animation.durationSeconds))); scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da); } } }
private void RenderTheme(DrawingContext dc) { Size size = RenderSize; bool horizontal = Orientation == Orientation.Horizontal; bool isClickable = IsClickable && IsEnabled; bool isHovered = isClickable && IsHovered; bool isPressed = isClickable && IsPressed; ListSortDirection?sortDirection = SortDirection; bool isSorted = sortDirection != null; bool isSelected = IsSelected; bool hasBevel = (!isHovered && !isPressed && !isSorted && !isSelected); EnsureCache((int)AeroFreezables.NumFreezables); if (horizontal) { // When horizontal, rotate the rendering by -90 degrees Matrix m1 = new Matrix(); m1.RotateAt(-90.0, 0.0, 0.0); Matrix m2 = new Matrix(); m2.Translate(0.0, size.Height); MatrixTransform horizontalRotate = new MatrixTransform(m1 * m2); horizontalRotate.Freeze(); dc.PushTransform(horizontalRotate); double temp = size.Width; size.Width = size.Height; size.Height = temp; } if (hasBevel) { // This is a highlight that can be drawn by just filling the background with the color. // It will be seen through the gab between the border and the background. LinearGradientBrush bevel = (LinearGradientBrush)GetCachedFreezable((int)AeroFreezables.NormalBevel); if (bevel == null) { bevel = new LinearGradientBrush(); bevel.StartPoint = new Point(); bevel.EndPoint = new Point(0.0, 1.0); bevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF), 0.0)); bevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF), 0.4)); bevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFC, 0xFC, 0xFD), 0.4)); bevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFB, 0xFC, 0xFC), 1.0)); bevel.Freeze(); CacheFreezable(bevel, (int)AeroFreezables.NormalBevel); } dc.DrawRectangle(bevel, null, new Rect(0.0, 0.0, size.Width, size.Height)); } // Fill the background AeroFreezables backgroundType = AeroFreezables.NormalBackground; if (isPressed) { backgroundType = AeroFreezables.PressedBackground; } else if (isHovered) { backgroundType = AeroFreezables.HoveredBackground; } else if (isSorted || isSelected) { backgroundType = AeroFreezables.SortedBackground; } LinearGradientBrush background = (LinearGradientBrush)GetCachedFreezable((int)backgroundType); if (background == null) { background = new LinearGradientBrush(); background.StartPoint = new Point(); background.EndPoint = new Point(0.0, 1.0); switch (backgroundType) { case AeroFreezables.NormalBackground: background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF), 0.0)); background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF), 0.4)); background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF7, 0xF8, 0xFA), 0.4)); background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF1, 0xF2, 0xF4), 1.0)); break; case AeroFreezables.PressedBackground: background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xBC, 0xE4, 0xF9), 0.0)); background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xBC, 0xE4, 0xF9), 0.4)); background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x8D, 0xD6, 0xF7), 0.4)); background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x8A, 0xD1, 0xF5), 1.0)); break; case AeroFreezables.HoveredBackground: background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xE3, 0xF7, 0xFF), 0.0)); background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xE3, 0xF7, 0xFF), 0.4)); background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xBD, 0xED, 0xFF), 0.4)); background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xB7, 0xE7, 0xFB), 1.0)); break; case AeroFreezables.SortedBackground: background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF2, 0xF9, 0xFC), 0.0)); background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF2, 0xF9, 0xFC), 0.4)); background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xE1, 0xF1, 0xF9), 0.4)); background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xD8, 0xEC, 0xF6), 1.0)); break; } background.Freeze(); CacheFreezable(background, (int)backgroundType); } dc.DrawRectangle(background, null, new Rect(0.0, 0.0, size.Width, size.Height)); if (size.Width >= 2.0) { // Draw the borders on the sides AeroFreezables sideType = AeroFreezables.NormalSides; if (isPressed) { sideType = AeroFreezables.PressedSides; } else if (isHovered) { sideType = AeroFreezables.HoveredSides; } else if (isSorted || isSelected) { sideType = AeroFreezables.SortedSides; } if (SeparatorVisibility == Visibility.Visible) { Brush sideBrush; if (SeparatorBrush != null) { sideBrush = SeparatorBrush; } else { sideBrush = (Brush)GetCachedFreezable((int)sideType); if (sideBrush == null) { LinearGradientBrush lgBrush = null; if (sideType != AeroFreezables.SortedSides) { lgBrush = new LinearGradientBrush(); lgBrush.StartPoint = new Point(); lgBrush.EndPoint = new Point(0.0, 1.0); sideBrush = lgBrush; } switch (sideType) { case AeroFreezables.NormalSides: lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF2, 0xF2, 0xF2), 0.0)); lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xEF, 0xEF, 0xEF), 0.4)); lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xE7, 0xE8, 0xEA), 0.4)); lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xDE, 0xDF, 0xE1), 1.0)); break; case AeroFreezables.PressedSides: lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x7A, 0x9E, 0xB1), 0.0)); lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x7A, 0x9E, 0xB1), 0.4)); lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x50, 0x91, 0xAF), 0.4)); lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x4D, 0x8D, 0xAD), 1.0)); break; case AeroFreezables.HoveredSides: lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x88, 0xCB, 0xEB), 0.0)); lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x88, 0xCB, 0xEB), 0.4)); lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x69, 0xBB, 0xE3), 0.4)); lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x69, 0xBB, 0xE3), 1.0)); break; case AeroFreezables.SortedSides: sideBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0x96, 0xD9, 0xF9)); break; } sideBrush.Freeze(); CacheFreezable(sideBrush, (int)sideType); } } dc.DrawRectangle(sideBrush, null, new Rect(0.0, 0.0, 1.0, Max0(size.Height - 0.95))); dc.DrawRectangle(sideBrush, null, new Rect(size.Width - 1.0, 0.0, 1.0, Max0(size.Height - 0.95))); } } if (isPressed && (size.Width >= 4.0) && (size.Height >= 4.0)) { // When pressed, there are added borders on the left and top LinearGradientBrush topBrush = (LinearGradientBrush)GetCachedFreezable((int)AeroFreezables.PressedTop); if (topBrush == null) { topBrush = new LinearGradientBrush(); topBrush.StartPoint = new Point(); topBrush.EndPoint = new Point(0.0, 1.0); topBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x86, 0xA3, 0xB2), 0.0)); topBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x86, 0xA3, 0xB2), 0.1)); topBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xAA, 0xCE, 0xE1), 0.9)); topBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xAA, 0xCE, 0xE1), 1.0)); topBrush.Freeze(); CacheFreezable(topBrush, (int)AeroFreezables.PressedTop); } dc.DrawRectangle(topBrush, null, new Rect(0.0, 0.0, size.Width, 2.0)); LinearGradientBrush pressedBevel = (LinearGradientBrush)GetCachedFreezable((int)AeroFreezables.PressedBevel); if (pressedBevel == null) { pressedBevel = new LinearGradientBrush(); pressedBevel.StartPoint = new Point(); pressedBevel.EndPoint = new Point(0.0, 1.0); pressedBevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xA2, 0xCB, 0xE0), 0.0)); pressedBevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xA2, 0xCB, 0xE0), 0.4)); pressedBevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x72, 0xBC, 0xDF), 0.4)); pressedBevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x6E, 0xB8, 0xDC), 1.0)); pressedBevel.Freeze(); CacheFreezable(pressedBevel, (int)AeroFreezables.PressedBevel); } dc.DrawRectangle(pressedBevel, null, new Rect(1.0, 0.0, 1.0, size.Height - 0.95)); dc.DrawRectangle(pressedBevel, null, new Rect(size.Width - 2.0, 0.0, 1.0, size.Height - 0.95)); } if (size.Height >= 2.0) { // Draw the bottom border AeroFreezables bottomType = AeroFreezables.NormalBottom; if (isPressed) { bottomType = AeroFreezables.PressedOrHoveredBottom; } else if (isHovered) { bottomType = AeroFreezables.PressedOrHoveredBottom; } else if (isSorted || isSelected) { bottomType = AeroFreezables.SortedBottom; } SolidColorBrush bottomBrush = (SolidColorBrush)GetCachedFreezable((int)bottomType); if (bottomBrush == null) { switch (bottomType) { case AeroFreezables.NormalBottom: bottomBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0xD5, 0xD5, 0xD5)); break; case AeroFreezables.PressedOrHoveredBottom: bottomBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0x93, 0xC9, 0xE3)); break; case AeroFreezables.SortedBottom: bottomBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0x96, 0xD9, 0xF9)); break; } bottomBrush.Freeze(); CacheFreezable(bottomBrush, (int)bottomType); } dc.DrawRectangle(bottomBrush, null, new Rect(0.0, size.Height - 1.0, size.Width, 1.0)); } if (isSorted && (size.Width > 14.0) && (size.Height > 10.0)) { // Draw the sort arrow TranslateTransform positionTransform = new TranslateTransform((size.Width - 8.0) * 0.5, 1.0); positionTransform.Freeze(); dc.PushTransform(positionTransform); bool ascending = (sortDirection == ListSortDirection.Ascending); PathGeometry arrowGeometry = (PathGeometry)GetCachedFreezable(ascending ? (int)AeroFreezables.ArrowUpGeometry : (int)AeroFreezables.ArrowDownGeometry); if (arrowGeometry == null) { arrowGeometry = new PathGeometry(); PathFigure arrowFigure = new PathFigure(); if (ascending) { arrowFigure.StartPoint = new Point(0.0, 4.0); LineSegment line = new LineSegment(new Point(4.0, 0.0), false); line.Freeze(); arrowFigure.Segments.Add(line); line = new LineSegment(new Point(8.0, 4.0), false); line.Freeze(); arrowFigure.Segments.Add(line); } else { arrowFigure.StartPoint = new Point(0.0, 0.0); LineSegment line = new LineSegment(new Point(8.0, 0.0), false); line.Freeze(); arrowFigure.Segments.Add(line); line = new LineSegment(new Point(4.0, 4.0), false); line.Freeze(); arrowFigure.Segments.Add(line); } arrowFigure.IsClosed = true; arrowFigure.Freeze(); arrowGeometry.Figures.Add(arrowFigure); arrowGeometry.Freeze(); CacheFreezable(arrowGeometry, ascending ? (int)AeroFreezables.ArrowUpGeometry : (int)AeroFreezables.ArrowDownGeometry); } // Draw two arrows, one inset in the other. This is to achieve a double gradient over both the border and the fill. LinearGradientBrush arrowBorder = (LinearGradientBrush)GetCachedFreezable((int)AeroFreezables.ArrowBorder); if (arrowBorder == null) { arrowBorder = new LinearGradientBrush(); arrowBorder.StartPoint = new Point(); arrowBorder.EndPoint = new Point(1.0, 1.0); arrowBorder.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x3C, 0x5E, 0x72), 0.0)); arrowBorder.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x3C, 0x5E, 0x72), 0.1)); arrowBorder.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xC3, 0xE4, 0xF5), 1.0)); arrowBorder.Freeze(); CacheFreezable(arrowBorder, (int)AeroFreezables.ArrowBorder); } dc.DrawGeometry(arrowBorder, null, arrowGeometry); LinearGradientBrush arrowFill = (LinearGradientBrush)GetCachedFreezable((int)AeroFreezables.ArrowFill); if (arrowFill == null) { arrowFill = new LinearGradientBrush(); arrowFill.StartPoint = new Point(); arrowFill.EndPoint = new Point(1.0, 1.0); arrowFill.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x61, 0x96, 0xB6), 0.0)); arrowFill.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x61, 0x96, 0xB6), 0.1)); arrowFill.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xCA, 0xE6, 0xF5), 1.0)); arrowFill.Freeze(); CacheFreezable(arrowFill, (int)AeroFreezables.ArrowFill); } // Inset the fill arrow inside the border arrow ScaleTransform arrowScale = (ScaleTransform)GetCachedFreezable((int)AeroFreezables.ArrowFillScale); if (arrowScale == null) { arrowScale = new ScaleTransform(0.75, 0.75, 3.5, 4.0); arrowScale.Freeze(); CacheFreezable(arrowScale, (int)AeroFreezables.ArrowFillScale); } dc.PushTransform(arrowScale); dc.DrawGeometry(arrowFill, null, arrowGeometry); dc.Pop(); // Scale Transform dc.Pop(); // Position Transform } if (horizontal) { dc.Pop(); // Horizontal Rotate } }
void DragBar_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (this.DraggingEnabled && !this.dragging) { e.Handled = true; combinedScaleTransform = this.GetCombinedScaleTransform(); this.lastDragPosition = e.GetPosition(sender as UIElement); // Fire the drag started event if (this.BeforeDragStarted != null) { this.BeforeDragStarted(this, new DragEventArgs(0, 0, e)); } // Bring the control to the front if (InitialValues.ContainingLayoutPanel == null) { throw new NullReferenceException("ContainingLayoutPanel is null. Please make sure that it is set."); } // fill droptarget-list with all droptargets on page? if (AllDropTargetsValid) { var dropTargets = GetChildsRecursive(UIHelpers.RootUI).OfType <DropTarget>().ToList(); this.InternalDropTargets = dropTargets; } // create a dummy overlay (to make sure the dragsource we drag is always on top) // and add the dragsource to this overlayed canvas at the correct position. To do // this, the dragsource must also be removed from its original parent. OriginalParent = ((Panel)VisualTreeHelper.GetParent(this)); DummyOverlay = new Canvas(); DummyOverlay.Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)); DummyOverlay.IsHitTestVisible = false; InitialValues.ContainingLayoutPanel.Children.Add(DummyOverlay); Point offsetMine = this.MainDraggableControl.TransformToVisual(InitialValues.ContainingLayoutPanel).Transform(new Point(0, 0)); OriginalOffset = offsetMine; // save datacontext! object currentDC = this.DataContext; OriginalParent.Children.Remove(this); this.DataContext = currentDC; // set correct position Canvas.SetLeft(this, offsetMine.X); Canvas.SetTop(this, offsetMine.Y); DummyOverlay.Children.Add(this); // Capture mouse & store position ((FrameworkElement)sender).CaptureMouse(); //this.lastDragPosition = e.GetPosition(sender as UIElement); // Set dragging to true this.dragging = true; this.isInDropTarget = false; // Fire the drag started event if (this.DragStarted != null) { this.DragStarted(this, new DragEventArgs(0, 0, e)); } } }
protected void FitToViewbox(WpfDrawingContext context, SvgElement svgElement, Rect elementBounds) { if (svgElement == null) { return; } ISvgFitToViewBox fitToView = svgElement as ISvgFitToViewBox; if (fitToView == null) { return; } SvgPreserveAspectRatio spar = (SvgPreserveAspectRatio)fitToView.PreserveAspectRatio.AnimVal; SvgRect viewBox = (SvgRect)fitToView.ViewBox.AnimVal; SvgRect rectToFit = new SvgRect(elementBounds.X, elementBounds.Y, elementBounds.Width, elementBounds.Height); double[] transformArray = spar.FitToViewBox(viewBox, rectToFit); double translateX = Math.Round(transformArray[0], 4); double translateY = Math.Round(transformArray[1], 4); double scaleX = Math.Round(transformArray[2], 4); double scaleY = Math.Round(transformArray[3], 4); Transform translateMatrix = null; Transform scaleMatrix = null; if (!translateX.Equals(0.0) || !translateY.Equals(0.0)) { translateMatrix = new TranslateTransform(translateX, translateY); } if (!scaleX.Equals(1.0) || !scaleY.Equals(1.0)) { scaleMatrix = new ScaleTransform(scaleX, scaleY); } if (translateMatrix != null && scaleMatrix != null) { // Create a TransformGroup to contain the transforms // and add the transforms to it. if (translateMatrix.Value.IsIdentity && scaleMatrix.Value.IsIdentity) { return; } if (translateMatrix.Value.IsIdentity) { this.Transform = scaleMatrix; return; } if (scaleMatrix.Value.IsIdentity) { this.Transform = translateMatrix; return; } TransformGroup transformGroup = new TransformGroup(); transformGroup.Children.Add(scaleMatrix); transformGroup.Children.Add(translateMatrix); this.Transform = transformGroup; } else if (translateMatrix != null) { this.Transform = translateMatrix; } else if (scaleMatrix != null) { this.Transform = scaleMatrix; } }
public QuickOperationMenu() { scaleTransform = new ScaleTransform(1.0, 1.0); this.LayoutTransform = scaleTransform; }
private void Window_Loaded(object sender, RoutedEventArgs e) { //카톡 개인 사진으로 찾기 //[친구들 움직이는 사진] pngImg = new BitmapImage(); pngImg.BeginInit(); pngImg.UriSource = new Uri(@"/AnimatedGifExamApp2;component/Resources/죠르디울어.png", UriKind.Relative); pngImg.EndInit(); gifImg = new BitmapImage(); gifImg.BeginInit(); gifImg.UriSource = new Uri(@"/AnimatedGifExamApp2;component/Resources/죠르디울어_m.gif", UriKind.Relative); gifImg.EndInit(); gif1.Source = pngImg; this.Topmost = true; sql.Crate_DB_File_Click(); sql.Open_DB(); sql.Crate_Table(); //sql.InsertRow("AAA", 10, 11, 12, 13); //sql.InsertRow("BBB", 11, 12, 13, 14); //sql.InsertRow("CCC", 12, 13, 14, 15); //sql.InsertRow("DDD", 13, 14, 15, 16); //sql.QueryData(); /* 부팅할 때 기본 셋팅 */ if (app.getId == null) { id = generate_id.GenerateString(10, new Random(), generate_id.GetLowerString() + generate_id.GetUpperString() + "123456789"); } else { id = app.getId; } if (app.getWidth != 0) { this.Width = app.getWidth; } if (app.getHeight != 0) { this.Height = app.getHeight; } if (app.getTop != 0) { this.Top = app.getTop; } if (app.getLeft != 0) { this.Left = app.getLeft; } if (app.getLoop) { gif_loop.IsChecked = true; gif_loop.IsCheckable = true; Loop_Animation(); } if (app.getIsBoot) { gif_boot.IsChecked = true; gif_boot.IsCheckable = true; } if (app.getFlip) { gif_filp.IsChecked = true; gif_filp.IsCheckable = true; gif1.RenderTransformOrigin = new Point(0.5, 0.5); ScaleTransform flipTrans = new ScaleTransform(); flipTrans.ScaleX = -1; gif1.RenderTransform = flipTrans; } if (app.getIsNew) { UpdateRow(); if (app.getIstop) { gif_top.IsCheckable = true; this.Topmost = true; } else { gif_top.IsCheckable = false; this.Topmost = false; } } else { gif_top.IsCheckable = true; this.Topmost = true; } }
public void AddItem(UIElement item) { Contract.Requires <ArgumentNullException>(item != null); Debug.Assert(VisualTreeHelper.GetParent(item) == null, "item", "item should not have a parent"); m_elements.Add(item); this.AddVisualChild(item); this.InvalidateMeasure(); item.RenderTransformOrigin = new Point(.5, .5); TransformGroup group = new TransformGroup(); group.Children.Add(new ScaleTransform(.6, .6)); ScaleTransform animatedScale = new ScaleTransform(); group.Children.Add(animatedScale); RotateTransform rotateTransform = new RotateTransform(); group.Children.Add(rotateTransform); group.Children.Add(new TranslateTransform()); item.RenderTransform = group; if (m_elements.Count >= c_maxCount) { int oldestCount = m_elements.Count - c_maxCount; for (int i = 0; i < oldestCount; i++) { UIElement oldest = m_elements[0]; m_fadingElements.Add(oldest); m_elements.RemoveAt(0); DoubleAnimation fadeOut = GetFadeOutAnimation(); fadeOut.Completed += delegate(object sender, EventArgs e) { m_fadingElements.Remove(oldest); this.RemoveVisualChild(oldest); }; oldest.BeginAnimation(UIElement.OpacityProperty, fadeOut); } } DoubleAnimation rotationAnimation = GetRandomRotateAnimation(); rotateTransform.BeginAnimation(RotateTransform.AngleProperty, rotationAnimation); DoubleAnimation fadeIn = GetFadeInAnimation(); item.BeginAnimation(UIElement.OpacityProperty, fadeIn); DoubleAnimation shrink = GetShrinkAnimation(); animatedScale.BeginAnimation(ScaleTransform.ScaleXProperty, shrink); animatedScale.BeginAnimation(ScaleTransform.ScaleYProperty, shrink); }
/// <summary> /// Generate the stereogram. Does all the common functionality, then calls the delegate /// set by the subclass to do the actual work. /// </summary> public Stereogram Generate() { // Let's do some profiling System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch(); timer.Start(); // Convert texture to RGB24 and scale it to fit the separation (preserving ratio but doubling width for HQ mode) bmTexture = texture.GetToScaleAndFormat(textureWidth, textureHeight, PixelFormats.Pbgra32); // Resize the depthmap to our target resolution bmDepthMap = depthmap.GetToScale(depthWidth, resolutionY); // Create a great big 2D array to hold the bytes - wasteful but convenient // ... and necessary for parallelisation pixels = new UInt32[lineWidth * rows]; // Copy the texture data into a buffer texturePixels = new UInt32[textureWidth * textureHeight]; bmTexture.CopyPixels(new Int32Rect(0, 0, textureWidth, textureHeight), texturePixels, textureWidth * bytesPerPixel, 0); // Copy the depthmap data into a buffer depthBytes = new byte[depthWidth * rows]; bmDepthMap.CopyPixels(new Int32Rect(0, 0, depthWidth, rows), depthBytes, depthWidth, 0); // Can mock up a progress indicator GeneratedLines = 0; // Prime candidate for Parallel.For... yes, about doubles the speed of generation on my Quad-Core if (System.Diagnostics.Debugger.IsAttached) // Don't run parallel when debugging { for (int y = 0; y < rows; y++) { DoLine(y); if (y > GeneratedLines) { GeneratedLines = y; } } } else { Parallel.For(0, rows, y => { if (false == abort) { DoLine(y); } if (y > GeneratedLines) { GeneratedLines = y; } }); } if (abort) { return(null); } // Virtual finaliser... not needed for any current algorithms Finalise(); // Create a writeable bitmap to dump the stereogram into wbStereogram = new WriteableBitmap(lineWidth, resolutionY, 96.0, 96.0, bmTexture.Format, bmTexture.Palette); wbStereogram.WritePixels(new Int32Rect(0, 0, lineWidth, rows), pixels, lineWidth * bytesPerPixel, 0); BitmapSource bmStereogram = wbStereogram; // High quality images need to be scaled back down... if (oversample > 1) { double over = (double)oversample; double centre = lineWidth / 2; while (over > 1) { // Scale by steps... could do it in one pass, but quality would depend on what the hardware does? double div = Math.Min(over, 2.0); // double div = over; ScaleTransform scale = new ScaleTransform(1.0 / div, 1.0, centre, 0); bmStereogram = new TransformedBitmap(bmStereogram, scale); over /= div; centre /= div; } } if (bAddConvergenceDots) { // Because I made these fields read-only, I can't now restore them... 'spose I could add the dots at hi-res but I'd still need to account for the stretching double sep = separation / oversample; double mid = midpoint / oversample; RenderTargetBitmap rtStereogram = new RenderTargetBitmap(bmStereogram.PixelWidth, bmStereogram.PixelHeight, 96.0, 96.0, PixelFormats.Pbgra32); DrawingVisual dots = new DrawingVisual(); DrawingContext dc = dots.RenderOpen(); dc.DrawImage(bmStereogram, new Rect(0.0, 0.0, rtStereogram.Width, rtStereogram.Height)); dc.DrawEllipse(new SolidColorBrush(Colors.Black), new Pen(new SolidColorBrush(Color.FromArgb(128, 0, 0, 0)), 1.0), new Point(mid - sep / 2, rtStereogram.Height / 16), sep / 16, sep / 16); dc.DrawEllipse(new SolidColorBrush(Colors.Black), new Pen(new SolidColorBrush(Color.FromArgb(128, 0, 0, 0)), 1.0), new Point(mid + sep / 2, rtStereogram.Height / 16), sep / 16, sep / 16); dc.Close(); rtStereogram.Render(dots); bmStereogram = rtStereogram; } // Freeze the bitmap so it can be passed to other threads bmStereogram.Freeze(); timer.Stop(); Stereogram stereogram = new Stereogram(bmStereogram); stereogram.options = this.options; stereogram.Name = String.Format("{0}+{1}+{2}", depthmap.Name, texture.Name, options.algorithm.ToString()); stereogram.Milliseconds = timer.ElapsedMilliseconds; return(stereogram); }
/* * 显示大图 */ public static void showBigImage(string imagePath, DControlDto ctl, Grid mainContainer, Cfg cfg) { FrameworkElement bigImageElement = FrameworkElementUtil.getByName(mainContainer, "bigImageCanvas"); if (bigImageElement == null) { Canvas bigImageCanvas = new Canvas(); bigImageCanvas.Name = "bigImageCanvas"; bigImageCanvas.Width = cfg.screenWidth; bigImageCanvas.Height = cfg.screenHeight; bigImageCanvas.Background = Brushes.Transparent; Panel.SetZIndex(bigImageCanvas, 10002); //图片背景,点击隐藏 Border borderBg = new Border(); borderBg.Width = cfg.screenWidth; borderBg.Height = cfg.screenHeight; borderBg.Background = Brushes.Black; borderBg.Opacity = 0.6; borderBg.HorizontalAlignment = HorizontalAlignment.Left; borderBg.VerticalAlignment = VerticalAlignment.Top; borderBg.SetValue(Canvas.LeftProperty, 0.0); borderBg.SetValue(Canvas.TopProperty, 0.0); Panel.SetZIndex(borderBg, 1); bigImageCanvas.Children.Add(borderBg); //显示大图 double maxWidth = cfg.screenWidth * 0.9; double maxHeight = cfg.screenHeight * 0.9; string img = FileUtil.notExistsShowDefault(imagePath, Params.ImageNotExists); BitmapImage bitmapImage = FileUtil.readImage(AppDomain.CurrentDomain.BaseDirectory + img); double showWidth = bitmapImage.Width; double showHeight = bitmapImage.Height; double w = bitmapImage.Width / maxWidth; double h = bitmapImage.Height / maxHeight; if (w > 1 && h > 1) { if (w > h) { showWidth = maxWidth; showHeight = bitmapImage.Height / w; } else { showHeight = maxHeight; showWidth = bitmapImage.Width / h; } } else if (w > 1) { showWidth = maxWidth; showHeight = bitmapImage.Height / w; } else if (h > 1) { showHeight = maxHeight; showWidth = bitmapImage.Width / h; } Canvas innerCanvas = new Canvas(); innerCanvas.Width = showWidth; innerCanvas.Height = showHeight; double left = ctl.left; double top = ctl.top; innerCanvas.SetValue(Canvas.LeftProperty, left); innerCanvas.SetValue(Canvas.TopProperty, top); Panel.SetZIndex(innerCanvas, 2); Image image = new Image(); image.Source = bitmapImage; image.Width = showWidth; image.Height = showHeight; Panel.SetZIndex(image, 1); innerCanvas.Children.Add(image); Button closebtn = new Button(); closebtn.Background = new ImageBrush { ImageSource = FileUtil.readImage(AppDomain.CurrentDomain.BaseDirectory + "/myfile/sysimg/ico-image-close.png") , Stretch = Stretch.Fill }; closebtn.Width = 50; closebtn.Height = 50; closebtn.BorderThickness = new Thickness(0); closebtn.HorizontalAlignment = HorizontalAlignment.Right; closebtn.VerticalAlignment = VerticalAlignment.Top; closebtn.SetValue(Canvas.RightProperty, -25.0); closebtn.SetValue(Canvas.TopProperty, -25.0); Panel.SetZIndex(closebtn, 2); closebtn.Click += (sender, e) => imageCloseBtnClick(bigImageCanvas, borderBg, innerCanvas, ctl, mainContainer); closebtn.PreviewTouchDown += imageCloseBtnTouchDown; closebtn.PreviewTouchMove += imageCloseBtnTouchMove; closebtn.PreviewTouchUp += (sender, e) => imageCloseBtnClick(bigImageCanvas, borderBg, innerCanvas, ctl, mainContainer); innerCanvas.Children.Add(closebtn); bigImageCanvas.Children.Add(innerCanvas); borderBg.PreviewMouseUp += (sender, e) => imageCloseBtnClick(bigImageCanvas, borderBg, innerCanvas, ctl, mainContainer); borderBg.PreviewTouchUp += (sender, e) => imageCloseBtnClick(bigImageCanvas, borderBg, innerCanvas, ctl, mainContainer); //手指缩放 移动 旋转 BehaviorCollection behaviors = Interaction.GetBehaviors(innerCanvas); TranslateZoomRotateBehavior tz = new TranslateZoomRotateBehavior(); tz.TranslateFriction = 0.3; tz.RotationalFriction = 0.4; tz.ConstrainToParentBounds = true; tz.SupportedGestures = ManipulationModes.All; behaviors.Add(tz); TransformGroup group = new TransformGroup(); double scaleX = ctl.width / innerCanvas.Width; double scaleY = ctl.height / innerCanvas.Height; ScaleTransform scaleTransform = new ScaleTransform(); scaleTransform.ScaleX = scaleX; scaleTransform.ScaleY = scaleY; group.Children.Add(scaleTransform); innerCanvas.RenderTransform = group; //动画,平移到指定位置 double toLeft = (cfg.screenWidth - innerCanvas.Width) / 2; double toTop = (cfg.screenHeight - innerCanvas.Height) / 2; double toTranslateTransformX = toLeft - ctl.left; double toTranslateTransformY = toTop - ctl.top; ShowBigImageUtil.showAnimation(borderBg, innerCanvas, ctl, toTranslateTransformX, toTranslateTransformY); mainContainer.Children.Add(bigImageCanvas); } }
public void AddGraphPort(IGraphPort aPort) { SetPixelHandler += new NewTOAPIA.Drawing.SetPixel(aPort.SetPixel); DrawLineHandler += new DrawLine(aPort.DrawLine); DrawLinesHandler += new DrawLines(aPort.DrawLines); DrawRectangleHandler += new NewTOAPIA.Drawing.DrawRectangle(aPort.DrawRectangle); DrawRectanglesHandler += new NewTOAPIA.Drawing.DrawRectangles(aPort.DrawRectangles); FillRectangleHandler += new NewTOAPIA.Drawing.FillRectangle(aPort.FillRectangle); DrawEllipseHandler += new NewTOAPIA.Drawing.DrawEllipse(aPort.DrawEllipse); FillEllipseHandler += new NewTOAPIA.Drawing.FillEllipse(aPort.FillEllipse); DrawRoundRectHandler += new NewTOAPIA.Drawing.DrawRoundRect(aPort.DrawRoundRect); PolygonHandler += new NewTOAPIA.Drawing.Polygon(aPort.Polygon); DrawBeziersHandler += new NewTOAPIA.Drawing.DrawBeziers(aPort.DrawBeziers); DrawPathHandler += new NewTOAPIA.Drawing.DrawPath(aPort.DrawPath); FillPathHandler += new FillPath(aPort.FillPath); //// Gradient fills //DrawGradientRectangleHandler += new NewTOAPIA.Drawing.DrawGradientRectangle(aPort.DrawGradientRectangle); //// Drawing Text DrawStringHandler += new NewTOAPIA.Drawing.DrawString(aPort.DrawString); ///// Draw bitmaps PixBltHandler += new NewTOAPIA.Drawing.PixBlt(aPort.PixBlt); //PixmapShardBltHandler += new NewTOAPIA.Drawing.PixmapShardBlt(aPort.PixmapShardBlt); //AlphaBlendHandler += new NewTOAPIA.Drawing.AlphaBlend(aPort.AlphaBlend); // Path handling //DrawPathHandler += new NewTOAPIA.Drawing.DrawPath(aPort.DrawPath); //SetPathAsClipRegionHandler += new NewTOAPIA.Drawing.SetPathAsClipRegion(aPort.SetPathAsClipRegion); //// Setting some objects SetPenHandler += new NewTOAPIA.Drawing.SetPen(aPort.SetPen); SetBrushHandler += new SetBrush(aPort.SetBrush); SetFontHandler += new SetFont(aPort.SetFont); //SelectStockObjectHandler += new NewTOAPIA.Drawing.SelectStockObject(aPort.SelectStockObject); SelectUniqueObjectHandler += new NewTOAPIA.Drawing.SelectUniqueObject(aPort.SelectUniqueObject); //// State Management FlushHandler += new NewTOAPIA.Drawing.Flush(aPort.Flush); SaveStateHandler += new NewTOAPIA.Drawing.SaveState(aPort.SaveState); ResetStateHandler += new NewTOAPIA.Drawing.ResetState(aPort.ResetState); RestoreStateHandler += new NewTOAPIA.Drawing.RestoreState(aPort.RestoreState); //// Setting Attributes and modes SetTextColorHandler += new NewTOAPIA.Drawing.SetTextColor(aPort.SetTextColor); //// Setting some modes SetBkColorHandler += new NewTOAPIA.Drawing.SetBkColor(aPort.SetBkColor); SetBkModeHandler += new NewTOAPIA.Drawing.SetBkMode(aPort.SetBkMode); SetMappingModeHandler += new NewTOAPIA.Drawing.SetMappingMode(aPort.SetMappingMode); SetPolyFillModeHandler += new NewTOAPIA.Drawing.SetPolyFillMode(aPort.SetPolyFillMode); SetROP2Handler += new NewTOAPIA.Drawing.SetROP2(aPort.SetROP2); SetClipRectangleHandler += new SetClipRectangle(aPort.SetClipRectangle); // World transform management SetWorldTransformHandler += new NewTOAPIA.Drawing.SetWorldTransform(aPort.SetWorldTransform); TranslateTransformHandler += new TranslateTransform(aPort.TranslateTransform); ScaleTransformHandler += new ScaleTransform(aPort.ScaleTransform); RotateTransformHandler += new RotateTransform(aPort.RotateTransform); }