Beispiel #1
0
 static MapApplication()
 {
     Window.AddEventListener("load", delegate(ElementEvent e) {
         MapPage page = new MapPage();
         page.Run();
     }, /* useCapture */ false);
 }
Beispiel #2
0
 static BingMapsApplication()
 {
     Window.AddEventListener("load", delegate(ElementEvent e) {
         BingMapsShell shell = new BingMapsShell();
         shell.Run();
     }, /* useCapture */ false);
 }
        private Html5HistoryRouter()
        {
            _navigatedCallbacks = NonNullList <Action <UrlDetails> > .Empty;
            LastNavigatedToUrl  = null;

            Window.AddEventListener(EventType.PopState, e => RaiseNavigateToForCurrentLocation());
        }
Beispiel #4
0
 static FishTankApplication()
 {
     Window.AddEventListener("load", delegate(ElementEvent e) {
         FishTank fishtank = new FishTank();
         fishtank.Run();
     }, /* useCapture */ false);
 }
Beispiel #5
0
        public void Run()
        {
            _backgroundImageElement = Document.GetElementById("backgroundImage").As <ImageElement>();
            _imageStripElement      = Document.GetElementById("imageStrip").As <ImageElement>();
            _tankCanvas             = Document.GetElementById("fishTankCanvas").As <CanvasElement>();
            _fishesCanvas           = Document.GetElementById("fishesCanvas").As <CanvasElement>();

            Debug.Assert(_backgroundImageElement != null);
            Debug.Assert(_imageStripElement != null);
            Debug.Assert(_tankCanvas != null);
            Debug.Assert(_fishesCanvas != null);

            _tankCanvasContext   = (CanvasContext2D)_tankCanvas.GetContext(Rendering.Render2D);
            _fishesCanvasContext = (CanvasContext2D)_fishesCanvas.GetContext(Rendering.Render2D);

            _fishes = new List <Fish>();
            for (int i = 0; i < FishTank.FishCount; i++)
            {
                double x = Math.Floor(Math.Random() * (_width - FishTank.FishWidth) + FishTank.FishWidth / 2);
                double y = Math.Floor(Math.Random() * (_height - FishTank.FishHeight) + FishTank.FishHeight / 2);
                double z = Math.Floor(Math.Random() * (FishTank.ZFar - FishTank.ZNear));

                _fishes.Add(new Fish(this, x, y, z, _imageStripElement, _fishesCanvasContext));
            }

            OnWindowResize(null);
            Window.AddEventListener("resize", OnWindowResize, false);

            _tickHandler = OnTick;
            QueueUpdate();
        }
Beispiel #6
0
        static EntryPoint()
        {
            application = new TodoApplication();
            application.Run();

            Window.AddEventListener("onbeforeunload", HandleApplicationExit);
        }
Beispiel #7
0
        public void Run()
        {
            configuration   = new Configuration();
            dialogContainer = new DialogContainer();

            statistics = new Statistics(configuration);
            statistics.ReportSessionStart();

            toolsView = new ToolsView(dialogContainer, statistics);

            int storedGameLevel;

            if (Int32.TryParse(configuration.GetValue(GameLevelConfigurationKey), out storedGameLevel))
            {
                gameLevel = storedGameLevel;
            }
            else
            {
                gameLevel = DefaultLevel;
                firstTime = true;
            }

            Document.Body.AppendChild(toolsView.HtmlElement);
            Document.Body.AppendChild(dialogContainer.HtmlElement);

            Window.AddEventListener("hashchange", e => OnHashChanged());
            Window.AddEventListener("resize", e => UpdateLayout());
            Window.AddEventListener("unload", e => statistics.ReportSessionEnd());

            CreateInitialGame();
        }
Beispiel #8
0
        /// <summary>
        /// Bind the localStorage backup function to the unload event.
        /// </summary>
        /// <param name="opt_workspace">Workspace.</param>
        public static void backupOnUnload(WorkspaceSvg opt_workspace = null)
        {
            var workspace = opt_workspace ?? Blockly.Core.getMainWorkspace();

            Window.AddEventListener("unload",
                                    new Action(() => { BlocklyStorage.backupBlocks_(workspace); }), false);
        }
