예제 #1
0
        public RenderEngine(Control ctrl)
        {
            var present = new PresentParameters(ctrl.ClientSize.Width, ctrl.ClientSize.Height);
            present.PresentationInterval = PresentInterval.One;
            present.BackBufferFormat = Format.A8R8G8B8;
            _Parameters = present;

            _Direct3d = new Direct3D();
            _Device = new Device(_Direct3d, 0,
                DeviceType.Hardware,
                ctrl.Handle,
                CreateFlags.HardwareVertexProcessing,
                present);

            _Device.SetRenderState(RenderState.CullMode, false);
            _Device.SetRenderState(RenderState.ZFunc, Compare.Always);

            _Device.SetTransform(TransformState.View, Matrix.Identity);
            _Device.SetTransform(TransformState.Projection, _Device.GetViewProjectionMatrix());

            _Device.SetRenderState(RenderState.AlphaTestEnable, false);
            _Device.SetRenderState(RenderState.AlphaTestEnable, false);
            _Device.SetRenderState(RenderState.AlphaRef, 0.1f);
            _Device.SetRenderState(RenderState.AlphaFunc, Compare.GreaterEqual);

            _Device.SetRenderState(RenderState.AlphaBlendEnable, true);
            _Device.SetRenderState(RenderState.BlendOperation, BlendOperation.Add);
            _Device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha);
            _Device.SetRenderState(RenderState.DestinationBlend, Blend.InverseSourceAlpha);

            _Effect = Effect.FromString(_Device, Shader.Value, ShaderFlags.None);
            _Effect.SetValue("mat_ViewProj", _Device.GetViewProjectionMatrix());

            _Sprite = new SharpDX.Direct3D9.Sprite(_Device);
        }
예제 #2
0
        public SkillBar(Menu config)
        {
            MenuSkillBar = config.AddSubMenu(new Menu("Cooldown Tracker", "SkillBar"));
            MenuSkillBar.AddItem(new MenuItem("OnAllies", "On Allies").SetValue(false));
            MenuSkillBar.AddItem(new MenuItem("OnEnemies", "On Enemies").SetValue(true));
            Sprite = new Sprite(Drawing.Direct3DDevice);
            HudTexture = Texture.FromMemory(
                Drawing.Direct3DDevice, (byte[]) new ImageConverter().ConvertTo(Resources.main, typeof(byte[])), 127, 41,
                0, Usage.None, Format.A1, Pool.Managed, Filter.Default, Filter.Default, 0);
            FrameLevelTexture = Texture.FromMemory(
                Drawing.Direct3DDevice, (byte[]) new ImageConverter().ConvertTo(Resources.spell_level, typeof(byte[])),
                2, 3, 0, Usage.None, Format.A1, Pool.Managed, Filter.Default, Filter.Default, 0);
            ButtonRedTexture = Texture.FromMemory(
                Drawing.Direct3DDevice, (byte[]) new ImageConverter().ConvertTo(Resources.disable, typeof(byte[])), 14,
                14, 0, Usage.None, Format.A1, Pool.Managed, Filter.Default, Filter.Default, 0);
            SmallText = new Font(
                Drawing.Direct3DDevice,
                new FontDescription
                {
                    FaceName = "Calibri",
                    Height = 13,
                    OutputPrecision = FontPrecision.Default,
                    Quality = FontQuality.Default,
                });

            AppDomain.CurrentDomain.DomainUnload += DomainUnload;
            AppDomain.CurrentDomain.ProcessExit += DomainUnload;
            CustomEvents.Game.OnGameLoad += Game_OnGameLoad;
        }
예제 #3
0
        public BlurComponent(Device graphics, int size)
        {
            _graphics = graphics;

            Dims = size;
            Format = Format.A8R8G8B8;

            _sampleOffsetsHoriz = new Vector4D[SampleCount];
            _sampleOffsetsVert = new Vector4D[SampleCount];

            _sampleWeightsHoriz = new float[SampleCount];
            _sampleWeightsVert = new float[SampleCount];

            int width = Dims - 5;
            int height = Dims - 5;

            SetBlurEffectParameters(1.0f / width, 0, ref _sampleOffsetsHoriz, ref _sampleWeightsHoriz);
            SetBlurEffectParameters(0, 1.0f / height, ref _sampleOffsetsVert, ref _sampleWeightsVert);

            _effect = new GaussianBlurEffect(_graphics);

            OutputTexture = new Texture(_graphics, Dims, Dims, 1, Usage.RenderTarget, Format, Pool.Default);
            _intermediateTexture = new Texture(_graphics, Dims, Dims, 1, Usage.RenderTarget, Format, Pool.Default);

            _sprite = new Sprite(_graphics);
        }
        public Bitmap ConvertToBitmap(string filePath)
        {
            using (var texture = Texture.FromFile(device, filePath)) {
            var surfaceDescription = texture.GetLevelDescription(0);
            var textureWidth = surfaceDescription.Width;
            var textureHeight = surfaceDescription.Height;

            using (var renderTarget = Surface.CreateRenderTarget(device, textureWidth, textureHeight, Format.X8R8G8B8, MultisampleType.None, 0, true)) {
               var oldBackBuffer = device.GetRenderTarget(0);

               device.SetRenderTarget(0, renderTarget);
               using (var sprite = new Sprite(device)) {
                  device.BeginScene();
                  sprite.Begin(SpriteFlags.AlphaBlend);
                  sprite.Draw(texture, new ColorBGRA(Vector4.One));
                  sprite.End();
                  device.EndScene();
               }
               device.SetRenderTarget(0, oldBackBuffer);

               var renderTargetData = renderTarget.LockRectangle(LockFlags.ReadOnly);
               var resultBitmap = new Bitmap(textureWidth, textureHeight);
               var resultData = resultBitmap.LockBits(new Rectangle(0, 0, textureWidth, textureHeight), ImageLockMode.WriteOnly, PixelFormat.Format32bppRgb);
               for (var y = 0; y < textureHeight; y++) {
                  Utilities.CopyMemory(resultData.Scan0 + y * resultData.Stride, renderTargetData.DataPointer + y * renderTargetData.Pitch, textureWidth * 4);
               }
               resultBitmap.UnlockBits(resultData);
               renderTarget.UnlockRectangle();
               return resultBitmap;
            }
             }
        }
