예제 #1
0
        public Switch(Scene scene, Point position)
            : base(ComponentType.Switch, new ComponentHitbox(new Rectangle(position, (int)(2 * scene.GetGridInterval()), (int)(2 * scene.GetGridInterval()))))
        {
            StartPosition = position / scene.ScaleFactor;
            Position      = position;
            Signal        = false;

            rectangles = new Rectangle[2];
            lines      = new Line[1];

            hitbox.Position = Position;
            Point indent = position + new Point((int)XIndent, (int)YIndent);

            uint interval = scene.GetGridInterval();

            rectangles[0] = new Rectangle(indent, (int)(2 * interval - 2 * XIndent * scene.ScaleFactor),
                                          (int)(2 * interval - 2 * YIndent * scene.ScaleFactor));

            rectangles[1] = new Rectangle(indent + new Point((int)(10 * scene.ScaleFactor), (int)(5 * scene.ScaleFactor)),
                                          (int)(rectangles[0].Width - 20 * scene.ScaleFactor),
                                          (int)(rectangles[0].Height - 10 * scene.ScaleFactor));

            outHitbox = new OutHitbox(new Point(rectangles[0].position.X + rectangles[0].Width, rectangles[0].position.Y + rectangles[0].Height / 2), this, (int)(scene.ScaleFactor * IOHitboxRadius), 0);

            lines[0] = new Line(new Point(rectangles[1].position.X,
                                          rectangles[1].position.Y + rectangles[1].Height / 4),
                                new Point(rectangles[1].position.X + rectangles[1].Width,
                                          rectangles[1].position.Y + rectangles[1].Height / 4));
        }
 public Rectangle(Point pos, int width, int height)
 {
     position = pos;
     Width    = width;
     Height   = height;
     Color    = Color.Black;
 }
예제 #3
0
        public override bool Select(Point location, Scene sender)
        {
            bool result = hitbox.Clicked(location);

            InHitbox  i = InputClicked(location);
            OutHitbox o = OutputClicked(location);

            if (i != null)
            {
                result = false;
                if (!sender.WirePlacementMode)
                {
                    sender.WireMode(location, this, i);
                }
            }

            else if (o != null)
            {
                result = false;
                if (!sender.WirePlacementMode)
                {
                    sender.WireMode(location, this, o, true);
                }
            }

            return(result);
        }
예제 #4
0
 public Arc(Point topEnd, Point botEnd, Point topLead, Point botLead)
 {
     ends[0]  = topEnd;
     ends[1]  = botEnd;
     leads[0] = topLead;
     leads[1] = botLead;
 }
예제 #5
0
 public bool Clicked(Point location)
 {
     return(location.X > hitbox.position.X &&
            location.X < hitbox.position.X + hitbox.Width &&
            location.Y > hitbox.position.Y &&
            location.Y < hitbox.position.Y + hitbox.Height);
 }
예제 #6
0
 public Grid(Point windowSize, Color color)
 {
     ScaleFactor   = 1;
     StartInterval = 35;
     Interval      = StartInterval;
     Color         = color;
     Thickness     = GridThickness.Small;
     WindowSize    = windowSize;
 }
예제 #7
0
 public Scene(Grid grid, Color background, IRenderer renderer)
 {
     Grid            = grid;
     Background      = background;
     Renderer        = renderer;
     ScaleFactor     = 1;
     LastScaleFactor = 1;
     Offset          = new Point(0, 0);
 }
예제 #8
0
 public Grid(Point windowSize)
 {
     ScaleFactor   = 1;
     StartInterval = 35;
     Interval      = StartInterval;
     Color         = Color.LightGray;
     Thickness     = GridThickness.Small;
     WindowSize    = windowSize;
 }
예제 #9
0
        public void MouseMove(Point location)
        {
            MouseLocation = location;

            if (WirePlacementMode)
            {
                Draw();
            }
        }
예제 #10
0
        public void Click(Point location, Scene sender)
        {
            if (hitbox.Clicked(location))
            {
                Flip();
            }

            sender.Update();
        }
예제 #11
0
 public Grid(Point windowSize, uint interval, Color color, GridThickness thickness)
 {
     ScaleFactor   = 1;
     StartInterval = interval;
     Interval      = interval;
     Color         = color;
     Thickness     = thickness;
     WindowSize    = windowSize;
 }
