private void InitNodeSurround()
        {
            picNodeHighlightSurround = new DrawingVisual();
            picNodeNormalSurround    = new DrawingVisual();

            if (!_Initialized)
            {
                foreach (var background in NodeBackgrounds)
                {
                    if (NodeBackgroundsActive.ContainsKey(background.Key))
                    {
                        Size normalSize;
                        var  normalBrush = new ImageBrush();
                        normalBrush.Stretch = Stretch.Uniform;
                        BitmapImage normalBrushPImage = _assets[NodeBackgrounds[background.Key]].PImage;
                        normalBrush.ImageSource = normalBrushPImage;
                        normalSize = new Size(normalBrushPImage.PixelWidth, normalBrushPImage.PixelHeight);

                        Size activeSize;
                        var  activeBrush = new ImageBrush();
                        activeBrush.Stretch = Stretch.Uniform;
                        BitmapImage activeBrushPImage = _assets[NodeBackgroundsActive[background.Key]].PImage;
                        activeBrush.ImageSource = activeBrushPImage;
                        activeSize = new Size(activeBrushPImage.PixelWidth, activeBrushPImage.PixelHeight);

                        NodeSurroundBrush.Add(new KeyValuePair <Size, ImageBrush>(normalSize, normalBrush));
                        NodeSurroundBrush.Add(new KeyValuePair <Size, ImageBrush>(activeSize, activeBrush));

                        //tree comparison highlight generator
                        var  outlinecolor = _treeComparisonColor;
                        uint omask        = (uint)outlinecolor.B | (uint)outlinecolor.G << 8 | (uint)outlinecolor.R << 16;

                        var bitmap = (BitmapImage)normalBrush.ImageSource;
                        var wb     = new WriteableBitmap(bitmap.PixelWidth, bitmap.PixelHeight, bitmap.DpiX, bitmap.DpiY, PixelFormats.Bgra32, null);
                        if (wb.Format == PixelFormats.Bgra32)//BGRA is byte order .. little endian in uint reverse it
                        {
                            uint[] pixeldata = new uint[wb.PixelHeight * wb.PixelWidth];
                            bitmap.CopyPixels(pixeldata, wb.PixelWidth * 4, 0);
                            for (int i = 0; i < pixeldata.Length; i++)
                            {
                                pixeldata[i] = pixeldata[i] & 0xFF000000 | omask;
                            }
                            wb.WritePixels(new Int32Rect(0, 0, wb.PixelWidth, wb.PixelHeight), pixeldata, wb.PixelWidth * 4, 0);

                            var ibr = new ImageBrush();
                            ibr.Stretch     = Stretch.Uniform;
                            ibr.ImageSource = wb;

                            NodeSurroundHighlightBrush.Add(new KeyValuePair <Size, ImageBrush>(normalSize, ibr));
                        }
                        else
                        {
                            //throw??
                        }
                    }
                }
            }
        }
