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 MineFieldButton() { ConstructorStopwatch = new Stopwatch(); ConstructorStopwatch.Start(); this.Shadow = new Rectangle { Fill = Brushes.Black, Opacity = 0.2, }.SizeTo(Size, Size); this.Container = new Canvas { }.SizeTo(Size, Size); this.Background = new Rectangle { Fill = 0xffc0c0c0.ToSolidColorBrush() }.SizeTo(Size, Size).AttachTo(Container); this.BackgroundOpacity = this.Background.ToAnimatedOpacity(); this.Flag = ("assets/AvalonMinesweeper.Core/flag_a.png").ToImage(Size, Size).AttachTo(Container); this.Question = ("assets/AvalonMinesweeper.Core/question_a.png").ToImage(Size, Size).AttachTo(Container); this.Mine = ("assets/AvalonMinesweeper.Core/mine_a.png").ToImage(Size, Size).AttachTo(Container); this.Strike = ("assets/AvalonMinesweeper.Core/strike_a.png").ToImage(Size, Size).AttachTo(Container); this.Flag.Hide(); this.Question.Hide(); this.Mine.Hide(); this.Strike.Hide(); this.TouchRectangle = new Rectangle { Fill = Brushes.Black, Opacity = 0, Cursor = Cursors.Hand }.SizeTo(Size, Size); var a = ("assets/AvalonMinesweeper.Core/button_a.png").ToImage(Size, Size).WithOpacity(0.8).AttachTo(Container); var b = ("assets/AvalonMinesweeper.Core/button_b.png").ToImage(Size, Size).WithOpacity(0.335).AttachTo(Container); var e = ("assets/AvalonMinesweeper.Core/empty_a.png").ToImage(Size, Size).WithOpacity(0.335).AttachTo(Container); e.Hide(); this.IsPressed = new Action <bool>( value => { a.Show(!value); b.Show(!value); e.Show(value); } ); this.VisibleNumber = new Func <int, Action>( n => { // if the following expressions were combined // jsc would emit: if (!(((n < 1)) ? true : !(n < 9))) // which will make mxmlc complain // jsc could be updated to actually detect short-circut expression if (n < 1) { return(null); } if (n > 8) { return(null); } var i = ("assets/AvalonMinesweeper.Core/a" + n + ".png").ToImage(Size, Size).AttachTo(Container); return(() => i.Orphanize()); } ).ToContinuation(); var CanClick = false; this.TouchRectangle.MouseLeftButtonDown += delegate { if (!IsEnabled) { return; } CanClick = true; IsPressed.Value = true; }; this.TouchRectangle.MouseLeave += (sender, args) => { if (!CanClick) { return; } CanClick = false; IsPressed.Value = false; }; this.TouchRectangle.MouseLeftButtonUp += (sender, args) => { if (!CanClick) { return; } CanClick = false; IsPressed.Value = false; if (this.Click != null) { this.Click(this, args); } }; this.IsEnabled = true; ConstructorStopwatch.Stop(); }
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(); } }; }
private static void ShowImageWhenReady(GameReference k, Image Image, TextBox Text, AnimatedOpacity AnimatedImage) { if (k.Source == null) { var s = new BitmapImage(); //Text.Text = "loading..."; s.DownloadCompleted += delegate { //Text.Text = "done!"; //Image.Opacity = 1; AnimatedImage.Opacity = 1; }; s.BeginInit(); s.UriSource = new Uri(k.Image); s.EndInit(); Image.Source = s; Text.Foreground = Brushes.Yellow; } else { //Text.Text = "done!!"; Image.Source = k.Source.ToSource(); //Image.Opacity = 1; AnimatedImage.Opacity = 1; } }
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; }