Example #1
0
        public override void UpdatePath(IPath path, PathOrientation pathOrientation, DimensionScale scale)
        {
            base.UpdatePath(path, pathOrientation, scale);

            if (path.GetBounds().Empty)
            {
                return;
            }

            //Trace.TraceInformation("GridLayout::ResizeChildren");

            var columnRatio = 1.0 / ColumnCount;
            //Trace.TraceInformation("columnRatio = {0}", columnRatio);

            var rowRatio = 1.0 / RowCount;

            //Trace.TraceInformation("rowRatio = {0}", rowRatio);

            for (var column = 0; column < ColumnCount; ++column)
            {
                for (var row = 0; row < RowCount; ++row)
                {
                    var columnSpan = GetColumnSpan(row, column);
                    var rowSpan    = GetRowSpan(row, column);

                    var top1 = Path.Interpolate(0, column * columnRatio);
                    var top2 = Path.Interpolate(0, (column + columnSpan) * columnRatio);

                    var bottom1 = Path.Interpolate(2, 1.0 - (column * columnRatio));
                    var bottom2 = Path.Interpolate(2, 1.0 - ((column + columnSpan) * columnRatio));

                    var right1 = Path.Interpolate(1, row * rowRatio);
                    var right2 = Path.Interpolate(1, (row + rowSpan) * rowRatio);

                    var left1 = Path.Interpolate(3, 1.0 - (row * rowRatio));
                    var left2 = Path.Interpolate(3, 1.0 - ((row + rowSpan) * rowRatio));

                    var p1 = Geometry.Intersection(top1, bottom1, right1, left1);
                    var p2 = Geometry.Intersection(top2, bottom2, right1, left1);
                    var p3 = Geometry.Intersection(top2, bottom2, right2, left2);
                    var p4 = Geometry.Intersection(top1, bottom1, right2, left2);

                    if (p1.IsInvalid || p2.IsInvalid || p3.IsInvalid || p4.IsInvalid)
                    {
                        throw new InvalidOperationException();
                    }
                    else
                    {
                        var pathCell = PathGeometries.Rectangle.CreatePath(
                            new PathPoint[] { p1, p2, p3, p4 });

                        //Trace.TraceInformation("Layout {0},{1} = {2}", row, column, path.ToString());

                        var layoutSite = GetLayoutSite(row, column);
                        layoutSite.UpdatePath(pathCell, scale);
                    }
                }
            }
        }
Example #2
0
        public void AddPath(IPath path, bool connect)
        {
            if (connect)
            {
                throw new Exception("The method or operation is not implemented.");
            }
            else
            {
                if (path is VectorPath)
                {
                    m_editMask.FillPath(Brushes.Black, (VectorPath)path);
                    m_editVisual.FillPath(m_visualFill, (VectorPath)path);

                    m_lineTrace.StartFigure();
                    m_lineTrace.AddPath((VectorPath)path, false);

                    // keep track of bounds
                    RectangleF rect = path.GetBounds();
                    if (rect.Left < m_left)
                        m_left = (int)rect.Left;
                    if (rect.Right > m_left + m_width)
                        m_width = (int)rect.Right - m_left;
                    if (rect.Top < m_top)
                        m_top = (int)rect.Top;
                    if (rect.Bottom > m_top + m_height)
                        m_height = (int)rect.Bottom - m_top;

                    m_count += path.PointCount;
                }
                else if (path is BitmapPath)
                {
                    if (m_count == 0)
                    {
                        BitmapPath o = (BitmapPath)path;
                        m_editMask.DrawImage(o.m_mask, new Point(0, 0));
                        m_editVisual.DrawImage(o.m_visual, new Point(0, 0));
                        m_count = o.m_count;
                        m_left = o.m_left;
                        m_top = o.m_top;
                        m_width = o.m_width;
                        m_height = o.m_height;

                        if (o.m_lineTrace.PointCount > 0)
                        {
                            m_lineTrace.StartFigure();
                            m_lineTrace.AddPath(o.m_lineTrace, false);
                        }
                        // m_lineTrace.AddRectangle(new Rectangle(m_left, m_top, m_width, m_height));

                    }
                    else
                    {
                        throw new Exception("not implemented");
                    }
                }
            }
        }