// code creates class, we create element. public __Button() { InternalDisplayObject = new IHTMLElement(ElementName); var s = InternalDisplayObject.createShadowRoot(); var button = new IHTMLButton(); button.AttachTo(s); button.onclick += delegate { InternalRaiseClick(); }; this.InternalVirtualSetContent = value => { // what aboout? shadow dom ContentElement? // X:\jsc.svn\examples\javascript\Avalon\Test\TestShadowTextBox\TestShadowTextBox\ApplicationCanvas.cs button.innerText = "" + value; }; }
/// <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(IDefaultPage page) { Action</*dynamic*/ IHTMLInput, string, Func<IHTMLScript>> apply = (btn, text, js) => { btn.disabled = true; var Content = js(); Content.AttachToHead(); var DisableScript = new IHTMLButton { innerText = "disable " + text }; DisableScript.AttachTo(page.Content); DisableScript.onclick += delegate { DisableScript.Orphanize(); Content.Orphanize(); btn.disabled = false; }; }; page.Bar.onclick += delegate { apply(page.Bar, "Boo.js", () => new WithJavaScript.JavaScript.Bar().Content); }; page.Foo.onclick += delegate { apply(page.Foo, "Foo.js", () => new WithJavaScript.JavaScript.Foo().Content); }; @"Hello world".ToDocumentTitle(); // Send data from JavaScript to the server tier service.WebMethod2( @"A string from JavaScript.", value => value.ToDocumentTitle() ); }
private static void CreateRotor(double _angle, IHTMLElement _container) { var shadow = new IHTMLDiv(); shadow.style.position = IStyle.PositionEnum.absolute; shadow.style.left = "0px"; shadow.style.top = "0px"; shadow.style.width = "600px"; shadow.style.height = "400px"; shadow.style.backgroundColor = "black"; shadow.style.Opacity = 0.3; shadow.AttachTo(_container); var borders = new IHTMLDiv(); borders.style.position = IStyle.PositionEnum.absolute; borders.style.left = "0px"; borders.style.top = "0px"; //borders.style.width = "400px"; //borders.style.height = "300px"; borders.style.border = "4px solid black"; borders.style.Opacity = 0.1; borders.AttachTo(_container); var a = new IHTMLDiv(); // we can specify rotation origin within red area! a.style.backgroundColor = "red"; a.style.marginTop = "-200px"; a.style.marginLeft = "-300px"; a.style.paddingLeft = "300px"; a.style.paddingTop = "200px"; var c = new IHTMLDiv(); var z = new IHTMLButton("hi"); z.AttachTo(c); c.AttachTo(a); //a.style.width = "300px"; //a.style.height = "200px"; c.style.width = "300px"; c.style.height = "200px"; //c.style.position = IStyle.PositionEnum.relative; //c.style.SetLocation(0, 0); //c.style.clip = "rect(0px,60px,200px,0px)"; c.appendChild("hello world"); c.appendChild(new IHTMLButton("click me")); var xx = new IHTMLButton("xx"); xx.style.SetLocation(32, 32); c.appendChild(xx); c.appendChild("hello world"); new IHTMLDiv { innerText = @"As it seems we can use apng files but we cannot have absolute children. This means we will be able to support non container objects." }.AttachTo(c); c.style.SetBackground("assets/MatrixTransformExample/bg.png", true); var t = new IHTMLDiv(); c.appendChild(t); //a.style.width = "400px"; //a.style.height = "300px"; var angle = _angle; ApplyRotation2(a, angle, 1, 200, 0); new Timer( delegate { t.innerHTML = "" + angle; angle -= 2; ApplyRotation2(a, angle, 1, 200, 0); borders.style.SetSize(a.offsetWidth, a.offsetHeight); borders.style.SetLocation((a.clientWidth - a.offsetWidth) / 2, (a.clientHeight - a.offsetHeight) / 2); a.style.SetLocation((a.clientWidth - a.offsetWidth) / 2, (a.clientHeight - a.offsetHeight) / 2); } , 0, 250 ); a.AttachTo(_container); }
/// <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(IDefault page) { @"Hello world".ToDocumentTitle(); var output = new IHTMLTextArea().AttachToDocument(); var gexf = new XElement("gexf"); gexf.Add( new XElement("meta", new XElement("creator", "jsc"), new XElement("description", "NASDAQSNA") ) ); var graph = new XElement("graph", new XAttribute("mode", "static"), new XAttribute("defaultedgetype", "directed") ); gexf.Add(graph); var nodes = new XElement("nodes"); graph.Add(nodes); var edges = new XElement("edges"); graph.Add(edges); output.value = gexf.ToString(); output.onfocus += delegate { output.value = gexf.ToString(); }; output.onmouseover += delegate { output.value = gexf.ToString(); }; var NumericNodeIdLookup = new List<string>(); Func<string, int> GetNumericNodeId = k => { if (!NumericNodeIdLookup.Contains(k)) NumericNodeIdLookup.Add(k); return NumericNodeIdLookup.IndexOf(k); }; #region AddRelatedCompanies Func<IHTMLDiv, string, Action, Task> AddRelatedCompanies = null; AddRelatedCompanies = (c, qid, done) => { var nqid = GetNumericNodeId(qid).ToString(); var cc = new IHTMLDiv(); cc.style.marginLeft = "2em"; var service = new ApplicationWebService { qid = qid, yield = (id, CompanyName, Price) => { var nid = GetNumericNodeId(id).ToString(); if (nodes.Elements().Any(k => k.Attribute("id").Name.LocalName == nid)) { } else { nodes.Add( new XElement("node", new XAttribute("id", nid), new XAttribute("label", CompanyName) ) ); } var btn = new IHTMLButton { innerText = id + " " + CompanyName + " " + Price }; btn.style.display = IStyle.DisplayEnum.block; if (qid == id) { btn.disabled = true; if (c == null) { btn.AttachToDocument(); cc.AttachToDocument(); } else { //btn.AttachTo(c); cc.AttachTo(c); } if (done != null) done(); } else { edges.Add( new XElement("edge", new XAttribute("source", nqid), new XAttribute("target", nid) ) ); btn.AttachTo(cc); var ccc = new IHTMLDiv(); ccc.AttachTo(cc); int cx = 0; ccc.ToggleVisible(); btn.WhenClicked( async delegate { if (cx == 0) { btn.style.color = JSColor.Red; await AddRelatedCompanies(ccc, id, delegate { btn.style.color = JSColor.Blue; } ); } cx++; ccc.ToggleVisible(); } ); } } }; return service.GetRelatedCompanies(); }; #endregion AddRelatedCompanies(null, "NASDAQ:FB", null); AddRelatedCompanies(null, "NASDAQ:GOOG", null); }
public static void InitializeContent() { #region tutorial step 2 #region arena var map = new Point(2000, 2000); var arena = new ArenaControl(); arena.Layers.Canvas.style.backgroundColor = Color.FromGray(0xc0); arena.SetLocation( Rectangle.Of(0, 0, Native.window.Width, Native.window.Height)); arena.SetCanvasSize(map); arena.Control.AttachToDocument(); arena.DrawTextToInfo(Title, new Point(8, 8), Color.Blue); Native.window.onresize += delegate { arena.SetLocation( Rectangle.Of(0, 0, Native.window.Width, Native.window.Height)); arena.SetCanvasPosition( arena.CurrentCanvasPosition ); }; #endregion #endregion var pending = default(Dude2); #region arsenal var arsenal = new Dictionary <string, DudeAnimationInfo> { { "Soldier", new DudeAnimationInfo { Frames_Stand = Frames.WolfSoldier, Frames_Walk = Frames.WolfSoldier_Walk } }, { "Imp", new DudeAnimationInfo { Frames_Stand = Frames.DoomImp, Frames_Walk = Frames.DoomImp_Walk } } }; #endregion #region tutorial step 3 Func <DudeAnimationInfo, Point, Dude2> CreateActor = (_frames, _coords) => { var actor = new Dude2(); actor.Frames = _frames.Frames_Stand; actor.AnimationInfo.Frames_Stand = _frames.Frames_Stand; actor.AnimationInfo.Frames_Walk = _frames.Frames_Walk; actor.Zoom.DynamicZoomFunc = a => 1; actor.SetSize(48, 72); actor.TeleportTo(_coords.X, _coords.Y); actor.Zoom.StaticZoom = DefaultActiorZoom; actor.Direction = Math.PI * 0.5; actor.Control.AttachTo(arena.Layers.Canvas); //actor.HasShadow = _frames.Frames_Stand.Length > 1; if (_frames.Frames_Stand.Length == 1) { actor.Shadow.style.Opacity = 0.4; } actor.AnimationInfo.WalkAnimationInterval = 1000 / 30; return(actor); }; var actors = new List <Dude2> { }; var selection = from i in actors where i.IsSelected select i; arena.ApplySelection += (rect, ev) => { if (pending != null) { return; } foreach (var v in actors) { v.IsSelected = rect.Contains(v.CurrentLocation.ToInt32()); } }; var Argh = new Argh(); var Affirmative = new Affirmative(); var ghoullaugh = new ghoullaugh(); var sheep = new sheep(); var pig = new pig(); var click = new click().AttachToDocument(); arena.SelectionClick += (p, ev) => { if (pending != null) { return; } foreach (var v in selection) { if (v.AnimationInfo.Frames_Stand[0].Source == MyFrames.ManWithHorns.Frames_Stand[0].Source) { ghoullaugh.play(); ghoullaugh = new ghoullaugh(); } else if (v.AnimationInfo.Frames_Stand[0].Source == MyFrames.ThePig.Frames_Stand[0].Source) { pig.play(); pig = new pig(); } else if (v.AnimationInfo.Frames_Stand[0].Source == MyFrames.TheSheep.Frames_Stand[0].Source) { sheep.play(); sheep = new sheep(); } else if (v.AnimationInfo.Frames_Stand[0].Source == Frames.WolfSoldier[0].Source) { Affirmative.play(); Affirmative = new Affirmative(); } else { Argh.play(); Argh = new Argh(); } v.WalkTo(p.ToDouble()); // move in group formation p.X += 16; p.Y += 16; } }; #endregion #region tutorial step 4 #region CreateDialogAt var CreateDialogAt = new { //Dialog = default(IHTMLDiv), Content = default(IHTMLDiv), Width = default(string) } .ToFunc( (Point pos, string width) => { var f = new Form(); f.Show(); f.SizeTo(200, 200); // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20151115/audio //f.PopupInsteadOfClosing(); f.MoveTo(pos.X, pos.Y); //f.SizeTo( //var dialog = new IHTMLDiv(); //dialog.style.SetLocation(pos.X, pos.Y); //dialog.style.backgroundColor = Color.Gray; //dialog.style.padding = "1px"; //var caption = new IHTMLDiv().AttachTo(dialog); //caption.style.backgroundColor = Color.Blue; //caption.style.width = width; //caption.style.height = "0.5em"; //caption.style.cursor = IStyle.CursorEnum.move; //var drag = new DragHelper(caption); //drag.Position = pos; //drag.Enabled = true; //drag.DragMove += // delegate // { // dialog.style.SetLocation(drag.Position.X, drag.Position.Y); // }; var _content = new IHTMLDiv().AttachTo(f.GetHTMLTargetContainer()); _content.style.textAlign = IStyle.TextAlignEnum.center; _content.style.backgroundColor = Color.White; _content.style.padding = "1px"; //dialog.AttachToDocument(); return(new { //Dialog = dialog, Content = _content, Width = width }); } ); #endregion #region dialog var toolbar = CreateDialogAt(new Point(2, 2), "8em"); var combo = new IHTMLSelect(); var build = new IHTMLButton(); build.style.SetSize(72, 72); build.style.padding = "0px"; var avatar = new IHTMLImage().AttachTo(build); var remove = new IHTMLButton("Remove"); combo.AttachTo(toolbar.Content); new IHTMLBreak().AttachTo(toolbar.Content); build.AttachTo(toolbar.Content); new IHTMLBreak().AttachTo(toolbar.Content); remove.AttachTo(toolbar.Content); new IHTMLBreak().AttachTo(toolbar.Content); #endregion #region GetSelectedArsenal Func <DudeAnimationInfo> GetSelectedArsenal = () => { if (arsenal.ContainsKey(combo[combo.selectedIndex].value)) { return(arsenal[combo[combo.selectedIndex].value]); } return(null); }; #endregion Action Refresh = delegate { var i = GetSelectedArsenal(); if (i != null) { avatar.src = i.Images.Random().src; } }; combo.Add(arsenal.Keys.ToArray()); Refresh(); combo.onchange += delegate { Refresh(); click.play(); click = new click().AttachToDocument(); }; #region pending actor arena.MouseMove += p => { if (pending == null) { return; } pending.TeleportTo(p.X, p.Y); }; arena.Layers.User.oncontextmenu += e => { e.preventDefault(); if (pending != null) { pending.Control.Orphanize(); pending = null; arena.ShowSelectionRectangle = true; return; } actors.ForEach( k => k.IsSelected = false ); }; arena.SelectionClick += (p, ev) => { if (pending == null) { return; } pending.TeleportTo(p.X, p.Y); actors.Add(pending); pending.IsHot = false; var x = GetSelectedArsenal(); pending = CreateActor(x, new Point( Native.window.Width / 2, Native.window.Height / 2 ) ); pending.IsHot = true; click.play(); click = new click().AttachToDocument(); }; build.onclick += delegate { if (pending != null) { pending.Control.Orphanize(); pending = null; return; } var x = GetSelectedArsenal(); pending = CreateActor(x, new Point( Native.window.Width / 2, Native.window.Height / 2 ) ); pending.IsHot = true; arena.ShowSelectionRectangle = false; click.play(); click = new click().AttachToDocument(); }; #endregion remove.onclick += delegate { foreach (var v in selection.ToArray()) { v.Control.Orphanize(); actors.Remove(v); } click.play(); click = new click().AttachToDocument(); }; #endregion if (FilterToImpAndSoldier) { } else { #region step 6 { var n = "NPC"; arsenal.Add(n, MyFrames.NPC3); combo.Add(n); } #endregion { var n = "ManWithHorns"; arsenal.Add(n, MyFrames.ManWithHorns); combo.Add(n); } { var n = "TheSheep"; arsenal.Add(n, MyFrames.TheSheep); combo.Add(n); } { var n = "ThePig"; arsenal.Add(n, MyFrames.ThePig); combo.Add(n); } { var n = "TheCactus"; arsenal.Add(n, MyFrames.TheCactus); combo.Add(n); } } if (BeforeAddingDebris != null) { BeforeAddingDebris(arena.Layers.Canvas); } 3.Times( delegate() { new DebrisImages().Images.ForEach( img => img.AttachTo(arena.Layers.Canvas).style.SetLocation(map.X.Random(), map.Y.Random()) ); } ); 16.Times( delegate() { actors.Add( CreateActor(arsenal.Random().Value, new Point(map.X.Random(), map.Y.Random())) ); } ); }
// change: C:\util\xampplite\apache\conf\httpd.conf // http://localhost/jsc/FlashBrowserDocument/FlashBrowserDocument.htm /* * Alias /jsc/FlashBrowserDocument "C:\work\jsc.svn\examples\actionscript\FlashBrowserDocument\FlashBrowserDocument\bin\Release\web" * <Directory "C:\work\jsc.svn\examples\actionscript\FlashBrowserDocument\FlashBrowserDocument\bin\Release\web"> * Options Indexes FollowSymLinks ExecCGI * AllowOverride All * Order allow,deny * Allow from all * </Directory> */ /// <summary> /// Default constructor /// </summary> public FlashBrowserDocument() { ConsoleFormPackageExperience.Initialize(); Console.WriteLine("ConsoleFormPackageExperience"); var t = new TextField { defaultTextFormat = new TextFormat { font = "Courier" }, backgroundColor = 0x303030, textColor = 0xffff00, text = "powered by jsc", background = true, x = 0, y = 0, alwaysShowSelection = true, width = DefaultWidth, height = DefaultHeight }.AttachTo(this); // you should be running within the browser //SecurityError: Error #2060: Security sandbox violation: ExternalInterface caller file:///C:/work/jsc.svn/examples/actionscript/FlashBrowserDocument/FlashBrowserDocument/bin/Release/web/FlashBrowserDocument.swf cannot access file:///C:/work/jsc.svn/examples/actionscript/FlashBrowserDocument/FlashBrowserDocument/bin/Release/web/FlashBrowserDocument.htm. // at flash.external::ExternalInterface$/_initJS() // at flash.external::ExternalInterface$/addCallback() // at Extensions::ExternalExtensions$/External_100668292() // at DOM::ExternalContext() // at DOM::ExternalContext$/ExternalAuthentication_100663321() // at FlashBrowserDocument.ActionScript::FlashBrowserDocument() t.text = "before ExternalAuthentication"; try { Console.WriteLine("before ExternalAuthentication"); ExternalContext.ExternalAuthentication( context => { Console.WriteLine("at ExternalAuthentication"); t.text = "after ExternalAuthentication"; context.Document.body.style.backgroundColor = "#afafff"; context.Document.body.style.color = "#000080"; t.appendText("\nflash element was found within html document"); context.Document.title = "hello world"; #region hide/show flash element var HideFlashButtonCounter = 0; var HideFlashButton = new IHTMLButton { innerHTML = "hide flash element" }; HideFlashButton.AttachTo(context); HideFlashButton.onclick += delegate { if (HideFlashButtonCounter % 2 == 0) { t.appendText("\nflash element hidden"); context.Element.width = 0; context.Element.height = 0; HideFlashButton.innerHTML = "show flash element"; } else { t.appendText("\nflash element shown"); context.Element.width = DefaultWidth; context.Element.height = DefaultHeight; HideFlashButton.innerHTML = "hide flash element"; } HideFlashButtonCounter++; }; #endregion var Content = @" <hr /> <blockqoute> <h1>This application was written in c# and was compiled to actionscript with <a href='http://jsc.sf.net'>jsc compiler</a>.</h1> <h2>Currently supported browsers:</h2> <ul> <li><img src='http://www.w3schools.com/images/compatible_firefox.gif' />Firefox</li> <li><img src='http://www.w3schools.com/images/compatible_chrome.gif' />Google Chrome</li> <li><img src='http://www.w3schools.com/images/compatible_safari.gif' />Safari</li> <li><img src='http://www.w3schools.com/images/compatible_opera.gif' />Opera</li> </ul> </blockqoute> " .AttachAsDiv(context); var DynamicChild = new IHTMLSpan { innerHTML = "hello world" }.AttachTo(Content); DynamicChild.style.color = "red"; DynamicChild.innerHTML = "click on the image to remove it!"; var DynamicChildImage = new IHTMLImage { title = "jsc diagram", src = "http://jsc.sourceforge.net/jsc.png" }.AttachTo(DynamicChild); DynamicChildImage.style.backgroundColor = "white"; DynamicChildImage.onclick += delegate { Console.WriteLine("at DynamicChildImage onclick"); DynamicChild.removeChild(DynamicChildImage); DynamicChild.innerHTML = "you have removed that image!"; var Undo = new IHTMLButton { innerHTML = "undo" }.AttachTo(DynamicChild); Undo.onclick += delegate { DynamicChildImage.AttachTo(DynamicChild); DynamicChild.removeChild(Undo); }; }; DynamicChild.onclick += delegate { Console.WriteLine("at DynamicChild onclick"); }; } ); } catch (Exception ex) { t.text = "error " + new { ex }; } }
public static void InitializeContent() { #region tutorial step 2 #region arena var map = new Point(2000, 2000); var arena = new ArenaControl(); arena.Layers.Canvas.style.backgroundColor = Color.FromGray(0xc0); arena.SetLocation( Rectangle.Of(0, 0, Native.window.Width, Native.window.Height)); arena.SetCanvasSize(map); arena.Control.AttachToDocument(); arena.DrawTextToInfo(Title, new Point(8, 8), Color.Blue); Native.window.onresize += delegate { arena.SetLocation( Rectangle.Of(0, 0, Native.window.Width, Native.window.Height)); arena.SetCanvasPosition( arena.CurrentCanvasPosition ); }; #endregion #endregion var pending = default(Dude2); #region arsenal var arsenal = new Dictionary<string, DudeAnimationInfo> { {"Soldier", new DudeAnimationInfo { Frames_Stand = Frames.WolfSoldier, Frames_Walk = Frames.WolfSoldier_Walk } }, {"Imp", new DudeAnimationInfo { Frames_Stand = Frames.DoomImp, Frames_Walk = Frames.DoomImp_Walk } } }; #endregion #region tutorial step 3 Func<DudeAnimationInfo, Point, Dude2> CreateActor = (_frames, _coords) => { var actor = new Dude2(); actor.Frames = _frames.Frames_Stand; actor.AnimationInfo.Frames_Stand = _frames.Frames_Stand; actor.AnimationInfo.Frames_Walk = _frames.Frames_Walk; actor.Zoom.DynamicZoomFunc = a => 1; actor.SetSize(48, 72); actor.TeleportTo(_coords.X, _coords.Y); actor.Zoom.StaticZoom = DefaultActiorZoom; actor.Direction = Math.PI * 0.5; actor.Control.AttachTo(arena.Layers.Canvas); //actor.HasShadow = _frames.Frames_Stand.Length > 1; if (_frames.Frames_Stand.Length == 1) actor.Shadow.style.Opacity = 0.4; actor.AnimationInfo.WalkAnimationInterval = 1000 / 30; return actor; }; var actors = new List<Dude2> { }; var selection = from i in actors where i.IsSelected select i; arena.ApplySelection += (rect, ev) => { if (pending != null) return; foreach (var v in actors) v.IsSelected = rect.Contains(v.CurrentLocation.ToInt32()); }; var Argh = new Argh(); var Affirmative = new Affirmative(); var ghoullaugh = new ghoullaugh(); var sheep = new sheep(); var pig = new pig(); var click = new click().AttachToDocument(); arena.SelectionClick += (p, ev) => { if (pending != null) return; foreach (var v in selection) { if (v.AnimationInfo.Frames_Stand[0].Source == MyFrames.ManWithHorns.Frames_Stand[0].Source) { ghoullaugh.play(); ghoullaugh = new ghoullaugh(); } else if (v.AnimationInfo.Frames_Stand[0].Source == MyFrames.ThePig.Frames_Stand[0].Source) { pig.play(); pig = new pig(); } else if (v.AnimationInfo.Frames_Stand[0].Source == MyFrames.TheSheep.Frames_Stand[0].Source) { sheep.play(); sheep = new sheep(); } else if (v.AnimationInfo.Frames_Stand[0].Source == Frames.WolfSoldier[0].Source) { Affirmative.play(); Affirmative = new Affirmative(); } else { Argh.play(); Argh = new Argh(); } v.WalkTo(p.ToDouble()); // move in group formation p.X += 16; p.Y += 16; } }; #endregion #region tutorial step 4 #region CreateDialogAt var CreateDialogAt = new { //Dialog = default(IHTMLDiv), Content = default(IHTMLDiv), Width = default(string) } .ToFunc( (Point pos, string width) => { var f = new Form(); f.Show(); f.SizeTo(200, 200); // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20151115/audio //f.PopupInsteadOfClosing(); f.MoveTo(pos.X, pos.Y); //f.SizeTo( //var dialog = new IHTMLDiv(); //dialog.style.SetLocation(pos.X, pos.Y); //dialog.style.backgroundColor = Color.Gray; //dialog.style.padding = "1px"; //var caption = new IHTMLDiv().AttachTo(dialog); //caption.style.backgroundColor = Color.Blue; //caption.style.width = width; //caption.style.height = "0.5em"; //caption.style.cursor = IStyle.CursorEnum.move; //var drag = new DragHelper(caption); //drag.Position = pos; //drag.Enabled = true; //drag.DragMove += // delegate // { // dialog.style.SetLocation(drag.Position.X, drag.Position.Y); // }; var _content = new IHTMLDiv().AttachTo(f.GetHTMLTargetContainer()); _content.style.textAlign = IStyle.TextAlignEnum.center; _content.style.backgroundColor = Color.White; _content.style.padding = "1px"; //dialog.AttachToDocument(); return new { //Dialog = dialog, Content = _content, Width = width }; } ); #endregion #region dialog var toolbar = CreateDialogAt(new Point(2, 2), "8em"); var combo = new IHTMLSelect(); var build = new IHTMLButton(); build.style.SetSize(72, 72); build.style.padding = "0px"; var avatar = new IHTMLImage().AttachTo(build); var remove = new IHTMLButton("Remove"); combo.AttachTo(toolbar.Content); new IHTMLBreak().AttachTo(toolbar.Content); build.AttachTo(toolbar.Content); new IHTMLBreak().AttachTo(toolbar.Content); remove.AttachTo(toolbar.Content); new IHTMLBreak().AttachTo(toolbar.Content); #endregion #region GetSelectedArsenal Func<DudeAnimationInfo> GetSelectedArsenal = () => { if (arsenal.ContainsKey(combo[combo.selectedIndex].value)) return arsenal[combo[combo.selectedIndex].value]; return null; }; #endregion Action Refresh = delegate { var i = GetSelectedArsenal(); if (i != null) avatar.src = i.Images.Random().src; }; combo.Add(arsenal.Keys.ToArray()); Refresh(); combo.onchange += delegate { Refresh(); click.play(); click = new click().AttachToDocument(); }; #region pending actor arena.MouseMove += p => { if (pending == null) return; pending.TeleportTo(p.X, p.Y); }; arena.Layers.User.oncontextmenu += e => { e.preventDefault(); if (pending != null) { pending.Control.Orphanize(); pending = null; arena.ShowSelectionRectangle = true; return; } actors.ForEach( k => k.IsSelected = false ); }; arena.SelectionClick += (p, ev) => { if (pending == null) { return; } pending.TeleportTo(p.X, p.Y); actors.Add(pending); pending.IsHot = false; var x = GetSelectedArsenal(); pending = CreateActor(x, new Point( Native.window.Width / 2, Native.window.Height / 2 ) ); pending.IsHot = true; click.play(); click = new click().AttachToDocument(); }; build.onclick += delegate { if (pending != null) { pending.Control.Orphanize(); pending = null; return; } var x = GetSelectedArsenal(); pending = CreateActor(x, new Point( Native.window.Width / 2, Native.window.Height / 2 ) ); pending.IsHot = true; arena.ShowSelectionRectangle = false; click.play(); click = new click().AttachToDocument(); }; #endregion remove.onclick += delegate { foreach (var v in selection.ToArray()) { v.Control.Orphanize(); actors.Remove(v); } click.play(); click = new click().AttachToDocument(); }; #endregion if (FilterToImpAndSoldier) { } else { #region step 6 { var n = "NPC"; arsenal.Add(n, MyFrames.NPC3); combo.Add(n); } #endregion { var n = "ManWithHorns"; arsenal.Add(n, MyFrames.ManWithHorns); combo.Add(n); } { var n = "TheSheep"; arsenal.Add(n, MyFrames.TheSheep); combo.Add(n); } { var n = "ThePig"; arsenal.Add(n, MyFrames.ThePig); combo.Add(n); } { var n = "TheCactus"; arsenal.Add(n, MyFrames.TheCactus); combo.Add(n); } } if (BeforeAddingDebris != null) BeforeAddingDebris(arena.Layers.Canvas); 3.Times( delegate() { new DebrisImages().Images.ForEach( img => img.AttachTo(arena.Layers.Canvas).style.SetLocation(map.X.Random(), map.Y.Random()) ); } ); 16.Times( delegate() { actors.Add( CreateActor(arsenal.Random().Value, new Point(map.X.Random(), map.Y.Random())) ); } ); }
public __ToolStripButton() { (this.InternalElement.style.display as dynamic).display = "table-cell"; var InternalElementSpan = new IHTMLSpan().AttachTo(InternalElement); //InternalElementSpan.style.verticalAlign = "baseline"; this.InternalElement.style.font = Control.DefaultFont.ToCssString(); //this.Font = DefaultFont; this.InternalImageChanged += delegate { if (this.InternalImage == null) { return; } var i = ((__Bitmap)(object)this.InternalImage).InternalImage; // https://developer.mozilla.org/en-US/docs/Web/CSS/vertical-align //i.style.verticalAlign = "baseline"; this.InternalElement.insertBefore( i, InternalElementSpan ); if (this.DisplayStyle == ToolStripItemDisplayStyle.Image) { i.InvokeOnComplete( delegate { InternalElementSpan.Hide(); } ); } }; this.InternalElement.onclick += delegate { this.RaiseClick(); }; this.TextChanged += delegate { InternalElementSpan.innerText = this.InternalText; }; this.InternalAfterSetOwner += delegate { __ToolStrip o = this.Owner; // or contaner? InternalElement.AttachTo(o.InternalElement); }; }
/// <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(IDefault page) { Action</*dynamic*/ IHTMLInput, string, Func<IHTMLLink>> apply = (btn, text, css) => { btn.disabled = true; var Content = css(); Content.AttachToHead(); var AddDynamicRule = new IHTMLButton { innerText = "add dynamic rule to " + text }; var DisableStyle = new IHTMLButton { innerText = "disable style " + text }; AddDynamicRule.AttachTo(page.Content); AddDynamicRule.onclick += delegate { AddDynamicRule.disabled = true; var rule1 = Content.StyleSheet.AddRule("button", s => { s.style.color = "green"; } ); var DisableDynamicRule = new IHTMLButton { innerText = "disable dynamic rule from " + text }; DisableDynamicRule.AttachTo(page.Content); DisableStyle.onclick += delegate { DisableDynamicRule.Orphanize(); }; DisableDynamicRule.onclick += delegate { // remove the last rule? :) Content.StyleSheet.RemoveRule(Content.StyleSheet.Rules.Length - 1); AddDynamicRule.disabled = false; DisableDynamicRule.Orphanize(); }; }; DisableStyle.AttachTo(page.Content); DisableStyle.onclick += delegate { AddDynamicRule.Orphanize(); DisableStyle.Orphanize(); Content.Orphanize(); btn.disabled = false; }; }; page.Bar.onclick += delegate { apply(page.Bar, "Boo.css", () => new WithStylesheet.Styles.BooStyle().Content); }; page.Foo.onclick += delegate { apply(page.Foo, "Foo.css", () => new WithStylesheet.Styles.FooStyle().Content); }; @"Hello world".ToDocumentTitle(); // Send data from JavaScript to the server tier service.WebMethod2( @"A string from JavaScript.", value => value.ToDocumentTitle() ); }
/// <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) { // Initialize ApplicationSprite sprite.AttachSpriteToDocument(); // how did it work before? #if v #region visualize Action<bool, byte[], Action<double, double, Action<double>, IWindow>> visualize_and_getpadding = null; visualize_and_getpadding = (allowpadding, bytes, set_padding) => { var r = new BinaryReader(new MemoryStream(bytes)); var floats = new double[bytes.Length / 4]; //Console.WriteLine("floats " + new { floats.Length }); for (int i = 0; i < floats.Length; i++) { // X:\jsc.svn\core\ScriptCoreLib\JavaScript\BCLImplementation\System\IO\BinaryReader.cs // do we do floats? floats[i] = r.ReadSingle(); } var paddingmode_yellow = allowpadding; var paddingsamples_yellow = 0; var paddingmode_yellow_agg = 0.0; var paddingmode_yellow_grace = 411; var paddingmode_red = allowpadding; var paddingsamples_red = 0; var paddingmode_red_agg = 0.0; var paddingmode_red_grace = 411; #region max var min = 0.0; var minset = false; var max = 0.0; var maxset = false; for (int ix = 0; ix < floats.Length; ix += 2) { // arg[0] is typeof System.Single //script: error JSC1000: No implementation found for this native method, please implement [static System.Console.WriteLine(System.Single)] var l0 = floats[ix]; var r0 = floats[ix + 1]; if (l0 != 0) if (minset) { min = Math.Min(min, l0); } else { min = l0; minset = true; } if (maxset) { max = Math.Max(max, l0); } else { max = l0; maxset = true; } } var absmax = max.Max(Math.Abs(min)); #endregion #region paddingmode_yellow for (int ix = 0; ix < floats.Length; ix += 2) { // arg[0] is typeof System.Single //script: error JSC1000: No implementation found for this native method, please implement [static System.Console.WriteLine(System.Single)] var l0 = floats[ix]; var r0 = floats[ix + 1]; if (paddingmode_yellow) { // discard noise if (Math.Abs(l0) > 0.08 * absmax) paddingmode_yellow_agg += Math.Abs(l0); } if (paddingmode_yellow_agg > absmax * 2.1) { if (Math.Abs(l0) < 0.02 * absmax) { paddingmode_yellow = false; } } if (paddingmode_yellow) { paddingsamples_yellow++; if (paddingmode_yellow_agg > absmax * 3.2) { if (paddingmode_yellow_grace > 0) { paddingmode_yellow_grace--; } else { // rollback paddingsamples_yellow -= 411; paddingmode_yellow = false; } } } } #endregion // count down while near zero, then wait for zero #region paddingmode_red for (int ix = floats.Length - 1; ix >= 0; ix -= 2) { var l0 = floats[ix]; var r0 = floats[ix + 1]; if (paddingmode_red) { // discard noise if (Math.Abs(l0) > 0.08 * absmax) paddingmode_red_agg += Math.Abs(l0); } if (paddingmode_red_agg > absmax * 2.1) { if (Math.Abs(l0) < 0.02 * absmax) { paddingmode_red = false; } } if (paddingmode_red) { paddingsamples_red++; if (paddingmode_red_agg > absmax * 3.2) { if (paddingmode_red_grace > 0) { paddingmode_red_grace--; } else { // rollback paddingsamples_red -= 411; paddingmode_red = false; } } } } #endregion var w = new IWindow(); w.onload += delegate { Console.WriteLine("onload"); try { //BitConverter.ToSingle( w.document.body.style.margin = "0px"; // verbose huh. svg::svg? var svg = new ISVGSVGElement().AttachTo(w.document.body); var path_current = new ISVGPathElement().AttachTo(svg); path_current.setAttribute("style", "stroke-width: 5; stroke: blue; fill: none;"); var path = new ISVGPathElement().AttachTo(svg); path.setAttribute("style", "stroke: black; fill: none;"); var path_loop2 = new ISVGPathElement().AttachTo(svg); path_loop2.setAttribute("style", "stroke: green; fill: none;"); var xw = new StringBuilder().Append("M0,400 "); // done { min = 7.847271400218976e-44, max = 2.320612754833406e-38, paddingsamples = 1337 } w.document.body.style.minHeight = 800 + "px"; var scalex = 4 / 44.1; w.document.body.style.minWidth = floats.Length * scalex * 2 + "px"; w.document.body.style.overflow = IStyle.OverflowEnum.auto; // we should have 4096 stereo samples var samples = floats.Length; var samplesperchannel = samples / 2; #region xw for (int ix = 0; ix < floats.Length; ix += 2) { // arg[0] is typeof System.Single //script: error JSC1000: No implementation found for this native method, please implement [static System.Console.WriteLine(System.Single)] var l0 = floats[ix]; var r0 = floats[ix + 1]; // 0 is -60db // max is 0db // http://audio.tutsplus.com/articles/general/all-youll-ever-need-to-know-about-samples-and-bits/ //iy = (200.0 - l0 * 1E37 * 200); var iy = (400.0 - l0 * 400.0); xw.Append(" L" + (ix * scalex) + "," + iy); //Console.WriteLine("" + ReadFloat32(i)); } #endregion #region xw_loop2 var xw_loop2 = new StringBuilder(); for (int ix = paddingsamples_yellow * 2; ix < floats.Length - paddingsamples_red * 2; ix += 2) { // arg[0] is typeof System.Single //script: error JSC1000: No implementation found for this native method, please implement [static System.Console.WriteLine(System.Single)] var l0 = floats[ix]; var r0 = floats[ix + 1]; var iy = (400.0 - l0 * 400.0); if (xw_loop2.ToString().Length == 0) xw_loop2.Append(" M" + ((2 * (samplesperchannel - paddingsamples_red - paddingsamples_yellow) * scalex) + ((ix + 1) * scalex)) + "," + iy); else xw_loop2.Append(" L" + ((2 * (samplesperchannel - paddingsamples_red - paddingsamples_yellow) * scalex) + ((ix + 1) * scalex)) + "," + iy); } #endregion // A frame rate of 44,100 is 44,100 samples per SECOND, or 44.1 kHz. var duration_seconds = samplesperchannel / 44100; w.document.title = new { samplesperchannel, paddingsamples_yellow, paddingsamples_red, duration_seconds }.ToString(); Console.WriteLine("done " + new { min, max, paddingsamples_yellow, paddingsamples_red }); //xw.Append(" L30,210"); path.d = xw.ToString(); path_loop2.d = xw_loop2.ToString(); var path_zero = new ISVGPathElement().AttachTo(svg); path_zero.setAttribute("style", "stroke-width: 1; stroke: gray; fill: none;"); path_zero.d = "M0,400 L" + (2 * samplesperchannel * scalex) + ",400"; //var path_leftpadding = new ISVGPathElement().AttachTo(svg); //path_leftpadding.setAttribute("style", "stroke-width: 5; stroke: red; fill: none;"); //path_leftpadding.d = "M0,400 L" + (2 * paddingsamples * scalex) + ",400"; var path_leftpadding_yellow = new ISVGPathElement().AttachTo(svg); path_leftpadding_yellow.setAttribute("style", "stroke-width: 3; stroke: yellow; fill: none;"); path_leftpadding_yellow.d = "M0,400 L" + (2 * paddingsamples_yellow * scalex) + ",400"; var path_leftpadding_red = new ISVGPathElement().AttachTo(svg); path_leftpadding_red.setAttribute("style", "stroke-width: 3; stroke: red; fill: none;"); path_leftpadding_red.d = "M" + (2 * (samplesperchannel - paddingsamples_red) * scalex) + ",400 L" + (2 * (samplesperchannel - 0) * scalex) + ",400"; Action<double> set_position = position => { var x = (2 * position * scalex); path_current.d = "M" + x + ",50 L" + x + ",750 L" + (x + MP3PitchLoop.BLOCK_SIZE * 2 * scalex) + ",750 L" + (x + MP3PitchLoop.BLOCK_SIZE * 2 * scalex) + ",50 L" + x + ",50"; }; set_padding( paddingsamples_yellow, paddingsamples_red, set_position, w ); set_position(paddingsamples_yellow); } catch (Exception error) { Console.WriteLine("error " + new { error.Message, error }); } Console.WriteLine("done"); }; }; #endregion #region f Func<IHTMLButton, Action<string, PlayAtAndAllowToStop>> f = x => (base64, playat) => { var bytes = Convert.FromBase64String(base64); visualize_and_getpadding( true, bytes, (paddingleft, paddingright, set_position, w) => { var toolbar = new IHTMLDiv().AttachTo(w.document.body); toolbar.style.SetLocation(4, 4); toolbar.style.position = IStyle.PositionEnum.@fixed; new IHTMLButton { innerText = "play" }.AttachTo(toolbar).WhenClicked( delegate { playat( "" + paddingleft, "" + paddingright, yield_stop: stop => { var stopbtn = new IHTMLButton { innerText = "Stop" }; stopbtn.WhenClicked( delegate { stop(); stopbtn.Orphanize(); } ); stopbtn.AttachTo(toolbar); }, yield_position_anddiagnostics: (position, diagnostics) => { set_position(Convert.ToDouble(position)); if (!string.IsNullOrEmpty(diagnostics)) { Console.WriteLine(diagnostics); var diagnostics_bytes = Convert.FromBase64String(diagnostics); visualize_and_getpadding( false, diagnostics_bytes, delegate { } ); } } ); } ); } ); }; #endregion page.VisualizeDiesel.WhenClicked( delegate { sprite.BytesForDiesel(f(page.VisualizeDiesel)); } ); page.VisualizeHelicopter.onclick += delegate { sprite.BytesForHelicopter(f(page.VisualizeHelicopter)); }; page.VisualizeJeep.onclick += delegate { sprite.BytesForJeep(f(page.VisualizeJeep)); }; page.VisualizeTone.onclick += delegate { sprite.BytesForTone(f(page.VisualizeTone)); }; page.VisualizeSandrun.onclick += delegate { sprite.BytesForSandrun(f(page.VisualizeSandrun)); }; #endif page.PlayDiesel.onclick += delegate { sprite.PlayDiesel(); }; page.PlayHelicopter.onclick += delegate { sprite.Playhelicopter1(); }; page.PlayJeep.onclick += delegate { sprite.PlayJeep(); }; page.PlayTone.onclick += delegate { sprite.PlayTone(); }; page.PlaySandrun.onclick += delegate { sprite.PlaySandrun(); }; }
/// <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(IDefault page) { @"Hello world".ToDocumentTitle(); var output = new IHTMLTextArea().AttachToDocument(); var gexf = new XElement("gexf"); gexf.Add( new XElement("meta", new XElement("creator", "jsc"), new XElement("description", "NASDAQSNA") ) ); var graph = new XElement("graph", new XAttribute("mode", "static"), new XAttribute("defaultedgetype", "directed") ); gexf.Add(graph); var nodes = new XElement("nodes"); graph.Add(nodes); var edges = new XElement("edges"); graph.Add(edges); output.value = gexf.ToString(); output.onfocus += delegate { output.value = gexf.ToString(); }; output.onmouseover += delegate { output.value = gexf.ToString(); }; var NumericNodeIdLookup = new List <string>(); Func <string, int> GetNumericNodeId = k => { if (!NumericNodeIdLookup.Contains(k)) { NumericNodeIdLookup.Add(k); } return(NumericNodeIdLookup.IndexOf(k)); }; #region AddRelatedCompanies Func <IHTMLDiv, string, Action, Task> AddRelatedCompanies = null; AddRelatedCompanies = (c, qid, done) => { var nqid = GetNumericNodeId(qid).ToString(); var cc = new IHTMLDiv(); cc.style.marginLeft = "2em"; var service = new ApplicationWebService { qid = qid, yield = (id, CompanyName, Price) => { var nid = GetNumericNodeId(id).ToString(); if (nodes.Elements().Any(k => k.Attribute("id").Name.LocalName == nid)) { } else { nodes.Add( new XElement("node", new XAttribute("id", nid), new XAttribute("label", CompanyName) ) ); } var btn = new IHTMLButton { innerText = id + " " + CompanyName + " " + Price }; btn.style.display = IStyle.DisplayEnum.block; if (qid == id) { btn.disabled = true; if (c == null) { btn.AttachToDocument(); cc.AttachToDocument(); } else { //btn.AttachTo(c); cc.AttachTo(c); } if (done != null) { done(); } } else { edges.Add( new XElement("edge", new XAttribute("source", nqid), new XAttribute("target", nid) ) ); btn.AttachTo(cc); var ccc = new IHTMLDiv(); ccc.AttachTo(cc); int cx = 0; ccc.ToggleVisible(); btn.WhenClicked( async delegate { if (cx == 0) { btn.style.color = JSColor.Red; await AddRelatedCompanies(ccc, id, delegate { btn.style.color = JSColor.Blue; } ); } cx++; ccc.ToggleVisible(); } ); } } }; return(service.GetRelatedCompanies()); }; #endregion AddRelatedCompanies(null, "NASDAQ:FB", null); AddRelatedCompanies(null, "NASDAQ:GOOG", null); }