blob: 7339c900da6435b746ee9258fefd534c9e99d141 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace Tango.Graphics2D
{
public class Drawing2DFrame : Drawing2DHost
{
public override Point GetElementLocation(FrameworkElement element)
{
if (element.HorizontalAlignment == HorizontalAlignment.Left)
{
if (element.VerticalAlignment == VerticalAlignment.Top)
{
return new Point(element.Margin.Left, element.Margin.Top);
}
else if (element.VerticalAlignment == VerticalAlignment.Bottom)
{
return new Point(element.Margin.Left, ActualHeight - GetElementHeight(element) - element.Margin.Bottom);
}
else
{
return new Point(element.Margin.Left, (ActualHeight / 2) - (GetElementHeight(element) / 2) + element.Margin.Top - element.Margin.Bottom);
}
}
else if (element.HorizontalAlignment == HorizontalAlignment.Right)
{
if (element.VerticalAlignment == VerticalAlignment.Top)
{
return new Point(ActualWidth - GetElementWidth(element) - element.Margin.Right, element.Margin.Top);
}
else if (element.VerticalAlignment == VerticalAlignment.Bottom)
{
return new Point(ActualWidth - GetElementWidth(element) - element.Margin.Right, ActualHeight - GetElementHeight(element) - element.Margin.Bottom);
}
else
{
return new Point(ActualWidth - GetElementWidth(element) - element.Margin.Right, (ActualHeight / 2) - (GetElementHeight(element) / 2) + element.Margin.Top - element.Margin.Bottom);
}
}
else
{
if (element.VerticalAlignment == VerticalAlignment.Top)
{
return new Point((ActualWidth / 2) - (GetElementWidth(element) / 2) + element.Margin.Left - element.Margin.Right, element.Margin.Top);
}
else if (element.VerticalAlignment == VerticalAlignment.Bottom)
{
return new Point((ActualWidth / 2) - (GetElementWidth(element) / 2) + element.Margin.Left - element.Margin.Right, ActualHeight - GetElementHeight(element) - element.Margin.Bottom);
}
else
{
return new Point((ActualWidth / 2) - (GetElementWidth(element) / 2) + element.Margin.Left, (ActualHeight / 2) - (GetElementHeight(element) / 2) + element.Margin.Top);
}
}
}
private double GetElementWidth(FrameworkElement element)
{
return double.IsNaN(element.Width) ? ActualWidth : element.Width;
}
private double GetElementHeight(FrameworkElement element)
{
return double.IsNaN(element.Height) ? ActualHeight : element.Height;
}
public override Size GetElementSize(FrameworkElement element)
{
double width = element.Width;
double height = element.Height;
if (double.IsNaN(width))
{
width = ActualWidth;
}
if (double.IsNaN(height))
{
height = ActualHeight;
}
width -= (element.Margin.Left + element.Margin.Right);
height -= (element.Margin.Top + element.Margin.Bottom);
return new Size(width, height);
}
}
}
|