コード例 #1
0
        private static bool IsCellFree(Canvass c, Coord pos, Model model)
        {
            int x = pos.X, y = pos.Y;

            if (x < 0 || y < 0)
            {
                return(false);
            }

            if (y >= c.Catode.Length)
            {
                return(false);                //throw new ArgumentException($"y=${y} is too large. Max ${Lines.Count}");
            }
            if (x >= c.Catode[0].Length)
            {
                return(false);                //throw new ArgumentException($"x=${x} is too large. Max ${line.Length}");
            }
            //Console.WriteLine($"{x},{y}::{(int)line[x]}");
            var cell = c.Catode[y][x];

            if (cell == null)
            {
                return(true);
            }
            var elem = model.Objects.First(z => z.Id == c.Occupants[y, x]);

            return(elem is Line || elem is SlopedLineVectorized || elem is SlopedLine2);
        }
コード例 #2
0
ファイル: TitledWindow.cs プロジェクト: jacobborella/AsciiUml
        public override Canvass Paint()
        {
            var size = Dimensions;

            if (Dimensions.IsFullyAutosize())
            {
                Position = Children.Single().Position - GetInnerCanvasTopLeft(); // todo find max spanning area of all children
                var childrensSize = GetSize();
                var mySize        = new GuiDimensions(new Size(title.Length + CloseButton.Length), childrensSize.Height);
                size = GuiDimensions.Max(childrensSize, mySize);
            }
            else
            {
                Position = Parent.GetInnerCanvasTopLeft();
            }

            var titleline = title.PadRight(size.Width.Pixels - CloseButton.Length) + CloseButton;

            var c = new Canvass();

            c.RawPaintString(titleline, 0, 0, ConsoleColor.DarkGray, ConsoleColor.Gray);
            var line = "".PadRight(size.Width.Pixels);

            for (int y = 1; y < size.Height.Pixels; y++)
            {
                c.RawPaintString(line, 0, y, BackGround, Foreground);
            }

            return(c);
        }
コード例 #3
0
        public override Canvass Paint()
        {
            var c    = new Canvass();
            var menu = state.Gui.TopMenuTextOverride ?? DefaultMenu();

            Canvass.PaintString(c, menu, 0, 0, -1, ConsoleColor.DarkGreen, ConsoleColor.Green);
            return(c);
        }
コード例 #4
0
ファイル: TopMenu.cs プロジェクト: jacobborella/AsciiUml
        public override Canvass Paint()
        {
            var c    = new Canvass();
            var menu = $"AsciiUml v0.1.1 Selected: {state.SelectedId?.ToString() ?? "None"}. ({state.TheCurser}) Press \'h\' for help";

            Canvass.PaintString(c, menu, 0, 0, -1, ConsoleColor.DarkGreen, ConsoleColor.Green);
            return(c);
        }
コード例 #5
0
ファイル: Button.cs プロジェクト: jacobborella/AsciiUml
        public override Canvass Paint()
        {
            var c           = new Canvass();
            var focusMarker = (IsFocused?">": " ");

            Canvass.PaintString(c, " " + focusMarker + buttonText + "  ", 0, 0, -10, backgroundColor, foregroundColor);
            return(c);
        }
コード例 #6
0
ファイル: TextBox.cs プロジェクト: jacobborella/AsciiUml
        public override Canvass Paint()
        {
            var c   = new Canvass();
            var res = Value.PadRight(Dimensions.Width.Pixels);

            c.RawPaintString(res, 0, 0, BackGround, Foreground);

            if (IsFocused)
            {
                WindowManager.SetCursorPosition(Position.Y, Position.X + cursor);
            }

            return(c);
        }
コード例 #7
0
        public static List <Coord> Calculate(Coord from, Coord to, Canvass c, Model model)
        {
            var size      = c.GetSize();
            var solutions = new Solution[size.Item1, size.Item2];
            var unHandled = new SimplePriorityQueue <UnhandledField>();

            unHandled.Enqueue(new UnhandledField(from, new List <Coord>(), 0), 0);

            while (unHandled.Count > 0)
            {
                var current = unHandled.Dequeue();

                var pathForPosition = new List <Coord>(current.Path.Count + 1);
                pathForPosition.AddRange(current.Path);
                pathForPosition.Add(current.Position);

                var solution = new Solution(pathForPosition, current.Distance);

                var ifNoOrWeakerSolution =
                    solution.Distance < (solutions[current.Position.Y, current.Position.X]?.Distance ?? int.MaxValue);
                if (ifNoOrWeakerSolution)
                {
                    solutions[current.Position.Y, current.Position.X] = solution;

                    var currentBestSolutionAtDestination = solutions[to.Y, to.X]?.Distance ?? int.MaxValue;
                    var neighbours = CalculateNSEW(current.Position);
                    var potentials = neighbours
                                     .Where(x => x == to || IsCellFree(c, x, model))
                                     .Select(x =>
                                             new {
                        Neighbour         = x,
                        EstimatedDistance =
                            PaintServiceCore.ManhattenDistance(x, to) + (Vector.IsStraightLine(x, to) ? 0 : WeightOfTurn),
                        Unhandled = new UnhandledField(x, pathForPosition, current.Distance + StepLength)
                    })
                                     .Where(x => current.Distance + x.EstimatedDistance + StepLength < currentBestSolutionAtDestination);

                    potentials.Each(x => unHandled.Enqueue(x.Unhandled, x.EstimatedDistance));
                }
            }

            var shortestPath = solutions[to.Y, to.X];

            return(shortestPath == null ? new List <Coord>() : shortestPath.Path);
        }
コード例 #8
0
ファイル: UnitTest1.cs プロジェクト: robbieg9876/Assessment1
 public UnitTest1()
 {
     //Sets graphics up on bitmap
     Test = new Canvass(Graphics.FromImage(OutputBitMap));
 }
コード例 #9
0
        public override Canvass Paint()
        {
            var c = new Canvass();

            return(c);
        }