void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:

            #line 9 "..\..\..\Environment\GetEnvVarDesigner.xaml"
                ((RPA.Core.Activities.EnvironmentActivity.GetEnvVarDesigner)(target)).Loaded += new System.Windows.RoutedEventHandler(this.IcoPath_Loaded);

            #line default
            #line hidden
                return;

            case 2:
                this.icoPath = ((System.Windows.Media.ImageDrawing)(target));
                return;

            case 3:
                this.expressTextBox = ((System.Activities.Presentation.View.ExpressionTextBox)(target));
                return;

            case 4:
                this.comboBox = ((System.Windows.Controls.ComboBox)(target));

            #line 50 "..\..\..\Environment\GetEnvVarDesigner.xaml"
                this.comboBox.SelectionChanged += new System.Windows.Controls.SelectionChangedEventHandler(this.comboBox_SelectionChanged);

            #line default
            #line hidden
                return;
            }
            this._contentLoaded = true;
        }
Example #2
0
        public Drawing Teken_jezelf()
        {
            ImageSource imageSource;
            ImageDrawing bulletDrawing;

            switch (_direction)
            {
                case Direction.Up:
                    imageSource = Resources.GetImage("SenneGameWpf", "images/projectiles/bullet_up.png");
                    Formaat = new Size(1, 3);
                    bulletDrawing = new ImageDrawing(imageSource, new Rect(_locatie.X, _locatie.Y - 3, 1, 3));
                    break;
                case Direction.Down:
                    imageSource = Resources.GetImage("SenneGameWpf", "images/projectiles/bullet_down.png");
                    Formaat = new Size(1, 3);
                    bulletDrawing = new ImageDrawing(imageSource, new Rect(_locatie.X, _locatie.Y, 1, 3));
                    break;
                case Direction.Left:
                    imageSource = Resources.GetImage("SenneGameWpf", "images/projectiles/bullet_left.png");
                    Formaat = new Size(3, 1);
                    bulletDrawing = new ImageDrawing(imageSource, new Rect(_locatie.X - 3, _locatie.Y, 3, 1));
                    break;
                case Direction.Right:
                    imageSource = Resources.GetImage("SenneGameWpf", "images/projectiles/bullet_right.png");
                    Formaat = new Size(3, 1);
                    bulletDrawing = new ImageDrawing(imageSource, new Rect(_locatie.X, _locatie.Y, 3, 1));
                    break;
                default:
                    bulletDrawing = null;
                    break;
            }

            return bulletDrawing;
        }
Example #3
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:

            #line 10 "..\..\..\..\Excel\Ope_Cell\CellMergeDesigner.xaml"
                ((RPA.Integration.Activities.ExcelPlugins.CellMergeDesigner)(target)).Loaded += new System.Windows.RoutedEventHandler(this.IcoPath_Loaded);

            #line default
            #line hidden
                return;

            case 2:
                this.icoPath = ((System.Windows.Media.ImageDrawing)(target));
                return;

            case 3:
                this.grid1 = ((System.Windows.Controls.Grid)(target));
                return;

            case 4:
                this.expressTextBox = ((System.Activities.Presentation.View.ExpressionTextBox)(target));
                return;

            case 5:
                this.expressTextBox_Copy = ((System.Activities.Presentation.View.ExpressionTextBox)(target));
                return;
            }
            this._contentLoaded = true;
        }
Example #4
0
        public void Init()
        {
            DrawingGroup dg = new DrawingGroup();
            ImageDrawing id = new ImageDrawing(UnderlayImage, new Rect(0, 0, UnderlayImage.PixelWidth, UnderlayImage.PixelHeight));
            dg.Children.Add(id);

            pointsGeometryGroup = new GeometryGroup();
            linesGeometryGroup = new GeometryGroup();
            middlePointGeoGrp = new GeometryGroup();
            if (points != null)
            {
                SetPointsGeometry();
            }

            GeometryDrawing gd = new GeometryDrawing(Brushes.Blue, null, pointsGeometryGroup);
            dg.Children.Add(gd);

            GeometryDrawing gd2 = new GeometryDrawing(null, new Pen(Brushes.LightGreen,3), linesGeometryGroup);
            dg.Children.Add(gd2);

            GeometryDrawing gd1 = new GeometryDrawing(Brushes.Red, null, middlePointGeoGrp);
            dg.Children.Add(gd1);

            Brush b = new SolidColorBrush(Colors.Red);
            b.Opacity = 0.5;
            mousePointGeometryDrwaing = new GeometryDrawing(b, null, null);
            dg.Children.Add(mousePointGeometryDrwaing);

            DrawingImage di = new DrawingImage(dg);
            this.Source = di;

            chosenPoint = -1;
        }
        public ImageSource Draw()
        {
            var drawing = new DrawingGroup();

            //background
            drawing.DrawRectangle(new Rect(-5, -210, 300, 220), Brushes.White, new Pen(Brushes.AntiqueWhite, 1));

            drawing.DrawLine(new Point(-5, 0), new Point(295, 0), Brushes.AntiqueWhite);

            //5 point marker
            drawing.DrawLine(new Point(200, -210), new Point(200, 10), Brushes.BurlyWood);
            drawing.DrawText(201, -107, "5");

            //10 point marker
            drawing.DrawLine(new Point(220, -210), new Point(220, 10), Brushes.BurlyWood);
            drawing.DrawText(221, -107, "10");

            //20 point marker
            drawing.DrawLine(new Point(240, -210), new Point(240, 10), Brushes.BurlyWood);
            drawing.DrawText(241, -107, "20");

            //50 point marker
            drawing.DrawLine(new Point(260, -210), new Point(260, 10), Brushes.BurlyWood);
            drawing.DrawText(261, -107, "50");
            drawing.DrawLine(new Point(280, -210), new Point(280, 10), Brushes.BurlyWood);
            drawing.DrawText(281, -107, "0");

            //disc
            drawing.DrawCircle(_cannonballPosition, 1.5, Brushes.Black);

            var imageDrawing = new ImageDrawing(ResourceProvider.GetImage(Images.Cannon), new Rect(0, -25, 34.0, 24.4));
            drawing.Children.Add(imageDrawing);

            return new DrawingImage(drawing);
        }
Example #6
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:

            #line 10 "..\..\..\..\Word\Ope_Settings\SettingsDesigner.xaml"
                ((RPA.Integration.Activities.WordPlugins.SettingsDesigner)(target)).Loaded += new System.Windows.RoutedEventHandler(this.IcoPath_Loaded);

            #line default
            #line hidden
                return;

            case 2:
                this.icoPath = ((System.Windows.Media.ImageDrawing)(target));
                return;

            case 3:
                this.grid1 = ((System.Windows.Controls.Grid)(target));
                return;

            case 4:
                this.urlTextBox = ((System.Windows.Controls.TextBox)(target));
                return;
            }
            this._contentLoaded = true;
        }
