コード例 #1
0
        private void editor_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox editor = sender as ComboBox;

            if (editor == null)
            {
                return;
            }

            if (editor.SelectedIndex < 0)
            {
                return;
            }

            value = options[editor.SelectedIndex];
            RaiseValueChanged();
        }
コード例 #2
0
ファイル: Picture.cs プロジェクト: unfriendly/Phasor
        private void Plot(int x, int y, PenShape penShape, PenType penType, byte penSize)
        {
            if (penType == PenType.Splatter)
            {
                SetPixel(x, y);
                return;
            }
            if (penShape == PenShape.Circle)
            {
                Circle ci     = Circle.Circles[penSize];
                int    width  = penSize + 1;
                int    height = penSize * 2 + 1;
                for (int y2 = 0; y2 < height; y2++)
                {
                    for (int x2 = 0; x2 < width; x2++)
                    {
                        byte data = ci.Data[(y2 * width) + x2];
                        if (data == 1)
                        {
                            SetPixel(x + x2 - ci.OffsetX, y + y2 - ci.OffsetY);
                        }
                    }
                }
            }

            if (penShape == PenShape.Square)
            {
                Square sq     = Square.Squares[penSize];
                int    width  = penSize + 1;
                int    height = penSize * 2 + 1;
                for (int y2 = 0; y2 < height; y2++)
                {
                    for (int x2 = 0; x2 < width; x2++)
                    {
                        SetPixel(x + x2 - sq.OffsetX, y + y2 - sq.OffsetY);
                    }
                }
            }
            else
            {
                SetPixel(x, y);
            }
        }
コード例 #3
0
        public override void ReadXML(XmlReader xmlReader)
        {
            xmlReader.ReadStartElement();
            string s = xmlReader.ReadElementContentAsString("Value", "");

            PenShape value = PenShape.Solid;

            try
            {
                TypeConverter converter = TypeDescriptor.GetConverter(typeof(PenShape));
                value = (PenShape)converter.ConvertFromString(s);
            }
            catch (Exception)
            {
                log.ErrorFormat("An error happened while parsing XML for pen shape. {0}", s);
            }

            this.value = options.IndexOf(value) >= 0 ? value : defaultValue;
            xmlReader.ReadEndElement();
        }
コード例 #4
0
        private void DoBindWrite(string targetProperty, object value)
        {
            // Check type and import value if compatible with the target prop.
            bool imported = false;

            switch (targetProperty)
            {
            case "Color":
            {
                if (value is Color)
                {
                    color    = (Color)value;
                    imported = true;
                }
                break;
            }

            case "LineSize":
            {
                if (value is int)
                {
                    lineSize = (int)value;
                    imported = true;
                }

                break;
            }

            case "LineShape":
            {
                if (value is LineShape)
                {
                    lineShape = (LineShape)value;
                    imported  = true;
                }

                break;
            }

            case "LineEnding":
            {
                if (value is LineEnding)
                {
                    lineEnding = (LineEnding)value;
                    imported   = true;
                }

                break;
            }

            case "TrackShape":
            {
                if (value is TrackShape)
                {
                    trackShape = (TrackShape)value;
                    imported   = true;
                }

                break;
            }

            case "PenShape":
            {
                if (value is PenShape)
                {
                    penShape = (PenShape)value;
                    imported = true;
                }

                break;
            }

            case "Curved":
            {
                if (value is bool)
                {
                    curved   = (bool)value;
                    imported = true;
                }

                break;
            }

            case "Perspective":
            {
                if (value is bool)
                {
                    perspective = (bool)value;
                    imported    = true;
                }

                break;
            }

            case "Font":
            {
                if (value is int)
                {
                    // Recreate the font changing just the size.
                    string    fontName  = font.Name;
                    FontStyle fontStyle = font.Style;
                    font.Dispose();
                    font     = new Font(fontName, (int)value, fontStyle);
                    imported = true;
                }
                break;
            }

            case "Bicolor":
            {
                if (value is Color)
                {
                    bicolor.Background = (Color)value;
                    imported           = true;
                }
                break;
            }

            case "GridDivisions":
            {
                if (value is int)
                {
                    gridDivisions = (int)value;
                    imported      = true;
                }
                break;
            }

            default:
            {
                log.DebugFormat("Unknown target property \"{0}\".", targetProperty);
                break;
            }
            }

            if (imported)
            {
                if (ValueChanged != null)
                {
                    ValueChanged(null, EventArgs.Empty);
                }
            }
            else
            {
                log.DebugFormat("Could not import value \"{0}\" to property \"{1}\".", value.ToString(), targetProperty);
            }
        }
