File: MyView.cs

package info (click to toggle)
monodevelop 3.0.3.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 153,256 kB
  • sloc: cs: 1,020,242; xml: 751,053; makefile: 9,596; sh: 1,529; objc: 302; sql: 129; ansic: 96
file content (93 lines) | stat: -rw-r--r-- 2,248 bytes parent folder | download | duplicates (3)
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
92
93

using System;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using MonoMac.Foundation;
using MonoMac.AppKit;
using MonoMac.CoreAnimation;
using MonoMac.CoreGraphics;

namespace CustomizeAnimation
{
	public partial class MyView : MonoMac.AppKit.NSView
	{
		float drawnLineWidth = 1;
		NSColor lineColor;
		NSBezierPath path;
		static CABasicAnimation drawnLineWidthBasicAnimation;

		public MyView (IntPtr handle) : base(handle) {}

		[Export("initWithCoder:")]
		public MyView (NSCoder coder) : base(coder) {}
		
		[Export("initWithFrame:")]
		public MyView (RectangleF frame) : base (frame)
		{
			lineColor = NSColor.Blue;
			path = new NSBezierPath ();
			path.MoveTo (Bounds.Location);
			path.LineTo (new PointF (Bounds.GetMaxX (),Bounds.GetMaxY ()));
		}
		
		public override void AwakeFromNib ()
		{
			slider.FloatValue = DrawnLineWidth;
		}
		
		public override void DrawRect (RectangleF dirtyRect)
		{
			lineColor.SetStroke ();
			path.Stroke ();
		}
		
		partial void setWidth (NSSlider sender)
		{			
			((MyView)Animator).setLineWidth(sender.FloatValue);
			//((MyView)Animator).DrawnLineWidth = sender.FloatValue;
			//this.setLineWidth(sender.FloatValue);
			//((MyView)Animator).SetValueForKeyPath((NSNumber)sender.FloatValue,(NSString)"drawnLineWidth");
			//((MyView)Animator).DrawnLineWidth = sender.FloatValue;
			//DrawnLineWidth = sender.FloatValue;
			
		}
		
		public void setLineWidth(float value)
		{
			SetValueForKeyPath((NSNumber) value,(NSString)"drawnLineWidth");
		}
		
		[Export("drawnLineWidth")]
		public float DrawnLineWidth {
			get {
				return drawnLineWidth;	
			}
			set {
				WillChangeValue ("drawnLineWidth");
				drawnLineWidth = value;
				path.LineWidth = drawnLineWidth;
				NeedsDisplay = true;				
				DidChangeValue ("drawnLineWidth");
			}
		}
		
		
		[Export ("defaultAnimationForKey:")]
		static new NSObject DefaultAnimationFor (NSString key)
		{
			if (key == "drawnLineWidth"){
				if (drawnLineWidthBasicAnimation == null) {
					drawnLineWidthBasicAnimation = new CABasicAnimation ();
					//drawnLineWidthBasicAnimation.Duration = 2.0f;
				}
				return drawnLineWidthBasicAnimation;
			} else
				return NSView.DefaultAnimationFor (key);
		}
		
		
		
	}
}