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 
19 namespace raylib {
20 
24 RLCPPAPI inline void InitWindow(int width, int height, const std::string& title = "raylib") {
25  ::InitWindow(width, height, title.c_str());
26 }
27 
31 RLCPPAPI inline void SetWindowTitle(const std::string& title) {
32  ::SetWindowTitle(title.c_str());
33 }
34 
38 RLCPPAPI inline std::string GetMonitorName(int monitor = 0) {
39  return ::GetMonitorName(monitor);
40 }
41 
45 RLCPPAPI inline void SetClipboardText(const std::string& text) {
46  ::SetClipboardText(text.c_str());
47 }
48 
52 RLCPPAPI inline std::string GetClipboardText() {
53  return ::GetClipboardText();
54 }
55 
59 RLCPPAPI inline void TakeScreenshot(const std::string& fileName) {
60  ::TakeScreenshot(fileName.c_str());
61 }
62 
66 RLCPPAPI inline std::string GetGamepadName(int gamepad) {
67  return ::GetGamepadName(gamepad);
68 }
69 
73 RLCPPAPI std::string LoadFileText(const std::string& fileName) {
74  char* text = ::LoadFileText(fileName.c_str());
75  std::string output(text);
76  ::UnloadFileText(text);
77  return output;
78 }
79 
83 RLCPPAPI inline bool SaveFileText(const std::string& fileName, const std::string& text) {
84  return ::SaveFileText(fileName.c_str(), const_cast<char*>(text.c_str()));
85 }
86 
90 RLCPPAPI inline bool FileExists(const std::string& fileName) {
91  return ::FileExists(fileName.c_str());
92 }
93 
97 RLCPPAPI inline bool DirectoryExists(const std::string& dirPath) {
98  return ::DirectoryExists(dirPath.c_str());
99 }
100 
104 RLCPPAPI inline bool IsFileExtension(const std::string& fileName, const std::string& ext) {
105  return ::IsFileExtension(fileName.c_str(), ext.c_str());
106 }
107 
111 RLCPPAPI inline std::string GetFileExtension(const std::string& fileName) {
112  return ::GetFileExtension(fileName.c_str());
113 }
114 
118 RLCPPAPI inline std::string GetFileName(const std::string& filePath) {
119  return ::GetFileName(filePath.c_str());
120 }
121 
125 RLCPPAPI inline std::string GetFileNameWithoutExt(const std::string& filePath) {
126  return ::GetFileNameWithoutExt(filePath.c_str());
127 }
128 
132 RLCPPAPI inline std::string GetDirectoryPath(const std::string& filePath) {
133  return ::GetDirectoryPath(filePath.c_str());
134 }
135 
139 RLCPPAPI inline std::string GetPrevDirectoryPath(const std::string& dirPath) {
140  return ::GetPrevDirectoryPath(dirPath.c_str());
141 }
142 
146 RLCPPAPI inline std::string GetWorkingDirectory() {
147  return ::GetWorkingDirectory();
148 }
149 
153 RLCPPAPI std::vector<std::string> LoadDirectoryFiles(const std::string& dirPath) {
154  FilePathList files = ::LoadDirectoryFiles(dirPath.c_str());
155  std::vector<std::string> output(files.paths, files.paths + files.count);
156  ::UnloadDirectoryFiles(files);
157  return output;
158 }
159 
163 RLCPPAPI inline bool ChangeDirectory(const std::string& dir) {
164  return ::ChangeDirectory(dir.c_str());
165 }
166 
170 RLCPPAPI std::vector<std::string> LoadDroppedFiles() {
171  if (!::IsFileDropped()) {
172  return std::vector<std::string>();
173  }
174  FilePathList files = ::LoadDroppedFiles();
175  std::vector<std::string> output(files.paths, files.paths + files.count);
176  ::UnloadDroppedFiles(files);
177  return output;
178 }
179 
183 RLCPPAPI inline long GetFileModTime(const std::string& fileName) { // NOLINT
184  return ::GetFileModTime(fileName.c_str());
185 }
186 
190 RLCPPAPI inline void OpenURL(const std::string& url) {
191  return ::OpenURL(url.c_str());
192 }
193 
197 RLCPPAPI inline void UpdateCamera(const ::Camera& camera) {
198  ::Camera* cameraPointer = (::Camera*)&camera;
199  ::UpdateCamera(cameraPointer);
200 }
201 
205 RLCPPAPI inline ::Image LoadImage(const std::string& fileName) {
206  return ::LoadImage(fileName.c_str());
207 }
208 
212 RLCPPAPI inline ::Image LoadImageRaw(const std::string& fileName,
213  int width, int height,
214  int format, int headerSize) {
215  return ::LoadImageRaw(fileName.c_str(), width, height, format, headerSize);
216 }
217 
221 RLCPPAPI inline ::Image LoadImageAnim(const std::string& fileName, int *frames) {
222  return ::LoadImageAnim(fileName.c_str(), frames);
223 }
224 
228 RLCPPAPI inline ::Image LoadImageFromMemory(const std::string& fileType,
229  const unsigned char *fileData,
230  int dataSize) {
231  return ::LoadImageFromMemory(fileType.c_str(), fileData, dataSize);
232 }
233 
237 RLCPPAPI inline bool ExportImage(const Image& image, const std::string& fileName) {
238  return ::ExportImage(image, fileName.c_str());
239 }
240 
244 RLCPPAPI inline bool ExportImageAsCode(const Image& image, const std::string& fileName) {
245  return ::ExportImageAsCode(image, fileName.c_str());
246 }
247 
251 RLCPPAPI inline void DrawText(const std::string& text, int posX, int posY, int fontSize, ::Color color) {
252  ::DrawText(text.c_str(), posX, posY, fontSize, color);
253 }
254 
258 RLCPPAPI inline void DrawTextEx(const Font& font, const std::string& text, Vector2 position,
259  float fontSize, float spacing, ::Color tint) {
260  ::DrawTextEx(font, text.c_str(), position, fontSize, spacing, tint);
261 }
262 
266 RLCPPAPI inline void DrawTextPro(const Font& font, const std::string& text, Vector2 position,
267  Vector2 origin, float rotation, float fontSize, float spacing, ::Color tint) {
268  ::DrawTextPro(font, text.c_str(), position, origin, rotation, fontSize, spacing, tint);
269 }
270 
274 RLCPPAPI inline ::Font LoadFont(const std::string& fileName) {
275  return ::LoadFont(fileName.c_str());
276 }
277 
281 RLCPPAPI inline ::Font LoadFontEx(const std::string& fileName, int fontSize, int *fontChars, int charsCount) {
282  return ::LoadFontEx(fileName.c_str(), fontSize, fontChars, charsCount);
283 }
284 
288 RLCPPAPI inline int MeasureText(const std::string& text, int fontSize) {
289  return ::MeasureText(text.c_str(), fontSize);
290 }
291 
295 RLCPPAPI inline bool TextIsEqual(const std::string& text1, const std::string& text2) {
296  return ::TextIsEqual(text1.c_str(), text2.c_str());
297 }
298 
302 RLCPPAPI inline unsigned int TextLength(const std::string& text) {
303  return ::TextLength(text.c_str());
304 }
305 
309 RLAPI inline std::string TextSubtext(const std::string& text, int position, int length) {
310  return ::TextSubtext(text.c_str(), position, length);
311 }
312 
316 RLAPI inline std::string TextReplace(const std::string& text, const std::string& replace, const std::string& by) {
317  const char* input = text.c_str();
318  char* output = ::TextReplace(const_cast<char*>(input), replace.c_str(), by.c_str());
319  if (output != NULL) {
320  std::string stringOutput(output);
321  free(output);
322  return stringOutput;
323  }
324  return "";
325 }
326 
330 RLAPI inline std::string TextInsert(const std::string& text, const std::string& insert, int position) {
331  char* output = ::TextInsert(text.c_str(), insert.c_str(), position);
332  if (output != NULL) {
333  std::string stringOutput(output);
334  free(output);
335  return stringOutput;
336  }
337  return "";
338 }
339 
343 RLAPI inline std::vector<std::string> TextSplit(const std::string& text, char delimiter) {
344  int count;
345  const char** split = ::TextSplit(text.c_str(), delimiter, &count);
346  return std::vector<std::string>(split, split + count);
347 }
348 
352 RLAPI inline int TextFindIndex(const std::string& text, const std::string& find) {
353  return ::TextFindIndex(text.c_str(), find.c_str());
354 }
355 
359 RLAPI inline std::string TextToUpper(const std::string& text) {
360  return ::TextToUpper(text.c_str());
361 }
362 
366 RLAPI inline std::string TextToLower(const std::string& text) {
367  return ::TextToLower(text.c_str());
368 }
369 
373 RLAPI inline std::string TextToPascal(const std::string& text) {
374  return ::TextToPascal(text.c_str());
375 }
376 
380 RLAPI inline int TextToInteger(const std::string& text) {
381  return ::TextToInteger(text.c_str());
382 }
383 
384 } // namespace raylib
385 
386 #endif // RAYLIB_CPP_INCLUDE_FUNCTIONS_HPP_
Camera type, defines a camera position/orientation in 3d space.
Definition: Camera3D.hpp:12
Color type, RGBA (32bit)
Definition: Color.hpp:14
Font type, includes texture and charSet array data.
Definition: Font.hpp:15
Image type, bpp always RGBA (32bit)
Definition: Image.hpp:17
Vector2 type.
Definition: Vector2.hpp:16
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:8
static bool ExportImageAsCode(const Image &image, const std::string &fileName)
Export image as code file (.h) defining an array of bytes.
Definition: Functions.hpp:244
RLAPI std::string TextToUpper(const std::string &text)
Get upper case version of provided string.
Definition: Functions.hpp:359
static bool DirectoryExists(const std::string &dirPath)
Check if directory path exists.
Definition: Functions.hpp:97
RLAPI std::string TextToLower(const std::string &text)
Get lower case version of provided string.
Definition: Functions.hpp:366
static inline ::Image LoadImage(const std::string &fileName)
Load an image.
Definition: Functions.hpp:205
RLAPI int TextFindIndex(const std::string &text, const std::string &find)
Find first text occurrence within a string.
Definition: Functions.hpp:352
static std::string GetWorkingDirectory()
Get current working directory.
Definition: Functions.hpp:146
static unsigned int TextLength(const std::string &text)
Check if two text string are equal.
Definition: Functions.hpp:302
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:281
static inline ::Font LoadFont(const std::string &fileName)
Load font from file (filename must include file extension)
Definition: Functions.hpp:274
static bool ExportImage(const Image &image, const std::string &fileName)
Export image data to file.
Definition: Functions.hpp:237
static void DrawText(const std::string &text, int posX, int posY, int fontSize, ::Color color)
Draw text (using default font)
Definition: Functions.hpp:251
RLAPI std::string TextSubtext(const std::string &text, int position, int length)
Get text length, checks for '\0' ending.
Definition: Functions.hpp:309
RLAPI std::string TextToPascal(const std::string &text)
Get Pascal case notation version of provided string.
Definition: Functions.hpp:373
static bool SaveFileText(const std::string &fileName, const std::string &text)
Save text data to file (write)
Definition: Functions.hpp:83
static bool IsFileExtension(const std::string &fileName, const std::string &ext)
Check file extension (including point: .png, .wav)
Definition: Functions.hpp:104
static std::vector< std::string > LoadDirectoryFiles(const std::string &dirPath)
Get filenames in a directory path.
Definition: Functions.hpp:153
RLAPI int TextToInteger(const std::string &text)
Get integer value from text (negative values not supported)
Definition: Functions.hpp:380
static std::string GetFileName(const std::string &filePath)
Get pointer to filename for a path string.
Definition: Functions.hpp:118
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:228
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:288
RLAPI std::string TextReplace(const std::string &text, const std::string &replace, const std::string &by)
Replace text string.
Definition: Functions.hpp:316
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:330
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:90
static void InitWindow(int width, int height, const std::string &title="raylib")
Initialize window and OpenGL context.
Definition: Functions.hpp:24
RLAPI std::vector< std::string > TextSplit(const std::string &text, char delimiter)
Split text into multiple strings.
Definition: Functions.hpp:343
static inline ::Image LoadImageAnim(const std::string &fileName, int *frames)
Load animated image data.
Definition: Functions.hpp:221
static std::string LoadFileText(const std::string &fileName)
Load text data from file (read)
Definition: Functions.hpp:73
static long GetFileModTime(const std::string &fileName)
Get file modification time (last write time)
Definition: Functions.hpp:183
static std::string GetFileExtension(const std::string &fileName)
Get pointer to extension for a filename string (including point: ".png")
Definition: Functions.hpp:111
static void UpdateCamera(const ::Camera &camera)
Update camera depending on selected mode.
Definition: Functions.hpp:197
static void OpenURL(const std::string &url)
Open URL with default system browser (if available)
Definition: Functions.hpp:190
static std::vector< std::string > LoadDroppedFiles()
Get dropped files names.
Definition: Functions.hpp:170
static std::string GetFileNameWithoutExt(const std::string &filePath)
Get filename string without extension.
Definition: Functions.hpp:125
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:212
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:266
static std::string GetPrevDirectoryPath(const std::string &dirPath)
Get previous directory path for a given path.
Definition: Functions.hpp:139
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:258
static bool ChangeDirectory(const std::string &dir)
Change working directory, return true on success.
Definition: Functions.hpp:163
static std::string GetDirectoryPath(const std::string &filePath)
Get full path for a given fileName with path.
Definition: Functions.hpp:132
static bool TextIsEqual(const std::string &text1, const std::string &text2)
Check if two text string are equal.
Definition: Functions.hpp:295
static std::string GetClipboardText()
Get clipboard text content.
Definition: Functions.hpp:52