2
0
mirror of https://github.com/raylib-cs/raylib-cs synced 2025-06-30 19:03:42 -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:
2018-10-12 20:42:51 +01:00
parent 3b21284b5f
commit 3f17281969
8 changed files with 262 additions and 279 deletions

View File

@ -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" />

View File

@ -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
View 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());
}
}
}

View File

@ -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.