Пример #1
0
		private static void AddSection11(Action<string, IHTMLDiv> AddSection)
		{
			var ToolbarHeight = "24px";

			var Content = new IHTMLDiv().With(
				k =>
				{
					k.style.border = "1px solid gray";
					k.style.position = ScriptCoreLib.JavaScript.DOM.IStyle.PositionEnum.relative;
					k.style.width = "100%";
					k.style.height = "20em";
				}
			);

            //global::ScriptCoreLib.Ultra.Components.HTML
            // reload the project to make visual studio happy!
			new TwentyTenWorkspace().ToBackground(Content.style, true);

			var ToolbarContainerBackground = new IHTMLDiv().With(
				k =>
				{
					k.style.position = ScriptCoreLib.JavaScript.DOM.IStyle.PositionEnum.absolute;
					k.style.left = "0px";
					k.style.right = "0px";
					k.style.top = "0px";
					k.style.height = ToolbarHeight;

					k.style.backgroundColor = Color.White;
					k.style.Opacity = 0.5;
				}
			).AttachTo(Content);

			var ToolbarContainer = new IHTMLDiv().With(
				k =>
				{
					k.style.position = ScriptCoreLib.JavaScript.DOM.IStyle.PositionEnum.absolute;
					k.style.left = "0px";
					k.style.right = "0px";
					k.style.top = "0px";
					k.style.height = ToolbarHeight;


				}
			).AttachTo(Content);

			var PreviewContainer = new IHTMLDiv().With(
				k =>
				{
					k.style.position = ScriptCoreLib.JavaScript.DOM.IStyle.PositionEnum.absolute;
					k.style.left = "0px";
					k.style.right = "0px";
					k.style.top = ToolbarHeight;
					k.style.bottom = "0px";
				}
			).AttachTo(Content);


			var PreviewFrame = new IHTMLIFrame { src = "about:blank" };

			PreviewFrame.style.width = "100%";
			PreviewFrame.style.height = "100%";
			PreviewFrame.style.border = "0";
			PreviewFrame.style.margin = "0";
			PreviewFrame.style.padding = "0";
			PreviewFrame.frameBorder = "0";
			PreviewFrame.border = "0";

			PreviewFrame.AttachTo(PreviewContainer);

			PreviewContainer.Hide();

			var EditorContainer = new IHTMLDiv().With(
				k =>
				{
					k.style.position = ScriptCoreLib.JavaScript.DOM.IStyle.PositionEnum.absolute;
					k.style.left = "0px";
					k.style.right = "0px";
					k.style.top = ToolbarHeight;
					k.style.bottom = "0px";
				}
			).AttachTo(Content);

			var EditorFrame = VisualStudioView.CreateEditor().AttachTo(EditorContainer);

			PreviewFrame.allowTransparency = true;
			EditorFrame.allowTransparency = true;

			EditorFrame.WhenContentReady(
				body =>
				{
					body.style.backgroundColor = Color.Transparent;

					new IHTMLDiv
					{
						"Hello world :)"
					}.With(
						div =>
						{
							div.style.backgroundColor = Color.White;
							div.style.borderColor = Color.Gray;
							div.style.borderStyle = "solid";
							div.style.borderWidth = "1px";

							div.style.margin = "2em";
							div.style.padding = "2em";
						}
					).AttachTo(body);

				}
			);

			var ToolbarContent = new IHTMLDiv().AttachTo(ToolbarContainer);

			ToolbarContent.style.position = ScriptCoreLib.JavaScript.DOM.IStyle.PositionEnum.relative;

			Action<IHTMLElement> ApplyToolbarButtonStyle =
				k =>
				{
					k.style.verticalAlign = "top";

					k.style.padding = "0";
					k.style.margin = "0";
					k.style.overflow = ScriptCoreLib.JavaScript.DOM.IStyle.OverflowEnum.hidden;
					k.style.SetSize(24, 24);

					VisualStudioView.ApplyMouseHoverStyle(k, Color.Transparent);
				};

			Func<IHTMLImage, IHTMLButton> AddButtonDummy =
				(img) =>
				{
					return new IHTMLButton { img.WithinContainer() }.With(k => ApplyToolbarButtonStyle(k)).AttachTo(ToolbarContent);
				};

			Func<IHTMLImage, Action, IHTMLButton> AddButtonAction =
				(img, command) =>
				{
					return AddButtonDummy(img).With(
						k =>
						{
							k.onclick +=
								delegate
								{
									command();
								};

						}
					);
				};

			Func<IHTMLImage, string, IHTMLButton> AddButton =
				(img, command) =>
				{
					return AddButtonAction(img, () =>
						EditorFrame.contentWindow.document.execCommand(
							command, false, null
						)
					);
				};


			//AddButtonDummy(new RTA_save());

			var SaveContainer = new IHTMLDiv().With(k => ApplyToolbarButtonStyle(k)).AttachTo(ToolbarContent);


			SaveContainer.style.display = ScriptCoreLib.JavaScript.DOM.IStyle.DisplayEnum.inline_block;

			//var Save = new InternalSaveActionSprite();

			//Save.ToTransparentSprite();
			//Save.AttachSpriteTo(SaveContainer);


			var s = new { VisualStudioTemplates.VisualCSharpProject };

			EditorFrame.WhenContentReady(
				body =>
				{
					var t = (IHTMLTextArea)EditorFrame.contentWindow.document.createElement("textarea");

					t.AttachTo(body);

					t.value = s.ToString();

				}
			);

			//Save.WhenReady(
			//    i =>
			//    {
			//        i.FileName = "Project1.zip";


			//        i.Add("Project1.txt", "x");
			//        i.Add("Project1.csproj", s.VisualCSharpProject);
			//    }
			//);

			ToolbarContent.Add(new RTA_separator_horizontal());

			var RTAButtons = new Dictionary<string, IHTMLImage>
			{
				// http://trac.symfony-project.org/browser/plugins/dmCkEditorPlugin/web/js/ckeditor/_source/plugins?rev=27455

				{"Bold", new RTA_bold()},
				{"Underline", new RTA_underline()},
				{"Strikethrough", new RTA_strikethrough()},
				{"Italic", new RTA_italic()},
				{"JustifyLeft", new RTA_justifyleft()},
				{"JustifyCenter", new RTA_justifycenter()},
				{"JustifyRight", new RTA_justifyright()},
				{"JustifyFull", new RTA_justifyfull()},
				{"Indent", new RTA_indent()},
				{"Outdent", new RTA_outdent()},
				{"Superscript", new RTA_superscript()},
				{"Subscript", new RTA_sub()},
				{"Removeformat", new RTA_removeformat()},
				{"InsertOrderedList", new RTA_numberedlist()},
				{"InsertUnorderedList", new RTA_numberedlist()},
				{"undo", new RTA_undo()},
				{"redo", new RTA_redo()},
			}.ToDictionary(
				k => k.Key,
				k => AddButton(k.Value, k.Key)
			);




			var ButtonDesign = default(IHTMLButton);
			var ButtonHTML = default(IHTMLButton);

			ButtonDesign = AddButtonAction(new RTA_mode_design(),
				delegate
				{
					ButtonDesign.Hide();
					ButtonHTML.Show();

					EditorContainer.Show();
					PreviewContainer.Hide();
				}
			);

			ButtonHTML = AddButtonAction(new RTA_mode_html(),
				delegate
				{
					ButtonHTML.Hide();


					PreviewFrame.WithContent(
						body =>
						{
							body.style.backgroundColor = Color.Transparent;
							body.innerHTML = EditorFrame.contentWindow.document.body.innerHTML;

							EditorContainer.Hide();
							PreviewContainer.Show();
							ButtonDesign.Show();
						}
					);
				}
			);

			ButtonDesign.Hide();

			AddSection(
				"Editor with toolbar with background and preview",
				Content
			);
		}