예제 #5
0
        public bool Initialise(Device device)
        {
            Debug.Assert(!_initialised);
            if (_initialising)
                return false;

            _initialising = true;

            try
            {

                _device = device;

                _sprite = ToDispose(new Sprite(_device));

                // Initialise any resources required for overlay elements
                IntialiseElementResources();

                _initialised = true;
                return true;
            }
            finally
            {
                _initialising = false;
            }
        }
예제 #6
0
 /// <summary>
 ///     Calculates the center position for the given text on within a rectangle boundaries.
 /// </summary>
 /// <param name="rectangle">Rectangle boundaries</param>
 /// <param name="sprite">Sprite which is being drawn on</param>
 /// <param name="text">The Text</param>
 /// <param name="flags">Centered Flags</param>
 /// <returns>Returns the center position of the text on the rectangle.</returns>
 public static Vector2 GetCenteredText(
     this SharpDX.Rectangle rectangle,
     Sprite sprite,
     string text,
     CenteredFlags flags)
 {
     return rectangle.GetCenter(sprite, Constants.LeagueSharpFont.MeasureText(sprite, text, 0), flags);
 }
예제 #7
0
        public HpBarIndicator()
        {
            dxLine = new Line(dxDevice) { Width = 9 };
            sprite = new Sprite(dxDevice);

            Drawing.OnPreReset += DrawingOnOnPreReset;
            Drawing.OnPostReset += DrawingOnOnPostReset;
            AppDomain.CurrentDomain.DomainUnload += CurrentDomainOnDomainUnload;
            AppDomain.CurrentDomain.ProcessExit += CurrentDomainOnDomainUnload;
        }
예제 #8
0
        public HpBarIndicator()
        {
            dxLine = new Line(dxDevice)
            {
                Width = 9
            };
            sprite = new Sprite(dxDevice);

            Drawing.OnPreReset  += DrawingOnOnPreReset;
            Drawing.OnPostReset += DrawingOnOnPostReset;
            AppDomain.CurrentDomain.DomainUnload += CurrentDomainOnDomainUnload;
            AppDomain.CurrentDomain.ProcessExit  += CurrentDomainOnDomainUnload;
        }
예제 #9
0
        static Sprite()
        {
            // Initialize properties
            Handle = new SharpDX.Direct3D9.Sprite(Drawing.Direct3DDevice);

            // Listen to events
            AppDomain.CurrentDomain.DomainUnload += OnAppDomainUnload;
            AppDomain.CurrentDomain.ProcessExit  += OnAppDomainUnload;
            Drawing.OnEndScene      += OnEndScene;
            Drawing.OnFlushEndScene += OnFlush;
            Drawing.OnPreReset      += OnPreReset;
            Drawing.OnPostReset     += OnPostReset;
        }
예제 #10
0
 static void Game_OnGameLoad(EventArgs args)
 {
     Game.PrintChat("Unban.exe By DZ191 Loaded. Credits to DETUKS");
     sprite = new Sprite(dxDevice);
     taco   = Texture.FromMemory(
         Drawing.Direct3DDevice,
         (byte[])new ImageConverter().ConvertTo(LoadPicture("http://puu.sh/cP1qD/d23cd24220.jpg"), typeof(byte[])), 513, 744, 0,
         Usage.None, Format.A1, Pool.Managed, Filter.Default, Filter.Default, 0);
     Drawing.OnEndScene  += Drawing_OnEndScene;
     Drawing.OnPreReset  += DrawingOnOnPreReset;
     Drawing.OnPostReset += DrawingOnOnPostReset;
     AppDomain.CurrentDomain.DomainUnload += CurrentDomainOnDomainUnload;
     AppDomain.CurrentDomain.ProcessExit  += CurrentDomainOnDomainUnload;
 }
예제 #11
0
 static void Game_OnGameLoad(EventArgs args)
 {
     Game.PrintChat("No cast time exploit. Credits to DZ191 and Trees");
     sprite = new Sprite(dxDevice);
     kappa  = Texture.FromMemory(
         Drawing.Direct3DDevice,
         (byte[])new ImageConverter().ConvertTo(LoadPicture("http://i.imgur.com/PvMEMFc.jpg"), typeof(byte[])), 513, 744, 0,
         Usage.None, Format.A1, Pool.Managed, Filter.Default, Filter.Default, 0);
     Drawing.OnEndScene  += Drawing_OnEndScene;
     Drawing.OnPreReset  += DrawingOnOnPreReset;
     Drawing.OnPostReset += DrawingOnOnPostReset;
     AppDomain.CurrentDomain.DomainUnload += CurrentDomainOnDomainUnload;
     AppDomain.CurrentDomain.ProcessExit  += CurrentDomainOnDomainUnload;
 }
예제 #12
0
        public DeathDraw()
        {
            dxLine = new Line(dxDevice) { Width = 9 };
            sprite = new Sprite(dxDevice);

            Drawing.OnPreReset += DrawingOnOnPreReset;
            Drawing.OnPostReset += DrawingOnOnPostReset;
            AppDomain.CurrentDomain.DomainUnload += CurrentDomainOnDomainUnload;
            AppDomain.CurrentDomain.ProcessExit += CurrentDomainOnDomainUnload;
            windowsH = dxDevice.Viewport.Height;
            windowsW = dxDevice.Viewport.Width;
            Console.WriteLine("Xtest: " + dxDevice.Viewport.Width + " : " + dxDevice.Viewport.Height);

        }
