forked from xamarin/mac-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColorRect.cs
71 lines (55 loc) · 1.71 KB
/
ColorRect.cs
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
using System;
using CoreGraphics;
using Foundation;
using AppKit;
namespace Rulers
{
/// <summary>
/// ColorRect is a lightweight class for splatting a colored rectangle
/// into a RectsView (which actually does most of the work). A ColorRect
/// can be locked down, so that the user can't move it, in which case it
/// draws a little X in the middle. When the selected rect is locked,
/// the RectsView doesn't allow the user to move the ruler markers.
/// </summary>
public class ColorRect : NSObject
{
public ColorRect (CGRect frame, NSColor color)
{
Frame = frame;
Color = color;
}
public CGRect Frame { get; set; }
public NSColor Color { get; set; }
public bool IsLocked { get; set; }
public void DrawRect(CGRect aRect, bool selected)
{
NSGraphics.RectClip (aRect);
aRect.Intersect (Frame);
Color.Set ();
NSGraphics.RectFill (aRect);
if (selected) {
NSColor.Black.Set ();
NSGraphics.FrameRectWithWidth (Frame, 4.0f);
}
if (IsLocked){
float xSize = (Frame.Width > 10.0f) ? 5.0f : 3.0f;
NSBezierPath path = new NSBezierPath ();
NSColor.Black.Set ();
path.LineWidth = 3.0f;
path.MoveTo (new CGPoint (MidX (Frame) - xSize, MidY (Frame) - xSize));
path.LineTo (new CGPoint (MidX (Frame) + xSize, MidY (Frame) + xSize));
path.MoveTo (new CGPoint (MidX (Frame) - xSize, MidY (Frame) + xSize));
path.LineTo (new CGPoint (MidX (Frame) + xSize, MidY (Frame) - xSize));
path.Stroke ();
}
}
static float MidX (CGRect rect)
{
return (float)rect.X + ((float)rect.Width / 2);
}
static float MidY (CGRect rect)
{
return (float)rect.Y + ((float)rect.Height / 2);
}
}
}