public ApplicationCanvas() { avg = new Rectangle(); avg.Fill = Brushes.Red; avg.AttachTo(this); avg.SizeTo(16, 16); avg.Opacity = 0.2; //Canvas.SetZIndex(avg, 1000); f.Fill = Brushes.Yellow; f.AttachTo(this); f.SizeTo(16, 16); f.Opacity = 0.5; }
public FreeCellCanvas() { this.Width = DefaultWidth; this.Height = DefaultHeight; // is this working? this.ClipToBounds = true; new TiledBackgroundImage( new felt().Source, 64, 64, // repeaters x: 32, y: 24 ).AttachContainerTo(this); var ShadowSize = 40; new GameBorders(DefaultWidth, DefaultHeight, ShadowSize, this).AttachContainerTo(this); var Margin = (DefaultWidth - CardInfo.Width * 10) / 11; //new Image //{ // Source = (KnownAssets.Path.Assets + "/jsc.png").ToSource(), // Width = 96, // Height = 96 //}.MoveTo(DefaultWidth - 96, DefaultHeight - 96).AttachTo(this); this.History = new AeroNavigationBar().MoveContainerTo( 12, 8 ); // make it bigger for android! //this.History.Container.RenderTransform = new ScaleTransform(2, 2); var Content = new Canvas { Width = DefaultWidth, Height = DefaultHeight }.AttachTo(this); var Game = default(FreeCellGame); var GameFocusBoost = false; Action AtSizeChanged = delegate { if (Game != null) Game.MoveTo( (this.Width - DefaultWidth) / 2, (this.Height - DefaultHeight) ); }; this.SizeChanged += delegate { AtSizeChanged(); }; Action CreateGame = delegate { var PreviousGame = Game; Game.Orphanize(); Game = new FreeCellGame() { History = History, }; Game.MyDeck.Sounds = this.Sounds; Game.AttachTo(Content); AtSizeChanged(); var CurrentGame = Game; this.History.History.Add( delegate { if (Game == PreviousGame) return; Game.Orphanize(); Game = PreviousGame.AttachTo(Content); if (Game == null) this.Menu.Show(); }, delegate { if (Game == CurrentGame) return; Game.Orphanize(); Game = CurrentGame.AttachTo(Content); if (Game != null) this.Menu.Hide(); } ); }; //new GameSocialLinks(this) //{ // new GameSocialLinks.Button { // Source = (KnownAssets.Path.Assets + "/plus_google.png").ToSource(), // Width = 62, // Height = 17, // Hyperlink = new Uri(Info.GoogleGadgetAddLink) // }, // new GameSocialLinks.Button { // Source = (KnownAssets.Path.Assets + "/su.png").ToSource(), // Width = 16, // Height = 16, // Hyperlink = new Uri( "http://www.stumbleupon.com/submit?url=" + Info.URL) // } //}; // redefine the ctor to fit our context //Func<string, string, string, GameMenuOption> Option = // (Text, Image, href) => // new GameMenuOption // { // Text = "Play " + Text + "!", // Source = (KnownAssets.Path.SocialLinks + "/" + Image + ".png").ToSource(), // Hyperlink = new Uri(href), // MarginAfter = Math.PI / 4 // }; this.Menu = new GameMenu((int)this.Width, DefaultHeight, ShadowSize, this) { new GameMenuOption { Text = "FreeCell - medium difficulty", Source = new Preview().Source, MarginAfter = Math.PI / 2, Click = delegate { GameFocusBoost = true; CreateGame(); this.Menu.Hide(); 1000.AtDelay(() => GameFocusBoost = false); } }, //Option("Spider Solitaire", "Preview_Spider", "http://nonoba.com/zproxy/avalon-spider-solitaire"), //Option("Treasure Hunt", "Preview_TreasureHunt", "http://nonoba.com/zproxy/treasure-hunt"), //Option("FlashMinesweeper:MP", "Preview_Minesweeper", "http://nonoba.com/zproxy/flashminesweepermp"), //Option("Multiplayer Mahjong", "Preview_Mahjong", "http://nonoba.com/zproxy/mahjong-multiplayer"), //Option("Multiplayer SpaceInvaders", "Preview_SpaceInvaders", "http://nonoba.com/zproxy/flashspaceinvaders"), }; this.Menu.ValidateHide = () => Game != null; this.Menu.ValidateShow = () => !GameFocusBoost; this.Menu.AttachContainerTo(this); // QA: is this working correctly for flash? #if DEBUG var HistoryNoZone = new Rectangle(); HistoryNoZone.Fill = Brushes.Yellow; HistoryNoZone.Width = 96; HistoryNoZone.Height = 48; HistoryNoZone.Opacity = 0; HistoryNoZone.AttachTo(this); this.History.AttachContainerTo(this); #endif this.Menu.Show(); }
public OrcasAvalonApplicationCanvas() { Width = DefaultWidth; Height = DefaultHeight; //Background = 0xffc0c0c0.ToSolidColorBrush(); Background = Brushes.Black; var InfoOverlay = new Canvas { Width = DefaultWidth, Height = DefaultHeight, }; var InfoOverlayShadow = new Rectangle { Width = DefaultWidth, Height = DefaultHeight, Fill = Brushes.Black }.AttachTo(InfoOverlay); var InfoOverlayShadowOpacity = InfoOverlay.ToAnimatedOpacity(); InfoOverlayShadowOpacity.Opacity = 1; var InfoOverlayText = new TextBox { AcceptsReturn = true, IsReadOnly = true, Background = Brushes.Transparent, BorderThickness = new Thickness(0), Width = DefaultWidth, Height = 180, TextAlignment = TextAlignment.Center, FontSize = 30, Foreground = Brushes.White, Text = "The winner is\n the first player\n to get an unbroken row\n of five stones", FontFamily = new FontFamily("Verdana") }.MoveTo(0, (DefaultHeight - 180) / 2).AttachTo(InfoOverlay); var TouchOverlay = new Canvas { Width = DefaultWidth, Height = DefaultHeight, Background = Brushes.Yellow, Opacity = 0, }; var Tiles = new Tile[Intersections * Intersections]; #region WhereUnderAttack Func<int, int, IEnumerable<Tile>> WhereUnderAttack = (length, value) => Tiles.Where( k => { if (k.Value != 0) return false; return k.IsUnderAttack(value, length); } ); #endregion #region AI Action AI = delegate { // defensive rule: var AttackWith4 = WhereUnderAttack(4, -1).FirstOrDefault(); if (AttackWith4 != null) { Console.WriteLine("AttackWith4"); AttackWith4.Value = -1; return; } var AttackedBy4 = WhereUnderAttack(4, 1).FirstOrDefault(); if (AttackedBy4 != null) { Console.WriteLine("AttackedBy4"); AttackedBy4.Value = -1; return; } var AttackWith3 = WhereUnderAttack(3, -1).FirstOrDefault(); if (AttackWith3 != null) { Console.WriteLine("AttackWith3"); AttackWith3.Value = -1; return; } var AttackedBy3 = WhereUnderAttack(3, 1).FirstOrDefault(); if (AttackedBy3 != null) { Console.WriteLine("AttackedBy3"); AttackedBy3.Value = -1; return; } var AttackWith2 = WhereUnderAttack(2, -1).FirstOrDefault(); if (AttackWith2 != null) { Console.WriteLine("AttackWith2"); AttackWith2.Value = -1; return; } var AttackedBy2 = WhereUnderAttack(2, 1).FirstOrDefault(); if (AttackedBy2 != null) { Console.WriteLine("AttackedBy2"); AttackedBy2.Value = -1; return; } var AttackedBy1 = WhereUnderAttack(1, 1).FirstOrDefault(); if (AttackedBy1 != null) { Console.WriteLine("AttackedBy1"); AttackedBy1.Value = -1; return; } Console.WriteLine("Random"); Tiles.Where(k => k.Value == 0).Random().Value = -1; }; #endregion var ResetOverlay = new Rectangle { Fill = Brushes.Yellow, Width = DefaultWidth, Height = DefaultHeight, Cursor = Cursors.Hand, }; //9000.AtDelay( // delegate // { // ResetOverlay.Orphanize(); // InfoOverlayShadowOpacity.Opacity = 0; // } //); ResetOverlay.MouseLeftButtonUp += delegate { Tiles.ForEach(k => k.Value = 0); ResetOverlay.Orphanize(); InfoOverlayShadowOpacity.Opacity = 0; }; Action<Tile> Tiles_WithEvents = t => { #region add 2d awareness t.ByOffset = (ox, oy) => { var x = t.X + ox; var y = t.Y + oy; if (x < 0) return null; if (y < 0) return null; if (x >= Intersections) return null; if (y >= Intersections) return null; return Tiles[x + y * Intersections]; }; #endregion t.TouchOverlay.MouseLeftButtonUp += delegate { if (t.Value != 0) return; t.Value = 1; if (AtClick != null) AtClick(); // did we win? if (Tiles.Any( k => { if (k.Value != 1) return false; return k.IsUnderAttack(1, 4); } )) { InfoOverlayShadowOpacity.Opacity = 0.8; InfoOverlayText.Text = "You won!\n\n:)"; ResetOverlay.AttachTo(TouchOverlay); if (AtWin != null) AtWin(); return; } t.TouchOverlay.Hide(); 100.AtDelay( delegate { AI(); t.TouchOverlay.Show(); if (Tiles.Any( k => { if (k.Value != -1) return false; return k.IsUnderAttack(-1, 4); } )) { InfoOverlayShadowOpacity.Opacity = 0.8; InfoOverlayText.Text = "You lost!\n\n:("; ResetOverlay.AttachTo(TouchOverlay); if (AtLoss != null) AtLoss(); return; } } ); }; }; var TileContainer = new Canvas().AttachTo(this); #region build board for (int x = 0; x < Intersections; x++) for (int y = 0; y < Intersections; y++) { var t = new Tile(x, y); t.Container.AttachTo(TileContainer); t.TouchOverlay.AttachTo(TouchOverlay); Tiles[x + y * Intersections] = t; Tiles_WithEvents(t); } #endregion #region add logo var img = new com.abstractatech.gomoku.Avalon.Images.jsc { }.MoveTo(DefaultWidth - 96, DefaultHeight - 96).AttachTo(TileContainer); #endregion ResetOverlay.AttachTo(TouchOverlay); InfoOverlay.AttachTo(this); TouchOverlay.AttachTo(this); this.SizeChanged += delegate { TileContainer.MoveTo( (this.Width - DefaultWidth) /2, (this.Height - DefaultHeight) /2 ); TouchOverlay.MoveTo( (this.Width - DefaultWidth) / 2, (this.Height - DefaultHeight) / 2 ); ResetOverlay.SizeTo(this.Width, this.Height); InfoOverlay.SizeTo(this.Width, this.Height); InfoOverlayShadow.SizeTo(this.Width, this.Height); //TouchOverlay.SizeTo(this.Width, this.Height); InfoOverlayText.MoveTo(0, (this.Height - 180) / 2); InfoOverlayText.SizeTo(this.Width, 180); }; }
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() { c = new Base.ApplicationCanvas(); c.Selection.GlassArea.Orphanize(); c.Selection.Orphanize(); c.AttachTo(this); c.MoveTo(8, 8); this.SizeChanged += (s, e) => c.SizeTo(this.Width - 16.0, this.Height - 16.0); r.Fill = Brushes.Red; r.Opacity = 0; r.AttachTo(this); r.MoveTo(8, 8); this.SizeChanged += (s, e) => r.SizeTo(this.Width - 16.0, this.Height - 16.0); Rectangle h = null; AnimatedOpacity<Rectangle> hOpacity = null; Action<Action<double, double>> GetPosition = null; var Windows = new List<Base.ApplicationCanvas.WindowInfo>(); #region GetSnapLocation Action<Func<UIElement, Point>, Action<bool, double, double, double, double>> GetSnapLocation = (e_GetPosition, SetLocation) => { var p = e_GetPosition(r); var x = 0.0; var y = 0.0; GetPosition((_x, _y) => { x = _x; y = _y; }); var cx = p.X - x; var cy = p.Y - y; if (cx < 0) { x += cx; cx = -cx; } if (cy < 0) { y += cy; cy = -cy; } var Snap = 16; var SnapMode = false; Enumerable.FirstOrDefault( from k in Windows let dx0 = Math.Abs(k.WindowLocation.Left - x) where dx0 < Snap orderby dx0 select k ).With( ax => { SnapMode = true; cx += x - ax.WindowLocation.Left; x = ax.WindowLocation.Left; } ); Enumerable.FirstOrDefault( from k in Windows let dx0 = Math.Abs(k.WindowLocation.Top - y) where dx0 < Snap orderby dx0 select k ).With( ax => { SnapMode = true; cy += y - ax.WindowLocation.Top; y = ax.WindowLocation.Top; } ); SetLocation(SnapMode, x, y, cx, cy); }; #endregion #region MouseLeftButtonDown r.MouseLeftButtonDown += (s, e) => { h = new Rectangle { Fill = Brushes.Black, }; hOpacity = h.ToAnimatedOpacity(); hOpacity.Opacity = 0.3; var p = e.GetPosition(r); //Console.WriteLine("MouseLeftButtonDown " + new { p.X, p.Y }); GetPosition = y => y(p.X, p.Y); h.AttachTo(c).MoveTo(p).SizeTo(0, 0); c.Selection.Orphanize(); c.Selection.WindowLocation.Left = p.X; c.Selection.WindowLocation.Top = p.Y; c.Selection.WindowLocation.Width = 0; c.Selection.WindowLocation.Height = 0; c.Selection.WindowLocationChanged(); c.Selection.Attach(); Windows.WithEach(k => k.GlassOpacity.Opacity = 0); }; #endregion #region MouseMove r.MouseMove += (s, e) => { if (GetPosition != null) { GetSnapLocation(e.GetPosition, (SnapMode, x, y, cx, cy) => { //Console.WriteLine("MouseMove " + new { x, y, cx, cy }); if (SnapMode) hOpacity.Opacity = 0.9; else hOpacity.Opacity = 0.3; c.Selection.WindowLocation.Left = x; c.Selection.WindowLocation.Top = y; c.Selection.WindowLocation.Width = cx; c.Selection.WindowLocation.Height = cy; c.Selection.WindowLocationChanged(); h.MoveTo(x, y).SizeTo(cx, cy); } ); } }; #endregion #region MouseLeftButtonUp r.MouseLeftButtonUp += (s, e) => { //Console.WriteLine("MouseLeftButtonUp"); if (GetPosition == null) return; GetSnapLocation(e.GetPosition, (SnapMode, x, y, cx, cy) => { //Console.WriteLine("MouseLeftButtonUp " + new { x, y, cx, cy }); Windows.WithEach(k => k.GlassOpacity.Opacity = 1); h.Orphanize(); c.Selection.Orphanize(); if (cx > 32) if (cy > 32) c.CreateWindow( new Base.ApplicationCanvas.Position { Left = x, Top = y, Width = cx, Height = cy }, Windows.Add ); } ); GetPosition = null; }; #endregion #region TouchDown r.TouchDown += (s, e) => { h = new Rectangle { Fill = Brushes.Black, }; hOpacity = h.ToAnimatedOpacity(); hOpacity.Opacity = 0.3; var p = e.GetTouchPoint(r).Position; //Console.WriteLine("MouseLeftButtonDown " + new { p.X, p.Y }); GetPosition = y => y(p.X, p.Y); h.AttachTo(c).MoveTo(p).SizeTo(0, 0); c.Selection.Orphanize(); c.Selection.WindowLocation.Left = p.X; c.Selection.WindowLocation.Top = p.Y; c.Selection.WindowLocation.Width = 0; c.Selection.WindowLocation.Height = 0; c.Selection.WindowLocationChanged(); c.Selection.Attach(); Windows.WithEach(k => k.GlassOpacity.Opacity = 0); }; #endregion #region MouseMove r.TouchMove += (s, e) => { if (GetPosition != null) { Func<UIElement, Point> e_GetPosition = x => e.GetTouchPoint(x).Position; GetSnapLocation(e_GetPosition, (SnapMode, x, y, cx, cy) => { //Console.WriteLine("MouseMove " + new { x, y, cx, cy }); if (SnapMode) hOpacity.Opacity = 0.9; else hOpacity.Opacity = 0.3; c.Selection.WindowLocation.Left = x; c.Selection.WindowLocation.Top = y; c.Selection.WindowLocation.Width = cx; c.Selection.WindowLocation.Height = cy; c.Selection.WindowLocationChanged(); h.MoveTo(x, y).SizeTo(cx, cy); } ); } }; #endregion #region TouchUp r.TouchUp += (s, e) => { //Console.WriteLine("MouseLeftButtonUp"); if (GetPosition == null) return; Func<UIElement, Point> e_GetPosition = x => e.GetTouchPoint(x).Position; GetSnapLocation(e_GetPosition, (SnapMode, x, y, cx, cy) => { //Console.WriteLine("MouseLeftButtonUp " + new { x, y, cx, cy }); Windows.WithEach(k => k.GlassOpacity.Opacity = 1); h.Orphanize(); c.Selection.Orphanize(); if (cx > 32) if (cy > 32) c.CreateWindow( new Base.ApplicationCanvas.Position { Left = x, Top = y, Width = cx, Height = cy }, Windows.Add ); } ); GetPosition = null; }; #endregion }
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 ImageCarouselCanvas(Arguments args) { this.CloseOnClick = true; this.Container = new Canvas { Width = DefaultWidth, Height = DefaultHeight }; //var r = new Rectangle //{ // Fill = Brushes.Red, // Opacity = 0.05 //}; //r.SizeTo(DefaultWidth, DefaultHeight); //r.AttachTo(this); //this.Container.Background = Brushes.Transparent; //this.Container.Background = Brushes.Red; var y = 0; var s = new Stopwatch(); s.Start(); var images = new List<XImage>(); #region AddImages Func<Image, XImage> Add = i => { y += 32; var n = new XImage { Image = i, Opacity = 0, Radius = 72 }; RenderOptions.SetBitmapScalingMode(i, BitmapScalingMode.Fant); images.Add(n); i.Opacity = 0; i.AttachTo(this); return n; }; args.AddImages(Add); #endregion var size = 64; Action<DispatcherTimer> AtAnimation = delegate { }; // .net is fast, but js will be slow :) var randomphase = Math.PI * 2 * new Random().NextDouble(); #region AtIntervalWithTimer var AnimationTimer = (1000 / 50).AtIntervalWithTimer( t => { var ms = s.ElapsedMilliseconds; var i = 0; AtAnimation(t); // using for each must be the last thing in a method // because .leave operator currently cannot be understood by jsc foreach (var item_ in images) { var item = item_.Image; var phase = Math.PI * 2 * i / images.Count + randomphase; var cos = Math.Cos(step * ms + phase); var sin = Math.Sin(step * ms + phase); var z1margin = 0.7; var z1 = (cos + (1 + z1margin)) / (2 + z1margin); var z2margin = 1.0; var z2 = (cos + (1 + z2margin)) / (2 + z2margin); item.Opacity = z1 * item_.Opacity; item.SizeTo(size * z2, size * z2); item.MoveTo( -sin * item_.Radius + (DefaultWidth + args.ImageDefaultWidth * 0.3) / 2 //+ jsc.ImageDefaultWidth + cos * item_.Radius - size * z2 * 0.5 , sin * item_.Radius + (DefaultHeight + args.ImageDefaultHeight * 0.3) / 2 //+ jsc.ImageDefaultHeight - size * z2 * 0.5 ); Canvas.SetZIndex(item, Convert.ToInt32(z1 * 1000)); i++; } } ); #endregion var logo = args.CreateCenterImage(); #region WaitAndAppear Action<int, double, Action<double>> WaitAndAppear = (delay, step__, set_Opacity) => { var a = 0.0; set_Opacity(a); delay.AtDelay( delegate { (1000 / 30).AtIntervalWithTimer( t => { a += step__; if (a > 1) { set_Opacity(1); t.Stop(); return; } set_Opacity(a); } ); } ); }; #endregion WaitAndAppear(200, 0.07, n => logo.Opacity = n); SattelitesHidden = false; ShowSattelites(images, WaitAndAppear); ShowSattelitesAgain = delegate { if (!SattelitesHidden) return; SattelitesHidden = false; if (AtSattelitesShownAgain != null) AtSattelitesShownAgain(); foreach (var item__ in images.ToArray()) { var item = item__; WaitAndAppear(0, StepSpeedToToggleSattelites, n => item.Opacity = n); } }; Canvas.SetZIndex(logo, 500); logo.AttachTo(this).MoveTo( (DefaultWidth - args.ImageDefaultWidth) / 2, (DefaultHeight - args.ImageDefaultHeight) / 2 ); var logo_hit = new Rectangle { Fill = Brushes.Red, Opacity = 0 }; Canvas.SetZIndex(logo_hit, 501); logo_hit.Cursor = Cursors.Hand; logo_hit.AttachTo(this).MoveTo( (DefaultWidth - args.ImageDefaultWidth) / 2, (DefaultHeight - args.ImageDefaultHeight) / 2 ); logo_hit.SizeTo(args.ImageDefaultWidth, args.ImageDefaultHeight); #region MouseLeftButtonUp logo_hit.MouseLeftButtonUp += delegate { if (AtLogoClick != null) AtLogoClick(); //new Uri("http://www.jsc-solutions.net").NavigateTo(this.Container); if (CloseOnClick) { Close(); logo_hit.Orphanize(); } }; #endregion #region HideSattelites this.HideSattelites = delegate { SattelitesHidden = true; Action TriggerClose = () => AtAnimation = t => { if (images.Any(k => k.Opacity > 0)) return; t.Stop(); if (AtClose != null) AtClose(); }; AtAnimation = t => { if (images.Any(k => k.Opacity < 1)) return; foreach (var item__ in images.ToArray()) { var item = item__; var NextDelay = 1; if (!DisableTimerShutdown) NextDelay = 1 + 1000.Random(); WaitAndAppear(NextDelay, StepSpeedToToggleSattelites, n => item.Opacity = 1 - n); } if (DisableTimerShutdown) { AtAnimation = delegate { }; } else TriggerClose(); }; }; #endregion this.Close = delegate { WaitAndAppear(1, 0.12, n => logo.Opacity = 1 - n); HideSattelites(); }; }
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(); }; }