Пример #1
0
        /// <summary>	
        /// Get the array of {{scissor rectangles}} bound to the {{rasterizer stage}}.	
        /// </summary>	
        /// <returns>An array of scissor rectangles (see <see cref="RawRectangle"/>).</returns>
        /// <unmanaged>void RSGetScissorRects([InOut] int* NumRects,[Out, Buffer, Optional] D3D10_RECT* pRects)</unmanaged>
        public RawRectangle[] GetScissorRectangles()
        {
            int numRects = 0;
            GetScissorRects(ref numRects, null);

            RawRectangle[] scissorRectangles = new RawRectangle[numRects];
            GetScissorRects(ref numRects, scissorRectangles);

            return scissorRectangles;
        }
Пример #2
0
        /// <summary>
        /// <p> Draws a run of glyphs to a bitmap target at the specified position.</p>
        /// </summary>
        /// <param name="baselineOriginX"><dd>  <p> The horizontal position of the baseline origin, in DIPs, relative to the upper-left corner of the DIB.</p> </dd></param>
        /// <param name="baselineOriginY"><dd>  <p> The vertical position of the baseline origin, in DIPs, relative to the upper-left corner of the DIB.</p> </dd></param>
        /// <param name="measuringMode"><dd>  <p> The measuring method for glyphs in the run, used with the other properties to determine the rendering mode.</p> </dd></param>
        /// <param name="glyphRun"><dd>  <p> The structure containing the properties of the glyph run.</p> </dd></param>
        /// <param name="renderingParams"><dd>  <p> The object that controls rendering behavior.</p> </dd></param>
        /// <param name="textColor"><dd>  <p> The foreground color of the text.</p> </dd></param>
        /// <param name="blackBoxRect"><dd>  <p> The optional rectangle that receives the bounding box (in pixels not DIPs) of all the pixels affected by  drawing the glyph run. The black box rectangle may extend beyond the dimensions of the bitmap.</p> </dd></param>
        /// <returns><p>If this method succeeds, it returns <strong><see cref="SharpDX.Result.Ok"/></strong>. Otherwise, it returns an <strong><see cref="SharpDX.Result"/></strong> error code.</p></returns>
        /// <remarks>
        /// <p>You can use the <strong><see cref="SharpDX.DirectWrite.BitmapRenderTarget.DrawGlyphRun"/></strong> to render to a bitmap from a custom text renderer that you implement.  The custom text renderer should call this method from within the <strong><see cref="SharpDX.DirectWrite.TextRenderer.DrawGlyphRun"/></strong> callback method as shown in the following code.</p><pre>STDMETHODIMP GdiTextRenderer::DrawGlyphRun( __maybenull void* clientDrawingContext, FLOAT baselineOriginX, FLOAT baselineOriginY, <see cref="SharpDX.Direct2D1.MeasuringMode"/> measuringMode, __in <see cref="SharpDX.DirectWrite.GlyphRun"/> const* glyphRun, __in <see cref="SharpDX.DirectWrite.GlyphRunDescription"/> const* glyphRunDescription, <see cref="SharpDX.ComObject"/>* clientDrawingEffect )
        /// { <see cref="SharpDX.Result"/> hr = <see cref="SharpDX.Result.Ok"/>; // Pass on the drawing call to the render target to do the real work. <see cref="SharpDX.Mathematics.Interop.RawRectangle"/> dirtyRect = {0}; hr = pRenderTarget_-&gt;DrawGlyphRun( baselineOriginX, baselineOriginY, measuringMode, glyphRun, pRenderingParams_, RGB(0,200,255), &amp;dirtyRect ); return hr;
        /// }
        /// </pre><p>The <em>baselineOriginX</em>, <em>baslineOriginY</em>, <em>measuringMethod</em>, and <em>glyphRun</em> parameters are provided (as arguments) when the callback method is invoked.  The <em>renderingParams</em>, <em>textColor</em> and <em>blackBoxRect</em> are not.</p><p>Default rendering params can be retrieved by using the <strong><see cref="SharpDX.DirectWrite.Factory.CreateMonitorRenderingParams"/></strong> method.</p><p></p>
        /// </remarks>
        /// <include file='Documentation\CodeComments.xml' path="/comments/comment[@id='IDWriteBitmapRenderTarget::DrawGlyphRun']/*"/>
        /// <msdn-id>dd368167</msdn-id>
        /// <unmanaged>HRESULT IDWriteBitmapRenderTarget::DrawGlyphRun([In] float baselineOriginX,[In] float baselineOriginY,[In] DWRITE_MEASURING_MODE measuringMode,[In] const DWRITE_GLYPH_RUN* glyphRun,[In] IDWriteRenderingParams* renderingParams,[In] int textColor,[Out, Optional] RECT* blackBoxRect)</unmanaged>
        /// <unmanaged-short>IDWriteBitmapRenderTarget::DrawGlyphRun</unmanaged-short>
        public void DrawGlyphRun(float baselineOriginX,
                                 float baselineOriginY,
                                 SharpDX.Direct2D1.MeasuringMode measuringMode,
                                 SharpDX.DirectWrite.GlyphRun glyphRun,
                                 SharpDX.DirectWrite.RenderingParams renderingParams,
                                 RawColorBGRA textColor,
                                 out SharpDX.Mathematics.Interop.RawRectangle blackBoxRect)
        {
            int colorRgb = (textColor.R) | (textColor.G << 8) | (textColor.B << 16);

            DrawGlyphRun(baselineOriginX, baselineOriginY, measuringMode, glyphRun, renderingParams, colorRgb, out blackBoxRect);
        }