Пример #2
0
            // dynamic does not work in static yet?
            //static 
            void InitializeContent()
        {
            //        script: error JSC1000: Method: InitializeContent, Type: CSSTransform3DFPSExperimentByKeith.Application; emmiting failed : System.InvalidOperationException: unsupported flow detected, try to simplify.
            // Assembly V:\CSSTransform3DFPSExperimentByKeith.Application.exe
            // DeclaringType CSSTransform3DFPSExperimentByKeith.Application, CSSTransform3DFPSExperimentByKeith.Application, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null
            //         OwnerMethod InitializeContent
            //         Offset 00a0
            //         .Try ommiting the return, break or continue instruction.
            //          at jsc.Script.CompilerBase.BreakToDebugger(String e) in x:\jsc.internal.svn\compiler\jsc\Languages\CompilerBase.cs:line 266
            //   at jsc.ILBlock.PrestatementBlock.AddPrestatement(Prestatement p) in x:\jsc.internal.svn\compiler\jsc\CodeModel\ILBlock.cs:line 1654
            //   at jsc.ILBlock.PrestatementBlock.Populate(ILInstruction First, ILInstruction Last) in x:\jsc.internal.svn\compiler\jsc\CodeModel\ILBlock.cs:line 1606
            //   at jsc.ILBlock.PrestatementBlock.Populate() in x:\jsc.internal.svn\compiler\jsc\CodeModel\ILBlock.cs:line 1433
            //   at jsc.ILBlock.get_Prestatements() in x:\jsc.internal.svn\compiler\jsc\CodeModel\ILBlock.cs:line 1759
            //   at jsc.Languages.JavaScript.MethodBodyOptimizer.TryOptimize(IdentWriter w, ILBlock xb) in x:\jsc.internal.svn\compiler\jsc\Languages\JavaScript\MethodBodyOptimizer.cs:line 89
            //   at jsc.IL2Script.EmitBody(IdentWriter w, MethodBase SourceMethod, Boolean define_self) in x:\jsc.internal.svn\compiler\jsc\Languages\JavaScript\IL2Script.cs:line 576

            //Unhandled Exception: System.InvalidOperationException: Method: InitializeContent, Type: CSSTransform3DFPSExperimentByKeith.Application; emmiting failed : System.InvalidOperationException: unsupported flow detected, try to simplify.


            //dynamic window = Native.Window;

            //dynamic __osxPlane = window.__osxPlane;
            //IHTMLDiv __osxPlane_node = __osxPlane.node;

            var discover = new IHTMLIFrame
            {
                //border = "0",
                src = "http://discover.xavalon.net",
                allowFullScreen = true,
                frameBorder = "0"
            };


            //discover.style.transform = "scale(0.5)";
            //discover.style.transformOrigin = "0% 0%";

            //var scale = 1.25;
            var scale = 1;
            var zoom = 8;

            discover.style.transform = "scale(" + (1 / scale) + ")";
            discover.style.transformOrigin = "0% 0%";

            discover.style.SetSize(
                (int)(__wall_c.clientWidth * zoom * scale),
                 (int)(__wall_c.clientHeight * zoom * scale)
            );

            //dynamic ds = discover.style;

            //ds.zoom = (100.0 / zoom) + "%";

            discover.AttachTo(__wall_c);


            var c = new Controls.UserControl1();
            c.GetHTMLTarget().className = "nolock";


            #region button1
            c.button1.Click +=
                delegate
            {
                var cf = new Form1();

                cf.Show();

                cf.FormClosing +=
                    (ss, ee) =>
                        {
                            if (cf.WindowState == FormWindowState.Normal)
                            {
                                if (ee.CloseReason == CloseReason.UserClosing)
                                {
                                    ee.Cancel = true;
                                    cf.WindowState = FormWindowState.Minimized;
                                }
                            }
                        };

                cf.GetHTMLTarget().className = "nolock";

            };
            #endregion


            #region button2
            c.button2.Click +=
                delegate
            {
                var cf = new Form();

                var cw = new WebBrowser { Dock = DockStyle.Fill };

                cf.Controls.Add(cw);

                cw.Navigate(
            "http://discover.xavalon.net"

                        //"/"

                        );

                cf.FormClosing +=
                    (ss, ee) =>
                        {
                            if (cf.WindowState == FormWindowState.Normal)
                            {
                                if (ee.CloseReason == CloseReason.UserClosing)
                                {
                                    ee.Cancel = true;
                                    cf.WindowState = FormWindowState.Minimized;
                                }
                            }
                        };
                cf.Show();

                //Console.WriteLine("button2.Click");
                cf.GetHTMLTarget().className = "nolock";

                //cf.GetHTMLTarget().style.border = "2px solid red";

            };
            #endregion

            c.BackColor = Color.Transparent;

            var x = c.GetHTMLTargetContainer();

            x.style.transform = "scale(0.5)";
            x.style.transformOrigin = "0% 0%";

            x.style.SetSize(
                __osxPlane_node.clientWidth * 2,
                __osxPlane_node.clientHeight * 2
            );

            c.AttachControlTo(__osxPlane_node);




            #region onkeydown
            Native.Document.body.onkeydown += e =>
            {
                //Console.WriteLine(new { e.KeyCode });

                if (e.KeyCode == 87)
                    window.keyState.forward = true;
                if (e.KeyCode == 83)
                    window.keyState.backward = true;
                if (e.KeyCode == (int)Keys.A)
                    window.keyState.strafeleft = true;
                if (e.KeyCode == (int)Keys.D)
                    window.keyState.straferight = true;
            };

            Native.Document.body.onkeyup += e =>
            {
                if (e.KeyCode == 87)
                    window.keyState.forward = false;

                if (e.KeyCode == 83)
                    window.keyState.backward = false;

                if (e.KeyCode == (int)Keys.A)
                    window.keyState.strafeleft = false;
                if (e.KeyCode == (int)Keys.D)
                    window.keyState.straferight = false;

            };
            #endregion


            #region isnolock
            Func<INode, bool> isnolock =
                p =>
                {
                    var nolock = false;

                    while (p != Native.Document.body)
                    {
                        if (((IHTMLElement)p).className == "nolock")
                            nolock = true;

                        p = p.parentNode;
                    }

                    return nolock;
                };
            #endregion



            #region onmousemove
            Native.Document.body.tabIndex = 101;
            Native.Document.body.onmousedown +=
                e =>
                {
                    var nolock = isnolock(e.Element);
                    if (nolock)
                        return;

                    e.PreventDefault();
                    Native.Document.body.focus();
                    Native.Document.body.requestPointerLock();
                };

            Native.Document.body.onmousemove +=
                e =>
                {
                    if (Native.Document.pointerLockElement == Native.Document.body)
                    {
                        window.viewport.camera.rotation.x -= e.movementY / 2;
                        window.viewport.camera.rotation.z += e.movementX / 2;
                    }
                    else
                    {
                        var nolock = isnolock(e.Element);

                        if (nolock)
                            Native.Document.body.style.cursor = IStyle.CursorEnum.auto;
                        else
                            Native.Document.body.style.cursor = IStyle.CursorEnum.move;
                    }
                };


            Native.Document.body.onmouseup +=
                 e =>
                 {
                     if (Native.Document.pointerLockElement == Native.Document.body)
                     {
                         Native.Document.exitPointerLock();
                     }
                 };
            #endregion





            #region onframe
            Native.window.onframe += delegate
            {
                // is external target working bot ways?
                //window.speed = window.speed;

                //Console.WriteLine(new { window.keyState.forward });

                #region speed
                if (window.keyState.backward)
                {
                    if (window.speed > -window.maxSpeed)
                        window.speed -= window.accel;
                }
                else if (window.keyState.forward)
                {
                    if (window.speed < window.maxSpeed)
                        window.speed += window.accel;
                }
                else if (window.speed > 0)
                {
                    window.speed = Math.Max(window.speed - window.accel, 0);
                }
                else if (window.speed < 0)
                {
                    window.speed = Math.Max(window.speed + window.accel, 0);
                }
                else
                {
                    window.speed = 0;
                }
                #endregion


                #region strafespeed
                if (window.keyState.straferight)
                {
                    if (window.strafespeed > -window.maxSpeed)
                        window.strafespeed -= window.accel;
                }
                else if (window.keyState.strafeleft)
                {
                    if (window.strafespeed < window.maxSpeed)
                        window.strafespeed += window.accel;
                }
                else if (window.strafespeed > 0)
                {
                    window.strafespeed = Math.Max(window.strafespeed - window.accel, 0);
                }
                else if (window.strafespeed < 0)
                {
                    window.strafespeed = Math.Max(window.strafespeed + window.accel, 0);
                }
                else
                {
                    window.strafespeed = 0;
                }
                #endregion


                // sideway
                {

                    var xo = Math.Sin(window.viewport.camera.rotation.z * 0.0174532925);
                    var yo = Math.Cos(window.viewport.camera.rotation.z * 0.0174532925);

                    window.viewport.camera.position.x -= xo * window.speed;
                    window.viewport.camera.position.y -= yo * window.speed;
                }

                {
                    var xo = Math.Sin(window.viewport.camera.rotation.z * 0.0174532925 - 3.14 / 2);
                    var yo = Math.Cos(window.viewport.camera.rotation.z * 0.0174532925 - 3.14 / 2);

                    window.viewport.camera.position.x -= xo * window.strafespeed;
                    window.viewport.camera.position.y -= yo * window.strafespeed;
                }

                window.viewport.camera.update();


            };
            #endregion



        }