raylib-cpp
C++ object-oriented wrapper library for raylib.
Functions.hpp
1
4#ifndef RAYLIB_CPP_INCLUDE_FUNCTIONS_HPP_
5#define RAYLIB_CPP_INCLUDE_FUNCTIONS_HPP_
6
7#include <string>
8#include <vector>
9
10#include "./raylib.hpp"
11
15#ifndef RLCPPAPI
16#define RLCPPAPI static
17#endif
18
19namespace raylib {
20
24RLCPPAPI inline void InitWindow(int width, int height, const std::string& title = "raylib") {
25 ::InitWindow(width, height, title.c_str());
26}
27
31RLCPPAPI inline void SetWindowTitle(const std::string& title) {
32 ::SetWindowTitle(title.c_str());
33}
34
38RLCPPAPI inline std::string GetMonitorName(int monitor = 0) {
39 return ::GetMonitorName(monitor);
40}
41
45RLCPPAPI inline void SetClipboardText(const std::string& text) {
46 ::SetClipboardText(text.c_str());
47}
48
52RLCPPAPI inline std::string GetClipboardText() {
53 return ::GetClipboardText();
54}
55
59RLCPPAPI inline void TakeScreenshot(const std::string& fileName) {
60 ::TakeScreenshot(fileName.c_str());
61}
62
66RLCPPAPI inline std::string GetGamepadName(int gamepad) {
67 return ::GetGamepadName(gamepad);
68}
69
73[[maybe_unused]]
74RLCPPAPI std::string LoadFileText(const std::string& fileName) {
75 char* text = ::LoadFileText(fileName.c_str());
76 std::string output(text);
77 ::UnloadFileText(text);
78 return output;
79}
80
84RLCPPAPI inline bool SaveFileText(const std::string& fileName, const std::string& text) {
85 return ::SaveFileText(fileName.c_str(), const_cast<char*>(text.c_str()));
86}
87
91RLCPPAPI inline bool FileExists(const std::string& fileName) {
92 return ::FileExists(fileName.c_str());
93}
94
98RLCPPAPI inline bool DirectoryExists(const std::string& dirPath) {
99 return ::DirectoryExists(dirPath.c_str());
100}
101
105RLCPPAPI inline bool IsFileExtension(const std::string& fileName, const std::string& ext) {
106 return ::IsFileExtension(fileName.c_str(), ext.c_str());
107}
108
112RLCPPAPI inline std::string GetFileExtension(const std::string& fileName) {
113 return ::GetFileExtension(fileName.c_str());
114}
115
119RLCPPAPI inline std::string GetFileName(const std::string& filePath) {
120 return ::GetFileName(filePath.c_str());
121}
122
126RLCPPAPI inline std::string GetFileNameWithoutExt(const std::string& filePath) {
127 return ::GetFileNameWithoutExt(filePath.c_str());
128}
129
133RLCPPAPI inline std::string GetDirectoryPath(const std::string& filePath) {
134 return ::GetDirectoryPath(filePath.c_str());
135}
136
140RLCPPAPI inline std::string GetPrevDirectoryPath(const std::string& dirPath) {
141 return ::GetPrevDirectoryPath(dirPath.c_str());
142}
143
147RLCPPAPI inline std::string GetWorkingDirectory() {
148 return ::GetWorkingDirectory();
149}
150
154[[maybe_unused]]
155RLCPPAPI std::vector<std::string> GetDirectoryFiles(const std::string& dirPath) {
156 int count;
157 char** files = ::GetDirectoryFiles(dirPath.c_str(), &count);
158 std::vector<std::string> output(files, files + count);
159 ::ClearDirectoryFiles();
160 return output;
161}
162
166RLCPPAPI inline bool ChangeDirectory(const std::string& dir) {
167 return ::ChangeDirectory(dir.c_str());
168}
169
173[[maybe_unused]]
174RLCPPAPI std::vector<std::string> GetDroppedFiles() {
175 if (!::IsFileDropped()) {
176 return std::vector<std::string>();
177 }
178 int count;
179 char** files = ::GetDroppedFiles(&count);
180 std::vector<std::string> output(files, files + count);
181 ::ClearDroppedFiles();
182 return output;
183}
184
188RLCPPAPI inline long GetFileModTime(const std::string& fileName) { // NOLINT
189 return ::GetFileModTime(fileName.c_str());
190}
191
195RLCPPAPI inline void OpenURL(const std::string& url) {
196 return ::OpenURL(url.c_str());
197}
198
202RLCPPAPI inline void UpdateCamera(const ::Camera& camera) {
203 ::Camera* cameraPointer = (::Camera*)&camera;
204 ::UpdateCamera(cameraPointer);
205}
206
210RLCPPAPI inline ::Image LoadImage(const std::string& fileName) {
211 return ::LoadImage(fileName.c_str());
212}
213
217RLCPPAPI inline ::Image LoadImageRaw(const std::string& fileName,
218 int width, int height,
219 int format, int headerSize) {
220 return ::LoadImageRaw(fileName.c_str(), width, height, format, headerSize);
221}
222
226RLCPPAPI inline ::Image LoadImageAnim(const std::string& fileName, int *frames) {
227 return ::LoadImageAnim(fileName.c_str(), frames);
228}
229
233RLCPPAPI inline ::Image LoadImageFromMemory(const std::string& fileType,
234 const unsigned char *fileData,
235 int dataSize) {
236 return ::LoadImageFromMemory(fileType.c_str(), fileData, dataSize);
237}
238
242RLCPPAPI inline bool ExportImage(const Image& image, const std::string& fileName) {
243 return ::ExportImage(image, fileName.c_str());
244}
245
249RLCPPAPI inline bool ExportImageAsCode(const Image& image, const std::string& fileName) {
250 return ::ExportImageAsCode(image, fileName.c_str());
251}
252
256RLCPPAPI inline void DrawText(const std::string& text, int posX, int posY, int fontSize, ::Color color) {
257 ::DrawText(text.c_str(), posX, posY, fontSize, color);
258}
259
263RLCPPAPI inline void DrawTextEx(const Font& font, const std::string& text, Vector2 position,
264 float fontSize, float spacing, ::Color tint) {
265 ::DrawTextEx(font, text.c_str(), position, fontSize, spacing, tint);
266}
267
271RLCPPAPI inline void DrawTextPro(const Font& font, const std::string& text, Vector2 position,
272 Vector2 origin, float rotation, float fontSize, float spacing, ::Color tint) {
273 ::DrawTextPro(font, text.c_str(), position, origin, rotation, fontSize, spacing, tint);
274}
275
279RLCPPAPI inline ::Font LoadFont(const std::string& fileName) {
280 return ::LoadFont(fileName.c_str());
281}
282
286RLCPPAPI inline ::Font LoadFontEx(const std::string& fileName, int fontSize, int *fontChars, int charsCount) {
287 return ::LoadFontEx(fileName.c_str(), fontSize, fontChars, charsCount);
288}
289
293RLCPPAPI inline int MeasureText(const std::string& text, int fontSize) {
294 return ::MeasureText(text.c_str(), fontSize);
295}
296
300RLCPPAPI inline bool TextIsEqual(const std::string& text1, const std::string& text2) {
301 return ::TextIsEqual(text1.c_str(), text2.c_str());
302}
303
307RLCPPAPI inline unsigned int TextLength(const std::string& text) {
308 return ::TextLength(text.c_str());
309}
310
314RLAPI inline std::string TextSubtext(const std::string& text, int position, int length) {
315 return ::TextSubtext(text.c_str(), position, length);
316}
317
321RLAPI inline std::string TextReplace(const std::string& text, const std::string& replace, const std::string& by) {
322 const char* input = text.c_str();
323 char* output = ::TextReplace(const_cast<char*>(input), replace.c_str(), by.c_str());
324 if (output != NULL) {
325 std::string stringOutput(output);
326 free(output);
327 return stringOutput;
328 }
329 return "";
330}
331
335RLAPI inline std::string TextInsert(const std::string& text, const std::string& insert, int position) {
336 char* output = ::TextInsert(text.c_str(), insert.c_str(), position);
337 if (output != NULL) {
338 std::string stringOutput(output);
339 free(output);
340 return stringOutput;
341 }
342 return "";
343}
344
348RLAPI inline int TextFindIndex(const std::string& text, const std::string& find) {
349 return ::TextFindIndex(text.c_str(), find.c_str());
350}
351
355RLAPI inline std::string TextToUpper(const std::string& text) {
356 return ::TextToUpper(text.c_str());
357}
358
362RLAPI inline std::string TextToLower(const std::string& text) {
363 return ::TextToLower(text.c_str());
364}
365
369RLAPI inline std::string TextToPascal(const std::string& text) {
370 return ::TextToPascal(text.c_str());
371}
372
376RLAPI inline int TextToInteger(const std::string& text) {
377 return ::TextToInteger(text.c_str());
378}
379
380} // namespace raylib
381
382#endif // RAYLIB_CPP_INCLUDE_FUNCTIONS_HPP_
Font type, includes texture and charSet array data.
Definition: Font.hpp:14
Image type, bpp always RGBA (32bit)
Definition: Image.hpp:16
Vector2 type.
Definition: Vector2.hpp:16
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:8
static std::vector< std::string > GetDroppedFiles()
Get dropped files names.
Definition: Functions.hpp:174
static bool ExportImageAsCode(const Image &image, const std::string &fileName)
Export image as code file (.h) defining an array of bytes.
Definition: Functions.hpp:249
RLAPI std::string TextToUpper(const std::string &text)
Get upper case version of provided string.
Definition: Functions.hpp:355
static bool DirectoryExists(const std::string &dirPath)
Check if directory path exists.
Definition: Functions.hpp:98
RLAPI std::string TextToLower(const std::string &text)
Get lower case version of provided string.
Definition: Functions.hpp:362
static inline ::Image LoadImage(const std::string &fileName)
Load an image.
Definition: Functions.hpp:210
RLAPI int TextFindIndex(const std::string &text, const std::string &find)
Find first text occurrence within a string.
Definition: Functions.hpp:348
static std::string GetWorkingDirectory()
Get current working directory.
Definition: Functions.hpp:147
static unsigned int TextLength(const std::string &text)
Check if two text string are equal.
Definition: Functions.hpp:307
Camera3D Camera
Definition: Camera3D.hpp:161
static std::string GetGamepadName(int gamepad)
Get gamepad internal name id.
Definition: Functions.hpp:66
static inline ::Font LoadFontEx(const std::string &fileName, int fontSize, int *fontChars, int charsCount)
Load font from file (filename must include file extension)
Definition: Functions.hpp:286
static inline ::Font LoadFont(const std::string &fileName)
Load font from file (filename must include file extension)
Definition: Functions.hpp:279
static bool ExportImage(const Image &image, const std::string &fileName)
Export image data to file.
Definition: Functions.hpp:242
static void DrawText(const std::string &text, int posX, int posY, int fontSize, ::Color color)
Draw text (using default font)
Definition: Functions.hpp:256
RLAPI std::string TextSubtext(const std::string &text, int position, int length)
Get text length, checks for '\0' ending.
Definition: Functions.hpp:314
RLAPI std::string TextToPascal(const std::string &text)
Get Pascal case notation version of provided string.
Definition: Functions.hpp:369
static bool SaveFileText(const std::string &fileName, const std::string &text)
Save text data to file (write)
Definition: Functions.hpp:84
static bool IsFileExtension(const std::string &fileName, const std::string &ext)
Check file extension (including point: .png, .wav)
Definition: Functions.hpp:105
static std::vector< std::string > GetDirectoryFiles(const std::string &dirPath)
Get filenames in a directory path.
Definition: Functions.hpp:155
RLAPI int TextToInteger(const std::string &text)
Get integer value from text (negative values not supported)
Definition: Functions.hpp:376
static std::string GetFileName(const std::string &filePath)
Get pointer to filename for a path string.
Definition: Functions.hpp:119
static inline ::Image LoadImageFromMemory(const std::string &fileType, const unsigned char *fileData, int dataSize)
Load image from memory buffer, fileType refers to extension like "png".
Definition: Functions.hpp:233
static std::string GetMonitorName(int monitor=0)
Get the human-readable, UTF-8 encoded name of the primary monitor.
Definition: Functions.hpp:38
static int MeasureText(const std::string &text, int fontSize)
Measure string width for default font.
Definition: Functions.hpp:293
RLAPI std::string TextReplace(const std::string &text, const std::string &replace, const std::string &by)
Replace text string.
Definition: Functions.hpp:321
static void TakeScreenshot(const std::string &fileName)
Takes a screenshot of current screen (saved a .png)
Definition: Functions.hpp:59
static void SetClipboardText(const std::string &text)
Set clipboard text content.
Definition: Functions.hpp:45
RLAPI std::string TextInsert(const std::string &text, const std::string &insert, int position)
Insert text in a position.
Definition: Functions.hpp:335
static void SetWindowTitle(const std::string &title)
Set title for window.
Definition: Functions.hpp:31
static bool FileExists(const std::string &fileName)
Check if file exists.
Definition: Functions.hpp:91
static void InitWindow(int width, int height, const std::string &title="raylib")
Initialize window and OpenGL context.
Definition: Functions.hpp:24
static inline ::Image LoadImageAnim(const std::string &fileName, int *frames)
Load animated image data.
Definition: Functions.hpp:226
static std::string LoadFileText(const std::string &fileName)
Load text data from file (read)
Definition: Functions.hpp:74
static long GetFileModTime(const std::string &fileName)
Get file modification time (last write time)
Definition: Functions.hpp:188
static std::string GetFileExtension(const std::string &fileName)
Get pointer to extension for a filename string (including point: ".png")
Definition: Functions.hpp:112
static void UpdateCamera(const ::Camera &camera)
Update camera depending on selected mode.
Definition: Functions.hpp:202
static void OpenURL(const std::string &url)
Open URL with default system browser (if available)
Definition: Functions.hpp:195
static std::string GetFileNameWithoutExt(const std::string &filePath)
Get filename string without extension.
Definition: Functions.hpp:126
static inline ::Image LoadImageRaw(const std::string &fileName, int width, int height, int format, int headerSize)
Load an image from RAW file data.
Definition: Functions.hpp:217
static void DrawTextPro(const Font &font, const std::string &text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, ::Color tint)
Draw text using Font and pro parameters (rotation)
Definition: Functions.hpp:271
static std::string GetPrevDirectoryPath(const std::string &dirPath)
Get previous directory path for a given path.
Definition: Functions.hpp:140
static void DrawTextEx(const Font &font, const std::string &text, Vector2 position, float fontSize, float spacing, ::Color tint)
Draw text using font and additional parameters.
Definition: Functions.hpp:263
static bool ChangeDirectory(const std::string &dir)
Change working directory, return true on success.
Definition: Functions.hpp:166
static std::string GetDirectoryPath(const std::string &filePath)
Get full path for a given fileName with path.
Definition: Functions.hpp:133
static bool TextIsEqual(const std::string &text1, const std::string &text2)
Check if two text string are equal.
Definition: Functions.hpp:300
static std::string GetClipboardText()
Get clipboard text content.
Definition: Functions.hpp:52