public void run()
            {
                LayoutFramework.CanvasItemFactory.setFactory(new BasicWindow.CanvasItemFactory());

                canvas = new CanvasCreator().createCanvas(width, height, "{DIFF}");

                layoutRenderer = new LayoutRenderer(canvas);

                rootLayout = new LayoutLoader().loadLayout();

                canvas.subscribeToKeyPress((LayoutFramework.Keys.Key keyPressed) => {
                    lock (lockObj)
                    {
                        KeyboardEvent keyEvent = new KeyboardEvent();
                        keyEvent.keyPressed    = keyPressed;
                        Keyboard.notifyKeyPressed(keyPressed);
                        if (calculatedTree != null)
                        {
                            reactiveLayout.handleKeyboardInput(keyEvent);
                        }
                    }
                });

                canvas.subscribeToKeyRelease((LayoutFramework.Keys.Key keyPressed) => {
                    lock (lockObj)
                    {
                        Keyboard.notifyKeyUp(keyPressed);
                    }
                });

                canvas.subscribeToMouseClicks((int x, int y) =>
                {
                    lock (lockObj)
                    {
                        MouseEvent motionEvent  = new MouseEvent();
                        motionEvent.eventType   = MotionType.DOWN;
                        motionEvent.coordinates = new Point(x, y);
                        if (calculatedTree != null)
                        {
                            reactiveLayout.handleMouseEvent(calculatedTree, motionEvent);
                        }
                    }
                });

                canvas.subscribeToMouseUp((int x, int y) =>
                {
                    lock (this)
                    {
                        MouseEvent motionEvent  = new MouseEvent();
                        motionEvent.eventType   = MotionType.UP;
                        motionEvent.coordinates = new Point(x, y);
                        if (calculatedTree != null)
                        {
                            reactiveLayout.handleMouseEvent(calculatedTree, motionEvent);
                        }
                    }
                });

                canvas.subscribeToMouseMove((int x, int y) =>
                {
                    lock (this)
                    {
                        MouseEvent motionEvent  = new MouseEvent();
                        motionEvent.eventType   = MotionType.MOVE;
                        motionEvent.coordinates = new Point(x, y);
                        if (calculatedTree != null)
                        {
                            reactiveLayout.handleMouseEvent(calculatedTree, motionEvent);
                        }
                    }
                });

                canvas.subscribeToFrameUpdates(() =>
                {
                    lock (this)
                    {
                        TaskRunner.RunTasks();
                        MeasuredLayout result = rootLayout.getMeasuredLayout(getWindowBounds());
                        layoutRenderer.drawTree(result);
                        calculatedTree = result;
                    }
                });

                canvas.Run();
            }
Exemple #2
0
 public static void Run(Action action)
 {
     TaskRunner.addAction(action);
 }