public LinearTimeTween Start() { if (_Timer != null) { _Timer.Stop(); } TimeStarted = DateTime.Now.Ticks / TicksPerMillisecond; if (Starting != null) { Starting(); } _Timer = new ScriptCoreLib.JavaScript.Runtime.Timer( t => { TimeNow = DateTime.Now.Ticks / TicksPerMillisecond; var x = TimeNow - TimeStarted; Console.WriteLine("x: " + x); Console.WriteLine("length: " + Length); if (x > Length) { t.Stop(); _Timer = null; Elapsed = Length; Changed(this); Stopping(); } else { Elapsed = x; Changed(this); } }, 0, Percision ); return(this); }
public static Action ToASCIIStyledLoadAnimation(this IHTMLElement e, string innerText) { var feed = new[] { "-", "/", "|", "\\" }; var t = new ScriptCoreLib.JavaScript.Runtime.Timer( tt => { e.innerText = "Loading... " + feed.ElementAt(tt.Counter % feed.Length); } ); t.StartInterval(300); return delegate { t.Stop(); e.innerText = innerText; }; }
private void Internal_add_TextChanged(TextChangedEventHandler value) { //Console.WriteLine("Internal_add_TextChanged: "); var NotifyText = default(string); Action Notify = delegate { //Console.WriteLine("notify: " + this.Text); InternalAutoSizeUpdate(); value(this, null); }; var t = new ScriptCoreLib.JavaScript.Runtime.Timer(); Action Check = delegate { var Text = this.Text; if (Text == NotifyText) return; NotifyText = Text; Notify(); }; t.Tick += delegate { Check(); }; this.InternalGetTextField().onfocus += delegate { //Console.WriteLine("onfocus: "); NotifyText = this.Text; // based on cpu and text length we may choose a larger interval t.StartInterval(1000 / 10); }; this.InternalGetTextField().onblur += delegate { //Console.WriteLine("onblur: "); t.Stop(); NotifyText = null; }; this.InternalGetTextField().onchange += delegate { Check(); }; this.InternalGetTextField().onkeyup += delegate { Check(); }; this.InternalGetTextField().onkeydown += delegate { Check(); }; }
private void Internal_add_TextChanged(TextChangedEventHandler value) { //Console.WriteLine("Internal_add_TextChanged: "); var NotifyText = default(string); Action Notify = delegate { //Console.WriteLine("notify: " + this.Text); InternalAutoSizeUpdate(); value(this, null); }; var t = new ScriptCoreLib.JavaScript.Runtime.Timer(); Action Check = delegate { var Text = this.Text; if (Text == NotifyText) { return; } NotifyText = Text; Notify(); }; t.Tick += delegate { Check(); }; this.InternalGetTextField().onfocus += delegate { //Console.WriteLine("onfocus: "); NotifyText = this.Text; // based on cpu and text length we may choose a larger interval t.StartInterval(1000 / 10); }; this.InternalGetTextField().onblur += delegate { //Console.WriteLine("onblur: "); t.Stop(); NotifyText = null; }; this.InternalGetTextField().onchange += delegate { Check(); }; this.InternalGetTextField().onkeyup += delegate { Check(); }; this.InternalGetTextField().onkeydown += delegate { Check(); }; }
//Revision: 3636 //Author: zproxy //Date: 22. aprill 2012. a. 11:16:53 //Message: //---- //Added : /examples/java/OutRun4KTemplate //Added : /examples/java/OutRun4KTemplate/OutRun4KTemplate // http://www.digitalinsane.com/archives/2007/01/21/space_invaders/ public SpaceInvaders() { ImageResources gfx = "http://server/"; var overlay = new Overlay(); overlay.BackgroundColor = Color.Black; overlay.MaximumOpacity = 1; overlay.ControlInBack.style.zIndex = 100000; overlay.ControlInFront.style.zIndex = 100001; var view = overlay.ControlInFront; view.style.textAlign = IStyle.TextAlignEnum.center; view.style.SetSize(480, 480); view.style.backgroundColor = Color.Green; view.style.color = Color.White; view.style.fontFamily = IStyle.FontFamilyEnum.Fixedsys; //Native.Document.body.appendChild( // new IHTMLElement(IHTMLElement.HTMLElementEnum.center, // view) // ); //Native.Document.body.style.backgroundColor = Color.Black; // Native.Document.body.style.overflow = IStyle.OverflowEnum.hidden; System.Func <IHTMLDiv> CreateCanvas = delegate { var c = new IHTMLDiv(); c.style.overflow = IStyle.OverflowEnum.hidden; c.style.SetLocation(1, 1, 478, 478); return(c); }; view.style.position = IStyle.PositionEnum.relative; var canvas = CreateCanvas(); var menu = CreateCanvas(); canvas.style.backgroundColor = Color.Black; view.appendChild(canvas, menu); var msg_loading = new IHTMLDiv("loading..."); msg_loading.style.color = Color.Green; menu.appendChild(msg_loading); // at this point we want our images overlay.Visible = true; ScriptCoreLib.JavaScript.Runtime.Timer.DoAsync(overlay.UpdateLocation); // now wait while all images are loaded/complete ((fbool)(() => !gfx.IsComplete)).Trigger( delegate { // loading images is done now. // build the scoreboard var MyEnemyDirectory = new EnemyDirectory(gfx); var board = new ScoreBoard(gfx); board.Control.style.SetLocation(8, 8, 464, 64); canvas.appendChild(board.Control); board.Lives = 2; board.Score = 450; // now we can see lives and score. // ie does not issue keypress for control keys. // scriptcorelib should filter firefox events... // lets show main menu var mmenu = new MainMenu(MyEnemyDirectory, gfx); var gameovermenu = new GameOverMenu(); menu.appendChild(mmenu.Control, gameovermenu.Control); gameovermenu.Visible = false; gameovermenu.Control.style.SetLocation(0, 100, 468, 468 - 100); mmenu.Control.style.SetLocation(0, 64, 468, 468 - 64); mmenu.Visible = true; var Enemy_Ammo = new AmmoInfo { Color = Color.White, Speed = 8 }; var Player = (IHTMLImage)gfx.biggun.Clone(); var Player_Ammo = new AmmoInfo { Color = Color.Green, Speed = -8 }; var Map_Top = 64; var Map_Left = 20; var Map_Right = 450; var Map_Bottom = 470; var Map_Rect = new Rectangle(); Map_Rect.Top = Map_Top; Map_Rect.Left = Map_Left; Map_Rect.Right = Map_Right; Map_Rect.Bottom = Map_Bottom; var Player_Y = 460; var Player_X = 200; var Player_X_step = 8; Action <int> UpdatePlayer = delegate(int v) { Player_X += v; if (Player_X < Map_Left) { Player_X = Map_Left; } if (Player_X > Map_Right) { Player_X = Map_Right; } Player.SetCenteredLocation(Player_X, Player_Y); Player.style.position = IStyle.PositionEnum.absolute; }; Player.Hide(); canvas.appendChild(Player, Player_Ammo.Control, Enemy_Ammo.Control); AmmoInfo[] KnownAmmo = new[] { Player_Ammo, Enemy_Ammo }; var KnownConcrete = new List <Concrete>(); var ConcreteTop = 432; KnownConcrete.AddRange(Concrete.BuildAt(new Point(62 + 120 * 0, ConcreteTop))); KnownConcrete.AddRange(Concrete.BuildAt(new Point(62 + 120 * 1, ConcreteTop))); KnownConcrete.AddRange(Concrete.BuildAt(new Point(62 + 120 * 2, ConcreteTop))); KnownConcrete.AddRange(Concrete.BuildAt(new Point(62 + 120 * 3, ConcreteTop))); foreach (Concrete v in KnownConcrete.ToArray()) { canvas.appendChild(v.Control); } var UFO = new EnemyUnit(MyEnemyDirectory.UFO); var UFO_Direction = 1; UFO.Visible = false; canvas.appendChild(UFO.Control); var EnemyTop = 128; var EnemySpacing = 32; var EnemyCount = 9; var KnownEnemies = new List <EnemyUnit>(); KnownEnemies.AddRange(EnemyUnit.Build(MyEnemyDirectory.A, 20, EnemyTop + 0 * EnemySpacing, EnemyCount, EnemySpacing)); KnownEnemies.AddRange(EnemyUnit.Build(MyEnemyDirectory.B, 20, EnemyTop + 1 * EnemySpacing, EnemyCount, EnemySpacing)); KnownEnemies.AddRange(EnemyUnit.Build(MyEnemyDirectory.B, 20, EnemyTop + 2 * EnemySpacing, EnemyCount, EnemySpacing)); KnownEnemies.AddRange(EnemyUnit.Build(MyEnemyDirectory.C, 20, EnemyTop + 3 * EnemySpacing, EnemyCount, EnemySpacing)); KnownEnemies.AddRange(EnemyUnit.Build(MyEnemyDirectory.C, 20, EnemyTop + 4 * EnemySpacing, EnemyCount, EnemySpacing)); foreach (EnemyUnit v in KnownEnemies.ToArray()) { canvas.appendChild(v.Control); } var HitDamage = 40; var GameTimer = new ScriptCoreLib.JavaScript.Runtime.Timer(); int GangDirection = 1; Action <string> EndGame = delegate { gameovermenu.Visible = true; GameTimer.Stop(); }; #region DoAmmoDamage Func <AmmoInfo, bool> DoAmmoDamage = delegate(AmmoInfo a) { bool hit = false; #region did we hit ufo? if (UFO.Visible) { if (UFO.Bounds.Contains(a.Location)) { board.Score += UFO.Info.Points; UFO.Visible = false; hit = true; } } #endregion #region did we hit player if (Player.Bounds.Contains(a.Location)) { board.Lives--; hit = true; if (board.Lives < 1) { EndGame("Ship destroied"); } } #endregion foreach (Concrete v in KnownConcrete.ToArray()) { if (v.Visible) { if (v.Bounds.Contains(a.Location)) { v.Health -= HitDamage; if (v.Health > 0) { hit = true; } else { v.Visible = false; } } } } foreach (EnemyUnit v in KnownEnemies.ToArray()) { if (v.Visible) { if (v.Bounds.Contains(a.Location)) { v.Visible = false; hit = true; new SpaceInvadersTemplate.HTML.Audio.FromAssets.invaderexplode().play(); board.Score += v.Info.Points; } } } return(hit); }; #endregion var MyRandom = new System.Random(); var mothershiploop = new SpaceInvadersTemplate.HTML.Audio.FromAssets.mothershiploopx { loop = true }; var duh = new IHTMLAudio[] { new SpaceInvadersTemplate.HTML.Audio.FromAssets.duh0(), new SpaceInvadersTemplate.HTML.Audio.FromAssets.duh1(), new SpaceInvadersTemplate.HTML.Audio.FromAssets.duh2(), new SpaceInvadersTemplate.HTML.Audio.FromAssets.duh3(), }; var duh_cycle = duh.ToCyclicAction(a => a.play()); #region EnemyAction Action EnemyAction = delegate { #region create ufo if (!UFO.Visible) { if (MyRandom.NextDouble() < 0.1) { Console.WriteLine("UFO!"); mothershiploop.play(); if (MyRandom.NextDouble() > 0.5) { UFO_Direction = 1; UFO.MoveTo(0, EnemyTop - UFO.Control.height * 2); } else { UFO_Direction = -1; UFO.MoveTo(478, EnemyTop - UFO.Control.height * 2); } UFO.Visible = true; } } #endregion var ev = Enumerable.Where(KnownEnemies.ToArray(), i => i.Visible); if (!Enemy_Ammo.Visible) { var ei = (int)System.Math.Round(MyRandom.NextDouble() * Enumerable.Count(ev)); EnemyUnit et = Enumerable.ElementAt(ev, ei); if (et == null) { System.Console.WriteLine("element at " + ei + " not found"); } else { int ey = Enumerable.Max( from i in ev where i.X == et.X select i.Y // Enumerable.Select(Enumerable.Where(ev, i => i.X == et.X), i => i.Y) ); Enemy_Ammo.MoveTo(et.X, ey + 20); Enemy_Ammo.Visible = true; } } #region MoveAll Action <Point> MoveAll = delegate(Point to) { var ConcreteReached = false; foreach (EnemyUnit v in ev) { var vy = v.Y + to.Y; if (vy > ConcreteTop) { ConcreteReached = true; } v.MoveTo(v.X + to.X, vy); } if (ConcreteReached) { EndGame("The walls have been breached."); } }; #endregion Action MoveAllDown = delegate { MoveAll(new Point(0, 8)); }; duh_cycle(); #region move the gang if (GangDirection > 0) { int ex_max = Enumerable.Max(Enumerable.Select(ev, i => i.X)); // gang goes right if (ex_max >= Map_Rect.Right) { GangDirection = -1; MoveAllDown(); } else { MoveAll(new Point(4, 0)); } } else { int ex_min = Enumerable.Min(Enumerable.Select(ev, i => i.X)); // gang goes left if (ex_min <= Map_Rect.Left) { GangDirection = 1; MoveAllDown(); } else { MoveAll(new Point(-4, 0)); } } #endregion }; #endregion bool GamePaused = false; GameTimer.Tick += delegate { #region only blink while paused if (GamePaused) { if (GameTimer.Counter % 15 == 0) { Player.ToggleVisible(); } return; } #endregion Player.Show(); #region move ufo if (UFO.Visible) { if (UFO_Direction > 0) { UFO.MoveTo(UFO.X + 4, UFO.Y); if (UFO.X > 478 + UFO.Control.width) { UFO.Visible = false; mothershiploop.pause(); } } else { UFO.MoveTo(UFO.X - 4, UFO.Y); if (UFO.X < -UFO.Control.width) { UFO.Visible = false; mothershiploop.pause(); } } } #endregion #region do ammo stuff foreach (AmmoInfo v in KnownAmmo) { if (v.Visible) { var y = v.Y + v.Speed; if (Map_Rect.Contains(new Point(v.X, y))) { // did we hit? if (DoAmmoDamage(v)) { v.Visible = false; } else { v.MoveTo(v.X, y); } } else { v.Visible = false; } } } #endregion var AliveEnemies = Enumerable.Where(KnownEnemies.ToArray(), i => i.Visible); var AliveCount = Enumerable.Count(AliveEnemies); if (AliveCount == 0) { EndGame("Aliens destoried"); return; } if (GameTimer.Counter % (AliveCount / 2) == 0) { EnemyAction(); } }; #region ResetGame Action ResetGame = delegate { mmenu.Visible = false; Player_X = 220; board.Score = 0; board.Lives = 3; Player.Show(); foreach (Concrete v in KnownConcrete.ToArray()) { v.Health = 255; v.Visible = true; } foreach (EnemyUnit v in KnownEnemies.ToArray()) { v.ResetPosition(); v.Visible = true; } EnemyAction(); GameTimer.StartInterval(50); UpdatePlayer(0); }; #endregion Action EgoShoot = delegate { if (!Player_Ammo.Visible) { Player_Ammo.MoveTo(Player_X, Player_Y - 20); new SpaceInvadersTemplate.HTML.Audio.FromAssets.firemissile().play(); Player_Ammo.Visible = true; } }; overlay.ControlInBack.onclick += delegate { if (mmenu.Visible) { ResetGame(); } else { EgoShoot(); } }; double gamma = 0; //Native.window.ondeviceorientation += // eventData => // { // if (eventData.gamma < -50) // gamma = eventData.beta; // else // gamma = eventData.gamma; // }; new ScriptCoreLib.JavaScript.Runtime.Timer( t => { // gamma is the left-to-right tilt in degrees, where right is positive if (gamma < -15) { if (mmenu.Visible) { ResetGame(); } else { UpdatePlayer(-Player_X_step); } } if (gamma > 15) { if (mmenu.Visible) { ResetGame(); } else { UpdatePlayer(Player_X_step); } } } ).StartInterval(100); Native.Document.onkeydown += delegate(IEvent ev) { Console.WriteLine(new { ev.KeyCode }.ToString()); if (mmenu.Visible) { if (ev.IsReturn) { ResetGame(); } return; } else { if (ev.IsEscape) { GameTimer.Stop(); Player.Hide(); mmenu.Visible = true; foreach (AmmoInfo v in KnownAmmo) { v.Visible = false; } foreach (Concrete v in KnownConcrete.ToArray()) { v.Visible = false; } foreach (EnemyUnit v in KnownEnemies.ToArray()) { v.Visible = false; } UFO.Visible = false; gameovermenu.Visible = false; // the animated gifs would stop after escape key ev.preventDefault(); GamePaused = false; } } int key_p = 80; if (ev.KeyCode == key_p) { GamePaused = !GamePaused; } // player shouldn't really move while game is paused // its cheating:) if (GamePaused) { return; } int key_right = 39; int key_left = 37; if (ev.KeyCode == key_left) { UpdatePlayer(-Player_X_step); } else if (ev.KeyCode == key_right) { UpdatePlayer(Player_X_step); } else if (ev.IsSpaceOrEnterKey()) { // the animated gifs would stop after escape key ev.preventDefault(); EgoShoot(); } else { Console.WriteLine(new { UnknownKeyCode = ev.KeyCode }.ToString()); } }; msg_loading.Orphanize(); } , 50); }
//Revision: 3636 //Author: zproxy //Date: 22. aprill 2012. a. 11:16:53 //Message: //---- //Added : /examples/java/OutRun4KTemplate //Added : /examples/java/OutRun4KTemplate/OutRun4KTemplate // http://www.digitalinsane.com/archives/2007/01/21/space_invaders/ public SpaceInvaders() { ImageResources gfx = "http://server/"; var overlay = new Overlay(); overlay.BackgroundColor = Color.Black; overlay.MaximumOpacity = 1; overlay.ControlInBack.style.zIndex = 100000; overlay.ControlInFront.style.zIndex = 100001; var view = overlay.ControlInFront; view.style.textAlign = IStyle.TextAlignEnum.center; view.style.SetSize(480, 480); view.style.backgroundColor = Color.Green; view.style.color = Color.White; view.style.fontFamily = IStyle.FontFamilyEnum.Fixedsys; //Native.Document.body.appendChild( // new IHTMLElement(IHTMLElement.HTMLElementEnum.center, // view) // ); //Native.Document.body.style.backgroundColor = Color.Black; // Native.Document.body.style.overflow = IStyle.OverflowEnum.hidden; System.Func<IHTMLDiv> CreateCanvas = delegate { var c = new IHTMLDiv(); c.style.overflow = IStyle.OverflowEnum.hidden; c.style.SetLocation(1, 1, 478, 478); return c; }; view.style.position = IStyle.PositionEnum.relative; var canvas = CreateCanvas(); var menu = CreateCanvas(); canvas.style.backgroundColor = Color.Black; view.appendChild(canvas, menu); var msg_loading = new IHTMLDiv("loading..."); msg_loading.style.color = Color.Green; menu.appendChild(msg_loading); // at this point we want our images overlay.Visible = true; ScriptCoreLib.JavaScript.Runtime.Timer.DoAsync(overlay.UpdateLocation); // now wait while all images are loaded/complete ((fbool)(() => !gfx.IsComplete)).Trigger( delegate { // loading images is done now. // build the scoreboard var MyEnemyDirectory = new EnemyDirectory(gfx); var board = new ScoreBoard(gfx); board.Control.style.SetLocation(8, 8, 464, 64); canvas.appendChild(board.Control); board.Lives = 2; board.Score = 450; // now we can see lives and score. // ie does not issue keypress for control keys. // scriptcorelib should filter firefox events... // lets show main menu var mmenu = new MainMenu(MyEnemyDirectory, gfx); var gameovermenu = new GameOverMenu(); menu.appendChild(mmenu.Control, gameovermenu.Control); gameovermenu.Visible = false; gameovermenu.Control.style.SetLocation(0, 100, 468, 468 - 100); mmenu.Control.style.SetLocation(0, 64, 468, 468 - 64); mmenu.Visible = true; var Enemy_Ammo = new AmmoInfo { Color = Color.White, Speed = 8 }; var Player = (IHTMLImage)gfx.biggun.Clone(); var Player_Ammo = new AmmoInfo { Color = Color.Green, Speed = -8 }; var Map_Top = 64; var Map_Left = 20; var Map_Right = 450; var Map_Bottom = 470; var Map_Rect = new Rectangle(); Map_Rect.Top = Map_Top; Map_Rect.Left = Map_Left; Map_Rect.Right = Map_Right; Map_Rect.Bottom = Map_Bottom; var Player_Y = 460; var Player_X = 200; var Player_X_step = 8; Action<int> UpdatePlayer = delegate(int v) { Player_X += v; if (Player_X < Map_Left) Player_X = Map_Left; if (Player_X > Map_Right) Player_X = Map_Right; Player.SetCenteredLocation(Player_X, Player_Y); Player.style.position = IStyle.PositionEnum.absolute; }; Player.Hide(); canvas.appendChild(Player, Player_Ammo.Control, Enemy_Ammo.Control); AmmoInfo[] KnownAmmo = new[] { Player_Ammo, Enemy_Ammo }; var KnownConcrete = new List<Concrete>(); var ConcreteTop = 432; KnownConcrete.AddRange(Concrete.BuildAt(new Point(62 + 120 * 0, ConcreteTop))); KnownConcrete.AddRange(Concrete.BuildAt(new Point(62 + 120 * 1, ConcreteTop))); KnownConcrete.AddRange(Concrete.BuildAt(new Point(62 + 120 * 2, ConcreteTop))); KnownConcrete.AddRange(Concrete.BuildAt(new Point(62 + 120 * 3, ConcreteTop))); foreach (Concrete v in KnownConcrete.ToArray()) { canvas.appendChild(v.Control); } var UFO = new EnemyUnit(MyEnemyDirectory.UFO); var UFO_Direction = 1; UFO.Visible = false; canvas.appendChild(UFO.Control); var EnemyTop = 128; var EnemySpacing = 32; var EnemyCount = 9; var KnownEnemies = new List<EnemyUnit>(); KnownEnemies.AddRange(EnemyUnit.Build(MyEnemyDirectory.A, 20, EnemyTop + 0 * EnemySpacing, EnemyCount, EnemySpacing)); KnownEnemies.AddRange(EnemyUnit.Build(MyEnemyDirectory.B, 20, EnemyTop + 1 * EnemySpacing, EnemyCount, EnemySpacing)); KnownEnemies.AddRange(EnemyUnit.Build(MyEnemyDirectory.B, 20, EnemyTop + 2 * EnemySpacing, EnemyCount, EnemySpacing)); KnownEnemies.AddRange(EnemyUnit.Build(MyEnemyDirectory.C, 20, EnemyTop + 3 * EnemySpacing, EnemyCount, EnemySpacing)); KnownEnemies.AddRange(EnemyUnit.Build(MyEnemyDirectory.C, 20, EnemyTop + 4 * EnemySpacing, EnemyCount, EnemySpacing)); foreach (EnemyUnit v in KnownEnemies.ToArray()) { canvas.appendChild(v.Control); } var HitDamage = 40; var GameTimer = new ScriptCoreLib.JavaScript.Runtime.Timer(); int GangDirection = 1; Action<string> EndGame = delegate { gameovermenu.Visible = true; GameTimer.Stop(); }; #region DoAmmoDamage Func<AmmoInfo, bool> DoAmmoDamage = delegate(AmmoInfo a) { bool hit = false; #region did we hit ufo? if (UFO.Visible) { if (UFO.Bounds.Contains(a.Location)) { board.Score += UFO.Info.Points; UFO.Visible = false; hit = true; } } #endregion #region did we hit player if (Player.Bounds.Contains(a.Location)) { board.Lives--; hit = true; if (board.Lives < 1) { EndGame("Ship destroied"); } } #endregion foreach (Concrete v in KnownConcrete.ToArray()) { if (v.Visible) { if (v.Bounds.Contains(a.Location)) { v.Health -= HitDamage; if (v.Health > 0) { hit = true; } else { v.Visible = false; } } } } foreach (EnemyUnit v in KnownEnemies.ToArray()) { if (v.Visible) { if (v.Bounds.Contains(a.Location)) { v.Visible = false; hit = true; new SpaceInvadersTemplate.HTML.Audio.FromAssets.invaderexplode().play(); board.Score += v.Info.Points; } } } return hit; }; #endregion var MyRandom = new System.Random(); var mothershiploop = new SpaceInvadersTemplate.HTML.Audio.FromAssets.mothershiploopx { loop = true }; var duh = new IHTMLAudio[] { new SpaceInvadersTemplate.HTML.Audio.FromAssets.duh0(), new SpaceInvadersTemplate.HTML.Audio.FromAssets.duh1(), new SpaceInvadersTemplate.HTML.Audio.FromAssets.duh2(), new SpaceInvadersTemplate.HTML.Audio.FromAssets.duh3(), }; var duh_cycle = duh.ToCyclicAction(a => a.play()); #region EnemyAction Action EnemyAction = delegate { #region create ufo if (!UFO.Visible) { if (MyRandom.NextDouble() < 0.1) { Console.WriteLine("UFO!"); mothershiploop.play(); if (MyRandom.NextDouble() > 0.5) { UFO_Direction = 1; UFO.MoveTo(0, EnemyTop - UFO.Control.height * 2); } else { UFO_Direction = -1; UFO.MoveTo(478, EnemyTop - UFO.Control.height * 2); } UFO.Visible = true; } } #endregion var ev = Enumerable.Where(KnownEnemies.ToArray(), i => i.Visible); if (!Enemy_Ammo.Visible) { var ei = (int)System.Math.Round(MyRandom.NextDouble() * Enumerable.Count(ev)); EnemyUnit et = Enumerable.ElementAt(ev, ei); if (et == null) System.Console.WriteLine("element at " + ei + " not found"); else { int ey = Enumerable.Max( from i in ev where i.X == et.X select i.Y // Enumerable.Select(Enumerable.Where(ev, i => i.X == et.X), i => i.Y) ); Enemy_Ammo.MoveTo(et.X, ey + 20); Enemy_Ammo.Visible = true; } } #region MoveAll Action<Point> MoveAll = delegate(Point to) { var ConcreteReached = false; foreach (EnemyUnit v in ev) { var vy = v.Y + to.Y; if (vy > ConcreteTop) { ConcreteReached = true; } v.MoveTo(v.X + to.X, vy); } if (ConcreteReached) { EndGame("The walls have been breached."); } }; #endregion Action MoveAllDown = delegate { MoveAll(new Point(0, 8)); }; duh_cycle(); #region move the gang if (GangDirection > 0) { int ex_max = Enumerable.Max(Enumerable.Select(ev, i => i.X)); // gang goes right if (ex_max >= Map_Rect.Right) { GangDirection = -1; MoveAllDown(); } else { MoveAll(new Point(4, 0)); } } else { int ex_min = Enumerable.Min(Enumerable.Select(ev, i => i.X)); // gang goes left if (ex_min <= Map_Rect.Left) { GangDirection = 1; MoveAllDown(); } else { MoveAll(new Point(-4, 0)); } } #endregion }; #endregion bool GamePaused = false; GameTimer.Tick += delegate { #region only blink while paused if (GamePaused) { if (GameTimer.Counter % 15 == 0) { Player.ToggleVisible(); } return; } #endregion Player.Show(); #region move ufo if (UFO.Visible) { if (UFO_Direction > 0) { UFO.MoveTo(UFO.X + 4, UFO.Y); if (UFO.X > 478 + UFO.Control.width) { UFO.Visible = false; mothershiploop.pause(); } } else { UFO.MoveTo(UFO.X - 4, UFO.Y); if (UFO.X < -UFO.Control.width) { UFO.Visible = false; mothershiploop.pause(); } } } #endregion #region do ammo stuff foreach (AmmoInfo v in KnownAmmo) { if (v.Visible) { var y = v.Y + v.Speed; if (Map_Rect.Contains(new Point(v.X, y))) { // did we hit? if (DoAmmoDamage(v)) { v.Visible = false; } else { v.MoveTo(v.X, y); } } else { v.Visible = false; } } } #endregion var AliveEnemies = Enumerable.Where(KnownEnemies.ToArray(), i => i.Visible); var AliveCount = Enumerable.Count(AliveEnemies); if (AliveCount == 0) { EndGame("Aliens destoried"); return; } if (GameTimer.Counter % (AliveCount / 2) == 0) { EnemyAction(); } }; #region ResetGame Action ResetGame = delegate { mmenu.Visible = false; Player_X = 220; board.Score = 0; board.Lives = 3; Player.Show(); foreach (Concrete v in KnownConcrete.ToArray()) { v.Health = 255; v.Visible = true; } foreach (EnemyUnit v in KnownEnemies.ToArray()) { v.ResetPosition(); v.Visible = true; } EnemyAction(); GameTimer.StartInterval(50); UpdatePlayer(0); }; #endregion Action EgoShoot = delegate { if (!Player_Ammo.Visible) { Player_Ammo.MoveTo(Player_X, Player_Y - 20); new SpaceInvadersTemplate.HTML.Audio.FromAssets.firemissile().play(); Player_Ammo.Visible = true; } }; overlay.ControlInBack.onclick += delegate { if (mmenu.Visible) ResetGame(); else EgoShoot(); }; double gamma = 0; //Native.window.ondeviceorientation += // eventData => // { // if (eventData.gamma < -50) // gamma = eventData.beta; // else // gamma = eventData.gamma; // }; new ScriptCoreLib.JavaScript.Runtime.Timer( t => { // gamma is the left-to-right tilt in degrees, where right is positive if (gamma < -15) { if (mmenu.Visible) ResetGame(); else UpdatePlayer(-Player_X_step); } if (gamma > 15) { if (mmenu.Visible) ResetGame(); else UpdatePlayer(Player_X_step); } } ).StartInterval(100); Native.Document.onkeydown += delegate(IEvent ev) { Console.WriteLine(new { ev.KeyCode }.ToString()); if (mmenu.Visible) { if (ev.IsReturn) { ResetGame(); } return; } else { if (ev.IsEscape) { GameTimer.Stop(); Player.Hide(); mmenu.Visible = true; foreach (AmmoInfo v in KnownAmmo) { v.Visible = false; } foreach (Concrete v in KnownConcrete.ToArray()) { v.Visible = false; } foreach (EnemyUnit v in KnownEnemies.ToArray()) { v.Visible = false; } UFO.Visible = false; gameovermenu.Visible = false; // the animated gifs would stop after escape key ev.preventDefault(); GamePaused = false; } } int key_p = 80; if (ev.KeyCode == key_p) { GamePaused = !GamePaused; } // player shouldn't really move while game is paused // its cheating:) if (GamePaused) return; int key_right = 39; int key_left = 37; if (ev.KeyCode == key_left) { UpdatePlayer(-Player_X_step); } else if (ev.KeyCode == key_right) { UpdatePlayer(Player_X_step); } else if (ev.IsSpaceOrEnterKey()) { // the animated gifs would stop after escape key ev.preventDefault(); EgoShoot(); } else { Console.WriteLine(new { UnknownKeyCode = ev.KeyCode }.ToString()); } }; msg_loading.Orphanize(); } , 50); }
// problems with roslyn build? public static void InitializeSidebarBehaviour( IApp page, Form f, bool HandleClosed = true, bool HandleDragToLeft = true ) { var tt = f.GetHTMLTarget(); //page.SidebarInfo.style.tr page.SidebarInfo.style.With( (dynamic s) => s.webkitTransition = "all 0.3s linear" ); var IsMinimized = false; #region Minimize Action Minimize = delegate { if (IsMinimized) return; var t = tt; dynamic style = t.style; var old = new { f.Left, f.Top, f.Height }; // http://developer.apple.com/library/safari/documentation/AudioVideo/Reference/WebKitTransitionEventClassReference/WebKitTransitionEvent/WebKitTransitionEvent.html var cleartransition = new ScriptCoreLib.JavaScript.Runtime.Timer( delegate { style.webkitTransition = ""; style = null; IsMinimized = false; f.MoveTo( old.Left.Max(page.Sidebar.clientWidth + 12) , old.Top); // prevent drawing artifacts tt.style.transform = ""; } ); Action DoRestore = null; DoRestore = delegate { if (t == null) return; DoRestore = null; Console.WriteLine("DoRestore"); style.webkitTransition = "all 0.3s linear"; t.style.transform = "scale(1)"; t.style.left = old.Left.Max(page.Sidebar.clientWidth + 12) + "px"; t.style.top = old.Top + "px"; //t.style.Opacity = 1; f.Opacity = 1; t = null; page.SidebarInfo.style.marginTop = (0) + "px"; }; var clicktorestore = new ScriptCoreLib.JavaScript.Runtime.Timer( delegate { style.webkitTransition = ""; page.SidebarOverlay.onclick += delegate { if (DoRestore != null) DoRestore(); }; f.Resize += delegate { if (DoRestore != null) DoRestore(); }; } ); t.addEventListener("webkitTransitionEnd", ee => { if (t == null) { // script: error JSC1000: No implementation found for this native method, please implement [static Microsoft.CSharp.RuntimeBinder.Binder.UnaryOperation(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags, System.Linq.Expressions.ExpressionType, System.Type, System.Collections.Generic.IEnumerable`1[[Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo, Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]])] if ((object)style != null) cleartransition.StartTimeout(300); return; } Console.WriteLine("webkitTransitionEnd"); clicktorestore.Stop(); clicktorestore.StartTimeout(300); } ); // http://www.the-art-of-web.com/css/css-animation/ t.style.transformOrigin = "0% 0%"; var scale = (double)(page.Sidebar.clientWidth - 10) / (double)f.Width; page.SidebarInfo.style.marginTop = (f.Height * scale + 20) + "px"; style.webkitTransition = "all 0.2s linear"; t.style.transform = "scale(" + scale + ")"; t.style.left = "0.2em"; t.style.top = "0.2em"; //t.style.Opacity = 0.5; f.Opacity = 0.5; IsMinimized = true; }; #endregion if (HandleDragToLeft) new ScriptCoreLib.JavaScript.Runtime.Timer( delegate { // popup mode? if (f.GetHTMLTarget().parentNode == null) return; if (IsMinimized) { return; } if (tt.offsetLeft < page.Sidebar.clientWidth) { page.SidebarOverlay.style.Opacity = 0.2; var scale = (double)(page.Sidebar.clientWidth - 10) / ((double)tt.clientHeight); Console.WriteLine(new { scale }); page.SidebarInfo.style.marginTop = (f.Height * scale + 20) + "px"; if (f.Capture) return; Console.WriteLine(new { f.WindowState }); if (f.WindowState != FormWindowState.Normal) return; Minimize(); } else { page.SidebarInfo.style.marginTop = (0) + "px"; } page.SidebarOverlay.style.Opacity = 0; } ).StartInterval(100); if (HandleClosed) { f.FormClosing += (s, e) => { if (e.CloseReason == System.Windows.Forms.CloseReason.UserClosing) { e.Cancel = true; Minimize(); } }; } dynamic xstyle = page.SidebarOverlay.style; xstyle.webkitTransition = "all 0.3s linear"; page.SidebarOverlay.onmouseout += delegate { page.SidebarOverlay.style.Opacity = 0; }; page.SidebarOverlay.onmouseover += delegate { page.SidebarOverlay.style.Opacity = 0.3; }; page.SidebarOverlay.onclick += delegate { if (IsMinimized) return; Minimize(); }; #region enforce overflow:hidden Native.window.onscroll += e => { e.preventDefault(); e.stopPropagation(); //Console.WriteLine("Window onscroll "); Native.Document.body.scrollTop = 0; Native.Document.body.scrollLeft = 0; }; #endregion }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { // 1e40:01:01 RewriteToAssembly error: System.MissingMethodException: Method not found: 'Void ScriptCoreLib.JavaScript.DOM.IWindow.add_onframe(System.Action`1<Int32>)'. #if chrome_works_again #region AtFormCreated FormStyler.AtFormCreated = s => { s.Context.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; var x = new ChromeTCPServerWithFrameNone.HTML.Pages.AppWindowDrag().AttachTo(s.Context.GetHTMLTarget()); }; #endregion // chrome 31 wont load view-source // chrome 33 shows black window. nice. #region ChromeTCPServer dynamic self = Native.self; dynamic self_chrome = self.chrome; object self_chrome_socket = self_chrome.socket; if (self_chrome_socket != null) { chrome.Notification.DefaultTitle = "Droplet"; //chrome.Notification.DefaultIconUrl = new HTML.Images.FromAssets.Preview().src; ChromeTCPServer.TheServerWithStyledForm.Invoke( AppSource.Text, AtFormCreated: FormStyler.AtFormCreated ); return; } #endregion #endif #region clouds new WebGLClouds.HTML.Pages.Default().With( layout => { layout.body.AttachTo(page.clouds); new WebGLClouds.Application(layout); } ); #endregion page.header.style.backgroundColor = ""; page.header.css.style.transition = "background-color 200ms linear"; page.header.css.style.backgroundColor = "rgba(255, 255, 0, 0)"; //page.header.css.style.backgroundColor = "rgba(255, 255, 0, 0.2)"; page.header.css.hover.style.backgroundColor = "rgba(255, 255, 0, 1.0)"; Native.window.onframe += delegate { if (Native.document.body.scrollTop == 0) { page.header.css.style.backgroundColor = "rgba(255, 255, 0, 0)"; } else { page.header.css.style.backgroundColor = "rgba(0, 0, 0, 0.3)"; } }; var oo = new List <THREE.Object3D>(); var window = Native.window; var camera = new THREE.PerspectiveCamera( 45, page.header.clientWidth / (double)page.header.clientHeight, 1, 2000 ); camera.position.z = 400; // scene var scene = new THREE.Scene(); var ambient = new THREE.AmbientLight(0x101030); scene.add(ambient); var directionalLight = new THREE.DirectionalLight(0xffeedd); directionalLight.position.set(0, 0, 1); scene.add(directionalLight); var renderer = new THREE.WebGLRenderer(); //renderer.domElement.AttachToDocument(); renderer.domElement.AttachTo(page.header); renderer.setSize(page.header.clientWidth, page.header.clientHeight); //renderer.setSize(window.Width, window.Height); //renderer.domElement.style.SetLocation(0, 0); var mouseX = 0; var mouseY = 0; var st = new Stopwatch(); st.Start(); Native.window.onframe += delegate { oo.WithEach( x => x.rotation.y = st.ElapsedMilliseconds * 0.001 ); camera.position.x += (mouseX - camera.position.x) * .05; camera.position.y += (-mouseY - camera.position.y) * .05; camera.lookAt(scene.position); renderer.render(scene, camera); }; Native.window.onresize += delegate { camera.aspect = page.header.clientWidth / (double)page.header.clientHeight; camera.updateProjectionMatrix(); //renderer.setSize(window.Width, window.Height); renderer.setSize(page.header.clientWidth, page.header.clientHeight); }; var data = Book1.GetDataSet(); #region bind Func <string, IHTMLElement, DataGridView> bind = (DataMember, c) => { var g = new DataGridView { BackgroundColor = Color.Transparent, // does this work? DefaultCellStyle = new DataGridViewCellStyle { SelectionBackColor = Color.Black, SelectionForeColor = Color.Yellow, //BackColor = Color.Transparent //BackColor = Color.FromArgb(0x05, 0, 0, 0) BackColor = Color.FromArgb(0x3f, 255, 255, 255) }, ColumnHeadersDefaultCellStyle = new DataGridViewCellStyle { BackColor = Color.FromArgb(0x8f, 255, 255, 255) }, SelectionMode = DataGridViewSelectionMode.FullRowSelect, AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill, // do we have a test for this? AllowUserToAddRows = false, //AllowUserToDeleteRows = false, RowHeadersVisible = false, // cannot hide column headers yet // script: error JSC1000: No implementation found for this native method, please implement [System.Windows.Forms.DataGridView.set_ColumnHeadersVisible(System.Boolean)] //ColumnHeadersVisible = false, DataSource = data, DataMember = DataMember, }; // this should be the one that maximizes itself onto the parent which is supposed to be absolute in size //g.GetHTMLTarget().With( // div => // { // //div.style.reset(); // // no scrollbars, thanks // div.style.overflow = IStyle.OverflowEnum.hidden; // (div.style as dynamic).zIndex = ""; // div.style.position = IStyle.PositionEnum.relative; // div.style.left = ""; // div.style.top = ""; // div.style.right = ""; // } //); c.style.position = IStyle.PositionEnum.relative; c.style.height = "20em"; c.Clear(); g.AttachControlTo(c); return(g); }; #endregion bind("Assets", page.assets); bind("Transactions", page.transactions).ReadOnly = true; // script: error JSC1000: No implementation found for this native method, please implement [System.Data.DataTableCollection.get_Item(System.String)] var data_Assets = data.Tables["Assets"]; var data_Transactions = data.Tables["Transactions"]; #region data_Assets_NewRow Action <DataRow> data_Assets_NewRow = SourceRow => { var r = new Random(); new sack_of_gold2().Source.Task.ContinueWithResult( o => { o.position.y = -80; scene.add(o); oo.Add(o); o.position.x = r.Next(-250, 250); o.position.z = r.Next(-400, 200); (o as dynamic).scale = new THREE.Vector3(0.5, 0.5, 0.5); data_Assets.RowDeleting += (sender, e) => { if (SourceRow != e.Row) { return; } scene.remove(o); oo.Remove(o); data_Transactions.Rows.Add( "now", "item removed -" + SourceRow["Net worth"] ); }; } ); }; #endregion data_Assets.Rows.AsEnumerable().WithEach(data_Assets_NewRow); // "X:\jsc.svn\examples\javascript\DropFileIntoSQLite\DropFileIntoSQLite.sln" // X:\jsc.svn\examples\javascript\DragDataTableIntoCSVFile\DragDataTableIntoCSVFile\Application.cs #region ondragstart page.header.ondragstart += e => { data_Assets.Rows.AsEnumerable().FirstOrDefault().With( SourceRow => { // x:\jsc.svn\examples\javascript\dropfileintosqlite\dropfileintosqlite\application.cs data_Assets.Rows.Remove(SourceRow); //data_Assets.Rows.RemoveAt(0); var clipboard = new DataTable(); clipboard.Columns.AddRange( Enumerable.ToArray( from x in data_Assets.Columns.AsEnumerable() select new DataColumn { ColumnName = x.ColumnName } ) ); clipboard.Rows.Add( Enumerable.ToArray( from x in data_Assets.Columns.AsEnumerable() select SourceRow[x] ) ); e.dataTransfer.effectAllowed = "copy"; var clipboard_string = StringConversionsForDataTable.ConvertToString(clipboard); e.dataTransfer.setData(typeof(DataTable).Name, clipboard_string); } ); }; #endregion // X:\jsc.svn\market\javascript\Abstractatech.JavaScript.FileStorage\Abstractatech.JavaScript.FileStorage\Application.cs var dz = new DropZone(); var TimerHide = new ScriptCoreLib.JavaScript.Runtime.Timer( delegate { dz.body.Orphanize(); } ); #region ondragover Action <DragEvent> ondragover = evt => { evt.stopPropagation(); evt.preventDefault(); if (evt.dataTransfer.types.Contains(typeof(DataTable).Name.ToLower())) { evt.dataTransfer.dropEffect = "copy"; // Explicitly show this is a copy. dz.body.AttachTo(Native.document.documentElement); dz.bglayer.style.transition = "background-color 500ms linear"; dz.bglayer.style.backgroundColor = "rgba(0,0,0, 0.7)"; TimerHide.Stop(); } }; Native.Document.body.ondragover += ondragover; dz.Container.ondragover += ondragover; #endregion dz.Container.ondragleave += evt => { //Console.WriteLine("ondragleave"); //Console.WriteLine(" dz.Container.ondragleave"); TimerHide.StartTimeout(90); evt.stopPropagation(); evt.preventDefault(); }; Native.window.onblur += delegate { data_Transactions.Rows.Add( //"now", "item added +" + SourceRow["Net worth"] "now", "blur" ); }; Native.window.onfocus += delegate { data_Transactions.Rows.Add( //"now", "item added +" + SourceRow["Net worth"] "now", "focus" ); }; data_Assets_NewRow += SourceRow => { data_Transactions.Rows.Add( //"now", "item added +" + SourceRow["Net worth"] "now", "item added" ); }; data_Assets.TableNewRow += (sender, e) => { data_Assets_NewRow(e.Row); }; #region ondrop dz.Container.ondrop += evt => { //Console.WriteLine("ondrop"); TimerHide.StartTimeout(90); evt.stopPropagation(); evt.preventDefault(); if (evt.dataTransfer.items != null) { // X:\jsc.svn\examples\javascript\DragDataTableIntoCSVFile\DragDataTableIntoCSVFile\Application.cs evt.dataTransfer.items.AsEnumerable().Where( x => x.type.ToLower() == // let jsc type system sort it out? // how much reflection does jsc give us nowadays? typeof(DataTable).Name.ToLower() ).WithEach( async xx => { // http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html#dfnReturnLink-0 var DataTable_xml = await xx.getAsString(); var DataTable = StringConversionsForDataTable.ConvertFromString(DataTable_xml); DataTable.Rows.AsEnumerable().WithEach( SourceRow => { data_Assets.Rows.Add( Enumerable.ToArray( from x in data_Assets.Columns.AsEnumerable() select SourceRow[x] ) ); } ); } ); } }; #endregion }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { // 1e40:01:01 RewriteToAssembly error: System.MissingMethodException: Method not found: 'Void ScriptCoreLib.JavaScript.DOM.IWindow.add_onframe(System.Action`1<Int32>)'. #if chrome_works_again #region AtFormCreated FormStyler.AtFormCreated = s => { s.Context.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; var x = new ChromeTCPServerWithFrameNone.HTML.Pages.AppWindowDrag().AttachTo(s.Context.GetHTMLTarget()); }; #endregion // chrome 31 wont load view-source // chrome 33 shows black window. nice. #region ChromeTCPServer dynamic self = Native.self; dynamic self_chrome = self.chrome; object self_chrome_socket = self_chrome.socket; if (self_chrome_socket != null) { chrome.Notification.DefaultTitle = "Droplet"; //chrome.Notification.DefaultIconUrl = new HTML.Images.FromAssets.Preview().src; ChromeTCPServer.TheServerWithStyledForm.Invoke( AppSource.Text, AtFormCreated: FormStyler.AtFormCreated ); return; } #endregion #endif #region clouds new WebGLClouds.HTML.Pages.Default().With( layout => { layout.body.AttachTo(page.clouds); new WebGLClouds.Application(layout); } ); #endregion page.header.style.backgroundColor = ""; page.header.css.style.transition = "background-color 200ms linear"; page.header.css.style.backgroundColor = "rgba(255, 255, 0, 0)"; //page.header.css.style.backgroundColor = "rgba(255, 255, 0, 0.2)"; page.header.css.hover.style.backgroundColor = "rgba(255, 255, 0, 1.0)"; Native.window.onframe += delegate { if (Native.document.body.scrollTop == 0) page.header.css.style.backgroundColor = "rgba(255, 255, 0, 0)"; else page.header.css.style.backgroundColor = "rgba(0, 0, 0, 0.3)"; }; var oo = new List<THREE.Object3D>(); var window = Native.window; var camera = new THREE.PerspectiveCamera( 45, page.header.clientWidth / (double)page.header.clientHeight, 1, 2000 ); camera.position.z = 400; // scene var scene = new THREE.Scene(); var ambient = new THREE.AmbientLight(0x101030); scene.add(ambient); var directionalLight = new THREE.DirectionalLight(0xffeedd); directionalLight.position.set(0, 0, 1); scene.add(directionalLight); var renderer = new THREE.WebGLRenderer(); //renderer.domElement.AttachToDocument(); renderer.domElement.AttachTo(page.header); renderer.setSize(page.header.clientWidth, page.header.clientHeight); //renderer.setSize(window.Width, window.Height); //renderer.domElement.style.SetLocation(0, 0); var mouseX = 0; var mouseY = 0; var st = new Stopwatch(); st.Start(); Native.window.onframe += delegate { oo.WithEach( x => x.rotation.y = st.ElapsedMilliseconds * 0.001 ); camera.position.x += (mouseX - camera.position.x) * .05; camera.position.y += (-mouseY - camera.position.y) * .05; camera.lookAt(scene.position); renderer.render(scene, camera); }; Native.window.onresize += delegate { camera.aspect = page.header.clientWidth / (double)page.header.clientHeight; camera.updateProjectionMatrix(); //renderer.setSize(window.Width, window.Height); renderer.setSize(page.header.clientWidth, page.header.clientHeight); }; var data = Book1.GetDataSet(); #region bind Func<string, IHTMLElement, DataGridView> bind = (DataMember, c) => { var g = new DataGridView { BackgroundColor = Color.Transparent, // does this work? DefaultCellStyle = new DataGridViewCellStyle { SelectionBackColor = Color.Black, SelectionForeColor = Color.Yellow, //BackColor = Color.Transparent //BackColor = Color.FromArgb(0x05, 0, 0, 0) BackColor = Color.FromArgb(0x3f, 255, 255, 255) }, ColumnHeadersDefaultCellStyle = new DataGridViewCellStyle { BackColor = Color.FromArgb(0x8f, 255, 255, 255) }, SelectionMode = DataGridViewSelectionMode.FullRowSelect, AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill, // do we have a test for this? AllowUserToAddRows = false, //AllowUserToDeleteRows = false, RowHeadersVisible = false, // cannot hide column headers yet // script: error JSC1000: No implementation found for this native method, please implement [System.Windows.Forms.DataGridView.set_ColumnHeadersVisible(System.Boolean)] //ColumnHeadersVisible = false, DataSource = data, DataMember = DataMember, }; // this should be the one that maximizes itself onto the parent which is supposed to be absolute in size //g.GetHTMLTarget().With( // div => // { // //div.style.reset(); // // no scrollbars, thanks // div.style.overflow = IStyle.OverflowEnum.hidden; // (div.style as dynamic).zIndex = ""; // div.style.position = IStyle.PositionEnum.relative; // div.style.left = ""; // div.style.top = ""; // div.style.right = ""; // } //); c.style.position = IStyle.PositionEnum.relative; c.style.height = "20em"; c.Clear(); g.AttachControlTo(c); return g; }; #endregion bind("Assets", page.assets); bind("Transactions", page.transactions).ReadOnly = true; // script: error JSC1000: No implementation found for this native method, please implement [System.Data.DataTableCollection.get_Item(System.String)] var data_Assets = data.Tables["Assets"]; var data_Transactions = data.Tables["Transactions"]; #region data_Assets_NewRow Action<DataRow> data_Assets_NewRow = SourceRow => { var r = new Random(); new sack_of_gold2().Source.Task.ContinueWithResult( o => { o.position.y = -80; scene.add(o); oo.Add(o); o.position.x = r.Next(-250, 250); o.position.z = r.Next(-400, 200); (o as dynamic).scale = new THREE.Vector3(0.5, 0.5, 0.5); data_Assets.RowDeleting += (sender, e) => { if (SourceRow != e.Row) return; scene.remove(o); oo.Remove(o); data_Transactions.Rows.Add( "now", "item removed -" + SourceRow["Net worth"] ); }; } ); }; #endregion data_Assets.Rows.AsEnumerable().WithEach(data_Assets_NewRow); // "X:\jsc.svn\examples\javascript\DropFileIntoSQLite\DropFileIntoSQLite.sln" // X:\jsc.svn\examples\javascript\DragDataTableIntoCSVFile\DragDataTableIntoCSVFile\Application.cs #region ondragstart page.header.ondragstart += e => { data_Assets.Rows.AsEnumerable().FirstOrDefault().With( SourceRow => { // x:\jsc.svn\examples\javascript\dropfileintosqlite\dropfileintosqlite\application.cs data_Assets.Rows.Remove(SourceRow); //data_Assets.Rows.RemoveAt(0); var clipboard = new DataTable(); clipboard.Columns.AddRange( Enumerable.ToArray( from x in data_Assets.Columns.AsEnumerable() select new DataColumn { ColumnName = x.ColumnName } ) ); clipboard.Rows.Add( Enumerable.ToArray( from x in data_Assets.Columns.AsEnumerable() select SourceRow[x] ) ); e.dataTransfer.effectAllowed = "copy"; var clipboard_string = StringConversionsForDataTable.ConvertToString(clipboard); e.dataTransfer.setData(typeof(DataTable).Name, clipboard_string); } ); }; #endregion // X:\jsc.svn\market\javascript\Abstractatech.JavaScript.FileStorage\Abstractatech.JavaScript.FileStorage\Application.cs var dz = new DropZone(); var TimerHide = new ScriptCoreLib.JavaScript.Runtime.Timer( delegate { dz.body.Orphanize(); } ); #region ondragover Action<DragEvent> ondragover = evt => { evt.stopPropagation(); evt.preventDefault(); if (evt.dataTransfer.types.Contains(typeof(DataTable).Name.ToLower())) { evt.dataTransfer.dropEffect = "copy"; // Explicitly show this is a copy. dz.body.AttachTo(Native.document.documentElement); dz.bglayer.style.transition = "background-color 500ms linear"; dz.bglayer.style.backgroundColor = "rgba(0,0,0, 0.7)"; TimerHide.Stop(); } }; Native.Document.body.ondragover += ondragover; dz.Container.ondragover += ondragover; #endregion dz.Container.ondragleave += evt => { //Console.WriteLine("ondragleave"); //Console.WriteLine(" dz.Container.ondragleave"); TimerHide.StartTimeout(90); evt.stopPropagation(); evt.preventDefault(); }; Native.window.onblur += delegate { data_Transactions.Rows.Add( //"now", "item added +" + SourceRow["Net worth"] "now", "blur" ); }; Native.window.onfocus += delegate { data_Transactions.Rows.Add( //"now", "item added +" + SourceRow["Net worth"] "now", "focus" ); }; data_Assets_NewRow += SourceRow => { data_Transactions.Rows.Add( //"now", "item added +" + SourceRow["Net worth"] "now", "item added" ); }; data_Assets.TableNewRow += (sender, e) => { data_Assets_NewRow(e.Row); }; #region ondrop dz.Container.ondrop += evt => { //Console.WriteLine("ondrop"); TimerHide.StartTimeout(90); evt.stopPropagation(); evt.preventDefault(); if (evt.dataTransfer.items != null) { // X:\jsc.svn\examples\javascript\DragDataTableIntoCSVFile\DragDataTableIntoCSVFile\Application.cs evt.dataTransfer.items.AsEnumerable().Where( x => x.type.ToLower() == // let jsc type system sort it out? // how much reflection does jsc give us nowadays? typeof(DataTable).Name.ToLower() ).WithEach( async xx => { // http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html#dfnReturnLink-0 var DataTable_xml = await xx.getAsString(); var DataTable = StringConversionsForDataTable.ConvertFromString(DataTable_xml); DataTable.Rows.AsEnumerable().WithEach( SourceRow => { data_Assets.Rows.Add( Enumerable.ToArray( from x in data_Assets.Columns.AsEnumerable() select SourceRow[x] ) ); } ); } ); } }; #endregion }