aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorraysan5 <raysan5@gmail.com>2016-06-01 14:01:35 +0200
committerraysan5 <raysan5@gmail.com>2016-06-01 14:01:35 +0200
commit0a27525a4ba2ca9f8f6c4e723b50411549d6c558 (patch)
tree22392949117f3b95327e01371cfba13ff6ed61db /src
parent3e88156817d5de5cc413acf67f0fd0a39a69acb2 (diff)
downloadraylib-0a27525a4ba2ca9f8f6c4e723b50411549d6c558.tar.gz
raylib-0a27525a4ba2ca9f8f6c4e723b50411549d6c558.zip
Dependencies review
Checking some files to be converted to header-only
Diffstat (limited to 'src')
-rw-r--r--src/camera.c2
-rw-r--r--src/gestures.c10
-rw-r--r--src/physac.c4
-rw-r--r--src/raygui.c88
-rw-r--r--src/raygui.h43
5 files changed, 130 insertions, 17 deletions
diff --git a/src/camera.c b/src/camera.c
index 8e5c527e..11571cca 100644
--- a/src/camera.c
+++ b/src/camera.c
@@ -30,7 +30,7 @@
#include "raylib.h"
#endif
-#include <math.h>
+#include <math.h> // Required for: sqrt(), sin(), cos()
//----------------------------------------------------------------------------------
// Defines and Macros
diff --git a/src/gestures.c b/src/gestures.c
index d72aaf4e..d3b85d12 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 <math.h> // Used for: atan2(), sqrt()
-#include <stdint.h> // Defines int32_t, int64_t
+#include <math.h> // Required for: atan2(), sqrt()
+#include <stdint.h> // 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 <sys/time.h> // Declares storage size of ‘now’
- #include <time.h> // Used for clock functions
+ #include <sys/time.h> // Required for: timespec
+ #include <time.h> // Required for: clock_gettime()
#endif
//----------------------------------------------------------------------------------
diff --git a/src/physac.c b/src/physac.c
index 181488ac..eed2f26e 100644
--- a/src/physac.c
+++ b/src/physac.c
@@ -29,8 +29,8 @@
#include "raylib.h"
#endif
-#include <stdlib.h> // Declares malloc() and free() for memory management
-#include <math.h> // Declares cos(), sin(), abs() and fminf() for math operations
+#include <stdlib.h> // Required for: malloc(), free()
+#include <math.h> // Required for: cos(), sin(), abs(), fminf()
//----------------------------------------------------------------------------------
// Defines and Macros
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
diff --git a/src/raygui.h b/src/raygui.h
index 6906eca7..3951e087 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,