Пример #3
0
 /// <summary>	
 /// <p>Adds a sprite to the list of batched sprites.</p>	
 /// </summary>	
 /// <param name="textureRef"><dd>  <p>Pointer to an <strong><see cref="SharpDX.Direct3D9.Texture"/></strong> interface that represents the sprite texture.</p> </dd></param>	
 /// <param name="srcRectRef"><dd>  <p>Pointer to a <strong><see cref="RawRectangle"/></strong> structure that indicates the portion of the source texture to use for the sprite. If this parameter is <strong><c>null</c></strong>, then the entire source image is used for the sprite.</p> </dd></param>	
 /// <param name="centerRef"><dd>  <p>Pointer to a <strong><see cref="RawVector3"/></strong> vector that identifies the center of the sprite. If this argument is <strong><c>null</c></strong>, the point (0,0,0) is used, which is the upper-left corner.</p> </dd></param>	
 /// <param name="positionRef"><dd>  <p>Pointer to a <strong><see cref="RawVector3"/></strong> vector that identifies the position of the sprite. If this argument is <strong><c>null</c></strong>, the point (0,0,0) is used, which is the upper-left corner.</p> </dd></param>	
 /// <param name="color"><dd>  <p> <strong><see cref="RawColor4"/></strong> type. The color and alpha channels are modulated by this value. A value of 0xFFFFFFFF maintains the original source color and alpha data. Use the <strong>D3DCOLOR_RGBA</strong> macro to help generate this color.</p> </dd></param>	
 /// <returns><p>If the method succeeds, the return value is <see cref="SharpDX.Result.Ok"/>. If the method fails, the return value can be one of the following: <see cref="SharpDX.Direct3D9.ResultCode.InvalidCall"/>, D3DXERR_INVALIDDATA.</p></returns>	
 /// <remarks>	
 /// <p>To scale, rotate, or translate a sprite, call <strong><see cref="SharpDX.Direct3D9.Sprite.SetTransform"/></strong> with a matrix that contains the scale, rotate, and translate (SRT) values, before calling <see cref="SharpDX.Direct3D9.Sprite.Draw"/>. For information about setting SRT values in a matrix, see Matrix Transforms.</p>	
 /// </remarks>	
 /// <msdn-id>bb174251</msdn-id>	
 /// <unmanaged>HRESULT ID3DXSprite::Draw([In] IDirect3DTexture9* pTexture,[In] const RECT* pSrcRect,[In] const D3DXVECTOR3* pCenter,[In] const D3DXVECTOR3* pPosition,[In] D3DCOLOR Color)</unmanaged>	
 /// <unmanaged-short>ID3DXSprite::Draw</unmanaged-short>	
 public unsafe void Draw(SharpDX.Direct3D9.Texture textureRef, RawColorBGRA color, RawRectangle? srcRectRef = null, RawVector3? centerRef = null, RawVector3? positionRef = null)
 {
     RawRectangle localRect = default(RawRectangle);
     RawVector3 localCenter;
     RawVector3 localPosition;
     if (srcRectRef.HasValue)
         localRect = srcRectRef.Value;
     if (centerRef.HasValue)
         localCenter = centerRef.Value;
     if (positionRef.HasValue)
         localPosition = positionRef.Value;
     Draw(textureRef, srcRectRef.HasValue ? (IntPtr)(void*)&localRect : IntPtr.Zero, centerRef.HasValue ? (IntPtr)(void*)&localCenter : IntPtr.Zero, positionRef.HasValue ? (IntPtr)(void*)&localPosition : IntPtr.Zero, color);
 }
