Giter Club home page Giter Club logo

Comments (5)

raysan5 avatar raysan5 commented on August 15, 2024

Some work on this issue on commit bbcf2e9

To use raygui with other graphic libraries than raylib, following functions should be provided by the user:

// 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 Font and Texture2D, those structs are very raylib specific and they should be mapped to similar implementations on other libraries, it could take some work.

Next steps on this issue would be:

  • Simplify shapes drawing functions required, a generic DrawRectangle() should be enough. Non-squared-shape elements could use rIcons or text characters.
  • Find a proper way to deal with Font and Texture2D structs, maybe just providing the implementation os some minimal API to deal with it...
  • Create a raygui standalone usage example with SDL.

Keep working on it. Feedback is welcome!

from raygui.

simonwashere avatar simonwashere commented on August 15, 2024

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()
Font font = LoadFontEx(FormatText("%s/%s", GetDirectoryPath(fileName), fontFileName), fontSize, NULL, 0);
and it uses three new functions from raylib that weren't needed before. Maybe have a define to not use styles?

from raygui.

raysan5 avatar raysan5 commented on August 15, 2024

@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 GuiLoadStyle() new dependencies, it was a quick addition for the talk I gave... need to find a better alternative, probably font data could be embedded in the .rgs text file, in a similar way I do with the style.h code generation... I'd think about it... fonts are always too dependant on underlying technology...

from raygui.

 avatar commented on August 15, 2024
  1. Map those routines to function pointers (make them exportable, in standalone mode)
  2. Use a pointer to the font struct instead.
  3. Now one could set standalone mode, everything gets exported, then map the routines on the host side and since the font struct is a pointer its implemented on the host side without issue.
  4. I did this before in an older version (1.x raylib time frame, I think 1.5 or 1.6 I believe) and was able to use it from Delphi. I need to find those sources.

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); }

from raygui.

raysan5 avatar raysan5 commented on August 15, 2024

Closing the issue. Current mechanism looks ok for me.

from raygui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.