Beispiel #9
0
        public Layers(Resolution resolution)
        {
            if (resolution == null)
            {
                throw new ArgumentNullException(nameof(resolution));
            }

            _resolution = resolution;

            Wrapper.AppendChild(_stageWrapper);

            Controls = new Layer(_resolution, Wrapper);
            Wrapper.AppendChild(Controls.CanvasElement);
            Document.Body.AppendChild(Wrapper);

            Wrapper.OnTouchStart  = CancelDefault;
            Wrapper.OnTouchEnd    = CancelDefault;
            Wrapper.OnTouchCancel = CancelDefault;
            Wrapper.OnTouchEnter  = CancelDefault;
            Wrapper.OnTouchLeave  = CancelDefault;
            Wrapper.OnTouchMove   = CancelDefault;
            Wrapper.OnMouseMove   = CancelDefault;
            Wrapper.OnMouseLeave  = CancelDefault;
            Wrapper.OnMouseDown   = CancelDefault;
            Wrapper.OnMouseEnter  = CancelDefault;
            Wrapper.OnMouseOut    = CancelDefault;
            Wrapper.OnMouseOver   = CancelDefault;
            Wrapper.OnMouseUp     = CancelDefault;
            Wrapper.OnMouseWheel  = CancelDefault;
            Wrapper.OnContextMenu = CancelDefault;

            Window.AddEventListener(EventType.Resize, ResizeLayer);
            Window.AddEventListener(EventType.Load, ResizeLayer);
            Window.AddEventListener(EventType.Focus, ResizeLayer);
        }
        internal void Show(Vector2d position)
        {
            DivElement menu = Document.GetElementById <DivElement>("contextmenu");

            while (menu.FirstChild != null)
            {
                menu.RemoveChild(menu.FirstChild);
            }

            menu.ClassName     = "contextmenu";
            menu.Style.Display = "block";
            menu.Style.Left    = position.X.ToString() + "px";
            menu.Style.Top     = position.Y.ToString() + "px";

            Window.AddEventListener("click", NonMenuClick, true);

            foreach (ToolStripMenuItem item in Items)
            {
                if (item.Visible)
                {
                    DivElement md = (DivElement)Document.CreateElement("div");
                    if (item.DropDownItems.Count > 0)
                    {
                        md.ClassName = "contextmenuitem submenu";
                    }
                    else
                    {
                        if (item.Checked)
                        {
                            md.ClassName = "contextmenuitem checkedmenu";
                        }
                        else
                        {
                            md.ClassName = "contextmenuitem";
                        }
                    }
                    md.InnerText = item.Name;

                    TagMe it = (TagMe)(Object)md;
                    it.ItemTag = item;

                    md.AddEventListener("mouseover", OpenSubMenu, false);

                    if (item.Click != null)
                    {
                        md.AddEventListener("click", MenuItemClicked, false);
                    }

                    menu.AppendChild(md);
                }
            }
        }
    public void Initialize(Window window = null)
    {
        if (m_initialized)
        {
            return;
        }

        m_linkedWindow = window ?? DetectLinkedWindow();
        if (!m_linkedWindow)
        {
            return;
        }

        m_initialized = true;

        m_linkedWindow.AddEventListener(Events.UI_WINDOW_SHOW, OnWindowShow);
        m_linkedWindow.AddEventListener(Events.UI_WINDOW_HIDE, OnWindowHide);

        SettingsManager.instance?.AddEventListener(Events.VEDIO_SETTINGS_CHANGED, OnVedioSettingsChanged);

        OnInitialize();
    }
Beispiel #12
0
        /// <summary>
        /// Sets up the CanvasElement and its context
        /// <param name="UseDefaults">Set to true to have the canvas take up the entire screen; the background color will also be turned black to make sure it worked and all that.</param>
        /// </summary>
        public static void Create(bool UseDefaults = false)
        {
            if (!Created)
            {
                // If using default layout, set the CSS, width and height
                if (UseDefaults)
                {
                    Position        = Position.Absolute;
                    Left            = "0px";
                    Top             = "0px";
                    Width           = Window.InnerWidth;
                    Height          = Window.InnerHeight;
                    BackgroundColor = "black";
                }

                Window.AddEventListener("resize", () =>
                {
                    if (Orientation == Orientation.PORTRAIT)
                    {
                        if (Window.InnerWidth > Window.InnerHeight)
                        {
                            // Left off here
                        }
                        else
                        {
                        }
                    }
                    if (Orientation == Orientation.LANDSCAPE)
                    {
                        if (Window.InnerWidth > Window.InnerHeight)
                        {
                        }
                        else
                        {
                        }
                    }
                });

                // Add the CanvasElement element to the page
                Document.Body.AppendChild(CanvasElement);

                // Try to get its "context"
                Context = CanvasElement.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);
                if (Context.Equals(null))
                {
                    throw new KissException("CanvasElementError: HTML5 CanvasElement not supported.");
                }
                Created = true;     // So it won't bug out if someone calls Create twice
            }
        }