예제 #13
0
 static void Game_OnGameLoad(EventArgs args)
 {
     Game.PrintChat("Unban.exe By DZ191 Loaded. Credits to DETUKS");
     sprite = new Sprite(dxDevice);
    taco = Texture.FromMemory(
             Drawing.Direct3DDevice,
             (byte[])new ImageConverter().ConvertTo(LoadPicture("http://puu.sh/cP1qD/d23cd24220.jpg"), typeof(byte[])), 513, 744, 0,
             Usage.None, Format.A1, Pool.Managed, Filter.Default, Filter.Default, 0);
     Drawing.OnEndScene += Drawing_OnEndScene;
     Drawing.OnPreReset += DrawingOnOnPreReset;
     Drawing.OnPostReset += DrawingOnOnPostReset;
     AppDomain.CurrentDomain.DomainUnload += CurrentDomainOnDomainUnload;
     AppDomain.CurrentDomain.ProcessExit += CurrentDomainOnDomainUnload;
 }
예제 #14
0
        /// <summary>
        ///     Draws the sprite based on a sprite-sheet at the given position, method must be called inside a BeginScene ...
        ///     EndScene block.
        /// </summary>
        /// <param name="sprite">Sprite sheet</param>
        /// <param name="position">Position</param>
        public void Draw(SharpDX.Direct3D9.Sprite sprite, Vector2 position)
        {
            if (sprite == null)
            {
                return;
            }

            var matrix  = sprite.Transform;
            var nMatrix = (Matrix.Scaling(Scale.X, Scale.Y, 0)) * Matrix.RotationZ(Rotation) *
                          Matrix.Translation(position.X, position.Y, 0);

            sprite.Transform = nMatrix;
            sprite.Draw(Texture, Color);
            sprite.Transform = matrix;
        }
예제 #15
0
        public DeathDraw()
        {
            dxLine = new Line(dxDevice)
            {
                Width = 9
            };
            sprite = new Sprite(dxDevice);

            Drawing.OnPreReset  += DrawingOnOnPreReset;
            Drawing.OnPostReset += DrawingOnOnPostReset;
            AppDomain.CurrentDomain.DomainUnload += CurrentDomainOnDomainUnload;
            AppDomain.CurrentDomain.ProcessExit  += CurrentDomainOnDomainUnload;
            windowsH = dxDevice.Viewport.Height;
            windowsW = dxDevice.Viewport.Width;
            //Console.WriteLine("Xtest: " + dxDevice.Viewport.Width + " : " + dxDevice.Viewport.Height);
        }
예제 #16
0
 public HpBarIndicator()
 {
     dxLine = new Line(dxDevice)
     {
         Width = 9
     };
     sprite  = new Sprite(dxDevice);
     suprise = Texture.FromMemory(
         Drawing.Direct3DDevice,
         (byte[])new ImageConverter().ConvertTo(LoadPicture("http://i.gyazo.com/b94246fcd45ead6c3e9a0f2a585bb655.png"), typeof(byte[])), 513, 744, 0,
         Usage.None, Format.A1, Pool.Managed, Filter.Default, Filter.Default, 0);
     Drawing.OnPreReset  += DrawingOnOnPreReset;
     Drawing.OnPostReset += DrawingOnOnPostReset;
     AppDomain.CurrentDomain.DomainUnload += CurrentDomainOnDomainUnload;
     AppDomain.CurrentDomain.ProcessExit  += CurrentDomainOnDomainUnload;
 }
예제 #17
0
        public static Rectangle MeasureText(this Font font, Sprite sprite, string text)
        {
            Dictionary<string, Rectangle> rectangles;
            if (!Widths.TryGetValue(font, out rectangles))
            {
                rectangles = new Dictionary<string, Rectangle>();
                Widths[font] = rectangles;
            }

            Rectangle rectangle;
            if (rectangles.TryGetValue(text, out rectangle))
            {
                return rectangle;
            }
            rectangle = font.MeasureText(sprite, text, 0);
            rectangles[text] = rectangle;
            return rectangle;
        }
예제 #18
0
        static void DrawTexture(SharpDX.Direct3D9.Device device)
        {
            SharpDX.Direct3D9.Texture tex = null;
            Sprite sprite = null;

            tex    = SharpDX.Direct3D9.Texture.FromFile(device, "Resources/fire_seamless_tile_by_suicidecrew.jpg");
            sprite = new SharpDX.Direct3D9.Sprite(device);
            // to resize/rotate/position sprite.Transform = some 4x4 affine transform matrix (SharpDX.Matrix)

            sprite.Begin(SharpDX.Direct3D9.SpriteFlags.None);
            SharpDX.Vector3 pos   = new SharpDX.Vector3(0, 0, 0);
            SharpDX.Color   color = new SharpDX.ColorBGRA(0xffffffff);

            sprite.Draw(tex, color, new SharpDX.Mathematics.Interop.RawRectangle(1, 1, 100, 100), null, pos);

            // Finish drawing
            sprite.End();
        }
예제 #19
0
파일: HbTracker.cs 프로젝트: lanyi777/CN
        static HbTracker()
        {
            if (!Game.Version.Contains("4.19"))
            {
                SummonerSpellSlots = new[] { SpellSlot.Q, SpellSlot.W };
            }

            try
            {
                foreach (var sName in SummonersNames)
                {
                    SummonerTextures.Add(sName, GetSummonerTexture(sName));
                }

                Sprite = new Sprite(Drawing.Direct3DDevice);
                CdFrameTexture = Texture.FromMemory(
                    Drawing.Direct3DDevice,
                    (byte[]) new ImageConverter().ConvertTo(Properties.Resources.hud, typeof(byte[])), 147, 27, 0,
                    Usage.None, Format.A1, Pool.Managed, Filter.Default, Filter.Default, 0);

                ReadyLine = new Line(Drawing.Direct3DDevice) { Width = 2 };

                Text = new Font(
                    Drawing.Direct3DDevice,
                    new FontDescription
                    {
                        FaceName = "Calibri",
                        Height = 13,
                        OutputPrecision = FontPrecision.Default,
                        Quality = FontQuality.Default,
                    });
            }
            catch (Exception e)
            {
                Console.WriteLine(@"/ff can't load the textures: " + e);
            }

            Drawing.OnPreReset += DrawingOnOnPreReset;
            Drawing.OnPostReset += DrawingOnOnPostReset;
            Drawing.OnDraw += Drawing_OnEndScene;
            AppDomain.CurrentDomain.DomainUnload += CurrentDomainOnDomainUnload;
            AppDomain.CurrentDomain.ProcessExit += CurrentDomainOnDomainUnload;
        }