Example #7
0
 public void ShowMidPoint()
 {
     DrawingGroup dg = new DrawingGroup();
     ImageDrawing id = new ImageDrawing(UnderlayImage, new Rect(0, 0, UnderlayImage.PixelWidth, UnderlayImage.PixelHeight));
     dg.Children.Add(id);
     GeometryDrawing gd1 = new GeometryDrawing(Brushes.Red, null, middlePointGeoGrp);
     dg.Children.Add(gd1);
     DrawingImage di = new DrawingImage(dg);
     this.Source = di;
 }
Example #8
0
        /// <summary>
        /// Return image for gate (not currently used)
        /// </summary>
        /// <param name="gate"></param>
        /// <returns></returns>
        private System.Windows.Media.ImageDrawing DrawGate(string gate, Rect bounds)
        {
            System.Windows.Media.ImageDrawing gateImage = new System.Windows.Media.ImageDrawing();
            string uriString = "Gate Images\\";

            uriString            += gate;
            uriString            += ".gif";
            gateImage.ImageSource = new System.Windows.Media.Imaging.BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + uriString));
            gateImage.Rect        = bounds;
            return(gateImage);
        }
Example #9
0
		public void AddImage(string path, TileMode tile = TileMode.None, Rect? targetArea = null, Stretch stretch = Stretch.Fill, Rectangle rect = null, UriKind kind = UriKind.Relative)
		{
			BitmapImage bm = new BitmapImage(new Uri(path, kind));
			UIElement el = null;
			if (tile != TileMode.None && rect == null)
			{
				Rectangle r = new Rectangle();
				if (targetArea.HasValue)
				{
					r.Width = targetArea.Value.Width;
					r.Height = targetArea.Value.Height;
				}
				else
				{
					r.Width = this.ActualWidth;
					r.Height = this.ActualHeight;
				}
				Rect rr = new Rect();
				rr.Width = bm.PixelWidth;
				rr.Height = bm.PixelHeight;
				ImageDrawing d = new ImageDrawing(bm, rr);
				DrawingBrush brush = new DrawingBrush(d);
				brush.Viewport = rr;
				brush.ViewportUnits = BrushMappingMode.Absolute;
				brush.TileMode = tile;
				brush.Stretch = Stretch.Fill;
				r.Fill = brush;
				el = r;
			}
			else
			{
				Image img = new Image();
				img.Width = bm.Width;
				img.Height = bm.Height;
				img.Source = bm;
				el = img;
			}
			RenderCanvas.Children.Add(el);
			if (targetArea.HasValue)
			{
				Canvas.SetLeft(el, targetArea.Value.X);
				Canvas.SetTop(el, targetArea.Value.Y);
			}
			else
			{
				Canvas.SetLeft(el, 0);
				Canvas.SetTop(el, 0);
			}
		}
Example #10
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:

            #line 9 "..\..\..\..\Excel\Ope_Process\ExcelCreateDesigner.xaml"
                ((RPA.Integration.Activities.ExcelPlugins.ExcelCreateDesigner)(target)).Loaded += new System.Windows.RoutedEventHandler(this.IcoPath_Loaded);

            #line default
            #line hidden
                return;

            case 2:
                this.icoPath = ((System.Windows.Media.ImageDrawing)(target));
                return;

            case 3:
                this.expressTextBox = ((System.Activities.Presentation.View.ExpressionTextBox)(target));
                return;

            case 4:
                this.getUrlButton = ((System.Windows.Controls.Button)(target));

            #line 45 "..\..\..\..\Excel\Ope_Process\ExcelCreateDesigner.xaml"
                this.getUrlButton.Click += new System.Windows.RoutedEventHandler(this.PathSelect);

            #line default
            #line hidden
                return;

            case 5:
                this.expressTextBox1 = ((System.Activities.Presentation.View.ExpressionTextBox)(target));
                return;

            case 6:
                this.getUrlButton1 = ((System.Windows.Controls.Button)(target));

            #line 60 "..\..\..\..\Excel\Ope_Process\ExcelCreateDesigner.xaml"
                this.getUrlButton1.Click += new System.Windows.RoutedEventHandler(this.ShowSaveFileDialog);

            #line default
            #line hidden
                return;
            }
            this._contentLoaded = true;
        }
 void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
     switch (connectionId)
     {
     case 1:
     
     #line 11 "..\..\..\..\Excel\Ope_RowCol\InsertRowColDesigner.xaml"
     ((RPA.Integration.Activities.ExcelPlugins.InsertRowColDesigner)(target)).Loaded += new System.Windows.RoutedEventHandler(this.IcoPath_Loaded);
     
     #line default
     #line hidden
     return;
     case 2:
     this.icoPath = ((System.Windows.Media.ImageDrawing)(target));
     return;
     }
     this._contentLoaded = true;
 }
Example #12
0
        private void UpdateDebugInfo(object sender, EventArgs e)
        {
            if (m_bWaitThread && Singleton<BusinessLogic>.Instance.ThreadHasFinished())
            {
                m_bWaitThread = false;
                Info.Content = "完成";

                m_timer.Stop();
                m_timer = null;

                // 随便画画
                DrawingGroup imageDrawings = new DrawingGroup();

                Card[] cards = Singleton<CardRepository>.Instance.Cards;
                for (int i = 0; i < cards.Length; ++i)
                {
                    ImageDrawing image = new ImageDrawing();
                    image.Rect = new Rect(i * 50, 50, 150, 200);
                    image.ImageSource = new BitmapImage(new Uri(cards[i].ImagePath, UriKind.Relative));

                    imageDrawings.Children.Add(image);
                }

                DrawingImage drawingImageSource = new DrawingImage(imageDrawings);
                drawingImageSource.Freeze();

                Image imageControl = new Image();
                imageControl.Stretch = Stretch.None;
                imageControl.Source = drawingImageSource;

                Border imageBorder = new Border();
                imageBorder.BorderBrush = Brushes.Gray;
                imageBorder.BorderThickness = new Thickness(1);
                imageBorder.HorizontalAlignment = HorizontalAlignment.Left;
                imageBorder.VerticalAlignment = VerticalAlignment.Top;
                imageBorder.Margin = new Thickness(20);
                imageBorder.Child = imageControl;

                CardsBrowser.Content = imageBorder;
            }
            else
            {
                Info.Content = m_strMsg;
            }
        }
        //------------------------------------------------------
        //
        //  Public Properties
        //
        //------------------------------------------------------

        private static void ImageSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            // The first change to the default value of a mutable collection property (e.g. GeometryGroup.Children)
            // will promote the property value from a default value to a local value. This is technically a sub-property
            // change because the collection was changed and not a new collection set (GeometryGroup.Children.
            // Add versus GeometryGroup.Children = myNewChildrenCollection). However, we never marshalled
            // the default value to the compositor. If the property changes from a default value, the new local value
            // needs to be marshalled to the compositor. We detect this scenario with the second condition
            // e.OldValueSource != e.NewValueSource. Specifically in this scenario the OldValueSource will be
            // Default and the NewValueSource will be Local.
            if (e.IsASubPropertyChange &&
                (e.OldValueSource == e.NewValueSource))
            {
                return;
            }


            ImageDrawing target = ((ImageDrawing)d);


            ImageSource oldV = (ImageSource)e.OldValue;
            ImageSource newV = (ImageSource)e.NewValue;

            System.Windows.Threading.Dispatcher dispatcher = target.Dispatcher;

            if (dispatcher != null)
            {
                DUCE.IResource targetResource = (DUCE.IResource)target;
                using (CompositionEngineLock.Acquire())
                {
                    int channelCount = targetResource.GetChannelCount();

                    for (int channelIndex = 0; channelIndex < channelCount; channelIndex++)
                    {
                        DUCE.Channel channel = targetResource.GetChannel(channelIndex);
                        Debug.Assert(!channel.IsOutOfBandChannel);
                        Debug.Assert(!targetResource.GetHandle(channel).IsNull);
                        target.ReleaseResource(oldV, channel);
                        target.AddRefResource(newV, channel);
                    }
                }
            }

            target.PropertyChanged(ImageSourceProperty);
        }
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:

            #line 9 "..\..\..\Orchestrator\GetCredentialDesigner.xaml"
                ((RPA.Core.Activities.OrchestratorActivity.GetCredentialDesigner)(target)).Loaded += new System.Windows.RoutedEventHandler(this.IcoPath_Loaded);

            #line default
            #line hidden
                return;

            case 2:
                this.icoPath = ((System.Windows.Media.ImageDrawing)(target));
                return;
            }
            this._contentLoaded = true;
        }
