public void Initialize(CommonDX.DeviceManager deviceManager)
        {

            _deviceManager = deviceManager;
            _d2dContext = deviceManager.ContextDirect2D;

            _generalGrayColor = new SharpDX.Direct2D1.SolidColorBrush(_deviceManager.ContextDirect2D, Color.Gray);
            _generalRedColor = new SharpDX.Direct2D1.SolidColorBrush(_deviceManager.ContextDirect2D, Color.Red);
            _generalLightGrayColor = new SharpDX.Direct2D1.SolidColorBrush(_deviceManager.ContextDirect2D, Color.LightGray);
            _generalLightWhiteColor = new SharpDX.Direct2D1.SolidColorBrush(_deviceManager.ContextDirect2D, Color.White);

            _generalTextFormat = new SharpDX.DirectWrite.TextFormat(
                _deviceManager.FactoryDirectWrite,
                "Segoe UI",
                SharpDX.DirectWrite.FontWeight.Light,
                SharpDX.DirectWrite.FontStyle.Normal,
                SharpDX.DirectWrite.FontStretch.Normal,
                16f);

            _debugTextFormat = new SharpDX.DirectWrite.TextFormat(
                _deviceManager.FactoryDirectWrite,
                "Segoe UI",
                SharpDX.DirectWrite.FontWeight.Light,
                SharpDX.DirectWrite.FontStyle.Normal,
                SharpDX.DirectWrite.FontStretch.Normal,
                20f);

            _layoutDetail = new LayoutDetail() { Width = this.State.DrawingSurfaceWidth, Height = this.State.DrawingSurfaceHeight };
            _layoutDeviceScreenSize = new RectangleF(0, 0, (float)_layoutDetail.Width, (float)_layoutDetail.Height);
            _appWidth = (float)_layoutDetail.Width + 5;
            _appHeight = (float)_layoutDetail.Height;

            _updateScaleTranslate(1.0f);


            ////_drawTiles(0);
            if (State.DefaultBackgroundUri != string.Empty) { 
                _clearRenderTree();
                _changeBackgroundImpl(1, _appWidth, _appHeight, 0, 0, State.DefaultBackgroundFolder, State.DefaultBackgroundUri, "", Color.White, 0.7f, "", false);
            }

            //GestureService.OnGestureRaised += (o,a) => {
            //    CustomGestureArgs gestureArgs = (CustomGestureArgs)a;
            //    //NumberFramesToRender += 3;
            //    if (gestureArgs.ManipulationStartedArgs != null)
            //    {
            //        _isInertialTranslationStaging = false;
            //        _globalCameraTranslationStaging = _globalCameraTranslation;
            //    }
            //    else if (gestureArgs.ManipulationInertiaStartingArgs != null)
            //    {
            //        _isInertialTranslationStaging = true;
            //        _globalCameraTranslationStaging = _globalCameraTranslation;
            //    }
            //    else if (gestureArgs.ManipulationUpdatedArgs != null)
            //    {
            //        if(_isInertialTranslationStaging)
            //            _updateCameraTranslationStaging((float)gestureArgs.ManipulationUpdatedArgs.Velocities.Linear.X);
            //        else
            //            _updateCameraTranslationStaging((float)gestureArgs.ManipulationUpdatedArgs.Cumulative.Translation.X);
            //    }
            //    else if (gestureArgs.ManipulationCompletedArgs != null)
            //    {
            //        if (gestureArgs.ManipulationCompletedArgs.Cumulative.Scale < 1)
            //        {
            //            if (_globalScale.X != 0.9f) { _updateBackgroundTweener(1.0f, 0.9f, 1.2f); SendInformationNotification("zoom level at 90%", 3); }
            //            //_updateScaleTranslate(0.9f);
            //        }
            //        else if (gestureArgs.ManipulationCompletedArgs.Cumulative.Scale > 1)
            //        {
            //            if (_globalScale.X != 1.0f) { _updateBackgroundTweener(0.9f, 1.0f, 1.2f); SendInformationNotification("zoom level at 100%", 3); }
            //            //_updateScaleTranslate(1.0f);
            //        }

            //        _globalCameraTranslation = _globalCameraTranslation + _globalCameraTranslationStaging;
            //        _globalCameraTranslationStaging = Vector3.Zero;
            //        _isInertialTranslationStaging = false;

            //    }
            //    else if (gestureArgs.TappedEventArgs != null)
            //    {
            //        var x = gestureArgs.TappedEventArgs.Position.X - _globalCameraTranslation.X;
            //        var y = gestureArgs.TappedEventArgs.Position.Y - _globalCameraTranslation.Y;

            //        var found = _doTilesHitTest((float)x, (float)y);
            //        if (found != null && found.Count > 0)
            //        {
            //            _selectedRect = found[0];
            //        }
            //        else _selectedRect = null;
            //    }
            //};


            WindowLayoutService.OnWindowLayoutRaised += WindowLayoutService_OnWindowLayoutRaised;


        }
        public void Render(CommonDX.TargetBase target)
        {
            var d2dContext = _d2dContext; //target.DeviceManager.ContextDirect2D;
            var d2dDevice = target.DeviceManager.DeviceDirect2D;

            var d3dContext = target.DeviceManager.ContextDirect3D;
            var d3dDevice = target.DeviceManager.DeviceDirect3D;




            if (NumberFramesToRender > 0)
            {
                //TurnOffRenderingBecauseThereAreRenderableEffects();

                _useStagingBitmap = false;


                var _tempTarget = d2dContext.Target;
                d2dContext.Target = _stagingBitmap;

                d2dContext.BeginDraw();

                //if (_doClear) {
                //d2dContext.Clear(Color.White);
                d2dContext.Clear( new Color4(0, 0, 0, 0)); 
                //    _doClear = false; 
                //}


                foreach (var renderTree in _renderTree.OrderBy(x => x.Order))
                {

                    if (renderTree.Type == eRenderType.Effect && renderTree.EffectDTO.IsRenderable && !renderTree.HasLinkedEffects) //effects
                    {
                        if (renderTree.EffectDTO.Effect != null)
                        {
                            d2dContext.Transform =
                                //Matrix.Identity
                                Matrix.Scaling(renderTree.EffectDTO.MainScale)
                                * Matrix.Translation(renderTree.EffectDTO.MainTranslation)

                                //* Matrix.Scaling(_globalScale)
                                //* Matrix.Translation(_globalTranslation)
                                ;
                            d2dContext.DrawImage(renderTree.EffectDTO.Effect);
                        }
                    }
                    else if (renderTree.Type == eRenderType.Text && renderTree.TextDTO.IsRenderable) //text
                    {
                        d2dContext.Transform =
                            Matrix.Scaling(renderTree.TextDTO.MainScale)
                            * Matrix.Translation(renderTree.TextDTO.MainTranslation)

                            //* Matrix.Scaling(_globalScale)
                            //* Matrix.Translation(_globalTranslation)
                            ;

                        d2dContext.DrawText(renderTree.TextDTO.Text, renderTree.TextDTO.TextFormat, renderTree.TextDTO.LayoutRect, renderTree.TextDTO.Brush);
                    }
                    else if (renderTree.Type == eRenderType.Media && renderTree.MediaDTO.IsRenderable) //video/audio
                    {

                    }
                    else if (renderTree.Type == eRenderType.Shape && renderTree.ShapeDTO.IsRenderable) //Geometry
                    {

                        d2dContext.Transform =
                            //Matrix.Identity
                            Matrix.Scaling(renderTree.ShapeDTO.MainScale)
                            * Matrix.Translation(renderTree.ShapeDTO.MainTranslation)

                            //* Matrix.Scaling(_globalScale)
                            //* Matrix.Translation(_globalTranslation)
                            ;



                        if (renderTree.ShapeDTO.Type == 2)
                            d2dContext.FillGeometry(renderTree.ShapeDTO.Shape, renderTree.ShapeDTO.Brush);
                        else
                            d2dContext.DrawGeometry(
                                renderTree.ShapeDTO.Shape,
                                renderTree.ShapeDTO.Brush,
                                renderTree.ShapeDTO.StrokeWidth,
                                new SharpDX.Direct2D1.StrokeStyle(
                                    _deviceManager.FactoryDirect2D, //target.DeviceManager.FactoryDirect2D,
                                    new SharpDX.Direct2D1.StrokeStyleProperties()
                                    {
                                        DashStyle = (SharpDX.Direct2D1.DashStyle)renderTree.ShapeDTO.DashStyleIndex,
                                        DashOffset = renderTree.ShapeDTO.DashOffset,
                                        StartCap = SharpDX.Direct2D1.CapStyle.Square,
                                        EndCap = SharpDX.Direct2D1.CapStyle.Square,
                                        DashCap = SharpDX.Direct2D1.CapStyle.Square,
                                        MiterLimit = renderTree.ShapeDTO.MiterLimit
                                    }));


                    }
                    else if (renderTree.Type == eRenderType.ShapePath && renderTree.ShapePathDTO.IsRenderable) //ShapePath Geometry
                    {
                        d2dContext.Transform =
                            //Matrix.Identity
                            Matrix.Scaling(renderTree.ShapePathDTO.MainScale)
                            * Matrix.RotationX(renderTree.ShapePathDTO.MainRotation.X)
                            * Matrix.RotationY(renderTree.ShapePathDTO.MainRotation.Y)
                            * Matrix.RotationZ(renderTree.ShapePathDTO.MainRotation.Z)
                            * Matrix.Translation(renderTree.ShapePathDTO.MainTranslation)

                            //* Matrix.Scaling(_globalScale)
                            //* Matrix.Translation(_globalTranslation)
                            ;


                        d2dContext.DrawGeometry(
                         renderTree.ShapePathDTO.Shapes[0],
                         renderTree.ShapePathDTO.Brush,
                         renderTree.ShapePathDTO.StrokeWidth,
                         new SharpDX.Direct2D1.StrokeStyle(
                             _deviceManager.FactoryDirect2D,//target.DeviceManager.FactoryDirect2D,
                             new SharpDX.Direct2D1.StrokeStyleProperties()
                             {
                                 DashStyle = (SharpDX.Direct2D1.DashStyle)renderTree.ShapePathDTO.DashStyleIndex,
                                 DashOffset = renderTree.ShapePathDTO.DashOffset,
                                 StartCap = SharpDX.Direct2D1.CapStyle.Square,
                                 EndCap = SharpDX.Direct2D1.CapStyle.Square,
                                 DashCap = SharpDX.Direct2D1.CapStyle.Square,
                                 MiterLimit = renderTree.ShapePathDTO.MiterLimit
                             }));

                    }
                }


                d2dContext.Target = _tempTarget;


                d2dContext.EndDraw();

                NumberFramesToRender--;
            }
            else
            {
                _useStagingBitmap = true;
            }
            

            d2dContext.BeginDraw();

            d2dContext.Clear(Color.White);
            
            if (_useStagingBitmap)
            {
                
                d2dContext.Transform =
                    Matrix.Scaling(_globalScale)
                    * Matrix.Translation(_globalTranslation);

                d2dContext.DrawImage(_stagingBitmap);
                
            }


            //SELECTED TILE
            _drawSelectedTile(d2dContext);

            //DESIGNER SURFACE REGION
            //_drawDesktopOutline(d2dContext);

            //DEBUGGING INFO
            //_drawDebuggingInfo(d2dContext);

            d2dContext.EndDraw();

        }
Exemplo n.º 3
0
 public void Render(CommonDX.TargetBase target)
 {
     Render(target.DeviceManager.ContextDirect2D);
 }