From 53f77597da2c0aa27efb127486b00e921c996863 Mon Sep 17 00:00:00 2001
From: ChrisDill <chris.rj.dill@gmail.com>
Date: Wed, 1 Aug 2018 17:17:53 +0100
Subject: [PATCH] Setup basic class to test with windows forms

- Added DrawControl class to test windows forms with raylib. Need a way to get the window handle?
---
 ExampleApplication/Program.cs                 |  46 +------
 ExampleApplication/Raylib-cs/DrawControl.cs   |  38 ++++++
 ExampleApplication/Raylib-cs/DrawControl.resx | 120 ++++++++++++++++++
 ExampleApplication/Raylib-cs/Raylib.cs        |  44 +++----
 README.md                                     |  24 ++--
 5 files changed, 193 insertions(+), 79 deletions(-)
 create mode 100644 ExampleApplication/Raylib-cs/DrawControl.cs
 create mode 100644 ExampleApplication/Raylib-cs/DrawControl.resx

diff --git a/ExampleApplication/Program.cs b/ExampleApplication/Program.cs
index 16bdba5..8c807f3 100644
--- a/ExampleApplication/Program.cs
+++ b/ExampleApplication/Program.cs
@@ -7,49 +7,9 @@ namespace ExampleApplication
     {
         static void Main(string[] args)
         {
-            // LoadApp();
-            Run();
-        }
-
-        public static int Run()
-        {
-            // Initialization
-            //--------------------------------------------------------------------------------------
-            int screenWidth = 800;
-            int screenHeight = 450;
-
-            InitWindow(screenWidth, screenHeight, "Raylib-cs [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, LIGHTGRAY);
-                DrawFPS(0, 0);
-
-                EndDrawing();
-                //----------------------------------------------------------------------------------
-            }
-
-            // De-Initialization
-            //--------------------------------------------------------------------------------------   
-            CloseWindow();        // Close window and OpenGL context
-            //-----------------------------
-
-            return 0;
+            // LoadApp();           
+            Examples.shapes_basic_shapes();
+            // DrawControl.Run();
         }
     }
 }
\ No newline at end of file
diff --git a/ExampleApplication/Raylib-cs/DrawControl.cs b/ExampleApplication/Raylib-cs/DrawControl.cs
new file mode 100644
index 0000000..d26e090
--- /dev/null
+++ b/ExampleApplication/Raylib-cs/DrawControl.cs
@@ -0,0 +1,38 @@
+using System;
+using System.Drawing;
+using System.Runtime.InteropServices;
+using System.Windows.Forms;
+
+namespace Raylib
+{
+    class DrawControl : Form
+    {
+        private Panel panel;
+
+        [DllImport("user32.dll")]
+        private static extern IntPtr SetParent(IntPtr child, IntPtr newParent);
+        [DllImport("user32.dll")]
+        private static extern IntPtr ShowWindow(IntPtr handle, int command);
+
+        public static void Run()
+        {
+            Application.EnableVisualStyles();
+            Application.SetCompatibleTextRenderingDefault(false);
+            Application.Run(new DrawControl());
+        }
+
+        public DrawControl()
+        {
+            panel = new Panel();
+            panel.Size = new Size(640, 480);
+            panel.Location = new Point(80, 10);
+            panel.BackColor = System.Drawing.Color.Red;
+            Controls.Add(panel);
+
+            // TODO: get raylib window handle?
+            IntPtr winHandle = IntPtr.Zero;
+            SetParent(winHandle, panel.Handle);
+            ShowWindow(winHandle, 1);
+        }
+    }
+}
\ No newline at end of file
diff --git a/ExampleApplication/Raylib-cs/DrawControl.resx b/ExampleApplication/Raylib-cs/DrawControl.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/ExampleApplication/Raylib-cs/DrawControl.resx
@@ -0,0 +1,120 @@
+<?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>
\ No newline at end of file
diff --git a/ExampleApplication/Raylib-cs/Raylib.cs b/ExampleApplication/Raylib-cs/Raylib.cs
index 579add6..605bacf 100644
--- a/ExampleApplication/Raylib-cs/Raylib.cs
+++ b/ExampleApplication/Raylib-cs/Raylib.cs
@@ -164,7 +164,7 @@ namespace Raylib
     }
 
     // Keyboard Function Keys