Example #15
0
        /// <summary>
        /// Creates a new instance of an ExtendedTextbox.
        /// </summary>
        /// <param name="iconPath">path to the icon that should be displayed.</param>
        /// <param name="watermarkText">The watermark text.</param>
        /// <param name="regexCondition">The regularexpresion that should be validated.</param>
        /// <param name="required">Whether this textbox needs a content.</param>
        /// <param name="parentForm">The form in which this textbox is located.</param>
        public ExtendedTextBox(string iconPath, string watermarkText, string regexCondition, bool required, DynamicForm parentForm)
        {
            InitializeComponent();
            this._parentForm = parentForm;
            this._required = required;
            this._watermarkText = watermarkText;

            // Initiate most of the content áfter everything is loaded.
            // This is necessary to know the textboxes width and height.
            this.Loaded += (object sender, RoutedEventArgs args) =>
            {
                int image_width = 0;

                if (File.Exists(iconPath))
                {
                    BitmapImage bmp = new BitmapImage(new Uri(iconPath));
                    image_width = (int)((this.ActualHeight * bmp.PixelWidth) / bmp.PixelHeight);
                    ImageDrawing i = new ImageDrawing(bmp, new Rect(new Size(image_width, this.ActualHeight)));

                    img.Source = new DrawingImage(i);
                }

                watermark.Text = watermarkText;
                watermark.Foreground = new SolidColorBrush(Color.FromArgb(128, 0, 0, 0));

                _regeExpr = new Regex(regexCondition);

                TextBlock.LostFocus += CheckWatermark;
                TextBlock.LostFocus += CheckRegex;
                TextBlock.TextChanged += CheckWatermark;
                TextBlock.TextChanged += CheckRegex;
                TextBlock.GotFocus += RemoveWatermark;
                TextBlock.GotFocus += CheckRegex;

                CheckWatermark(this, EventArgs.Empty);
            };

        }
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:

            #line 10 "..\..\..\..\Word\Ope_Write\InsertFileDesigner.xaml"
                ((RPA.Integration.Activities.WordPlugins.InsertFileDesigner)(target)).Loaded += new System.Windows.RoutedEventHandler(this.IcoPath_Loaded);

            #line default
            #line hidden
                return;

            case 2:
                this.icoPath = ((System.Windows.Media.ImageDrawing)(target));
                return;

            case 3:
                this.grid1 = ((System.Windows.Controls.Grid)(target));
                return;

            case 4:
                this.expressTextBox = ((System.Activities.Presentation.View.ExpressionTextBox)(target));
                return;

            case 5:
                this.getUrlButton = ((System.Windows.Controls.Button)(target));

            #line 47 "..\..\..\..\Word\Ope_Write\InsertFileDesigner.xaml"
                this.getUrlButton.Click += new System.Windows.RoutedEventHandler(this.PathSelect);

            #line default
            #line hidden
                return;
            }
            this._contentLoaded = true;
        }
Example #17
0
        protected override Size ArrangeOverride(Size arrangeBounds)
        {
            Debug.Print("Arrange");

            var columns = (int)(arrangeBounds.Width / m_tileSize);
            var rows = (int)(arrangeBounds.Height / m_tileSize);

            if (columns != m_columns || rows != m_rows)
            {
                m_columns = columns;
                m_rows = rows;

                var bmp = m_symbolBitmapCache.GetBitmap(SymbolID.Undefined, Colors.Black, false);

                var drawingCollection = new DrawingCollection();

                for (int y = 0; y < m_rows; ++y)
                {
                    for (int x = 0; x < m_columns; ++x)
                    {
                        var imageDrawing = new ImageDrawing(bmp, new Rect(new Point(x * m_tileSize, y * m_tileSize),
                            new Size(m_tileSize, m_tileSize)));
                        drawingCollection.Add(imageDrawing);
                        imageDrawing = new ImageDrawing(bmp, new Rect(new Point(x * m_tileSize, y * m_tileSize),
                            new Size(m_tileSize, m_tileSize)));
                        drawingCollection.Add(imageDrawing);
                    }
                }

                var drawingGroup = new DrawingGroup();
                drawingGroup.Children = drawingCollection;
                m_drawing = drawingGroup;
            }

            Render();

            return base.ArrangeOverride(arrangeBounds);
        }
        private static ImageSource _GetFramedImage(ImageSource usertile, ImageSource overlay, int dimensions)
        {
            FrameMetric metric = _GetMetric(dimensions);
            var drawingGroup = new DrawingGroup();

            var frameDrawing = new ImageDrawing
            {
                Rect = new Rect(0, 0, metric.Width, metric.Height),
                ImageSource = new BitmapImage(metric.Path)
            };

            var tileDrawing = new ImageDrawing();
            if (null == usertile)
            {
                usertile = new BitmapImage(_emptyUserTileUri);
            }

            tileDrawing.Rect = _GetScaledRect(metric.BoundingFrame, usertile.Width, usertile.Height);
            tileDrawing.ImageSource = usertile;

            ImageDrawing overlayDrawing = null;
            if (null != overlay)
            {
                overlayDrawing = new ImageDrawing
                {
                    Rect = (metric.Width > 32
                        ? new Rect(0, metric.Height*2/3, metric.Width*1/3, metric.Height*1/3)
                        : new Rect(0, metric.Height*1/2, metric.Width*1/2, metric.Height*1/2)),
                    ImageSource = overlay
                };
            }

            // The frame has an alpha overlay in the middle.
            // Blit it second to get the bevel effect.
            drawingGroup.Children.Add(tileDrawing);
            drawingGroup.Children.Add(frameDrawing);
            if (null != overlayDrawing)
            {
                drawingGroup.Children.Add(overlayDrawing);
            }

            var compositeImage = new DrawingImage(drawingGroup);
            compositeImage.Freeze();
            return compositeImage;
        }
