Exemple #1
0
		public PreviewPixel Clone()
		{
			PreviewPixel p = new PreviewPixel(X, Y, Z, size);
			p.color = color;
			p.drawArea = new Rectangle(drawArea.X, drawArea.Y, drawArea.Width, drawArea.Height);
			p.Node = Node;
			p.MaxAlpha = _maxAlpha;

			return p;
		}
Exemple #2
0
        public PreviewFlood(PreviewPoint point, ElementNode selectedNode)
        {
            _p1 = point;

            PixelSize = 40;

            StringType = StringTypes.Standard;

            PreviewPixel pixel = AddPixel(10, 10);

            pixel.PixelColor = Color.White;

            if (selectedNode != null)
            {
                if (selectedNode.IsLeaf)
                {
                    pixel.Node   = selectedNode;
                    pixel.NodeId = selectedNode.Id;
                }
            }

            // Lay out the flood
            Layout();
        }
Exemple #3
0
        public PreviewSetElements(List <PreviewBaseShape> shapes)
        {
            InitializeComponent();
            _shapes = shapes;
            connectStandardStrings = shapes[0].connectStandardStrings;
            int i = 1;

            foreach (PreviewBaseShape shape in _shapes)
            {
                if (shape.Pixels.Count == 0)
                {
                    continue;
                }
                PreviewSetElementString newString = new PreviewSetElementString();
                // If this is a Standard string, only set the first pixel of the string
                if (shape.StringType == PreviewBaseShape.StringTypes.Standard)
                {
                    //Console.WriteLine("Standard String");
                    PreviewPixel pixel = shape.Pixels[0];
                    ;
                    //Console.WriteLine(shape.Pixels[0].Node.Name.ToString());
                    newString.Pixels.Add(pixel.Clone());
                }
                // If this is a pixel string, let them set every pixel
                else
                {
                    foreach (PreviewPixel pixel in shape.Pixels)
                    {
                        newString.Pixels.Add(pixel.Clone());
                    }
                }
                newString.StringName = "String " + i.ToString();
                _strings.Add(newString);
                i++;
            }
        }
        public override void Layout()
        {
            ElementNode node = null;

            if (PixelCount > 0)
            {
                node = _pixels[0].Node;
                _pixels.Clear();
            }
            else if (initiallyAssignedNode != null)
            {
                if (initiallyAssignedNode.IsLeaf)
                {
                    node = initiallyAssignedNode;
                }
            }

            Point boundsTopLeft = new Point();

            boundsTopLeft.X = Math.Min(_topLeft.X, Math.Min(Math.Min(_topRight.X, _bottomRight.X), _bottomLeft.X));
            boundsTopLeft.Y = Math.Min(_topLeft.Y, Math.Min(Math.Min(_topRight.Y, _bottomRight.Y), _bottomLeft.Y));
            Point bottomRight = new Point();

            bottomRight.X = Math.Max(_topLeft.X, Math.Max(Math.Max(_topRight.X, _bottomRight.X), _bottomLeft.X));
            bottomRight.Y = Math.Max(_topLeft.Y, Math.Max(Math.Max(_topRight.Y, _bottomRight.Y), _bottomLeft.Y));
            Rectangle rect = new Rectangle(boundsTopLeft,
                                           new Size(bottomRight.X - boundsTopLeft.X, bottomRight.Y - boundsTopLeft.Y));

            Point tL = new Point(_topLeft.X - boundsTopLeft.X, _topLeft.Y - boundsTopLeft.Y);
            Point tR = new Point(_topRight.X - boundsTopLeft.X, _topRight.Y - boundsTopLeft.Y);
            Point bL = new Point(_bottomLeft.X - boundsTopLeft.X, _bottomLeft.Y - boundsTopLeft.Y);
            Point bR = new Point(_bottomRight.X - boundsTopLeft.X, _bottomRight.Y - boundsTopLeft.Y);

            Point[] points = { tL, tR, bR, bL };

            if (rect.Width > 0 && rect.Height > 0)
            {
                using (var b = new Bitmap(rect.Width, rect.Height)) {
                    Graphics g = Graphics.FromImage(b);
                    g.Clear(Color.Transparent);
                    g.FillPolygon(Brushes.White, points);
                    using (FastPixel.FastPixel fp = new FastPixel.FastPixel(b)) {
                        fp.Lock();
                        int xCount   = 1;
                        int spacingY = _pixelSpacing;
                        for (int y = 0; y < rect.Height; y++)
                        {
                            if (spacingY % _pixelSpacing == 0)
                            {
                                int xDiv;
                                if (xCount % 2 == 0)
                                {
                                    xDiv = _pixelSpacing;
                                }
                                else
                                {
                                    xDiv = _pixelSpacing / 2;
                                }

                                for (int x = 0; x < rect.Width; x++)
                                {
                                    if ((x + xDiv) % _pixelSpacing == 0)
                                    {
                                        Color newColor = fp.GetPixel(x, y);
                                        if (newColor.A != 0)
                                        {
                                            PreviewPixel pixel = new PreviewPixel(x + boundsTopLeft.X, y + boundsTopLeft.Y, 0, PixelSize);
                                            pixel.Node = node;
                                            _pixels.Add(pixel);
                                        }
                                    }
                                }
                                xCount += 1;
                            }
                            spacingY += 1;
                        }
                        fp.Unlock(false);
                    }
                }
            }
        }
