diff --git a/Generator/App.config b/Generator/App.config
new file mode 100644
index 0000000..731f6de
--- /dev/null
+++ b/Generator/App.config
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Generator/Dia2Dump.exe b/Generator/Dia2Dump.exe
new file mode 100644
index 0000000..028d3be
Binary files /dev/null and b/Generator/Dia2Dump.exe differ
diff --git a/Generator/Generator.csproj b/Generator/Generator.csproj
new file mode 100644
index 0000000..55b99bc
--- /dev/null
+++ b/Generator/Generator.csproj
@@ -0,0 +1,78 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {0ADEB5B1-BF57-4D45-BE28-176C1D79C764}
+ Exe
+ Generator
+ Generator
+ v4.6.1
+ 512
+ true
+ true
+
+
+ AnyCPU
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ AnyCPU
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 2.10.0
+
+
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+
+
\ No newline at end of file
diff --git a/Generator/Program.cs b/Generator/Program.cs
new file mode 100644
index 0000000..33763f8
--- /dev/null
+++ b/Generator/Program.cs
@@ -0,0 +1,679 @@
+using System;
+using System.IO;
+using System.Collections.Generic;
+using System.Linq;
+using System.Globalization;
+using Microsoft.CodeAnalysis.CSharp.Syntax;
+using Microsoft.CodeAnalysis.CSharp;
+using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
+using Microsoft.CodeAnalysis;
+using System.Diagnostics;
+
+namespace Generator
+{
+ public struct TypeMember
+ {
+ public string Name;
+ public Type Type;
+ public int Offset;
+ public TypeMember(string name, Type type, int offset)
+ {
+ Name = name;
+ Type = type;
+ Offset = offset;
+ }
+ }
+
+ public struct UserDefinedEnumData
+ {
+ public string Name;
+ public List> Enums;
+ public UserDefinedEnumData(string name)
+ {
+ Name = name;
+ Enums = new List>();
+ }
+ }
+
+ public struct UserDefinedTypeData
+ {
+ public string Name;
+ public List Members;
+
+ public UserDefinedTypeData(string name)
+ {
+ Name = name;
+ Members = new List();
+ }
+ }
+
+
+ public struct Function
+ {
+ public string Name;
+ public Type ReturnType;
+ public List Params;
+
+ public Function(string name, string returnType, params FunctionParam[] parameters)
+ {
+ var Isreturnpointer = name[0] == '*';
+ Name = Isreturnpointer ? name.Replace("*","") : name;
+ ReturnType = new Type(returnType, Isreturnpointer);
+ Params = new List(parameters);
+
+ }
+
+
+ public override string ToString()
+ {
+ var str = $"{ReturnType} {Name}(";
+ for (int i = 0; i < Params.Count; i++)
+ {
+ if (i != 0) str += ",";
+ str += $"{Params[i].ToString()}";
+ }
+ str += ")";
+ return str;
+ }
+ }
+
+ public struct Type
+ {
+ public string Name;
+ public bool IsPointer;
+
+ public Type(string name, bool isPointer)
+ {
+ Name = name;
+ IsPointer = isPointer;
+ }
+
+
+ public override string ToString()
+ {
+ return Name + (IsPointer == true ? "*" : "");
+ }
+ }
+
+ public struct FunctionParam
+ {
+ public string Name;
+ public Type Type;
+
+ public FunctionParam(string name, Type type)
+ {
+ Name = name;
+ Type = type;
+ }
+
+ public FunctionParam(string FullParam)
+ {
+ FullParam = FullParam.Trim();
+ if (FullParam.Split(' ').Length == 2)
+ {
+ var Isreturnpointer = FullParam.Split(' ')[1][0] == '*';
+ Name = Isreturnpointer ? FullParam.Replace("*", "").Split(' ')[1] : FullParam.Split(' ')[1];
+ Type = new Type(FullParam.Replace("*", "").Split(' ')[0], Isreturnpointer);
+ }
+ else
+ {
+ var Isreturnpointer = FullParam.Split(' ')[2][0] == '*';
+ Name = Isreturnpointer ? FullParam.Replace("*","").Split(' ')[2] : FullParam.Split(' ')[2];
+ Type = new Type(FullParam.Replace("*", "").Split(' ')[0] + " " + FullParam.Replace("*", "").Split(' ')[1], Isreturnpointer);
+ }
+ }
+
+ public override string ToString()
+ {
+ return Name == "..." ? "..." : $"{Type.ToString()} {Name}";
+ }
+ }
+
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ var process = Process.Start(new ProcessStartInfo("Dia2Dump.exe", " -t raylib.pdb") { RedirectStandardOutput = true, UseShellExecute = false });
+ string typedata = "";
+ var ischkout = process.StandardOutput;
+ while (process.HasExited == false)
+ {
+ typedata += ischkout.ReadToEnd();
+ }
+ File.WriteAllText("types.txt", typedata);
+ var typesfile = File.ReadAllLines("types.txt");
+ var TypeMap = new Dictionary();
+ typesfile = typesfile.Where(x => x != "").ToArray();
+
+ var sources = new KeyValuePair[] { new KeyValuePair( "raylib.h","RLAPI") , new KeyValuePair("physac.h", "PHYSACDEF"),
+ new KeyValuePair( "easings.h","EASEDEF"),new KeyValuePair( "raygui.h","RAYGUIDEF")};
+ foreach (var sourcefilenameandexporttag in sources)
+ {
+ var functions = new List();
+ var types = new HashSet();
+ var enums = new HashSet();
+ var Funcs = new List();
+ var tps = new Dictionary();
+ var eps = new Dictionary();
+ var sourcefilename = sourcefilenameandexporttag.Key;
+ var FileName = new CultureInfo("en-us", false).TextInfo.ToTitleCase(sourcefilename.Replace(".h", ""));
+ var ExportTag = sourcefilenameandexporttag.Value;
+ var sourcefile = File.ReadAllLines(sourcefilename);
+
+ for (int i = 0; i < sourcefile.Length; i++)
+ {
+ var source = sourcefile[i].Split("//".ToCharArray())[0].Trim();
+ if (source.Contains(ExportTag))
+ {
+ if (!source.Contains("#define"))
+ {
+ source = source.TrimStart(ExportTag.ToCharArray()).Trim();
+ if (!source.Contains("{")) functions.Add(source);
+ }
+ }
+
+ if (source.Contains("typedef"))
+ {
+ if (source.Split(' ')[1].Trim() == "struct")
+ {
+ if (source.Contains('}'))
+ {
+ types.Add(source.Split('}', ';')[1].Trim());
+ }
+ else
+ {
+ int t = 1;
+ var src = sourcefile[i + t];
+ while (!src.Contains('}'))
+ {
+ src = sourcefile[i + t];
+ t++;
+ }
+ types.Add(src.Trim('}', ';').Trim());
+ }
+
+ }
+ }
+ }
+
+ for (int i = 0; i < functions.Count; i++)
+ {
+ var func = functions[i];
+ var returntype = func.Split('(')[0].Split(' ').Length == 3 ? func.Split('(')[0].Split(' ')[0] + " " + func.Split('(')[0].Split(' ')[1] : func.Split('(')[0].Split(' ')[0];
+ types.Add(returntype);
+ func = func.Substring(returntype.Length).Trim();
+ var funcname = func.Split('(')[0].Trim();
+ var Func = new Function(funcname, returntype);
+ if (func.Contains(','))
+ {
+ var Params = func.Split('(', ')')[1].Split(',');
+ for (int t = 0; t < Params.Length; t++)
+ {
+ var Param = Params[t];
+ Param = Param.Trim();
+ if (Param == "...")
+ {
+ Func.Params.Add(new FunctionParam(Param, new Type("...", false)));
+ }
+ else
+ {
+
+ var TypeAndVar = Param.Trim().Split(' ');
+ if (TypeAndVar.Length == 2)
+ {
+ var type = TypeAndVar[0];
+ var Var = TypeAndVar[1];
+ types.Add(type);
+ }
+ else if (TypeAndVar.Length == 3)
+ {
+ var type = TypeAndVar[0] + " " + TypeAndVar[1];
+ var Var = TypeAndVar[2];
+ types.Add(type);
+ }
+
+ Func.Params.Add(new FunctionParam(Param));
+
+ }
+ }
+ }
+ else if (func.Contains(' '))
+ {
+ var Param = func.Split('(', ')')[1];
+ var TypeAndVar = Param.Trim().Split(' ');
+ var type = TypeAndVar[0];
+ var Var = TypeAndVar[1];
+ types.Add(type);
+ Func.Params.Add(new FunctionParam(Param));
+ }
+ Funcs.Add(Func);
+ }
+
+ for (int i = 0; i < sourcefile.Length; i++)
+ {
+ var source = sourcefile[i].Split("//".ToCharArray())[0].Trim();
+ if (source.Contains("typedef"))
+ {
+ if (source.Split(' ')[1].Trim() != "struct")
+ {
+ if (source.Split(' ')[1].Trim() == "enum")
+ {
+ if (source.Contains('}'))
+ {
+ enums.Add(source.Split('}', ';')[1].Trim());
+ }
+ else
+ {
+ int t = 1;
+ var src = sourcefile[i + t];
+ while (!src.Contains('}'))
+ {
+ src = sourcefile[i + t];
+ t++;
+ }
+ enums.Add(src.Trim('}', ';').Trim());
+ }
+ }
+ else
+ {
+ TypeMap.Add(source.Split(" ".ToCharArray(), 3)[2].Trim(';').Trim(), source.Split(" ".ToCharArray(), 3)[1].Trim());
+ }
+ }
+ else
+ {
+
+ }
+ }
+ else if (source.Contains("#define") && source.Split(' ').Length > 2 && source.Split(' ')[1] != (ExportTag))
+ {
+ if (types.Contains(source.Split(" ".ToCharArray(), 3)[1].Trim(';').Trim())) TypeMap.Add(source.Split(" ".ToCharArray(), 3)[1].Trim(';').Trim(), source.Split(" ".ToCharArray(), 3)[2].Trim());
+ }
+ }
+
+
+ for (int i = 0; i < Funcs.Count; i++)
+ {
+ var Func = Funcs[i];
+ if (TypeMap.ContainsKey(Func.ReturnType.Name))
+ {
+ Func.ReturnType.Name = TypeMap[Func.ReturnType.Name];
+ }
+ for (int t = 0; t < Func.Params.Count; t++)
+ {
+ if (TypeMap.ContainsKey(Func.Params[t].Type.Name))
+ {
+
+ Func.Params[t] = new FunctionParam(Func.Params[t].Name, new Type(TypeMap[Func.Params[t].Type.Name], Func.Params[t].Type.IsPointer));
+ }
+ }
+ Funcs[i] = Func;
+ }
+ for (int i = 0; i < typesfile.Length; i++)
+ {
+ var typestr = typesfile[i];
+ if (typestr.Contains("UserDefinedType: ") && !typestr.Contains("UserDefinedType: "))
+ {
+ var type = typestr.Substring("UserDefinedType: ".Length).Trim();
+ if (types.Contains(type) && type[0] != ' ' && !tps.Any(x => x.Key == type))
+ {
+ var usertype = new UserDefinedTypeData(type);
+ int t = 1;
+ typestr = typesfile[i + t];
+ while (!(typestr.Contains("UserDefinedType: ") && typestr["UserDefinedType: ".Length - 1] == ' '))
+ {
+ if (typestr.Contains("Member"))
+ {
+ var tpsrc = typesfile[i + t];
+ var MemberNameandType = tpsrc.Substring(tpsrc.IndexOf("Type:") + "Type:".Length).Trim().Split(',');
+ var MemberName = MemberNameandType[1].Trim();
+ var MemberType = MemberNameandType[0].Trim();
+ if (MemberType.Contains(""))
+ {
+ MemberType = "bool";
+ }
+ var isptr = MemberType[MemberType.Length - 1] == '*';
+ var offset = int.Parse(tpsrc.Split(',')[0].Split(':')[1].Trim().Substring("this+0x".Length), System.Globalization.NumberStyles.HexNumber);
+ if (isptr)
+ {
+ MemberType = MemberType.Remove(MemberType.Length - 1);
+ }
+ usertype.Members.Add(new TypeMember(MemberName, new Type(MemberType, isptr), offset));
+ if (typesfile[i + t + 1].Contains(MemberType.Trim("struct".ToCharArray())) &&
+ typesfile[i + t + 1].Contains("UserDefinedType: "))
+ {
+ t++;
+ }
+ }
+ t++;
+ typestr = typesfile[i + t];
+ }
+ tps.Add(usertype.Name, usertype);
+ }
+ }
+ if (typestr.Contains("Enum : "))
+ {
+ var Enum = typestr.Substring("Enum : ".Length).Split(',')[0].Trim();
+ if (enums.Contains(Enum) && Enum != "bool")
+ {
+ var UserDefineEnum = new UserDefinedEnumData(Enum);
+ int t = 1;
+ typestr = typesfile[i + t];
+ while (typestr.Contains("Constant"))
+ {
+ var intstr = typestr.Split(",".ToCharArray(), 2)[0].Split(':')[1].Split(' ')[4].Substring("0x".Length).Trim();
+ int Int = int.Parse(intstr, System.Globalization.NumberStyles.HexNumber);
+ var name = typestr.Split(",".ToCharArray(), 4)[3].Trim();
+ UserDefineEnum.Enums.Add(new KeyValuePair(name, Int));
+ t++;
+ typestr = typesfile[i + t];
+ }
+ eps.Add(Enum, UserDefineEnum);
+ }
+ }
+ }
+ types.IntersectWith(tps.Select(x => x.Key));
+
+
+ var codetree = CompilationUnit().AddUsings(UsingDirective(ParseName("System")))
+ .AddUsings(UsingDirective(ParseName("System.IO")))
+ .AddUsings(UsingDirective(ParseName("System.Collections.Generic")))
+ .AddUsings(UsingDirective(ParseName("System.Security")))
+ .AddUsings(UsingDirective(ParseName("System.Runtime.InteropServices")))
+ ;
+ var Raylibnamespace = NamespaceDeclaration(ParseName("Raylib")).NormalizeWhitespace();
+
+ foreach (var Enumtype in eps.Values)
+ {
+ var Enum = EnumDeclaration(Enumtype.Name)
+ .WithModifiers(
+ TokenList(
+ Token(SyntaxKind.PublicKeyword)));
+ foreach (var Member in Enumtype.Enums)
+ {
+
+ var enummember = EnumMemberDeclaration(
+ Identifier(Member.Key))
+ .WithEqualsValue(
+ EqualsValueClause(
+ LiteralExpression(
+ SyntaxKind.NumericLiteralExpression,
+ Literal(Member.Value))));
+ Enum = Enum.AddMembers(enummember);
+ }
+ Raylibnamespace = Raylibnamespace.AddMembers(Enum);
+ }
+ foreach (var Type in tps.Values)
+ {
+ var Struct = StructDeclaration(Type.Name).WithAttributeLists(
+ SingletonList(
+ AttributeList(
+ SingletonSeparatedList(
+ Attribute(
+ IdentifierName("StructLayout"))
+ .WithArgumentList(
+ AttributeArgumentList(
+ SeparatedList(
+ new SyntaxNodeOrToken[]{
+ AttributeArgument(
+ MemberAccessExpression(
+ SyntaxKind.SimpleMemberAccessExpression,
+ IdentifierName("LayoutKind"),
+ IdentifierName("Sequential"))),
+ Token(SyntaxKind.CommaToken),
+ AttributeArgument(
+ MemberAccessExpression(
+ SyntaxKind.SimpleMemberAccessExpression,
+ IdentifierName("CharSet"),
+ IdentifierName("Ansi")))
+ .WithNameEquals(
+ NameEquals(
+ IdentifierName("CharSet")))})))))))
+ .WithModifiers(
+ TokenList(
+ Token(SyntaxKind.PublicKeyword)));
+ bool IsUnsafe = false;
+ var FixedStructTypes = new List();
+ foreach (var Member in Type.Members)
+ {
+ var IsStruct = false;
+ var TypeName = (Member.Type.IsPointer ? "IntPtr" : Member.Type.Name).Trim();
+ if (TypeName.Contains("struct"))
+ {
+ IsStruct = true;
+ TypeName = TypeName.Substring(TypeName.LastIndexOf("struct") + "struct".Length);
+ }
+
+ if (TypeName.Contains("enum"))
+ {
+ TypeName = TypeName.Substring(TypeName.LastIndexOf("enum") + "enum".Length);
+ }
+
+ if (TypeName.Contains("unsigned int"))
+ {
+ TypeName = TypeName.Replace("unsigned int", "uint");
+ }
+
+ if (TypeName.Contains("unsigned char"))
+ {
+ TypeName = TypeName.Replace("unsigned char", "byte");
+ }
+
+
+ var IsFixed = false;
+ var VariableDec = VariableDeclarator(Member.Name);
+ if (TypeName.Contains("["))
+ {
+ int arraycount = int.Parse(TypeName.Split('[', ']')[1].Substring("0x".Length), System.Globalization.NumberStyles.HexNumber);
+ TypeName = TypeName.Split('[', ']')[0].Trim();
+ if (IsStruct)
+ {
+ if (!FixedStructTypes.Contains($"_{TypeName}_e_FixedBuffer_{arraycount}"))
+ {
+ FixedStructTypes.Add($"_{TypeName}_e_FixedBuffer_{arraycount}");
+ var FixedBufferStruct = StructDeclaration($"_{TypeName}_e_FixedBuffer_{arraycount}")
+ .WithModifiers(
+ TokenList(
+ new[]{
+ Token(SyntaxKind.PublicKeyword),
+ Token(SyntaxKind.UnsafeKeyword)}));
+
+ for (int i = 0; i < arraycount; i++)
+ {
+ FixedBufferStruct = FixedBufferStruct.AddMembers(
+ FieldDeclaration(
+ VariableDeclaration(
+ IdentifierName(TypeName))
+ .WithVariables(
+ SingletonSeparatedList(
+ VariableDeclarator(
+ Identifier($"{Member.Name}{i}")))))
+ .WithModifiers(
+ TokenList(
+ Token(SyntaxKind.PublicKeyword))));
+ }
+
+
+ FixedBufferStruct = FixedBufferStruct.AddMembers(IndexerDeclaration(
+ RefType(
+ IdentifierName(TypeName)))
+ .WithModifiers(
+ TokenList(
+ Token(SyntaxKind.PublicKeyword)))
+ .WithParameterList(
+ BracketedParameterList(
+ SingletonSeparatedList(
+ Parameter(
+ Identifier("index"))
+ .WithType(
+ PredefinedType(
+ Token(SyntaxKind.IntKeyword))))))
+ .WithAccessorList(
+ AccessorList(
+ SingletonList(
+ AccessorDeclaration(
+ SyntaxKind.GetAccessorDeclaration)
+ .WithBody(
+ Block(
+ SingletonList(
+ FixedStatement(
+ VariableDeclaration(
+ PointerType(
+ IdentifierName(TypeName)))
+ .WithVariables(
+ SingletonSeparatedList(
+ VariableDeclarator(
+ Identifier("e"))
+ .WithInitializer(
+ EqualsValueClause(
+ PrefixUnaryExpression(
+ SyntaxKind.AddressOfExpression,
+ IdentifierName($"{Member.Name}0")))))),
+ ReturnStatement(
+ RefExpression(
+ ElementAccessExpression(
+ IdentifierName("e"))
+ .WithArgumentList(
+ BracketedArgumentList(
+ SingletonSeparatedList(
+ Argument(
+ IdentifierName("index")))))))))))))));
+ Raylibnamespace = Raylibnamespace.AddMembers(FixedBufferStruct);
+ }
+ TypeName = $"_{TypeName}_e_FixedBuffer_{arraycount}";
+ }
+ else
+ {
+ VariableDec = VariableDec.WithArgumentList(
+ BracketedArgumentList(
+ SingletonSeparatedList(
+ Argument(
+ LiteralExpression(
+ SyntaxKind.NumericLiteralExpression,
+ Literal(arraycount))))));
+ IsFixed = true;
+ IsUnsafe = true;
+ }
+ }
+ var variable = VariableDeclaration(ParseTypeName(TypeName)).AddVariables(VariableDec);
+ var field = FieldDeclaration(variable).AddModifiers(Token(SyntaxKind.PublicKeyword));
+ if (IsFixed) field = field.AddModifiers(Token(SyntaxKind.FixedKeyword));
+ Struct = Struct.AddMembers(field);
+ }
+ if (IsUnsafe) Struct = Struct.AddModifiers(Token(SyntaxKind.UnsafeKeyword));
+ Raylibnamespace = Raylibnamespace.AddMembers(Struct);
+ }
+
+ {
+ var RaylibClass = ClassDeclaration(FileName)
+ .WithAttributeLists(
+ SingletonList(
+ AttributeList(
+ SingletonSeparatedList(
+ Attribute(
+ IdentifierName("SuppressUnmanagedCodeSecurity"))))))
+ .WithModifiers(
+ TokenList(
+ new[]{
+ Token(SyntaxKind.PublicKeyword),
+ Token(SyntaxKind.StaticKeyword),
+ Token(SyntaxKind.PartialKeyword)}));
+
+ var LibraryNameField = FieldDeclaration(
+ VariableDeclaration(
+ PredefinedType(
+ Token(SyntaxKind.StringKeyword)))
+ .WithVariables(
+ SingletonSeparatedList(
+ VariableDeclarator(
+ Identifier("nativeLibName"))
+ .WithInitializer(
+ EqualsValueClause(
+ LiteralExpression(
+ SyntaxKind.StringLiteralExpression,
+ Literal("raylib")))))))
+ .WithModifiers(
+ TokenList(
+ new[]{
+ Token(SyntaxKind.PublicKeyword),
+ Token(SyntaxKind.ConstKeyword)}));
+ RaylibClass = RaylibClass.AddMembers(LibraryNameField);
+ foreach (var Func in Funcs)
+ {
+ var typename = Func.ReturnType.IsPointer ? "IntPtr" : Func.ReturnType.Name;
+ var Function = MethodDeclaration(ParseTypeName(typename),
+ Identifier(Func.Name))
+ .WithAttributeLists(
+ SingletonList(
+ AttributeList(
+ SingletonSeparatedList(
+ Attribute(
+ IdentifierName("DllImport"))
+ .WithArgumentList(
+ AttributeArgumentList(
+ SeparatedList(
+ new SyntaxNodeOrToken[]{
+ AttributeArgument(
+ IdentifierName("nativeLibName")),
+ Token(SyntaxKind.CommaToken),
+ AttributeArgument(
+ MemberAccessExpression(
+ SyntaxKind.SimpleMemberAccessExpression,
+ IdentifierName("CallingConvention"),
+ IdentifierName("Cdecl")))
+ .WithNameEquals(
+ NameEquals(
+ IdentifierName("CallingConvention")))})))))))
+ .WithModifiers(
+ TokenList(
+ new[]{
+ Token(SyntaxKind.PublicKeyword),
+ Token(SyntaxKind.StaticKeyword),
+ Token(SyntaxKind.ExternKeyword)
+ })).WithSemicolonToken(Token(SyntaxKind.SemicolonToken));
+
+ for (int i=0; i < Func.Params.Count;i++)
+ {
+ var Param = Func.Params[i];
+ var TypeName = (Param.Type.IsPointer ? "IntPtr" : Param.Type.Name).Trim();
+ if (TypeName.Contains("unsigned int"))
+ {
+ TypeName = TypeName.Replace("unsigned int", "uint");
+ }
+
+ if (TypeName.Contains("..."))
+ {
+ TypeName = "params object[]";
+ Param.Name = "args";
+ }
+
+ if (TypeName.Contains("unsigned char"))
+ {
+ TypeName = TypeName.Replace("unsigned char", "byte");
+ }
+
+ if (TypeName.Contains("struct"))
+ {
+ TypeName = TypeName.Substring(TypeName.LastIndexOf("struct") + "struct".Length);
+ }
+ Function = Function.AddParameterListParameters(
+ Parameter(
+ Identifier(Param.Name))
+ .WithType(
+ IdentifierName(TypeName)));
+ }
+
+ RaylibClass = RaylibClass.AddMembers(Function);
+ }
+ Raylibnamespace = Raylibnamespace.AddMembers(RaylibClass);
+ }
+ codetree = codetree.AddMembers(Raylibnamespace);
+ Console.WriteLine(codetree.NormalizeWhitespace().ToFullString());
+ File.WriteAllText($"{FileName}.cs", codetree.NormalizeWhitespace().ToFullString());
+
+ }
+ Console.ReadLine();
+ }
+
+ }
+}
+
diff --git a/Generator/Properties/AssemblyInfo.cs b/Generator/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..2aae937
--- /dev/null
+++ b/Generator/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Generator")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Generator")]
+[assembly: AssemblyCopyright("Copyright © 2018")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("0adeb5b1-bf57-4d45-be28-176c1d79c764")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/Generator/easings.h b/Generator/easings.h
new file mode 100644
index 0000000..9ad2731
--- /dev/null
+++ b/Generator/easings.h
@@ -0,0 +1,253 @@
+/*******************************************************************************************
+*
+* raylib easings (header only file)
+*
+* Useful easing functions for values animation
+*
+* This header uses:
+* #define EASINGS_STATIC_INLINE // Inlines all functions code, so it runs faster.
+* // This requires lots of memory on system.
+* How to use:
+* The four inputs t,b,c,d are defined as follows:
+* t = current time (in any unit measure, but same unit as duration)
+* b = starting value to interpolate
+* c = the total change in value of b that needs to occur
+* d = total time it should take to complete (duration)
+*
+* Example:
+*
+* int currentTime = 0;
+* int duration = 100;
+* float startPositionX = 0.0f;
+* float finalPositionX = 30.0f;
+* float currentPositionX = startPositionX;
+*
+* while (currentPositionX < finalPositionX)
+* {
+* currentPositionX = EaseSineIn(currentTime, startPositionX, finalPositionX - startPositionX, duration);
+* currentTime++;
+* }
+*
+* A port of Robert Penner's easing equations to C (http://robertpenner.com/easing/)
+*
+* Robert Penner License
+* ---------------------------------------------------------------------------------
+* Open source under the BSD License.
+*
+* Copyright (c) 2001 Robert Penner. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification,
+* are permitted provided that the following conditions are met:
+*
+* - Redistributions of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+* - Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+* - Neither the name of the author nor the names of contributors may be used
+* to endorse or promote products derived from this software without specific
+* prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+* OF THE POSSIBILITY OF SUCH DAMAGE.
+* ---------------------------------------------------------------------------------
+*
+* Copyright (c) 2015 Ramon Santamaria
+*
+* 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.
+*
+* Permission is granted to anyone to use this software for any purpose, including commercial
+* applications, and to alter it and redistribute it freely, subject to the following restrictions:
+*
+* 1. The origin of this software must not be misrepresented; you must not claim that you
+* wrote the original software. If you use this software in a product, an acknowledgment
+* in the product documentation would be appreciated but is not required.
+*
+* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
+* as being the original software.
+*
+* 3. This notice may not be removed or altered from any source distribution.
+*
+**********************************************************************************************/
+
+#ifndef EASINGS_H
+#define EASINGS_H
+
+#define EASINGS_STATIC_INLINE // NOTE: By default, compile functions as static inline
+
+#if defined(EASINGS_STATIC_INLINE)
+ #define EASEDEF static inline
+#else
+ #define EASEDEF extern
+#endif
+
+#include // Required for: sin(), cos(), sqrt(), pow()
+
+#ifdef __cplusplus
+extern "C" { // Prevents name mangling of functions
+#endif
+
+// Linear Easing functions
+EASEDEF float EaseLinearNone(float t, float b, float c, float d) { return (c*t/d + b); }
+EASEDEF float EaseLinearIn(float t, float b, float c, float d) { return (c*t/d + b); }
+EASEDEF float EaseLinearOut(float t, float b, float c, float d) { return (c*t/d + b); }
+EASEDEF float EaseLinearInOut(float t,float b, float c, float d) { return (c*t/d + b); }
+
+// Sine Easing functions
+EASEDEF float EaseSineIn(float t, float b, float c, float d) { return (-c*cos(t/d*(PI/2)) + c + b); }
+EASEDEF float EaseSineOut(float t, float b, float c, float d) { return (c*sin(t/d*(PI/2)) + b); }
+EASEDEF float EaseSineInOut(float t, float b, float c, float d) { return (-c/2*(cos(PI*t/d) - 1) + b); }
+
+// Circular Easing functions
+EASEDEF float EaseCircIn(float t, float b, float c, float d) { return (-c*(sqrt(1 - (t/=d)*t) - 1) + b); }
+EASEDEF float EaseCircOut(float t, float b, float c, float d) { return (c*sqrt(1 - (t=t/d-1)*t) + b); }
+EASEDEF float EaseCircInOut(float t, float b, float c, float d)
+{
+ if ((t/=d/2) < 1) return (-c/2*(sqrt(1 - t*t) - 1) + b);
+ return (c/2*(sqrt(1 - t*(t-=2)) + 1) + b);
+}
+
+// Cubic Easing functions
+EASEDEF float EaseCubicIn(float t, float b, float c, float d) { return (c*(t/=d)*t*t + b); }
+EASEDEF float EaseCubicOut(float t, float b, float c, float d) { return (c*((t=t/d-1)*t*t + 1) + b); }
+EASEDEF float EaseCubicInOut(float t, float b, float c, float d)
+{
+ if ((t/=d/2) < 1) return (c/2*t*t*t + b);
+ return (c/2*((t-=2)*t*t + 2) + b);
+}
+
+// Quadratic Easing functions
+EASEDEF float EaseQuadIn(float t, float b, float c, float d) { return (c*(t/=d)*t + b); }
+EASEDEF float EaseQuadOut(float t, float b, float c, float d) { return (-c*(t/=d)*(t-2) + b); }
+EASEDEF float EaseQuadInOut(float t, float b, float c, float d)
+{
+ if ((t/=d/2) < 1) return (((c/2)*(t*t)) + b);
+ return (-c/2*(((t-2)*(--t)) - 1) + b);
+}
+
+// Exponential Easing functions
+EASEDEF float EaseExpoIn(float t, float b, float c, float d) { return (t == 0) ? b : (c*pow(2, 10*(t/d - 1)) + b); }
+EASEDEF float EaseExpoOut(float t, float b, float c, float d) { return (t == d) ? (b + c) : (c*(-pow(2, -10*t/d) + 1) + b); }
+EASEDEF float EaseExpoInOut(float t, float b, float c, float d)
+{
+ if (t == 0) return b;
+ if (t == d) return (b + c);
+ if ((t/=d/2) < 1) return (c/2*pow(2, 10*(t - 1)) + b);
+
+ return (c/2*(-pow(2, -10*--t) + 2) + b);
+}
+
+// Back Easing functions
+EASEDEF float EaseBackIn(float t, float b, float c, float d)
+{
+ float s = 1.70158f;
+ float postFix = t/=d;
+ return (c*(postFix)*t*((s + 1)*t - s) + b);
+}
+
+EASEDEF float EaseBackOut(float t, float b, float c, float d)
+{
+ float s = 1.70158f;
+ return (c*((t=t/d-1)*t*((s + 1)*t + s) + 1) + b);
+}
+
+EASEDEF float EaseBackInOut(float t, float b, float c, float d)
+{
+ float s = 1.70158f;
+ if ((t/=d/2) < 1) return (c/2*(t*t*(((s*=(1.525f)) + 1)*t - s)) + b);
+
+ float postFix = t-=2;
+ return (c/2*((postFix)*t*(((s*=(1.525f)) + 1)*t + s) + 2) + b);
+}
+
+// Bounce Easing functions
+EASEDEF float EaseBounceOut(float t, float b, float c, float d)
+{
+ if ((t/=d) < (1/2.75f))
+ {
+ return (c*(7.5625f*t*t) + b);
+ }
+ else if (t < (2/2.75f))
+ {
+ float postFix = t-=(1.5f/2.75f);
+ return (c*(7.5625f*(postFix)*t + 0.75f) + b);
+ }
+ else if (t < (2.5/2.75))
+ {
+ float postFix = t-=(2.25f/2.75f);
+ return (c*(7.5625f*(postFix)*t + 0.9375f) + b);
+ }
+ else
+ {
+ float postFix = t-=(2.625f/2.75f);
+ return (c*(7.5625f*(postFix)*t + 0.984375f) + b);
+ }
+}
+
+EASEDEF float EaseBounceIn(float t, float b, float c, float d) { return (c - EaseBounceOut(d-t, 0, c, d) + b); }
+EASEDEF float EaseBounceInOut(float t, float b, float c, float d)
+{
+ if (t < d/2) return (EaseBounceIn(t*2, 0, c, d)*0.5f + b);
+ else return (EaseBounceOut(t*2-d, 0, c, d)*0.5f + c*0.5f + b);
+}
+
+// Elastic Easing functions
+EASEDEF float EaseElasticIn(float t, float b, float c, float d)
+{
+ if (t == 0) return b;
+ if ((t/=d) == 1) return (b + c);
+
+ float p = d*0.3f;
+ float a = c;
+ float s = p/4;
+ float postFix = a*pow(2, 10*(t-=1));
+
+ return (-(postFix*sin((t*d-s)*(2*PI)/p )) + b);
+}
+
+EASEDEF float EaseElasticOut(float t, float b, float c, float d)
+{
+ if (t == 0) return b;
+ if ((t/=d) == 1) return (b + c);
+
+ float p = d*0.3f;
+ float a = c;
+ float s = p/4;
+
+ return (a*pow(2,-10*t)*sin((t*d-s)*(2*PI)/p) + c + b);
+}
+
+EASEDEF float EaseElasticInOut(float t, float b, float c, float d)
+{
+ if (t == 0) return b;
+ if ((t/=d/2) == 2) return (b + c);
+
+ float p = d*(0.3f*1.5f);
+ float a = c;
+ float s = p/4;
+
+ if (t < 1)
+ {
+ float postFix = a*pow(2, 10*(t-=1));
+ return -0.5f*(postFix*sin((t*d-s)*(2*PI)/p)) + b;
+ }
+
+ float postFix = a*pow(2, -10*(t-=1));
+
+ return (postFix*sin((t*d-s)*(2*PI)/p)*0.5f + c + b);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // EASINGS_H
\ No newline at end of file
diff --git a/Generator/physac.h b/Generator/physac.h
new file mode 100644
index 0000000..038361a
--- /dev/null
+++ b/Generator/physac.h
@@ -0,0 +1,2056 @@
+/**********************************************************************************************
+*
+* Physac v1.0 - 2D Physics library for videogames
+*
+* DESCRIPTION:
+*
+* Physac is a small 2D physics engine written in pure C. The engine uses a fixed time-step thread loop
+* to simluate physics. A physics step contains the following phases: get collision information,
+* apply dynamics, collision solving and position correction. It uses a very simple struct for physic
+* bodies with a position vector to be used in any 3D rendering API.
+*
+* CONFIGURATION:
+*
+* #define PHYSAC_IMPLEMENTATION
+* Generates the implementation of the library into the included file.
+* If not defined, the library is in header only mode and can be included in other headers
+* or source files without problems. But only ONE file should hold the implementation.
+*
+* #define PHYSAC_STATIC (defined by default)
+* The generated implementation will stay private inside implementation file and all
+* internal symbols and functions will only be visible inside that file.
+*
+* #define PHYSAC_NO_THREADS
+* The generated implementation won't include pthread library and user must create a secondary thread to call PhysicsThread().
+* It is so important that the thread where PhysicsThread() is called must not have v-sync or any other CPU limitation.
+*
+* #define PHYSAC_STANDALONE
+* Avoid raylib.h header inclusion in this file. Data types defined on raylib are defined
+* internally in the library and input management and drawing functions must be provided by
+* the user (check library implementation for further details).
+*
+* #define PHYSAC_DEBUG
+* Traces log messages when creating and destroying physics bodies and detects errors in physics
+* calculations and reference exceptions; it is useful for debug purposes
+*
+* #define PHYSAC_MALLOC()
+* #define PHYSAC_FREE()
+* You can define your own malloc/free implementation replacing stdlib.h malloc()/free() functions.
+* Otherwise it will include stdlib.h and use the C standard library malloc()/free() function.
+*
+*
+* NOTE 1: Physac requires multi-threading, when InitPhysics() a second thread is created to manage physics calculations.
+* NOTE 2: Physac requires static C library linkage to avoid dependency on MinGW DLL (-static -lpthread)
+*
+* Use the following code to compile:
+* gcc -o $(NAME_PART).exe $(FILE_NAME) -s -static -lraylib -lpthread -lopengl32 -lgdi32 -std=c99
+*
+* VERY THANKS TO:
+* Ramon Santamaria (github: @raysan5)
+*
+*
+* LICENSE: zlib/libpng
+*
+* Copyright (c) 2016-2018 Victor Fisac (github: @victorfisac)
+*
+* 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.
+*
+* Permission is granted to anyone to use this software for any purpose, including commercial
+* applications, and to alter it and redistribute it freely, subject to the following restrictions:
+*
+* 1. The origin of this software must not be misrepresented; you must not claim that you
+* wrote the original software. If you use this software in a product, an acknowledgment
+* in the product documentation would be appreciated but is not required.
+*
+* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
+* as being the original software.
+*
+* 3. This notice may not be removed or altered from any source distribution.
+*
+**********************************************************************************************/
+
+#if !defined(PHYSAC_H)
+#define PHYSAC_H
+
+// #define PHYSAC_STATIC
+// #define PHYSAC_NO_THREADS
+// #define PHYSAC_STANDALONE
+// #define PHYSAC_DEBUG
+
+#if defined(PHYSAC_STATIC)
+ #define PHYSACDEF static // Functions just visible to module including this file
+#else
+ #if defined(__cplusplus)
+ #define PHYSACDEF extern "C" // Functions visible from other files (no name mangling of functions in C++)
+ #else
+ #define PHYSACDEF extern // Functions visible from other files
+ #endif
+#endif
+
+//----------------------------------------------------------------------------------
+// Defines and Macros
+//----------------------------------------------------------------------------------
+#define PHYSAC_MAX_BODIES 64
+#define PHYSAC_MAX_MANIFOLDS 4096
+#define PHYSAC_MAX_VERTICES 24
+#define PHYSAC_CIRCLE_VERTICES 24
+
+#define PHYSAC_COLLISION_ITERATIONS 100
+#define PHYSAC_PENETRATION_ALLOWANCE 0.05f
+#define PHYSAC_PENETRATION_CORRECTION 0.4f
+
+#define PHYSAC_PI 3.14159265358979323846
+#define PHYSAC_DEG2RAD (PHYSAC_PI/180.0f)
+
+#define PHYSAC_MALLOC(size) malloc(size)
+#define PHYSAC_FREE(ptr) free(ptr)
+
+//----------------------------------------------------------------------------------
+// Types and Structures Definition
+// NOTE: Below types are required for PHYSAC_STANDALONE usage
+//----------------------------------------------------------------------------------
+#if defined(PHYSAC_STANDALONE)
+ // Vector2 type
+ typedef struct Vector2 {
+ float x;
+ float y;
+ } Vector2;
+
+ // Boolean type
+ #if !defined(_STDBOOL_H)
+ typedef enum { false, true } bool;
+ #define _STDBOOL_H
+ #endif
+#endif
+
+typedef enum PhysicsShapeType { PHYSICS_CIRCLE, PHYSICS_POLYGON } PhysicsShapeType;
+
+// Previously defined to be used in PhysicsShape struct as circular dependencies
+typedef struct PhysicsBodyData *PhysicsBody;
+
+// Mat2 type (used for polygon shape rotation matrix)
+typedef struct Mat2 {
+ float m00;
+ float m01;
+ float m10;
+ float m11;
+} Mat2;
+
+typedef struct PolygonData {
+ unsigned int vertexCount; // Current used vertex and normals count
+ Vector2 positions[PHYSAC_MAX_VERTICES]; // Polygon vertex positions vectors
+ Vector2 normals[PHYSAC_MAX_VERTICES]; // Polygon vertex normals vectors
+} PolygonData;
+
+typedef struct PhysicsShape {
+ PhysicsShapeType type; // Physics shape type (circle or polygon)
+ PhysicsBody body; // Shape physics body reference
+ float radius; // Circle shape radius (used for circle shapes)
+ Mat2 transform; // Vertices transform matrix 2x2
+ PolygonData vertexData; // Polygon shape vertices position and normals data (just used for polygon shapes)
+} PhysicsShape;
+
+typedef struct PhysicsBodyData {
+ unsigned int id; // Reference unique identifier
+ bool enabled; // Enabled dynamics state (collisions are calculated anyway)
+ Vector2 position; // Physics body shape pivot
+ Vector2 velocity; // Current linear velocity applied to position
+ Vector2 force; // Current linear force (reset to 0 every step)
+ float angularVelocity; // Current angular velocity applied to orient
+ float torque; // Current angular force (reset to 0 every step)
+ float orient; // Rotation in radians
+ float inertia; // Moment of inertia
+ float inverseInertia; // Inverse value of inertia
+ float mass; // Physics body mass
+ float inverseMass; // Inverse value of mass
+ float staticFriction; // Friction when the body has not movement (0 to 1)
+ float dynamicFriction; // Friction when the body has movement (0 to 1)
+ float restitution; // Restitution coefficient of the body (0 to 1)
+ bool useGravity; // Apply gravity force to dynamics
+ bool isGrounded; // Physics grounded on other body state
+ bool freezeOrient; // Physics rotation constraint
+ PhysicsShape shape; // Physics body shape information (type, radius, vertices, normals)
+} PhysicsBodyData;
+
+typedef struct PhysicsManifoldData {
+ unsigned int id; // Reference unique identifier
+ PhysicsBody bodyA; // Manifold first physics body reference
+ PhysicsBody bodyB; // Manifold second physics body reference
+ float penetration; // Depth of penetration from collision
+ Vector2 normal; // Normal direction vector from 'a' to 'b'
+ Vector2 contacts[2]; // Points of contact during collision
+ unsigned int contactsCount; // Current collision number of contacts
+ float restitution; // Mixed restitution during collision
+ float dynamicFriction; // Mixed dynamic friction during collision
+ float staticFriction; // Mixed static friction during collision
+} PhysicsManifoldData, *PhysicsManifold;
+
+#if defined(__cplusplus)
+extern "C" { // Prevents name mangling of functions
+#endif
+
+//----------------------------------------------------------------------------------
+// Module Functions Declaration
+//----------------------------------------------------------------------------------
+PHYSACDEF void InitPhysics(void); // Initializes physics values, pointers and creates physics loop thread
+PHYSACDEF void RunPhysicsStep(void); // Run physics step, to be used if PHYSICS_NO_THREADS is set in your main loop
+PHYSACDEF void SetPhysicsTimeStep(double delta); // Sets physics fixed time step in milliseconds. 1.666666 by default
+PHYSACDEF bool IsPhysicsEnabled(void); // Returns true if physics thread is currently enabled
+PHYSACDEF void SetPhysicsGravity(float x, float y); // Sets physics global gravity force
+PHYSACDEF PhysicsBody CreatePhysicsBodyCircle(Vector2 pos, float radius, float density); // Creates a new circle physics body with generic parameters
+PHYSACDEF PhysicsBody CreatePhysicsBodyRectangle(Vector2 pos, float width, float height, float density); // Creates a new rectangle physics body with generic parameters
+PHYSACDEF PhysicsBody CreatePhysicsBodyPolygon(Vector2 pos, float radius, int sides, float density); // Creates a new polygon physics body with generic parameters
+PHYSACDEF void PhysicsAddForce(PhysicsBody body, Vector2 force); // Adds a force to a physics body
+PHYSACDEF void PhysicsAddTorque(PhysicsBody body, float amount); // Adds an angular force to a physics body
+PHYSACDEF void PhysicsShatter(PhysicsBody body, Vector2 position, float force); // Shatters a polygon shape physics body to little physics bodies with explosion force
+PHYSACDEF int GetPhysicsBodiesCount(void); // Returns the current amount of created physics bodies
+PHYSACDEF PhysicsBody GetPhysicsBody(int index); // Returns a physics body of the bodies pool at a specific index
+PHYSACDEF int GetPhysicsShapeType(int index); // Returns the physics body shape type (PHYSICS_CIRCLE or PHYSICS_POLYGON)
+PHYSACDEF int GetPhysicsShapeVerticesCount(int index); // Returns the amount of vertices of a physics body shape
+PHYSACDEF Vector2 GetPhysicsShapeVertex(PhysicsBody body, int vertex); // Returns transformed position of a body shape (body position + vertex transformed position)
+PHYSACDEF void SetPhysicsBodyRotation(PhysicsBody body, float radians); // Sets physics body shape transform based on radians parameter
+PHYSACDEF void DestroyPhysicsBody(PhysicsBody body); // Unitializes and destroy a physics body
+PHYSACDEF void ResetPhysics(void); // Destroys created physics bodies and manifolds and resets global values
+PHYSACDEF void ClosePhysics(void); // Unitializes physics pointers and closes physics loop thread
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif // PHYSAC_H
+
+/***********************************************************************************
+*
+* PHYSAC IMPLEMENTATION
+*
+************************************************************************************/
+
+#if defined(PHYSAC_IMPLEMENTATION)
+
+#if !defined(PHYSAC_NO_THREADS)
+ #include // Required for: pthread_t, pthread_create()
+#endif
+
+#if defined(PHYSAC_DEBUG)
+ #include // Required for: printf()
+#endif
+
+#include // Required for: malloc(), free(), srand(), rand()
+#include // Required for: cosf(), sinf(), fabs(), sqrtf()
+#include // Required for: uint64_t
+
+#if !defined(PHYSAC_STANDALONE)
+ #include "raymath.h" // Required for: Vector2Add(), Vector2Subtract()
+#endif
+
+// Time management functionality
+#include // Required for: time(), clock_gettime()
+#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__)
+ #if _POSIX_C_SOURCE < 199309L
+ #undef _POSIX_C_SOURCE
+ #define _POSIX_C_SOURCE 199309L // Required for CLOCK_MONOTONIC if compiled with c99 without gnu ext.
+ #endif
+ #include // Required for: timespec
+#elif defined(__APPLE__) // macOS also defines __MACH__
+ #include // Required for: mach_absolute_time()
+#endif
+
+//----------------------------------------------------------------------------------
+// Defines and Macros
+//----------------------------------------------------------------------------------
+#define min(a,b) (((a)<(b))?(a):(b))
+#define max(a,b) (((a)>(b))?(a):(b))
+#define PHYSAC_FLT_MAX 3.402823466e+38f
+#define PHYSAC_EPSILON 0.000001f
+#define PHYSAC_K 1.0f/3.0f
+#define PHYSAC_VECTOR_ZERO (Vector2){ 0.0f, 0.0f }
+
+//----------------------------------------------------------------------------------
+// Global Variables Definition
+//----------------------------------------------------------------------------------
+#if !defined(PHYSAC_NO_THREADS)
+static pthread_t physicsThreadId; // Physics thread id
+#endif
+static unsigned int usedMemory = 0; // Total allocated dynamic memory
+static bool physicsThreadEnabled = false; // Physics thread enabled state
+static double baseTime = 0.0; // Offset time for MONOTONIC clock
+static double startTime = 0.0; // Start time in milliseconds
+static double deltaTime = 1.0/60.0/10.0 * 1000; // Delta time used for physics steps, in milliseconds
+static double currentTime = 0.0; // Current time in milliseconds
+static uint64_t frequency = 0; // Hi-res clock frequency
+
+static double accumulator = 0.0; // Physics time step delta time accumulator
+static unsigned int stepsCount = 0; // Total physics steps processed
+static Vector2 gravityForce = { 0.0f, 9.81f }; // Physics world gravity force
+static PhysicsBody bodies[PHYSAC_MAX_BODIES]; // Physics bodies pointers array
+static unsigned int physicsBodiesCount = 0; // Physics world current bodies counter
+static PhysicsManifold contacts[PHYSAC_MAX_MANIFOLDS]; // Physics bodies pointers array
+static unsigned int physicsManifoldsCount = 0; // Physics world current manifolds counter
+
+//----------------------------------------------------------------------------------
+// Module Internal Functions Declaration
+//----------------------------------------------------------------------------------
+static int FindAvailableBodyIndex(); // Finds a valid index for a new physics body initialization
+static PolygonData CreateRandomPolygon(float radius, int sides); // Creates a random polygon shape with max vertex distance from polygon pivot
+static PolygonData CreateRectanglePolygon(Vector2 pos, Vector2 size); // Creates a rectangle polygon shape based on a min and max positions
+static void *PhysicsLoop(void *arg); // Physics loop thread function
+static void PhysicsStep(void); // Physics steps calculations (dynamics, collisions and position corrections)
+static int FindAvailableManifoldIndex(); // Finds a valid index for a new manifold initialization
+static PhysicsManifold CreatePhysicsManifold(PhysicsBody a, PhysicsBody b); // Creates a new physics manifold to solve collision
+static void DestroyPhysicsManifold(PhysicsManifold manifold); // Unitializes and destroys a physics manifold
+static void SolvePhysicsManifold(PhysicsManifold manifold); // Solves a created physics manifold between two physics bodies
+static void SolveCircleToCircle(PhysicsManifold manifold); // Solves collision between two circle shape physics bodies
+static void SolveCircleToPolygon(PhysicsManifold manifold); // Solves collision between a circle to a polygon shape physics bodies
+static void SolvePolygonToCircle(PhysicsManifold manifold); // Solves collision between a polygon to a circle shape physics bodies
+static void SolvePolygonToPolygon(PhysicsManifold manifold); // Solves collision between two polygons shape physics bodies
+static void IntegratePhysicsForces(PhysicsBody body); // Integrates physics forces into velocity
+static void InitializePhysicsManifolds(PhysicsManifold manifold); // Initializes physics manifolds to solve collisions
+static void IntegratePhysicsImpulses(PhysicsManifold manifold); // Integrates physics collisions impulses to solve collisions
+static void IntegratePhysicsVelocity(PhysicsBody body); // Integrates physics velocity into position and forces
+static void CorrectPhysicsPositions(PhysicsManifold manifold); // Corrects physics bodies positions based on manifolds collision information
+static float FindAxisLeastPenetration(int *faceIndex, PhysicsShape shapeA, PhysicsShape shapeB); // Finds polygon shapes axis least penetration
+static void FindIncidentFace(Vector2 *v0, Vector2 *v1, PhysicsShape ref, PhysicsShape inc, int index); // Finds two polygon shapes incident face
+static int Clip(Vector2 normal, float clip, Vector2 *faceA, Vector2 *faceB); // Calculates clipping based on a normal and two faces
+static bool BiasGreaterThan(float valueA, float valueB); // Check if values are between bias range
+static Vector2 TriangleBarycenter(Vector2 v1, Vector2 v2, Vector2 v3); // Returns the barycenter of a triangle given by 3 points
+
+static void InitTimer(void); // Initializes hi-resolution MONOTONIC timer
+static uint64_t GetTimeCount(void); // Get hi-res MONOTONIC time measure in mseconds
+static double GetCurrentTime(void); // Get current time measure in milliseconds
+
+static int GetRandomNumber(int min, int max); // Returns a random number between min and max (both included)
+
+// Math functions
+static Vector2 MathCross(float value, Vector2 vector); // Returns the cross product of a vector and a value
+static float MathCrossVector2(Vector2 v1, Vector2 v2); // Returns the cross product of two vectors
+static float MathLenSqr(Vector2 vector); // Returns the len square root of a vector
+static float MathDot(Vector2 v1, Vector2 v2); // Returns the dot product of two vectors
+static inline float DistSqr(Vector2 v1, Vector2 v2); // Returns the square root of distance between two vectors
+static void MathNormalize(Vector2 *vector); // Returns the normalized values of a vector
+#if defined(PHYSAC_STANDALONE)
+static Vector2 Vector2Add(Vector2 v1, Vector2 v2); // Returns the sum of two given vectors
+static Vector2 Vector2Subtract(Vector2 v1, Vector2 v2); // Returns the subtract of two given vectors
+#endif
+
+static Mat2 Mat2Radians(float radians); // Creates a matrix 2x2 from a given radians value
+static void Mat2Set(Mat2 *matrix, float radians); // Set values from radians to a created matrix 2x2
+static inline Mat2 Mat2Transpose(Mat2 matrix); // Returns the transpose of a given matrix 2x2
+static inline Vector2 Mat2MultiplyVector2(Mat2 matrix, Vector2 vector); // Multiplies a vector by a matrix 2x2
+
+//----------------------------------------------------------------------------------
+// Module Functions Definition
+//----------------------------------------------------------------------------------
+// Initializes physics values, pointers and creates physics loop thread
+PHYSACDEF void InitPhysics(void)
+{
+ #if !defined(PHYSAC_NO_THREADS)
+ // NOTE: if defined, user will need to create a thread for PhysicsThread function manually
+ // Create physics thread using POSIXS thread libraries
+ pthread_create(&physicsThreadId, NULL, &PhysicsLoop, NULL);
+ #endif
+
+ // Initialize high resolution timer
+ InitTimer();
+
+ #if defined(PHYSAC_DEBUG)
+ printf("[PHYSAC] physics module initialized successfully\n");
+ #endif
+
+ accumulator = 0.0;
+}
+
+// Returns true if physics thread is currently enabled
+PHYSACDEF bool IsPhysicsEnabled(void)
+{
+ return physicsThreadEnabled;
+}
+
+// Sets physics global gravity force
+PHYSACDEF void SetPhysicsGravity(float x, float y)
+{
+ gravityForce.x = x;
+ gravityForce.y = y;
+}
+
+// Creates a new circle physics body with generic parameters
+PHYSACDEF PhysicsBody CreatePhysicsBodyCircle(Vector2 pos, float radius, float density)
+{
+ PhysicsBody newBody = CreatePhysicsBodyPolygon(pos, radius, PHYSAC_CIRCLE_VERTICES, density);
+ return newBody;
+}
+
+// Creates a new rectangle physics body with generic parameters
+PHYSACDEF PhysicsBody CreatePhysicsBodyRectangle(Vector2 pos, float width, float height, float density)
+{
+ PhysicsBody newBody = (PhysicsBody)PHYSAC_MALLOC(sizeof(PhysicsBodyData));
+ usedMemory += sizeof(PhysicsBodyData);
+
+ int newId = FindAvailableBodyIndex();
+ if (newId != -1)
+ {
+ // Initialize new body with generic values
+ newBody->id = newId;
+ newBody->enabled = true;
+ newBody->position = pos;
+ newBody->velocity = (Vector2){ 0.0f };
+ newBody->force = (Vector2){ 0.0f };
+ newBody->angularVelocity = 0.0f;
+ newBody->torque = 0.0f;
+ newBody->orient = 0.0f;
+ newBody->shape.type = PHYSICS_POLYGON;
+ newBody->shape.body = newBody;
+ newBody->shape.radius = 0.0f;
+ newBody->shape.transform = Mat2Radians(0.0f);
+ newBody->shape.vertexData = CreateRectanglePolygon(pos, (Vector2){ width, height });
+
+ // Calculate centroid and moment of inertia
+ Vector2 center = { 0.0f, 0.0f };
+ float area = 0.0f;
+ float inertia = 0.0f;
+
+ for (int i = 0; i < newBody->shape.vertexData.vertexCount; i++)
+ {
+ // Triangle vertices, third vertex implied as (0, 0)
+ Vector2 p1 = newBody->shape.vertexData.positions[i];
+ int nextIndex = (((i + 1) < newBody->shape.vertexData.vertexCount) ? (i + 1) : 0);
+ Vector2 p2 = newBody->shape.vertexData.positions[nextIndex];
+
+ float D = MathCrossVector2(p1, p2);
+ float triangleArea = D/2;
+
+ area += triangleArea;
+
+ // Use area to weight the centroid average, not just vertex position
+ center.x += triangleArea*PHYSAC_K*(p1.x + p2.x);
+ center.y += triangleArea*PHYSAC_K*(p1.y + p2.y);
+
+ float intx2 = p1.x*p1.x + p2.x*p1.x + p2.x*p2.x;
+ float inty2 = p1.y*p1.y + p2.y*p1.y + p2.y*p2.y;
+ inertia += (0.25f*PHYSAC_K*D)*(intx2 + inty2);
+ }
+
+ center.x *= 1.0f/area;
+ center.y *= 1.0f/area;
+
+ // Translate vertices to centroid (make the centroid (0, 0) for the polygon in model space)
+ // Note: this is not really necessary
+ for (int i = 0; i < newBody->shape.vertexData.vertexCount; i++)
+ {
+ newBody->shape.vertexData.positions[i].x -= center.x;
+ newBody->shape.vertexData.positions[i].y -= center.y;
+ }
+
+ newBody->mass = density*area;
+ newBody->inverseMass = ((newBody->mass != 0.0f) ? 1.0f/newBody->mass : 0.0f);
+ newBody->inertia = density*inertia;
+ newBody->inverseInertia = ((newBody->inertia != 0.0f) ? 1.0f/newBody->inertia : 0.0f);
+ newBody->staticFriction = 0.4f;
+ newBody->dynamicFriction = 0.2f;
+ newBody->restitution = 0.0f;
+ newBody->useGravity = true;
+ newBody->isGrounded = false;
+ newBody->freezeOrient = false;
+
+ // Add new body to bodies pointers array and update bodies count
+ bodies[physicsBodiesCount] = newBody;
+ physicsBodiesCount++;
+
+ #if defined(PHYSAC_DEBUG)
+ printf("[PHYSAC] created polygon physics body id %i\n", newBody->id);
+ #endif
+ }
+ #if defined(PHYSAC_DEBUG)
+ else printf("[PHYSAC] new physics body creation failed because there is any available id to use\n");
+ #endif
+
+ return newBody;
+}
+
+// Creates a new polygon physics body with generic parameters
+PHYSACDEF PhysicsBody CreatePhysicsBodyPolygon(Vector2 pos, float radius, int sides, float density)
+{
+ PhysicsBody newBody = (PhysicsBody)PHYSAC_MALLOC(sizeof(PhysicsBodyData));
+ usedMemory += sizeof(PhysicsBodyData);
+
+ int newId = FindAvailableBodyIndex();
+ if (newId != -1)
+ {
+ // Initialize new body with generic values
+ newBody->id = newId;
+ newBody->enabled = true;
+ newBody->position = pos;
+ newBody->velocity = PHYSAC_VECTOR_ZERO;
+ newBody->force = PHYSAC_VECTOR_ZERO;
+ newBody->angularVelocity = 0.0f;
+ newBody->torque = 0.0f;
+ newBody->orient = 0.0f;
+ newBody->shape.type = PHYSICS_POLYGON;
+ newBody->shape.body = newBody;
+ newBody->shape.transform = Mat2Radians(0.0f);
+ newBody->shape.vertexData = CreateRandomPolygon(radius, sides);
+
+ // Calculate centroid and moment of inertia
+ Vector2 center = { 0.0f, 0.0f };
+ float area = 0.0f;
+ float inertia = 0.0f;
+
+ for (int i = 0; i < newBody->shape.vertexData.vertexCount; i++)
+ {
+ // Triangle vertices, third vertex implied as (0, 0)
+ Vector2 position1 = newBody->shape.vertexData.positions[i];
+ int nextIndex = (((i + 1) < newBody->shape.vertexData.vertexCount) ? (i + 1) : 0);
+ Vector2 position2 = newBody->shape.vertexData.positions[nextIndex];
+
+ float cross = MathCrossVector2(position1, position2);
+ float triangleArea = cross/2;
+
+ area += triangleArea;
+
+ // Use area to weight the centroid average, not just vertex position
+ center.x += triangleArea*PHYSAC_K*(position1.x + position2.x);
+ center.y += triangleArea*PHYSAC_K*(position1.y + position2.y);
+
+ float intx2 = position1.x*position1.x + position2.x*position1.x + position2.x*position2.x;
+ float inty2 = position1.y*position1.y + position2.y*position1.y + position2.y*position2.y;
+ inertia += (0.25f*PHYSAC_K*cross)*(intx2 + inty2);
+ }
+
+ center.x *= 1.0f/area;
+ center.y *= 1.0f/area;
+
+ // Translate vertices to centroid (make the centroid (0, 0) for the polygon in model space)
+ // Note: this is not really necessary
+ for (int i = 0; i < newBody->shape.vertexData.vertexCount; i++)
+ {
+ newBody->shape.vertexData.positions[i].x -= center.x;
+ newBody->shape.vertexData.positions[i].y -= center.y;
+ }
+
+ newBody->mass = density*area;
+ newBody->inverseMass = ((newBody->mass != 0.0f) ? 1.0f/newBody->mass : 0.0f);
+ newBody->inertia = density*inertia;
+ newBody->inverseInertia = ((newBody->inertia != 0.0f) ? 1.0f/newBody->inertia : 0.0f);
+ newBody->staticFriction = 0.4f;
+ newBody->dynamicFriction = 0.2f;
+ newBody->restitution = 0.0f;
+ newBody->useGravity = true;
+ newBody->isGrounded = false;
+ newBody->freezeOrient = false;
+
+ // Add new body to bodies pointers array and update bodies count
+ bodies[physicsBodiesCount] = newBody;
+ physicsBodiesCount++;
+
+ #if defined(PHYSAC_DEBUG)
+ printf("[PHYSAC] created polygon physics body id %i\n", newBody->id);
+ #endif
+ }
+ #if defined(PHYSAC_DEBUG)
+ else printf("[PHYSAC] new physics body creation failed because there is any available id to use\n");
+ #endif
+
+ return newBody;
+}
+
+// Adds a force to a physics body
+PHYSACDEF void PhysicsAddForce(PhysicsBody body, Vector2 force)
+{
+ if (body != NULL) body->force = Vector2Add(body->force, force);
+}
+
+// Adds an angular force to a physics body
+PHYSACDEF void PhysicsAddTorque(PhysicsBody body, float amount)
+{
+ if (body != NULL) body->torque += amount;
+}
+
+// Shatters a polygon shape physics body to little physics bodies with explosion force
+PHYSACDEF void PhysicsShatter(PhysicsBody body, Vector2 position, float force)
+{
+ if (body != NULL)
+ {
+ if (body->shape.type == PHYSICS_POLYGON)
+ {
+ PolygonData vertexData = body->shape.vertexData;
+ bool collision = false;
+
+ for (int i = 0; i < vertexData.vertexCount; i++)
+ {
+ Vector2 positionA = body->position;
+ Vector2 positionB = Mat2MultiplyVector2(body->shape.transform, Vector2Add(body->position, vertexData.positions[i]));
+ int nextIndex = (((i + 1) < vertexData.vertexCount) ? (i + 1) : 0);
+ Vector2 positionC = Mat2MultiplyVector2(body->shape.transform, Vector2Add(body->position, vertexData.positions[nextIndex]));
+
+ // Check collision between each triangle
+ float alpha = ((positionB.y - positionC.y)*(position.x - positionC.x) + (positionC.x - positionB.x)*(position.y - positionC.y))/
+ ((positionB.y - positionC.y)*(positionA.x - positionC.x) + (positionC.x - positionB.x)*(positionA.y - positionC.y));
+
+ float beta = ((positionC.y - positionA.y)*(position.x - positionC.x) + (positionA.x - positionC.x)*(position.y - positionC.y))/
+ ((positionB.y - positionC.y)*(positionA.x - positionC.x) + (positionC.x - positionB.x)*(positionA.y - positionC.y));
+
+ float gamma = 1.0f - alpha - beta;
+
+ if ((alpha > 0.0f) && (beta > 0.0f) & (gamma > 0.0f))
+ {
+ collision = true;
+ break;
+ }
+ }
+
+ if (collision)
+ {
+ int count = vertexData.vertexCount;
+ Vector2 bodyPos = body->position;
+ Vector2 *vertices = (Vector2*)malloc(sizeof(Vector2) * count);
+ Mat2 trans = body->shape.transform;
+ for (int i = 0; i < count; i++) vertices[i] = vertexData.positions[i];
+
+ // Destroy shattered physics body
+ DestroyPhysicsBody(body);
+
+ for (int i = 0; i < count; i++)
+ {
+ int nextIndex = (((i + 1) < count) ? (i + 1) : 0);
+ Vector2 center = TriangleBarycenter(vertices[i], vertices[nextIndex], PHYSAC_VECTOR_ZERO);
+ center = Vector2Add(bodyPos, center);
+ Vector2 offset = Vector2Subtract(center, bodyPos);
+
+ PhysicsBody newBody = CreatePhysicsBodyPolygon(center, 10, 3, 10); // Create polygon physics body with relevant values
+
+ PolygonData newData = { 0 };
+ newData.vertexCount = 3;
+
+ newData.positions[0] = Vector2Subtract(vertices[i], offset);
+ newData.positions[1] = Vector2Subtract(vertices[nextIndex], offset);
+ newData.positions[2] = Vector2Subtract(position, center);
+
+ // Separate vertices to avoid unnecessary physics collisions
+ newData.positions[0].x *= 0.95f;
+ newData.positions[0].y *= 0.95f;
+ newData.positions[1].x *= 0.95f;
+ newData.positions[1].y *= 0.95f;
+ newData.positions[2].x *= 0.95f;
+ newData.positions[2].y *= 0.95f;
+
+ // Calculate polygon faces normals
+ for (int j = 0; j < newData.vertexCount; j++)
+ {
+ int nextVertex = (((j + 1) < newData.vertexCount) ? (j + 1) : 0);
+ Vector2 face = Vector2Subtract(newData.positions[nextVertex], newData.positions[j]);
+
+ newData.normals[j] = (Vector2){ face.y, -face.x };
+ MathNormalize(&newData.normals[j]);
+ }
+
+ // Apply computed vertex data to new physics body shape
+ newBody->shape.vertexData = newData;
+ newBody->shape.transform = trans;
+
+ // Calculate centroid and moment of inertia
+ center = PHYSAC_VECTOR_ZERO;
+ float area = 0.0f;
+ float inertia = 0.0f;
+
+ for (int j = 0; j < newBody->shape.vertexData.vertexCount; j++)
+ {
+ // Triangle vertices, third vertex implied as (0, 0)
+ Vector2 p1 = newBody->shape.vertexData.positions[j];
+ int nextVertex = (((j + 1) < newBody->shape.vertexData.vertexCount) ? (j + 1) : 0);
+ Vector2 p2 = newBody->shape.vertexData.positions[nextVertex];
+
+ float D = MathCrossVector2(p1, p2);
+ float triangleArea = D/2;
+
+ area += triangleArea;
+
+ // Use area to weight the centroid average, not just vertex position
+ center.x += triangleArea*PHYSAC_K*(p1.x + p2.x);
+ center.y += triangleArea*PHYSAC_K*(p1.y + p2.y);
+
+ float intx2 = p1.x*p1.x + p2.x*p1.x + p2.x*p2.x;
+ float inty2 = p1.y*p1.y + p2.y*p1.y + p2.y*p2.y;
+ inertia += (0.25f*PHYSAC_K*D)*(intx2 + inty2);
+ }
+
+ center.x *= 1.0f/area;
+ center.y *= 1.0f/area;
+
+ newBody->mass = area;
+ newBody->inverseMass = ((newBody->mass != 0.0f) ? 1.0f/newBody->mass : 0.0f);
+ newBody->inertia = inertia;
+ newBody->inverseInertia = ((newBody->inertia != 0.0f) ? 1.0f/newBody->inertia : 0.0f);
+
+ // Calculate explosion force direction
+ Vector2 pointA = newBody->position;
+ Vector2 pointB = Vector2Subtract(newData.positions[1], newData.positions[0]);
+ pointB.x /= 2.0f;
+ pointB.y /= 2.0f;
+ Vector2 forceDirection = Vector2Subtract(Vector2Add(pointA, Vector2Add(newData.positions[0], pointB)), newBody->position);
+ MathNormalize(&forceDirection);
+ forceDirection.x *= force;
+ forceDirection.y *= force;
+
+ // Apply force to new physics body
+ PhysicsAddForce(newBody, forceDirection);
+ }
+
+ free(vertices);
+ }
+ }
+ }
+ #if defined(PHYSAC_DEBUG)
+ else printf("[PHYSAC] error when trying to shatter a null reference physics body");
+ #endif
+}
+
+// Returns the current amount of created physics bodies
+PHYSACDEF int GetPhysicsBodiesCount(void)
+{
+ return physicsBodiesCount;
+}
+
+// Returns a physics body of the bodies pool at a specific index
+PHYSACDEF PhysicsBody GetPhysicsBody(int index)
+{
+ PhysicsBody body = NULL;
+
+ if (index < physicsBodiesCount)
+ {
+ body = bodies[index];
+
+ if (body == NULL)
+ {
+ #if defined(PHYSAC_DEBUG)
+ printf("[PHYSAC] error when trying to get a null reference physics body");
+ #endif
+ }
+ }
+ #if defined(PHYSAC_DEBUG)
+ else printf("[PHYSAC] physics body index is out of bounds");
+ #endif
+
+ return body;
+}
+
+// Returns the physics body shape type (PHYSICS_CIRCLE or PHYSICS_POLYGON)
+PHYSACDEF int GetPhysicsShapeType(int index)
+{
+ int result = -1;
+
+ if (index < physicsBodiesCount)
+ {
+ PhysicsBody body = bodies[index];
+
+ if (body != NULL) result = body->shape.type;
+ #if defined(PHYSAC_DEBUG)
+ else printf("[PHYSAC] error when trying to get a null reference physics body");
+ #endif
+ }
+ #if defined(PHYSAC_DEBUG)
+ else printf("[PHYSAC] physics body index is out of bounds");
+ #endif
+
+ return result;
+}
+
+// Returns the amount of vertices of a physics body shape
+PHYSACDEF int GetPhysicsShapeVerticesCount(int index)
+{
+ int result = 0;
+
+ if (index < physicsBodiesCount)
+ {
+ PhysicsBody body = bodies[index];
+
+ if (body != NULL)
+ {
+ switch (body->shape.type)
+ {
+ case PHYSICS_CIRCLE: result = PHYSAC_CIRCLE_VERTICES; break;
+ case PHYSICS_POLYGON: result = body->shape.vertexData.vertexCount; break;
+ default: break;
+ }
+ }
+ #if defined(PHYSAC_DEBUG)
+ else printf("[PHYSAC] error when trying to get a null reference physics body");
+ #endif
+ }
+ #if defined(PHYSAC_DEBUG)
+ else printf("[PHYSAC] physics body index is out of bounds");
+ #endif
+
+ return result;
+}
+
+// Returns transformed position of a body shape (body position + vertex transformed position)
+PHYSACDEF Vector2 GetPhysicsShapeVertex(PhysicsBody body, int vertex)
+{
+ Vector2 position = { 0.0f, 0.0f };
+
+ if (body != NULL)
+ {
+ switch (body->shape.type)
+ {
+ case PHYSICS_CIRCLE:
+ {
+ position.x = body->position.x + cosf(360.0f/PHYSAC_CIRCLE_VERTICES*vertex*PHYSAC_DEG2RAD)*body->shape.radius;
+ position.y = body->position.y + sinf(360.0f/PHYSAC_CIRCLE_VERTICES*vertex*PHYSAC_DEG2RAD)*body->shape.radius;
+ } break;
+ case PHYSICS_POLYGON:
+ {
+ PolygonData vertexData = body->shape.vertexData;
+ position = Vector2Add(body->position, Mat2MultiplyVector2(body->shape.transform, vertexData.positions[vertex]));
+ } break;
+ default: break;
+ }
+ }
+ #if defined(PHYSAC_DEBUG)
+ else printf("[PHYSAC] error when trying to get a null reference physics body");
+ #endif
+
+ return position;
+}
+
+// Sets physics body shape transform based on radians parameter
+PHYSACDEF void SetPhysicsBodyRotation(PhysicsBody body, float radians)
+{
+ if (body != NULL)
+ {
+ body->orient = radians;
+
+ if (body->shape.type == PHYSICS_POLYGON) body->shape.transform = Mat2Radians(radians);
+ }
+}
+
+// Unitializes and destroys a physics body
+PHYSACDEF void DestroyPhysicsBody(PhysicsBody body)
+{
+ if (body != NULL)
+ {
+ int id = body->id;
+ int index = -1;
+
+ for (int i = 0; i < physicsBodiesCount; i++)
+ {
+ if (bodies[i]->id == id)
+ {
+ index = i;
+ break;
+ }
+ }
+
+ #if defined(PHYSAC_DEBUG)
+ if (index == -1) printf("[PHYSAC] cannot find body id %i in pointers array\n", id);
+ #endif
+
+ // Free body allocated memory
+ PHYSAC_FREE(body);
+ usedMemory -= sizeof(PhysicsBodyData);
+ bodies[index] = NULL;
+
+ // Reorder physics bodies pointers array and its catched index
+ for (int i = index; i < physicsBodiesCount; i++)
+ {
+ if ((i + 1) < physicsBodiesCount) bodies[i] = bodies[i + 1];
+ }
+
+ // Update physics bodies count
+ physicsBodiesCount--;
+
+ #if defined(PHYSAC_DEBUG)
+ printf("[PHYSAC] destroyed physics body id %i\n", id);
+ #endif
+ }
+ #if defined(PHYSAC_DEBUG)
+ else printf("[PHYSAC] error trying to destroy a null referenced body\n");
+ #endif
+}
+
+// Destroys created physics bodies and manifolds and resets global values
+PHYSACDEF void ResetPhysics(void)
+{
+ // Unitialize physics bodies dynamic memory allocations
+ for (int i = physicsBodiesCount - 1; i >= 0; i--)
+ {
+ PhysicsBody body = bodies[i];
+
+ if (body != NULL)
+ {
+ PHYSAC_FREE(body);
+ bodies[i] = NULL;
+ usedMemory -= sizeof(PhysicsBodyData);
+ }
+ }
+
+ physicsBodiesCount = 0;
+
+ // Unitialize physics manifolds dynamic memory allocations
+ for (int i = physicsManifoldsCount - 1; i >= 0; i--)
+ {
+ PhysicsManifold manifold = contacts[i];
+
+ if (manifold != NULL)
+ {
+ PHYSAC_FREE(manifold);
+ contacts[i] = NULL;
+ usedMemory -= sizeof(PhysicsManifoldData);
+ }
+ }
+
+ physicsManifoldsCount = 0;
+
+ #if defined(PHYSAC_DEBUG)
+ printf("[PHYSAC] physics module reset successfully\n");
+ #endif
+}
+
+// Unitializes physics pointers and exits physics loop thread
+PHYSACDEF void ClosePhysics(void)
+{
+ // Exit physics loop thread
+ physicsThreadEnabled = false;
+
+ #if !defined(PHYSAC_NO_THREADS)
+ pthread_join(physicsThreadId, NULL);
+ #endif
+
+ // Unitialize physics manifolds dynamic memory allocations
+ for (int i = physicsManifoldsCount - 1; i >= 0; i--) DestroyPhysicsManifold(contacts[i]);
+
+ // Unitialize physics bodies dynamic memory allocations
+ for (int i = physicsBodiesCount - 1; i >= 0; i--) DestroyPhysicsBody(bodies[i]);
+
+ #if defined(PHYSAC_DEBUG)
+ if (physicsBodiesCount > 0 || usedMemory != 0) printf("[PHYSAC] physics module closed with %i still allocated bodies [MEMORY: %i bytes]\n", physicsBodiesCount, usedMemory);
+ else if (physicsManifoldsCount > 0 || usedMemory != 0) printf("[PHYSAC] physics module closed with %i still allocated manifolds [MEMORY: %i bytes]\n", physicsManifoldsCount, usedMemory);
+ else printf("[PHYSAC] physics module closed successfully\n");
+ #endif
+}
+
+//----------------------------------------------------------------------------------
+// Module Internal Functions Definition
+//----------------------------------------------------------------------------------
+// Finds a valid index for a new physics body initialization
+static int FindAvailableBodyIndex()
+{
+ int index = -1;
+ for (int i = 0; i < PHYSAC_MAX_BODIES; i++)
+ {
+ int currentId = i;
+
+ // Check if current id already exist in other physics body
+ for (int k = 0; k < physicsBodiesCount; k++)
+ {
+ if (bodies[k]->id == currentId)
+ {
+ currentId++;
+ break;
+ }
+ }
+
+ // If it is not used, use it as new physics body id
+ if (currentId == i)
+ {
+ index = i;
+ break;
+ }
+ }
+
+ return index;
+}
+
+// Creates a random polygon shape with max vertex distance from polygon pivot
+static PolygonData CreateRandomPolygon(float radius, int sides)
+{
+ PolygonData data = { 0 };
+ data.vertexCount = sides;
+
+ // Calculate polygon vertices positions
+ for (int i = 0; i < data.vertexCount; i++)
+ {
+ data.positions[i].x = cosf(360.0f/sides*i*PHYSAC_DEG2RAD)*radius;
+ data.positions[i].y = sinf(360.0f/sides*i*PHYSAC_DEG2RAD)*radius;
+ }
+
+ // Calculate polygon faces normals
+ for (int i = 0; i < data.vertexCount; i++)
+ {
+ int nextIndex = (((i + 1) < sides) ? (i + 1) : 0);
+ Vector2 face = Vector2Subtract(data.positions[nextIndex], data.positions[i]);
+
+ data.normals[i] = (Vector2){ face.y, -face.x };
+ MathNormalize(&data.normals[i]);
+ }
+
+ return data;
+}
+
+// Creates a rectangle polygon shape based on a min and max positions
+static PolygonData CreateRectanglePolygon(Vector2 pos, Vector2 size)
+{
+ PolygonData data = { 0 };
+ data.vertexCount = 4;
+
+ // Calculate polygon vertices positions
+ data.positions[0] = (Vector2){ pos.x + size.x/2, pos.y - size.y/2 };
+ data.positions[1] = (Vector2){ pos.x + size.x/2, pos.y + size.y/2 };
+ data.positions[2] = (Vector2){ pos.x - size.x/2, pos.y + size.y/2 };
+ data.positions[3] = (Vector2){ pos.x - size.x/2, pos.y - size.y/2 };
+
+ // Calculate polygon faces normals
+ for (int i = 0; i < data.vertexCount; i++)
+ {
+ int nextIndex = (((i + 1) < data.vertexCount) ? (i + 1) : 0);
+ Vector2 face = Vector2Subtract(data.positions[nextIndex], data.positions[i]);
+
+ data.normals[i] = (Vector2){ face.y, -face.x };
+ MathNormalize(&data.normals[i]);
+ }
+
+ return data;
+}
+
+// Physics loop thread function
+static void *PhysicsLoop(void *arg)
+{
+ #if defined(PHYSAC_DEBUG)
+ printf("[PHYSAC] physics thread created successfully\n");
+ #endif
+
+ // Initialize physics loop thread values
+ physicsThreadEnabled = true;
+
+ // Physics update loop
+ while (physicsThreadEnabled)
+ {
+ RunPhysicsStep();
+ }
+
+ return NULL;
+}
+
+// Physics steps calculations (dynamics, collisions and position corrections)
+static void PhysicsStep(void)
+{
+ // Update current steps count
+ stepsCount++;
+
+ // Clear previous generated collisions information
+ for (int i = physicsManifoldsCount - 1; i >= 0; i--)
+ {
+ PhysicsManifold manifold = contacts[i];
+ if (manifold != NULL) DestroyPhysicsManifold(manifold);
+ }
+
+ // Reset physics bodies grounded state
+ for (int i = 0; i < physicsBodiesCount; i++)
+ {
+ PhysicsBody body = bodies[i];
+ body->isGrounded = false;
+ }
+
+ // Generate new collision information
+ for (int i = 0; i < physicsBodiesCount; i++)
+ {
+ PhysicsBody bodyA = bodies[i];
+
+ if (bodyA != NULL)
+ {
+ for (int j = i + 1; j < physicsBodiesCount; j++)
+ {
+ PhysicsBody bodyB = bodies[j];
+
+ if (bodyB != NULL)
+ {
+ if ((bodyA->inverseMass == 0) && (bodyB->inverseMass == 0)) continue;
+
+ PhysicsManifold manifold = CreatePhysicsManifold(bodyA, bodyB);
+ SolvePhysicsManifold(manifold);
+
+ if (manifold->contactsCount > 0)
+ {
+ // Create a new manifold with same information as previously solved manifold and add it to the manifolds pool last slot
+ PhysicsManifold newManifold = CreatePhysicsManifold(bodyA, bodyB);
+ newManifold->penetration = manifold->penetration;
+ newManifold->normal = manifold->normal;
+ newManifold->contacts[0] = manifold->contacts[0];
+ newManifold->contacts[1] = manifold->contacts[1];
+ newManifold->contactsCount = manifold->contactsCount;
+ newManifold->restitution = manifold->restitution;
+ newManifold->dynamicFriction = manifold->dynamicFriction;
+ newManifold->staticFriction = manifold->staticFriction;
+ }
+ }
+ }
+ }
+ }
+
+ // Integrate forces to physics bodies
+ for (int i = 0; i < physicsBodiesCount; i++)
+ {
+ PhysicsBody body = bodies[i];
+ if (body != NULL) IntegratePhysicsForces(body);
+ }
+
+ // Initialize physics manifolds to solve collisions
+ for (int i = 0; i < physicsManifoldsCount; i++)
+ {
+ PhysicsManifold manifold = contacts[i];
+ if (manifold != NULL) InitializePhysicsManifolds(manifold);
+ }
+
+ // Integrate physics collisions impulses to solve collisions
+ for (int i = 0; i < PHYSAC_COLLISION_ITERATIONS; i++)
+ {
+ for (int j = 0; j < physicsManifoldsCount; j++)
+ {
+ PhysicsManifold manifold = contacts[i];
+ if (manifold != NULL) IntegratePhysicsImpulses(manifold);
+ }
+ }
+
+ // Integrate velocity to physics bodies
+ for (int i = 0; i < physicsBodiesCount; i++)
+ {
+ PhysicsBody body = bodies[i];
+ if (body != NULL) IntegratePhysicsVelocity(body);
+ }
+
+ // Correct physics bodies positions based on manifolds collision information
+ for (int i = 0; i < physicsManifoldsCount; i++)
+ {
+ PhysicsManifold manifold = contacts[i];
+ if (manifold != NULL) CorrectPhysicsPositions(manifold);
+ }
+
+ // Clear physics bodies forces
+ for (int i = 0; i < physicsBodiesCount; i++)
+ {
+ PhysicsBody body = bodies[i];
+ if (body != NULL)
+ {
+ body->force = PHYSAC_VECTOR_ZERO;
+ body->torque = 0.0f;
+ }
+ }
+}
+
+// Wrapper to ensure PhysicsStep is run with at a fixed time step
+PHYSACDEF void RunPhysicsStep(void)
+{
+ // Calculate current time
+ currentTime = GetCurrentTime();
+
+ // Calculate current delta time
+ const double delta = currentTime - startTime;
+
+ // Store the time elapsed since the last frame began
+ accumulator += delta;
+
+ // Fixed time stepping loop
+ while (accumulator >= deltaTime)
+ {
+#ifdef PHYSAC_DEBUG
+ //printf("currentTime %f, startTime %f, accumulator-pre %f, accumulator-post %f, delta %f, deltaTime %f\n",
+ // currentTime, startTime, accumulator, accumulator-deltaTime, delta, deltaTime);
+#endif
+ PhysicsStep();
+ accumulator -= deltaTime;
+ }
+
+ // Record the starting of this frame
+ startTime = currentTime;
+}
+
+PHYSACDEF void SetPhysicsTimeStep(double delta)
+{
+ deltaTime = delta;
+}
+
+// Finds a valid index for a new manifold initialization
+static int FindAvailableManifoldIndex()
+{
+ int index = -1;
+ for (int i = 0; i < PHYSAC_MAX_MANIFOLDS; i++)
+ {
+ int currentId = i;
+
+ // Check if current id already exist in other physics body
+ for (int k = 0; k < physicsManifoldsCount; k++)
+ {
+ if (contacts[k]->id == currentId)
+ {
+ currentId++;
+ break;
+ }
+ }
+
+ // If it is not used, use it as new physics body id
+ if (currentId == i)
+ {
+ index = i;
+ break;
+ }
+ }
+
+ return index;
+}
+
+// Creates a new physics manifold to solve collision
+static PhysicsManifold CreatePhysicsManifold(PhysicsBody a, PhysicsBody b)
+{
+ PhysicsManifold newManifold = (PhysicsManifold)PHYSAC_MALLOC(sizeof(PhysicsManifoldData));
+ usedMemory += sizeof(PhysicsManifoldData);
+
+ int newId = FindAvailableManifoldIndex();
+ if (newId != -1)
+ {
+ // Initialize new manifold with generic values
+ newManifold->id = newId;
+ newManifold->bodyA = a;
+ newManifold->bodyB = b;
+ newManifold->penetration = 0;
+ newManifold->normal = PHYSAC_VECTOR_ZERO;
+ newManifold->contacts[0] = PHYSAC_VECTOR_ZERO;
+ newManifold->contacts[1] = PHYSAC_VECTOR_ZERO;
+ newManifold->contactsCount = 0;
+ newManifold->restitution = 0.0f;
+ newManifold->dynamicFriction = 0.0f;
+ newManifold->staticFriction = 0.0f;
+
+ // Add new body to bodies pointers array and update bodies count
+ contacts[physicsManifoldsCount] = newManifold;
+ physicsManifoldsCount++;
+ }
+ #if defined(PHYSAC_DEBUG)
+ else printf("[PHYSAC] new physics manifold creation failed because there is any available id to use\n");
+ #endif
+
+ return newManifold;
+}
+
+// Unitializes and destroys a physics manifold
+static void DestroyPhysicsManifold(PhysicsManifold manifold)
+{
+ if (manifold != NULL)
+ {
+ int id = manifold->id;
+ int index = -1;
+
+ for (int i = 0; i < physicsManifoldsCount; i++)
+ {
+ if (contacts[i]->id == id)
+ {
+ index = i;
+ break;
+ }
+ }
+
+ #if defined(PHYSAC_DEBUG)
+ if (index == -1) printf("[PHYSAC] cannot find manifold id %i in pointers array\n", id);
+ #endif
+
+ // Free manifold allocated memory
+ PHYSAC_FREE(manifold);
+ usedMemory -= sizeof(PhysicsManifoldData);
+ contacts[index] = NULL;
+
+ // Reorder physics manifolds pointers array and its catched index
+ for (int i = index; i < physicsManifoldsCount; i++)
+ {
+ if ((i + 1) < physicsManifoldsCount) contacts[i] = contacts[i + 1];
+ }
+
+ // Update physics manifolds count
+ physicsManifoldsCount--;
+ }
+ #if defined(PHYSAC_DEBUG)
+ else printf("[PHYSAC] error trying to destroy a null referenced manifold\n");
+ #endif
+}
+
+// Solves a created physics manifold between two physics bodies
+static void SolvePhysicsManifold(PhysicsManifold manifold)
+{
+ switch (manifold->bodyA->shape.type)
+ {
+ case PHYSICS_CIRCLE:
+ {
+ switch (manifold->bodyB->shape.type)
+ {
+ case PHYSICS_CIRCLE: SolveCircleToCircle(manifold); break;
+ case PHYSICS_POLYGON: SolveCircleToPolygon(manifold); break;
+ default: break;
+ }
+ } break;
+ case PHYSICS_POLYGON:
+ {
+ switch (manifold->bodyB->shape.type)
+ {
+ case PHYSICS_CIRCLE: SolvePolygonToCircle(manifold); break;
+ case PHYSICS_POLYGON: SolvePolygonToPolygon(manifold); break;
+ default: break;
+ }
+ } break;
+ default: break;
+ }
+
+ // Update physics body grounded state if normal direction is down and grounded state is not set yet in previous manifolds
+ if (!manifold->bodyB->isGrounded) manifold->bodyB->isGrounded = (manifold->normal.y < 0);
+}
+
+// Solves collision between two circle shape physics bodies
+static void SolveCircleToCircle(PhysicsManifold manifold)
+{
+ PhysicsBody bodyA = manifold->bodyA;
+ PhysicsBody bodyB = manifold->bodyB;
+
+ if ((bodyA == NULL) || (bodyB == NULL)) return;
+
+ // Calculate translational vector, which is normal
+ Vector2 normal = Vector2Subtract(bodyB->position, bodyA->position);
+
+ float distSqr = MathLenSqr(normal);
+ float radius = bodyA->shape.radius + bodyB->shape.radius;
+
+ // Check if circles are not in contact
+ if (distSqr >= radius*radius)
+ {
+ manifold->contactsCount = 0;
+ return;
+ }
+
+ float distance = sqrtf(distSqr);
+ manifold->contactsCount = 1;
+
+ if (distance == 0.0f)
+ {
+ manifold->penetration = bodyA->shape.radius;
+ manifold->normal = (Vector2){ 1.0f, 0.0f };
+ manifold->contacts[0] = bodyA->position;
+ }
+ else
+ {
+ manifold->penetration = radius - distance;
+ manifold->normal = (Vector2){ normal.x/distance, normal.y/distance }; // Faster than using MathNormalize() due to sqrt is already performed
+ manifold->contacts[0] = (Vector2){ manifold->normal.x*bodyA->shape.radius + bodyA->position.x, manifold->normal.y*bodyA->shape.radius + bodyA->position.y };
+ }
+
+ // Update physics body grounded state if normal direction is down
+ if (!bodyA->isGrounded) bodyA->isGrounded = (manifold->normal.y < 0);
+}
+
+// Solves collision between a circle to a polygon shape physics bodies
+static void SolveCircleToPolygon(PhysicsManifold manifold)
+{
+ PhysicsBody bodyA = manifold->bodyA;
+ PhysicsBody bodyB = manifold->bodyB;
+
+ if ((bodyA == NULL) || (bodyB == NULL)) return;
+
+ manifold->contactsCount = 0;
+
+ // Transform circle center to polygon transform space
+ Vector2 center = bodyA->position;
+ center = Mat2MultiplyVector2(Mat2Transpose(bodyB->shape.transform), Vector2Subtract(center, bodyB->position));
+
+ // Find edge with minimum penetration
+ // It is the same concept as using support points in SolvePolygonToPolygon
+ float separation = -PHYSAC_FLT_MAX;
+ int faceNormal = 0;
+ PolygonData vertexData = bodyB->shape.vertexData;
+
+ for (int i = 0; i < vertexData.vertexCount; i++)
+ {
+ float currentSeparation = MathDot(vertexData.normals[i], Vector2Subtract(center, vertexData.positions[i]));
+
+ if (currentSeparation > bodyA->shape.radius) return;
+
+ if (currentSeparation > separation)
+ {
+ separation = currentSeparation;
+ faceNormal = i;
+ }
+ }
+
+ // Grab face's vertices
+ Vector2 v1 = vertexData.positions[faceNormal];
+ int nextIndex = (((faceNormal + 1) < vertexData.vertexCount) ? (faceNormal + 1) : 0);
+ Vector2 v2 = vertexData.positions[nextIndex];
+
+ // Check to see if center is within polygon
+ if (separation < PHYSAC_EPSILON)
+ {
+ manifold->contactsCount = 1;
+ Vector2 normal = Mat2MultiplyVector2(bodyB->shape.transform, vertexData.normals[faceNormal]);
+ manifold->normal = (Vector2){ -normal.x, -normal.y };
+ manifold->contacts[0] = (Vector2){ manifold->normal.x*bodyA->shape.radius + bodyA->position.x, manifold->normal.y*bodyA->shape.radius + bodyA->position.y };
+ manifold->penetration = bodyA->shape.radius;
+ return;
+ }
+
+ // Determine which voronoi region of the edge center of circle lies within
+ float dot1 = MathDot(Vector2Subtract(center, v1), Vector2Subtract(v2, v1));
+ float dot2 = MathDot(Vector2Subtract(center, v2), Vector2Subtract(v1, v2));
+ manifold->penetration = bodyA->shape.radius - separation;
+
+ if (dot1 <= 0.0f) // Closest to v1
+ {
+ if (DistSqr(center, v1) > bodyA->shape.radius*bodyA->shape.radius) return;
+
+ manifold->contactsCount = 1;
+ Vector2 normal = Vector2Subtract(v1, center);
+ normal = Mat2MultiplyVector2(bodyB->shape.transform, normal);
+ MathNormalize(&normal);
+ manifold->normal = normal;
+ v1 = Mat2MultiplyVector2(bodyB->shape.transform, v1);
+ v1 = Vector2Add(v1, bodyB->position);
+ manifold->contacts[0] = v1;
+ }
+ else if (dot2 <= 0.0f) // Closest to v2
+ {
+ if (DistSqr(center, v2) > bodyA->shape.radius*bodyA->shape.radius) return;
+
+ manifold->contactsCount = 1;
+ Vector2 normal = Vector2Subtract(v2, center);
+ v2 = Mat2MultiplyVector2(bodyB->shape.transform, v2);
+ v2 = Vector2Add(v2, bodyB->position);
+ manifold->contacts[0] = v2;
+ normal = Mat2MultiplyVector2(bodyB->shape.transform, normal);
+ MathNormalize(&normal);
+ manifold->normal = normal;
+ }
+ else // Closest to face
+ {
+ Vector2 normal = vertexData.normals[faceNormal];
+
+ if (MathDot(Vector2Subtract(center, v1), normal) > bodyA->shape.radius) return;
+
+ normal = Mat2MultiplyVector2(bodyB->shape.transform, normal);
+ manifold->normal = (Vector2){ -normal.x, -normal.y };
+ manifold->contacts[0] = (Vector2){ manifold->normal.x*bodyA->shape.radius + bodyA->position.x, manifold->normal.y*bodyA->shape.radius + bodyA->position.y };
+ manifold->contactsCount = 1;
+ }
+}
+
+// Solves collision between a polygon to a circle shape physics bodies
+static void SolvePolygonToCircle(PhysicsManifold manifold)
+{
+ PhysicsBody bodyA = manifold->bodyA;
+ PhysicsBody bodyB = manifold->bodyB;
+
+ if ((bodyA == NULL) || (bodyB == NULL)) return;
+
+ manifold->bodyA = bodyB;
+ manifold->bodyB = bodyA;
+ SolveCircleToPolygon(manifold);
+
+ manifold->normal.x *= -1.0f;
+ manifold->normal.y *= -1.0f;
+}
+
+// Solves collision between two polygons shape physics bodies
+static void SolvePolygonToPolygon(PhysicsManifold manifold)
+{
+ if ((manifold->bodyA == NULL) || (manifold->bodyB == NULL)) return;
+
+ PhysicsShape bodyA = manifold->bodyA->shape;
+ PhysicsShape bodyB = manifold->bodyB->shape;
+ manifold->contactsCount = 0;
+
+ // Check for separating axis with A shape's face planes
+ int faceA = 0;
+ float penetrationA = FindAxisLeastPenetration(&faceA, bodyA, bodyB);
+ if (penetrationA >= 0.0f) return;
+
+ // Check for separating axis with B shape's face planes
+ int faceB = 0;
+ float penetrationB = FindAxisLeastPenetration(&faceB, bodyB, bodyA);
+ if (penetrationB >= 0.0f) return;
+
+ int referenceIndex = 0;
+ bool flip = false; // Always point from A shape to B shape
+
+ PhysicsShape refPoly; // Reference
+ PhysicsShape incPoly; // Incident
+
+ // Determine which shape contains reference face
+ if (BiasGreaterThan(penetrationA, penetrationB))
+ {
+ refPoly = bodyA;
+ incPoly = bodyB;
+ referenceIndex = faceA;
+ }
+ else
+ {
+ refPoly = bodyB;
+ incPoly = bodyA;
+ referenceIndex = faceB;
+ flip = true;
+ }
+
+ // World space incident face
+ Vector2 incidentFace[2];
+ FindIncidentFace(&incidentFace[0], &incidentFace[1], refPoly, incPoly, referenceIndex);
+
+ // Setup reference face vertices
+ PolygonData refData = refPoly.vertexData;
+ Vector2 v1 = refData.positions[referenceIndex];
+ referenceIndex = (((referenceIndex + 1) < refData.vertexCount) ? (referenceIndex + 1) : 0);
+ Vector2 v2 = refData.positions[referenceIndex];
+
+ // Transform vertices to world space
+ v1 = Mat2MultiplyVector2(refPoly.transform, v1);
+ v1 = Vector2Add(v1, refPoly.body->position);
+ v2 = Mat2MultiplyVector2(refPoly.transform, v2);
+ v2 = Vector2Add(v2, refPoly.body->position);
+
+ // Calculate reference face side normal in world space
+ Vector2 sidePlaneNormal = Vector2Subtract(v2, v1);
+ MathNormalize(&sidePlaneNormal);
+
+ // Orthogonalize
+ Vector2 refFaceNormal = { sidePlaneNormal.y, -sidePlaneNormal.x };
+ float refC = MathDot(refFaceNormal, v1);
+ float negSide = MathDot(sidePlaneNormal, v1)*-1;
+ float posSide = MathDot(sidePlaneNormal, v2);
+
+ // Clip incident face to reference face side planes (due to floating point error, possible to not have required points
+ if (Clip((Vector2){ -sidePlaneNormal.x, -sidePlaneNormal.y }, negSide, &incidentFace[0], &incidentFace[1]) < 2) return;
+ if (Clip(sidePlaneNormal, posSide, &incidentFace[0], &incidentFace[1]) < 2) return;
+
+ // Flip normal if required
+ manifold->normal = (flip ? (Vector2){ -refFaceNormal.x, -refFaceNormal.y } : refFaceNormal);
+
+ // Keep points behind reference face
+ int currentPoint = 0; // Clipped points behind reference face
+ float separation = MathDot(refFaceNormal, incidentFace[0]) - refC;
+ if (separation <= 0.0f)
+ {
+ manifold->contacts[currentPoint] = incidentFace[0];
+ manifold->penetration = -separation;
+ currentPoint++;
+ }
+ else manifold->penetration = 0.0f;
+
+ separation = MathDot(refFaceNormal, incidentFace[1]) - refC;
+
+ if (separation <= 0.0f)
+ {
+ manifold->contacts[currentPoint] = incidentFace[1];
+ manifold->penetration += -separation;
+ currentPoint++;
+
+ // Calculate total penetration average
+ manifold->penetration /= currentPoint;
+ }
+
+ manifold->contactsCount = currentPoint;
+}
+
+// Integrates physics forces into velocity
+static void IntegratePhysicsForces(PhysicsBody body)
+{
+ if ((body == NULL) || (body->inverseMass == 0.0f) || !body->enabled) return;
+
+ body->velocity.x += (body->force.x*body->inverseMass)*(deltaTime/2.0);
+ body->velocity.y += (body->force.y*body->inverseMass)*(deltaTime/2.0);
+
+ if (body->useGravity)
+ {
+ body->velocity.x += gravityForce.x*(deltaTime/1000/2.0);
+ body->velocity.y += gravityForce.y*(deltaTime/1000/2.0);
+ }
+
+ if (!body->freezeOrient) body->angularVelocity += body->torque*body->inverseInertia*(deltaTime/2.0);
+}
+
+// Initializes physics manifolds to solve collisions
+static void InitializePhysicsManifolds(PhysicsManifold manifold)
+{
+ PhysicsBody bodyA = manifold->bodyA;
+ PhysicsBody bodyB = manifold->bodyB;
+
+ if ((bodyA == NULL) || (bodyB == NULL)) return;
+
+ // Calculate average restitution, static and dynamic friction
+ manifold->restitution = sqrtf(bodyA->restitution*bodyB->restitution);
+ manifold->staticFriction = sqrtf(bodyA->staticFriction*bodyB->staticFriction);
+ manifold->dynamicFriction = sqrtf(bodyA->dynamicFriction*bodyB->dynamicFriction);
+
+ for (int i = 0; i < manifold->contactsCount; i++)
+ {
+ // Caculate radius from center of mass to contact
+ Vector2 radiusA = Vector2Subtract(manifold->contacts[i], bodyA->position);
+ Vector2 radiusB = Vector2Subtract(manifold->contacts[i], bodyB->position);
+
+ Vector2 crossA = MathCross(bodyA->angularVelocity, radiusA);
+ Vector2 crossB = MathCross(bodyB->angularVelocity, radiusB);
+
+ Vector2 radiusV = { 0.0f, 0.0f };
+ radiusV.x = bodyB->velocity.x + crossB.x - bodyA->velocity.x - crossA.x;
+ radiusV.y = bodyB->velocity.y + crossB.y - bodyA->velocity.y - crossA.y;
+
+ // Determine if we should perform a resting collision or not;
+ // The idea is if the only thing moving this object is gravity, then the collision should be performed without any restitution
+ if (MathLenSqr(radiusV) < (MathLenSqr((Vector2){ gravityForce.x*deltaTime/1000, gravityForce.y*deltaTime/1000 }) + PHYSAC_EPSILON)) manifold->restitution = 0;
+ }
+}
+
+// Integrates physics collisions impulses to solve collisions
+static void IntegratePhysicsImpulses(PhysicsManifold manifold)
+{
+ PhysicsBody bodyA = manifold->bodyA;
+ PhysicsBody bodyB = manifold->bodyB;
+
+ if ((bodyA == NULL) || (bodyB == NULL)) return;
+
+ // Early out and positional correct if both objects have infinite mass
+ if (fabs(bodyA->inverseMass + bodyB->inverseMass) <= PHYSAC_EPSILON)
+ {
+ bodyA->velocity = PHYSAC_VECTOR_ZERO;
+ bodyB->velocity = PHYSAC_VECTOR_ZERO;
+ return;
+ }
+
+ for (int i = 0; i < manifold->contactsCount; i++)
+ {
+ // Calculate radius from center of mass to contact
+ Vector2 radiusA = Vector2Subtract(manifold->contacts[i], bodyA->position);
+ Vector2 radiusB = Vector2Subtract(manifold->contacts[i], bodyB->position);
+
+ // Calculate relative velocity
+ Vector2 radiusV = { 0.0f, 0.0f };
+ radiusV.x = bodyB->velocity.x + MathCross(bodyB->angularVelocity, radiusB).x - bodyA->velocity.x - MathCross(bodyA->angularVelocity, radiusA).x;
+ radiusV.y = bodyB->velocity.y + MathCross(bodyB->angularVelocity, radiusB).y - bodyA->velocity.y - MathCross(bodyA->angularVelocity, radiusA).y;
+
+ // Relative velocity along the normal
+ float contactVelocity = MathDot(radiusV, manifold->normal);
+
+ // Do not resolve if velocities are separating
+ if (contactVelocity > 0.0f) return;
+
+ float raCrossN = MathCrossVector2(radiusA, manifold->normal);
+ float rbCrossN = MathCrossVector2(radiusB, manifold->normal);
+
+ float inverseMassSum = bodyA->inverseMass + bodyB->inverseMass + (raCrossN*raCrossN)*bodyA->inverseInertia + (rbCrossN*rbCrossN)*bodyB->inverseInertia;
+
+ // Calculate impulse scalar value
+ float impulse = -(1.0f + manifold->restitution)*contactVelocity;
+ impulse /= inverseMassSum;
+ impulse /= (float)manifold->contactsCount;
+
+ // Apply impulse to each physics body
+ Vector2 impulseV = { manifold->normal.x*impulse, manifold->normal.y*impulse };
+
+ if (bodyA->enabled)
+ {
+ bodyA->velocity.x += bodyA->inverseMass*(-impulseV.x);
+ bodyA->velocity.y += bodyA->inverseMass*(-impulseV.y);
+ if (!bodyA->freezeOrient) bodyA->angularVelocity += bodyA->inverseInertia*MathCrossVector2(radiusA, (Vector2){ -impulseV.x, -impulseV.y });
+ }
+
+ if (bodyB->enabled)
+ {
+ bodyB->velocity.x += bodyB->inverseMass*(impulseV.x);
+ bodyB->velocity.y += bodyB->inverseMass*(impulseV.y);
+ if (!bodyB->freezeOrient) bodyB->angularVelocity += bodyB->inverseInertia*MathCrossVector2(radiusB, impulseV);
+ }
+
+ // Apply friction impulse to each physics body
+ radiusV.x = bodyB->velocity.x + MathCross(bodyB->angularVelocity, radiusB).x - bodyA->velocity.x - MathCross(bodyA->angularVelocity, radiusA).x;
+ radiusV.y = bodyB->velocity.y + MathCross(bodyB->angularVelocity, radiusB).y - bodyA->velocity.y - MathCross(bodyA->angularVelocity, radiusA).y;
+
+ Vector2 tangent = { radiusV.x - (manifold->normal.x*MathDot(radiusV, manifold->normal)), radiusV.y - (manifold->normal.y*MathDot(radiusV, manifold->normal)) };
+ MathNormalize(&tangent);
+
+ // Calculate impulse tangent magnitude
+ float impulseTangent = -MathDot(radiusV, tangent);
+ impulseTangent /= inverseMassSum;
+ impulseTangent /= (float)manifold->contactsCount;
+
+ float absImpulseTangent = fabs(impulseTangent);
+
+ // Don't apply tiny friction impulses
+ if (absImpulseTangent <= PHYSAC_EPSILON) return;
+
+ // Apply coulumb's law
+ Vector2 tangentImpulse = { 0.0f, 0.0f };
+ if (absImpulseTangent < impulse*manifold->staticFriction) tangentImpulse = (Vector2){ tangent.x*impulseTangent, tangent.y*impulseTangent };
+ else tangentImpulse = (Vector2){ tangent.x*-impulse*manifold->dynamicFriction, tangent.y*-impulse*manifold->dynamicFriction };
+
+ // Apply friction impulse
+ if (bodyA->enabled)
+ {
+ bodyA->velocity.x += bodyA->inverseMass*(-tangentImpulse.x);
+ bodyA->velocity.y += bodyA->inverseMass*(-tangentImpulse.y);
+
+ if (!bodyA->freezeOrient) bodyA->angularVelocity += bodyA->inverseInertia*MathCrossVector2(radiusA, (Vector2){ -tangentImpulse.x, -tangentImpulse.y });
+ }
+
+ if (bodyB->enabled)
+ {
+ bodyB->velocity.x += bodyB->inverseMass*(tangentImpulse.x);
+ bodyB->velocity.y += bodyB->inverseMass*(tangentImpulse.y);
+
+ if (!bodyB->freezeOrient) bodyB->angularVelocity += bodyB->inverseInertia*MathCrossVector2(radiusB, tangentImpulse);
+ }
+ }
+}
+
+// Integrates physics velocity into position and forces
+static void IntegratePhysicsVelocity(PhysicsBody body)
+{
+ if ((body == NULL) ||!body->enabled) return;
+
+ body->position.x += body->velocity.x*deltaTime;
+ body->position.y += body->velocity.y*deltaTime;
+
+ if (!body->freezeOrient) body->orient += body->angularVelocity*deltaTime;
+ Mat2Set(&body->shape.transform, body->orient);
+
+ IntegratePhysicsForces(body);
+}
+
+// Corrects physics bodies positions based on manifolds collision information
+static void CorrectPhysicsPositions(PhysicsManifold manifold)
+{
+ PhysicsBody bodyA = manifold->bodyA;
+ PhysicsBody bodyB = manifold->bodyB;
+
+ if ((bodyA == NULL) || (bodyB == NULL)) return;
+
+ Vector2 correction = { 0.0f, 0.0f };
+ correction.x = (max(manifold->penetration - PHYSAC_PENETRATION_ALLOWANCE, 0.0f)/(bodyA->inverseMass + bodyB->inverseMass))*manifold->normal.x*PHYSAC_PENETRATION_CORRECTION;
+ correction.y = (max(manifold->penetration - PHYSAC_PENETRATION_ALLOWANCE, 0.0f)/(bodyA->inverseMass + bodyB->inverseMass))*manifold->normal.y*PHYSAC_PENETRATION_CORRECTION;
+
+ if (bodyA->enabled)
+ {
+ bodyA->position.x -= correction.x*bodyA->inverseMass;
+ bodyA->position.y -= correction.y*bodyA->inverseMass;
+ }
+
+ if (bodyB->enabled)
+ {
+ bodyB->position.x += correction.x*bodyB->inverseMass;
+ bodyB->position.y += correction.y*bodyB->inverseMass;
+ }
+}
+
+// Returns the extreme point along a direction within a polygon
+static Vector2 GetSupport(PhysicsShape shape, Vector2 dir)
+{
+ float bestProjection = -PHYSAC_FLT_MAX;
+ Vector2 bestVertex = { 0.0f, 0.0f };
+ PolygonData data = shape.vertexData;
+
+ for (int i = 0; i < data.vertexCount; i++)
+ {
+ Vector2 vertex = data.positions[i];
+ float projection = MathDot(vertex, dir);
+
+ if (projection > bestProjection)
+ {
+ bestVertex = vertex;
+ bestProjection = projection;
+ }
+ }
+
+ return bestVertex;
+}
+
+// Finds polygon shapes axis least penetration
+static float FindAxisLeastPenetration(int *faceIndex, PhysicsShape shapeA, PhysicsShape shapeB)
+{
+ float bestDistance = -PHYSAC_FLT_MAX;
+ int bestIndex = 0;
+
+ PolygonData dataA = shapeA.vertexData;
+ PolygonData dataB = shapeB.vertexData;
+
+ for (int i = 0; i < dataA.vertexCount; i++)
+ {
+ // Retrieve a face normal from A shape
+ Vector2 normal = dataA.normals[i];
+ Vector2 transNormal = Mat2MultiplyVector2(shapeA.transform, normal);
+
+ // Transform face normal into B shape's model space
+ Mat2 buT = Mat2Transpose(shapeB.transform);
+ normal = Mat2MultiplyVector2(buT, transNormal);
+
+ // Retrieve support point from B shape along -n
+ Vector2 support = GetSupport(shapeB, (Vector2){ -normal.x, -normal.y });
+
+ // Retrieve vertex on face from A shape, transform into B shape's model space
+ Vector2 vertex = dataA.positions[i];
+ vertex = Mat2MultiplyVector2(shapeA.transform, vertex);
+ vertex = Vector2Add(vertex, shapeA.body->position);
+ vertex = Vector2Subtract(vertex, shapeB.body->position);
+ vertex = Mat2MultiplyVector2(buT, vertex);
+
+ // Compute penetration distance in B shape's model space
+ float distance = MathDot(normal, Vector2Subtract(support, vertex));
+
+ // Store greatest distance
+ if (distance > bestDistance)
+ {
+ bestDistance = distance;
+ bestIndex = i;
+ }
+ }
+
+ *faceIndex = bestIndex;
+ return bestDistance;
+}
+
+// Finds two polygon shapes incident face
+static void FindIncidentFace(Vector2 *v0, Vector2 *v1, PhysicsShape ref, PhysicsShape inc, int index)
+{
+ PolygonData refData = ref.vertexData;
+ PolygonData incData = inc.vertexData;
+
+ Vector2 referenceNormal = refData.normals[index];
+
+ // Calculate normal in incident's frame of reference
+ referenceNormal = Mat2MultiplyVector2(ref.transform, referenceNormal); // To world space
+ referenceNormal = Mat2MultiplyVector2(Mat2Transpose(inc.transform), referenceNormal); // To incident's model space
+
+ // Find most anti-normal face on polygon
+ int incidentFace = 0;
+ float minDot = PHYSAC_FLT_MAX;
+
+ for (int i = 0; i < incData.vertexCount; i++)
+ {
+ float dot = MathDot(referenceNormal, incData.normals[i]);
+
+ if (dot < minDot)
+ {
+ minDot = dot;
+ incidentFace = i;
+ }
+ }
+
+ // Assign face vertices for incident face
+ *v0 = Mat2MultiplyVector2(inc.transform, incData.positions[incidentFace]);
+ *v0 = Vector2Add(*v0, inc.body->position);
+ incidentFace = (((incidentFace + 1) < incData.vertexCount) ? (incidentFace + 1) : 0);
+ *v1 = Mat2MultiplyVector2(inc.transform, incData.positions[incidentFace]);
+ *v1 = Vector2Add(*v1, inc.body->position);
+}
+
+// Calculates clipping based on a normal and two faces
+static int Clip(Vector2 normal, float clip, Vector2 *faceA, Vector2 *faceB)
+{
+ int sp = 0;
+ Vector2 out[2] = { *faceA, *faceB };
+
+ // Retrieve distances from each endpoint to the line
+ float distanceA = MathDot(normal, *faceA) - clip;
+ float distanceB = MathDot(normal, *faceB) - clip;
+
+ // If negative (behind plane)
+ if (distanceA <= 0.0f) out[sp++] = *faceA;
+ if (distanceB <= 0.0f) out[sp++] = *faceB;
+
+ // If the points are on different sides of the plane
+ if ((distanceA*distanceB) < 0.0f)
+ {
+ // Push intersection point
+ float alpha = distanceA/(distanceA - distanceB);
+ out[sp] = *faceA;
+ Vector2 delta = Vector2Subtract(*faceB, *faceA);
+ delta.x *= alpha;
+ delta.y *= alpha;
+ out[sp] = Vector2Add(out[sp], delta);
+ sp++;
+ }
+
+ // Assign the new converted values
+ *faceA = out[0];
+ *faceB = out[1];
+
+ return sp;
+}
+
+// Check if values are between bias range
+static bool BiasGreaterThan(float valueA, float valueB)
+{
+ return (valueA >= (valueB*0.95f + valueA*0.01f));
+}
+
+// Returns the barycenter of a triangle given by 3 points
+static Vector2 TriangleBarycenter(Vector2 v1, Vector2 v2, Vector2 v3)
+{
+ Vector2 result = { 0.0f, 0.0f };
+
+ result.x = (v1.x + v2.x + v3.x)/3;
+ result.y = (v1.y + v2.y + v3.y)/3;
+
+ return result;
+}
+
+// Initializes hi-resolution MONOTONIC timer
+static void InitTimer(void)
+{
+ srand(time(NULL)); // Initialize random seed
+
+#if defined(_WIN32)
+ QueryPerformanceFrequency((unsigned long long int *) &frequency);
+#endif
+
+#if defined(__linux__)
+ struct timespec now;
+ if (clock_gettime(CLOCK_MONOTONIC, &now) == 0) frequency = 1000000000;
+#endif
+
+#if defined(__APPLE__)
+ mach_timebase_info_data_t timebase;
+ mach_timebase_info(&timebase);
+ frequency = (timebase.denom*1e9)/timebase.numer;
+#endif
+
+ baseTime = GetTimeCount(); // Get MONOTONIC clock time offset
+ startTime = GetCurrentTime(); // Get current time
+}
+
+// Get hi-res MONOTONIC time measure in seconds
+static uint64_t GetTimeCount(void)
+{
+ uint64_t value;
+
+#if defined(_WIN32)
+ QueryPerformanceCounter((unsigned long long int *) &value);
+#endif
+
+#if defined(__linux__)
+ struct timespec now;
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ value = (uint64_t)now.tv_sec*(uint64_t)1000000000 + (uint64_t)now.tv_nsec;
+#endif
+
+#if defined(__APPLE__)
+ value = mach_absolute_time();
+#endif
+
+ return value;
+}
+
+// Get current time in milliseconds
+static double GetCurrentTime(void)
+{
+ return (double)(GetTimeCount() - baseTime)/frequency*1000;
+}
+
+// Returns a random number between min and max (both included)
+static int GetRandomNumber(int min, int max)
+{
+ if (min > max)
+ {
+ int tmp = max;
+ max = min;
+ min = tmp;
+ }
+
+ return (rand()%(abs(max - min) + 1) + min);
+}
+
+// Returns the cross product of a vector and a value
+static inline Vector2 MathCross(float value, Vector2 vector)
+{
+ return (Vector2){ -value*vector.y, value*vector.x };
+}
+
+// Returns the cross product of two vectors
+static inline float MathCrossVector2(Vector2 v1, Vector2 v2)
+{
+ return (v1.x*v2.y - v1.y*v2.x);
+}
+
+// Returns the len square root of a vector
+static inline float MathLenSqr(Vector2 vector)
+{
+ return (vector.x*vector.x + vector.y*vector.y);
+}
+
+// Returns the dot product of two vectors
+static inline float MathDot(Vector2 v1, Vector2 v2)
+{
+ return (v1.x*v2.x + v1.y*v2.y);
+}
+
+// Returns the square root of distance between two vectors
+static inline float DistSqr(Vector2 v1, Vector2 v2)
+{
+ Vector2 dir = Vector2Subtract(v1, v2);
+ return MathDot(dir, dir);
+}
+
+// Returns the normalized values of a vector
+static void MathNormalize(Vector2 *vector)
+{
+ float length, ilength;
+
+ Vector2 aux = *vector;
+ length = sqrtf(aux.x*aux.x + aux.y*aux.y);
+
+ if (length == 0) length = 1.0f;
+
+ ilength = 1.0f/length;
+
+ vector->x *= ilength;
+ vector->y *= ilength;
+}
+
+#if defined(PHYSAC_STANDALONE)
+// Returns the sum of two given vectors
+static inline Vector2 Vector2Add(Vector2 v1, Vector2 v2)
+{
+ return (Vector2){ v1.x + v2.x, v1.y + v2.y };
+}
+
+// Returns the subtract of two given vectors
+static inline Vector2 Vector2Subtract(Vector2 v1, Vector2 v2)
+{
+ return (Vector2){ v1.x - v2.x, v1.y - v2.y };
+}
+#endif
+
+// Creates a matrix 2x2 from a given radians value
+static Mat2 Mat2Radians(float radians)
+{
+ float c = cosf(radians);
+ float s = sinf(radians);
+
+ return (Mat2){ c, -s, s, c };
+}
+
+// Set values from radians to a created matrix 2x2
+static void Mat2Set(Mat2 *matrix, float radians)
+{
+ float cos = cosf(radians);
+ float sin = sinf(radians);
+
+ matrix->m00 = cos;
+ matrix->m01 = -sin;
+ matrix->m10 = sin;
+ matrix->m11 = cos;
+}
+
+// Returns the transpose of a given matrix 2x2
+static inline Mat2 Mat2Transpose(Mat2 matrix)
+{
+ return (Mat2){ matrix.m00, matrix.m10, matrix.m01, matrix.m11 };
+}
+
+// Multiplies a vector by a matrix 2x2
+static inline Vector2 Mat2MultiplyVector2(Mat2 matrix, Vector2 vector)
+{
+ return (Vector2){ matrix.m00*vector.x + matrix.m01*vector.y, matrix.m10*vector.x + matrix.m11*vector.y };
+}
+
+#endif // PHYSAC_IMPLEMENTATION
diff --git a/Generator/raygui.h b/Generator/raygui.h
new file mode 100644
index 0000000..8773346
--- /dev/null
+++ b/Generator/raygui.h
@@ -0,0 +1,3155 @@
+/*******************************************************************************************
+*
+* raygui v2.0-dev - A simple and easy-to-use immedite-mode-gui library
+*
+* DESCRIPTION:
+*
+* raygui is a tools-dev-focused immediate-mode-gui library based on raylib but also possible
+* to be used as a standalone library, as long as input and drawing functions are provided.
+*
+* Basic controls provided:
+*
+* - WindowBox
+* - GroupBox
+* - Line
+* - Panel
+* - Label
+* - Button
+* - LabelButton --> Label
+* - ImageButton --> Button
+* - ImageButtonEx --> Button
+* - Toggle
+* - ToggleGroup --> Toggle
+* - CheckBox
+* - ComboBox
+* - DropdownBox
+* - TextBox
+* - TextBoxMulti --> TextBox
+* - ValueBox --> TextBox
+* - Spinner --> Button, ValueBox
+* - Slider
+* - SliderBar --> Slider
+* - ProgressBar
+* - StatusBar
+* - ScrollPanel
+* - ListView --> ListElement
+* - ColorPicker --> ColorPanel, ColorBarHue
+* - MessageBox
+* - DummyRec
+* - Grid
+*
+* It also provides a set of functions for styling the controls based on its properties (size, color).
+*
+* CONFIGURATION:
+*
+* #define RAYGUI_IMPLEMENTATION
+* Generates the implementation of the library into the included file.
+* If not defined, the library is in header only mode and can be included in other headers
+* or source files without problems. But only ONE file should hold the implementation.
+*
+* #define RAYGUI_STATIC (defined by default)
+* The generated implementation will stay private inside implementation file and all
+* internal symbols and functions will only be visible inside that file.
+*
+* #define RAYGUI_STANDALONE
+* Avoid raylib.h header inclusion in this file. Data types defined on raylib are defined
+* internally in the library and input management and drawing functions must be provided by
+* the user (check library implementation for further details).
+*
+* VERSIONS HISTORY:
+* 2.0 (xx-Nov-2018) Complete review of new controls, redesigned style system
+* 1.9 (01-May-2018) Lot of rework and redesign! Lots of new controls!
+* 1.5 (21-Jun-2017) Working in an improved styles system
+* 1.4 (15-Jun-2017) Rewritten all GUI functions (removed useless ones)
+* 1.3 (12-Jun-2017) Redesigned styles system
+* 1.1 (01-Jun-2017) Complete review of the library
+* 1.0 (07-Jun-2016) Converted to header-only by Ramon Santamaria.
+* 0.9 (07-Mar-2016) Reviewed and tested by Albert Martos, Ian Eito, Sergio Martinez and Ramon Santamaria.
+* 0.8 (27-Aug-2015) Initial release. Implemented by Kevin Gato, Daniel Nicolás and Ramon Santamaria.
+*
+* CONTRIBUTORS:
+* Ramon Santamaria: Supervision, review, redesign, update and maintenance...
+* Sergio Martinez: Review, testing (2015) and redesign of multiple controls (2018)
+* Adria Arranz: Testing and Implementation of additional controls (2018)
+* Jordi Jorba: Testing and Implementation of additional controls (2018)
+* Albert Martos: Review and testing of the library (2015)
+* Ian Eito: Review and testing of the library (2015)
+* Kevin Gato: Initial implementation of basic components (2014)
+* Daniel Nicolas: Initial implementation of basic components (2014)
+*
+*
+* LICENSE: zlib/libpng
+*
+* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5)
+*
+* 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.
+*
+* Permission is granted to anyone to use this software for any purpose, including commercial
+* applications, and to alter it and redistribute it freely, subject to the following restrictions:
+*
+* 1. The origin of this software must not be misrepresented; you must not claim that you
+* wrote the original software. If you use this software in a product, an acknowledgment
+* in the product documentation would be appreciated but is not required.
+*
+* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
+* as being the original software.
+*
+* 3. This notice may not be removed or altered from any source distribution.
+*
+**********************************************************************************************/
+
+#ifndef RAYGUI_H
+#define RAYGUI_H
+
+#define RAYGUI_VERSION "2.0-dev"
+
+#if !defined(RAYGUI_STANDALONE)
+ #include "raylib.h"
+#endif
+
+#if defined(RAYGUI_IMPLEMENTATION)
+ #if defined(_WIN32) && defined(BUILD_LIBTYPE_SHARED)
+ #define RAYGUIDEF __declspec(dllexport) extern // We are building raygui as a Win32 shared library (.dll).
+ #elif defined(_WIN32) && defined(USE_LIBTYPE_SHARED)
+ #define RAYGUIDEF __declspec(dllimport) // We are using raygui as a Win32 shared library (.dll)
+ #else
+ #ifdef __cplusplus
+ #define RAYGUIDEF extern "C" // Functions visible from other files (no name mangling of functions in C++)
+ #else
+ #define RAYGUIDEF extern // Functions visible from other files
+ #endif
+ #endif
+#elif defined(RAYGUI_STATIC)
+ #define RAYGUIDEF static // Functions just visible to module including this file
+#endif
+
+#include // Required for: atoi()
+
+//----------------------------------------------------------------------------------
+// Defines and Macros
+//----------------------------------------------------------------------------------
+#define VALIGN_OFFSET(h) ((int)h%2) // Vertical alignment for pixel perfect
+#define LINE_BLINK_FRAMES 20 // Text edit controls cursor blink timming
+
+#define NUM_CONTROLS 12 // Number of standard controls
+#define NUM_PROPS_DEFAULT 16 // Number of standard properties
+#define NUM_PROPS_EXTENDED 8 // Number of extended properties
+
+//----------------------------------------------------------------------------------
+// Types and Structures Definition
+// NOTE: Some types are required for RAYGUI_STANDALONE usage
+//----------------------------------------------------------------------------------
+#if defined(RAYGUI_STANDALONE)
+ #ifndef __cplusplus
+ // Boolean type
+ #ifndef true
+ typedef enum { false, true } bool;
+ #endif
+ #endif
+
+ // Vector2 type
+ typedef struct Vector2 {
+ float x;
+ float y;
+ } Vector2;
+
+ // Vector3 type
+ typedef struct Vector3 {
+ float x;
+ float y;
+ float z;
+ } Vector3;
+
+ // 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;
+#endif
+
+// Gui global state enum
+typedef enum {
+ GUI_STATE_NORMAL = 0,
+ GUI_STATE_FOCUSED,
+ GUI_STATE_PRESSED,
+ GUI_STATE_DISABLED,
+} GuiControlState;
+
+// Gui standard controls
+typedef enum {
+ DEFAULT = 0,
+ LABEL, // LABELBUTTON
+ BUTTON, // IMAGEBUTTON
+ TOGGLE, // TOGGLEGROUP
+ SLIDER, // SLIDERBAR
+ PROGRESSBAR,
+ CHECKBOX,
+ COMBOBOX,
+ DROPDOWNBOX,
+ TEXTBOX, // VALUEBOX, SPINNER
+ LISTVIEW,
+ COLORPICKER
+} GuiControlStandard;
+
+// Gui default properties for every control
+typedef enum {
+ BORDER_COLOR_NORMAL = 0,
+ BASE_COLOR_NORMAL,
+ TEXT_COLOR_NORMAL,
+ BORDER_COLOR_FOCUSED,
+ BASE_COLOR_FOCUSED,
+ TEXT_COLOR_FOCUSED,
+ BORDER_COLOR_PRESSED,
+ BASE_COLOR_PRESSED,
+ TEXT_COLOR_PRESSED,
+ BORDER_COLOR_DISABLED,
+ BASE_COLOR_DISABLED,
+ TEXT_COLOR_DISABLED,
+ BORDER_WIDTH,
+ INNER_PADDING,
+ RESERVED01,
+ RESERVED02
+} GuiControlProperty;
+
+// Gui extended properties depending on control type
+// NOTE: We reserve a fixed size of additional properties per control (8)
+
+// Default properties
+typedef enum {
+ TEXT_SIZE = 16,
+ TEXT_SPACING,
+ LINES_COLOR,
+ BACKGROUND_COLOR,
+} GuiDefaultProperty;
+
+// Label
+//typedef enum { } GuiLabelProperty;
+
+// Button
+//typedef enum { } GuiButtonProperty;
+
+// Toggle / ToggleGroup
+typedef enum {
+ GROUP_PADDING = 16,
+} GuiToggleProperty;
+
+// Slider / SliderBar
+typedef enum {
+ SLIDER_WIDTH = 16,
+ EX_TEXT_PADDING
+} GuiSliderProperty;
+
+// ProgressBar
+//typedef enum { } GuiProgressBarProperty;
+
+// TextBox / ValueBox / Spinner
+typedef enum {
+ MULTILINE_PADDING = 16,
+ SPINNER_BUTTON_WIDTH,
+ SPINNER_BUTTON_PADDING,
+ SPINNER_BUTTON_BORDER_WIDTH
+} GuiTextBoxProperty;
+
+// CheckBox
+typedef enum {
+ CHECK_TEXT_PADDING = 16
+} GuiCheckBoxProperty;
+
+// ComboBox
+typedef enum {
+ SELECTOR_WIDTH = 16,
+ SELECTOR_PADDING
+} GuiComboBoxProperty;
+
+// DropdownBox
+typedef enum {
+ ARROW_RIGHT_PADDING = 16,
+} GuiDropdownBoxProperty;
+
+// ColorPicker
+typedef enum {
+ COLOR_SELECTOR_SIZE = 16,
+ BAR_WIDTH, // Lateral bar width
+ BAR_PADDING, // Lateral bar separation from panel
+ BAR_SELECTOR_HEIGHT, // Lateral bar selector height
+ BAR_SELECTOR_PADDING // Lateral bar selector outer padding
+} GuiColorPickerProperty;
+
+// ListView
+typedef enum {
+ ELEMENTS_HEIGHT = 16,
+ ELEMENTS_PADDING,
+ SCROLLBAR_WIDTH,
+} GuiListViewProperty;
+
+//----------------------------------------------------------------------------------
+// Global Variables Definition
+//----------------------------------------------------------------------------------
+// ...
+
+//----------------------------------------------------------------------------------
+// Module Functions Declaration
+//----------------------------------------------------------------------------------
+
+// Global gui modification functions
+RAYGUIDEF void GuiEnable(void); // Enable gui controls (global state)
+RAYGUIDEF void GuiDisable(void); // Disable gui controls (global state)
+RAYGUIDEF void GuiLock(void); // Lock gui controls (global state)
+RAYGUIDEF void GuiUnlock(void); // Unlock gui controls (global state)
+RAYGUIDEF void GuiState(int state); // Set gui state (global state)
+RAYGUIDEF void GuiFont(Font font); // Set gui custom font (global state)
+RAYGUIDEF void GuiFade(float alpha); // Set gui controls alpha (global state), alpha goes from 0.0f to 1.0f
+
+// Style set/get functions
+RAYGUIDEF void GuiSetStyle(int control, int property, int value); // Set one style property
+RAYGUIDEF int GuiGetStyle(int control, int property); // Get one style property
+
+// Container/separator controls, useful for controls organization
+RAYGUIDEF bool GuiWindowBox(Rectangle bounds, const char *text); // Window Box control, shows a window that can be closed
+RAYGUIDEF void GuiGroupBox(Rectangle bounds, const char *text); // Group Box control with title name
+RAYGUIDEF void GuiLine(Rectangle bounds, int thick); // Line separator control
+RAYGUIDEF void GuiPanel(Rectangle bounds); // Panel control, useful to group controls
+RAYGUIDEF Vector2 GuiScrollPanel(Rectangle bounds, Rectangle content, Vector2 viewScroll); // Scroll Panel control
+
+// Basic controls set
+RAYGUIDEF void GuiLabel(Rectangle bounds, const char *text); // Label control, shows text
+RAYGUIDEF void GuiLabelEx(Rectangle bounds, const char *text, int alignment, int padding); // Label control extended
+RAYGUIDEF bool GuiButton(Rectangle bounds, const char *text); // Button control, returns true when clicked
+RAYGUIDEF bool GuiLabelButton(Rectangle bounds, const char *text); // Label button control, show true when clicked
+RAYGUIDEF bool GuiImageButton(Rectangle bounds, Texture2D texture); // Image button control, returns true when clicked
+RAYGUIDEF bool GuiImageButtonEx(Rectangle bounds, Texture2D texture, Rectangle texSource, const char *text); // Image button extended control, returns true when clicked
+RAYGUIDEF bool GuiToggle(Rectangle bounds, const char *text, bool toggle); // Toggle Button control, returns true when active
+RAYGUIDEF int GuiToggleGroup(Rectangle bounds, const char **text, int count, int active); // Toggle Group control, returns toggled button index
+RAYGUIDEF int GuiToggleGroupEx(Rectangle bounds, const char **text, int count, int active, int padding, int columns); // Toggle Group with extended parameters
+RAYGUIDEF bool GuiCheckBox(Rectangle bounds, bool checked); // Check Box control, returns true when active
+RAYGUIDEF bool GuiCheckBoxEx(Rectangle bounds, bool checked, const char *text); // Check Box control with text, returns true when active
+RAYGUIDEF int GuiComboBox(Rectangle bounds, const char **text, int count, int active); // Combo Box control, returns selected item index
+RAYGUIDEF bool GuiDropdownBox(Rectangle bounds, const char **text, int count, int *active, bool editMode); // Dropdown Box control, returns selected item
+RAYGUIDEF bool GuiSpinner(Rectangle bounds, int *value, int minValue, int maxValue, int btnWidth, bool editMode); // Spinner control, returns selected value
+RAYGUIDEF bool GuiValueBox(Rectangle bounds, int *value, int minValue, int maxValue, bool editMode); // Value Box control, updates input text with numbers
+RAYGUIDEF bool GuiTextBox(Rectangle bounds, char *text, int textSize, bool freeEdit); // Text Box control, updates input text
+RAYGUIDEF bool GuiTextBoxMulti(Rectangle bounds, char *text, int textSize, bool editMode); // Text Box control with multiple lines
+RAYGUIDEF float GuiSlider(Rectangle bounds, float value, float minValue, float maxValue); // Slider control, returns selected value
+RAYGUIDEF float GuiSliderEx(Rectangle bounds, float value, float minValue, float maxValue, const char *text, bool showValue); // Slider control, returns selected value
+RAYGUIDEF float GuiSliderBar(Rectangle bounds, float value, float minValue, float maxValue); // Slider Bar control, returns selected value
+RAYGUIDEF float GuiSliderBarEx(Rectangle bounds, float value, float minValue, float maxValue, const char *text, bool showValue); // Slider Bar control, returns selected value
+RAYGUIDEF float GuiProgressBar(Rectangle bounds, float value, float minValue, float maxValue); // Progress Bar control, shows current progress value
+RAYGUIDEF float GuiProgressBarEx(Rectangle bounds, float value, float minValue, float maxValue, bool showValue); // Progress Bar control, shows current progress value
+RAYGUIDEF void GuiStatusBar(Rectangle bounds, const char *text, int offsetX); // Status Bar control, shows info text
+RAYGUIDEF void GuiDummyRec(Rectangle bounds, const char *text); // Dummy control for placeholders
+
+// Advance controls set
+RAYGUIDEF bool GuiListView(Rectangle bounds, const char **text, int count, int *scrollIndex, int *active, bool editMode); // List View control, returns selected list element index
+RAYGUIDEF bool GuiListViewEx(Rectangle bounds, const char **text, int *enabledElements, int count, int *scrollIndex, int *active, int *focus, bool editMode); // with List View extended parameters
+RAYGUIDEF Color GuiColorPicker(Rectangle bounds, Color color); // Color Picker control
+RAYGUIDEF bool GuiMessageBox(Rectangle bounds, const char *windowTitle, const char *message); // Message Box control, displays a message
+
+// Styles loading functions
+RAYGUIDEF void GuiLoadStyle(const char *fileName); // Load style file (.rgs)
+RAYGUIDEF void GuiLoadStyleProps(const int *props, int count); // Load style from a color palette array (14 values required)
+RAYGUIDEF void GuiLoadStyleDefault(void); // Load style default over global style
+RAYGUIDEF void GuiUpdateStyleComplete(void); // Updates full style properties set with default values
+
+/*
+typedef GuiStyle (unsigned int *)
+RAYGUIDEF GuiStyle LoadGuiStyle(const char *fileName); // Load style from file (.rgs)
+RAYGUIDEF void UnloadGuiStyle(GuiStyle style); // Unload style
+*/
+
+#endif // RAYGUI_H
+
+
+/***********************************************************************************
+*
+* RAYGUI IMPLEMENTATION
+*
+************************************************************************************/
+
+#if defined(RAYGUI_IMPLEMENTATION)
+
+#include // Required for: FILE, fopen(), fclose(), fprintf(), feof(), fscanf(), vsprintf()
+#include // Required for: strlen() on GuiTextBox()
+
+#if defined(RAYGUI_STANDALONE)
+ #include // Required for: va_list, va_start(), vfprintf(), va_end()
+#endif
+
+//----------------------------------------------------------------------------------
+// Defines and Macros
+//----------------------------------------------------------------------------------
+//...
+
+//----------------------------------------------------------------------------------
+// Types and Structures Definition
+//----------------------------------------------------------------------------------
+//...
+
+//----------------------------------------------------------------------------------
+// Global Variables Definition
+//----------------------------------------------------------------------------------
+static GuiControlState guiState = GUI_STATE_NORMAL;
+
+static Font guiFont = { 0 }; // NOTE: Highly coupled to raylib
+static bool guiLocked = false;
+static float guiAlpha = 1.0f;
+
+// Global gui style array (allocated on heap by default)
+// NOTE: In raygui we manage a single int array with all the possible style properties.
+// When a new style is loaded, it loads over the global style... but default gui style
+// could always be recovered with GuiLoadStyleDefault()
+static unsigned int guiStyle[NUM_CONTROLS*(NUM_PROPS_DEFAULT + NUM_PROPS_EXTENDED)] = { 0 };
+static bool guiStyleLoaded = false;
+
+//----------------------------------------------------------------------------------
+// Standalone Mode Functions Declaration
+//----------------------------------------------------------------------------------
+#if defined(RAYGUI_STANDALONE)
+
+#define KEY_RIGHT 262
+#define KEY_LEFT 263
+#define KEY_DOWN 264
+#define KEY_UP 265
+#define KEY_BACKSPACE 259
+#define MOUSE_LEFT_BUTTON 0
+
+#ifdef __cplusplus
+ #define CLITERAL
+#else
+ #define CLITERAL (Color)
+#endif
+
+#define WHITE CLITERAL{ 255, 255, 255, 255 } // White
+#define BLACK CLITERAL{ 0, 0, 0, 255 } // Black
+#define RAYWHITE CLITERAL{ 245, 245, 245, 255 } // My own White (raylib logo)
+
+// This functions are directly implemented in raygui
+static Color GetColor(int hexValue); // Returns a Color struct from hexadecimal value
+static int ColorToInt(Color color); // Returns hexadecimal value for a Color
+static Color Fade(Color color, float alpha); // Color fade-in or fade-out, alpha goes from 0.0f to 1.0f
+static bool CheckCollisionPointRec(Vector2 point, Rectangle rec); // Check if point is inside rectangle
+static const char *FormatText(const char *text, ...); // Formatting of text with variables to 'embed'
+
+// raygui depend on some raylib input and drawing functions
+// NOTE: To use raygui as standalone library, below functions must be defined by the user
+
+static Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing) { } // Measure string size for Font
+static void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint) { 0 } // Draw text using font and additional parameters
+
+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); }
+
+// Input related functions
+static Vector2 GetMousePosition(void) { return (Vector2){ 0, 0 }; }
+static bool IsMouseButtonDown(int button);
+static bool IsMouseButtonReleased(int button);
+
+static int GetKeyPressed(void); // -- GuiTextBox()
+static bool IsKeyPressed(int key); // -- GuiTextBox()
+static bool IsKeyDown(int key); // -- GuiTextBox()
+
+// Control specific functions
+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 DrawTextureRec(Texture2D texture, int posX, int posY, Color tint); // -- GuiImageButtonEx()
+
+#endif // RAYGUI_STANDALONE
+
+//----------------------------------------------------------------------------------
+// Module specific Functions Declaration
+//----------------------------------------------------------------------------------
+
+// List Element control, returns element state
+static bool GuiListElement(Rectangle bounds, const char *text, bool active, bool editMode);
+
+static Vector3 ConvertHSVtoRGB(Vector3 hsv); // Convert color data from HSV to RGB
+static Vector3 ConvertRGBtoHSV(Vector3 rgb); // Convert color data from RGB to HSV
+
+// Gui draw text using default font
+static void GuiDrawText(const char *text, int posX, int posY, Color tint)
+{
+ if (guiFont.texture.id == 0) guiFont = GetFontDefault();
+
+ DrawTextEx(guiFont, text, (Vector2){ posX, posY }, GuiGetStyle(DEFAULT, TEXT_SIZE), GuiGetStyle(DEFAULT, TEXT_SPACING), tint);
+}
+
+// Gui get text width using default font
+static int GuiTextWidth(const char *text)
+{
+ if (guiFont.texture.id == 0) guiFont = GetFontDefault();
+
+ Vector2 size = MeasureTextEx(guiFont, text, GuiGetStyle(DEFAULT, TEXT_SIZE), GuiGetStyle(DEFAULT, TEXT_SPACING));
+
+ return (int)size.x;
+}
+
+//----------------------------------------------------------------------------------
+// Module Functions Definition
+//----------------------------------------------------------------------------------
+
+// Enable gui global state
+RAYGUIDEF void GuiEnable(void) { guiState = GUI_STATE_NORMAL; }
+
+// Disable gui global state
+RAYGUIDEF void GuiDisable(void) { guiState = GUI_STATE_DISABLED; }
+
+// Lock gui global state
+RAYGUIDEF void GuiLock(void) { guiLocked = true; }
+
+// Unlock gui global state
+RAYGUIDEF void GuiUnlock(void) { guiLocked = false; }
+
+// Set gui state (global state)
+RAYGUIDEF void GuiState(int state) { guiState = (GuiControlState)state; }
+
+// Define custom gui font
+RAYGUIDEF void GuiFont(Font font)
+{
+ if (font.texture.id > 0)
+ {
+ guiFont = font;
+ GuiSetStyle(DEFAULT, TEXT_SIZE, font.baseSize);
+
+ // Populate all controls with new font size
+ for (int i = 1; i < NUM_CONTROLS; i++) GuiSetStyle(i, TEXT_SIZE, GuiGetStyle(DEFAULT, TEXT_SIZE));
+
+ // NOTE: Loaded font spacing must be set manually
+ //GuiSetStyle(DEFAULT, TEXT_SPACING, 1);
+ }
+}
+
+// Set gui controls alpha global state
+RAYGUIDEF void GuiFade(float alpha)
+{
+ if (alpha < 0.0f) alpha = 0.0f;
+ else if (alpha > 1.0f) alpha = 1.0f;
+
+ guiAlpha = alpha;
+}
+
+// Set control style property value
+RAYGUIDEF void GuiSetStyle(int control, int property, int value)
+{
+ if (!guiStyleLoaded) GuiLoadStyleDefault();
+ guiStyle[control*(NUM_PROPS_DEFAULT + NUM_PROPS_EXTENDED) + property] = value;
+}
+
+// Get control style property value
+RAYGUIDEF int GuiGetStyle(int control, int property)
+{
+ if (!guiStyleLoaded) GuiLoadStyleDefault();
+ return guiStyle[control*(NUM_PROPS_DEFAULT + NUM_PROPS_EXTENDED) + property];
+}
+
+// Window Box control
+RAYGUIDEF bool GuiWindowBox(Rectangle bounds, const char *text)
+{
+ #define WINDOW_CLOSE_BUTTON_PADDING 2
+ #define WINDOW_SATUSBAR_HEIGHT 24
+
+ GuiControlState state = guiState;
+ bool clicked = false;
+
+ int offsetX = 10;
+ int textWidth = GuiTextWidth(text);
+ //int textHeight = GuiGetStyle(DEFAULT, TEXT_SIZE);
+
+ if (bounds.width < textWidth + offsetX*2 + 16) bounds.width = textWidth + offsetX*2 + 16;
+ Rectangle statusBar = { bounds.x, bounds.y, bounds.width, WINDOW_SATUSBAR_HEIGHT };
+ if (bounds.height < WINDOW_SATUSBAR_HEIGHT*2) bounds.height = WINDOW_SATUSBAR_HEIGHT*2;
+
+ // Update control
+ //--------------------------------------------------------------------
+ if ((state != GUI_STATE_DISABLED) && !guiLocked)
+ {
+ Vector2 mousePoint = GetMousePosition();
+
+ // Check button state
+ if (CheckCollisionPointRec(mousePoint, (Rectangle){ statusBar.x + statusBar.width - WINDOW_SATUSBAR_HEIGHT, statusBar.y, 20, statusBar.height }))
+ {
+ if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = GUI_STATE_PRESSED;
+ else if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) clicked = true;
+ else state = GUI_STATE_FOCUSED;
+ }
+ }
+ //--------------------------------------------------------------------
+
+ // Draw control
+ //--------------------------------------------------------------------
+ switch (state)
+ {
+ case GUI_STATE_NORMAL:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(DEFAULT, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(DEFAULT, BORDER_COLOR_NORMAL)), guiAlpha));
+ DrawRectangleRec((Rectangle){ bounds.x + GuiGetStyle(DEFAULT, BORDER_WIDTH), bounds.y + GuiGetStyle(DEFAULT, BORDER_WIDTH), bounds.width - GuiGetStyle(DEFAULT, BORDER_WIDTH)*2, bounds.height - GuiGetStyle(DEFAULT, BORDER_WIDTH)*2 }, Fade(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR)), guiAlpha));
+ GuiStatusBar(statusBar, text, offsetX);
+ DrawRectangleRec((Rectangle){statusBar.x + statusBar.width - 27 + WINDOW_CLOSE_BUTTON_PADDING*2, statusBar.y + 1 + WINDOW_CLOSE_BUTTON_PADDING, 25 - WINDOW_CLOSE_BUTTON_PADDING*3, statusBar.height - 2 - WINDOW_CLOSE_BUTTON_PADDING*2}, Fade(GetColor(GuiGetStyle(DEFAULT, BASE_COLOR_NORMAL)), guiAlpha));
+ GuiDrawText("x", statusBar.x + statusBar.width - 16, statusBar.y + statusBar.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2, Fade(GetColor(GuiGetStyle(DEFAULT, TEXT_COLOR_NORMAL)), guiAlpha));
+ } break;
+ case GUI_STATE_FOCUSED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(DEFAULT, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(DEFAULT, BORDER_COLOR_NORMAL)), guiAlpha));
+ DrawRectangleRec((Rectangle){ bounds.x + GuiGetStyle(DEFAULT, BORDER_WIDTH), bounds.y + GuiGetStyle(DEFAULT, BORDER_WIDTH), bounds.width - GuiGetStyle(DEFAULT, BORDER_WIDTH)*2, bounds.height - GuiGetStyle(DEFAULT, BORDER_WIDTH)*2 }, Fade(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR)), guiAlpha));
+ GuiStatusBar(statusBar, text, offsetX);
+ DrawRectangleRec((Rectangle){statusBar.x + statusBar.width - 27 + WINDOW_CLOSE_BUTTON_PADDING*2, statusBar.y + 1 + WINDOW_CLOSE_BUTTON_PADDING, 25 - WINDOW_CLOSE_BUTTON_PADDING*3, statusBar.height - 2 - WINDOW_CLOSE_BUTTON_PADDING*2}, Fade(GetColor(GuiGetStyle(DEFAULT, BASE_COLOR_FOCUSED)), guiAlpha));
+ GuiDrawText("x", statusBar.x + statusBar.width - 16, statusBar.y + statusBar.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2, Fade(GetColor(GuiGetStyle(DEFAULT, TEXT_COLOR_FOCUSED)), guiAlpha));
+ } break;
+ case GUI_STATE_PRESSED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(DEFAULT, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(DEFAULT, BORDER_COLOR_NORMAL)), guiAlpha));
+ DrawRectangleRec((Rectangle){ bounds.x + GuiGetStyle(DEFAULT, BORDER_WIDTH), bounds.y + GuiGetStyle(DEFAULT, BORDER_WIDTH), bounds.width - GuiGetStyle(DEFAULT, BORDER_WIDTH)*2, bounds.height - GuiGetStyle(DEFAULT, BORDER_WIDTH)*2 }, Fade(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR)), guiAlpha));
+ GuiStatusBar(statusBar, text, offsetX);
+ DrawRectangleRec((Rectangle){statusBar.x + statusBar.width - 27 + WINDOW_CLOSE_BUTTON_PADDING*2, statusBar.y + 1 + WINDOW_CLOSE_BUTTON_PADDING, 25 - WINDOW_CLOSE_BUTTON_PADDING*3, statusBar.height - 2 - WINDOW_CLOSE_BUTTON_PADDING*2}, Fade(GetColor(GuiGetStyle(DEFAULT, BASE_COLOR_PRESSED)), guiAlpha));
+ GuiDrawText("x", statusBar.x + statusBar.width - 16, statusBar.y + statusBar.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2, Fade(GetColor(GuiGetStyle(DEFAULT, TEXT_COLOR_PRESSED)), guiAlpha));
+ } break;
+ case GUI_STATE_DISABLED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(DEFAULT, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(DEFAULT, BORDER_COLOR_DISABLED)), guiAlpha));
+ DrawRectangleRec((Rectangle){ bounds.x + GuiGetStyle(DEFAULT, BORDER_WIDTH), bounds.y + GuiGetStyle(DEFAULT, BORDER_WIDTH), bounds.width - GuiGetStyle(DEFAULT, BORDER_WIDTH)*2, bounds.height - GuiGetStyle(DEFAULT, BORDER_WIDTH)*2 }, Fade(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR)), guiAlpha));
+ GuiStatusBar(statusBar, text, offsetX);
+ DrawRectangleRec((Rectangle){statusBar.x + statusBar.width - 27 + WINDOW_CLOSE_BUTTON_PADDING*2, statusBar.y + 1 + WINDOW_CLOSE_BUTTON_PADDING, 25 - WINDOW_CLOSE_BUTTON_PADDING*3, statusBar.height - 2 - WINDOW_CLOSE_BUTTON_PADDING*2}, Fade(GetColor(GuiGetStyle(DEFAULT, BASE_COLOR_DISABLED)), guiAlpha));
+ GuiDrawText("x", statusBar.x + statusBar.width - 16, statusBar.y + statusBar.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2, Fade(GetColor(GuiGetStyle(DEFAULT, TEXT_COLOR_DISABLED)), guiAlpha));
+ } break;
+ default: break;
+ }
+
+ //--------------------------------------------------------------------
+ return clicked;
+}
+
+// Group Box control with title name
+RAYGUIDEF void GuiGroupBox(Rectangle bounds, const char *text)
+{
+ #define GROUPBOX_LINE_THICK 1
+ #define GROUPBOX_TEXT_PADDING 10
+ #define GROUPBOX_PADDING 2
+
+ GuiControlState state = guiState;
+
+ // Draw control
+ //--------------------------------------------------------------------
+ switch (state)
+ {
+ case GUI_STATE_NORMAL:
+ case GUI_STATE_FOCUSED:
+ case GUI_STATE_PRESSED:
+ {
+ DrawRectangle(bounds.x, bounds.y, GROUPBOX_LINE_THICK, bounds.height, Fade(GetColor(GuiGetStyle(DEFAULT, LINES_COLOR)), guiAlpha));
+ DrawRectangle(bounds.x, bounds.y + bounds.height - 1, bounds.width, GROUPBOX_LINE_THICK, Fade(GetColor(GuiGetStyle(DEFAULT, LINES_COLOR)), guiAlpha));
+ DrawRectangle(bounds.x + bounds.width - 1, bounds.y, GROUPBOX_LINE_THICK, bounds.height, Fade(GetColor(GuiGetStyle(DEFAULT, LINES_COLOR)), guiAlpha));
+ if ((text == NULL) || (text[0] == '\0')) DrawRectangle(bounds.x, bounds.y, bounds.width, GROUPBOX_LINE_THICK, Fade(GetColor(GuiGetStyle(DEFAULT, LINES_COLOR)), guiAlpha));
+ else
+ {
+ DrawRectangle(bounds.x, bounds.y, GROUPBOX_TEXT_PADDING, GROUPBOX_LINE_THICK, Fade(GetColor(GuiGetStyle(DEFAULT, LINES_COLOR)), guiAlpha));
+ DrawRectangle(bounds.x + 2*GROUPBOX_TEXT_PADDING + GuiTextWidth(text), bounds.y, bounds.width - 2*GROUPBOX_TEXT_PADDING - GuiTextWidth(text), GROUPBOX_LINE_THICK, Fade(GetColor(GuiGetStyle(DEFAULT, LINES_COLOR)), guiAlpha));
+ GuiDrawText(text, bounds.x + GROUPBOX_TEXT_PADDING + 2*GROUPBOX_PADDING, bounds.y - 2*GROUPBOX_PADDING - GROUPBOX_LINE_THICK, Fade(GetColor(GuiGetStyle(LABEL, TEXT_COLOR_NORMAL)), guiAlpha));
+ }
+ } break;
+ case GUI_STATE_DISABLED:
+ {
+ DrawRectangle(bounds.x, bounds.y, GROUPBOX_LINE_THICK, bounds.height, Fade(GetColor(GuiGetStyle(DEFAULT, BORDER_COLOR_DISABLED)), guiAlpha));
+ DrawRectangle(bounds.x, bounds.y + bounds.height - 1, bounds.width, GROUPBOX_LINE_THICK, Fade(GetColor(GuiGetStyle(DEFAULT, BORDER_COLOR_DISABLED)), guiAlpha));
+ DrawRectangle(bounds.x + bounds.width - 1, bounds.y, GROUPBOX_LINE_THICK, bounds.height, Fade(GetColor(GuiGetStyle(DEFAULT, BORDER_COLOR_DISABLED)), guiAlpha));
+ if ((text == NULL) || (text[0] == '\0')) DrawRectangle(bounds.x, bounds.y, bounds.width, GROUPBOX_LINE_THICK, Fade(GetColor(GuiGetStyle(DEFAULT, LINES_COLOR)), guiAlpha));
+ else
+ {
+ DrawRectangle(bounds.x, bounds.y, GROUPBOX_TEXT_PADDING, GROUPBOX_LINE_THICK, Fade(GetColor(GuiGetStyle(DEFAULT, BORDER_COLOR_DISABLED)), guiAlpha));
+ DrawRectangle(bounds.x + 2*GROUPBOX_TEXT_PADDING + GuiTextWidth(text), bounds.y, bounds.width - 2*GROUPBOX_TEXT_PADDING - GuiTextWidth(text), GROUPBOX_LINE_THICK, Fade(GetColor(GuiGetStyle(DEFAULT, BORDER_COLOR_DISABLED)), guiAlpha));
+ GuiDrawText(text, bounds.x + GROUPBOX_TEXT_PADDING + 2*GROUPBOX_PADDING, bounds.y - 2*GROUPBOX_PADDING - GROUPBOX_LINE_THICK, Fade(GetColor(GuiGetStyle(LABEL, TEXT_COLOR_DISABLED)), guiAlpha));
+ }
+ } break;
+ default: break;
+ }
+ //--------------------------------------------------------------------
+}
+
+// Line control
+RAYGUIDEF void GuiLine(Rectangle bounds, int thick)
+{
+ GuiControlState state = guiState;
+
+ Rectangle line = { bounds.x, bounds.y + bounds.height/2 - thick/2, bounds.width, thick };
+
+ // Draw control
+ //--------------------------------------------------------------------
+ switch (state)
+ {
+ case GUI_STATE_NORMAL:
+ case GUI_STATE_FOCUSED:
+ case GUI_STATE_PRESSED: DrawRectangleLinesEx(line, thick, Fade(GetColor(GuiGetStyle(DEFAULT, LINES_COLOR)), guiAlpha)); break;
+ case GUI_STATE_DISABLED: DrawRectangleLinesEx(line, thick, Fade(GetColor(GuiGetStyle(DEFAULT, BORDER_COLOR_DISABLED)), guiAlpha)); break;
+ default: break;
+ }
+ //--------------------------------------------------------------------
+}
+
+// Panel control
+RAYGUIDEF void GuiPanel(Rectangle bounds)
+{
+ #define PANEL_BORDER_WIDTH 1
+
+ GuiControlState state = guiState;
+
+ // Draw control
+ //--------------------------------------------------------------------
+ switch (state)
+ {
+ case GUI_STATE_NORMAL:
+ case GUI_STATE_FOCUSED:
+ case GUI_STATE_PRESSED:
+ {
+ DrawRectangleRec(bounds, Fade(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR)), guiAlpha));
+ DrawRectangleLinesEx(bounds, PANEL_BORDER_WIDTH, Fade(GetColor(GuiGetStyle(DEFAULT, LINES_COLOR)), guiAlpha));
+ } break;
+ case GUI_STATE_DISABLED:
+ {
+ DrawRectangleRec(bounds, Fade(GetColor(GuiGetStyle(DEFAULT, BASE_COLOR_DISABLED)), guiAlpha));
+ DrawRectangleLinesEx(bounds, PANEL_BORDER_WIDTH, Fade(GetColor(GuiGetStyle(DEFAULT, BORDER_COLOR_DISABLED)), guiAlpha));
+ } break;
+ default: break;
+ }
+ //--------------------------------------------------------------------
+}
+
+// Scroll Panel control
+// NOTE: bounds define the view area, content defines size of internal data
+RAYGUIDEF Vector2 GuiScrollPanel(Rectangle bounds, Rectangle content, Vector2 viewScroll)
+{
+ // TODO: Implement scroll panel control
+
+ return viewScroll;
+}
+
+// Label control
+RAYGUIDEF void GuiLabel(Rectangle bounds, const char *text)
+{
+ GuiLabelEx(bounds, text, 0, 0); // Left-alignment, no-padding
+}
+
+// Label control extended
+// NOTE: Alignment and padding are just considered on horizontal
+RAYGUIDEF void GuiLabelEx(Rectangle bounds, const char *text, int alignment, int padding)
+{
+ GuiControlState state = guiState;
+
+ int textWidth = GuiTextWidth(text);
+ int textHeight = GuiGetStyle(DEFAULT, TEXT_SIZE);
+
+ if (bounds.width < textWidth) bounds.width = textWidth;
+ if (bounds.height < textHeight) bounds.height = textHeight;
+
+ Vector2 textPosition = { bounds.x + padding, bounds.y + bounds.height/2 - textHeight/2 + VALIGN_OFFSET(bounds.height) }; // Left alignment
+
+ if (alignment == 1) textPosition.x = bounds.x + bounds.width/2 - textWidth/2 + padding; // Middle-alignment
+ else if (alignment == 2) textPosition.x = bounds.x + bounds.width - textWidth + padding; // Right alignment
+
+ // Update control
+ //--------------------------------------------------------------------
+ // ...
+ //--------------------------------------------------------------------
+
+ // Draw control
+ //--------------------------------------------------------------------
+ switch (state)
+ {
+ case GUI_STATE_NORMAL:
+ case GUI_STATE_FOCUSED:
+ case GUI_STATE_PRESSED: GuiDrawText(text, textPosition.x, textPosition.y, Fade(GetColor(GuiGetStyle(LABEL, TEXT_COLOR_NORMAL)), guiAlpha)); break;
+ case GUI_STATE_DISABLED: GuiDrawText(text, textPosition.x, textPosition.y, Fade(GetColor(GuiGetStyle(LABEL, TEXT_COLOR_DISABLED)), guiAlpha)); break;
+ default: break;
+ }
+ //--------------------------------------------------------------------
+}
+
+// Button control, returns true when clicked
+RAYGUIDEF bool GuiButton(Rectangle bounds, const char *text)
+{
+ GuiControlState state = guiState;
+ bool pressed = false;
+
+ int textWidth = GuiTextWidth(text);
+ int textHeight = GuiGetStyle(DEFAULT, TEXT_SIZE);
+
+ if (bounds.width < textWidth) bounds.width = textWidth;
+ if (bounds.height < textHeight) bounds.height = textHeight;
+
+ // Update control
+ //--------------------------------------------------------------------
+ if ((state != GUI_STATE_DISABLED) && !guiLocked)
+ {
+ Vector2 mousePoint = GetMousePosition();
+
+ // Check button state
+ if (CheckCollisionPointRec(mousePoint, bounds))
+ {
+ if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = GUI_STATE_PRESSED;
+ else state = GUI_STATE_FOCUSED;
+
+ if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) pressed = true;
+ }
+ }
+ //--------------------------------------------------------------------
+
+ // Draw control
+ //--------------------------------------------------------------------
+ switch (state)
+ {
+ case GUI_STATE_NORMAL:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(BUTTON, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(BUTTON, BORDER_COLOR_NORMAL)), guiAlpha));
+ DrawRectangle(bounds.x + GuiGetStyle(BUTTON, BORDER_WIDTH), bounds.y + GuiGetStyle(BUTTON, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(BUTTON, BORDER_WIDTH), bounds.height - 2*GuiGetStyle(BUTTON, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(BUTTON, BASE_COLOR_NORMAL)), guiAlpha));
+ GuiDrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2 + VALIGN_OFFSET(bounds.height), Fade(GetColor(GuiGetStyle(BUTTON, TEXT_COLOR_NORMAL)), guiAlpha));
+ } break;
+ case GUI_STATE_FOCUSED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(BUTTON, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(BUTTON, BORDER_COLOR_FOCUSED)), guiAlpha));
+ DrawRectangle(bounds.x + GuiGetStyle(BUTTON, BORDER_WIDTH), bounds.y + GuiGetStyle(BUTTON, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(BUTTON, BORDER_WIDTH), bounds.height - 2*GuiGetStyle(BUTTON, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(BUTTON, BASE_COLOR_FOCUSED)), guiAlpha));
+ GuiDrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2 + VALIGN_OFFSET(bounds.height), Fade(GetColor(GuiGetStyle(BUTTON, TEXT_COLOR_FOCUSED)), guiAlpha));
+ } break;
+ case GUI_STATE_PRESSED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(BUTTON, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(BUTTON, BORDER_COLOR_PRESSED)), guiAlpha));
+ DrawRectangle(bounds.x + GuiGetStyle(BUTTON, BORDER_WIDTH), bounds.y + GuiGetStyle(BUTTON, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(BUTTON, BORDER_WIDTH), bounds.height - 2*GuiGetStyle(BUTTON, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(BUTTON, BASE_COLOR_PRESSED)), guiAlpha));
+ GuiDrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2 + VALIGN_OFFSET(bounds.height), Fade(GetColor(GuiGetStyle(BUTTON, TEXT_COLOR_PRESSED)), guiAlpha));
+ } break;
+ case GUI_STATE_DISABLED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(BUTTON, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(BUTTON, BORDER_COLOR_DISABLED)), guiAlpha));
+ DrawRectangle(bounds.x + GuiGetStyle(BUTTON, BORDER_WIDTH), bounds.y + GuiGetStyle(BUTTON, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(BUTTON, BORDER_WIDTH), bounds.height - 2*GuiGetStyle(BUTTON, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(BUTTON, BASE_COLOR_DISABLED)), guiAlpha));
+ GuiDrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2 + VALIGN_OFFSET(bounds.height), Fade(GetColor(GuiGetStyle(BUTTON, TEXT_COLOR_DISABLED)), guiAlpha));
+ } break;
+ default: break;
+ }
+ //------------------------------------------------------------------
+
+ return pressed;
+}
+
+// Label button control
+RAYGUIDEF bool GuiLabelButton(Rectangle bounds, const char *text)
+{
+ GuiControlState state = guiState;
+ bool pressed = false;
+
+ int textWidth = GuiTextWidth(text);
+ int textHeight = GuiGetStyle(DEFAULT, TEXT_SIZE);
+
+ if (bounds.width < textWidth) bounds.width = textWidth;
+ if (bounds.height < textHeight) bounds.height = textHeight;
+
+ // Update control
+ //--------------------------------------------------------------------
+ if ((state != GUI_STATE_DISABLED) && !guiLocked)
+ {
+ Vector2 mousePoint = GetMousePosition();
+
+ // Check checkbox state
+ if (CheckCollisionPointRec(mousePoint, bounds))
+ {
+ if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = GUI_STATE_PRESSED;
+ else state = GUI_STATE_FOCUSED;
+
+ if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) pressed = true;
+ }
+ }
+ //--------------------------------------------------------------------
+
+ // Draw control
+ //--------------------------------------------------------------------
+ switch (state)
+ {
+ case GUI_STATE_NORMAL: GuiDrawText(text, bounds.x, bounds.y + bounds.height/2 - textHeight/2, Fade(GetColor(GuiGetStyle(LABEL, TEXT_COLOR_NORMAL)), guiAlpha)); break;
+ case GUI_STATE_FOCUSED: GuiDrawText(text, bounds.x, bounds.y + bounds.height/2 - textHeight/2, Fade(GetColor(GuiGetStyle(LABEL, TEXT_COLOR_FOCUSED)), guiAlpha)); break;
+ case GUI_STATE_PRESSED: GuiDrawText(text, bounds.x, bounds.y + bounds.height/2 - textHeight/2, Fade(GetColor(GuiGetStyle(LABEL, TEXT_COLOR_PRESSED)), guiAlpha)); break;
+ case GUI_STATE_DISABLED: GuiDrawText(text, bounds.x, bounds.y + bounds.height/2 - textHeight/2, Fade(GetColor(GuiGetStyle(LABEL, TEXT_COLOR_DISABLED)), guiAlpha)); break;
+ default: break;
+ }
+ //--------------------------------------------------------------------
+
+ return pressed;
+}
+
+// Image button control, returns true when clicked
+RAYGUIDEF bool GuiImageButton(Rectangle bounds, Texture2D texture)
+{
+ return GuiImageButtonEx(bounds, texture, (Rectangle){ 0, 0, texture.width, texture.height }, NULL);
+}
+
+// Image button control, returns true when clicked
+RAYGUIDEF bool GuiImageButtonEx(Rectangle bounds, Texture2D texture, Rectangle texSource, const char *text)
+{
+ GuiControlState state = guiState;
+ bool clicked = false;
+ int textWidth = 0;
+ int textHeight = 0;
+
+ if (bounds.width < texSource.width) bounds.width = texSource.width;
+ if (bounds.height < texSource.height) bounds.height = texSource.height;
+
+ if (text != NULL)
+ {
+ textWidth = GuiTextWidth(text);
+ textHeight = GuiGetStyle(DEFAULT, TEXT_SIZE);
+
+ if (bounds.width < textWidth + texSource.width) bounds.width = textWidth + texSource.width + GuiGetStyle(BUTTON, INNER_PADDING);
+ if (bounds.height < textHeight) bounds.height = textHeight;
+ }
+
+ // Update control
+ //--------------------------------------------------------------------
+ if ((state != GUI_STATE_DISABLED) && !guiLocked)
+ {
+ Vector2 mousePoint = GetMousePosition();
+
+ // Check button state
+ if (CheckCollisionPointRec(mousePoint, bounds))
+ {
+ if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = GUI_STATE_PRESSED;
+ else if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) clicked = true;
+ else state = GUI_STATE_FOCUSED;
+ }
+ }
+ //--------------------------------------------------------------------
+
+ // Draw control
+ //--------------------------------------------------------------------
+ switch (state)
+ {
+ case GUI_STATE_NORMAL:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(BUTTON, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(BUTTON, BORDER_COLOR_NORMAL)), guiAlpha));
+ DrawRectangle(bounds.x + GuiGetStyle(BUTTON, BORDER_WIDTH), bounds.y + GuiGetStyle(BUTTON, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(BUTTON, BORDER_WIDTH), bounds.height - 2*GuiGetStyle(BUTTON, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(BUTTON, BASE_COLOR_NORMAL)), guiAlpha));
+ if (text != NULL) GuiDrawText(text, (bounds.x + bounds.width/2 - (texSource.width + GuiGetStyle(BUTTON, INNER_PADDING) + textWidth)/2) + texSource.width, bounds.y + bounds.height/2 - textHeight/2, Fade(GetColor(GuiGetStyle(BUTTON, TEXT_COLOR_NORMAL)), guiAlpha));
+ if (texture.id > 0) DrawTextureRec(texture, texSource, (Vector2){ bounds.x + bounds.width/2 - (texSource.width + GuiGetStyle(BUTTON, INNER_PADDING)/2 + textWidth)/2, bounds.y + bounds.height/2 - texSource.height/2 }, Fade(GetColor(GuiGetStyle(BUTTON, TEXT_COLOR_NORMAL)), guiAlpha));
+ } break;
+ case GUI_STATE_FOCUSED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(BUTTON, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(BUTTON, BORDER_COLOR_FOCUSED)), guiAlpha));
+ DrawRectangle(bounds.x + GuiGetStyle(BUTTON, BORDER_WIDTH), bounds.y + GuiGetStyle(BUTTON, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(BUTTON, BORDER_WIDTH), bounds.height - 2*GuiGetStyle(BUTTON, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(BUTTON, BASE_COLOR_FOCUSED)), guiAlpha));
+ if (text != NULL) GuiDrawText(text, (bounds.x + bounds.width/2 - (texSource.width + GuiGetStyle(BUTTON, INNER_PADDING) + textWidth)/2) + texSource.width, bounds.y + bounds.height/2 - textHeight/2, Fade(GetColor(GuiGetStyle(BUTTON, TEXT_COLOR_FOCUSED)), guiAlpha));
+ if (texture.id > 0) DrawTextureRec(texture, texSource, (Vector2){ bounds.x + bounds.width/2 - (texSource.width + GuiGetStyle(BUTTON, INNER_PADDING)/2 + textWidth)/2, bounds.y + bounds.height/2 - texSource.height/2 }, Fade(GetColor(GuiGetStyle(BUTTON, TEXT_COLOR_FOCUSED)), guiAlpha));
+ } break;
+ case GUI_STATE_PRESSED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(BUTTON, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(BUTTON, BORDER_COLOR_PRESSED)), guiAlpha));
+ DrawRectangle(bounds.x + GuiGetStyle(BUTTON, BORDER_WIDTH), bounds.y + GuiGetStyle(BUTTON, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(BUTTON, BORDER_WIDTH), bounds.height - 2*GuiGetStyle(BUTTON, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(BUTTON, BASE_COLOR_PRESSED)), guiAlpha));
+ if (text != NULL) GuiDrawText(text, (bounds.x + bounds.width/2 - (texSource.width + GuiGetStyle(BUTTON, INNER_PADDING) + textWidth)/2) + texSource.width, bounds.y + bounds.height/2 - textHeight/2, Fade(GetColor(GuiGetStyle(BUTTON, TEXT_COLOR_PRESSED)), guiAlpha));
+ if (texture.id > 0) DrawTextureRec(texture, texSource, (Vector2){ bounds.x + bounds.width/2 - (texSource.width + GuiGetStyle(BUTTON, INNER_PADDING)/2 + textWidth)/2, bounds.y + bounds.height/2 - texSource.height/2 }, Fade(GetColor(GuiGetStyle(BUTTON, TEXT_COLOR_PRESSED)), guiAlpha));
+ } break;
+ case GUI_STATE_DISABLED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(BUTTON, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(BUTTON, BORDER_COLOR_DISABLED)), guiAlpha));
+ DrawRectangle(bounds.x + GuiGetStyle(BUTTON, BORDER_WIDTH), bounds.y + GuiGetStyle(BUTTON, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(BUTTON, BORDER_WIDTH), bounds.height - 2*GuiGetStyle(BUTTON, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(BUTTON, BASE_COLOR_DISABLED)), guiAlpha));
+ if (text != NULL) GuiDrawText(text, (bounds.x + bounds.width/2 - (texSource.width + GuiGetStyle(BUTTON, INNER_PADDING) + textWidth)/2) + texSource.width, bounds.y + bounds.height/2 - textHeight/2, Fade(GetColor(GuiGetStyle(BUTTON, TEXT_COLOR_DISABLED)), guiAlpha));
+ if (texture.id > 0) DrawTextureRec(texture, texSource, (Vector2){ bounds.x + bounds.width/2 - (texSource.width + GuiGetStyle(BUTTON, INNER_PADDING)/2 + textWidth)/2, bounds.y + bounds.height/2 - texSource.height/2 }, Fade(GetColor(GuiGetStyle(BUTTON, TEXT_COLOR_DISABLED)), guiAlpha));
+ } break;
+ default: break;
+ }
+ //------------------------------------------------------------------
+
+ return clicked;
+}
+
+// Toggle Button control, returns true when active
+RAYGUIDEF bool GuiToggle(Rectangle bounds, const char *text, bool active)
+{
+ GuiControlState state = guiState;
+
+ int textWidth = GuiTextWidth(text);
+ int textHeight = GuiGetStyle(DEFAULT, TEXT_SIZE);
+
+ if (bounds.width < textWidth) bounds.width = textWidth;
+ if (bounds.height < textHeight) bounds.height = textHeight;
+
+ // Update control
+ //--------------------------------------------------------------------
+ if ((state != GUI_STATE_DISABLED) && !guiLocked)
+ {
+ Vector2 mousePoint = GetMousePosition();
+
+ // Check toggle button state
+ if (CheckCollisionPointRec(mousePoint, bounds))
+ {
+ if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = GUI_STATE_PRESSED;
+ else if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON))
+ {
+ state = GUI_STATE_NORMAL;
+ active = !active;
+ }
+ else state = GUI_STATE_FOCUSED;
+ }
+ }
+ //--------------------------------------------------------------------
+
+ // Draw control
+ //--------------------------------------------------------------------
+ switch (state)
+ {
+ case GUI_STATE_NORMAL:
+ {
+ if (active)
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(TOGGLE, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TOGGLE, BORDER_COLOR_PRESSED)), guiAlpha));
+ DrawRectangle(bounds.x + GuiGetStyle(TOGGLE, BORDER_WIDTH), bounds.y + GuiGetStyle(TOGGLE, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(TOGGLE, BORDER_WIDTH), bounds.height - 2*GuiGetStyle(TOGGLE, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TOGGLE, BASE_COLOR_PRESSED)), guiAlpha));
+ GuiDrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2 + VALIGN_OFFSET(bounds.height), Fade(GetColor(GuiGetStyle(TOGGLE, TEXT_COLOR_PRESSED)), guiAlpha));
+ }
+ else
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(TOGGLE, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TOGGLE, BORDER_COLOR_NORMAL)), guiAlpha));
+ DrawRectangle(bounds.x + GuiGetStyle(TOGGLE, BORDER_WIDTH), bounds.y + GuiGetStyle(TOGGLE, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(TOGGLE, BORDER_WIDTH), bounds.height - 2*GuiGetStyle(TOGGLE, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TOGGLE, BASE_COLOR_NORMAL)), guiAlpha));
+ GuiDrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2 + VALIGN_OFFSET(bounds.height), Fade(GetColor(GuiGetStyle(TOGGLE, TEXT_COLOR_NORMAL)), guiAlpha));
+ }
+ } break;
+ case GUI_STATE_FOCUSED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(TOGGLE, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TOGGLE, BORDER_COLOR_FOCUSED)), guiAlpha));
+ DrawRectangle(bounds.x + GuiGetStyle(TOGGLE, BORDER_WIDTH), bounds.y + GuiGetStyle(TOGGLE, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(TOGGLE, BORDER_WIDTH), bounds.height - 2*GuiGetStyle(TOGGLE, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TOGGLE, BASE_COLOR_FOCUSED)), guiAlpha));
+ GuiDrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2 + VALIGN_OFFSET(bounds.height), Fade(GetColor(GuiGetStyle(TOGGLE, TEXT_COLOR_FOCUSED)), guiAlpha));
+ } break;
+ case GUI_STATE_PRESSED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(TOGGLE, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TOGGLE, BORDER_COLOR_PRESSED)), guiAlpha));
+ DrawRectangle(bounds.x + GuiGetStyle(TOGGLE, BORDER_WIDTH), bounds.y + GuiGetStyle(TOGGLE, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(TOGGLE, BORDER_WIDTH), bounds.height - 2*GuiGetStyle(TOGGLE, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TOGGLE, BASE_COLOR_PRESSED)), guiAlpha));
+ GuiDrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2 + VALIGN_OFFSET(bounds.height), Fade(GetColor(GuiGetStyle(TOGGLE, TEXT_COLOR_PRESSED)), guiAlpha));
+ } break;
+ case GUI_STATE_DISABLED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(TOGGLE, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TOGGLE, BORDER_COLOR_DISABLED)), guiAlpha));
+ DrawRectangle(bounds.x + GuiGetStyle(TOGGLE, BORDER_WIDTH), bounds.y + GuiGetStyle(TOGGLE, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(TOGGLE, BORDER_WIDTH), bounds.height - 2*GuiGetStyle(TOGGLE, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TOGGLE, BASE_COLOR_DISABLED)), guiAlpha));
+ GuiDrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2 + VALIGN_OFFSET(bounds.height), Fade(GetColor(GuiGetStyle(TOGGLE, TEXT_COLOR_DISABLED)), guiAlpha));
+ } break;
+ default: break;
+ }
+ //--------------------------------------------------------------------
+
+ return active;
+}
+
+// Toggle Group control, returns toggled button index
+RAYGUIDEF int GuiToggleGroup(Rectangle bounds, const char **text, int count, int active)
+{
+ return GuiToggleGroupEx(bounds, text, count, active, GuiGetStyle(TOGGLE, GROUP_PADDING), 512);
+}
+
+// Toggle Group with pro parameters, returns toggled button index
+// NOTE: bounds refer to an individual toggle size, spacing refers to toggles separation and columns defines number of columns
+RAYGUIDEF int GuiToggleGroupEx(Rectangle bounds, const char **text, int count, int active, int padding, int columns)
+{
+ float initBoundsX = bounds.x;
+ int currentColumn = 0;
+
+ for (int i = 0; i < count; i++)
+ {
+ if (i == active) GuiToggle(bounds, text[i], true);
+ else if (GuiToggle(bounds, text[i], false) == true) active = i;
+
+ bounds.x += (bounds.width + padding);
+ currentColumn++;
+
+ if ((currentColumn + 1) > columns)
+ {
+ currentColumn = 0;
+ bounds.y += (bounds.height + padding);
+ bounds.x = initBoundsX;
+ }
+ }
+
+ return active;
+}
+
+// Check Box control, returns true when active
+RAYGUIDEF bool GuiCheckBox(Rectangle bounds, bool checked)
+{
+ return GuiCheckBoxEx(bounds, checked, NULL);
+}
+
+// Check Box extended control, returns true when active
+// TODO: Focus check box when text selected!
+RAYGUIDEF bool GuiCheckBoxEx(Rectangle bounds, bool checked, const char *text)
+{
+ GuiControlState state = guiState;
+ int textWidth = (text == NULL) ? 0 : GuiTextWidth(text);
+
+ // Update control
+ //--------------------------------------------------------------------
+ if ((state != GUI_STATE_DISABLED) && !guiLocked)
+ {
+ Vector2 mousePoint = GetMousePosition();
+
+ // Check checkbox state
+ if (CheckCollisionPointRec(mousePoint, bounds))
+ {
+ if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = GUI_STATE_PRESSED;
+ else state = GUI_STATE_FOCUSED;
+
+ if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) checked = !checked;
+ }
+ }
+ //--------------------------------------------------------------------
+
+ // Draw control
+ //--------------------------------------------------------------------
+ if (text != NULL) if (GuiLabelButton((Rectangle){ bounds.x + bounds.width + GuiGetStyle(CHECKBOX, CHECK_TEXT_PADDING), bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2, textWidth, GuiGetStyle(DEFAULT, TEXT_SIZE) }, text)) checked = !checked;
+
+ switch (state)
+ {
+ case GUI_STATE_NORMAL:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(CHECKBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(CHECKBOX, BORDER_COLOR_NORMAL)), guiAlpha));
+ if (checked) DrawRectangle(bounds.x + GuiGetStyle(CHECKBOX, BORDER_WIDTH) + GuiGetStyle(CHECKBOX, INNER_PADDING),
+ bounds.y + GuiGetStyle(CHECKBOX, BORDER_WIDTH) + GuiGetStyle(CHECKBOX, INNER_PADDING),
+ bounds.width - 2*(GuiGetStyle(CHECKBOX, BORDER_WIDTH) + GuiGetStyle(CHECKBOX, INNER_PADDING)),
+ bounds.height - 2*(GuiGetStyle(CHECKBOX, BORDER_WIDTH) + GuiGetStyle(CHECKBOX, INNER_PADDING)), Fade(GetColor(GuiGetStyle(CHECKBOX, TEXT_COLOR_PRESSED)), guiAlpha));
+ } break;
+ case GUI_STATE_FOCUSED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(CHECKBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(CHECKBOX, BORDER_COLOR_FOCUSED)), guiAlpha));
+ if (checked) DrawRectangle(bounds.x + GuiGetStyle(CHECKBOX, BORDER_WIDTH) + GuiGetStyle(CHECKBOX, INNER_PADDING),
+ bounds.y + GuiGetStyle(CHECKBOX, BORDER_WIDTH) + GuiGetStyle(CHECKBOX, INNER_PADDING),
+ bounds.width - 2*(GuiGetStyle(CHECKBOX, BORDER_WIDTH) + GuiGetStyle(CHECKBOX, INNER_PADDING)),
+ bounds.height - 2*(GuiGetStyle(CHECKBOX, BORDER_WIDTH) + GuiGetStyle(CHECKBOX, INNER_PADDING)), Fade(GetColor(GuiGetStyle(CHECKBOX, TEXT_COLOR_FOCUSED)), guiAlpha));
+ } break;
+ case GUI_STATE_PRESSED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(CHECKBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(CHECKBOX, BORDER_COLOR_PRESSED)), guiAlpha));
+ if (checked) DrawRectangle(bounds.x + GuiGetStyle(CHECKBOX, BORDER_WIDTH) + GuiGetStyle(CHECKBOX, INNER_PADDING),
+ bounds.y + GuiGetStyle(CHECKBOX, BORDER_WIDTH) + GuiGetStyle(CHECKBOX, INNER_PADDING),
+ bounds.width - 2*(GuiGetStyle(CHECKBOX, BORDER_WIDTH) + GuiGetStyle(CHECKBOX, INNER_PADDING)),
+ bounds.height - 2*(GuiGetStyle(CHECKBOX, BORDER_WIDTH) + GuiGetStyle(CHECKBOX, INNER_PADDING)), Fade(GetColor(GuiGetStyle(CHECKBOX, TEXT_COLOR_PRESSED)), guiAlpha));
+ } break;
+ case GUI_STATE_DISABLED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(CHECKBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(DEFAULT, BORDER_COLOR_DISABLED)), guiAlpha));
+ if (checked) DrawRectangle(bounds.x + GuiGetStyle(CHECKBOX, BORDER_WIDTH) + GuiGetStyle(CHECKBOX, INNER_PADDING),
+ bounds.y + GuiGetStyle(CHECKBOX, BORDER_WIDTH) + GuiGetStyle(CHECKBOX, INNER_PADDING),
+ bounds.width - 2*(GuiGetStyle(CHECKBOX, BORDER_WIDTH) + GuiGetStyle(CHECKBOX, INNER_PADDING)),
+ bounds.height - 2*(GuiGetStyle(CHECKBOX, BORDER_WIDTH) + GuiGetStyle(CHECKBOX, INNER_PADDING)), Fade(GetColor(GuiGetStyle(DEFAULT, TEXT_COLOR_DISABLED)), guiAlpha));
+ } break;
+ default: break;
+ }
+ //--------------------------------------------------------------------
+
+ return checked;
+}
+
+// Combo Box control, returns selected item index
+RAYGUIDEF int GuiComboBox(Rectangle bounds, const char **text, int count, int active)
+{
+ GuiControlState state = guiState;
+
+ bounds.width -= (GuiGetStyle(COMBOBOX, SELECTOR_WIDTH) + GuiGetStyle(COMBOBOX, SELECTOR_PADDING));
+
+ Rectangle selector = { bounds.x + bounds.width + GuiGetStyle(COMBOBOX, SELECTOR_PADDING),
+ bounds.y, GuiGetStyle(COMBOBOX, SELECTOR_WIDTH), bounds.height };
+
+ if (active < 0) active = 0;
+ else if (active > count - 1) active = count - 1;
+
+ int textWidth = GuiTextWidth(text[active]);
+ int textHeight = GuiGetStyle(DEFAULT, TEXT_SIZE);
+
+ if (bounds.width < textWidth) bounds.width = textWidth;
+ if (bounds.height < textHeight) bounds.height = textHeight;
+
+ // Update control
+ //--------------------------------------------------------------------
+ if ((state != GUI_STATE_DISABLED) && !guiLocked)
+ {
+ Vector2 mousePoint = GetMousePosition();
+
+ if (CheckCollisionPointRec(mousePoint, bounds) ||
+ CheckCollisionPointRec(mousePoint, selector))
+ {
+ if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
+ {
+ active += 1;
+ if (active >= count) active = 0;
+ }
+
+ if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = GUI_STATE_PRESSED;
+ else state = GUI_STATE_FOCUSED;
+ }
+ }
+ //--------------------------------------------------------------------
+
+ // Draw control
+ //--------------------------------------------------------------------
+ switch (state)
+ {
+ case GUI_STATE_NORMAL:
+ {
+ // Draw combo box main
+ DrawRectangleLinesEx(bounds, GuiGetStyle(COMBOBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(COMBOBOX, BORDER_COLOR_NORMAL)), guiAlpha));
+ DrawRectangle(bounds.x + GuiGetStyle(COMBOBOX, BORDER_WIDTH), bounds.y + GuiGetStyle(COMBOBOX, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(COMBOBOX, BORDER_WIDTH), bounds.height - 2*GuiGetStyle(COMBOBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(COMBOBOX, BASE_COLOR_NORMAL)), guiAlpha));
+
+ // Draw selector
+ DrawRectangleLinesEx(selector, GuiGetStyle(COMBOBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(COMBOBOX, BORDER_COLOR_NORMAL)), guiAlpha));
+ DrawRectangle(selector.x + GuiGetStyle(COMBOBOX, BORDER_WIDTH), selector.y + GuiGetStyle(COMBOBOX, BORDER_WIDTH), selector.width - 2*GuiGetStyle(COMBOBOX, BORDER_WIDTH), selector.height - 2*GuiGetStyle(COMBOBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(COMBOBOX, BASE_COLOR_NORMAL)), guiAlpha));
+
+ GuiDrawText(text[active], bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2 + VALIGN_OFFSET(bounds.height), Fade(GetColor(GuiGetStyle(COMBOBOX, TEXT_COLOR_NORMAL)), guiAlpha));
+ GuiDrawText(FormatText("%i/%i", active + 1, count), selector.x + selector.width/2 - GuiTextWidth(FormatText("%i/%i", active + 1, count))/2, selector.y + selector.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2 + VALIGN_OFFSET(bounds.height), Fade(GetColor(GuiGetStyle(COMBOBOX, TEXT_COLOR_NORMAL)), guiAlpha));
+ } break;
+ case GUI_STATE_FOCUSED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(COMBOBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(COMBOBOX, BORDER_COLOR_FOCUSED)), guiAlpha));
+ DrawRectangle(bounds.x + GuiGetStyle(COMBOBOX, BORDER_WIDTH), bounds.y + GuiGetStyle(COMBOBOX, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(COMBOBOX, BORDER_WIDTH), bounds.height - 2*GuiGetStyle(COMBOBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(COMBOBOX, BASE_COLOR_FOCUSED)), guiAlpha));
+
+ DrawRectangleLinesEx(selector, GuiGetStyle(COMBOBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(COMBOBOX, BORDER_COLOR_FOCUSED)), guiAlpha));
+ DrawRectangle(selector.x + GuiGetStyle(COMBOBOX, BORDER_WIDTH), selector.y + GuiGetStyle(COMBOBOX, BORDER_WIDTH), selector.width - 2*GuiGetStyle(COMBOBOX, BORDER_WIDTH), selector.height - 2*GuiGetStyle(COMBOBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(COMBOBOX, BASE_COLOR_FOCUSED)), guiAlpha));
+
+ GuiDrawText(text[active], bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2 + VALIGN_OFFSET(bounds.height), Fade(GetColor(GuiGetStyle(COMBOBOX, TEXT_COLOR_FOCUSED)), guiAlpha));
+ GuiDrawText(FormatText("%i/%i", active + 1, count), selector.x + selector.width/2 - GuiTextWidth(FormatText("%i/%i", active + 1, count))/2, selector.y + selector.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2 + VALIGN_OFFSET(bounds.height), Fade(GetColor(GuiGetStyle(COMBOBOX, TEXT_COLOR_FOCUSED)), guiAlpha));
+ } break;
+ case GUI_STATE_PRESSED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(COMBOBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(COMBOBOX, BORDER_COLOR_PRESSED)), guiAlpha));
+ DrawRectangle(bounds.x + GuiGetStyle(COMBOBOX, BORDER_WIDTH), bounds.y + GuiGetStyle(COMBOBOX, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(COMBOBOX, BORDER_WIDTH), bounds.height - 2*GuiGetStyle(COMBOBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(COMBOBOX, BASE_COLOR_PRESSED)), guiAlpha));
+
+ DrawRectangleLinesEx(selector, GuiGetStyle(COMBOBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(COMBOBOX, BORDER_COLOR_PRESSED)), guiAlpha));
+ DrawRectangle(selector.x + GuiGetStyle(COMBOBOX, BORDER_WIDTH), selector.y + GuiGetStyle(COMBOBOX, BORDER_WIDTH), selector.width - 2*GuiGetStyle(COMBOBOX, BORDER_WIDTH), selector.height - 2*GuiGetStyle(COMBOBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(COMBOBOX, BASE_COLOR_PRESSED)), guiAlpha));
+
+ GuiDrawText(text[active], bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2 + VALIGN_OFFSET(bounds.height), Fade(GetColor(GuiGetStyle(COMBOBOX, TEXT_COLOR_PRESSED)), guiAlpha));
+ GuiDrawText(FormatText("%i/%i", active + 1, count), selector.x + selector.width/2 - GuiTextWidth(FormatText("%i/%i", active + 1, count))/2, selector.y + selector.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2 + VALIGN_OFFSET(bounds.height), Fade(GetColor(GuiGetStyle(COMBOBOX, TEXT_COLOR_PRESSED)), guiAlpha));
+ } break;
+ case GUI_STATE_DISABLED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(COMBOBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(COMBOBOX, BORDER_COLOR_DISABLED)), guiAlpha));
+ DrawRectangle(bounds.x + GuiGetStyle(COMBOBOX, BORDER_WIDTH), bounds.y + GuiGetStyle(COMBOBOX, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(COMBOBOX, BORDER_WIDTH), bounds.height - 2*GuiGetStyle(COMBOBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(COMBOBOX, BASE_COLOR_DISABLED)), guiAlpha));
+
+ DrawRectangleLinesEx(selector, GuiGetStyle(COMBOBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(COMBOBOX, BORDER_COLOR_DISABLED)), guiAlpha));
+ DrawRectangle(selector.x + GuiGetStyle(COMBOBOX, BORDER_WIDTH), selector.y + GuiGetStyle(COMBOBOX, BORDER_WIDTH), selector.width - 2*GuiGetStyle(COMBOBOX, BORDER_WIDTH), selector.height - 2*GuiGetStyle(COMBOBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(COMBOBOX, BASE_COLOR_DISABLED)), guiAlpha));
+
+ GuiDrawText(text[active], bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2 + VALIGN_OFFSET(bounds.height), Fade(GetColor(GuiGetStyle(COMBOBOX, TEXT_COLOR_DISABLED)), guiAlpha));
+ GuiDrawText(FormatText("%i/%i", active + 1, count), selector.x + selector.width/2 - GuiTextWidth(FormatText("%i/%i", active + 1, count))/2, selector.y + selector.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2 + VALIGN_OFFSET(bounds.height), Fade(GetColor(GuiGetStyle(COMBOBOX, TEXT_COLOR_DISABLED)), guiAlpha));
+ } break;
+ default: break;
+ }
+ //--------------------------------------------------------------------
+
+ return active;
+}
+
+// Dropdown Box control, returns selected item
+RAYGUIDEF bool GuiDropdownBox(Rectangle bounds, const char **text, int count, int *active, bool editMode)
+{
+ GuiControlState state = guiState;
+ bool pressed = false;
+ int auxActive = *active;
+ int textWidth = GuiTextWidth(text[auxActive]);
+ int textHeight = GuiGetStyle(DEFAULT, TEXT_SIZE);
+
+ if (bounds.width < textWidth) bounds.width = textWidth;
+ if (bounds.height < textHeight) bounds.height = textHeight;
+
+ Rectangle closeBounds = bounds;
+ Rectangle openBounds = bounds;
+ openBounds.height *= (count + 1);
+
+ // Update control
+ //--------------------------------------------------------------------
+ if (guiLocked && editMode) guiLocked = false;
+
+ if ((state != GUI_STATE_DISABLED) && !guiLocked)
+ {
+ Vector2 mousePoint = GetMousePosition();
+
+ if (editMode) state = GUI_STATE_PRESSED;
+
+ if (!editMode)
+ {
+ if (CheckCollisionPointRec(mousePoint, closeBounds))
+ {
+ if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = GUI_STATE_PRESSED;
+
+ if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) pressed = true;
+ else state = GUI_STATE_FOCUSED;
+ }
+ }
+ else
+ {
+ if (CheckCollisionPointRec(mousePoint, closeBounds))
+ {
+ if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) pressed = true;
+ }
+ else if (!CheckCollisionPointRec(mousePoint, openBounds))
+ {
+ if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) || IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) pressed = true;
+ }
+ }
+ }
+ //--------------------------------------------------------------------
+
+ // Draw control
+ //--------------------------------------------------------------------
+ switch (state)
+ {
+ case GUI_STATE_NORMAL:
+ {
+ DrawRectangle(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(GuiGetStyle(DEFAULT, BASE_COLOR_NORMAL)), guiAlpha));
+ DrawRectangleLinesEx(bounds, GuiGetStyle(DROPDOWNBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(LISTVIEW, BORDER_COLOR_NORMAL)), guiAlpha));
+ GuiListElement((Rectangle){ bounds.x, bounds.y, bounds.width, bounds.height }, text[auxActive], false, false);
+
+ DrawTriangle((Vector2){ bounds.x + bounds.width - GuiGetStyle(DROPDOWNBOX, ARROW_RIGHT_PADDING), bounds.y + bounds.height/2 - 2 },
+ (Vector2){ bounds.x + bounds.width - GuiGetStyle(DROPDOWNBOX, ARROW_RIGHT_PADDING) + 5, bounds.y + bounds.height/2 - 2 + 5 },
+ (Vector2){ bounds.x + bounds.width - GuiGetStyle(DROPDOWNBOX, ARROW_RIGHT_PADDING) + 10, bounds.y + bounds.height/2 - 2 }, Fade(GetColor(GuiGetStyle(DEFAULT, TEXT_COLOR_NORMAL)), guiAlpha));
+ } break;
+ case GUI_STATE_FOCUSED:
+ {
+ GuiListElement((Rectangle){ bounds.x, bounds.y, bounds.width, bounds.height }, text[auxActive], false, editMode);
+
+ DrawTriangle((Vector2){ bounds.x + bounds.width - GuiGetStyle(DROPDOWNBOX, ARROW_RIGHT_PADDING), bounds.y + bounds.height/2 - 2 },
+ (Vector2){ bounds.x + bounds.width - GuiGetStyle(DROPDOWNBOX, ARROW_RIGHT_PADDING) + 5, bounds.y + bounds.height/2 - 2 + 5 },
+ (Vector2){ bounds.x + bounds.width - GuiGetStyle(DROPDOWNBOX, ARROW_RIGHT_PADDING) + 10, bounds.y + bounds.height/2 - 2 }, Fade(GetColor(GuiGetStyle(DEFAULT, TEXT_COLOR_FOCUSED)), guiAlpha));
+ } break;
+ case GUI_STATE_PRESSED:
+ {
+
+ if (!editMode) GuiListElement((Rectangle){ bounds.x, bounds.y, bounds.width, bounds.height }, text[auxActive], true, true);
+ if (editMode)
+ {
+ GuiPanel(openBounds);
+
+ GuiListElement((Rectangle){ bounds.x, bounds.y, bounds.width, bounds.height }, text[auxActive], true, true);
+
+ for (int i = 0; i < count; i++)
+ {
+ if (i == auxActive && editMode)
+ {
+ if (GuiListElement((Rectangle){ bounds.x, bounds.y + bounds.height*(i+1) + GuiGetStyle(DROPDOWNBOX, INNER_PADDING), bounds.width, bounds.height - GuiGetStyle(DROPDOWNBOX, INNER_PADDING) }, text[i], true, true) == false) pressed = true; //auxActive = i;
+ }
+ else
+ {
+ if (GuiListElement((Rectangle){ bounds.x, bounds.y + bounds.height*(i+1) + GuiGetStyle(DROPDOWNBOX, INNER_PADDING), bounds.width, bounds.height - GuiGetStyle(DROPDOWNBOX, INNER_PADDING) }, text[i], false, true))
+ {
+ auxActive = i;
+ pressed = true;
+ }
+ }
+ }
+ }
+
+ DrawTriangle((Vector2){ bounds.x + bounds.width - GuiGetStyle(DROPDOWNBOX, ARROW_RIGHT_PADDING), bounds.y + bounds.height/2 - 2 },
+ (Vector2){ bounds.x + bounds.width - GuiGetStyle(DROPDOWNBOX, ARROW_RIGHT_PADDING) + 5, bounds.y + bounds.height/2 - 2 + 5 },
+ (Vector2){ bounds.x + bounds.width - GuiGetStyle(DROPDOWNBOX, ARROW_RIGHT_PADDING) + 10, bounds.y + bounds.height/2 - 2 }, Fade(GetColor(GuiGetStyle(DEFAULT, TEXT_COLOR_PRESSED)), guiAlpha));
+ } break;
+ case GUI_STATE_DISABLED:
+ {
+ DrawRectangle(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(GuiGetStyle(DEFAULT, BASE_COLOR_DISABLED)), guiAlpha));
+ DrawRectangleLinesEx(bounds, GuiGetStyle(DROPDOWNBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(LISTVIEW, BORDER_COLOR_DISABLED)), guiAlpha));
+ GuiListElement((Rectangle){ bounds.x, bounds.y, bounds.width, bounds.height }, text[auxActive], false, false);
+
+ DrawTriangle((Vector2){ bounds.x + bounds.width - GuiGetStyle(DROPDOWNBOX, ARROW_RIGHT_PADDING), bounds.y + bounds.height/2 - 2 },
+ (Vector2){ bounds.x + bounds.width - GuiGetStyle(DROPDOWNBOX, ARROW_RIGHT_PADDING) + 5, bounds.y + bounds.height/2 - 2 + 5 },
+ (Vector2){ bounds.x + bounds.width - GuiGetStyle(DROPDOWNBOX, ARROW_RIGHT_PADDING) + 10, bounds.y + bounds.height/2 - 2 }, Fade(GetColor(GuiGetStyle(DEFAULT, TEXT_COLOR_DISABLED)), guiAlpha));
+ } break;
+ default: break;
+ }
+ //--------------------------------------------------------------------
+
+ *active = auxActive;
+ return pressed;
+}
+
+// Spinner control, returns selected value
+// NOTE: Requires static variables: framesCounter, valueSpeed - ERROR!
+RAYGUIDEF bool GuiSpinner(Rectangle bounds, int *value, int minValue, int maxValue, int btnWidth, bool editMode)
+{
+ bool pressed = false;
+ int tempValue = *value;
+ int tempBorderWidth = GuiGetStyle(BUTTON, BORDER_WIDTH);
+
+ Rectangle spinner = { bounds.x + btnWidth + GuiGetStyle(TEXTBOX, SPINNER_BUTTON_PADDING), bounds.y, bounds.width - 2*(btnWidth + GuiGetStyle(TEXTBOX, SPINNER_BUTTON_PADDING)), bounds.height };
+ Rectangle leftButtonBound = { bounds.x, bounds.y, btnWidth, bounds.height };
+ Rectangle rightButtonBound = { bounds.x + bounds.width - btnWidth, bounds.y, btnWidth, bounds.height };
+
+ int textWidth = GuiTextWidth(FormatText("%i", tempValue));
+ int textHeight = GuiGetStyle(DEFAULT, TEXT_SIZE);
+
+ if (bounds.width < textWidth) bounds.width = textWidth;
+ if (bounds.height < textHeight) bounds.height = textHeight;
+
+ // Update control
+ //--------------------------------------------------------------------
+ if (!editMode)
+ {
+ if (tempValue < minValue) tempValue = minValue;
+ if (tempValue > maxValue) tempValue = maxValue;
+ }
+ //--------------------------------------------------------------------
+
+ // Draw control
+ //--------------------------------------------------------------------
+ pressed = GuiValueBox(spinner, &tempValue, minValue, maxValue, editMode);
+
+ GuiSetStyle(BUTTON, BORDER_WIDTH, GuiGetStyle(TEXTBOX, SPINNER_BUTTON_BORDER_WIDTH));
+ if (GuiButton(leftButtonBound, "<")) tempValue--;
+ if (GuiButton(rightButtonBound, ">")) tempValue++;
+ GuiSetStyle(BUTTON, BORDER_WIDTH, tempBorderWidth);
+ //--------------------------------------------------------------------
+
+ *value = tempValue;
+ return pressed;
+}
+
+// Value Box control, updates input text with numbers
+// NOTE: Requires static variables: framesCounter
+RAYGUIDEF bool GuiValueBox(Rectangle bounds, int *value, int minValue, int maxValue, bool editMode)
+{
+ #define MAX_VALUE_CHARS 32
+
+ static int framesCounter = 0; // Required for blinking cursor
+
+ GuiControlState state = guiState;
+ bool pressed = false;
+
+ char text[MAX_VALUE_CHARS + 1] = "\0";
+ sprintf(text, "%i", *value);
+ int textWidth = GuiTextWidth(text);
+
+ // Update control
+ //--------------------------------------------------------------------
+ if ((state != GUI_STATE_DISABLED) && !guiLocked)
+ {
+ Vector2 mousePoint = GetMousePosition();
+
+ bool valueHasChanged = false;
+
+ if (editMode)
+ {
+ state = GUI_STATE_PRESSED;
+
+ framesCounter++;
+
+ int keyCount = strlen(text);
+
+ // Only allow keys in range [48..57]
+ if (keyCount < MAX_VALUE_CHARS)
+ {
+ int maxWidth = (bounds.width - (GuiGetStyle(DEFAULT, INNER_PADDING)*2));
+ if (GuiTextWidth(text) < maxWidth)
+ {
+ int key = GetKeyPressed();
+ if ((key >= 48) && (key <= 57))
+ {
+ text[keyCount] = (char)key;
+ keyCount++;
+ valueHasChanged = true;
+ }
+ }
+ }
+
+ // Delete text
+ if (keyCount > 0)
+ {
+ if (IsKeyPressed(KEY_BACKSPACE))
+ {
+ keyCount--;
+ text[keyCount] = '\0';
+ framesCounter = 0;
+ if (keyCount < 0) keyCount = 0;
+ valueHasChanged = true;
+ }
+ else if (IsKeyDown(KEY_BACKSPACE))
+ {
+ if ((framesCounter > LINE_BLINK_FRAMES) && (framesCounter%2) == 0) keyCount--;
+ text[keyCount] = '\0';
+ if (keyCount < 0) keyCount = 0;
+ valueHasChanged = true;
+ }
+ }
+
+ if (valueHasChanged) *value = atoi(text);
+ }
+ else
+ {
+ if (*value > maxValue) *value = maxValue;
+ else if (*value < minValue) *value = minValue;
+ }
+
+ if (!editMode)
+ {
+ if (CheckCollisionPointRec(mousePoint, bounds))
+ {
+ state = GUI_STATE_FOCUSED;
+ if (IsMouseButtonPressed(0)) pressed = true;
+ }
+ }
+ else
+ {
+ if (IsKeyPressed(KEY_ENTER) || (!CheckCollisionPointRec(mousePoint, bounds) && IsMouseButtonPressed(0))) pressed = true;
+ }
+
+ if (pressed) framesCounter = 0;
+ }
+ //--------------------------------------------------------------------
+
+ // Draw control
+ //--------------------------------------------------------------------
+ switch (state)
+ {
+ case GUI_STATE_NORMAL:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(TEXTBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TEXTBOX, BORDER_COLOR_NORMAL)), guiAlpha));
+ GuiDrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2 + VALIGN_OFFSET(bounds.height), Fade(GetColor(GuiGetStyle(TEXTBOX, TEXT_COLOR_NORMAL)), guiAlpha));
+ } break;
+ case GUI_STATE_FOCUSED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(TEXTBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TEXTBOX, BORDER_COLOR_FOCUSED)), guiAlpha));
+ GuiDrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2 + VALIGN_OFFSET(bounds.height), Fade(GetColor(GuiGetStyle(TEXTBOX, TEXT_COLOR_FOCUSED)), guiAlpha));
+ } break;
+ case GUI_STATE_PRESSED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(TEXTBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TEXTBOX, BORDER_COLOR_PRESSED)), guiAlpha));
+ DrawRectangle(bounds.x + GuiGetStyle(TEXTBOX, BORDER_WIDTH), bounds.y + GuiGetStyle(TEXTBOX, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(TEXTBOX, BORDER_WIDTH), bounds.height - 2*GuiGetStyle(TEXTBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TEXTBOX, BASE_COLOR_FOCUSED)), guiAlpha));
+ GuiDrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2 + VALIGN_OFFSET(bounds.height), Fade(GetColor(GuiGetStyle(TEXTBOX, TEXT_COLOR_PRESSED)), guiAlpha));
+
+ if (editMode && ((framesCounter/20)%2 == 0)) DrawRectangle(bounds.x + GuiTextWidth(text)/2 + bounds.width/2 + 2, bounds.y + GuiGetStyle(TEXTBOX, INNER_PADDING), 1, bounds.height - GuiGetStyle(TEXTBOX, INNER_PADDING)*2, Fade(GetColor(GuiGetStyle(TEXTBOX, BORDER_COLOR_FOCUSED)), guiAlpha));
+ } break;
+ case GUI_STATE_DISABLED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(TEXTBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TEXTBOX, BORDER_COLOR_DISABLED)), guiAlpha));
+ DrawRectangle(bounds.x + GuiGetStyle(TEXTBOX, BORDER_WIDTH), bounds.y + GuiGetStyle(TEXTBOX, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(TEXTBOX, BORDER_WIDTH), bounds.height - 2*GuiGetStyle(TEXTBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TEXTBOX, BASE_COLOR_DISABLED)), guiAlpha));
+ GuiDrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2 + VALIGN_OFFSET(bounds.height), Fade(GetColor(GuiGetStyle(TEXTBOX, TEXT_COLOR_DISABLED)), guiAlpha));
+ } break;
+ default: break;
+ }
+ //--------------------------------------------------------------------
+
+ return pressed;
+}
+
+// Text Box control, updates input text
+// NOTE 1: Requires static variables: framesCounter
+// NOTE 2: Returns if KEY_ENTER pressed (useful for data validation)
+RAYGUIDEF bool GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode)
+{
+ static int framesCounter = 0; // Required for blinking cursor
+
+ GuiControlState state = guiState;
+ bool pressed = false;
+
+ // Update control
+ //--------------------------------------------------------------------
+ if ((state != GUI_STATE_DISABLED) && !guiLocked)
+ {
+ Vector2 mousePoint = GetMousePosition();
+
+ if (editMode)
+ {
+ state = GUI_STATE_PRESSED;
+
+ framesCounter++;
+
+ int key = GetKeyPressed();
+ int keyCount = strlen(text);
+
+ // Only allow keys in range [32..125]
+ if (keyCount < (textSize - 1))
+ {
+ int maxWidth = (bounds.width - (GuiGetStyle(DEFAULT, INNER_PADDING)*2));
+ if (GuiTextWidth(text) < (maxWidth - GuiGetStyle(DEFAULT, TEXT_SIZE)))
+ {
+ if ((key >= 32) && (key <= 125))
+ {
+ text[keyCount] = (char)key;
+ keyCount++;
+ }
+ }
+ }
+
+ // Delete text
+ if (keyCount > 0)
+ {
+ if (IsKeyPressed(KEY_BACKSPACE))
+ {
+ keyCount--;
+ text[keyCount] = '\0';
+ framesCounter = 0;
+ if (keyCount < 0) keyCount = 0;
+ }
+ else if (IsKeyDown(KEY_BACKSPACE))
+ {
+ if ((framesCounter > LINE_BLINK_FRAMES) && (framesCounter%2) == 0) keyCount--;
+ text[keyCount] = '\0';
+ if (keyCount < 0) keyCount = 0;
+ }
+ }
+ }
+
+ if (!editMode)
+ {
+ if (CheckCollisionPointRec(mousePoint, bounds))
+ {
+ state = GUI_STATE_FOCUSED;
+ if (IsMouseButtonPressed(0)) pressed = true;
+ }
+ }
+ else
+ {
+ if (IsKeyPressed(KEY_ENTER) || (!CheckCollisionPointRec(mousePoint, bounds) && IsMouseButtonPressed(0))) pressed = true;
+ }
+
+ if (pressed) framesCounter = 0;
+ }
+ //--------------------------------------------------------------------
+
+ // Draw control
+ //--------------------------------------------------------------------
+ switch (state)
+ {
+ case GUI_STATE_NORMAL:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(TEXTBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TEXTBOX, BORDER_COLOR_NORMAL)), guiAlpha));
+ GuiDrawText(text, bounds.x + GuiGetStyle(TEXTBOX, INNER_PADDING), bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2, Fade(GetColor(GuiGetStyle(TEXTBOX, TEXT_COLOR_NORMAL)), guiAlpha));
+ } break;
+ case GUI_STATE_FOCUSED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(TEXTBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TEXTBOX, BORDER_COLOR_FOCUSED)), guiAlpha));
+ GuiDrawText(text, bounds.x + GuiGetStyle(TEXTBOX, INNER_PADDING), bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2, Fade(GetColor(GuiGetStyle(TEXTBOX, TEXT_COLOR_FOCUSED)), guiAlpha));
+ } break;
+ case GUI_STATE_PRESSED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(TEXTBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TEXTBOX, BORDER_COLOR_PRESSED)), guiAlpha));
+ DrawRectangle(bounds.x + GuiGetStyle(TEXTBOX, BORDER_WIDTH), bounds.y + GuiGetStyle(TEXTBOX, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(TEXTBOX, BORDER_WIDTH), bounds.height - 2*GuiGetStyle(TEXTBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TEXTBOX, BASE_COLOR_FOCUSED)), guiAlpha));
+ GuiDrawText(text, bounds.x + GuiGetStyle(TEXTBOX, INNER_PADDING), bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2, Fade(GetColor(GuiGetStyle(TEXTBOX, TEXT_COLOR_PRESSED)), guiAlpha));
+
+ if (editMode && ((framesCounter/20)%2 == 0)) DrawRectangle(bounds.x + GuiGetStyle(TEXTBOX, INNER_PADDING) + GuiTextWidth(text) + 2, bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE), 1, GuiGetStyle(DEFAULT, TEXT_SIZE)*2, Fade(GetColor(GuiGetStyle(TEXTBOX, BORDER_COLOR_PRESSED)), guiAlpha));
+ } break;
+ case GUI_STATE_DISABLED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(TEXTBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TEXTBOX, BORDER_COLOR_DISABLED)), guiAlpha));
+ DrawRectangle(bounds.x + GuiGetStyle(TEXTBOX, BORDER_WIDTH), bounds.y + GuiGetStyle(TEXTBOX, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(TEXTBOX, BORDER_WIDTH), bounds.height - 2*GuiGetStyle(TEXTBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TEXTBOX, BASE_COLOR_DISABLED)), guiAlpha));
+ GuiDrawText(text, bounds.x + GuiGetStyle(TEXTBOX, INNER_PADDING), bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2, Fade(GetColor(GuiGetStyle(TEXTBOX, TEXT_COLOR_DISABLED)), guiAlpha));
+ } break;
+ default: break;
+ }
+ //--------------------------------------------------------------------
+
+ return pressed;
+}
+
+// Text Box control with multiple lines
+RAYGUIDEF bool GuiTextBoxMulti(Rectangle bounds, char *text, int textSize, bool editMode)
+{
+ static int framesCounter = 0; // Required for blinking cursor
+
+ GuiControlState state = guiState;
+ bool pressed = false;
+
+ bool textHasChange = false;
+ int currentLine = 0;
+ const char *numChars = "";
+
+ // Security check because font is used directly in this control
+ if (guiFont.texture.id == 0) guiFont = GetFontDefault();
+
+ // Update control
+ //--------------------------------------------------------------------
+ if ((state != GUI_STATE_DISABLED) && !guiLocked)
+ {
+ Vector2 mousePoint = GetMousePosition();
+
+ if (editMode)
+ {
+ state = GUI_STATE_PRESSED;
+
+ framesCounter++;
+
+ int keyCount = strlen(text);
+ int maxWidth = (bounds.width - (GuiGetStyle(TEXTBOX, INNER_PADDING)*2));
+ int maxHeight = (bounds.height - (GuiGetStyle(TEXTBOX, INNER_PADDING)*2));
+
+ numChars = FormatText("%i/%i", keyCount, textSize - 1);
+
+ // Only allow keys in range [32..125]
+ if (keyCount < (textSize - 1))
+ {
+ int key = GetKeyPressed();
+
+ if (MeasureTextEx(guiFont, text, GuiGetStyle(DEFAULT, TEXT_SIZE), 1).y < (maxHeight - GuiGetStyle(DEFAULT, TEXT_SIZE)))
+ {
+ if (IsKeyPressed(KEY_ENTER))
+ {
+ text[keyCount] = '\n';
+ keyCount++;
+ }
+ else if ((key >= 32) && (key <= 125))
+ {
+ text[keyCount] = (char)key;
+ keyCount++;
+ textHasChange = true;
+ }
+ }
+ else if (GuiTextWidth(strrchr(text, '\n')) < (maxWidth - GuiGetStyle(DEFAULT, TEXT_SIZE)))
+ {
+ if ((key >= 32) && (key <= 125))
+ {
+ text[keyCount] = (char)key;
+ keyCount++;
+ textHasChange = true;
+ }
+ }
+ }
+
+ // Delete text
+ if (keyCount > 0)
+ {
+ if (IsKeyPressed(KEY_BACKSPACE))
+ {
+ keyCount--;
+ text[keyCount] = '\0';
+ framesCounter = 0;
+ if (keyCount < 0) keyCount = 0;
+ textHasChange = true;
+ }
+ else if (IsKeyDown(KEY_BACKSPACE))
+ {
+ if ((framesCounter > LINE_BLINK_FRAMES) && (framesCounter%2) == 0) keyCount--;
+ text[keyCount] = '\0';
+ if (keyCount < 0) keyCount = 0;
+ textHasChange = true;
+ }
+ }
+
+ // Introduce automatic new line if necessary
+ if (textHasChange)
+ {
+ textHasChange = false;
+
+ char *lastLine = strrchr(text, '\n');
+ int maxWidth = (bounds.width - (GuiGetStyle(TEXTBOX, INNER_PADDING)*2));
+
+ if (lastLine != NULL)
+ {
+ if (GuiTextWidth(lastLine) > maxWidth)
+ {
+ int firstIndex = lastLine - text;
+
+ char *lastSpace = strrchr(lastLine, 32);
+
+ if (lastSpace != NULL)
+ {
+ int secondIndex = lastSpace - lastLine;
+ text[firstIndex + secondIndex] = '\n';
+ }
+ else
+ {
+ int len = (lastLine != NULL) ? strlen(lastLine) : 0;
+ char lastChar = lastLine[len - 1];
+ lastLine[len - 1] = '\n';
+ lastLine[len] = lastChar;
+ lastLine[len + 1] = '\0';
+ keyCount++;
+ }
+ }
+ }
+ else
+ {
+ if (GuiTextWidth(text) > maxWidth)
+ {
+ char *lastSpace = strrchr(text, 32);
+
+ if (lastSpace != NULL)
+ {
+ int index = lastSpace - text;
+ text[index] = '\n';
+ }
+ else
+ {
+ int len = (lastLine != NULL) ? strlen(lastLine) : 0;
+ char lastChar = lastLine[len - 1];
+ lastLine[len - 1] = '\n';
+ lastLine[len] = lastChar;
+ lastLine[len + 1] = '\0';
+ keyCount++;
+ }
+ }
+ }
+ }
+
+ // Counting how many new lines
+ for (int i = 0; i < keyCount; i++)
+ {
+ if (text[i] == '\n') currentLine++;
+ }
+ }
+
+ // Changing edit mode
+ if (!editMode)
+ {
+ if (CheckCollisionPointRec(mousePoint, bounds))
+ {
+ state = GUI_STATE_FOCUSED;
+ if (IsMouseButtonPressed(0)) pressed = true;
+ }
+ }
+ else
+ {
+ if (!CheckCollisionPointRec(mousePoint, bounds) && IsMouseButtonPressed(0)) pressed = true;
+ }
+
+ if (pressed) framesCounter = 0;
+ }
+ //--------------------------------------------------------------------
+
+ // Draw control
+ //--------------------------------------------------------------------
+ switch (state)
+ {
+ case GUI_STATE_NORMAL:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(TEXTBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TEXTBOX, BORDER_COLOR_NORMAL)), guiAlpha));
+ GuiDrawText(text, bounds.x + GuiGetStyle(TEXTBOX, INNER_PADDING), bounds.y + GuiGetStyle(TEXTBOX, INNER_PADDING), Fade(GetColor(GuiGetStyle(TEXTBOX, TEXT_COLOR_NORMAL)), guiAlpha));
+ } break;
+ case GUI_STATE_FOCUSED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(TEXTBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TEXTBOX, BORDER_COLOR_FOCUSED)), guiAlpha));
+ GuiDrawText(text, bounds.x + GuiGetStyle(TEXTBOX, INNER_PADDING), bounds.y + GuiGetStyle(TEXTBOX, INNER_PADDING), Fade(GetColor(GuiGetStyle(TEXTBOX, TEXT_COLOR_FOCUSED)), guiAlpha));
+ } break;
+ case GUI_STATE_PRESSED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(TEXTBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TEXTBOX, BORDER_COLOR_PRESSED)), guiAlpha));
+ DrawRectangle(bounds.x + GuiGetStyle(TEXTBOX, BORDER_WIDTH), bounds.y + GuiGetStyle(TEXTBOX, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(TEXTBOX, BORDER_WIDTH), bounds.height - 2*GuiGetStyle(TEXTBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TEXTBOX, BASE_COLOR_FOCUSED)), guiAlpha));
+ GuiDrawText(text, bounds.x + GuiGetStyle(TEXTBOX, INNER_PADDING), bounds.y + GuiGetStyle(TEXTBOX, INNER_PADDING), Fade(GetColor(GuiGetStyle(TEXTBOX, TEXT_COLOR_PRESSED)), guiAlpha));
+
+ if (editMode)
+ {
+ if ((framesCounter/20)%2 == 0)
+ {
+ char *line = NULL;
+ if (currentLine > 0) line = strrchr(text, '\n');
+ else line = text;
+
+ DrawRectangle(bounds.x + GuiGetStyle(TEXTBOX, BORDER_WIDTH) + GuiGetStyle(TEXTBOX, INNER_PADDING) + GuiTextWidth(line), bounds.y + GuiGetStyle(TEXTBOX, BORDER_WIDTH) + GuiGetStyle(TEXTBOX, INNER_PADDING)/2 + ((GuiGetStyle(DEFAULT, TEXT_SIZE) + GuiGetStyle(TEXTBOX, INNER_PADDING))*currentLine), 1, GuiGetStyle(DEFAULT, TEXT_SIZE) + GuiGetStyle(TEXTBOX, INNER_PADDING), Fade(GetColor(GuiGetStyle(TEXTBOX, BORDER_COLOR_FOCUSED)), guiAlpha));
+ }
+
+ GuiDrawText(numChars, bounds.x + bounds.width - GuiTextWidth(numChars) - GuiGetStyle(TEXTBOX, INNER_PADDING), bounds.y + bounds.height - GuiGetStyle(DEFAULT, TEXT_SIZE) - GuiGetStyle(TEXTBOX, INNER_PADDING), Fade(GetColor(GuiGetStyle(TEXTBOX, TEXT_COLOR_PRESSED)), guiAlpha/2));
+ }
+
+ } break;
+ case GUI_STATE_DISABLED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(TEXTBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TEXTBOX, BORDER_COLOR_DISABLED)), guiAlpha));
+ DrawRectangle(bounds.x + GuiGetStyle(TEXTBOX, BORDER_WIDTH), bounds.y + GuiGetStyle(TEXTBOX, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(TEXTBOX, BORDER_WIDTH), bounds.height - 2*GuiGetStyle(TEXTBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TEXTBOX, BASE_COLOR_DISABLED)), guiAlpha));
+ GuiDrawText(text, bounds.x + GuiGetStyle(TEXTBOX, INNER_PADDING), bounds.y + GuiGetStyle(TEXTBOX, INNER_PADDING), Fade(GetColor(GuiGetStyle(TEXTBOX, TEXT_COLOR_DISABLED)), guiAlpha));
+ } break;
+ default: break;
+ }
+ //--------------------------------------------------------------------
+
+ return pressed;
+}
+
+// Slider control with pro parameters
+// NOTE: Other GuiSlider*() controls use this one
+RAYGUIDEF float GuiSliderPro(Rectangle bounds, float value, float minValue, float maxValue, int sliderWidth, const char *text, bool showValue)
+{
+ GuiControlState state = guiState;
+
+ int textWidth = (text == NULL) ? 0: GuiTextWidth(text);
+ int sliderValue = (int)(((value - minValue)/(maxValue - minValue))*(bounds.width - 2*GuiGetStyle(SLIDER, BORDER_WIDTH)));
+
+ Rectangle slider = { bounds.x, bounds.y + GuiGetStyle(SLIDER, BORDER_WIDTH) + GuiGetStyle(SLIDER, INNER_PADDING),
+ 0, bounds.height - 2*GuiGetStyle(SLIDER, BORDER_WIDTH) - 2*GuiGetStyle(SLIDER, INNER_PADDING) };
+
+ if (sliderWidth > 0) // Slider
+ {
+ slider.x += (sliderValue - sliderWidth/2);
+ slider.width = sliderWidth;
+ }
+ else if (sliderWidth == 0) // SliderBar
+ {
+ slider.x += GuiGetStyle(SLIDER, BORDER_WIDTH);
+ slider.width = sliderValue;
+ }
+
+ // Update control
+ //--------------------------------------------------------------------
+ if ((state != GUI_STATE_DISABLED) && !guiLocked)
+ {
+ Vector2 mousePoint = GetMousePosition();
+
+ if (CheckCollisionPointRec(mousePoint, bounds))
+ {
+ if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
+ {
+ state = GUI_STATE_PRESSED;
+
+ // Get equivalent value and slider position from mousePoint.x
+ value = ((maxValue - minValue)*(mousePoint.x - (float)(bounds.x + sliderWidth/2)))/(float)(bounds.width - sliderWidth) + minValue;
+
+ if (sliderWidth > 0) slider.x = mousePoint.x - slider.width/2; // Slider
+ else if (sliderWidth == 0) slider.width = sliderValue; // SliderBar
+ }
+ else state = GUI_STATE_FOCUSED;
+ }
+
+ if (value > maxValue) value = maxValue;
+ else if (value < minValue) value = minValue;
+
+ // Bar limits check
+ if (sliderWidth > 0) // Slider
+ {
+ if (slider.x <= (bounds.x + GuiGetStyle(SLIDER, BORDER_WIDTH))) slider.x = bounds.x + GuiGetStyle(SLIDER, BORDER_WIDTH);
+ else if ((slider.x + slider.width) >= (bounds.x + bounds.width)) slider.x = bounds.x + bounds.width - slider.width - GuiGetStyle(SLIDER, BORDER_WIDTH);
+ }
+ else if (sliderWidth == 0) // SliderBar
+ {
+ if (slider.width > bounds.width) slider.width = bounds.width - 2*GuiGetStyle(SLIDER, BORDER_WIDTH);
+ }
+ }
+ //--------------------------------------------------------------------
+
+ // Draw control
+ //--------------------------------------------------------------------
+ switch (state)
+ {
+ case GUI_STATE_NORMAL:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(SLIDER, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(SLIDER, BORDER_COLOR_NORMAL)), guiAlpha));
+ DrawRectangle(bounds.x + GuiGetStyle(SLIDER, BORDER_WIDTH), bounds.y + GuiGetStyle(SLIDER, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(SLIDER, BORDER_WIDTH), bounds.height - 2*GuiGetStyle(SLIDER, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(SLIDER, BASE_COLOR_NORMAL)), guiAlpha));
+ DrawRectangleRec(slider, Fade(GetColor(GuiGetStyle(SLIDER, BASE_COLOR_PRESSED)), guiAlpha));
+ if (text != NULL) GuiDrawText(text, bounds.x - GuiGetStyle(SLIDER, EX_TEXT_PADDING) - textWidth, bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2 + GuiGetStyle(SLIDER, INNER_PADDING), Fade(GetColor(GuiGetStyle(DEFAULT, TEXT_COLOR_NORMAL)), guiAlpha));
+ if (showValue) GuiDrawText(FormatText("%.02f", value), bounds.x + bounds.width + GuiGetStyle(SLIDER, EX_TEXT_PADDING), bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2 + GuiGetStyle(SLIDER, INNER_PADDING), Fade(GetColor(GuiGetStyle(DEFAULT, TEXT_COLOR_NORMAL)), guiAlpha));
+ } break;
+ case GUI_STATE_FOCUSED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(SLIDER, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(SLIDER, BORDER_COLOR_FOCUSED)), guiAlpha));
+ DrawRectangle(bounds.x + GuiGetStyle(SLIDER, BORDER_WIDTH), bounds.y + GuiGetStyle(SLIDER, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(SLIDER, BORDER_WIDTH), bounds.height - 2*GuiGetStyle(SLIDER, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(SLIDER, BASE_COLOR_NORMAL)), guiAlpha));
+ DrawRectangleRec(slider, Fade(GetColor(GuiGetStyle(SLIDER, BASE_COLOR_FOCUSED)), guiAlpha));
+ if (text != NULL) GuiDrawText(text, bounds.x - GuiGetStyle(SLIDER, EX_TEXT_PADDING) - textWidth, bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2 + GuiGetStyle(SLIDER, INNER_PADDING), Fade(GetColor(GuiGetStyle(DEFAULT, TEXT_COLOR_FOCUSED)), guiAlpha));
+ if (showValue) GuiDrawText(FormatText("%.02f", value), bounds.x + bounds.width + GuiGetStyle(SLIDER, EX_TEXT_PADDING), bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2 + GuiGetStyle(SLIDER, INNER_PADDING), Fade(GetColor(GuiGetStyle(DEFAULT, TEXT_COLOR_FOCUSED)), guiAlpha));
+ } break;
+ case GUI_STATE_PRESSED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(SLIDER, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(SLIDER, BORDER_COLOR_PRESSED)), guiAlpha));
+ DrawRectangle(bounds.x + GuiGetStyle(SLIDER, BORDER_WIDTH), bounds.y + GuiGetStyle(SLIDER, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(SLIDER, BORDER_WIDTH), bounds.height - 2*GuiGetStyle(SLIDER, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(SLIDER, BASE_COLOR_NORMAL)), guiAlpha));
+ DrawRectangleRec(slider, Fade(GetColor(GuiGetStyle(SLIDER, BASE_COLOR_PRESSED)), guiAlpha));
+ if (text != NULL) GuiDrawText(text, bounds.x - GuiGetStyle(SLIDER, EX_TEXT_PADDING) - textWidth, bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2 + GuiGetStyle(SLIDER, INNER_PADDING), Fade(GetColor(GuiGetStyle(DEFAULT, TEXT_COLOR_PRESSED)), guiAlpha));
+ if (showValue) GuiDrawText(FormatText("%.02f", value), bounds.x + bounds.width + GuiGetStyle(SLIDER, EX_TEXT_PADDING), bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2 + GuiGetStyle(SLIDER, INNER_PADDING), Fade(GetColor(GuiGetStyle(DEFAULT, TEXT_COLOR_PRESSED)), guiAlpha));
+ } break;
+ case GUI_STATE_DISABLED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(SLIDER, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(SLIDER, BORDER_COLOR_DISABLED)), guiAlpha));
+ DrawRectangle(bounds.x + GuiGetStyle(SLIDER, BORDER_WIDTH), bounds.y + GuiGetStyle(SLIDER, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(SLIDER, BORDER_WIDTH), bounds.height - 2*GuiGetStyle(SLIDER, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(SLIDER, BASE_COLOR_DISABLED)), guiAlpha));
+ DrawRectangleRec(slider, Fade(GetColor(GuiGetStyle(DEFAULT, TEXT_COLOR_DISABLED)), guiAlpha));
+ if (text != NULL) GuiDrawText(text, bounds.x - GuiGetStyle(SLIDER, EX_TEXT_PADDING) - textWidth, bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2 + GuiGetStyle(SLIDER, INNER_PADDING), Fade(GetColor(GuiGetStyle(DEFAULT, TEXT_COLOR_DISABLED)), guiAlpha));
+ if (showValue) GuiDrawText(FormatText("%.02f", value), bounds.x + bounds.width + GuiGetStyle(SLIDER, EX_TEXT_PADDING), bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2 + GuiGetStyle(SLIDER, INNER_PADDING), Fade(GetColor(GuiGetStyle(DEFAULT, TEXT_COLOR_DISABLED)), guiAlpha));
+ } break;
+ default: break;
+ }
+ //--------------------------------------------------------------------
+
+ return value;
+}
+
+// Slider control, returns selected value
+RAYGUIDEF float GuiSlider(Rectangle bounds, float value, float minValue, float maxValue)
+{
+ return GuiSliderPro(bounds, value, minValue, maxValue, GuiGetStyle(SLIDER, SLIDER_WIDTH), NULL, false);
+}
+
+// Slider control extended, returns selected value and has text
+RAYGUIDEF float GuiSliderEx(Rectangle bounds, float value, float minValue, float maxValue, const char *text, bool showValue)
+{
+ return GuiSliderPro(bounds, value, minValue, maxValue, GuiGetStyle(SLIDER, SLIDER_WIDTH), text, showValue);
+}
+
+// Slider Bar control, returns selected value
+RAYGUIDEF float GuiSliderBar(Rectangle bounds, float value, float minValue, float maxValue)
+{
+ return GuiSliderPro(bounds, value, minValue, maxValue, 0, NULL, false);
+}
+
+// Slider Bar control extended, returns selected value
+RAYGUIDEF float GuiSliderBarEx(Rectangle bounds, float value, float minValue, float maxValue, const char *text, bool showValue)
+{
+ return GuiSliderPro(bounds, value, minValue, maxValue, 0, text, showValue);
+}
+
+// Progress Bar control, shows current progress value
+RAYGUIDEF float GuiProgressBar(Rectangle bounds, float value, float minValue, float maxValue)
+{
+ return GuiProgressBarEx(bounds, value, minValue, maxValue, false);
+}
+
+// Progress Bar control extended, shows current progress value
+RAYGUIDEF float GuiProgressBarEx(Rectangle bounds, float value, float minValue, float maxValue, bool showValue)
+{
+ GuiControlState state = guiState;
+
+ Rectangle progress = { bounds.x + GuiGetStyle(PROGRESSBAR, BORDER_WIDTH),
+ bounds.y + GuiGetStyle(PROGRESSBAR, BORDER_WIDTH) + GuiGetStyle(PROGRESSBAR, INNER_PADDING), 0,
+ bounds.height - 2*GuiGetStyle(PROGRESSBAR, BORDER_WIDTH) - 2*GuiGetStyle(PROGRESSBAR, INNER_PADDING) };
+
+ // Update control
+ //--------------------------------------------------------------------
+ if (state != GUI_STATE_DISABLED) progress.width = (int)(value/(maxValue - minValue)*(float)(bounds.width - 2*GuiGetStyle(PROGRESSBAR, BORDER_WIDTH)));
+ //--------------------------------------------------------------------
+
+ // Draw control
+ //--------------------------------------------------------------------
+ if (showValue) GuiLabel((Rectangle){ bounds.x + bounds.width + GuiGetStyle(SLIDER, EX_TEXT_PADDING), bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2 + GuiGetStyle(SLIDER, INNER_PADDING), GuiGetStyle(DEFAULT, TEXT_SIZE), GuiGetStyle(DEFAULT, TEXT_SIZE) }, FormatText("%.02f", value));
+
+ switch (state)
+ {
+ case GUI_STATE_NORMAL:
+ case GUI_STATE_FOCUSED:
+ case GUI_STATE_PRESSED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(PROGRESSBAR, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(PROGRESSBAR, BORDER_COLOR_NORMAL)), guiAlpha));
+ DrawRectangle(bounds.x + GuiGetStyle(PROGRESSBAR, BORDER_WIDTH), bounds.y + GuiGetStyle(PROGRESSBAR, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(PROGRESSBAR, BORDER_WIDTH), bounds.height - 2*GuiGetStyle(PROGRESSBAR, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR)), guiAlpha));
+ DrawRectangleRec(progress, Fade(GetColor(GuiGetStyle(PROGRESSBAR, BASE_COLOR_NORMAL)), guiAlpha));
+ } break;
+ case GUI_STATE_DISABLED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(PROGRESSBAR, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(PROGRESSBAR, BORDER_COLOR_DISABLED)), guiAlpha));
+ DrawRectangle(bounds.x + GuiGetStyle(PROGRESSBAR, BORDER_WIDTH), bounds.y + GuiGetStyle(PROGRESSBAR, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(PROGRESSBAR, BORDER_WIDTH), bounds.height - 2*GuiGetStyle(PROGRESSBAR, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR)), guiAlpha));
+ DrawRectangleRec(progress, Fade(GetColor(GuiGetStyle(PROGRESSBAR, BASE_COLOR_DISABLED)), guiAlpha));
+ } break;
+ default: break;
+ }
+ //--------------------------------------------------------------------
+
+ return value;
+}
+
+// Status Bar control
+RAYGUIDEF void GuiStatusBar(Rectangle bounds, const char *text, int offsetX)
+{
+ GuiControlState state = guiState;
+
+ int textWidth = GuiTextWidth(text);
+ int textHeight = GuiGetStyle(DEFAULT, TEXT_SIZE);
+
+ if (bounds.width < textWidth + offsetX) bounds.width = textWidth + offsetX;
+ if (bounds.height < textHeight) bounds.height = textHeight;
+
+ // Draw control
+ //--------------------------------------------------------------------
+ switch (state)
+ {
+ case GUI_STATE_NORMAL:
+ case GUI_STATE_FOCUSED:
+ case GUI_STATE_PRESSED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(DEFAULT, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(DEFAULT, BORDER_COLOR_NORMAL)), guiAlpha));
+ DrawRectangleRec((Rectangle){ bounds.x + GuiGetStyle(DEFAULT, BORDER_WIDTH), bounds.y + GuiGetStyle(DEFAULT, BORDER_WIDTH), bounds.width - GuiGetStyle(DEFAULT, BORDER_WIDTH)*2, bounds.height - GuiGetStyle(DEFAULT, BORDER_WIDTH)*2 }, Fade(GetColor(GuiGetStyle(DEFAULT, BASE_COLOR_NORMAL)), guiAlpha));
+ GuiDrawText(text, bounds.x + offsetX, bounds.y + bounds.height/2 - textHeight/2, Fade(GetColor(GuiGetStyle(DEFAULT, TEXT_COLOR_NORMAL)), guiAlpha));
+ } break;
+ case GUI_STATE_DISABLED:
+ {
+ DrawRectangleLinesEx(bounds, GuiGetStyle(DEFAULT, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(DEFAULT, BORDER_COLOR_DISABLED)), guiAlpha));
+ DrawRectangleRec((Rectangle){ bounds.x + GuiGetStyle(DEFAULT, BORDER_WIDTH), bounds.y + GuiGetStyle(DEFAULT, BORDER_WIDTH), bounds.width - GuiGetStyle(DEFAULT, BORDER_WIDTH)*2, bounds.height - GuiGetStyle(DEFAULT, BORDER_WIDTH)*2 }, Fade(GetColor(GuiGetStyle(DEFAULT, BASE_COLOR_DISABLED)), guiAlpha));
+ GuiDrawText(text, bounds.x + offsetX, bounds.y + bounds.height/2 - textHeight/2, Fade(GetColor(GuiGetStyle(DEFAULT, TEXT_COLOR_DISABLED)), guiAlpha));
+ } break;
+ default: break;
+ }
+ //--------------------------------------------------------------------
+}
+
+// Dummy rectangle control, intended for placeholding
+RAYGUIDEF void GuiDummyRec(Rectangle bounds, const char *text)
+{
+ GuiControlState state = guiState;
+
+ int textWidth = GuiTextWidth(text);
+ int textHeight = GuiGetStyle(DEFAULT, TEXT_SIZE);
+
+ if (bounds.width < textWidth) bounds.width = textWidth;
+ if (bounds.height < textHeight) bounds.height = textHeight;
+
+ // Update control
+ //--------------------------------------------------------------------
+ if ((state != GUI_STATE_DISABLED) && !guiLocked)
+ {
+ Vector2 mousePoint = GetMousePosition();
+
+ // Check button state
+ if (CheckCollisionPointRec(mousePoint, bounds))
+ {
+ if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = GUI_STATE_PRESSED;
+ else state = GUI_STATE_FOCUSED;
+ }
+ }
+ //--------------------------------------------------------------------
+
+ // Draw control
+ //--------------------------------------------------------------------
+ switch (state)
+ {
+ case GUI_STATE_NORMAL:
+ case GUI_STATE_FOCUSED:
+ case GUI_STATE_PRESSED:
+ {
+ DrawRectangleRec(bounds, Fade(GetColor(GuiGetStyle(DEFAULT, BASE_COLOR_NORMAL)), guiAlpha));
+ GuiDrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, Fade(GetColor(GuiGetStyle(BUTTON, TEXT_COLOR_NORMAL)), guiAlpha));
+
+ } break;
+ case GUI_STATE_DISABLED:
+ {
+ DrawRectangleRec(bounds, Fade(GetColor(GuiGetStyle(DEFAULT, BASE_COLOR_DISABLED)), guiAlpha));
+ GuiDrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, Fade(GetColor(GuiGetStyle(BUTTON, TEXT_COLOR_DISABLED)), guiAlpha));
+ } break;
+ default: break;
+ }
+ //------------------------------------------------------------------
+}
+
+// List Element control, returns element state
+static bool GuiListElement(Rectangle bounds, const char *text, bool active, bool editMode)
+{
+ GuiControlState state = guiState;
+
+ int textWidth = GuiTextWidth(text);
+ int textHeight = GuiGetStyle(DEFAULT, TEXT_SIZE);
+
+ if (!guiLocked && editMode) state = GUI_STATE_NORMAL;
+
+ // Update control
+ //--------------------------------------------------------------------
+ if ((state != GUI_STATE_DISABLED) && !guiLocked)
+ {
+ if (bounds.width < textWidth)
+ {
+ // TODO: Remove/edit character if they dont fit inside bounds
+ }
+
+ Vector2 mousePoint = GetMousePosition();
+
+ if (CheckCollisionPointRec(mousePoint, bounds))
+ {
+ if (!active)
+ {
+ if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = GUI_STATE_PRESSED;
+ else state = GUI_STATE_FOCUSED;
+ }
+
+ if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) active = !active;
+ }
+ }
+ //--------------------------------------------------------------------
+
+ // Draw control
+ //--------------------------------------------------------------------
+ switch (state)
+ {
+ case GUI_STATE_NORMAL:
+ {
+ if (active)
+ {
+ DrawRectangle(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(GuiGetStyle(LISTVIEW, BASE_COLOR_PRESSED)), guiAlpha));
+ DrawRectangleLinesEx(bounds, GuiGetStyle(DEFAULT, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(LISTVIEW, BORDER_COLOR_PRESSED)), guiAlpha));
+ GuiDrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, Fade(GetColor(GuiGetStyle(LISTVIEW, TEXT_COLOR_PRESSED)), guiAlpha));
+ }
+ else
+ {
+ GuiDrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, Fade(GetColor(GuiGetStyle(LISTVIEW, TEXT_COLOR_NORMAL)), guiAlpha));
+ }
+ } break;
+ case GUI_STATE_FOCUSED:
+ {
+ DrawRectangle(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(GuiGetStyle(LISTVIEW, BASE_COLOR_FOCUSED)), guiAlpha));
+ DrawRectangleLinesEx(bounds, GuiGetStyle(DEFAULT, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(LISTVIEW, BORDER_COLOR_FOCUSED)), guiAlpha));
+ GuiDrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, Fade(GetColor(GuiGetStyle(LISTVIEW, TEXT_COLOR_FOCUSED)), guiAlpha));
+ } break;
+ case GUI_STATE_PRESSED:
+ {
+ DrawRectangle(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(GuiGetStyle(LISTVIEW, BASE_COLOR_PRESSED)), guiAlpha));
+ DrawRectangleLinesEx(bounds, GuiGetStyle(DEFAULT, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(LISTVIEW, BORDER_COLOR_PRESSED)), guiAlpha));
+ GuiDrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, Fade(GetColor(GuiGetStyle(LISTVIEW, TEXT_COLOR_PRESSED)), guiAlpha));
+ } break;
+ case GUI_STATE_DISABLED:
+ {
+ if (active)
+ {
+ DrawRectangle(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(GuiGetStyle(LISTVIEW, BASE_COLOR_DISABLED)), guiAlpha));
+ DrawRectangleLinesEx(bounds, GuiGetStyle(DEFAULT, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(LISTVIEW, BORDER_COLOR_NORMAL)), guiAlpha));
+ GuiDrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, Fade(GetColor(GuiGetStyle(LISTVIEW, TEXT_COLOR_NORMAL)), guiAlpha));
+
+ }
+ else GuiDrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, Fade(GetColor(GuiGetStyle(LISTVIEW, TEXT_COLOR_DISABLED)), guiAlpha));
+ } break;
+ default: break;
+ }
+ //--------------------------------------------------------------------
+
+ return active;
+}
+
+// List View control
+RAYGUIDEF bool GuiListView(Rectangle bounds, const char **text, int count, int *scrollIndex, int *active, bool editMode)
+{
+ return GuiListViewEx(bounds, text, NULL, count, scrollIndex, active, NULL, editMode);
+}
+
+// List View control extended parameters
+RAYGUIDEF bool GuiListViewEx(Rectangle bounds, const char **text, int *enabledElements, int count, int *scrollIndex, int *active, int *focus, bool editMode)
+{
+ GuiControlState state = guiState;
+ bool pressed = false;
+
+ int focusElement = -1;
+ int startIndex = (scrollIndex == NULL) ? 0 : *scrollIndex;
+ bool useScrollBar = true;
+ bool pressedKey = false;
+
+ int visibleElements = bounds.height/(GuiGetStyle(LISTVIEW, ELEMENTS_HEIGHT) + GuiGetStyle(LISTVIEW, ELEMENTS_PADDING));
+ if ((startIndex < 0) || (startIndex > count - visibleElements)) startIndex = 0;
+ int endIndex = startIndex + visibleElements;
+
+ int auxActive = *active;
+
+ float barHeight = bounds.height;
+ float minBarHeight = 10;
+ float barPosY = 0;
+
+ // Update control
+ //--------------------------------------------------------------------
+
+ // All the elements fit inside ListView and dont need scrollbar.
+ if (visibleElements >= count)
+ {
+ useScrollBar = false;
+ startIndex = 0;
+ endIndex = count;
+ }
+
+ // Calculate position X and width to draw each element.
+ int posX = bounds.x + GuiGetStyle(LISTVIEW, SCROLLBAR_WIDTH) + GuiGetStyle(LISTVIEW, ELEMENTS_PADDING);
+ int elementWidth = bounds.width - GuiGetStyle(LISTVIEW, SCROLLBAR_WIDTH) - 2*GuiGetStyle(LISTVIEW, ELEMENTS_PADDING) - GuiGetStyle(DEFAULT, BORDER_WIDTH);
+
+ if (!useScrollBar)
+ {
+ posX = bounds.x + GuiGetStyle(LISTVIEW, ELEMENTS_PADDING);
+ elementWidth = bounds.width - 2*GuiGetStyle(LISTVIEW, ELEMENTS_PADDING) - GuiGetStyle(DEFAULT, BORDER_WIDTH);
+ }
+
+ if ((state != GUI_STATE_DISABLED) && !guiLocked) // && !guiLocked
+ {
+ Vector2 mousePoint = GetMousePosition();
+
+ if (editMode)
+ {
+ state = GUI_STATE_PRESSED;
+
+ // Change active with keys
+ if (IsKeyPressed(KEY_UP))
+ {
+ if (auxActive > 0)
+ {
+ auxActive--;
+ if ((useScrollBar) && (auxActive < startIndex)) startIndex--;
+ }
+ pressedKey = true;
+ }
+ else if (IsKeyPressed(KEY_DOWN))
+ {
+ if (auxActive < count - 1)
+ {
+ auxActive++;
+ if ((useScrollBar) && (auxActive >= endIndex)) startIndex++;
+ }
+ pressedKey = true;
+ }
+
+ if (useScrollBar && CheckCollisionPointRec(mousePoint, bounds))
+ {
+ endIndex = startIndex + visibleElements;
+ int wheel = GetMouseWheelMove();
+
+ if (wheel < 0 && endIndex < count) startIndex -= wheel;
+ else if (wheel > 0 && startIndex > 0) startIndex -= wheel;
+
+ if (pressedKey)
+ {
+ pressedKey = false;
+ if ((auxActive < startIndex) || (auxActive >= endIndex)) startIndex = auxActive;
+ }
+
+ if (startIndex < 0) startIndex = 0;
+ else if (startIndex > (count - (endIndex - startIndex)))
+ {
+ startIndex = count - (endIndex - startIndex);
+ }
+
+ endIndex = startIndex + visibleElements;
+ if (endIndex > count) endIndex = count;
+ }
+ }
+
+ if (!editMode)
+ {
+ if (CheckCollisionPointRec(mousePoint, bounds))
+ {
+ state = GUI_STATE_FOCUSED;
+ if (IsMouseButtonPressed(0)) pressed = true;
+
+ int wheel = GetMouseWheelMove();
+ if (wheel)
+ {
+ startIndex -= wheel;
+ if (startIndex < 0) startIndex = 0;
+ else if (startIndex > (count - (endIndex - startIndex)))
+ {
+ startIndex = count - (endIndex - startIndex);
+ }
+ pressed = true;
+ }
+ }
+ }
+ else
+ {
+ if (!CheckCollisionPointRec(mousePoint, bounds))
+ {
+ if (IsMouseButtonPressed(0) || GetMouseWheelMove() != 0) pressed = true;
+ }
+ }
+
+ // Get focused element
+ for (int i = startIndex; i < endIndex; i++)
+ {
+ if (CheckCollisionPointRec(mousePoint, (Rectangle){ posX, bounds.y + GuiGetStyle(LISTVIEW, ELEMENTS_PADDING) + GuiGetStyle(DEFAULT, BORDER_WIDTH) + (i - startIndex)*(GuiGetStyle(LISTVIEW, ELEMENTS_HEIGHT) + GuiGetStyle(LISTVIEW, ELEMENTS_PADDING)), elementWidth, GuiGetStyle(LISTVIEW, ELEMENTS_HEIGHT) }))
+ {
+ focusElement = i;
+ }
+ }
+ }
+
+ // Calculate percentage of visible elements and apply same percentage to scrollbar
+ if (useScrollBar)
+ {
+ float percentVisible = (endIndex - startIndex)*100/count;
+ barHeight *= percentVisible/100;
+
+ if (barHeight < minBarHeight) barHeight = minBarHeight;
+ else if (barHeight > bounds.height) barHeight = bounds.height;
+
+ barPosY = bounds.y + startIndex*((bounds.height - barHeight)/(count - (endIndex - startIndex)));
+ }
+ //--------------------------------------------------------------------
+
+ // Draw control
+ //--------------------------------------------------------------------
+ DrawRectangleRec(bounds, GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR))); // Draw background
+
+ // Draw scrollBar background
+ if (useScrollBar) DrawRectangle(bounds.x, bounds.y, GuiGetStyle(LISTVIEW, SCROLLBAR_WIDTH), bounds.height, Fade(GetColor(GuiGetStyle(DEFAULT, BORDER_COLOR_DISABLED)), guiAlpha));
+
+ // Draw ListView states
+ switch (state)
+ {
+ case GUI_STATE_NORMAL:
+ {
+ if (useScrollBar) DrawRectangle(bounds.x, barPosY, GuiGetStyle(LISTVIEW, SCROLLBAR_WIDTH), barHeight, Fade(GetColor(GuiGetStyle(SLIDER, BORDER_COLOR_NORMAL)), guiAlpha));
+ DrawRectangleLinesEx(bounds, GuiGetStyle(DEFAULT, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(LISTVIEW, BORDER_COLOR_NORMAL)), guiAlpha));
+
+ for (int i = startIndex; i < endIndex; i++)
+ {
+ if ((enabledElements != NULL) && (enabledElements[i] == 0))
+ {
+ GuiDisable();
+ GuiListElement((Rectangle){ posX, bounds.y + GuiGetStyle(LISTVIEW, ELEMENTS_PADDING) + GuiGetStyle(DEFAULT, BORDER_WIDTH) + (i - startIndex)*(GuiGetStyle(LISTVIEW, ELEMENTS_HEIGHT) + GuiGetStyle(LISTVIEW, ELEMENTS_PADDING)), elementWidth, GuiGetStyle(LISTVIEW, ELEMENTS_HEIGHT) }, text[i], false, false);
+ GuiEnable();
+ }
+ else if (i == auxActive)
+ {
+ GuiDisable();
+ GuiListElement((Rectangle){ posX, bounds.y + GuiGetStyle(LISTVIEW, ELEMENTS_PADDING) + GuiGetStyle(DEFAULT, BORDER_WIDTH) + (i - startIndex)*(GuiGetStyle(LISTVIEW, ELEMENTS_HEIGHT) + GuiGetStyle(LISTVIEW, ELEMENTS_PADDING)), elementWidth, GuiGetStyle(LISTVIEW, ELEMENTS_HEIGHT) }, text[i], true, false);
+ GuiEnable();
+ }
+ else GuiListElement((Rectangle){ posX, bounds.y + GuiGetStyle(LISTVIEW, ELEMENTS_PADDING) + GuiGetStyle(DEFAULT, BORDER_WIDTH) + (i - startIndex)*(GuiGetStyle(LISTVIEW, ELEMENTS_HEIGHT) + GuiGetStyle(LISTVIEW, ELEMENTS_PADDING)), elementWidth, GuiGetStyle(LISTVIEW, ELEMENTS_HEIGHT) }, text[i], false, false);
+ }
+ } break;
+ case GUI_STATE_FOCUSED:
+ {
+ if (useScrollBar) DrawRectangle(bounds.x, barPosY, GuiGetStyle(LISTVIEW, SCROLLBAR_WIDTH), barHeight, Fade(GetColor(GuiGetStyle(SLIDER, BASE_COLOR_FOCUSED)), guiAlpha));
+ DrawRectangleLinesEx(bounds, GuiGetStyle(DEFAULT, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(LISTVIEW, BORDER_COLOR_FOCUSED)), guiAlpha));
+
+ for (int i = startIndex; i < endIndex; i++)
+ {
+ if ((enabledElements != NULL) && (enabledElements[i] == 0))
+ {
+ GuiDisable();
+ GuiListElement((Rectangle){ posX, bounds.y + GuiGetStyle(LISTVIEW, ELEMENTS_PADDING) + GuiGetStyle(DEFAULT, BORDER_WIDTH) + (i - startIndex)*(GuiGetStyle(LISTVIEW, ELEMENTS_HEIGHT) + GuiGetStyle(LISTVIEW, ELEMENTS_PADDING)), elementWidth, GuiGetStyle(LISTVIEW, ELEMENTS_HEIGHT) }, text[i], false, false);
+ GuiEnable();
+ }
+ else if (i == auxActive) GuiListElement((Rectangle){ posX, bounds.y + GuiGetStyle(LISTVIEW, ELEMENTS_PADDING) + GuiGetStyle(DEFAULT, BORDER_WIDTH) + (i - startIndex)*(GuiGetStyle(LISTVIEW, ELEMENTS_HEIGHT) + GuiGetStyle(LISTVIEW, ELEMENTS_PADDING)), elementWidth, GuiGetStyle(LISTVIEW, ELEMENTS_HEIGHT) }, text[i], true, false);
+ else GuiListElement((Rectangle){ posX, bounds.y + GuiGetStyle(LISTVIEW, ELEMENTS_PADDING) + GuiGetStyle(DEFAULT, BORDER_WIDTH) + (i - startIndex)*(GuiGetStyle(LISTVIEW, ELEMENTS_HEIGHT) + GuiGetStyle(LISTVIEW, ELEMENTS_PADDING)), elementWidth, GuiGetStyle(LISTVIEW, ELEMENTS_HEIGHT) }, text[i], false, false);
+ }
+ } break;
+ case GUI_STATE_PRESSED:
+ {
+ if (useScrollBar) DrawRectangle(bounds.x, barPosY, GuiGetStyle(LISTVIEW, SCROLLBAR_WIDTH), barHeight, Fade(GetColor(GuiGetStyle(SLIDER, BASE_COLOR_PRESSED)), guiAlpha));
+ DrawRectangleLinesEx(bounds, GuiGetStyle(DEFAULT, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(LISTVIEW, BORDER_COLOR_PRESSED)), guiAlpha));
+
+ for (int i = startIndex; i < endIndex; i++)
+ {
+ if ((enabledElements != NULL) && (enabledElements[i] == 0))
+ {
+ GuiDisable();
+ GuiListElement((Rectangle){ posX, bounds.y + GuiGetStyle(LISTVIEW, ELEMENTS_PADDING) + GuiGetStyle(DEFAULT, BORDER_WIDTH) + (i - startIndex)*(GuiGetStyle(LISTVIEW, ELEMENTS_HEIGHT) + GuiGetStyle(LISTVIEW, ELEMENTS_PADDING)), elementWidth, GuiGetStyle(LISTVIEW, ELEMENTS_HEIGHT) }, text[i], false, false);
+ GuiEnable();
+ }
+ else if ((i == auxActive) && editMode)
+ {
+ if (GuiListElement((Rectangle){ posX, bounds.y + GuiGetStyle(LISTVIEW, ELEMENTS_PADDING) + GuiGetStyle(DEFAULT, BORDER_WIDTH) + (i - startIndex)*(GuiGetStyle(LISTVIEW, ELEMENTS_HEIGHT) + GuiGetStyle(LISTVIEW, ELEMENTS_PADDING)), elementWidth, GuiGetStyle(LISTVIEW, ELEMENTS_HEIGHT) }, text[i], true, true) == false) auxActive = -1;
+ }
+ else
+ {
+ if (GuiListElement((Rectangle){ posX, bounds.y + GuiGetStyle(LISTVIEW, ELEMENTS_PADDING) + GuiGetStyle(DEFAULT, BORDER_WIDTH) + (i - startIndex)*(GuiGetStyle(LISTVIEW, ELEMENTS_HEIGHT) + GuiGetStyle(LISTVIEW, ELEMENTS_PADDING)), elementWidth, GuiGetStyle(LISTVIEW, ELEMENTS_HEIGHT) }, text[i], false, true) == true) auxActive = i;
+ }
+ }
+ } break;
+ case GUI_STATE_DISABLED:
+ {
+ if (useScrollBar) DrawRectangle(bounds.x, barPosY, GuiGetStyle(LISTVIEW, SCROLLBAR_WIDTH), barHeight, Fade(GetColor(GuiGetStyle(LISTVIEW, BASE_COLOR_DISABLED)), guiAlpha));
+
+ DrawRectangleLinesEx(bounds, GuiGetStyle(DEFAULT, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(LISTVIEW, BORDER_COLOR_DISABLED)), guiAlpha));
+
+ for (int i = startIndex; i < endIndex; i++)
+ {
+ if (i == auxActive) GuiListElement((Rectangle){ posX, bounds.y + GuiGetStyle(LISTVIEW, ELEMENTS_PADDING) + GuiGetStyle(DEFAULT, BORDER_WIDTH) + (i - startIndex)*(GuiGetStyle(LISTVIEW, ELEMENTS_HEIGHT) + GuiGetStyle(LISTVIEW, ELEMENTS_PADDING)), elementWidth, GuiGetStyle(LISTVIEW, ELEMENTS_HEIGHT) }, text[i], true, false);
+ else GuiListElement((Rectangle){ posX, bounds.y + GuiGetStyle(LISTVIEW, ELEMENTS_PADDING) + GuiGetStyle(DEFAULT, BORDER_WIDTH) + (i - startIndex)*(GuiGetStyle(LISTVIEW, ELEMENTS_HEIGHT) + GuiGetStyle(LISTVIEW, ELEMENTS_PADDING)), elementWidth, GuiGetStyle(LISTVIEW, ELEMENTS_HEIGHT) }, text[i], false, false);
+ }
+ } break;
+ default: break;
+ }
+ //--------------------------------------------------------------------
+
+ if (scrollIndex != NULL) *scrollIndex = startIndex;
+ if (focus != NULL) *focus = focusElement;
+ *active = auxActive;
+
+ return pressed;
+}
+
+// Color Panel control
+RAYGUIDEF Color GuiColorPanel(Rectangle bounds, Color color)
+{
+ GuiControlState state = guiState;
+ Vector2 pickerSelector = { 0 };
+
+ Vector3 vcolor = { (float)color.r/255.0f, (float)color.g/255.0f, (float)color.b/255.0f };
+ Vector3 hsv = ConvertRGBtoHSV(vcolor);
+
+ pickerSelector.x = bounds.x + (float)hsv.y*bounds.width; // HSV: Saturation
+ pickerSelector.y = bounds.y + (1.0f - (float)hsv.z)*bounds.height; // HSV: Value
+
+ Vector3 maxHue = { hsv.x, 1.0f, 1.0f };
+ Vector3 rgbHue = ConvertHSVtoRGB(maxHue);
+ Color maxHueCol = { (unsigned char)(255.0f*rgbHue.x),
+ (unsigned char)(255.0f*rgbHue.y),
+ (unsigned char)(255.0f*rgbHue.z), 255 };
+
+ // Update control
+ //--------------------------------------------------------------------
+ if ((state != GUI_STATE_DISABLED) && !guiLocked)
+ {
+ Vector2 mousePoint = GetMousePosition();
+
+ if (CheckCollisionPointRec(mousePoint, bounds))
+ {
+ if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
+ {
+ state = GUI_STATE_PRESSED;
+ pickerSelector = mousePoint;
+
+ // Calculate color from picker
+ Vector2 colorPick = { pickerSelector.x - bounds.x, pickerSelector.y - bounds.y };
+
+ colorPick.x /= (float)bounds.width; // Get normalized value on x
+ colorPick.y /= (float)bounds.height; // Get normalized value on y
+
+ hsv.y = colorPick.x;
+ hsv.z = 1.0f - colorPick.y;
+
+ Vector3 rgb = ConvertHSVtoRGB(hsv);
+
+ // NOTE: Vector3ToColor() only available on raylib 1.8.1
+ color = (Color){ (unsigned char)(255.0f*rgb.x),
+ (unsigned char)(255.0f*rgb.y),
+ (unsigned char)(255.0f*rgb.z),
+ (unsigned char)(255.0f*(float)color.a/255.0f) };
+
+ }
+ else state = GUI_STATE_FOCUSED;
+ }
+ }
+ //--------------------------------------------------------------------
+
+ // Draw control
+ //--------------------------------------------------------------------
+ if (state != GUI_STATE_DISABLED)
+ {
+ DrawRectangleGradientEx(bounds, Fade(WHITE, guiAlpha), Fade(WHITE, guiAlpha), Fade(maxHueCol, guiAlpha), Fade(maxHueCol, guiAlpha));
+ DrawRectangleGradientEx(bounds, Fade(BLACK, 0), Fade(BLACK, guiAlpha), Fade(BLACK, guiAlpha), Fade(BLACK, 0));
+
+ // Draw color picker: selector
+ DrawRectangle(pickerSelector.x - GuiGetStyle(COLORPICKER, COLOR_SELECTOR_SIZE)/2, pickerSelector.y - GuiGetStyle(COLORPICKER, COLOR_SELECTOR_SIZE)/2, GuiGetStyle(COLORPICKER, COLOR_SELECTOR_SIZE), GuiGetStyle(COLORPICKER, COLOR_SELECTOR_SIZE), Fade(WHITE, guiAlpha));
+ }
+ else
+ {
+ DrawRectangleGradientEx(bounds, Fade(Fade(GetColor(GuiGetStyle(COLORPICKER, BASE_COLOR_DISABLED)), 0.1f), guiAlpha), Fade(Fade(BLACK, 0.6f), guiAlpha), Fade(Fade(BLACK, 0.6f), guiAlpha), Fade(Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER_COLOR_DISABLED)), 0.6f), guiAlpha));
+ }
+
+ switch (state)
+ {
+ case GUI_STATE_NORMAL: DrawRectangleLines(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER_COLOR_NORMAL)), guiAlpha)); break;
+ case GUI_STATE_FOCUSED: DrawRectangleLines(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER_COLOR_FOCUSED)), guiAlpha)); break;
+ case GUI_STATE_PRESSED: DrawRectangleLines(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER_COLOR_PRESSED)), guiAlpha)); break;
+ case GUI_STATE_DISABLED: DrawRectangleLines(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER_COLOR_DISABLED)), guiAlpha)); break;
+ default: break;
+ }
+ //--------------------------------------------------------------------
+
+ return color;
+}
+
+// Color Bar Alpha control
+// NOTE: Returns alpha value normalized [0..1]
+RAYGUIDEF float GuiColorBarAlpha(Rectangle bounds, float alpha)
+{
+ #define BACK_CHECKER_SIZE 10
+
+ GuiControlState state = guiState;
+ Rectangle selector = { bounds.x + alpha*bounds.width - GuiGetStyle(COLORPICKER, BAR_SELECTOR_PADDING), bounds.y - GuiGetStyle(COLORPICKER, BAR_SELECTOR_PADDING), GuiGetStyle(COLORPICKER, BAR_SELECTOR_HEIGHT), bounds.height + GuiGetStyle(COLORPICKER, BAR_SELECTOR_PADDING)*2 };
+
+ // Update control
+ //--------------------------------------------------------------------
+ if ((state != GUI_STATE_DISABLED) && !guiLocked)
+ {
+ Vector2 mousePoint = GetMousePosition();
+
+ if (CheckCollisionPointRec(mousePoint, bounds) ||
+ CheckCollisionPointRec(mousePoint, selector))
+ {
+ if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
+ {
+ state = GUI_STATE_PRESSED;
+ selector.x = mousePoint.x - selector.width/2;
+
+ alpha = (mousePoint.x - bounds.x)/bounds.width;
+ if (alpha <= 0.0f) alpha = 0.0f;
+ if (alpha >= 1.0f) alpha = 1.0f;
+ //selector.x = bounds.x + (int)(((alpha - 0)/(100 - 0))*(bounds.width - 2*GuiGetStyle(SLIDER, BORDER_WIDTH))) - selector.width/2;
+ }
+ else state = GUI_STATE_FOCUSED;
+ }
+ }
+ //--------------------------------------------------------------------
+
+ // Draw control
+ //--------------------------------------------------------------------
+ // Draw alpha bar: checked background
+ if (state != GUI_STATE_DISABLED)
+ {
+ for (int i = 0; i < bounds.width/BACK_CHECKER_SIZE; i++) DrawRectangle(bounds.x + BACK_CHECKER_SIZE*(i%((int)bounds.width/BACK_CHECKER_SIZE)), bounds.y, bounds.width/(bounds.width/BACK_CHECKER_SIZE), BACK_CHECKER_SIZE, (i%2) ? Fade(Fade(GRAY, 0.4f), guiAlpha) : Fade(Fade(RAYWHITE, 0.4f), guiAlpha));
+ for (int i = 0; i < bounds.width/BACK_CHECKER_SIZE; i++) DrawRectangle(bounds.x + BACK_CHECKER_SIZE*(i%((int)bounds.width/BACK_CHECKER_SIZE)), bounds.y + BACK_CHECKER_SIZE, bounds.width/(bounds.width/BACK_CHECKER_SIZE), BACK_CHECKER_SIZE, (i%2) ? Fade(Fade(RAYWHITE, 0.4f), guiAlpha) : Fade(Fade(GRAY, 0.4f), guiAlpha));
+ DrawRectangleGradientH(bounds.x, bounds.y, bounds.width, bounds.height, Fade((Color){ 255,255,255,0 }, guiAlpha), Fade((Color){ 0,0,0,255 }, guiAlpha));
+ }
+ else DrawRectangleGradientH(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(GuiGetStyle(COLORPICKER, BASE_COLOR_DISABLED)), 0.1f), Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER_COLOR_DISABLED)), guiAlpha));
+
+ switch (state)
+ {
+ case GUI_STATE_NORMAL:
+ {
+ DrawRectangleLines(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER_COLOR_NORMAL)), guiAlpha));
+ DrawRectangle(selector.x , selector.y, selector.width, selector.height, Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER_COLOR_PRESSED)), guiAlpha));
+ } break;
+ case GUI_STATE_FOCUSED:
+ {
+ DrawRectangleLines(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER_COLOR_FOCUSED)), guiAlpha));
+ DrawRectangle(selector.x, selector.y, selector.width, selector.height, Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER_COLOR_FOCUSED)), guiAlpha));
+ } break;
+ case GUI_STATE_PRESSED:
+ {
+ DrawRectangleLines(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER_COLOR_PRESSED)), guiAlpha));
+ DrawRectangle(selector.x, selector.y, selector.width, selector.height, Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER_COLOR_PRESSED)), guiAlpha));
+ } break;
+ case GUI_STATE_DISABLED:
+ {
+ DrawRectangleLines(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER_COLOR_DISABLED)), guiAlpha));
+ DrawRectangleRec(selector, Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER_COLOR_DISABLED)), guiAlpha));
+ } break;
+ default: break;
+ }
+ //--------------------------------------------------------------------
+
+ return alpha;
+}
+
+// Color Bar Hue control
+// NOTE: Returns hue value normalized [0..1]
+RAYGUIDEF float GuiColorBarHue(Rectangle bounds, float hue)
+{
+ GuiControlState state = guiState;
+ Rectangle selector = { bounds.x - GuiGetStyle(COLORPICKER, BAR_SELECTOR_PADDING), bounds.y + hue/360.0f*bounds.height - GuiGetStyle(COLORPICKER, BAR_SELECTOR_PADDING), bounds.width + GuiGetStyle(COLORPICKER, BAR_SELECTOR_PADDING)*2, GuiGetStyle(COLORPICKER, BAR_SELECTOR_HEIGHT) };
+
+ // Update control
+ //--------------------------------------------------------------------
+ if ((state != GUI_STATE_DISABLED) && !guiLocked)
+ {
+ Vector2 mousePoint = GetMousePosition();
+
+ if (CheckCollisionPointRec(mousePoint, bounds) ||
+ CheckCollisionPointRec(mousePoint, selector))
+ {
+ if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
+ {
+ state = GUI_STATE_PRESSED;
+ selector.y = mousePoint.y - selector.height/2;
+
+ hue = (mousePoint.y - bounds.y)*360/bounds.height;
+ if (hue <= 0.0f) hue = 0.0f;
+ if (hue >= 359.0f) hue = 359.0f;
+
+ }
+ else state = GUI_STATE_FOCUSED;
+
+ /*if (IsKeyDown(KEY_UP))
+ {
+ hue -= 2.0f;
+ if (hue <= 0.0f) hue = 0.0f;
+ }
+ else if (IsKeyDown(KEY_DOWN))
+ {
+ hue += 2.0f;
+ if (hue >= 360.0f) hue = 360.0f;
+ }*/
+ }
+ }
+ //--------------------------------------------------------------------
+
+ // Draw control
+ //--------------------------------------------------------------------
+ if (state != GUI_STATE_DISABLED)
+ {
+ // Draw hue bar:color bars
+ DrawRectangleGradientV(bounds.x + GuiGetStyle(COLORPICKER, BAR_SELECTOR_PADDING)/2, bounds.y + GuiGetStyle(COLORPICKER, BAR_SELECTOR_PADDING)/2, bounds.width - GuiGetStyle(COLORPICKER, BAR_SELECTOR_PADDING), (int)bounds.height/6, Fade((Color){ 255,0,0,255 }, guiAlpha), Fade((Color){ 255,255,0,255 }, guiAlpha));
+ DrawRectangleGradientV(bounds.x + GuiGetStyle(COLORPICKER, BAR_SELECTOR_PADDING)/2, bounds.y + (int)bounds.height/6 + GuiGetStyle(COLORPICKER, BAR_SELECTOR_PADDING)/2, bounds.width - GuiGetStyle(COLORPICKER, BAR_SELECTOR_PADDING), (int)bounds.height/6, Fade((Color){ 255,255,0,255 }, guiAlpha), Fade((Color){ 0,255,0,255 }, guiAlpha));
+ DrawRectangleGradientV(bounds.x + GuiGetStyle(COLORPICKER, BAR_SELECTOR_PADDING)/2, bounds.y + 2*((int)bounds.height/6) + GuiGetStyle(COLORPICKER, BAR_SELECTOR_PADDING)/2, bounds.width - GuiGetStyle(COLORPICKER, BAR_SELECTOR_PADDING), (int)bounds.height/6, Fade((Color){ 0,255,0,255 }, guiAlpha), Fade((Color){ 0,255,255,255 }, guiAlpha));
+ DrawRectangleGradientV(bounds.x + GuiGetStyle(COLORPICKER, BAR_SELECTOR_PADDING)/2, bounds.y + 3*((int)bounds.height/6) + GuiGetStyle(COLORPICKER, BAR_SELECTOR_PADDING)/2, bounds.width - GuiGetStyle(COLORPICKER, BAR_SELECTOR_PADDING), (int)bounds.height/6, Fade((Color){ 0,255,255,255 }, guiAlpha), Fade((Color){ 0,0,255,255 }, guiAlpha));
+ DrawRectangleGradientV(bounds.x + GuiGetStyle(COLORPICKER, BAR_SELECTOR_PADDING)/2, bounds.y + 4*((int)bounds.height/6) + GuiGetStyle(COLORPICKER, BAR_SELECTOR_PADDING)/2, bounds.width - GuiGetStyle(COLORPICKER, BAR_SELECTOR_PADDING), (int)bounds.height/6, Fade((Color){ 0,0,255,255 }, guiAlpha), Fade((Color){ 255,0,255,255 }, guiAlpha));
+ DrawRectangleGradientV(bounds.x + GuiGetStyle(COLORPICKER, BAR_SELECTOR_PADDING)/2, bounds.y + 5*((int)bounds.height/6) + GuiGetStyle(COLORPICKER, BAR_SELECTOR_PADDING)/2, bounds.width - GuiGetStyle(COLORPICKER, BAR_SELECTOR_PADDING), (int)bounds.height/6 - GuiGetStyle(COLORPICKER, BAR_SELECTOR_PADDING), Fade((Color){ 255,0,255,255 }, guiAlpha), Fade((Color){ 255,0,0,255 }, guiAlpha));
+ }
+ else
+ {
+ DrawRectangleGradientV(bounds.x, bounds.y, bounds.width, bounds.height, Fade(Fade(GetColor(GuiGetStyle(COLORPICKER, BASE_COLOR_DISABLED)), 0.1f), guiAlpha), Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER_COLOR_DISABLED)), guiAlpha));
+ }
+
+ switch (state)
+ {
+ case GUI_STATE_NORMAL:
+ {
+ // Draw hue bar: selector
+ DrawRectangleLines(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER_COLOR_NORMAL)), guiAlpha));
+ DrawRectangle(selector.x, selector.y, selector.width, selector.height, Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER_COLOR_PRESSED)), guiAlpha));
+ } break;
+ case GUI_STATE_FOCUSED:
+ {
+ DrawRectangleLines(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER_COLOR_FOCUSED)), guiAlpha));
+ DrawRectangle(selector.x, selector.y , selector.width, selector.height, Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER_COLOR_FOCUSED)), guiAlpha));
+ } break;
+ case GUI_STATE_PRESSED:
+ {
+ DrawRectangleLines(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER_COLOR_PRESSED)), guiAlpha));
+ DrawRectangle(selector.x, selector.y, selector.width, selector.height, Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER_COLOR_PRESSED)), guiAlpha));
+ } break;
+ case GUI_STATE_DISABLED:
+ {
+ DrawRectangleLines(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER_COLOR_DISABLED)), guiAlpha));
+ DrawRectangle(selector.x, selector.y, selector.width, selector.height, Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER_COLOR_DISABLED)), guiAlpha));
+ } break;
+ default: break;
+ }
+ //--------------------------------------------------------------------
+
+ return hue;
+}
+
+// TODO: Color GuiColorBarSat() [WHITE->color]
+// TODO: Color GuiColorBarValue() [BLACK->color], HSV / HSL
+// TODO: float GuiColorBarLuminance() [BLACK->WHITE]
+
+// Color Picker control
+// NOTE: It's divided in multiple controls:
+// Color GuiColorPanel() - Color select panel
+// float GuiColorBarAlpha(Rectangle bounds, float alpha)
+// float GuiColorBarHue(Rectangle bounds, float value)
+// NOTE: bounds define GuiColorPanel() size
+RAYGUIDEF Color GuiColorPicker(Rectangle bounds, Color color)
+{
+ color = GuiColorPanel(bounds, color);
+
+ Rectangle boundsHue = { bounds.x + bounds.width + GuiGetStyle(COLORPICKER, BAR_PADDING), bounds.y, GuiGetStyle(COLORPICKER, BAR_WIDTH), bounds.height };
+ //Rectangle boundsAlpha = { bounds.x, bounds.y + bounds.height + GuiGetStyle(COLORPICKER, BARS_PADDING), bounds.width, GuiGetStyle(COLORPICKER, BARS_THICK) };
+
+ Vector3 hsv = ConvertRGBtoHSV((Vector3){ color.r/255.0f, color.g/255.0f, color.b/255.0f });
+ hsv.x = GuiColorBarHue(boundsHue, hsv.x);
+ //color.a = (unsigned char)(GuiColorBarAlpha(boundsAlpha, (float)color.a/255.0f)*255.0f);
+ Vector3 rgb = ConvertHSVtoRGB(hsv);
+ color = (Color){ (unsigned char)(rgb.x*255.0f), (unsigned char)(rgb.y*255.0f), (unsigned char)(rgb.z*255.0f), color.a };
+
+ return color;
+}
+
+// Message Box control
+RAYGUIDEF bool GuiMessageBox(Rectangle bounds, const char *windowTitle, const char *message)
+{
+ #define MESSAGEBOX_BUTTON_HEIGHT 26
+ #define MESSAGEBOX_BUTTON_PADDING 10
+ #define MESSAGEBOX_STATUSBAR_BUTTON_SIZE 16
+ #define MESSAGEBOX_STATUSBAR_HEIGHT 24
+
+ bool clicked = false;
+
+ int textWidth = GuiTextWidth(windowTitle);
+ int offsetX = 20;
+
+ if (bounds.width < textWidth + offsetX + MESSAGEBOX_STATUSBAR_BUTTON_SIZE) bounds.width = textWidth + offsetX + MESSAGEBOX_STATUSBAR_BUTTON_SIZE;
+
+ Vector2 textSize = MeasureTextEx(GetFontDefault(), message, GuiGetStyle(DEFAULT, TEXT_SIZE), 1);
+ if (bounds.width < textSize.x + offsetX) bounds.width = textSize.x + offsetX;
+ if (bounds.height < (MESSAGEBOX_BUTTON_HEIGHT + MESSAGEBOX_BUTTON_PADDING*2 + MESSAGEBOX_STATUSBAR_HEIGHT + MESSAGEBOX_STATUSBAR_BUTTON_SIZE + textSize.y))
+ {
+ bounds.height = (MESSAGEBOX_BUTTON_HEIGHT + MESSAGEBOX_BUTTON_PADDING*2 + MESSAGEBOX_STATUSBAR_HEIGHT + MESSAGEBOX_STATUSBAR_BUTTON_SIZE + textSize.y);
+ }
+
+ Rectangle buttonBounds = { bounds.x + MESSAGEBOX_BUTTON_PADDING, bounds.y + bounds.height - MESSAGEBOX_BUTTON_PADDING - MESSAGEBOX_BUTTON_HEIGHT, bounds.width - MESSAGEBOX_BUTTON_PADDING*2, MESSAGEBOX_BUTTON_HEIGHT };
+
+ // Draw control
+ //--------------------------------------------------------------------
+ clicked = GuiWindowBox(bounds, windowTitle);
+ GuiLabel((Rectangle){ bounds.x + bounds.width/2 - textSize.x/2, bounds.y + (MESSAGEBOX_STATUSBAR_HEIGHT - MESSAGEBOX_BUTTON_HEIGHT - MESSAGEBOX_BUTTON_PADDING)/2 + bounds.height/2 - textSize.y/2, 0, 0 }, message);
+
+ clicked = GuiButton(buttonBounds, "OK");
+ //--------------------------------------------------------------------
+
+ return clicked;
+}
+
+// Grid control
+// NOTE: Returns grid mouse-hover selected cell
+RAYGUIDEF Vector2 GuiGrid(Rectangle bounds, int spacing, int subdivs)
+{
+ #define GRID_COLOR_ALPHA 0.15f // Grid lines alpha amount
+
+ GuiControlState state = guiState;
+ Vector2 mousePoint = GetMousePosition();
+ Vector2 currentCell = { -1, -1 };
+
+ // Update control
+ //--------------------------------------------------------------------
+ if ((state != GUI_STATE_DISABLED) && !guiLocked)
+ {
+ if (CheckCollisionPointRec(mousePoint, bounds))
+ {
+ currentCell.x = (int)((mousePoint.x - bounds.x)/spacing);
+ currentCell.y = (int)((mousePoint.y - bounds.y)/spacing);
+ }
+ }
+ //--------------------------------------------------------------------
+
+ // Draw control
+ //--------------------------------------------------------------------
+ switch (state)
+ {
+ case GUI_STATE_NORMAL:
+ {
+ // Draw vertical grid lines
+ for (int i = 0; i < (bounds.width/spacing + 1)*subdivs; i++)
+ {
+ DrawRectangle(bounds.x + spacing*i, bounds.y, 1, bounds.height, ((i%subdivs) == 0) ? Fade(GetColor(GuiGetStyle(DEFAULT, LINES_COLOR)), GRID_COLOR_ALPHA*4) : Fade(GetColor(GuiGetStyle(DEFAULT, LINES_COLOR)), GRID_COLOR_ALPHA));
+ }
+
+ // Draw horizontal grid lines
+ for (int i = 0; i < (bounds.height/spacing + 1)*subdivs; i++)
+ {
+ DrawRectangle(bounds.x, bounds.y + spacing*i, bounds.width, 1, ((i%subdivs) == 0) ? Fade(GetColor(GuiGetStyle(DEFAULT, LINES_COLOR)), GRID_COLOR_ALPHA*4) : Fade(GetColor(GuiGetStyle(DEFAULT, LINES_COLOR)), GRID_COLOR_ALPHA));
+ }
+
+ } break;
+ default: break;
+ }
+
+ return currentCell;
+}
+
+// Load raygui style file (.rgs)
+RAYGUIDEF void GuiLoadStyle(const char *fileName)
+{
+ FILE *rgsFile = fopen(fileName, "rb");
+
+ if (rgsFile != NULL)
+ {
+ unsigned int value = 0;
+
+ char signature[5] = "";
+ short version = 0;
+ short numControls = 0;
+ short numPropsDefault = 0;
+ short numPropsExtended = 0;
+
+ fread(signature, 1, 4, rgsFile);
+ fread(&version, 1, sizeof(short), rgsFile);
+ fread(&numControls, 1, sizeof(short), rgsFile);
+ fread(&numPropsDefault, 1, sizeof(short), rgsFile);
+ fread(&numPropsExtended, 1, sizeof(short), rgsFile);
+
+ if ((signature[0] == 'r') &&
+ (signature[1] == 'G') &&
+ (signature[2] == 'S') &&
+ (signature[3] == ' '))
+ {
+ for (int i = 0; i < NUM_CONTROLS; i++)
+ {
+ for (int j = 0; j < NUM_PROPS_DEFAULT + NUM_PROPS_EXTENDED; j++)
+ {
+ fread(&value, 1, sizeof(unsigned int), rgsFile);
+ GuiSetStyle(i, j, value);
+ }
+ }
+
+ // Load custom font if available
+ int fontDataSize = 0;
+ fwrite(&fontDataSize, 1, sizeof(int), rgsFile);
+
+ if (fontDataSize > 0)
+ {
+ Font font = { 0 };
+ int fontType = 0; // 0-Normal, 1-SDF
+ Rectangle whiteRec = { 0 };
+
+ fread(&font.baseSize, 1, sizeof(int), rgsFile);
+ fread(&font.charsCount, 1, sizeof(int), rgsFile);
+ fread(&fontType, 1, sizeof(int), rgsFile);
+
+ // Load font white rectangle
+ fread(&whiteRec, 1, sizeof(Rectangle), rgsFile);
+
+ // Load font image parameters
+ int fontImageSize = 0;
+ fread(&fontImageSize, 1, sizeof(int), rgsFile);
+
+ if (fontImageSize > 0)
+ {
+ Image imFont = { 0 };
+ imFont.mipmaps = 1;
+ fread(&imFont.width, 1, sizeof(int), rgsFile);
+ fread(&imFont.height, 1, sizeof(int), rgsFile);
+ fread(&imFont.format, 1, sizeof(int), rgsFile);
+ fread(&imFont.data, 1, fontImageSize, rgsFile);
+
+ font.texture = LoadTextureFromImage(imFont);
+ UnloadImage(imFont);
+ }
+
+ // Load font chars data
+ font.chars = (CharInfo *)calloc(font.charsCount, sizeof(CharInfo));
+ for (int i = 0; i < font.charsCount; i++)
+ {
+ fread(&font.chars[i].rec, 1, sizeof(Rectangle), rgsFile);
+ fread(&font.chars[i].value, 1, sizeof(int), rgsFile);
+ fread(&font.chars[i].offsetX, 1, sizeof(int), rgsFile);
+ fread(&font.chars[i].offsetY, 1, sizeof(int), rgsFile);
+ fread(&font.chars[i].advanceX, 1, sizeof(int), rgsFile);
+ }
+
+ GuiFont(font);
+
+ // Set font texture source rectangle to be used as white texture to draw shapes
+ // NOTE: This way, all gui can be draw using a single draw call
+ if ((whiteRec.width != 0) && (whiteRec.height != 0)) SetShapesTexture(font.texture, whiteRec);
+ }
+ }
+ else TraceLog(LOG_WARNING, "[raygui] Invalid style properties file");
+
+ fclose(rgsFile);
+ }
+}
+
+// Load style from a palette values array
+RAYGUIDEF void GuiLoadStyleProps(const int *props, int count)
+{
+ int completeSets = count/(NUM_PROPS_DEFAULT + NUM_PROPS_EXTENDED);
+ int uncompleteSetProps = count%(NUM_PROPS_DEFAULT + NUM_PROPS_EXTENDED);
+
+ // Load style palette values from array (complete property sets)
+ for (int i = 0; i < completeSets; i++)
+ {
+ for (int j = 0; j < (NUM_PROPS_DEFAULT + NUM_PROPS_EXTENDED); i++) GuiSetStyle(i, j, props[i]);
+ }
+
+ // Load style palette values from array (uncomplete property set)
+ for (int k = 0; k < uncompleteSetProps; k++) GuiSetStyle(completeSets, k, props[completeSets*(NUM_PROPS_DEFAULT + NUM_PROPS_EXTENDED) + k]);
+}
+
+// Load style default over global style
+RAYGUIDEF void GuiLoadStyleDefault(void)
+{
+ // We set this variable first to avoid cyclic function calls
+ // when calling GuiSetStyle() and GuiGetStyle()
+ guiStyleLoaded = true;
+
+ // Initialize default LIGHT style property values
+ GuiSetStyle(DEFAULT, BORDER_COLOR_NORMAL, 0x838383ff);
+ GuiSetStyle(DEFAULT, BASE_COLOR_NORMAL, 0xc9c9c9ff);
+ GuiSetStyle(DEFAULT, TEXT_COLOR_NORMAL, 0x686868ff);
+ GuiSetStyle(DEFAULT, BORDER_COLOR_FOCUSED, 0x5bb2d9ff);
+ GuiSetStyle(DEFAULT, BASE_COLOR_FOCUSED, 0xc9effeff);
+ GuiSetStyle(DEFAULT, TEXT_COLOR_FOCUSED, 0x6c9bbcff);
+ GuiSetStyle(DEFAULT, BORDER_COLOR_PRESSED, 0x0492c7ff);
+ GuiSetStyle(DEFAULT, BASE_COLOR_PRESSED, 0x97e8ffff);
+ GuiSetStyle(DEFAULT, TEXT_COLOR_PRESSED, 0x368bafff);
+ GuiSetStyle(DEFAULT, BORDER_COLOR_DISABLED, 0xb5c1c2ff);
+ GuiSetStyle(DEFAULT, BASE_COLOR_DISABLED, 0xe6e9e9ff);
+ GuiSetStyle(DEFAULT, TEXT_COLOR_DISABLED, 0xaeb7b8ff);
+ GuiSetStyle(DEFAULT, BORDER_WIDTH, 1);
+ GuiSetStyle(DEFAULT, INNER_PADDING, 1);
+
+ // Populate all controls with default style
+ for (int i = 1; i < NUM_CONTROLS; i++)
+ {
+ for (int j = 0; j < NUM_PROPS_DEFAULT; j++) GuiSetStyle(i, j, GuiGetStyle(DEFAULT, j));
+ }
+
+ // Initialize extended property values
+ // NOTE: By default, extended property values are initialized to 0
+ GuiSetStyle(DEFAULT, TEXT_SIZE, 10);
+ GuiSetStyle(DEFAULT, TEXT_SPACING, 1);
+ GuiSetStyle(DEFAULT, LINES_COLOR, 0x90abb5ff); // DEFAULT specific property
+ GuiSetStyle(DEFAULT, BACKGROUND_COLOR, 0xf5f5f5ff); // DEFAULT specific property
+
+ GuiSetStyle(BUTTON, BORDER_WIDTH, 2);
+ GuiSetStyle(TOGGLE, GROUP_PADDING, 2);
+ GuiSetStyle(SLIDER, SLIDER_WIDTH, 15);
+ GuiSetStyle(SLIDER, EX_TEXT_PADDING, 5);
+ GuiSetStyle(CHECKBOX, CHECK_TEXT_PADDING, 5);
+ GuiSetStyle(COMBOBOX, SELECTOR_WIDTH, 30);
+ GuiSetStyle(COMBOBOX, SELECTOR_PADDING, 2);
+ GuiSetStyle(DROPDOWNBOX, ARROW_RIGHT_PADDING, 16);
+ GuiSetStyle(TEXTBOX, INNER_PADDING, 4);
+ GuiSetStyle(TEXTBOX, MULTILINE_PADDING, 5);
+ GuiSetStyle(TEXTBOX, SPINNER_BUTTON_PADDING, 20); // SPINNER specific property
+ GuiSetStyle(TEXTBOX, SPINNER_BUTTON_PADDING, 2); // SPINNER specific property
+ GuiSetStyle(TEXTBOX, SPINNER_BUTTON_BORDER_WIDTH, 1); // SPINNER specific property
+ GuiSetStyle(COLORPICKER, COLOR_SELECTOR_SIZE, 6);
+ GuiSetStyle(COLORPICKER, BAR_WIDTH, 0x14);
+ GuiSetStyle(COLORPICKER, BAR_PADDING, 0xa);
+ GuiSetStyle(COLORPICKER, BAR_SELECTOR_HEIGHT, 6);
+ GuiSetStyle(COLORPICKER, BAR_SELECTOR_PADDING, 2);
+ GuiSetStyle(LISTVIEW, ELEMENTS_HEIGHT, 0x1e);
+ GuiSetStyle(LISTVIEW, ELEMENTS_PADDING, 2);
+ GuiSetStyle(LISTVIEW, SCROLLBAR_WIDTH, 10);
+}
+
+// Updates controls style with default values
+RAYGUIDEF void GuiUpdateStyleComplete(void)
+{
+ // Populate all controls with default style
+ // NOTE: Extended style properties are ignored
+ for (int i = 1; i < NUM_CONTROLS; i++)
+ {
+ for (int j = 0; j < NUM_PROPS_DEFAULT; j++) GuiSetStyle(i, j, GuiGetStyle(DEFAULT, j));
+ }
+}
+
+//----------------------------------------------------------------------------------
+// Module specific Functions Definition
+//----------------------------------------------------------------------------------
+
+// Convert color data from RGB to HSV
+// NOTE: Color data should be passed normalized
+static Vector3 ConvertRGBtoHSV(Vector3 rgb)
+{
+ Vector3 hsv = { 0.0f };
+ float min = 0.0f;
+ float max = 0.0f;
+ float delta = 0.0f;
+
+ min = (rgb.x < rgb.y) ? rgb.x : rgb.y;
+ min = (min < rgb.z) ? min : rgb.z;
+
+ max = (rgb.x > rgb.y) ? rgb.x : rgb.y;
+ max = (max > rgb.z) ? max : rgb.z;
+
+ hsv.z = max; // Value
+ delta = max - min;
+
+ if (delta < 0.00001f)
+ {
+ hsv.y = 0.0f;
+ hsv.x = 0.0f; // Undefined, maybe NAN?
+ return hsv;
+ }
+
+ if (max > 0.0f)
+ {
+ // NOTE: If max is 0, this divide would cause a crash
+ hsv.y = (delta/max); // Saturation
+ }
+ else
+ {
+ // NOTE: If max is 0, then r = g = b = 0, s = 0, h is undefined
+ hsv.y = 0.0f;
+ hsv.x = 0.0f; // Undefined, maybe NAN?
+ return hsv;
+ }
+
+ // NOTE: Comparing float values could not work properly
+ if (rgb.x >= max) hsv.x = (rgb.y - rgb.z)/delta; // Between yellow & magenta
+ else
+ {
+ if (rgb.y >= max) hsv.x = 2.0f + (rgb.z - rgb.x)/delta; // Between cyan & yellow
+ else hsv.x = 4.0f + (rgb.x - rgb.y)/delta; // Between magenta & cyan
+ }
+
+ hsv.x *= 60.0f; // Convert to degrees
+
+ if (hsv.x < 0.0f) hsv.x += 360.0f;
+
+ return hsv;
+}
+
+// Convert color data from HSV to RGB
+// NOTE: Color data should be passed normalized
+static Vector3 ConvertHSVtoRGB(Vector3 hsv)
+{
+ Vector3 rgb = { 0.0f };
+ float hh = 0.0f, p = 0.0f, q = 0.0f, t = 0.0f, ff = 0.0f;
+ long i = 0;
+
+ // NOTE: Comparing float values could not work properly
+ if (hsv.y <= 0.0f)
+ {
+ rgb.x = hsv.z;
+ rgb.y = hsv.z;
+ rgb.z = hsv.z;
+ return rgb;
+ }
+
+ hh = hsv.x;
+ if (hh >= 360.0f) hh = 0.0f;
+ hh /= 60.0f;
+
+ i = (long)hh;
+ ff = hh - i;
+ p = hsv.z*(1.0f - hsv.y);
+ q = hsv.z*(1.0f - (hsv.y*ff));
+ t = hsv.z*(1.0f - (hsv.y*(1.0f - ff)));
+
+ switch (i)
+ {
+ case 0:
+ {
+ rgb.x = hsv.z;
+ rgb.y = t;
+ rgb.z = p;
+ } break;
+ case 1:
+ {
+ rgb.x = q;
+ rgb.y = hsv.z;
+ rgb.z = p;
+ } break;
+ case 2:
+ {
+ rgb.x = p;
+ rgb.y = hsv.z;
+ rgb.z = t;
+ } break;
+ case 3:
+ {
+ rgb.x = p;
+ rgb.y = q;
+ rgb.z = hsv.z;
+ } break;
+ case 4:
+ {
+ rgb.x = t;
+ rgb.y = p;
+ rgb.z = hsv.z;
+ } break;
+ case 5:
+ default:
+ {
+ rgb.x = hsv.z;
+ rgb.y = p;
+ rgb.z = q;
+ } break;
+ }
+
+ return rgb;
+}
+
+#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 ColorToInt(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;
+}
+
+// Color fade-in or fade-out, alpha goes from 0.0f to 1.0f
+Color Fade(Color color, float alpha)
+{
+ if (alpha < 0.0f) alpha = 0.0f;
+ else if (alpha > 1.0f) alpha = 1.0f;
+
+ return (Color){color.r, color.g, color.b, (unsigned char)(255.0f*alpha)};
+}
+
+// Formatting of text with variables to 'embed'
+static const char *FormatText(const char *text, ...)
+{
+ #define MAX_FORMATTEXT_LENGTH 64
+
+ static char buffer[MAX_FORMATTEXT_LENGTH];
+
+ va_list args;
+ va_start(args, text);
+ vsprintf(buffer, text, args);
+ va_end(args);
+
+ return buffer;
+}
+#endif // RAYGUI_STANDALONE
+
+#endif // RAYGUI_IMPLEMENTATION
diff --git a/Generator/raylib.h b/Generator/raylib.h
new file mode 100644
index 0000000..aa5bd16
--- /dev/null
+++ b/Generator/raylib.h
@@ -0,0 +1,1284 @@
+/**********************************************************************************************
+*
+* raylib - A simple and easy-to-use library to enjoy videogames programming (www.raylib.com)
+*
+* FEATURES:
+* - NO external dependencies, all required libraries included with raylib
+* - Multiple platforms support: Windows, Linux, FreeBSD, OpenBSD, NetBSD, DragonFly, MacOS, UWP, Android, Raspberry Pi, HTML5.
+* - Written in plain C code (C99) in PascalCase/camelCase notation
+* - Hardware accelerated with OpenGL (1.1, 2.1, 3.3 or ES2 - choose at compile)
+* - Unique OpenGL abstraction layer (usable as standalone module): [rlgl]
+* - Powerful fonts module with Fonts support (XNA fonts, AngelCode fonts, TTF)
+* - Outstanding texture formats support, including compressed formats (DXT, ETC, ASTC)
+* - Full 3d support for 3d Shapes, Models, Billboards, Heightmaps and more!
+* - Flexible Materials system, supporting classic maps and PBR maps
+* - Shaders support, including Model shaders and Postprocessing shaders
+* - Powerful math module for Vector, Matrix and Quaternion operations: [raymath]
+* - Audio loading and playing with streaming support (WAV, OGG, MP3, FLAC, XM, MOD)
+* - VR stereo rendering with configurable HMD device parameters
+* - Complete bindings to LUA (raylib-lua) and Go (raylib-go)
+*
+* NOTES:
+* One custom font is loaded by default when InitWindow() [core]
+* If using OpenGL 3.3 or ES2, one default shader is loaded automatically (internally defined) [rlgl]
+* If using OpenGL 3.3 or ES2, several vertex buffers (VAO/VBO) are created to manage lines-triangles-quads
+*
+* DEPENDENCIES (included):
+* rglfw (github.com/glfw/glfw) for window/context management and input (only PLATFORM_DESKTOP) [core]
+* glad (github.com/Dav1dde/glad) for OpenGL extensions loading (3.3 Core profile, only PLATFORM_DESKTOP) [rlgl]
+* mini_al (github.com/dr-soft/mini_al) for audio device/context management [audio]
+*
+* OPTIONAL DEPENDENCIES (included):
+* stb_image (Sean Barret) for images loading (BMP, TGA, PNG, JPEG, HDR...) [textures]
+* stb_image_resize (Sean Barret) for image resizing algorythms [textures]
+* stb_image_write (Sean Barret) for image writting (PNG) [utils]
+* stb_truetype (Sean Barret) for ttf fonts loading [text]
+* stb_rect_pack (Sean Barret) for rectangles packing [text]
+* stb_vorbis (Sean Barret) for OGG audio loading [audio]
+* stb_perlin (Sean Barret) for Perlin noise image generation [textures]
+* par_shapes (Philip Rideout) for parametric 3d shapes generation [models]
+* jar_xm (Joshua Reisenauer) for XM audio module loading [audio]
+* jar_mod (Joshua Reisenauer) for MOD audio module loading [audio]
+* dr_flac (David Reid) for FLAC audio file loading [audio]
+* dr_mp3 (David Reid) for MP3 audio file loading [audio]
+* rgif (Charlie Tangora, Ramon Santamaria) for GIF recording [core]
+*
+*
+* LICENSE: zlib/libpng
+*
+* raylib is licensed under an unmodified zlib/libpng license, which is an OSI-certified,
+* BSD-like license that allows static linking with closed source software:
+*
+* Copyright (c) 2013-2018 Ramon Santamaria (@raysan5)
+*
+* 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.
+*
+* Permission is granted to anyone to use this software for any purpose, including commercial
+* applications, and to alter it and redistribute it freely, subject to the following restrictions:
+*
+* 1. The origin of this software must not be misrepresented; you must not claim that you
+* wrote the original software. If you use this software in a product, an acknowledgment
+* in the product documentation would be appreciated but is not required.
+*
+* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
+* as being the original software.
+*
+* 3. This notice may not be removed or altered from any source distribution.
+*
+**********************************************************************************************/
+
+#ifndef RAYLIB_H
+#define RAYLIB_H
+
+#include // Required for: va_list - Only used by TraceLogCallback
+
+#if defined(_WIN32) && defined(BUILD_LIBTYPE_SHARED)
+ #define RLAPI __declspec(dllexport) // We are building raylib as a Win32 shared library (.dll)
+#elif defined(_WIN32) && defined(USE_LIBTYPE_SHARED)
+ #define RLAPI __declspec(dllimport) // We are using raylib as a Win32 shared library (.dll)
+#else
+ #define RLAPI // We are building or using raylib as a static library (or Linux shared library)
+#endif
+
+//----------------------------------------------------------------------------------
+// Some basic Defines
+//----------------------------------------------------------------------------------
+#ifndef PI
+ #define PI 3.14159265358979323846f
+#endif
+
+#define DEG2RAD (PI/180.0f)
+#define RAD2DEG (180.0f/PI)
+
+// raylib Config Flags
+#define FLAG_SHOW_LOGO 1 // Set to show raylib logo at startup
+#define FLAG_FULLSCREEN_MODE 2 // Set to run program in fullscreen
+#define FLAG_WINDOW_RESIZABLE 4 // Set to allow resizable window
+#define FLAG_WINDOW_UNDECORATED 8 // Set to disable window decoration (frame and buttons)
+#define FLAG_WINDOW_TRANSPARENT 16 // Set to allow transparent window
+#define FLAG_MSAA_4X_HINT 32 // Set to try enabling MSAA 4X
+#define FLAG_VSYNC_HINT 64 // Set to try enabling V-Sync on GPU
+
+// Keyboard Function Keys
+#define KEY_SPACE 32
+#define KEY_ESCAPE 256
+#define KEY_ENTER 257
+#define KEY_TAB 258
+#define KEY_BACKSPACE 259
+#define KEY_INSERT 260
+#define KEY_DELETE 261
+#define KEY_RIGHT 262
+#define KEY_LEFT 263
+#define KEY_DOWN 264
+#define KEY_UP 265
+#define KEY_PAGE_UP 266
+#define KEY_PAGE_DOWN 267
+#define KEY_HOME 268
+#define KEY_END 269
+#define KEY_CAPS_LOCK 280
+#define KEY_SCROLL_LOCK 281
+#define KEY_NUM_LOCK 282
+#define KEY_PRINT_SCREEN 283
+#define KEY_PAUSE 284
+#define KEY_F1 290
+#define KEY_F2 291
+#define KEY_F3 292
+#define KEY_F4 293
+#define KEY_F5 294
+#define KEY_F6 295
+#define KEY_F7 296
+#define KEY_F8 297
+#define KEY_F9 298
+#define KEY_F10 299
+#define KEY_F11 300
+#define KEY_F12 301
+#define KEY_LEFT_SHIFT 340
+#define KEY_LEFT_CONTROL 341
+#define KEY_LEFT_ALT 342
+#define KEY_LEFT_SUPER 343
+#define KEY_RIGHT_SHIFT 344
+#define KEY_RIGHT_CONTROL 345
+#define KEY_RIGHT_ALT 346
+#define KEY_RIGHT_SUPER 347
+#define KEY_KB_MENU 348
+#define KEY_LEFT_BRACKET 91
+#define KEY_BACKSLASH 92
+#define KEY_RIGHT_BRACKET 93
+#define KEY_GRAVE 96
+
+// Keyboard Number Pad Keys
+#define KEY_KP_0 320
+#define KEY_KP_1 321
+#define KEY_KP_2 322
+#define KEY_KP_3 323
+#define KEY_KP_4 324
+#define KEY_KP_5 325
+#define KEY_KP_6 326
+#define KEY_KP_7 327
+#define KEY_KP_8 328
+#define KEY_KP_9 329
+#define KEY_KP_DECIMAL 330
+#define KEY_KP_DIVIDE 331
+#define KEY_KP_MULTIPLY 332
+#define KEY_KP_SUBTRACT 333
+#define KEY_KP_ADD 334
+#define KEY_KP_ENTER 335
+#define KEY_KP_EQUAL 336
+
+// Keyboard Alpha Numeric Keys
+#define KEY_APOSTROPHE 39
+#define KEY_COMMA 44
+#define KEY_MINUS 45
+#define KEY_PERIOD 46
+#define KEY_SLASH 47
+#define KEY_ZERO 48
+#define KEY_ONE 49
+#define KEY_TWO 50
+#define KEY_THREE 51
+#define KEY_FOUR 52
+#define KEY_FIVE 53
+#define KEY_SIX 54
+#define KEY_SEVEN 55
+#define KEY_EIGHT 56
+#define KEY_NINE 57
+#define KEY_SEMICOLON 59
+#define KEY_EQUAL 61
+#define KEY_A 65
+#define KEY_B 66
+#define KEY_C 67
+#define KEY_D 68
+#define KEY_E 69
+#define KEY_F 70
+#define KEY_G 71
+#define KEY_H 72
+#define KEY_I 73
+#define KEY_J 74
+#define KEY_K 75
+#define KEY_L 76
+#define KEY_M 77
+#define KEY_N 78
+#define KEY_O 79
+#define KEY_P 80
+#define KEY_Q 81
+#define KEY_R 82
+#define KEY_S 83
+#define KEY_T 84
+#define KEY_U 85
+#define KEY_V 86
+#define KEY_W 87
+#define KEY_X 88
+#define KEY_Y 89
+#define KEY_Z 90
+
+// Android Physical Buttons
+#define KEY_BACK 4
+#define KEY_MENU 82
+#define KEY_VOLUME_UP 24
+#define KEY_VOLUME_DOWN 25
+
+// Mouse Buttons
+#define MOUSE_LEFT_BUTTON 0
+#define MOUSE_RIGHT_BUTTON 1
+#define MOUSE_MIDDLE_BUTTON 2
+
+// Touch points registered
+#define MAX_TOUCH_POINTS 2
+
+// Gamepad Number
+#define GAMEPAD_PLAYER1 0
+#define GAMEPAD_PLAYER2 1
+#define GAMEPAD_PLAYER3 2
+#define GAMEPAD_PLAYER4 3
+
+// Gamepad Buttons/Axis
+
+// PS3 USB Controller Buttons
+#define GAMEPAD_PS3_BUTTON_TRIANGLE 0
+#define GAMEPAD_PS3_BUTTON_CIRCLE 1
+#define GAMEPAD_PS3_BUTTON_CROSS 2
+#define GAMEPAD_PS3_BUTTON_SQUARE 3
+#define GAMEPAD_PS3_BUTTON_L1 6
+#define GAMEPAD_PS3_BUTTON_R1 7
+#define GAMEPAD_PS3_BUTTON_L2 4
+#define GAMEPAD_PS3_BUTTON_R2 5
+#define GAMEPAD_PS3_BUTTON_START 8
+#define GAMEPAD_PS3_BUTTON_SELECT 9
+#define GAMEPAD_PS3_BUTTON_UP 24
+#define GAMEPAD_PS3_BUTTON_RIGHT 25
+#define GAMEPAD_PS3_BUTTON_DOWN 26
+#define GAMEPAD_PS3_BUTTON_LEFT 27
+#define GAMEPAD_PS3_BUTTON_PS 12
+
+// PS3 USB Controller Axis
+#define GAMEPAD_PS3_AXIS_LEFT_X 0
+#define GAMEPAD_PS3_AXIS_LEFT_Y 1
+#define GAMEPAD_PS3_AXIS_RIGHT_X 2
+#define GAMEPAD_PS3_AXIS_RIGHT_Y 5
+#define GAMEPAD_PS3_AXIS_L2 3 // [1..-1] (pressure-level)
+#define GAMEPAD_PS3_AXIS_R2 4 // [1..-1] (pressure-level)
+
+// Xbox360 USB Controller Buttons
+#define GAMEPAD_XBOX_BUTTON_A 0
+#define GAMEPAD_XBOX_BUTTON_B 1
+#define GAMEPAD_XBOX_BUTTON_X 2
+#define GAMEPAD_XBOX_BUTTON_Y 3
+#define GAMEPAD_XBOX_BUTTON_LB 4
+#define GAMEPAD_XBOX_BUTTON_RB 5
+#define GAMEPAD_XBOX_BUTTON_SELECT 6
+#define GAMEPAD_XBOX_BUTTON_START 7
+#define GAMEPAD_XBOX_BUTTON_UP 10
+#define GAMEPAD_XBOX_BUTTON_RIGHT 11
+#define GAMEPAD_XBOX_BUTTON_DOWN 12
+#define GAMEPAD_XBOX_BUTTON_LEFT 13
+#define GAMEPAD_XBOX_BUTTON_HOME 8
+
+// Android Gamepad Controller (SNES CLASSIC)
+#define GAMEPAD_ANDROID_DPAD_UP 19
+#define GAMEPAD_ANDROID_DPAD_DOWN 20
+#define GAMEPAD_ANDROID_DPAD_LEFT 21
+#define GAMEPAD_ANDROID_DPAD_RIGHT 22
+#define GAMEPAD_ANDROID_DPAD_CENTER 23
+
+#define GAMEPAD_ANDROID_BUTTON_A 96
+#define GAMEPAD_ANDROID_BUTTON_B 97
+#define GAMEPAD_ANDROID_BUTTON_C 98
+#define GAMEPAD_ANDROID_BUTTON_X 99
+#define GAMEPAD_ANDROID_BUTTON_Y 100
+#define GAMEPAD_ANDROID_BUTTON_Z 101
+#define GAMEPAD_ANDROID_BUTTON_L1 102
+#define GAMEPAD_ANDROID_BUTTON_R1 103
+#define GAMEPAD_ANDROID_BUTTON_L2 104
+#define GAMEPAD_ANDROID_BUTTON_R2 105
+
+// Xbox360 USB Controller Axis
+// NOTE: For Raspberry Pi, axis must be reconfigured
+#if defined(PLATFORM_RPI)
+ #define GAMEPAD_XBOX_AXIS_LEFT_X 0 // [-1..1] (left->right)
+ #define GAMEPAD_XBOX_AXIS_LEFT_Y 1 // [-1..1] (up->down)
+ #define GAMEPAD_XBOX_AXIS_RIGHT_X 3 // [-1..1] (left->right)
+ #define GAMEPAD_XBOX_AXIS_RIGHT_Y 4 // [-1..1] (up->down)
+ #define GAMEPAD_XBOX_AXIS_LT 2 // [-1..1] (pressure-level)
+ #define GAMEPAD_XBOX_AXIS_RT 5 // [-1..1] (pressure-level)
+#else
+ #define GAMEPAD_XBOX_AXIS_LEFT_X 0 // [-1..1] (left->right)
+ #define GAMEPAD_XBOX_AXIS_LEFT_Y 1 // [1..-1] (up->down)
+ #define GAMEPAD_XBOX_AXIS_RIGHT_X 2 // [-1..1] (left->right)
+ #define GAMEPAD_XBOX_AXIS_RIGHT_Y 3 // [1..-1] (up->down)
+ #define GAMEPAD_XBOX_AXIS_LT 4 // [-1..1] (pressure-level)
+ #define GAMEPAD_XBOX_AXIS_RT 5 // [-1..1] (pressure-level)
+#endif
+
+// NOTE: MSC C++ compiler does not support compound literals (C99 feature)
+// Plain structures in C++ (without constructors) can be initialized from { } initializers.
+#if defined(__cplusplus)
+ #define CLITERAL
+#else
+ #define CLITERAL (Color)
+#endif
+
+// Some Basic Colors
+// NOTE: Custom raylib color palette for amazing visuals on WHITE background
+#define LIGHTGRAY CLITERAL{ 200, 200, 200, 255 } // Light Gray
+#define GRAY CLITERAL{ 130, 130, 130, 255 } // Gray
+#define DARKGRAY CLITERAL{ 80, 80, 80, 255 } // Dark Gray
+#define YELLOW CLITERAL{ 253, 249, 0, 255 } // Yellow
+#define GOLD CLITERAL{ 255, 203, 0, 255 } // Gold
+#define ORANGE CLITERAL{ 255, 161, 0, 255 } // Orange
+#define PINK CLITERAL{ 255, 109, 194, 255 } // Pink
+#define RED CLITERAL{ 230, 41, 55, 255 } // Red
+#define MAROON CLITERAL{ 190, 33, 55, 255 } // Maroon
+#define GREEN CLITERAL{ 0, 228, 48, 255 } // Green
+#define LIME CLITERAL{ 0, 158, 47, 255 } // Lime
+#define DARKGREEN CLITERAL{ 0, 117, 44, 255 } // Dark Green
+#define SKYBLUE CLITERAL{ 102, 191, 255, 255 } // Sky Blue
+#define BLUE CLITERAL{ 0, 121, 241, 255 } // Blue
+#define DARKBLUE CLITERAL{ 0, 82, 172, 255 } // Dark Blue
+#define PURPLE CLITERAL{ 200, 122, 255, 255 } // Purple
+#define VIOLET CLITERAL{ 135, 60, 190, 255 } // Violet
+#define DARKPURPLE CLITERAL{ 112, 31, 126, 255 } // Dark Purple
+#define BEIGE CLITERAL{ 211, 176, 131, 255 } // Beige
+#define BROWN CLITERAL{ 127, 106, 79, 255 } // Brown
+#define DARKBROWN CLITERAL{ 76, 63, 47, 255 } // Dark Brown
+
+#define WHITE CLITERAL{ 255, 255, 255, 255 } // White
+#define BLACK CLITERAL{ 0, 0, 0, 255 } // Black
+#define BLANK CLITERAL{ 0, 0, 0, 0 } // Blank (Transparent)
+#define MAGENTA CLITERAL{ 255, 0, 255, 255 } // Magenta
+#define RAYWHITE CLITERAL{ 245, 245, 245, 255 } // My own White (raylib logo)
+
+// Shader and material limits
+#define MAX_SHADER_LOCATIONS 32 // Maximum number of predefined locations stored in shader struct
+#define MAX_MATERIAL_MAPS 12 // Maximum number of texture maps stored in shader struct
+
+//----------------------------------------------------------------------------------
+// Structures Definition
+//----------------------------------------------------------------------------------
+// Boolean type
+#if defined(__STDC__) && __STDC_VERSION__ >= 199901L
+ #include
+#elif !defined(__cplusplus) && !defined(bool)
+ typedef enum { false, true } bool;
+#endif
+
+// Vector2 type
+typedef struct Vector2 {
+ float x;
+ float y;
+} Vector2;
+
+// Vector3 type
+typedef struct Vector3 {
+ float x;
+ float y;
+ float z;
+} Vector3;
+
+// Vector4 type
+typedef struct Vector4 {
+ float x;
+ float y;
+ float z;
+ float w;
+} Vector4;
+
+// Quaternion type, same as Vector4
+typedef Vector4 Quaternion;
+
+// Matrix type (OpenGL style 4x4 - right handed, column major)
+typedef struct Matrix {
+ float m0, m4, m8, m12;
+ float m1, m5, m9, m13;
+ float m2, m6, m10, m14;
+ float m3, m7, m11, m15;
+} Matrix;
+
+// 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 {
+ float x;
+ float y;
+ float width;
+ float height;
+} Rectangle;
+
+// Image type, bpp always RGBA (32bit)
+// NOTE: Data stored in CPU memory (RAM)
+typedef struct Image {
+ void *data; // Image raw data
+ int width; // Image base width
+ int height; // Image base height
+ int mipmaps; // Mipmap levels, 1 by default
+ int format; // Data format (PixelFormat type)
+} Image;
+
+// Texture2D type
+// NOTE: Data stored in GPU memory
+typedef struct Texture2D {
+ unsigned int id; // OpenGL texture id
+ int width; // Texture base width
+ int height; // Texture base height
+ int mipmaps; // Mipmap levels, 1 by default
+ int format; // Data format (PixelFormat type)
+} Texture2D;
+
+// Texture type, same as Texture2D
+typedef Texture2D Texture;
+
+// RenderTexture2D type, for texture rendering
+typedef struct RenderTexture2D {
+ unsigned int id; // OpenGL Framebuffer Object (FBO) id
+ Texture2D texture; // Color buffer attachment texture
+ Texture2D depth; // Depth buffer attachment texture
+} RenderTexture2D;
+
+// RenderTexture type, same as RenderTexture2D
+typedef RenderTexture2D RenderTexture;
+
+// N-Patch layout info
+typedef struct NPatchInfo {
+ Rectangle sourceRec; // Region in the texture
+ int left; // left border offset
+ int top; // top border offset
+ int right; // right border offset
+ int bottom; // bottom border offset
+ int type; // layout of the n-patch: 3x3, 1x3 or 3x1
+} NPatchInfo;
+
+// Font character info
+typedef struct CharInfo {
+ int value; // Character value (Unicode)
+ Rectangle rec; // Character rectangle in sprite font
+ int offsetX; // Character offset X when drawing
+ int offsetY; // Character offset Y when drawing
+ int advanceX; // Character advance position X
+ unsigned char *data; // Character pixel data (grayscale)
+} CharInfo;
+
+// Font type, includes texture and charSet array data
+typedef struct Font {
+ Texture2D texture; // Font texture
+ int baseSize; // Base size (default chars height)
+ int charsCount; // Number of characters
+ CharInfo *chars; // Characters info data
+} Font;
+
+#define SpriteFont Font // SpriteFont type fallback, defaults to Font
+
+// Camera type, defines a camera position/orientation in 3d space
+typedef struct Camera3D {
+ Vector3 position; // Camera position
+ Vector3 target; // Camera target it looks-at
+ Vector3 up; // Camera up vector (rotation over its axis)
+ float fovy; // Camera field-of-view apperture in Y (degrees) in perspective, used as near plane width in orthographic
+ int type; // Camera type, defines projection type: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC
+} Camera3D;
+
+#define Camera Camera3D // Camera type fallback, defaults to Camera3D
+
+// Camera2D type, defines a 2d camera
+typedef struct Camera2D {
+ Vector2 offset; // Camera offset (displacement from target)
+ Vector2 target; // Camera target (rotation and zoom origin)
+ float rotation; // Camera rotation in degrees
+ float zoom; // Camera zoom (scaling), should be 1.0f by default
+} Camera2D;
+
+// Bounding box type
+typedef struct BoundingBox {
+ Vector3 min; // Minimum vertex box-corner
+ Vector3 max; // Maximum vertex box-corner
+} BoundingBox;
+
+// Vertex data definning a mesh
+// NOTE: Data stored in CPU memory (and GPU)
+typedef struct Mesh {
+ int vertexCount; // Number of vertices stored in arrays
+ int triangleCount; // Number of triangles stored (indexed or not)
+
+ // Default vertex data
+ float *vertices; // Vertex position (XYZ - 3 components per vertex) (shader-location = 0)
+ float *texcoords; // Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1)
+ float *texcoords2; // Vertex second texture coordinates (useful for lightmaps) (shader-location = 5)
+ float *normals; // Vertex normals (XYZ - 3 components per vertex) (shader-location = 2)
+ float *tangents; // Vertex tangents (XYZW - 4 components per vertex) (shader-location = 4)
+ unsigned char *colors; // Vertex colors (RGBA - 4 components per vertex) (shader-location = 3)
+ unsigned short *indices;// Vertex indices (in case vertex data comes indexed)
+
+ // Animation vertex data
+ float *baseVertices; // Vertex base position (required to apply bones transformations)
+ float *baseNormals; // Vertex base normals (required to apply bones transformations)
+ float *weightBias; // Vertex weight bias
+ int *weightId; // Vertex weight id
+
+ // OpenGL identifiers
+ unsigned int vaoId; // OpenGL Vertex Array Object id
+ unsigned int vboId[7]; // OpenGL Vertex Buffer Objects id (default vertex data)
+} Mesh;
+
+// Shader type (generic)
+typedef struct Shader {
+ unsigned int id; // Shader program id
+ int locs[MAX_SHADER_LOCATIONS]; // Shader locations array
+} Shader;
+
+// Material texture map
+typedef struct MaterialMap {
+ Texture2D texture; // Material map texture
+ Color color; // Material map color
+ float value; // Material map value
+} MaterialMap;
+
+// Material type (generic)
+typedef struct Material {
+ Shader shader; // Material shader
+ MaterialMap maps[MAX_MATERIAL_MAPS]; // Material maps
+ float *params; // Material generic parameters (if required)
+} Material;
+
+// Model type
+typedef struct Model {
+ Mesh mesh; // Vertex data buffers (RAM and VRAM)
+ Matrix transform; // Local transform matrix
+ Material material; // Shader and textures data
+} Model;
+
+// Ray type (useful for raycast)
+typedef struct Ray {
+ Vector3 position; // Ray position (origin)
+ Vector3 direction; // Ray direction
+} Ray;
+
+// Raycast hit information
+typedef struct RayHitInfo {
+ bool hit; // Did the ray hit something?
+ float distance; // Distance to nearest hit
+ Vector3 position; // Position of nearest hit
+ Vector3 normal; // Surface normal of hit
+} RayHitInfo;
+
+// Wave type, defines audio wave data
+typedef struct Wave {
+ unsigned int sampleCount; // Number of samples
+ unsigned int sampleRate; // Frequency (samples per second)
+ unsigned int sampleSize; // Bit depth (bits per sample): 8, 16, 32 (24 not supported)
+ unsigned int channels; // Number of channels (1-mono, 2-stereo)
+ void *data; // Buffer data pointer
+} Wave;
+
+// Sound source type
+typedef struct Sound {
+ void *audioBuffer; // Pointer to internal data used by the audio system
+
+ unsigned int source; // Audio source id
+ unsigned int buffer; // Audio buffer id
+ int format; // Audio format specifier
+} Sound;
+
+// Music type (file streaming from memory)
+// NOTE: Anything longer than ~10 seconds should be streamed
+typedef struct MusicData *Music;
+
+// Audio stream type
+// NOTE: Useful to create custom audio streams not bound to a specific file
+typedef struct AudioStream {
+ unsigned int sampleRate; // Frequency (samples per second)
+ unsigned int sampleSize; // Bit depth (bits per sample): 8, 16, 32 (24 not supported)
+ unsigned int channels; // Number of channels (1-mono, 2-stereo)
+
+ void *audioBuffer; // Pointer to internal data used by the audio system.
+
+ int format; // Audio format specifier
+ unsigned int source; // Audio source id
+ unsigned int buffers[2]; // Audio buffers (double buffering)
+} AudioStream;
+
+// Head-Mounted-Display device parameters
+typedef struct VrDeviceInfo {
+ int hResolution; // HMD horizontal resolution in pixels
+ int vResolution; // HMD vertical resolution in pixels
+ float hScreenSize; // HMD horizontal size in meters
+ float vScreenSize; // HMD vertical size in meters
+ float vScreenCenter; // HMD screen center in meters
+ float eyeToScreenDistance; // HMD distance between eye and display in meters
+ float lensSeparationDistance; // HMD lens separation distance in meters
+ float interpupillaryDistance; // HMD IPD (distance between pupils) in meters
+ float lensDistortionValues[4]; // HMD lens distortion constant parameters
+ float chromaAbCorrection[4]; // HMD chromatic aberration correction parameters
+} VrDeviceInfo;
+
+//----------------------------------------------------------------------------------
+// Enumerators Definition
+//----------------------------------------------------------------------------------
+// Trace log type
+typedef enum {
+ LOG_INFO = 1,
+ LOG_WARNING = 2,
+ LOG_ERROR = 4,
+ LOG_DEBUG = 8,
+ LOG_OTHER = 16
+} LogType;
+
+// Shader location point type
+typedef enum {
+ LOC_VERTEX_POSITION = 0,
+ LOC_VERTEX_TEXCOORD01,
+ LOC_VERTEX_TEXCOORD02,
+ LOC_VERTEX_NORMAL,
+ LOC_VERTEX_TANGENT,
+ LOC_VERTEX_COLOR,
+ LOC_MATRIX_MVP,
+ LOC_MATRIX_MODEL,
+ LOC_MATRIX_VIEW,
+ LOC_MATRIX_PROJECTION,
+ LOC_VECTOR_VIEW,
+ LOC_COLOR_DIFFUSE,
+ LOC_COLOR_SPECULAR,
+ LOC_COLOR_AMBIENT,
+ LOC_MAP_ALBEDO, // LOC_MAP_DIFFUSE
+ LOC_MAP_METALNESS, // LOC_MAP_SPECULAR
+ LOC_MAP_NORMAL,
+ LOC_MAP_ROUGHNESS,
+ LOC_MAP_OCCLUSION,
+ LOC_MAP_EMISSION,
+ LOC_MAP_HEIGHT,
+ LOC_MAP_CUBEMAP,
+ LOC_MAP_IRRADIANCE,
+ LOC_MAP_PREFILTER,
+ LOC_MAP_BRDF
+} ShaderLocationIndex;
+
+#define LOC_MAP_DIFFUSE LOC_MAP_ALBEDO
+#define LOC_MAP_SPECULAR LOC_MAP_METALNESS
+
+// Material map type
+typedef enum {
+ MAP_ALBEDO = 0, // MAP_DIFFUSE
+ MAP_METALNESS = 1, // MAP_SPECULAR
+ MAP_NORMAL = 2,
+ MAP_ROUGHNESS = 3,
+ MAP_OCCLUSION,
+ MAP_EMISSION,
+ MAP_HEIGHT,
+ MAP_CUBEMAP, // NOTE: Uses GL_TEXTURE_CUBE_MAP
+ MAP_IRRADIANCE, // NOTE: Uses GL_TEXTURE_CUBE_MAP
+ MAP_PREFILTER, // NOTE: Uses GL_TEXTURE_CUBE_MAP
+ MAP_BRDF
+} TexmapIndex;
+
+#define MAP_DIFFUSE MAP_ALBEDO
+#define MAP_SPECULAR MAP_METALNESS
+
+// Pixel formats
+// NOTE: Support depends on OpenGL version and platform
+typedef enum {
+ UNCOMPRESSED_GRAYSCALE = 1, // 8 bit per pixel (no alpha)
+ UNCOMPRESSED_GRAY_ALPHA, // 8*2 bpp (2 channels)
+ UNCOMPRESSED_R5G6B5, // 16 bpp
+ UNCOMPRESSED_R8G8B8, // 24 bpp
+ UNCOMPRESSED_R5G5B5A1, // 16 bpp (1 bit alpha)
+ UNCOMPRESSED_R4G4B4A4, // 16 bpp (4 bit alpha)
+ UNCOMPRESSED_R8G8B8A8, // 32 bpp
+ UNCOMPRESSED_R32, // 32 bpp (1 channel - float)
+ UNCOMPRESSED_R32G32B32, // 32*3 bpp (3 channels - float)
+ UNCOMPRESSED_R32G32B32A32, // 32*4 bpp (4 channels - float)
+ COMPRESSED_DXT1_RGB, // 4 bpp (no alpha)
+ COMPRESSED_DXT1_RGBA, // 4 bpp (1 bit alpha)
+ COMPRESSED_DXT3_RGBA, // 8 bpp
+ COMPRESSED_DXT5_RGBA, // 8 bpp
+ COMPRESSED_ETC1_RGB, // 4 bpp
+ COMPRESSED_ETC2_RGB, // 4 bpp
+ COMPRESSED_ETC2_EAC_RGBA, // 8 bpp
+ COMPRESSED_PVRT_RGB, // 4 bpp
+ COMPRESSED_PVRT_RGBA, // 4 bpp
+ COMPRESSED_ASTC_4x4_RGBA, // 8 bpp
+ COMPRESSED_ASTC_8x8_RGBA // 2 bpp
+} PixelFormat;
+
+// Texture parameters: filter mode
+// NOTE 1: Filtering considers mipmaps if available in the texture
+// NOTE 2: Filter is accordingly set for minification and magnification
+typedef enum {
+ FILTER_POINT = 0, // No filter, just pixel aproximation
+ FILTER_BILINEAR, // Linear filtering
+ FILTER_TRILINEAR, // Trilinear filtering (linear with mipmaps)
+ FILTER_ANISOTROPIC_4X, // Anisotropic filtering 4x
+ FILTER_ANISOTROPIC_8X, // Anisotropic filtering 8x
+ FILTER_ANISOTROPIC_16X, // Anisotropic filtering 16x
+} TextureFilterMode;
+
+// Texture parameters: wrap mode
+typedef enum {
+ WRAP_REPEAT = 0,
+ WRAP_CLAMP,
+ WRAP_MIRROR
+} TextureWrapMode;
+
+// Font type, defines generation method
+typedef enum {
+ FONT_DEFAULT = 0, // Default font generation, anti-aliased
+ FONT_BITMAP, // Bitmap font generation, no anti-aliasing
+ FONT_SDF // SDF font generation, requires external shader
+} FontType;
+
+// Color blending modes (pre-defined)
+typedef enum {
+ BLEND_ALPHA = 0,
+ BLEND_ADDITIVE,
+ BLEND_MULTIPLIED
+} BlendMode;
+
+// Gestures type
+// NOTE: It could be used as flags to enable only some gestures
+typedef enum {
+ GESTURE_NONE = 0,
+ GESTURE_TAP = 1,
+ GESTURE_DOUBLETAP = 2,
+ GESTURE_HOLD = 4,
+ GESTURE_DRAG = 8,
+ GESTURE_SWIPE_RIGHT = 16,
+ GESTURE_SWIPE_LEFT = 32,
+ GESTURE_SWIPE_UP = 64,
+ GESTURE_SWIPE_DOWN = 128,
+ GESTURE_PINCH_IN = 256,
+ GESTURE_PINCH_OUT = 512
+} Gestures;
+
+// Camera system modes
+typedef enum {
+ CAMERA_CUSTOM = 0,
+ CAMERA_FREE,
+ CAMERA_ORBITAL,
+ CAMERA_FIRST_PERSON,
+ CAMERA_THIRD_PERSON
+} CameraMode;
+
+// Camera projection modes
+typedef enum {
+ CAMERA_PERSPECTIVE = 0,
+ CAMERA_ORTHOGRAPHIC
+} CameraType;
+
+// Head Mounted Display devices
+typedef enum {
+ HMD_DEFAULT_DEVICE = 0,
+ HMD_OCULUS_RIFT_DK2,
+ HMD_OCULUS_RIFT_CV1,
+ HMD_OCULUS_GO,
+ HMD_VALVE_HTC_VIVE,
+ HMD_SONY_PSVR
+} VrDeviceType;
+
+// Type of n-patch
+typedef enum {
+ NPT_9PATCH = 0, // 3x3
+ NPT_3PATCH_VERTICAL, // 1x3
+ NPT_3PATCH_HORIZONTAL // 3x1
+} NPatchType;
+
+// Callbacks to be implemented by users
+typedef void (*TraceLogCallback)(int msgType, const char *text, va_list args);
+
+#if defined(__cplusplus)
+extern "C" { // Prevents name mangling of functions
+#endif
+
+//------------------------------------------------------------------------------------
+// Global Variables Definition
+//------------------------------------------------------------------------------------
+// It's lonely here...
+
+//------------------------------------------------------------------------------------
+// Window and Graphics Device Functions (Module: core)
+//------------------------------------------------------------------------------------
+
+// Window-related functions
+RLAPI void InitWindow(int width, int height, const char *title); // Initialize window and OpenGL context
+RLAPI void CloseWindow(void); // Close window and unload OpenGL context
+RLAPI bool IsWindowReady(void); // Check if window has been initialized successfully
+RLAPI bool WindowShouldClose(void); // Check if KEY_ESCAPE pressed or Close icon pressed
+RLAPI bool IsWindowMinimized(void); // Check if window has been minimized (or lost focus)
+RLAPI void ToggleFullscreen(void); // Toggle fullscreen mode (only PLATFORM_DESKTOP)
+RLAPI void SetWindowIcon(Image image); // Set icon for window (only PLATFORM_DESKTOP)
+RLAPI void SetWindowTitle(const char *title); // Set title for window (only PLATFORM_DESKTOP)
+RLAPI void SetWindowPosition(int x, int y); // Set window position on screen (only PLATFORM_DESKTOP)
+RLAPI void SetWindowMonitor(int monitor); // Set monitor for the current window (fullscreen mode)
+RLAPI void SetWindowMinSize(int width, int height); // Set window minimum dimensions (for FLAG_WINDOW_RESIZABLE)
+RLAPI void SetWindowSize(int width, int height); // Set window dimensions
+RLAPI int GetScreenWidth(void); // Get current screen width
+RLAPI int GetScreenHeight(void); // Get current screen height
+RLAPI void *GetWindowHandle(void); // Get native window handle
+RLAPI int GetMonitorCount(void); // Get number of connected monitors
+RLAPI int GetMonitorWidth(int monitor); // Get primary monitor width
+RLAPI int GetMonitorHeight(int monitor); // Get primary monitor height
+RLAPI int GetMonitorPhysicalWidth(int monitor); // Get primary monitor physical width in millimetres
+RLAPI int GetMonitorPhysicalHeight(int monitor); // Get primary monitor physical height in millimetres
+RLAPI const char *GetMonitorName(int monitor); // Get the human-readable, UTF-8 encoded name of the primary monitor
+
+// Cursor-related functions
+RLAPI void ShowCursor(void); // Shows cursor
+RLAPI void HideCursor(void); // Hides cursor
+RLAPI bool IsCursorHidden(void); // Check if cursor is not visible
+RLAPI void EnableCursor(void); // Enables cursor (unlock cursor)
+RLAPI void DisableCursor(void); // Disables cursor (lock cursor)
+
+// Drawing-related functions
+RLAPI void ClearBackground(Color color); // Set background color (framebuffer clear color)
+RLAPI void BeginDrawing(void); // Setup canvas (framebuffer) to start drawing
+RLAPI void EndDrawing(void); // End canvas drawing and swap buffers (double buffering)
+RLAPI void BeginMode2D(Camera2D camera); // Initialize 2D mode with custom camera (2D)
+RLAPI void EndMode2D(void); // Ends 2D mode with custom camera
+RLAPI void BeginMode3D(Camera3D camera); // Initializes 3D mode with custom camera (3D)
+RLAPI void EndMode3D(void); // Ends 3D mode and returns to default 2D orthographic mode
+RLAPI void BeginTextureMode(RenderTexture2D target); // Initializes render texture for drawing
+RLAPI void EndTextureMode(void); // Ends drawing to render texture
+
+// Screen-space-related functions
+RLAPI Ray GetMouseRay(Vector2 mousePosition, Camera camera); // Returns a ray trace from mouse position
+RLAPI Vector2 GetWorldToScreen(Vector3 position, Camera camera); // Returns the screen space position for a 3d world space position
+RLAPI Matrix GetCameraMatrix(Camera camera); // Returns camera transform matrix (view matrix)
+
+// timing-related functions
+RLAPI void SetTargetFPS(int fps); // Set target FPS (maximum)
+RLAPI int GetFPS(void); // Returns current FPS
+RLAPI float GetFrameTime(void); // Returns time in seconds for last frame drawn
+RLAPI double GetTime(void); // Returns elapsed time in seconds since InitWindow()
+
+// Color-related functions
+RLAPI int ColorToInt(Color color); // Returns hexadecimal value for a Color
+RLAPI Vector4 ColorNormalize(Color color); // Returns color normalized as float [0..1]
+RLAPI Vector3 ColorToHSV(Color color); // Returns HSV values for a Color
+RLAPI Color GetColor(int hexValue); // Returns a Color struct from hexadecimal value
+RLAPI Color Fade(Color color, float alpha); // Color fade-in or fade-out, alpha goes from 0.0f to 1.0f
+
+// Misc. functions
+RLAPI void ShowLogo(void); // Activate raylib logo at startup (can be done with flags)
+RLAPI void SetConfigFlags(unsigned char flags); // Setup window configuration flags (view FLAGS)
+RLAPI void SetTraceLog(unsigned char types); // Enable trace log message types (bit flags based)
+RLAPI void SetTraceLogCallback(TraceLogCallback callback); // Set a trace log callback to enable custom logging bypassing raylib's one
+RLAPI void TraceLog(int logType, const char *text, ...); // Show trace log messages (LOG_INFO, LOG_WARNING, LOG_ERROR, LOG_DEBUG)
+RLAPI void TakeScreenshot(const char *fileName); // Takes a screenshot of current screen (saved a .png)
+RLAPI int GetRandomValue(int min, int max); // Returns a random value between min and max (both included)
+
+// Files management functions
+RLAPI bool FileExists(const char *fileName); // Check if file exists
+RLAPI bool IsFileExtension(const char *fileName, const char *ext);// Check file extension
+RLAPI const char *GetExtension(const char *fileName); // Get pointer to extension for a filename string
+RLAPI const char *GetFileName(const char *filePath); // Get pointer to filename for a path string
+RLAPI const char *GetFileNameWithoutExt(const char *filePath); // Get filename string without extension (memory should be freed)
+RLAPI const char *GetDirectoryPath(const char *fileName); // Get full path for a given fileName (uses static string)
+RLAPI const char *GetWorkingDirectory(void); // Get current working directory (uses static string)
+RLAPI char **GetDirectoryFiles(const char *dirPath, int *count); // Get filenames in a directory path (memory should be freed)
+RLAPI void ClearDirectoryFiles(void); // Clear directory files paths buffers (free memory)
+RLAPI bool ChangeDirectory(const char *dir); // Change working directory, returns true if success
+RLAPI bool IsFileDropped(void); // Check if a file has been dropped into window
+RLAPI char **GetDroppedFiles(int *count); // Get dropped files names (memory should be freed)
+RLAPI void ClearDroppedFiles(void); // Clear dropped files paths buffer (free memory)
+RLAPI long GetFileModTime(const char *fileName); // Get file modification time (last write time)
+
+// Persistent storage management
+RLAPI void StorageSaveValue(int position, int value); // Save integer value to storage file (to defined position)
+RLAPI int StorageLoadValue(int position); // Load integer value from storage file (from defined position)
+
+//------------------------------------------------------------------------------------
+// Input Handling Functions (Module: core)
+//------------------------------------------------------------------------------------
+
+// Input-related functions: keyboard
+RLAPI bool IsKeyPressed(int key); // Detect if a key has been pressed once
+RLAPI bool IsKeyDown(int key); // Detect if a key is being pressed
+RLAPI bool IsKeyReleased(int key); // Detect if a key has been released once
+RLAPI bool IsKeyUp(int key); // Detect if a key is NOT being pressed
+RLAPI int GetKeyPressed(void); // Get latest key pressed
+RLAPI void SetExitKey(int key); // Set a custom key to exit program (default is ESC)
+
+// Input-related functions: gamepads
+RLAPI bool IsGamepadAvailable(int gamepad); // Detect if a gamepad is available
+RLAPI bool IsGamepadName(int gamepad, const char *name); // Check gamepad name (if available)
+RLAPI const char *GetGamepadName(int gamepad); // Return gamepad internal name id
+RLAPI bool IsGamepadButtonPressed(int gamepad, int button); // Detect if a gamepad button has been pressed once
+RLAPI bool IsGamepadButtonDown(int gamepad, int button); // Detect if a gamepad button is being pressed
+RLAPI bool IsGamepadButtonReleased(int gamepad, int button); // Detect if a gamepad button has been released once
+RLAPI bool IsGamepadButtonUp(int gamepad, int button); // Detect if a gamepad button is NOT being pressed
+RLAPI int GetGamepadButtonPressed(void); // Get the last gamepad button pressed
+RLAPI int GetGamepadAxisCount(int gamepad); // Return gamepad axis count for a gamepad
+RLAPI float GetGamepadAxisMovement(int gamepad, int axis); // Return axis movement value for a gamepad axis
+
+// Input-related functions: mouse
+RLAPI bool IsMouseButtonPressed(int button); // Detect if a mouse button has been pressed once
+RLAPI bool IsMouseButtonDown(int button); // Detect if a mouse button is being pressed
+RLAPI bool IsMouseButtonReleased(int button); // Detect if a mouse button has been released once
+RLAPI bool IsMouseButtonUp(int button); // Detect if a mouse button is NOT being pressed
+RLAPI int GetMouseX(void); // Returns mouse position X
+RLAPI int GetMouseY(void); // Returns mouse position Y
+RLAPI Vector2 GetMousePosition(void); // Returns mouse position XY
+RLAPI void SetMousePosition(Vector2 position); // Set mouse position XY
+RLAPI void SetMouseScale(float scale); // Set mouse scaling
+RLAPI int GetMouseWheelMove(void); // Returns mouse wheel movement Y
+
+// Input-related functions: touch
+RLAPI int GetTouchX(void); // Returns touch position X for touch point 0 (relative to screen size)
+RLAPI int GetTouchY(void); // Returns touch position Y for touch point 0 (relative to screen size)
+RLAPI Vector2 GetTouchPosition(int index); // Returns touch position XY for a touch point index (relative to screen size)
+
+//------------------------------------------------------------------------------------
+// Gestures and Touch Handling Functions (Module: gestures)
+//------------------------------------------------------------------------------------
+RLAPI void SetGesturesEnabled(unsigned int gestureFlags); // Enable a set of gestures using flags
+RLAPI bool IsGestureDetected(int gesture); // Check if a gesture have been detected
+RLAPI int GetGestureDetected(void); // Get latest detected gesture
+RLAPI int GetTouchPointsCount(void); // Get touch points count
+RLAPI float GetGestureHoldDuration(void); // Get gesture hold time in milliseconds
+RLAPI Vector2 GetGestureDragVector(void); // Get gesture drag vector
+RLAPI float GetGestureDragAngle(void); // Get gesture drag angle
+RLAPI Vector2 GetGesturePinchVector(void); // Get gesture pinch delta
+RLAPI float GetGesturePinchAngle(void); // Get gesture pinch angle
+
+//------------------------------------------------------------------------------------
+// Camera System Functions (Module: camera)
+//------------------------------------------------------------------------------------
+RLAPI void SetCameraMode(Camera camera, int mode); // Set camera mode (multiple camera modes available)
+RLAPI void UpdateCamera(Camera *camera); // Update camera position for selected mode
+
+RLAPI void SetCameraPanControl(int panKey); // Set camera pan key to combine with mouse movement (free camera)
+RLAPI void SetCameraAltControl(int altKey); // Set camera alt key to combine with mouse movement (free camera)
+RLAPI void SetCameraSmoothZoomControl(int szKey); // Set camera smooth zoom key to combine with mouse (free camera)
+RLAPI void SetCameraMoveControls(int frontKey, int backKey, int rightKey, int leftKey, int upKey, int downKey); // Set camera move controls (1st person and 3rd person cameras)
+
+//------------------------------------------------------------------------------------
+// Basic Shapes Drawing Functions (Module: shapes)
+//------------------------------------------------------------------------------------
+
+// Basic shapes drawing functions
+RLAPI void DrawPixel(int posX, int posY, Color color); // Draw a pixel
+RLAPI void DrawPixelV(Vector2 position, Color color); // Draw a pixel (Vector version)
+RLAPI void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, Color color); // Draw a line
+RLAPI void DrawLineV(Vector2 startPos, Vector2 endPos, Color color); // Draw a line (Vector version)
+RLAPI void DrawLineEx(Vector2 startPos, Vector2 endPos, float thick, Color color); // Draw a line defining thickness
+RLAPI void DrawLineBezier(Vector2 startPos, Vector2 endPos, float thick, Color color); // Draw a line using cubic-bezier curves in-out
+RLAPI void DrawCircle(int centerX, int centerY, float radius, Color color); // Draw a color-filled circle
+RLAPI void DrawCircleGradient(int centerX, int centerY, float radius, Color color1, Color color2); // Draw a gradient-filled circle
+RLAPI void DrawCircleV(Vector2 center, float radius, Color color); // Draw a color-filled circle (Vector version)
+RLAPI void DrawCircleLines(int centerX, int centerY, float radius, Color color); // Draw circle outline
+RLAPI void DrawRectangle(int posX, int posY, int width, int height, Color color); // Draw a color-filled rectangle
+RLAPI void DrawRectangleV(Vector2 position, Vector2 size, Color color); // Draw a color-filled rectangle (Vector version)
+RLAPI void DrawRectangleRec(Rectangle rec, Color color); // Draw a color-filled rectangle
+RLAPI void DrawRectanglePro(Rectangle rec, Vector2 origin, float rotation, Color color); // Draw a color-filled rectangle with pro parameters
+RLAPI void DrawRectangleGradientV(int posX, int posY, int width, int height, Color color1, Color color2);// Draw a vertical-gradient-filled rectangle
+RLAPI void DrawRectangleGradientH(int posX, int posY, int width, int height, Color color1, Color color2);// Draw a horizontal-gradient-filled rectangle
+RLAPI void DrawRectangleGradientEx(Rectangle rec, Color col1, Color col2, Color col3, Color col4); // Draw a gradient-filled rectangle with custom vertex colors
+RLAPI void DrawRectangleLines(int posX, int posY, int width, int height, Color color); // Draw rectangle outline
+RLAPI void DrawRectangleLinesEx(Rectangle rec, int lineThick, Color color); // Draw rectangle outline with extended parameters
+RLAPI void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw a color-filled triangle
+RLAPI void DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw triangle outline
+RLAPI void DrawPoly(Vector2 center, int sides, float radius, float rotation, Color color); // Draw a regular polygon (Vector version)
+RLAPI void DrawPolyEx(Vector2 *points, int numPoints, Color color); // Draw a closed polygon defined by points
+RLAPI void DrawPolyExLines(Vector2 *points, int numPoints, Color color); // Draw polygon lines
+
+// Basic shapes collision detection functions
+RLAPI bool CheckCollisionRecs(Rectangle rec1, Rectangle rec2); // Check collision between two rectangles
+RLAPI bool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, float radius2); // Check collision between two circles
+RLAPI bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec); // Check collision between circle and rectangle
+RLAPI Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2); // Get collision rectangle for two rectangles collision
+RLAPI bool CheckCollisionPointRec(Vector2 point, Rectangle rec); // Check if point is inside rectangle
+RLAPI bool CheckCollisionPointCircle(Vector2 point, Vector2 center, float radius); // Check if point is inside circle
+RLAPI bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2 p3); // Check if point is inside a triangle
+
+//------------------------------------------------------------------------------------
+// Texture Loading and Drawing Functions (Module: textures)
+//------------------------------------------------------------------------------------
+
+// Image/Texture2D data loading/unloading/saving functions
+RLAPI Image LoadImage(const char *fileName); // Load image from file into CPU memory (RAM)
+RLAPI Image LoadImageEx(Color *pixels, int width, int height); // Load image from Color array data (RGBA - 32bit)
+RLAPI Image LoadImagePro(void *data, int width, int height, int format); // Load image from raw data with parameters
+RLAPI Image LoadImageRaw(const char *fileName, int width, int height, int format, int headerSize); // Load image from RAW file data
+RLAPI void ExportImage(Image image, const char *fileName); // Export image data to file
+RLAPI Texture2D LoadTexture(const char *fileName); // Load texture from file into GPU memory (VRAM)
+RLAPI Texture2D LoadTextureFromImage(Image image); // Load texture from image data
+RLAPI RenderTexture2D LoadRenderTexture(int width, int height); // Load texture for rendering (framebuffer)
+RLAPI void UnloadImage(Image image); // Unload image from CPU memory (RAM)
+RLAPI void UnloadTexture(Texture2D texture); // Unload texture from GPU memory (VRAM)
+RLAPI void UnloadRenderTexture(RenderTexture2D target); // Unload render texture from GPU memory (VRAM)
+RLAPI Color *GetImageData(Image image); // Get pixel data from image as a Color struct array
+RLAPI Vector4 *GetImageDataNormalized(Image image); // Get pixel data from image as Vector4 array (float normalized)
+RLAPI int GetPixelDataSize(int width, int height, int format); // Get pixel data size in bytes (image or texture)
+RLAPI Image GetTextureData(Texture2D texture); // Get pixel data from GPU texture and return an Image
+RLAPI void UpdateTexture(Texture2D texture, const void *pixels); // Update GPU texture with new data
+
+// Image manipulation functions
+RLAPI Image ImageCopy(Image image); // Create an image duplicate (useful for transformations)
+RLAPI void ImageToPOT(Image *image, Color fillColor); // Convert image to POT (power-of-two)
+RLAPI void ImageFormat(Image *image, int newFormat); // Convert image data to desired format
+RLAPI void ImageAlphaMask(Image *image, Image alphaMask); // Apply alpha mask to image
+RLAPI void ImageAlphaClear(Image *image, Color color, float threshold); // Clear alpha channel to desired color
+RLAPI void ImageAlphaCrop(Image *image, float threshold); // Crop image depending on alpha value
+RLAPI void ImageAlphaPremultiply(Image *image); // Premultiply alpha channel
+RLAPI void ImageCrop(Image *image, Rectangle crop); // Crop an image to a defined rectangle
+RLAPI void ImageResize(Image *image, int newWidth, int newHeight); // Resize image (Bicubic scaling algorithm)
+RLAPI void ImageResizeNN(Image *image, int newWidth,int newHeight); // Resize image (Nearest-Neighbor scaling algorithm)
+RLAPI void ImageResizeCanvas(Image *image, int newWidth, int newHeight, int offsetX, int offsetY, Color color); // Resize canvas and fill with color
+RLAPI void ImageMipmaps(Image *image); // Generate all mipmap levels for a provided image
+RLAPI void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp); // Dither image data to 16bpp or lower (Floyd-Steinberg dithering)
+RLAPI Color *ImageExtractPalette(Image image, int maxPaletteSize, int *extractCount); // Extract color palette from image to maximum size (memory should be freed)
+RLAPI Image ImageText(const char *text, int fontSize, Color color); // Create an image from text (default font)
+RLAPI Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Color tint); // Create an image from text (custom sprite font)
+RLAPI void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec); // Draw a source image within a destination image
+RLAPI void ImageDrawRectangle(Image *dst, Vector2 position, Rectangle rec, Color color); // Draw rectangle within an image
+RLAPI void ImageDrawText(Image *dst, Vector2 position, const char *text, int fontSize, Color color); // Draw text (default font) within an image (destination)
+RLAPI void ImageDrawTextEx(Image *dst, Vector2 position, Font font, const char *text, float fontSize, float spacing, Color color); // Draw text (custom sprite font) within an image (destination)
+RLAPI void ImageFlipVertical(Image *image); // Flip image vertically
+RLAPI void ImageFlipHorizontal(Image *image); // Flip image horizontally
+RLAPI void ImageRotateCW(Image *image); // Rotate image clockwise 90deg
+RLAPI void ImageRotateCCW(Image *image); // Rotate image counter-clockwise 90deg
+RLAPI void ImageColorTint(Image *image, Color color); // Modify image color: tint
+RLAPI void ImageColorInvert(Image *image); // Modify image color: invert
+RLAPI void ImageColorGrayscale(Image *image); // Modify image color: grayscale
+RLAPI void ImageColorContrast(Image *image, float contrast); // Modify image color: contrast (-100 to 100)
+RLAPI void ImageColorBrightness(Image *image, int brightness); // Modify image color: brightness (-255 to 255)
+RLAPI void ImageColorReplace(Image *image, Color color, Color replace); // Modify image color: replace color
+
+// Image generation functions
+RLAPI Image GenImageColor(int width, int height, Color color); // Generate image: plain color
+RLAPI Image GenImageGradientV(int width, int height, Color top, Color bottom); // Generate image: vertical gradient
+RLAPI Image GenImageGradientH(int width, int height, Color left, Color right); // Generate image: horizontal gradient
+RLAPI Image GenImageGradientRadial(int width, int height, float density, Color inner, Color outer); // Generate image: radial gradient
+RLAPI Image GenImageChecked(int width, int height, int checksX, int checksY, Color col1, Color col2); // Generate image: checked
+RLAPI Image GenImageWhiteNoise(int width, int height, float factor); // Generate image: white noise
+RLAPI Image GenImagePerlinNoise(int width, int height, int offsetX, int offsetY, float scale); // Generate image: perlin noise
+RLAPI Image GenImageCellular(int width, int height, int tileSize); // Generate image: cellular algorithm. Bigger tileSize means bigger cells
+
+// Texture2D configuration functions
+RLAPI void GenTextureMipmaps(Texture2D *texture); // Generate GPU mipmaps for a texture
+RLAPI void SetTextureFilter(Texture2D texture, int filterMode); // Set texture scaling filter mode
+RLAPI void SetTextureWrap(Texture2D texture, int wrapMode); // Set texture wrapping mode
+
+// Texture2D drawing functions
+RLAPI void DrawTexture(Texture2D texture, int posX, int posY, Color tint); // Draw a Texture2D
+RLAPI void DrawTextureV(Texture2D texture, Vector2 position, Color tint); // Draw a Texture2D with position defined as Vector2
+RLAPI void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); // Draw a Texture2D with extended parameters
+RLAPI void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint); // Draw a part of a texture defined by a rectangle
+RLAPI void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, float rotation, Color tint); // Draw a part of a texture defined by a rectangle with 'pro' parameters
+RLAPI void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle destRec, Vector2 origin, float rotation, Color tint); // Draws a texture (or part of it) that stretches or shrinks nicely.
+
+//------------------------------------------------------------------------------------
+// Font Loading and Text Drawing Functions (Module: text)
+//------------------------------------------------------------------------------------
+
+// Font loading/unloading functions
+RLAPI Font GetFontDefault(void); // Get the default Font
+RLAPI Font LoadFont(const char *fileName); // Load font from file into GPU memory (VRAM)
+RLAPI Font LoadFontEx(const char *fileName, int fontSize, int charsCount, int *fontChars); // Load font from file with extended parameters
+RLAPI CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int charsCount, int type); // Load font data for further use
+RLAPI Image GenImageFontAtlas(CharInfo *chars, int charsCount, int fontSize, int padding, int packMethod); // Generate image font atlas using chars info
+RLAPI void UnloadFont(Font font); // Unload Font from GPU memory (VRAM)
+
+// Text drawing functions
+RLAPI void DrawFPS(int posX, int posY); // Shows current FPS
+RLAPI void DrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font)
+RLAPI void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint); // Draw text using font and additional parameters
+
+// Text misc. functions
+RLAPI int MeasureText(const char *text, int fontSize); // Measure string width for default font
+RLAPI Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing); // Measure string size for Font
+RLAPI const char *FormatText(const char *text, ...); // Formatting of text with variables to 'embed'
+RLAPI const char *SubText(const char *text, int position, int length); // Get a piece of a text string
+RLAPI int GetGlyphIndex(Font font, int character); // Get index position for a unicode character on font
+
+//------------------------------------------------------------------------------------
+// Basic 3d Shapes Drawing Functions (Module: models)
+//------------------------------------------------------------------------------------
+
+// Basic geometric 3D shapes drawing functions
+RLAPI void DrawLine3D(Vector3 startPos, Vector3 endPos, Color color); // Draw a line in 3D world space
+RLAPI void DrawCircle3D(Vector3 center, float radius, Vector3 rotationAxis, float rotationAngle, Color color); // Draw a circle in 3D world space
+RLAPI void DrawCube(Vector3 position, float width, float height, float length, Color color); // Draw cube
+RLAPI void DrawCubeV(Vector3 position, Vector3 size, Color color); // Draw cube (Vector version)
+RLAPI void DrawCubeWires(Vector3 position, float width, float height, float length, Color color); // Draw cube wires
+RLAPI void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float height, float length, Color color); // Draw cube textured
+RLAPI void DrawSphere(Vector3 centerPos, float radius, Color color); // Draw sphere
+RLAPI void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere with extended parameters
+RLAPI void DrawSphereWires(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere wires
+RLAPI void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); // Draw a cylinder/cone
+RLAPI void DrawCylinderWires(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color); // Draw a cylinder/cone wires
+RLAPI void DrawPlane(Vector3 centerPos, Vector2 size, Color color); // Draw a plane XZ
+RLAPI void DrawRay(Ray ray, Color color); // Draw a ray line
+RLAPI void DrawGrid(int slices, float spacing); // Draw a grid (centered at (0, 0, 0))
+RLAPI void DrawGizmo(Vector3 position); // Draw simple gizmo
+//DrawTorus(), DrawTeapot() could be useful?
+
+//------------------------------------------------------------------------------------
+// Model 3d Loading and Drawing Functions (Module: models)
+//------------------------------------------------------------------------------------
+
+// Model loading/unloading functions
+RLAPI Model LoadModel(const char *fileName); // Load model from files (mesh and material)
+RLAPI Model LoadModelFromMesh(Mesh mesh); // Load model from generated mesh
+RLAPI void UnloadModel(Model model); // Unload model from memory (RAM and/or VRAM)
+
+// Mesh loading/unloading functions
+RLAPI Mesh LoadMesh(const char *fileName); // Load mesh from file
+RLAPI void UnloadMesh(Mesh *mesh); // Unload mesh from memory (RAM and/or VRAM)
+RLAPI void ExportMesh(Mesh mesh, const char *fileName); // Export mesh data to file
+
+// Mesh manipulation functions
+RLAPI BoundingBox MeshBoundingBox(Mesh mesh); // Compute mesh bounding box limits
+RLAPI void MeshTangents(Mesh *mesh); // Compute mesh tangents
+RLAPI void MeshBinormals(Mesh *mesh); // Compute mesh binormals
+
+// Mesh generation functions
+RLAPI Mesh GenMeshPlane(float width, float length, int resX, int resZ); // Generate plane mesh (with subdivisions)
+RLAPI Mesh GenMeshCube(float width, float height, float length); // Generate cuboid mesh
+RLAPI Mesh GenMeshSphere(float radius, int rings, int slices); // Generate sphere mesh (standard sphere)
+RLAPI Mesh GenMeshHemiSphere(float radius, int rings, int slices); // Generate half-sphere mesh (no bottom cap)
+RLAPI Mesh GenMeshCylinder(float radius, float height, int slices); // Generate cylinder mesh
+RLAPI Mesh GenMeshTorus(float radius, float size, int radSeg, int sides); // Generate torus mesh
+RLAPI Mesh GenMeshKnot(float radius, float size, int radSeg, int sides); // Generate trefoil knot mesh
+RLAPI Mesh GenMeshHeightmap(Image heightmap, Vector3 size); // Generate heightmap mesh from image data
+RLAPI Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize); // Generate cubes-based map mesh from image data
+
+// Material loading/unloading functions
+RLAPI Material LoadMaterial(const char *fileName); // Load material from file
+RLAPI Material LoadMaterialDefault(void); // Load default material (Supports: DIFFUSE, SPECULAR, NORMAL maps)
+RLAPI void UnloadMaterial(Material material); // Unload material from GPU memory (VRAM)
+
+// Model drawing functions
+RLAPI void DrawModel(Model model, Vector3 position, float scale, Color tint); // Draw a model (with texture if set)
+RLAPI void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model with extended parameters
+RLAPI void DrawModelWires(Model model, Vector3 position, float scale, Color tint); // Draw a model wires (with texture if set)
+RLAPI void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model wires (with texture if set) with extended parameters
+RLAPI void DrawBoundingBox(BoundingBox box, Color color); // Draw bounding box (wires)
+RLAPI void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size, Color tint); // Draw a billboard texture
+RLAPI void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, Vector3 center, float size, Color tint); // Draw a billboard texture defined by sourceRec
+
+// Collision detection functions
+RLAPI bool CheckCollisionSpheres(Vector3 centerA, float radiusA, Vector3 centerB, float radiusB); // Detect collision between two spheres
+RLAPI bool CheckCollisionBoxes(BoundingBox box1, BoundingBox box2); // Detect collision between two bounding boxes
+RLAPI bool CheckCollisionBoxSphere(BoundingBox box, Vector3 centerSphere, float radiusSphere); // Detect collision between box and sphere
+RLAPI bool CheckCollisionRaySphere(Ray ray, Vector3 spherePosition, float sphereRadius); // Detect collision between ray and sphere
+RLAPI bool CheckCollisionRaySphereEx(Ray ray, Vector3 spherePosition, float sphereRadius, Vector3 *collisionPoint); // Detect collision between ray and sphere, returns collision point
+RLAPI bool CheckCollisionRayBox(Ray ray, BoundingBox box); // Detect collision between ray and box
+RLAPI RayHitInfo GetCollisionRayModel(Ray ray, Model *model); // Get collision info between ray and model
+RLAPI RayHitInfo GetCollisionRayTriangle(Ray ray, Vector3 p1, Vector3 p2, Vector3 p3); // Get collision info between ray and triangle
+RLAPI RayHitInfo GetCollisionRayGround(Ray ray, float groundHeight); // Get collision info between ray and ground plane (Y-normal plane)
+
+//------------------------------------------------------------------------------------
+// Shaders System Functions (Module: rlgl)
+// NOTE: This functions are useless when using OpenGL 1.1
+//------------------------------------------------------------------------------------
+
+// Shader loading/unloading functions
+RLAPI char *LoadText(const char *fileName); // Load chars array from text file
+RLAPI Shader LoadShader(const char *vsFileName, const char *fsFileName); // Load shader from files and bind default locations
+RLAPI Shader LoadShaderCode(char *vsCode, char *fsCode); // Load shader from code strings and bind default locations
+RLAPI void UnloadShader(Shader shader); // Unload shader from GPU memory (VRAM)
+
+RLAPI Shader GetShaderDefault(void); // Get default shader
+RLAPI Texture2D GetTextureDefault(void); // Get default texture
+
+// Shader configuration functions
+RLAPI int GetShaderLocation(Shader shader, const char *uniformName); // Get shader uniform location
+RLAPI void SetShaderValue(Shader shader, int uniformLoc, const float *value, int size); // Set shader uniform value (float)
+RLAPI void SetShaderValuei(Shader shader, int uniformLoc, const int *value, int size); // Set shader uniform value (int)
+RLAPI void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat); // Set shader uniform value (matrix 4x4)
+RLAPI void SetMatrixProjection(Matrix proj); // Set a custom projection matrix (replaces internal projection matrix)
+RLAPI void SetMatrixModelview(Matrix view); // Set a custom modelview matrix (replaces internal modelview matrix)
+RLAPI Matrix GetMatrixModelview(); // Get internal modelview matrix
+
+// Texture maps generation (PBR)
+// NOTE: Required shaders should be provided
+RLAPI Texture2D GenTextureCubemap(Shader shader, Texture2D skyHDR, int size); // Generate cubemap texture from HDR texture
+RLAPI Texture2D GenTextureIrradiance(Shader shader, Texture2D cubemap, int size); // Generate irradiance texture using cubemap data
+RLAPI Texture2D GenTexturePrefilter(Shader shader, Texture2D cubemap, int size); // Generate prefilter texture using cubemap data
+RLAPI Texture2D GenTextureBRDF(Shader shader, Texture2D cubemap, int size); // Generate BRDF texture using cubemap data
+
+// Shading begin/end functions
+RLAPI void BeginShaderMode(Shader shader); // Begin custom shader drawing
+RLAPI void EndShaderMode(void); // End custom shader drawing (use default shader)
+RLAPI void BeginBlendMode(int mode); // Begin blending mode (alpha, additive, multiplied)
+RLAPI void EndBlendMode(void); // End blending mode (reset to default: alpha blending)
+
+// VR control functions
+RLAPI VrDeviceInfo GetVrDeviceInfo(int vrDeviceType); // Get VR device information for some standard devices
+RLAPI void InitVrSimulator(VrDeviceInfo info); // Init VR simulator for selected device parameters
+RLAPI void CloseVrSimulator(void); // Close VR simulator for current device
+RLAPI bool IsVrSimulatorReady(void); // Detect if VR simulator is ready
+RLAPI void SetVrDistortionShader(Shader shader); // Set VR distortion shader for stereoscopic rendering
+RLAPI void UpdateVrTracking(Camera *camera); // Update VR tracking (position and orientation) and camera
+RLAPI void ToggleVrMode(void); // Enable/Disable VR experience
+RLAPI void BeginVrDrawing(void); // Begin VR simulator stereo rendering
+RLAPI void EndVrDrawing(void); // End VR simulator stereo rendering
+
+//------------------------------------------------------------------------------------
+// Audio Loading and Playing Functions (Module: audio)
+//------------------------------------------------------------------------------------
+
+// Audio device management functions
+RLAPI void InitAudioDevice(void); // Initialize audio device and context
+RLAPI void CloseAudioDevice(void); // Close the audio device and context
+RLAPI bool IsAudioDeviceReady(void); // Check if audio device has been initialized successfully
+RLAPI void SetMasterVolume(float volume); // Set master volume (listener)
+
+// Wave/Sound loading/unloading functions
+RLAPI Wave LoadWave(const char *fileName); // Load wave data from file
+RLAPI Wave LoadWaveEx(void *data, int sampleCount, int sampleRate, int sampleSize, int channels); // Load wave data from raw array data
+RLAPI Sound LoadSound(const char *fileName); // Load sound from file
+RLAPI Sound LoadSoundFromWave(Wave wave); // Load sound from wave data
+RLAPI void UpdateSound(Sound sound, const void *data, int samplesCount);// Update sound buffer with new data
+RLAPI void UnloadWave(Wave wave); // Unload wave data
+RLAPI void UnloadSound(Sound sound); // Unload sound
+RLAPI void ExportWave(Wave wave, const char *fileName); // Export wave data to file
+
+// Wave/Sound management functions
+RLAPI void PlaySound(Sound sound); // Play a sound
+RLAPI void PauseSound(Sound sound); // Pause a sound
+RLAPI void ResumeSound(Sound sound); // Resume a paused sound
+RLAPI void StopSound(Sound sound); // Stop playing a sound
+RLAPI bool IsSoundPlaying(Sound sound); // Check if a sound is currently playing
+RLAPI void SetSoundVolume(Sound sound, float volume); // Set volume for a sound (1.0 is max level)
+RLAPI void SetSoundPitch(Sound sound, float pitch); // Set pitch for a sound (1.0 is base level)
+RLAPI void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels); // Convert wave data to desired format
+RLAPI Wave WaveCopy(Wave wave); // Copy a wave to a new wave
+RLAPI void WaveCrop(Wave *wave, int initSample, int finalSample); // Crop a wave to defined samples range
+RLAPI float *GetWaveData(Wave wave); // Get samples data from wave as a floats array
+
+// Music management functions
+RLAPI Music LoadMusicStream(const char *fileName); // Load music stream from file
+RLAPI void UnloadMusicStream(Music music); // Unload music stream
+RLAPI void PlayMusicStream(Music music); // Start music playing
+RLAPI void UpdateMusicStream(Music music); // Updates buffers for music streaming
+RLAPI void StopMusicStream(Music music); // Stop music playing
+RLAPI void PauseMusicStream(Music music); // Pause music playing
+RLAPI void ResumeMusicStream(Music music); // Resume playing paused music
+RLAPI bool IsMusicPlaying(Music music); // Check if music is playing
+RLAPI void SetMusicVolume(Music music, float volume); // Set volume for music (1.0 is max level)
+RLAPI void SetMusicPitch(Music music, float pitch); // Set pitch for a music (1.0 is base level)
+RLAPI void SetMusicLoopCount(Music music, int count); // Set music loop count (loop repeats)
+RLAPI float GetMusicTimeLength(Music music); // Get music time length (in seconds)
+RLAPI float GetMusicTimePlayed(Music music); // Get current music time played (in seconds)
+
+// AudioStream management functions
+RLAPI AudioStream InitAudioStream(unsigned int sampleRate, unsigned int sampleSize, unsigned int channels); // Init audio stream (to stream raw audio pcm data)
+RLAPI void UpdateAudioStream(AudioStream stream, const void *data, int samplesCount); // Update audio stream buffers with data
+RLAPI void CloseAudioStream(AudioStream stream); // Close audio stream and free memory
+RLAPI bool IsAudioBufferProcessed(AudioStream stream); // Check if any audio stream buffers requires refill
+RLAPI void PlayAudioStream(AudioStream stream); // Play audio stream
+RLAPI void PauseAudioStream(AudioStream stream); // Pause audio stream
+RLAPI void ResumeAudioStream(AudioStream stream); // Resume audio stream
+RLAPI bool IsAudioStreamPlaying(AudioStream stream); // Check if audio stream is playing
+RLAPI void StopAudioStream(AudioStream stream); // Stop audio stream
+RLAPI void SetAudioStreamVolume(AudioStream stream, float volume); // Set volume for audio stream (1.0 is max level)
+RLAPI void SetAudioStreamPitch(AudioStream stream, float pitch); // Set pitch for audio stream (1.0 is base level)
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif // RAYLIB_H
diff --git a/Generator/raylib.pdb b/Generator/raylib.pdb
new file mode 100644
index 0000000..60e8f14
Binary files /dev/null and b/Generator/raylib.pdb differ
diff --git a/Raylib-cs.sln b/Raylib-cs.sln
index f616bac..d6090d2 100644
--- a/Raylib-cs.sln
+++ b/Raylib-cs.sln
@@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test.NetFX", "Test.NetFX\Te
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test.NetCoreRT", "Test.NetCoreRT\Test.NetCoreRT.csproj", "{98B914D1-8CCF-4895-A9E7-CE4AA8067528}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Generator", "Generator\Generator.csproj", "{0ADEB5B1-BF57-4D45-BE28-176C1D79C764}"
+EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Examples\Examples.projitems*{36e54e2a-5899-4d4d-9d78-120db1b4c7b2}*SharedItemsImports = 13
@@ -75,6 +77,18 @@ Global
{98B914D1-8CCF-4895-A9E7-CE4AA8067528}.Release|x64.Build.0 = Release|x64
{98B914D1-8CCF-4895-A9E7-CE4AA8067528}.Release|x86.ActiveCfg = Release|x86
{98B914D1-8CCF-4895-A9E7-CE4AA8067528}.Release|x86.Build.0 = Release|x86
+ {0ADEB5B1-BF57-4D45-BE28-176C1D79C764}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {0ADEB5B1-BF57-4D45-BE28-176C1D79C764}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {0ADEB5B1-BF57-4D45-BE28-176C1D79C764}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {0ADEB5B1-BF57-4D45-BE28-176C1D79C764}.Debug|x64.Build.0 = Debug|Any CPU
+ {0ADEB5B1-BF57-4D45-BE28-176C1D79C764}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {0ADEB5B1-BF57-4D45-BE28-176C1D79C764}.Debug|x86.Build.0 = Debug|Any CPU
+ {0ADEB5B1-BF57-4D45-BE28-176C1D79C764}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {0ADEB5B1-BF57-4D45-BE28-176C1D79C764}.Release|Any CPU.Build.0 = Release|Any CPU
+ {0ADEB5B1-BF57-4D45-BE28-176C1D79C764}.Release|x64.ActiveCfg = Release|Any CPU
+ {0ADEB5B1-BF57-4D45-BE28-176C1D79C764}.Release|x64.Build.0 = Release|Any CPU
+ {0ADEB5B1-BF57-4D45-BE28-176C1D79C764}.Release|x86.ActiveCfg = Release|Any CPU
+ {0ADEB5B1-BF57-4D45-BE28-176C1D79C764}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/Test.NetCoreRT/Test.NetCoreRT.csproj b/Test.NetCoreRT/Test.NetCoreRT.csproj
index 8173858..3f055da 100644
--- a/Test.NetCoreRT/Test.NetCoreRT.csproj
+++ b/Test.NetCoreRT/Test.NetCoreRT.csproj
@@ -24,7 +24,7 @@
-
+