Example #19
0
 /// <summary>
 /// Actualiza los fondos de los generos desde archivo(fotos y colores-archivo "background en carpeta:Images"-)
 /// </summary>
 public void UpdateBackGround()
 {
     BackGrounds = new SortedList<string, Brush>();
     BackGroundsStrings=new SortedList<string, string>();
     BackGround = Brushes.MediumOrchid;
     var dirbg = CurrentDirectory + DirBackGround + "background";
     if (File.Exists(dirbg))
     {
         SortedList<string, byte[]> temp = Util.DeserializeBrushes(dirbg);
         if (temp != null)
         {
             BackGrounds = Util.ByteToBrush(temp);
         }
     }
     if ((Genres != null && Genres.Count != 0))
     {
         foreach (string t in Genres)
         {
             var dir = CurrentDirectory + DirBackGround + t;
             if (File.Exists(dir))
             {
                 var imageDrawing = new ImageDrawing {Rect = new Rect(0, 0, 150, 100)};
                 var image = new BitmapImage();
                 image.BeginInit();
                 image.StreamSource = new FileStream(dir, FileMode.Open, FileAccess.Read,FileShare.ReadWrite);
                 image.EndInit();
                 BitmapImages.Add(image);
                 imageDrawing.ImageSource = image;
                 if (BackGrounds.ContainsKey(t))
                 {
                     BackGrounds[t] = new DrawingBrush(imageDrawing);
                     BackGroundsStrings[t] = dir;
                 }
                 else
                 {
                     BackGrounds.Add(t, new DrawingBrush(imageDrawing));
                     BackGroundsStrings.Add(t,dir);
                 }
             }
         }
         if (BackGrounds.ContainsKey(SelectedGenre))
             BackGround = BackGrounds[SelectedGenre];
     }
 }
Example #20
0
        private DrawingGroup LoadGroup(IList<Shape> elements, Rect? viewBox)
        {
            List<ControlLine> debugPoints = new List<ControlLine>();
            DrawingGroup grp = new DrawingGroup();

            if (viewBox.HasValue) grp.ClipGeometry = new RectangleGeometry(viewBox.Value);

            foreach (Shape shape in elements)
            {
                if (shape is UseShape)
                {
                    UseShape useshape = shape as UseShape;
                    Group group = this.SVG.GetShape(useshape.hRef) as Group;
                    if (group != null)
                    {
                        Shape oldparent = group.Parent;
                        group.Parent = useshape; // this to get proper style propagated
                        DrawingGroup subgroup = this.LoadGroup(group.Elements, null);
                        if (group.Clip != null) subgroup.ClipGeometry = group.Clip.ClipGeometry;
                        subgroup.Transform = new TranslateTransform(useshape.X, useshape.Y);
                        grp.Children.Add(subgroup);
                        group.Parent = oldparent;
                    }
                    continue;

                }
                if (shape is Clip)
                {
                    DrawingGroup subgroup = this.LoadGroup((shape as Clip).Elements, null);
                    if (shape.Transform != null) subgroup.Transform = shape.Transform;
                    grp.Children.Add(subgroup);
                    continue;
                }
                if (shape is Group)
                {
                    DrawingGroup subgroup = this.LoadGroup((shape as Group).Elements, null);
                    if (shape.Clip != null)
                    {
                        subgroup.ClipGeometry = shape.Clip.ClipGeometry;
                    }
                    if (shape.Transform != null) subgroup.Transform = shape.Transform;
                    grp.Children.Add(subgroup);
                    continue;
                }
                if (shape is RectangleShape)
                {
                    RectangleShape r = shape as RectangleShape;
                    RectangleGeometry rect = new RectangleGeometry(new Rect(r.X, r.Y, r.Width, r.Height));
                    rect.RadiusX = r.RX;
                    rect.RadiusY = r.RY;
                    if (rect.RadiusX == 0 && rect.RadiusY > 0) rect.RadiusX = rect.RadiusY;
                    grp.Children.Add(this.NewDrawingItem(shape, rect));
                }
                if (shape is LineShape)
                {
                    LineShape r = shape as LineShape;
                    LineGeometry line = new LineGeometry(r.P1, r.P2);
                    grp.Children.Add(this.NewDrawingItem(shape, line));
                }
                if (shape is PolylineShape)
                {
                    PolylineShape r = shape as PolylineShape;
                    PathGeometry path = new PathGeometry();
                    PathFigure p = new PathFigure();
                    path.Figures.Add(p);
                    p.IsClosed = false;
                    p.StartPoint = r.Points[0];
                    for (int index = 1; index < r.Points.Length; index++)
                    {
                        p.Segments.Add(new LineSegment(r.Points[index], true));
                    }
                    grp.Children.Add(this.NewDrawingItem(shape, path));
                }
                if (shape is PolygonShape)
                {
                    PolygonShape r = shape as PolygonShape;
                    PathGeometry path = new PathGeometry();
                    PathFigure p = new PathFigure();
                    path.Figures.Add(p);
                    p.IsClosed = true;
                    p.StartPoint = r.Points[0];
                    for (int index = 1; index < r.Points.Length; index++)
                    {
                        p.Segments.Add(new LineSegment(r.Points[index], true));
                    }
                    grp.Children.Add(this.NewDrawingItem(shape, path));
                }
                if (shape is CircleShape)
                {
                    CircleShape r = shape as CircleShape;
                    EllipseGeometry c = new EllipseGeometry(new Point(r.CX, r.CY), r.R, r.R);
                    grp.Children.Add(this.NewDrawingItem(shape, c));
                }
                if (shape is EllipseShape)
                {
                    EllipseShape r = shape as EllipseShape;
                    EllipseGeometry c = new EllipseGeometry(new Point(r.CX, r.CY), r.RX, r.RY);
                    grp.Children.Add(this.NewDrawingItem(shape, c));
                }
                if (shape is ImageShape)
                {
                    ImageShape image = shape as ImageShape;
                    ImageDrawing i = new ImageDrawing(image.ImageSource, new Rect(image.X, image.Y, image.Width, image.Height));
                    grp.Children.Add(i);
                }
                if (shape is TextShape)
                {
                    GeometryGroup gp = TextRender.BuildTextGeometry(shape as TextShape);
                    if (gp != null)
                    {
                        foreach (Geometry gm in gp.Children)
                        {
                            TextShape.TSpan.Element tspan = TextRender.GetElement(gm);
                            if (tspan != null) grp.Children.Add(this.NewDrawingItem(tspan, gm));
                            else grp.Children.Add(this.NewDrawingItem(shape, gm));
                        }
                    }
                }
                if (shape is PathShape)
                {
                    PathShape r = shape as PathShape;
                    PathFigure p = null;
                    Point lastPoint = new Point(0, 0);

                    PathShape.CurveTo lastc = null;
                    Point lastcirPoint = new Point(0, 0);

                    PathGeometry path = new PathGeometry();
                    foreach (PathShape.PathElement element in r.Elements)
                    {
                        bool isRelative = element.IsRelative;
                        if (element is PathShape.MoveTo)
                        {
                            p = new PathFigure();
                            p.IsClosed = r.ClosePath;
                            if (isRelative) p.StartPoint = lastPoint + (Vector)((PathShape.MoveTo)element).Point;
                            else p.StartPoint = ((PathShape.MoveTo)element).Point;
                            lastPoint = p.StartPoint;
                            path.Figures.Add(p);
                            continue;
                        }
                        if (element is PathShape.LineTo)
                        {
                            PathShape.LineTo lineto = element as PathShape.LineTo;
                            foreach (Point point in lineto.Points)
                            {
                                if (isRelative)
                                {
                                    Point newpoint = lastPoint + (Vector)point;
                                    lastPoint = newpoint;
                                    p.Segments.Add(new LineSegment(newpoint, true));
                                }
                                else
                                {
                                    if (lineto.PositionType == PathShape.LineTo.eType.Point) lastPoint = point;
                                    if (lineto.PositionType == PathShape.LineTo.eType.Horizontal) lastPoint = new Point(point.X, lastPoint.Y);
                                    if (lineto.PositionType == PathShape.LineTo.eType.Vertical) lastPoint = new Point(lastPoint.X, point.Y);
                                    p.Segments.Add(new LineSegment(lastPoint, true));
                                }
                            }
                            continue;
                        }
                        if (element is PathShape.CurveTo)
                        {
                            PathShape.CurveTo c = element as PathShape.CurveTo;
                            Point startPoint = lastPoint;
                            BezierSegment s = new BezierSegment();
                            if (isRelative)
                            {
                                s.Point1 = lastPoint + (Vector)c.CtrlPoint1;

                                if (c.Command == 's')
                                {
                                    // first control point is a mirrored point of last end control point
                                    //s.Point1 = lastPoint + new Vector(lastc.Point.X - dx, lastc.Point.Y - dy);
                                    //s.Point1 = new Point(lastctrlpoint.X+2, lastctrlpoint.Y+2);

                                    double dx = lastc.CtrlPoint2.X - lastc.Point.X;
                                    double dy = lastc.CtrlPoint2.Y - lastc.Point.Y;
                                    s.Point1 = new Point(lastcirPoint.X - dx, lastcirPoint.Y - dy);
                                    //s.Point1 = lastctrlpoint;
                                }

                                s.Point2 = lastPoint + (Vector)c.CtrlPoint2;
                                s.Point3 = lastPoint + (Vector)c.Point;
                            }
                            else
                            {
                                if (c.Command == 'S')
                                {
                                    // first control point is a mirrored point of last end control point
                                    //s.Point1 = lastPoint + new Vector(lastc.Point.X - dx, lastc.Point.Y - dy);
                                    //s.Point1 = new Point(lastctrlpoint.X+2, lastctrlpoint.Y+2);

                                    double dx = lastc.CtrlPoint2.X - lastc.Point.X;
                                    double dy = lastc.CtrlPoint2.Y - lastc.Point.Y;
                                    s.Point1 = new Point(lastcirPoint.X - dx, lastcirPoint.Y - dy);
                                }
                                else s.Point1 = c.CtrlPoint1;
                                s.Point2 = c.CtrlPoint2;
                                s.Point3 = c.Point;
                            }
                            lastPoint = s.Point3;
                            p.Segments.Add(s);

                            lastc = c;
                            lastcirPoint = s.Point3;

                            //debugPoints.Add(new ControlLine(startPoint, s.Point1));
                            //debugPoints.Add(new ControlLine(s.Point3, s.Point2));
                            continue;
                        }
                        if (element is PathShape.EllipticalArcTo)
                        {
                            PathShape.EllipticalArcTo c = element as PathShape.EllipticalArcTo;
                            ArcSegment s = new ArcSegment();
                            if (isRelative) s.Point = lastPoint + new Vector(c.X, c.Y);
                            else s.Point = new Point(c.X, c.Y);

                            s.Size = new Size(c.RX, c.RY);
                            s.RotationAngle = c.AxisRotation;
                            s.SweepDirection = SweepDirection.Counterclockwise;
                            if (c.Clockwise) s.SweepDirection = SweepDirection.Clockwise;
                            s.IsLargeArc = c.LargeArc;
                            lastPoint = s.Point;
                            p.Segments.Add(s);
                            continue;
                        }
                    }
                    /*
                    if (r.Transform != null)
                        path.Transform = r.Transform;
                    */
                    grp.Children.Add(this.NewDrawingItem(shape, path));
                    //}
                }
            }

            if (debugPoints != null)
            {
                foreach (ControlLine line in debugPoints) grp.Children.Add(line.Draw());
            }
            return grp;
        }