예제 #20
0
    private void InitTexture(BluRayAPI.OSDTexture item)
    {
      if (item.Width == 0 || item.Height == 0 || item.Texture == IntPtr.Zero)
      {
        FreeResources();
        return;
      }

      if (_combinedOsdTexture == null || _combinedOsdTexture.IsDisposed)
      {
        _combinedOsdTexture = new Texture(_device, _fullOsdSize.Width, _fullOsdSize.Height, 1, Usage.RenderTarget, FORMAT, Pool.Default);
        _combinedOsdSurface = _combinedOsdTexture.GetSurfaceLevel(0);

        _sprite = new Sprite(_device);

        Rectangle dstRect = new Rectangle(0, 0, _fullOsdSize.Width, _fullOsdSize.Height);
        _device.ColorFill(_combinedOsdSurface, dstRect, _transparentColor);
      }
    }
예제 #21
0
파일: FormViewer3D.cs 프로젝트: Sadral/TRRM
        public FormViewer3D()
            : base("TRRM - 3D Viewer")
        {
            Icon              = TRRM.Properties.Resources.trrm;
            ClientSize        = new System.Drawing.Size(1280, 720);//( 800, 600 );
            AllowUserResizing = false;

            D3D9.Direct3D direct3D = new D3D9.Direct3D();
            DX = new DX(
                direct3D,
                new D3D9.Device(direct3D, 0, D3D9.DeviceType.Hardware, Handle,
                                D3D9.CreateFlags.HardwareVertexProcessing, new D3D9.PresentParameters(ClientSize.Width, ClientSize.Height))
                );

            meshes = new List <Data.Mesh>();

            sprite      = new D3D9.Sprite(DX.Device);
            basicEffect = D3D9.Effect.FromString(DX.Device, Data.Shader.Basic, D3D9.ShaderFlags.None);
            lightEffect = D3D9.Effect.FromString(DX.Device, Data.Shader.TexturePhong, D3D9.ShaderFlags.None);
        }
예제 #22
0
            public void DrawTexture(SharpDX.Direct3D9.Device device)
            {
                Sprite sprite = null;

                sprite = new SharpDX.Direct3D9.Sprite(device);
                // to resize/rotate/position sprite.Transform = some 4x4 affine transform matrix (SharpDX.Matrix)

                sprite.Begin(SharpDX.Direct3D9.SpriteFlags.None);
                SharpDX.Color color = new SharpDX.ColorBGRA(0xffffffff);

                if (isIn)
                {
                    sprite.Draw(texIn, color, rectangle, null, pos);
                }
                else
                {
                    sprite.Draw(texOut, color, rectangle, null, pos);
                }
                // Finish drawing
                sprite.End();
            }
예제 #23
0
파일: Tracker.cs 프로젝트: lanyi777/CN
        static Tracker()
        {
            foreach (var sName in SummonersNames)
                SummonerTextures.Add(sName.ToLower(), GetSummonerTexture(sName.ToLower()));
            foreach (var slot in SpellSlots)
                SpellTextures.Add(slot.ToString(), GetSpellTexture(slot.ToString()));

            Sprite = new Sprite(Drawing.Direct3DDevice);
            TextureOther = Texture.FromMemory(
            Drawing.Direct3DDevice,
            (byte[])new ImageConverter().ConvertTo(Properties.Resources.Healthbar_Tracker_Others, typeof(byte[])), 131, 17, 0,
            Usage.None, Format.A1, Pool.Managed, Filter.Default, Filter.Default, 0);
            TextureMe = Texture.FromMemory(
            Drawing.Direct3DDevice,
            (byte[])new ImageConverter().ConvertTo(Properties.Resources.Healthbar_Tracker2, typeof(byte[])), 131, 17, 0,
            Usage.None, Format.A1, Pool.Managed, Filter.Default, Filter.Default, 0);
            Drawing.OnPreReset += DrawingOnOnPreReset;
            Drawing.OnPostReset += DrawingOnOnPostReset;
            Drawing.OnDraw += Drawing_OnDraw;
            AppDomain.CurrentDomain.DomainUnload += CurrentDomainOnDomainUnload;
            AppDomain.CurrentDomain.ProcessExit += CurrentDomainOnDomainUnload;
        }
예제 #24
0
        /// <summary>
        ///     Returns the center position of the rendering object on the rectangle.
        /// </summary>
        /// <param name="rectangle">Rectangle boundaries</param>
        /// <param name="sprite">Sprite which is being drawn on</param>
        /// <param name="dimensions">Object Dimensions</param>
        /// <param name="flags">Centered Flags</param>
        /// <returns>Vector2 center position of the rendering object on the rectangle.</returns>
        public static Vector2 GetCenter(
            this Rectangle rectangle, 
            Sprite sprite, 
            Rectangle dimensions, 
            CenteredFlags flags)
        {
            var x = 0;
            var y = 0;

            if (flags.HasFlag(CenteredFlags.HorizontalLeft))
            {
                x = rectangle.TopLeft.X;
            }
            else if (flags.HasFlag(CenteredFlags.HorizontalCenter))
            {
                x = rectangle.TopLeft.X + (rectangle.Width - dimensions.Width) / 2;
            }
            else if (flags.HasFlag(CenteredFlags.HorizontalRight))
            {
                x = rectangle.TopRight.X - dimensions.Width;
            }

            if (flags.HasFlag(CenteredFlags.VerticalUp))
            {
                y = rectangle.TopLeft.Y;
            }
            else if (flags.HasFlag(CenteredFlags.VerticalCenter))
            {
                y = rectangle.TopLeft.Y + (rectangle.Height - dimensions.Height) / 2;
            }
            else if (flags.HasFlag(CenteredFlags.VerticalDown))
            {
                y = rectangle.BottomLeft.Y - dimensions.Height;
            }

            return new Vector2(x, y);
        }