Пример #4
0
 public ScreenManager(int adapterIndex, int outputIndex)
 {
     using (var adapter = InitializeAdapter(adapterIndex))
     {
         _device = new Device(adapter);
         using(var output = InitializeOutput(adapter, outputIndex))
         {
             _desktopBounds = output.Description.DesktopBounds;
             _outputDuplication = InitializeOutputDuplication(output);
             _texture2DDescription = InitializeTexture2DDescription(_desktopBounds);
         }
     }
 }
Пример #5
0
        /// <summary>
        /// Presents the contents of the next buffer in the sequence of back buffers to the screen.
        /// </summary>
        /// <param name="presentFlags">The present flags.</param>
        /// <param name="sourceRectangle">The area of the back buffer that should be presented.</param>
        /// <param name="destinationRectangle">The area of the front buffer that should receive the result of the presentation.</param>
        /// <param name="windowOverride">The destination window whose client area is taken as the target for this presentation.</param>
        /// <unmanaged>HRESULT IDirect3DSwapChain9::Present([In, Optional] const void* pSourceRect,[InOut, Optional] const void* pDestRect,[In] HWND hDestWindowOverride,[In] const RGNDATA* pDirtyRegion,[In] unsigned int dwFlags)</unmanaged>
        public void Present(Present presentFlags, RawRectangle sourceRectangle, RawRectangle destinationRectangle, IntPtr windowOverride)
        {
            unsafe
            {
                var srcPtr = IntPtr.Zero;
                if (!sourceRectangle.IsEmpty)
                    srcPtr = new IntPtr(&sourceRectangle);

                var destPtr = IntPtr.Zero;
                if (!destinationRectangle.IsEmpty)
                    destPtr = new IntPtr(&destinationRectangle);

                Present(srcPtr, destPtr, windowOverride, IntPtr.Zero, (int)presentFlags);
            }
        }
Пример #6
0
 private unsafe static int MapOutputRectToInputRectsImpl(IntPtr thisPtr, IntPtr outputRect, IntPtr inputRects, int inputRectsCount)
 {
     try
     {
         var shadow = ToShadow<TransformShadow>(thisPtr);
         var callback = (Transform)shadow.Callback;
         var inputRectangles = new RawRectangle[inputRectsCount];
         Utilities.Read(inputRects, inputRectangles, 0, inputRectsCount);
         callback.MapOutputRectangleToInputRectangles(*(RawRectangle*)outputRect, inputRectangles);
         Utilities.Write(inputRects, inputRectangles, 0, inputRectsCount);
     }
     catch (Exception exception)
     {
         return (int)SharpDX.Result.GetResultFromException(exception);
     }
     return Result.Ok.Code;
 }
Пример #7
0
 /// <summary>
 /// Presents the contents of the next buffer in the sequence of back buffers to the screen.
 /// </summary>
 /// <param name="presentFlags">The present flags.</param>
 /// <param name="sourceRectangle">The area of the back buffer that should be presented.</param>
 /// <param name="destinationRectangle">The area of the front buffer that should receive the result of the presentation.</param>
 /// <unmanaged>HRESULT IDirect3DSwapChain9::Present([In, Optional] const void* pSourceRect,[InOut, Optional] const void* pDestRect,[In] HWND hDestWindowOverride,[In] const RGNDATA* pDirtyRegion,[In] unsigned int dwFlags)</unmanaged>
 public void Present(Present presentFlags, RawRectangle sourceRectangle, RawRectangle destinationRectangle)
 {
     Present(presentFlags, sourceRectangle, destinationRectangle, IntPtr.Zero);
 }
Пример #8
0
        private void ProcessModifiedRegions()
        {
            var numberOfBytes = 0;
            var rectangles = new RawRectangle[_frameInfo.TotalMetadataBufferSize];

            if (_frameInfo.TotalMetadataBufferSize > 0)
            {
                _outputDuplication.GetFrameDirtyRects(rectangles.Length, rectangles, out numberOfBytes);
            }

            _frame.ModifiedRegions = new ScreenFrameRectangle[numberOfBytes / Marshal.SizeOf(typeof(RawRectangle))];

            for (var i = 0; i < _frame.ModifiedRegions.Length; i++)
            {
                _frame.ModifiedRegions[i].Bottom = rectangles[i].Bottom;
                _frame.ModifiedRegions[i].Left = rectangles[i].Left;
                _frame.ModifiedRegions[i].Right = rectangles[i].Right;
                _frame.ModifiedRegions[i].Top = rectangles[i].Top;
            }
        }