Example #21
0
            private ImageSource PlatedImage(BitmapImage image)
            {
                if (!string.IsNullOrEmpty(BackgroundColor) && BackgroundColor != "transparent")
                {
                    var width = image.Width;
                    var height = image.Height;
                    var x = 0;
                    var y = 0;

                    var group = new DrawingGroup();

                    var converted = ColorConverter.ConvertFromString(BackgroundColor);
                    if (converted != null)
                    {
                        var color = (Color)converted;
                        var brush = new SolidColorBrush(color);
                        var pen = new Pen(brush, 1);
                        var backgroundArea = new Rect(0, 0, width, width);
                        var rectabgle = new RectangleGeometry(backgroundArea);
                        var rectDrawing = new GeometryDrawing(brush, pen, rectabgle);
                        group.Children.Add(rectDrawing);

                        var imageArea = new Rect(x, y, image.Width, image.Height);
                        var imageDrawing = new ImageDrawing(image, imageArea);
                        group.Children.Add(imageDrawing);

                        // http://stackoverflow.com/questions/6676072/get-system-drawing-bitmap-of-a-wpf-area-using-visualbrush
                        var visual = new DrawingVisual();
                        var context = visual.RenderOpen();
                        context.DrawDrawing(group);
                        context.Close();
                        const int dpiScale100 = 96;
                        var bitmap = new RenderTargetBitmap(
                            Convert.ToInt32(width), Convert.ToInt32(height),
                            dpiScale100, dpiScale100,
                            PixelFormats.Pbgra32
                        );
                        bitmap.Render(visual);
                        return bitmap;
                    }
                    else
                    {
                        Log.Error($"Can't convert background string <{BackgroundColor}> to color, Package location: <{Package.Location}>.");
                        return new BitmapImage(new Uri(Constant.ErrorIcon));
                    }
                }
                else
                {
                    // todo use windows theme as background
                    return image;
                }
            }
Example #22
0
        private void DrawDashboard(DrawingGroup dg, int x, int y)
        {
            var levenImageSource = Resources.GetImage("SenneGameWpf", "images/smiley Angry.png");
            for (var i = 0; i < _life; i++)
            {
                var leven = new ImageDrawing(levenImageSource, new Rect(10 * i + x, y, 10, 10));

                dg.Children.Add(leven);
            }

            var ammodrawing = DrawText(x, y + 10, string.Format("AMMO: {0}", _ammo));
            dg.Children.Add(ammodrawing);
            var pointsdrawing = DrawText(x, y + 20, string.Format("POINTS: {0}", _points));
            dg.Children.Add(pointsdrawing);
        }