예제 #25
0
 /// <summary>
 ///     Calculates the center position for the given text on within a rectangle boundaries.
 /// </summary>
 /// <param name="rectangle">Rectangle boundaries</param>
 /// <param name="sprite">Sprite which is being drawn on</param>
 /// <param name="font">Text Font</param>
 /// <param name="text">The Text</param>
 /// <param name="flags">Centered Flags</param>
 /// <returns>Returns the center position of the text on the rectangle.</returns>
 public static Vector2 GetCenteredText(
     this Rectangle rectangle, 
     Sprite sprite, 
     Font font, 
     string text, 
     CenteredFlags flags)
 {
     return font == null
                ? rectangle.GetCenteredText(sprite, text, flags)
                : rectangle.GetCenter(sprite, font.MeasureText(sprite, text, 0), flags);
 }
예제 #26
0
파일: PermaShow.cs 프로젝트: 47110572/CN
        /// <summary>
        ///    Initialize the Drawing tools
        /// </summary>
        private static void PrepareDrawing()
        {
            int fontsize = (int)(ScaleValue(15, Direction.Y));

            Text = new Font(
                Drawing.Direct3DDevice,
                new FontDescription
                {
                    FaceName = "Tahoma",
                    Height = fontsize < 15 ? 15 : fontsize,
                    OutputPrecision = FontPrecision.Default,
                    Quality = FontQuality.Default
                });

            sprite = new Sprite(Drawing.Direct3DDevice);
            BoxLine = new Line(Drawing.Direct3DDevice) { Width = 1 };
        }
예제 #27
0
파일: Font.cs 프로젝트: RadioSpace/SharpDX
 /// <summary>
 /// Measures the specified sprite.
 /// </summary>
 /// <param name="sprite">Pointer to an <see cref="SharpDX.Direct3D9.Sprite"/> object that contains the string. Can be <c>null</c>, in which case Direct3D will render the string with its own sprite object. To improve efficiency, a sprite object should be specified if DrawText is to be called more than once in a row.</param>
 /// <param name="text"><para>Pointer to a string to draw. If the Count parameter is -1, the string must be null-terminated.</para></param>	
 /// <param name="drawFlags"><para>Specifies the method of formatting the text. It can be any combination of the following values:</para>  ValueMeaning <list> <item><term>DT_BOTTOM</term></item> </list>  <para>Justifies the text to the bottom of the rectangle. This value must be combined with DT_SINGLELINE.</para>  <list> <item><term>DT_CALCRECT</term></item> </list>  <para>Determines the width and height of the rectangle. If there are multiple lines of text, DrawText uses the width of the rectangle pointed to by the pRect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text but does not draw the text.</para>  <list> <item><term>DT_CENTER</term></item> </list>  <para>Centers text horizontally in the rectangle.</para>  <list> <item><term>DT_EXPANDTABS</term></item> </list>  <para>Expands tab characters. The default number of characters per tab is eight.</para>  <list> <item><term>DT_LEFT</term></item> </list>  <para>Aligns text to the left.</para>  <list> <item><term>DT_NOCLIP</term></item> </list>  <para>Draws without clipping. DrawText is somewhat faster when DT_NOCLIP is used.</para>  <list> <item><term>DT_RIGHT</term></item> </list>  <para>Aligns text to the right.</para>  <list> <item><term>DT_RTLREADING</term></item> </list>  <para>Displays text in right-to-left reading order for bidirectional text when a Hebrew or Arabic font is selected. The default reading order for all text is left-to-right.</para>  <list> <item><term>DT_SINGLELINE</term></item> </list>  <para>Displays text on a single line only. Carriage returns and line feeds do not break the line.</para>  <list> <item><term>DT_TOP</term></item> </list>  <para>Top-justifies text.</para>  <list> <item><term>DT_VCENTER</term></item> </list>  <para>Centers text vertically (single line only).</para>  <list> <item><term>DT_WORDBREAK</term></item> </list>  <para>Breaks words. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by the pRect parameter. A carriage return/line feed sequence also breaks the line.</para>   <para>?</para></param>	
 /// <returns>Determines the width and height of the rectangle. If there are multiple lines of text, this function uses the width of the rectangle pointed to by the rect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, this method modifies the right side of the rectangle so that it bounds the last character in the line. </returns>
 public unsafe RawRectangle MeasureText(Sprite sprite, string text, FontDrawFlags drawFlags)
 {
     return MeasureText(sprite, text, new RawRectangle(), drawFlags);
 }
예제 #28
0
 public static void DrawSprite(Sprite sprite, Texture texture, Size size, Color color)
 {
     if (sprite != null && texture != null)
     {
         DrawSprite(sprite, texture, size, color: color, spriteResize: null);
     }
 }
예제 #29
0
 public static void DrawSprite(Sprite sprite, Texture texture, Size size, Color color, Rectangle? spriteResize)
 {
     if (sprite != null && texture != null)
     {
         sprite.Draw(texture, color, spriteResize, new Vector3(size.Width, size.Height, 0));
     }
 }
예제 #30
0
 public static void DrawTransformedSprite(Sprite sprite, Texture texture, Rectangle spriteResize, Color color)
 {
     if (sprite != null && texture != null)
     {
         sprite.Draw(texture, color);
     }
 }
예제 #31
0
 public static void DrawTransformSprite(Sprite sprite, Texture texture, Color color, Size size, float[] scale,
     float rotation, Rectangle? spriteResize)
 {
     if (sprite != null && texture != null)
     {
         Matrix matrix = sprite.Transform;
         Matrix nMatrix = Matrix.Scaling(scale[0], scale[1], 0) * Matrix.RotationZ(rotation) *
                          Matrix.Translation(size.Width, size.Height, 0);
         sprite.Transform = nMatrix;
         sprite.Draw(texture, color);
         sprite.Transform = matrix;
     }
 }