Пример #9
0
        /// <summary>
        /// Presents the contents of the next buffer in the sequence of back buffers to the screen.
        /// </summary>
        /// <param name="flags">The flags.</param>
        /// <param name="sourceRectangle">The area of the back buffer that should be presented.</param>
        /// <param name="destinationRectangle">The area of the front buffer that should receive the result of the presentation.</param>
        /// <param name="windowOverride">The destination window whose client area is taken as the target for this presentation.</param>
        /// <param name="region">Specifies a region on the back buffer that contains the minimal amount of pixels that need to be updated.</param>
        /// <unmanaged>HRESULT IDirect3DSwapChain9::Present([In, Optional] const void* pSourceRect,[InOut, Optional] const void* pDestRect,[In] HWND hDestWindowOverride,[In] const RGNDATA* pDirtyRegion,[In] unsigned int dwFlags)</unmanaged>
        public void Present(Present flags, RawRectangle sourceRectangle, RawRectangle destinationRectangle, IntPtr windowOverride, System.Drawing.Region region)
        {
            unsafe
            {
                var graphics = System.Drawing.Graphics.FromHwnd(windowOverride);
                var regionPtr = region.GetHrgn(graphics);
                graphics.Dispose();

                var srcPtr = IntPtr.Zero;
                if (!sourceRectangle.IsEmpty)
                    srcPtr = new IntPtr(&sourceRectangle);

                var destPtr = IntPtr.Zero;
                if (!destinationRectangle.IsEmpty)
                    destPtr = new IntPtr(&destinationRectangle);

                Present(srcPtr, destPtr, windowOverride, regionPtr, (int)flags);
            }
        }
Пример #10
0
 /// <summary>
 /// Initializes a new instance of <see cref="BoundsAdjustmentTransform"/> class
 /// </summary>
 /// <param name="context">The effect context</param>
 /// <param name="outputRectangle">The output rectangle region used for this transformation</param>
 /// <unmanaged>HRESULT ID2D1EffectContext::CreateBoundsAdjustmentTransform([In] const RECT* outputRectangle,[Out, Fast] ID2D1BoundsAdjustmentTransform** transform)</unmanaged>	
 public BoundsAdjustmentTransform(EffectContext context, RawRectangle outputRectangle)
     : base(IntPtr.Zero)
 {
     context.CreateBoundsAdjustmentTransform(outputRectangle, this);
 }
 public static int GetHeight(this Rectangle rect)
 {
     return(rect.Bottom - rect.Top);
 }
Пример #12
0
 /// <inheritdoc/>
 public void MapOutputRectangleToInputRectangles(RawRectangle outputRect, RawRectangle[] inputRects)
 {
     MapOutputRectToInputRects_(outputRect, inputRects, inputRects.Length);
 }
Пример #13
0
 /// <summary>
 /// Получить изменившиеся области
 /// </summary>
 /// <returns>Массив прямоугольников, где были изменения относительно предыдущего кадра</returns>
 private Rectangle[] GetDirtyRectangles()
 {
     Rectangle[] result = new Rectangle[0];
     if (this._screenInfo.TotalMetadataBufferSize > 0)
     {
         int dirtyRegionsLength = 0;
         RawRectangle[] rectangles = new RawRectangle[this._screenInfo.TotalMetadataBufferSize];
         this._outputDublication.GetFrameDirtyRects(rectangles.Length, rectangles, out dirtyRegionsLength);
         result = new Rectangle[dirtyRegionsLength / Marshal.SizeOf(typeof(RawRectangle))];
         for (int i = 0; i < result.Length; i++)
         {
             result[i] = new Rectangle(
                 rectangles[i].Left, 
                 rectangles[i].Top,
                 rectangles[i].Right - rectangles[i].Left,
                 rectangles[i].Bottom - rectangles[i].Top
             );
         }
     }
     return result;
 }
Пример #14
0
 /// <summary>
 /// Measures the specified text.
 /// </summary>
 /// <param name="sprite">Pointer to an <see cref="SharpDX.Direct3D10.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> </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>
 /// <unmanaged>int ID3DX10Font::DrawTextW([In] ID3DX10Sprite* pSprite,[In] const wchar_t* pString,[In] int Count,[In] RECT* pRect,[In] unsigned int Format,[In] D3DXCOLOR Color)</unmanaged>	
 public unsafe RawRectangle MeasureText(Sprite sprite, string text, RawRectangle rect, FontDrawFlags drawFlags)
 {
     // DT_CALCRECT
     DrawText(sprite, text, text.Length, new IntPtr(&rect), ((int)drawFlags) | 0x400, whiteColor);
     return rect;
 }