예제 #12
0
        public override void Scale(Scene scene, bool zoom)
        {
            Position = scene.ScaleFactor * StartPosition;

            Position = scene.Grid.SnapToGrid(Position);

            Point indent = Position + scene.ScaleFactor * new Point((int)XIndent, (int)YIndent);

            uint interval = scene.GetGridInterval();

            hitbox.Position = Position;
            hitbox.Width    = interval * 2f;
            hitbox.Height   = interval * 2f;

            rectangles[0] = new Rectangle(indent, (int)(2 * interval - 2 * XIndent * scene.ScaleFactor),
                                          (int)(2 * interval - 2 * YIndent * scene.ScaleFactor));

            rectangles[1] = new Rectangle(indent + new Point((int)(10 * scene.ScaleFactor), (int)(5 * scene.ScaleFactor)),
                                          (int)(rectangles[0].Width - 20 * scene.ScaleFactor),
                                          (int)(rectangles[0].Height - 10 * scene.ScaleFactor));

            ChangeColor(Color);

            outHitbox.Position = new Point(rectangles[0].position.X + rectangles[0].Width, rectangles[0].position.Y + rectangles[0].Height / 2);
            outHitbox.Radius   = (int)(scene.ScaleFactor * IOHitboxRadius);


            float yLine = 0;

            if (Signal)
            {
                yLine = 3 * rectangles[1].Height / 4;
            }
            else
            {
                yLine = rectangles[1].Height / 4;
            }

            lines[0] = new Line(new Point(rectangles[1].position.X,
                                          (int)(rectangles[1].position.Y + yLine)),
                                new Point(rectangles[1].position.X + rectangles[1].Width,
                                          (int)(rectangles[1].position.Y + yLine)));

            foreach (Component output in outputs)
            {
                if (output is Wire)
                {
                    output.Scale(scene, zoom);
                }
            }
        }
예제 #13
0
        internal void WireMode(Point start, Component sender, object hitbox, bool input = false)
        {
            WirePlacementMode = true;
            WireStart         = start;
            WireInput         = input;

            if (input)
            {
                WireInputComponent = sender;
                WireOutputHitbox   = (OutHitbox)hitbox;
            }
            else
            {
                WireOutputComponent = sender;
                WireInputHitbox     = (InHitbox)hitbox;
            }
        }
예제 #14
0
        private void SetParameter()
        {
            Point higher = points.OrderBy(y => y.Y).First();
            Point lower  = points.OrderBy(y => y.Y).Last();

            CollinearVector = new Vector(higher.X - lower.X,
                                         higher.Y - lower.Y);

            if (CollinearVector.X != 0)
            {
                Parameter = (higher.X - lower.X) / CollinearVector.X;
            }
            if (CollinearVector.Y != 0)
            {
                Parameter = (higher.Y - lower.Y) / CollinearVector.Y;
            }
        }
예제 #15
0
        public void SelectComponent(Point location)
        {
            Component selected = components
                                 .Where(c => c.Select(location, this))
                                 .OrderBy(c => c.ID)
                                 .LastOrDefault();

            if (SelectedComponent == selected)
            {
                DeselectComponent(selected);
            }
            else
            {
                DeselectComponent(SelectedComponent);
                SelectedComponent = selected;

                if (SelectedComponent != null)
                {
                    SelectedComponent.ChangeColor(Color.Orange);
                }
            }

            Draw(true);
        }
예제 #16
0
 public Circle(Point pos, int radius)
 {
     position    = pos;
     this.radius = radius;
 }
예제 #17
0
        public void KeyStroke(Key key, Point mouseLocation)
        {
            Point closest = Grid.SnapToGrid(mouseLocation);

            if (!WirePlacementMode)
            {
                switch (key)
                {
                case Key.T:
                    AddComponent(new Switch(this, closest));
                    break;

                case Key.L:
                    AddComponent(new Light(this, closest));
                    break;

                case Key.Q:
                    AddComponent(new ANDGate(this, closest));
                    break;

                case Key.W:
                    AddComponent(new NOTGate(this, closest));
                    break;

                case Key.E:
                    AddComponent(new ORGate(this, closest));
                    break;

                case Key.R:
                    AddComponent(new XORGate(this, closest));
                    break;

                case Key.Y:
                    AddComponent(new Clock(this, closest));
                    break;

                case Key.Plus:
                    Scale(0.25f);
                    break;

                case Key.Minus:
                    Scale(-0.25f);
                    break;

                case Key.Up:
                    if (SelectedComponent != null && !(SelectedComponent is Wire))
                    {
                        SelectedComponent.Translate(this, Direction.Up, 1);
                    }
                    else
                    {
                        TranslateScene(Direction.Down);
                    }
                    break;

                case Key.Down:
                    if (SelectedComponent != null && !(SelectedComponent is Wire))
                    {
                        SelectedComponent.Translate(this, Direction.Down, 1);
                    }
                    else
                    {
                        TranslateScene(Direction.Up);
                    }
                    break;

                case Key.Right:
                    if (SelectedComponent != null && !(SelectedComponent is Wire))
                    {
                        SelectedComponent.Translate(this, Direction.Right, 1);
                    }
                    else
                    {
                        TranslateScene(Direction.Left);
                    }
                    break;

                case Key.Left:
                    if (SelectedComponent != null && !(SelectedComponent is Wire))
                    {
                        SelectedComponent.Translate(this, Direction.Left, 1);
                    }
                    else
                    {
                        TranslateScene(Direction.Right);
                    }
                    break;

                case Key.Delete:
                    if (SelectedComponent != null)
                    {
                        RemoveComponent(SelectedComponent);
                    }
                    break;
                }
            }
        }