Beispiel #13
0
        public Button(bool initialCheck, params string[] classesName) :
            base("button")
        {
            this.isChecked = initialCheck;
            this.IsEnabled = true;

            foreach (string className in classesName)
            {
                HtmlElement.ClassList.Add(className);
            }

            HtmlElement.SetAttribute("data-is-checked", IsChecked.ToString());

            Shadow  = new Control("button-shadow");
            overlay = new Control("button-overlay");

            AppendChild(overlay);

            Window.AddEventListener("touchstart", OnPointerDown, false);
            Window.AddEventListener("mousedown", OnPointerDown, false);

            IValueBounds transformValueBounds = new ScaleValueBounds(1, 1.08);
            IValueBounds opacityValueBounds   = new DoubleValueBounds(0, 1);

            TransitionTiming transitionTiming = new TransitionTiming(CheckAnimationDurationMilliseconds);

            checkedAnimation = new ParallelTransition(
                new MultiplePropertyTransition(HtmlElement, new [] { "transform", "-webkit-transform" }, transformValueBounds, transitionTiming),
                new MultiplePropertyTransition(Shadow.HtmlElement, new[] { "transform", "-webkit-transform" }, transformValueBounds, transitionTiming),
                new Transition(Shadow.HtmlElement, "opacity", opacityValueBounds, transitionTiming));

            uncheckedAnimation = new ParallelTransition(
                new MultiplePropertyTransition(HtmlElement, new [] { "transform", "-webkit-transform" }, transformValueBounds.Reverse(), transitionTiming),
                new MultiplePropertyTransition(Shadow.HtmlElement, new[] { "transform", "-webkit-transform" }, transformValueBounds.Reverse(), transitionTiming),
                new Transition(Shadow.HtmlElement, "opacity", opacityValueBounds.Reverse(), transitionTiming));

            overlayAnimation = new ParallelTransition(
                new MultiplePropertyTransition(overlay.HtmlElement, new[] { "transform", "-webkit-transform" }, new ScaleValueBounds(0, 1.5), new TransitionTiming(400, TimingCurve.EaseOut)),
                new Transition(overlay.HtmlElement, "opacity", new DoubleValueBounds(0, 1), new TransitionTiming(100, TimingCurve.EaseIn), 0, Transition.ContinuationMode.ContinueValueAndTime),
                new Transition(overlay.HtmlElement, "opacity", new DoubleValueBounds(1, 0), new TransitionTiming(200, TimingCurve.EaseOut), 100, Transition.ContinuationMode.ContinueValueAndTime));

            if (IsChecked)
            {
                HtmlElement.Style["transform"]                = transformValueBounds.FormattedEndValue;
                HtmlElement.Style["-webkit-transform"]        = transformValueBounds.FormattedEndValue;
                Shadow.HtmlElement.Style["transform"]         = transformValueBounds.FormattedEndValue;
                Shadow.HtmlElement.Style["-webkit-transform"] = transformValueBounds.FormattedEndValue;
            }
        }
        public void Show(Vector2d position)
        {
            DivElement picker = Document.GetElementById <DivElement>("colorpicker");

            picker.ClassName     = "colorpicker";
            picker.Style.Display = "block";
            picker.Style.Left    = position.X.ToString() + "px";
            picker.Style.Top     = position.Y.ToString() + "px";

            Window.AddEventListener("click", NonMenuClick, true);

            ImageElement image = Document.GetElementById <ImageElement>("colorhex");

            image.AddEventListener("mousedown", PickColor, false);
        }
        internal void OpenSubMenu(ElementEvent e)
        {
            TagMe             me    = (TagMe)(Object)e.CurrentTarget;
            ToolStripMenuItem child = me.ItemTag;

            DivElement menu = Document.GetElementById <DivElement>("popoutmenu");

            while (menu.FirstChild != null)
            {
                menu.RemoveChild(menu.FirstChild);
            }

            menu.Style.Display = "none";

            if (child.DropDownItems.Count == 0)
            {
                return;
            }

            Vector2d position = new Vector2d();

            position.X = e.CurrentTarget.ParentNode.OffsetLeft + e.CurrentTarget.ParentNode.ClientWidth;
            position.Y = e.CurrentTarget.ParentNode.OffsetTop + e.CurrentTarget.OffsetTop;


            menu.ClassName     = "contextmenu";
            menu.Style.Display = "block";
            menu.Style.Left    = position.X.ToString() + "px";
            menu.Style.Top     = position.Y.ToString() + "px";

            Window.AddEventListener("click", NonMenuClick, true);

            foreach (ToolStripMenuItem item in child.DropDownItems)
            {
                if (item.Visible)
                {
                    DivElement md = (DivElement)Document.CreateElement("div");
                    md.ClassName = item.Checked ? "contextmenuitem checkedmenu" : "contextmenuitem";
                    md.InnerText = item.Name;

                    TagMe it = (TagMe)(Object)md;
                    it.ItemTag = item;

                    md.AddEventListener("click", MenuItemClicked, false);
                    menu.AppendChild(md);
                }
            }
        }