Exemple #5
0
 private void RenderPixel( D2D.RenderTarget rt, PreviewPixel p, D2D.SolidColorBrush brush)
 {
     if (p.PixelSize <= 4)
         rt.DrawLine(new D2D.Point2F(p.X, p.Y), new D2D.Point2F(p.X + 1, p.Y + 1), brush, p.PixelSize);
     else
         rt.FillEllipse(new D2D.Ellipse() { Point = new D2D.Point2F(p.X, p.Y), RadiusX = p.PixelSize / 2, RadiusY = p.PixelSize / 2 }, brush);
 }
Exemple #6
0
 public virtual void DrawPixel(PreviewPixel pixel, FastPixel.FastPixel fp, bool editMode, List<ElementNode> highlightedElements,
     bool selected, bool forceDraw)
 {
     if (forceDraw) {
         pixel.Draw(fp, forceDraw);
     }
     else if (selected) {
         pixel.Draw(fp, PreviewTools.SelectedItemColor);
     }
     else if (highlightedElements != null && highlightedElements.Contains(pixel.Node)) {
         pixel.Draw(fp, Color.HotPink);
     }
     else {
         pixel.Draw(fp, Color.White);
     }
 }
Exemple #7
0
 // Add a pxiel at a specific location
 public PreviewPixel AddPixel(int x, int y)
 {
     PreviewPixel pixel = new PreviewPixel(x, y, 0, PixelSize);
     pixel.PixelColor = PixelColor;
     Pixels.Add(pixel);
     return pixel;
 }
Exemple #8
0
		public virtual void DrawPixel(PreviewPixel pixel, FastPixel.FastPixel fp, bool editMode, List<ElementNode> highlightedElements,
		                              bool selected, bool forceDraw)
		{
            if (forceDraw)
            {
                pixel.Draw(fp, forceDraw);
            }
            else
            {
                Color pixelColor = Color.White;
                if (
                    (_pixels.Count > 0) &&
                    (pixel == _pixels[0] || (_strings != null && _strings.Count > 0 && _strings[0].Pixels != null && _strings[0].Pixels.Count > 0 && _strings[0].Pixels[0] == pixel))
                   )
                {
                    pixelColor = Color.Yellow;
                    pixel.PixelSize = PixelSize + 2;
                }
                else
                {
                    if (selected)
                    {
                        pixelColor = PreviewTools.SelectedItemColor;
                    }
                    else if (highlightedElements != null && highlightedElements.Contains(pixel.Node))
                    {
                        pixelColor = Color.HotPink;
                    }
                    else
                    {
                        if (pixel.Node != null)
                        {
                            pixelColor = Color.Turquoise;
                        }
                        else
                        {
                            pixelColor = Color.White;
                        }
                    }
                }
                pixel.Draw(fp, pixelColor);
            }
		}
Exemple #9
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            if ((connectStandardStrings || _shapes.Count() == 1) && _shapes[0].StringType == PreviewBaseShape.StringTypes.Standard)
            {
                //var shape = _shapes[0];
                for (int i = 0; i < _shapes.Count; i++)
                {
                    foreach (var pixel in _shapes[i]._pixels)
                    {
                        pixel.Node   = _strings[0].Pixels[0].Node;
                        pixel.NodeId = _strings[0].Pixels[0].NodeId;
                    }
                }
            }
            else
            {
                // shapes with count==0 don't show up in combo box so keep separate index
                var comboidx = -1;
                for (var i = 0; i < _shapes.Count; i++)
                {
                    if (_shapes[i].Pixels.Count == 0)
                    {
                        continue;
                    }
                    comboidx++;
                    var item        = comboStrings.Items[comboidx] as Common.Controls.ComboBoxItem;
                    var lightString = item.Value as PreviewSetElementString;
                    var shape       = _shapes[i];

                    if (shape.StringType == PreviewBaseShape.StringTypes.Pixel)
                    {
                        while (shape.Pixels.Count > lightString.Pixels.Count)
                        {
                            shape.Pixels.RemoveAt(shape.Pixels.Count - 1);
                        }
                        while (shape.Pixels.Count < lightString.Pixels.Count)
                        {
                            var pixel = new PreviewPixel();
                            shape.Pixels.Add(pixel);
                        }
                    }

                    for (int pixelNum = 0; pixelNum < lightString.Pixels.Count; pixelNum++)
                    {
                        //Console.WriteLine("   pixelNum=" + pixelNum.ToString());
                        // If this is a standard light string, assing ALL pixels to the first node
                        if (shape.StringType == PreviewBaseShape.StringTypes.Standard)
                        {
                            foreach (var pixel in shape._pixels)
                            {
                                //Console.WriteLine("       pixel:" + lightString.Pixels[0].Node.Id.ToString());
                                pixel.Node   = _strings[i].Pixels[0].Node;
                                pixel.NodeId = _strings[i].Pixels[0].NodeId;
                            }
                        }
                        else
                        {
                            shape.Pixels[pixelNum] = lightString.Pixels[pixelNum];
                        }
                    }
                }
            }

            DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }
Exemple #10
0
        public override void Layout()
        {
            ElementNode node = null;

            if (PixelCount > 0) {
                node = _pixels[0].Node;
                _pixels.Clear();
            }
            else if (initiallyAssignedNode != null) {
                if (initiallyAssignedNode.IsLeaf) {
                    node = initiallyAssignedNode;
                }
            }

            Point boundsTopLeft = new Point();
            boundsTopLeft.X = Math.Min(_topLeft.X, Math.Min(Math.Min(_topRight.X, _bottomRight.X), _bottomLeft.X));
            boundsTopLeft.Y = Math.Min(_topLeft.Y, Math.Min(Math.Min(_topRight.Y, _bottomRight.Y), _bottomLeft.Y));
            Point bottomRight = new Point();
            bottomRight.X = Math.Max(_topLeft.X, Math.Max(Math.Max(_topRight.X, _bottomRight.X), _bottomLeft.X));
            bottomRight.Y = Math.Max(_topLeft.Y, Math.Max(Math.Max(_topRight.Y, _bottomRight.Y), _bottomLeft.Y));
            Rectangle rect = new Rectangle(boundsTopLeft,
                                           new Size(bottomRight.X - boundsTopLeft.X, bottomRight.Y - boundsTopLeft.Y));

            Point tL = new Point(_topLeft.X - boundsTopLeft.X, _topLeft.Y - boundsTopLeft.Y);
            Point tR = new Point(_topRight.X - boundsTopLeft.X, _topRight.Y - boundsTopLeft.Y);
            Point bL = new Point(_bottomLeft.X - boundsTopLeft.X, _bottomLeft.Y - boundsTopLeft.Y);
            Point bR = new Point(_bottomRight.X - boundsTopLeft.X, _bottomRight.Y - boundsTopLeft.Y);
            Point[] points = {tL, tR, bR, bL};

            if (rect.Width > 0 && rect.Height > 0) {
                using (var b = new Bitmap(rect.Width, rect.Height)) {
                    Graphics g = Graphics.FromImage(b);
                    g.Clear(Color.Transparent);
                    g.FillPolygon(Brushes.White, points);
                    using (FastPixel.FastPixel fp = new FastPixel.FastPixel(b)) {
                        fp.Lock();
                        int xCount = 1;
                        int spacingY = _pixelSpacing;
                        for (int y = 0; y < rect.Height; y++) {
                            if (spacingY%_pixelSpacing == 0) {
                                int xDiv;
                                if (xCount%2 == 0)
                                    xDiv = _pixelSpacing;
                                else
                                    xDiv = _pixelSpacing/2;

                                for (int x = 0; x < rect.Width; x++) {
                                    if ((x + xDiv)%_pixelSpacing == 0) {
                                        Color newColor = fp.GetPixel(x, y);
                                        if (newColor.A != 0) {
                                            PreviewPixel pixel = new PreviewPixel(x + boundsTopLeft.X, y + boundsTopLeft.Y, 0, PixelSize);
                                            pixel.Node = node;
                                            _pixels.Add(pixel);
                                        }
                                    }
                                }
                                xCount += 1;
                            }
                            spacingY += 1;
                        }
                        fp.Unlock(false);
                    }
                }
            }
        }
