Exemple #1
0
 private void CalculateNewSize()
 {
     if (_visual != null)
     {
         _size = _visual.GetSize (new GraphicsContext (Graphics.FromHwnd (Handle)));
         Width = Convert.ToInt32 (_size.Width);
         Height = Convert.ToInt32 (_size.Height);
     }
     Invalidate ();
 }
Exemple #2
0
 /// <summary>
 /// Add another box to vertically to this one.
 /// </summary>
 public VBox VAdd(VBox other)
 {
     return new VBox (Width, Height + other.Height);
 }
Exemple #3
0
 protected override VBox Draw(GraphicsContext context, VBox availableSize)
 {
     var st = context.Graphics.Save ();
     context.Graphics.TranslateTransform (Left, Top);
     var box = base.Draw (context, availableSize);
     context.Graphics.Restore (st);
     return new VBox (box.Width + Left + Right, box.Height + Top + Bottom);
 }
Exemple #4
0
 protected override VBox Draw(GraphicsContext context, VBox availableSize)
 {
     return GetSize (context);
 }
Exemple #5
0
            private IEnumerable<Tuple<int, VBox>> WrapToLines(GraphicsContext context, 
				VBox availableSize)
            {
                var remaining = availableSize;
                var line = VBox.Empty;

                for (int i = 0; i < Items.Length; i++)
                {
                    if (remaining.IsEmpty)
                        yield break;
                    var item = Items[i].GetSize (context);
                    if (Direction == VisualDirection.Horizontal)
                    {
                        if (line.HAdd(item).Width >= availableSize.Width)
                        {
                            yield return Tuple.Create (i, line.HMin (availableSize));
                            remaining = remaining.VSub (line);
                            line = item;
                        }
                        else
                            line = line.HAdd (item).VMax (item);
                    }
                    else
                    {
                        if (line.VAdd(item).Height >= availableSize.Height)
                        {
                            yield return Tuple.Create (i, line.VMin (availableSize));
                            remaining = remaining.HSub (line);
                            line = item;
                        }
                        else
                            line = line.VAdd (item).HMax (item);
                    }
                }
                if (!line.IsEmpty)
                    yield return Tuple.Create (Items.Length, line);
            }
Exemple #6
0
 protected override VBox Draw(GraphicsContext context, VBox availableSize)
 {
     return _size.Value;
 }
Exemple #7
0
 protected override VBox Draw(GraphicsContext context, VBox availableSize)
 {
     return GetChild ().Draw (context, availableSize);
 }
Exemple #8
0
 /// <summary>
 /// Add another box to horizontally to this one.
 /// </summary>
 public VBox HAdd(VBox other)
 {
     return(new VBox(Width + other.Width, Height));
 }
Exemple #9
0
 protected override VBox Draw(GraphicsContext context, VBox availableSize)
 {
     if (Direction == VisualDirection.Horizontal)
     {
         var y = availableSize.Height / 2;
         context.Graphics.DrawLine (context.Style.Pen, 0, y, availableSize.Width, y);
         return new VBox (availableSize.Width, 8f);
     }
     else
     {
         var x = availableSize.Width / 2;
         context.Graphics.DrawLine (context.Style.Pen, x, 0, x, availableSize.Height);
         return new VBox (8f, availableSize.Width);
     }
 }
Exemple #10
0
 /// <summary>
 /// Draw the pile into the specified context.
 /// </summary>
 protected override VBox Draw(GraphicsContext context, VBox availableSize)
 {
     foreach (var pair in Items)
     {
         var inner = pair.Item2.GetSize (context);
         var outer = Direction == VisualDirection.Horizontal ?
             new VBox (0f, availableSize.Height) :
             new VBox (availableSize.Width, 0f);
         var dx = DeltaX (outer.Width, inner.Width);
         var dy = DeltaY (outer.Height, inner.Height);
         if (Direction == VisualDirection.Horizontal)
         {
             dx += availableSize.Width * pair.Item1;
             outer = new VBox (inner.Width, outer.Height);
         }
         else
         {
             dy += availableSize.Height * pair.Item1;
             outer = new VBox (outer.Width, inner.Height);
         }
         var gs = context.Graphics.Save ();
         context.Graphics.TranslateTransform (dx, dy);
         pair.Item2.Render (context, outer);
         context.Graphics.Restore (gs);
     }
     return availableSize;
 }
Exemple #11
0
 /// <summary>
 /// Subtract another box from this one vertically.
 /// </summary>
 public VBox VSub(VBox other)
 {
     return(new VBox(Width, Height - other.Height));
 }
Exemple #12
0
 /// <summary>
 /// Add another box to vertically to this one.
 /// </summary>
 public VBox VAdd(VBox other)
 {
     return(new VBox(Width, Height + other.Height));
 }
Exemple #13
0
 /// <summary>
 /// Returns the horizontal intersection with another box. This means that the
 /// width of the result is the minimum of the box widths.
 /// </summary>
 public VBox HMin(VBox other)
 {
     return(new VBox(Math.Min(Width, other.Width), Height));
 }