Beispiel #16
0
        public ToolbarButton(string className, Action mouseDown = null, Action mouseUp = null) :
            base("toolbar-button", className)
        {
            this.mouseDown = mouseDown;
            this.mouseUp = mouseUp;

            IsEnabled = true;

            Window.AddEventListener("touchstart", OnPointerDown, false);
            Window.AddEventListener("touchend", OnPointerUp, false);
            Window.AddEventListener("touchmove", OnPointerMove, false);
            Window.AddEventListener("touchcancel", OnPointerUp, false);
            Window.AddEventListener("mousedown", OnPointerDown, false);
            Window.AddEventListener("mouseup", OnPointerUp, false);
            HtmlElement.AddEventListener("mouseleave", e => { if (IsPressed) { OnPointerUp(e); } }, false);
        }
Beispiel #17
0
        public DialogContainer() :
            base("dialog-container")
        {
            this.HtmlElement.Style.Opacity    = "0";
            this.HtmlElement.Style.Visibility = "hidden";

            appearTransition = new SequentialTransition(
                new Keyframe(this.HtmlElement, "visibility", "visible"),
                new Transition(this.HtmlElement, "opacity", new DoubleValueBounds(0, 1), new TransitionTiming(200, TimingCurve.EaseIn)));

            disappearTransition = new SequentialTransition(
                new Transition(this.HtmlElement, "opacity", new DoubleValueBounds(1, 0), new TransitionTiming(200, TimingCurve.EaseIn)),
                new Keyframe(this.HtmlElement, "visibility", "hidden"));

            Window.AddEventListener("touchstart", OnPointerDown, false);
            Window.AddEventListener("mousedown", OnPointerDown, false);

            Window.AddEventListener("resize", UpdateLayout);
        }
Beispiel #18
0
        public App(HTMLCanvasElement screen)
        {
            this.canvasScreen = screen;
            ctx = screen.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);
            ctx.ImageSmoothingEnabled = true;
            LastMousePos             = new Vec2i();
            LastPinchGestureDistance = 0.0;

            Window.AddEventListener(EventType.Resize, OnSizeChanged);
            screen.AddEventListener(EventType.Wheel, OnMouseWheel);
            screen.AddEventListener(EventType.MouseDown, OnMouseDown);
            screen.AddEventListener(EventType.MouseUp, OnMouseUp);
            screen.AddEventListener(EventType.MouseMove, OnMouseMove);
            screen.AddEventListener(EventType.TouchStart, OnTouchStart);
            screen.AddEventListener(EventType.TouchEnd, OnTouchEnd);
            screen.AddEventListener(EventType.TouchMove, OnTouchMove);

            ReadLayerInfos();
        }
Beispiel #19
0
        public SpecificResizeObserver()
        {
            Window.AddEventListener(
                "resize",
                () => {
                Logger.Debug(GetType(), "[SpecificResizeObserver] updating listeners?");
                var updated = Document.Body.TraverseAll(x => {
                    if (!x.IsResizeRecipient() || !_listeners.ContainsKey(x))
                    {
                        return(false);
                    }
                    _listeners[x]();
                    return(true);
                });

                Logger.Debug(GetType(), "updated {0} listeners", updated);
            }
                );
        }
