Пример #1
0
        void InitPhysics()
        {
            var s = CCDirector.SharedDirector.WinSize;

            space = new Space()
            {
                Gravity = new PointF(0, -300)
            };

            // bottom
            walls[0] = new SegmentShape(space.StaticBody, new PointF(0, 0), new PointF(s.Width, 0), 0f);
            // top
            walls[1] = new SegmentShape(space.StaticBody, new PointF(0, s.Height), new PointF(s.Width, s.Height), 0f);
            // left
            walls[2] = new SegmentShape(space.StaticBody, new PointF(0, 0), new PointF(0, s.Height), 0f);
            // right
            walls[3] = new SegmentShape(space.StaticBody, new PointF(s.Width, 0), new PointF(s.Width, s.Height), 0f);

            foreach (var shape in walls)
            {
                shape.Elasticity = 2f;
                shape.Friction   = 1f;
                space.AddStaticShape(shape);
            }
        }
Пример #2
0
 public SegmentShape Inflate(SegmentShape other)
 {
     return(new SegmentShape(
                Math.Max(Width, other.Width),
                Math.Max(Height, other.Height)));
 }
Пример #3
0
    protected override IEnumerable <Segment> Render(RenderContext context, int maxWidth)
    {
        lock (_lock)
        {
            DidOverflow = false;

            if (_renderable != null)
            {
                var segments = _renderable.Render(context, maxWidth);
                var lines    = Segment.SplitLines(segments);

                var shape = SegmentShape.Calculate(context, lines);
                if (shape.Height > _console.Profile.Height)
                {
                    if (Overflow == VerticalOverflow.Crop)
                    {
                        if (OverflowCropping == VerticalOverflowCropping.Bottom)
                        {
                            // Remove bottom lines
                            var index = Math.Min(_console.Profile.Height, lines.Count);
                            var count = lines.Count - index;
                            lines.RemoveRange(index, count);
                        }
                        else
                        {
                            // Remove top lines
                            var start = lines.Count - _console.Profile.Height;
                            lines.RemoveRange(0, start);
                        }

                        shape = SegmentShape.Calculate(context, lines);
                    }
                    else if (Overflow == VerticalOverflow.Ellipsis)
                    {
                        var ellipsisText = _console.Profile.Capabilities.Unicode ? "…" : "...";
                        var ellipsis     = new SegmentLine(((IRenderable) new Markup($"[yellow]{ellipsisText}[/]")).Render(context, maxWidth));

                        if (OverflowCropping == VerticalOverflowCropping.Bottom)
                        {
                            // Remove bottom lines
                            var index = Math.Min(_console.Profile.Height - 1, lines.Count);
                            var count = lines.Count - index;
                            lines.RemoveRange(index, count);
                            lines.Add(ellipsis);
                        }
                        else
                        {
                            // Remove top lines
                            var start = lines.Count - _console.Profile.Height;
                            lines.RemoveRange(0, start + 1);
                            lines.Insert(0, ellipsis);
                        }

                        shape = SegmentShape.Calculate(context, lines);
                    }

                    DidOverflow = true;
                }

                _shape = _shape == null ? shape : _shape.Value.Inflate(shape);
                _shape.Value.Apply(context, ref lines);

                foreach (var(_, _, last, line) in lines.Enumerate())
                {
                    foreach (var item in line)
                    {
                        yield return(item);
                    }

                    if (!last)
                    {
                        yield return(Segment.LineBreak);
                    }
                }

                yield break;
            }

            _shape = null;
        }
    }