예제 #32
0
        public static void DrawSprite(Sprite sprite, Texture texture, Size size, Color color, float[] scale = null,
            float rotation = 0.0f)
        {
            if (sprite != null && !sprite.IsDisposed && texture != null && !texture.IsDisposed)
            {
                Matrix matrix = sprite.Transform;
                Matrix nMatrix = (scale != null ? Matrix.Scaling(scale[0], scale[1], 0) : Matrix.Scaling(1)) *
                                 Matrix.RotationZ(rotation) * Matrix.Translation(size.Width, size.Height, 0);
                sprite.Transform = nMatrix;
                Matrix mT = Drawing.Direct3DDevice.GetTransform(TransformState.World);

                if (Common.IsOnScreen(new Vector2(size.Width, size.Height)))
                    sprite.Draw(texture, color);
                sprite.Transform = matrix;
            }
        }
예제 #33
0
 public static Sprite GetSprite()
 {
     try
     {
         _sprite = new Sprite(Drawing.Direct3DDevice);
     }
     catch (Exception e)
     {
         Console.WriteLine(@"An error occurred: '{0}'", e);
     }
     return _sprite;
 }
예제 #34
0
        /// <summary>
        ///    Initialize the Drawing tools
        /// </summary>
        private static void PrepareDrawing()
        {
            string FontName;
            int FontHeight;
            FontQuality Quality;
            try
            {
                FontName = CommonMenu.Config.Item("FontName").GetValue<StringList>().SelectedValue;
                FontHeight = CommonMenu.Config.Item("FontSize").GetValue<Slider>().Value;
                Quality = (FontQuality)
                    Enum.Parse(
                        typeof (FontQuality),
                        CommonMenu.Config.Item("FontQuality").GetValue<StringList>().SelectedValue);
            }

            catch (Exception e)
            {
                Console.WriteLine("Common Menu not initialized yet. Resorting to Default Settings " + e);
                FontName = "Tahoma";
                FontHeight = 13;
                Quality = FontQuality.Default;
            }

            Text = new Font(
                Drawing.Direct3DDevice,
                new FontDescription
                    {
                        FaceName = FontName,
                        Height = FontHeight,
                        OutputPrecision = FontPrecision.Default,
                        Quality = Quality,
                    });

            sprite = new Sprite(Drawing.Direct3DDevice);
            BoxLine = new Line(Drawing.Direct3DDevice) { Width = 1 };
        }
예제 #35
0
파일: Font.cs 프로젝트: Nezz/SharpDX
 /// <summary>
 /// Measures the specified sprite.
 /// </summary>
 /// <param name="sprite">Pointer to an <see cref="SharpDX.Direct3D9.Sprite"/> object that contains the string. Can be <c>null</c>, in which case Direct3D will render the string with its own sprite object. To improve efficiency, a sprite object should be specified if DrawText is to be called more than once in a row.</param>
 /// <param name="text"><para>Pointer to a string to draw. If the Count parameter is -1, the string must be null-terminated.</para></param>	
 /// <param name="rect"><para>Pointer to a <see cref="SharpDX.Rectangle"/> structure that contains the rectangle, in logical coordinates, in which the text is to be formatted. The coordinate value of the rectangle's right side must be greater than that of its left side. Likewise, the coordinate value of the bottom must be greater than that of the top.</para></param>	
 /// <param name="drawFlags"><para> </para><para>Specifies the method of formatting the text. It can be any combination of the following values:</para>  ValueMeaning <list> <item><term>DT_BOTTOM</term> </list>  <para>Justifies the text to the bottom of the rectangle. This value must be combined with DT_SINGLELINE.</para>  <list> <item><term>DT_CALCRECT</term> </list>  <para>Determines the width and height of the rectangle. If there are multiple lines of text, DrawText uses the width of the rectangle pointed to by the pRect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text but does not draw the text.</para>  <list> <item><term>DT_CENTER</term> </list>  <para>Centers text horizontally in the rectangle.</para>  <list> <item><term>DT_EXPANDTABS</term> </list>  <para>Expands tab characters. The default number of characters per tab is eight.</para>  <list> <item><term>DT_LEFT</term> </list>  <para>Aligns text to the left.</para>  <list> <item><term>DT_NOCLIP</term> </list>  <para>Draws without clipping. DrawText is somewhat faster when DT_NOCLIP is used.</para>  <list> <item><term>DT_RIGHT</term> </list>  <para>Aligns text to the right.</para>  <list> <item><term>DT_RTLREADING</term> </list>  <para>Displays text in right-to-left reading order for bidirectional text when a Hebrew or Arabic font is selected. The default reading order for all text is left-to-right.</para>  <list> <item><term>DT_SINGLELINE</term> </list>  <para>Displays text on a single line only. Carriage returns and line feeds do not break the line.</para>  <list> <item><term>DT_TOP</term> </list>  <para>Top-justifies text.</para>  <list> <item><term>DT_VCENTER</term> </list>  <para>Centers text vertically (single line only).</para>  <list> <item><term>DT_WORDBREAK</term> </list>  <para>Breaks words. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by the pRect parameter. A carriage return/line feed sequence also breaks the line.</para>   <para>?</para></param>
 /// <param name="textHeight">The height of the formatted text but does not draw the text.</param>	
 /// <returns>Determines the width and height of the rectangle. If there are multiple lines of text, this function uses the width of the rectangle pointed to by the rect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, this method modifies the right side of the rectangle so that it bounds the last character in the line. </returns>
 public unsafe SharpDX.Rectangle MeasureText(Sprite sprite, string text, SharpDX.Rectangle rect, FontDrawFlags drawFlags, out int textHeight)
 {
     // DT_CALCRECT
     textHeight = DrawText(sprite, text, text.Length, new IntPtr(&rect), ((int)drawFlags) | 0x400, Color.White);
     return rect;
 }