-    public enum Keys
+    public enum Key
     {
         SPACE = 32,
         ESCAPE = 256,
@@ -1017,7 +1017,7 @@ namespace Raylib
 
         // Update camera position for selected mode
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
-        public static extern void UpdateCamera(ref Camera camera);
+        public static extern void UpdateCamera(Camera camera);
 
         // Set camera pan key to combine with mouse movement (free camera)
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@@ -1223,24 +1223,24 @@ namespace Raylib
         // Image manipulation functions
 
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
-        public static extern void ImageToPOT(ref Image image, Color fillColor); // Convert image to POT (power-of-two)
+        public static extern void ImageToPOT(Image image, Color fillColor); // Convert image to POT (power-of-two)
 
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
-        public static extern void ImageFormat(ref Image image, int newFormat); // Convert image data to desired format
+        public static extern void ImageFormat(Image image, int newFormat); // Convert image data to desired format
 
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
-        public static extern void ImageAlphaMask(ref Image image, Image alphaMask); // Apply alpha mask to image
+        public static extern void ImageAlphaMask(Image image, Image alphaMask); // Apply alpha mask to image
 
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
         public static extern void
-            ImageDither(ref Image image, int rBpp, int gBpp, int bBpp,
+            ImageDither(Image image, int rBpp, int gBpp, int bBpp,
                 int aBpp); // Dither image data to 16bpp or lower (Floyd-Steinberg dithering)
 
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
         public static extern Image ImageCopy(Image image); // Create an image duplicate (useful for transformations)
 
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
-        public static extern void ImageCrop(ref Image image, Rectangle crop); // Crop an image to a defined rectangle
+        public static extern void ImageCrop( Image image, Rectangle crop); // Crop an image to a defined rectangle
 
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
         public static extern void
@@ -1248,7 +1248,7 @@ namespace Raylib
 
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
         public static extern void
-            ImageResizeNN(ref Image image, int newWidth,
+            ImageResizeNN(Image image, int newWidth,
                 int newHeight); // Resize and image (Nearest-Neighbor scaling algorithm)
 
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@@ -1262,40 +1262,40 @@ namespace Raylib
 
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
         public static extern void
-            ImageDraw(ref Image dst, Image src, Rectangle srcRec,
+            ImageDraw(Image dst, Image src, Rectangle srcRec,
                 Rectangle dstRec); // Draw a source image within a destination image
 
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
         public static extern void
-            ImageDrawText(ref Image dst, Vector2 position, string text, int fontSize,
+            ImageDrawText(Image dst, Vector2 position, string text, int fontSize,
                 Color color); // Draw text (default font) within an image (destination)
 
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
-        public static extern void ImageDrawTextEx(ref Image dst, Vector2 position, Font font, string text,
+        public static extern void ImageDrawTextEx(Image dst, Vector2 position, Font font, string text,
             int fontSize, int spacing, Color color); // Draw text (custom sprite font) within image
 
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
-        public static extern void ImageFlipVertical(ref Image image); // Flip image vertically
+        public static extern void ImageFlipVertical(Image image); // Flip image vertically
 
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
         public static extern void ImageFlipHorizontal(ref Image image); // Flip image horizontally
 
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
-        public static extern void ImageColorTint(ref Image image, Color color); // Modify image color: tint
+        public static extern void ImageColorTint(Image image, Color color); // Modify image color: tint
 
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
-        public static extern void ImageColorInvert(ref Image image); // Modify image color: invert
+        public static extern void ImageColorInvert(Image image); // Modify image color: invert
 
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
-        public static extern void ImageColorGrayscale(ref Image image); // Modify bimage color: grayscale
+        public static extern void ImageColorGrayscale(Image image); // Modify bimage color: grayscale
 
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
         public static extern void
-            ImageColorContrast(ref Image image, float contrast); // Modify image color: contrast (-100 to 100)
+            ImageColorContrast(Image image, float contrast); // Modify image color: contrast (-100 to 100)
 
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
         public static extern void
-            ImageColorBrightness(ref Image image, int brightness); // Modify image color: brightness (-255 to 255)
+            ImageColorBrightness(Image image, int brightness); // Modify image color: brightness (-255 to 255)
 
         // Image generation functions
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@@ -1329,7 +1329,7 @@ namespace Raylib
 
         // Texture2D configuration functions
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
-        public static extern void GenTextureMipmaps(ref Texture2D texture); // Generate GPU mipmaps for a texture
+        public static extern void GenTextureMipmaps(Texture2D texture); // Generate GPU mipmaps for a texture
 
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
         public static extern void
@@ -1479,7 +1479,7 @@ namespace Raylib
         public static extern Mesh LoadMesh(string fileName); // Load mesh from file
 
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
-        public static extern void UnloadMesh(ref Mesh mesh); // Unload mesh from memory (RAM and/or VRAM)
+        public static extern void UnloadMesh(Mesh mesh); // Unload mesh from memory (RAM and/or VRAM)
 
         // Mesh generation functions
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@@ -1672,7 +1672,7 @@ namespace Raylib
 
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
         public static extern void
-            UpdateVrTracking(ref Camera camera); // Update VR tracking (position and orientation) and camera
+            UpdateVrTracking(Camera camera); // Update VR tracking (position and orientation) and camera
 
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
         public static extern void ToggleVrMode(); // Enable/Disable VR experience
@@ -1748,7 +1748,7 @@ namespace Raylib
 
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
         public static extern void
-            WaveFormat(ref Wave wave, int sampleRate, int sampleSize,
+            WaveFormat(Wave wave, int sampleRate, int sampleSize,
                 int channels); // Convert wave data to desired format
 
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@@ -1756,7 +1756,7 @@ namespace Raylib
 
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
         public static extern void
-            WaveCrop(ref Wave wave, int initSample, int finalSample); // Crop a wave to defined samples range
+            WaveCrop(Wave wave, int initSample, int finalSample); // Crop a wave to defined samples range
 
         [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
         public static extern float[] GetWaveData(Wave wave); // Get samples data from wave as a floats array
diff --git a/README.md b/README.md
index 8673456..51f0704 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,13 @@
-# Raylib-cs
+# raylib-cs
 
-Testing C# bindings for Raylib, a simple and easy-to-use library to learn videogames programming (www.raylib.com)
+C# bindings for raylib 2.0, a simple and easy-to-use library to learn videogames programming (www.raylib.com)
 
-![](header.png)
+## Installation
+Windows:
+- Download the repository
+- Open Raylib-cs.sln
+- Copy x86 or x64 dll inside ExampleApplication to your output folder
+- Build and run
 
 # TODO:
 ## Cppsharp generator:
@@ -16,20 +21,11 @@ Testing C# bindings for Raylib, a simple and easy-to-use library to learn videog
 - Allow raylib to be used inside windows forms
 - Convert across raylib examples
 
-## Installation
-Windows:
-- Download the repository
-- Open Raylib-cs.sln
-- Copy x86 or x64 dll inside ExampleApplication to your output folder
-- Build and run
-
 ## Contributing
-As I use this for my own projects, I know this might not be the perfect approach
-for all the projects out there. If you have any ideas, just
-open an issue and tell me what you think.
+If you have any ideas, feel free to open an issue and tell me what you think.
 
 If you'd like to contribute, please fork the repository and make changes as
 you'd like. Pull requests are warmly welcome.
 
 ## Licensing
-Raylib-cs is licensed under an unmodified zlib/libpng license, which is an OSI-certified, BSD-like license that allows static linking with closed source software. Check [LICENSE](LICENSE) for further details.
+raylib-cs is licensed under an unmodified zlib/libpng license, which is an OSI-certified, BSD-like license that allows static linking with closed source software. Check [LICENSE](LICENSE) for further details.