Beispiel #1
0
        private void Initialize()
        {
            // add canvas layers to root layout
            for (int i = 0; i < _view.Layers.Count; i++)
            {
                Layout.Children.Add(_view.Layers[i].Native as UIElement);
            }

            // create grid canvas
            _view.CreateGrid(600.0, 600.0, 30.0, 0.0, 0.0);

            // handle keyboard input
            PreviewKeyDown += (sender, e) =>
            {
                Action action;
                bool   result = _shortcuts.TryGetValue(
                    new Tuple <Key, ModifierKeys>(e.Key, Keyboard.Modifiers),
                    out action);

                if (result == true && action != null)
                {
                    action();
                }
            };

            // set data context
            DataContext = _view.Layers.LastOrDefault();
        }
Beispiel #2
0
        private void Initialize()
        {
            var panel = _view.Layers.LastOrDefault().Native as WinFormsCanvasPanel;

            // add canvas panel to root layout, same panel is used for all layers
            this.SuspendLayout();
            this.Controls.Add(panel);
            this.ResumeLayout(false);

            // focus panel to enable mouse wheel event
            panel.Select();

            // create grid canvas
            _view.CreateGrid(600.0, 600.0, 30.0, 0.0, 0.0);

            // handle keyboard input
            panel.KeyDown += (sender, e) =>
            {
                Action action;
                bool   result = _shortcuts.TryGetValue(
                    new Tuple <Keys, Keys>(e.KeyCode, e.Modifiers),
                    out action);

                if (result == true && action != null)
                {
                    action();
                }
            };

            // open file dialog
            this.openFileDialog1.FileOk += (sender, e) =>
            {
                string path        = openFileDialog1.FileName;
                int    filterIndex = openFileDialog1.FilterIndex;
                _view.Open(path, filterIndex - 1);
                _view.Render();
            };

            // save file dialog
            this.saveFileDialog1.FileOk += (sender, e) =>
            {
                string path        = saveFileDialog1.FileName;
                int    filterIndex = saveFileDialog1.FilterIndex;
                _view.Save(path, filterIndex - 1);
            };

            // export file dialog
            this.saveFileDialog2.FileOk += (sender, e) =>
            {
                string path        = saveFileDialog2.FileName;
                int    filterIndex = saveFileDialog2.FilterIndex;
                _view.Export(path, filterIndex - 1);
            };

            // draw canvas panel
            _view.Render();
        }
Beispiel #3
0
        public void Initialize(Context context)
        {
            Holder.AddCallback(this);
            SetWillNotDraw(true);

            _touch   = Observable.FromEventPattern <TouchEventArgs>(this, "Touch").Select(e => e.EventArgs.Event);
            _touches = _touch.Subscribe((e) => OnTouch(e));

            Renderer = new SurfaceRenderer();
            View     = new DrawingView(
                new Assembly[]
            {
                typeof(Bootstrapper).GetTypeInfo().Assembly,
                typeof(CanvasView).GetTypeInfo().Assembly
            });

            var canvas = View.Layers.LastOrDefault();

            canvas.Downs = Observable.FromEventPattern <Android.Views.View.TouchEventArgs>(this, "Touch")
                           .Where(e => (e.EventArgs.Event.Action & MotionEventActions.Mask) == MotionEventActions.Down && e.EventArgs.Event.PointerCount == 1)
                           .Select(e =>
            {
                float px = e.EventArgs.Event.GetX();
                float py = e.EventArgs.Event.GetY();

                double x = canvas.EnableSnap ?
                           canvas.Snap(px - Renderer.PanX, canvas.SnapX * Renderer.Zoom) : px - Renderer.PanX;

                double y = canvas.EnableSnap ?
                           canvas.Snap(py - Renderer.PanY, canvas.SnapY * Renderer.Zoom) : py - Renderer.PanY;

                x /= Renderer.Zoom;
                y /= Renderer.Zoom;

                return(new Vector2(x, y));
            });

            canvas.Ups = Observable.FromEventPattern <Android.Views.View.TouchEventArgs>(this, "Touch")
                         .Where(e => (e.EventArgs.Event.Action & MotionEventActions.Mask) == MotionEventActions.Up && e.EventArgs.Event.PointerCount == 1)
                         .Select(e =>
            {
                float px = e.EventArgs.Event.GetX();
                float py = e.EventArgs.Event.GetY();

                double x = canvas.EnableSnap ?
                           canvas.Snap(px - Renderer.PanX, canvas.SnapX * Renderer.Zoom) : px - Renderer.PanX;

                double y = canvas.EnableSnap ?
                           canvas.Snap(py - Renderer.PanY, canvas.SnapY * Renderer.Zoom) : py - Renderer.PanY;

                x /= Renderer.Zoom;
                y /= Renderer.Zoom;

                return(new Vector2(x, y));
            });

            canvas.Moves = Observable.FromEventPattern <Android.Views.View.TouchEventArgs>(this, "Touch")
                           .Where(e => (e.EventArgs.Event.Action & MotionEventActions.Mask) == MotionEventActions.Move && e.EventArgs.Event.PointerCount == 1)
                           .Select(e =>
            {
                float px = e.EventArgs.Event.GetX();
                float py = e.EventArgs.Event.GetY();

                double x = canvas.EnableSnap ?
                           canvas.Snap(px - Renderer.PanX, canvas.SnapX * Renderer.Zoom) : px - Renderer.PanX;

                double y = canvas.EnableSnap ?
                           canvas.Snap(py - Renderer.PanY, canvas.SnapY * Renderer.Zoom) : py - Renderer.PanY;

                x /= Renderer.Zoom;
                y /= Renderer.Zoom;

                return(new Vector2(x, y));
            });

            canvas.Native = this;

            View.Initialize();

            // background layer
            View.Layers[0].Background.A = 0xFF;
            View.Layers[0].Background.R = 0xFF;
            View.Layers[0].Background.G = 0xFF;
            View.Layers[0].Background.B = 0xFF;

            // drawing layer
            View.Layers[1].Background.A = 0xFF;
            View.Layers[1].Background.R = 0xF5;
            View.Layers[1].Background.G = 0xF5;
            View.Layers[1].Background.B = 0xF5;

            View.CreateGrid(600.0, 600.0, 30.0, 0.0, 0.0);
        }