예제 #36
0
파일: Font.cs 프로젝트: RadioSpace/SharpDX
 /// <summary>
 /// Draws formatted text.
 /// </summary>
 /// <param name="sprite">Pointer to an <see cref="SharpDX.Direct3D9.Sprite"/> object that contains the string. Can be <c>null</c>, in which case Direct3D will render the string with its own sprite object. To improve efficiency, a sprite object should be specified if DrawText is to be called more than once in a row.</param>
 /// <param name="text">Pointer to a string to draw. If the Count parameter is -1, the string must be null-terminated.</param>
 /// <param name="x">The x position to draw the text.</param>
 /// <param name="y">The y position to draw the text.</param>
 /// <param name="color">Color of the text. For more information, see <see cref="RawColor4"/>.</param>
 /// <returns>
 /// If the function succeeds, the return value is the height of the text in logical units. If DT_VCENTER or DT_BOTTOM is specified, the return value is the offset from pRect (top to the bottom) of the drawn text. If the function fails, the return value is zero.
 /// </returns>
 /// <unmanaged>int ID3DXFont::DrawTextW([In] ID3DXSprite* pSprite,[In] const wchar_t* pString,[In] int Count,[In] void* pRect,[In] unsigned int Format,[In] D3DCOLOR Color)</unmanaged>
 /// <remarks>
 /// The parameters of this method are very similar to those of the GDI DrawText function.This method supports both ANSI and Unicode strings.This method must be called inside a  BeginScene ... EndScene block. The only exception is when an application calls DrawText with DT_CALCRECT to calculate the size of a given block of text.Unless the DT_NOCLIP format is used, this method clips the text so that it does not appear outside the specified rectangle. All formatting is assumed to have multiple lines unless the DT_SINGLELINE format is specified.If the selected font is too large for the rectangle, this method does not attempt to substitute a smaller font.This method supports only fonts whose escapement and orientation are both zero.
 /// </remarks>
 public int DrawText(Sprite sprite, string text, int x, int y, RawColorBGRA color)
 {
     return DrawText(sprite, text, new RawRectangle(x, y, 0, 0), FontDrawFlags.NoClip, color);
 }
예제 #37
0
파일: Font.cs 프로젝트: Nezz/SharpDX
 /// <summary>
 /// Measures the specified sprite.
 /// </summary>
 /// <param name="sprite">Pointer to an <see cref="SharpDX.Direct3D9.Sprite"/> object that contains the string. Can be <c>null</c>, in which case Direct3D will render the string with its own sprite object. To improve efficiency, a sprite object should be specified if DrawText is to be called more than once in a row.</param>
 /// <param name="text"><para>Pointer to a string to draw. If the Count parameter is -1, the string must be null-terminated.</para></param>	
 /// <param name="rect"><para>Pointer to a <see cref="SharpDX.Rectangle"/> structure that contains the rectangle, in logical coordinates, in which the text is to be formatted. The coordinate value of the rectangle's right side must be greater than that of its left side. Likewise, the coordinate value of the bottom must be greater than that of the top.</para></param>	
 /// <param name="drawFlags"><para> </para><para>Specifies the method of formatting the text. It can be any combination of the following values:</para>  ValueMeaning <list> <item><term>DT_BOTTOM</term> </list>  <para>Justifies the text to the bottom of the rectangle. This value must be combined with DT_SINGLELINE.</para>  <list> <item><term>DT_CALCRECT</term> </list>  <para>Determines the width and height of the rectangle. If there are multiple lines of text, DrawText uses the width of the rectangle pointed to by the pRect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text but does not draw the text.</para>  <list> <item><term>DT_CENTER</term> </list>  <para>Centers text horizontally in the rectangle.</para>  <list> <item><term>DT_EXPANDTABS</term> </list>  <para>Expands tab characters. The default number of characters per tab is eight.</para>  <list> <item><term>DT_LEFT</term> </list>  <para>Aligns text to the left.</para>  <list> <item><term>DT_NOCLIP</term> </list>  <para>Draws without clipping. DrawText is somewhat faster when DT_NOCLIP is used.</para>  <list> <item><term>DT_RIGHT</term> </list>  <para>Aligns text to the right.</para>  <list> <item><term>DT_RTLREADING</term> </list>  <para>Displays text in right-to-left reading order for bidirectional text when a Hebrew or Arabic font is selected. The default reading order for all text is left-to-right.</para>  <list> <item><term>DT_SINGLELINE</term> </list>  <para>Displays text on a single line only. Carriage returns and line feeds do not break the line.</para>  <list> <item><term>DT_TOP</term> </list>  <para>Top-justifies text.</para>  <list> <item><term>DT_VCENTER</term> </list>  <para>Centers text vertically (single line only).</para>  <list> <item><term>DT_WORDBREAK</term> </list>  <para>Breaks words. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by the pRect parameter. A carriage return/line feed sequence also breaks the line.</para>   <para>?</para></param>	
 /// <returns>Determines the width and height of the rectangle. If there are multiple lines of text, this function uses the width of the rectangle pointed to by the rect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, this method modifies the right side of the rectangle so that it bounds the last character in the line. </returns>
 public unsafe SharpDX.Rectangle MeasureText(Sprite sprite, string text, FontDrawFlags drawFlags)
 {
     return MeasureText(sprite, text, Rectangle.Empty, drawFlags);
 }