Example #23
0
        public Drawing Teken_jezelf()
        {
            var dg = new DrawingGroup();

            ImageSource imageSource;

            if (!(Heb_timeout > 0))
                imageSource = Resources.GetImage("SenneGameWpf", "images/tux_soldier.png");
            else
                imageSource = Resources.GetImage("SenneGameWpf", "images/tux_snowman.png");

            var ventje = new ImageDrawing(imageSource, new Rect(_waar_ben_ik.X - 5, _waar_ben_ik.Y - 5, 10, 10));

            dg.Children.Add(ventje);

            DrawDashboard(dg, -70, 0);

            return dg;
        }
Example #24
0
	private void InsertPictureLayer (DataRow PictureRow, DrawingGroup FramingGroup,
					DataRow ConnectPicturesRow, double OriginalWidth, double OriginalHeight,
					String LocalWPMediaRoot, DataTable MaterialTable)
		{

		System.Windows.Point StartingPoint = new System.Windows.Point
			((Convert.ToInt32 (PictureRow ["PositionLeft"]) * OriginalWidth) / 100,
			(Convert.ToInt32 (PictureRow ["PositionTop"]) * OriginalHeight) / 100);
		bool FixPositioned = false;
		if (ConnectPicturesRow ["PositionedByFileName"] != null)
			if (ConnectPicturesRow ["PositionedByFileName"].ToString () == "Yes")
				{
				StartingPoint.X = (Convert.ToInt32 (ConnectPicturesRow ["XPositioningPercentage"]) * OriginalWidth) / 100;
				StartingPoint.Y = (Convert.ToInt32 (ConnectPicturesRow ["YPositioningPercentage"]) * OriginalHeight) / 100;
				FixPositioned = true;
				}
		String PhysicalFileName = ConnectPicturesRow ["PictureFileName"].ToString ();
		Stream PictureSource = null;
		if (MaterialTable != null)
			{
			DataRow [] Materials = MaterialTable.Select ("NameID = '" + PhysicalFileName + "'");
			if (Materials.Length != 1)
				return;
			PictureSource = new MemoryStream (Materials [0] ["MaterialByteArray"] as Byte []);
			}
		else
			{
			if (!Path.IsPathRooted (PhysicalFileName))
				PhysicalFileName
					= Path.Combine (LocalWPMediaRoot, PhysicalFileName);
			if (String.IsNullOrEmpty (PhysicalFileName))
				return;
			if (!File.Exists (PhysicalFileName))
				return;
			PictureSource = new FileStream (PhysicalFileName, FileMode.Open, FileAccess.Read);
			
			}


		DrawingGroup PictureDrawingGroup = new DrawingGroup ();


		BitmapImage PicturePart = new BitmapImage ();
		PicturePart.BeginInit ();
		PicturePart.CacheOption = BitmapCacheOption.OnLoad;
		PicturePart.StreamSource = PictureSource;
		PicturePart.EndInit ();

		PictureSource.Close ();
		PictureSource.Dispose ();

		double RealWidth = PicturePart.PixelWidth;
		double RealHeight = PicturePart.PixelHeight;
		double RealAspectRatio = RealWidth / RealHeight;
		double MeasuredWidth = PicturePart.Width;
		double MeasuredHeight = PicturePart.Height;


		double PositionLeft = Convert.ToDouble (PictureRow ["PositionLeft"]);
		double PositionTop = Convert.ToDouble (PictureRow ["PositionTop"]);
		double PositionRight = Convert.ToDouble (PictureRow ["PositionRight"]);
		double PositionBottom = Convert.ToDouble (PictureRow ["PositionBottom"]);

		double TargetWidth = ((PositionRight - PositionLeft) * OriginalWidth) / 100;
		double TargetHeight = ((PositionBottom - PositionTop) * OriginalHeight) / 100;
		double PositioningFactor = 1;
		if (!FixPositioned)
			{
			double FramingAspectRatio = TargetWidth/TargetHeight;
			if (FramingAspectRatio >= RealAspectRatio)
				{
				RealHeight = TargetHeight;
				RealWidth = RealHeight * RealAspectRatio;
				}
			else
				{
				RealWidth = TargetWidth;
				RealHeight = RealWidth / RealAspectRatio;
				}

			}


		System.Windows.Point DrawingStartingPoint = StartingPoint;
		System.Windows.Size DrawingSize = new System.Windows.Size
			(RealWidth, RealHeight);
		double TargetAspectRatio = DrawingSize.Width / DrawingSize.Height;
		if (TargetAspectRatio >= RealAspectRatio)
			{
			DrawingSize.Width = DrawingSize.Height*RealAspectRatio;
			if (!FixPositioned)
				{
				DrawingStartingPoint.X += (TargetWidth - DrawingSize.Width) / 2;
				}
			else
				{
				}
			}
		else
			{
			DrawingSize.Height = DrawingSize.Width / RealAspectRatio;
			if (!FixPositioned)
				{
				DrawingStartingPoint.Y += (TargetHeight - DrawingSize.Height) / 2;
				}
			else
				{
				}
			}
		ImageDrawing PositionableEntry = new ImageDrawing();
		PositionableEntry.ImageSource = PicturePart; ;
		PositionableEntry.Rect = new Rect (DrawingStartingPoint, DrawingSize);
		PictureDrawingGroup.Children.Add (PositionableEntry);
		PictureDrawingGroup.Opacity = Convert.ToDouble (PictureRow ["Transparency"])/100;
		FramingGroup.Children.Add (PictureDrawingGroup);
		PictureDrawingGroup.Freeze ();
		InsertDisposeableElement (PositionableEntry);
		InsertDisposeableElement (PictureDrawingGroup);
		InsertDisposeableElement (PicturePart);
		}
Example #25
0
        /// <summary>
        /// Actualiza los fondos de generos de la vitrola
        /// </summary>
        private void UpdateBackGroundVitrola()
        {
            var result = new SortedList<string, Brush>();
            _vitrola.BackGroundsStrings =new SortedList<string, string>(ImagesBackGround);

            foreach (var colorBrush in ColorsBackGround)
            {
                if (!result.ContainsKey(colorBrush.Key))
                {
                    result.Add(colorBrush.Key,colorBrush.Value);
                }
            }
            foreach (var image in ImagesBackGround)
            {
                if(File.Exists(image.Value))
                {
                    var imageDrawing = new ImageDrawing
                    {
                        Rect = new Rect(0, 0, 150, 100),
                        ImageSource = new BitmapImage(new Uri(image.Value))
                    };
                    if (result.ContainsKey(image.Key))
                        result[image.Key] = new DrawingBrush(imageDrawing);
                    else
                        result.Add(image.Key, new DrawingBrush(imageDrawing));
                }
            }
            _vitrola.BackGrounds = result;
            if(_vitrola.Genres==null || _vitrola.Genres.Count==0)
                return;
            _vitrola.SelectedGenre = _vitrola.Genres.First();
            _vitrola.BackGround = _vitrola.BackGrounds[_vitrola.SelectedGenre];
        }
