/// <summary>
        /// Creates a new ElementControl that can create clones of el.
        /// </summary>
        /// <param name="el">Element that should be cloned.</param>
        /// <param name="label">Label for the element.</param>
        /// <param name="font">Font used for the label.</param>
        public ElementControl(PinballElement el, string label, Font font)
        {
            InitializeComponent();

            // Assign instance vars
            ElementFont = font;
            Element = el;
            Label = label;
            Height = THUMB_HEIGHT;
            Width = 200;

            // Add event listeners
            MouseEnter += (s, e) => { BackColor = System.Drawing.SystemColors.Highlight; ForeColor = Color.White; };
            MouseLeave += (s, e) => { BackColor = System.Drawing.SystemColors.Control; ForeColor = Color.Black; };

            thumb = GetImage();
        }
 public TranslationChange(PinballElement element, Vector vector)
     : this(element, (int)vector.X, (int)vector.Y)
 {
 }
 public CreationChange(ElementCollection collection, PinballElement element)
 {
     this.collection = collection;
     this.element = element;
 }
Esempio n. 4
0
        protected override void OnMouseDown(object sender, MouseEventArgs e)
        {
            // Only act if we're idle
            if (State == SelectionState.Idle)
            {
                if (e.LeftButton == MouseButtonState.Pressed)
                {
                    if (SelectedElement != null && Control.ModifierKeys == System.Windows.Forms.Keys.Control)
                    {
                        State = SelectionState.Shaping;

                        var pos = Editor.PointToEditor(SelectedElement.Location + SelectedElement.GetRotationOrigin());
                        shapeData.origin = new Point(pos.X, pos.Y);

                        shapeData.startPoint = e.GetPosition(Editor);
                        double factor = (shapeData.startPoint - shapeData.origin).Length / MIN_LENGTH;
                        if (factor < 1)
                        {
                            shapeData.startPoint += (shapeData.startPoint - shapeData.origin) * (1 / factor);
                        }

                        currentPoint = new Point(shapeData.startPoint.X, shapeData.startPoint.Y);

                        shapeData.initialPoint = SelectedElement.Location;
                        shapeData.initialScale = SelectedElement.Scale;
                        shapeData.initialRotation = SelectedElement.BaseRotation;
                    }
                    else
                    {
                        State = SelectionState.Dragging;

                        var pos = e.GetPosition(Editor);
                        Point loc = Editor.PointToPinball(pos);

                        PinballElement element = FindElement(loc);
                        if (element != null)
                        {
                            // Select
                            SelectedElement = element;
                            this.delta = new Vector(pos.X, pos.Y) - Editor.PointToEditor(SelectedElement.Location);
                            startVector = SelectedElement.Location;
                        }
                        else
                        {
                            SelectedElement = null;
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        protected override void OnUnselect()
        {
            Editor.KeyDown -= OnDelete;

            SelectedElement = null;
        }
 /// <summary>
 /// Construtor to create new bounding container
 /// </summary>
 /// <param name="parent">Parent of this container</param>
 public BoundingContainer(PinballElement parent)
 {
     this.BoundingBoxes = new List<IBoundingBox>();
     this.ParentElement = parent;
     this.Rotation = 0;
 }
 private void raiseCollision(PinballElement element)
 {
     var handlers = Collision;
     if (handlers != null)
     {
         handlers(element);
     }
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="msg">Describes the problem.</param>
 /// <param name="element">Element involved.</param>
 public ValidationProblem(string msg, PinballElement element)
     : this(msg, new PinballElement[] { element })
 {
 }
 /// <summary>
 /// Brings an element to front for drawing.
 /// </summary>
 /// <param name="element"></param>
 public void BringToFront(PinballElement element)
 {
     DynamicElements.MoveToTail(element);
 }
Esempio n. 10
0
 public void Add(PinballElement element)
 {
     DynamicElements.Add(element);
 }
 private void RaiseSelectionChanged(PinballElement prev)
 {
     var listeners = SelectionChanged;
     if (listeners != null)
     {
         listeners(prev, SelectedElement);
     }
 }
        /// <summary>
        /// Removes an element from the pinball machine AND keeps track of it.
        /// </summary>
        /// <param name="element"></param>
        public void RemoveElement(PinballElement element)
        {
            IChange change = new DeletionChange(PinballMachine.DynamicElements, element);

            if (element is WormholeExit)
            {
                List<IChange> changes = new List<IChange>();
                changes.Add(change);

                var exit = element as WormholeExit;
                foreach (var entry in exit.Entries)
                {
                    changes.Add(new DeletionChange(PinballMachine.DynamicElements, entry));
                }

                IChange mainChange = new CompoundChange(changes);
                mainChange.Do();
                History.Add(mainChange);
            }
            else
            {
                change.Do();

                History.Add(change);
            }
        }
        /// <summary>
        /// Adds a new element to the pinball machine AND keeps track of it.
        /// </summary>
        /// <param name="element"></param>
        public void AddElement(PinballElement element)
        {
            IChange change = new CreationChange(PinballMachine.DynamicElements, element);
            change.Do();

            History.Add(change);
        }
 public TranslationChange(PinballElement element, int dx, int dy)
 {
     this.element = element;
     this.dx = dx;
     this.dy = dy;
 }
Esempio n. 15
0
 public bool Remove(PinballElement element)
 {
     return DynamicElements.Remove(element);
 }
Esempio n. 16
0
 // Makes sure that the elementInspector always has the right element.
 private void onSelectionChanged(PinballElement prevElement, PinballElement newElement)
 {
     if (newElement != null)
     {
         elementInspector.SelectedObject = newElement;
     }
     else
     {
         elementInspector.SelectedObject = null;
     }
 }
Esempio n. 17
0
 protected override void OnClone(PinballElement element)
 {
     var el = element as CustomElement;
     el.Color = System.Drawing.Color.FromArgb(255, Color.R, Color.G, Color.B);
 }
Esempio n. 18
0
 /// <summary>
 /// Does additional stuff when an element is cloned.
 /// </summary>
 /// <param name="element"></param>
 protected virtual void OnClone(PinballElement element)
 {
 }
Esempio n. 19
0
 /// <summary>
 /// Increment score when a collision happened.
 /// </summary>
 /// <param name="sender"></param>
 private void OnScore(PinballElement sender)
 {
     Score += sender.Value;
 }