Пример #15
0
 /// <inheritdoc/>
 public RawRectangle MapInputRectanglesToOutputRectangle(RawRectangle[] inputRects, RawRectangle[] inputOpaqueSubRects, out RawRectangle outputOpaqueSubRect)
 {
     return MapInputRectsToOutputRect_(inputRects, inputOpaqueSubRects, inputRects.Length, out outputOpaqueSubRect);
 }
Пример #16
0
 public RawRectangle MapInputRectanglesToOutputRectangle(RawRectangle[] inputRects, RawRectangle[] inputOpaqueSubRects, out RawRectangle outputOpaqueSubRect)
 {
     if (inputRects.Length != 1)
         throw new ArgumentException("InputRects must be length of 1", "inputRects");
     outputOpaqueSubRect = default(Rectangle);
     return inputRects[0];
 }
Пример #17
0
 /// <inheritdoc/>
 public void Draw(SharpDX.Direct2D1.Bitmap1 target, RawRectangle drawRect, RawPoint targetOrigin)
 {
     Draw_(target, drawRect, targetOrigin);
 }
Пример #18
0
 /// <summary>
 /// Swap the swapchain's next buffer with the front buffer.
 /// </summary>
 /// <param name="flags">The flags.</param>
 /// <param name="sourceRectangle">The source rectangle.</param>
 /// <param name="destinationRectangle">The destination rectangle.</param>
 /// <param name="windowOverride">The window override.</param>
 /// <param name="region">The region.</param>
 /// <returns>
 /// A <see cref="SharpDX.Result"/> object describing the result of the operation.
 /// </returns>
 /// <unmanaged>HRESULT IDirect3DDevice9Ex::PresentEx([In] const void* pSourceRect,[In] const void* pDestRect,[In] HWND hDestWindowOverride,[In] const RGNDATA* pDirtyRegion,[In] unsigned int dwFlags)</unmanaged>
 public void PresentEx(Present flags, RawRectangle sourceRectangle, RawRectangle destinationRectangle, IntPtr windowOverride, Region region)
 {
     unsafe
     {
         var graphics = Graphics.FromHwnd(windowOverride);
         var regionPtr = region.GetHrgn(graphics);
         graphics.Dispose();
         PresentEx(new IntPtr(&sourceRectangle), new IntPtr(&destinationRectangle), windowOverride, regionPtr, (int)flags);
     }            
 }
Пример #19
0
 /// <summary>
 /// Swap the swapchain's next buffer with the front buffer.
 /// </summary>
 /// <param name="flags">The flags.</param>
 /// <param name="sourceRectangle">The source rectangle.</param>
 /// <param name="destinationRectangle">The destination rectangle.</param>
 /// <param name="windowOverride">The window override.</param>
 /// <returns>
 /// A <see cref="SharpDX.Result"/> object describing the result of the operation.
 /// </returns>
 /// <unmanaged>HRESULT IDirect3DDevice9Ex::PresentEx([In] const void* pSourceRect,[In] const void* pDestRect,[In] HWND hDestWindowOverride,[In] const RGNDATA* pDirtyRegion,[In] unsigned int dwFlags)</unmanaged>
 public void PresentEx(Present flags, RawRectangle sourceRectangle, RawRectangle destinationRectangle, IntPtr windowOverride)
 {
     unsafe
     {
         PresentEx(new IntPtr(&sourceRectangle), new IntPtr(&destinationRectangle), windowOverride, IntPtr.Zero, (int)flags);
     }
 }
Пример #20
0
 public void MapOutputRectangleToInputRectangles(RawRectangle outputRect, RawRectangle[] inputRects)
 {
     int expansion = (int)Math.Round(constants.Amplitude);
     if (inputRects.Length != 1)
         throw new ArgumentException("InputRects must be length of 1", "inputRects");
     inputRects[0].Left = outputRect.Left - expansion;
     inputRects[0].Top = outputRect.Top - expansion;
     inputRects[0].Right = outputRect.Right + expansion;
     inputRects[0].Bottom = outputRect.Bottom + expansion;
 }
