Esempio n. 1
0
        public static Drawable parseCommand(string[] subCommands)
        {
            switch (subCommands[0])
            {
            case "l":
                Line s = new Line(
                    new Vector2f(int.Parse(subCommands[1]), int.Parse(subCommands[2])),
                    new Vector2f(int.Parse(subCommands[3]), int.Parse(subCommands[4])),
                    new Color(
                        byte.Parse(subCommands[5]),
                        byte.Parse(subCommands[6]),
                        byte.Parse(subCommands[7])
                        )
                    );
                s.Update();
                return(s);

            case "c":
                CircleShape c = new CircleShape(int.Parse(subCommands[3]));
                c.Position         = new Vector2f(int.Parse(subCommands[1]) - int.Parse(subCommands[3]), int.Parse(subCommands[2]) - int.Parse(subCommands[3]));
                c.OutlineColor     = new Color(byte.Parse(subCommands[4]), byte.Parse(subCommands[5]), byte.Parse(subCommands[6]));
                c.OutlineThickness = 1;
                c.FillColor        = Color.Transparent;
                string[] addentum = subCommands.Skip(6).ToArray();
                byte     Opacity  = 255;
                foreach (string a in addentum)
                {
                    string[] subaddentum = a.Split(':');
                    switch (subaddentum[0])
                    {
                    case "f":
                        c.FillColor = new Color(byte.Parse(subaddentum[1]), byte.Parse(subaddentum[2]), byte.Parse(subaddentum[3]));
                        break;

                    case "o":
                        Opacity = byte.Parse(subaddentum[1]);
                        break;
                    }
                }
                if (Opacity != 255)
                {
                    Color oc = new Color(c.OutlineColor);
                    oc.A           = (byte)Opacity;
                    c.OutlineColor = oc;
                    if (c.FillColor.A != 0)
                    {
                        Color fc = new Color(c.FillColor);
                        fc.A        = Opacity;
                        c.FillColor = fc;
                    }
                }
                return(c);

            case "t":
                Font font = new Font(Properties.Resources.aileron_bold);
                SFML.Graphics.Text text = new Text(subCommands[1], font, uint.Parse(subCommands[4]));
                text.Position  = new Vector2f(int.Parse(subCommands[2]), int.Parse(subCommands[3]));
                text.FillColor = new Color(byte.Parse(subCommands[5]), byte.Parse(subCommands[6]), byte.Parse(subCommands[7]));

                return(text);

            case "b":
                BezierCurve b = new BezierCurve(new Vector2f(int.Parse(subCommands[1]), int.Parse(subCommands[2])), new Vector2f(int.Parse(subCommands[3]), int.Parse(subCommands[4])), new Vector2f(int.Parse(subCommands[5]), int.Parse(subCommands[6])), new Vector2f(int.Parse(subCommands[7]), int.Parse(subCommands[8])), new Color(byte.Parse(subCommands[9]), byte.Parse(subCommands[10]), byte.Parse(subCommands[11])));
                b.Update();
                return(b);
            }

            return(null);
        }
Esempio n. 2
0
        private void window_mousedown(object sender, MouseButtonEventArgs e)
        {
            if (current.drawable == null || e.Button == Mouse.Button.Right)
            {
                if (e.Button == Mouse.Button.Right && current.drawable != null)
                {
                    sprites.Add(current.drawable);
                }

                switch (Selected)
                {
                case "line":
                    current          = new DrawingCurrent();
                    current.drawable = new Line((Vector2f)Mouse.GetPosition(window), (Vector2f)Mouse.GetPosition(window), currentColor);
                    break;

                case "circle":
                    float radius = 50;
                    if (current.drawable != null)
                    {
                        if (current.drawable.GetType() == typeof(CircleShape))
                        {
                            radius = (current.drawable as CircleShape).Radius;
                        }
                    }

                    current = new DrawingCurrent();
                    CircleShape c = new CircleShape(radius);
                    c.Position         = (Vector2f)Mouse.GetPosition(window) - new Vector2f(c.Radius, c.Radius);
                    c.OutlineColor     = currentColor;
                    c.OutlineThickness = 1;
                    c.FillColor        = Color.Transparent;
                    current.drawable   = c;
                    break;

                case "text":

                    string s = "";
                    if (e.Button == Mouse.Button.Right && current.drawable.GetType() == typeof(Text))
                    {
                        s = (current.drawable as Text).DisplayedString;
                    }
                    else
                    {
                        s = Interaction.InputBox("Text", "Text");
                    }
                    SFML.Graphics.Text t = new Text(s, new Font(Properties.Resources.aileron_bold));
                    t.CharacterSize = 50;
                    t.Position      = new Vector2f(50, 55);
                    t.FillColor     = currentColor;

                    current.drawable = t;
                    break;

                case "bezier":
                    current          = new DrawingCurrent();
                    current.drawable = new BezierCurve((Vector2f)Mouse.GetPosition(window), (Vector2f)Mouse.GetPosition(window), (Vector2f)Mouse.GetPosition(window), (Vector2f)Mouse.GetPosition(window), currentColor);

                    break;
                }
            }
            else
            {
                if (current.drawable.GetType() == typeof(BezierCurve))
                {
                    BezierCurve b = current.drawable as BezierCurve;
                    if (b.handling == "n")
                    {
                        if (Drawables.CircleContains((Vector2i)b.starthandle, 12, Mouse.GetPosition(window)))
                        {
                            b.handling = "s";
                        }
                        else if (Drawables.CircleContains((Vector2i)b.endhandle, 12, Mouse.GetPosition(window)))
                        {
                            b.handling = "e";
                        }
                        else
                        {
                            b.handling       = "";
                            current.drawable = b;
                            sprites.Add(current.drawable);
                            current.drawable = null;
                            return;
                        }
                    }
                    else
                    {
                        b.handling = "n";
                    }
                    current.drawable = b;
                    return;
                }
                sprites.Add(current.drawable);
                current.drawable = null;
            }
        }