Example #26
0
 // Image Lazy Loading
 public static Lazy<ImageDrawing> LoadImage(string fileName)
 {
     return new Lazy<ImageDrawing>(() =>
     {
         System.Drawing.Bitmap b = new System.Drawing.Bitmap(fileName);
         System.Drawing.Size s = b.Size;
         System.Windows.Media.ImageDrawing im = new System.Windows.Media.ImageDrawing();
         im.Rect = new System.Windows.Rect(0, 0, s.Width, s.Height);
         im.ImageSource = new System.Windows.Media.Imaging.BitmapImage(new Uri(fileName, UriKind.Absolute));
         return im;
     });
 }
Example #27
0
        private DrawingImage Teken_gameOver()
        {
            var imageSource = Resources.GetImage("SenneGameWpf", "images/gameover2.jpg");
            var gameover = new ImageDrawing(imageSource, new Rect(0, 0, 600, 270));

            var speelveld = new DrawingGroup();
            speelveld.Children.Add(gameover);
            return new DrawingImage( speelveld);
        }
        /// <summary>
        ///     DrawImage -
        ///     Draw an Image into the region specified by the Rect.
        ///     The Image will potentially be stretched and distorted to fit the Rect. 
        ///     For more fine grained control, consider filling a Rect with an ImageBrush via
        ///     DrawRectangle. 
        /// </summary> 
        /// <param name="imageSource"> The ImageSource to draw. </param>
        /// <param name="rectangle"> 
        ///     The Rect into which the ImageSource will be fit.
        /// </param>
        /// <param name="rectangleAnimations"> Optional AnimationClock for rectangle. </param>
        public override void DrawImage( 
            ImageSource imageSource,
            Rect rectangle, 
            AnimationClock rectangleAnimations) 
        {
 
        #if DEBUG
            MediaTrace.DrawingContextOp.Trace("DrawImage(animate)");
        #endif
 
            //
            // Verify that parameters & state are valid 
            // 

            VerifyApiNonstructuralChange(); 

            if (imageSource == null)
            {
                return; 
            }
 
            // 
            // Create a drawing & add animations if they exist
            // 

            ImageDrawing imageDrawing = new ImageDrawing();

            // 
            // We may need to opt-out of inheritance through the new Freezable.
            // This is controlled by this.CanBeInheritanceContext. 
            // 

            imageDrawing.CanBeInheritanceContext = CanBeInheritanceContext; 

            imageDrawing.ImageSource = imageSource;
            imageDrawing.Rect = rectangle;
 
            SetupNewFreezable(
                imageDrawing, 
                (null == rectangleAnimations) && // Freeze if there are no animations 
                imageSource.IsFrozen            // and the bitmap source is frozen
                ); 

            if (rectangleAnimations != null)
            {
                imageDrawing.ApplyAnimationClock(ImageDrawing.RectProperty, rectangleAnimations); 
            }
 
            AddDrawing(imageDrawing); 
        }
Example #29
0
 public override Drawing draw(Geometry g)
 {
     ImageDrawing id = new ImageDrawing(imagesource, g.Bounds);
     return id;
 }
Example #30
0
        public void ParseMapText(string text)
        {
            mapGrid.Visibility = Visibility.Visible;
            lblDescription.Visibility = Visibility.Collapsed;
            char[] pipe = { '|' };
            char[] newline = { '\n' };
            char[] colon = { ':' };
            string[] lines = text.Split(colon, StringSplitOptions.RemoveEmptyEntries);
            foreach (string str in lines)
            {
                if (str.Length < 2)
                    continue;
                string[] pieces = { str.Substring(0,1), str.Substring(2) };
                if( pieces.Length > 1 )
                {
                    int line = 0;
                    if( Int32.TryParse(pieces[0], out line) && line < 9)
                    {
                        string data = pieces[1];
                        if (data.Length > 17)
                        {
                            for (int i = 0; i < 9; i++)
                            {
                                _backgroundTiles[line, i] = data[i * 2] - 64;
                                _foregroundTiles[line, i] = data[i * 2 + 1] - 64;

                                System.Windows.Controls.Image img = mapGrid.Children.Cast<System.Windows.Controls.Image>().First(e => Grid.GetRow(e) == line && Grid.GetColumn(e) == i);

                                if (img != null)
                                {
                                    // This may be a bit of a memory leak that we have to look at later.
                                    Uri fore = GetForegroundImageURIFromNumber(_foregroundTiles[line, i]);
                                    Uri back = GetBackgroundImageURIFromNumber(_backgroundTiles[line, i]);
                                    //img.Source = new BitmapImage(back);
                                    ImageDrawing background = new ImageDrawing(new BitmapImage(back), new Rect(0, 0, 32, 32));
                                    Bitmap bitmap = new Bitmap(fore.OriginalString);
                                    bitmap.MakeTransparent();
                                    ImageDrawing foreground = new ImageDrawing(System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(),
                                        IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()), new Rect(0, 0, 32, 32));
                                    DrawingGroup myDrawingGroup = new DrawingGroup();
                                    myDrawingGroup.Children.Add(background);
                                    myDrawingGroup.Children.Add(foreground);
                                    // Add player icon to center of map.
                                    //if (line == 4 && i == 4)
                                    //{
                                    //    Bitmap bitmap2 = new Bitmap("MapTiles/humanoid_shadow_medium_w.png");
                                    //    bitmap2.MakeTransparent();
                                    //    ImageDrawing player = new ImageDrawing(System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(),
                                    //        IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()), new Rect(0, 0, 32, 32));
                                    //    myDrawingGroup.Children.Add(player);
                                    //}
                                    img.Source = new DrawingImage(myDrawingGroup);
                                }
                                else
                                {
                                    throw new IndexOutOfRangeException("Bad tile location on map: " + line + "," + i);
                                }
                            }
                        }
                    }
                }
            }
        }
Example #31
0
 public void loadTexture(String filename, String relativePath)
 {
     Drawing drawing = new ImageDrawing();
     ImageSource img = new BitmapImage(new Uri(filename));
     String name = filename.Substring(relativePath.Length, filename.Length - relativePath.Length).Trim('\\');
     m_textures.Add(new Pair<String, Drawing>(name, drawing));
 }