Exemple #11
0
 private void buttonSetLightCount_Click(object sender, EventArgs e)
 {
     Common.Controls.ComboBoxItem comboBoxItem = comboStrings.SelectedItem as Common.Controls.ComboBoxItem;
     if (comboBoxItem != null)
     {
         PreviewSetElementString elementString = comboBoxItem.Value as PreviewSetElementString;
         if (elementString != null)
         {
             while (elementString.Pixels.Count > numericUpDownLightCount.Value)
             {
                 elementString.Pixels.RemoveAt(elementString.Pixels.Count - 1);
             }
             while (elementString.Pixels.Count < numericUpDownLightCount.Value)
             {
                 PreviewPixel pixel = new PreviewPixel();
                 elementString.Pixels.Add(pixel);
             }
         }
         UpdateListLinkedElements();
     }
 }
Exemple #12
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            if ((connectStandardStrings || _shapes.Count() == 1) && _shapes[0].StringType == PreviewBaseShape.StringTypes.Standard)
            {
                //var shape = _shapes[0];
                for (int i = 0; i < _shapes.Count; i++)
                {
                    foreach (var pixel in _shapes[i]._pixels)
                    {
                        pixel.Node = _strings[0].Pixels[0].Node;
                        pixel.NodeId = _strings[0].Pixels[0].NodeId;
                    }
                }
            }
            else
            {
                // shapes with count==0 don't show up in combo box so keep separate index
                var comboidx = -1;
                for (var i = 0; i < _shapes.Count; i++)
                {                    
                    if (_shapes[i].Pixels.Count == 0)
                        continue;
                    comboidx++;
                    var item = comboStrings.Items[comboidx] as Common.Controls.ComboBoxItem;
                    var lightString = item.Value as PreviewSetElementString;
                    var shape = _shapes[i];

                    if (shape.StringType == PreviewBaseShape.StringTypes.Pixel) { 
                        while (shape.Pixels.Count > lightString.Pixels.Count)
                        {
                            shape.Pixels.RemoveAt(shape.Pixels.Count - 1);
                        }
                        while (shape.Pixels.Count < lightString.Pixels.Count)
                        {
                            var pixel = new PreviewPixel();
                            shape.Pixels.Add(pixel);
                        }
                    }

                    for (int pixelNum = 0; pixelNum < lightString.Pixels.Count; pixelNum++)
                    {
                        //Console.WriteLine("   pixelNum=" + pixelNum.ToString());
                        // If this is a standard light string, assing ALL pixels to the first node
                        if (shape.StringType == PreviewBaseShape.StringTypes.Standard)
                        {
                            foreach (var pixel in shape._pixels)
                            {
                                //Console.WriteLine("       pixel:" + lightString.Pixels[0].Node.Id.ToString());
                                pixel.Node = _strings[i].Pixels[0].Node;
                                pixel.NodeId = _strings[i].Pixels[0].NodeId;
                            }
                        }
                        else
                        {
                            shape.Pixels[pixelNum] = lightString.Pixels[pixelNum];
                        }
                    }
                }
            }

            DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }
        public PreviewCane(PreviewPoint point, ElementNode selectedNode)
        {
            _topLeftPoint     = point;
            _bottomRightPoint = new PreviewPoint(point.X, point.Y);
            _archLeftPoint    = new PreviewPoint(point.X, point.Y);

            _archPixelCount = 8;
            _linePixelCount = 8;

            int lightCount = _archPixelCount + _linePixelCount;

            if (selectedNode != null)
            {
                //List<ElementNode> children = selectedNode.Children.ToList();
                List <ElementNode> children = PreviewTools.GetLeafNodes(selectedNode);
                // is this a single node?
                if (children.Count >= 8)
                {
                    StringType      = StringTypes.Pixel;
                    _archPixelCount = children.Count / 2;
                    _linePixelCount = children.Count / 2;
                    if (_archPixelCount + _linePixelCount > children.Count)
                    {
                        _archPixelCount -= 1;
                    }
                    else if (_archPixelCount + _linePixelCount < children.Count)
                    {
                        _linePixelCount -= 1;
                    }
                    lightCount = children.Count;
                    // Just add the pixels, they will get layed out next
                    foreach (ElementNode child in children)
                    {
                        PreviewPixel pixel = AddPixel(10, 10);
                        pixel.Node = child;
                        //pixel.NodeId = child.Id;
                        pixel.PixelColor = Color.White;
                    }
                }
            }

            if (_pixels.Count == 0)
            {
                // Just add the pixels, they will get layed out next
                for (int lightNum = 0; lightNum < lightCount; lightNum++)
                {
                    PreviewPixel pixel = AddPixel(10, 10);
                    pixel.PixelColor = Color.White;
                    if (selectedNode != null && selectedNode.IsLeaf)
                    {
                        pixel.Node = selectedNode;
                        //pixel.NodeId = selectedNode.Id;
                    }
                }
            }

            // Lay out the pixels
            Layout();

            //DoResize += new ResizeEvent(OnResize);
        }