Beispiel #20
0
        public override void HandleApplicationEvents(ElementId elementId)
        {
            Window.OnKeyDown  += e => HandleEvent(InteropCall.App_OnKeyDown, elementId, e, e);
            Window.OnKeyUp    += e => HandleEvent(InteropCall.App_OnKeyUp, elementId, e, e);
            Window.OnKeyPress += e => HandleEvent(InteropCall.App_OnKeyPress, elementId, e);

            Window.OnMouseDown += e => HandleEvent(InteropCall.App_OnMouseDown, elementId, e, e);
            Window.OnMouseUp   += e => HandleEvent(InteropCall.App_OnMouseUp, elementId, e, e);
            Window.AddEventListener(EventType.Wheel, e => HandleEvent(InteropCall.App_OnMouseWheel, elementId, e));
            Window.OnMouseMove += e => HandleEvent(InteropCall.App_OnMouseMove, elementId, e, e);

            Window.AddEventListener(EventType.DblClick, e => HandleEvent(InteropCall.App_OnDoubleClick, elementId, e));
            Window.OnContextMenu += e => HandleEvent(InteropCall.App_OnContextMenu, elementId, e);
            Window.OnClick       += e => HandleEvent(InteropCall.App_OnClick, elementId, e);

            Window.OnFocus  += e => Fire(InteropCall.App_OnFocus, elementId);
            Window.OnBlur   += e => Fire(InteropCall.App_OnBlur, elementId);
            Window.OnResize += e => Fire(InteropCall.App_OnResize, elementId);
        }
Beispiel #21
0
        public static void Main()
        {
            ResetBrowserFrame();
            canvas = new HTMLCanvasElement();

            Document.Body.AppendChild(canvas);

            var app = new App(canvas);

            app.ResizeCalc();
            app.Draw();

            Script.Call("init_serviceworker");

            Window.AddEventListener(EventType.Resize, () =>
            {
                app.ResizeCalc();
                app.Draw();
            });
        }