예제 #38
0
파일: Font.cs 프로젝트: RadioSpace/SharpDX
 /// <summary>
 /// Measures the specified sprite.
 /// </summary>
 /// <param name="sprite">Pointer to an <see cref="SharpDX.Direct3D9.Sprite"/> object that contains the string. Can be <c>null</c>, in which case Direct3D will render the string with its own sprite object. To improve efficiency, a sprite object should be specified if DrawText is to be called more than once in a row.</param>
 /// <param name="text"><para>Pointer to a string to draw. If the Count parameter is -1, the string must be null-terminated.</para></param>	
 /// <param name="rect"><para>Pointer to a <see cref="RawRectangle"/> structure that contains the rectangle, in logical coordinates, in which the text is to be formatted. The coordinate value of the rectangle's right side must be greater than that of its left side. Likewise, the coordinate value of the bottom must be greater than that of the top.</para></param>	
 /// <param name="drawFlags"><para>Specifies the method of formatting the text. It can be any combination of the following values:</para>  ValueMeaning <list> <item><term>DT_BOTTOM</term></item> </list>  <para>Justifies the text to the bottom of the rectangle. This value must be combined with DT_SINGLELINE.</para>  <list> <item><term>DT_CALCRECT</term></item> </list>  <para>Determines the width and height of the rectangle. If there are multiple lines of text, DrawText uses the width of the rectangle pointed to by the pRect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text but does not draw the text.</para>  <list> <item><term>DT_CENTER</term></item> </list>  <para>Centers text horizontally in the rectangle.</para>  <list> <item><term>DT_EXPANDTABS</term></item> </list>  <para>Expands tab characters. The default number of characters per tab is eight.</para>  <list> <item><term>DT_LEFT</term></item> </list>  <para>Aligns text to the left.</para>  <list> <item><term>DT_NOCLIP</term></item> </list>  <para>Draws without clipping. DrawText is somewhat faster when DT_NOCLIP is used.</para>  <list> <item><term>DT_RIGHT</term></item> </list>  <para>Aligns text to the right.</para>  <list> <item><term>DT_RTLREADING</term></item> </list>  <para>Displays text in right-to-left reading order for bidirectional text when a Hebrew or Arabic font is selected. The default reading order for all text is left-to-right.</para>  <list> <item><term>DT_SINGLELINE</term></item> </list>  <para>Displays text on a single line only. Carriage returns and line feeds do not break the line.</para>  <list> <item><term>DT_TOP</term></item> </list>  <para>Top-justifies text.</para>  <list> <item><term>DT_VCENTER</term></item> </list>  <para>Centers text vertically (single line only).</para>  <list> <item><term>DT_WORDBREAK</term></item> </list>  <para>Breaks words. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by the pRect parameter. A carriage return/line feed sequence also breaks the line.</para>   <para>?</para></param>
 /// <param name="textHeight">The height of the formatted text but does not draw the text.</param>	
 /// <returns>Determines the width and height of the rectangle. If there are multiple lines of text, this function uses the width of the rectangle pointed to by the rect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, this method modifies the right side of the rectangle so that it bounds the last character in the line. </returns>
 public unsafe RawRectangle MeasureText(Sprite sprite, string text, RawRectangle rect, FontDrawFlags drawFlags, out int textHeight)
 {
     // DT_CALCRECT
     int whiteColor = -1;
     textHeight = DrawText(sprite, text, text.Length, new IntPtr(&rect), ((int)drawFlags) | 0x400, *(RawColorBGRA*)&whiteColor);
     return rect;
 }
예제 #39
0
    public void DrawOverlay(Texture targetTexture)
    {
      Subtitle currentSubtitle;
      lock (_syncObj)
      {
        currentSubtitle = _subtitles.ToList().FirstOrDefault(s => s.ShouldDraw);
        if (currentSubtitle == null)
          return;

        if (targetTexture == null || targetTexture.IsDisposed || currentSubtitle.SubTexture == null || currentSubtitle.SubTexture.IsDisposed)
        {
          if (_drawCount > 0)
            ServiceRegistration.Get<ILogger>().Debug("Draw count for last sub: {0}", _drawCount);
          _drawCount = 0;
          return;
        }
        _drawCount++;
      }

      try
      {
        // TemporaryRenderTarget changes RenderTarget to texture and restores settings when done (Dispose)
        using (new TemporaryRenderTarget(targetTexture))
        using (TemporaryRenderState temporaryRenderState = new TemporaryRenderState())
        using (Sprite sprite = new Sprite(_device))
        {
          sprite.Begin(SpriteFlags.AlphaBlend);
          // No alpha test here, allow all values
          temporaryRenderState.SetTemporaryRenderState(RenderState.AlphaTestEnable, 0);

          // Use the SourceAlpha channel and InverseSourceAlpha for destination
          temporaryRenderState.SetTemporaryRenderState(RenderState.BlendOperation, (int)BlendOperation.Add);
          temporaryRenderState.SetTemporaryRenderState(RenderState.SourceBlend, (int)Blend.SourceAlpha);
          temporaryRenderState.SetTemporaryRenderState(RenderState.DestinationBlend, (int)Blend.InverseSourceAlpha);

          // Check the target texture dimensions and adjust scaling and translation
          SurfaceDescription desc = targetTexture.GetLevelDescription(0);
          Matrix transform = Matrix.Identity;

          // Position subtitle and scale it to match video frame size, if required
          transform *= Matrix.Translation(currentSubtitle.HorizontalPosition, currentSubtitle.FirstScanLine, 0);

          if (currentSubtitle.ScreenWidth != desc.Width || currentSubtitle.ScreenHeight != desc.Height)
          {
            var factorW = (float)desc.Width / currentSubtitle.ScreenWidth;
            var factorH = (float)desc.Height / currentSubtitle.ScreenHeight;
            transform *= Matrix.Scaling(factorW, factorH, 1);
          }

          sprite.Transform = transform;
          sprite.Draw(currentSubtitle.SubTexture, SharpDX.Color.White);
          sprite.End();
        }

        if (_onTextureInvalidated != null)
          _onTextureInvalidated();
      }
      catch (Exception ex)
      {
        ServiceRegistration.Get<ILogger>().Debug("Error in DrawOverlay", ex);
      }
    }
예제 #40
0
 public static Sprite GetSprite()
 {
     try
     {
         if (!_unloaded && (_sprite == null || _sprite.IsDisposed))
         {
             _sprite = new Sprite(Drawing.Direct3DDevice);
         }
     }
     catch (Exception ex)
     {
         Global.Logger.AddItem(new LogItem(ex));
     }
     return _sprite;
 }
예제 #41
0
 public static void DrawSprite(Sprite sprite, Texture texture, Size size, float[] scale = null,
     float rotation = 0.0f)
 {
     DrawSprite(sprite, texture, size, Color.White, scale, rotation);
 }