Exemplo n.º 1
0
        public bool RenderGauge()
        {
            try
            {
                if (device != null && !DX_reinit)
                {
                    Single brushAngle = (Int32)(m_BaseArcStart + (m_value - m_MinValue) * m_BaseArcSweep /
                                                (m_MaxValue - m_MinValue)) % 360;
                    Double needleAngle = brushAngle * Math.PI / 180;
                    verts1[0].X = (float)(Center.X + m_NeedleRadius / 4 * Math.Cos(needleAngle));
                    verts1[0].Y = (float)(Center.Y + m_NeedleRadius / 4 * Math.Sin(needleAngle));
                    verts1[1].X = (float)(Center.X + m_NeedleRadius * Math.Cos(needleAngle));
                    verts1[1].Y = (float)(Center.Y + m_NeedleRadius * Math.Sin(needleAngle));

                    device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black.ToArgb(), 0.0f, 0);
                    sprite.Begin(SpriteFlags.AlphaBlend);

                    if (BackgroundTexture != null)
                    {
                        sprite.Draw(BackgroundTexture, texture_size, (Color4)Color.White);
                    }

                    sprite.End();
                    //Begin the scene
                    device.BeginScene();
                    device.SetRenderState(RenderState.AlphaBlendEnable, true);
                    device.SetRenderState(RenderState.SourceBlend, SlimDX.Direct3D9.Blend.SourceAlpha);
                    device.SetRenderState(RenderState.DestinationBlend, SlimDX.Direct3D9.Blend.DestinationAlpha);
                    line.Draw(verts1, Color.Red);
                    device.EndScene();
                    device.Present();
                    return(true);
                }

                if (DX_reinit)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Debug.Write(ex.ToString());

                if (DX_reinit)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
        public void DrawFilledBox(float x, float y, float w, float h, Color4 Color)
        {
            x += shiftX;
            y += shiftY;
            var vLine = new Vector2[2];

            line.GLLines   = true;
            line.Antialias = true;
            line.Width     = w;

            vLine[0].X = x + w / 2;
            vLine[0].Y = y;
            vLine[1].X = x + w / 2;
            vLine[1].Y = y + h;

            line.Draw(vLine, Color);
        }
        // DrawControl2D
        internal void DrawControl2D(string Title, int SizeX, int SizeY, int PosX, int PosY, System.Drawing.Color TitleTextColor, System.Drawing.Color TitleColor, System.Drawing.Color BackgroundColor, System.Drawing.Color BorderColor)
        {
            int num  = 18;
            int num2 = PosY + 1;

            if (SizeY >= 18)
            {
                // Draw Header
                SlimDX.Direct3D9.Line line = new SlimDX.Direct3D9.Line(D3D.Device);
                List <SlimDX.Vector2> list = new List <SlimDX.Vector2>();
                for (int i = 0; i < num; i++)
                {
                    list.Add(new SlimDX.Vector2((float)PosX, (float)num2));
                    list.Add(new SlimDX.Vector2((float)(PosX + SizeX), (float)num2));
                    num2++;
                }
                line.Draw(list.ToArray(), TitleColor);


                // Draw Title
                DrawString2D(Title, PosX + 4, PosY + 1, TitleTextColor);

                // Draw Background
                List <SlimDX.Vector2> list2 = new List <SlimDX.Vector2>();
                for (int j = num; j < SizeY; j++)
                {
                    list2.Add(new SlimDX.Vector2((float)PosX, (float)num2));
                    list2.Add(new SlimDX.Vector2((float)(PosX + SizeX), (float)num2));
                    num2++;
                }
                line.Draw(list2.ToArray(), BackgroundColor);

                // Draw top border
                SlimDX.Vector2[] vertexList = new SlimDX.Vector2[] { new SlimDX.Vector2((float)PosX, (float)PosY), new SlimDX.Vector2((float)(PosX + SizeX), (float)PosY) };
                line.Draw(vertexList, BorderColor);

                // Draw bottom border
                SlimDX.Vector2[] vectorArray2 = new SlimDX.Vector2[] { new SlimDX.Vector2((float)PosX, (float)(PosY + SizeY)), new SlimDX.Vector2((float)((PosX + SizeX) + 1), (float)(PosY + SizeY)) };
                line.Draw(vectorArray2, BorderColor);

                // Draw right border
                SlimDX.Vector2[] vectorArray3 = new SlimDX.Vector2[] { new SlimDX.Vector2((float)(PosX + SizeX), (float)PosY), new SlimDX.Vector2((float)(PosX + SizeX), (float)(PosY + SizeY)) };
                line.Draw(vectorArray3, BorderColor);

                // Draw left border
                SlimDX.Vector2[] vectorArray4 = new SlimDX.Vector2[] { new SlimDX.Vector2((float)PosX, (float)PosY), new SlimDX.Vector2((float)PosX, (float)(PosY + SizeY)) };
                line.Draw(vectorArray4, BorderColor);

                // Dispose
                line.Dispose();
            }
        }
Exemplo n.º 4
0
        public int CompositeImage(IntPtr pD3DDevice, IntPtr pddsRenderTarget, AMMediaType pmtRenderTarget, long rtStart, long rtEnd, int dwClrBkGnd, VMR9VideoStreamInfo[] pVideoStreamInfo, int cStreams)
        {
            try
            {
                // Just in case the filter call CompositeImage before InitCompositionDevice (this sometime occure)
                if (unmanagedDevice != pD3DDevice)
                {
                    SetManagedDevice(pD3DDevice);
                }

                // Create a managed Direct3D surface (the Render Target) from the unmanaged pointer.
                // The constructor don't call IUnknown.AddRef but the "destructor" seem to call IUnknown.Release
                // Direct3D seem to be happier with that according to the DirectX log
                Marshal.AddRef(pddsRenderTarget);
                Surface            renderTarget     = Surface.FromPointer(pddsRenderTarget);
                SurfaceDescription renderTargetDesc = renderTarget.Description;
                Rectangle          renderTargetRect = new Rectangle(0, 0, renderTargetDesc.Width, renderTargetDesc.Height);

                // Same thing for the first video surface
                // WARNING : This Compositor sample only use the video provided to the first pin.
                Marshal.AddRef(pVideoStreamInfo[0].pddsVideoSurface);
                Surface            surface     = Surface.FromPointer(pVideoStreamInfo[0].pddsVideoSurface);
                SurfaceDescription surfaceDesc = surface.Description;
                Rectangle          surfaceRect = new Rectangle(0, 0, surfaceDesc.Width, surfaceDesc.Height);


                // Set the device's render target (this doesn't seem to be needed)
                device.SetRenderTarget(0, renderTarget);

                // Copy the whole video surface into the render target
                // it's a de facto surface cleaning...
                device.StretchRectangle(surface, surfaceRect, renderTarget, renderTargetRect, TextureFilter.None);

                // sprite's methods need to be called between device.BeginScene and device.EndScene
                device.BeginScene();

                // Init the sprite engine for AlphaBlending operations
                sprite.Begin(SpriteFlags.AlphaBlend | SpriteFlags.DoNotSaveState);

                //mouse
                if (_mouseTrack != null)
                {
                    if (_mouseTrack.Count > 1)
                    {
                        if (_mouseTrackDraw)
                        {
                            _d3dMouseTrackLine.Width = _mouseTrackLineWidth;
                            _d3dMouseTrackLine.Begin();
                            _d3dMouseTrackLine.Draw(_mouseTrack.ToArray(), _mouseTrackColor);
                            _d3dMouseTrackLine.End();
                        }
                    }
                    if (_mouseTrack.Count > 0)
                    {
                        if (_mouseCursorCircleDraw)
                        {
                            _d3dMouseCursorCircleLine.Width = _mouseCursorCircleLineWidth;
                            _d3dMouseCursorCircleLine.Begin();
                            _d3dMouseCursorCircleLine.Draw(InitCircle(100, _mouseTrack[_mouseTrack.Count - 1], 50), _mouseCursorCircleColor);
                            _d3dMouseCursorCircleLine.End();
                        }

                        if (_mouseCursorDraw)
                        {
                            Vector3 cursorPos = new Vector3(_mouseTrack[_mouseTrack.Count - 1], 0.5f);
                            sprite.Draw(_mouseCursorTex, Vector3.Zero, cursorPos, Color.White);
                        }
                    }
                }
                if (_mouseFixationDraw && _mouseFixation != null)
                {
                    if (_mouseFixation.Count > 0)
                    {
                        List <Vector2> scanpath = new List <Vector2>();
                        for (int i = 0; i < _mouseFixation.Count; i++)
                        {
                            //Fixation
                            _d3dMouseFixationLine.Width = _mouseFixationLineWidth;
                            _d3dMouseFixationLine.Begin();
                            _d3dMouseFixationLine.Draw(InitCircle(100, _mouseFixation[i].fixation, _mouseFixation[i].fsize), _mouseFixationColor);
                            _d3dMouseFixationLine.End();

                            //ScanPath
                            scanpath.Add(_mouseFixation[i].fixation);
                            if (i >= 1 && _mouseScanpathDraw)
                            {
                                _d3dMouseScanpathLine.Width = _mouseScanpathLineWidth;
                                _d3dMouseScanpathLine.Begin();
                                _d3dMouseScanpathLine.Draw(scanpath.ToArray(), _mouseScanpathColor);
                                _d3dMouseScanpathLine.End();
                            }

                            //Fixation ID
                            if (_mouseFixationIDDraw)
                            {
                                _d3dMouseFixtionFont.DrawString(sprite, (i + 1).ToString(), new Rectangle(new Point((int)_mouseFixation[i].fixation.X, (int)_mouseFixation[i].fixation.Y), new Size(50, 50)), 0, _mouseFixationIDColor);
                            }
                        }
                    }
                }
                //gaze
                if (_gazeTrack != null)
                {
                    if (_gazeTrack.Count > 1)
                    {
                        if (_gazeTrackDraw)
                        {
                            _d3dGazeTrackLine.Width = _gazeTrackLineWidth;
                            _d3dGazeTrackLine.Begin();
                            _d3dGazeTrackLine.Draw(_gazeTrack.ToArray(), _gazeTrackColor);
                            _d3dGazeTrackLine.End();
                        }
                    }
                    if (_gazeTrack.Count > 0)
                    {
                        if (_gazeCursorCircleDraw)
                        {
                            _d3dGazeCursorCircleLine.Width = _gazeCursorCircleLineWidth;
                            _d3dGazeCursorCircleLine.Begin();
                            _d3dGazeCursorCircleLine.Draw(InitCircle(100, _gazeTrack[_gazeTrack.Count - 1], 50), _gazeCursorCircleColor);
                            _d3dGazeCursorCircleLine.End();
                        }

                        if (_gazeCursorDraw)
                        {
                            Vector3 cursorPos = new Vector3(_gazeTrack[_gazeTrack.Count - 1], 0.5f);
                            sprite.Draw(_gazeCursorTex, Vector3.Zero, cursorPos, Color.White);
                        }
                    }
                }
                if (_gazeFixationDraw && _gazeFixation != null)
                {
                    if (_gazeFixation.Count > 0)
                    {
                        List <Vector2> scanpath = new List <Vector2>();
                        for (int i = 0; i < _gazeFixation.Count; i++)
                        {
                            //Fixation
                            _d3dGazeFixationLine.Width = _gazeFixationLineWidth;
                            _d3dGazeFixationLine.Begin();
                            _d3dGazeFixationLine.Draw(InitCircle(100, _gazeFixation[i].fixation, _gazeFixation[i].fsize), _gazeFixationColor);
                            _d3dGazeFixationLine.End();

                            //ScanPath
                            scanpath.Add(_gazeFixation[i].fixation);
                            if (i >= 1 && _gazeScanpathDraw)
                            {
                                _d3dGazeScanpathLine.Width = _gazeScanpathLineWidth;
                                _d3dGazeScanpathLine.Begin();
                                _d3dGazeScanpathLine.Draw(scanpath.ToArray(), _gazeScanpathColor);
                                _d3dGazeScanpathLine.End();
                            }
                            //Fixation ID
                            if (_gazeFixationIDDraw)
                            {
                                _d3dGazeFixtionFont.DrawString(sprite, (i + 1).ToString(), new Rectangle(new Point((int)_gazeFixation[i].fixation.X, (int)_gazeFixation[i].fixation.Y), new Size(50, 50)), 0, _gazeFixationIDColor);
                            }
                        }
                    }
                }


                // End the spite engine (drawings take place here)
                sprite.Flush();
                sprite.End();


                // End the sceen.
                device.EndScene();

                // No Present requiered because the rendering is on a render target...
                // device.Present();

                // Dispose the managed surface
                surface.Dispose();
                surface = null;

                // and the managed render target
                renderTarget.Dispose();
                renderTarget = null;
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
            }

            // return a success to the filter
            return(0);
        }
Exemplo n.º 5
0
        void Render(GameTime RenderTime)
        {
            lock (queue)
            {
                if (queue.Count > 0)
                {
                    render = queue.Dequeue();
                }
            }

            spriteRenderer.Begin(SpriteFlags.SortTexture | SpriteFlags.SortDepthFrontToBack | SpriteFlags.AlphaBlend);

            //if (engine.UseTextureFilter)
            //{
            //    device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Anisotropic);
            //    device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Anisotropic);
            //    device.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Anisotropic);
            //}
            //else
            {
                device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Point);
                device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Point);
                device.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Point);
            }

            // TODO engine scale
            spriteRenderer.Transform = SlimDX.Matrix.Scaling(new SlimDX.Vector3(renderScale, renderScale, 1));

            SlimDX.Matrix lineMatrix = SlimDX.Matrix.AffineTransformation2D(1, new SlimDX.Vector2(), 0, new SlimDX.Vector2());
            // TODO engine scale
            //lineMatrix = SlimDX.Matrix.Transformation2D(new SlimDX.Vector2(), 0, new SlimDX.Vector2(engine.Scale.x, engine.Scale.y), new SlimDX.Vector2(), 0, new SlimDX.Vector2());
            lineMatrix = SlimDX.Matrix.Transformation2D(new SlimDX.Vector2(), 0, new SlimDX.Vector2(renderScale, renderScale), new SlimDX.Vector2(), 0, new SlimDX.Vector2());
            lineMatrix = spriteRenderer.Transform;
            lineRenderer.Begin();

            // application render
            engine.MainTarget.elapsed = RenderTime.Elapsed;

            float currentFactor = 1;

            if (render != null)
            {
                foreach (RenderEntity entity in render)
                {
                    if (entity is SpriteEntity)
                    {
                        SpriteEntity sprite = entity as SpriteEntity;
                        // diposed texture links may remain in queue after direct3d reset, just skip them
                        if (sprite.Texture.Disposed)
                        {
                            continue;
                        }

                        // if sprite resolution changed, then update transform matrix
                        if (currentFactor != sprite.Factor)
                        {
                            currentFactor = sprite.Factor;
                            // TODO engine scale
                            //spriteRenderer.Transform = SlimDX.Matrix.Scaling(new SlimDX.Vector3(engine.Scale.x * sprite.Factor, engine.Scale.y * sprite.Factor, 1));
                            spriteRenderer.Transform = SlimDX.Matrix.Scaling(new SlimDX.Vector3(renderScale * sprite.Factor, renderScale * sprite.Factor, 1));
                        }

                        // recompute position for not 1:1 sprite resolutions
                        SlimDX.Vector3 pos = sprite.Position;
                        if (currentFactor != 1)
                        {
                            pos.X /= currentFactor;
                            pos.Y /= currentFactor;
                        }

                        spriteRenderer.Draw(sprite.Texture, sprite.Rectangle, new SlimDX.Vector3(0, 0, 0), pos, sprite.Color);
                    }
                    else if (entity is LineEntity)
                    {
                        LineEntity       line = entity as LineEntity;
                        SlimDX.Vector3[] vec  = new SlimDX.Vector3[] { line.Start, line.End };
                        SlimDX.Vector4[] v    = SlimDX.Vector3.Transform(vec, ref lineMatrix);

                        SlimDX.Vector2[] vec2 = new SlimDX.Vector2[] { new SlimDX.Vector2(v[0].X, v[0].Y), new SlimDX.Vector2(v[1].X, v[1].Y) };
                        lineRenderer.Draw(vec2, line.Color);
                    }
                }
            }

            lineRenderer.End();

            blendOverlay.BlockFadeOut = engine.IsLoading || blockBlend;
            blendOverlay.Render(RenderTime, spriteRenderer);
            if (engine.MusicBlend)
            {
                engine.Music.Volume = 1 - BlendState;
            }
            else
            {
                engine.Music.Volume = 1;
            }

            spriteRenderer.End();

            errorOverlay.Render(RenderTime, spriteRenderer);

            loadingOverlay.Render(RenderTime, spriteRenderer);
        }