Beispiel #22
0
        /// <summary>
        /// Add event listeners for workspace factory.
        /// </summary>
        /// <param name="controller"> The controller for the workspace
        /// factory tab.</param>
        private static void addWorkspaceFactoryEventListeners_(WorkspaceFactoryController controller)
        {
            // Use up and down arrow keys to move categories.
            Window.AddEventListener("keydown", new Action <Event>((e) => {
                // Don't let arrow keys have any effect if not in Workspace Factory
                // editing the toolbox.
                if (!(controller.keyEventsEnabled && controller.selectedMode
                      == WorkspaceFactoryController.MODE_TOOLBOX))
                {
                    return;
                }

                if (e.KeyCode == 38)
                {
                    // Arrow up.
                    controller.moveElement(-1);
                }
                else if (e.KeyCode == 40)
                {
                    // Arrow down.
                    controller.moveElement(1);
                }
            }));

            // Determines if a block breaks shadow block placement rules.
            // Breaks rules if (1) a shadow block no longer has a valid
            // parent, or (2) a normal block is inside of a shadow block.
            var isInvalidBlockPlacement = new Func <Blockly.Block, bool>((block) => {
                return((controller.isUserGenShadowBlock(block.id) &&
                        block.getSurroundParent() == null) ||
                       (!controller.isUserGenShadowBlock(block.id) && block.getSurroundParent() != null &&
                        controller.isUserGenShadowBlock(block.getSurroundParent().id)));
            });

            // Add change listeners for toolbox workspace in workspace factory.
            controller.toolboxWorkspace.addChangeListener((e) => {
                // Listen for Blockly move and delete events to update preview.
                // Not listening for Blockly create events because causes the user to drop
                // blocks when dragging them into workspace. Could cause problems if ever
                // load blocks into workspace directly without calling updatePreview.
                if (e.type == Blockly.Events.MOVE || e.type == Blockly.Events.DELETE ||
                    e.type == Blockly.Events.CHANGE)
                {
                    controller.saveStateFromWorkspace();
                    controller.updatePreview();
                }

                // Listen for Blockly UI events to correctly enable the "Edit Block" button.
                // Only enable "Edit Block" when a block is selected and it has a
                // surrounding parent, meaning it is nested in another block (blocks that
                // are not nested in parents cannot be shadow blocks).
                if (e.type == Blockly.Events.MOVE || (e.type == Blockly.Events.UI &&
                                                      ((Blockly.Events.Ui)e).element == "selected"))
                {
                    var selected = Blockly.Core.selected;

                    // Show shadow button if a block is selected. Show "Add Shadow" if
                    // a block is not a shadow block, show "Remove Shadow" if it is a
                    // shadow block.
                    if (selected != null)
                    {
                        var isShadow = controller.isUserGenShadowBlock(selected.id);
                        WorkspaceFactoryInit.displayAddShadow_(!isShadow);
                        WorkspaceFactoryInit.displayRemoveShadow_(isShadow);
                    }
                    else
                    {
                        WorkspaceFactoryInit.displayAddShadow_(false);
                        WorkspaceFactoryInit.displayRemoveShadow_(false);
                    }

                    if (selected != null && selected.getSurroundParent() != null &&
                        !controller.isUserGenShadowBlock(selected.getSurroundParent().id))
                    {
                        // Selected block is a valid shadow block or could be a valid shadow
                        // block.

                        // Enable block editing and remove warnings if the block is not a
                        // variable user-generated shadow block.
                        ((HTMLButtonElement)Document.GetElementById("button_addShadow")).Disabled    = false;
                        ((HTMLButtonElement)Document.GetElementById("button_removeShadow")).Disabled = false;

                        if (!FactoryUtils.hasVariableField(selected) &&
                            controller.isDefinedBlock(selected))
                        {
                            selected.setWarningText(null);
                        }
                    }
                    else
                    {
                        // Selected block cannot be a valid shadow block.

                        if (selected != null && isInvalidBlockPlacement(selected))
                        {
                            // Selected block breaks shadow block rules.
                            // Invalid shadow block if (1) a shadow block no longer has a valid
                            // parent, or (2) a normal block is inside of a shadow block.

                            if (!controller.isUserGenShadowBlock(selected.id))
                            {
                                // Warn if a non-shadow block is nested inside a shadow block.
                                selected.setWarningText("Only shadow blocks can be nested inside\n"
                                                        + "other shadow blocks.");
                            }
                            else if (!FactoryUtils.hasVariableField(selected))
                            {
                                // Warn if a shadow block is invalid only if not replacing
                                // warning for variables.
                                selected.setWarningText("Shadow blocks must be nested inside other"
                                                        + " blocks.");
                            }

                            // Give editing options so that the user can make an invalid shadow
                            // block a normal block.
                            ((HTMLButtonElement)Document.GetElementById("button_removeShadow")).Disabled = false;
                            ((HTMLButtonElement)Document.GetElementById("button_addShadow")).Disabled    = true;
                        }
                        else
                        {
                            // Selected block does not break any shadow block rules, but cannot
                            // be a shadow block.

                            // Remove possible "invalid shadow block placement" warning.
                            if (selected != null && controller.isDefinedBlock(selected) &&
                                (!FactoryUtils.hasVariableField(selected) ||
                                 !controller.isUserGenShadowBlock(selected.id)))
                            {
                                selected.setWarningText(null);
                            }

                            // No block selected that is a shadow block or could be a valid shadow
                            // block. Disable block editing.
                            ((HTMLButtonElement)Document.GetElementById("button_addShadow")).Disabled    = true;
                            ((HTMLButtonElement)Document.GetElementById("button_removeShadow")).Disabled = true;
                        }
                    }
                }

                // Convert actual shadow blocks added from the toolbox to user-generated
                // shadow blocks.
                if (e.type == Blockly.Events.CREATE)
                {
                    controller.convertShadowBlocks();

                    // Let the user create a Variables or Functions category if they use
                    // blocks from either category.

                    // Get all children of a block and add them to childList.
                    Action <Blockly.Block, JsArray <Blockly.Block> > getAllChildren = null;
                    getAllChildren = new Action <Blockly.Block, JsArray <Blockly.Block> >((block, childList) => {
                        childList.Push(block);
                        var children = block.getChildren();
                        for (var i = 0; i < children.Length; i++)
                        {
                            var child = children[i];
                            getAllChildren(child, childList);
                        }
                    });

                    var newBaseBlock = controller.toolboxWorkspace.getBlockById(e.blockId);
                    var allNewBlocks = new JsArray <Blockly.Block>();
                    getAllChildren(newBaseBlock, allNewBlocks);
                    var variableCreated  = false;
                    var procedureCreated = false;

                    // Check if the newly created block or any of its children are variable
                    // or procedure blocks.
                    for (var i = 0; i < allNewBlocks.Length; i++)
                    {
                        var block = allNewBlocks[i];
                        if (FactoryUtils.hasVariableField(block))
                        {
                            variableCreated = true;
                        }
                        else if (FactoryUtils.isProcedureBlock(block))
                        {
                            procedureCreated = true;
                        }
                    }

                    // If any of the newly created blocks are variable or procedure blocks,
                    // prompt the user to create the corresponding standard category.
                    if (variableCreated && !controller.hasVariablesCategory())
                    {
                        if (Window.Confirm("Your new block has a variables field. To use this block "
                                           + "fully, you will need a Variables category. Do you want to add "
                                           + "a Variables category to your custom toolbox?"))
                        {
                            controller.setMode(WorkspaceFactoryController.MODE_TOOLBOX);
                            controller.loadCategoryByName("variables");
                        }
                    }

                    if (procedureCreated && !controller.hasProceduresCategory())
                    {
                        if (Window.Confirm("Your new block is a function block. To use this block "
                                           + "fully, you will need a Functions category. Do you want to add "
                                           + "a Functions category to your custom toolbox?"))
                        {
                            controller.setMode(WorkspaceFactoryController.MODE_TOOLBOX);
                            controller.loadCategoryByName("functions");
                        }
                    }
                }
            });
        }
