File: SharedContentView.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 (107 lines) | stat: -rw-r--r-- 3,191 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107

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

namespace QCBackground
{
	public partial class SharedContentView : MonoMac.AppKit.NSView
	{
		
		NSImageView mover;
		
		public override void AwakeFromNib ()
		{
			WantsLayer = true;
			Layer = MakeCompositionLayer();
		}
		
		public override bool AcceptsFirstResponder ()
		{
			return true;
		}
		
		public override void KeyDown (NSEvent theEvent)
		{
			if ((theEvent.ModifierFlags & NSEventModifierMask.AlphaShiftKeyMask) == NSEventModifierMask.AlphaShiftKeyMask ||
			    (theEvent.ModifierFlags & NSEventModifierMask.ShiftKeyMask) == NSEventModifierMask.ShiftKeyMask){
				NSAnimationContext.BeginGrouping ();
				NSAnimationContext.CurrentContext.Duration = 2.0f;
			}
			
			if (theEvent.Characters.ToUpper ()[0] == 'A') {
				NSView view = Mover ();
				if (view.Superview == null){
					// there is a problem here with AddSubview with animator
					//((NSView)Animator).AddSubview(view);
					this.AddSubview(view);
				} else 
					((NSView)view.Animator).RemoveFromSuperview();
			} else 
				base.KeyDown(theEvent);
			
			if ((theEvent.ModifierFlags & NSEventModifierMask.AlphaShiftKeyMask) == NSEventModifierMask.AlphaShiftKeyMask ||
			    (theEvent.ModifierFlags & NSEventModifierMask.ShiftKeyMask) == NSEventModifierMask.ShiftKeyMask)
				NSAnimationContext.EndGrouping();
		}
		
		private CALayer MakeCompositionLayer ()
		{
			QCCompositionRepository repo = QCCompositionRepository.SharedCompositionRepository;
			
			QCComposition composition = repo.GetComposition ("/moving shapes");
			QCCompositionLayer compLayer = QCCompositionLayer.Create (composition);
			//CGColor cgColor = new CGColor(0.25f, 0.675f, 0.1f, 1.0f);
			NSColor nsColor = NSColor.FromCalibratedRgba (0.25f, 0.675f, 0.1f, 1.0f);
			
			string path = String.Format ("patch.{0}.value", QCComposition.InputPrimaryColorKey);
			compLayer.SetValueForKeyPath (nsColor, (NSString)path);
			
			path = String.Format ("patch.{0}.value", QCComposition.InputPaceKey);
			compLayer.SetValueForKeyPath (NSNumber.FromFloat (5.0f), (NSString) path);
						
			return compLayer;
		}
		
		private NSImageView Mover()
		{
			if (mover == null) {
				float xInset = 0.25f * Bounds.Width;
				float yInset = 0.25f * Bounds.Height;
				
				RectangleF moverFrame = Bounds.Inset (xInset,yInset);
				moverFrame.Location = new PointF (Bounds.GetMidX () - moverFrame.Width / 2.0f,
				                            Bounds.GetMidY () - moverFrame.Height / 2.0f);
				
				mover = new NSImageView (Bounds) {
					ImageScaling = NSImageScale.AxesIndependently,
					Image = NSImage.ImageNamed("photo.jpg"),
					Frame = moverFrame,
					AlphaValue = 0.5f
				};
			}
			return mover;
		}
		
		// Constructors
		
		// Called when created from unmanaged code
		public SharedContentView (IntPtr handle) : base(handle)
		{
		}

		// Called when created directly from a XIB file
		[Export("initWithCoder:")]
		public SharedContentView (NSCoder coder) : base(coder)
		{
		}		
	}
}