Пример #21
0
 /// <summary>
 /// Binds a set of scissor rectangles to the rasterizer stage. See <see cref="Render+states"/> to learn how to use it.
 /// </summary>
 /// <param name="scissorRectangles">The set of scissor rectangles to bind.</param>
 public unsafe void SetScissorRectangles(params Rectangle[] scissorRectangles)
 {
     if (scissorRectangles == null) throw new ArgumentNullException("scissorRectangles");
     var localScissorRectangles = new RawRectangle[scissorRectangles.Length];
     for (int i = 0; i < scissorRectangles.Length; i++)
     {
         localScissorRectangles[i] = new RawRectangle(scissorRectangles[i].X, scissorRectangles[i].Y, scissorRectangles[i].Right, scissorRectangles[i].Bottom);
     }
     NativeDeviceContext.Rasterizer.SetScissorRectangles(localScissorRectangles);
 }
Пример #22
0
 /// <summary>
 /// Locks a rectangle on a cube texture resource.
 /// </summary>
 /// <param name="faceType">Type of the face.</param>
 /// <param name="level">The level.</param>
 /// <param name="rectangle">The rectangle.</param>
 /// <param name="flags">The flags.</param>
 /// <returns>
 /// A <see cref="DataRectangle"/> describing the region locked.
 /// </returns>
 /// <unmanaged>HRESULT IDirect3DCubeTexture9::LockRect([In] D3DCUBEMAP_FACES FaceType,[In] unsigned int Level,[In] D3DLOCKED_RECT* pLockedRect,[In] const void* pRect,[In] D3DLOCK Flags)</unmanaged>
 public DataRectangle LockRectangle(SharpDX.Direct3D9.CubeMapFace faceType, int level, RawRectangle rectangle, SharpDX.Direct3D9.LockFlags flags) {
     unsafe
     {
         LockedRectangle lockedRect;
         LockRectangle(faceType, level, out lockedRect, new IntPtr(&rectangle), flags);
         return new DataRectangle(lockedRect.PBits, lockedRect.Pitch);
     }
 }
Пример #23
0
 /// <summary>
 /// Locks a rectangle on a cube texture resource.
 /// </summary>
 /// <param name="faceType">Type of the face.</param>
 /// <param name="level">The level.</param>
 /// <param name="rectangle">The rectangle.</param>
 /// <param name="flags">The flags.</param>
 /// <param name="stream">The stream pointing to the locked region.</param>
 /// <returns>
 /// A <see cref="DataRectangle"/> describing the region locked.
 /// </returns>
 /// <unmanaged>HRESULT IDirect3DCubeTexture9::LockRect([In] D3DCUBEMAP_FACES FaceType,[In] unsigned int Level,[In] D3DLOCKED_RECT* pLockedRect,[In] const void* pRect,[In] D3DLOCK Flags)</unmanaged>
 public DataRectangle LockRectangle(SharpDX.Direct3D9.CubeMapFace faceType, int level, RawRectangle rectangle, SharpDX.Direct3D9.LockFlags flags, out DataStream stream)
 {
     unsafe
     {
         LockedRectangle lockedRect;
         LockRectangle(faceType, level, out lockedRect, new IntPtr(&rectangle), flags);
         stream = new DataStream(lockedRect.PBits, lockedRect.Pitch * GetLevelDescription(level).Height, true, (flags & LockFlags.ReadOnly) == 0);
         return new DataRectangle(lockedRect.PBits, lockedRect.Pitch);
     }
 }
Пример #24
0
 /// <summary>
 /// Adds a dirty region to a cube texture resource.
 /// </summary>
 /// <param name="faceType">Type of the face.</param>
 /// <param name="dirtyRectRef">The dirty rect ref.</param>
 /// <returns>A <see cref="SharpDX.Result" /> object describing the result of the operation.</returns>
 /// <unmanaged>HRESULT IDirect3DCubeTexture9::AddDirtyRect([In] D3DCUBEMAP_FACES FaceType,[In] const void* pDirtyRect)</unmanaged>
 public void AddDirtyRectangle(SharpDX.Direct3D9.CubeMapFace faceType, RawRectangle dirtyRectRef)
 {
     unsafe
     {
         AddDirtyRectangle(faceType, new IntPtr(&dirtyRectRef));
     }
 }
Пример #25
0
 /// <inheritdoc/>
 public RawRectangle MapInvalidRect(int inputIndex, RawRectangle invalidInputRect)
 {
     return MapInvalidRect_(inputIndex, invalidInputRect);
 }