コード例 #5
0
        private void Plot(int x, int y, PenShape penShape, PenType penType, byte penSize)
        {
            if (penType == PenType.Splatter)
              {
            SetPixel(x, y);
            return;
              }
              if (penShape == PenShape.Circle)
              {
            Circle ci = Circle.Circles[penSize];
            int width = penSize + 1;
            int height = penSize * 2 + 1;
            for (int y2 = 0; y2 < height; y2++)
            {
              for (int x2 = 0; x2 < width; x2++)
              {
            byte data = ci.Data[(y2 * width) + x2];
            if (data == 1)
              SetPixel(x + x2 - ci.OffsetX, y + y2 - ci.OffsetY);
              }
            }
              }

              if (penShape == PenShape.Square)
              {
            Square sq = Square.Squares[penSize];
            int width = penSize + 1;
            int height = penSize * 2 + 1;
            for (int y2 = 0; y2 < height; y2++)
              for (int x2 = 0; x2 < width; x2++)
            SetPixel(x + x2 - sq.OffsetX, y + y2 - sq.OffsetY);
              }
              else
            SetPixel(x, y);
        }
コード例 #6
0
 public StyleElementPenShape(PenShape initialValue)
 {
     value = options.IndexOf(initialValue) >= 0 ? initialValue : defaultValue;
 }
