NotNotTech / Raylib-CsLo

autogen bindings to Raylib 4.x and convenience wrappers on top. Requires use of `unsafe`
Mozilla Public License 2.0
113 stars 9 forks source link

a lot of RAYGUI parameters require int* instead of int #37

Closed FormalSnake closed 4 months ago

FormalSnake commented 10 months ago

for example:

error CS0266: Cannot implicitly convert type 'int' to 'int*'. An explicit conversion exists (are you missing a cast?)
jasonswearingen commented 10 months ago

You need to learn to use unsafe in C#. it's not particularly hard, as you can just look at/copy the sample code under here: https://github.com/NotNotTech/Raylib-CsLo/tree/main/Raylib-CsLo.Examples

If you have a specific API you are having problems with, paste an example code and the problem.

FormalSnake commented 10 months ago

The thing is I am already using unsafe code. The csproj is unsafe, the classes are unsafe and the voids are unsafe

jasonswearingen commented 10 months ago

if you could give an example I'll try to explain further or help.

I think why you see int* is because it's a pointer to data, because pointers are the same sizeofan int. not because they actually want a pointer to an integer. (but sometimes they might want that)

FormalSnake commented 10 months ago

So, I am trying to change my GUISliderBar to a GuiSpinner, but it is expecting an int* and i have to put null in the name because it expects an sbyte instead of a string, and I do not know what an sbyte is :P

using Raylib_CsLo;
using static Raylib_CsLo.Raylib;
using static Raylib_CsLo.RayGui;
using System.Numerics;

namespace FormalEngine;

public unsafe class UI
{
        private Rectangle vector3EditorRect = new Rectangle(20, 40, 300, 140);
        private float sliderSensitivity = 1.0f;
        public Vector3 pos;

        public void Initialize()
        {
                vector3EditorRect = new Rectangle(10, 63, 300, 140);
                sliderSensitivity = 1.0f;
                pos = new Vector3(0.0f, 0.0f, 0.0f);
        }

        public unsafe void XYZEditor()
        {
                // Create a RayGUI window
                GuiGroupBox(vector3EditorRect, "");
                GuiPanel(vector3EditorRect, null);
                pos.X = GuiSpinner(
                    new Rectangle(vector3EditorRect.x + 90, vector3EditorRect.y + 30, 120, 20),
                    null,
                    (int)pos.X,
                    -100,
                    100,
                    true
                );
                // pos.X = GuiSliderBar(
                //  new Rectangle(vector3EditorRect.x + 90, vector3EditorRect.y + 30, 120, 20),
                //  "X",
                //  null,
                //  pos.X,
                //  -100.0f,
                //  100.0f
                // );
                pos.Y = GuiSliderBar(
                    new Rectangle(vector3EditorRect.x + 90, vector3EditorRect.y + 60, 120, 20),
                    "Y",
                    null,
                    pos.Y,
                    -100.0f,
                    100.0f
                );
                pos.Z = GuiSliderBar(
                    new Rectangle(vector3EditorRect.x + 90, vector3EditorRect.y + 90, 120, 20),
                    "Z",
                    null,
                    pos.Z,
                    -100.0f,
                    100.0f
                );
                DrawText($"Vector3: ({pos.X}, {pos.Y}, {pos.Z})", 10, 233, 20, DARKGRAY);
        }
}
jasonswearingen commented 4 months ago

a bit late, but I still think the problem is you need to pass a handle here. I think the examples offer a good how-to and I don't plan on investigating.