Пример #26
0
 private Texture2DDescription InitializeTexture2DDescription(RawRectangle desktopBounds)
 {
     return new Texture2DDescription
     {
         ArraySize = 1,
         BindFlags = BindFlags.None,
         CpuAccessFlags = CpuAccessFlags.Read,
         Format = Format.B8G8R8A8_UNorm,
         Height = desktopBounds.Bottom,
         MipLevels = 1,
         OptionFlags = ResourceOptionFlags.None,
         SampleDescription = { Count = 1, Quality = 0 },
         Usage = ResourceUsage.Staging,
         Width = desktopBounds.Right
     };
 }
Пример #27
0
 /// <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;
 }
 public static int GetWidth(this Rectangle rect)
 {
     return(rect.Right - rect.Left);
 }
Пример #29
0
        private Glyph ImportGlyph(Factory factory, FontFace fontFace, char character, FontMetrics fontMetrics, float fontSize, FontAntiAliasMode antiAliasMode)
        {
            var indices = fontFace.GetGlyphIndices(new int[] { character });

            var metrics = fontFace.GetDesignGlyphMetrics(indices, false);
            var metric = metrics[0];

            var width = (float)(metric.AdvanceWidth - metric.LeftSideBearing - metric.RightSideBearing) / fontMetrics.DesignUnitsPerEm * fontSize;
            var height = (float)(metric.AdvanceHeight - metric.TopSideBearing - metric.BottomSideBearing) / fontMetrics.DesignUnitsPerEm * fontSize;

            var xOffset = (float)metric.LeftSideBearing / fontMetrics.DesignUnitsPerEm * fontSize;
            var yOffset = (float)(metric.TopSideBearing - metric.VerticalOriginY) / fontMetrics.DesignUnitsPerEm * fontSize;

            var advanceWidth = (float)metric.AdvanceWidth / fontMetrics.DesignUnitsPerEm * fontSize;
            //var advanceHeight = (float)metric.AdvanceHeight / fontMetrics.DesignUnitsPerEm * fontSize;

            var pixelWidth = (int)Math.Ceiling(width + 4);
            var pixelHeight = (int)Math.Ceiling(height + 4);

            var matrix = new RawMatrix3x2
            {
                M11 = 1,
                M22 = 1,
                M31 = -(float)Math.Floor(xOffset) + 1,
                M32 = -(float)Math.Floor(yOffset) + 1
            };

            Bitmap bitmap;
            if (char.IsWhiteSpace(character))
            {
                bitmap = new Bitmap(1, 1, PixelFormat.Format32bppArgb);
            }
            else
            {
                var glyphRun = new GlyphRun
                {
                    FontFace = fontFace,
                    Advances = new[] { (float)Math.Ceiling(advanceWidth) },
                    FontSize = fontSize,
                    BidiLevel = 0,
                    Indices = indices,
                    IsSideways = false,
                    Offsets = new[] { new GlyphOffset() }
                };


                RenderingMode renderingMode;
                if (antiAliasMode != FontAntiAliasMode.Aliased)
                {
                    var rtParams = new RenderingParams(factory);
                    renderingMode = fontFace.GetRecommendedRenderingMode(fontSize, 1.0f, MeasuringMode.Natural, rtParams);
                    rtParams.Dispose();
                }
                else
                {
                    renderingMode = RenderingMode.Aliased;
                }

                using (var runAnalysis = new GlyphRunAnalysis(factory,
                    glyphRun,
                    1.0f,
                    matrix,
                    renderingMode,
                    MeasuringMode.Natural,
                    0.0f,
                    0.0f))
                {

                    var bounds = new RawRectangle(0, 0, pixelWidth, pixelHeight);
                    bitmap = new Bitmap(pixelWidth, pixelHeight, PixelFormat.Format32bppArgb);

                    if (renderingMode == RenderingMode.Aliased)
                    {

                        var texture = new byte[pixelWidth * pixelHeight];
                        runAnalysis.CreateAlphaTexture(TextureType.Aliased1x1, bounds, texture, texture.Length);
                        for (int y = 0; y < pixelHeight; y++)
                        {
                            for (int x = 0; x < pixelWidth; x++)
                            {
                                int pixelX = y * pixelWidth + x;
                                var grey = texture[pixelX];
                                var color = Color.FromArgb(grey, grey, grey);

                                bitmap.SetPixel(x, y, color);
                            }
                        }
                    }
                    else
                    {
                        var texture = new byte[pixelWidth * pixelHeight * 3];
                        runAnalysis.CreateAlphaTexture(TextureType.Cleartype3x1, bounds, texture, texture.Length);
                        for (int y = 0; y < pixelHeight; y++)
                        {
                            for (int x = 0; x < pixelWidth; x++)
                            {
                                int pixelX = (y * pixelWidth + x) * 3;
                                var red = LinearToGamma(texture[pixelX]);
                                var green = LinearToGamma(texture[pixelX + 1]);
                                var blue = LinearToGamma(texture[pixelX + 2]);
                                var color = Color.FromArgb(red, green, blue);

                                bitmap.SetPixel(x, y, color);
                            }
                        }
                    }
                }
            }

            var glyph = new Glyph(character, bitmap)
            {
                XOffset = -matrix.M31,
                XAdvance = advanceWidth,
                YOffset = -matrix.M32,
            };
            return glyph;
        }
