2
0
mirror of https://github.com/raylib-cs/raylib-cs synced 2025-04-05 11:19:39 -04:00

Back to unsafe

- Fixed array issue means we have to use unsafe in a few parts for now.
- Testing rayforms in bindings
This commit is contained in:
ChrisDill 2018-10-12 20:42:51 +01:00
parent 3b21284b5f
commit 3f17281969
8 changed files with 262 additions and 279 deletions

@ -5,7 +5,7 @@
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A2B3BBC8-3D48-46DD-B3CF-263F554E4474}</ProjectGuid>
<OutputType>Exe</OutputType>
<OutputType>Library</OutputType>
<RootNamespace>Raylib</RootNamespace>
<AssemblyName>Bindings</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
@ -36,7 +36,7 @@
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
@ -52,6 +52,7 @@
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
@ -83,14 +84,19 @@
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Easings.cs" />
<Compile Include="Physac.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RayForms.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Raygui.cs" />
<Compile Include="Raylib.cs" />
<Compile Include="Raymath.cs" />

@ -1,44 +1,50 @@
using Raylib;
using static Raylib.Raylib;
// example to quickly test bindings
// otherwise build as a class library to use in other projects
class Program
{
public static void Main()
{
// Initialization
//--------------------------------------------------------------------------------------
int screenWidth = 800; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// TODO: Update your variables here
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("Congrats! You created your first window!", 190, 200, 20, MAROON);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
}
}
using System;
using Raylib;
using static Raylib.Raylib;
// example to quickly test bindings
// otherwise build as a class library to use in other projects
class Program
{
public static void Main()
{
//RayForms.Run();
//return;
// Initialization
//--------------------------------------------------------------------------------------
int screenWidth = 800;
int screenHeight = 450;
// SetConfigFlags((int)Flag.WINDOW_UNDECORATED);
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// TODO: Update your variables here
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("Congrats! You created your first window!", 190, 200, 20, MAROON);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
}
}

102
Bindings/RayForms.cs Normal file

@ -0,0 +1,102 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
using static Raylib.Raylib;
namespace Raylib
{
public partial class RayForms : Form
{
private Panel gamePanel;
private bool windowAttached = false;
#region WinAPI Entry Points
[DllImport("user32.dll")]
private static extern IntPtr SetWindowPos(IntPtr handle, IntPtr handleAfter, int x, int y, int cx, int cy, uint flags);
[DllImport("user32.dll")]
private static extern IntPtr SetParent(IntPtr child, IntPtr newParent);
[DllImport("user32.dll")]
private static extern IntPtr ShowWindow(IntPtr handle, int command);
#endregion
public RayForms()
{
Size = new Size(1024, 700);
Text = "Rayforms";
gamePanel = new Panel();
gamePanel.Size = new Size(800, 500);
gamePanel.Location = new Point(50, 50);
Button button = new Button();
button.Text = "Attach window";
button.Size = new Size(150, 20);
button.Location = new Point(
(Size.Width / 2) - (button.Size.Width / 2),
gamePanel.Location.Y + gamePanel.Size.Height + 10
);
button.Click += new EventHandler(ClickedButton);
Controls.Add(button);
Controls.Add(gamePanel);
}
private void ClickedButton(object sender, EventArgs e)
{
if (!windowAttached)
{
// new Thread(Test).Start();
Test();
}
}
private void Test()
{
SetConfigFlags((int)Flag.WINDOW_UNDECORATED);
InitWindow(800, 480, "Rayforms test");
SetTargetFPS(60);
IntPtr winHandle = GetWindowHandle();
Invoke(new Action(() =>
{
SetWindowPos(winHandle, Handle, 0, 0, 0, 0, 0x0401 /*NOSIZE | SHOWWINDOW */);
SetParent(winHandle, gamePanel.Handle);
ShowWindow(winHandle, 1);
windowAttached = true;
}));
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// TODO: Update your variables here
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("Congrats! You created your first window!", 190, 200, 20, MAROON);
DrawText(GetFrameTime().ToString(), 100, 10, 15, MAROON);
DrawFPS(10, 10);
EndDrawing();
//----------------------------------------------------------------------------------
}
CloseWindow();
}
public static void Run()
{
Application.Run(new RayForms());
}
}
}