예제 #18
0
        public void MouseClick(MouseKey key, Point location)
        {
            switch (key)
            {
            case MouseKey.Left:
                if (WirePlacementMode)
                {
                    foreach (Component component in components)
                    {
                        component.Select(location, this);
                    }

                    if (WireOutputComponent == null)
                    {
                        WireOutputComponent = components
                                              .Where(c => c.InputClicked(location) != null)
                                              .LastOrDefault();
                    }

                    if (WireInputComponent == null)
                    {
                        WireInputComponent = components
                                             .Where(c => c.OutputClicked(location) != null)
                                             .LastOrDefault();
                    }

                    if (WireInputHitbox == null && WireOutputComponent is Wire)
                    {
                        WireInputHitbox = WireOutputComponent.inHitboxes[0];
                    }
                    else if (WireInputHitbox == null && WireOutputComponent != null)
                    {
                        foreach (InHitbox hitbox in WireOutputComponent.inHitboxes)
                        {
                            if (hitbox.Clicked(location))
                            {
                                WireInputHitbox = hitbox;
                            }
                        }
                    }

                    if (WireOutputHitbox == null)
                    {
                        WireOutputHitbox = WireInputComponent.outHitbox;
                    }

                    Wire wire = new Wire(this, new Line(WireStart, location), WireInputComponent, WireOutputComponent);

                    if (WireInputComponent is Wire && WireOutputComponent is Wire)
                    {
                        //((Wire)WireInputComponent).InConnected = wire.inHitboxes[0];
                        wire.outHitbox     = ((Wire)WireInputComponent).OutConnected;
                        wire.inHitboxes[0] = ((Wire)WireOutputComponent).InConnected;

                        wire.InConnected = wire.inHitboxes[0];
                        //wire.OutConnected = wire.outHitbox;
                    }

                    AddComponent(wire);

                    // Update output component on wire creation.
                    if (WireOutputComponent != null && !(WireOutputComponent is Wire))
                    {
                        WireOutputComponent.Process(this);
                    }

                    EndPlacementMode();
                }
                else
                {
                    SelectComponent(location);
                    Draw(true);
                }
                break;

            case MouseKey.Right:
                if (WirePlacementMode)
                {
                    EndPlacementMode();

                    Draw();
                }
                else
                {
                    foreach (Component c in components)
                    {
                        if (c is IClickable)
                        {
                            ((IClickable)c).Click(location, this);
                        }
                    }

                    Draw();
                }
                break;

            default:
                if (WirePlacementMode)
                {
                    EndPlacementMode();
                }
                break;
            }
        }
 public Rectangle(Point pos, int width, int height, Color color)
 {
     position = pos;
     Width    = width;
     Height   = height;
 }
 public InHitbox(Point position, Component component, int radius, int inputIndex)
 {
     AttachedInputIndex = inputIndex;
     hitbox             = new Circle(position, radius);
     Component          = component;
 }
예제 #21
0
 public OutHitbox(Point position, Component component, int radius, int outputIndex)
 {
     AttachedOutputIndex = outputIndex;
     hitbox    = new Circle(position, radius);
     Component = component;
 }
예제 #22
0
 public bool Clicked(Point location)
 {
     return(Point.Distance(location, hitbox.position) <= hitbox.radius);
 }
 public Rectangle()
 {
     position = new Point(0, 0);
     Width    = 0;
     Height   = 0;
 }
예제 #24
0
 public Point SnapToGrid(Point point)
 {
     return(new Point(point.X - (point.X % (int)Interval),
                      point.Y - (point.Y % (int)Interval)));
 }
예제 #25
0
        public Line(Point point1, Point point2)
        {
            points = new Point[] { point1, point2 };

            SetParameter();
        }