New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Review standalone usage mechanism #12
Comments
Some work on this issue on commit bbcf2e9 To use // Input required functions
//-------------------------------------------------------------------------------
static Vector2 GetMousePosition(void) { return (Vector2){ 0, 0 }; }
static int GetMouseWheelMove(void) { return 0; }
static bool IsMouseButtonDown(int button) { return false; }
static bool IsMouseButtonPressed(int button) { return false; }
static bool IsMouseButtonReleased(int button) { return false; }
static bool IsKeyDown(int key) { return false; }
static bool IsKeyPressed(int key) { return false; }
static int GetKeyPressed(void) { return 0; } // -- GuiTextBox()
//-------------------------------------------------------------------------------
// Drawing required functions
//-------------------------------------------------------------------------------
static void DrawRectangle(int x, int y, int width, int height, Color color) { /* TODO */ }
static void DrawRectangleRec(Rectangle rec, Color color) { DrawRectangle(rec.x, rec.y, rec.width, rec.height, color); }
static void DrawRectangleLinesEx(Rectangle rec, int lineThick, Color color) { /* TODO */ }
static void DrawRectangleLines(int x, int y, int width, int height, Color color) { /* TODO */ } // -- GuiColorPicker()
static void DrawRectangleGradientV(int posX, int posY, int width, int height, Color color1, Color color2); // -- GuiColorPicker()
static void DrawRectangleGradientH(int posX, int posY, int width, int height, Color color1, Color color2); // -- GuiColorPicker()
static void DrawRectangleGradientEx(Rectangle rec, Color col1, Color col2, Color col3, Color col4); // -- GuiColorPicker()
static void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color) { /* TODO */ } // -- GuiDropdownBox()
static void DrawLineEx(Vector2 startPos, Vector2 endPos, float thick, Color color) { /* TODO */ } // -- GuiScrollBar()
static void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint) { } // -- GuiImageButtonEx()
//-------------------------------------------------------------------------------
// Text required functions
//-------------------------------------------------------------------------------
static Font GetFontDefault(void); // -- GetTextWidth()
static Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing) { return (Vector2){ 0.0f }; } // Measure text size depending on font
static void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint) { } // Draw text using font and additional parameters
//------------------------------------------------------------------------------- Note that some of those functions are only used by some specific control, in case that control is not required, it could be removed with the function dependency. Also note some drawing functions could probably be removed or simplified to use some other function, i.e. Rectangle drawing functions could all be simplified to only one function usage. Main issue comes when dealing with Next steps on this issue would be:
Keep working on it. Feedback is welcome! |
I think the current system is working well, I found it quite easy to integrate into my engine. It would probably be a mistake to provide an implementation of the Font and Texture2D structures, they need to be whatever is required by the engine that is being used. An example project with SDL would be nice, and simplifying the required drawing functions would help, but really I don't think it is difficult at the moment anyway. One minor issue is that in a recent commit you added this line to GuiLoadStyle() |
@simonwashere thanks for reporting! Agree that an SDL sample would be great, actually, it has been on my raygui TODO list for long time... Also aware of |
Ahh, here is how I got it working back then. All the myXXX function type where avail on the host side, in my case delphi: typedef int (*myMeasureText)(const char *text, int fontSize);
typedef void (*myDrawText)(const char *text, int posX, int posY, int fontSize, Color color);
typedef void (*myDrawRectangle)(int x, int y, int width, int height, Color color);
typedef Vector2 (*myGetMousePosition)(void);
typedef bool (*myIsMouseButtonDown)(int button);
typedef bool (*myIsMouseButtonReleased)(int button);
typedef bool (*myIsMouseButtonUp)(int button);
typedef int (*myGetKeyPressed)(void);
typedef bool (*myIsKeyPressed)(int key);
typedef bool (*myIsKeyDown)(int key);
typedef void (*myDrawRectangleLines)(int x, int y, int width, int height, Color color);
typedef void (*myDrawRectangleGradientV)(int posX, int posY, int width, int height, Color color1, Color color2);
typedef void (*myDrawRectangleGradientH)(int posX, int posY, int width, int height, Color color1, Color color2);
typedef void (*myDrawRectangleGradientEx)(Rectangle rec, Color col1, Color col2, Color col3, Color col4);
typedef void (*myDrawTexture)(Texture2D texture, int posX, int posY, Color tint);
myMeasureText MeasureTextFunc = NULL;
myDrawText DrawTextFunc = NULL;
myDrawRectangle DrawRectangleFunc = NULL;
myGetMousePosition GetMousePositionFunc = NULL;
myIsMouseButtonDown IsMouseButtonDownFunc = NULL;
myIsMouseButtonReleased IsMouseButtonReleasedFunc = NULL;
myIsMouseButtonUp IsMouseButtonUpFunc = NULL;
myGetKeyPressed GetKeyPressedFunc = NULL;
myIsKeyPressed IsKeyPressedFunc = NULL;
myIsKeyDown IsKeyDownFunc = NULL;
myDrawRectangleLines DrawRectangleLinesFunc = NULL;
myDrawRectangleGradientV DrawRectangleGradientVFunc = NULL;
myDrawRectangleGradientH DrawRectangleGradientHFunc = NULL;
myDrawRectangleGradientEx DrawRectangleGradientExFunc = NULL;
myDrawTexture DrawTextureFunc = NULL;
//---
static int MeasureText(const char *text, int fontSize) { MeasureTextFunc(text, fontSize); }
static void DrawText(const char *text, int posX, int posY, int fontSize, Color color) { DrawTextFunc(text, posX, posY, fontSize, color); }
static void DrawRectangle(int x, int y, int width, int height, Color color) { DrawRectangleFunc(x, y, width, height, color); }
static void DrawRectangleRec(Rectangle rec, Color color) { DrawRectangle(rec.x, rec.y, rec.width, rec.height, color); }
// Input related functions
static Vector2 GetMousePosition(void) { return GetMousePositionFunc(); }
static bool IsMouseButtonDown(int button) {return IsMouseButtonDownFunc(button); }
static bool IsMouseButtonReleased(int button) {return IsMouseButtonReleasedFunc(button); }
static bool IsMouseButtonUp(int button) {return IsMouseButtonUpFunc(button);}
static int GetKeyPressed(void) {return GetKeyPressedFunc();}
static bool IsKeyPressed(int key) {return IsKeyPressedFunc(key); }
static bool IsKeyDown(int key) {return IsKeyDownFunc(key); }
// Control specific functions
static void DrawRectangleLines(int x, int y, int width, int height, Color color) { DrawRectangleLinesFunc(x, y, width, height, color); }
static void DrawRectangleGradientV(int posX, int posY, int width, int height, Color color1, Color color2) { DrawRectangleGradientVFunc(posX, posY, width, height, color1, color2); }
static void DrawRectangleGradientH(int posX, int posY, int width, int height, Color color1, Color color2) { DrawRectangleGradientHFunc(posX, posY, width, height, color1, color2); }
static void DrawRectangleGradientEx(Rectangle rec, Color col1, Color col2, Color col3, Color col4) { DrawRectangleGradientExFunc(rec, col1, col2, col3, col4); }
static void DrawTexture(Texture2D texture, int posX, int posY, Color tint) { DrawTextureFunc(texture, posX, posY, tint); } |
Closing the issue. Current mechanism looks ok for me. |
Right now raygui is quite tied to raylib, using a specific set of raylib functions.
Despite being possible to hook other library functions to raygui, I feel current mechanism is not easy enough... or at least, has not been properly tested. It should be reviewed.
raygui required functions include:
The idea is to expose and minimize external required hooks to cover the basic raygui needs.
The text was updated successfully, but these errors were encountered: