markus / KCOM / Extensions / VisualHelper.cs @ 3dbace4e
이력 | 보기 | 이력해설 | 다운로드 (2.25 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Linq; |
4 |
using System.Text; |
5 |
using System.Threading.Tasks; |
6 |
using System.Windows; |
7 |
using System.Windows.Media; |
8 |
|
9 |
namespace KCOM |
10 |
{ |
11 |
public static class VisualHelper |
12 |
{ |
13 |
public static Rect Bounds(this UIElement element, Visual parent) |
14 |
{ |
15 |
return element.TransformToVisual(parent).TransformBounds(new Rect(element.RenderSize)); |
16 |
} |
17 |
|
18 |
public static Rect Rect(this UIElement element) |
19 |
{ |
20 |
return new Rect(element.RenderSize); |
21 |
} |
22 |
|
23 |
public static Direction GetPointDirection(Point point,double angle) |
24 |
{ |
25 |
Direction direction = Direction.None; |
26 |
|
27 |
double xValue = point.X; |
28 |
double yValue = point.Y; |
29 |
|
30 |
if(0 > xValue && Math.Abs(xValue) > Math.Abs(yValue)) |
31 |
{ |
32 |
direction = Direction.Left; |
33 |
} |
34 |
|
35 |
if (0 < xValue && Math.Abs(xValue) > Math.Abs(yValue)) |
36 |
{ |
37 |
direction = Direction.Right; |
38 |
} |
39 |
|
40 |
if (0 > yValue && Math.Abs(xValue) < Math.Abs(yValue)) |
41 |
{ |
42 |
direction = Direction.Up; |
43 |
} |
44 |
|
45 |
if (0 < yValue && Math.Abs(xValue) < Math.Abs(yValue)) |
46 |
{ |
47 |
direction = Direction.Down; |
48 |
} |
49 |
|
50 |
return direction; |
51 |
} |
52 |
|
53 |
public static MoveDirection Movement(this Rect Owner,Rect contentRect) |
54 |
{ |
55 |
MoveDirection result = new MoveDirection(); |
56 |
|
57 |
if(contentRect.Top > 0) |
58 |
{ |
59 |
result.Up = true; |
60 |
} |
61 |
|
62 |
if(contentRect.Left > 0) |
63 |
{ |
64 |
result.Left = true; |
65 |
} |
66 |
|
67 |
if(Owner.Width > contentRect.Right) |
68 |
{ |
69 |
result.Right = true; |
70 |
} |
71 |
|
72 |
if (Owner.Height > contentRect.Bottom) |
73 |
{ |
74 |
result.Down = true; |
75 |
} |
76 |
|
77 |
return result; |
78 |
} |
79 |
} |
80 |
|
81 |
public class MoveDirection |
82 |
{ |
83 |
public bool Left { get; set; } |
84 |
|
85 |
public bool Right { get; set; } |
86 |
|
87 |
public bool Up { get; set; } |
88 |
|
89 |
public bool Down { get; set; } |
90 |
} |
91 |
|
92 |
public enum Direction |
93 |
{ |
94 |
None, |
95 |
Left, |
96 |
|
97 |
Right, |
98 |
|
99 |
Up, |
100 |
|
101 |
Down |
102 |
} |
103 |
} |