diff options
| author | raysan5 <raysan5@gmail.com> | 2016-06-01 14:01:35 +0200 |
|---|---|---|
| committer | raysan5 <raysan5@gmail.com> | 2016-06-01 14:01:35 +0200 |
| commit | 0a27525a4ba2ca9f8f6c4e723b50411549d6c558 (patch) | |
| tree | 22392949117f3b95327e01371cfba13ff6ed61db /src/raygui.c | |
| parent | 3e88156817d5de5cc413acf67f0fd0a39a69acb2 (diff) | |
| download | raylib-0a27525a4ba2ca9f8f6c4e723b50411549d6c558.tar.gz raylib-0a27525a4ba2ca9f8f6c4e723b50411549d6c558.zip | |
Dependencies review
Checking some files to be converted to header-only
Diffstat (limited to 'src/raygui.c')
| -rw-r--r-- | src/raygui.c | 88 |
1 files changed, 81 insertions, 7 deletions
diff --git a/src/raygui.c b/src/raygui.c index 95cea0b6..40d7b265 100644 --- a/src/raygui.c +++ b/src/raygui.c @@ -5,6 +5,13 @@ * Initial design by Kevin Gato and Daniel Nicolás * Reviewed by Albert Martos, Ian Eito, Sergio Martinez and Ramon Santamaria (@raysan5) * +* The following functions from raylib are required for drawing and input reading: + GetColor(), GetHexValue() --> Used on SetStyleProperty() + MeasureText(), GetDefaultFont() + DrawRectangleRec(), DrawRectangle(), DrawText(), DrawLine() + GetMousePosition(), (), IsMouseButtonDown(), IsMouseButtonReleased() + 'FormatText(), IsKeyDown(), 'IsMouseButtonUp() +* * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. * @@ -22,12 +29,20 @@ * **********************************************************************************************/ -#include "raygui.h" +#define RAYGUI_STANDALONE // NOTE: To use the raygui module as standalone lib, just uncomment this line + // NOTE: Some external funtions are required for drawing and input management + +#if defined(RAYGUI_STANDALONE) + #include "raygui.h" +#else + #include "raylib.h" +#endif -#include <math.h> -#include <stdio.h> -#include <stdlib.h> // Required for malloc(), free() -#include <string.h> // Required for strcmp() +#include <stdio.h> // Required for: FILE, fopen(), fclose(), fprintf(), feof(), fscanf() + // NOTE: Those functions are only used in SaveGuiStyle() and LoadGuiStyle() + +#include <stdlib.h> // Required for: malloc(), free() +#include <string.h> // Required for: strcmp() //---------------------------------------------------------------------------------- // Defines and Macros @@ -157,6 +172,21 @@ static int style[NUM_PROPERTIES] = { //---------------------------------------------------------------------------------- static Color ColorMultiply(Color baseColor, float value); +#if defined RAYGUI_STANDALONE +static Color GetColor(int hexValue); // Returns a Color struct from hexadecimal value +static int GetHexValue(Color color); // Returns hexadecimal value for a Color +static bool CheckCollisionPointRec(Vector2 point, Rectangle rec); // Check if point is inside rectangle + +// NOTE: raygui depend on some raylib input and drawing functions +// TODO: Set your own input functions (used in ProcessCamera()) +static Vector2 GetMousePosition() { return (Vector2){ 0.0f, 0.0f }; } +static int IsMouseButtonDown(int button) { return 0; } +static int IsMouseButtonPressed(int button) { return 0; } +static int IsMouseButtonReleased(int button) { return 0; } +static int IsMouseButtonUp(int button) { return 0; } +static int IsKeyDown(int key) { return 0; } +#endif + //---------------------------------------------------------------------------------- // Module Functions Definition //---------------------------------------------------------------------------------- @@ -164,7 +194,7 @@ static Color ColorMultiply(Color baseColor, float value); // Label element, show text void GuiLabel(Rectangle bounds, const char *text) { - GuiLabelEx(bounds,text, GetColor(style[LABEL_TEXT_COLOR]), BLANK, BLANK); + GuiLabelEx(bounds, text, GetColor(style[LABEL_TEXT_COLOR]), BLANK, BLANK); } // Label element extended, configurable colors @@ -1051,4 +1081,48 @@ static Color ColorMultiply(Color baseColor, float value) multColor.b += (255 - multColor.b)*value; return multColor; -}
\ No newline at end of file +} + +#if defined (RAYGUI_STANDALONE) +// Returns a Color struct from hexadecimal value +static Color GetColor(int hexValue) +{ + Color color; + + color.r = (unsigned char)(hexValue >> 24) & 0xFF; + color.g = (unsigned char)(hexValue >> 16) & 0xFF; + color.b = (unsigned char)(hexValue >> 8) & 0xFF; + color.a = (unsigned char)hexValue & 0xFF; + + return color; +} + +// Returns hexadecimal value for a Color +static int GetHexValue(Color color) +{ + return (((int)color.r << 24) | ((int)color.g << 16) | ((int)color.b << 8) | (int)color.a); +} + +// Check if point is inside rectangle +static bool CheckCollisionPointRec(Vector2 point, Rectangle rec) +{ + bool collision = false; + + if ((point.x >= rec.x) && (point.x <= (rec.x + rec.width)) && (point.y >= rec.y) && (point.y <= (rec.y + rec.height))) collision = true; + + return collision; +} + +// Formatting of text with variables to 'embed' +static const char *FormatText(const char *text, ...) +{ + static char buffer[MAX_FORMATTEXT_LENGTH]; + + va_list args; + va_start(args, text); + vsprintf(buffer, text, args); + va_end(args); + + return buffer; +} +#endif
\ No newline at end of file |
