public ApplicationCanvas() { r.Fill = Brushes.Gray; r.AttachTo(this); r.MoveTo(8, 8); this.SizeChanged += (s, e) => r.SizeTo(this.Width - 16.0, this.Height - 16.0); var Shadow = new Canvas { Width = 200, Height = 200, Background = Brushes.White }.MoveTo(16, 16).AttachTo(this); var t = new TextBox().AttachTo(Shadow).MoveTo(4, 4); var gx = 120; var gy = 120; var gw = 550; var gh = 150; var Red = new Rectangle { Width = 8, Height = 8, Fill = Brushes.Red, Cursor = Cursors.Hand, RenderTransform = new TranslateTransform(-4, -4) }.AttachTo(this).MoveTo(gx + gw / 2, gy + gh / 2); var Black = new Rectangle { Width = 8, Height = 8, Fill = Brushes.Black, Cursor = Cursors.Hand, RenderTransform = new TranslateTransform(-4, -4) }.AttachTo(this).MoveTo(gx + gw / 2, gy + gh / 2); this.MouseMove += (s, e) => { var p = e.GetPosition(Black); Red.MoveTo(p.X + 4, p.Y + 4); var RedLeft = Canvas.GetLeft(Red); var RedTop = Canvas.GetTop(Red); t.Text = new { p.X, p.Y, RedLeft, RedTop }.ToString(); }; }
public ApplicationCanvas() { r.Fill = Brushes.Red; r.AttachTo(this); r.MoveTo(0, 0); this.SizeChanged += (s, e) => r.SizeTo(this.Width, this.Height); space = new Rectangle { Fill = Brushes.White, Opacity = 0.5 }.AttachTo(this); space.SizeTo(64, 64 + 4 + 64); this.SizeChanged += (s, e) => space.MoveTo(this.Width - 64 - 4 - 64 - 4, this.Height - 64 - 4 - 64 - 4); up = new Rectangle { Fill = Brushes.White, Opacity = 0.5 }.AttachTo(this); up.SizeTo(64, 64); this.SizeChanged += (s, e) => up.MoveTo(this.Width - 64 - 4, this.Height - 64 - 4 - 64 - 4); down = new Rectangle { Fill = Brushes.White, Opacity = 0.5 }.AttachTo(this); down.SizeTo(64, 64); this.SizeChanged += (s, e) => down.MoveTo(this.Width - 64 - 4, this.Height - 64 - 4); control = new Rectangle { Fill = Brushes.White, Opacity = 0.5 }.AttachTo(this); control.SizeTo(64 + 4 + 64, 64); this.SizeChanged += (s, e) => control.MoveTo(4, this.Height - 64 - 4 - 64 - 4); left = new Rectangle { Fill = Brushes.White, Opacity = 0.5 }.AttachTo(this); left.SizeTo(64, 64); this.SizeChanged += (s, e) => left.MoveTo(4, this.Height - 64 - 4); right = new Rectangle { Fill = Brushes.White, Opacity = 0.5 }.AttachTo(this); right.SizeTo(64, 64); this.SizeChanged += (s, e) => right.MoveTo(4 + 64 + 4, this.Height - 64 - 4); }
public ApplicationCanvas() { r.Fill = Brushes.Black; r.AttachTo(this); r.MoveTo(0, 0); this.SizeChanged += (s, e) => r.SizeTo(this.Width, this.Height); rtiltx = new Rectangle { Fill = Brushes.Red, Opacity = 0.5 }.AttachTo(this); rtilty = new Rectangle { Fill = Brushes.Blue, Opacity = 0.5 }.AttachTo(this); tilt_update = delegate { rtiltx.SizeTo(8, this.Height); rtiltx.MoveTo((this.Width - 8) * tiltx, 0); rtilty.SizeTo(this.Width, 8); rtilty.MoveTo(0, (this.Height - 8) * tilty); rtiltx.Opacity = tiltx; rtilty.Opacity = tilty; }; this.SizeChanged += (s, e) => { tilt_update(); }; enter = new Rectangle { Fill = Brushes.Green, Opacity = 0.5 }.AttachTo(this); enter.SizeTo(fingersize + 4 + fingersize, fingersize + 4 + fingersize); this.SizeChanged += (s, e) => enter.MoveTo(this.Width - fingersize - 4 - fingersize - 4, this.Height - fingersize - 4 - fingersize - 4 - fingersize - 4); space = new Rectangle { Fill = Brushes.White, Opacity = 0.5 }.AttachTo(this); space.SizeTo(fingersize + 4 + fingersize, fingersize); this.SizeChanged += (s, e) => space.MoveTo(this.Width - fingersize - 4 - fingersize - 4, this.Height - fingersize - 4); //up = new Rectangle //{ // Fill = Brushes.White, // Opacity = 0.5 //}.AttachTo(this); //up.SizeTo(fingersize, fingersize); //this.SizeChanged += (s, e) => up.MoveTo(this.Width - fingersize - 4, this.Height - fingersize - 4 - fingersize - 4); //down = new Rectangle //{ // Fill = Brushes.White, // Opacity = 0.5 //}.AttachTo(this); //down.SizeTo(fingersize, fingersize); //this.SizeChanged += (s, e) => down.MoveTo(this.Width - fingersize - 4, this.Height - fingersize - 4); control = new Rectangle { Fill = Brushes.Red, Opacity = 0.5 }.AttachTo(this); control.SizeTo(fingersize + 4 + fingersize, fingersize + 4 + fingersize); this.SizeChanged += (s, e) => control.MoveTo(4, this.Height - fingersize - 4 - fingersize - 4); alt = new Rectangle { Fill = Brushes.White, Opacity = 0.5 }.AttachTo(this); alt.SizeTo(fingersize + 4 + fingersize, fingersize); this.SizeChanged += (s, e) => alt.MoveTo(4, this.Height - fingersize - 4 - fingersize - 4 - fingersize - 4); //left = new Rectangle //{ // Fill = Brushes.White, // Opacity = 0.5 //}.AttachTo(this); //left.SizeTo(fingersize, fingersize); //this.SizeChanged += (s, e) => left.MoveTo(4, this.Height - fingersize - 4); //right = new Rectangle //{ // Fill = Brushes.White, // Opacity = 0.5 //}.AttachTo(this); //right.SizeTo(fingersize, fingersize); //this.SizeChanged += (s, e) => right.MoveTo(4 + fingersize + 4, this.Height - fingersize - 4); }
private TransformerControl CreateTransformer(TextBox t1, int gw, int gh, int gx, int gy) { var RB = new Rectangle { Width = gw, Height = gh, Fill = Brushes.Red, Opacity = 0.1, Cursor = Cursors.Hand, }.AttachTo(this).MoveTo(gx, gy); var GB = new Rectangle { Width = gw, Height = gh, Fill = Brushes.Green, Opacity = 0.1, Cursor = Cursors.Hand, }.AttachTo(this).MoveTo(gx, gy); var g0 = new Rectangle { Width = gw, Height = gh, Fill = Brushes.Purple, Opacity = 0.2 }.AttachTo(this.Shadow).MoveTo(gx, gy); var g1 = new Image { Width = gw, Height = gh, Source = new Avalon.Images.d().Source, Opacity = 0.7, }.AttachTo(this).MoveTo(gx, gy); var g2 = new Image { Width = gw, Height = gh, Source = new Avalon.Images.d().Source, Opacity = 0.7, }.AttachTo(this).MoveTo(gx, gy); var R = new Rectangle { Width = 8, Height = 8, Fill = Brushes.Red, Cursor = Cursors.Hand, RenderTransform = new TranslateTransform(-4, -4) }.AttachTo(this).MoveTo(gx, gy); var G = new Rectangle { Width = 8, Height = 8, Fill = Brushes.Green, Cursor = Cursors.Hand, RenderTransform = new TranslateTransform(-4, -4) }.AttachTo(this).MoveTo(gx, gy); var M = new Rectangle { Width = 8, Height = 8, Fill = Brushes.Magenta, Cursor = Cursors.Hand, RenderTransform = new TranslateTransform(-4, -4) }.AttachTo(this).MoveTo(gx, gy); var Y = new Rectangle { Width = 8, Height = 8, Fill = Brushes.Yellow, Cursor = Cursors.Hand, RenderTransform = new TranslateTransform(-4, -4) }.AttachTo(this).MoveTo(gx, gy); var Orange = new Rectangle { Width = 8, Height = 8, Fill = Brushes.Orange, Cursor = Cursors.Hand, RenderTransform = new TranslateTransform(-4, -4) }.AttachTo(this).MoveTo(gx + gw / 2, gy + gh / 2 - 8); // rotation origin var Black = new Rectangle { Width = 8, Height = 8, Fill = Brushes.Black, Cursor = Cursors.Hand, RenderTransform = new TranslateTransform(-4, -4) }.AttachTo(this).MoveTo(gx + gw / 2, gy + gh / 2); // rotation handler var White = new Rectangle { Width = 8, Height = 8, Fill = Brushes.White, Cursor = Cursors.Hand, RenderTransform = new TranslateTransform(-4, -4) }.AttachTo(this).MoveTo(gx + gw, gy + gh / 2); var OrangeSelfAverage = true; Action Update = delegate { var w = new StringBuilder(); w.AppendLine("Magneta:"); w.AppendLine(ApplyMatrix(RB, GB, R, G, M, g2, gx, gy, gw, gh)); w.AppendLine("Yellow:"); w.AppendLine(ApplyMatrix(RB, GB, R, G, Y, g1, gx, gy, gw, gh)); if (t1 != null) t1.Text = w.ToString(); if (OrangeSelfAverage) { var args = new[] { new { x = Canvas.GetLeft(R), y = Canvas.GetTop(R) }, new { x = Canvas.GetLeft(G), y = Canvas.GetTop(G) }, new { x = Canvas.GetLeft(M), y = Canvas.GetTop(M) }, new { x = Canvas.GetLeft(Y), y = Canvas.GetTop(Y) } }; var _x = args.Average(k => k.x); var _y = args.Average(k => k.y); Orange.MoveTo( _x, _y - 8 ); } }; Action Reset = delegate { M.MoveTo(gx, gy); R.MoveTo(gx + gw, gy); G.MoveTo(gx, gy + gh); Y.MoveTo(gx + gw, gy + gh); }; AsMovableByMouse(R, Update); AsMovableByMouse(G, Update); AsMovableByMouse(M, Update); AsMovableByMouse(Y, Update); var RotationInfo = new { x = 0.0, y = 0.0 }; RotationInfo = null; Action UpdateRotation = delegate { var p = new { White = new { x = Canvas.GetLeft(White), y = Canvas.GetTop(White) }, Black = new { x = Canvas.GetLeft(Black), y = Canvas.GetTop(Black) }, R = new { x = Canvas.GetLeft(R), y = Canvas.GetTop(R) }, G = new { x = Canvas.GetLeft(G), y = Canvas.GetTop(G) }, M = new { x = Canvas.GetLeft(M), y = Canvas.GetTop(M) }, Y = new { x = Canvas.GetLeft(Y), y = Canvas.GetTop(Y) } }; if (RotationInfo == null) { RotationInfo = p.White; return; } // we now need // - previous distance and rotation // - current distance and rotation var q = new { o = new { x = RotationInfo.x - p.Black.x, y = RotationInfo.y - p.Black.y }, n = new { x = p.White.x - p.Black.x, y = p.White.y - p.Black.y }, R = new { x = p.Black.x - p.R.x, y = p.Black.y - p.R.y }, G = new { x = p.Black.x - p.G.x, y = p.Black.y - p.G.y }, M = new { x = p.Black.x - p.M.x, y = p.Black.y - p.M.y }, Y = new { x = p.Black.x - p.Y.x, y = p.Black.y - p.Y.y }, }; Func<double, double, double> GetLength = (x, y) => { return new vec2(x, y).Length; }; var a = new { o = new { z = GetLength(q.o.x, q.o.y), a = new Point(q.o.x, q.o.y).GetRotation() }, n = new { z = GetLength(q.n.x, q.n.y), a = new Point(q.n.x, q.n.y).GetRotation() }, R = new { z = -GetLength(q.R.x, q.R.y), a = new Point(q.R.x, q.R.y).GetRotation() }, G = new { z = -GetLength(q.G.x, q.G.y), a = new Point(q.G.x, q.G.y).GetRotation() }, M = new { z = -GetLength(q.M.x, q.M.y), a = new Point(q.M.x, q.M.y).GetRotation() }, Y = new { z = -GetLength(q.Y.x, q.Y.y), a = new Point(q.Y.x, q.Y.y).GetRotation() }, }; var n = new { z = a.n.z / a.o.z, a = a.n.a - a.o.a }; if (n.z == 1) if (n.a == 0) { RotationInfo = p.White; return; } R.MoveTo( p.Black.x + Math.Cos(a.R.a + n.a) * a.R.z * n.z, p.Black.y + Math.Sin(a.R.a + n.a) * a.R.z * n.z ); G.MoveTo( p.Black.x + Math.Cos(a.G.a + n.a) * a.G.z * n.z, p.Black.y + Math.Sin(a.G.a + n.a) * a.G.z * n.z ); M.MoveTo( p.Black.x + Math.Cos(a.M.a + n.a) * a.M.z * n.z, p.Black.y + Math.Sin(a.M.a + n.a) * a.M.z * n.z ); Y.MoveTo( p.Black.x + Math.Cos(a.Y.a + n.a) * a.Y.z * n.z, p.Black.y + Math.Sin(a.Y.a + n.a) * a.Y.z * n.z ); Update(); RotationInfo = p.White; }; AsMovableByMouse(Black, null); AsMovableByMouse(White, UpdateRotation); var TranslationInfo = new { x = 0.0, y = 0.0 }; TranslationInfo = null; Action ShowVisuals = delegate { g0.Show(); GB.Show(); RB.Show(); Orange.Opacity = 1; var e = new[] { M, R, G, Y, White, Black }; foreach (var k in e) { k.Show(); k.BringToFront(); } }; Action UpdateTranslation = delegate { ShowVisuals(); var p = new { Orange = new { x = Canvas.GetLeft(Orange), y = Canvas.GetTop(Orange) }, White = new { x = Canvas.GetLeft(White), y = Canvas.GetTop(White) }, Black = new { x = Canvas.GetLeft(Black), y = Canvas.GetTop(Black) }, R = new { x = Canvas.GetLeft(R), y = Canvas.GetTop(R) }, G = new { x = Canvas.GetLeft(G), y = Canvas.GetTop(G) }, M = new { x = Canvas.GetLeft(M), y = Canvas.GetTop(M) }, Y = new { x = Canvas.GetLeft(Y), y = Canvas.GetTop(Y) } }; if (TranslationInfo == null) { TranslationInfo = p.Orange; return; } var q = new { x = p.Orange.x - TranslationInfo.x, y = p.Orange.y - TranslationInfo.y, }; if (q.x == 0) if (q.y == 0) { TranslationInfo = p.Orange; return; } RotationInfo = null; R.MoveTo(p.R.x + q.x, p.R.y + q.y); G.MoveTo(p.G.x + q.x, p.G.y + q.y); Y.MoveTo(p.Y.x + q.x, p.Y.y + q.y); M.MoveTo(p.M.x + q.x, p.M.y + q.y); Black.MoveTo(p.Black.x + q.x, p.Black.y + q.y); White.MoveTo(p.White.x + q.x, p.White.y + q.y); Update(); TranslationInfo = p.Orange; }; var OrangeDrag = AsMovableByMouse(Orange, UpdateTranslation); OrangeDrag.Enter = () => OrangeSelfAverage = false; OrangeDrag.Exit = () => OrangeSelfAverage = true; Reset(); UpdateRotation(); Update(); var rr = new TransformerControl { SetOpacity = Opacity => { g1.Opacity = Opacity; g2.Opacity = Opacity; }, SetSource = src => { g1.Source = src; g2.Source = src; }, HideMirror = delegate { Y.Opacity = 0.2; g1.Hide(); }, HideVisuals = delegate { g0.Hide(); GB.Hide(); RB.Hide(); Orange.Opacity = 0.05; var e = new[] { M, R, G, Y, White, Black }; foreach (var k in e) { k.Hide(); } }, SetBounds = args => { var e = new[] { M, R, G, Y }; for (int i = 0; i < args.Length; i++) { e[i].MoveTo(args[i].X, args[i].Y); } var _x = args.Average(k => k.X); var _y = args.Average(k => k.Y); Orange.MoveTo( _x, _y - 8 ); RotationInfo = null; Update(); }, //g2 = g2 }; return rr; }
public ApplicationCanvas() { { var r = new Rectangle(); r.Fill = Brushes.Black; r.AttachTo(this); r.MoveTo(0, 0); r.Opacity = 0.9; this.SizeChanged += (s, e) => r.SizeTo(this.Width, this.Height / 2); } { var r = new Rectangle(); r.Fill = Brushes.Black; r.AttachTo(this); this.SizeChanged += (s, e) => r.MoveTo(0, this.Height / 2).SizeTo(this.Width, this.Height / 2); } var VocabularyLines = Vocabulary.Trim().Split('\n'); var v = VocabularyLines.Select( k => { var verbs = k.Split(':'); return new { A = verbs[0].Trim(), B = verbs[1].Trim() }; } ).Randomize().AsCyclicEnumerator(); var az = 0.5; var ax = 0.0; var ABCanvas = new Canvas().AttachTo(this); var A = new TextBox { BorderThickness = new Thickness(0), Background = Brushes.Transparent, TextAlignment = System.Windows.TextAlignment.Center, Foreground = Brushes.White, Text = "suur ettevõte", IsReadOnly = true, FontSize = 70 }; A.AttachTo(ABCanvas); var B = new TextBox { BorderThickness = new Thickness(0), Background = Brushes.Transparent, TextAlignment = System.Windows.TextAlignment.Center, Foreground = Brushes.White, Text = "large-scale enterprise", IsReadOnly = true, FontSize = 70 }; var MoveNextDisabled = false; Action MoveNext = delegate { if (MoveNextDisabled) return; MoveNextDisabled = true; v.MoveNext(); A.Text = v.Current.A; B.Text = v.Current.B; 600.AtDelay(() => MoveNextDisabled = false); }; MoveNext(); B.AttachTo(ABCanvas); B.MoveTo(0, 64); Action Update = delegate { if (Math.Abs(ax) > 0.4) MoveNext(); az = Math.Min(1, az); az = Math.Max(0, az); var max = this.Height / 6; var min = this.Height / 3; // az = 1 is 0 degrees // az = 0 is 90 degrees az = 1 - az; az -= 0.05; az *= 10; az = 1 - az; az = Math.Min(1, az); az = Math.Max(0, az); //Console.WriteLine(new { az }); A.Opacity = Math.Pow(az, 10); var bz = 1 - az; B.Opacity = Math.Pow(bz, 10); A.MoveTo(0, min + az * max - 16).SizeTo(this.Width, 100); B.MoveTo(0, min + (1 - az) * max - 16).SizeTo(this.Width, 100); ABCanvas.MoveTo(this.Width * ax * 0.1, 0); }; this.SizeChanged += delegate { Update(); }; this.MouseMove += (sender, args) => { var p = args.GetPosition(this); az = (p.Y / this.Height); ax = -1 * ((p.X / this.Width) - 0.5); Update(); }; this.TouchMove += (sender, args) => { var p = args.GetTouchPoint(this).Position; az = (p.Y / this.Height); ax = -1 * ((p.X / this.Width) - 0.5); Update(); }; this.Accelerate = (x, y, z) => { az = z; ax = x; Update(); }; }
public ApplicationCanvas() { var Container720X = new Canvas().AttachTo(this); Container720 = new Canvas().AttachTo(Container720X); //Container720A = Container720.ToAnimatedOpacity(); i = new Avalon.Images.Promotion3D_controller_720p(); i.AttachTo(Container720); iA = i.ToAnimatedOpacity(); iA.Opacity = 0.8; var ShadowOverlay = new Rectangle { Fill = Brushes.Black }; var ShadowOverlayA = ShadowOverlay.ToAnimatedOpacity(); ShadowOverlay.AttachTo(Container720); ShadowOverlay.SizeTo(1280, 720); ii = new Avalon.Images.Promotion3D_controller_android_720(); ii.AttachTo(Container720); var iiA = ii.ToAnimatedOpacity(); var Title = new Avalon.Images.Title(); Title.AttachTo(Container720X); this.SizeChanged += (s, e) => { Container720X.MoveTo( (this.Width - 1280) / 2, (this.Height - 720) / 2 ); Console.WriteLine(new { this.Width, this.Height }); }; enter = new Avalon.Images.start { Cursor = Cursors.Hand }.AttachTo(this); entero = enter.ToAnimatedOpacity(); this.SizeChanged += (s, e) => enter.MoveTo( (this.Width - 128) * 0.8 + 64, (this.Height - 128) / 2 + 32); #region Black { Rectangle r = new Rectangle(); r.Fill = Brushes.Black; r.AttachTo(this); r.MoveTo(0, 0); this.SizeChanged += (s, e) => { r.Width = this.Width; r.Height = ((this.Height - 720) / 2).Max(0); }; } { Rectangle r = new Rectangle(); r.Fill = Brushes.Black; r.AttachTo(this); r.MoveTo(0, 0); this.SizeChanged += (s, e) => { r.Width = this.Width; // NotImplementedException //at ScriptCoreLib.ActionScript.BCLImplementation.System.Windows::__UIElement/InternalGetHeight_100663344() //at ScriptCoreLib.ActionScript.BCLImplementation.System.Windows::__UIElement/VirtualGetHeight_100663342() //at ScriptCoreLib.ActionScript.BCLImplementation.System.Windows::__FrameworkElement/get Height() var Height = ((this.Height - 720) / 2).Max(0); r.Height = Height; r.MoveTo(0, this.Height - Height); }; } #endregion var hotzone = new Rectangle { Fill = Brushes.Green, Opacity = 0 }.AttachTo(Container720X); hotzone.Cursor = Cursors.Hand; hotzone.MoveTo(1280 / 3, 720 * 2 / 3); hotzone.SizeTo(1280 / 3, 720 / 3); hotzone.MouseEnter += delegate { ShadowOverlayA.Opacity = 0.4; iiA.Opacity = 1.0; entero.Opacity = 0.2; //Container720A.Opacity = 1; }; hotzone.MouseLeave += delegate { ShadowOverlayA.Opacity = 0; iiA.Opacity = 0; entero.Opacity = 0.8; //Container720A.Opacity = VideoPlayingOpacity; }; hotzone.MouseLeftButtonUp += delegate { new Uri("http://young-beach-4377.herokuapp.com/android").NavigateTo(); }; #region enter enter.MouseEnter += delegate { entero.Opacity = 1; ShadowOverlayA.Opacity = 0.4; //Container720A.Opacity = 1; }; enter.MouseLeave += delegate { entero.Opacity = 0.8; ShadowOverlayA.Opacity = 0; // got video? //Container720A.Opacity = VideoPlayingOpacity; //Container720A.Opacity = 1.0; }; #endregion ShadowOverlayA.Opacity = 0; iiA.Opacity = 0; entero.Opacity = 0.8; }
public SimpleCarouselControl(int DefaultWidth, int DefaultHeight) { this.Container = new Canvas { Width = DefaultWidth, Height = DefaultHeight }; var ContentContainer = new Canvas { Width = DefaultWidth, Height = DefaultHeight }.AttachTo(this.Container); this.Caption = new TextBox { Width = DefaultWidth, Height = 32, TextAlignment = TextAlignment.Center, Foreground = Brushes.White, BorderThickness = new Thickness(0), Background = Brushes.Transparent, IsReadOnly = true }.MoveTo(0, (DefaultHeight - 32) / 2).AttachTo(this.Container); this.Overlay = new Canvas { Width = DefaultWidth, Height = DefaultHeight, }; var OverlayFill = new Rectangle { Width = DefaultWidth, Height = DefaultHeight, Fill = Brushes.Red, Opacity = 0 }.AttachTo(this.Overlay); var a = new List<Entry>(); var OverlayReorderingEnabled = true; #region Timer this.Timer = (1000 / 30).AtInterval( delegate { a.ForEach(k => k.Tick()); a.OrderBy(k => k.cy).ForEach( k => { if (OverlayReorderingEnabled) { // in javascript reordering an element under mouse // will leave you without the leave event // we could sort other nodes around it tho k.Overlay.Orphanize(); k.Overlay.AttachTo(this.Overlay); } k.pc.Orphanize(); k.pc.AttachTo(this.Container); } ); } ); #endregion var s = 0.01; this.AddEntry = e => { var pc_Width = 166 + 9; var pc_Height = 90 + 9 * 2; var pc = new Canvas { //Background = Brushes.Green, Width = pc_Width, Height = pc_Height }.AttachTo(ContentContainer); const string Assets = "assets/ScriptCoreLib.Avalon.Carousel"; var p = new Image { Width = 166, Height = 90, Stretch = Stretch.Fill, Source = (Assets + "/PreviewShadow.png").ToSource() }.AttachTo(pc); var ps = new Image { Width = 138, Height = 108, Stretch = Stretch.Fill, Source = (Assets + "/PreviewSelection.png").ToSource() }.AttachTo(pc); var pi = new Image { Width = 120, Height = 90, Stretch = Stretch.Fill, Source = e.Source, Cursor = Cursors.Hand }.AttachTo(pc); var Overlay_Width = 120; var Overlay_Height = 90; var Overlay = new Rectangle { Fill = Brushes.Black, Width = Overlay_Width, Height = Overlay_Height, Cursor = Cursors.Hand, Opacity = 0 }.AttachTo(this.Overlay); ps.Hide(); Overlay.TouchDown += (sender, ee) => { ee.Handled = true; if (e.Click != null) e.Click(); }; Overlay.TouchMove += (sender, ee) => { ee.Handled = true; }; Overlay.TouchUp += (sender, ee) => { ee.Handled = true; }; Overlay.MouseLeftButtonUp += (sender, ee) => { ee.Handled = true; if (e.Click != null) e.Click(); }; var IsHot = false; Overlay.MouseLeave += delegate { OverlayReorderingEnabled = true; if (e.Text != null) this.Caption.Text = ""; if (Idle != null) Idle(); }; Overlay.MouseEnter += delegate { OverlayReorderingEnabled = false; if (e.MouseEnter != null) e.MouseEnter(); if (Hover != null) Hover(e); if (e.Text != null) this.Caption.Text = e.Text; IsHot = true; s = 0.004; p.Opacity = 1; pi.Opacity = 1; a.ForEach( k => { if (k.ps == ps) { ps.Show(); } else { k.ps.Hide(); } } ); }; var MyEntry = new Entry { o = 1, cy = 0, pc = (Canvas)pc, ps = (Image)ps, Overlay = (Rectangle)Overlay, Info = e }; //var o = new Boxed<double>(); //var _cy = new Boxed<double>(); Overlay.MouseLeave += delegate { if (e.MouseLeave != null) e.MouseLeave(); IsHot = false; p.Opacity = MyEntry.o; pi.Opacity = MyEntry.o; s = 0.01; ps.Hide(); }; #region Tick MyEntry.Tick = delegate { var x = Math.Cos(e.Position); var y = Math.Sin(e.Position); var z = (y + 3) / 4; MyEntry.o = z; if (!IsHot) { pi.Opacity = MyEntry.o; //p.Opacity = MyEntry.o; } e.Position += s * z; pc.Width = pc_Width * z; pc.Height = pc_Height * z; Overlay.Width = Overlay_Width * z; Overlay.Height = Overlay_Height * z; p.Width = 166 * z; p.Height = 90 * z; pi.Width = 120 * z; pi.Height = 90 * z; ps.Width = 138 * z; ps.Height = 108 * z; var cx = x * (DefaultWidth - 160) / 2 + DefaultWidth / 2; var cy = y * (DefaultHeight / 2) / 2 + DefaultHeight / 2; MyEntry.cy = cy; pc.MoveTo( cx - pc.Width / 2, cy - pc.Height / 2 ); p.MoveTo( z * 9, z * 9 ); pi.MoveTo( z * 9, z * 9 ); ps.MoveTo( 0, 0 ); Overlay.MoveTo( cx - pc.Width / 2 + 9 * z, cy - pc.Height / 2 + 9 * z ); }; #endregion a.Add( MyEntry ); MyEntry.Tick(); }; }
void InitializeContent() { Colors.Blue.ToGradient(Colors.Red, Convert.ToInt32( Height) / 4).Select( (c, i) => new Rectangle { Fill = new SolidColorBrush(c), Width = Width, Height = 4, }.MoveTo(0, i * 4).AttachTo(this) ).ToArray(); //var help = new Image //{ // Source = (KnownAssets.Path.Assets + "/help.png").ToSource() //}.AttachTo(this); //help.Opacity = 0; var img = new Image { Source = new Avalon.Images.jsc().Source }.MoveTo(Width - 128, Height - 128).AttachTo(this); var t = new TextBox { FontSize = 10, Text = "powered by jsc", BorderThickness = new Thickness(0), Foreground = 0xffffffff.ToSolidColorBrush(), Background = Brushes.Transparent, IsReadOnly = true, Width = Width }.MoveTo(8, 8).AttachTo(this); //help.Opacity = 1; img.Opacity = 0.5; // cursor position calculations are not ready // for transofrmed elements. // we will provide a floor for those events... var shadow = new Rectangle { Width = Width, Height = Height, Fill = Brushes.Black, }.AttachTo(this); var shadowa = shadow.ToAnimatedOpacity(); shadowa.Opacity = 0; var a = new AffineMesh(); Func<double, double, double, Brush, AffinePoint> a_Add = (X, Y, Z, Fill) => { var p = new AffinePoint { Z = Z, X = X, Y = Y }; var h = new Rectangle { Fill = Fill, Width = 4, Height = 4 }.AttachTo(this); //var ht = new TextBox { }.AttachTo(this); var historysize = 64; var history = new Queue<Rectangle>(); Action<AffinePoint> p_Update = pp => { if (history.Count > historysize) { history.Dequeue(); } // -100 == 0.5 // 0 == 1 // +100 == 2 //var zoom = (pp.Z) / 1000; var zoom = 0.5; var pp_X = Width / 2 - 4 + pp.X * zoom; var pp_Y = Height / 2 - 4 + pp.Y * zoom; // Z is ignored here // but could be used for sorting h.MoveTo(pp_X, pp_Y); //var hh = new Rectangle { Fill = Fill, Width = 4, Height = 4, Opacity = 1 }.MoveTo(pp_X, pp_Y).AttachTo(this); //history.Enqueue(hh); //foreach (var k in history.Select((c, i) => new { c, i })) //{ // k.c.Opacity = ((double)k.i / historysize) * 0.6; //} //ht.MoveTo( // DefaultWidth / 2 + pp.X - 4, // DefaultHeight / 2 + pp.Y + 4 //); //ht.Text = new { pp.X, pp.Y, pp.Z }.ToString(); }; p.Tag = p_Update; a.Add(p); p_Update(p); return p; }; Enumerable.Range(0, 10).Select(X => a_Add(X * 10, 0, 0, Brushes.Red)).ToArray(); Enumerable.Range(0, 10).Select(Y => a_Add(0, Y * 10, 0, Brushes.Blue)).ToArray(); Enumerable.Range(0, 10).Select(Z => a_Add(0, 0, Z * 10, Brushes.GreenYellow)).ToArray(); Enumerable.Range(0, 10).Select(X => a_Add(X * 10 + 100, 0, 0, Brushes.Red)).ToArray(); Enumerable.Range(0, 10).Select(Y => a_Add(100, Y * 10, 0, Brushes.Blue)).ToArray(); Enumerable.Range(0, 10).Select(Z => a_Add(100, 0, Z * 10, Brushes.GreenYellow)).ToArray(); Enumerable.Range(0, 100).Select(X => a_Add(X * 10 + 200, 0, 0, Brushes.Red)).ToArray(); Enumerable.Range(0, 10).Select(Y => a_Add(200, Y * 10, 0, Brushes.Blue)).ToArray(); Enumerable.Range(0, 10).Select(Z => a_Add(200, 0, Z * 10, Brushes.GreenYellow)).ToArray(); { var radius = 100; foreach (var i in Enumerable.Range(0, 90).Select(aa => (aa * 4).DegreesToRadians())) { a_Add(Math.Cos(i) * radius, Math.Sin(i) * radius, 0, Brushes.GreenYellow); a_Add(Math.Cos(i) * radius, 0, Math.Sin(i) * radius, Brushes.BlueViolet); a_Add(0, Math.Cos(i) * radius, Math.Sin(i) * radius, Brushes.Magenta); } } { var radius = 200; foreach (var i in Enumerable.Range(0, 90).Select(aa => (aa * 4).DegreesToRadians())) { a_Add(Math.Cos(i) * radius, Math.Sin(i) * radius, 0, Brushes.GreenYellow); a_Add(Math.Cos(i) * radius, 0, Math.Sin(i) * radius, Brushes.BlueViolet); a_Add(0, Math.Cos(i) * radius, Math.Sin(i) * radius, Brushes.Magenta); } } { var radius = 500; foreach (var i in Enumerable.Range(0, 90).Select(aa => (aa * 4).DegreesToRadians())) { a_Add(Math.Cos(i) * radius, Math.Sin(i) * radius, 0, Brushes.GreenYellow); a_Add(Math.Cos(i) * radius, 0, Math.Sin(i) * radius, Brushes.BlueViolet); a_Add(0, Math.Cos(i) * radius, Math.Sin(i) * radius, Brushes.Magenta); } } a_Add(200, 0, 0, Brushes.BlueViolet); a_Add(0, 200, 0, Brushes.Yellow); a_Add(0, 0, 200, Brushes.Red); (1000 / 50).AtIntervalWithCounter( c => { // rotate floor var _a = a.ToRotation( new AffineRotation { XY = 0.01, YZ = 0.02, XZ = 0.03 } ); //var _a = a.ToRotation(0, 0.01); a = _a; //var _a = a.ToRotation(c * 0.01, c * 0.005); //var _a = a.ToRotation(c * 0.01, 0); foreach (var p in _a.Points) { ((Action<AffinePoint>)p.Tag)(p); } } ); }
public ApplicationCanvas() { Width = DefaultWidth; Height = DefaultHeight; Colors.Blue.ToGradient(Colors.Red, DefaultHeight / 4).Select( (c, i) => new Rectangle { Fill = new SolidColorBrush(c), Width = DefaultWidth, Height = 4, }.MoveTo(0, i * 4).AttachTo(this) ).ToArray(); var bg = new Avalon.Images.belchite_bw { Width = DefaultWidth, Height = DefaultHeight }.AttachTo(this); var fg_50 = new Avalon.Images.belchite { Width = DefaultWidth, Height = DefaultHeight, Opacity = 0.5 }.AttachTo(this); var fg = new Avalon.Images.belchite { Width = DefaultWidth, Height = DefaultHeight }.AttachTo(this); var cursor = new Rectangle { Fill = Brushes.Red, Width = 16, Height = 16 }.AttachTo(this); var overlay = new Rectangle { Fill = Brushes.White, Width = DefaultWidth, Height = DefaultHeight, Opacity = 0 } //.MoveTo(0, 0) .AttachTo(this); overlay.MouseMove += (sender, e) => { var p = e.GetPosition(overlay); cursor.MoveTo(p.X - 8, p.Y - 8); { var c = new RectangleGeometry { Rect = new Rect { X = p.X - 64, Y = p.Y - 32, Width = 128, Height = 64 } }; fg_50.Clip = c; } { var c = new RectangleGeometry { Rect = new Rect { X = p.X - 32, Y = p.Y - 32, Width = 64, Height = 64 } }; fg.Clip = c; } }; }
static void Main(string[] args) { var c = new JSCSolutionsNETCarouselCanvas { CloseOnClick = false }; c.HideSattelites(); //c.Container.Effect = new DropShadowEffect(); //c.Container.BitmapEffect = new DropShadowBitmapEffect(); //.MoveTo(0, ImageCarouselCanvas.DefaultHeight - 96).SizeTo(ImageCarouselCanvas.DefaultWidth, 96); var cc = new Canvas(); // http://cloudstore.blogspot.com/2008/05/creating-custom-window-style.html var wcam = new Window(); wcam.Background = Brushes.Transparent; wcam.WindowStyle = WindowStyle.None; wcam.ResizeMode = ResizeMode.NoResize; wcam.SizeTo(200, 200); wcam.AllowsTransparency = true; //wcam.Opacity = 0.5; wcam.ShowInTaskbar = false; wcam.Cursor = Cursors.Hand; wcam.Focusable = false; wcam.Topmost = true; var w = cc.ToWindow(); w.SizeToContent = SizeToContent.Manual; //w.SizeTo(400, 400); //w.ToTransparentWindow(); // http://blog.joachim.at/?p=39 // http://blogs.msdn.com/changov/archive/2009/01/19/webbrowser-control-on-transparent-wpf-window.aspx // http://blogs.interknowlogy.com/johnbowen/archive/2007/06/20/20458.aspx w.AllowsTransparency = true; w.WindowStyle = System.Windows.WindowStyle.None; w.Focusable = false; //w.Background = new SolidColorBrush(Color.FromArgb(0x20, 0, 0, 0)); w.Background = Brushes.Transparent; w.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen; w.Topmost = true; //w.ShowInTaskbar = false; var winfoc = new Canvas(); var winfo = winfoc.ToWindow(); winfo.AllowsTransparency = true; winfo.ShowInTaskbar = false; winfo.WindowStyle = WindowStyle.None; //winfo.Background = Brushes.Transparent; winfo.Background = Brushes.Red; winfo.Opacity = 0.3; winfo.ResizeMode = ResizeMode.NoResize; winfo.SizeToContent = SizeToContent.Manual; winfo.Topmost = true; // http://www.squidoo.com/youtubehd var NextInputModeEnabled = false; var NextInputModeKeyDownEnabled = false; Action<Key> NextInputModeKeyDown = delegate { }; var CommandKeysEnabled = false; #region TopicText var TopicText = new System.Windows.Controls.TextBox { //IsReadOnly = true, Background = Brushes.Transparent, BorderThickness = new System.Windows.Thickness(0), Foreground = Brushes.White, Effect = new DropShadowEffect(), Text = "JSC C# Foo Bar", //TextDecorations = TextDecorations.Underline, FontFamily = new FontFamily("Verdana"), FontSize = 24, TextAlignment = System.Windows.TextAlignment.Right }; #endregion #region KeyDown InterceptKeys.KeyDown += key => { if (key == Key.LeftShift) { //w.Background = new SolidColorBrush(Color.FromArgb(2, 0, 0, 0)); //w.MakeInteractive(true); NextInputModeEnabled = true; } else { if (NextInputModeEnabled || NextInputModeKeyDownEnabled) { NextInputModeKeyDownEnabled = false; NextInputModeKeyDown(key); } NextInputModeEnabled = false; } }; #endregion #region KeyUp InterceptKeys.KeyUp += key => { if (key == Key.CapsLock) { CommandKeysEnabled = !CommandKeysEnabled; TopicText.IsReadOnly = CommandKeysEnabled; TopicText.Select(0, 0); } if (key == Key.LeftShift) { NextInputModeKeyDownEnabled = false; } else { } NextInputModeEnabled = false; }; #endregion var s = 7; var ThumbnailSize = 0.4; var CaptionBackgroundHeight = 24; #region UpdateChildren Action UpdateChildren = delegate { if (w.ActualWidth == 0) return; var ss = s; var ss2 = 0; Console.WriteLine( new { w.Left, w.Top }); winfo.MoveTo(w.Left, w.Top).SizeTo(w.ActualWidth, w.ActualHeight); if (ThumbnailSize == 1) { wcam.Background = Brushes.Black; ss = 0; var qw = w.ActualWidth - ss * 2; var qh = w.ActualHeight - ss * 2; // no status bars or menues please :) wcam.MoveTo( w.Left + ss + ss2, w.Top + (w.ActualHeight - qh * ThumbnailSize - ss) - ss2 ).SizeTo( qw * ThumbnailSize, qh * ThumbnailSize ); } else { wcam.Background = Brushes.Transparent; //if (w.WindowState == WindowState.Maximized) //{ // ss2 = s; //} var qw = w.ActualWidth - ss * 2; var qh = w.ActualHeight - ss * 2; wcam.MoveTo(w.Left + ss + ss2, w.Top + (w.ActualHeight - qh * ThumbnailSize - ss) - ss2).SizeTo(qw * ThumbnailSize, qh * ThumbnailSize); } }; #endregion w.LocationChanged += delegate { UpdateChildren(); }; var Borders = Enumerable.Range(1, s * 2).Reverse().Select( Width => new { Width = Width * 2, Left = new Rectangle { Fill = Brushes.Black, Opacity = 0.06 }.MoveTo(0, 0).AttachTo(winfoc), Right = new Rectangle { Fill = Brushes.Black, Opacity = 0.06 }.MoveTo(0, 0).AttachTo(winfoc), Bottom = new Rectangle { Fill = Brushes.Black, Opacity = 0.03 }.MoveTo(0, 0).AttachTo(winfoc), Top = new Rectangle { Fill = Brushes.Black, Opacity = 0.11 }.MoveTo(0, 0).AttachTo(winfoc) } ).ToArray(); var CaptionBackgroundOverlay = new Rectangle { Fill = Brushes.Black, Opacity = 0.02, }.AttachTo(cc); var CaptionSysMenuOverlay = new Rectangle { Fill = Brushes.Black, Opacity = 0.02, }.AttachTo(cc).SizeTo(CaptionBackgroundHeight * 4, CaptionBackgroundHeight); var ExtraBorderTop = new Rectangle { Fill = Brushes.Black, Opacity = 0.0, }.AttachTo(winfoc); var ExtraBorderBottom = new Rectangle { Fill = Brushes.Black, Opacity = 0.0, }.AttachTo(winfoc); var CaptionClose = new TextBox { Foreground = Brushes.Red, FontFamily = new FontFamily("Webdings"), Text = "r", Background = Brushes.Transparent, BorderThickness = new Thickness(0), TextAlignment = System.Windows.TextAlignment.Center, Opacity = 0.5 }.AttachTo(winfoc); var CaptionText = new System.Windows.Controls.TextBox { IsReadOnly = true, Background = Brushes.Transparent, BorderThickness = new System.Windows.Thickness(0), Foreground = Brushes.White, Effect = new System.Windows.Media.Effects.DropShadowEffect(), Text = "jsc-solutions.net", //TextDecorations = TextDecorations.Underline, FontFamily = new FontFamily("Verdana"), FontSize = 16, TextAlignment = System.Windows.TextAlignment.Right } .AttachTo(winfoc); TopicText.AttachTo(winfoc); #region SetCaption Action<string> SetCaption = text => { if (string.IsNullOrEmpty(text)) CaptionText.Text = "jsc-solutions.net"; else CaptionText.Text = text + " | jsc-solutions.net"; }; #endregion c.AttachContainerTo(winfoc); var ExtraBorderSize = 0.10; var Intro = new PromotionBrandIntro.ApplicationCanvas().AttachTo(winfoc); Intro.Opacity = 0; #region SizeChanged Action SizeChanged = delegate { Intro.SizeTo(w.ActualWidth, w.ActualHeight); //ink.SizeTo(w.ActualWidth, w.ActualHeight - CaptionBackgroundHeight); var CaptionWidth = 200; CaptionBackgroundOverlay.MoveTo(w.ActualWidth - CaptionWidth, 0).SizeTo(CaptionWidth, CaptionBackgroundHeight); ExtraBorderTop.MoveTo(0, 0).SizeTo(w.ActualWidth, w.ActualHeight * ExtraBorderSize); ExtraBorderBottom.MoveTo(0, w.ActualHeight * (1 - ExtraBorderSize)).SizeTo(w.ActualWidth, w.ActualHeight * ExtraBorderSize); TopicText.MoveTo( 0, w.ActualHeight - 48 ).SizeTo(w.ActualWidth - 48, 48); if (c != null) c.MoveContainerTo(-200 + 42, -200 + 38); Borders.WithEach(k => k.Left.MoveTo(0, 0).SizeTo(k.Width, w.ActualHeight)); Borders.WithEach(k => k.Right.MoveTo(w.ActualWidth - k.Width, 0).SizeTo(k.Width, w.ActualHeight)); Borders.WithEach(k => k.Bottom.MoveTo(0, w.ActualHeight - k.Width).SizeTo(w.ActualWidth, k.Width)); Borders.WithEach(k => k.Top.MoveTo(0, 0).SizeTo(w.ActualWidth, k.Width)); CaptionText.MoveTo(0, 2).SizeTo(w.ActualWidth - CaptionBackgroundHeight, 32); CaptionClose.MoveTo(w.ActualWidth - CaptionBackgroundHeight, s).SizeTo(CaptionBackgroundHeight - s, CaptionBackgroundHeight - s); UpdateChildren(); }; #endregion w.SizeChanged += delegate { SizeChanged(); }; w.StateChanged += delegate { if (w.WindowState == WindowState.Maximized) w.WindowState = WindowState.Normal; SizeChanged(); }; #region GetWindows Func<IEnumerable<Internal.Window>> GetWindows = delegate { var windows = new List<Internal.Window>(); Internal.EnumWindows( (IntPtr hwnd, int lParam) => { if (new WindowInteropHelper(wcam).Handle != hwnd && (Internal.GetWindowLongA(hwnd, Internal.GWL_STYLE) & Internal.TARGETWINDOW) == Internal.TARGETWINDOW ) { StringBuilder sb = new StringBuilder(100); Internal.GetWindowText(hwnd, sb, sb.Capacity); windows.Add( new Internal.Window { Handle = hwnd, Title = sb.ToString() } ); } return true; //continue enumeration } , 0); return windows.OrderBy(k => k.Title); }; #endregion var ResetThumbnailSkip = 0; Func<Internal.Window> GetCurrentThumbnail = () => GetWindows().AsCyclicEnumerable().Skip(ResetThumbnailSkip).First(); #region AnimationCompleted Intro.AnimationCompleted += delegate { if (c == null) { c = new JSCSolutionsNETCarouselCanvas { CloseOnClick = false }.AttachContainerTo(winfoc); c.HideSattelites(); CaptionClose.Show(); SizeChanged(); } }; #endregion wcam.SourceInitialized += delegate { { wcam.MakeInteractive(false); UpdateChildren(); } var thumb = IntPtr.Zero; ResetThumbnailSkip = GetWindows().Where( k => k.Title.Contains("Chrome") || k.Title.Contains("Studio") || k.Title.Contains("Minefield") ).TakeWhile(k => k.Handle != Internal.GetForegroundWindow()).Count(); #region ResetThumbnail Action ResetThumbnail = delegate { GetCurrentThumbnail().With( shadow => { //t.Text = shadow.Title; if (thumb != IntPtr.Zero) Internal.DwmUnregisterThumbnail(thumb); int i = Internal.DwmRegisterThumbnail( new WindowInteropHelper(wcam).Handle, shadow.Handle, out thumb); #region UpdateThumbnail Action UpdateThumbnail = delegate { if (thumb != IntPtr.Zero) { Internal.PSIZE size; Internal.DwmQueryThumbnailSourceSize(thumb, out size); Internal.DWM_THUMBNAIL_PROPERTIES props = new Internal.DWM_THUMBNAIL_PROPERTIES(); props.fVisible = true; props.dwFlags = Internal.DWM_TNP_VISIBLE | Internal.DWM_TNP_RECTDESTINATION | Internal.DWM_TNP_OPACITY | Internal.DWM_TNP_SOURCECLIENTAREAONLY; props.opacity = (byte)((byte)(0x7F) + (byte)((0x80) * (ThumbnailSize))); props.rcDestination = new Internal.Rect(0, 0, (int)wcam.ActualWidth, (int)wcam.ActualHeight); props.fSourceClientAreaOnly = true; if (size.x < wcam.ActualWidth) { props.rcDestination.Right = props.rcDestination.Left + size.x; props.rcDestination.Left += ((int)wcam.ActualWidth - size.x) / 2; props.rcDestination.Right += ((int)wcam.ActualWidth - size.x) / 2; } if (size.y < wcam.ActualHeight) { props.rcDestination.Bottom = props.rcDestination.Top + size.y; props.rcDestination.Top += ((int)wcam.ActualHeight - size.y) / 2; props.rcDestination.Bottom += ((int)wcam.ActualHeight - size.y) / 2; } Internal.DwmUpdateThumbnailProperties(thumb, ref props); } }; #endregion (1000 / 15).AtInterval(UpdateThumbnail); wcam.SizeChanged += delegate { UpdateThumbnail(); }; } ); }; #endregion ResetThumbnail(); NextInputModeKeyDown += key => { if (key == Key.RightShift) { NextInputModeKeyDownEnabled = true; if (c != null) { CaptionClose.Hide(); c.AtClose += delegate { c.OrphanizeContainer(); }; c.Close(); c = null; } Intro.Background = Brushes.Transparent; Intro.Overlay.Opacity = 1; Intro.FadeIn( delegate { 2000.AtDelay(Intro.PrepareAnimation()); } ); } if (!CommandKeysEnabled) { if (key == Key.F2) { w.Activate(); TopicText.Focusable = true; TopicText.Focus(); TopicText.SelectAll(); } return; } if (key == Key.Right) { if (w.IsActive) { GetCurrentThumbnail().Activate(); } else { NextInputModeKeyDownEnabled = true; ResetThumbnailSkip = GetWindows().TakeWhile(k => k.Handle != Internal.GetForegroundWindow()).Count(); ResetThumbnail(); } } if (key == Key.Up) { NextInputModeKeyDownEnabled = true; if (ThumbnailSize < 0.3) ThumbnailSize = 0.3; else if (ThumbnailSize < 0.5) ThumbnailSize = 0.5; else if (ThumbnailSize < 1) ThumbnailSize = 1; else { if (c != null) { CaptionClose.Hide(); c.AtClose += delegate { c.OrphanizeContainer(); }; c.Close(); c = null; } } UpdateChildren(); } if (key == Key.Down) { NextInputModeKeyDownEnabled = true; if (c == null) { c = new JSCSolutionsNETCarouselCanvas { CloseOnClick = false }.AttachContainerTo(winfoc); CaptionClose.Show(); } else if (ThumbnailSize > 0.5) ThumbnailSize = 0.5; else if (ThumbnailSize > 0.3) ThumbnailSize = 0.3; else if (ThumbnailSize == 0.3) ThumbnailSize = 0; SizeChanged(); } if (key == Key.Left) { if (w.IsActive) { NextInputModeKeyDownEnabled = true; if (ExtraBorderTop.Opacity == 1) { ExtraBorderTop.Opacity = 0; ExtraBorderBottom.Opacity = 0; } else { ExtraBorderTop.Opacity = 1; ExtraBorderBottom.Opacity = 1; } } } }; }; winfo.SourceInitialized += delegate { winfo.MakeInteractive(false); }; w.SourceInitialized += delegate { // http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/61e93dca-e24c-4953-9719-22ce3f705353 Matrix m = PresentationSource.FromVisual(w).CompositionTarget.TransformToDevice; double dx = m.M11; double dy = m.M22; w.SizeTo(1280 / dx, 768 /dy); w.MoveTo(8, 0); SizeChanged(); wcam.Owner = w; winfo.Owner = w; wcam.Show(); winfo.Show(); HwndSource hwndSource = (HwndSource)HwndSource.FromVisual(w); hwndSource.AddHook( (IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handeled) => { if (msg == 0x0084) // WM_NCHITTEST { //http://agsmith.wordpress.com/2008/09/16/hit-testing-in-wpf/ var p = new { cx = w.ActualWidth - (Internal.LOWORD(lParam) - w.Left), cy = w.ActualHeight - (Internal.HIWORD(lParam) - w.Top), x = Internal.LOWORD(lParam) - w.Left, y = Internal.HIWORD(lParam) - w.Top }; CaptionText.Text = p.ToString(); handeled = true; return (IntPtr)HitTestValues.HTCAPTION; // HTCAPTION if (false) { if (p.x < s) if (p.y < s) return (IntPtr)HitTestValues.HTTOPLEFT; // HTCAPTION if (p.x < CaptionBackgroundHeight) if (p.y < CaptionBackgroundHeight) return (IntPtr)HitTestValues.HTSYSMENU; // HTCAPTION if (p.cx < CaptionBackgroundHeight) if (p.y < CaptionBackgroundHeight) return (IntPtr)HitTestValues.HTCLOSE; // HTCAPTION if (p.cx < s) if (p.cy < s) return (IntPtr)HitTestValues.HTBOTTOMRIGHT; // HTCAPTION if (p.cx < s) if (p.y < s) return (IntPtr)HitTestValues.HTTOPRIGHT; // HTCAPTION if (p.x < s) if (p.cy < s) return (IntPtr)HitTestValues.HTBOTTOMLEFT; // HTCAPTION if (p.x < s) return (IntPtr)HitTestValues.HTLEFT; // HTCAPTION if (p.y < s) return (IntPtr)HitTestValues.HTTOP; // HTCAPTION if (p.cx < s) return (IntPtr)HitTestValues.HTRIGHT; // HTCAPTION if (p.cy < s) return (IntPtr)HitTestValues.HTBOTTOM; // HTCAPTION if (p.y < CaptionBackgroundHeight) return (IntPtr)HitTestValues.HTCAPTION; // HTCAPTION return (IntPtr)HitTestValues.HTTRANSPARENT; // HTCAPTION } } return IntPtr.Zero; } ); }; InterceptKeys.InternalMain( Rehook => { w.Deactivated += delegate { TopicText.Focusable = false; }; w.Activated += delegate { //TopicText.Focus(); Rehook(); }; w.ShowDialog(); } ); }
public ApplicationCanvas() { var c = new CheckBox { Content = new TextBlock { Text = "Print to Console " } }.MoveTo(8, 96); var t = new TextBlock { Text = "?" }.AttachTo(this); var redblockcontainer = new Canvas(); redblockcontainer.Opacity = 0.8; redblockcontainer.Background = Brushes.Red; redblockcontainer.AttachTo(this); redblockcontainer.MoveTo(8, 8); this.SizeChanged += (s, e) => redblockcontainer.MoveTo(64 - 16, this.Height / 3 - 16).SizeTo(this.Width - 96, this.Height / 3 - 8); var redblockoverlay = new Canvas(); redblockoverlay.Opacity = 0.1; redblockoverlay.Background = Brushes.Red; redblockoverlay.AttachTo(this); redblockoverlay.MoveTo(8, 8); this.SizeChanged += (s, e) => redblockoverlay.MoveTo(64 + 64, this.Height / 3).SizeTo(this.Width - 96 - 64, this.Height / 3 - 8); var yellowblock = new Canvas(); yellowblock.Opacity = 0.7; yellowblock.Background = Brushes.Yellow; yellowblock.AttachTo(this); yellowblock.SizeTo(400, 200); var a_case1 = Enumerable.Range(0, 64).Select( i => { var rr = new Rectangle(); rr.Fill = Brushes.Blue; rr.AttachTo(yellowblock); rr.SizeTo(32, 32); rr.MoveTo(-32, -32); return rr; } ).ToArray(); var a_case2 = Enumerable.Range(0, 64).Select( i => { var rr = new Rectangle(); rr.Fill = Brushes.Green; rr.AttachTo(this); rr.SizeTo(32, 32); rr.MoveTo(-32, -32); return rr; } ).ToArray(); var greenblock = new Canvas(); greenblock.Opacity = 0.5; greenblock.Background = Brushes.Green; greenblock.AttachTo(this); greenblock.SizeTo(400, 200); greenblock.MoveTo(200 - 12, 12); var a_case3 = Enumerable.Range(0, 64).Select( i => { var rr = new Rectangle(); rr.Fill = Brushes.Black; rr.AttachTo(redblockcontainer); rr.SizeTo(32, 32); rr.MoveTo(-32, -32); return rr; } ).ToArray(); var case1 = yellowblock; var case2 = greenblock; var case3 = redblockoverlay; #region case1 case1.TouchDown += (s, e) => { e.Handled = true; // is called implicitly on Android Chrome e.TouchDevice.Capture(case1); Console.WriteLine("TouchDown"); }; case1.MouseMove += (s, e) => { // case 1 var p = e.GetPosition(case1); a_case1.Last().MoveTo(p); if ((bool)c.IsChecked) Console.WriteLine("MouseMove " + p); }; case1.TouchUp += (s, e) => { Console.WriteLine("TouchUp"); }; #endregion case1.TouchMove += (s, e) => { // case 1 var p = e.GetTouchPoint(case1).Position; a_case1[e.TouchDevice.Id].MoveTo(p); if ((bool)c.IsChecked) Console.WriteLine("TouchMove " + e.TouchDevice.Id + " " + p); }; #region case2 case2.TouchDown += (s, e) => { e.Handled = true; // is called implicitly on Android Chrome e.TouchDevice.Capture(case2); Console.WriteLine("TouchDown"); }; case2.MouseMove += (s, e) => { // case 1 var p = e.GetPosition(this); a_case2.Last().MoveTo(p); if ((bool)c.IsChecked) Console.WriteLine("MouseMove " + p); }; case2.TouchUp += (s, e) => { Console.WriteLine("TouchUp"); }; #endregion case2.TouchMove += (s, e) => { var p = e.GetTouchPoint(this).Position; t.Text = new { case2 = p }.ToString(); //// case 2 //var a = ((object)e as __TouchEventArgs); //if (a != null) //{ // var pp = new Point( // a.InternalValue.pageX, // a.InternalValue.pageY // ); // var b = GetPositionData.Of(a.InternalElement); // var item = b.Last(); // pp.X -= item.X; // pp.Y -= item.Y; // t.Text = new // { // case2 = new // { // pp, // a.InternalValue.screenX, // a.InternalValue.screenY, // a.InternalValue.clientX, // a.InternalValue.clientY, // a.InternalValue.pageX, // a.InternalValue.pageY // } // }.ToString(); //} a_case2[e.TouchDevice.Id].MoveTo(p); if ((bool)c.IsChecked) Console.WriteLine("TouchMove " + e.TouchDevice.Id + " " + p); }; #region case3 case3.TouchDown += (s, e) => { e.Handled = true; // is called implicitly on Android Chrome e.TouchDevice.Capture(case3); Console.WriteLine("TouchDown"); }; case3.MouseMove += (s, e) => { // case 1 var p = e.GetPosition(redblockcontainer); a_case3.Last().MoveTo(p); if ((bool)c.IsChecked) Console.WriteLine("MouseMove " + p); }; case3.TouchUp += (s, e) => { Console.WriteLine("TouchUp"); }; #endregion case3.TouchMove += (s, e) => { // case 3 var p = e.GetTouchPoint(redblockcontainer).Position; t.Text = new { case3 = p }.ToString(); //var args = ((object)e as __TouchEventArgs); //if (args != null) //{ // var pp = new Point( // args.InternalValue.pageX, // args.InternalValue.pageY // ); // var a = GetPositionData.Of(((object)redblockcontainer as __Canvas).InternalContent); // var b = GetPositionData.Of(args.InternalElement); // if (b.Count > 0) // { // var item = b.Last(); // pp.X -= item.X; // pp.Y -= item.Y; // } // // top elements might be the same so we remove them // var loop = true; // while (loop) // { // loop = false; // if (a.Count > 0) // if (b.Count > 0) // if (a[a.Count - 1].Element == b[b.Count - 1].Element) // { // a.RemoveAt(a.Count - 1); // b.RemoveAt(b.Count - 1); // loop = true; // } // } // if (a.Count > 0) // { // var itembb = a.Last(); // pp.X -= itembb.X; // pp.Y -= itembb.Y; // } // if (b.Count > 0) // { // var item = b.Last(); // pp.X += item.X; // pp.Y += item.Y; // } // t.Text = new // { // case2 = new // { // p, // pp, // //a.InternalValue.screenX, // //a.InternalValue.screenY, // //a.InternalValue.clientX, // //a.InternalValue.clientY, // args.InternalValue.pageX, // args.InternalValue.pageY // } // }.ToString(); // a_case3[e.TouchDevice.Id].MoveTo(pp); // Console.WriteLine("TouchMove " + e.TouchDevice.Id + " " + pp); // return; //} a_case3[e.TouchDevice.Id].MoveTo(p); if ((bool)c.IsChecked) Console.WriteLine("TouchMove " + e.TouchDevice.Id + " " + p); }; c.AttachTo(this); }
public void Step5_ShowMistakeMatrix( AeroNavigationBar.HistoryInfo History, LinkImage[] Source, ComparisionInfo[] Comparision, ComparisionValue[] Values) { History.AddFrame( delegate { var More = Comparision.Count(k => k.WaitingForUser && k.Value == null); #region headers var o = Source.Select<LinkImage, Action>( (k, i) => { k.SizeTo(0.15); k.AttachContainerTo(this); k.MoveContainerTo(60, 150 + i * 60); var kx = new TextButtonControl { Text = "#" + (1 + i), Width = 40, Height = 32 }; kx.AttachContainerTo(this); kx.MoveContainerTo(130, 160 + i * 60); kx.Background.Fill = Brushes.White; kx.Background.Opacity = 0.3; var ky = new TextButtonControl { Text = "#" + (1 + i), Width = 40, Height = 32 }; ky.AttachContainerTo(this); ky.MoveContainerTo(200 + i * 60, 100); ky.Background.Fill = Brushes.White; ky.Background.Opacity = 0.3; var kxr = new Rectangle { Fill = Brushes.Black, Width = Source.Length * 60 + 140, Height = 1 }; kxr.AttachTo(this); kxr.MoveTo(60, 200 + i * 60); var kyr = new Rectangle { Fill = Brushes.Black, Height = Source.Length * 60 + 60, Width = 1 }; kyr.AttachTo(this); kyr.MoveTo(250 + i * 60, 100); return delegate { k.OrphanizeContainer(); kx.OrphanizeContainer(); ky.OrphanizeContainer(); kxr.Orphanize(); kyr.Orphanize(); }; } ).ToArray(); #endregion #region values var Mistakes = Comparision.Where(q => q.WaitingForUser).ToArray( q => { var x_cells = Comparision.Where(k => k.X == q.Y).OrderBy(k => k.Y).ToArray(); var x_product = x_cells.Product(k => k.GetCurrentValue()); var y_cells = Comparision.Where(k => k.Y == q.X).OrderBy(k => k.X).ToArray(); var y_product = y_cells.Product(k => k.GetCurrentValue()); var z = Math.Pow(q.GetCurrentValue(), Source.Length); return new { q, Mistake = 1.0 / Math.Pow(x_product * y_product * z, 1.0 / (Source.Length - 2)) }; /* 1/POWER(PRODUCT(R4C2:R9C2)*PRODUCT(R9C2:R9C7)*POWER(R[-46]C;veerge);1/(veerge-2)) 1/POWER(x_product*y_product*POWER(R[-46]C;veerge);1/(veerge-2)) 1/POWER(x_product*y_product*z;1/(veerge-2)) */ } ).OrderBy( ContextMistakes => { var Mistakes_Max = ContextMistakes.Max(k => k.Mistake); var Mistakes_Min = ContextMistakes.Min(k => k.Mistake); var Mistake_Value = Mistakes_Min; if (Mistakes_Max * Mistakes_Min > 1.0) Mistake_Value = Mistakes_Max; return ContextMistakes.First(k => k.Mistake == Mistake_Value); } ).ToArray(); var Gradient = Colors.Red.ToGradient(Colors.Blue, Mistakes.Length).ToArray(); Title.Text = "Biggest mistake was made at " + Mistakes.First().q.ToVersusString() + ". Click on a cell to recompare."; var v = Mistakes.Select( (k, k_index) => { var kt = new TextButtonControl { Text = "", Width = 60 - 4, Height = 32 }; kt.AttachContainerTo(this); kt.MoveContainerTo(192 + k.q.X * 60, 160 + k.q.Y * 60); kt.Background.Fill = new SolidColorBrush(Gradient[k_index]); kt.Text = k.Mistake.ToString(); kt.Click += delegate { var NewComparision = Comparision.ToArray( oo => { var n = new ComparisionInfo { WaitingForUser = oo.WaitingForUser, Value = oo.Value, X = oo.X, Y = oo.Y }; if (oo == k.q) { n.Value = null; } return n; } ); Step3_Compare(History, Source, NewComparision, Values); }; return new Action( delegate { kt.OrphanizeContainer(); } ); } ).ToArray(); #endregion return delegate { this.Title.Text = "..."; o.ForEach(h => h()); v.ForEach(h => h()); }; } ); }
public void Step4_ShowMatrix( AeroNavigationBar.HistoryInfo History, LinkImage[] Source, ComparisionInfo[] Comparision, ComparisionValue[] Values) { History.AddFrame( delegate { var More = Comparision.Count(k => k.WaitingForUser && k.Value == null); this.Title.Text = "The Matrix. You have " + More + " image pairs to compare..."; #region headers var o = Source.Select<LinkImage, Action>( (k, i) => { k.SizeTo(0.15); k.AttachContainerTo(this); k.MoveContainerTo(60, 150 + i * 60); var kx = new TextButtonControl { Text = "#" + (1 + i), Width = 40, Height = 32 }; kx.AttachContainerTo(this); kx.MoveContainerTo(130, 160 + i * 60); kx.Background.Fill = Brushes.White; kx.Background.Opacity = 0.3; var ky = new TextButtonControl { Text = "#" + (1 + i), Width = 40, Height = 32 }; ky.AttachContainerTo(this); ky.MoveContainerTo(200 + i * 60, 100); ky.Background.Fill = Brushes.White; ky.Background.Opacity = 0.3; var kxr = new Rectangle { Fill = Brushes.Black, Width = Source.Length * 60 + 140, Height = 1 }; kxr.AttachTo(this); kxr.MoveTo(60, 200 + i * 60); var kyr = new Rectangle { Fill = Brushes.Black, Height = Source.Length * 60 + 60, Width = 1 }; kyr.AttachTo(this); kyr.MoveTo(250 + i * 60, 100); return delegate { k.OrphanizeContainer(); kx.OrphanizeContainer(); ky.OrphanizeContainer(); kxr.Orphanize(); kyr.Orphanize(); }; } ).ToArray(); #endregion #region values var v = Comparision.Select<ComparisionInfo, Action>( k => { var kt = new TextButtonControl { Text = "", Width = 40, Height = 32 }; kt.AttachContainerTo(this); kt.MoveContainerTo(200 + k.X * 60, 160 + k.Y * 60); kt.Background.Fill = Brushes.White; kt.Background.Opacity = 0.3; if (k.Value == null) { if (k.WaitingForUser) { kt.Background.Fill = Brushes.Yellow; kt.Background.Opacity = 0.5; } } else { kt.Text = k.Value.ToString(); if (k.Value.Value == 1) { kt.Background.Fill = Brushes.Cyan; kt.Background.Opacity = 0.5; } } return delegate { kt.OrphanizeContainer(); }; } ).ToArray(); #endregion return delegate { this.Title.Text = "..."; o.ForEach(h => h()); v.ForEach(h => h()); }; } ); }
public ApplicationCanvas() { var r0shadow = new Rectangle(); r0shadow.Opacity = 0.5; r0shadow.Fill = Brushes.Black; r0shadow.AttachTo(this); var r1shadow = new Rectangle(); r1shadow.Opacity = 0.5; r1shadow.Fill = Brushes.Black; r1shadow.AttachTo(this); var rcontent = new Canvas().AttachTo(this); var r0 = new Rectangle(); r0.Opacity = 0.8; r0.Fill = Brushes.DarkGreen; r0.AttachTo(rcontent); var r1 = new Rectangle(); r1.Opacity = 0.8; r1.Fill = Brushes.DarkGreen; r1.AttachTo(rcontent); r1.MoveTo(0, 96); r0.SizeTo(500, 96 - 16); r1.SizeTo(500, 230); r0shadow.SizeTo(500, 96 - 16); r1shadow.SizeTo(500, 230); var t = new TextBox(); t.IsReadOnly = true; // type: System.Windows.Controls.TextBlock //method: Void set_Foreground(System.Windows.Media.Brush) t.Foreground = Brushes.Yellow; t.AttachTo(rcontent); t.AcceptsReturn = true; t.Text = "You have found a shop.\nSee something you like?"; t.Background = Brushes.Transparent; t.BorderThickness = new Thickness(0); t.FontSize = 24; t.MoveTo(8, 8); t2 = new TextBox(); t2.IsReadOnly = true; // type: System.Windows.Controls.TextBlock //method: Void set_Foreground(System.Windows.Media.Brush) t2.Foreground = Brushes.Yellow; t2.AttachTo(rcontent); t2.AcceptsReturn = true; t2.Text = "! First we will log you in to FACEBOOK and then to PAYPAL, takes a few..."; t2.Background = Brushes.Transparent; t2.BorderThickness = new Thickness(0); t2.MoveTo(8, 290); t2o = t2.ToAnimatedOpacity(); t2o.Opacity = 0.2; bg_ammo = new Rectangle(); bg_ammo.Fill = Brushes.Yellow; bg_ammo.AttachTo(rcontent); bg_ammo.SizeTo(400, 48); bg_ammo.MoveTo(50, 128 + 32 - 8); var ammo = new Avalon.Images.avatars_ammo(); ammo.AttachTo(rcontent); ammo.MoveTo(32 + 32, 128 + 32); overlay_ammo.Fill = Brushes.Yellow; overlay_ammo.Opacity = 0; overlay_ammo.AttachTo(rcontent); overlay_ammo.SizeTo(400, 48); overlay_ammo.MoveTo(50, 128 + 32 - 8); var bg_ammo_opacity = bg_ammo.ToAnimatedOpacity(); overlay_ammo.Cursor = Cursors.Hand; bg_ammo_opacity.Opacity = 0.5; overlay_ammo.MouseEnter += delegate { bg_ammo_opacity.Opacity = 1.0; }; overlay_ammo.MouseLeave += delegate { bg_ammo_opacity.Opacity = 0.5; }; overlay_ammo.MouseLeftButtonUp += delegate { t2o.Opacity = 1; if (BuyAmmo != null) BuyAmmo(); }; bg_shotgun.Opacity = 0.5; bg_shotgun.Fill = Brushes.Yellow; bg_shotgun.AttachTo(rcontent); bg_shotgun.SizeTo(400, 48); bg_shotgun.MoveTo(50, 128 + 64 + 32); var shotgun = new Avalon.Images.avatars_shotgun(); shotgun.AttachTo(rcontent); shotgun.MoveTo(32 + 32, 128 + 64 + 32 + 8); var overlay_shotgun = new Rectangle(); overlay_shotgun.Opacity = 0; overlay_shotgun.Fill = Brushes.Yellow; overlay_shotgun.AttachTo(rcontent); overlay_shotgun.SizeTo(400, 48); overlay_shotgun.MoveTo(50, 128 + 64 + 32); var bg_shotgun_opacity = bg_shotgun.ToAnimatedOpacity(); overlay_shotgun.Cursor = Cursors.Hand; bg_shotgun_opacity.Opacity = 0.5; overlay_shotgun.MouseEnter += delegate { bg_shotgun_opacity.Opacity = 1.0; }; overlay_shotgun.MouseLeave += delegate { bg_shotgun_opacity.Opacity = 0.5; }; overlay_shotgun.MouseLeftButtonUp += delegate { t2o.Opacity = 1; if (BuyShotgun != null) BuyShotgun(); }; this.SizeChanged += (s, e) => { r0shadow.MoveTo((this.Width - 500) / 2 + 4, (this.Height - 400) / 2 + 4); r1shadow.MoveTo((this.Width - 500) / 2 + 4, (this.Height - 400) / 2 + 4 + 96); rcontent.MoveTo((this.Width - 500) / 2, (this.Height - 400) / 2); }; var rclose_shadow = new Rectangle(); //rclose.Opacity = 0.8; rclose_shadow.Fill = Brushes.Black; rclose_shadow.AttachTo(rcontent); rclose_shadow.Opacity = 0.3; rclose_shadow.SizeTo(32, 32); var rclose = new Rectangle(); rclose.Fill = Brushes.Red; rclose.AttachTo(rcontent); rclose.Cursor = Cursors.Hand; rclose.SizeTo(32, 32); var rclosemagin = -8; rclose.MoveTo(500 - 32 - rclosemagin, rclosemagin); rclose_shadow.MoveTo(500 - 32 - rclosemagin + 4, rclosemagin + 4); rclose.MouseLeftButtonUp += delegate { if (Close != null) Close(); }; }