<commit_before>﻿/*
* Copyright (c) 2007-2009 SlimDX Group
* 
* 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.Collections.Generic;
using System.IO;
using System.Reflection;

using D3D = SlimDX.Direct3D10;

namespace SlimDX.SampleFramework {
	/// <summary>
	/// Provides functionality to render a user interface using Direct3D10.
	/// </summary>
	public class UserInterfaceRenderer10 : UserInterfaceRenderer {
		#region Public Interface

		/// <summary>
		/// Initializes a new instance of the <see cref="UserInterfaceRenderer10"/> class.
		/// </summary>
		/// <param name="device">The device.</param>
		/// <param name="width">The width of the renderable area.</param>
		/// <param name="height">The height of the renderable area.</param>
		public UserInterfaceRenderer10( D3D.Device device, int width, int height ) {
			if( device == null )
				throw new ArgumentNullException( "device" );
			if( width < 0 )
				throw new ArgumentException( "Value must be positive.", "width" );
			if( height < 0 )
				throw new ArgumentException( "Value must be positive.", "height" );

			this.device = device;
			halfWidth = width / 2;
			halfHeight = height / 2;

			font = new D3D.Font( device, 18, 0, D3D.FontWeight.Bold, 0, false, D3D.FontCharacterSet.Default, D3D.FontPrecision.Default, D3D.FontQuality.Antialiased, D3D.FontPitchAndFamily.Default, "Arial" );
			sprite = new SlimDX.Direct3D10.Sprite( device, 0 );
			lineBuffer = new DynamicPrimitiveBuffer10<ColoredVertex>( device );

			Assembly assembly = Assembly.GetExecutingAssembly();
			using( Stream stream = assembly.GetManifestResourceStream( "SampleFramework.Resources.UserInterface10.fx" ) )
			using( StreamReader reader = new StreamReader( stream ) ) {
				effect = D3D.Effect.FromString( device, reader.ReadToEnd(), "fx_4_0", D3D.ShaderFlags.None, D3D.EffectFlags.None, null, null );
			}

			technique = effect.GetTechniqueByIndex( 0 );
			pass = technique.GetPassByIndex( 0 );
			
			D3D.ShaderSignature signature = pass.Description.Signature;
			inputLayout = new D3D.InputLayout( device, new[] {
				new D3D.InputElement("POSITION", 0, SlimDX.DXGI.Format.R32G32B32_Float, 0, 0),
				new D3D.InputElement("COLOR", 0, SlimDX.DXGI.Format.R8G8B8A8_UNorm, D3D.InputElement.AppendAligned, 0 )
			}, signature );
			signature.Dispose();
		}

		/// <summary>
		/// Disposes of object resources.
		/// </summary>
		/// <param name="disposeManagedResources">If true, managed resources should be
		/// disposed of in addition to unmanaged resources.</param>
		protected override void Dispose( bool disposeManagedResources ) {
			if( disposeManagedResources ) {
				effect.Dispose();
				inputLayout.Dispose();
				lineBuffer.Dispose();
				sprite.Dispose();
				font.Dispose();
			}

			base.Dispose( disposeManagedResources );
		}

		/// <summary>
		/// In a derived class, implements logic to flush all pending rendering commands.
		/// </summary>
		protected override void Flush() {
			Matrix offset = Matrix.Translation( -1.0f, 1.0f, 0.0f );
			Matrix scale = Matrix.Scaling( 1.0f / halfWidth, -1.0f / halfHeight, 1.0f );

			D3D.EffectVariable transform = effect.GetVariableBySemantic( "MatrixWVP" );<commit_msg>10 UI renderer no longer uses deprecated calls.<commit_after>﻿/*
* Copyright (c) 2007-2009 SlimDX Group
* 
* 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.Collections.Generic;
using System.IO;
using System.Reflection;

using D3D = SlimDX.Direct3D10;

namespace SlimDX.SampleFramework {
	/// <summary>
	/// Provides functionality to render a user interface using Direct3D10.
	/// </summary>
	public class UserInterfaceRenderer10 : UserInterfaceRenderer {
		#region Public Interface

		/// <summary>
		/// Initializes a new instance of the <see cref="UserInterfaceRenderer10"/> class.
		/// </summary>
		/// <param name="device">The device.</param>
		/// <param name="width">The width of the renderable area.</param>
		/// <param name="height">The height of the renderable area.</param>
		public UserInterfaceRenderer10( D3D.Device device, int width, int height ) {
			if( device == null )
				throw new ArgumentNullException( "device" );
			if( width < 0 )
				throw new ArgumentException( "Value must be positive.", "width" );
			if( height < 0 )
				throw new ArgumentException( "Value must be positive.", "height" );

			this.device = device;
			halfWidth = width / 2;
			halfHeight = height / 2;

			font = new D3D.Font( device, 18, 0, D3D.FontWeight.Bold, 0, false, D3D.FontCharacterSet.Default, D3D.FontPrecision.Default, D3D.FontQuality.Antialiased, D3D.FontPitchAndFamily.Default, "Arial" );
			sprite = new SlimDX.Direct3D10.Sprite( device, 0 );
			lineBuffer = new DynamicPrimitiveBuffer10<ColoredVertex>( device );

			Assembly assembly = Assembly.GetExecutingAssembly();
			using( Stream stream = assembly.GetManifestResourceStream( "SampleFramework.Resources.UserInterface10.fx" ) )
			using( StreamReader reader = new StreamReader( stream ) ) {
				effect = D3D.Effect.FromString( device, reader.ReadToEnd(), "fx_4_0", D3D.ShaderFlags.None, D3D.EffectFlags.None, null, null );
			}

			technique = effect.GetTechniqueByIndex( 0 );
			pass = technique.GetPassByIndex( 0 );
			
			D3D.ShaderSignature signature = pass.Description.Signature;
			inputLayout = new D3D.InputLayout( device, signature, new[] {
				new D3D.InputElement("POSITION", 0, SlimDX.DXGI.Format.R32G32B32_Float, 0, 0),
				new D3D.InputElement("COLOR", 0, SlimDX.DXGI.Format.R8G8B8A8_UNorm, D3D.InputElement.AppendAligned, 0 )
			} );
			signature.Dispose();
		}

		/// <summary>
		/// Disposes of object resources.
		/// </summary>
		/// <param name="disposeManagedResources">If true, managed resources should be
		/// disposed of in addition to unmanaged resources.</param>
		protected override void Dispose( bool disposeManagedResources ) {
			if( disposeManagedResources ) {
				effect.Dispose();
				inputLayout.Dispose();
				lineBuffer.Dispose();
				sprite.Dispose();
				font.Dispose();
			}

			base.Dispose( disposeManagedResources );
		}

		/// <summary>
		/// In a derived class, implements logic to flush all pending rendering commands.
		/// </summary>
		protected override void Flush() {
			Matrix offset = Matrix.Translation( -1.0f, 1.0f, 0.0f );
			Matrix scale = Matrix.Scaling( 1.0f / halfWidth, -1.0f / halfHeight, 1.0f );

			D3D.EffectVariable transform = effect.GetVariableBySemantic( "MatrixWVP" );
{'fraction_non_alphanumeric': 0.10775964040690797, 'fraction_numerical': 0.02010882422521883, 'mean_word_length': 3.9589442815249267, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2560206', 'n_tokens_mistral': 2800, 'n_tokens_neox': 2429, 'n_words': 841}