示例#1
0
文件: Camera.cs 项目: dzamkov/DUIP
 /// <summary>
 /// Gets the view for this camera using a viewport with the given aspect ratio.
 /// </summary>
 public View GetView(double AspectRatio)
 {
     double size = this.Scale;
     Point off = AspectRatio > 1.0 ? new Point(size * AspectRatio, size) : new Point(size, size / AspectRatio);
     Rectangle rect = new Rectangle(this.Center - off, this.Center + off);
     return new View(rect);
 }
示例#2
0
 public override Layout CreateLayout(Context Context, Rectangle SizeRange, out Point Size)
 {
     return new _Layout
     {
         Block = this,
         Inner = this.Inner.CreateLayout(null, SizeRange, out Size),
         Size = Size
     };
 }
示例#3
0
文件: Size.cs 项目: dzamkov/DUIP
 /// <summary>
 /// Gets the limited size range created by this size block when given the full available size range.
 /// </summary>
 public Rectangle GetLimitedSizeRange(Rectangle SizeRange)
 {
     Rectangle lsr = this.LimitSizeRange;
     Rectangle csr = SizeRange;
     return new Rectangle(
         Math.Max(csr.Left, Math.Min(csr.Right, lsr.Left)),
         Math.Max(csr.Top, Math.Min(csr.Bottom, lsr.Top)),
         Math.Max(csr.Left, Math.Min(csr.Right, lsr.Right)),
         Math.Max(csr.Top, Math.Min(csr.Bottom, lsr.Bottom)));
 }
示例#4
0
文件: Margin.cs 项目: dzamkov/DUIP
 public override Layout CreateLayout(Context Context, Rectangle SizeRange, out Point Size)
 {
     Compass<double> margin = this.Margin;
     Point sizepadding = new Point(margin.Left + margin.Right, margin.Up + margin.Down);
     Layout inner = this.Inner.CreateLayout(null, SizeRange.Translate(-sizepadding), out Size);
     Size += sizepadding;
     return new _Layout
     {
         Offset = new Point(margin.Left, margin.Up),
         Inner = inner
     };
 }
示例#5
0
文件: Grid.cs 项目: dzamkov/DUIP
        public override Layout CreateLayout(Context Context, Rectangle SizeRange, out Point Size)
        {
            int cols = this.Columns;
            int rows = this.Rows;

            double sep = this.Seperator.Weight;
            Rectangle contentsizerange = SizeRange.Translate(-new Point(sep * (cols - 1), sep * (rows - 1)));

            // Create preliminary cell layouts to estimate sizes needed
            Point maxcellsize = contentsizerange.BottomRight;
            double[] widths = new double[cols];
            double[] heights = new double[rows];
            Layout[,] cells = new Layout[cols, rows];
            for (int c = 0; c < cols; c++)
            {
                for (int r = 0; r < rows; r++)
                {
                    Point size;
                    cells[c, r] = this.Cells[c, r].CreateLayout(null, new Rectangle(new Point(widths[c], heights[r]), maxcellsize), out size);
                    widths[c] = Math.Max(widths[c], size.X);
                    heights[r] = Math.Max(heights[r], size.Y);
                }
            }
            _AdjustSizes(widths, contentsizerange.Left, contentsizerange.Right);
            _AdjustSizes(heights, contentsizerange.Top, contentsizerange.Bottom);

            // Adjust cells to have the new sizes
            for (int c = 0; c < cols; c++)
            {
                double width = widths[c];
                for (int r = 0; r < rows; r++)
                {
                    double height = heights[r];
                    cells[c, r] = this.Cells[c, r].CreateLayout(null, new Point(width, height));
                }
            }

            // Determine offsets
            double totalwidth;
            double totalheight;
            double[] coloffsets = _GetOffsets(widths, sep, out totalwidth);
            double[] rowoffsets = _GetOffsets(heights, sep, out totalheight);

            Size = new Point(totalwidth, totalheight);
            return new _Layout
            {
                Block = this,
                Cells = cells,
                ColumnOffsets = coloffsets,
                RowOffsets = rowoffsets,
                Size = Size
            };
        }
示例#6
0
文件: Size.cs 项目: dzamkov/DUIP
 public override Layout CreateLayout(Context Context, Rectangle SizeRange, out Point Size)
 {
     return this.Inner.CreateLayout(Context, this.GetLimitedSizeRange(SizeRange), out Size);
 }
示例#7
0
文件: Size.cs 项目: dzamkov/DUIP
 public SizeBlock(Rectangle LimitSizeRange, Block Inner)
 {
     this.LimitSizeRange = LimitSizeRange;
     this.Inner = Inner;
 }