@ -1,6 +1,6 @@
/**********************************************************************************************
*
* Raylib 2.0 - A simple and easy-to-use library to learn videogames programming (www.raylib.com)
* Raylib - A simple and easy-to-use library to learn videogames programming (www.raylib.com)
* Original - https://github.com/raysan5/raylib/blob/master/src/raylib.h
*
**********************************************************************************************/
@ -528,12 +528,16 @@ namespace Raylib
// Shader type (generic)
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct Shader
public unsafe struct Shader
{
public uint id;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = Raylib.MAX_SHADER_LOCATIONS)]
public int[] locs;
// public IntPtr locs;
// [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.I1, SizeConst = Raylib.MAX_SHADER_LOCATIONS)]
// [MarshalAs(UnmanagedType.ByValArray, SizeConst = Raylib.MAX_SHADER_LOCATIONS)]
//[MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_I4)]
// public int[] locs;
public fixed int locs[Raylib.MAX_SHADER_LOCATIONS];
}
// Material texture map
@ -745,39 +749,43 @@ namespace Raylib
public static extern int GetScreenHeight();
// Get number of connected monitors
[DllImport(nativeLibName)]
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern int GetMonitorCount();
// Get primary monitor width
[DllImport(nativeLibName)]
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern int GetMonitorWidth(int monitor);
// Get primary monitor height
[DllImport(nativeLibName)]
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern int GetMonitorHeight(int monitor);
// Get primary monitor physical width in millimetres
[DllImport(nativeLibName)]
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern int GetMonitorPhysicalWidth(int monitor);
// Get primary monitor physical height in millimetres
[DllImport(nativeLibName)]
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern int GetMonitorPhysicalHeight(int monitor);
// Get the human-readable, UTF-8 encoded name of the primary monitor
[DllImport(nativeLibName)]
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern string GetMonitorName(int monitor);
// Get current clipboard text
//[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
//public static extern string GetClipboard();
// Get handle from window
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr GetWindowHandle();
// Set current clipboard text
//[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
//public static extern void SetClipboard(string text);
// Get current clipboard text
//[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
//public static extern string GetClipboard();
// Shows cursor
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
// Set current clipboard text
//[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
//public static extern void SetClipboard(string text);
// Shows cursor
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void ShowCursor();
// Hides cursor

Binary file not shown.

@ -1,63 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Raylib {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
public class RayForm {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal RayForm() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
public static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Raylib.RayForm", typeof(RayForm).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
public static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}

@ -1,14 +1,16 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
using static Raylib.Raylib;
namespace Raylib
{
class RayForm : Form
public partial class RayForms : Form
{
private Panel panel;
private Panel gamePanel;
private bool windowAttached = false;
#region WinAPI Entry Points
@ -21,38 +23,80 @@ namespace Raylib
#endregion
public RayForms()
{
Size = new Size(1024, 700);
Text = "Rayforms";
gamePanel = new Panel();
gamePanel.Size = new Size(800, 500);
gamePanel.Location = new Point(50, 50);
Button button = new Button();
button.Text = "Attach window";
button.Size = new Size(150, 20);
button.Location = new Point(
(Size.Width / 2) - (button.Size.Width / 2),
gamePanel.Location.Y + gamePanel.Size.Height + 10
);
button.Click += new EventHandler(ClickedButton);
Controls.Add(button);
Controls.Add(gamePanel);
}
private void ClickedButton(object sender, EventArgs e)
{
if (!windowAttached)
{
// new Thread(Test).Start();
Test();
}
}
private void Test()
{
SetConfigFlags((int)Flag.WINDOW_UNDECORATED);
InitWindow(800, 480, "Rayforms test");
SetTargetFPS(60);
IntPtr winHandle = GetWindowHandle();
Invoke(new Action(() =>
{
SetWindowPos(winHandle, Handle, 0, 0, 0, 0, 0x0401 /*NOSIZE | SHOWWINDOW */);
SetParent(winHandle, gamePanel.Handle);
ShowWindow(winHandle, 1);
windowAttached = true;
}));
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// TODO: Update your variables here
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("Congrats! You created your first window!", 190, 200, 20, MAROON);
DrawText(GetFrameTime().ToString(), 100, 10, 15, MAROON);
DrawFPS(10, 10);
EndDrawing();
//----------------------------------------------------------------------------------
}
CloseWindow();
}
public static void Run()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new RayForm());
}
public RayForm()
{
panel = new Panel();
panel.Size = new Size(640, 480);
panel.Location = new Point(80, 10);
panel.BackColor = System.Drawing.Color.Red;
Controls.Add(panel);
}
private void InitializeComponent()
{
this.SuspendLayout();
//
// DrawControl
//
this.ClientSize = new System.Drawing.Size(284, 261);
this.Name = "DrawControl";
this.Load += new System.EventHandler(this.DrawControl_Load);
this.ResumeLayout(false);
}
private void DrawControl_Load(object sender, EventArgs e)
{
Application.Run(new RayForms());
}
}
}

@ -1,120 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>