Exemple #1
0
    Tuple <Image, Image> LoadSignalImages(RoadID road)
    {
        Image l = new Image();
        Image r = new Image();

        switch (road)
        {
        case (RoadID.Bottom):
            l.PixbufAnimation = new Gdk.PixbufAnimation(null, "monitor.resources.signal_left.gif");
            r.PixbufAnimation = new Gdk.PixbufAnimation(null, "monitor.resources.signal_right.gif");
            break;

        case (RoadID.Left):
            l.PixbufAnimation = new Gdk.PixbufAnimation(null, "monitor.resources.signal_up.gif");
            r.PixbufAnimation = new Gdk.PixbufAnimation(null, "monitor.resources.signal_down.gif");
            break;

        case (RoadID.Top):
            l.PixbufAnimation = new Gdk.PixbufAnimation(null, "monitor.resources.signal_right.gif");
            r.PixbufAnimation = new Gdk.PixbufAnimation(null, "monitor.resources.signal_left.gif");
            break;

        case (RoadID.Right):
            l.PixbufAnimation = new Gdk.PixbufAnimation(null, "monitor.resources.signal_down.gif");
            r.PixbufAnimation = new Gdk.PixbufAnimation(null, "monitor.resources.signal_up.gif");
            break;
        }
        return(Tuple.Create(l, r));
    }
Exemple #2
0
    Tuple <int, int> ComputeLabelPosition(RoadID road, Gdk.Rectangle allocation)
    {
        int x = 0;
        int y = 0;

        switch (road)
        {
        case (RoadID.Bottom):
            x = allocation.Width / 2 + cRadW;
            y = allocation.Height / 2 + cRadH;
            break;

        case (RoadID.Left):
            x = allocation.Width / 2 - cRadW - labelW;
            y = allocation.Height / 2 + cRadH;
            break;

        case (RoadID.Top):
            x = allocation.Width / 2 - cRadW - labelW;
            y = allocation.Height / 2 - cRadH - labelH;
            break;

        case (RoadID.Right):
            x = allocation.Width / 2 + cRadW;
            y = allocation.Height / 2 - cRadH - labelH;
            break;
        }

        return(Tuple.Create(x, y));
    }
Exemple #3
0
    void PlaceSignals(Image leftSignal, Image rightSignal, RoadID road)
    {
        Tuple <int, int, int, int> pos = ComputeSignalPositions(road, leftSignal, Allocation);
        int xl = pos.Item1;
        int yl = pos.Item2;
        int xr = pos.Item3;
        int yr = pos.Item4;

        container.Put(leftSignal, xl, yl);
        container.Put(rightSignal, xr, yr);
        leftSignal.Hide();
        rightSignal.Hide();
    }
Exemple #4
0
    Label LoadLabel(RoadID road)
    {
        Label label = new Label();

        label.SetSizeRequest(labelW, labelH);
        label.ModifyBase(StateType.Normal, new Gdk.Color(230, 230, 230));
        label.ModifyFont(Pango.FontDescription.FromString(fontFamily + " " + fontSize));
        label.Text = MakeCarLabelText();
        if (road == RoadID.Left || road == RoadID.Top)
        {
            label.Justify = Justification.Right;
        }
        return(label);
    }
Exemple #5
0
    Image LoadCarImage(string expectedImagePath, RoadID id)
    {
        Image car;

        // Image not present, I have to create it
        try
        {
            car      = Image.LoadFromResource(expectedImagePath);
            car.Name = id + expectedImagePath;
        }
        catch (ArgumentException)
        {
            // The car advertised an unknown manufacturer or model
            car      = Image.LoadFromResource(unknownImagePath);
            car.Name = id + unknownImagePath;
        }
        return(car);
    }
Exemple #6
0
    /**
     * returns the positions of the signals of the car on `road`.
     * Assumptions: image `signal` already rotated; the two signals have the same size
     */
    Tuple <int, int, int, int> ComputeSignalPositions(RoadID road, Image signal, Gdk.Rectangle allocation)
    {
        int sW = signal.PixbufAnimation.Width;
        int sH = signal.PixbufAnimation.Height;

        int xl = 0;
        int yl = 0;
        int xr = 0;
        int yr = 0;

        switch (road)
        {
        case (RoadID.Bottom):
            xl = allocation.Width / 2;
            yl = allocation.Height / 2 + cRadH - sH;
            xr = xl + cRadW - sW;
            yr = yl;
            break;

        case (RoadID.Left):
            xl = allocation.Width / 2 - cRadW;
            yl = allocation.Height / 2;
            xr = xl;
            yr = yl + cRadH - sH;
            break;

        case (RoadID.Top):
            xl = allocation.Width / 2 - sW;
            xr = xl - cRadW + sW;
            yl = allocation.Height / 2 - cRadH;
            yr = yl;
            break;

        case (RoadID.Right):
            xl = allocation.Width / 2 + cRadW - sW;
            xr = xl;
            yl = allocation.Height / 2 - sH;
            yr = yl - cRadH + sH;
            break;
        }

        return(Tuple.Create(xl, yl, xr, yr));
    }
Exemple #7
0
    Tuple <int, int> ComputeCarPosition(RoadID road, Image car, Gdk.Rectangle allocation)
    {
        int crossW             = allocation.Width;
        int crossH             = allocation.Height;
        int carLong            = car.Pixbuf.Height > car.Pixbuf.Width ? car.Pixbuf.Height : car.Pixbuf.Width;
        int carShort           = car.Pixbuf.Height < car.Pixbuf.Width ? car.Pixbuf.Height : car.Pixbuf.Width;
        int stepToMiddleShortW = (cRadW - carShort) / 2;
        int stepToMiddleShortH = (cRadH - carShort) / 2;

        int x = 0;
        int y = 0;

        switch (road)
        {
        case RoadID.Bottom:
            x = crossW / 2 + stepToMiddleShortW;
            y = crossH / 2 + cRadH;
            break;

        case RoadID.Left:
            x = crossW / 2 - cRadW - carLong;
            y = crossH / 2 + stepToMiddleShortH;
            break;

        case RoadID.Top:
            x = crossW / 2 - cRadW + stepToMiddleShortW;
            y = crossH / 2 - cRadW - carLong;
            break;

        case RoadID.Right:
            x = crossW / 2 + cRadW;
            y = crossH / 2 - cRadH + stepToMiddleShortH;
            break;
        }

        return(Tuple.Create(x, y));
    }
Exemple #8
0
 public Road(RoadID id)
 {
     Id = id;
 }
Exemple #9
0
    void PlaceLabel(Label label, RoadID road)
    {
        Tuple <int, int> pos = ComputeLabelPosition(road, Allocation);

        container.Put(label, pos.Item1, pos.Item2);
    }