4#ifndef RAYLIB_CPP_INCLUDE_FUNCTIONS_HPP_
5#define RAYLIB_CPP_INCLUDE_FUNCTIONS_HPP_
12#include "./raylib.hpp"
13#include "./RadiansDegrees.hpp"
19#define RLCPPAPI static
27 [[maybe_unused]] RLCPPAPI
inline void InitWindow(
int width,
int height,
const std::string_view title =
"raylib") {
34 [[maybe_unused]] RLCPPAPI
inline void SetWindowTitle(
const std::string_view title) {
41[[maybe_unused]] RLCPPAPI
inline std::string
GetMonitorName(
int monitor = 0) {
42 return ::GetMonitorName(monitor);
56 return ::GetClipboardText();
62 [[maybe_unused]] RLCPPAPI
inline void TakeScreenshot(
const std::string_view fileName) {
70 return ::GetGamepadName(gamepad);
76 [[maybe_unused]] RLCPPAPI std::string
LoadFileText(
const std::string_view fileName) {
78 std::string output(text);
79 ::UnloadFileText(text);
86 [[maybe_unused]] RLCPPAPI
inline bool SaveFileText(
const std::string_view fileName,
const std::string_view text) {
87 return ::SaveFileText(fileName.data(),
const_cast<char*
>(text.data()));
93 [[maybe_unused]] RLCPPAPI
inline bool FileExists(
const std::string_view fileName) {
94 return ::FileExists(fileName.data());
100 [[maybe_unused]] RLCPPAPI
inline bool DirectoryExists(
const std::string_view dirPath) {
101 return ::DirectoryExists(dirPath.data());
107 [[maybe_unused]] RLCPPAPI
inline bool IsFileExtension(
const std::string_view fileName,
const std::string_view ext) {
108 return ::IsFileExtension(fileName.data(), ext.data());
114 [[maybe_unused]] RLCPPAPI
inline std::string
GetFileExtension(
const std::string_view fileName) {
115 return ::GetFileExtension(fileName.data());
121 [[maybe_unused]] RLCPPAPI
inline std::string
GetFileName(
const std::string_view filePath) {
122 return ::GetFileName(filePath.data());
129 return ::GetFileNameWithoutExt(filePath.data());
135 [[maybe_unused]] RLCPPAPI
inline std::string
GetDirectoryPath(
const std::string_view filePath) {
136 return ::GetDirectoryPath(filePath.data());
143 return ::GetPrevDirectoryPath(dirPath.data());
150 return ::GetWorkingDirectory();
156 [[maybe_unused]] RLCPPAPI std::vector<std::string>
LoadDirectoryFiles(
const std::string_view dirPath) {
158 std::vector<std::string> output(files.paths, files.paths + files.count);
159 ::UnloadDirectoryFiles(files);
167 return ::ChangeDirectory(dir.data());
174 if (!::IsFileDropped()) {
175 return std::vector<std::string>();
178 std::vector<std::string> output(files.paths, files.paths + files.count);
179 ::UnloadDroppedFiles(files);
186 [[maybe_unused]] RLCPPAPI
inline long GetFileModTime(
const std::string_view fileName) {
187 return ::GetFileModTime(fileName.data());
193 [[maybe_unused]] RLCPPAPI
inline void OpenURL(
const std::string_view url) {
194 return ::OpenURL(url.data());
200 [[maybe_unused]] RLCPPAPI inline ::Image
LoadImage(
const std::string_view fileName) {
201 return ::LoadImage(fileName.data());
207 [[maybe_unused]] RLCPPAPI inline ::Image
LoadImageRaw(
const std::string_view fileName,
208 int width,
int height,
209 int format,
int headerSize) {
210 return ::LoadImageRaw(fileName.data(), width, height, format, headerSize);
216 [[maybe_unused]] RLCPPAPI inline ::Image
LoadImageAnim(
const std::string_view fileName,
int *frames) {
217 return ::LoadImageAnim(fileName.data(), frames);
223RLCPPAPI inline ::Image
LoadImageAnim(
const std::string_view fileName, std::span<int> frames) {
224 return ::LoadImageAnim(fileName.data(), frames.data());
231 const unsigned char *fileData,
233 return ::LoadImageFromMemory(fileType.data(), fileData, dataSize);
239 [[maybe_unused]] RLCPPAPI
inline bool ExportImage(
const Image& image,
const std::string_view fileName) {
240 return ::ExportImage(image, fileName.data());
247 return ::ExportImageAsCode(image, fileName.data());
253[[maybe_unused]] RLCPPAPI
inline void DrawText(
const char* text,
int posX,
int posY,
int fontSize, ::Color color) {
254 ::DrawText(text, posX, posY, fontSize, color);
260[[maybe_unused]] RLCPPAPI
inline void DrawText(
const std::string_view text,
int posX,
int posY,
int fontSize, ::Color color) {
261 ::DrawText(text.data(), posX, posY, fontSize, color);
267[[maybe_unused]] RLCPPAPI
inline void
269 ::DrawTextEx(font, text, position, fontSize, spacing, tint);
276 float fontSize,
float spacing, ::Color tint) {
277 ::DrawTextEx(font, text.data(), position, fontSize, spacing, tint);
284 Vector2 origin,
Degree rotation,
float fontSize,
float spacing, ::Color tint) {
285 ::DrawTextPro(font, text, position, origin, rotation, fontSize, spacing, tint);
292 Vector2 origin,
Degree rotation,
float fontSize,
float spacing, ::Color tint) {
293 ::DrawTextPro(font, text.data(), position, origin, rotation, fontSize, spacing, tint);
299 [[maybe_unused]] RLCPPAPI inline ::Font
LoadFont(
const std::string_view fileName) {
300 return ::LoadFont(fileName.data());
306 [[maybe_unused]] RLCPPAPI inline ::Font
LoadFontEx(
const std::string_view fileName,
int fontSize,
int *fontChars,
int charsCount) {
307 return ::LoadFontEx(fileName.data(), fontSize, fontChars, charsCount);
313RLCPPAPI inline ::Font
LoadFontEx(
const std::string_view fileName,
int fontSize, std::span<int> fontChars) {
314 return ::LoadFontEx(fileName.data(), fontSize, fontChars.data(),
static_cast<int>(fontChars.size()));
320[[maybe_unused]] RLCPPAPI
inline int MeasureText(
const char* text,
int fontSize) {
321 return ::MeasureText(text, fontSize);
327[[maybe_unused]] RLCPPAPI
inline int MeasureText(
const std::string_view text,
int fontSize) {
328 return ::MeasureText(text.data(), fontSize);
334[[maybe_unused]] RLCPPAPI
inline bool TextIsEqual(
const char* text1,
const char* text2) {
335 return ::TextIsEqual(text1, text2);
341[[maybe_unused]] RLCPPAPI
inline bool TextIsEqual(
const std::string_view text1,
const std::string_view text2) {
342 return ::TextIsEqual(text1.data(), text2.data());
348[[maybe_unused]] RLCPPAPI
inline unsigned int TextLength(
const char* text) {
349 return ::TextLength(text);
355[[maybe_unused]] RLCPPAPI
inline unsigned int TextLength(
const std::string_view text) {
356 return ::TextLength(text.data());
362[[maybe_unused]] RLCPPAPI
inline std::string
TextSubtext(
const std::string_view text,
int position,
int length) {
363 return ::TextSubtext(text.data(), position, length);
369[[maybe_unused]] RLCPPAPI std::string
TextReplace(
const std::string_view text,
const std::string_view replace,
const std::string_view by) {
370 const char* input = text.data();
371 char* output =
::TextReplace(
const_cast<char*
>(input), replace.data(), by.data());
372 if (output != NULL) {
373 std::string stringOutput(output);
383[[maybe_unused]] RLCPPAPI std::string
TextInsert(
const std::string_view text,
const std::string_view insert,
int position) {
384 char* output =
::TextInsert(text.data(), insert.data(), position);
385 if (output != NULL) {
386 std::string stringOutput(output);
396[[maybe_unused]] RLCPPAPI std::vector<std::string>
TextSplit(
const std::string_view text,
char delimiter) {
398 const char** split =
::TextSplit(text.data(), delimiter, &count);
399 return std::vector<std::string>(split, split + count);
405[[maybe_unused]] RLCPPAPI
inline int TextFindIndex(
const std::string_view text,
const std::string_view find) {
406 return ::TextFindIndex(text.data(), find.data());
412[[maybe_unused]] RLCPPAPI
inline std::string
TextToUpper(
const std::string_view text) {
413 return ::TextToUpper(text.data());
419[[maybe_unused]] RLCPPAPI
inline std::string
TextToLower(
const std::string_view text) {
420 return ::TextToLower(text.data());
426[[maybe_unused]] RLCPPAPI
inline std::string
TextToPascal(
const std::string_view text) {
427 return ::TextToPascal(text.data());
433[[maybe_unused]] RLCPPAPI
inline int TextToInteger(
const std::string_view text) {
434 return ::TextToInteger(text.data());
Degree type (allows automatic worry free conversion between radians and degrees)
Font type, includes texture and charSet array data.
Image type, bpp always RGBA (32bit)
All raylib-cpp classes and functions appear in the raylib namespace.
static std::string GetPrevDirectoryPath(const std::string_view dirPath)
Get previous directory path for a given path.
static inline ::Image LoadImage(const std::string_view fileName)
Load an image.
static std::vector< std::string > TextSplit(const std::string_view text, char delimiter)
Split text into multiple strings.
static inline ::Font LoadFont(const std::string_view fileName)
Load font from file (filename must include file extension)
static std::string GetFileName(const std::string_view filePath)
Get pointer to filename for a path string.
static bool FileExists(const std::string_view fileName)
Check if file exists.
static inline ::Image LoadImageFromMemory(const std::string_view fileType, const unsigned char *fileData, int dataSize)
Load image from memory buffer, fileType refers to extension like "png".
static int TextToInteger(const std::string_view text)
Get integer value from text (negative values not supported)
static bool ExportImageAsCode(const Image &image, const std::string_view fileName)
Export image as code file (.h) defining an array of bytes.
static std::vector< std::string > LoadDirectoryFiles(const std::string_view dirPath)
Get filenames in a directory path.
static inline ::Image LoadImageAnim(const std::string_view fileName, int *frames)
Load animated image data.
static bool IsFileExtension(const std::string_view fileName, const std::string_view ext)
Check file extension (including point: .png, .wav)
static std::string GetWorkingDirectory()
Get current working directory.
static bool DirectoryExists(const std::string_view dirPath)
Check if directory path exists.
static std::string GetGamepadName(int gamepad)
Get gamepad internal name id.
static std::vector< std::string > LoadDroppedFiles()
Get dropped files names.
static void DrawText(const char *text, int posX, int posY, int fontSize, ::Color color)
Draw text (using default font)
static bool ChangeDirectory(const std::string_view dir)
Change working directory, return true on success.
static inline ::Font LoadFontEx(const std::string_view fileName, int fontSize, int *fontChars, int charsCount)
Load font from file (filename must include file extension)
static void SetWindowTitle(const std::string_view title)
Set title for window.
static void TakeScreenshot(const std::string_view fileName)
Takes a screenshot of current screen (saved a .png)
static bool TextIsEqual(const char *text1, const char *text2)
Check if two text string are equal.
static std::string GetFileNameWithoutExt(const std::string_view filePath)
Get filename string without extension.
static std::string TextReplace(const std::string_view text, const std::string_view replace, const std::string_view by)
Replace text string.
static std::string GetDirectoryPath(const std::string_view filePath)
Get full path for a given fileName with path.
static std::string TextSubtext(const std::string_view text, int position, int length)
Get text length, checks for '\0' ending.
static std::string GetMonitorName(int monitor=0)
Get the human-readable, UTF-8 encoded name of the primary monitor.
static inline ::Image LoadImageRaw(const std::string_view fileName, int width, int height, int format, int headerSize)
Load an image from RAW file data.
static std::string TextToLower(const std::string_view text)
Get lower case version of provided string.
static unsigned int TextLength(const char *text)
Check if two text string are equal.
static std::string TextToUpper(const std::string_view text)
Get upper case version of provided string.
static void InitWindow(int width, int height, const std::string_view title="raylib")
Initialize window and OpenGL context.
static int TextFindIndex(const std::string_view text, const std::string_view find)
Find first text occurrence within a string.
static bool ExportImage(const Image &image, const std::string_view fileName)
Export image data to file.
static long GetFileModTime(const std::string_view fileName)
Get file modification time (last write time)
static std::string LoadFileText(const std::string_view fileName)
Load text data from file (read)
static void DrawTextPro(const Font &font, const char *text, Vector2 position, Vector2 origin, Degree rotation, float fontSize, float spacing, ::Color tint)
Draw text using Font and pro parameters (rotation)
static bool SaveFileText(const std::string_view fileName, const std::string_view text)
Save text data to file (write)
static std::string TextToPascal(const std::string_view text)
Get Pascal case notation version of provided string.
static void OpenURL(const std::string_view url)
Open URL with default system browser (if available)
static std::string GetFileExtension(const std::string_view fileName)
Get pointer to extension for a filename string (including point: ".png")
static void SetClipboardText(const std::string_view text)
Set clipboard text content.
static void DrawTextEx(const Font &font, char *text, Vector2 position, float fontSize, float spacing, ::Color tint)
Draw text using font and additional parameters.
static int MeasureText(const char *text, int fontSize)
Measure string width for default font.
static std::string GetClipboardText()
Get clipboard text content.
static std::string TextInsert(const std::string_view text, const std::string_view insert, int position)
Insert text in a position.