Skip to content

Commit

Permalink
Added SpriteSheet support (1.1.950)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThuCommix committed Jul 2, 2014
1 parent 78566e8 commit 7a7fbd0
Show file tree
Hide file tree
Showing 58 changed files with 945 additions and 220 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
using System;
// Copyright (c) 2012-2014 Sharpex2D - Kevin Scholz (ThuCommix)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the 'Software'), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System;
using System.IO;
using Sharpex2D.Framework.Rendering.DirectX10.Fonts;
using Sharpex2D.Framework.Rendering.Fonts;

namespace Sharpex2D.Framework.Content.Pipeline.Processors
{
[Developer("ThuCommix", "developer@sharpex2d.de")]
[Copyright("©Sharpex2D 2013 - 2014")]
[TestState(TestState.Tested)]
public class DirectXFontContentProcessor : ContentProcessor<DirectXFont>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
using System;
// Copyright (c) 2012-2014 Sharpex2D - Kevin Scholz (ThuCommix)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the 'Software'), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System;
using System.IO;
using Sharpex2D.Framework.Rendering;
using Sharpex2D.Framework.Rendering.DirectX10;

namespace Sharpex2D.Framework.Content.Pipeline.Processors
{
[Developer("ThuCommix", "developer@sharpex2d.de")]
[Copyright("©Sharpex2D 2013 - 2014")]
[TestState(TestState.Tested)]
public class DirectXPenContentProcessor : ContentProcessor<DirectXPen>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
using System;
// Copyright (c) 2012-2014 Sharpex2D - Kevin Scholz (ThuCommix)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the 'Software'), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
Expand All @@ -8,7 +28,6 @@
namespace Sharpex2D.Framework.Content.Pipeline.Processors
{
[Developer("ThuCommix", "developer@sharpex2d.de")]
[Copyright("©Sharpex2D 2013 - 2014")]
[TestState(TestState.Tested)]
public class DirectXTextureContentProcessor : ContentProcessor<DirectXTexture>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
using System.Drawing;
// Copyright (c) 2012-2014 Sharpex2D - Kevin Scholz (ThuCommix)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the 'Software'), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System.Drawing;
using SlimDX;
using SlimDX.Direct2D;
using Brush = SlimDX.Direct2D.Brush;
Expand All @@ -7,7 +27,6 @@
namespace Sharpex2D.Framework.Rendering.DirectX10
{
[Developer("ThuCommix", "developer@sharpex2d.de")]
[Copyright("©Sharpex2D 2013 - 2014")]
[TestState(TestState.Tested)]
public class DirectXHelper
{
Expand Down Expand Up @@ -89,5 +108,15 @@ public static Brush ConvertSolidColorBrush(Color color)
{
return new SolidColorBrush(RenderTarget, ConvertColor(color));
}

/// <summary>
/// Converts the Rectangle.
/// </summary>
/// <param name="rectangle">The Rectangle.</param>
/// <returns>Rectangle.</returns>
internal static RectangleF ConvertRectangleF(Math.Rectangle rectangle)
{
return new RectangleF(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
using Sharpex2D.Framework.Content.Pipeline;
// Copyright (c) 2012-2014 Sharpex2D - Kevin Scholz (ThuCommix)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the 'Software'), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using Sharpex2D.Framework.Content.Pipeline;
using SlimDX;
using SlimDX.Direct2D;

namespace Sharpex2D.Framework.Rendering.DirectX10
{
[Developer("ThuCommix", "developer@sharpex2d.de")]
[Copyright("©Sharpex2D 2013 - 2014")]
[TestState(TestState.Tested)]
[Content("DirectX10 Pen")]
public class DirectXPen : IPen
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
using System;
// Copyright (c) 2012-2014 Sharpex2D - Kevin Scholz (ThuCommix)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the 'Software'), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System;
using System.Drawing;
using Sharpex2D.Framework.Content.Pipeline;
using Sharpex2D.Framework.Content.Pipeline.Processors;
Expand All @@ -23,7 +43,6 @@
namespace Sharpex2D.Framework.Rendering.DirectX10
{
[Developer("ThuCommix", "developer@sharpex2d.de")]
[Copyright("©Sharpex2D 2013 - 2014")]
[TestState(TestState.Tested)]
[Device("DirectX10 Device")]
public class DirectXRenderDevice : RenderDevice
Expand Down Expand Up @@ -122,18 +141,22 @@ public override void InitializeDevice()

SlimDX.DXGI.Surface backBuffer = SlimDX.DXGI.Surface.FromSwapChain(_swapChain, 0);
var d2DFactory = new SlimDX.Direct2D.Factory(SlimDX.Direct2D.FactoryType.Multithreaded);
SizeF dpi = d2DFactory.DesktopDpi;

RenderTarget renderTarget = RenderTarget.FromDXGI(d2DFactory, backBuffer, new RenderTargetProperties
{
HorizontalDpi = dpi.Width,
VerticalDpi = dpi.Height,
HorizontalDpi = 96,
VerticalDpi = 96,
MinimumFeatureLevel = SlimDX.Direct2D.FeatureLevel.Default,
PixelFormat = new PixelFormat(Format.R8G8B8A8_UNorm, AlphaMode.Ignore),
PixelFormat = new PixelFormat(Format.R8G8B8A8_UNorm, AlphaMode.Premultiplied),
Type = RenderTargetType.Hardware,
Usage = RenderTargetUsage.None
});
renderTarget.AntialiasMode = AntialiasMode.Aliased;
renderTarget.AntialiasMode = _smoothingMode == SmoothingMode.AntiAlias
? AntialiasMode.Aliased
: AntialiasMode.PerPrimitive;
renderTarget.TextAntialiasMode = _smoothingMode == SmoothingMode.AntiAlias
? TextAntialiasMode.Aliased
: TextAntialiasMode.Default;

_renderTarget = renderTarget;
DirectXHelper.RenderTarget = _renderTarget;
Expand Down Expand Up @@ -229,6 +252,50 @@ public override void DrawTexture(Texture2D texture, Rectangle rectangle, Color c
: SlimDX.Direct2D.InterpolationMode.NearestNeighbor);
}

/// <summary>
/// Draws a Texture.
/// </summary>
/// <param name="spriteSheet">The SpriteSheet.</param>
/// <param name="position">The Position.</param>
/// <param name="color">The Color.</param>
/// <param name="opacity">The Opacity.</param>
public override void DrawTexture(SpriteSheet spriteSheet, Vector2 position, Color color, float opacity = 1)
{
var dxTexture = spriteSheet.Texture2D as DirectXTexture;
if (dxTexture == null) throw new ArgumentException("DirectXRenderer expects a DirectXTexture as resource.");
Bitmap dxBmp = dxTexture.GetBitmap();

DirectXHelper.RenderTarget.DrawBitmap(dxBmp,
new RectangleF(position.X, position.Y, spriteSheet.Rectangle.Width, spriteSheet.Rectangle.Height),
opacity,
_interpolationMode == InterpolationMode.Linear
? SlimDX.Direct2D.InterpolationMode.Linear
: SlimDX.Direct2D.InterpolationMode.NearestNeighbor,
DirectXHelper.ConvertRectangleF(spriteSheet.Rectangle));
}


/// <summary>
/// Draws a Texture.
/// </summary>
/// <param name="spriteSheet">The SpriteSheet.</param>
/// <param name="rectangle">The Rectangle.</param>
/// <param name="color">The Color.</param>
/// <param name="opacity">The Opacity.</param>
public override void DrawTexture(SpriteSheet spriteSheet, Rectangle rectangle, Color color, float opacity = 1)
{
var dxTexture = spriteSheet.Texture2D as DirectXTexture;
if (dxTexture == null) throw new ArgumentException("DirectXRenderer expects a DirectXTexture as resource.");
Bitmap dxBmp = dxTexture.GetBitmap();

DirectXHelper.RenderTarget.DrawBitmap(dxBmp,
new RectangleF(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height), opacity,
_interpolationMode == InterpolationMode.Linear
? SlimDX.Direct2D.InterpolationMode.Linear
: SlimDX.Direct2D.InterpolationMode.NearestNeighbor,
DirectXHelper.ConvertRectangleF(spriteSheet.Rectangle));
}

/// <summary>
/// Measures the string.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) 2012-2014 Sharpex2D - Kevin Scholz (ThuCommix)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the 'Software'), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using Sharpex2D.Framework.Rendering.Devices;
using Sharpex2D.Framework.Rendering.DirectX10.Fonts;
using Sharpex2D.Framework.Rendering.Fonts;

namespace Sharpex2D.Framework.Rendering.DirectX10
{
[Developer("ThuCommix", "developer@sharpex2d.de")]
[TestState(TestState.Tested)]
public class DirectXResourceManager : ResourceManager
{
/// <summary>
/// Creates a new Resource.
/// </summary>
/// <param name="color">The Color.</param>
/// <param name="width">The Width.</param>
/// <returns>IPen.</returns>
public override IPen CreateResource(Color color, float width)
{
return new DirectXPen(color, width);
}

/// <summary>
/// Creates a new Resource.
/// </summary>
/// <param name="typeface">The Typeface.</param>
/// <returns>IFont.</returns>
public override IFont CreateResource(Typeface typeface)
{
return new DirectXFont(typeface);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
using System.Drawing;
// Copyright (c) 2012-2014 Sharpex2D - Kevin Scholz (ThuCommix)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the 'Software'), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using Sharpex2D.Framework.Content.Pipeline;
Expand All @@ -11,7 +31,6 @@
namespace Sharpex2D.Framework.Rendering.DirectX10
{
[Developer("ThuCommix", "developer@sharpex2d.de")]
[Copyright("©Sharpex2D 2013 - 2014")]
[TestState(TestState.Tested)]
[Content("DirectX10 Texture")]
public class DirectXTexture : Texture2D
Expand Down Expand Up @@ -54,8 +73,8 @@ internal DirectXTexture(System.Drawing.Bitmap bmp)
var bitmapProperties = new BitmapProperties
{
PixelFormat = new PixelFormat(Format.R8G8B8A8_UNorm, AlphaMode.Premultiplied),
HorizontalDpi = _width,
VerticalDpi = _height
HorizontalDpi = 96,
VerticalDpi = 96
};
var size = new Size(bmp.Width, bmp.Height);

Expand Down
Loading

0 comments on commit 7a7fbd0

Please sign in to comment.