Beispiel #23
0
        public static void Main()
        {
            Application application = new Application();

            Window.AddEventListener("load", e => application.Run());
        }
Beispiel #24
0
        public static spriteCanvas CreateScreenCanvas(WebGLRenderingContext webgl, canvasAction useraction)
        {
            var el = webgl.Canvas;

            el.Width  = el.ClientWidth;
            el.Height = el.ClientHeight;

            var c = new spriteCanvas(webgl, webgl.DrawingBufferWidth, webgl.DrawingBufferHeight);

            //var asp = range.width / range.height;
            c.spriteBatcher.matrix = new Float32Array(new float[] {
                1.0f * 2 / c.width, 0, 0, 0,    //去掉asp的影响
                0, 1 * -1 * 2 / c.height, 0, 0,
                0, 0, 1, 0,
                -1, 1, 0, 1
            });
            c.spriteBatcher.ztest = false;//最前不需要ztest

            var ua = useraction;

            Bridge.Html5.Window.SetInterval(() =>
            {
                webgl.Viewport(0, 0, webgl.DrawingBufferWidth, webgl.DrawingBufferHeight);
                webgl.Clear(webgl.COLOR_BUFFER_BIT | webgl.DEPTH_BUFFER_BIT);
                webgl.ClearColor(1.0, 0.0, 1.0, 1.0);

                c.spriteBatcher.begindraw();

                ua.ondraw(c);

                c.spriteBatcher.enddraw();

                //dynamic _webgl = webgl;
                //_webgl.flush();
                //webgl.Flush();
            }, 20);
            Window.AddEventListener("resize", () =>
            {
                var sel    = webgl.Canvas;
                sel.Width  = sel.ClientWidth;
                sel.Height = sel.ClientHeight;
                sel.Width  = sel.ClientWidth;
                sel.Height = sel.ClientHeight;

                c.width  = sel.Width;
                c.height = sel.Height;
                c.spriteBatcher.matrix = new Float32Array(new float[] {
                    1.0f * 2 / c.width, 0, 0, 0,//去掉asp的影响
                    0, 1.0f * -1 * 2 / c.height, 0, 0,
                    0, 0, 1, 0,
                    -1, 1, 0, 1
                });
                ////do resize func
                ua.onresize(c);
            });


            el.OnMouseMove = (ev) =>
            {
                ua.onpointevent(c, canvaspointevent.POINT_MOVE, (float)ev["offsetX"], (float)ev["offsetY"]);
            };
            el.OnMouseUp = (MouseEvent <HTMLCanvasElement> ev) =>
            {
                ua.onpointevent(c, canvaspointevent.POINT_UP, (float)ev["offsetX"], (float)ev["offsetY"]);
            };
            el.OnMouseDown = (MouseEvent <HTMLCanvasElement> ev) =>
            {
                ua.onpointevent(c, canvaspointevent.POINT_DOWN, (float)ev["offsetX"], (float)ev["offsetY"]);
            };
            //scene.onPointerObservable.add((pinfo: BABYLON.PointerInfo, state: BABYLON.EventState) =>
            //{
            //    var range = scene.getEngine().getRenderingCanvasClientRect();
            //    //输入
            //    var e: lighttool.canvaspointevent = lighttool.canvaspointevent.NONE;
            //    if (pinfo.type == BABYLON.PointerEventTypes.POINTERDOWN)
            //        e = lighttool.canvaspointevent.POINT_DOWN;
            //    if (pinfo.type == BABYLON.PointerEventTypes.POINTERMOVE)
            //        e = lighttool.canvaspointevent.POINT_MOVE;
            //    if (pinfo.type == BABYLON.PointerEventTypes.POINTERUP)
            //        e = lighttool.canvaspointevent.POINT_UP;

            //    //缩放到canvas size
            //    var x = pinfo.event.offsetX / range.width * c.width;
            //    var y = pinfo.event.offsetY / range.height * c.height;

            //    var skip: boolean = ua.onpointevent(c, e, x, y);
            //    //对 babylon,来说 2d在这里输入,3d 要 pick 以后咯

            //    state.skipNextObservers = skip;//是否中断事件
            //}
            //);

            return(c);
        }