コード例 #7
0
ファイル: Picture.cs プロジェクト: unfriendly/Phasor
        private void parseData()
        {
            byte       command        = 0;
            int        argumentCount  = 0;
            int        startX         = 0;
            int        startY         = 0;
            int        commandCount   = 0;
            XmlElement commandNode    = null;
            XmlElement goaCommandNode = null;
            XmlElement argNode        = null;
            PenType    penType        = PenType.Solid;
            PenShape   penShape       = PenShape.Square;
            byte       penSize        = 0;

            XmlElement pictureNode = pictureDoc.CreateElement("picture");

            pictureDoc.AppendChild(pictureNode);
            pictureNode.SetAttribute("id", id);

            XmlElement goaPictureNode = goaDoc.CreateElement("picture");

            goaPictureNode.SetAttribute("id", id);
            layersNode = goaDoc.CreateElement("layers");
            XmlElement controlLinesNode = goaDoc.CreateElement("control-lines");

            goaDoc.AppendChild(goaPictureNode);
            goaPictureNode.AppendChild(layersNode);
            goaPictureNode.AppendChild(controlLinesNode);

            int stop = 11;

            for (int i = 0; i < fileData.Length; i++)
            {
                byte c = fileData[i];

                if (c >= 240 && c <= 250)
                {
                    commandCount++;
                    argumentCount = 0;
                    command       = c;
                    string commandString = commands[c - 240];
                    commandNode = pictureDoc.CreateElement(commandString);
                    pictureNode.AppendChild(commandNode);

                    //if (commandCount == stop)
                    //break;
                }
                if (c == 241)
                {
                    pictureDrawingEnabled = false;
                }
                if (c == 243)
                {
                    priorityDrawingEnabled = false;
                }
                // build up the goa doc
                if (c >= 244 && c <= 247 && priorityDrawingEnabled && priorityColor <= 4)
                {
                    goaCommandNode = goaDoc.CreateElement("line");
                    goaCommandNode.SetAttribute("priority", "" + priorityColor);
                    controlLinesNode.AppendChild(goaCommandNode);
                }
                if (c == 248 && priorityDrawingEnabled && priorityColor <= 4)
                {
                    goaCommandNode = goaDoc.CreateElement("fill");
                    goaCommandNode.SetAttribute("priority", "" + priorityColor);
                    controlLinesNode.AppendChild(goaCommandNode);
                }
                // add command arguments to command nodes
                if (c < 240)
                {
                    bool even = argumentCount % 2 == 0;
                    switch (command)
                    {
                    case 240: // enable picture draw and set picture color
                        commandNode.SetAttribute("color", "" + c);
                        pictureDrawingEnabled = true;
                        pictureColor          = c;
                        break;

                    case 242: // enable priority draw and set priority color
                        commandNode.SetAttribute("color", "" + c);
                        priorityDrawingEnabled = true;
                        priorityColor          = c;
                        break;

                    case 244: // y-corner
                    case 245: // x-corner
                        if (argumentCount == 0)
                        {
                            argNode = pictureDoc.CreateElement("coord");
                            argNode.SetAttribute("x", "" + c);
                            commandNode.AppendChild(argNode);
                            startX = c;
                        }
                        else if (argumentCount == 1)
                        {
                            argNode.SetAttribute("y", "" + c);
                            startY = c;
                            if (priorityDrawingEnabled && priorityColor <= 4)
                            {
                                XmlElement goaArgNode = (XmlElement)goaDoc.ImportNode(argNode.CloneNode(true), true);
                                goaCommandNode.AppendChild(goaArgNode);
                            }
                        }
                        else
                        {
                            bool shiftX = (command == 245 && even) || (command == 244 && !even);
                            int  x      = (shiftX)? c : startX;
                            int  y      = (shiftX)? startY : c;

                            argNode = pictureDoc.CreateElement("coord");
                            argNode.SetAttribute("x", "" + startX);
                            argNode.SetAttribute("y", "" + startY);
                            commandNode.AppendChild(argNode);
                            if (priorityDrawingEnabled && priorityColor <= 4)
                            {
                                XmlElement goaArgNode = (XmlElement)goaDoc.ImportNode(argNode.CloneNode(true), true);
                                goaCommandNode.AppendChild(goaArgNode);
                            }

                            DrawLine(startX, startY, x, y);

                            startX = x;
                            startY = y;
                        }
                        break;

                    case 246: // absolute line -> converted to line
                        if (even)
                        {
                            argNode = pictureDoc.CreateElement("coord");
                            argNode.SetAttribute("x", "" + c);
                            commandNode.AppendChild(argNode);
                        }
                        else
                        {
                            argNode.SetAttribute("y", "" + c);
                            int x = int.Parse(argNode.GetAttribute("x"));
                            int y = int.Parse(argNode.GetAttribute("y"));
                            SetPixel(x, y);
                            if (priorityDrawingEnabled && priorityColor <= 4)
                            {
                                XmlElement goaArgNode = (XmlElement)goaDoc.ImportNode(argNode.CloneNode(true), true);
                                goaCommandNode.AppendChild(goaArgNode);
                            }
                            if (((XmlElement)argNode.PreviousSibling) != null)
                            {
                                int x1 = int.Parse(((XmlElement)argNode.PreviousSibling).GetAttribute("x"));
                                int y1 = int.Parse(((XmlElement)argNode.PreviousSibling).GetAttribute("y"));
                                int x2 = int.Parse(argNode.GetAttribute("x"));
                                int y2 = int.Parse(argNode.GetAttribute("y"));
                                DrawLine(x1, y1, x2, y2);
                            }
                        }
                        break;

                    case 247: // relative line -> converted to line
                        if (argumentCount == 0)
                        {
                            argNode = pictureDoc.CreateElement("coord");
                            argNode.SetAttribute("x", "" + c);
                            commandNode.AppendChild(argNode);
                            startX = c;
                        }
                        else if (argumentCount == 1)
                        {
                            argNode.SetAttribute("y", "" + c);
                            startY = c;
                            if (priorityDrawingEnabled && priorityColor <= 4)
                            {
                                XmlElement goaArgNode = (XmlElement)goaDoc.ImportNode(argNode.CloneNode(true), true);
                                goaCommandNode.AppendChild(goaArgNode);
                            }
                            SetPixel(startX, startY);
                        }
                        else
                        {
                            decimal nibble1 = c / 16;
                            int     x       = (int)Math.Floor(nibble1);
                            int     y       = c - (16 * x);
                            if (x >= 8)
                            {
                                x = 8 - x;
                            }
                            if (y >= 8)
                            {
                                y = 8 - y;
                            }

                            startX += x;
                            startY += y;

                            argNode = pictureDoc.CreateElement("coord");
                            argNode.SetAttribute("x", "" + startX);
                            argNode.SetAttribute("y", "" + startY);
                            commandNode.AppendChild(argNode);
                            if (priorityDrawingEnabled && priorityColor <= 4)
                            {
                                XmlElement goaArgNode = (XmlElement)goaDoc.ImportNode(argNode.CloneNode(true), true);
                                goaCommandNode.AppendChild(goaArgNode);
                            }
                            if (((XmlElement)argNode.PreviousSibling) != null)
                            {
                                int x1 = int.Parse(((XmlElement)argNode.PreviousSibling).GetAttribute("x"));
                                int y1 = int.Parse(((XmlElement)argNode.PreviousSibling).GetAttribute("y"));
                                int x2 = int.Parse(argNode.GetAttribute("x"));
                                int y2 = int.Parse(argNode.GetAttribute("y"));
                                DrawLine(x1, y1, x2, y2);
                            }
                        }
                        break;

                    case 248: // flood fill
                        if (even)
                        {
                            argNode = pictureDoc.CreateElement("coord");
                            argNode.SetAttribute("x", "" + c);
                            commandNode.AppendChild(argNode);
                        }
                        else
                        {
                            argNode.SetAttribute("y", "" + c);
                            int x = int.Parse(argNode.GetAttribute("x"));
                            int y = int.Parse(argNode.GetAttribute("y"));

                            if (priorityDrawingEnabled && priorityColor <= 4)
                            {
                                XmlElement goaArgNode = (XmlElement)goaDoc.ImportNode(argNode.CloneNode(true), true);
                                goaCommandNode.AppendChild(goaArgNode);
                            }

                            Fill(x, y);
                        }
                        break;

                    case 249:
                        // set pen type, shape and size
                        BitArray bits = new BitArray(new Byte[1] {
                            c
                        });
                        penType  = bits[5] ? PenType.Splatter : PenType.Solid;
                        penShape = bits[4] ? PenShape.Square : PenShape.Circle;
                        penSize  = 0;
                        if (bits[2])
                        {
                            penSize += 4;
                        }
                        if (bits[1])
                        {
                            penSize += 2;
                        }
                        if (bits[0])
                        {
                            penSize += 1;
                        }

                        break;

                    case 250: // plot
                        int plotX = 0;
                        int plotY = 0;
                        if (penType == PenType.Splatter)
                        {
                            int texture = c; // not used
                            plotX = fileData[++i];
                            plotY = fileData[++i];
                        }
                        else
                        {
                            plotX = c;
                            c     = fileData[++i];
                            plotY = c;
                        }
                        argNode = pictureDoc.CreateElement("coord");
                        argNode.SetAttribute("x", "" + plotX);
                        argNode.SetAttribute("y", "" + plotY);
                        Plot(plotX, plotY, penShape, penType, penSize);
                        break;
                    }
                    argumentCount++;
                }
            }
        }