Comments (5)
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 userIcons
or text characters. - Find a proper way to deal with
Font
andTexture2D
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.
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.
@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.
- Map those routines to function pointers (make them exportable, in standalone mode)
- Use a pointer to the font struct instead.
- 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.
- 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.
Closing the issue. Current mechanism looks ok for me.
from raygui.
Related Issues (20)
- Dynamic depth management HOT 4
- Input blocking / input event consuming HOT 2
- [Feature Request] Keyboard Navigation HOT 2
- Error - cannot convert bool* to int* HOT 1
- [Feature Request] Accessibility support? HOT 5
- Problem with Installation HOT 1
- Problem when define HOT 2
- Documentation on the `rgs` format HOT 2
- Issue with Unicode input on `GuiTextBox()` HOT 1
- Compile for Rapberry Pi 2B HOT 3
- Raspberry Pi - touch does not works. HOT 3
- Define a consistent convention on controls return values
- missing .c file in src ? HOT 2
- GuiLoadIcons example? HOT 4
- ``TextToFloat`` was not declared in this scope when compiling a raygui program HOT 8
- Multiple definitions of raygui functions HOT 2
- Check whatever any GUI element was just clicked HOT 2
- GetTextWidth returns incorrect value for multi-line strings
- GuiListView can only draw 128 items
- Does this work with the master branch of raylib? - Zig Compilation Error HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from raygui.