Example #2
0
        private void InitNodeSurround()
        {
            picSkillSurround     = new DrawingVisual();
            picSkillBaseSurround = new DrawingVisual();

            if (!_Initialized)
            {
                Size sizeNot;
                var  brNot = new ImageBrush();
                brNot.Stretch = Stretch.Uniform;
                BitmapImage PImageNot = _assets[NodeBackgrounds["notable"]].PImage;
                brNot.ImageSource = PImageNot;
                sizeNot           = new Size(PImageNot.PixelWidth, PImageNot.PixelHeight);

                var brNotH = new ImageBrush();
                brNotH.Stretch = Stretch.Uniform;
                BitmapImage PImageNotH = _assets[NodeBackgroundsActive["notable"]].PImage;
                brNotH.ImageSource = PImageNotH;
                Size sizeNotH = new Size(PImageNotH.PixelWidth, PImageNotH.PixelHeight);


                var brKS = new ImageBrush();
                brKS.Stretch = Stretch.Uniform;
                BitmapImage PImageKr = _assets[NodeBackgrounds["keystone"]].PImage;
                brKS.ImageSource = PImageKr;
                Size sizeKs = new Size(PImageKr.PixelWidth, PImageKr.PixelHeight);

                var brKSH = new ImageBrush();
                brKSH.Stretch = Stretch.Uniform;
                BitmapImage PImageKrH = _assets[NodeBackgroundsActive["keystone"]].PImage;
                brKSH.ImageSource = PImageKrH;
                Size sizeKsH = new Size(PImageKrH.PixelWidth, PImageKrH.PixelHeight);

                var brNorm = new ImageBrush();
                brNorm.Stretch = Stretch.Uniform;
                BitmapImage PImageNorm = _assets[NodeBackgrounds["normal"]].PImage;
                brNorm.ImageSource = PImageNorm;
                Size isizeNorm = new Size(PImageNorm.PixelWidth, PImageNorm.PixelHeight);

                var brNormA = new ImageBrush();
                brNormA.Stretch = Stretch.Uniform;
                BitmapImage PImageNormA = _assets[NodeBackgroundsActive["normal"]].PImage;
                brNormA.ImageSource = PImageNormA;
                Size isizeNormA = new Size(PImageNormA.PixelWidth, PImageNormA.PixelHeight);

                var brJewel = new ImageBrush();
                brJewel.Stretch = Stretch.Uniform;
                BitmapImage PImageJewel = _assets[NodeBackgrounds["jewel"]].PImage;
                brJewel.ImageSource = PImageJewel;
                Size isSizeJewel = new Size(PImageJewel.PixelWidth, PImageJewel.PixelHeight);

                var brJewelA = new ImageBrush();
                brJewelA.Stretch = Stretch.Uniform;
                BitmapImage PImageJewelA = _assets[NodeBackgroundsActive["jewel"]].PImage;
                brJewelA.ImageSource = PImageJewelA;
                Size isSizeJewelA = new Size(PImageJewelA.PixelWidth, PImageJewelA.PixelHeight);

                NodeSurroundBrush.Add(new KeyValuePair <Size, ImageBrush>(isizeNorm, brNorm));
                NodeSurroundBrush.Add(new KeyValuePair <Size, ImageBrush>(isizeNormA, brNormA));
                NodeSurroundBrush.Add(new KeyValuePair <Size, ImageBrush>(sizeKs, brKS));
                NodeSurroundBrush.Add(new KeyValuePair <Size, ImageBrush>(sizeNot, brNot));
                NodeSurroundBrush.Add(new KeyValuePair <Size, ImageBrush>(sizeKsH, brKSH));
                NodeSurroundBrush.Add(new KeyValuePair <Size, ImageBrush>(sizeNotH, brNotH));
                NodeSurroundBrush.Add(new KeyValuePair <Size, ImageBrush>(isSizeJewel, brJewel));
                NodeSurroundBrush.Add(new KeyValuePair <Size, ImageBrush>(isSizeJewelA, brJewelA));



                //outline generator
                foreach (var item in NodeSurroundBrush)
                {
                    var  outlinecolor = _treeComparisonColor;
                    uint omask        = (uint)outlinecolor.B | (uint)outlinecolor.G << 8 | (uint)outlinecolor.R << 16;

                    var bitmap = (BitmapImage)item.Value.ImageSource;
                    var wb     = new WriteableBitmap(bitmap.PixelWidth, bitmap.PixelHeight, bitmap.DpiX, bitmap.DpiY, PixelFormats.Bgra32, null);
                    if (wb.Format == PixelFormats.Bgra32)//BGRA is byte order .. little endian in uint reverse it
                    {
                        uint[] pixeldata = new uint[wb.PixelHeight * wb.PixelWidth];
                        bitmap.CopyPixels(pixeldata, wb.PixelWidth * 4, 0);
                        for (int i = 0; i < pixeldata.Length; i++)
                        {
                            pixeldata[i] = pixeldata[i] & 0xFF000000 | omask;
                        }
                        wb.WritePixels(new Int32Rect(0, 0, wb.PixelWidth, wb.PixelHeight), pixeldata, wb.PixelWidth * 4, 0);

                        var ibr = new ImageBrush();
                        ibr.Stretch     = Stretch.Uniform;
                        ibr.ImageSource = wb;

                        NodeSurroundHighlightBrush.Add(new KeyValuePair <Size, ImageBrush>(item.Key, ibr));
                    }
                    else
                    {
                        //throw??
                    }
                }
            }
        }