From 0a27525a4ba2ca9f8f6c4e723b50411549d6c558 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Wed, 1 Jun 2016 14:01:35 +0200 Subject: [PATCH] Dependencies review Checking some files to be converted to header-only --- src/camera.c | 2 +- src/gestures.c | 10 +++--- src/physac.c | 4 +-- src/raygui.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++---- src/raygui.h | 43 ++++++++++++++++++++++-- 5 files changed, 130 insertions(+), 17 deletions(-) diff --git a/src/camera.c b/src/camera.c index 8e5c527e1..11571ccad 100644 --- a/src/camera.c +++ b/src/camera.c @@ -30,7 +30,7 @@ #include "raylib.h" #endif -#include +#include // Required for: sqrt(), sin(), cos() //---------------------------------------------------------------------------------- // Defines and Macros diff --git a/src/gestures.c b/src/gestures.c index d72aaf4e9..d3b85d124 100644 --- a/src/gestures.c +++ b/src/gestures.c @@ -28,19 +28,19 @@ #if defined(GESTURES_STANDALONE) #include "gestures.h" #else - #include "raylib.h" // Required for typedef(s): Vector2, Gestures + #include "raylib.h" // Required for: Vector2, Gestures #endif -#include // Used for: atan2(), sqrt() -#include // Defines int32_t, int64_t +#include // Required for: atan2(), sqrt() +#include // Required for: uint64_t #if defined(_WIN32) // Functions required to query time on Windows int __stdcall QueryPerformanceCounter(unsigned long long int *lpPerformanceCount); int __stdcall QueryPerformanceFrequency(unsigned long long int *lpFrequency); #elif defined(__linux) - #include // Declares storage size of ‘now’ - #include // Used for clock functions + #include // Required for: timespec + #include // Required for: clock_gettime() #endif //---------------------------------------------------------------------------------- diff --git a/src/physac.c b/src/physac.c index 181488ac7..eed2f26e2 100644 --- a/src/physac.c +++ b/src/physac.c @@ -29,8 +29,8 @@ #include "raylib.h" #endif -#include // Declares malloc() and free() for memory management -#include // Declares cos(), sin(), abs() and fminf() for math operations +#include // Required for: malloc(), free() +#include // Required for: cos(), sin(), abs(), fminf() //---------------------------------------------------------------------------------- // Defines and Macros diff --git a/src/raygui.c b/src/raygui.c index 95cea0b66..40d7b265d 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 -#include -#include -#include // Required for malloc(), free() -#include // Required for strcmp() +#if defined(RAYGUI_STANDALONE) + #include "raygui.h" +#else + #include "raylib.h" +#endif + +#include // Required for: FILE, fopen(), fclose(), fprintf(), feof(), fscanf() + // NOTE: Those functions are only used in SaveGuiStyle() and LoadGuiStyle() + +#include // Required for: malloc(), free() +#include // 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 diff --git a/src/raygui.h b/src/raygui.h index 6906eca71..3951e087c 100644 --- a/src/raygui.h +++ b/src/raygui.h @@ -23,16 +23,55 @@ #ifndef RAYGUI_H #define RAYGUI_H -#include "raylib.h" +//#include "raylib.h" //---------------------------------------------------------------------------------- // Defines and Macros //---------------------------------------------------------------------------------- -#define NUM_PROPERTIES 98 +#define NUM_PROPERTIES 98 + +#define BLANK (Color){ 0, 0, 0, 0 } // Blank (Transparent) + +#define KEY_LEFT 263 +#define KEY_RIGHT 262 + +#define MOUSE_LEFT_BUTTON 0 + //---------------------------------------------------------------------------------- // Types and Structures Definition +// NOTE: Some types are required for RAYGUI_STANDALONE usage //---------------------------------------------------------------------------------- +#ifndef __cplusplus +// Boolean type + #ifndef true + typedef enum { false, true } bool; + #endif +#endif + +// Vector2 type +typedef struct Vector2 { + float x; + float y; +} Vector2; + +// Color type, RGBA (32bit) +typedef struct Color { + unsigned char r; + unsigned char g; + unsigned char b; + unsigned char a; +} Color; + +// Rectangle type +typedef struct Rectangle { + int x; + int y; + int width; + int height; +} Rectangle; + +// Gui properties enumeration typedef enum GuiProperty { GLOBAL_BASE_COLOR = 0, GLOBAL_BORDER_COLOR,