示例#8
0
文件: Space.cs 项目: dzamkov/DUIP
 public override Layout CreateLayout(Context Context, Rectangle SizeRange, out Point Size)
 {
     Size = SizeRange.TopLeft;
     return _Layout.Instance;
 }
示例#9
0
文件: Block.cs 项目: dzamkov/DUIP
 /// <summary>
 /// Creates a block that limits the size range available to this block.
 /// </summary>
 public SizeBlock WithSize(Rectangle LimitSizeRange)
 {
     return new SizeBlock(LimitSizeRange, this);
 }
示例#10
0
文件: Block.cs 项目: dzamkov/DUIP
 /// <summary>
 /// Creates a layout for this block with the preferred size within the given size range.
 /// </summary>
 public abstract Layout CreateLayout(Context Context, Rectangle SizeRange, out Point Size);
示例#11
0
文件: Flow.cs 项目: dzamkov/DUIP
        public override Layout CreateLayout(Context Context, Rectangle SizeRange, out Point Size)
        {
            FlowBlockStyle style = this.Style;
            Axis minoraxis = style.MinorAxis;
            SizeRange.TopLeft = SizeRange.TopLeft.Shift(minoraxis);
            SizeRange.BottomRight = SizeRange.BottomRight.Shift(minoraxis);

            // Determine minor size
            double minor = 0.0;
            if (this.Fit == CompactFlowFit.Instance)
            {
                minor = SizeRange.Right;
            }
            else
            {
                if (SizeRange.Left == SizeRange.Right)
                {
                    minor = SizeRange.Left;
                }
                else
                {
                    double pmajor;
                    minor = this._PickMinor(SizeRange.Left, SizeRange.Right, out pmajor);
                }
            }

            // Create lines
            List<_PlannedLine> lines;
            switch (style.WrapMode)
            {
                case FlowWrap.Greedy:
                    lines = _GetLinesGreedy(this.Items, minor, SizeRange.Right, style);
                    break;
                default:
                    throw new NotImplementedException();
            }

            // Create a space layout if lines can not be created
            if (lines == null)
            {
                Size = SizeRange.TopLeft;
                return SpaceBlock.Layout;
            }

            // Get minimum minor size needed to display all lines (this becomes the new minor size).
            double lminor = minor;
            minor = SizeRange.Left;
            foreach (_PlannedLine pl in lines)
            {
                double waste = lminor - pl.Length;
                minor = Math.Max(minor, pl.Length);
            }

            // Build layout lines
            double major;
            List<_Layout.Line> layoutlines = _BuildLayout(lines, this.Items, style, minor, SizeRange.Top, out major);

            // Create a space layout if the major size exceeds the size range
            if (major > SizeRange.Bottom + Layout.ErrorThreshold)
            {
                Size = SizeRange.TopLeft;
                return SpaceBlock.Layout;
            }

            // Create layout
            Size = new Point(minor, major).Shift(style.MinorAxis);
            return new _Layout
            {
                Block = this,
                Lines = layoutlines
            };
        }
示例#12
0
文件: Text.cs 项目: dzamkov/DUIP
        public override Layout CreateLayout(Context Context, Rectangle SizeRange, out Point Size)
        {
            TextBlockStyle style = this.Style;
            Point cellsize = style.CellSize;

            int minwidth = (int)(SizeRange.Left / cellsize.X);
            int minheight = (int)(SizeRange.Top / cellsize.Y);

            // Calculate width, height and line indices
            List<int> lineindices = new List<int>();
            int offset = 0;
            int width = minwidth;
            lineindices.Add(0); // Initial line, not explicitly indicated, but still deserves an index
            _Measure(style, this.Text, 0, lineindices, ref offset, ref width);
            int height = Math.Max(lineindices.Count, minheight);

            // Calculate actual size
            Size = new Point(width * cellsize.X, height * cellsize.Y);
            Size.X = Math.Min(Size.X, SizeRange.Right);
            Size.Y = Math.Min(Size.Y, SizeRange.Bottom);
            _Layout layout = new _Layout
            {
                TextBlock = this,
                Width = width,
                Height = height,
                LineIndices = lineindices
            };
            return layout;
        }
示例#13
0
文件: Border.cs 项目: dzamkov/DUIP
 public override Layout CreateLayout(Context Context, Rectangle SizeRange, out Point Size)
 {
     Point sizepadding = this.SizePadding;
     Layout inner = this.Inner.CreateLayout(null, SizeRange.Translate(-sizepadding), out Size);
     Size += sizepadding;
     return new _Layout
     {
         Block = this,
         Inner = inner,
         Size = Size
     };
 }