Exemple #14
0
 /// <summary>
 /// Subtract another box from this one horizontally.
 /// </summary>
 public VBox HSub(VBox other)
 {
     return(new VBox(Width - other.Width, Height));
 }
Exemple #15
0
 /// <summary>
 /// Subtract another box from this one vertically.
 /// </summary>
 public VBox VSub(VBox other)
 {
     return new VBox (Width, Height - other.Height);
 }
Exemple #16
0
 /// <summary>
 /// Returns the horizontal union with another box. This means that the
 /// width of the result is the maximum of the box widths.
 /// </summary>
 public VBox HMax(VBox other)
 {
     return new VBox (Math.Max (Width, other.Width), Height);
 }
Exemple #17
0
 /// <summary>
 /// Create an empty visual.
 /// </summary>
 public static Visual Empty(VBox size)
 {
     return new _Empty (size);
 }
Exemple #18
0
 protected override VBox Draw(GraphicsContext context, VBox availableSize)
 {
     return new VBox (Paint (context, availableSize.AsSizeF));
 }
Exemple #19
0
            /// <summary>
            /// Draw the stack into the specified context.
            /// </summary>
            protected override VBox Draw(GraphicsContext context, VBox availableSize)
            {
                var stack = GetSize (context);
                var gs1 = context.Graphics.Save ();
                var remainingSize = availableSize;

                foreach (var visual in Items)
                {
                    if (remainingSize.IsEmpty)
                        return stack.HMin (availableSize).VMin (availableSize);

                    var inner = visual.GetSize (context);
                    var outer = Direction == VisualDirection.Horizontal ?
                        new VBox (inner.Width, stack.Height) :
                        new VBox (stack.Width, inner.Height);
                    var gs2 = context.Graphics.Save ();
                    context.Graphics.TranslateTransform (DeltaX (outer.Width, inner.Width),
                        DeltaY (outer.Height, inner.Height));
                    visual.Render (context, outer);
                    context.Graphics.Restore (gs2);

                    if (Direction == VisualDirection.Horizontal)
                    {
                        context.Graphics.TranslateTransform (outer.Width, 0);
                        remainingSize = remainingSize.HSub (outer);
                    }
                    else
                    {
                        context.Graphics.TranslateTransform (0, outer.Height);
                        remainingSize = remainingSize.VSub (outer);
                    }
                }
                context.Graphics.Restore (gs1);
                return stack;
            }
Exemple #20
0
 public _Empty(VBox size)
 {
     _size = size;
 }
Exemple #21
0
 protected override VBox Draw(GraphicsContext context, VBox availableSize)
 {
     return Visual.Draw (new GraphicsContext(context, GetStyle (context.Style)), availableSize);
 }
Exemple #22
0
            protected override VBox Draw(GraphicsContext context, VBox availableSize)
            {
                var gs1 = context.Graphics.Save ();
                var i = 0;
                var totalSize = VBox.Empty;

                foreach (var line in WrapToLines (context, availableSize))
                {
                    var gs2 = context.Graphics.Save ();
                    while (i < line.Item1)
                    {
                        var visual = Items[i++];
                        var itemBox = visual.GetSize (context);
                        var outer = Direction == VisualDirection.Horizontal ?
                            new VBox (itemBox.Width, line.Item2.Height) :
                            new VBox (line.Item2.Width, itemBox.Height);
                        var gs3 = context.Graphics.Save ();
                        context.Graphics.TranslateTransform (DeltaX (outer.Width, itemBox.Width),
                            DeltaY (outer.Height, itemBox.Height));
                        visual.Render (context, outer);
                        context.Graphics.Restore (gs3);

                        if (Direction == VisualDirection.Horizontal)
                            context.Graphics.TranslateTransform (outer.Width, 0f);
                        else
                            context.Graphics.TranslateTransform (0f, outer.Height);
                    }
                    context.Graphics.Restore (gs2);
                    if (Direction == VisualDirection.Horizontal)
                    {
                        totalSize = totalSize.VAdd (line.Item2).HMax (line.Item2);
                        context.Graphics.TranslateTransform (0f, line.Item2.Height);
                    }
                    else
                    {
                        totalSize = totalSize.HAdd (line.Item2).VMax (line.Item2);
                        context.Graphics.TranslateTransform (line.Item2.Width, 0f);
                    }
                }
                context.Graphics.Restore (gs1);
                return totalSize;
            }
Exemple #23
0
 protected override VBox Draw(GraphicsContext context, VBox availableSize)
 {
     return Visual.Draw (context, availableSize);
 }
Exemple #24
0
            protected override VBox Draw(GraphicsContext context, VBox availableSize)
            {
                var box = Visual.GetSize (context);

                switch (Kind)
                {
                    case FrameKind.Rectangle:
                        if (Filled)
                            context.Graphics.FillRectangle (context.Style.Brush,
                                0, 0, box.Width, box.Height);
                        else
                            context.Graphics.DrawRectangle (context.Style.Pen,
                                0, 0, box.Width, box.Height);
                        break;
                    case FrameKind.Ellipse:
                        if (Filled)
                            context.Graphics.FillEllipse (context.Style.Brush,
                                0, 0, box.Width, box.Height);
                        else
                            context.Graphics.DrawEllipse (context.Style.Pen,
                                0, 0, box.Width, box.Height);
                        break;
                    case FrameKind.RoundRectangle:
                        if (Filled)
                            DrawRoundedRectangle (context.Graphics, null, context.Style.Brush,
                                new RectangleF (0, 0, box.Width, box.Height), 10);
                        else
                            DrawRoundedRectangle (context.Graphics, context.Style.Pen, null,
                            new RectangleF(0, 0, box.Width, box.Height), 10);
                        break;
                }
                return base.Draw (context, availableSize);
            }
Exemple #25
0
 public void Render(GraphicsContext context, VBox availableSize)
 {
     Draw (context, availableSize);
 }
Exemple #26
0
 /// <summary>
 /// Draw the label into the specified context.
 /// </summary>
 protected override VBox Draw(GraphicsContext context, VBox availableSize)
 {
     context.Graphics.DrawString (Text, context.Style.Font, context.Style.TextBrush,
         new PointF (0, 0));
     return CalculateSize (context);
 }
Exemple #27
0
 /// <summary>
 /// Draw the visual into specified context using the available size.
 /// </summary>
 /// <param name="context">The graphics context which used in drawing.</param>
 /// <param name='availableSize'>The available size into which the visual should
 /// fit.</param>
 protected abstract VBox Draw(GraphicsContext context, VBox availableSize);
Exemple #28
0
 /// <summary>
 /// Subtract another box from this one horizontally.
 /// </summary>
 public VBox HSub(VBox other)
 {
     return new VBox (Width - other.Width, Height);
 }
Exemple #29
0
 protected override VBox Draw(GraphicsContext context, VBox availableSize)
 {
     Position = GetAnchorPosition (context.Graphics.Transform, Visual.GetSize (context));
     return base.Draw (context, availableSize);
 }
Exemple #30
0
 /// <summary>
 /// Returns the vertical intersection with another box. This means that the
 /// height of the result is the minimum of the box heights.
 /// </summary>
 public VBox VMin(VBox other)
 {
     return new VBox (Width, Math.Min (Height, other.Height));
 }
Exemple #31
0
 private PointF GetAnchorPosition(Matrix matrix, VBox box)
 {
     var anchor = new PointF[1];
     switch (HorizAlign)
     {
         case HAlign.Left:
             anchor[0].X = 0;
             break;
         case HAlign.Center:
             anchor[0].X = box.Width / 2;
             break;
         case HAlign.Right:
             anchor[0].X = box.Width;
             break;
     }
     switch (VertAlign)
     {
         case VAlign.Top:
             anchor[0].Y = 0;
             break;
         case VAlign.Center:
             anchor[0].Y = box.Height / 2;
             break;
         case VAlign.Bottom:
             anchor[0].Y = box.Height;
             break;
     }
     matrix.TransformPoints (anchor);
     return anchor[0];
 }
Exemple #32
0
 /// <summary>
 /// Add another box to horizontally to this one.
 /// </summary>
 public VBox HAdd(VBox other)
 {
     return new VBox (Width + other.Width, Height);
 }
Exemple #33
0
 protected override VBox Draw(GraphicsContext context, VBox availableSize)
 {
     var box = base.Draw (context, availableSize);
     SetClickRegion (box.AsRectF (context.Graphics.Transform));
     return box;
 }
Exemple #34
0
 protected override VBox Draw(GraphicsContext context, VBox availableSize)
 {
     var box = base.Draw (context, availableSize);
     var state = context.Graphics.Save ();
     context.Graphics.ResetTransform ();
     if (Kind == ConnectorKind.Line)
         context.Graphics.DrawLine (context.Style.Pen, Position, Target.Position);
     else
     {
         var p1 = Position;
         var p4 = Target.Position;
         PointF p2, p3;
         if (Direction == VisualDirection.Horizontal)
         {
             var xcenter = (p1.X + p4.X) / 2f;
             p2 = new PointF (xcenter, p1.Y);
             p3 = new PointF (xcenter, p4.Y);
         }
         else
         {
             var ycenter = (p1.Y + p4.Y) / 2f;
             p2 = new PointF (p1.X, ycenter);
             p3 = new PointF (p4.X, ycenter);
         }
         context.Graphics.DrawBezier (context.Style.Pen, p1, p2, p3, p4);
     }
     context.Graphics.Restore (state);
     return box;
 }
Exemple #35
0
 /// <summary>
 /// Returns the vertical intersection with another box. This means that the
 /// height of the result is the minimum of the box heights.
 /// </summary>
 public VBox VMin(VBox other)
 {
     return(new VBox(Width, Math.Min(Height, other.Height)));
 }