Пример #30
0
 public static extern bool GetClientRect(IntPtr hWnd, out RawRectangle lpRect);
Пример #31
0
 /// <summary>
 ///   Binds a single scissor rectangle to the rasterizer stage.
 /// </summary>
 /// <param name = "scissorRectangle">The scissor rectangle to bind.</param>
 public void SetScissorRectangles(RawRectangle scissorRectangle)
 {
     SetScissorRectangles(new RawRectangle[] { scissorRectangle });
 }
Пример #32
0
 /// <summary>	
 /// Get the array of {{scissor rectangles}} bound to the {{rasterizer stage}}.	
 /// </summary>	
 /// <returns>An array of scissor rectangles (see <see cref="RawRectangle"/>).</returns>
 /// <unmanaged>void RSGetScissorRects([InOut] int* NumRects,[Out, Buffer, Optional] D3D10_RECT* pRects)</unmanaged>
 public void GetScissorRectangles(RawRectangle[] scissorRectangles)
 {
     int numRects = scissorRectangles.Length;
     GetScissorRects(ref numRects, scissorRectangles);
 }
Пример #33
-1
 /// <summary>	
 /// Draw formatted text.
 /// </summary>	
 /// <remarks>	
 /// The parameters of this method are very similar to those of the {{GDI DrawText}} function. This method supports both ANSI and Unicode strings. 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>	
 /// <param name="sprite">Reference to an ID3DX10Sprite object that contains the string you wish to draw. Can be NULL, in which case Direct3D will render the string with its own sprite object. To improve efficiency, a sprite object should be specified if ID3DX10Font::DrawText is to be called more than once in a row. </param>
 /// <param name="text">Pointer to a string to draw. If UNICODE is defined, this parameter type resolves to an LPCWSTR, otherwise, the type resolves to an LPCSTR. If the Count parameter is -1, the string must be NULL terminated. </param>
 /// <param name="rect">Pointer to a <see cref="RawRectangle"/> structure that contains the rectangle, in logical coordinates, in which the text is to be formatted. As with any RECT object, 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. </param>
 /// <param name="drawFlags">Specify the method of formatting the text. It can be any combination of the following values:    ItemDescription  DT_BOTTOM  Justify the text to the bottom of the rectangle. This value must be combined with DT_SINGLELINE.   DT_CALCRECT  Tell DrawText to automatically calculate the width and height of the rectangle based on the length of the string you tell it to draw. If there are multiple lines of text, ID3DX10Font::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, ID3DX10Font::DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, ID3DX10Font::DrawText returns the height of the formatted text but does not draw the text.   DT_CENTER  Center text horizontally in the rectangle.   DT_EXPANDTABS  Expand tab characters. The default number of characters per tab is eight.   DT_LEFT  Align text to the left.   DT_NOCLIP  Draw without clipping. ID3DX10Font::DrawText is somewhat faster when DT_NOCLIP is used.   DT_RIGHT  Align text to the right.   DT_RTLREADING  Display 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.   DT_SINGLELINE  Display text on a single line only. Carriage returns and line feeds do not break the line.   DT_TOP  Top-justify text.   DT_VCENTER  Center text vertically (single line only).   DT_WORDBREAK  Break 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.   ? </param>
 /// <param name="color">Color of the text. 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 ID3DX10Font::DrawTextW([None] LPD3DX10SPRITE pSprite,[None] const wchar_t* pString,[None] int Count,[None] RECT* pRect,[None] int Format,[None] D3DXCOLOR Color)</unmanaged>
 public unsafe int DrawText(SharpDX.Direct3D10.Sprite sprite, string text, RawRectangle rect, FontDrawFlags drawFlags, RawColor4 color)
 {
     int value = DrawText(sprite, text, text.Length, new IntPtr(&rect), (int) drawFlags, color);
     if (value == 0)
         throw new SharpDXException("Draw failed");
     return value;
 }