Beispiel #25
0
 /// <summary>
 /// Adds an event listener to the canvas
 /// </summary>
 /// <param name="EventName">The event name (i.e. "click", "keydown", "touchstart" etc.)</param>
 /// <param name="Callback">The code to run when the event is triggered</param>
 public static void AddEvent(string EventName, Action <Event> Callback)
 {
     Window.AddEventListener(EventName, Callback);
 }
Beispiel #26
0
 public virtual void Init()
 {
     camera            = new THREE.PerspectiveCamera(60, Width / Height, 1, 1000);
     camera.position.z = 500;
     Window.AddEventListener("resize", this.onWindowResize, false);
 }
Beispiel #27
0
        /// <summary>
        /// Initialize Blockly and layout.  Called on page load.
        /// </summary>
        public void init()
        {
            // Block Factory has a dependency on bits of Closure that core Blockly
            // doesn't have. When you run this from file:// without a copy of Closure,
            // it breaks it non-obvious ways.  Warning about this for now until the
            // dependency is broken.
            // TODO: #668.
            if (!goog.dom.xml.isNotDefined())
            {
                Window.Alert("Sorry: Closure dependency not found. We are working on removing " +
                             "this dependency.  In the meantime, you can use our hosted demo\n " +
                             "https://blockly-demo.appspot.com/static/demos/blockfactory/index.html" +
                             "\nor use these instructions to continue running locally:\n" +
                             "https://developers.google.com/blockly/guides/modify/web/closure");
                return;
            }

            var self = this;

            // Handle Blockly Storage with App Engine.
            if (BlocklyStorage.InWindow())
            {
                this.initializeBlocklyStorage();
            }

            // Assign click handlers.
            this.assignExporterClickHandlers();
            this.assignLibraryClickHandlers();
            this.assignBlockFactoryClickHandlers();
            // Hide and show the block library dropdown.
            Document.GetElementById("modalShadow").AddEventListener("click",
                                                                    new Action(() => {
                self.closeModal();
            }));

            this.onresize(null);
            Window.AddEventListener("resize", new Action(() => {
                self.onresize(null);
            }));

            // Inject Block Factory Main Workspace.
            var toolbox = Document.GetElementById("blockfactory_toolbox");

            BlockFactory.mainWorkspace = Blockly.Core.inject("blockly", new Dictionary <string, object> {
                { "collapse", false },
                { "toolbox", toolbox },
                { "media", "../../media/" }
            });

            // Add tab handlers for switching between Block Factory and Block Exporter.
            this.addTabHandlers(this.tabMap);

            // Assign exporter change listeners.
            this.assignExporterChangeListeners();

            // Create the root block on Block Factory main workspace.
            if (BlocklyStorage.InWindow() && Window.Location.Hash != null && Window.Location.Hash.Length > 1)
            {
                BlocklyStorage.retrieveXml(Window.Location.Hash.Substring(1),
                                           BlockFactory.mainWorkspace);
            }
            else
            {
                BlockFactory.showStarterBlock();
            }
            BlockFactory.mainWorkspace.clearUndo();

            // Add Block Factory event listeners.
            this.addBlockFactoryEventListeners();

            // Workspace Factory init.
            WorkspaceFactoryInit.initWorkspaceFactory(this.workspaceFactoryController);
        }