Example #32
0
        public override void Render(WpfDrawingRenderer renderer)
        {
            WpfDrawingContext context    = renderer.Context;
            SvgImageElement imageElement = (SvgImageElement)_svgElement;

            double width  = imageElement.Width.AnimVal.Value;
            double height = imageElement.Height.AnimVal.Value;

            Rect destRect = new Rect(imageElement.X.AnimVal.Value, imageElement.Y.AnimVal.Value,
                width, height);

            ImageSource imageSource = null;
            if (imageElement.IsSvgImage)
            {
                SvgWindow wnd = GetSvgWindow();
                //_embeddedRenderer.BackColor = Color.Empty;
                _embeddedRenderer.Render(wnd.Document);

                DrawingGroup imageGroup = _embeddedRenderer.Drawing as DrawingGroup;
                if (imageGroup != null &&
                    (imageGroup.Children != null && imageGroup.Children.Count == 1))
                {
                    DrawingGroup drawImage = imageGroup.Children[0] as DrawingGroup;
                    if (drawImage != null)
                    {
                        if (drawImage.ClipGeometry != null)
                        {
                            drawImage.ClipGeometry = null;
                        }

                        imageSource = new DrawingImage(drawImage);
                    }
                    else
                    {
                        if (imageGroup.ClipGeometry != null)
                        {
                            imageGroup.ClipGeometry = null;
                        }

                        imageSource = new DrawingImage(imageGroup);
                    }
                }
                else
                {
                    imageSource = new DrawingImage(_embeddedRenderer.Drawing);
                }

                if (_embeddedRenderer != null)
                {
                    _embeddedRenderer.Dispose();
                    _embeddedRenderer = null;
                }
            }
            else
            {
                imageSource = GetBitmapSource(imageElement, context);
            }

            if (imageSource == null)
            {
                return;
            }

            //TODO--PAUL: Set the DecodePixelWidth/DecodePixelHeight?

            // Freeze the DrawingImage for performance benefits.
            imageSource.Freeze();

            DrawingGroup drawGroup = null;

            ISvgAnimatedPreserveAspectRatio animatedAspectRatio = imageElement.PreserveAspectRatio;
            if (animatedAspectRatio != null && animatedAspectRatio.AnimVal != null)
            {
                SvgPreserveAspectRatio aspectRatio = animatedAspectRatio.AnimVal as SvgPreserveAspectRatio;
                SvgPreserveAspectRatioType aspectRatioType =
                    (aspectRatio != null) ? aspectRatio.Align : SvgPreserveAspectRatioType.Unknown;
                if (aspectRatio != null && aspectRatioType != SvgPreserveAspectRatioType.None &&
                    aspectRatioType != SvgPreserveAspectRatioType.Unknown)
                {
                    double imageWidth  = imageSource.Width;
                    double imageHeight = imageSource.Height;

                    double viewWidth  = destRect.Width;
                    double viewHeight = destRect.Height;

                    SvgMeetOrSlice meetOrSlice = aspectRatio.MeetOrSlice;
                    if (meetOrSlice == SvgMeetOrSlice.Meet)
                    {
                        if (imageWidth <= viewWidth && imageHeight <= viewHeight)
                        {
                            if (this.Transform == null)
                            {
                                destRect = this.GetBounds(destRect,
                                    new Size(imageWidth, imageHeight), aspectRatioType);
                            }
                            else
                            {
                                destRect = new Rect(0, 0, viewWidth, viewHeight);
                            }
                        }
                        else
                        {
                            Transform viewTransform = this.GetAspectRatioTransform(aspectRatio,
                              new SvgRect(0, 0, imageWidth, imageHeight),
                              new SvgRect(destRect.X, destRect.Y, destRect.Width, destRect.Height));
                            //Transform scaleTransform = this.FitToViewbox(aspectRatio,
                            //  new SvgRect(destRect.X, destRect.Y, imageWidth, imageHeight),
                            //  new SvgRect(destRect.X, destRect.Y, destRect.Width, destRect.Height));

                            if (viewTransform != null)
                            {
                                drawGroup = new DrawingGroup();
                                drawGroup.Transform = viewTransform;

                                DrawingGroup lastGroup = context.Peek();
                                Debug.Assert(lastGroup != null);

                                if (lastGroup != null)
                                {
                                    lastGroup.Children.Add(drawGroup);
                                }

                                destRect = this.GetBounds(destRect,
                                    new Size(imageWidth, imageHeight), aspectRatioType);

                                // The origin is already handled by the view transform...
                                destRect.X = 0;
                                destRect.Y = 0;
                            }
                        }
                    }
                    else if (meetOrSlice == SvgMeetOrSlice.Slice)
                    {
                    }
                }
            }

            ImageDrawing drawing = new ImageDrawing(imageSource, destRect);

            float opacityValue = -1;

            string opacity = imageElement.GetAttribute("opacity");
            if (opacity != null && opacity.Length > 0)
            {
                opacityValue = (float)SvgNumber.ParseNumber(opacity);
                opacityValue = Math.Min(opacityValue, 1);
                opacityValue = Math.Max(opacityValue, 0);
            }

            Geometry clipGeom   = this.ClipGeometry;
            Transform transform = this.Transform;

            if (drawGroup == null)
            {
                drawGroup = context.Peek();
            }
            Debug.Assert(drawGroup != null);
            if (drawGroup != null)
            {
                if (opacityValue >= 0 || (clipGeom != null && !clipGeom.IsEmpty()) ||
                    (transform != null && !transform.Value.IsIdentity))
                {
                    DrawingGroup clipGroup = new DrawingGroup();
                    if (opacityValue >= 0)
                    {
                        clipGroup.Opacity = opacityValue;
                    }
                    if (clipGeom != null)
                    {
                        SvgUnitType clipUnits = this.ClipUnits;
                        if (clipUnits == SvgUnitType.ObjectBoundingBox)
                        {
                            Rect drawingBounds = drawing.Bounds;

                            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;
                        }

                        clipGroup.ClipGeometry = clipGeom;
                    }
                    if (transform != null)
                    {
                        clipGroup.Transform = transform;
                    }

                    clipGroup.Children.Add(drawing);
                    drawGroup.Children.Add(clipGroup);
                }
                else
                {
                    drawGroup.Children.Add(drawing);
                }
            }
        }
Example #33
0
        private Drawing Teken_gewonnen()
        {
            var imageSource = Resources.GetImage("SenneGameWpf", "images/win.jpg");
            var gewonnen = new ImageDrawing(imageSource, new Rect(0, 0, 1000, 667));

            var speelveld = new DrawingGroup();
            speelveld.Children.Add(gewonnen);
            return speelveld;
        }
		private void Render(bool bitmapDirty)
		{
			if (bitmapDirty)
			{
				lock (l)
				{
					_bitmap = BitmapSource.Create(
						_bitmapWidth,
						_bitmapHeight,
						96,
						96,
						_pixelFormat,
						null,
						_bitmapPixels,
						_bitmapStride);
				}
			}

			// Render the text bitmap with scaling
			DrawingGroup drawingGroup = new DrawingGroup();
			RenderOptions.SetBitmapScalingMode(drawingGroup, BitmapScalingMode.HighQuality);
			ImageDrawing image = new ImageDrawing();
			double textHeight = Math.Min(Height, _progressiveScroll.DrawHeight);
			image.Rect = new Rect(0.0, 0.0, _progressiveScroll.ActualWidth, textHeight);
			image.ImageSource = _bitmap;
			drawingGroup.Children.Add(image);

			using (DrawingContext drawingContext = TextVisual.RenderOpen())
			{
				drawingContext.DrawDrawing((Drawing)drawingGroup);
			}

			if (_invalidateAgain)
			{
				Invalidate(Parts.TextContent);
			}
		}