diff --git a/.editorconfig b/.editorconfig index 50272ee2..60c11a10 100644 --- a/.editorconfig +++ b/.editorconfig @@ -65,28 +65,33 @@ end_of_line = lf # .NET Code Style Settings [*.{cs,csx,cake,vb}] + # "this." and "Me." qualifiers # https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#this_and_me -dotnet_style_qualification_for_field = true:warning -dotnet_style_qualification_for_property = true:warning -dotnet_style_qualification_for_method = true:warning -dotnet_style_qualification_for_event = true:warning +dotnet_style_qualification_for_field = false:warning +dotnet_style_qualification_for_property = false:warning +dotnet_style_qualification_for_method = false:warning +dotnet_style_qualification_for_event = false:warning + # Language keywords instead of framework type names for type references # https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#language_keywords dotnet_style_predefined_type_for_locals_parameters_members = true:warning dotnet_style_predefined_type_for_member_access = true:warning + # Modifier preferences # https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#normalize_modifiers dotnet_style_require_accessibility_modifiers = always:warning csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async visual_basic_preferred_modifier_order = Partial,Default,Private,Protected,Public,Friend,NotOverridable,Overridable,MustOverride,Overloads,Overrides,MustInherit,NotInheritable,Static,Shared,Shadows,ReadOnly,WriteOnly,Dim,Const,WithEvents,Widening,Narrowing,Custom,Async dotnet_style_readonly_field = true:warning + # Parentheses preferences # https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#parentheses dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:warning dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:warning dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:warning dotnet_style_parentheses_in_other_operators = never_if_unnecessary:suggestion + # Expression-level preferences # https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#expression_level dotnet_style_object_initializer = true:warning @@ -98,6 +103,7 @@ dotnet_style_prefer_auto_properties = true:warning dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning dotnet_style_prefer_conditional_expression_over_assignment = false:suggestion dotnet_style_prefer_conditional_expression_over_return = false:suggestion + # Null-checking preferences # https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#null_checking dotnet_style_coalesce_expression = true:warning @@ -105,11 +111,13 @@ dotnet_style_null_propagation = true:warning # C# Code Style Settings [*.{cs,csx,cake}] + # Implicit and explicit types # https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#implicit-and-explicit-types csharp_style_var_for_built_in_types = true:warning csharp_style_var_when_type_is_apparent = true:warning csharp_style_var_elsewhere = true:warning + # Expression-bodied members # https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#expression_bodied_members csharp_style_expression_bodied_methods = true:warning @@ -118,25 +126,31 @@ csharp_style_expression_bodied_operators = true:warning csharp_style_expression_bodied_properties = true:warning csharp_style_expression_bodied_indexers = true:warning csharp_style_expression_bodied_accessors = true:warning + # Pattern matching # https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#pattern_matching csharp_style_pattern_matching_over_is_with_cast_check = true:warning csharp_style_pattern_matching_over_as_with_null_check = true:warning + # Inlined variable declarations # https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#inlined_variable_declarations csharp_style_inlined_variable_declaration = true:warning + # Expression-level preferences # https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#expression_level_csharp csharp_prefer_simple_default_expression = true:warning csharp_style_deconstructed_variable_declaration = true:warning csharp_style_pattern_local_over_anonymous_function = true:warning + # "Null" checking preferences # https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#null_checking_csharp csharp_style_throw_expression = true:warning csharp_style_conditional_delegate_call = true:warning + # Code block preferences # https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#code_block csharp_prefer_braces = true:warning +csharp_style_prefer_top_level_statements = false:warning ############################# # .NET Formatting Conventions @@ -146,6 +160,7 @@ csharp_prefer_braces = true:warning # Organize usings # https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#usings dotnet_sort_system_directives_first = true + # C# formatting settings # https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#c-formatting-settings csharp_new_line_before_open_brace = all @@ -155,31 +170,36 @@ csharp_new_line_before_finally = true csharp_new_line_before_members_in_object_initializers = true csharp_new_line_before_members_in_anonymous_types = true csharp_new_line_between_query_expression_clauses = true + # Indentation options # https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#indent csharp_indent_case_contents = true csharp_indent_switch_labels = true csharp_indent_labels = no_change + # Spacing options # https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#spacing csharp_space_after_cast = false csharp_space_after_keywords_in_control_flow_statements = true csharp_space_between_method_declaration_parameter_list_parentheses = false csharp_space_between_method_call_parameter_list_parentheses = false -csharp_space_between_parentheses = expressions +csharp_space_between_parentheses = false csharp_space_before_colon_in_inheritance_clause = true csharp_space_after_colon_in_inheritance_clause = true csharp_space_around_binary_operators = before_and_after csharp_space_between_method_declaration_empty_parameter_list_parentheses = false csharp_space_between_method_call_name_and_opening_parenthesis = false csharp_space_between_method_call_empty_parameter_list_parentheses = false + # Wrapping options # https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#wrapping csharp_preserve_single_line_statements = false csharp_preserve_single_line_blocks = true + # More Indentation options (Undocumented) csharp_indent_block_contents = true csharp_indent_braces = false + # Spacing Options (Undocumented) csharp_space_after_comma = true csharp_space_after_dot = false @@ -199,86 +219,135 @@ csharp_space_between_square_brackets = false ######################### [*.{cs,csx,cake,vb}] + # Naming Symbols + # constant_fields - Define constant fields dotnet_naming_symbols.constant_fields.applicable_kinds = field dotnet_naming_symbols.constant_fields.required_modifiers = const + # non_private_readonly_fields - Define public, internal and protected readonly fields dotnet_naming_symbols.non_private_readonly_fields.applicable_accessibilities = public, internal, protected dotnet_naming_symbols.non_private_readonly_fields.applicable_kinds = field dotnet_naming_symbols.non_private_readonly_fields.required_modifiers = readonly + # static_readonly_fields - Define static and readonly fields dotnet_naming_symbols.static_readonly_fields.applicable_kinds = field dotnet_naming_symbols.static_readonly_fields.required_modifiers = static, readonly + # private_readonly_fields - Define private readonly fields dotnet_naming_symbols.private_readonly_fields.applicable_accessibilities = private dotnet_naming_symbols.private_readonly_fields.applicable_kinds = field dotnet_naming_symbols.private_readonly_fields.required_modifiers = readonly + # public_internal_fields - Define public and internal fields dotnet_naming_symbols.public_internal_fields.applicable_accessibilities = public, internal dotnet_naming_symbols.public_internal_fields.applicable_kinds = field -# private_protected_fields - Define private and protected fields -dotnet_naming_symbols.private_protected_fields.applicable_accessibilities = private, protected -dotnet_naming_symbols.private_protected_fields.applicable_kinds = field + +# protected_fields - Define protected fields +dotnet_naming_symbols.protected_fields.applicable_accessibilities = protected +dotnet_naming_symbols.protected_fields.applicable_kinds = field + +# private_fields - Define private fields +dotnet_naming_symbols.private_fields.applicable_accessibilities = private +dotnet_naming_symbols.private_fields.applicable_kinds = field + # public_symbols - Define any public symbol dotnet_naming_symbols.public_symbols.applicable_accessibilities = public, internal, protected, protected_internal dotnet_naming_symbols.public_symbols.applicable_kinds = method, property, event, delegate + # parameters - Defines any parameter dotnet_naming_symbols.parameters.applicable_kinds = parameter + # non_interface_types - Defines class, struct, enum and delegate types dotnet_naming_symbols.non_interface_types.applicable_kinds = class, struct, enum, delegate + # interface_types - Defines interfaces dotnet_naming_symbols.interface_types.applicable_kinds = interface +# local_variables - Defines local_variables +dotnet_naming_symbols.local_variables.applicable_kinds = local + # Naming Styles + # camel_case - Define the camelCase style dotnet_naming_style.camel_case.capitalization = camel_case + +# underscored_camel_case - Define the camelCase style with an underscore prefix +dotnet_naming_style.underscored_camel_case.capitalization = camel_case +dotnet_naming_style.underscored_camel_case.required_prefix = _ + # pascal_case - Define the Pascal_case style dotnet_naming_style.pascal_case.capitalization = pascal_case + # first_upper - The first character must start with an upper-case character dotnet_naming_style.first_upper.capitalization = first_word_upper + # prefix_interface_interface_with_i - Interfaces must be PascalCase and the first character of an interface must be an 'I' dotnet_naming_style.prefix_interface_interface_with_i.capitalization = pascal_case dotnet_naming_style.prefix_interface_interface_with_i.required_prefix = I # Naming Rules + # Constant fields must be PascalCase dotnet_naming_rule.constant_fields_must_be_pascal_case.severity = warning dotnet_naming_rule.constant_fields_must_be_pascal_case.symbols = constant_fields dotnet_naming_rule.constant_fields_must_be_pascal_case.style = pascal_case + # Public, internal and protected readonly fields must be PascalCase dotnet_naming_rule.non_private_readonly_fields_must_be_pascal_case.severity = warning dotnet_naming_rule.non_private_readonly_fields_must_be_pascal_case.symbols = non_private_readonly_fields dotnet_naming_rule.non_private_readonly_fields_must_be_pascal_case.style = pascal_case -# Static readonly fields must be PascalCase -dotnet_naming_rule.static_readonly_fields_must_be_pascal_case.severity = warning -dotnet_naming_rule.static_readonly_fields_must_be_pascal_case.symbols = static_readonly_fields -dotnet_naming_rule.static_readonly_fields_must_be_pascal_case.style = pascal_case -# Private readonly fields must be camelCase -dotnet_naming_rule.private_readonly_fields_must_be_camel_case.severity = warning -dotnet_naming_rule.private_readonly_fields_must_be_camel_case.symbols = private_readonly_fields -dotnet_naming_rule.private_readonly_fields_must_be_camel_case.style = camel_case + # Public and internal fields must be PascalCase dotnet_naming_rule.public_internal_fields_must_be_pascal_case.severity = warning dotnet_naming_rule.public_internal_fields_must_be_pascal_case.symbols = public_internal_fields dotnet_naming_rule.public_internal_fields_must_be_pascal_case.style = pascal_case -# Private and protected fields must be camelCase -dotnet_naming_rule.private_protected_fields_must_be_camel_case.severity = warning -dotnet_naming_rule.private_protected_fields_must_be_camel_case.symbols = private_protected_fields -dotnet_naming_rule.private_protected_fields_must_be_camel_case.style = camel_case + +# Protected fields must be camelCase +dotnet_naming_rule.protected_fields_must_be_camel_case.severity = warning +dotnet_naming_rule.protected_fields_must_be_camel_case.symbols = protected_fields +dotnet_naming_rule.protected_fields_must_be_camel_case.style = camel_case + +# Private fields must be _camelCase +dotnet_naming_rule.private_fields_must_be_underscored_camel_case.severity = warning +dotnet_naming_rule.private_fields_must_be_underscored_camel_case.symbols = private_fields +dotnet_naming_rule.private_fields_must_be_underscored_camel_case.style = underscored_camel_case + # Public members must be capitalized dotnet_naming_rule.public_members_must_be_capitalized.severity = warning dotnet_naming_rule.public_members_must_be_capitalized.symbols = public_symbols dotnet_naming_rule.public_members_must_be_capitalized.style = first_upper + # Parameters must be camelCase dotnet_naming_rule.parameters_must_be_camel_case.severity = warning dotnet_naming_rule.parameters_must_be_camel_case.symbols = parameters dotnet_naming_rule.parameters_must_be_camel_case.style = camel_case + # Class, struct, enum and delegates must be PascalCase dotnet_naming_rule.non_interface_types_must_be_pascal_case.severity = warning dotnet_naming_rule.non_interface_types_must_be_pascal_case.symbols = non_interface_types dotnet_naming_rule.non_interface_types_must_be_pascal_case.style = pascal_case + # Interfaces must be PascalCase and start with an 'I' dotnet_naming_rule.interface_types_must_be_prefixed_with_i.severity = warning dotnet_naming_rule.interface_types_must_be_prefixed_with_i.symbols = interface_types dotnet_naming_rule.interface_types_must_be_prefixed_with_i.style = prefix_interface_interface_with_i + +# Local variables must be camelCase +dotnet_naming_rule.local_variables_must_be_camel_case.severity = warning +dotnet_naming_rule.local_variables_must_be_camel_case.symbols = local_variables +dotnet_naming_rule.local_variables_must_be_camel_case.style = camel_case + +#################### +# Configure severity +#################### + +# IDE0130: Namespace does not match folder structure +dotnet_diagnostic.IDE0130.severity = suggestion + +# IDE0060: Remove unused parameter +dotnet_diagnostic.IDE0060.severity = suggestion + +# CA1805: Do not initialize unnecessarily +dotnet_diagnostic.CA1805.severity = warning \ No newline at end of file diff --git a/SFML.CodeStyle.props b/SFML.CodeStyle.props new file mode 100644 index 00000000..110d2673 --- /dev/null +++ b/SFML.CodeStyle.props @@ -0,0 +1,13 @@ + + + + + + true + true + all + all + all + + + diff --git a/SFML.Module.props b/SFML.Module.props index 7b3ca3ff..f6a6da25 100644 --- a/SFML.Module.props +++ b/SFML.Module.props @@ -3,6 +3,7 @@ + true diff --git a/SFML.sln b/SFML.sln index 1974829e..f25045b8 100644 --- a/SFML.sln +++ b/SFML.sln @@ -1,17 +1,22 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26124.0 +# Visual Studio Version 17 +VisualStudioVersion = 17.11.35208.52 MinimumVisualStudioVersion = 15.0.26124.0 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SFML.Audio", "src\SFML.Audio\SFML.Audio.csproj", "{A1E4E9AA-7468-4FCF-8091-A9A96E818E50}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SFML.Audio", "src\SFML.Audio\SFML.Audio.csproj", "{A1E4E9AA-7468-4FCF-8091-A9A96E818E50}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SFML.Graphics", "src\SFML.Graphics\SFML.Graphics.csproj", "{0C118BA2-904B-4AB1-ADC6-5C22DEFCEFA9}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SFML.Graphics", "src\SFML.Graphics\SFML.Graphics.csproj", "{0C118BA2-904B-4AB1-ADC6-5C22DEFCEFA9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SFML.Net", "src\SFML.Net\SFML.Net.csproj", "{E5467355-AB84-41E9-A80D-3044A45904B0}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SFML.Net", "src\SFML.Net\SFML.Net.csproj", "{E5467355-AB84-41E9-A80D-3044A45904B0}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SFML.System", "src\SFML.System\SFML.System.csproj", "{FCD90AB3-EAF7-429A-876A-4DB80D6CC6D8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SFML.System", "src\SFML.System\SFML.System.csproj", "{FCD90AB3-EAF7-429A-876A-4DB80D6CC6D8}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SFML.Window", "src\SFML.Window\SFML.Window.csproj", "{88DD6B5D-3013-4737-A77C-EC2563FCED38}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SFML.Window", "src\SFML.Window\SFML.Window.csproj", "{88DD6B5D-3013-4737-A77C-EC2563FCED38}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4BBA7B74-E003-4D9B-826A-43BD6BA48111}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -22,9 +27,6 @@ Global Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {A1E4E9AA-7468-4FCF-8091-A9A96E818E50}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {A1E4E9AA-7468-4FCF-8091-A9A96E818E50}.Debug|Any CPU.Build.0 = Debug|Any CPU @@ -87,4 +89,10 @@ Global {88DD6B5D-3013-4737-A77C-EC2563FCED38}.Release|x86.ActiveCfg = Release|x86 {88DD6B5D-3013-4737-A77C-EC2563FCED38}.Release|x86.Build.0 = Release|x86 EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {384AFDD8-7EEF-462A-B496-B5F71D0EEF1D} + EndGlobalSection EndGlobal diff --git a/code_style.md b/code_style.md index 7b0a08d6..f0884b86 100644 --- a/code_style.md +++ b/code_style.md @@ -1,5 +1,5 @@ # Code style -## VS Code references +Visual Studio and VS Code use the rules defined in [.editorconfig](./.editorconfig) for code style and formatting. -VS Code uses Omnisharp.json instead `.editorconfig` for setting up formatting style. References to setup can be found [here](https://github.com/OmniSharp/omnisharp-roslyn/wiki/Configuration-Options). +For VS Code, you may need to install [C# Dev Kit](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csdevkit) and [EditorConfig for VS Code](https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig) for the configuration to function correctly. diff --git a/examples/Examples.sln b/examples/Examples.sln index 9452b426..a114aeac 100644 --- a/examples/Examples.sln +++ b/examples/Examples.sln @@ -29,6 +29,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SFML.Window", "..\src\SFML. EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "netcore", "netcore\netcore.csproj", "{93B8425A-AC40-4486-96AF-20027B738C09}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A64BFAB3-DD36-4ABE-AABB-8A594327CCDD}" + ProjectSection(SolutionItems) = preProject + ..\.editorconfig = ..\.editorconfig + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/examples/netcore/Program.cs b/examples/netcore/Program.cs index 88e7666a..08351421 100644 --- a/examples/netcore/Program.cs +++ b/examples/netcore/Program.cs @@ -1,4 +1,4 @@ -using System; +using System; using SFML.Audio; using SFML.Graphics; using SFML.System; @@ -6,9 +6,9 @@ namespace netcore { - class Program + internal class Program { - static void Main(string[] args) + private static void Main() { var shape = new RectangleShape(new Vector2f(100, 100)) { @@ -18,7 +18,7 @@ static void Main(string[] args) var sound = new Sound(GenerateSineWave(frequency: 440.0, volume: .25, seconds: 1)); var window = new RenderWindow(new VideoMode(800, 600), "SFML running in .NET Core"); - window.Closed += (_, __) => window.Close(); + window.Closed += (_, _) => window.Close(); sound.Play(); @@ -36,8 +36,10 @@ private static SoundBuffer GenerateSineWave(double frequency, double volume, int uint sampleRate = 44100; var samples = new short[seconds * sampleRate]; - for (int i = 0; i < samples.Length; i++) + for (var i = 0; i < samples.Length; i++) + { samples[i] = (short)(Math.Sin(frequency * (2 * Math.PI) * i / sampleRate) * volume * short.MaxValue); + } return new SoundBuffer(samples, 1, sampleRate); } diff --git a/examples/netcore/netcore.csproj b/examples/netcore/netcore.csproj index 86e47ebb..004005c2 100644 --- a/examples/netcore/netcore.csproj +++ b/examples/netcore/netcore.csproj @@ -1,5 +1,7 @@ + + Exe net6.0 diff --git a/examples/opengl/OpenGL.cs b/examples/opengl/OpenGL.cs index ebb177f9..3c51d401 100644 --- a/examples/opengl/OpenGL.cs +++ b/examples/opengl/OpenGL.cs @@ -7,22 +7,24 @@ namespace opengl { - static class Program + internal static class Program { /// /// The main entry point for the application. /// - static void Main() + private static void Main() { // NOTE : This is workaround to create a functioning opengl context for OpenTK (for current OpenTK version) var gameWindow = new OpenTK.GameWindow(); // Request a 24-bits depth buffer when creating the window - var contextSettings = new ContextSettings(); - contextSettings.DepthBits = 24; + var contextSettings = new ContextSettings + { + DepthBits = 24 + }; // Create the main window - RenderWindow window = new RenderWindow(new VideoMode(800, 600), "SFML graphics with OpenGL", Styles.Default, contextSettings); + var window = new RenderWindow(new VideoMode(800, 600), "SFML graphics with OpenGL", Styles.Default, contextSettings); window.SetVerticalSyncEnabled(true); // Initialize OpenTK @@ -39,17 +41,19 @@ static void Main() var background = new Sprite(new Texture("resources/background.jpg")); // Create a text to display on top of the OpenGL object - var text = new Text("SFML / OpenGL demo", new Font("resources/sansation.ttf")); - text.Position = new Vector2f(250, 450); - text.FillColor = new SFML.Graphics.Color(255, 255, 255, 170); + var text = new Text("SFML / OpenGL demo", new Font("resources/sansation.ttf")) + { + Position = new Vector2f(250, 450), + FillColor = new SFML.Graphics.Color(255, 255, 255, 170) + }; // Make the window the active target for OpenGL calls - window.SetActive(); + _ = window.SetActive(); // Load an OpenGL texture. // We could directly use a SFML.Graphics.Texture as an OpenGL texture (with its Bind() member function), // but here we want more control on it (generate mipmaps, ...) so we create a new one - int texture = 0; + var texture = 0; using (var image = new SFML.Graphics.Image("resources/texture.jpg")) { GL.GenTextures(1, out texture); @@ -73,7 +77,7 @@ static void Main() // Setup a perspective projection GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); - float ratio = (float)( window.Size.X ) / window.Size.Y; + var ratio = (float)window.Size.X / window.Size.Y; GL.Frustum(-ratio, ratio, -1, 1, 1, 500); // Bind the texture @@ -81,7 +85,7 @@ static void Main() GL.BindTexture(TextureTarget.Texture2D, texture); // Define a 3D cube (6 faces made of 2 triangles composed by 3 vertices) - float[] cube = new float[] + var cube = new float[] { // positions // texture coordinates -20, -20, -20, 0, 0, @@ -157,8 +161,8 @@ static void Main() GL.Clear(ClearBufferMask.DepthBufferBit); // We get the position of the mouse cursor, so that we can move the box accordingly - float x = Mouse.GetPosition(window).X * 200.0F / window.Size.X - 100.0F; - float y = -Mouse.GetPosition(window).Y * 200.0F / window.Size.Y + 100.0F; + var x = (Mouse.GetPosition(window).X * 200.0F / window.Size.X) - 100.0F; + var y = (-Mouse.GetPosition(window).Y * 200.0F / window.Size.Y) + 100.0F; // Apply some transformations GL.MatrixMode(MatrixMode.Modelview); @@ -187,18 +191,18 @@ static void Main() /// /// Function called when the window is closed /// - static void OnClosed(object sender, EventArgs e) + private static void OnClosed(object sender, EventArgs e) { - RenderWindow window = (RenderWindow)sender; + var window = (RenderWindow)sender; window.Close(); } /// /// Function called when a key is pressed /// - static void OnKeyPressed(object sender, KeyEventArgs e) + private static void OnKeyPressed(object sender, KeyEventArgs e) { - RenderWindow window = (RenderWindow)sender; + var window = (RenderWindow)sender; if (e.Code == Keyboard.Key.Escape) { window.Close(); @@ -208,9 +212,6 @@ static void OnKeyPressed(object sender, KeyEventArgs e) /// /// Function called when the window is resized /// - static void OnResized(object sender, SizeEventArgs e) - { - GL.Viewport(0, 0, (int)e.Width, (int)e.Height); - } + private static void OnResized(object sender, SizeEventArgs e) => GL.Viewport(0, 0, (int)e.Width, (int)e.Height); } } diff --git a/examples/opengl/opengl.csproj b/examples/opengl/opengl.csproj index 247d18c9..fb1aa4d6 100644 --- a/examples/opengl/opengl.csproj +++ b/examples/opengl/opengl.csproj @@ -1,35 +1,37 @@ - - Exe - net48 - opengl - opengl - Debug;Release - 2.6.0 - AnyCPU;x64;x86 - + - - - + + Exe + net48 + opengl + opengl + Debug;Release + 2.6.0 + AnyCPU;x64;x86 + - - - - - + + + - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - + + + + + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + diff --git a/examples/shader/Shader.cs b/examples/shader/Shader.cs index c176d718..f2c09694 100644 --- a/examples/shader/Shader.cs +++ b/examples/shader/Shader.cs @@ -6,14 +6,11 @@ namespace shader { /// Base class for effects - abstract class Effect : Drawable + internal abstract class Effect : IDrawable { - protected Effect(string name) - { - myName = name; - } + protected Effect(string name) => Name = name; - public string Name => myName; + public string Name { get; } public void Update(float time, float x, float y) { if (Shader.IsAvailable) @@ -22,7 +19,7 @@ public void Update(float time, float x, float y) } } - public void Draw(RenderTarget target, RenderStates states) + public void Draw(IRenderTarget target, RenderStates states) { if (Shader.IsAvailable) { @@ -30,7 +27,7 @@ public void Draw(RenderTarget target, RenderStates states) } else { - var error = new Text("Shader not\nsupported", GetFont()) + var error = new Text("Shader not\nsupported", Font) { Position = new Vector2f(320, 200), CharacterSize = 36 @@ -39,63 +36,49 @@ public void Draw(RenderTarget target, RenderStates states) } } - public static void SetFont(Font font) - { - ourFont = font; - } - protected abstract void OnUpdate(float time, float x, float y); - protected abstract void OnDraw(RenderTarget target, RenderStates states); - - protected Font GetFont() - { - return ourFont; - } + protected abstract void OnDraw(IRenderTarget target, RenderStates states); - private readonly string myName; - private static Font ourFont; + public static Font Font { get; set; } } /// "Pixelate" fragment shader - class Pixelate : Effect + internal class Pixelate : Effect { public Pixelate() : base("pixelate") { // Load the texture and initialize the sprite - myTexture = new Texture("resources/background.jpg"); - mySprite = new Sprite(myTexture); + _texture = new Texture("resources/background.jpg"); + _sprite = new Sprite(_texture); // Load the shader - myShader = new Shader(null, null, "resources/pixelate.frag"); - myShader.SetUniform("texture", Shader.CurrentTexture); + _shader = new Shader(null, null, "resources/pixelate.frag"); + _shader.SetUniform("texture", Shader.CurrentTexture); } - protected override void OnUpdate(float time, float x, float y) - { - myShader.SetUniform("pixel_threshold", ( x + y ) / 30); - } + protected override void OnUpdate(float time, float x, float y) => _shader.SetUniform("pixel_threshold", (x + y) / 30); - protected override void OnDraw(RenderTarget target, RenderStates states) + protected override void OnDraw(IRenderTarget target, RenderStates states) { states = new RenderStates(states) { - Shader = myShader + Shader = _shader }; - target.Draw(mySprite, states); + target.Draw(_sprite, states); } - private readonly Texture myTexture; - private readonly Sprite mySprite; - private Shader myShader; + private readonly Texture _texture; + private readonly Sprite _sprite; + private readonly Shader _shader; } /// "Wave" vertex shader + "blur" fragment shader - class WaveBlur : Effect + internal class WaveBlur : Effect { public WaveBlur() : base("wave + blur") { // Create the text - myText = new Text + _text = new Text { DisplayedString = "Praesent suscipit augue in velit pulvinar hendrerit varius purus aliquam.\n" + "Mauris mi odio, bibendum quis fringilla a, laoreet vel orci. Proin vitae vulputate tortor.\n" + @@ -115,165 +98,169 @@ public WaveBlur() : base("wave + blur") "Mauris ultricies dolor sed massa convallis sed aliquet augue fringilla.\n" + "Duis erat eros, porta in accumsan in, blandit quis sem.\n" + "In hac habitasse platea dictumst. Etiam fringilla est id odio dapibus sit amet semper dui laoreet.\n", - Font = GetFont(), + Font = Font, CharacterSize = 22, Position = new Vector2f(30, 20) }; // Load the shader - myShader = new Shader("resources/wave.vert", null, "resources/blur.frag"); + _shader = new Shader("resources/wave.vert", null, "resources/blur.frag"); } protected override void OnUpdate(float time, float x, float y) { - myShader.SetUniform("wave_phase", time); - myShader.SetUniform("wave_amplitude", new Vector2f(x * 40, y * 40)); - myShader.SetUniform("blur_radius", ( x + y ) * 0.008F); + _shader.SetUniform("wave_phase", time); + _shader.SetUniform("wave_amplitude", new Vector2f(x * 40, y * 40)); + _shader.SetUniform("blur_radius", (x + y) * 0.008F); } - protected override void OnDraw(RenderTarget target, RenderStates states) + protected override void OnDraw(IRenderTarget target, RenderStates states) { states = new RenderStates(states) { - Shader = myShader + Shader = _shader }; - target.Draw(myText, states); + target.Draw(_text, states); } - private readonly Text myText; - private Shader myShader; + private readonly Text _text; + private readonly Shader _shader; } /// "Storm" vertex shader + "blink" fragment shader - class StormBlink : Effect + internal class StormBlink : Effect { public StormBlink() : base("storm + blink") { - Random random = new Random(); + var random = new Random(); // Create the points - myPoints = new VertexArray(PrimitiveType.Points); - for (int i = 0; i < 40000; ++i) + _points = new VertexArray(PrimitiveType.Points); + for (var i = 0; i < 40000; ++i) { float x = random.Next(0, 800); float y = random.Next(0, 600); - byte r = (byte)random.Next(0, 255); - byte g = (byte)random.Next(0, 255); - byte b = (byte)random.Next(0, 255); - myPoints.Append(new Vertex(new Vector2f(x, y), new Color(r, g, b))); + var r = (byte)random.Next(0, 255); + var g = (byte)random.Next(0, 255); + var b = (byte)random.Next(0, 255); + _points.Append(new Vertex(new Vector2f(x, y), new Color(r, g, b))); } // Load the shader - myShader = new Shader("resources/storm.vert", null, "resources/blink.frag"); + _shader = new Shader("resources/storm.vert", null, "resources/blink.frag"); } protected override void OnUpdate(float time, float x, float y) { - float radius = 200 + (float)Math.Cos(time) * 150; - myShader.SetUniform("storm_position", new Vector2f(x * 800, y * 600)); - myShader.SetUniform("storm_inner_radius", radius / 3); - myShader.SetUniform("storm_total_radius", radius); - myShader.SetUniform("blink_alpha", 0.5F + (float)Math.Cos(time * 3) * 0.25F); + var radius = 200 + ((float)Math.Cos(time) * 150); + _shader.SetUniform("storm_position", new Vector2f(x * 800, y * 600)); + _shader.SetUniform("storm_inner_radius", radius / 3); + _shader.SetUniform("storm_total_radius", radius); + _shader.SetUniform("blink_alpha", 0.5F + ((float)Math.Cos(time * 3) * 0.25F)); } - protected override void OnDraw(RenderTarget target, RenderStates states) + protected override void OnDraw(IRenderTarget target, RenderStates states) { - states = new RenderStates(states); - states.Shader = myShader; - target.Draw(myPoints, states); + states = new RenderStates(states) + { + Shader = _shader + }; + target.Draw(_points, states); } - private VertexArray myPoints; - private Shader myShader; + private readonly VertexArray _points; + private readonly Shader _shader; } /// "Edge" post-effect fragment shader - class Edge : Effect + internal class Edge : Effect { public Edge() : base("edge post-effect") { // Create the off-screen surface - mySurface = new RenderTexture(800, 600) + _surface = new RenderTexture(800, 600) { Smooth = true }; // Load the textures - myBackgroundTexture = new Texture("resources/sfml.png") + _backgroundTexture = new Texture("resources/sfml.png") { Smooth = true }; - myEntityTexture = new Texture("resources/devices.png") + _entityTexture = new Texture("resources/devices.png") { Smooth = true }; // Initialize the background sprite - myBackgroundSprite = new Sprite(myBackgroundTexture); - myBackgroundSprite.Position = new Vector2f(135, 100); + _backgroundSprite = new Sprite(_backgroundTexture) + { + Position = new Vector2f(135, 100) + }; // Load the moving entities - myEntities = new Sprite[6]; - for (int i = 0; i < myEntities.Length; ++i) + _entities = new Sprite[6]; + for (var i = 0; i < _entities.Length; ++i) { - myEntities[i] = new Sprite(myEntityTexture, new IntRect(96 * i, 0, 96, 96)); + _entities[i] = new Sprite(_entityTexture, new IntRect(96 * i, 0, 96, 96)); } // Load the shader - myShader = new Shader(null, null, "resources/edge.frag"); - myShader.SetUniform("texture", Shader.CurrentTexture); + _shader = new Shader(null, null, "resources/edge.frag"); + _shader.SetUniform("texture", Shader.CurrentTexture); } protected override void OnUpdate(float time, float x, float y) { - myShader.SetUniform("edge_threshold", 1 - ( x + y ) / 2); + _shader.SetUniform("edge_threshold", 1 - ((x + y) / 2)); // Update the position of the moving entities - for (var i = 0; i < myEntities.Length; ++i) + for (var i = 0; i < _entities.Length; ++i) { - float posX = (float)Math.Cos(0.25F * ( time * i + ( myEntities.Length - i ) )) * 300 + 350; - float posY = (float)Math.Sin(0.25F * ( time * ( myEntities.Length - i ) + i )) * 200 + 250; - myEntities[i].Position = new Vector2f(posX, posY); + var posX = ((float)Math.Cos(0.25F * ((time * i) + (_entities.Length - i))) * 300) + 350; + var posY = ((float)Math.Sin(0.25F * ((time * (_entities.Length - i)) + i)) * 200) + 250; + _entities[i].Position = new Vector2f(posX, posY); } // Render the updated scene to the off-screen surface - mySurface.Clear(Color.White); - mySurface.Draw(myBackgroundSprite); - foreach (Sprite entity in myEntities) + _surface.Clear(Color.White); + _surface.Draw(_backgroundSprite); + foreach (var entity in _entities) { - mySurface.Draw(entity); + _surface.Draw(entity); } - mySurface.Display(); + _surface.Display(); } - protected override void OnDraw(RenderTarget target, RenderStates states) + protected override void OnDraw(IRenderTarget target, RenderStates states) { states = new RenderStates(states) { - Shader = myShader + Shader = _shader }; - target.Draw(new Sprite(mySurface.Texture), states); + target.Draw(new Sprite(_surface.Texture), states); } - private RenderTexture mySurface; - private readonly Texture myBackgroundTexture; - private readonly Texture myEntityTexture; - private Sprite myBackgroundSprite; - Sprite[] myEntities; - private Shader myShader; + private readonly RenderTexture _surface; + private readonly Texture _backgroundTexture; + private readonly Texture _entityTexture; + private readonly Sprite _backgroundSprite; + private readonly Sprite[] _entities; + private readonly Shader _shader; } - static class Program + internal static class Program { - private static Effect[] effects; - private static int current; - private static Text description; + private static Effect[] _effects; + private static int _current; + private static Text _description; /// /// The main entry point for the application. /// - static void Main() + private static void Main() { // Create the main window var window = new RenderWindow(new VideoMode(800, 600), "SFML.Net Shader"); @@ -285,17 +272,17 @@ static void Main() // Load the application font and pass it to the Effect class var font = new Font("resources/sansation.ttf"); - Effect.SetFont(font); + Effect.Font = font; // Create the effects - effects = new Effect[] + _effects = new Effect[] { new Pixelate(), new WaveBlur(), new StormBlink(), new Edge() }; - current = 0; + _current = 0; // Create the messages background var textBackgroundTexture = new Texture("resources/text-background.png"); @@ -306,7 +293,7 @@ static void Main() }; // Create the description text - description = new Text("Current effect: " + effects[current].Name, font, 20) + _description = new Text("Current effect: " + _effects[_current].Name, font, 20) { Position = new Vector2f(10, 530), FillColor = new Color(80, 80, 80) @@ -329,18 +316,18 @@ static void Main() // Update the current example var x = (float)Mouse.GetPosition(window).X / window.Size.X; var y = (float)Mouse.GetPosition(window).Y / window.Size.Y; - effects[current].Update(clock.ElapsedTime.AsSeconds(), x, y); + _effects[_current].Update(clock.ElapsedTime.AsSeconds(), x, y); // Clear the window window.Clear(new Color(255, 128, 0)); // Draw the current example - window.Draw(effects[current]); + window.Draw(_effects[_current]); // Draw the text window.Draw(textBackground); window.Draw(instructions); - window.Draw(description); + window.Draw(_description); // Finally, display the rendered frame on screen window.Display(); @@ -350,7 +337,7 @@ static void Main() /// /// Function called when the window is closed /// - static void OnClosed(object sender, EventArgs e) + private static void OnClosed(object sender, EventArgs e) { var window = (RenderWindow)sender; window.Close(); @@ -359,7 +346,7 @@ static void OnClosed(object sender, EventArgs e) /// /// Function called when a key is pressed /// - static void OnKeyPressed(object sender, KeyEventArgs e) + private static void OnKeyPressed(object sender, KeyEventArgs e) { var window = (RenderWindow)sender; @@ -373,31 +360,31 @@ static void OnKeyPressed(object sender, KeyEventArgs e) // Left arrow key: previous shader if (e.Code == Keyboard.Key.Left) { - if (current == 0) + if (_current == 0) { - current = effects.Length - 1; + _current = _effects.Length - 1; } else { - current--; + _current--; } - description.DisplayedString = $"Current effect: {effects[current].Name}"; + _description.DisplayedString = $"Current effect: {_effects[_current].Name}"; } // Right arrow key: next shader if (e.Code == Keyboard.Key.Right) { - if (current == effects.Length - 1) + if (_current == _effects.Length - 1) { - current = 0; + _current = 0; } else { - current++; + _current++; } - description.DisplayedString = $"Current effect: {effects[current].Name}"; + _description.DisplayedString = $"Current effect: {_effects[_current].Name}"; } } } diff --git a/examples/shader/shader.csproj b/examples/shader/shader.csproj index a76127c5..fee32556 100644 --- a/examples/shader/shader.csproj +++ b/examples/shader/shader.csproj @@ -1,55 +1,57 @@ - - Exe - net48 - shader - shader - Debug;Release - 2.6.0 - AnyCPU;x64;x86 - + - - - - - + + Exe + net48 + shader + shader + Debug;Release + 2.6.0 + AnyCPU;x64;x86 + - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - + + + + + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + diff --git a/examples/sound/Sound.cs b/examples/sound/Sound.cs index 6859cbab..7ea43582 100644 --- a/examples/sound/Sound.cs +++ b/examples/sound/Sound.cs @@ -4,12 +4,12 @@ namespace sound { - static class Program + internal static class Program { /// /// The main entry point for the application. /// - static void Main(string[] args) + private static void Main() { // Play a sound PlaySound(); @@ -25,7 +25,7 @@ static void Main(string[] args) private static void PlaySound() { // Load a sound buffer from a wav file - SoundBuffer buffer = new SoundBuffer("resources/canary.wav"); + var buffer = new SoundBuffer("resources/canary.wav"); // Display sound information Console.WriteLine("canary.wav :"); @@ -34,7 +34,7 @@ private static void PlaySound() Console.WriteLine(" " + buffer.ChannelCount + " channels"); // Create a sound instance and play it - Sound sound = new Sound(buffer); + var sound = new Sound(buffer); sound.Play(); // Loop while the sound is playing @@ -55,7 +55,7 @@ private static void PlaySound() private static void PlayMusic() { // Load an ogg music file - Music music = new Music("resources/orchestral.ogg"); + var music = new Music("resources/orchestral.ogg"); // Display music information Console.WriteLine("orchestral.ogg :"); diff --git a/examples/sound/sound.csproj b/examples/sound/sound.csproj index ba1790c2..99a3afe2 100644 --- a/examples/sound/sound.csproj +++ b/examples/sound/sound.csproj @@ -1,29 +1,31 @@ - - Exe - net48 - sound - sound - Debug;Release - 2.6.0 - AnyCPU;x64;x86 - + - - - - - - + + Exe + net48 + sound + sound + Debug;Release + 2.6.0 + AnyCPU;x64;x86 + - - - PreserveNewest - - - PreserveNewest - - + + + + + + + + + + PreserveNewest + + + PreserveNewest + + diff --git a/examples/sound_capture/SoundCapture.cs b/examples/sound_capture/SoundCapture.cs index 7a813ae1..961ab67b 100644 --- a/examples/sound_capture/SoundCapture.cs +++ b/examples/sound_capture/SoundCapture.cs @@ -4,15 +4,15 @@ namespace sound_capture { - static class Program + internal static class Program { /// /// The main entry point for the application. /// - static void Main(string[] args) + private static void Main() { // Check that the device can capture audio - if (SoundRecorder.IsAvailable == false) + if (!SoundRecorder.IsAvailable) { Console.WriteLine("Sorry, audio capture is not supported by your system"); return; @@ -20,23 +20,23 @@ static void Main(string[] args) // Choose the sample rate Console.WriteLine("Please choose the sample rate for sound capture (44100 is CD quality) : "); - uint sampleRate = uint.Parse(Console.ReadLine()); + var sampleRate = uint.Parse(Console.ReadLine()); // Wait for user input... Console.WriteLine("Press enter to start recording audio"); - Console.ReadLine(); + _ = Console.ReadLine(); // Here we'll use an integrated custom recorder, which saves the captured data into a SoundBuffer - SoundBufferRecorder recorder = new SoundBufferRecorder(); + var recorder = new SoundBufferRecorder(); // Audio capture is done in a separate thread, so we can block the main thread while it is capturing - recorder.Start(sampleRate); + _ = recorder.Start(sampleRate); Console.WriteLine("Recording... press enter to stop"); - Console.ReadLine(); + _ = Console.ReadLine(); recorder.Stop(); // Get the buffer containing the captured data - SoundBuffer buffer = recorder.SoundBuffer; + var buffer = recorder.SoundBuffer; // Display captured sound information Console.WriteLine("Sound information :"); @@ -46,21 +46,21 @@ static void Main(string[] args) // Choose what to do with the recorded sound data Console.WriteLine("What do you want to do with captured sound (p = play, s = save) ? "); - char choice = char.Parse(Console.ReadLine()); + var choice = char.Parse(Console.ReadLine()); if (choice == 's') { // Choose the filename Console.WriteLine("Choose the file to create : "); - string filename = Console.ReadLine(); + var filename = Console.ReadLine(); // Save the buffer - buffer.SaveToFile(filename); + _ = buffer.SaveToFile(filename); } else { // Create a sound instance and play it - Sound sound = new Sound(buffer); + var sound = new Sound(buffer); sound.Play(); // Wait until finished diff --git a/examples/sound_capture/sound_capture.csproj b/examples/sound_capture/sound_capture.csproj index 15811fbe..7c75da44 100644 --- a/examples/sound_capture/sound_capture.csproj +++ b/examples/sound_capture/sound_capture.csproj @@ -1,20 +1,22 @@ - - Exe - net48 - sound_capture - sound_capture - Debug;Release - 2.6.0 - AnyCPU;x64;x86 - + - - - - - - + + Exe + net48 + sound_capture + sound_capture + Debug;Release + 2.6.0 + AnyCPU;x64;x86 + + + + + + + + diff --git a/examples/visualbasic/My Project/AssemblyInfo.vb b/examples/visualbasic/My Project/AssemblyInfo.vb index 23527f4b..f831d3ff 100644 --- a/examples/visualbasic/My Project/AssemblyInfo.vb +++ b/examples/visualbasic/My Project/AssemblyInfo.vb @@ -1,4 +1,3 @@ -Imports System Imports System.Reflection Imports System.Runtime.InteropServices @@ -8,17 +7,17 @@ Imports System.Runtime.InteropServices ' Review the values of the assembly attributes - - - - - - + + + + + + 'The following GUID is for the ID of the typelib if this project is exposed to COM - + ' Version information for an assembly consists of the following four values: ' @@ -31,5 +30,5 @@ Imports System.Runtime.InteropServices ' by using the '*' as shown below: ' - - + + diff --git a/examples/visualbasic/OpenGL.vb b/examples/visualbasic/OpenGL.vb index 98ea2ced..d7642c87 100644 --- a/examples/visualbasic/OpenGL.vb +++ b/examples/visualbasic/OpenGL.vb @@ -1,4 +1,3 @@ -Imports System Imports System.Runtime.InteropServices Imports SFML.System Imports SFML.Window @@ -7,37 +6,38 @@ Imports OpenTK Imports OpenTK.Graphics Imports OpenTk.Graphics.OpenGL -Module OpenGL - - Dim WithEvents window As RenderWindow +Friend Module OpenGL + Private WithEvents window As RenderWindow ''' ''' Entry point of application ''' - Sub Main() + Public Sub Main() ' Request a 24-bits depth buffer when creating the window - Dim contextSettings As New ContextSettings() - contextSettings.DepthBits = 24 + Dim contextSettings As New ContextSettings With { + .DepthBits = 24 + } ' Create main window window = New RenderWindow(New VideoMode(800, 600), "SFML graphics with OpenGL (Visual Basic)", Styles.Default, contextSettings) window.SetVerticalSyncEnabled(True) ' Initialize OpenTK - Toolkit.Init() - Dim context As GraphicsContext = New GraphicsContext(New ContextHandle(IntPtr.Zero), Nothing) + Dim unused1 = Toolkit.Init() + Dim context As New GraphicsContext(New ContextHandle(IntPtr.Zero), Nothing) ' Create a sprite for the background Dim background = New Sprite(New Texture("resources/background.jpg")) ' Create a text to display on top of the OpenGL object - Dim text = New Text("SFML / OpenGL demo", New Font("resources/sansation.ttf")) - text.Position = New Vector2f(250, 450) - text.FillColor = New SFML.Graphics.Color(255, 255, 255, 170) + Dim text = New Text("SFML / OpenGL demo", New Font("resources/sansation.ttf")) With { + .Position = New Vector2f(250, 450), + .FillColor = New SFML.Graphics.Color(255, 255, 255, 170) + } ' Make it the active window for OpenGL calls - window.SetActive(True) + Dim unused2 = window.SetActive(True) ' Load an OpenGL texture ' We could directly use a SFML.Graphics.Texture as an OpenGL texture (with its Bind() member function), @@ -131,7 +131,7 @@ Module OpenGL Dim clock = New Clock() ' Start the game loop - While (window.IsOpen) + While window.IsOpen ' Process events window.DispatchEvents() @@ -145,8 +145,8 @@ Module OpenGL window.PopGLStates() ' We get the position of the mouse cursor, so that we can move the box accordingly - Dim x = Mouse.GetPosition(window).X * 200.0F / window.Size.X - 100.0F - Dim y = -Mouse.GetPosition(window).Y * 200.0F / window.Size.Y + 100.0F + Dim x = (Mouse.GetPosition(window).X * 200.0F / window.Size.X) - 100.0F + Dim y = (-Mouse.GetPosition(window).Y * 200.0F / window.Size.Y) + 100.0F ' Apply some transformations GL.MatrixMode(MatrixMode.Modelview) @@ -177,7 +177,7 @@ Module OpenGL ''' ''' Function called when the window is closed ''' - Sub App_Closed(ByVal sender As Object, ByVal e As EventArgs) Handles window.Closed + Public Sub App_Closed(sender As Object, e As EventArgs) Handles window.Closed Dim window = CType(sender, RenderWindow) window.Close() End Sub @@ -185,7 +185,7 @@ Module OpenGL ''' ''' Function called when a key is pressed ''' - Sub App_KeyPressed(ByVal sender As Object, ByVal e As KeyEventArgs) Handles window.KeyPressed + Public Sub App_KeyPressed(sender As Object, e As KeyEventArgs) Handles window.KeyPressed Dim window = CType(sender, RenderWindow) If e.Code = Keyboard.Key.Escape Then window.Close() @@ -195,7 +195,7 @@ Module OpenGL ''' ''' Function called when the window is resized ''' - Sub App_Resized(ByVal sender As Object, ByVal e As SizeEventArgs) Handles window.Resized + Public Sub App_Resized(sender As Object, e As SizeEventArgs) Handles window.Resized GL.Viewport(0, 0, e.Width, e.Height) End Sub diff --git a/examples/visualbasic/visualbasic.vbproj b/examples/visualbasic/visualbasic.vbproj index 52856b58..e5bcc7a3 100644 --- a/examples/visualbasic/visualbasic.vbproj +++ b/examples/visualbasic/visualbasic.vbproj @@ -1,4 +1,5 @@ + net48 WinExe diff --git a/examples/window/Program.cs b/examples/window/Program.cs index 89969278..1c94acb2 100644 --- a/examples/window/Program.cs +++ b/examples/window/Program.cs @@ -2,9 +2,9 @@ namespace window_core { - static class Program + internal static class Program { - static void Main(string[] args) + private static void Main() { Console.WriteLine("Press ESC key to close window"); var window = new SimpleWindow(); @@ -14,7 +14,7 @@ static void Main(string[] args) } } - class SimpleWindow + internal class SimpleWindow { public void Run() { diff --git a/examples/window/window.csproj b/examples/window/window.csproj index fb888aad..72dce20d 100644 --- a/examples/window/window.csproj +++ b/examples/window/window.csproj @@ -1,19 +1,21 @@ - - Exe - net48 - window - window - Debug;Release - 2.6.0 - AnyCPU;x64;x86 - + - - - - - + + Exe + net48 + window + window + Debug;Release + 2.6.0 + AnyCPU;x64;x86 + + + + + + + diff --git a/omnisharp.json b/omnisharp.json deleted file mode 100644 index 74d21aff..00000000 --- a/omnisharp.json +++ /dev/null @@ -1,53 +0,0 @@ -{ - "FormattingOptions": { - "UseTabs": false, - "TabSize": 4, - "IndentationSize": 4, - "SpacingAfterMethodDeclarationName": false, - "SpaceWithinMethodDeclarationParenthesis": false, - "SpaceBetweenEmptyMethodDeclarationParentheses": false, - "SpaceAfterMethodCallName": false, - "SpaceWithinMethodCallParentheses": false, - "SpaceBetweenEmptyMethodCallParentheses": false, - "SpaceAfterControlFlowStatementKeyword": true, - "SpaceWithinExpressionParentheses": false, - "SpaceWithinCastParentheses": false, - "SpaceWithinOtherParentheses": false, - "SpaceAfterCast": false, - "SpacesIgnoreAroundVariableDeclaration": false, - "SpaceBeforeOpenSquareBracket": false, - "SpaceBetweenEmptySquareBrackets": false, - "SpaceWithinSquareBrackets": false, - "SpaceAfterColonInBaseTypeDeclaration": true, - "SpaceAfterComma": true, - "SpaceAfterDot": false, - "SpaceAfterSemicolonsInForStatement": true, - "SpaceBeforeColonInBaseTypeDeclaration": true, - "SpaceBeforeComma": false, - "SpaceBeforeDot": false, - "SpaceBeforeSemicolonsInForStatement": false, - "SpacingAroundBinaryOperator": "single", - "IndentBraces": false, - "IndentBlock": true, - "IndentSwitchSection": true, - "IndentSwitchCaseSection": true, - "LabelPositioning": "oneLess", - "WrappingPreserveSingleLine": true, - "WrappingKeepStatementsOnSingleLine": true, - "NewLinesForBracesInTypes": true, - "NewLinesForBracesInMethods": true, - "NewLinesForBracesInProperties": true, - "NewLinesForBracesInAccessors": true, - "NewLinesForBracesInAnonymousMethods": true, - "NewLinesForBracesInControlBlocks": true, - "NewLinesForBracesInAnonymousTypes": true, - "NewLinesForBracesInObjectCollectionArrayInitializers": true, - "NewLinesForBracesInLambdaExpressionBody": true, - "NewLineForElse": true, - "NewLineForCatch": true, - "NewLineForFinally": true, - "NewLineForMembersInObjectInit": true, - "NewLineForMembersInAnonymousTypes": true, - "NewLineForClausesInQuery": true - } -} \ No newline at end of file diff --git a/src/SFML.Audio/Listener.cs b/src/SFML.Audio/Listener.cs index 76f2daa4..bea4d727 100644 --- a/src/SFML.Audio/Listener.cs +++ b/src/SFML.Audio/Listener.cs @@ -21,8 +21,8 @@ public class Listener //////////////////////////////////////////////////////////// public static float GlobalVolume { - get { return sfListener_getGlobalVolume(); } - set { sfListener_setGlobalVolume(value); } + get => sfListener_getGlobalVolume(); + set => sfListener_setGlobalVolume(value); } //////////////////////////////////////////////////////////// @@ -32,8 +32,8 @@ public static float GlobalVolume //////////////////////////////////////////////////////////// public static Vector3f Position { - get { return sfListener_getPosition(); } - set { sfListener_setPosition(value); } + get => sfListener_getPosition(); + set => sfListener_setPosition(value); } //////////////////////////////////////////////////////////// @@ -48,8 +48,8 @@ public static Vector3f Position //////////////////////////////////////////////////////////// public static Vector3f Direction { - get { return sfListener_getDirection(); } - set { sfListener_setDirection(value); } + get => sfListener_getDirection(); + set => sfListener_setDirection(value); } //////////////////////////////////////////////////////////// @@ -64,33 +64,33 @@ public static Vector3f Direction //////////////////////////////////////////////////////////// public static Vector3f UpVector { - get { return sfListener_getUpVector(); } - set { sfListener_setUpVector(value); } + get => sfListener_getUpVector(); + set => sfListener_setUpVector(value); } #region Imports - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfListener_setGlobalVolume(float Volume); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfListener_setGlobalVolume(float volume); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern float sfListener_getGlobalVolume(); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfListener_setPosition(Vector3f position); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern Vector3f sfListener_getPosition(); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfListener_setDirection(Vector3f direction); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern Vector3f sfListener_getDirection(); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfListener_setUpVector(Vector3f upVector); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern Vector3f sfListener_getUpVector(); #endregion } diff --git a/src/SFML.Audio/Music.cs b/src/SFML.Audio/Music.cs index 612141ac..ffdd7b84 100644 --- a/src/SFML.Audio/Music.cs +++ b/src/SFML.Audio/Music.cs @@ -49,8 +49,8 @@ public Music(string filename) : public Music(Stream stream) : base(IntPtr.Zero) { - myStream = new StreamAdaptor(stream); - CPointer = sfMusic_createFromStream(myStream.InputStreamPtr); + _stream = new StreamAdaptor(stream); + CPointer = sfMusic_createFromStream(_stream.InputStreamPtr); if (IsInvalid) { @@ -74,7 +74,7 @@ public Music(Stream stream) : public Music(byte[] bytes) : base(IntPtr.Zero) { - GCHandle pin = GCHandle.Alloc(bytes, GCHandleType.Pinned); + var pin = GCHandle.Alloc(bytes, GCHandleType.Pinned); try { CPointer = sfMusic_createFromMemory(pin.AddrOfPinnedObject(), (UIntPtr)bytes.Length); @@ -100,10 +100,7 @@ public Music(byte[] bytes) : /// the rest of the program while the stream is played. /// //////////////////////////////////////////////////////////// - public void Play() - { - sfMusic_play(CPointer); - } + public void Play() => sfMusic_play(CPointer); //////////////////////////////////////////////////////////// /// @@ -113,10 +110,7 @@ public void Play() /// otherwise (stream already paused or stopped) it has no effect. /// //////////////////////////////////////////////////////////// - public void Pause() - { - sfMusic_pause(CPointer); - } + public void Pause() => sfMusic_pause(CPointer); //////////////////////////////////////////////////////////// /// @@ -127,10 +121,7 @@ public void Pause() /// It also resets the playing position (unlike Pause()). /// //////////////////////////////////////////////////////////// - public void Stop() - { - sfMusic_stop(CPointer); - } + public void Stop() => sfMusic_stop(CPointer); //////////////////////////////////////////////////////////// /// @@ -140,43 +131,28 @@ public void Stop() /// second. The higher, the better the quality. /// //////////////////////////////////////////////////////////// - public uint SampleRate - { - get { return sfMusic_getSampleRate(CPointer); } - } + public uint SampleRate => sfMusic_getSampleRate(CPointer); //////////////////////////////////////////////////////////// /// /// Number of channels (1 = mono, 2 = stereo) /// //////////////////////////////////////////////////////////// - public uint ChannelCount - { - get { return sfMusic_getChannelCount(CPointer); } - } + public uint ChannelCount => sfMusic_getChannelCount(CPointer); //////////////////////////////////////////////////////////// /// /// Current status of the music (see SoundStatus enum) /// //////////////////////////////////////////////////////////// - public SoundStatus Status - { - get { return sfMusic_getStatus(CPointer); } - } + public SoundStatus Status => sfMusic_getStatus(CPointer); //////////////////////////////////////////////////////////// /// /// Total duration of the music /// //////////////////////////////////////////////////////////// - public Time Duration - { - get - { - return sfMusic_getDuration(CPointer); - } - } + public Time Duration => sfMusic_getDuration(CPointer); //////////////////////////////////////////////////////////// /// @@ -190,8 +166,8 @@ public Time Duration //////////////////////////////////////////////////////////// public bool Loop { - get { return sfMusic_getLoop(CPointer); } - set { sfMusic_setLoop(CPointer, value); } + get => sfMusic_getLoop(CPointer); + set => sfMusic_setLoop(CPointer, value); } //////////////////////////////////////////////////////////// @@ -207,8 +183,8 @@ public bool Loop //////////////////////////////////////////////////////////// public float Pitch { - get { return sfMusic_getPitch(CPointer); } - set { sfMusic_setPitch(CPointer, value); } + get => sfMusic_getPitch(CPointer); + set => sfMusic_setPitch(CPointer, value); } //////////////////////////////////////////////////////////// @@ -221,8 +197,8 @@ public float Pitch //////////////////////////////////////////////////////////// public float Volume { - get { return sfMusic_getVolume(CPointer); } - set { sfMusic_setVolume(CPointer, value); } + get => sfMusic_getVolume(CPointer); + set => sfMusic_setVolume(CPointer, value); } //////////////////////////////////////////////////////////// @@ -236,8 +212,8 @@ public float Volume //////////////////////////////////////////////////////////// public Vector3f Position { - get { return sfMusic_getPosition(CPointer); } - set { sfMusic_setPosition(CPointer, value); } + get => sfMusic_getPosition(CPointer); + set => sfMusic_setPosition(CPointer, value); } //////////////////////////////////////////////////////////// @@ -253,8 +229,8 @@ public Vector3f Position //////////////////////////////////////////////////////////// public bool RelativeToListener { - get { return sfMusic_isRelativeToListener(CPointer); } - set { sfMusic_setRelativeToListener(CPointer, value); } + get => sfMusic_isRelativeToListener(CPointer); + set => sfMusic_setRelativeToListener(CPointer, value); } //////////////////////////////////////////////////////////// @@ -271,8 +247,8 @@ public bool RelativeToListener //////////////////////////////////////////////////////////// public float MinDistance { - get { return sfMusic_getMinDistance(CPointer); } - set { sfMusic_setMinDistance(CPointer, value); } + get => sfMusic_getMinDistance(CPointer); + set => sfMusic_setMinDistance(CPointer, value); } //////////////////////////////////////////////////////////// @@ -291,8 +267,8 @@ public float MinDistance //////////////////////////////////////////////////////////// public float Attenuation { - get { return sfMusic_getAttenuation(CPointer); } - set { sfMusic_setAttenuation(CPointer, value); } + get => sfMusic_getAttenuation(CPointer); + set => sfMusic_setAttenuation(CPointer, value); } //////////////////////////////////////////////////////////// @@ -305,8 +281,8 @@ public float Attenuation //////////////////////////////////////////////////////////// public Time PlayingOffset { - get { return sfMusic_getPlayingOffset(CPointer); } - set { sfMusic_setPlayingOffset(CPointer, value); } + get => sfMusic_getPlayingOffset(CPointer); + set => sfMusic_setPlayingOffset(CPointer, value); } //////////////////////////////////////////////////////////// @@ -323,8 +299,8 @@ public Time PlayingOffset //////////////////////////////////////////////////////////// public TimeSpan LoopPoints { - get { return sfMusic_getLoopPoints(CPointer); } - set { sfMusic_setLoopPoints(CPointer, value); } + get => sfMusic_getLoopPoints(CPointer); + set => sfMusic_setLoopPoints(CPointer, value); } //////////////////////////////////////////////////////////// @@ -336,7 +312,9 @@ public TimeSpan LoopPoints public override string ToString() { if (IsInvalid) + { return MakeDisposedObjectString(); + } return "[Music]" + " SampleRate(" + SampleRate + ")" + @@ -364,16 +342,13 @@ protected override void Destroy(bool disposing) { if (disposing) { - if (myStream != null) - { - myStream.Dispose(); - } + _stream?.Dispose(); } sfMusic_destroy(CPointer); } - private StreamAdaptor myStream = null; + private readonly StreamAdaptor _stream; /// /// Structure defining a Time range. @@ -404,92 +379,92 @@ public TimeSpan(Time offset, Time length) } #region Imports - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfMusic_createFromFile(string Filename); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfMusic_createFromFile(string filename); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private unsafe static extern IntPtr sfMusic_createFromStream(IntPtr stream); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern unsafe IntPtr sfMusic_createFromStream(IntPtr stream); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfMusic_createFromMemory(IntPtr data, UIntPtr size); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfMusic_destroy(IntPtr MusicStream); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfMusic_destroy(IntPtr musicStream); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfMusic_play(IntPtr Music); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfMusic_play(IntPtr music); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfMusic_pause(IntPtr Music); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfMusic_pause(IntPtr music); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfMusic_stop(IntPtr Music); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfMusic_stop(IntPtr music); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern SoundStatus sfMusic_getStatus(IntPtr Music); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern SoundStatus sfMusic_getStatus(IntPtr music); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Time sfMusic_getDuration(IntPtr Music); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Time sfMusic_getDuration(IntPtr music); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern TimeSpan sfMusic_getLoopPoints(IntPtr Music); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern TimeSpan sfMusic_getLoopPoints(IntPtr music); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfMusic_setLoopPoints(IntPtr Music, TimeSpan timePoints); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfMusic_setLoopPoints(IntPtr music, TimeSpan timePoints); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern uint sfMusic_getChannelCount(IntPtr Music); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern uint sfMusic_getChannelCount(IntPtr music); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern uint sfMusic_getSampleRate(IntPtr Music); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern uint sfMusic_getSampleRate(IntPtr music); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfMusic_setPitch(IntPtr Music, float Pitch); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfMusic_setPitch(IntPtr music, float pitch); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfMusic_setLoop(IntPtr Music, bool Loop); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfMusic_setLoop(IntPtr music, bool loop); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfMusic_setVolume(IntPtr Music, float Volume); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfMusic_setVolume(IntPtr music, float volume); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfMusic_setPosition(IntPtr Music, Vector3f position); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfMusic_setPosition(IntPtr music, Vector3f position); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfMusic_setRelativeToListener(IntPtr Music, bool Relative); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfMusic_setRelativeToListener(IntPtr music, bool relative); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfMusic_setMinDistance(IntPtr Music, float MinDistance); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfMusic_setMinDistance(IntPtr music, float minDistance); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfMusic_setAttenuation(IntPtr Music, float Attenuation); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfMusic_setAttenuation(IntPtr music, float attenuation); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfMusic_setPlayingOffset(IntPtr Music, Time TimeOffset); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfMusic_setPlayingOffset(IntPtr music, Time timeOffset); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfMusic_getLoop(IntPtr Music); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfMusic_getLoop(IntPtr music); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern float sfMusic_getPitch(IntPtr Music); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern float sfMusic_getPitch(IntPtr music); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern float sfMusic_getVolume(IntPtr Music); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern float sfMusic_getVolume(IntPtr music); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Vector3f sfMusic_getPosition(IntPtr Music); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Vector3f sfMusic_getPosition(IntPtr music); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfMusic_isRelativeToListener(IntPtr Music); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfMusic_isRelativeToListener(IntPtr music); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern float sfMusic_getMinDistance(IntPtr Music); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern float sfMusic_getMinDistance(IntPtr music); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern float sfMusic_getAttenuation(IntPtr Music); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern float sfMusic_getAttenuation(IntPtr music); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Time sfMusic_getPlayingOffset(IntPtr Music); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Time sfMusic_getPlayingOffset(IntPtr music); #endregion } } diff --git a/src/SFML.Audio/Properties/AssemblyInfo.cs b/src/SFML.Audio/Properties/AssemblyInfo.cs index 1b73fe58..29bebc3b 100644 --- a/src/SFML.Audio/Properties/AssemblyInfo.cs +++ b/src/SFML.Audio/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ -using System.Reflection; -using System.Runtime.InteropServices; +using System.Runtime.InteropServices; // [assembly: AssemblyTitle("sfml-audio")] //[assembly: AssemblyDescription("Audio module of the SFML library")] diff --git a/src/SFML.Audio/Sound.cs b/src/SFML.Audio/Sound.cs index 627c2432..b2507b4b 100644 --- a/src/SFML.Audio/Sound.cs +++ b/src/SFML.Audio/Sound.cs @@ -46,10 +46,7 @@ public Sound() : /// Sound buffer containing the audio data to play with the sound //////////////////////////////////////////////////////////// public Sound(SoundBuffer buffer) : - base(sfSound_create()) - { - SoundBuffer = buffer; - } + base(sfSound_create()) => SoundBuffer = buffer; //////////////////////////////////////////////////////////// /// @@ -58,10 +55,7 @@ public Sound(SoundBuffer buffer) : /// Sound to copy //////////////////////////////////////////////////////////// public Sound(Sound copy) : - base(sfSound_copy(copy.CPointer)) - { - SoundBuffer = copy.SoundBuffer; - } + base(sfSound_copy(copy.CPointer)) => SoundBuffer = copy.SoundBuffer; //////////////////////////////////////////////////////////// /// @@ -74,10 +68,7 @@ public Sound(Sound copy) : /// the rest of the program while the sound is played. /// //////////////////////////////////////////////////////////// - public void Play() - { - sfSound_play(CPointer); - } + public void Play() => sfSound_play(CPointer); //////////////////////////////////////////////////////////// /// @@ -87,10 +78,7 @@ public void Play() /// otherwise (sound already paused or stopped) it has no effect. /// //////////////////////////////////////////////////////////// - public void Pause() - { - sfSound_pause(CPointer); - } + public void Pause() => sfSound_pause(CPointer); //////////////////////////////////////////////////////////// /// @@ -101,10 +89,7 @@ public void Pause() /// It also resets the playing position (unlike pause()). /// //////////////////////////////////////////////////////////// - public void Stop() - { - sfSound_stop(CPointer); - } + public void Stop() => sfSound_stop(CPointer); //////////////////////////////////////////////////////////// /// @@ -117,8 +102,8 @@ public void Stop() //////////////////////////////////////////////////////////// public SoundBuffer SoundBuffer { - get { return myBuffer; } - set { myBuffer = value; sfSound_setBuffer(CPointer, value != null ? value.CPointer : IntPtr.Zero); } + get => _buffer; + set { _buffer = value; sfSound_setBuffer(CPointer, value != null ? value.CPointer : IntPtr.Zero); } } //////////////////////////////////////////////////////////// @@ -126,10 +111,7 @@ public SoundBuffer SoundBuffer /// Current status of the sound (see SoundStatus enum) /// //////////////////////////////////////////////////////////// - public SoundStatus Status - { - get { return sfSound_getStatus(CPointer); } - } + public SoundStatus Status => sfSound_getStatus(CPointer); //////////////////////////////////////////////////////////// /// @@ -143,8 +125,8 @@ public SoundStatus Status //////////////////////////////////////////////////////////// public bool Loop { - get { return sfSound_getLoop(CPointer); } - set { sfSound_setLoop(CPointer, value); } + get => sfSound_getLoop(CPointer); + set => sfSound_setLoop(CPointer, value); } //////////////////////////////////////////////////////////// @@ -160,8 +142,8 @@ public bool Loop //////////////////////////////////////////////////////////// public float Pitch { - get { return sfSound_getPitch(CPointer); } - set { sfSound_setPitch(CPointer, value); } + get => sfSound_getPitch(CPointer); + set => sfSound_setPitch(CPointer, value); } //////////////////////////////////////////////////////////// @@ -174,8 +156,8 @@ public float Pitch //////////////////////////////////////////////////////////// public float Volume { - get { return sfSound_getVolume(CPointer); } - set { sfSound_setVolume(CPointer, value); } + get => sfSound_getVolume(CPointer); + set => sfSound_setVolume(CPointer, value); } //////////////////////////////////////////////////////////// @@ -188,8 +170,8 @@ public float Volume //////////////////////////////////////////////////////////// public Time PlayingOffset { - get { return sfSound_getPlayingOffset(CPointer); } - set { sfSound_setPlayingOffset(CPointer, value); } + get => sfSound_getPlayingOffset(CPointer); + set => sfSound_setPlayingOffset(CPointer, value); } //////////////////////////////////////////////////////////// @@ -203,8 +185,8 @@ public Time PlayingOffset //////////////////////////////////////////////////////////// public Vector3f Position { - get { return sfSound_getPosition(CPointer); } - set { sfSound_setPosition(CPointer, value); } + get => sfSound_getPosition(CPointer); + set => sfSound_setPosition(CPointer, value); } //////////////////////////////////////////////////////////// @@ -220,8 +202,8 @@ public Vector3f Position //////////////////////////////////////////////////////////// public bool RelativeToListener { - get { return sfSound_isRelativeToListener(CPointer); } - set { sfSound_setRelativeToListener(CPointer, value); } + get => sfSound_isRelativeToListener(CPointer); + set => sfSound_setRelativeToListener(CPointer, value); } //////////////////////////////////////////////////////////// @@ -238,8 +220,8 @@ public bool RelativeToListener //////////////////////////////////////////////////////////// public float MinDistance { - get { return sfSound_getMinDistance(CPointer); } - set { sfSound_setMinDistance(CPointer, value); } + get => sfSound_getMinDistance(CPointer); + set => sfSound_setMinDistance(CPointer, value); } //////////////////////////////////////////////////////////// @@ -258,8 +240,8 @@ public float MinDistance //////////////////////////////////////////////////////////// public float Attenuation { - get { return sfSound_getAttenuation(CPointer); } - set { sfSound_setAttenuation(CPointer, value); } + get => sfSound_getAttenuation(CPointer); + set => sfSound_setAttenuation(CPointer, value); } //////////////////////////////////////////////////////////// @@ -271,7 +253,9 @@ public float Attenuation public override string ToString() { if (IsInvalid) + { return MakeDisposedObjectString(); + } return "[Sound]" + " Status(" + Status + ")" + @@ -292,85 +276,82 @@ public override string ToString() /// /// Is the GC disposing the object, or is it an explicit call ? //////////////////////////////////////////////////////////// - protected override void Destroy(bool disposing) - { - sfSound_destroy(CPointer); - } + protected override void Destroy(bool disposing) => sfSound_destroy(CPointer); - private SoundBuffer myBuffer; + private SoundBuffer _buffer; #region Imports - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfSound_create(); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfSound_copy(IntPtr Sound); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfSound_copy(IntPtr sound); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSound_destroy(IntPtr Sound); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSound_destroy(IntPtr sound); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSound_play(IntPtr Sound); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSound_play(IntPtr sound); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSound_pause(IntPtr Sound); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSound_pause(IntPtr sound); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSound_stop(IntPtr Sound); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSound_stop(IntPtr sound); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSound_setBuffer(IntPtr Sound, IntPtr Buffer); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSound_setBuffer(IntPtr sound, IntPtr buffer); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSound_setLoop(IntPtr Sound, bool Loop); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSound_setLoop(IntPtr sound, bool loop); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfSound_getLoop(IntPtr Sound); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfSound_getLoop(IntPtr sound); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern SoundStatus sfSound_getStatus(IntPtr Sound); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern SoundStatus sfSound_getStatus(IntPtr sound); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSound_setPitch(IntPtr Sound, float Pitch); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSound_setPitch(IntPtr sound, float pitch); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSound_setVolume(IntPtr Sound, float Volume); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSound_setVolume(IntPtr sound, float volume); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSound_setPosition(IntPtr Sound, Vector3f position); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSound_setPosition(IntPtr sound, Vector3f position); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSound_setRelativeToListener(IntPtr Sound, bool Relative); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSound_setRelativeToListener(IntPtr sound, bool relative); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSound_setMinDistance(IntPtr Sound, float MinDistance); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSound_setMinDistance(IntPtr sound, float minDistance); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSound_setAttenuation(IntPtr Sound, float Attenuation); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSound_setAttenuation(IntPtr sound, float attenuation); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSound_setPlayingOffset(IntPtr Sound, Time TimeOffset); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSound_setPlayingOffset(IntPtr sound, Time timeOffset); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern float sfSound_getPitch(IntPtr Sound); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern float sfSound_getPitch(IntPtr sound); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern float sfSound_getVolume(IntPtr Sound); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern float sfSound_getVolume(IntPtr sound); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Vector3f sfSound_getPosition(IntPtr Sound); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Vector3f sfSound_getPosition(IntPtr sound); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfSound_isRelativeToListener(IntPtr Sound); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfSound_isRelativeToListener(IntPtr sound); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern float sfSound_getMinDistance(IntPtr Sound); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern float sfSound_getMinDistance(IntPtr sound); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern float sfSound_getAttenuation(IntPtr Sound); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern float sfSound_getAttenuation(IntPtr sound); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Time sfSound_getPlayingOffset(IntPtr Sound); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Time sfSound_getPlayingOffset(IntPtr sound); #endregion } } diff --git a/src/SFML.Audio/SoundBuffer.cs b/src/SFML.Audio/SoundBuffer.cs index 9e2138f5..cb032403 100644 --- a/src/SFML.Audio/SoundBuffer.cs +++ b/src/SFML.Audio/SoundBuffer.cs @@ -47,7 +47,7 @@ public SoundBuffer(string filename) : public SoundBuffer(Stream stream) : base(IntPtr.Zero) { - using (StreamAdaptor adaptor = new StreamAdaptor(stream)) + using (var adaptor = new StreamAdaptor(stream)) { CPointer = sfSoundBuffer_createFromStream(adaptor.InputStreamPtr); } @@ -72,7 +72,7 @@ public SoundBuffer(Stream stream) : public SoundBuffer(byte[] bytes) : base(IntPtr.Zero) { - GCHandle pin = GCHandle.Alloc(bytes, GCHandleType.Pinned); + var pin = GCHandle.Alloc(bytes, GCHandleType.Pinned); try { CPointer = sfSoundBuffer_createFromMemory(pin.AddrOfPinnedObject(), (UIntPtr)bytes.Length); @@ -101,9 +101,9 @@ public SoundBuffer(short[] samples, uint channelCount, uint sampleRate) : { unsafe { - fixed (short* SamplesPtr = samples) + fixed (short* samplesPtr = samples) { - CPointer = sfSoundBuffer_createFromSamples(SamplesPtr, (uint)samples.Length, channelCount, sampleRate); + CPointer = sfSoundBuffer_createFromSamples(samplesPtr, (uint)samples.Length, channelCount, sampleRate); } } @@ -135,10 +135,7 @@ public SoundBuffer(SoundBuffer copy) : /// Path of the sound file to write /// True if saving has been successful //////////////////////////////////////////////////////////// - public bool SaveToFile(string filename) - { - return sfSoundBuffer_saveToFile(CPointer, filename); - } + public bool SaveToFile(string filename) => sfSoundBuffer_saveToFile(CPointer, filename); //////////////////////////////////////////////////////////// /// @@ -148,30 +145,21 @@ public bool SaveToFile(string filename) /// second. The higher, the better the quality. /// //////////////////////////////////////////////////////////// - public uint SampleRate - { - get { return sfSoundBuffer_getSampleRate(CPointer); } - } + public uint SampleRate => sfSoundBuffer_getSampleRate(CPointer); //////////////////////////////////////////////////////////// /// /// Number of channels (1 = mono, 2 = stereo) /// //////////////////////////////////////////////////////////// - public uint ChannelCount - { - get { return sfSoundBuffer_getChannelCount(CPointer); } - } + public uint ChannelCount => sfSoundBuffer_getChannelCount(CPointer); //////////////////////////////////////////////////////////// /// /// Total duration of the buffer /// //////////////////////////////////////////////////////////// - public Time Duration - { - get { return sfSoundBuffer_getDuration(CPointer); } - } + public Time Duration => sfSoundBuffer_getDuration(CPointer); //////////////////////////////////////////////////////////// /// @@ -185,9 +173,9 @@ public short[] Samples { get { - short[] SamplesArray = new short[sfSoundBuffer_getSampleCount(CPointer)]; - Marshal.Copy(sfSoundBuffer_getSamples(CPointer), SamplesArray, 0, SamplesArray.Length); - return SamplesArray; + var samplesArray = new short[sfSoundBuffer_getSampleCount(CPointer)]; + Marshal.Copy(sfSoundBuffer_getSamples(CPointer), samplesArray, 0, samplesArray.Length); + return samplesArray; } } @@ -200,7 +188,9 @@ public short[] Samples public override string ToString() { if (IsInvalid) + { return MakeDisposedObjectString(); + } return "[SoundBuffer]" + " SampleRate(" + SampleRate + ")" + @@ -214,47 +204,44 @@ public override string ToString() /// /// Is the GC disposing the object, or is it an explicit call ? //////////////////////////////////////////////////////////// - protected override void Destroy(bool disposing) - { - sfSoundBuffer_destroy(CPointer); - } + protected override void Destroy(bool disposing) => sfSoundBuffer_destroy(CPointer); #region Imports - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfSoundBuffer_createFromFile(string Filename); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfSoundBuffer_createFromFile(string filename); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private unsafe static extern IntPtr sfSoundBuffer_createFromStream(IntPtr stream); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern unsafe IntPtr sfSoundBuffer_createFromStream(IntPtr stream); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private unsafe static extern IntPtr sfSoundBuffer_createFromMemory(IntPtr data, UIntPtr size); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern unsafe IntPtr sfSoundBuffer_createFromMemory(IntPtr data, UIntPtr size); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private unsafe static extern IntPtr sfSoundBuffer_createFromSamples(short* Samples, ulong SampleCount, uint ChannelsCount, uint SampleRate); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern unsafe IntPtr sfSoundBuffer_createFromSamples(short* samples, ulong sampleCount, uint channelsCount, uint sampleRate); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfSoundBuffer_copy(IntPtr SoundBuffer); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfSoundBuffer_copy(IntPtr soundBuffer); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSoundBuffer_destroy(IntPtr SoundBuffer); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSoundBuffer_destroy(IntPtr soundBuffer); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfSoundBuffer_saveToFile(IntPtr SoundBuffer, string Filename); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfSoundBuffer_saveToFile(IntPtr soundBuffer, string filename); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfSoundBuffer_getSamples(IntPtr SoundBuffer); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfSoundBuffer_getSamples(IntPtr soundBuffer); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern ulong sfSoundBuffer_getSampleCount(IntPtr SoundBuffer); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern ulong sfSoundBuffer_getSampleCount(IntPtr soundBuffer); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern uint sfSoundBuffer_getSampleRate(IntPtr SoundBuffer); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern uint sfSoundBuffer_getSampleRate(IntPtr soundBuffer); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern uint sfSoundBuffer_getChannelCount(IntPtr SoundBuffer); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern uint sfSoundBuffer_getChannelCount(IntPtr soundBuffer); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Time sfSoundBuffer_getDuration(IntPtr SoundBuffer); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Time sfSoundBuffer_getDuration(IntPtr soundBuffer); #endregion } } diff --git a/src/SFML.Audio/SoundBufferRecorder.cs b/src/SFML.Audio/SoundBufferRecorder.cs index 07968cb0..9ab0fb08 100644 --- a/src/SFML.Audio/SoundBufferRecorder.cs +++ b/src/SFML.Audio/SoundBufferRecorder.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; namespace SFML.Audio @@ -21,10 +20,7 @@ public class SoundBufferRecorder : SoundRecorder /// to make any modifications to it. /// //////////////////////////////////////////////////////////// - public SoundBuffer SoundBuffer - { - get { return mySoundBuffer; } - } + public SoundBuffer SoundBuffer { get; private set; } //////////////////////////////////////////////////////////// /// @@ -35,7 +31,9 @@ public SoundBuffer SoundBuffer public override string ToString() { if (IsInvalid) + { return MakeDisposedObjectString(); + } return "[SoundBufferRecorder]" + " SampleRate(" + SampleRate + ")" + @@ -50,7 +48,7 @@ public override string ToString() //////////////////////////////////////////////////////////// protected override bool OnStart() { - mySamplesArray.Clear(); + _samplesArray.Clear(); return true; } @@ -63,7 +61,7 @@ protected override bool OnStart() //////////////////////////////////////////////////////////// protected override bool OnProcessSamples(short[] samples) { - mySamplesArray.AddRange(samples); + _samplesArray.AddRange(samples); return true; } @@ -72,12 +70,8 @@ protected override bool OnProcessSamples(short[] samples) /// Called when the current capture stops /// //////////////////////////////////////////////////////////// - protected override void OnStop() - { - mySoundBuffer = new SoundBuffer(mySamplesArray.ToArray(), 1, SampleRate); - } + protected override void OnStop() => SoundBuffer = new SoundBuffer(_samplesArray.ToArray(), 1, SampleRate); - private List mySamplesArray = new List(); - private SoundBuffer mySoundBuffer = null; + private readonly List _samplesArray = new List(); } } diff --git a/src/SFML.Audio/SoundRecorder.cs b/src/SFML.Audio/SoundRecorder.cs index cc3a34da..001416ce 100644 --- a/src/SFML.Audio/SoundRecorder.cs +++ b/src/SFML.Audio/SoundRecorder.cs @@ -20,11 +20,11 @@ public abstract class SoundRecorder : ObjectBase public SoundRecorder() : base(IntPtr.Zero) { - myStartCallback = new StartCallback(StartRecording); - myProcessCallback = new ProcessCallback(ProcessSamples); - myStopCallback = new StopCallback(StopRecording); + _startCallback = new StartCallback(StartRecording); + _processCallback = new ProcessCallback(ProcessSamples); + _stopCallback = new StopCallback(StopRecording); - CPointer = sfSoundRecorder_create(myStartCallback, myProcessCallback, myStopCallback, IntPtr.Zero); + CPointer = sfSoundRecorder_create(_startCallback, _processCallback, _stopCallback, IntPtr.Zero); } //////////////////////////////////////////////////////////// @@ -34,10 +34,7 @@ public SoundRecorder() : /// Please note that only one capture can happen at the same time. /// //////////////////////////////////////////////////////////// - public bool Start() - { - return Start(44100); - } + public bool Start() => Start(44100); //////////////////////////////////////////////////////////// /// @@ -53,20 +50,14 @@ public bool Start() /// /// Sound frequency; the more samples, the higher the quality (44100 by default = CD quality) //////////////////////////////////////////////////////////// - public bool Start(uint sampleRate) - { - return sfSoundRecorder_start(CPointer, sampleRate); - } + public bool Start(uint sampleRate) => sfSoundRecorder_start(CPointer, sampleRate); //////////////////////////////////////////////////////////// /// /// Stop the capture /// //////////////////////////////////////////////////////////// - public void Stop() - { - sfSoundRecorder_stop(CPointer); - } + public void Stop() => sfSoundRecorder_stop(CPointer); //////////////////////////////////////////////////////////// /// @@ -79,10 +70,7 @@ public void Stop() /// (for example, 44100 samples/sec is CD quality). /// //////////////////////////////////////////////////////////// - public uint SampleRate - { - get { return sfSoundRecorder_getSampleRate(CPointer); } - } + public uint SampleRate => sfSoundRecorder_getSampleRate(CPointer); //////////////////////////////////////////////////////////// /// @@ -97,8 +85,8 @@ public uint SampleRate //////////////////////////////////////////////////////////// public uint ChannelCount { - get { return sfSoundRecorder_getChannelCount(CPointer); } - set { sfSoundRecorder_setChannelCount(CPointer, value); } + get => sfSoundRecorder_getChannelCount(CPointer); + set => sfSoundRecorder_setChannelCount(CPointer, value); } //////////////////////////////////////////////////////////// @@ -113,10 +101,7 @@ public uint ChannelCount /// classes will fail. /// //////////////////////////////////////////////////////////// - public static bool IsAvailable - { - get { return sfSoundRecorder_isAvailable(); } - } + public static bool IsAvailable => sfSoundRecorder_isAvailable(); //////////////////////////////////////////////////////////// /// @@ -127,7 +112,9 @@ public static bool IsAvailable public override string ToString() { if (IsInvalid) + { return MakeDisposedObjectString(); + } return "[SoundRecorder]" + " SampleRate(" + SampleRate + ")"; } @@ -143,11 +130,9 @@ public override string ToString() /// /// False to abort recording audio data, true to continue //////////////////////////////////////////////////////////// - protected virtual bool OnStart() - { + protected virtual bool OnStart() => // Does nothing by default - return true; - } + true; //////////////////////////////////////////////////////////// /// @@ -191,10 +176,7 @@ protected virtual void OnStop() /// The default processing interval is 100 ms. /// //////////////////////////////////////////////////////////// - protected void SetProcessingInterval(Time interval) - { - sfSoundRecorder_setProcessingInterval(CPointer, interval); - } + protected void SetProcessingInterval(Time interval) => sfSoundRecorder_setProcessingInterval(CPointer, interval); //////////////////////////////////////////////////////////// /// @@ -207,15 +189,14 @@ public static string[] AvailableDevices { unsafe { - UIntPtr Count; - IntPtr* DevicesPtr = sfSoundRecorder_getAvailableDevices(out Count); - string[] Devices = new string[(int)Count]; - for (int i = 0; i < (int)Count; ++i) + var devicesPtr = sfSoundRecorder_getAvailableDevices(out var count); + var devices = new string[(int)count]; + for (var i = 0; i < (int)count; ++i) { - Devices[i] = Marshal.PtrToStringAnsi(DevicesPtr[i]); + devices[i] = Marshal.PtrToStringAnsi(devicesPtr[i]); } - return Devices; + return devices; } } } @@ -225,22 +206,16 @@ public static string[] AvailableDevices /// Get the name of the default audio capture device /// //////////////////////////////////////////////////////////// - public static string DefaultDevice - { - get { return Marshal.PtrToStringAnsi(sfSoundRecorder_getDefaultDevice()); } - } + public static string DefaultDevice => Marshal.PtrToStringAnsi(sfSoundRecorder_getDefaultDevice()); //////////////////////////////////////////////////////////// /// /// Set the audio capture device /// - /// The name of the audio capture device + /// The name of the audio capture device /// True, if it was able to set the requested device //////////////////////////////////////////////////////////// - public bool SetDevice(string Name) - { - return sfSoundRecorder_setDevice(CPointer, Name); - } + public bool SetDevice(string name) => sfSoundRecorder_setDevice(CPointer, name); //////////////////////////////////////////////////////////// /// @@ -248,10 +223,7 @@ public bool SetDevice(string Name) /// /// The name of the current audio capture device //////////////////////////////////////////////////////////// - public string GetDevice() - { - return Marshal.PtrToStringAnsi(sfSoundRecorder_getDevice(CPointer)); - } + public string GetDevice() => Marshal.PtrToStringAnsi(sfSoundRecorder_getDevice(CPointer)); //////////////////////////////////////////////////////////// /// @@ -259,10 +231,7 @@ public string GetDevice() /// /// Is the GC disposing the object, or is it an explicit call ? //////////////////////////////////////////////////////////// - protected override void Destroy(bool disposing) - { - sfSoundRecorder_destroy(CPointer); - } + protected override void Destroy(bool disposing) => sfSoundRecorder_destroy(CPointer); //////////////////////////////////////////////////////////// /// @@ -272,10 +241,7 @@ protected override void Destroy(bool disposing) /// User data -- unused /// False to stop recording audio data, true to continue //////////////////////////////////////////////////////////// - private bool StartRecording(IntPtr userData) - { - return OnStart(); - } + private bool StartRecording(IntPtr userData) => OnStart(); //////////////////////////////////////////////////////////// /// @@ -289,7 +255,7 @@ private bool StartRecording(IntPtr userData) //////////////////////////////////////////////////////////// private bool ProcessSamples(IntPtr samples, UIntPtr nbSamples, IntPtr userData) { - short[] samplesArray = new short[(int)nbSamples]; + var samplesArray = new short[(int)nbSamples]; Marshal.Copy(samples, samplesArray, 0, samplesArray.Length); return OnProcessSamples(samplesArray); @@ -302,10 +268,7 @@ private bool ProcessSamples(IntPtr samples, UIntPtr nbSamples, IntPtr userData) /// /// User data -- unused //////////////////////////////////////////////////////////// - private void StopRecording(IntPtr userData) - { - OnStop(); - } + private void StopRecording(IntPtr userData) => OnStop(); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate bool StartCallback(IntPtr userData); @@ -316,49 +279,49 @@ private void StopRecording(IntPtr userData) [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void StopCallback(IntPtr userData); - private readonly StartCallback myStartCallback; - private readonly ProcessCallback myProcessCallback; - private readonly StopCallback myStopCallback; + private readonly StartCallback _startCallback; + private readonly ProcessCallback _processCallback; + private readonly StopCallback _stopCallback; #region Imports - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfSoundRecorder_create(StartCallback OnStart, ProcessCallback OnProcess, StopCallback OnStop, IntPtr UserData); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfSoundRecorder_create(StartCallback onStart, ProcessCallback onProcess, StopCallback onStop, IntPtr userData); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSoundRecorder_destroy(IntPtr SoundRecorder); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSoundRecorder_destroy(IntPtr soundRecorder); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfSoundRecorder_start(IntPtr SoundRecorder, uint SampleRate); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfSoundRecorder_start(IntPtr soundRecorder, uint sampleRate); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSoundRecorder_stop(IntPtr SoundRecorder); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSoundRecorder_stop(IntPtr soundRecorder); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern uint sfSoundRecorder_getSampleRate(IntPtr SoundRecorder); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern uint sfSoundRecorder_getSampleRate(IntPtr soundRecorder); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern bool sfSoundRecorder_isAvailable(); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSoundRecorder_setProcessingInterval(IntPtr SoundRecorder, Time Interval); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSoundRecorder_setProcessingInterval(IntPtr soundRecorder, Time interval); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private unsafe static extern IntPtr* sfSoundRecorder_getAvailableDevices(out UIntPtr Count); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern unsafe IntPtr* sfSoundRecorder_getAvailableDevices(out UIntPtr count); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfSoundRecorder_getDefaultDevice(); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfSoundRecorder_setDevice(IntPtr SoundRecorder, string Name); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfSoundRecorder_setDevice(IntPtr soundRecorder, string name); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfSoundRecorder_getDevice(IntPtr SoundRecorder); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfSoundRecorder_getDevice(IntPtr soundRecorder); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSoundRecorder_setChannelCount(IntPtr SoundRecorder, uint channelCount); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSoundRecorder_setChannelCount(IntPtr soundRecorder, uint channelCount); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern uint sfSoundRecorder_getChannelCount(IntPtr SoundRecorder); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern uint sfSoundRecorder_getChannelCount(IntPtr soundRecorder); #endregion } } diff --git a/src/SFML.Audio/SoundStream.cs b/src/SFML.Audio/SoundStream.cs index 06fd9b29..f009930d 100644 --- a/src/SFML.Audio/SoundStream.cs +++ b/src/SFML.Audio/SoundStream.cs @@ -33,10 +33,7 @@ public SoundStream() : /// the rest of the program while the stream is played. /// //////////////////////////////////////////////////////////// - public void Play() - { - sfSoundStream_play(CPointer); - } + public void Play() => sfSoundStream_play(CPointer); //////////////////////////////////////////////////////////// /// @@ -46,10 +43,7 @@ public void Play() /// otherwise (stream already paused or stopped) it has no effect. /// //////////////////////////////////////////////////////////// - public void Pause() - { - sfSoundStream_pause(CPointer); - } + public void Pause() => sfSoundStream_pause(CPointer); //////////////////////////////////////////////////////////// /// @@ -60,10 +54,7 @@ public void Pause() /// It also resets the playing position (unlike pause()). /// //////////////////////////////////////////////////////////// - public void Stop() - { - sfSoundStream_stop(CPointer); - } + public void Stop() => sfSoundStream_stop(CPointer); //////////////////////////////////////////////////////////// /// @@ -73,30 +64,21 @@ public void Stop() /// second. The higher, the better the quality. /// //////////////////////////////////////////////////////////// - public uint SampleRate - { - get { return sfSoundStream_getSampleRate(CPointer); } - } + public uint SampleRate => sfSoundStream_getSampleRate(CPointer); //////////////////////////////////////////////////////////// /// /// Number of channels (1 = mono, 2 = stereo) /// //////////////////////////////////////////////////////////// - public uint ChannelCount - { - get { return sfSoundStream_getChannelCount(CPointer); } - } + public uint ChannelCount => sfSoundStream_getChannelCount(CPointer); //////////////////////////////////////////////////////////// /// /// Current status of the sound stream (see SoundStatus enum) /// //////////////////////////////////////////////////////////// - public SoundStatus Status - { - get { return sfSoundStream_getStatus(CPointer); } - } + public SoundStatus Status => sfSoundStream_getStatus(CPointer); //////////////////////////////////////////////////////////// /// @@ -110,8 +92,8 @@ public SoundStatus Status //////////////////////////////////////////////////////////// public bool Loop { - get { return sfSoundStream_getLoop(CPointer); } - set { sfSoundStream_setLoop(CPointer, value); } + get => sfSoundStream_getLoop(CPointer); + set => sfSoundStream_setLoop(CPointer, value); } //////////////////////////////////////////////////////////// @@ -127,8 +109,8 @@ public bool Loop //////////////////////////////////////////////////////////// public float Pitch { - get { return sfSoundStream_getPitch(CPointer); } - set { sfSoundStream_setPitch(CPointer, value); } + get => sfSoundStream_getPitch(CPointer); + set => sfSoundStream_setPitch(CPointer, value); } //////////////////////////////////////////////////////////// @@ -141,8 +123,8 @@ public float Pitch //////////////////////////////////////////////////////////// public float Volume { - get { return sfSoundStream_getVolume(CPointer); } - set { sfSoundStream_setVolume(CPointer, value); } + get => sfSoundStream_getVolume(CPointer); + set => sfSoundStream_setVolume(CPointer, value); } //////////////////////////////////////////////////////////// @@ -156,8 +138,8 @@ public float Volume //////////////////////////////////////////////////////////// public Vector3f Position { - get { return sfSoundStream_getPosition(CPointer); } - set { sfSoundStream_setPosition(CPointer, value); } + get => sfSoundStream_getPosition(CPointer); + set => sfSoundStream_setPosition(CPointer, value); } //////////////////////////////////////////////////////////// @@ -173,8 +155,8 @@ public Vector3f Position //////////////////////////////////////////////////////////// public bool RelativeToListener { - get { return sfSoundStream_isRelativeToListener(CPointer); } - set { sfSoundStream_setRelativeToListener(CPointer, value); } + get => sfSoundStream_isRelativeToListener(CPointer); + set => sfSoundStream_setRelativeToListener(CPointer, value); } //////////////////////////////////////////////////////////// @@ -191,8 +173,8 @@ public bool RelativeToListener //////////////////////////////////////////////////////////// public float MinDistance { - get { return sfSoundStream_getMinDistance(CPointer); } - set { sfSoundStream_setMinDistance(CPointer, value); } + get => sfSoundStream_getMinDistance(CPointer); + set => sfSoundStream_setMinDistance(CPointer, value); } //////////////////////////////////////////////////////////// @@ -211,8 +193,8 @@ public float MinDistance //////////////////////////////////////////////////////////// public float Attenuation { - get { return sfSoundStream_getAttenuation(CPointer); } - set { sfSoundStream_setAttenuation(CPointer, value); } + get => sfSoundStream_getAttenuation(CPointer); + set => sfSoundStream_setAttenuation(CPointer, value); } //////////////////////////////////////////////////////////// @@ -225,8 +207,8 @@ public float Attenuation //////////////////////////////////////////////////////////// public Time PlayingOffset { - get { return sfSoundStream_getPlayingOffset(CPointer); } - set { sfSoundStream_setPlayingOffset(CPointer, value); } + get => sfSoundStream_getPlayingOffset(CPointer); + set => sfSoundStream_setPlayingOffset(CPointer, value); } //////////////////////////////////////////////////////////// @@ -238,7 +220,9 @@ public Time PlayingOffset public override string ToString() { if (IsInvalid) + { return MakeDisposedObjectString(); + } return "[SoundStream]" + " SampleRate(" + SampleRate + ")" + @@ -263,9 +247,9 @@ public override string ToString() //////////////////////////////////////////////////////////// protected void Initialize(uint channelCount, uint sampleRate) { - myGetDataCallback = new GetDataCallbackType(GetData); - mySeekCallback = new SeekCallbackType(Seek); - CPointer = sfSoundStream_create(myGetDataCallback, mySeekCallback, channelCount, sampleRate, IntPtr.Zero); + _getDataCallback = new GetDataCallbackType(GetData); + _seekCallback = new SeekCallbackType(Seek); + CPointer = sfSoundStream_create(_getDataCallback, _seekCallback, channelCount, sampleRate, IntPtr.Zero); } //////////////////////////////////////////////////////////// @@ -291,10 +275,7 @@ protected void Initialize(uint channelCount, uint sampleRate) /// /// Is the GC disposing the object, or is it an explicit call ? //////////////////////////////////////////////////////////// - protected override void Destroy(bool disposing) - { - sfSoundStream_destroy(CPointer); - } + protected override void Destroy(bool disposing) => sfSoundStream_destroy(CPointer); //////////////////////////////////////////////////////////// /// @@ -304,8 +285,8 @@ protected override void Destroy(bool disposing) [StructLayout(LayoutKind.Sequential)] private struct Chunk { - unsafe public short* samples; - public uint sampleCount; + public unsafe short* Samples; + public uint SampleCount; } //////////////////////////////////////////////////////////// @@ -318,14 +299,14 @@ private struct Chunk //////////////////////////////////////////////////////////// private bool GetData(ref Chunk dataChunk, IntPtr userData) { - if (OnGetData(out myTempBuffer)) + if (OnGetData(out _tempBuffer)) { unsafe { - fixed (short* samplesPtr = myTempBuffer) + fixed (short* samplesPtr = _tempBuffer) { - dataChunk.samples = samplesPtr; - dataChunk.sampleCount = (uint)myTempBuffer.Length; + dataChunk.Samples = samplesPtr; + dataChunk.SampleCount = (uint)_tempBuffer.Length; } } @@ -345,93 +326,90 @@ private bool GetData(ref Chunk dataChunk, IntPtr userData) /// User data -- unused /// If false is returned, the playback is aborted //////////////////////////////////////////////////////////// - private void Seek(Time timeOffset, IntPtr userData) - { - OnSeek(timeOffset); - } + private void Seek(Time timeOffset, IntPtr userData) => OnSeek(timeOffset); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate bool GetDataCallbackType(ref Chunk dataChunk, IntPtr UserData); + private delegate bool GetDataCallbackType(ref Chunk dataChunk, IntPtr userData); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void SeekCallbackType(Time timeOffset, IntPtr UserData); + private delegate void SeekCallbackType(Time timeOffset, IntPtr userData); - private GetDataCallbackType myGetDataCallback; - private SeekCallbackType mySeekCallback; - private short[] myTempBuffer; + private GetDataCallbackType _getDataCallback; + private SeekCallbackType _seekCallback; + private short[] _tempBuffer; #region Imports - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfSoundStream_create(GetDataCallbackType OnGetData, SeekCallbackType OnSeek, uint ChannelCount, uint SampleRate, IntPtr UserData); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfSoundStream_create(GetDataCallbackType onGetData, SeekCallbackType onSeek, uint channelCount, uint sampleRate, IntPtr userData); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSoundStream_destroy(IntPtr SoundStreamStream); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSoundStream_destroy(IntPtr soundStream); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSoundStream_play(IntPtr SoundStream); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSoundStream_play(IntPtr soundStream); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSoundStream_pause(IntPtr SoundStream); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSoundStream_pause(IntPtr soundStream); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSoundStream_stop(IntPtr SoundStream); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSoundStream_stop(IntPtr soundStream); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern SoundStatus sfSoundStream_getStatus(IntPtr SoundStream); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern SoundStatus sfSoundStream_getStatus(IntPtr soundStream); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern uint sfSoundStream_getChannelCount(IntPtr SoundStream); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern uint sfSoundStream_getChannelCount(IntPtr soundStream); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern uint sfSoundStream_getSampleRate(IntPtr SoundStream); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern uint sfSoundStream_getSampleRate(IntPtr soundStream); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSoundStream_setLoop(IntPtr SoundStream, bool Loop); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSoundStream_setLoop(IntPtr soundStream, bool loop); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSoundStream_setPitch(IntPtr SoundStream, float Pitch); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSoundStream_setPitch(IntPtr soundStream, float pitch); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSoundStream_setVolume(IntPtr SoundStream, float Volume); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSoundStream_setVolume(IntPtr soundStream, float volume); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSoundStream_setPosition(IntPtr SoundStream, Vector3f position); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSoundStream_setPosition(IntPtr soundStream, Vector3f position); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSoundStream_setRelativeToListener(IntPtr SoundStream, bool Relative); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSoundStream_setRelativeToListener(IntPtr soundStream, bool relative); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSoundStream_setMinDistance(IntPtr SoundStream, float MinDistance); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSoundStream_setMinDistance(IntPtr soundStream, float minDistance); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSoundStream_setAttenuation(IntPtr SoundStream, float Attenuation); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSoundStream_setAttenuation(IntPtr soundStream, float attenuation); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSoundStream_setPlayingOffset(IntPtr SoundStream, Time TimeOffset); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSoundStream_setPlayingOffset(IntPtr soundStream, Time timeOffset); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfSoundStream_getLoop(IntPtr SoundStream); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfSoundStream_getLoop(IntPtr soundStream); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern float sfSoundStream_getPitch(IntPtr SoundStream); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern float sfSoundStream_getPitch(IntPtr soundStream); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern float sfSoundStream_getVolume(IntPtr SoundStream); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern float sfSoundStream_getVolume(IntPtr soundStream); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Vector3f sfSoundStream_getPosition(IntPtr SoundStream); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Vector3f sfSoundStream_getPosition(IntPtr soundStream); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfSoundStream_isRelativeToListener(IntPtr SoundStream); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfSoundStream_isRelativeToListener(IntPtr soundStream); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern float sfSoundStream_getMinDistance(IntPtr SoundStream); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern float sfSoundStream_getMinDistance(IntPtr soundStream); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern float sfSoundStream_getAttenuation(IntPtr SoundStream); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern float sfSoundStream_getAttenuation(IntPtr soundStream); - [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Time sfSoundStream_getPlayingOffset(IntPtr SoundStream); + [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Time sfSoundStream_getPlayingOffset(IntPtr soundStream); #endregion } } diff --git a/src/SFML.Graphics/BlendMode.cs b/src/SFML.Graphics/BlendMode.cs index 651569f1..5c100ee3 100644 --- a/src/SFML.Graphics/BlendMode.cs +++ b/src/SFML.Graphics/BlendMode.cs @@ -96,11 +96,11 @@ public enum Equation /// /// Construct the blend mode given the factors and equation /// - /// Specifies how to compute the source factor for the color and alpha channels. - /// Specifies how to compute the destination factor for the color and alpha channels. + /// Specifies how to compute the source factor for the color and alpha channels. + /// Specifies how to compute the destination factor for the color and alpha channels. //////////////////////////////////////////////////////////// - public BlendMode(Factor SourceFactor, Factor DestinationFactor) - : this(SourceFactor, DestinationFactor, Equation.Add) + public BlendMode(Factor sourceFactor, Factor destinationFactor) + : this(sourceFactor, destinationFactor, Equation.Add) { } @@ -108,12 +108,12 @@ public BlendMode(Factor SourceFactor, Factor DestinationFactor) /// /// Construct the blend mode given the factors and equation /// - /// Specifies how to compute the source factor for the color and alpha channels. - /// Specifies how to compute the destination factor for the color and alpha channels. - /// Specifies how to combine the source and destination colors and alpha. + /// Specifies how to compute the source factor for the color and alpha channels. + /// Specifies how to compute the destination factor for the color and alpha channels. + /// Specifies how to combine the source and destination colors and alpha. //////////////////////////////////////////////////////////// - public BlendMode(Factor SourceFactor, Factor DestinationFactor, Equation BlendEquation) - : this(SourceFactor, DestinationFactor, BlendEquation, SourceFactor, DestinationFactor, BlendEquation) + public BlendMode(Factor sourceFactor, Factor destinationFactor, Equation blendEquation) + : this(sourceFactor, destinationFactor, blendEquation, sourceFactor, destinationFactor, blendEquation) { } @@ -121,21 +121,21 @@ public BlendMode(Factor SourceFactor, Factor DestinationFactor, Equation BlendEq /// /// Construct the blend mode given the factors and equation /// - /// Specifies how to compute the source factor for the color channels. - /// Specifies how to compute the destination factor for the color channels. - /// Specifies how to combine the source and destination colors. - /// Specifies how to compute the source factor. - /// Specifies how to compute the destination factor. - /// Specifies how to combine the source and destination alphas. - //////////////////////////////////////////////////////////// - public BlendMode(Factor ColorSourceFactor, Factor ColorDestinationFactor, Equation ColorBlendEquation, Factor AlphaSourceFactor, Factor AlphaDestinationFactor, Equation AlphaBlendEquation) + /// Specifies how to compute the source factor for the color channels. + /// Specifies how to compute the destination factor for the color channels. + /// Specifies how to combine the source and destination colors. + /// Specifies how to compute the source factor. + /// Specifies how to compute the destination factor. + /// Specifies how to combine the source and destination alphas. + //////////////////////////////////////////////////////////// + public BlendMode(Factor colorSourceFactor, Factor colorDestinationFactor, Equation colorBlendEquation, Factor alphaSourceFactor, Factor alphaDestinationFactor, Equation alphaBlendEquation) { - ColorSrcFactor = ColorSourceFactor; - ColorDstFactor = ColorDestinationFactor; - ColorEquation = ColorBlendEquation; - AlphaSrcFactor = AlphaSourceFactor; - AlphaDstFactor = AlphaDestinationFactor; - AlphaEquation = AlphaBlendEquation; + ColorSrcFactor = colorSourceFactor; + ColorDstFactor = colorDestinationFactor; + ColorEquation = colorBlendEquation; + AlphaSrcFactor = alphaSourceFactor; + AlphaDstFactor = alphaDestinationFactor; + AlphaEquation = alphaBlendEquation; } //////////////////////////////////////////////////////////// @@ -161,7 +161,7 @@ public BlendMode(Factor ColorSourceFactor, Factor ColorDestinationFactor, Equati /// Object to check /// Object and blend mode are equal //////////////////////////////////////////////////////////// - public override bool Equals(object obj) => ( obj is BlendMode ) && Equals((BlendMode)obj); + public override bool Equals(object obj) => (obj is BlendMode mode) && Equals(mode); /////////////////////////////////////////////////////////// /// @@ -170,15 +170,12 @@ public BlendMode(Factor ColorSourceFactor, Factor ColorDestinationFactor, Equati /// Blend Mode to check /// blend modes are equal //////////////////////////////////////////////////////////// - public bool Equals(BlendMode other) - { - return ( ColorSrcFactor == other.ColorSrcFactor ) && - ( ColorDstFactor == other.ColorDstFactor ) && - ( ColorEquation == other.ColorEquation ) && - ( AlphaSrcFactor == other.AlphaSrcFactor ) && - ( AlphaDstFactor == other.AlphaDstFactor ) && - ( AlphaEquation == other.AlphaEquation ); - } + public bool Equals(BlendMode other) => (ColorSrcFactor == other.ColorSrcFactor) && + (ColorDstFactor == other.ColorDstFactor) && + (ColorEquation == other.ColorEquation) && + (AlphaSrcFactor == other.AlphaSrcFactor) && + (AlphaDstFactor == other.AlphaDstFactor) && + (AlphaEquation == other.AlphaEquation); //////////////////////////////////////////////////////////// /// @@ -186,15 +183,12 @@ public bool Equals(BlendMode other) /// /// Integer description of the object //////////////////////////////////////////////////////////// - public override int GetHashCode() - { - return ColorSrcFactor.GetHashCode() ^ + public override int GetHashCode() => ColorSrcFactor.GetHashCode() ^ ColorDstFactor.GetHashCode() ^ ColorEquation.GetHashCode() ^ AlphaSrcFactor.GetHashCode() ^ AlphaDstFactor.GetHashCode() ^ AlphaEquation.GetHashCode(); - } /// Source blending factor for the color channels public Factor ColorSrcFactor; diff --git a/src/SFML.Graphics/CircleShape.cs b/src/SFML.Graphics/CircleShape.cs index a7c1844f..9b3e0a84 100644 --- a/src/SFML.Graphics/CircleShape.cs +++ b/src/SFML.Graphics/CircleShape.cs @@ -57,8 +57,8 @@ public CircleShape(CircleShape copy) : base(copy) //////////////////////////////////////////////////////////// public float Radius { - get { return myRadius; } - set { myRadius = value; Update(); } + get => _radius; + set { _radius = value; Update(); } } //////////////////////////////////////////////////////////// @@ -67,7 +67,7 @@ public float Radius /// /// The total point count //////////////////////////////////////////////////////////// - public override uint GetPointCount() => myPointCount; + public override uint GetPointCount() => _pointCount; //////////////////////////////////////////////////////////// /// @@ -78,7 +78,7 @@ public float Radius //////////////////////////////////////////////////////////// public void SetPointCount(uint count) { - myPointCount = count; + _pointCount = count; Update(); } @@ -96,14 +96,14 @@ public void SetPointCount(uint count) //////////////////////////////////////////////////////////// public override Vector2f GetPoint(uint index) { - float angle = (float)( index * 2 * Math.PI / myPointCount - Math.PI / 2 ); - float x = (float)Math.Cos(angle) * myRadius; - float y = (float)Math.Sin(angle) * myRadius; + var angle = (float)((index * 2 * Math.PI / _pointCount) - (Math.PI / 2)); + var x = (float)Math.Cos(angle) * _radius; + var y = (float)Math.Sin(angle) * _radius; - return new Vector2f(myRadius + x, myRadius + y); + return new Vector2f(_radius + x, _radius + y); } - private float myRadius; - private uint myPointCount; + private float _radius; + private uint _pointCount; } } diff --git a/src/SFML.Graphics/Color.cs b/src/SFML.Graphics/Color.cs index f8c771d1..52b3dcb8 100644 --- a/src/SFML.Graphics/Color.cs +++ b/src/SFML.Graphics/Color.cs @@ -48,9 +48,9 @@ public Color(uint color) { unchecked { - R = (byte)( color >> 24 ); - G = (byte)( color >> 16 ); - B = (byte)( color >> 8 ); + R = (byte)(color >> 24); + G = (byte)(color >> 16); + B = (byte)(color >> 8); A = (byte)color; } } @@ -69,7 +69,7 @@ public Color(Color color) : this(color.R, color.G, color.B, color.A) { } /// /// Color represented as a 32-bit unsigned integer //////////////////////////////////////////////////////////// - public uint ToInteger() => (uint)( ( R << 24 ) | ( G << 16 ) | ( B << 8 ) | A ); + public uint ToInteger() => (uint)((R << 24) | (G << 16) | (B << 8) | A); //////////////////////////////////////////////////////////// /// @@ -101,7 +101,7 @@ public void Deconstruct(out byte red, out byte green, out byte blue, out byte al /// Object to check /// Object and color are equal //////////////////////////////////////////////////////////// - public override bool Equals(object obj) => ( obj is Color ) && Equals((Color)obj); + public override bool Equals(object obj) => (obj is Color) && Equals((Color)obj); /////////////////////////////////////////////////////////// /// @@ -110,7 +110,7 @@ public void Deconstruct(out byte red, out byte green, out byte blue, out byte al /// Color to check /// Colors are equal //////////////////////////////////////////////////////////// - public bool Equals(Color other) => ( R == other.R ) && ( G == other.G ) && ( B == other.B ) && ( A == other.A ); + public bool Equals(Color other) => (R == other.R) && (G == other.G) && (B == other.B) && (A == other.A); //////////////////////////////////////////////////////////// /// @@ -118,7 +118,7 @@ public void Deconstruct(out byte red, out byte green, out byte blue, out byte al /// /// Integer description of the object //////////////////////////////////////////////////////////// - public override int GetHashCode() => ( R << 24 ) | ( G << 16 ) | ( B << 8 ) | A; + public override int GetHashCode() => (R << 24) | (G << 16) | (B << 8) | A; //////////////////////////////////////////////////////////// /// @@ -143,13 +143,10 @@ public void Deconstruct(out byte red, out byte green, out byte blue, out byte al /// /// Result of left + right //////////////////////////////////////////////////////////// - public static Color operator +(Color left, Color right) - { - return new Color((byte)Math.Min(left.R + right.R, 255), + public static Color operator +(Color left, Color right) => new Color((byte)Math.Min(left.R + right.R, 255), (byte)Math.Min(left.G + right.G, 255), (byte)Math.Min(left.B + right.B, 255), (byte)Math.Min(left.A + right.A, 255)); - } //////////////////////////////////////////////////////////// /// @@ -158,13 +155,10 @@ public void Deconstruct(out byte red, out byte green, out byte blue, out byte al /// /// Result of left - right //////////////////////////////////////////////////////////// - public static Color operator -(Color left, Color right) - { - return new Color((byte)Math.Max(left.R - right.R, 0), + public static Color operator -(Color left, Color right) => new Color((byte)Math.Max(left.R - right.R, 0), (byte)Math.Max(left.G - right.G, 0), (byte)Math.Max(left.B - right.B, 0), (byte)Math.Max(left.A - right.A, 0)); - } //////////////////////////////////////////////////////////// /// @@ -173,13 +167,10 @@ public void Deconstruct(out byte red, out byte green, out byte blue, out byte al /// /// Result of left * right //////////////////////////////////////////////////////////// - public static Color operator *(Color left, Color right) - { - return new Color((byte)( left.R * right.R / 255 ), - (byte)( left.G * right.G / 255 ), - (byte)( left.B * right.B / 255 ), - (byte)( left.A * right.A / 255 )); - } + public static Color operator *(Color left, Color right) => new Color((byte)(left.R * right.R / 255), + (byte)(left.G * right.G / 255), + (byte)(left.B * right.B / 255), + (byte)(left.A * right.A / 255)); /// /// Converts a tuple of bytes to a Color diff --git a/src/SFML.Graphics/ConvexShape.cs b/src/SFML.Graphics/ConvexShape.cs index cec6c3b3..ef9d4a59 100644 --- a/src/SFML.Graphics/ConvexShape.cs +++ b/src/SFML.Graphics/ConvexShape.cs @@ -23,10 +23,7 @@ public ConvexShape() : this(0) { } /// /// Number of points of the shape //////////////////////////////////////////////////////////// - public ConvexShape(uint pointCount) - { - SetPointCount(pointCount); - } + public ConvexShape(uint pointCount) => SetPointCount(pointCount); //////////////////////////////////////////////////////////// /// @@ -49,7 +46,7 @@ public ConvexShape(ConvexShape copy) : base(copy) /// /// The total point count //////////////////////////////////////////////////////////// - public override uint GetPointCount() => (uint)(myPoints?.Length ?? 0); + public override uint GetPointCount() => (uint)(_points?.Length ?? 0); //////////////////////////////////////////////////////////// /// @@ -60,7 +57,7 @@ public ConvexShape(ConvexShape copy) : base(copy) //////////////////////////////////////////////////////////// public void SetPointCount(uint count) { - Array.Resize(ref myPoints, (int)count); + Array.Resize(ref _points, (int)count); Update(); } @@ -76,7 +73,7 @@ public void SetPointCount(uint count) /// Index of the point to get, in range [0 .. PointCount - 1] /// index-th point of the shape //////////////////////////////////////////////////////////// - public override Vector2f GetPoint(uint index) => myPoints[index]; + public override Vector2f GetPoint(uint index) => _points[index]; //////////////////////////////////////////////////////////// /// @@ -93,10 +90,10 @@ public void SetPointCount(uint count) //////////////////////////////////////////////////////////// public void SetPoint(uint index, Vector2f point) { - myPoints[index] = point; + _points[index] = point; Update(); } - private Vector2f[] myPoints; + private Vector2f[] _points; } } diff --git a/src/SFML.Graphics/Font.cs b/src/SFML.Graphics/Font.cs index 239dfae4..1e67d781 100644 --- a/src/SFML.Graphics/Font.cs +++ b/src/SFML.Graphics/Font.cs @@ -62,7 +62,7 @@ public Font(Stream stream) : base(IntPtr.Zero) public Font(byte[] bytes) : base(IntPtr.Zero) { - GCHandle pin = GCHandle.Alloc(bytes, GCHandleType.Pinned); + var pin = GCHandle.Alloc(bytes, GCHandleType.Pinned); try { CPointer = sfFont_createFromMemory(pin.AddrOfPinnedObject(), (UIntPtr)bytes.Length); @@ -157,8 +157,8 @@ public Font(Font copy) : base(sfFont_copy(copy.CPointer)) { } //////////////////////////////////////////////////////////// public Texture GetTexture(uint characterSize) { - myTextures[characterSize] = new Texture(sfFont_getTexture(CPointer, characterSize)); - return myTextures[characterSize]; + _textures[characterSize] = new Texture(sfFont_getTexture(CPointer, characterSize)); + return _textures[characterSize]; } //////////////////////////////////////////////////////////// @@ -191,10 +191,11 @@ public Texture GetTexture(uint characterSize) //////////////////////////////////////////////////////////// public Info GetInfo() { - InfoMarshalData data = sfFont_getInfo(CPointer); - Info info = new Info(); - - info.Family = Marshal.PtrToStringAnsi(data.Family); + var data = sfFont_getInfo(CPointer); + var info = new Info + { + Family = Marshal.PtrToStringAnsi(data.Family) + }; return info; } @@ -217,27 +218,22 @@ protected override void Destroy(bool disposing) { if (!disposing) { - Context.Global.SetActive(true); + _ = Context.Global.SetActive(true); } sfFont_destroy(CPointer); if (disposing) { - foreach (Texture texture in myTextures.Values) + foreach (var texture in _textures.Values) { texture.Dispose(); } - - if (myStream != null) - { - myStream.Dispose(); - } } if (!disposing) { - Context.Global.SetActive(false); + _ = Context.Global.SetActive(false); } } @@ -272,54 +268,53 @@ internal struct InfoMarshalData public IntPtr Family; } - private Dictionary myTextures = new Dictionary(); - private SFML.System.StreamAdaptor myStream = null; + private readonly Dictionary _textures = new Dictionary(); #region Imports - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfFont_createFromFile(string Filename); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfFont_createFromFile(string filename); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfFont_createFromStream(IntPtr stream); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfFont_createFromMemory(IntPtr data, UIntPtr size); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfFont_copy(IntPtr Font); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfFont_copy(IntPtr font); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfFont_destroy(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfFont_destroy(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Glyph sfFont_getGlyph(IntPtr CPointer, uint codePoint, uint characterSize, bool bold, float outlineThickness); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Glyph sfFont_getGlyph(IntPtr cPointer, uint codePoint, uint characterSize, bool bold, float outlineThickness); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern float sfFont_getKerning(IntPtr CPointer, uint first, uint second, uint characterSize); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern float sfFont_getKerning(IntPtr cPointer, uint first, uint second, uint characterSize); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern float sfFont_getBoldKerning(IntPtr CPointer, uint first, uint second, uint characterSize); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern float sfFont_getBoldKerning(IntPtr cPointer, uint first, uint second, uint characterSize); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern float sfFont_getLineSpacing(IntPtr CPointer, uint characterSize); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern float sfFont_getLineSpacing(IntPtr cPointer, uint characterSize); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern float sfFont_getUnderlinePosition(IntPtr CPointer, uint characterSize); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern float sfFont_getUnderlinePosition(IntPtr cPointer, uint characterSize); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern float sfFont_getUnderlineThickness(IntPtr CPointer, uint characterSize); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern float sfFont_getUnderlineThickness(IntPtr cPointer, uint characterSize); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfFont_getTexture(IntPtr CPointer, uint characterSize); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfFont_getTexture(IntPtr cPointer, uint characterSize); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfFont_setSmooth(IntPtr CPointer, bool smooth); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfFont_setSmooth(IntPtr cPointer, bool smooth); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfFont_isSmooth(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfFont_isSmooth(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern InfoMarshalData sfFont_getInfo(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern InfoMarshalData sfFont_getInfo(IntPtr cPointer); #endregion } } diff --git a/src/SFML.Graphics/Glsl.cs b/src/SFML.Graphics/Glsl.cs index fd7c751b..f381dcae 100644 --- a/src/SFML.Graphics/Glsl.cs +++ b/src/SFML.Graphics/Glsl.cs @@ -419,7 +419,7 @@ public Mat3(float a00, float a01, float a02, float a10, float a11, float a12, float a20, float a21, float a22) { - fixed (float* m = array) + fixed (float* m = _array) { m[0] = a00; m[3] = a01; @@ -441,22 +441,22 @@ public Mat3(float a00, float a01, float a02, //////////////////////////////////////////////////////////// public Mat3(Transform transform) { - fixed (float* m = array) + fixed (float* m = _array) { - m[0] = transform.m00; - m[3] = transform.m01; - m[6] = transform.m02; - m[1] = transform.m10; - m[4] = transform.m11; - m[7] = transform.m12; - m[2] = transform.m20; - m[5] = transform.m21; - m[8] = transform.m22; + m[0] = transform.M00; + m[3] = transform.M01; + m[6] = transform.M02; + m[1] = transform.M10; + m[4] = transform.M11; + m[7] = transform.M12; + m[2] = transform.M20; + m[5] = transform.M21; + m[8] = transform.M22; } } // column-major! - private fixed float array[3 * 3]; + private fixed float _array[3 * 3]; } //////////////////////////////////////////////////////////// @@ -476,16 +476,10 @@ public unsafe struct Mat4 /// Keep in mind that a Mat4 cannot be modified after construction /// //////////////////////////////////////////////////////////// - public static Mat4 Identity - { - get - { - return new Mat4(1, 0, 0, 0, + public static Mat4 Identity => new Mat4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); - } - } //////////////////////////////////////////////////////////// /// @@ -501,7 +495,7 @@ public Mat4(float a00, float a01, float a02, float a03, float a20, float a21, float a22, float a23, float a30, float a31, float a32, float a33) { - fixed (float* m = array) + fixed (float* m = _array) { // transpose to column major m[0] = a00; @@ -531,32 +525,32 @@ public Mat4(float a00, float a01, float a02, float a03, //////////////////////////////////////////////////////////// public Mat4(Transform transform) { - fixed (float* m = array) + fixed (float* m = _array) { // swapping to column-major (OpenGL) from row-major (SFML) order // in addition, filling in the blanks (from expanding to a mat4) with values from // an identity matrix - m[0] = transform.m00; - m[4] = transform.m01; + m[0] = transform.M00; + m[4] = transform.M01; m[8] = 0; - m[12] = transform.m02; - m[1] = transform.m10; - m[5] = transform.m11; + m[12] = transform.M02; + m[1] = transform.M10; + m[5] = transform.M11; m[9] = 0; - m[13] = transform.m12; + m[13] = transform.M12; m[2] = 0; m[6] = 0; m[10] = 1; m[14] = 0; - m[3] = transform.m20; - m[7] = transform.m21; + m[3] = transform.M20; + m[7] = transform.M21; m[11] = 0; - m[15] = transform.m22; + m[15] = transform.M22; } } // column major! - private fixed float array[4 * 4]; + private fixed float _array[4 * 4]; } #endregion } diff --git a/src/SFML.Graphics/Drawable.cs b/src/SFML.Graphics/IDrawable.cs similarity index 89% rename from src/SFML.Graphics/Drawable.cs rename to src/SFML.Graphics/IDrawable.cs index 54911b87..dcb86c25 100644 --- a/src/SFML.Graphics/Drawable.cs +++ b/src/SFML.Graphics/IDrawable.cs @@ -5,7 +5,7 @@ namespace SFML.Graphics /// Interface for every object that can be drawn to a render window /// //////////////////////////////////////////////////////////// - public interface Drawable + public interface IDrawable { //////////////////////////////////////////////////////////// /// @@ -17,6 +17,6 @@ public interface Drawable /// Render target to draw to /// Current render states //////////////////////////////////////////////////////////// - void Draw(RenderTarget target, RenderStates states); + void Draw(IRenderTarget target, RenderStates states); } } diff --git a/src/SFML.Graphics/RenderTarget.cs b/src/SFML.Graphics/IRenderTarget.cs similarity index 98% rename from src/SFML.Graphics/RenderTarget.cs rename to src/SFML.Graphics/IRenderTarget.cs index 9aa19ef5..cebdcd3c 100644 --- a/src/SFML.Graphics/RenderTarget.cs +++ b/src/SFML.Graphics/IRenderTarget.cs @@ -9,7 +9,7 @@ namespace SFML.Graphics /// or instead. /// //////////////////////////////////////////////////////////// - public interface RenderTarget + public interface IRenderTarget { //////////////////////////////////////////////////////////// /// @@ -161,7 +161,7 @@ public interface RenderTarget /// /// Object to draw //////////////////////////////////////////////////////////// - void Draw(Drawable drawable); + void Draw(IDrawable drawable); //////////////////////////////////////////////////////////// /// @@ -170,7 +170,7 @@ public interface RenderTarget /// Object to draw /// Render states to use for drawing //////////////////////////////////////////////////////////// - void Draw(Drawable drawable, RenderStates states); + void Draw(IDrawable drawable, RenderStates states); //////////////////////////////////////////////////////////// /// diff --git a/src/SFML.Graphics/Image.cs b/src/SFML.Graphics/Image.cs index 17347c12..1c55176f 100644 --- a/src/SFML.Graphics/Image.cs +++ b/src/SFML.Graphics/Image.cs @@ -87,7 +87,7 @@ public Image(Stream stream) : public Image(byte[] bytes) : base(IntPtr.Zero) { - GCHandle pin = GCHandle.Alloc(bytes, GCHandleType.Pinned); + var pin = GCHandle.Alloc(bytes, GCHandleType.Pinned); try { CPointer = sfImage_createFromMemory(pin.AddrOfPinnedObject(), (UIntPtr)bytes.Length); @@ -112,14 +112,14 @@ public Image(byte[] bytes) : public Image(Color[,] pixels) : base(IntPtr.Zero) { - uint Width = (uint)pixels.GetLength(0); - uint Height = (uint)pixels.GetLength(1); + var width = (uint)pixels.GetLength(0); + var height = (uint)pixels.GetLength(1); // Transpose the array (.Net gives dimensions in reverse order of what SFML expects) - Color[,] transposed = new Color[Height, Width]; - for (int x = 0; x < Width; ++x) + var transposed = new Color[height, width]; + for (var x = 0; x < width; ++x) { - for (int y = 0; y < Height; ++y) + for (var y = 0; y < height; ++y) { transposed[y, x] = pixels[x, y]; } @@ -127,9 +127,9 @@ public Image(Color[,] pixels) : unsafe { - fixed (Color* PixelsPtr = transposed) + fixed (Color* pixelsPtr = transposed) { - CPointer = sfImage_createFromPixels(Width, Height, (byte*)PixelsPtr); + CPointer = sfImage_createFromPixels(width, height, (byte*)pixelsPtr); } } @@ -153,9 +153,9 @@ public Image(uint width, uint height, byte[] pixels) : { unsafe { - fixed (byte* PixelsPtr = pixels) + fixed (byte* pixelsPtr = pixels) { - CPointer = sfImage_createFromPixels(width, height, PixelsPtr); + CPointer = sfImage_createFromPixels(width, height, pixelsPtr); } } @@ -200,7 +200,7 @@ public Image(Image copy) : //////////////////////////////////////////////////////////// public bool SaveToMemory(out byte[] output, string format) { - using (SFML.System.Buffer buffer = new SFML.System.Buffer()) + using (var buffer = new SFML.System.Buffer()) { var success = sfImage_saveToMemory(CPointer, buffer.CPointer, format); @@ -215,10 +215,7 @@ public bool SaveToMemory(out byte[] output, string format) /// /// Color to become transparent //////////////////////////////////////////////////////////// - public void CreateMaskFromColor(Color color) - { - CreateMaskFromColor(color, 0); - } + public void CreateMaskFromColor(Color color) => CreateMaskFromColor(color, 0); //////////////////////////////////////////////////////////// /// @@ -227,10 +224,7 @@ public void CreateMaskFromColor(Color color) /// Color to become transparent /// Alpha value to use for transparent pixels //////////////////////////////////////////////////////////// - public void CreateMaskFromColor(Color color, byte alpha) - { - sfImage_createMaskFromColor(CPointer, color, alpha); - } + public void CreateMaskFromColor(Color color, byte alpha) => sfImage_createMaskFromColor(CPointer, color, alpha); //////////////////////////////////////////////////////////// /// @@ -242,10 +236,7 @@ public void CreateMaskFromColor(Color color, byte alpha) /// X coordinate of the destination position /// Y coordinate of the destination position //////////////////////////////////////////////////////////// - public void Copy(Image source, uint destX, uint destY) - { - Copy(source, destX, destY, new IntRect(0, 0, 0, 0)); - } + public void Copy(Image source, uint destX, uint destY) => Copy(source, destX, destY, new IntRect(0, 0, 0, 0)); //////////////////////////////////////////////////////////// /// @@ -258,10 +249,7 @@ public void Copy(Image source, uint destX, uint destY) /// Y coordinate of the destination position /// Sub-rectangle of the source image to copy //////////////////////////////////////////////////////////// - public void Copy(Image source, uint destX, uint destY, IntRect sourceRect) - { - Copy(source, destX, destY, sourceRect, false); - } + public void Copy(Image source, uint destX, uint destY, IntRect sourceRect) => Copy(source, destX, destY, sourceRect, false); //////////////////////////////////////////////////////////// /// @@ -275,10 +263,7 @@ public void Copy(Image source, uint destX, uint destY, IntRect sourceRect) /// Sub-rectangle of the source image to copy /// Should the copy take in account the source transparency? //////////////////////////////////////////////////////////// - public void Copy(Image source, uint destX, uint destY, IntRect sourceRect, bool applyAlpha) - { - sfImage_copyImage(CPointer, source.CPointer, destX, destY, sourceRect, applyAlpha); - } + public void Copy(Image source, uint destX, uint destY, IntRect sourceRect, bool applyAlpha) => sfImage_copyImage(CPointer, source.CPointer, destX, destY, sourceRect, applyAlpha); //////////////////////////////////////////////////////////// /// @@ -298,10 +283,7 @@ public void Copy(Image source, uint destX, uint destY, IntRect sourceRect, bool /// Y coordinate of pixel in the image /// New color for pixel (x, y) //////////////////////////////////////////////////////////// - public void SetPixel(uint x, uint y, Color color) - { - sfImage_setPixel(CPointer, x, y, color); - } + public void SetPixel(uint x, uint y, Color color) => sfImage_setPixel(CPointer, x, y, color); //////////////////////////////////////////////////////////// /// @@ -314,10 +296,10 @@ public byte[] Pixels { get { - Vector2u size = Size; - byte[] PixelsPtr = new byte[size.X * size.Y * 4]; - Marshal.Copy(sfImage_getPixelsPtr(CPointer), PixelsPtr, 0, PixelsPtr.Length); - return PixelsPtr; + var size = Size; + var pixelsPtr = new byte[size.X * size.Y * 4]; + Marshal.Copy(sfImage_getPixelsPtr(CPointer), pixelsPtr, 0, pixelsPtr.Length); + return pixelsPtr; } } @@ -333,20 +315,14 @@ public byte[] Pixels /// Flip the image horizontally /// //////////////////////////////////////////////////////////// - public void FlipHorizontally() - { - sfImage_flipHorizontally(CPointer); - } + public void FlipHorizontally() => sfImage_flipHorizontally(CPointer); //////////////////////////////////////////////////////////// /// /// Flip the image vertically /// //////////////////////////////////////////////////////////// - public void FlipVertically() - { - sfImage_flipVertically(CPointer); - } + public void FlipVertically() => sfImage_flipVertically(CPointer); //////////////////////////////////////////////////////////// /// @@ -357,7 +333,9 @@ public void FlipVertically() public override string ToString() { if (IsInvalid) + { return MakeDisposedObjectString(); + } return $"[Image] Size({Size})"; } @@ -376,62 +354,59 @@ internal Image(IntPtr cPointer) : base(cPointer) { } /// /// Is the GC disposing the object, or is it an explicit call ? //////////////////////////////////////////////////////////// - protected override void Destroy(bool disposing) - { - sfImage_destroy(CPointer); - } + protected override void Destroy(bool disposing) => sfImage_destroy(CPointer); #region Imports - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfImage_createFromColor(uint Width, uint Height, Color Col); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfImage_createFromColor(uint width, uint height, Color col); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private unsafe static extern IntPtr sfImage_createFromPixels(uint Width, uint Height, byte* Pixels); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern unsafe IntPtr sfImage_createFromPixels(uint width, uint height, byte* pixels); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfImage_createFromFile(string Filename); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfImage_createFromFile(string filename); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private unsafe static extern IntPtr sfImage_createFromStream(IntPtr stream); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern unsafe IntPtr sfImage_createFromStream(IntPtr stream); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private unsafe static extern IntPtr sfImage_createFromMemory(IntPtr data, UIntPtr size); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern unsafe IntPtr sfImage_createFromMemory(IntPtr data, UIntPtr size); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfImage_copy(IntPtr Image); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfImage_copy(IntPtr image); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfImage_destroy(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfImage_destroy(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfImage_saveToFile(IntPtr CPointer, string Filename); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfImage_saveToFile(IntPtr cPointer, string filename); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfImage_saveToMemory(IntPtr CPointer, IntPtr bufferOutput, string format); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfImage_saveToMemory(IntPtr cPointer, IntPtr bufferOutput, string format); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfImage_createMaskFromColor(IntPtr CPointer, Color Col, byte Alpha); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfImage_createMaskFromColor(IntPtr cPointer, Color col, byte alpha); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfImage_copyImage(IntPtr CPointer, IntPtr Source, uint DestX, uint DestY, IntRect SourceRect, bool applyAlpha); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfImage_copyImage(IntPtr cPointer, IntPtr source, uint destX, uint destY, IntRect sourceRect, bool applyAlpha); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfImage_setPixel(IntPtr CPointer, uint X, uint Y, Color Col); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfImage_setPixel(IntPtr cPointer, uint x, uint y, Color col); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Color sfImage_getPixel(IntPtr CPointer, uint X, uint Y); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Color sfImage_getPixel(IntPtr cPointer, uint x, uint y); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfImage_getPixelsPtr(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfImage_getPixelsPtr(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Vector2u sfImage_getSize(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Vector2u sfImage_getSize(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfImage_flipHorizontally(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfImage_flipHorizontally(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfImage_flipVertically(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfImage_flipVertically(IntPtr cPointer); #endregion } } diff --git a/src/SFML.Graphics/Properties/AssemblyInfo.cs b/src/SFML.Graphics/Properties/AssemblyInfo.cs index dd2aef51..226a9d96 100644 --- a/src/SFML.Graphics/Properties/AssemblyInfo.cs +++ b/src/SFML.Graphics/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ -using System.Reflection; -using System.Runtime.InteropServices; +using System.Runtime.InteropServices; // [assembly: AssemblyTitle("sfml-graphics")] //[assembly: AssemblyDescription("Graphics module of the SFML library")] diff --git a/src/SFML.Graphics/Rect.cs b/src/SFML.Graphics/Rect.cs index d90ccb7d..9cfe5a01 100644 --- a/src/SFML.Graphics/Rect.cs +++ b/src/SFML.Graphics/Rect.cs @@ -52,12 +52,12 @@ public IntRect(Vector2i position, Vector2i size) //////////////////////////////////////////////////////////// public bool Contains(int x, int y) { - int minX = Math.Min(Left, Left + Width); - int maxX = Math.Max(Left, Left + Width); - int minY = Math.Min(Top, Top + Height); - int maxY = Math.Max(Top, Top + Height); + var minX = Math.Min(Left, Left + Width); + var maxX = Math.Max(Left, Left + Width); + var minY = Math.Min(Top, Top + Height); + var maxY = Math.Max(Top, Top + Height); - return ( x >= minX ) && ( x < maxX ) && ( y >= minY ) && ( y < maxY ); + return (x >= minX) && (x < maxX) && (y >= minY) && (y < maxY); } @@ -68,10 +68,7 @@ public bool Contains(int x, int y) /// Vector2 position of the point to test /// True if the point is inside //////////////////////////////////////////////////////////// - public bool Contains(Vector2i point) - { - return Contains(point.X, point.Y); - } + public bool Contains(Vector2i point) => Contains(point.X, point.Y); //////////////////////////////////////////////////////////// @@ -81,10 +78,7 @@ public bool Contains(Vector2i point) /// Vector2 position of the point to test /// True if the point is inside //////////////////////////////////////////////////////////// - public bool Contains(Vector2u point) - { - return Contains((Vector2i)point); - } + public bool Contains(Vector2u point) => Contains((Vector2i)point); //////////////////////////////////////////////////////////// @@ -94,10 +88,7 @@ public bool Contains(Vector2u point) /// Vector2 position of the point to test /// True if the point is inside //////////////////////////////////////////////////////////// - public bool Contains(Vector2f point) - { - return Contains((Vector2i)point); - } + public bool Contains(Vector2f point) => Contains((Vector2i)point); //////////////////////////////////////////////////////////// /// @@ -106,11 +97,7 @@ public bool Contains(Vector2f point) /// Rectangle to test /// True if rectangles overlap //////////////////////////////////////////////////////////// - public bool Intersects(IntRect rect) - { - IntRect overlap; - return Intersects(rect, out overlap); - } + public bool Intersects(IntRect rect) => Intersects(rect, out _); //////////////////////////////////////////////////////////// /// @@ -125,25 +112,25 @@ public bool Intersects(IntRect rect, out IntRect overlap) // Rectangles with negative dimensions are allowed, so we must handle them correctly // Compute the min and max of the first rectangle on both axes - int r1MinX = Math.Min(Left, Left + Width); - int r1MaxX = Math.Max(Left, Left + Width); - int r1MinY = Math.Min(Top, Top + Height); - int r1MaxY = Math.Max(Top, Top + Height); + var r1MinX = Math.Min(Left, Left + Width); + var r1MaxX = Math.Max(Left, Left + Width); + var r1MinY = Math.Min(Top, Top + Height); + var r1MaxY = Math.Max(Top, Top + Height); // Compute the min and max of the second rectangle on both axes - int r2MinX = Math.Min(rect.Left, rect.Left + rect.Width); - int r2MaxX = Math.Max(rect.Left, rect.Left + rect.Width); - int r2MinY = Math.Min(rect.Top, rect.Top + rect.Height); - int r2MaxY = Math.Max(rect.Top, rect.Top + rect.Height); + var r2MinX = Math.Min(rect.Left, rect.Left + rect.Width); + var r2MaxX = Math.Max(rect.Left, rect.Left + rect.Width); + var r2MinY = Math.Min(rect.Top, rect.Top + rect.Height); + var r2MaxY = Math.Max(rect.Top, rect.Top + rect.Height); // Compute the intersection boundaries - int interLeft = Math.Max(r1MinX, r2MinX); - int interTop = Math.Max(r1MinY, r2MinY); - int interRight = Math.Min(r1MaxX, r2MaxX); - int interBottom = Math.Min(r1MaxY, r2MaxY); + var interLeft = Math.Max(r1MinX, r2MinX); + var interTop = Math.Max(r1MinY, r2MinY); + var interRight = Math.Min(r1MaxX, r2MaxX); + var interBottom = Math.Min(r1MaxY, r2MaxY); // If the intersection is valid (positive non zero area), then there is an intersection - if (( interLeft < interRight ) && ( interTop < interBottom )) + if ((interLeft < interRight) && (interTop < interBottom)) { overlap.Left = interLeft; overlap.Top = interTop; @@ -207,7 +194,7 @@ public void Deconstruct(out int left, out int top, out int width, out int height /// Object to check /// Object and rectangle are equal //////////////////////////////////////////////////////////// - public override bool Equals(object obj) => ( obj is IntRect ) && Equals((IntRect)obj); + public override bool Equals(object obj) => (obj is IntRect) && Equals((IntRect)obj); /////////////////////////////////////////////////////////// /// @@ -216,13 +203,10 @@ public void Deconstruct(out int left, out int top, out int width, out int height /// Rectangle to check /// Rectangles are equal //////////////////////////////////////////////////////////// - public bool Equals(IntRect other) - { - return ( Left == other.Left ) && - ( Top == other.Top ) && - ( Width == other.Width ) && - ( Height == other.Height ); - } + public bool Equals(IntRect other) => (Left == other.Left) && + (Top == other.Top) && + (Width == other.Width) && + (Height == other.Height); //////////////////////////////////////////////////////////// /// @@ -230,13 +214,10 @@ public bool Equals(IntRect other) /// /// Integer description of the object //////////////////////////////////////////////////////////// - public override int GetHashCode() - { - return unchecked((int)( (uint)Left ^ - ( ( (uint)Top << 13 ) | ( (uint)Top >> 19 ) ) ^ - ( ( (uint)Width << 26 ) | ( (uint)Width >> 6 ) ) ^ - ( ( (uint)Height << 7 ) | ( (uint)Height >> 25 ) ) )); - } + public override int GetHashCode() => unchecked((int)((uint)Left ^ + (((uint)Top << 13) | ((uint)Top >> 19)) ^ + (((uint)Width << 26) | ((uint)Width >> 6)) ^ + (((uint)Height << 7) | ((uint)Height >> 25)))); //////////////////////////////////////////////////////////// /// @@ -246,10 +227,7 @@ public override int GetHashCode() /// Second rect /// r1 == r2 //////////////////////////////////////////////////////////// - public static bool operator ==(IntRect r1, IntRect r2) - { - return r1.Equals(r2); - } + public static bool operator ==(IntRect r1, IntRect r2) => r1.Equals(r2); //////////////////////////////////////////////////////////// /// @@ -274,13 +252,10 @@ public override int GetHashCode() /// Rectangle being casted /// Casting result //////////////////////////////////////////////////////////// - public static explicit operator FloatRect(IntRect r) - { - return new FloatRect(r.Left, + public static explicit operator FloatRect(IntRect r) => new FloatRect(r.Left, r.Top, r.Width, r.Height); - } /// Left coordinate of the rectangle public int Left; @@ -343,12 +318,12 @@ public FloatRect(Vector2f position, Vector2f size) //////////////////////////////////////////////////////////// public bool Contains(float x, float y) { - float minX = Math.Min(Left, Left + Width); - float maxX = Math.Max(Left, Left + Width); - float minY = Math.Min(Top, Top + Height); - float maxY = Math.Max(Top, Top + Height); + var minX = Math.Min(Left, Left + Width); + var maxX = Math.Max(Left, Left + Width); + var minY = Math.Min(Top, Top + Height); + var maxY = Math.Max(Top, Top + Height); - return ( x >= minX ) && ( x < maxX ) && ( y >= minY ) && ( y < maxY ); + return (x >= minX) && (x < maxX) && (y >= minY) && (y < maxY); } //////////////////////////////////////////////////////////// @@ -358,10 +333,7 @@ public bool Contains(float x, float y) /// Vector2 position of the point to test /// True if the point is inside //////////////////////////////////////////////////////////// - public bool Contains(Vector2f point) - { - return Contains(point.X, point.Y); - } + public bool Contains(Vector2f point) => Contains(point.X, point.Y); //////////////////////////////////////////////////////////// /// @@ -370,10 +342,7 @@ public bool Contains(Vector2f point) /// Vector2 position of the point to test /// True if the point is inside //////////////////////////////////////////////////////////// - public bool Contains(Vector2i point) - { - return Contains((Vector2f)point); - } + public bool Contains(Vector2i point) => Contains((Vector2f)point); //////////////////////////////////////////////////////////// @@ -383,10 +352,7 @@ public bool Contains(Vector2i point) /// Vector2 position of the point to test /// True if the point is inside //////////////////////////////////////////////////////////// - public bool Contains(Vector2u point) - { - return Contains((Vector2f)point); - } + public bool Contains(Vector2u point) => Contains((Vector2f)point); //////////////////////////////////////////////////////////// /// @@ -395,11 +361,7 @@ public bool Contains(Vector2u point) /// Rectangle to test /// True if rectangles overlap //////////////////////////////////////////////////////////// - public bool Intersects(FloatRect rect) - { - FloatRect overlap; - return Intersects(rect, out overlap); - } + public bool Intersects(FloatRect rect) => Intersects(rect, out _); //////////////////////////////////////////////////////////// /// @@ -414,25 +376,25 @@ public bool Intersects(FloatRect rect, out FloatRect overlap) // Rectangles with negative dimensions are allowed, so we must handle them correctly // Compute the min and max of the first rectangle on both axes - float r1MinX = Math.Min(Left, Left + Width); - float r1MaxX = Math.Max(Left, Left + Width); - float r1MinY = Math.Min(Top, Top + Height); - float r1MaxY = Math.Max(Top, Top + Height); + var r1MinX = Math.Min(Left, Left + Width); + var r1MaxX = Math.Max(Left, Left + Width); + var r1MinY = Math.Min(Top, Top + Height); + var r1MaxY = Math.Max(Top, Top + Height); // Compute the min and max of the second rectangle on both axes - float r2MinX = Math.Min(rect.Left, rect.Left + rect.Width); - float r2MaxX = Math.Max(rect.Left, rect.Left + rect.Width); - float r2MinY = Math.Min(rect.Top, rect.Top + rect.Height); - float r2MaxY = Math.Max(rect.Top, rect.Top + rect.Height); + var r2MinX = Math.Min(rect.Left, rect.Left + rect.Width); + var r2MaxX = Math.Max(rect.Left, rect.Left + rect.Width); + var r2MinY = Math.Min(rect.Top, rect.Top + rect.Height); + var r2MaxY = Math.Max(rect.Top, rect.Top + rect.Height); // Compute the intersection boundaries - float interLeft = Math.Max(r1MinX, r2MinX); - float interTop = Math.Max(r1MinY, r2MinY); - float interRight = Math.Min(r1MaxX, r2MaxX); - float interBottom = Math.Min(r1MaxY, r2MaxY); + var interLeft = Math.Max(r1MinX, r2MinX); + var interTop = Math.Max(r1MinY, r2MinY); + var interRight = Math.Min(r1MaxX, r2MaxX); + var interBottom = Math.Min(r1MaxY, r2MaxY); // If the intersection is valid (positive non zero area), then there is an intersection - if (( interLeft < interRight ) && ( interTop < interBottom )) + if ((interLeft < interRight) && (interTop < interBottom)) { overlap.Left = interLeft; overlap.Top = interTop; @@ -487,14 +449,11 @@ public void Deconstruct(out float left, out float top, out float width, out floa /// /// String description of the object //////////////////////////////////////////////////////////// - public override string ToString() - { - return "[FloatRect]" + + public override string ToString() => "[FloatRect]" + " Left(" + Left + ")" + " Top(" + Top + ")" + " Width(" + Width + ")" + " Height(" + Height + ")"; - } //////////////////////////////////////////////////////////// /// @@ -503,10 +462,7 @@ public override string ToString() /// Object to check /// Object and rectangle are equal //////////////////////////////////////////////////////////// - public override bool Equals(object obj) - { - return ( obj is FloatRect ) && Equals((FloatRect)obj); - } + public override bool Equals(object obj) => (obj is FloatRect) && Equals((FloatRect)obj); /////////////////////////////////////////////////////////// /// @@ -515,13 +471,10 @@ public override bool Equals(object obj) /// Rectangle to check /// Rectangles are equal //////////////////////////////////////////////////////////// - public bool Equals(FloatRect other) - { - return ( Left == other.Left ) && - ( Top == other.Top ) && - ( Width == other.Width ) && - ( Height == other.Height ); - } + public bool Equals(FloatRect other) => (Left == other.Left) && + (Top == other.Top) && + (Width == other.Width) && + (Height == other.Height); //////////////////////////////////////////////////////////// /// @@ -529,13 +482,10 @@ public bool Equals(FloatRect other) /// /// Integer description of the object //////////////////////////////////////////////////////////// - public override int GetHashCode() - { - return unchecked((int)( (uint)Left ^ - ( ( (uint)Top << 13 ) | ( (uint)Top >> 19 ) ) ^ - ( ( (uint)Width << 26 ) | ( (uint)Width >> 6 ) ) ^ - ( ( (uint)Height << 7 ) | ( (uint)Height >> 25 ) ) )); - } + public override int GetHashCode() => unchecked((int)((uint)Left ^ + (((uint)Top << 13) | ((uint)Top >> 19)) ^ + (((uint)Width << 26) | ((uint)Width >> 6)) ^ + (((uint)Height << 7) | ((uint)Height >> 25)))); //////////////////////////////////////////////////////////// /// @@ -545,10 +495,7 @@ public override int GetHashCode() /// Second rect /// r1 == r2 //////////////////////////////////////////////////////////// - public static bool operator ==(FloatRect r1, FloatRect r2) - { - return r1.Equals(r2); - } + public static bool operator ==(FloatRect r1, FloatRect r2) => r1.Equals(r2); //////////////////////////////////////////////////////////// /// @@ -558,10 +505,7 @@ public override int GetHashCode() /// Second rect /// r1 != r2 //////////////////////////////////////////////////////////// - public static bool operator !=(FloatRect r1, FloatRect r2) - { - return !r1.Equals(r2); - } + public static bool operator !=(FloatRect r1, FloatRect r2) => !r1.Equals(r2); /// /// Converts a tuple of floats to a FloatRect @@ -576,13 +520,10 @@ public override int GetHashCode() /// Rectangle being casted /// Casting result //////////////////////////////////////////////////////////// - public static explicit operator IntRect(FloatRect r) - { - return new IntRect((int)r.Left, + public static explicit operator IntRect(FloatRect r) => new IntRect((int)r.Left, (int)r.Top, (int)r.Width, (int)r.Height); - } /// Left coordinate of the rectangle public float Left; diff --git a/src/SFML.Graphics/RectangleShape.cs b/src/SFML.Graphics/RectangleShape.cs index 789e885f..d5dae6e5 100644 --- a/src/SFML.Graphics/RectangleShape.cs +++ b/src/SFML.Graphics/RectangleShape.cs @@ -25,10 +25,7 @@ public RectangleShape() : /// /// Size of the shape //////////////////////////////////////////////////////////// - public RectangleShape(Vector2f size) - { - Size = size; - } + public RectangleShape(Vector2f size) => Size = size; //////////////////////////////////////////////////////////// /// @@ -37,10 +34,7 @@ public RectangleShape(Vector2f size) /// Shape to copy //////////////////////////////////////////////////////////// public RectangleShape(RectangleShape copy) : - base(copy) - { - Size = copy.Size; - } + base(copy) => Size = copy.Size; //////////////////////////////////////////////////////////// /// @@ -49,8 +43,8 @@ public RectangleShape(RectangleShape copy) : //////////////////////////////////////////////////////////// public Vector2f Size { - get { return mySize; } - set { mySize = value; Update(); } + get => _size; + set { _size = value; Update(); } } //////////////////////////////////////////////////////////// @@ -82,14 +76,14 @@ public override Vector2f GetPoint(uint index) case 0: return new Vector2f(0, 0); case 1: - return new Vector2f(mySize.X, 0); + return new Vector2f(_size.X, 0); case 2: - return new Vector2f(mySize.X, mySize.Y); + return new Vector2f(_size.X, _size.Y); case 3: - return new Vector2f(0, mySize.Y); + return new Vector2f(0, _size.Y); } } - private Vector2f mySize; + private Vector2f _size; } } diff --git a/src/SFML.Graphics/RenderStates.cs b/src/SFML.Graphics/RenderStates.cs index 2796d608..0531395d 100644 --- a/src/SFML.Graphics/RenderStates.cs +++ b/src/SFML.Graphics/RenderStates.cs @@ -88,10 +88,7 @@ public RenderStates(RenderStates copy) //////////////////////////////////////////////////////////// /// Special instance holding the default render states //////////////////////////////////////////////////////////// - public static RenderStates Default - { - get { return new RenderStates(BlendMode.Alpha, Transform.Identity, null, null); } - } + public static RenderStates Default => new RenderStates(BlendMode.Alpha, Transform.Identity, null, null); /// Blending mode public BlendMode BlendMode; @@ -108,11 +105,13 @@ public static RenderStates Default // Return a marshalled version of the instance, that can directly be passed to the C API internal MarshalData Marshal() { - MarshalData data = new MarshalData(); - data.blendMode = BlendMode; - data.transform = Transform; - data.texture = Texture != null ? Texture.CPointer : IntPtr.Zero; - data.shader = Shader != null ? Shader.CPointer : IntPtr.Zero; + var data = new MarshalData + { + BlendMode = BlendMode, + Transform = Transform, + Texture = Texture != null ? Texture.CPointer : IntPtr.Zero, + Shader = Shader != null ? Shader.CPointer : IntPtr.Zero + }; return data; } @@ -120,10 +119,10 @@ internal MarshalData Marshal() [StructLayout(LayoutKind.Sequential)] internal struct MarshalData { - public BlendMode blendMode; - public Transform transform; - public IntPtr texture; - public IntPtr shader; + public BlendMode BlendMode; + public Transform Transform; + public IntPtr Texture; + public IntPtr Shader; } } } diff --git a/src/SFML.Graphics/RenderTexture.cs b/src/SFML.Graphics/RenderTexture.cs index 27b3b259..98dd0500 100644 --- a/src/SFML.Graphics/RenderTexture.cs +++ b/src/SFML.Graphics/RenderTexture.cs @@ -11,7 +11,7 @@ namespace SFML.Graphics /// Target for off-screen 2D rendering into an texture /// //////////////////////////////////////////////////////////// - public class RenderTexture : ObjectBase, RenderTarget + public class RenderTexture : ObjectBase, IRenderTarget { //////////////////////////////////////////////////////////// /// @@ -38,10 +38,10 @@ public RenderTexture(uint width, uint height) : public RenderTexture(uint width, uint height, bool depthBuffer) : base(sfRenderTexture_create(width, height, depthBuffer)) { - myDefaultView = new View(sfRenderTexture_getDefaultView(CPointer)); - myTexture = new Texture(sfRenderTexture_getTexture(CPointer)); - GC.SuppressFinalize(myDefaultView); - GC.SuppressFinalize(myTexture); + _defaultView = new View(sfRenderTexture_getDefaultView(CPointer)); + Texture = new Texture(sfRenderTexture_getTexture(CPointer)); + GC.SuppressFinalize(_defaultView); + GC.SuppressFinalize(Texture); } //////////////////////////////////////////////////////////// @@ -56,10 +56,10 @@ public RenderTexture(uint width, uint height, bool depthBuffer) : public RenderTexture(uint width, uint height, ContextSettings contextSettings) : base(sfRenderTexture_createWithSettings(width, height, ref contextSettings)) { - myDefaultView = new View(sfRenderTexture_getDefaultView(CPointer)); - myTexture = new Texture(sfRenderTexture_getTexture(CPointer)); - GC.SuppressFinalize(myDefaultView); - GC.SuppressFinalize(myTexture); + _defaultView = new View(sfRenderTexture_getDefaultView(CPointer)); + Texture = new Texture(sfRenderTexture_getTexture(CPointer)); + GC.SuppressFinalize(_defaultView); + GC.SuppressFinalize(Texture); } //////////////////////////////////////////////////////////// @@ -70,10 +70,7 @@ public RenderTexture(uint width, uint height, ContextSettings contextSettings) : /// True to activate, false to deactivate (true by default) /// True if operation was successful, false otherwise //////////////////////////////////////////////////////////// - public bool SetActive(bool active) - { - return sfRenderTexture_setActive(CPointer, active); - } + public bool SetActive(bool active) => sfRenderTexture_setActive(CPointer, active); //////////////////////////////////////////////////////////// /// @@ -87,8 +84,8 @@ public bool SetActive(bool active) //////////////////////////////////////////////////////////// public bool Repeated { - get { return sfRenderTexture_isRepeated(CPointer); } - set { sfRenderTexture_setRepeated(CPointer, value); } + get => sfRenderTexture_isRepeated(CPointer); + set => sfRenderTexture_setRepeated(CPointer, value); } //////////////////////////////////////////////////////////// @@ -96,30 +93,21 @@ public bool Repeated /// Size of the rendering region of the render texture /// //////////////////////////////////////////////////////////// - public Vector2u Size - { - get { return sfRenderTexture_getSize(CPointer); } - } + public Vector2u Size => sfRenderTexture_getSize(CPointer); //////////////////////////////////////////////////////////// /// /// Tell if the render texture will use sRGB encoding when drawing on it /// //////////////////////////////////////////////////////////// - public bool IsSrgb - { - get { return sfRenderTexture_isSrgb(CPointer); } - } + public bool IsSrgb => sfRenderTexture_isSrgb(CPointer); //////////////////////////////////////////////////////////// /// /// Default view of the render texture /// //////////////////////////////////////////////////////////// - public View DefaultView - { - get { return new View(myDefaultView); } - } + public View DefaultView => new View(_defaultView); //////////////////////////////////////////////////////////// /// @@ -127,10 +115,7 @@ public View DefaultView /// /// The current view //////////////////////////////////////////////////////////// - public View GetView() - { - return new View(sfRenderTexture_getView(CPointer)); - } + public View GetView() => new View(sfRenderTexture_getView(CPointer)); //////////////////////////////////////////////////////////// /// @@ -138,10 +123,7 @@ public View GetView() /// /// New view //////////////////////////////////////////////////////////// - public void SetView(View view) - { - sfRenderTexture_setView(CPointer, view.CPointer); - } + public void SetView(View view) => sfRenderTexture_setView(CPointer, view.CPointer); //////////////////////////////////////////////////////////// /// @@ -150,10 +132,7 @@ public void SetView(View view) /// Target view /// Viewport rectangle, expressed in pixels in the current target //////////////////////////////////////////////////////////// - public IntRect GetViewport(View view) - { - return sfRenderTexture_getViewport(CPointer, view.CPointer); - } + public IntRect GetViewport(View view) => sfRenderTexture_getViewport(CPointer, view.CPointer); //////////////////////////////////////////////////////////// /// @@ -168,10 +147,7 @@ public IntRect GetViewport(View view) /// Pixel to convert /// The converted point, in "world" coordinates //////////////////////////////////////////////////////////// - public Vector2f MapPixelToCoords(Vector2i point) - { - return MapPixelToCoords(point, GetView()); - } + public Vector2f MapPixelToCoords(Vector2i point) => MapPixelToCoords(point, GetView()); //////////////////////////////////////////////////////////// /// @@ -199,10 +175,7 @@ public Vector2f MapPixelToCoords(Vector2i point) /// The view to use for converting the point /// The converted point, in "world" coordinates //////////////////////////////////////////////////////////// - public Vector2f MapPixelToCoords(Vector2i point, View view) - { - return sfRenderTexture_mapPixelToCoords(CPointer, point, view != null ? view.CPointer : IntPtr.Zero); - } + public Vector2f MapPixelToCoords(Vector2i point, View view) => sfRenderTexture_mapPixelToCoords(CPointer, point, view != null ? view.CPointer : IntPtr.Zero); //////////////////////////////////////////////////////////// /// @@ -217,10 +190,7 @@ public Vector2f MapPixelToCoords(Vector2i point, View view) /// Point to convert /// The converted point, in target coordinates (pixels) //////////////////////////////////////////////////////////// - public Vector2i MapCoordsToPixel(Vector2f point) - { - return MapCoordsToPixel(point, GetView()); - } + public Vector2i MapCoordsToPixel(Vector2f point) => MapCoordsToPixel(point, GetView()); //////////////////////////////////////////////////////////// /// @@ -244,10 +214,7 @@ public Vector2i MapCoordsToPixel(Vector2f point) /// The view to use for converting the point /// The converted point, in target coordinates (pixels) //////////////////////////////////////////////////////////// - public Vector2i MapCoordsToPixel(Vector2f point, View view) - { - return sfRenderTexture_mapCoordsToPixel(CPointer, point, view != null ? view.CPointer : IntPtr.Zero); - } + public Vector2i MapCoordsToPixel(Vector2f point, View view) => sfRenderTexture_mapCoordsToPixel(CPointer, point, view != null ? view.CPointer : IntPtr.Zero); //////////////////////////////////////////////////////////// /// @@ -266,20 +233,14 @@ public Vector2i MapCoordsToPixel(Vector2f point, View view) /// /// True if mipmap generation was successful, false if unsuccessful //////////////////////////////////////////////////////////// - public bool GenerateMipmap() - { - return sfRenderTexture_generateMipmap(CPointer); - } + public bool GenerateMipmap() => sfRenderTexture_generateMipmap(CPointer); //////////////////////////////////////////////////////////// /// /// Clear the entire render texture with black color /// //////////////////////////////////////////////////////////// - public void Clear() - { - sfRenderTexture_clear(CPointer, Color.Black); - } + public void Clear() => sfRenderTexture_clear(CPointer, Color.Black); //////////////////////////////////////////////////////////// /// @@ -287,37 +248,28 @@ public void Clear() /// /// Color to use to clear the texture //////////////////////////////////////////////////////////// - public void Clear(Color color) - { - sfRenderTexture_clear(CPointer, color); - } + public void Clear(Color color) => sfRenderTexture_clear(CPointer, color); //////////////////////////////////////////////////////////// /// /// Update the contents of the target texture /// //////////////////////////////////////////////////////////// - public void Display() - { - sfRenderTexture_display(CPointer); - } + public void Display() => sfRenderTexture_display(CPointer); //////////////////////////////////////////////////////////// /// /// Target texture of the render texture /// //////////////////////////////////////////////////////////// - public Texture Texture - { - get { return myTexture; } - } + public Texture Texture { get; } //////////////////////////////////////////////////////////// /// /// The maximum anti-aliasing level supported by the system /// //////////////////////////////////////////////////////////// - static public uint MaximumAntialiasingLevel => sfRenderTexture_getMaximumAntialiasingLevel(); + public static uint MaximumAntialiasingLevel => sfRenderTexture_getMaximumAntialiasingLevel(); //////////////////////////////////////////////////////////// /// @@ -326,8 +278,8 @@ public Texture Texture //////////////////////////////////////////////////////////// public bool Smooth { - get { return sfRenderTexture_isSmooth(CPointer); } - set { sfRenderTexture_setSmooth(CPointer, value); } + get => sfRenderTexture_isSmooth(CPointer); + set => sfRenderTexture_setSmooth(CPointer, value); } //////////////////////////////////////////////////////////// @@ -336,10 +288,7 @@ public bool Smooth /// /// Object to draw //////////////////////////////////////////////////////////// - public void Draw(Drawable drawable) - { - Draw(drawable, RenderStates.Default); - } + public void Draw(IDrawable drawable) => Draw(drawable, RenderStates.Default); //////////////////////////////////////////////////////////// /// @@ -348,10 +297,7 @@ public void Draw(Drawable drawable) /// Object to draw /// Render states to use for drawing //////////////////////////////////////////////////////////// - public void Draw(Drawable drawable, RenderStates states) - { - drawable.Draw(this, states); - } + public void Draw(IDrawable drawable, RenderStates states) => drawable.Draw(this, states); //////////////////////////////////////////////////////////// /// @@ -360,10 +306,7 @@ public void Draw(Drawable drawable, RenderStates states) /// Pointer to the vertices /// Type of primitives to draw //////////////////////////////////////////////////////////// - public void Draw(Vertex[] vertices, PrimitiveType type) - { - Draw(vertices, type, RenderStates.Default); - } + public void Draw(Vertex[] vertices, PrimitiveType type) => Draw(vertices, type, RenderStates.Default); //////////////////////////////////////////////////////////// /// @@ -373,10 +316,7 @@ public void Draw(Vertex[] vertices, PrimitiveType type) /// Type of primitives to draw /// Render states to use for drawing //////////////////////////////////////////////////////////// - public void Draw(Vertex[] vertices, PrimitiveType type, RenderStates states) - { - Draw(vertices, 0, (uint)vertices.Length, type, states); - } + public void Draw(Vertex[] vertices, PrimitiveType type, RenderStates states) => Draw(vertices, 0, (uint)vertices.Length, type, states); //////////////////////////////////////////////////////////// /// @@ -387,10 +327,7 @@ public void Draw(Vertex[] vertices, PrimitiveType type, RenderStates states) /// Number of vertices to draw /// Type of primitives to draw //////////////////////////////////////////////////////////// - public void Draw(Vertex[] vertices, uint start, uint count, PrimitiveType type) - { - Draw(vertices, start, count, type, RenderStates.Default); - } + public void Draw(Vertex[] vertices, uint start, uint count, PrimitiveType type) => Draw(vertices, start, count, type, RenderStates.Default); //////////////////////////////////////////////////////////// /// @@ -404,7 +341,7 @@ public void Draw(Vertex[] vertices, uint start, uint count, PrimitiveType type) //////////////////////////////////////////////////////////// public void Draw(Vertex[] vertices, uint start, uint count, PrimitiveType type, RenderStates states) { - RenderStates.MarshalData marshaledStates = states.Marshal(); + var marshaledStates = states.Marshal(); unsafe { @@ -445,10 +382,7 @@ public void Draw(Vertex[] vertices, uint start, uint count, PrimitiveType type, /// function if you do so. /// //////////////////////////////////////////////////////////// - public void PushGLStates() - { - sfRenderTexture_pushGLStates(CPointer); - } + public void PushGLStates() => sfRenderTexture_pushGLStates(CPointer); //////////////////////////////////////////////////////////// /// @@ -458,10 +392,7 @@ public void PushGLStates() /// description of these functions. /// //////////////////////////////////////////////////////////// - public void PopGLStates() - { - sfRenderTexture_popGLStates(CPointer); - } + public void PopGLStates() => sfRenderTexture_popGLStates(CPointer); //////////////////////////////////////////////////////////// /// @@ -484,10 +415,7 @@ public void PopGLStates() /// // OpenGL code here... /// //////////////////////////////////////////////////////////// - public void ResetGLStates() - { - sfRenderTexture_resetGLStates(CPointer); - } + public void ResetGLStates() => sfRenderTexture_resetGLStates(CPointer); //////////////////////////////////////////////////////////// /// @@ -498,7 +426,9 @@ public void ResetGLStates() public override string ToString() { if (IsInvalid) + { return MakeDisposedObjectString(); + } return "[RenderTexture]" + " Size(" + Size + ")" + @@ -517,101 +447,100 @@ protected override void Destroy(bool disposing) { if (!disposing) { - Context.Global.SetActive(true); + _ = Context.Global.SetActive(true); } sfRenderTexture_destroy(CPointer); if (disposing) { - myDefaultView.Dispose(); - myTexture.Dispose(); + _defaultView.Dispose(); + Texture.Dispose(); } if (!disposing) { - Context.Global.SetActive(false); + _ = Context.Global.SetActive(false); } } - private View myDefaultView = null; - private Texture myTexture = null; + private readonly View _defaultView; #region Imports - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity, Obsolete] - private static extern IntPtr sfRenderTexture_create(uint Width, uint Height, bool DepthBuffer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity, Obsolete] + private static extern IntPtr sfRenderTexture_create(uint width, uint height, bool depthBuffer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfRenderTexture_createWithSettings(uint Width, uint Height, ref ContextSettings Settings); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfRenderTexture_createWithSettings(uint width, uint height, ref ContextSettings settings); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderTexture_destroy(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderTexture_destroy(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderTexture_clear(IntPtr CPointer, Color ClearColor); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderTexture_clear(IntPtr cPointer, Color clearColor); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Vector2u sfRenderTexture_getSize(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Vector2u sfRenderTexture_getSize(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfRenderTexture_isSrgb(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfRenderTexture_isSrgb(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfRenderTexture_setActive(IntPtr CPointer, bool Active); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfRenderTexture_setActive(IntPtr cPointer, bool active); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderTexture_display(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderTexture_display(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderTexture_setView(IntPtr CPointer, IntPtr View); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderTexture_setView(IntPtr cPointer, IntPtr view); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfRenderTexture_getView(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfRenderTexture_getView(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfRenderTexture_getDefaultView(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfRenderTexture_getDefaultView(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntRect sfRenderTexture_getViewport(IntPtr CPointer, IntPtr TargetView); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntRect sfRenderTexture_getViewport(IntPtr cPointer, IntPtr targetView); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Vector2i sfRenderTexture_mapCoordsToPixel(IntPtr CPointer, Vector2f point, IntPtr View); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Vector2i sfRenderTexture_mapCoordsToPixel(IntPtr cPointer, Vector2f point, IntPtr view); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Vector2f sfRenderTexture_mapPixelToCoords(IntPtr CPointer, Vector2i point, IntPtr View); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Vector2f sfRenderTexture_mapPixelToCoords(IntPtr cPointer, Vector2i point, IntPtr view); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfRenderTexture_getTexture(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfRenderTexture_getTexture(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern uint sfRenderTexture_getMaximumAntialiasingLevel(); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderTexture_setSmooth(IntPtr CPointer, bool smooth); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderTexture_setSmooth(IntPtr cPointer, bool smooth); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfRenderTexture_isSmooth(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfRenderTexture_isSmooth(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderTexture_setRepeated(IntPtr CPointer, bool repeated); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderTexture_setRepeated(IntPtr cPointer, bool repeated); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfRenderTexture_isRepeated(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfRenderTexture_isRepeated(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfRenderTexture_generateMipmap(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfRenderTexture_generateMipmap(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private unsafe static extern void sfRenderTexture_drawPrimitives(IntPtr CPointer, Vertex* vertexPtr, UIntPtr vertexCount, PrimitiveType type, ref RenderStates.MarshalData renderStates); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern unsafe void sfRenderTexture_drawPrimitives(IntPtr cPointer, Vertex* vertexPtr, UIntPtr vertexCount, PrimitiveType type, ref RenderStates.MarshalData renderStates); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderTexture_pushGLStates(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderTexture_pushGLStates(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderTexture_popGLStates(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderTexture_popGLStates(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderTexture_resetGLStates(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderTexture_resetGLStates(IntPtr cPointer); #endregion } } diff --git a/src/SFML.Graphics/RenderWindow.cs b/src/SFML.Graphics/RenderWindow.cs index e112a81a..838db6c1 100644 --- a/src/SFML.Graphics/RenderWindow.cs +++ b/src/SFML.Graphics/RenderWindow.cs @@ -13,7 +13,7 @@ namespace SFML.Graphics /// 2D rendering /// //////////////////////////////////////////////////////////// - public class RenderWindow : Window.Window, RenderTarget + public class RenderWindow : Window.Window, IRenderTarget { //////////////////////////////////////////////////////////// /// @@ -53,7 +53,7 @@ public RenderWindow(VideoMode mode, string title, Styles style, ContextSettings base(IntPtr.Zero, 0) { // Copy the string to a null-terminated UTF-32 byte array - byte[] titleAsUtf32 = Encoding.UTF32.GetBytes(title + '\0'); + var titleAsUtf32 = Encoding.UTF32.GetBytes(title + '\0'); unsafe { @@ -84,10 +84,7 @@ public RenderWindow(IntPtr handle) : /// Creation parameters //////////////////////////////////////////////////////////// public RenderWindow(IntPtr handle, ContextSettings settings) : - base(sfRenderWindow_createFromHandle(handle, ref settings), 0) - { - Initialize(); - } + base(sfRenderWindow_createFromHandle(handle, ref settings), 0) => Initialize(); //////////////////////////////////////////////////////////// /// @@ -96,10 +93,7 @@ public RenderWindow(IntPtr handle, ContextSettings settings) : /// Create to recreate the window /// //////////////////////////////////////////////////////////// - public override void Close() - { - sfRenderWindow_close(CPointer); - } + public override void Close() => sfRenderWindow_close(CPointer); //////////////////////////////////////////////////////////// /// @@ -109,20 +103,14 @@ public override void Close() /// /// True if the window is opened //////////////////////////////////////////////////////////// - public override bool IsOpen - { - get { return sfRenderWindow_isOpen(CPointer); } - } + public override bool IsOpen => sfRenderWindow_isOpen(CPointer); //////////////////////////////////////////////////////////// /// /// Creation settings of the window /// //////////////////////////////////////////////////////////// - public override ContextSettings Settings - { - get { return sfRenderWindow_getSettings(CPointer); } - } + public override ContextSettings Settings => sfRenderWindow_getSettings(CPointer); //////////////////////////////////////////////////////////// /// @@ -131,8 +119,8 @@ public override ContextSettings Settings //////////////////////////////////////////////////////////// public override Vector2i Position { - get { return sfRenderWindow_getPosition(CPointer); } - set { sfRenderWindow_setPosition(CPointer, value); } + get => sfRenderWindow_getPosition(CPointer); + set => sfRenderWindow_setPosition(CPointer, value); } //////////////////////////////////////////////////////////// @@ -142,8 +130,8 @@ public override Vector2i Position //////////////////////////////////////////////////////////// public override Vector2u Size { - get { return sfRenderWindow_getSize(CPointer); } - set { sfRenderWindow_setSize(CPointer, value); } + get => sfRenderWindow_getSize(CPointer); + set => sfRenderWindow_setSize(CPointer, value); } //////////////////////////////////////////////////////////// @@ -151,10 +139,7 @@ public override Vector2u Size /// Tell if the render window will use sRGB encoding when drawing on it /// //////////////////////////////////////////////////////////// - public bool IsSrgb - { - get { return sfRenderWindow_isSrgb(CPointer); } - } + public bool IsSrgb => sfRenderWindow_isSrgb(CPointer); //////////////////////////////////////////////////////////// /// @@ -165,7 +150,7 @@ public bool IsSrgb public override void SetTitle(string title) { // Copy the title to a null-terminated UTF-32 byte array - byte[] titleAsUtf32 = Encoding.UTF32.GetBytes(title + '\0'); + var titleAsUtf32 = Encoding.UTF32.GetBytes(title + '\0'); unsafe { @@ -188,9 +173,9 @@ public override void SetIcon(uint width, uint height, byte[] pixels) { unsafe { - fixed (byte* PixelsPtr = pixels) + fixed (byte* pixelsPtr = pixels) { - sfRenderWindow_setIcon(CPointer, width, height, PixelsPtr); + sfRenderWindow_setIcon(CPointer, width, height, pixelsPtr); } } } @@ -201,10 +186,7 @@ public override void SetIcon(uint width, uint height, byte[] pixels) /// /// True to show the window, false to hide it //////////////////////////////////////////////////////////// - public override void SetVisible(bool visible) - { - sfRenderWindow_setVisible(CPointer, visible); - } + public override void SetVisible(bool visible) => sfRenderWindow_setVisible(CPointer, visible); //////////////////////////////////////////////////////////// /// @@ -212,10 +194,7 @@ public override void SetVisible(bool visible) /// /// True to enable v-sync, false to deactivate //////////////////////////////////////////////////////////// - public override void SetVerticalSyncEnabled(bool enable) - { - sfRenderWindow_setVerticalSyncEnabled(CPointer, enable); - } + public override void SetVerticalSyncEnabled(bool enable) => sfRenderWindow_setVerticalSyncEnabled(CPointer, enable); //////////////////////////////////////////////////////////// /// @@ -223,10 +202,7 @@ public override void SetVerticalSyncEnabled(bool enable) /// /// True to show, false to hide //////////////////////////////////////////////////////////// - public override void SetMouseCursorVisible(bool visible) - { - sfRenderWindow_setMouseCursorVisible(CPointer, visible); - } + public override void SetMouseCursorVisible(bool visible) => sfRenderWindow_setMouseCursorVisible(CPointer, visible); //////////////////////////////////////////////////////////// /// @@ -243,10 +219,7 @@ public override void SetMouseCursorVisible(bool visible) /// cursor). /// //////////////////////////////////////////////////////////// - public override void SetMouseCursorGrabbed(bool grabbed) - { - sfRenderWindow_setMouseCursorGrabbed(CPointer, grabbed); - } + public override void SetMouseCursorGrabbed(bool grabbed) => sfRenderWindow_setMouseCursorGrabbed(CPointer, grabbed); //////////////////////////////////////////////////////////// /// @@ -254,10 +227,7 @@ public override void SetMouseCursorGrabbed(bool grabbed) /// /// Native system cursor type to display //////////////////////////////////////////////////////////// - public override void SetMouseCursor(Cursor cursor) - { - sfRenderWindow_setMouseCursor(CPointer, cursor.CPointer); - } + public override void SetMouseCursor(Cursor cursor) => sfRenderWindow_setMouseCursor(CPointer, cursor.CPointer); //////////////////////////////////////////////////////////// /// @@ -266,10 +236,7 @@ public override void SetMouseCursor(Cursor cursor) /// /// True to enable, false to disable //////////////////////////////////////////////////////////// - public override void SetKeyRepeatEnabled(bool enable) - { - sfRenderWindow_setKeyRepeatEnabled(CPointer, enable); - } + public override void SetKeyRepeatEnabled(bool enable) => sfRenderWindow_setKeyRepeatEnabled(CPointer, enable); //////////////////////////////////////////////////////////// /// @@ -277,10 +244,7 @@ public override void SetKeyRepeatEnabled(bool enable) /// /// Framerate limit, in frames per seconds (use 0 to disable limit) //////////////////////////////////////////////////////////// - public override void SetFramerateLimit(uint limit) - { - sfRenderWindow_setFramerateLimit(CPointer, limit); - } + public override void SetFramerateLimit(uint limit) => sfRenderWindow_setFramerateLimit(CPointer, limit); //////////////////////////////////////////////////////////// /// @@ -289,10 +253,7 @@ public override void SetFramerateLimit(uint limit) /// /// New threshold, in range [0, 100] //////////////////////////////////////////////////////////// - public override void SetJoystickThreshold(float threshold) - { - sfRenderWindow_setJoystickThreshold(CPointer, threshold); - } + public override void SetJoystickThreshold(float threshold) => sfRenderWindow_setJoystickThreshold(CPointer, threshold); //////////////////////////////////////////////////////////// /// @@ -302,10 +263,7 @@ public override void SetJoystickThreshold(float threshold) /// True to activate, false to deactivate (true by default) /// True if operation was successful, false otherwise //////////////////////////////////////////////////////////// - public override bool SetActive(bool active) - { - return sfRenderWindow_setActive(CPointer, active); - } + public override bool SetActive(bool active) => sfRenderWindow_setActive(CPointer, active); //////////////////////////////////////////////////////////// /// @@ -313,10 +271,7 @@ public override bool SetActive(bool active) /// foreground window /// //////////////////////////////////////////////////////////// - public override void RequestFocus() - { - sfRenderWindow_requestFocus(CPointer); - } + public override void RequestFocus() => sfRenderWindow_requestFocus(CPointer); //////////////////////////////////////////////////////////// /// @@ -324,10 +279,7 @@ public override void RequestFocus() /// /// True if the window has focus, false otherwise //////////////////////////////////////////////////////////// - public override bool HasFocus() - { - return sfRenderWindow_hasFocus(CPointer); - } + public override bool HasFocus() => sfRenderWindow_hasFocus(CPointer); //////////////////////////////////////////////////////////// /// @@ -338,40 +290,28 @@ public override bool HasFocus() /// Allocator to use /// True if surface creation was successful, false otherwise //////////////////////////////////////////////////////////// - public override bool CreateVulkanSurface(IntPtr vkInstance, out IntPtr vkSurface, IntPtr vkAllocator) - { - return sfRenderWindow_createVulkanSurface(CPointer, vkInstance, out vkSurface, vkAllocator); - } + public override bool CreateVulkanSurface(IntPtr vkInstance, out IntPtr vkSurface, IntPtr vkAllocator) => sfRenderWindow_createVulkanSurface(CPointer, vkInstance, out vkSurface, vkAllocator); //////////////////////////////////////////////////////////// /// /// Display the window on screen /// //////////////////////////////////////////////////////////// - public override void Display() - { - sfRenderWindow_display(CPointer); - } + public override void Display() => sfRenderWindow_display(CPointer); //////////////////////////////////////////////////////////// /// /// OS-specific handle of the window /// //////////////////////////////////////////////////////////// - public override IntPtr SystemHandle - { - get { return sfRenderWindow_getSystemHandle(CPointer); } - } + public override IntPtr SystemHandle => sfRenderWindow_getSystemHandle(CPointer); //////////////////////////////////////////////////////////// /// /// Clear the entire window with black color /// //////////////////////////////////////////////////////////// - public void Clear() - { - sfRenderWindow_clear(CPointer, Color.Black); - } + public void Clear() => sfRenderWindow_clear(CPointer, Color.Black); //////////////////////////////////////////////////////////// /// @@ -379,10 +319,7 @@ public void Clear() /// /// Color to use to clear the window //////////////////////////////////////////////////////////// - public void Clear(Color color) - { - sfRenderWindow_clear(CPointer, color); - } + public void Clear(Color color) => sfRenderWindow_clear(CPointer, color); //////////////////////////////////////////////////////////// /// @@ -390,10 +327,7 @@ public void Clear(Color color) /// /// New view //////////////////////////////////////////////////////////// - public void SetView(View view) - { - sfRenderWindow_setView(CPointer, view.CPointer); - } + public void SetView(View view) => sfRenderWindow_setView(CPointer, view.CPointer); //////////////////////////////////////////////////////////// /// @@ -401,20 +335,14 @@ public void SetView(View view) /// /// The current view //////////////////////////////////////////////////////////// - public View GetView() - { - return new View(sfRenderWindow_getView(CPointer)); - } + public View GetView() => new View(sfRenderWindow_getView(CPointer)); //////////////////////////////////////////////////////////// /// /// Default view of the window /// //////////////////////////////////////////////////////////// - public View DefaultView - { - get { return new View(myDefaultView); } - } + public View DefaultView => new View(_defaultView); //////////////////////////////////////////////////////////// /// @@ -423,10 +351,7 @@ public View DefaultView /// Target view /// Viewport rectangle, expressed in pixels in the current target //////////////////////////////////////////////////////////// - public IntRect GetViewport(View view) - { - return sfRenderWindow_getViewport(CPointer, view.CPointer); - } + public IntRect GetViewport(View view) => sfRenderWindow_getViewport(CPointer, view.CPointer); //////////////////////////////////////////////////////////// /// @@ -441,10 +366,7 @@ public IntRect GetViewport(View view) /// Pixel to convert /// The converted point, in "world" coordinates //////////////////////////////////////////////////////////// - public Vector2f MapPixelToCoords(Vector2i point) - { - return MapPixelToCoords(point, GetView()); - } + public Vector2f MapPixelToCoords(Vector2i point) => MapPixelToCoords(point, GetView()); //////////////////////////////////////////////////////////// /// @@ -472,10 +394,7 @@ public Vector2f MapPixelToCoords(Vector2i point) /// The view to use for converting the point /// The converted point, in "world" coordinates //////////////////////////////////////////////////////////// - public Vector2f MapPixelToCoords(Vector2i point, View view) - { - return sfRenderWindow_mapPixelToCoords(CPointer, point, view != null ? view.CPointer : IntPtr.Zero); - } + public Vector2f MapPixelToCoords(Vector2i point, View view) => sfRenderWindow_mapPixelToCoords(CPointer, point, view != null ? view.CPointer : IntPtr.Zero); //////////////////////////////////////////////////////////// /// @@ -490,10 +409,7 @@ public Vector2f MapPixelToCoords(Vector2i point, View view) /// Point to convert /// The converted point, in target coordinates (pixels) //////////////////////////////////////////////////////////// - public Vector2i MapCoordsToPixel(Vector2f point) - { - return MapCoordsToPixel(point, GetView()); - } + public Vector2i MapCoordsToPixel(Vector2f point) => MapCoordsToPixel(point, GetView()); //////////////////////////////////////////////////////////// /// @@ -517,10 +433,7 @@ public Vector2i MapCoordsToPixel(Vector2f point) /// The view to use for converting the point /// The converted point, in target coordinates (pixels) //////////////////////////////////////////////////////////// - public Vector2i MapCoordsToPixel(Vector2f point, View view) - { - return sfRenderWindow_mapCoordsToPixel(CPointer, point, view != null ? view.CPointer : IntPtr.Zero); - } + public Vector2i MapCoordsToPixel(Vector2f point, View view) => sfRenderWindow_mapCoordsToPixel(CPointer, point, view != null ? view.CPointer : IntPtr.Zero); //////////////////////////////////////////////////////////// /// @@ -528,10 +441,7 @@ public Vector2i MapCoordsToPixel(Vector2f point, View view) /// /// Object to draw //////////////////////////////////////////////////////////// - public void Draw(Drawable drawable) - { - Draw(drawable, RenderStates.Default); - } + public void Draw(IDrawable drawable) => Draw(drawable, RenderStates.Default); //////////////////////////////////////////////////////////// /// @@ -540,10 +450,7 @@ public void Draw(Drawable drawable) /// Object to draw /// Render states to use for drawing //////////////////////////////////////////////////////////// - public void Draw(Drawable drawable, RenderStates states) - { - drawable.Draw(this, states); - } + public void Draw(IDrawable drawable, RenderStates states) => drawable.Draw(this, states); //////////////////////////////////////////////////////////// /// @@ -552,10 +459,7 @@ public void Draw(Drawable drawable, RenderStates states) /// Pointer to the vertices /// Type of primitives to draw //////////////////////////////////////////////////////////// - public void Draw(Vertex[] vertices, PrimitiveType type) - { - Draw(vertices, type, RenderStates.Default); - } + public void Draw(Vertex[] vertices, PrimitiveType type) => Draw(vertices, type, RenderStates.Default); //////////////////////////////////////////////////////////// /// @@ -565,10 +469,7 @@ public void Draw(Vertex[] vertices, PrimitiveType type) /// Type of primitives to draw /// Render states to use for drawing //////////////////////////////////////////////////////////// - public void Draw(Vertex[] vertices, PrimitiveType type, RenderStates states) - { - Draw(vertices, 0, (uint)vertices.Length, type, states); - } + public void Draw(Vertex[] vertices, PrimitiveType type, RenderStates states) => Draw(vertices, 0, (uint)vertices.Length, type, states); //////////////////////////////////////////////////////////// /// @@ -579,10 +480,7 @@ public void Draw(Vertex[] vertices, PrimitiveType type, RenderStates states) /// Number of vertices to draw /// Type of primitives to draw //////////////////////////////////////////////////////////// - public void Draw(Vertex[] vertices, uint start, uint count, PrimitiveType type) - { - Draw(vertices, start, count, type, RenderStates.Default); - } + public void Draw(Vertex[] vertices, uint start, uint count, PrimitiveType type) => Draw(vertices, start, count, type, RenderStates.Default); //////////////////////////////////////////////////////////// /// @@ -596,7 +494,7 @@ public void Draw(Vertex[] vertices, uint start, uint count, PrimitiveType type) //////////////////////////////////////////////////////////// public void Draw(Vertex[] vertices, uint start, uint count, PrimitiveType type, RenderStates states) { - RenderStates.MarshalData marshaledStates = states.Marshal(); + var marshaledStates = states.Marshal(); unsafe { @@ -641,10 +539,7 @@ public void Draw(Vertex[] vertices, uint start, uint count, PrimitiveType type, /// function if you do so. /// //////////////////////////////////////////////////////////// - public void PushGLStates() - { - sfRenderWindow_pushGLStates(CPointer); - } + public void PushGLStates() => sfRenderWindow_pushGLStates(CPointer); //////////////////////////////////////////////////////////// /// @@ -654,10 +549,7 @@ public void PushGLStates() /// description of these functions. /// //////////////////////////////////////////////////////////// - public void PopGLStates() - { - sfRenderWindow_popGLStates(CPointer); - } + public void PopGLStates() => sfRenderWindow_popGLStates(CPointer); //////////////////////////////////////////////////////////// /// @@ -682,10 +574,7 @@ public void PopGLStates() /// // OpenGL code here... /// //////////////////////////////////////////////////////////// - public void ResetGLStates() - { - sfRenderWindow_resetGLStates(CPointer); - } + public void ResetGLStates() => sfRenderWindow_resetGLStates(CPointer); //////////////////////////////////////////////////////////// /// @@ -703,10 +592,7 @@ public void ResetGLStates() /// //////////////////////////////////////////////////////////// [Obsolete("Use Texture and Texture.Update(RenderWindow)")] - public Image Capture() - { - return new Image(sfRenderWindow_capture(CPointer)); - } + public Image Capture() => new Image(sfRenderWindow_capture(CPointer)); //////////////////////////////////////////////////////////// /// @@ -717,7 +603,9 @@ public Image Capture() public override string ToString() { if (IsInvalid) + { return MakeDisposedObjectString(); + } return "[RenderWindow]" + " Size(" + Size + ")" + @@ -734,10 +622,7 @@ public override string ToString() /// Variable to fill with the raw pointer to the event structure /// True if there was an event, false otherwise //////////////////////////////////////////////////////////// - protected override bool PollEvent(out Event eventToFill) - { - return sfRenderWindow_pollEvent(CPointer, out eventToFill); - } + protected override bool PollEvent(out Event eventToFill) => sfRenderWindow_pollEvent(CPointer, out eventToFill); //////////////////////////////////////////////////////////// /// @@ -746,10 +631,7 @@ protected override bool PollEvent(out Event eventToFill) /// Variable to fill with the raw pointer to the event structure /// False if any error occurred //////////////////////////////////////////////////////////// - protected override bool WaitEvent(out Event eventToFill) - { - return sfRenderWindow_waitEvent(CPointer, out eventToFill); - } + protected override bool WaitEvent(out Event eventToFill) => sfRenderWindow_waitEvent(CPointer, out eventToFill); //////////////////////////////////////////////////////////// /// @@ -759,10 +641,7 @@ protected override bool WaitEvent(out Event eventToFill) /// /// Relative mouse position //////////////////////////////////////////////////////////// - protected override Vector2i InternalGetMousePosition() - { - return sfMouse_getPositionRenderWindow(CPointer); - } + protected override Vector2i InternalGetMousePosition() => sfMouse_getPositionRenderWindow(CPointer); //////////////////////////////////////////////////////////// /// @@ -772,10 +651,7 @@ protected override Vector2i InternalGetMousePosition() /// /// Relative mouse position //////////////////////////////////////////////////////////// - protected override void InternalSetMousePosition(Vector2i position) - { - sfMouse_setPositionRenderWindow(position, CPointer); - } + protected override void InternalSetMousePosition(Vector2i position) => sfMouse_setPositionRenderWindow(position, CPointer); //////////////////////////////////////////////////////////// /// @@ -783,13 +659,10 @@ protected override void InternalSetMousePosition(Vector2i position) /// This function is protected because it is called by another class of /// another module, it is not meant to be called by users. /// - /// Finger index + /// Finger index /// Relative touch position //////////////////////////////////////////////////////////// - protected override Vector2i InternalGetTouchPosition(uint Finger) - { - return sfTouch_getPositionRenderWindow(Finger, CPointer); - } + protected override Vector2i InternalGetTouchPosition(uint finger) => sfTouch_getPositionRenderWindow(finger, CPointer); //////////////////////////////////////////////////////////// /// @@ -803,10 +676,10 @@ protected override void Destroy(bool disposing) if (disposing) { - myDefaultView.Dispose(); + _defaultView.Dispose(); } - myDefaultView = null; + _defaultView = null; } //////////////////////////////////////////////////////////// @@ -816,144 +689,144 @@ protected override void Destroy(bool disposing) //////////////////////////////////////////////////////////// private void Initialize() { - myDefaultView = new View(sfRenderWindow_getDefaultView(CPointer)); - GC.SuppressFinalize(myDefaultView); + _defaultView = new View(sfRenderWindow_getDefaultView(CPointer)); + GC.SuppressFinalize(_defaultView); } - private View myDefaultView = null; + private View _defaultView; #region Imports - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfRenderWindow_createUnicode(VideoMode Mode, IntPtr Title, Styles Style, ref ContextSettings Params); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfRenderWindow_createUnicode(VideoMode mode, IntPtr title, Styles style, ref ContextSettings settings); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfRenderWindow_createFromHandle(IntPtr Handle, ref ContextSettings Params); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfRenderWindow_createFromHandle(IntPtr handle, ref ContextSettings settings); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderWindow_destroy(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderWindow_destroy(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderWindow_close(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderWindow_close(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfRenderWindow_isOpen(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfRenderWindow_isOpen(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern ContextSettings sfRenderWindow_getSettings(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern ContextSettings sfRenderWindow_getSettings(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfRenderWindow_pollEvent(IntPtr CPointer, out Event Evt); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfRenderWindow_pollEvent(IntPtr cPointer, out Event evt); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfRenderWindow_waitEvent(IntPtr CPointer, out Event Evt); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfRenderWindow_waitEvent(IntPtr cPointer, out Event evt); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Vector2i sfRenderWindow_getPosition(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Vector2i sfRenderWindow_getPosition(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderWindow_setPosition(IntPtr CPointer, Vector2i position); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderWindow_setPosition(IntPtr cPointer, Vector2i position); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Vector2u sfRenderWindow_getSize(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Vector2u sfRenderWindow_getSize(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfRenderWindow_isSrgb(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfRenderWindow_isSrgb(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderWindow_setSize(IntPtr CPointer, Vector2u size); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderWindow_setSize(IntPtr cPointer, Vector2u size); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderWindow_setUnicodeTitle(IntPtr CPointer, IntPtr title); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderWindow_setUnicodeTitle(IntPtr cPointer, IntPtr title); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private unsafe static extern void sfRenderWindow_setIcon(IntPtr CPointer, uint Width, uint Height, byte* Pixels); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern unsafe void sfRenderWindow_setIcon(IntPtr cPointer, uint width, uint height, byte* pixels); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderWindow_setVisible(IntPtr CPointer, bool visible); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderWindow_setVisible(IntPtr cPointer, bool visible); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderWindow_setVerticalSyncEnabled(IntPtr CPointer, bool Enable); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderWindow_setVerticalSyncEnabled(IntPtr cPointer, bool enable); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderWindow_setMouseCursorVisible(IntPtr CPointer, bool visible); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderWindow_setMouseCursorVisible(IntPtr cPointer, bool visible); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderWindow_setMouseCursorGrabbed(IntPtr CPointer, bool grabbed); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderWindow_setMouseCursorGrabbed(IntPtr cPointer, bool grabbed); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfRenderWindow_setMouseCursor(IntPtr window, IntPtr cursor); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderWindow_setKeyRepeatEnabled(IntPtr CPointer, bool Enable); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderWindow_setKeyRepeatEnabled(IntPtr cPointer, bool enable); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderWindow_setFramerateLimit(IntPtr CPointer, uint Limit); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderWindow_setFramerateLimit(IntPtr cPointer, uint limit); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderWindow_setJoystickThreshold(IntPtr CPointer, float Threshold); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderWindow_setJoystickThreshold(IntPtr cPointer, float threshold); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfRenderWindow_setActive(IntPtr CPointer, bool Active); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfRenderWindow_setActive(IntPtr cPointer, bool active); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderWindow_requestFocus(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderWindow_requestFocus(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfRenderWindow_hasFocus(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfRenderWindow_hasFocus(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderWindow_display(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderWindow_display(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfRenderWindow_getSystemHandle(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfRenderWindow_getSystemHandle(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderWindow_clear(IntPtr CPointer, Color ClearColor); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderWindow_clear(IntPtr cPointer, Color clearColor); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderWindow_setView(IntPtr CPointer, IntPtr View); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderWindow_setView(IntPtr cPointer, IntPtr view); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfRenderWindow_getView(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfRenderWindow_getView(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfRenderWindow_getDefaultView(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfRenderWindow_getDefaultView(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntRect sfRenderWindow_getViewport(IntPtr CPointer, IntPtr TargetView); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntRect sfRenderWindow_getViewport(IntPtr cPointer, IntPtr targetView); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Vector2f sfRenderWindow_mapPixelToCoords(IntPtr CPointer, Vector2i point, IntPtr View); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Vector2f sfRenderWindow_mapPixelToCoords(IntPtr cPointer, Vector2i point, IntPtr view); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Vector2i sfRenderWindow_mapCoordsToPixel(IntPtr CPointer, Vector2f point, IntPtr View); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Vector2i sfRenderWindow_mapCoordsToPixel(IntPtr cPointer, Vector2f point, IntPtr view); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private unsafe static extern void sfRenderWindow_drawPrimitives(IntPtr CPointer, Vertex* vertexPtr, UIntPtr vertexCount, PrimitiveType type, ref RenderStates.MarshalData renderStates); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern unsafe void sfRenderWindow_drawPrimitives(IntPtr cPointer, Vertex* vertexPtr, UIntPtr vertexCount, PrimitiveType type, ref RenderStates.MarshalData renderStates); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderWindow_pushGLStates(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderWindow_pushGLStates(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderWindow_popGLStates(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderWindow_popGLStates(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderWindow_resetGLStates(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderWindow_resetGLStates(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfRenderWindow_capture(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfRenderWindow_capture(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Vector2i sfMouse_getPositionRenderWindow(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Vector2i sfMouse_getPositionRenderWindow(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfMouse_setPositionRenderWindow(Vector2i position, IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfMouse_setPositionRenderWindow(Vector2i position, IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Vector2i sfTouch_getPositionRenderWindow(uint Finger, IntPtr RelativeTo); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Vector2i sfTouch_getPositionRenderWindow(uint finger, IntPtr relativeTo); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfRenderWindow_createVulkanSurface(IntPtr CPointer, IntPtr vkInstance, out IntPtr surface, IntPtr vkAllocator); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfRenderWindow_createVulkanSurface(IntPtr cPointer, IntPtr vkInstance, out IntPtr surface, IntPtr vkAllocator); #endregion } } diff --git a/src/SFML.Graphics/Shader.cs b/src/SFML.Graphics/Shader.cs index 41c512bd..08d83032 100644 --- a/src/SFML.Graphics/Shader.cs +++ b/src/SFML.Graphics/Shader.cs @@ -29,7 +29,7 @@ public class CurrentTextureType { } /// and that represents the texture of the object being drawn /// //////////////////////////////////////////////////////////// - public static readonly CurrentTextureType CurrentTexture = null; + public static readonly CurrentTextureType CurrentTexture; //////////////////////////////////////////////////////////// /// @@ -107,10 +107,7 @@ public Shader(Stream vertexShaderStream, Stream geometryShaderStream, Stream fra /// or implement a temporary workaround until a bug is fixed. /// //////////////////////////////////////////////////////////// - public uint NativeHandle - { - get { return sfShader_getNativeHandle(CPointer); } - } + public uint NativeHandle => sfShader_getNativeHandle(CPointer); //////////////////////////////////////////////////////////// /// @@ -133,7 +130,7 @@ public uint NativeHandle //////////////////////////////////////////////////////////// public static Shader FromString(string vertexShader, string geometryShader, string fragmentShader) { - IntPtr ptr = sfShader_createFromMemory(vertexShader, geometryShader, fragmentShader); + var ptr = sfShader_createFromMemory(vertexShader, geometryShader, fragmentShader); if (ptr == IntPtr.Zero) { throw new LoadingFailedException("shader"); @@ -149,10 +146,7 @@ public static Shader FromString(string vertexShader, string geometryShader, stri /// Name of the uniform variable in GLSL /// Value of the float scalar //////////////////////////////////////////////////////////// - public void SetUniform(string name, float x) - { - sfShader_setFloatUniform(CPointer, name, x); - } + public void SetUniform(string name, float x) => sfShader_setFloatUniform(CPointer, name, x); //////////////////////////////////////////////////////////// /// @@ -161,10 +155,7 @@ public void SetUniform(string name, float x) /// Name of the uniform variable in GLSL /// Value of the vec2 vector //////////////////////////////////////////////////////////// - public void SetUniform(string name, Glsl.Vec2 vector) - { - sfShader_setVec2Uniform(CPointer, name, vector); - } + public void SetUniform(string name, Glsl.Vec2 vector) => sfShader_setVec2Uniform(CPointer, name, vector); //////////////////////////////////////////////////////////// /// @@ -173,10 +164,7 @@ public void SetUniform(string name, Glsl.Vec2 vector) /// Name of the uniform variable in GLSL /// Value of the vec3 vector //////////////////////////////////////////////////////////// - public void SetUniform(string name, Glsl.Vec3 vector) - { - sfShader_setVec3Uniform(CPointer, name, vector); - } + public void SetUniform(string name, Glsl.Vec3 vector) => sfShader_setVec3Uniform(CPointer, name, vector); //////////////////////////////////////////////////////////// /// @@ -185,10 +173,7 @@ public void SetUniform(string name, Glsl.Vec3 vector) /// Name of the uniform variable in GLSL /// Value of the vec4 vector //////////////////////////////////////////////////////////// - public void SetUniform(string name, Glsl.Vec4 vector) - { - sfShader_setVec4Uniform(CPointer, name, vector); - } + public void SetUniform(string name, Glsl.Vec4 vector) => sfShader_setVec4Uniform(CPointer, name, vector); //////////////////////////////////////////////////////////// /// @@ -197,11 +182,8 @@ public void SetUniform(string name, Glsl.Vec4 vector) /// Name of the uniform variable in GLSL /// Value of the int scalar //////////////////////////////////////////////////////////// - public void SetUniform(string name, int x) - { - sfShader_setIntUniform(CPointer, name, x); - } - + public void SetUniform(string name, int x) => sfShader_setIntUniform(CPointer, name, x); + //////////////////////////////////////////////////////////// /// /// Specify value for color uniform @@ -209,11 +191,8 @@ public void SetUniform(string name, int x) /// Name of the uniform variable in GLSL /// Value of the vec4 vector //////////////////////////////////////////////////////////// - public void SetUniform(string name, Color color) - { - sfShader_setColorUniform(CPointer, name, color); - } - + public void SetUniform(string name, Color color) => sfShader_setColorUniform(CPointer, name, color); + //////////////////////////////////////////////////////////// /// /// Specify value for ivec2 uniform @@ -221,10 +200,7 @@ public void SetUniform(string name, Color color) /// Name of the uniform variable in GLSL /// Value of the ivec2 vector //////////////////////////////////////////////////////////// - public void SetUniform(string name, Glsl.Ivec2 vector) - { - sfShader_setIvec2Uniform(CPointer, name, vector); - } + public void SetUniform(string name, Glsl.Ivec2 vector) => sfShader_setIvec2Uniform(CPointer, name, vector); //////////////////////////////////////////////////////////// /// @@ -233,10 +209,7 @@ public void SetUniform(string name, Glsl.Ivec2 vector) /// Name of the uniform variable in GLSL /// Value of the ivec3 vector //////////////////////////////////////////////////////////// - public void SetUniform(string name, Glsl.Ivec3 vector) - { - sfShader_setIvec3Uniform(CPointer, name, vector); - } + public void SetUniform(string name, Glsl.Ivec3 vector) => sfShader_setIvec3Uniform(CPointer, name, vector); //////////////////////////////////////////////////////////// /// @@ -245,10 +218,7 @@ public void SetUniform(string name, Glsl.Ivec3 vector) /// Name of the uniform variable in GLSL /// Value of the ivec4 vector //////////////////////////////////////////////////////////// - public void SetUniform(string name, Glsl.Ivec4 vector) - { - sfShader_setIvec4Uniform(CPointer, name, vector); - } + public void SetUniform(string name, Glsl.Ivec4 vector) => sfShader_setIvec4Uniform(CPointer, name, vector); //////////////////////////////////////////////////////////// /// @@ -257,10 +227,7 @@ public void SetUniform(string name, Glsl.Ivec4 vector) /// Name of the uniform variable in GLSL /// Value of the bool scalar //////////////////////////////////////////////////////////// - public void SetUniform(string name, bool x) - { - sfShader_setBoolUniform(CPointer, name, x); - } + public void SetUniform(string name, bool x) => sfShader_setBoolUniform(CPointer, name, x); //////////////////////////////////////////////////////////// /// @@ -269,10 +236,7 @@ public void SetUniform(string name, bool x) /// Name of the uniform variable in GLSL /// Value of the bvec2 vector //////////////////////////////////////////////////////////// - public void SetUniform(string name, Glsl.Bvec2 vector) - { - sfShader_setBvec2Uniform(CPointer, name, vector); - } + public void SetUniform(string name, Glsl.Bvec2 vector) => sfShader_setBvec2Uniform(CPointer, name, vector); //////////////////////////////////////////////////////////// /// @@ -281,10 +245,7 @@ public void SetUniform(string name, Glsl.Bvec2 vector) /// Name of the uniform variable in GLSL /// Value of the bvec3 vector //////////////////////////////////////////////////////////// - public void SetUniform(string name, Glsl.Bvec3 vector) - { - sfShader_setBvec3Uniform(CPointer, name, vector); - } + public void SetUniform(string name, Glsl.Bvec3 vector) => sfShader_setBvec3Uniform(CPointer, name, vector); //////////////////////////////////////////////////////////// /// @@ -293,10 +254,7 @@ public void SetUniform(string name, Glsl.Bvec3 vector) /// Name of the uniform variable in GLSL /// Value of the bvec4 vector //////////////////////////////////////////////////////////// - public void SetUniform(string name, Glsl.Bvec4 vector) - { - sfShader_setBvec4Uniform(CPointer, name, vector); - } + public void SetUniform(string name, Glsl.Bvec4 vector) => sfShader_setBvec4Uniform(CPointer, name, vector); //////////////////////////////////////////////////////////// /// @@ -305,10 +263,7 @@ public void SetUniform(string name, Glsl.Bvec4 vector) /// Name of the uniform variable in GLSL /// Value of the mat3 matrix //////////////////////////////////////////////////////////// - public void SetUniform(string name, Glsl.Mat3 matrix) - { - sfShader_setMat3Uniform(CPointer, name, matrix); - } + public void SetUniform(string name, Glsl.Mat3 matrix) => sfShader_setMat3Uniform(CPointer, name, matrix); //////////////////////////////////////////////////////////// /// @@ -317,10 +272,7 @@ public void SetUniform(string name, Glsl.Mat3 matrix) /// Name of the uniform variable in GLSL /// Value of the mat4 matrix //////////////////////////////////////////////////////////// - public void SetUniform(string name, Glsl.Mat4 matrix) - { - sfShader_setMat4Uniform(CPointer, name, matrix); - } + public void SetUniform(string name, Glsl.Mat4 matrix) => sfShader_setMat4Uniform(CPointer, name, matrix); //////////////////////////////////////////////////////////// /// @@ -360,7 +312,7 @@ public void SetUniform(string name, Glsl.Mat4 matrix) public void SetUniform(string name, Texture texture) { // Keep a reference to the Texture so it doesn't get GC'd - myTextures[name] = texture; + _textures[name] = texture; sfShader_setTextureUniform(CPointer, name, texture.CPointer); } @@ -390,10 +342,7 @@ public void SetUniform(string name, Texture texture) /// Name of the texture in the shader /// //////////////////////////////////////////////////////////// - public void SetUniform(string name, CurrentTextureType current) - { - sfShader_setCurrentTextureUniform(CPointer, name); - } + public void SetUniform(string name, CurrentTextureType current) => sfShader_setCurrentTextureUniform(CPointer, name); //////////////////////////////////////////////////////////// /// @@ -499,10 +448,7 @@ public unsafe void SetUniformArray(string name, Glsl.Mat4[] array) /// //////////////////////////////////////////////////////////// [Obsolete("Use SetUniform()")] - public void SetParameter(string name, float x) - { - sfShader_setFloatParameter(CPointer, name, x); - } + public void SetParameter(string name, float x) => sfShader_setFloatParameter(CPointer, name, x); //////////////////////////////////////////////////////////// /// @@ -517,10 +463,7 @@ public void SetParameter(string name, float x) /// Second component of the value to assign //////////////////////////////////////////////////////////// [Obsolete("Use SetUniform()")] - public void SetParameter(string name, float x, float y) - { - sfShader_setFloat2Parameter(CPointer, name, x, y); - } + public void SetParameter(string name, float x, float y) => sfShader_setFloat2Parameter(CPointer, name, x, y); //////////////////////////////////////////////////////////// /// @@ -536,10 +479,7 @@ public void SetParameter(string name, float x, float y) /// Third component of the value to assign //////////////////////////////////////////////////////////// [Obsolete("Use SetUniform()")] - public void SetParameter(string name, float x, float y, float z) - { - sfShader_setFloat3Parameter(CPointer, name, x, y, z); - } + public void SetParameter(string name, float x, float y, float z) => sfShader_setFloat3Parameter(CPointer, name, x, y, z); //////////////////////////////////////////////////////////// /// @@ -556,10 +496,7 @@ public void SetParameter(string name, float x, float y, float z) /// Fourth component of the value to assign //////////////////////////////////////////////////////////// [Obsolete("Use SetUniform()")] - public void SetParameter(string name, float x, float y, float z, float w) - { - sfShader_setFloat4Parameter(CPointer, name, x, y, z, w); - } + public void SetParameter(string name, float x, float y, float z, float w) => sfShader_setFloat4Parameter(CPointer, name, x, y, z, w); //////////////////////////////////////////////////////////// /// @@ -573,10 +510,7 @@ public void SetParameter(string name, float x, float y, float z, float w) /// Vector to assign //////////////////////////////////////////////////////////// [Obsolete("Use SetUniform()")] - public void SetParameter(string name, Vector2f vector) - { - SetParameter(name, vector.X, vector.Y); - } + public void SetParameter(string name, Vector2f vector) => SetParameter(name, vector.X, vector.Y); //////////////////////////////////////////////////////////// /// @@ -590,10 +524,7 @@ public void SetParameter(string name, Vector2f vector) /// Color to assign //////////////////////////////////////////////////////////// [Obsolete("Use SetUniform()")] - public void SetParameter(string name, Color color) - { - sfShader_setColorParameter(CPointer, name, color); - } + public void SetParameter(string name, Color color) => sfShader_setColorParameter(CPointer, name, color); //////////////////////////////////////////////////////////// /// @@ -607,10 +538,7 @@ public void SetParameter(string name, Color color) /// Transform to assign //////////////////////////////////////////////////////////// [Obsolete("Use SetUniform()")] - public void SetParameter(string name, Transform transform) - { - sfShader_setTransformParameter(CPointer, name, transform); - } + public void SetParameter(string name, Transform transform) => sfShader_setTransformParameter(CPointer, name, transform); //////////////////////////////////////////////////////////// /// @@ -634,7 +562,7 @@ public void SetParameter(string name, Transform transform) public void SetParameter(string name, Texture texture) { // Keep a reference to the Texture so it doesn't get GC'd - myTextures[name] = texture; + _textures[name] = texture; sfShader_setTextureParameter(CPointer, name, texture.CPointer); } @@ -653,10 +581,7 @@ public void SetParameter(string name, Texture texture) /// Always pass the special value Shader.CurrentTexture //////////////////////////////////////////////////////////// [Obsolete("Use SetUniform()")] - public void SetParameter(string name, CurrentTextureType current) - { - sfShader_setCurrentTextureParameter(CPointer, name); - } + public void SetParameter(string name, CurrentTextureType current) => sfShader_setCurrentTextureParameter(CPointer, name); //////////////////////////////////////////////////////////// /// @@ -664,10 +589,7 @@ public void SetParameter(string name, CurrentTextureType current) /// /// Shader to bind (can be null to use no shader) //////////////////////////////////////////////////////////// - public static void Bind(Shader shader) - { - sfShader_bind(shader != null ? shader.CPointer : IntPtr.Zero); - } + public static void Bind(Shader shader) => sfShader_bind(shader != null ? shader.CPointer : IntPtr.Zero); //////////////////////////////////////////////////////////// /// @@ -680,10 +602,7 @@ public static void Bind(Shader shader) /// any attempt to use Shader will fail. /// //////////////////////////////////////////////////////////// - public static bool IsAvailable - { - get { return sfShader_isAvailable(); } - } + public static bool IsAvailable => sfShader_isAvailable(); //////////////////////////////////////////////////////////// /// @@ -699,10 +618,7 @@ public static bool IsAvailable /// code or SFML will result in a context switch. /// //////////////////////////////////////////////////////////// - public static bool IsGeometryAvailable - { - get { return sfShader_isGeometryAvailable(); } - } + public static bool IsGeometryAvailable => sfShader_isGeometryAvailable(); //////////////////////////////////////////////////////////// /// @@ -713,7 +629,9 @@ public static bool IsGeometryAvailable public override string ToString() { if (IsInvalid) + { return MakeDisposedObjectString(); + } return "[Shader]"; } @@ -728,15 +646,15 @@ protected override void Destroy(bool disposing) { if (!disposing) { - Context.Global.SetActive(true); + _ = Context.Global.SetActive(true); } - myTextures.Clear(); + _textures.Clear(); sfShader_destroy(CPointer); if (!disposing) { - Context.Global.SetActive(false); + _ = Context.Global.SetActive(false); } } @@ -752,124 +670,124 @@ public Shader(IntPtr ptr) : } // Keeps references to used Textures for GC prevention during use - private Dictionary myTextures = new Dictionary(); + private readonly Dictionary _textures = new Dictionary(); #region Imports - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfShader_createFromFile(string vertexShaderFilename, string geometryShaderFilename, string fragmentShaderFilename); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfShader_createFromMemory(string vertexShader, string geometryShader, string fragmentShader); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfShader_createFromStream(IntPtr vertexShaderStream, IntPtr geometryShaderStream, IntPtr fragmentShaderStream); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfShader_destroy(IntPtr shader); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfShader_setFloatUniform(IntPtr shader, string name, float x); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfShader_setVec2Uniform(IntPtr shader, string name, Glsl.Vec2 vector); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfShader_setVec3Uniform(IntPtr shader, string name, Glsl.Vec3 vector); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfShader_setVec4Uniform(IntPtr shader, string name, Glsl.Vec4 vector); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfShader_setIntUniform(IntPtr shader, string name, int x); - - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfShader_setColorUniform(IntPtr shader, string name, Color color); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfShader_setIvec2Uniform(IntPtr shader, string name, Glsl.Ivec2 vector); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfShader_setIvec3Uniform(IntPtr shader, string name, Glsl.Ivec3 vector); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfShader_setIvec4Uniform(IntPtr shader, string name, Glsl.Ivec4 vector); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfShader_setBoolUniform(IntPtr shader, string name, bool x); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfShader_setBvec2Uniform(IntPtr shader, string name, Glsl.Bvec2 vector); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfShader_setBvec3Uniform(IntPtr shader, string name, Glsl.Bvec3 vector); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfShader_setBvec4Uniform(IntPtr shader, string name, Glsl.Bvec4 vector); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfShader_setMat3Uniform(IntPtr shader, string name, Glsl.Mat3 matrix); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfShader_setMat4Uniform(IntPtr shader, string name, Glsl.Mat4 matrix); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfShader_setTextureUniform(IntPtr shader, string name, IntPtr texture); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfShader_setCurrentTextureUniform(IntPtr shader, string name); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern unsafe void sfShader_setFloatUniformArray(IntPtr shader, string name, float* data, UIntPtr length); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern unsafe void sfShader_setVec2UniformArray(IntPtr shader, string name, Glsl.Vec2* data, UIntPtr length); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern unsafe void sfShader_setVec3UniformArray(IntPtr shader, string name, Glsl.Vec3* data, UIntPtr length); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern unsafe void sfShader_setVec4UniformArray(IntPtr shader, string name, Glsl.Vec4* data, UIntPtr length); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern unsafe void sfShader_setMat3UniformArray(IntPtr shader, string name, Glsl.Mat3* data, UIntPtr length); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern unsafe void sfShader_setMat4UniformArray(IntPtr shader, string name, Glsl.Mat4* data, UIntPtr length); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity, Obsolete] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity, Obsolete] private static extern void sfShader_setFloatParameter(IntPtr shader, string name, float x); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity, Obsolete] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity, Obsolete] private static extern void sfShader_setFloat2Parameter(IntPtr shader, string name, float x, float y); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity, Obsolete] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity, Obsolete] private static extern void sfShader_setFloat3Parameter(IntPtr shader, string name, float x, float y, float z); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity, Obsolete] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity, Obsolete] private static extern void sfShader_setFloat4Parameter(IntPtr shader, string name, float x, float y, float z, float w); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity, Obsolete] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity, Obsolete] private static extern void sfShader_setColorParameter(IntPtr shader, string name, Color color); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity, Obsolete] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity, Obsolete] private static extern void sfShader_setTransformParameter(IntPtr shader, string name, Transform transform); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity, Obsolete] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity, Obsolete] private static extern void sfShader_setTextureParameter(IntPtr shader, string name, IntPtr texture); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity, Obsolete] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity, Obsolete] private static extern void sfShader_setCurrentTextureParameter(IntPtr shader, string name); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern uint sfShader_getNativeHandle(IntPtr shader); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfShader_bind(IntPtr shader); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern bool sfShader_isAvailable(); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern bool sfShader_isGeometryAvailable(); #endregion } diff --git a/src/SFML.Graphics/Shape.cs b/src/SFML.Graphics/Shape.cs index e5382a1b..a0429839 100644 --- a/src/SFML.Graphics/Shape.cs +++ b/src/SFML.Graphics/Shape.cs @@ -10,7 +10,7 @@ namespace SFML.Graphics /// Base class for textured shapes with outline /// //////////////////////////////////////////////////////////// - public abstract class Shape : Transformable, Drawable + public abstract class Shape : Transformable, IDrawable { //////////////////////////////////////////////////////////// /// @@ -19,8 +19,8 @@ public abstract class Shape : Transformable, Drawable //////////////////////////////////////////////////////////// public Texture Texture { - get { return myTexture; } - set { myTexture = value; sfShape_setTexture(CPointer, value != null ? value.CPointer : IntPtr.Zero, false); } + get => _texture; + set { _texture = value; sfShape_setTexture(CPointer, value != null ? value.CPointer : IntPtr.Zero, false); } } //////////////////////////////////////////////////////////// @@ -30,8 +30,8 @@ public Texture Texture //////////////////////////////////////////////////////////// public IntRect TextureRect { - get { return sfShape_getTextureRect(CPointer); } - set { sfShape_setTextureRect(CPointer, value); } + get => sfShape_getTextureRect(CPointer); + set => sfShape_setTextureRect(CPointer, value); } //////////////////////////////////////////////////////////// @@ -41,8 +41,8 @@ public IntRect TextureRect //////////////////////////////////////////////////////////// public Color FillColor { - get { return sfShape_getFillColor(CPointer); } - set { sfShape_setFillColor(CPointer, value); } + get => sfShape_getFillColor(CPointer); + set => sfShape_setFillColor(CPointer, value); } //////////////////////////////////////////////////////////// @@ -52,8 +52,8 @@ public Color FillColor //////////////////////////////////////////////////////////// public Color OutlineColor { - get { return sfShape_getOutlineColor(CPointer); } - set { sfShape_setOutlineColor(CPointer, value); } + get => sfShape_getOutlineColor(CPointer); + set => sfShape_setOutlineColor(CPointer, value); } //////////////////////////////////////////////////////////// @@ -63,8 +63,8 @@ public Color OutlineColor //////////////////////////////////////////////////////////// public float OutlineThickness { - get { return sfShape_getOutlineThickness(CPointer); } - set { sfShape_setOutlineThickness(CPointer, value); } + get => sfShape_getOutlineThickness(CPointer); + set => sfShape_setOutlineThickness(CPointer, value); } //////////////////////////////////////////////////////////// @@ -101,10 +101,7 @@ public float OutlineThickness /// /// Local bounding rectangle of the entity //////////////////////////////////////////////////////////// - public FloatRect GetLocalBounds() - { - return sfShape_getLocalBounds(CPointer); - } + public FloatRect GetLocalBounds() => sfShape_getLocalBounds(CPointer); //////////////////////////////////////////////////////////// /// @@ -118,12 +115,10 @@ public FloatRect GetLocalBounds() /// /// Global bounding rectangle of the entity //////////////////////////////////////////////////////////// - public FloatRect GetGlobalBounds() - { + public FloatRect GetGlobalBounds() => // we don't use the native getGlobalBounds function, // because we override the object's transform - return Transform.TransformRect(GetLocalBounds()); - } + Transform.TransformRect(GetLocalBounds()); //////////////////////////////////////////////////////////// /// @@ -132,18 +127,18 @@ public FloatRect GetGlobalBounds() /// Render target to draw to /// Current render states //////////////////////////////////////////////////////////// - public void Draw(RenderTarget target, RenderStates states) + public void Draw(IRenderTarget target, RenderStates states) { states.Transform *= Transform; - RenderStates.MarshalData marshaledStates = states.Marshal(); + var marshaledStates = states.Marshal(); - if (target is RenderWindow) + if (target is RenderWindow window) { - sfRenderWindow_drawShape(( (RenderWindow)target ).CPointer, CPointer, ref marshaledStates); + sfRenderWindow_drawShape(window.CPointer, CPointer, ref marshaledStates); } - else if (target is RenderTexture) + else if (target is RenderTexture texture) { - sfRenderTexture_drawShape(( (RenderTexture)target ).CPointer, CPointer, ref marshaledStates); + sfRenderTexture_drawShape(texture.CPointer, CPointer, ref marshaledStates); } } @@ -155,9 +150,9 @@ public void Draw(RenderTarget target, RenderStates states) protected Shape() : base(IntPtr.Zero) { - myGetPointCountCallback = new GetPointCountCallbackType(InternalGetPointCount); - myGetPointCallback = new GetPointCallbackType(InternalGetPoint); - CPointer = sfShape_create(myGetPointCountCallback, myGetPointCallback, IntPtr.Zero); + _getPointCountCallback = new GetPointCountCallbackType(InternalGetPointCount); + _getPointCallback = new GetPointCallbackType(InternalGetPoint); + CPointer = sfShape_create(_getPointCountCallback, _getPointCallback, IntPtr.Zero); } //////////////////////////////////////////////////////////// @@ -169,9 +164,9 @@ protected Shape() : public Shape(Shape copy) : base(IntPtr.Zero) { - myGetPointCountCallback = new GetPointCountCallbackType(InternalGetPointCount); - myGetPointCallback = new GetPointCallbackType(InternalGetPoint); - CPointer = sfShape_create(myGetPointCountCallback, myGetPointCallback, IntPtr.Zero); + _getPointCountCallback = new GetPointCountCallbackType(InternalGetPointCount); + _getPointCallback = new GetPointCallbackType(InternalGetPoint); + CPointer = sfShape_create(_getPointCountCallback, _getPointCallback, IntPtr.Zero); Origin = copy.Origin; Position = copy.Position; @@ -194,10 +189,7 @@ public Shape(Shape copy) : /// PointCount or GetPoint is different). /// //////////////////////////////////////////////////////////// - protected void Update() - { - sfShape_update(CPointer); - } + protected void Update() => sfShape_update(CPointer); //////////////////////////////////////////////////////////// /// @@ -205,87 +197,78 @@ protected void Update() /// /// Is the GC disposing the object, or is it an explicit call ? //////////////////////////////////////////////////////////// - protected override void Destroy(bool disposing) - { - sfShape_destroy(CPointer); - } + protected override void Destroy(bool disposing) => sfShape_destroy(CPointer); //////////////////////////////////////////////////////////// /// /// Callback passed to the C API /// //////////////////////////////////////////////////////////// - private UIntPtr InternalGetPointCount(IntPtr userData) - { - return (UIntPtr)GetPointCount(); - } + private UIntPtr InternalGetPointCount(IntPtr userData) => (UIntPtr)GetPointCount(); //////////////////////////////////////////////////////////// /// /// Callback passed to the C API /// //////////////////////////////////////////////////////////// - private Vector2f InternalGetPoint(UIntPtr index, IntPtr userData) - { - return GetPoint((uint)index); - } + private Vector2f InternalGetPoint(UIntPtr index, IntPtr userData) => GetPoint((uint)index); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate UIntPtr GetPointCountCallbackType(IntPtr UserData); + private delegate UIntPtr GetPointCountCallbackType(IntPtr userData); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate Vector2f GetPointCallbackType(UIntPtr index, IntPtr UserData); + private delegate Vector2f GetPointCallbackType(UIntPtr index, IntPtr userData); - private readonly GetPointCountCallbackType myGetPointCountCallback; - private readonly GetPointCallbackType myGetPointCallback; + private readonly GetPointCountCallbackType _getPointCountCallback; + private readonly GetPointCallbackType _getPointCallback; - private Texture myTexture = null; + private Texture _texture; #region Imports - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfShape_create(GetPointCountCallbackType getPointCount, GetPointCallbackType getPoint, IntPtr userData); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfShape_destroy(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfShape_destroy(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfShape_setTexture(IntPtr CPointer, IntPtr Texture, bool AdjustToNewSize); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfShape_setTexture(IntPtr cPointer, IntPtr texture, bool adjustToNewSize); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfShape_setTextureRect(IntPtr CPointer, IntRect Rect); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfShape_setTextureRect(IntPtr cPointer, IntRect rect); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntRect sfShape_getTextureRect(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntRect sfShape_getTextureRect(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfShape_setFillColor(IntPtr CPointer, Color Color); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfShape_setFillColor(IntPtr cPointer, Color color); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Color sfShape_getFillColor(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Color sfShape_getFillColor(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfShape_setOutlineColor(IntPtr CPointer, Color Color); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfShape_setOutlineColor(IntPtr cPointer, Color color); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Color sfShape_getOutlineColor(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Color sfShape_getOutlineColor(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfShape_setOutlineThickness(IntPtr CPointer, float Thickness); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfShape_setOutlineThickness(IntPtr cPointer, float thickness); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern float sfShape_getOutlineThickness(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern float sfShape_getOutlineThickness(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern FloatRect sfShape_getLocalBounds(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern FloatRect sfShape_getLocalBounds(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfShape_update(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfShape_update(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderWindow_drawShape(IntPtr CPointer, IntPtr Shape, ref RenderStates.MarshalData states); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderWindow_drawShape(IntPtr cPointer, IntPtr shape, ref RenderStates.MarshalData states); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderTexture_drawShape(IntPtr CPointer, IntPtr Shape, ref RenderStates.MarshalData states); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderTexture_drawShape(IntPtr cPointer, IntPtr shape, ref RenderStates.MarshalData states); #endregion } } diff --git a/src/SFML.Graphics/Sprite.cs b/src/SFML.Graphics/Sprite.cs index f5d302c0..c74cf4a0 100644 --- a/src/SFML.Graphics/Sprite.cs +++ b/src/SFML.Graphics/Sprite.cs @@ -14,7 +14,7 @@ namespace SFML.Graphics /// See also the note on coordinates and undistorted rendering in SFML.Graphics.Transformable. /// //////////////////////////////////////////////////////////// - public class Sprite : Transformable, Drawable + public class Sprite : Transformable, IDrawable { //////////////////////////////////////////////////////////// /// @@ -33,10 +33,7 @@ public Sprite() : /// Source texture to assign to the sprite //////////////////////////////////////////////////////////// public Sprite(Texture texture) : - base(sfSprite_create()) - { - Texture = texture; - } + base(sfSprite_create()) => Texture = texture; //////////////////////////////////////////////////////////// /// @@ -75,8 +72,8 @@ public Sprite(Sprite copy) : //////////////////////////////////////////////////////////// public Color Color { - get { return sfSprite_getColor(CPointer); } - set { sfSprite_setColor(CPointer, value); } + get => sfSprite_getColor(CPointer); + set => sfSprite_setColor(CPointer, value); } //////////////////////////////////////////////////////////// @@ -86,8 +83,8 @@ public Color Color //////////////////////////////////////////////////////////// public Texture Texture { - get { return myTexture; } - set { myTexture = value; sfSprite_setTexture(CPointer, value != null ? value.CPointer : IntPtr.Zero, false); } + get => _texture; + set { _texture = value; sfSprite_setTexture(CPointer, value != null ? value.CPointer : IntPtr.Zero, false); } } //////////////////////////////////////////////////////////// @@ -97,8 +94,8 @@ public Texture Texture //////////////////////////////////////////////////////////// public IntRect TextureRect { - get { return sfSprite_getTextureRect(CPointer); } - set { sfSprite_setTextureRect(CPointer, value); } + get => sfSprite_getTextureRect(CPointer); + set => sfSprite_setTextureRect(CPointer, value); } //////////////////////////////////////////////////////////// @@ -113,10 +110,7 @@ public IntRect TextureRect /// /// Local bounding rectangle of the entity //////////////////////////////////////////////////////////// - public FloatRect GetLocalBounds() - { - return sfSprite_getLocalBounds(CPointer); - } + public FloatRect GetLocalBounds() => sfSprite_getLocalBounds(CPointer); //////////////////////////////////////////////////////////// /// @@ -130,12 +124,10 @@ public FloatRect GetLocalBounds() /// /// Global bounding rectangle of the entity //////////////////////////////////////////////////////////// - public FloatRect GetGlobalBounds() - { + public FloatRect GetGlobalBounds() => // we don't use the native getGlobalBounds function, // because we override the object's transform - return Transform.TransformRect(GetLocalBounds()); - } + Transform.TransformRect(GetLocalBounds()); //////////////////////////////////////////////////////////// /// @@ -146,7 +138,9 @@ public FloatRect GetGlobalBounds() public override string ToString() { if (IsInvalid) + { return MakeDisposedObjectString(); + } return $"[Sprite] Color({Color}) Texture({Texture}) TextureRect({TextureRect})"; } @@ -158,18 +152,18 @@ public override string ToString() /// Render target to draw to /// Current render states //////////////////////////////////////////////////////////// - public void Draw(RenderTarget target, RenderStates states) + public void Draw(IRenderTarget target, RenderStates states) { states.Transform *= Transform; - RenderStates.MarshalData marshaledStates = states.Marshal(); + var marshaledStates = states.Marshal(); - if (target is RenderWindow) + if (target is RenderWindow window) { - sfRenderWindow_drawSprite(( (RenderWindow)target ).CPointer, CPointer, ref marshaledStates); + sfRenderWindow_drawSprite(window.CPointer, CPointer, ref marshaledStates); } - else if (target is RenderTexture) + else if (target is RenderTexture texture) { - sfRenderTexture_drawSprite(( (RenderTexture)target ).CPointer, CPointer, ref marshaledStates); + sfRenderTexture_drawSprite(texture.CPointer, CPointer, ref marshaledStates); } } @@ -179,47 +173,44 @@ public void Draw(RenderTarget target, RenderStates states) /// /// Is the GC disposing the object, or is it an explicit call ? //////////////////////////////////////////////////////////// - protected override void Destroy(bool disposing) - { - sfSprite_destroy(CPointer); - } + protected override void Destroy(bool disposing) => sfSprite_destroy(CPointer); - private Texture myTexture = null; + private Texture _texture; #region Imports - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfSprite_create(); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfSprite_copy(IntPtr Sprite); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfSprite_copy(IntPtr sprite); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSprite_destroy(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSprite_destroy(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSprite_setColor(IntPtr CPointer, Color Color); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSprite_setColor(IntPtr cPointer, Color color); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Color sfSprite_getColor(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Color sfSprite_getColor(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderWindow_drawSprite(IntPtr CPointer, IntPtr Sprite, ref RenderStates.MarshalData states); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderWindow_drawSprite(IntPtr cPointer, IntPtr sprite, ref RenderStates.MarshalData states); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderTexture_drawSprite(IntPtr CPointer, IntPtr Sprite, ref RenderStates.MarshalData states); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderTexture_drawSprite(IntPtr cPointer, IntPtr sprite, ref RenderStates.MarshalData states); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSprite_setTexture(IntPtr CPointer, IntPtr Texture, bool AdjustToNewSize); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSprite_setTexture(IntPtr cPointer, IntPtr texture, bool adjustToNewSize); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSprite_setTextureRect(IntPtr CPointer, IntRect Rect); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSprite_setTextureRect(IntPtr cPointer, IntRect rect); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntRect sfSprite_getTextureRect(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntRect sfSprite_getTextureRect(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern FloatRect sfSprite_getLocalBounds(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern FloatRect sfSprite_getLocalBounds(IntPtr cPointer); #endregion } } diff --git a/src/SFML.Graphics/Text.cs b/src/SFML.Graphics/Text.cs index bc4da59a..b6e2f612 100644 --- a/src/SFML.Graphics/Text.cs +++ b/src/SFML.Graphics/Text.cs @@ -14,7 +14,7 @@ namespace SFML.Graphics /// See also the note on coordinates and undistorted rendering in SFML.Graphics.Transformable. /// //////////////////////////////////////////////////////////// - public class Text : Transformable, Drawable + public class Text : Transformable, IDrawable { //////////////////////////////////////////////////////////// /// @@ -113,8 +113,8 @@ public Text(Text copy) : [Obsolete("Use FillColor and OutlineColor")] public Color Color { - get { return sfText_getFillColor(CPointer); } - set { sfText_setFillColor(CPointer, value); } + get => sfText_getFillColor(CPointer); + set => sfText_setFillColor(CPointer, value); } //////////////////////////////////////////////////////////// @@ -132,8 +132,8 @@ public Color Color //////////////////////////////////////////////////////////// public Color FillColor { - get { return sfText_getFillColor(CPointer); } - set { sfText_setFillColor(CPointer, value); } + get => sfText_getFillColor(CPointer); + set => sfText_setFillColor(CPointer, value); } //////////////////////////////////////////////////////////// @@ -147,8 +147,8 @@ public Color FillColor //////////////////////////////////////////////////////////// public Color OutlineColor { - get { return sfText_getOutlineColor(CPointer); } - set { sfText_setOutlineColor(CPointer, value); } + get => sfText_getOutlineColor(CPointer); + set => sfText_setOutlineColor(CPointer, value); } //////////////////////////////////////////////////////////// @@ -164,8 +164,8 @@ public Color OutlineColor //////////////////////////////////////////////////////////// public float OutlineThickness { - get { return sfText_getOutlineThickness(CPointer); } - set { sfText_setOutlineThickness(CPointer, value); } + get => sfText_getOutlineThickness(CPointer); + set => sfText_setOutlineThickness(CPointer, value); } //////////////////////////////////////////////////////////// @@ -178,20 +178,20 @@ public string DisplayedString get { // Get a pointer to the source string (UTF-32) - IntPtr source = sfText_getUnicodeString(CPointer); + var source = sfText_getUnicodeString(CPointer); // Find its length (find the terminating 0) uint length = 0; unsafe { - for (uint* ptr = (uint*)source.ToPointer(); *ptr != 0; ++ptr) + for (var ptr = (uint*)source.ToPointer(); *ptr != 0; ++ptr) { length++; } } // Copy it to a byte array - byte[] sourceBytes = new byte[length * 4]; + var sourceBytes = new byte[length * 4]; Marshal.Copy(source, sourceBytes, 0, sourceBytes.Length); // Convert it to a C# string @@ -201,7 +201,7 @@ public string DisplayedString set { // Copy the string to a null-terminated UTF-32 byte array - byte[] utf32 = Encoding.UTF32.GetBytes(value + '\0'); + var utf32 = Encoding.UTF32.GetBytes(value + '\0'); // Pass it to the C API unsafe @@ -221,8 +221,8 @@ public string DisplayedString //////////////////////////////////////////////////////////// public Font Font { - get { return myFont; } - set { myFont = value; sfText_setFont(CPointer, value != null ? value.CPointer : IntPtr.Zero); } + get => _font; + set { _font = value; sfText_setFont(CPointer, value != null ? value.CPointer : IntPtr.Zero); } } //////////////////////////////////////////////////////////// @@ -232,8 +232,8 @@ public Font Font //////////////////////////////////////////////////////////// public uint CharacterSize { - get { return sfText_getCharacterSize(CPointer); } - set { sfText_setCharacterSize(CPointer, value); } + get => sfText_getCharacterSize(CPointer); + set => sfText_setCharacterSize(CPointer, value); } //////////////////////////////////////////////////////////// @@ -243,8 +243,8 @@ public uint CharacterSize //////////////////////////////////////////////////////////// public float LetterSpacing { - get { return sfText_getLetterSpacing(CPointer); } - set { sfText_setLetterSpacing(CPointer, value); } + get => sfText_getLetterSpacing(CPointer); + set => sfText_setLetterSpacing(CPointer, value); } //////////////////////////////////////////////////////////// @@ -254,8 +254,8 @@ public float LetterSpacing //////////////////////////////////////////////////////////// public float LineSpacing { - get { return sfText_getLineSpacing(CPointer); } - set { sfText_setLineSpacing(CPointer, value); } + get => sfText_getLineSpacing(CPointer); + set => sfText_setLineSpacing(CPointer, value); } //////////////////////////////////////////////////////////// @@ -265,8 +265,8 @@ public float LineSpacing //////////////////////////////////////////////////////////// public Styles Style { - get { return sfText_getStyle(CPointer); } - set { sfText_setStyle(CPointer, value); } + get => sfText_getStyle(CPointer); + set => sfText_setStyle(CPointer, value); } //////////////////////////////////////////////////////////// @@ -280,10 +280,7 @@ public Styles Style /// Index of the character /// Position of the Index-th character (end of text if Index is out of range) //////////////////////////////////////////////////////////// - public Vector2f FindCharacterPos(uint index) - { - return sfText_findCharacterPos(CPointer, (UIntPtr)index); - } + public Vector2f FindCharacterPos(uint index) => sfText_findCharacterPos(CPointer, (UIntPtr)index); //////////////////////////////////////////////////////////// /// @@ -297,10 +294,7 @@ public Vector2f FindCharacterPos(uint index) /// /// Local bounding rectangle of the entity //////////////////////////////////////////////////////////// - public FloatRect GetLocalBounds() - { - return sfText_getLocalBounds(CPointer); - } + public FloatRect GetLocalBounds() => sfText_getLocalBounds(CPointer); //////////////////////////////////////////////////////////// /// @@ -314,12 +308,10 @@ public FloatRect GetLocalBounds() /// /// Global bounding rectangle of the entity //////////////////////////////////////////////////////////// - public FloatRect GetGlobalBounds() - { - // we don't use the native getGlobalBounds function, - // because we override the object's transform - return Transform.TransformRect(GetLocalBounds()); - } + public FloatRect GetGlobalBounds() => + // we don't use the native getGlobalBounds function, + // because we override the object's transform + Transform.TransformRect(GetLocalBounds()); //////////////////////////////////////////////////////////// /// @@ -330,8 +322,10 @@ public FloatRect GetGlobalBounds() public override string ToString() { if (IsInvalid) + { return MakeDisposedObjectString(); - + } + return "[Text]" + " FillColor(" + FillColor + ")" + " OutlineColor(" + OutlineColor + ")" + @@ -344,23 +338,23 @@ public override string ToString() //////////////////////////////////////////////////////////// /// - /// Draw the text to a + /// Draw the text to a /// /// Render target to draw to /// Current render states //////////////////////////////////////////////////////////// - public void Draw(RenderTarget target, RenderStates states) + public void Draw(IRenderTarget target, RenderStates states) { states.Transform *= Transform; - RenderStates.MarshalData marshaledStates = states.Marshal(); + var marshaledStates = states.Marshal(); - if (target is RenderWindow) + if (target is RenderWindow window) { - sfRenderWindow_drawText(( (RenderWindow)target ).CPointer, CPointer, ref marshaledStates); + sfRenderWindow_drawText(window.CPointer, CPointer, ref marshaledStates); } - else if (target is RenderTexture) + else if (target is RenderTexture texture) { - sfRenderTexture_drawText(( (RenderTexture)target ).CPointer, CPointer, ref marshaledStates); + sfRenderTexture_drawText(texture.CPointer, CPointer, ref marshaledStates); } } @@ -370,85 +364,82 @@ public void Draw(RenderTarget target, RenderStates states) /// /// Is the GC disposing the object, or is it an explicit call ? //////////////////////////////////////////////////////////// - protected override void Destroy(bool disposing) - { - sfText_destroy(CPointer); - } + protected override void Destroy(bool disposing) => sfText_destroy(CPointer); - private Font myFont = null; + private Font _font; #region Imports - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfText_create(); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfText_copy(IntPtr Text); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfText_copy(IntPtr text); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfText_destroy(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfText_destroy(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfText_setFillColor(IntPtr CPointer, Color Color); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfText_setFillColor(IntPtr cPointer, Color color); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfText_setOutlineColor(IntPtr CPointer, Color Color); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfText_setOutlineColor(IntPtr cPointer, Color color); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfText_setOutlineThickness(IntPtr CPointer, float thickness); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfText_setOutlineThickness(IntPtr cPointer, float thickness); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Color sfText_getFillColor(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Color sfText_getFillColor(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Color sfText_getOutlineColor(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Color sfText_getOutlineColor(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern float sfText_getOutlineThickness(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern float sfText_getOutlineThickness(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderWindow_drawText(IntPtr CPointer, IntPtr Text, ref RenderStates.MarshalData states); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderWindow_drawText(IntPtr cPointer, IntPtr text, ref RenderStates.MarshalData states); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderTexture_drawText(IntPtr CPointer, IntPtr Text, ref RenderStates.MarshalData states); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderTexture_drawText(IntPtr cPointer, IntPtr text, ref RenderStates.MarshalData states); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfText_setUnicodeString(IntPtr CPointer, IntPtr Text); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfText_setUnicodeString(IntPtr cPointer, IntPtr text); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfText_setFont(IntPtr CPointer, IntPtr Font); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfText_setFont(IntPtr cPointer, IntPtr font); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfText_setCharacterSize(IntPtr CPointer, uint Size); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfText_setCharacterSize(IntPtr cPointer, uint size); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfText_setLineSpacing(IntPtr CPointer, float spacingFactor); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfText_setLineSpacing(IntPtr cPointer, float spacingFactor); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfText_setLetterSpacing(IntPtr CPointer, float spacingFactor); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfText_setLetterSpacing(IntPtr cPointer, float spacingFactor); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfText_setStyle(IntPtr CPointer, Styles Style); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfText_setStyle(IntPtr cPointer, Styles style); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfText_getUnicodeString(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfText_getUnicodeString(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern uint sfText_getCharacterSize(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern uint sfText_getCharacterSize(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern float sfText_getLetterSpacing(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern float sfText_getLetterSpacing(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern float sfText_getLineSpacing(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern float sfText_getLineSpacing(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Styles sfText_getStyle(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Styles sfText_getStyle(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Vector2f sfText_findCharacterPos(IntPtr CPointer, UIntPtr Index); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Vector2f sfText_findCharacterPos(IntPtr cPointer, UIntPtr index); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern FloatRect sfText_getLocalBounds(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern FloatRect sfText_getLocalBounds(IntPtr cPointer); #endregion } } diff --git a/src/SFML.Graphics/Texture.cs b/src/SFML.Graphics/Texture.cs index 849bacf5..45d3bbbb 100644 --- a/src/SFML.Graphics/Texture.cs +++ b/src/SFML.Graphics/Texture.cs @@ -1,7 +1,6 @@ using System; using System.IO; using System.Runtime.InteropServices; -using System.Runtime.InteropServices.ComTypes; using System.Security; using SFML.System; using SFML.Window; @@ -123,7 +122,7 @@ public Texture(Stream stream, bool srgb = false) : public Texture(Stream stream, IntRect area, bool srgb = false) : base(IntPtr.Zero) { - using (StreamAdaptor adaptor = new StreamAdaptor(stream)) + using (var adaptor = new StreamAdaptor(stream)) { if (srgb) { @@ -206,7 +205,7 @@ public Texture(byte[] bytes, bool srgb = false) : public Texture(byte[] bytes, IntRect area, bool srgb = false) : base(IntPtr.Zero) { - GCHandle pin = GCHandle.Alloc(bytes, GCHandleType.Pinned); + var pin = GCHandle.Alloc(bytes, GCHandleType.Pinned); try { if (srgb) @@ -216,7 +215,7 @@ public Texture(byte[] bytes, IntRect area, bool srgb = false) : else { CPointer = sfTexture_createFromMemory(pin.AddrOfPinnedObject(), (UIntPtr)bytes.Length, ref area); - } + } } finally { @@ -250,10 +249,7 @@ public Texture(Texture copy) : /// or implement a temporary workaround until a bug is fixed. /// //////////////////////////////////////////////////////////// - public uint NativeHandle - { - get { return sfTexture_getNativeHandle(CPointer); } - } + public uint NativeHandle => sfTexture_getNativeHandle(CPointer); //////////////////////////////////////////////////////////// /// @@ -261,10 +257,7 @@ public uint NativeHandle /// /// Image containing the texture's pixels //////////////////////////////////////////////////////////// - public Image CopyToImage() - { - return new Image(sfTexture_copyToImage(CPointer)); - } + public Image CopyToImage() => new Image(sfTexture_copyToImage(CPointer)); //////////////////////////////////////////////////////////// /// @@ -274,7 +267,7 @@ public Image CopyToImage() //////////////////////////////////////////////////////////// public void Update(byte[] pixels) { - Vector2u size = Size; + var size = Size; Update(pixels, size.X, size.Y, 0, 0); } @@ -307,10 +300,7 @@ public void Update(byte[] pixels, uint width, uint height, uint x, uint y) /// X offset in this texture where to copy the source texture /// Y offset in this texture where to copy the source texture //////////////////////////////////////////////////////////// - public void Update(Texture texture, uint x, uint y) - { - sfTexture_updateFromTexture(CPointer, texture.CPointer, x, y); - } + public void Update(Texture texture, uint x, uint y) => sfTexture_updateFromTexture(CPointer, texture.CPointer, x, y); //////////////////////////////////////////////////////////// /// @@ -318,10 +308,7 @@ public void Update(Texture texture, uint x, uint y) /// /// Image to copy to the texture //////////////////////////////////////////////////////////// - public void Update(Image image) - { - Update(image, 0, 0); - } + public void Update(Image image) => Update(image, 0, 0); //////////////////////////////////////////////////////////// /// @@ -331,10 +318,7 @@ public void Update(Image image) /// X offset in the texture where to copy the source pixels /// Y offset in the texture where to copy the source pixels //////////////////////////////////////////////////////////// - public void Update(Image image, uint x, uint y) - { - sfTexture_updateFromImage(CPointer, image.CPointer, x, y); - } + public void Update(Image image, uint x, uint y) => sfTexture_updateFromImage(CPointer, image.CPointer, x, y); //////////////////////////////////////////////////////////// /// @@ -342,10 +326,7 @@ public void Update(Image image, uint x, uint y) /// /// Window to copy to the texture //////////////////////////////////////////////////////////// - public void Update(SFML.Window.Window window) - { - Update(window, 0, 0); - } + public void Update(SFML.Window.Window window) => Update(window, 0, 0); //////////////////////////////////////////////////////////// /// @@ -355,10 +336,7 @@ public void Update(SFML.Window.Window window) /// X offset in the texture where to copy the source pixels /// Y offset in the texture where to copy the source pixels //////////////////////////////////////////////////////////// - public void Update(SFML.Window.Window window, uint x, uint y) - { - sfTexture_updateFromWindow(CPointer, window.CPointer, x, y); - } + public void Update(SFML.Window.Window window, uint x, uint y) => sfTexture_updateFromWindow(CPointer, window.CPointer, x, y); //////////////////////////////////////////////////////////// /// @@ -366,10 +344,7 @@ public void Update(SFML.Window.Window window, uint x, uint y) /// /// Render-window to copy to the texture //////////////////////////////////////////////////////////// - public void Update(RenderWindow window) - { - Update(window, 0, 0); - } + public void Update(RenderWindow window) => Update(window, 0, 0); //////////////////////////////////////////////////////////// /// @@ -379,10 +354,7 @@ public void Update(RenderWindow window) /// X offset in the texture where to copy the source pixels /// Y offset in the texture where to copy the source pixels //////////////////////////////////////////////////////////// - public void Update(RenderWindow window, uint x, uint y) - { - sfTexture_updateFromRenderWindow(CPointer, window.CPointer, x, y); - } + public void Update(RenderWindow window, uint x, uint y) => sfTexture_updateFromRenderWindow(CPointer, window.CPointer, x, y); //////////////////////////////////////////////////////////// /// @@ -410,10 +382,7 @@ public void Update(RenderWindow window, uint x, uint y) /// /// True if mipmap generation was successful, false if unsuccessful //////////////////////////////////////////////////////////// - public bool GenerateMipmap() - { - return sfTexture_generateMipmap(CPointer); - } + public bool GenerateMipmap() => sfTexture_generateMipmap(CPointer); //////////////////////////////////////////////////////////// /// @@ -421,10 +390,7 @@ public bool GenerateMipmap() /// /// Instance to swap with //////////////////////////////////////////////////////////// - public void Swap(Texture right) - { - sfTexture_swap(CPointer, right.CPointer); - } + public void Swap(Texture right) => sfTexture_swap(CPointer, right.CPointer); //////////////////////////////////////////////////////////// /// @@ -433,8 +399,8 @@ public void Swap(Texture right) //////////////////////////////////////////////////////////// public bool Smooth { - get { return sfTexture_isSmooth(CPointer); } - set { sfTexture_setSmooth(CPointer, value); } + get => sfTexture_isSmooth(CPointer); + set => sfTexture_setSmooth(CPointer, value); } //////////////////////////////////////////////////////////// @@ -459,10 +425,7 @@ public bool Smooth /// framebuffer. This can be requested during window creation. /// //////////////////////////////////////////////////////////// - public bool Srgb - { - get { return sfTexture_isSrgb(CPointer); } - } + public bool Srgb => sfTexture_isSrgb(CPointer); //////////////////////////////////////////////////////////// /// @@ -471,8 +434,8 @@ public bool Srgb //////////////////////////////////////////////////////////// public bool Repeated { - get { return sfTexture_isRepeated(CPointer); } - set { sfTexture_setRepeated(CPointer, value); } + get => sfTexture_isRepeated(CPointer); + set => sfTexture_setRepeated(CPointer, value); } //////////////////////////////////////////////////////////// @@ -480,10 +443,7 @@ public bool Repeated /// Size of the texture, in pixels /// //////////////////////////////////////////////////////////// - public Vector2u Size - { - get { return sfTexture_getSize(CPointer); } - } + public Vector2u Size => sfTexture_getSize(CPointer); //////////////////////////////////////////////////////////// /// @@ -492,20 +452,14 @@ public Vector2u Size /// Shader to bind (can be null to use no texture) /// Type of texture coordinates to use //////////////////////////////////////////////////////////// - public static void Bind(Texture texture, TextureCoordinateType type) - { - sfTexture_bind(texture != null ? texture.CPointer : IntPtr.Zero, type); - } + public static void Bind(Texture texture, TextureCoordinateType type) => sfTexture_bind(texture != null ? texture.CPointer : IntPtr.Zero, type); //////////////////////////////////////////////////////////// /// /// Maximum texture size allowed /// //////////////////////////////////////////////////////////// - public static uint MaximumSize - { - get { return sfTexture_getMaximumSize(); } - } + public static uint MaximumSize => sfTexture_getMaximumSize(); //////////////////////////////////////////////////////////// /// @@ -516,7 +470,9 @@ public static uint MaximumSize public override string ToString() { if (IsInvalid) + { return MakeDisposedObjectString(); + } return "[Texture]" + " Size(" + Size + ")" + @@ -531,10 +487,7 @@ public override string ToString() /// Pointer to the object in C library //////////////////////////////////////////////////////////// internal Texture(IntPtr cPointer) : - base(cPointer) - { - myExternal = true; - } + base(cPointer) => _external = true; //////////////////////////////////////////////////////////// /// @@ -544,107 +497,107 @@ internal Texture(IntPtr cPointer) : //////////////////////////////////////////////////////////// protected override void Destroy(bool disposing) { - if (!myExternal) + if (!_external) { if (!disposing) { - Context.Global.SetActive(true); + _ = Context.Global.SetActive(true); } sfTexture_destroy(CPointer); if (!disposing) { - Context.Global.SetActive(false); + _ = Context.Global.SetActive(false); } } } - private readonly bool myExternal = false; + private readonly bool _external; #region Imports - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfTexture_create(uint width, uint height); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfTexture_createFromFile(string filename, ref IntRect area); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfTexture_createSrgbFromFile(string filename, ref IntRect area); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfTexture_createFromStream(IntPtr stream, ref IntRect area); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfTexture_createSrgbFromStream(IntPtr stream, ref IntRect area); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfTexture_createFromImage(IntPtr image, ref IntRect area); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfTexture_createSrgbFromImage(IntPtr image, ref IntRect area); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfTexture_createFromMemory(IntPtr data, UIntPtr size, ref IntRect area); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfTexture_createSrgbFromMemory(IntPtr data, UIntPtr size, ref IntRect area); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfTexture_copy(IntPtr texture); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfTexture_destroy(IntPtr texture); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern Vector2u sfTexture_getSize(IntPtr texture); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfTexture_copyToImage(IntPtr texture); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private unsafe static extern void sfTexture_updateFromPixels(IntPtr texture, byte* pixels, uint width, uint height, uint x, uint y); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern unsafe void sfTexture_updateFromPixels(IntPtr texture, byte* pixels, uint width, uint height, uint x, uint y); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfTexture_updateFromTexture(IntPtr CPointer, IntPtr texture, uint x, uint y); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfTexture_updateFromTexture(IntPtr cPointer, IntPtr texture, uint x, uint y); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfTexture_updateFromImage(IntPtr texture, IntPtr image, uint x, uint y); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfTexture_updateFromWindow(IntPtr texture, IntPtr window, uint x, uint y); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfTexture_updateFromRenderWindow(IntPtr texture, IntPtr renderWindow, uint x, uint y); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfTexture_bind(IntPtr texture, TextureCoordinateType type); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfTexture_setSmooth(IntPtr texture, bool smooth); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern bool sfTexture_isSmooth(IntPtr texture); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern bool sfTexture_isSrgb(IntPtr texture); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfTexture_setRepeated(IntPtr texture, bool repeated); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern bool sfTexture_isRepeated(IntPtr texture); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern bool sfTexture_generateMipmap(IntPtr texture); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfTexture_swap(IntPtr CPointer, IntPtr right); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfTexture_swap(IntPtr cPointer, IntPtr right); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern uint sfTexture_getNativeHandle(IntPtr shader); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern uint sfTexture_getMaximumSize(); #endregion } diff --git a/src/SFML.Graphics/Transform.cs b/src/SFML.Graphics/Transform.cs index aad4c3ea..b54a68b5 100644 --- a/src/SFML.Graphics/Transform.cs +++ b/src/SFML.Graphics/Transform.cs @@ -1,4 +1,3 @@ -using System; using System.Runtime.InteropServices; using System.Security; using SFML.System; @@ -31,15 +30,15 @@ public Transform(float a00, float a01, float a02, float a10, float a11, float a12, float a20, float a21, float a22) { - m00 = a00; - m01 = a01; - m02 = a02; - m10 = a10; - m11 = a11; - m12 = a12; - m20 = a20; - m21 = a21; - m22 = a22; + M00 = a00; + M01 = a01; + M02 = a02; + M10 = a10; + M11 = a11; + M12 = a12; + M20 = a20; + M21 = a21; + M22 = a22; } //////////////////////////////////////////////////////////// @@ -51,10 +50,7 @@ public Transform(float a00, float a01, float a02, /// /// A new transform which is the inverse of self //////////////////////////////////////////////////////////// - public Transform GetInverse() - { - return sfTransform_getInverse(ref this); - } + public Transform GetInverse() => sfTransform_getInverse(ref this); //////////////////////////////////////////////////////////// /// @@ -64,10 +60,7 @@ public Transform GetInverse() /// Y coordinate of the point to transform /// Transformed point //////////////////////////////////////////////////////////// - public Vector2f TransformPoint(float x, float y) - { - return TransformPoint(new Vector2f(x, y)); - } + public Vector2f TransformPoint(float x, float y) => TransformPoint(new Vector2f(x, y)); //////////////////////////////////////////////////////////// /// @@ -76,10 +69,7 @@ public Vector2f TransformPoint(float x, float y) /// Point to transform /// Transformed point //////////////////////////////////////////////////////////// - public Vector2f TransformPoint(Vector2f point) - { - return sfTransform_transformPoint(ref this, point); - } + public Vector2f TransformPoint(Vector2f point) => sfTransform_transformPoint(ref this, point); //////////////////////////////////////////////////////////// /// @@ -94,10 +84,7 @@ public Vector2f TransformPoint(Vector2f point) /// Rectangle to transform /// Transformed rectangle //////////////////////////////////////////////////////////// - public FloatRect TransformRect(FloatRect rectangle) - { - return sfTransform_transformRect(ref this, rectangle); - } + public FloatRect TransformRect(FloatRect rectangle) => sfTransform_transformRect(ref this, rectangle); //////////////////////////////////////////////////////////// /// @@ -109,10 +96,7 @@ public FloatRect TransformRect(FloatRect rectangle) /// /// Transform to combine to this transform //////////////////////////////////////////////////////////// - public void Combine(Transform transform) - { - sfTransform_combine(ref this, ref transform); - } + public void Combine(Transform transform) => sfTransform_combine(ref this, ref transform); //////////////////////////////////////////////////////////// /// @@ -121,10 +105,7 @@ public void Combine(Transform transform) /// Offset to apply on X axis /// Offset to apply on Y axis //////////////////////////////////////////////////////////// - public void Translate(float x, float y) - { - sfTransform_translate(ref this, x, y); - } + public void Translate(float x, float y) => sfTransform_translate(ref this, x, y); //////////////////////////////////////////////////////////// /// @@ -132,10 +113,7 @@ public void Translate(float x, float y) /// /// Translation offset to apply //////////////////////////////////////////////////////////// - public void Translate(Vector2f offset) - { - Translate(offset.X, offset.Y); - } + public void Translate(Vector2f offset) => Translate(offset.X, offset.Y); //////////////////////////////////////////////////////////// /// @@ -143,10 +121,7 @@ public void Translate(Vector2f offset) /// /// Rotation angle, in degrees //////////////////////////////////////////////////////////// - public void Rotate(float angle) - { - sfTransform_rotate(ref this, angle); - } + public void Rotate(float angle) => sfTransform_rotate(ref this, angle); //////////////////////////////////////////////////////////// /// @@ -161,10 +136,7 @@ public void Rotate(float angle) /// X coordinate of the center of rotation /// Y coordinate of the center of rotation //////////////////////////////////////////////////////////// - public void Rotate(float angle, float centerX, float centerY) - { - sfTransform_rotateWithCenter(ref this, angle, centerX, centerY); - } + public void Rotate(float angle, float centerX, float centerY) => sfTransform_rotateWithCenter(ref this, angle, centerX, centerY); //////////////////////////////////////////////////////////// /// @@ -178,10 +150,7 @@ public void Rotate(float angle, float centerX, float centerY) /// Rotation angle, in degrees /// Center of rotation //////////////////////////////////////////////////////////// - public void Rotate(float angle, Vector2f center) - { - Rotate(angle, center.X, center.Y); - } + public void Rotate(float angle, Vector2f center) => Rotate(angle, center.X, center.Y); //////////////////////////////////////////////////////////// /// @@ -190,10 +159,7 @@ public void Rotate(float angle, Vector2f center) /// Scaling factor on the X axis /// Scaling factor on the Y axis //////////////////////////////////////////////////////////// - public void Scale(float scaleX, float scaleY) - { - sfTransform_scale(ref this, scaleX, scaleY); - } + public void Scale(float scaleX, float scaleY) => sfTransform_scale(ref this, scaleX, scaleY); //////////////////////////////////////////////////////////// /// @@ -209,10 +175,7 @@ public void Scale(float scaleX, float scaleY) /// X coordinate of the center of scaling /// Y coordinate of the center of scaling //////////////////////////////////////////////////////////// - public void Scale(float scaleX, float scaleY, float centerX, float centerY) - { - sfTransform_scaleWithCenter(ref this, scaleX, scaleY, centerX, centerY); - } + public void Scale(float scaleX, float scaleY, float centerX, float centerY) => sfTransform_scaleWithCenter(ref this, scaleX, scaleY, centerX, centerY); //////////////////////////////////////////////////////////// /// @@ -220,10 +183,7 @@ public void Scale(float scaleX, float scaleY, float centerX, float centerY) /// /// Scaling factors //////////////////////////////////////////////////////////// - public void Scale(Vector2f factors) - { - Scale(factors.X, factors.Y); - } + public void Scale(Vector2f factors) => Scale(factors.X, factors.Y); //////////////////////////////////////////////////////////// /// @@ -237,10 +197,7 @@ public void Scale(Vector2f factors) /// Scaling factors /// Center of scaling //////////////////////////////////////////////////////////// - public void Scale(Vector2f factors, Vector2f center) - { - Scale(factors.X, factors.Y, center.X, center.Y); - } + public void Scale(Vector2f factors, Vector2f center) => Scale(factors.X, factors.Y, center.X, center.Y); //////////////////////////////////////////////////////////// /// @@ -261,10 +218,7 @@ public void Scale(Vector2f factors, Vector2f center) /// Transform to check /// Transforms are equal //////////////////////////////////////////////////////////// - public bool Equals(Transform transform) - { - return sfTransform_equal(ref this, ref transform); - } + public bool Equals(Transform transform) => sfTransform_equal(ref this, ref transform); //////////////////////////////////////////////////////////// /// @@ -274,10 +228,10 @@ public bool Equals(Transform transform) //////////////////////////////////////////////////////////// public override int GetHashCode() { - var hash0 = m00.GetHashCode() ^ m01.GetHashCode() ^ m02.GetHashCode(); - var hash1 = m10.GetHashCode() ^ m11.GetHashCode() ^ m12.GetHashCode(); - var hash2 = m20.GetHashCode() ^ m21.GetHashCode() ^ m22.GetHashCode(); - return (hash0 ^ hash1 ^ hash2); + var hash0 = M00.GetHashCode() ^ M01.GetHashCode() ^ M02.GetHashCode(); + var hash1 = M10.GetHashCode() ^ M11.GetHashCode() ^ M12.GetHashCode(); + var hash2 = M20.GetHashCode() ^ M21.GetHashCode() ^ M22.GetHashCode(); + return hash0 ^ hash1 ^ hash2; } //////////////////////////////////////////////////////////// @@ -304,23 +258,14 @@ public override int GetHashCode() /// Right operand (the point to transform) /// New transformed point //////////////////////////////////////////////////////////// - public static Vector2f operator *(Transform left, Vector2f right) - { - return left.TransformPoint(right); - } + public static Vector2f operator *(Transform left, Vector2f right) => left.TransformPoint(right); //////////////////////////////////////////////////////////// /// The identity transform (does nothing) //////////////////////////////////////////////////////////// - public static Transform Identity - { - get - { - return new Transform(1, 0, 0, + public static Transform Identity => new Transform(1, 0, 0, 0, 1, 0, 0, 0, 1); - } - } //////////////////////////////////////////////////////////// /// @@ -328,51 +273,48 @@ public static Transform Identity /// /// String description of the object //////////////////////////////////////////////////////////// - public override string ToString() - { - return string.Format("[Transform]" + + public override string ToString() => string.Format("[Transform]" + " Matrix(" + "{0}, {1}, {2}," + "{3}, {4}, {5}," + "{6}, {7}, {8}, )", - m00, m01, m02, - m10, m11, m12, - m20, m21, m22); - } + M00, M01, M02, + M10, M11, M12, + M20, M21, M22); - internal float m00, m01, m02; - internal float m10, m11, m12; - internal float m20, m21, m22; + internal float M00, M01, M02; + internal float M10, M11, M12; + internal float M20, M21, M22; #region Imports - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern Transform sfTransform_getInverse(ref Transform transform); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern Vector2f sfTransform_transformPoint(ref Transform transform, Vector2f point); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern FloatRect sfTransform_transformRect(ref Transform transform, FloatRect rectangle); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfTransform_combine(ref Transform transform, ref Transform other); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfTransform_translate(ref Transform transform, float x, float y); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfTransform_rotate(ref Transform transform, float angle); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfTransform_rotateWithCenter(ref Transform transform, float angle, float centerX, float centerY); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfTransform_scale(ref Transform transform, float scaleX, float scaleY); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfTransform_scaleWithCenter(ref Transform transform, float scaleX, float scaleY, float centerX, float centerY); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern bool sfTransform_equal(ref Transform left, ref Transform right); #endregion } diff --git a/src/SFML.Graphics/Transformable.cs b/src/SFML.Graphics/Transformable.cs index f62e156d..52510a3a 100644 --- a/src/SFML.Graphics/Transformable.cs +++ b/src/SFML.Graphics/Transformable.cs @@ -55,15 +55,12 @@ public Transformable(Transformable transformable) : //////////////////////////////////////////////////////////// public Vector2f Position { - get - { - return myPosition; - } + get => _position; set { - myPosition = value; - myTransformNeedUpdate = true; - myInverseNeedUpdate = true; + _position = value; + _transformNeedUpdate = true; + _inverseNeedUpdate = true; } } @@ -74,15 +71,12 @@ public Vector2f Position //////////////////////////////////////////////////////////// public float Rotation { - get - { - return myRotation; - } + get => _rotation; set { - myRotation = value; - myTransformNeedUpdate = true; - myInverseNeedUpdate = true; + _rotation = value; + _transformNeedUpdate = true; + _inverseNeedUpdate = true; } } @@ -93,15 +87,12 @@ public float Rotation //////////////////////////////////////////////////////////// public Vector2f Scale { - get - { - return myScale; - } + get => _scale; set { - myScale = value; - myTransformNeedUpdate = true; - myInverseNeedUpdate = true; + _scale = value; + _transformNeedUpdate = true; + _inverseNeedUpdate = true; } } @@ -116,15 +107,12 @@ public Vector2f Scale //////////////////////////////////////////////////////////// public Vector2f Origin { - get - { - return myOrigin; - } + get => _origin; set { - myOrigin = value; - myTransformNeedUpdate = true; - myInverseNeedUpdate = true; + _origin = value; + _transformNeedUpdate = true; + _inverseNeedUpdate = true; } } @@ -137,25 +125,25 @@ public Transform Transform { get { - if (myTransformNeedUpdate) + if (_transformNeedUpdate) { - myTransformNeedUpdate = false; + _transformNeedUpdate = false; - float angle = -myRotation * 3.141592654F / 180.0F; - float cosine = (float)Math.Cos(angle); - float sine = (float)Math.Sin(angle); - float sxc = myScale.X * cosine; - float syc = myScale.Y * cosine; - float sxs = myScale.X * sine; - float sys = myScale.Y * sine; - float tx = -myOrigin.X * sxc - myOrigin.Y * sys + myPosition.X; - float ty = myOrigin.X * sxs - myOrigin.Y * syc + myPosition.Y; + var angle = -_rotation * 3.141592654F / 180.0F; + var cosine = (float)Math.Cos(angle); + var sine = (float)Math.Sin(angle); + var sxc = _scale.X * cosine; + var syc = _scale.Y * cosine; + var sxs = _scale.X * sine; + var sys = _scale.Y * sine; + var tx = (-_origin.X * sxc) - (_origin.Y * sys) + _position.X; + var ty = (_origin.X * sxs) - (_origin.Y * syc) + _position.Y; - myTransform = new Transform(sxc, sys, tx, + _transform = new Transform(sxc, sys, tx, -sxs, syc, ty, 0.0F, 0.0F, 1.0F); } - return myTransform; + return _transform; } } @@ -168,12 +156,12 @@ public Transform InverseTransform { get { - if (myInverseNeedUpdate) + if (_inverseNeedUpdate) { - myInverseTransform = Transform.GetInverse(); - myInverseNeedUpdate = false; + _inverseTransform = Transform.GetInverse(); + _inverseNeedUpdate = false; } - return myInverseTransform; + return _inverseTransform; } } @@ -200,13 +188,13 @@ protected override void Destroy(bool disposing) // or not the final object (if used as a base for a drawable class) } - private Vector2f myOrigin = new Vector2f(0, 0); - private Vector2f myPosition = new Vector2f(0, 0); - private float myRotation = 0; - private Vector2f myScale = new Vector2f(1, 1); - private Transform myTransform; - private Transform myInverseTransform; - private bool myTransformNeedUpdate = true; - private bool myInverseNeedUpdate = true; + private Vector2f _origin = new Vector2f(0, 0); + private Vector2f _position = new Vector2f(0, 0); + private float _rotation; + private Vector2f _scale = new Vector2f(1, 1); + private Transform _transform; + private Transform _inverseTransform; + private bool _transformNeedUpdate = true; + private bool _inverseNeedUpdate = true; } } diff --git a/src/SFML.Graphics/Vertex.cs b/src/SFML.Graphics/Vertex.cs index 210363d4..6ed013dc 100644 --- a/src/SFML.Graphics/Vertex.cs +++ b/src/SFML.Graphics/Vertex.cs @@ -70,13 +70,10 @@ public Vertex(Vector2f position, Color color, Vector2f texCoords) /// /// String description of the object //////////////////////////////////////////////////////////// - public override string ToString() - { - return "[Vertex]" + + public override string ToString() => "[Vertex]" + " Position(" + Position + ")" + " Color(" + Color + ")" + " TexCoords(" + TexCoords + ")"; - } /// 2D position of the vertex public Vector2f Position; diff --git a/src/SFML.Graphics/VertexArray.cs b/src/SFML.Graphics/VertexArray.cs index 2c2f516a..d47e62dd 100644 --- a/src/SFML.Graphics/VertexArray.cs +++ b/src/SFML.Graphics/VertexArray.cs @@ -10,7 +10,7 @@ namespace SFML.Graphics /// Define a set of one or more 2D primitives /// //////////////////////////////////////////////////////////// - public class VertexArray : ObjectBase, Drawable + public class VertexArray : ObjectBase, IDrawable { //////////////////////////////////////////////////////////// /// @@ -29,10 +29,7 @@ public VertexArray() : /// Type of primitives //////////////////////////////////////////////////////////// public VertexArray(PrimitiveType type) : - base(sfVertexArray_create()) - { - PrimitiveType = type; - } + base(sfVertexArray_create()) => PrimitiveType = type; //////////////////////////////////////////////////////////// /// @@ -64,10 +61,7 @@ public VertexArray(VertexArray copy) : /// Total count /// //////////////////////////////////////////////////////////// - public uint VertexCount - { - get { return (uint)sfVertexArray_getVertexCount(CPointer); } - } + public uint VertexCount => (uint)sfVertexArray_getVertexCount(CPointer); //////////////////////////////////////////////////////////// /// @@ -104,10 +98,7 @@ public Vertex this[uint index] /// Clear the vertex array /// //////////////////////////////////////////////////////////// - public void Clear() - { - sfVertexArray_clear(CPointer); - } + public void Clear() => sfVertexArray_clear(CPointer); //////////////////////////////////////////////////////////// /// @@ -122,10 +113,7 @@ public void Clear() /// /// New size of the array (number of vertices) //////////////////////////////////////////////////////////// - public void Resize(uint vertexCount) - { - sfVertexArray_resize(CPointer, (UIntPtr)vertexCount); - } + public void Resize(uint vertexCount) => sfVertexArray_resize(CPointer, (UIntPtr)vertexCount); //////////////////////////////////////////////////////////// /// @@ -133,10 +121,7 @@ public void Resize(uint vertexCount) /// /// Vertex to add //////////////////////////////////////////////////////////// - public void Append(Vertex vertex) - { - sfVertexArray_append(CPointer, vertex); - } + public void Append(Vertex vertex) => sfVertexArray_append(CPointer, vertex); //////////////////////////////////////////////////////////// /// @@ -148,8 +133,8 @@ public void Append(Vertex vertex) //////////////////////////////////////////////////////////// public PrimitiveType PrimitiveType { - get { return sfVertexArray_getPrimitiveType(CPointer); } - set { sfVertexArray_setPrimitiveType(CPointer, value); } + get => sfVertexArray_getPrimitiveType(CPointer); + set => sfVertexArray_setPrimitiveType(CPointer, value); } //////////////////////////////////////////////////////////// @@ -160,29 +145,26 @@ public PrimitiveType PrimitiveType /// Contains the axis-aligned that contains all the vertices of the array. /// //////////////////////////////////////////////////////////// - public FloatRect Bounds - { - get { return sfVertexArray_getBounds(CPointer); } - } + public FloatRect Bounds => sfVertexArray_getBounds(CPointer); //////////////////////////////////////////////////////////// /// - /// Draw the vertex array to a + /// Draw the vertex array to a /// /// Render target to draw to /// Current render states //////////////////////////////////////////////////////////// - public void Draw(RenderTarget target, RenderStates states) + public void Draw(IRenderTarget target, RenderStates states) { - RenderStates.MarshalData marshaledStates = states.Marshal(); + var marshaledStates = states.Marshal(); - if (target is RenderWindow) + if (target is RenderWindow window) { - sfRenderWindow_drawVertexArray(( (RenderWindow)target ).CPointer, CPointer, ref marshaledStates); + sfRenderWindow_drawVertexArray(window.CPointer, CPointer, ref marshaledStates); } - else if (target is RenderTexture) + else if (target is RenderTexture texture) { - sfRenderTexture_drawVertexArray(( (RenderTexture)target ).CPointer, CPointer, ref marshaledStates); + sfRenderTexture_drawVertexArray(texture.CPointer, CPointer, ref marshaledStates); } } @@ -192,50 +174,47 @@ public void Draw(RenderTarget target, RenderStates states) /// /// Is the GC disposing the object, or is it an explicit call ? //////////////////////////////////////////////////////////// - protected override void Destroy(bool disposing) - { - sfVertexArray_destroy(CPointer); - } + protected override void Destroy(bool disposing) => sfVertexArray_destroy(CPointer); #region Imports - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfVertexArray_create(); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfVertexArray_copy(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfVertexArray_copy(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfVertexArray_destroy(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfVertexArray_destroy(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern UIntPtr sfVertexArray_getVertexCount(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern UIntPtr sfVertexArray_getVertexCount(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern unsafe Vertex* sfVertexArray_getVertex(IntPtr CPointer, UIntPtr index); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern unsafe Vertex* sfVertexArray_getVertex(IntPtr cPointer, UIntPtr index); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfVertexArray_clear(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfVertexArray_clear(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfVertexArray_resize(IntPtr CPointer, UIntPtr vertexCount); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfVertexArray_resize(IntPtr cPointer, UIntPtr vertexCount); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfVertexArray_append(IntPtr CPointer, Vertex vertex); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfVertexArray_append(IntPtr cPointer, Vertex vertex); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfVertexArray_setPrimitiveType(IntPtr CPointer, PrimitiveType type); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfVertexArray_setPrimitiveType(IntPtr cPointer, PrimitiveType type); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern PrimitiveType sfVertexArray_getPrimitiveType(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern PrimitiveType sfVertexArray_getPrimitiveType(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern FloatRect sfVertexArray_getBounds(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern FloatRect sfVertexArray_getBounds(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderWindow_drawVertexArray(IntPtr CPointer, IntPtr VertexArray, ref RenderStates.MarshalData states); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderWindow_drawVertexArray(IntPtr cPointer, IntPtr vertexArray, ref RenderStates.MarshalData states); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderTexture_drawVertexArray(IntPtr CPointer, IntPtr VertexArray, ref RenderStates.MarshalData states); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderTexture_drawVertexArray(IntPtr cPointer, IntPtr vertexArray, ref RenderStates.MarshalData states); #endregion } } diff --git a/src/SFML.Graphics/VertexBuffer.cs b/src/SFML.Graphics/VertexBuffer.cs index ab1e0276..0a269615 100644 --- a/src/SFML.Graphics/VertexBuffer.cs +++ b/src/SFML.Graphics/VertexBuffer.cs @@ -14,7 +14,7 @@ namespace SFML.Graphics /// Unlike SFML.VertexArray, the vertex data is stored in graphics memory. /// //////////////////////////////////////////////////////////// - public class VertexBuffer : ObjectBase, Drawable + public class VertexBuffer : ObjectBase, IDrawable { //////////////////////////////////////////////////////////// /// @@ -49,7 +49,7 @@ public enum UsageSpecifier /// any attempt to use will fail. /// /////////////////////////////////////////////////////////// - public static bool Available { get { return sfVertexBuffer_isAvailable(); } } + public static bool Available => sfVertexBuffer_isAvailable(); //////////////////////////////////////////////////////////// /// @@ -86,7 +86,7 @@ public VertexBuffer(VertexBuffer copy) /// Total vertex count /// //////////////////////////////////////////////////////////// - public uint VertexCount { get { return sfVertexBuffer_getVertexCount(CPointer); } } + public uint VertexCount => sfVertexBuffer_getVertexCount(CPointer); //////////////////////////////////////////////////////////// /// @@ -98,10 +98,7 @@ public VertexBuffer(VertexBuffer copy) /// or implement a temporary workaround until a bug is fixed. /// //////////////////////////////////////////////////////////// - public uint NativeHandle - { - get { return sfVertexBuffer_getNativeHandle(CPointer); } - } + public uint NativeHandle => sfVertexBuffer_getNativeHandle(CPointer); //////////////////////////////////////////////////////////// /// @@ -110,8 +107,8 @@ public uint NativeHandle //////////////////////////////////////////////////////////// public PrimitiveType PrimitiveType { - get { return sfVertexBuffer_getPrimitiveType(CPointer); } - set { sfVertexBuffer_setPrimitiveType(CPointer, value); } + get => sfVertexBuffer_getPrimitiveType(CPointer); + set => sfVertexBuffer_setPrimitiveType(CPointer, value); } //////////////////////////////////////////////////////////// @@ -121,8 +118,8 @@ public PrimitiveType PrimitiveType //////////////////////////////////////////////////////////// public UsageSpecifier Usage { - get { return sfVertexBuffer_getUsage(CPointer); } - set { sfVertexBuffer_setUsage(CPointer, value); } + get => sfVertexBuffer_getUsage(CPointer); + set => sfVertexBuffer_setUsage(CPointer, value); } //////////////////////////////////////////////////////////// @@ -136,10 +133,7 @@ public UsageSpecifier Usage /// /// The vertex buffer to bind; can be null to use no vertex buffer //////////////////////////////////////////////////////////// - public static void Bind(VertexBuffer vertexBuffer) - { - sfVertexBuffer_bind(vertexBuffer?.CPointer ?? IntPtr.Zero); - } + public static void Bind(VertexBuffer vertexBuffer) => sfVertexBuffer_bind(vertexBuffer?.CPointer ?? IntPtr.Zero); //////////////////////////////////////////////////////////// /// @@ -215,10 +209,7 @@ public bool Update(Vertex[] vertices, uint vertexCount, uint offset) /// /// Array of vertices to copy to the buffer //////////////////////////////////////////////////////////// - public bool Update(Vertex[] vertices) - { - return this.Update(vertices, (uint)vertices.Length, 0); - } + public bool Update(Vertex[] vertices) => Update(vertices, (uint)vertices.Length, 0); //////////////////////////////////////////////////////////// /// @@ -256,10 +247,7 @@ public bool Update(Vertex[] vertices) /// Array of vertices to copy to the buffer /// Offset in the buffer to copy to //////////////////////////////////////////////////////////// - public bool Update(Vertex[] vertices, uint offset) - { - return this.Update(vertices, (uint)vertices.Length, offset); - } + public bool Update(Vertex[] vertices, uint offset) => Update(vertices, (uint)vertices.Length, offset); //////////////////////////////////////////////////////////// /// @@ -267,10 +255,7 @@ public bool Update(Vertex[] vertices, uint offset) /// /// VertexBuffer whose contents to copy from //////////////////////////////////////////////////////////// - public bool Update(VertexBuffer other) - { - return sfVertexBuffer_updateFromVertexBuffer(CPointer, other.CPointer); - } + public bool Update(VertexBuffer other) => sfVertexBuffer_updateFromVertexBuffer(CPointer, other.CPointer); //////////////////////////////////////////////////////////// /// @@ -278,10 +263,7 @@ public bool Update(VertexBuffer other) /// /// VertexBuffer whose contents to swap with //////////////////////////////////////////////////////////// - public void Swap(VertexBuffer other) - { - sfVertexBuffer_swap(CPointer, other.CPointer); - } + public void Swap(VertexBuffer other) => sfVertexBuffer_swap(CPointer, other.CPointer); //////////////////////////////////////////////////////////// /// @@ -289,29 +271,26 @@ public void Swap(VertexBuffer other) /// /// Is the GC disposing the object, or is it an explicit call ? //////////////////////////////////////////////////////////// - protected override void Destroy(bool disposing) - { - sfVertexBuffer_destroy(CPointer); - } + protected override void Destroy(bool disposing) => sfVertexBuffer_destroy(CPointer); //////////////////////////////////////////////////////////// /// - /// Draw the to a + /// Draw the to a /// /// Render target to draw to /// Current render states //////////////////////////////////////////////////////////// - public void Draw(RenderTarget target, RenderStates states) + public void Draw(IRenderTarget target, RenderStates states) { - RenderStates.MarshalData marshaledStates = states.Marshal(); + var marshaledStates = states.Marshal(); - if(target is RenderWindow) + if (target is RenderWindow window) { - sfRenderWindow_drawVertexBuffer(((RenderWindow)target).CPointer, CPointer, ref marshaledStates); + sfRenderWindow_drawVertexBuffer(window.CPointer, CPointer, ref marshaledStates); } - else if(target is RenderTexture) + else if (target is RenderTexture texture) { - sfRenderTexture_drawVertexBuffer(((RenderTexture)target).CPointer, CPointer, ref marshaledStates); + sfRenderTexture_drawVertexBuffer(texture.CPointer, CPointer, ref marshaledStates); } } @@ -324,74 +303,74 @@ public void Draw(RenderTarget target, RenderStates states) /// Number of vertices to render /// Current render states //////////////////////////////////////////////////////////// - public void Draw(RenderTarget target, uint firstVertex, uint vertexCount, RenderStates states) + public void Draw(IRenderTarget target, uint firstVertex, uint vertexCount, RenderStates states) { - RenderStates.MarshalData marshaledStates = states.Marshal(); + var marshaledStates = states.Marshal(); - if (target is RenderWindow) + if (target is RenderWindow window) { - sfRenderWindow_drawVertexBufferRange(( (RenderWindow)target ).CPointer, CPointer, (UIntPtr)firstVertex, (UIntPtr)vertexCount, ref marshaledStates); + sfRenderWindow_drawVertexBufferRange(window.CPointer, CPointer, (UIntPtr)firstVertex, (UIntPtr)vertexCount, ref marshaledStates); } - else if (target is RenderTexture) + else if (target is RenderTexture texture) { - sfRenderTexture_drawVertexBufferRange(( (RenderTexture)target ).CPointer, CPointer, (UIntPtr)firstVertex, (UIntPtr)vertexCount, ref marshaledStates); + sfRenderTexture_drawVertexBufferRange(texture.CPointer, CPointer, (UIntPtr)firstVertex, (UIntPtr)vertexCount, ref marshaledStates); } } #region Imports - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfVertexBuffer_create(uint vertexCount, PrimitiveType type, UsageSpecifier usage); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfVertexBuffer_copy(IntPtr copy); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfVertexBuffer_destroy(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfVertexBuffer_destroy(IntPtr cPointer); + + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern uint sfVertexBuffer_getVertexCount(IntPtr cPointer); + + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern unsafe bool sfVertexBuffer_update(IntPtr cPointer, Vertex* vertices, uint vertexCount, uint offset); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern uint sfVertexBuffer_getVertexCount(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfVertexBuffer_updateFromVertexBuffer(IntPtr cPointer, IntPtr other); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern unsafe bool sfVertexBuffer_update(IntPtr CPointer, Vertex* vertices, uint vertexCount, uint offset); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfVertexBuffer_swap(IntPtr cPointer, IntPtr other); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfVertexBuffer_updateFromVertexBuffer(IntPtr CPointer, IntPtr other); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern uint sfVertexBuffer_getNativeHandle(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfVertexBuffer_swap(IntPtr CPointer, IntPtr other); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfVertexBuffer_setPrimitiveType(IntPtr cPointer, PrimitiveType primitiveType); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern uint sfVertexBuffer_getNativeHandle(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern PrimitiveType sfVertexBuffer_getPrimitiveType(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfVertexBuffer_setPrimitiveType(IntPtr CPointer, PrimitiveType primitiveType); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfVertexBuffer_setUsage(IntPtr cPointer, UsageSpecifier usageType); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern PrimitiveType sfVertexBuffer_getPrimitiveType(IntPtr CPointer); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern UsageSpecifier sfVertexBuffer_getUsage(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfVertexBuffer_setUsage(IntPtr CPointer, UsageSpecifier usageType); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfVertexBuffer_bind(IntPtr cPointer); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern UsageSpecifier sfVertexBuffer_getUsage(IntPtr CPointer); - - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfVertexBuffer_bind(IntPtr CPointer); - - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern bool sfVertexBuffer_isAvailable(); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderWindow_drawVertexBuffer(IntPtr CPointer, IntPtr VertexArray, ref RenderStates.MarshalData states); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderWindow_drawVertexBuffer(IntPtr cPointer, IntPtr vertexArray, ref RenderStates.MarshalData states); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderWindow_drawVertexBufferRange(IntPtr CPointer, IntPtr VertexBuffer, UIntPtr firstVertex, UIntPtr vertexCount, ref RenderStates.MarshalData states); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderWindow_drawVertexBufferRange(IntPtr cPointer, IntPtr vertexBuffer, UIntPtr firstVertex, UIntPtr vertexCount, ref RenderStates.MarshalData states); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderTexture_drawVertexBuffer(IntPtr CPointer, IntPtr VertexBuffer, ref RenderStates.MarshalData states); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderTexture_drawVertexBuffer(IntPtr cPointer, IntPtr vertexBuffer, ref RenderStates.MarshalData states); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderTexture_drawVertexBufferRange(IntPtr CPointer, IntPtr VertexBuffer, UIntPtr firstVertex, UIntPtr vertexCount, ref RenderStates.MarshalData states); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfRenderTexture_drawVertexBufferRange(IntPtr cPointer, IntPtr vertexBuffer, UIntPtr firstVertex, UIntPtr vertexCount, ref RenderStates.MarshalData states); #endregion } } diff --git a/src/SFML.Graphics/View.cs b/src/SFML.Graphics/View.cs index 29b3c796..d01e2588 100644 --- a/src/SFML.Graphics/View.cs +++ b/src/SFML.Graphics/View.cs @@ -69,8 +69,8 @@ public View(View copy) : //////////////////////////////////////////////////////////// public Vector2f Center { - get { return sfView_getCenter(CPointer); } - set { sfView_setCenter(CPointer, value); } + get => sfView_getCenter(CPointer); + set => sfView_setCenter(CPointer, value); } //////////////////////////////////////////////////////////// @@ -80,8 +80,8 @@ public Vector2f Center //////////////////////////////////////////////////////////// public Vector2f Size { - get { return sfView_getSize(CPointer); } - set { sfView_setSize(CPointer, value); } + get => sfView_getSize(CPointer); + set => sfView_setSize(CPointer, value); } //////////////////////////////////////////////////////////// @@ -91,8 +91,8 @@ public Vector2f Size //////////////////////////////////////////////////////////// public float Rotation { - get { return sfView_getRotation(CPointer); } - set { sfView_setRotation(CPointer, value); } + get => sfView_getRotation(CPointer); + set => sfView_setRotation(CPointer, value); } //////////////////////////////////////////////////////////// @@ -103,8 +103,8 @@ public float Rotation //////////////////////////////////////////////////////////// public FloatRect Viewport { - get { return sfView_getViewport(CPointer); } - set { sfView_setViewport(CPointer, value); } + get => sfView_getViewport(CPointer); + set => sfView_setViewport(CPointer, value); } //////////////////////////////////////////////////////////// @@ -113,10 +113,7 @@ public FloatRect Viewport /// /// Rectangle defining the position and size of the view //////////////////////////////////////////////////////////// - public void Reset(FloatRect rectangle) - { - sfView_reset(CPointer, rectangle); - } + public void Reset(FloatRect rectangle) => sfView_reset(CPointer, rectangle); //////////////////////////////////////////////////////////// /// @@ -124,10 +121,7 @@ public void Reset(FloatRect rectangle) /// /// Offset to move the view //////////////////////////////////////////////////////////// - public void Move(Vector2f offset) - { - sfView_move(CPointer, offset); - } + public void Move(Vector2f offset) => sfView_move(CPointer, offset); //////////////////////////////////////////////////////////// /// @@ -135,10 +129,7 @@ public void Move(Vector2f offset) /// /// Angle of rotation, in degrees //////////////////////////////////////////////////////////// - public void Rotate(float angle) - { - sfView_rotate(CPointer, angle); - } + public void Rotate(float angle) => sfView_rotate(CPointer, angle); //////////////////////////////////////////////////////////// /// @@ -146,10 +137,7 @@ public void Rotate(float angle) /// /// Zoom factor to apply, relative to the current zoom //////////////////////////////////////////////////////////// - public void Zoom(float factor) - { - sfView_zoom(CPointer, factor); - } + public void Zoom(float factor) => sfView_zoom(CPointer, factor); //////////////////////////////////////////////////////////// /// @@ -160,7 +148,9 @@ public void Zoom(float factor) public override string ToString() { if (IsInvalid) + { return MakeDisposedObjectString(); + } return "[View]" + " Center(" + Center + ")" + @@ -176,10 +166,7 @@ public override string ToString() /// Direct pointer to the view object in the C library //////////////////////////////////////////////////////////// internal View(IntPtr cPointer) : - base(cPointer) - { - myExternal = true; - } + base(cPointer) => _external = true; //////////////////////////////////////////////////////////// /// @@ -189,62 +176,62 @@ internal View(IntPtr cPointer) : //////////////////////////////////////////////////////////// protected override void Destroy(bool disposing) { - if (!myExternal) + if (!_external) { sfView_destroy(CPointer); } } - private readonly bool myExternal = false; + private readonly bool _external; #region Imports - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfView_create(); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfView_createFromRect(FloatRect Rect); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfView_createFromRect(FloatRect rect); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfView_copy(IntPtr View); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfView_copy(IntPtr view); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfView_destroy(IntPtr View); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfView_destroy(IntPtr view); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfView_setCenter(IntPtr View, Vector2f center); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfView_setCenter(IntPtr view, Vector2f center); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfView_setSize(IntPtr View, Vector2f size); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfView_setSize(IntPtr view, Vector2f size); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfView_setRotation(IntPtr View, float Angle); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfView_setRotation(IntPtr view, float angle); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfView_setViewport(IntPtr View, FloatRect Viewport); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfView_setViewport(IntPtr view, FloatRect viewport); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfView_reset(IntPtr View, FloatRect Rectangle); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfView_reset(IntPtr view, FloatRect rectangle); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Vector2f sfView_getCenter(IntPtr View); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Vector2f sfView_getCenter(IntPtr view); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Vector2f sfView_getSize(IntPtr View); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Vector2f sfView_getSize(IntPtr view); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern float sfView_getRotation(IntPtr View); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern float sfView_getRotation(IntPtr view); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern FloatRect sfView_getViewport(IntPtr View); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern FloatRect sfView_getViewport(IntPtr view); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfView_move(IntPtr View, Vector2f offset); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfView_move(IntPtr view, Vector2f offset); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfView_rotate(IntPtr View, float Angle); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfView_rotate(IntPtr view, float angle); - [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfView_zoom(IntPtr View, float Factor); + [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfView_zoom(IntPtr view, float factor); #endregion } } diff --git a/src/SFML.System/Allocation.cs b/src/SFML.System/Allocation.cs index d4da1168..2c96f8a4 100644 --- a/src/SFML.System/Allocation.cs +++ b/src/SFML.System/Allocation.cs @@ -20,7 +20,7 @@ public static class Allocation /// Pointer to the memory to deallocate public static void Free(IntPtr ptr) => sfFree(ptr); - [DllImport(CSFML.system, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.System, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfFree(IntPtr ptr); } } diff --git a/src/SFML.System/Buffer.cs b/src/SFML.System/Buffer.cs index 76b91432..2d5eeb4b 100644 --- a/src/SFML.System/Buffer.cs +++ b/src/SFML.System/Buffer.cs @@ -65,22 +65,19 @@ internal Buffer(IntPtr cPointer) : /// /// Is the GC disposing the object, or is it an explicit call? //////////////////////////////////////////////////////////// - protected override void Destroy(bool disposing) - { - sfBuffer_destroy(CPointer); - } + protected override void Destroy(bool disposing) => sfBuffer_destroy(CPointer); #region Imports - [DllImport(CSFML.system, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.System, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfBuffer_create(); - [DllImport(CSFML.system, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.System, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfBuffer_destroy(IntPtr buffer); - [DllImport(CSFML.system, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.System, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern UIntPtr sfBuffer_getSize(IntPtr buffer); - [DllImport(CSFML.system, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.System, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfBuffer_getData(IntPtr buffer); #endregion } diff --git a/src/SFML.System/Clock.cs b/src/SFML.System/Clock.cs index 0299d835..cce8b5cd 100644 --- a/src/SFML.System/Clock.cs +++ b/src/SFML.System/Clock.cs @@ -24,10 +24,7 @@ public Clock() : base(sfClock_create()) { } /// /// Is the GC disposing the object, or is it an explicit call ? //////////////////////////////////////////////////////////// - protected override void Destroy(bool disposing) - { - sfClock_destroy(CPointer); - } + protected override void Destroy(bool disposing) => sfClock_destroy(CPointer); //////////////////////////////////////////////////////////// /// @@ -45,17 +42,17 @@ protected override void Destroy(bool disposing) public Time Restart() => sfClock_restart(CPointer); #region Imports - [DllImport(CSFML.system, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.System, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfClock_create(); - [DllImport(CSFML.system, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfClock_destroy(IntPtr CPointer); + [DllImport(CSFML.System, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfClock_destroy(IntPtr cPointer); - [DllImport(CSFML.system, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Time sfClock_getElapsedTime(IntPtr Clock); + [DllImport(CSFML.System, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Time sfClock_getElapsedTime(IntPtr clock); - [DllImport(CSFML.system, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Time sfClock_restart(IntPtr Clock); + [DllImport(CSFML.System, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Time sfClock_restart(IntPtr clock); #endregion } } diff --git a/src/SFML.System/ObjectBase.cs b/src/SFML.System/ObjectBase.cs index fd54bc9e..3d0e3562 100644 --- a/src/SFML.System/ObjectBase.cs +++ b/src/SFML.System/ObjectBase.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics; namespace SFML { @@ -17,10 +16,7 @@ public abstract class ObjectBase : IDisposable /// /// Internal pointer to the object in the C libraries //////////////////////////////////////////////////////////// - public ObjectBase(IntPtr cPointer) - { - myCPointer = cPointer; - } + public ObjectBase(IntPtr cPointer) => _cPointer = cPointer; //////////////////////////////////////////////////////////// /// @@ -44,12 +40,14 @@ public IntPtr CPointer { get { - if (myCPointer == IntPtr.Zero) + if (_cPointer == IntPtr.Zero) + { throw new ObjectDisposedException($"This {GetType().Name} instance has been disposed and should not be used."); + } - return myCPointer; + return _cPointer; } - protected set { myCPointer = value; } + protected set => _cPointer = value; } //////////////////////////////////////////////////////////// @@ -58,7 +56,7 @@ public IntPtr CPointer /// For internal use only /// //////////////////////////////////////////////////////////// - public bool IsInvalid => myCPointer == IntPtr.Zero; + public bool IsInvalid => _cPointer == IntPtr.Zero; //////////////////////////////////////////////////////////// /// @@ -79,10 +77,10 @@ public void Dispose() //////////////////////////////////////////////////////////// private void Dispose(bool disposing) { - if (myCPointer != IntPtr.Zero) + if (_cPointer != IntPtr.Zero) { Destroy(disposing); - myCPointer = IntPtr.Zero; + _cPointer = IntPtr.Zero; } } @@ -100,6 +98,6 @@ private void Dispose(bool disposing) /// A string representation of the disposed object protected string MakeDisposedObjectString() => $"[{GetType().Name} (disposed)]"; - private IntPtr myCPointer = IntPtr.Zero; + private IntPtr _cPointer = IntPtr.Zero; } } diff --git a/src/SFML.System/Properties/AssemblyInfo.cs b/src/SFML.System/Properties/AssemblyInfo.cs index 94a68ab7..817eab89 100644 --- a/src/SFML.System/Properties/AssemblyInfo.cs +++ b/src/SFML.System/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ -using System.Reflection; -using System.Runtime.InteropServices; +using System.Runtime.InteropServices; // [assembly: AssemblyTitle("sfml-system")] //[assembly: AssemblyDescription("System module of the SFML library")] diff --git a/src/SFML.System/SharedLibName.cs b/src/SFML.System/SharedLibName.cs index 2fcdecbc..1c24b354 100644 --- a/src/SFML.System/SharedLibName.cs +++ b/src/SFML.System/SharedLibName.cs @@ -4,13 +4,13 @@ namespace SFML.System public static class CSFML { /// CSFML Audio Lib Name - public const string audio = "csfml-audio"; + public const string Audio = "csfml-audio"; /// CSFML Graphics Lib Name - public const string graphics = "csfml-graphics"; + public const string Graphics = "csfml-graphics"; /// CSFML System Lib Name - public const string system = "csfml-system"; + public const string System = "csfml-system"; /// CSFML Window Lib Name - public const string window = "csfml-window"; + public const string Window = "csfml-window"; } } diff --git a/src/SFML.System/StreamAdaptor.cs b/src/SFML.System/StreamAdaptor.cs index a4798b16..284ec043 100644 --- a/src/SFML.System/StreamAdaptor.cs +++ b/src/SFML.System/StreamAdaptor.cs @@ -89,9 +89,9 @@ public class StreamAdaptor : IDisposable //////////////////////////////////////////////////////////// public StreamAdaptor(Stream stream) { - myStream = stream; + _stream = stream; - myInputStream = new InputStream + _inputStream = new InputStream { Read = new InputStream.ReadCallbackType(Read), Seek = new InputStream.SeekCallbackType(Seek), @@ -99,8 +99,8 @@ public StreamAdaptor(Stream stream) GetSize = new InputStream.GetSizeCallbackType(GetSize) }; - myInputStreamPtr = Marshal.AllocHGlobal(Marshal.SizeOf(myInputStream)); - Marshal.StructureToPtr(myInputStream, myInputStreamPtr, false); + InputStreamPtr = Marshal.AllocHGlobal(Marshal.SizeOf(_inputStream)); + Marshal.StructureToPtr(_inputStream, InputStreamPtr, false); } //////////////////////////////////////////////////////////// @@ -118,7 +118,7 @@ public StreamAdaptor(Stream stream) /// The pointer to the CSFML InputStream structure /// //////////////////////////////////////////////////////////// - public IntPtr InputStreamPtr => myInputStreamPtr; + public IntPtr InputStreamPtr { get; } //////////////////////////////////////////////////////////// /// @@ -137,10 +137,7 @@ public void Dispose() /// /// Is the GC disposing the object, or is it an explicit call ? //////////////////////////////////////////////////////////// - private void Dispose(bool disposing) - { - Marshal.FreeHGlobal(myInputStreamPtr); - } + private void Dispose(bool disposing) => Marshal.FreeHGlobal(InputStreamPtr); //////////////////////////////////////////////////////////// /// @@ -153,8 +150,8 @@ private void Dispose(bool disposing) //////////////////////////////////////////////////////////// private long Read(IntPtr data, long size, IntPtr userData) { - byte[] buffer = new byte[size]; - int count = myStream.Read(buffer, 0, (int)size); + var buffer = new byte[size]; + var count = _stream.Read(buffer, 0, (int)size); Marshal.Copy(buffer, 0, data, count); return count; } @@ -167,10 +164,7 @@ private long Read(IntPtr data, long size, IntPtr userData) /// User data -- unused /// Actual position //////////////////////////////////////////////////////////// - private long Seek(long position, IntPtr userData) - { - return myStream.Seek(position, SeekOrigin.Begin); - } + private long Seek(long position, IntPtr userData) => _stream.Seek(position, SeekOrigin.Begin); //////////////////////////////////////////////////////////// /// @@ -179,10 +173,7 @@ private long Seek(long position, IntPtr userData) /// User data -- unused /// Current position in the stream //////////////////////////////////////////////////////////// - private long Tell(IntPtr userData) - { - return myStream.Position; - } + private long Tell(IntPtr userData) => _stream.Position; //////////////////////////////////////////////////////////// /// @@ -191,10 +182,9 @@ private long Tell(IntPtr userData) /// User data -- unused /// Number of bytes in the stream //////////////////////////////////////////////////////////// - private long GetSize(IntPtr userData) => myStream.Length; + private long GetSize(IntPtr userData) => _stream.Length; - private Stream myStream; - private InputStream myInputStream; - private readonly IntPtr myInputStreamPtr; + private readonly Stream _stream; + private InputStream _inputStream; } } diff --git a/src/SFML.System/Time.cs b/src/SFML.System/Time.cs index 8bd6dc37..c6e41c5b 100644 --- a/src/SFML.System/Time.cs +++ b/src/SFML.System/Time.cs @@ -16,7 +16,7 @@ namespace SFML.System /// //////////////////////////////////////////////////////////// [StructLayout(LayoutKind.Sequential)] - public struct Time : IEquatable /// String description of the object //////////////////////////////////////////////////////////// - public override string ToString() - { - return "[TouchEventArgs]" + + public override string ToString() => "[TouchEventArgs]" + " Finger(" + Finger + ")" + " X(" + X + ")" + " Y(" + Y + ")"; - } /// Index of the finger in case of multi-touch events public uint Finger; @@ -499,14 +460,11 @@ public SensorEventArgs(SensorEvent e) /// /// String description of the object //////////////////////////////////////////////////////////// - public override string ToString() - { - return "[SensorEventArgs]" + + public override string ToString() => "[SensorEventArgs]" + " Type(" + Type + ")" + " X(" + X + ")" + " Y(" + Y + ")" + " Z(" + Z + ")"; - } /// Type of the sensor public Sensor.Type Type; diff --git a/src/SFML.Window/Joystick.cs b/src/SFML.Window/Joystick.cs index b8bd2c04..140975ae 100644 --- a/src/SFML.Window/Joystick.cs +++ b/src/SFML.Window/Joystick.cs @@ -60,10 +60,7 @@ public enum Axis /// Index of the joystick to check /// True if the joystick is connected, false otherwise //////////////////////////////////////////////////////////// - public static bool IsConnected(uint joystick) - { - return sfJoystick_isConnected(joystick); - } + public static bool IsConnected(uint joystick) => sfJoystick_isConnected(joystick); //////////////////////////////////////////////////////////// /// @@ -73,10 +70,7 @@ public static bool IsConnected(uint joystick) /// Index of the joystick /// Number of buttons supported by the joystick //////////////////////////////////////////////////////////// - public static uint GetButtonCount(uint joystick) - { - return sfJoystick_getButtonCount(joystick); - } + public static uint GetButtonCount(uint joystick) => sfJoystick_getButtonCount(joystick); //////////////////////////////////////////////////////////// /// @@ -87,10 +81,7 @@ public static uint GetButtonCount(uint joystick) /// Axis to check /// True if the joystick supports the axis, false otherwise //////////////////////////////////////////////////////////// - public static bool HasAxis(uint joystick, Axis axis) - { - return sfJoystick_hasAxis(joystick, axis); - } + public static bool HasAxis(uint joystick, Axis axis) => sfJoystick_hasAxis(joystick, axis); //////////////////////////////////////////////////////////// /// @@ -101,10 +92,7 @@ public static bool HasAxis(uint joystick, Axis axis) /// Button to check /// True if the button is pressed, false otherwise //////////////////////////////////////////////////////////// - public static bool IsButtonPressed(uint joystick, uint button) - { - return sfJoystick_isButtonPressed(joystick, button); - } + public static bool IsButtonPressed(uint joystick, uint button) => sfJoystick_isButtonPressed(joystick, button); //////////////////////////////////////////////////////////// /// @@ -115,10 +103,7 @@ public static bool IsButtonPressed(uint joystick, uint button) /// Axis to check /// Current position of the axis, in range [-100 .. 100] //////////////////////////////////////////////////////////// - public static float GetAxisPosition(uint joystick, Axis axis) - { - return sfJoystick_getAxisPosition(joystick, axis); - } + public static float GetAxisPosition(uint joystick, Axis axis) => sfJoystick_getAxisPosition(joystick, axis); //////////////////////////////////////////////////////////// /// @@ -129,10 +114,7 @@ public static float GetAxisPosition(uint joystick, Axis axis) /// call it if you have no window yet (or no window at all): /// in this case the joysticks states are not updated automatically. //////////////////////////////////////////////////////////// - public static void Update() - { - sfJoystick_update(); - } + public static void Update() => sfJoystick_update(); //////////////////////////////////////////////////////////// /// @@ -143,12 +125,13 @@ public static void Update() //////////////////////////////////////////////////////////// public static Identification GetIdentification(uint joystick) { - IdentificationMarshalData identification = sfJoystick_getIdentification(joystick); - Identification retIdentification = new Identification(); - - retIdentification.Name = Marshal.PtrToStringAnsi(identification.Name); - retIdentification.VendorId = identification.VendorId; - retIdentification.ProductId = identification.ProductId; + var identification = sfJoystick_getIdentification(joystick); + var retIdentification = new Identification + { + Name = Marshal.PtrToStringAnsi(identification.Name), + VendorId = identification.VendorId, + ProductId = identification.ProductId + }; return retIdentification; } @@ -185,25 +168,25 @@ internal struct IdentificationMarshalData } #region Imports - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern bool sfJoystick_isConnected(uint joystick); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern uint sfJoystick_getButtonCount(uint joystick); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern bool sfJoystick_hasAxis(uint joystick, Axis axis); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern bool sfJoystick_isButtonPressed(uint joystick, uint button); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern float sfJoystick_getAxisPosition(uint joystick, Axis axis); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfJoystick_update(); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IdentificationMarshalData sfJoystick_getIdentification(uint joystick); #endregion } diff --git a/src/SFML.Window/Keyboard.cs b/src/SFML.Window/Keyboard.cs index 68a8f856..49918b0e 100644 --- a/src/SFML.Window/Keyboard.cs +++ b/src/SFML.Window/Keyboard.cs @@ -578,10 +578,7 @@ public enum Scancode /// Key to check /// True if the key is pressed, false otherwise //////////////////////////////////////////////////////////// - public static bool IsKeyPressed(Key key) - { - return sfKeyboard_isKeyPressed(key); - } + public static bool IsKeyPressed(Key key) => sfKeyboard_isKeyPressed(key); //////////////////////////////////////////////////////////// /// @@ -590,10 +587,7 @@ public static bool IsKeyPressed(Key key) /// Scancode to check /// True if the physical key is pressed, false otherwise //////////////////////////////////////////////////////////// - public static bool IsScancodePressed(Scancode code) - { - return sfKeyboard_isScancodePressed(code); - } + public static bool IsScancodePressed(Scancode code) => sfKeyboard_isScancodePressed(code); //////////////////////////////////////////////////////////// /// @@ -607,10 +601,7 @@ public static bool IsScancodePressed(Scancode code) /// to a . /// //////////////////////////////////////////////////////////// - public static Key Localize(Scancode code) - { - return sfKeyboard_localize(code); - } + public static Key Localize(Scancode code) => sfKeyboard_localize(code); //////////////////////////////////////////////////////////// /// @@ -624,10 +615,7 @@ public static Key Localize(Scancode code) /// to a . /// //////////////////////////////////////////////////////////// - public static Scancode Delocalize(Key key) - { - return sfKeyboard_delocalize(key); - } + public static Scancode Delocalize(Key key) => sfKeyboard_delocalize(key); //////////////////////////////////////////////////////////// /// @@ -667,28 +655,25 @@ public static string GetDescription(Scancode code) /// Applicable only on Android and iOS /// Whether to make the virtual keyboard visible (true) or not (false) //////////////////////////////////////////////////////////// - public static void SetVirtualKeyboardVisible(bool visible) - { - sfKeyboard_setVirtualKeyboardVisible(visible); - } + public static void SetVirtualKeyboardVisible(bool visible) => sfKeyboard_setVirtualKeyboardVisible(visible); #region Imports - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfKeyboard_isKeyPressed(Key Key); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfKeyboard_isKeyPressed(Key key); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern bool sfKeyboard_isScancodePressed(Scancode code); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern Key sfKeyboard_localize(Scancode code); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern Scancode sfKeyboard_delocalize(Key key); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfKeyboard_getDescription(Scancode code); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfKeyboard_setVirtualKeyboardVisible(bool visible); #endregion } diff --git a/src/SFML.Window/Mouse.cs b/src/SFML.Window/Mouse.cs index 174aeb21..b1b0ca07 100644 --- a/src/SFML.Window/Mouse.cs +++ b/src/SFML.Window/Mouse.cs @@ -59,10 +59,7 @@ public enum Wheel /// Button to check /// True if the button is pressed, false otherwise //////////////////////////////////////////////////////////// - public static bool IsButtonPressed(Button button) - { - return sfMouse_isButtonPressed(button); - } + public static bool IsButtonPressed(Button button) => sfMouse_isButtonPressed(button); //////////////////////////////////////////////////////////// /// @@ -72,10 +69,7 @@ public static bool IsButtonPressed(Button button) /// cursor in desktop coordinates. /// Current position of the mouse //////////////////////////////////////////////////////////// - public static Vector2i GetPosition() - { - return GetPosition(null); - } + public static Vector2i GetPosition() => GetPosition(null); //////////////////////////////////////////////////////////// /// @@ -106,10 +100,7 @@ public static Vector2i GetPosition(WindowBase relativeTo) /// cursor in desktop coordinates. /// New position of the mouse //////////////////////////////////////////////////////////// - public static void SetPosition(Vector2i position) - { - SetPosition(position, null); - } + public static void SetPosition(Vector2i position) => SetPosition(position, null); //////////////////////////////////////////////////////////// /// @@ -133,13 +124,13 @@ public static void SetPosition(Vector2i position, WindowBase relativeTo) } #region Imports - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern bool sfMouse_isButtonPressed(Button button); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern Vector2i sfMouse_getPosition(IntPtr relativeTo); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfMouse_setPosition(Vector2i position, IntPtr relativeTo); #endregion } diff --git a/src/SFML.Window/Properties/AssemblyInfo.cs b/src/SFML.Window/Properties/AssemblyInfo.cs index 2d355d6d..2229b0a1 100644 --- a/src/SFML.Window/Properties/AssemblyInfo.cs +++ b/src/SFML.Window/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ -using System.Reflection; -using System.Runtime.InteropServices; +using System.Runtime.InteropServices; // [assembly: AssemblyTitle("sfml-window")] diff --git a/src/SFML.Window/Sensor.cs b/src/SFML.Window/Sensor.cs index afe41121..e004fb8a 100644 --- a/src/SFML.Window/Sensor.cs +++ b/src/SFML.Window/Sensor.cs @@ -44,47 +44,38 @@ public enum Type /// /// Check if a sensor is available on the underlying platform /// - /// Sensor to check + /// Sensor to check /// True if the sensor is available, false otherwise //////////////////////////////////////////////////////////// - public static bool IsAvailable(Type Sensor) - { - return sfSensor_isAvailable(Sensor); - } + public static bool IsAvailable(Type sensor) => sfSensor_isAvailable(sensor); //////////////////////////////////////////////////////////// /// /// Enable or disable a sensor /// - /// Sensor to check - /// True to enable, false to disable + /// Sensor to check + /// True to enable, false to disable //////////////////////////////////////////////////////////// - public static void SetEnabled(Type Sensor, bool Enabled) - { - sfSensor_setEnabled(Sensor, Enabled); - } + public static void SetEnabled(Type sensor, bool enabled) => sfSensor_setEnabled(sensor, enabled); //////////////////////////////////////////////////////////// /// /// Get the current sensor value /// - /// Sensor to check + /// Sensor to check /// The current sensor value //////////////////////////////////////////////////////////// - public static Vector3f GetValue(Type Sensor) - { - return sfSensor_getValue(Sensor); - } + public static Vector3f GetValue(Type sensor) => sfSensor_getValue(sensor); #region Imports - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfSensor_isAvailable(Type Sensor); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfSensor_isAvailable(Type sensor); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfSensor_setEnabled(Type Sensor, bool Enabled); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfSensor_setEnabled(Type sensor, bool enabled); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Vector3f sfSensor_getValue(Type Sensor); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Vector3f sfSensor_getValue(Type sensor); #endregion } } diff --git a/src/SFML.Window/Touch.cs b/src/SFML.Window/Touch.cs index e717e7c9..164aaa94 100644 --- a/src/SFML.Window/Touch.cs +++ b/src/SFML.Window/Touch.cs @@ -16,53 +16,47 @@ public static class Touch /// /// Check if a touch event is currently down /// - /// Finger index + /// Finger index /// True if the finger is currently touching the screen, false otherwise //////////////////////////////////////////////////////////// - public static bool IsDown(uint Finger) - { - return sfTouch_isDown(Finger); - } + public static bool IsDown(uint finger) => sfTouch_isDown(finger); //////////////////////////////////////////////////////////// /// /// This function returns the current touch position /// - /// Finger index + /// Finger index /// Current position of the finger //////////////////////////////////////////////////////////// - public static Vector2i GetPosition(uint Finger) - { - return GetPosition(Finger, null); - } + public static Vector2i GetPosition(uint finger) => GetPosition(finger, null); //////////////////////////////////////////////////////////// /// /// This function returns the current touch position /// relative to the given window /// - /// Finger index - /// Reference window + /// Finger index + /// Reference window /// Current position of the finger //////////////////////////////////////////////////////////// - public static Vector2i GetPosition(uint Finger, WindowBase RelativeTo) + public static Vector2i GetPosition(uint finger, WindowBase relativeTo) { - if (RelativeTo != null) + if (relativeTo != null) { - return RelativeTo.InternalGetTouchPosition(Finger); + return relativeTo.InternalGetTouchPosition(finger); } else { - return sfTouch_getPosition(Finger, IntPtr.Zero); + return sfTouch_getPosition(finger, IntPtr.Zero); } } #region Imports - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfTouch_isDown(uint Finger); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfTouch_isDown(uint finger); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Vector2i sfTouch_getPosition(uint Finger, IntPtr RelativeTo); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Vector2i sfTouch_getPosition(uint finger, IntPtr relativeTo); #endregion } } diff --git a/src/SFML.Window/VideoMode.cs b/src/SFML.Window/VideoMode.cs index 1bd93afb..ca374b0a 100644 --- a/src/SFML.Window/VideoMode.cs +++ b/src/SFML.Window/VideoMode.cs @@ -48,10 +48,7 @@ public VideoMode(uint width, uint height, uint bpp) /// /// True if the video mode is valid, false otherwise //////////////////////////////////////////////////////////// - public bool IsValid() - { - return sfVideoMode_isValid(this); - } + public bool IsValid() => sfVideoMode_isValid(this); //////////////////////////////////////////////////////////// /// @@ -64,15 +61,14 @@ public static VideoMode[] FullscreenModes { unsafe { - UIntPtr Count; - VideoMode* ModesPtr = sfVideoMode_getFullscreenModes(out Count); - VideoMode[] Modes = new VideoMode[(int)Count]; - for (int i = 0; i < (int)Count; ++i) + var modesPtr = sfVideoMode_getFullscreenModes(out var count); + var modes = new VideoMode[(int)count]; + for (var i = 0; i < (int)count; ++i) { - Modes[i] = ModesPtr[i]; + modes[i] = modesPtr[i]; } - return Modes; + return modes; } } } @@ -82,10 +78,7 @@ public static VideoMode[] FullscreenModes /// Get the current desktop video mode /// //////////////////////////////////////////////////////////// - public static VideoMode DesktopMode - { - get { return sfVideoMode_getDesktopMode(); } - } + public static VideoMode DesktopMode => sfVideoMode_getDesktopMode(); //////////////////////////////////////////////////////////// /// @@ -93,13 +86,10 @@ public static VideoMode DesktopMode /// /// String description of the object //////////////////////////////////////////////////////////// - public override string ToString() - { - return "[VideoMode]" + + public override string ToString() => "[VideoMode]" + " Width(" + Width + ")" + " Height(" + Height + ")" + " BitsPerPixel(" + BitsPerPixel + ")"; - } /// Video mode width, in pixels public uint Width; @@ -111,14 +101,14 @@ public override string ToString() public uint BitsPerPixel; #region Imports - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern VideoMode sfVideoMode_getDesktopMode(); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private unsafe static extern VideoMode* sfVideoMode_getFullscreenModes(out UIntPtr Count); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern unsafe VideoMode* sfVideoMode_getFullscreenModes(out UIntPtr count); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfVideoMode_isValid(VideoMode Mode); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfVideoMode_isValid(VideoMode mode); #endregion } } diff --git a/src/SFML.Window/Vulkan.cs b/src/SFML.Window/Vulkan.cs index 69dee7ab..190c9194 100644 --- a/src/SFML.Window/Vulkan.cs +++ b/src/SFML.Window/Vulkan.cs @@ -47,7 +47,7 @@ public static string[] GetGraphicsRequiredInstanceExtensions() var extensionsPtr = sfVulkan_getGraphicsRequiredInstanceExtensions(out var count); var extensions = new string[(int)count]; - for (int i = 0; i < (int)count; ++i) + for (var i = 0; i < (int)count; ++i) { extensions[i] = Marshal.PtrToStringAnsi(extensionsPtr[i]); } @@ -57,14 +57,14 @@ public static string[] GetGraphicsRequiredInstanceExtensions() } #region Imports - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern bool sfVulkan_isAvailable(bool requireGraphics); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfVulkan_getFunction(string name); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private unsafe static extern IntPtr* sfVulkan_getGraphicsRequiredInstanceExtensions(out UIntPtr count); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern unsafe IntPtr* sfVulkan_getGraphicsRequiredInstanceExtensions(out UIntPtr count); #endregion } } \ No newline at end of file diff --git a/src/SFML.Window/Window.cs b/src/SFML.Window/Window.cs index d90e82a2..13209bbd 100644 --- a/src/SFML.Window/Window.cs +++ b/src/SFML.Window/Window.cs @@ -51,7 +51,7 @@ public Window(VideoMode mode, string title, Styles style, ContextSettings settin base(IntPtr.Zero) { // Copy the title to a null-terminated UTF-32 byte array - byte[] titleAsUtf32 = Encoding.UTF32.GetBytes(title + '\0'); + var titleAsUtf32 = Encoding.UTF32.GetBytes(title + '\0'); unsafe { @@ -77,11 +77,11 @@ public Window(IntPtr handle) : /// /// Create the window from an existing control /// - /// Platform-specific handle of the control + /// Platform-specific handle of the control /// Creation parameters //////////////////////////////////////////////////////////// - public Window(IntPtr Handle, ContextSettings settings) : - base(sfWindow_createFromHandle(Handle, ref settings)) + public Window(IntPtr handle, ContextSettings settings) : + base(sfWindow_createFromHandle(handle, ref settings)) { } @@ -93,10 +93,7 @@ public Window(IntPtr Handle, ContextSettings settings) : /// /// True if the window is opened //////////////////////////////////////////////////////////// - public override bool IsOpen - { - get { return sfWindow_isOpen(CPointer); } - } + public override bool IsOpen => sfWindow_isOpen(CPointer); //////////////////////////////////////////////////////////// /// @@ -105,30 +102,21 @@ public override bool IsOpen /// Create to recreate the window /// //////////////////////////////////////////////////////////// - public override void Close() - { - sfWindow_close(CPointer); - } + public override void Close() => sfWindow_close(CPointer); //////////////////////////////////////////////////////////// /// /// Display the window on screen /// //////////////////////////////////////////////////////////// - public virtual void Display() - { - sfWindow_display(CPointer); - } + public virtual void Display() => sfWindow_display(CPointer); //////////////////////////////////////////////////////////// /// /// Creation settings of the window /// //////////////////////////////////////////////////////////// - public virtual ContextSettings Settings - { - get { return sfWindow_getSettings(CPointer); } - } + public virtual ContextSettings Settings => sfWindow_getSettings(CPointer); //////////////////////////////////////////////////////////// /// @@ -137,8 +125,8 @@ public virtual ContextSettings Settings //////////////////////////////////////////////////////////// public override Vector2i Position { - get { return sfWindow_getPosition(CPointer); } - set { sfWindow_setPosition(CPointer, value); } + get => sfWindow_getPosition(CPointer); + set => sfWindow_setPosition(CPointer, value); } //////////////////////////////////////////////////////////// @@ -148,8 +136,8 @@ public override Vector2i Position //////////////////////////////////////////////////////////// public override Vector2u Size { - get { return sfWindow_getSize(CPointer); } - set { sfWindow_setSize(CPointer, value); } + get => sfWindow_getSize(CPointer); + set => sfWindow_setSize(CPointer, value); } //////////////////////////////////////////////////////////// @@ -161,7 +149,7 @@ public override Vector2u Size public override void SetTitle(string title) { // Copy the title to a null-terminated UTF-32 byte array - byte[] titleAsUtf32 = Encoding.UTF32.GetBytes(title + '\0'); + var titleAsUtf32 = Encoding.UTF32.GetBytes(title + '\0'); unsafe { @@ -184,9 +172,9 @@ public override void SetIcon(uint width, uint height, byte[] pixels) { unsafe { - fixed (byte* PixelsPtr = pixels) + fixed (byte* pixelsPtr = pixels) { - sfWindow_setIcon(CPointer, width, height, PixelsPtr); + sfWindow_setIcon(CPointer, width, height, pixelsPtr); } } } @@ -197,10 +185,7 @@ public override void SetIcon(uint width, uint height, byte[] pixels) /// /// True to show the window, false to hide it //////////////////////////////////////////////////////////// - public override void SetVisible(bool visible) - { - sfWindow_setVisible(CPointer, visible); - } + public override void SetVisible(bool visible) => sfWindow_setVisible(CPointer, visible); //////////////////////////////////////////////////////////// /// @@ -208,10 +193,7 @@ public override void SetVisible(bool visible) /// /// True to show, false to hide //////////////////////////////////////////////////////////// - public override void SetMouseCursorVisible(bool show) - { - sfWindow_setMouseCursorVisible(CPointer, show); - } + public override void SetMouseCursorVisible(bool show) => sfWindow_setMouseCursorVisible(CPointer, show); //////////////////////////////////////////////////////////// /// @@ -228,10 +210,7 @@ public override void SetMouseCursorVisible(bool show) /// cursor). /// //////////////////////////////////////////////////////////// - public override void SetMouseCursorGrabbed(bool grabbed) - { - sfWindow_setMouseCursorGrabbed(CPointer, grabbed); - } + public override void SetMouseCursorGrabbed(bool grabbed) => sfWindow_setMouseCursorGrabbed(CPointer, grabbed); //////////////////////////////////////////////////////////// /// @@ -239,10 +218,7 @@ public override void SetMouseCursorGrabbed(bool grabbed) /// /// Native system cursor type to display //////////////////////////////////////////////////////////// - public override void SetMouseCursor(Cursor cursor) - { - sfWindow_setMouseCursor(CPointer, cursor.CPointer); - } + public override void SetMouseCursor(Cursor cursor) => sfWindow_setMouseCursor(CPointer, cursor.CPointer); //////////////////////////////////////////////////////////// /// @@ -250,10 +226,7 @@ public override void SetMouseCursor(Cursor cursor) /// /// True to enable v-sync, false to deactivate //////////////////////////////////////////////////////////// - public virtual void SetVerticalSyncEnabled(bool enable) - { - sfWindow_setVerticalSyncEnabled(CPointer, enable); - } + public virtual void SetVerticalSyncEnabled(bool enable) => sfWindow_setVerticalSyncEnabled(CPointer, enable); //////////////////////////////////////////////////////////// /// @@ -262,10 +235,7 @@ public virtual void SetVerticalSyncEnabled(bool enable) /// /// True to enable, false to disable //////////////////////////////////////////////////////////// - public override void SetKeyRepeatEnabled(bool enable) - { - sfWindow_setKeyRepeatEnabled(CPointer, enable); - } + public override void SetKeyRepeatEnabled(bool enable) => sfWindow_setKeyRepeatEnabled(CPointer, enable); //////////////////////////////////////////////////////////// /// @@ -274,10 +244,7 @@ public override void SetKeyRepeatEnabled(bool enable) /// /// True if operation was successful, false otherwise //////////////////////////////////////////////////////////// - public virtual bool SetActive() - { - return SetActive(true); - } + public virtual bool SetActive() => SetActive(true); //////////////////////////////////////////////////////////// /// @@ -287,10 +254,7 @@ public virtual bool SetActive() /// True to activate, false to deactivate (true by default) /// True if operation was successful, false otherwise //////////////////////////////////////////////////////////// - public virtual bool SetActive(bool active) - { - return sfWindow_setActive(CPointer, active); - } + public virtual bool SetActive(bool active) => sfWindow_setActive(CPointer, active); //////////////////////////////////////////////////////////// /// @@ -298,10 +262,7 @@ public virtual bool SetActive(bool active) /// /// Framerate limit, in frames per seconds (use 0 to disable limit) //////////////////////////////////////////////////////////// - public virtual void SetFramerateLimit(uint limit) - { - sfWindow_setFramerateLimit(CPointer, limit); - } + public virtual void SetFramerateLimit(uint limit) => sfWindow_setFramerateLimit(CPointer, limit); //////////////////////////////////////////////////////////// /// @@ -310,20 +271,14 @@ public virtual void SetFramerateLimit(uint limit) /// /// New threshold, in range [0, 100] //////////////////////////////////////////////////////////// - public override void SetJoystickThreshold(float threshold) - { - sfWindow_setJoystickThreshold(CPointer, threshold); - } + public override void SetJoystickThreshold(float threshold) => sfWindow_setJoystickThreshold(CPointer, threshold); //////////////////////////////////////////////////////////// /// /// OS-specific handle of the window /// //////////////////////////////////////////////////////////// - public override IntPtr SystemHandle - { - get { return sfWindow_getSystemHandle(CPointer); } - } + public override IntPtr SystemHandle => sfWindow_getSystemHandle(CPointer); //////////////////////////////////////////////////////////// /// @@ -331,10 +286,7 @@ public override IntPtr SystemHandle /// foreground window /// //////////////////////////////////////////////////////////// - public override void RequestFocus() - { - sfWindow_requestFocus(CPointer); - } + public override void RequestFocus() => sfWindow_requestFocus(CPointer); //////////////////////////////////////////////////////////// /// @@ -342,10 +294,7 @@ public override void RequestFocus() /// /// True if the window has focus, false otherwise //////////////////////////////////////////////////////////// - public override bool HasFocus() - { - return sfWindow_hasFocus(CPointer); - } + public override bool HasFocus() => sfWindow_hasFocus(CPointer); //////////////////////////////////////////////////////////// /// @@ -356,10 +305,7 @@ public override bool HasFocus() /// Allocator to use /// True if surface creation was successful, false otherwise //////////////////////////////////////////////////////////// - public override bool CreateVulkanSurface(IntPtr vkInstance, out IntPtr vkSurface, IntPtr vkAllocator) - { - return sfWindow_createVulkanSurface(CPointer, vkInstance, out vkSurface, vkAllocator); - } + public override bool CreateVulkanSurface(IntPtr vkInstance, out IntPtr vkSurface, IntPtr vkAllocator) => sfWindow_createVulkanSurface(CPointer, vkInstance, out vkSurface, vkAllocator); //////////////////////////////////////////////////////////// /// @@ -370,7 +316,9 @@ public override bool CreateVulkanSurface(IntPtr vkInstance, out IntPtr vkSurface public override string ToString() { if (IsInvalid) + { return MakeDisposedObjectString(); + } return "[Window]" + " Size(" + Size + ")" + @@ -399,10 +347,7 @@ protected Window(IntPtr cPointer, int dummy) : /// /// Relative mouse position //////////////////////////////////////////////////////////// - protected internal override Vector2i InternalGetMousePosition() - { - return sfMouse_getPosition(CPointer); - } + protected internal override Vector2i InternalGetMousePosition() => sfMouse_getPosition(CPointer); //////////////////////////////////////////////////////////// /// @@ -412,10 +357,7 @@ protected internal override Vector2i InternalGetMousePosition() /// /// Relative mouse position //////////////////////////////////////////////////////////// - protected internal override void InternalSetMousePosition(Vector2i position) - { - sfMouse_setPosition(position, CPointer); - } + protected internal override void InternalSetMousePosition(Vector2i position) => sfMouse_setPosition(position, CPointer); //////////////////////////////////////////////////////////// /// @@ -423,13 +365,10 @@ protected internal override void InternalSetMousePosition(Vector2i position) /// This function is protected because it is called by another class of /// another module, it is not meant to be called by users. /// - /// Finger index + /// Finger index /// Relative touch position //////////////////////////////////////////////////////////// - protected internal override Vector2i InternalGetTouchPosition(uint Finger) - { - return sfTouch_getPosition(Finger, CPointer); - } + protected internal override Vector2i InternalGetTouchPosition(uint finger) => sfTouch_getPosition(finger, CPointer); //////////////////////////////////////////////////////////// /// @@ -438,10 +377,7 @@ protected internal override Vector2i InternalGetTouchPosition(uint Finger) /// Variable to fill with the raw pointer to the event structure /// True if there was an event, false otherwise //////////////////////////////////////////////////////////// - protected override bool PollEvent(out Event eventToFill) - { - return sfWindow_pollEvent(CPointer, out eventToFill); - } + protected override bool PollEvent(out Event eventToFill) => sfWindow_pollEvent(CPointer, out eventToFill); //////////////////////////////////////////////////////////// /// @@ -450,10 +386,7 @@ protected override bool PollEvent(out Event eventToFill) /// Variable to fill with the raw pointer to the event structure /// False if any error occurred //////////////////////////////////////////////////////////// - protected override bool WaitEvent(out Event eventToFill) - { - return sfWindow_waitEvent(CPointer, out eventToFill); - } + protected override bool WaitEvent(out Event eventToFill) => sfWindow_waitEvent(CPointer, out eventToFill); //////////////////////////////////////////////////////////// /// @@ -461,104 +394,101 @@ protected override bool WaitEvent(out Event eventToFill) /// /// Is the GC disposing the object, or is it an explicit call ? //////////////////////////////////////////////////////////// - protected override void Destroy(bool disposing) - { - sfWindow_destroy(CPointer); - } + protected override void Destroy(bool disposing) => sfWindow_destroy(CPointer); #region Imports - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfWindow_createUnicode(VideoMode Mode, IntPtr Title, Styles Style, ref ContextSettings Params); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfWindow_createUnicode(VideoMode mode, IntPtr title, Styles style, ref ContextSettings settings); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfWindow_createFromHandle(IntPtr Handle, ref ContextSettings Params); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfWindow_createFromHandle(IntPtr handle, ref ContextSettings settings); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfWindow_destroy(IntPtr CPointer); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfWindow_destroy(IntPtr cPointer); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfWindow_isOpen(IntPtr CPointer); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfWindow_isOpen(IntPtr cPointer); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfWindow_close(IntPtr CPointer); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfWindow_close(IntPtr cPointer); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfWindow_pollEvent(IntPtr CPointer, out Event Evt); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfWindow_pollEvent(IntPtr cPointer, out Event evt); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfWindow_waitEvent(IntPtr CPointer, out Event Evt); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfWindow_waitEvent(IntPtr cPointer, out Event evt); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfWindow_display(IntPtr CPointer); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfWindow_display(IntPtr cPointer); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern ContextSettings sfWindow_getSettings(IntPtr CPointer); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern ContextSettings sfWindow_getSettings(IntPtr cPointer); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Vector2i sfWindow_getPosition(IntPtr CPointer); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Vector2i sfWindow_getPosition(IntPtr cPointer); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfWindow_setPosition(IntPtr CPointer, Vector2i position); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfWindow_setPosition(IntPtr cPointer, Vector2i position); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Vector2u sfWindow_getSize(IntPtr CPointer); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Vector2u sfWindow_getSize(IntPtr cPointer); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfWindow_setSize(IntPtr CPointer, Vector2u size); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfWindow_setSize(IntPtr cPointer, Vector2u size); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfWindow_setUnicodeTitle(IntPtr CPointer, IntPtr title); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfWindow_setUnicodeTitle(IntPtr cPointer, IntPtr title); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private unsafe static extern void sfWindow_setIcon(IntPtr CPointer, uint Width, uint Height, byte* Pixels); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern unsafe void sfWindow_setIcon(IntPtr cPointer, uint width, uint height, byte* pixels); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfWindow_setVisible(IntPtr CPointer, bool visible); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfWindow_setVisible(IntPtr cPointer, bool visible); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfWindow_setMouseCursorVisible(IntPtr CPointer, bool Show); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfWindow_setMouseCursorVisible(IntPtr cPointer, bool show); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfWindow_setMouseCursorGrabbed(IntPtr CPointer, bool grabbed); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfWindow_setMouseCursorGrabbed(IntPtr cPointer, bool grabbed); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfWindow_setMouseCursor(IntPtr CPointer, IntPtr cursor); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfWindow_setMouseCursor(IntPtr cPointer, IntPtr cursor); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfWindow_setVerticalSyncEnabled(IntPtr CPointer, bool Enable); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfWindow_setVerticalSyncEnabled(IntPtr cPointer, bool enable); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfWindow_setKeyRepeatEnabled(IntPtr CPointer, bool Enable); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfWindow_setKeyRepeatEnabled(IntPtr cPointer, bool enable); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfWindow_setActive(IntPtr CPointer, bool Active); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfWindow_setActive(IntPtr cPointer, bool active); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfWindow_setFramerateLimit(IntPtr CPointer, uint Limit); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfWindow_setFramerateLimit(IntPtr cPointer, uint limit); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfWindow_setJoystickThreshold(IntPtr CPointer, float Threshold); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfWindow_setJoystickThreshold(IntPtr cPointer, float threshold); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfWindow_getSystemHandle(IntPtr CPointer); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfWindow_getSystemHandle(IntPtr cPointer); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfWindow_requestFocus(IntPtr CPointer); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfWindow_requestFocus(IntPtr cPointer); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfWindow_hasFocus(IntPtr CPointer); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfWindow_hasFocus(IntPtr cPointer); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Vector2i sfMouse_getPosition(IntPtr CPointer); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Vector2i sfMouse_getPosition(IntPtr cPointer); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfMouse_setPosition(Vector2i position, IntPtr CPointer); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfMouse_setPosition(Vector2i position, IntPtr cPointer); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Vector2i sfTouch_getPosition(uint Finger, IntPtr RelativeTo); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Vector2i sfTouch_getPosition(uint finger, IntPtr relativeTo); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfWindow_createVulkanSurface(IntPtr CPointer, IntPtr vkInstance, out IntPtr surface, IntPtr vkAllocator); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfWindow_createVulkanSurface(IntPtr cPointer, IntPtr vkInstance, out IntPtr surface, IntPtr vkAllocator); #endregion } } diff --git a/src/SFML.Window/WindowBase.cs b/src/SFML.Window/WindowBase.cs index d9ced5fe..ddf6794f 100644 --- a/src/SFML.Window/WindowBase.cs +++ b/src/SFML.Window/WindowBase.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Runtime; using System.Runtime.InteropServices; using System.Security; using System.Text; @@ -82,10 +80,10 @@ public WindowBase(VideoMode mode, string title, Styles style) : /// /// Create the window from an existing control /// - /// Platform-specific handle of the control + /// Platform-specific handle of the control //////////////////////////////////////////////////////////// - public WindowBase(IntPtr Handle) : - base(sfWindowBase_createFromHandle(Handle)) + public WindowBase(IntPtr handle) : + base(sfWindowBase_createFromHandle(handle)) { } @@ -97,10 +95,7 @@ public WindowBase(IntPtr Handle) : /// /// True if the window is opened //////////////////////////////////////////////////////////// - public virtual bool IsOpen - { - get { return sfWindowBase_isOpen(CPointer); } - } + public virtual bool IsOpen => sfWindowBase_isOpen(CPointer); //////////////////////////////////////////////////////////// /// @@ -109,10 +104,7 @@ public virtual bool IsOpen /// Create to recreate the window /// //////////////////////////////////////////////////////////// - public virtual void Close() - { - sfWindowBase_close(CPointer); - } + public virtual void Close() => sfWindowBase_close(CPointer); //////////////////////////////////////////////////////////// /// @@ -121,8 +113,8 @@ public virtual void Close() //////////////////////////////////////////////////////////// public virtual Vector2i Position { - get { return sfWindowBase_getPosition(CPointer); } - set { sfWindowBase_setPosition(CPointer, value); } + get => sfWindowBase_getPosition(CPointer); + set => sfWindowBase_setPosition(CPointer, value); } //////////////////////////////////////////////////////////// @@ -132,8 +124,8 @@ public virtual Vector2i Position //////////////////////////////////////////////////////////// public virtual Vector2u Size { - get { return sfWindowBase_getSize(CPointer); } - set { sfWindowBase_setSize(CPointer, value); } + get => sfWindowBase_getSize(CPointer); + set => sfWindowBase_setSize(CPointer, value); } //////////////////////////////////////////////////////////// @@ -168,9 +160,9 @@ public virtual void SetIcon(uint width, uint height, byte[] pixels) { unsafe { - fixed (byte* PixelsPtr = pixels) + fixed (byte* pixelsPtr = pixels) { - sfWindowBase_setIcon(CPointer, width, height, PixelsPtr); + sfWindowBase_setIcon(CPointer, width, height, pixelsPtr); } } } @@ -181,10 +173,7 @@ public virtual void SetIcon(uint width, uint height, byte[] pixels) /// /// True to show the window, false to hide it //////////////////////////////////////////////////////////// - public virtual void SetVisible(bool visible) - { - sfWindowBase_setVisible(CPointer, visible); - } + public virtual void SetVisible(bool visible) => sfWindowBase_setVisible(CPointer, visible); //////////////////////////////////////////////////////////// /// @@ -192,10 +181,7 @@ public virtual void SetVisible(bool visible) /// /// True to show, false to hide //////////////////////////////////////////////////////////// - public virtual void SetMouseCursorVisible(bool show) - { - sfWindowBase_setMouseCursorVisible(CPointer, show); - } + public virtual void SetMouseCursorVisible(bool show) => sfWindowBase_setMouseCursorVisible(CPointer, show); //////////////////////////////////////////////////////////// /// @@ -212,10 +198,7 @@ public virtual void SetMouseCursorVisible(bool show) /// cursor). /// //////////////////////////////////////////////////////////// - public virtual void SetMouseCursorGrabbed(bool grabbed) - { - sfWindowBase_setMouseCursorGrabbed(CPointer, grabbed); - } + public virtual void SetMouseCursorGrabbed(bool grabbed) => sfWindowBase_setMouseCursorGrabbed(CPointer, grabbed); //////////////////////////////////////////////////////////// /// @@ -225,10 +208,7 @@ public virtual void SetMouseCursorGrabbed(bool grabbed) /// /// Native system cursor type to display //////////////////////////////////////////////////////////// - public virtual void SetMouseCursor(Cursor cursor) - { - sfWindowBase_setMouseCursor(CPointer, cursor.CPointer); - } + public virtual void SetMouseCursor(Cursor cursor) => sfWindowBase_setMouseCursor(CPointer, cursor.CPointer); //////////////////////////////////////////////////////////// /// @@ -242,10 +222,7 @@ public virtual void SetMouseCursor(Cursor cursor) /// /// True to enable, false to disable //////////////////////////////////////////////////////////// - public virtual void SetKeyRepeatEnabled(bool enable) - { - sfWindowBase_setKeyRepeatEnabled(CPointer, enable); - } + public virtual void SetKeyRepeatEnabled(bool enable) => sfWindowBase_setKeyRepeatEnabled(CPointer, enable); //////////////////////////////////////////////////////////// /// @@ -254,20 +231,14 @@ public virtual void SetKeyRepeatEnabled(bool enable) /// /// New threshold, in range [0, 100] //////////////////////////////////////////////////////////// - public virtual void SetJoystickThreshold(float threshold) - { - sfWindowBase_setJoystickThreshold(CPointer, threshold); - } + public virtual void SetJoystickThreshold(float threshold) => sfWindowBase_setJoystickThreshold(CPointer, threshold); //////////////////////////////////////////////////////////// /// /// OS-specific handle of the window /// //////////////////////////////////////////////////////////// - public virtual IntPtr SystemHandle - { - get { return sfWindowBase_getSystemHandle(CPointer); } - } + public virtual IntPtr SystemHandle => sfWindowBase_getSystemHandle(CPointer); //////////////////////////////////////////////////////////// /// @@ -277,8 +248,7 @@ public virtual IntPtr SystemHandle //////////////////////////////////////////////////////////// public void WaitAndDispatchEvents() { - Event e; - if (WaitEvent(out e)) + if (WaitEvent(out var e)) { CallEventHandler(e); } @@ -291,8 +261,7 @@ public void WaitAndDispatchEvents() //////////////////////////////////////////////////////////// public void DispatchEvents() { - Event e; - while (PollEvent(out e)) + while (PollEvent(out var e)) { CallEventHandler(e); } @@ -304,10 +273,7 @@ public void DispatchEvents() /// foreground window /// //////////////////////////////////////////////////////////// - public virtual void RequestFocus() - { - sfWindowBase_requestFocus(CPointer); - } + public virtual void RequestFocus() => sfWindowBase_requestFocus(CPointer); //////////////////////////////////////////////////////////// /// @@ -315,10 +281,7 @@ public virtual void RequestFocus() /// /// True if the window has focus, false otherwise //////////////////////////////////////////////////////////// - public virtual bool HasFocus() - { - return sfWindowBase_hasFocus(CPointer); - } + public virtual bool HasFocus() => sfWindowBase_hasFocus(CPointer); //////////////////////////////////////////////////////////// /// @@ -329,10 +292,7 @@ public virtual bool HasFocus() /// Allocator to use /// True if surface creation was successful, false otherwise //////////////////////////////////////////////////////////// - public virtual bool CreateVulkanSurface(IntPtr vkInstance, out IntPtr vkSurface, IntPtr vkAllocator) - { - return sfWindowBase_createVulkanSurface(CPointer, vkInstance, out vkSurface, vkAllocator); - } + public virtual bool CreateVulkanSurface(IntPtr vkInstance, out IntPtr vkSurface, IntPtr vkAllocator) => sfWindowBase_createVulkanSurface(CPointer, vkInstance, out vkSurface, vkAllocator); //////////////////////////////////////////////////////////// /// @@ -343,7 +303,9 @@ public virtual bool CreateVulkanSurface(IntPtr vkInstance, out IntPtr vkSurface, public override string ToString() { if (IsInvalid) + { return MakeDisposedObjectString(); + } return "[WindowBase]" + " Size(" + Size + ")" + @@ -370,10 +332,7 @@ protected WindowBase(IntPtr cPointer, int dummy) : /// Variable to fill with the raw pointer to the event structure /// True if there was an event, false otherwise //////////////////////////////////////////////////////////// - protected virtual bool PollEvent(out Event eventToFill) - { - return sfWindowBase_pollEvent(CPointer, out eventToFill); - } + protected virtual bool PollEvent(out Event eventToFill) => sfWindowBase_pollEvent(CPointer, out eventToFill); //////////////////////////////////////////////////////////// /// @@ -382,10 +341,7 @@ protected virtual bool PollEvent(out Event eventToFill) /// Variable to fill with the raw pointer to the event structure /// False if any error occurred //////////////////////////////////////////////////////////// - protected virtual bool WaitEvent(out Event eventToFill) - { - return sfWindowBase_waitEvent(CPointer, out eventToFill); - } + protected virtual bool WaitEvent(out Event eventToFill) => sfWindowBase_waitEvent(CPointer, out eventToFill); //////////////////////////////////////////////////////////// /// @@ -395,10 +351,7 @@ protected virtual bool WaitEvent(out Event eventToFill) /// /// Relative mouse position //////////////////////////////////////////////////////////// - protected internal virtual Vector2i InternalGetMousePosition() - { - return sfMouse_getPositionWindowBase(CPointer); - } + protected internal virtual Vector2i InternalGetMousePosition() => sfMouse_getPositionWindowBase(CPointer); //////////////////////////////////////////////////////////// /// @@ -408,10 +361,7 @@ protected internal virtual Vector2i InternalGetMousePosition() /// /// Relative mouse position //////////////////////////////////////////////////////////// - protected internal virtual void InternalSetMousePosition(Vector2i position) - { - sfMouse_setPositionWindowBase(position, CPointer); - } + protected internal virtual void InternalSetMousePosition(Vector2i position) => sfMouse_setPositionWindowBase(position, CPointer); //////////////////////////////////////////////////////////// /// @@ -419,13 +369,10 @@ protected internal virtual void InternalSetMousePosition(Vector2i position) /// This function is protected because it is called by another class of /// another module, it is not meant to be called by users. /// - /// Finger index + /// Finger index /// Relative touch position //////////////////////////////////////////////////////////// - protected internal virtual Vector2i InternalGetTouchPosition(uint Finger) - { - return sfTouch_getPositionWindowBase(Finger, CPointer); - } + protected internal virtual Vector2i InternalGetTouchPosition(uint finger) => sfTouch_getPositionWindowBase(finger, CPointer); //////////////////////////////////////////////////////////// /// @@ -433,10 +380,7 @@ protected internal virtual Vector2i InternalGetTouchPosition(uint Finger) /// /// Is the GC disposing the object, or is it an explicit call ? //////////////////////////////////////////////////////////// - protected override void Destroy(bool disposing) - { - sfWindowBase_destroy(CPointer); - } + protected override void Destroy(bool disposing) => sfWindowBase_destroy(CPointer); //////////////////////////////////////////////////////////// /// @@ -449,191 +393,99 @@ private void CallEventHandler(Event e) switch (e.Type) { case EventType.Closed: - if (Closed != null) - { - Closed(this, EventArgs.Empty); - } - + Closed?.Invoke(this, EventArgs.Empty); break; case EventType.GainedFocus: - if (GainedFocus != null) - { - GainedFocus(this, EventArgs.Empty); - } - + GainedFocus?.Invoke(this, EventArgs.Empty); break; case EventType.JoystickButtonPressed: - if (JoystickButtonPressed != null) - { - JoystickButtonPressed(this, new JoystickButtonEventArgs(e.JoystickButton)); - } - + JoystickButtonPressed?.Invoke(this, new JoystickButtonEventArgs(e.JoystickButton)); break; case EventType.JoystickButtonReleased: - if (JoystickButtonReleased != null) - { - JoystickButtonReleased(this, new JoystickButtonEventArgs(e.JoystickButton)); - } - + JoystickButtonReleased?.Invoke(this, new JoystickButtonEventArgs(e.JoystickButton)); break; case EventType.JoystickMoved: - if (JoystickMoved != null) - { - JoystickMoved(this, new JoystickMoveEventArgs(e.JoystickMove)); - } - + JoystickMoved?.Invoke(this, new JoystickMoveEventArgs(e.JoystickMove)); break; case EventType.JoystickConnected: - if (JoystickConnected != null) - { - JoystickConnected(this, new JoystickConnectEventArgs(e.JoystickConnect)); - } - + JoystickConnected?.Invoke(this, new JoystickConnectEventArgs(e.JoystickConnect)); break; case EventType.JoystickDisconnected: - if (JoystickDisconnected != null) - { - JoystickDisconnected(this, new JoystickConnectEventArgs(e.JoystickConnect)); - } - + JoystickDisconnected?.Invoke(this, new JoystickConnectEventArgs(e.JoystickConnect)); break; case EventType.KeyPressed: - if (KeyPressed != null) - { - KeyPressed(this, new KeyEventArgs(e.Key)); - } - + KeyPressed?.Invoke(this, new KeyEventArgs(e.Key)); break; case EventType.KeyReleased: - if (KeyReleased != null) - { - KeyReleased(this, new KeyEventArgs(e.Key)); - } - + KeyReleased?.Invoke(this, new KeyEventArgs(e.Key)); break; case EventType.LostFocus: - if (LostFocus != null) - { - LostFocus(this, EventArgs.Empty); - } - + LostFocus?.Invoke(this, EventArgs.Empty); break; case EventType.MouseButtonPressed: - if (MouseButtonPressed != null) - { - MouseButtonPressed(this, new MouseButtonEventArgs(e.MouseButton)); - } - + MouseButtonPressed?.Invoke(this, new MouseButtonEventArgs(e.MouseButton)); break; case EventType.MouseButtonReleased: - if (MouseButtonReleased != null) - { - MouseButtonReleased(this, new MouseButtonEventArgs(e.MouseButton)); - } - + MouseButtonReleased?.Invoke(this, new MouseButtonEventArgs(e.MouseButton)); break; case EventType.MouseEntered: - if (MouseEntered != null) - { - MouseEntered(this, EventArgs.Empty); - } - + MouseEntered?.Invoke(this, EventArgs.Empty); break; case EventType.MouseLeft: - if (MouseLeft != null) - { - MouseLeft(this, EventArgs.Empty); - } - + MouseLeft?.Invoke(this, EventArgs.Empty); break; case EventType.MouseMoved: - if (MouseMoved != null) - { - MouseMoved(this, new MouseMoveEventArgs(e.MouseMove)); - } - + MouseMoved?.Invoke(this, new MouseMoveEventArgs(e.MouseMove)); break; // Disable CS0618 (Obsolete Warning). This Event will be removed in SFML.NET 3.0, but should remain supported until then. #pragma warning disable CS0618 case EventType.MouseWheelMoved: - if (MouseWheelMoved != null) - { - MouseWheelMoved(this, new MouseWheelEventArgs(e.MouseWheel)); - } - + MouseWheelMoved?.Invoke(this, new MouseWheelEventArgs(e.MouseWheel)); break; // restore CS0618 #pragma warning restore CS0618 case EventType.MouseWheelScrolled: - if (MouseWheelScrolled != null) - { - MouseWheelScrolled(this, new MouseWheelScrollEventArgs(e.MouseWheelScroll)); - } - + MouseWheelScrolled?.Invoke(this, new MouseWheelScrollEventArgs(e.MouseWheelScroll)); break; case EventType.Resized: - if (Resized != null) - { - Resized(this, new SizeEventArgs(e.Size)); - } - + Resized?.Invoke(this, new SizeEventArgs(e.Size)); break; case EventType.TextEntered: - if (TextEntered != null) - { - TextEntered(this, new TextEventArgs(e.Text)); - } - + TextEntered?.Invoke(this, new TextEventArgs(e.Text)); break; case EventType.TouchBegan: - if (TouchBegan != null) - { - TouchBegan(this, new TouchEventArgs(e.Touch)); - } - + TouchBegan?.Invoke(this, new TouchEventArgs(e.Touch)); break; case EventType.TouchMoved: - if (TouchMoved != null) - { - TouchMoved(this, new TouchEventArgs(e.Touch)); - } - + TouchMoved?.Invoke(this, new TouchEventArgs(e.Touch)); break; case EventType.TouchEnded: - if (TouchEnded != null) - { - TouchEnded(this, new TouchEventArgs(e.Touch)); - } - + TouchEnded?.Invoke(this, new TouchEventArgs(e.Touch)); break; case EventType.SensorChanged: - if (SensorChanged != null) - { - SensorChanged(this, new SensorEventArgs(e.Sensor)); - } - + SensorChanged?.Invoke(this, new SensorEventArgs(e.Sensor)); break; default: @@ -642,153 +494,153 @@ private void CallEventHandler(Event e) } /// Event handler for the Closed event - public event EventHandler Closed = null; + public event EventHandler Closed; /// Event handler for the Resized event - public event EventHandler Resized = null; + public event EventHandler Resized; /// Event handler for the LostFocus event - public event EventHandler LostFocus = null; + public event EventHandler LostFocus; /// Event handler for the GainedFocus event - public event EventHandler GainedFocus = null; + public event EventHandler GainedFocus; /// Event handler for the TextEntered event - public event EventHandler TextEntered = null; + public event EventHandler TextEntered; /// Event handler for the KeyPressed event - public event EventHandler KeyPressed = null; + public event EventHandler KeyPressed; /// Event handler for the KeyReleased event - public event EventHandler KeyReleased = null; + public event EventHandler KeyReleased; /// Event handler for the MouseWheelMoved event [Obsolete("Use MouseWheelScrolled")] - public event EventHandler MouseWheelMoved = null; + public event EventHandler MouseWheelMoved; /// Event handler for the MouseWheelScrolled event - public event EventHandler MouseWheelScrolled = null; + public event EventHandler MouseWheelScrolled; /// Event handler for the MouseButtonPressed event - public event EventHandler MouseButtonPressed = null; + public event EventHandler MouseButtonPressed; /// Event handler for the MouseButtonReleased event - public event EventHandler MouseButtonReleased = null; + public event EventHandler MouseButtonReleased; /// Event handler for the MouseMoved event - public event EventHandler MouseMoved = null; + public event EventHandler MouseMoved; /// Event handler for the MouseEntered event - public event EventHandler MouseEntered = null; + public event EventHandler MouseEntered; /// Event handler for the MouseLeft event - public event EventHandler MouseLeft = null; + public event EventHandler MouseLeft; /// Event handler for the JoystickButtonPressed event - public event EventHandler JoystickButtonPressed = null; + public event EventHandler JoystickButtonPressed; /// Event handler for the JoystickButtonReleased event - public event EventHandler JoystickButtonReleased = null; + public event EventHandler JoystickButtonReleased; /// Event handler for the JoystickMoved event - public event EventHandler JoystickMoved = null; + public event EventHandler JoystickMoved; /// Event handler for the JoystickConnected event - public event EventHandler JoystickConnected = null; + public event EventHandler JoystickConnected; /// Event handler for the JoystickDisconnected event - public event EventHandler JoystickDisconnected = null; + public event EventHandler JoystickDisconnected; /// Event handler for the TouchBegan event - public event EventHandler TouchBegan = null; + public event EventHandler TouchBegan; /// Event handler for the TouchMoved event - public event EventHandler TouchMoved = null; + public event EventHandler TouchMoved; /// Event handler for the TouchEnded event - public event EventHandler TouchEnded = null; + public event EventHandler TouchEnded; /// Event handler for the SensorChanged event - public event EventHandler SensorChanged = null; + public event EventHandler SensorChanged; #region Imports - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfWindowBase_createUnicode(VideoMode Mode, IntPtr Title, Styles Style); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfWindowBase_createUnicode(VideoMode mode, IntPtr title, Styles style); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfWindowBase_createFromHandle(IntPtr Handle); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfWindowBase_createFromHandle(IntPtr handle); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfWindowBase_destroy(IntPtr CPointer); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfWindowBase_destroy(IntPtr cPointer); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfWindowBase_close(IntPtr CPointer); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfWindowBase_close(IntPtr cPointer); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfWindowBase_isOpen(IntPtr CPointer); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfWindowBase_isOpen(IntPtr cPointer); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfWindowBase_pollEvent(IntPtr CPointer, out Event Evt); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfWindowBase_pollEvent(IntPtr cPointer, out Event evt); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfWindowBase_waitEvent(IntPtr CPointer, out Event Evt); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfWindowBase_waitEvent(IntPtr cPointer, out Event evt); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Vector2i sfWindowBase_getPosition(IntPtr CPointer); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Vector2i sfWindowBase_getPosition(IntPtr cPointer); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfWindowBase_setPosition(IntPtr CPointer, Vector2i position); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfWindowBase_setPosition(IntPtr cPointer, Vector2i position); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Vector2u sfWindowBase_getSize(IntPtr CPointer); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Vector2u sfWindowBase_getSize(IntPtr cPointer); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfWindowBase_setSize(IntPtr CPointer, Vector2u size); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfWindowBase_setSize(IntPtr cPointer, Vector2u size); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfWindowBase_setUnicodeTitle(IntPtr CPointer, IntPtr title); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfWindowBase_setUnicodeTitle(IntPtr cPointer, IntPtr title); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private unsafe static extern void sfWindowBase_setIcon(IntPtr CPointer, uint Width, uint Height, byte* Pixels); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern unsafe void sfWindowBase_setIcon(IntPtr cPointer, uint width, uint height, byte* pixels); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfWindowBase_setVisible(IntPtr CPointer, bool visible); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfWindowBase_setVisible(IntPtr cPointer, bool visible); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfWindowBase_setMouseCursorVisible(IntPtr CPointer, bool Show); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfWindowBase_setMouseCursorVisible(IntPtr cPointer, bool show); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfWindowBase_setMouseCursorGrabbed(IntPtr CPointer, bool grabbed); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfWindowBase_setMouseCursorGrabbed(IntPtr cPointer, bool grabbed); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfWindowBase_setMouseCursor(IntPtr CPointer, IntPtr cursor); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfWindowBase_setMouseCursor(IntPtr cPointer, IntPtr cursor); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfWindowBase_setKeyRepeatEnabled(IntPtr CPointer, bool Enable); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfWindowBase_setKeyRepeatEnabled(IntPtr cPointer, bool enable); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfWindowBase_setJoystickThreshold(IntPtr CPointer, float Threshold); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfWindowBase_setJoystickThreshold(IntPtr cPointer, float threshold); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfWindowBase_requestFocus(IntPtr CPointer); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfWindowBase_requestFocus(IntPtr cPointer); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfWindowBase_hasFocus(IntPtr CPointer); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfWindowBase_hasFocus(IntPtr cPointer); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfWindowBase_getSystemHandle(IntPtr CPointer); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern IntPtr sfWindowBase_getSystemHandle(IntPtr cPointer); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern bool sfWindowBase_createVulkanSurface(IntPtr CPointer, IntPtr vkInstance, out IntPtr surface, IntPtr vkAllocator); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern bool sfWindowBase_createVulkanSurface(IntPtr cPointer, IntPtr vkInstance, out IntPtr surface, IntPtr vkAllocator); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Vector2i sfMouse_getPositionWindowBase(IntPtr CPointer); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Vector2i sfMouse_getPositionWindowBase(IntPtr cPointer); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfMouse_setPositionWindowBase(Vector2i position, IntPtr CPointer); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern void sfMouse_setPositionWindowBase(Vector2i position, IntPtr cPointer); - [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Vector2i sfTouch_getPositionWindowBase(uint Finger, IntPtr RelativeTo); + [DllImport(CSFML.Window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] + private static extern Vector2i sfTouch_getPositionWindowBase(uint finger, IntPtr relativeTo); #endregion } }