Dependencies review

Checking some files to be converted to header-only
This commit is contained in:
raysan5 2016-06-01 14:01:35 +02:00
parent 3e88156817
commit 0a27525a4b
5 changed files with 130 additions and 17 deletions

View File

@ -30,7 +30,7 @@
#include "raylib.h"
#endif
#include <math.h>
#include <math.h> // Required for: sqrt(), sin(), cos()
//----------------------------------------------------------------------------------
// Defines and Macros

View File

@ -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
//----------------------------------------------------------------------------------

View File

@ -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

View File

@ -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 <math.h>
#include <stdio.h>
#include <stdlib.h> // Required for malloc(), free()
#include <string.h> // Required for strcmp()
#if defined(RAYGUI_STANDALONE)
#include "raygui.h"
#else
#include "raylib.h"
#endif
#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;
}
}
#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

View File

@ -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,