Exemple #1
0
        //Update every frame
        private new void Update()
        {
            if (current.drawable != null)
            {
                if (current.drawable.GetType() == typeof(Line))//Set end of the line to mouse position
                {
                    Line l = current.drawable as Line;
                    l.end = (Vector2f)Mouse.GetPosition(window);
                    l.Update();
                    current.drawable = l;
                }
                else if (current.drawable.GetType() == typeof(CircleShape))//Set the position of the circle
                {
                    CircleShape c = current.drawable as CircleShape;
                    c.Position = (Vector2f)Mouse.GetPosition(window) - new Vector2f(c.Radius, c.Radius);

                    current.drawable = c;
                }
                else if (current.drawable.GetType() == typeof(Text))
                {
                    Text t = current.drawable as Text;
                    t.Position = (Vector2f)Mouse.GetPosition(window);

                    current.drawable = t;
                }
                else if (current.drawable.GetType() == typeof(BezierCurve))//If no handle is selected set the end position and handles
                {
                    BezierCurve b = current.drawable as BezierCurve;
                    switch (b.handling) //If a handle is selected set the position
                    {
                    case "n":
                        return;

                    case "s":
                        b.starthandle = (Vector2f)Mouse.GetPosition(window);
                        b.Update();
                        current.drawable = b;
                        return;

                    case "e":
                        b.endhandle = (Vector2f)Mouse.GetPosition(window);
                        b.Update();
                        current.drawable = b;
                        return;
                    }
                    b.end         = (Vector2f)Mouse.GetPosition(window);
                    b.starthandle = new Vector2f((b.end.X - b.start.X) * 0.25f + b.start.X, (b.end.Y - b.start.Y) * 0.25f + b.start.Y);
                    b.endhandle   = new Vector2f((b.end.X - b.start.X) * 0.75f + b.start.X, (b.end.Y - b.start.Y) * 0.75f + b.start.Y);
                    b.Update();
                    current.drawable = b;
                }
            }
        }
Exemple #2
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);
        }