raylib-cpp
C++ object-oriented wrapper library for raylib.
Functions.hpp
1 /*
2 * LICENSE: zlib/libpng
3 *
4 * raylib-cpp is licensed under an unmodified zlib/libpng license, which is an OSI-certified,
5 * BSD-like license that allows static linking with closed source software:
6 *
7 * Copyright (c) 2020 Rob Loach (@RobLoach)
8 *
9 * This software is provided "as-is", without any express or implied warranty. In no event
10 * will the authors be held liable for any damages arising from the use of this software.
11 *
12 * Permission is granted to anyone to use this software for any purpose, including commercial
13 * applications, and to alter it and redistribute it freely, subject to the following restrictions:
14 *
15 * 1. The origin of this software must not be misrepresented; you must not claim that you
16 * wrote the original software. If you use this software in a product, an acknowledgment
17 * in the product documentation would be appreciated but is not required.
18 *
19 * 2. Altered source versions must be plainly marked as such, and must not be misrepresented
20 * as being the original software.
21 *
22 * 3. This notice may not be removed or altered from any source distribution.
23 */
24 
25 #ifndef RAYLIB_CPP_INCLUDE_FUNCTIONS_HPP_
26 #define RAYLIB_CPP_INCLUDE_FUNCTIONS_HPP_
27 
28 #include <string>
29 #include <vector>
30 
31 #include "./raylib.hpp"
32 
33 #ifndef RLCPPAPI
34 
37 #define RLCPPAPI static
38 #endif
39 
40 namespace raylib {
41 
45 RLCPPAPI inline void InitWindow(int width, int height, const std::string& title = "raylib") {
46  ::InitWindow(width, height, title.c_str());
47 }
48 
52 RLCPPAPI inline void SetWindowTitle(const std::string& title) {
53  ::SetWindowTitle(title.c_str());
54 }
55 
59 RLCPPAPI inline std::string GetMonitorName(int monitor = 0) {
60  return ::GetMonitorName(monitor);
61 }
62 
66 RLCPPAPI inline void SetClipboardText(const std::string& text) {
67  ::SetClipboardText(text.c_str());
68 }
69 
73 RLCPPAPI inline std::string GetClipboardText() {
74  return ::GetClipboardText();
75 }
76 
80 RLCPPAPI inline void TakeScreenshot(const std::string& fileName) {
81  ::TakeScreenshot(fileName.c_str());
82 }
83 
87 RLCPPAPI std::string LoadFileText(const std::string& fileName) {
88  char* text = ::LoadFileText(fileName.c_str());
89  std::string output(text);
90  ::UnloadFileText((unsigned char*)text);
91  return output;
92 }
93 
97 RLCPPAPI inline bool SaveFileText(const std::string& fileName, const std::string& text) {
98  return ::SaveFileText(fileName.c_str(), const_cast<char*>(text.c_str()));
99 }
100 
104 RLCPPAPI inline bool FileExists(const std::string& fileName) {
105  return ::FileExists(fileName.c_str());
106 }
107 
111 RLCPPAPI inline bool DirectoryExists(const std::string& dirPath) {
112  return ::DirectoryExists(dirPath.c_str());
113 }
114 
118 RLCPPAPI inline bool IsFileExtension(const std::string& fileName, const std::string& ext) {
119  return ::IsFileExtension(fileName.c_str(), ext.c_str());
120 }
121 
125 RLCPPAPI inline std::string GetFileExtension(const std::string& fileName) {
126  return ::GetFileExtension(fileName.c_str());
127 }
128 
132 RLCPPAPI inline std::string GetFileName(const std::string& filePath) {
133  return ::GetFileName(filePath.c_str());
134 }
135 
139 RLCPPAPI inline std::string GetFileNameWithoutExt(const std::string& filePath) {
140  return ::GetFileNameWithoutExt(filePath.c_str());
141 }
142 
146 RLCPPAPI inline std::string GetDirectoryPath(const std::string& filePath) {
147  return ::GetDirectoryPath(filePath.c_str());
148 }
149 
153 RLCPPAPI inline std::string GetPrevDirectoryPath(const std::string& dirPath) {
154  return ::GetPrevDirectoryPath(dirPath.c_str());
155 }
156 
160 RLCPPAPI inline std::string GetWorkingDirectory() {
161  return ::GetWorkingDirectory();
162 }
163 
167 RLCPPAPI std::vector<std::string> GetDirectoryFiles(const std::string& dirPath) {
168  int count;
169  char** files = ::GetDirectoryFiles(dirPath.c_str(), &count);
170  std::vector<std::string> output(files, files + count);
171  ::ClearDirectoryFiles();
172  return output;
173 }
174 
178 RLCPPAPI inline bool ChangeDirectory(const std::string& dir) {
179  return ::ChangeDirectory(dir.c_str());
180 }
181 
185 RLCPPAPI std::vector<std::string> GetDroppedFiles() {
186  int count;
187  char** files = ::GetDroppedFiles(&count);
188  std::vector<std::string> output(files, files + count);
189  ::ClearDroppedFiles();
190  return output;
191 }
192 
196 RLCPPAPI inline long GetFileModTime(const std::string& fileName) { // NOLINT
197  return ::GetFileModTime(fileName.c_str());
198 }
199 
203 RLCPPAPI inline void OpenURL(const std::string& url) {
204  return ::OpenURL(url.c_str());
205 }
206 
207 RLCPPAPI inline bool IsGamepadName(int gamepad, const std::string& name) {
208  return ::IsGamepadName(gamepad, name.c_str());
209 }
210 
211 RLCPPAPI inline void UpdateCamera(const ::Camera& camera) {
212  ::Camera* cameraPointer = (::Camera*)&camera;
213  ::UpdateCamera(cameraPointer);
214 }
215 
216 RLCPPAPI inline ::Image LoadImage(const std::string& fileName) {
217  return ::LoadImage(fileName.c_str());
218 }
219 
220 RLCPPAPI inline ::Image LoadImageRaw(const std::string& fileName,
221  int width, int height,
222  int format, int headerSize) {
223  return ::LoadImageRaw(fileName.c_str(), width, height, format, headerSize);
224 }
225 
226 RLCPPAPI inline ::Image LoadImageAnim(const std::string& fileName, int *frames) {
227  return ::LoadImageAnim(fileName.c_str(), frames);
228 }
229 
230 RLCPPAPI inline ::Image LoadImageFromMemory(const std::string& fileType,
231  const unsigned char *fileData,
232  int dataSize) {
233  return ::LoadImageFromMemory(fileType.c_str(), fileData, dataSize);
234 }
235 
236 RLCPPAPI inline bool ExportImage(const Image& image, const std::string& fileName) {
237  return ::ExportImage(image, fileName.c_str());
238 }
239 
240 RLCPPAPI inline bool ExportImageAsCode(const Image& image, const std::string& fileName) {
241  return ::ExportImageAsCode(image, fileName.c_str());
242 }
243 
244 } // namespace raylib
245 
246 #endif // RAYLIB_CPP_INCLUDE_FUNCTIONS_HPP_
raylib
Provides all the classes associated with raylib-cpp.
Definition: AudioDevice.hpp:31
raylib::LoadImage
static inline ::Image LoadImage(const std::string &fileName)
Definition: Functions.hpp:216
raylib::GetFileName
static std::string GetFileName(const std::string &filePath)
Get pointer to filename for a path string.
Definition: Functions.hpp:132
raylib::UpdateCamera
static void UpdateCamera(const ::Camera &camera)
Definition: Functions.hpp:211
raylib::LoadImageRaw
static inline ::Image LoadImageRaw(const std::string &fileName, int width, int height, int format, int headerSize)
Definition: Functions.hpp:220
raylib::GetPrevDirectoryPath
static std::string GetPrevDirectoryPath(const std::string &dirPath)
Get previous directory path for a given path.
Definition: Functions.hpp:153
raylib::LoadImageFromMemory
static inline ::Image LoadImageFromMemory(const std::string &fileType, const unsigned char *fileData, int dataSize)
Definition: Functions.hpp:230
raylib::SetWindowTitle
static void SetWindowTitle(const std::string &title)
Set title for window.
Definition: Functions.hpp:52
raylib::IsGamepadName
static bool IsGamepadName(int gamepad, const std::string &name)
Definition: Functions.hpp:207
raylib::Image
Definition: Image.hpp:34
raylib::GetMonitorName
static std::string GetMonitorName(int monitor=0)
Get the human-readable, UTF-8 encoded name of the primary monitor.
Definition: Functions.hpp:59
raylib::LoadImageAnim
static inline ::Image LoadImageAnim(const std::string &fileName, int *frames)
Definition: Functions.hpp:226
raylib::GetFileModTime
static long GetFileModTime(const std::string &fileName)
Get file modification time (last write time)
Definition: Functions.hpp:196
raylib::TakeScreenshot
static void TakeScreenshot(const std::string &fileName)
Takes a screenshot of current screen (saved a .png)
Definition: Functions.hpp:80
raylib::GetDroppedFiles
static std::vector< std::string > GetDroppedFiles()
Get dropped files names.
Definition: Functions.hpp:185
raylib::InitWindow
static void InitWindow(int width, int height, const std::string &title="raylib")
Initialize window and OpenGL context.
Definition: Functions.hpp:45
raylib::ExportImageAsCode
static bool ExportImageAsCode(const Image &image, const std::string &fileName)
Definition: Functions.hpp:240
raylib::Camera3D
Definition: Camera3D.hpp:33
raylib::DirectoryExists
static bool DirectoryExists(const std::string &dirPath)
Check if directory path exists.
Definition: Functions.hpp:111
raylib::GetFileNameWithoutExt
static std::string GetFileNameWithoutExt(const std::string &filePath)
Get filename string without extension.
Definition: Functions.hpp:139
raylib::GetDirectoryPath
static std::string GetDirectoryPath(const std::string &filePath)
Get full path for a given fileName with path.
Definition: Functions.hpp:146
raylib::IsFileExtension
static bool IsFileExtension(const std::string &fileName, const std::string &ext)
Check file extension (including point: .png, .wav)
Definition: Functions.hpp:118
raylib::FileExists
static bool FileExists(const std::string &fileName)
Check if file exists.
Definition: Functions.hpp:104
raylib::GetDirectoryFiles
static std::vector< std::string > GetDirectoryFiles(const std::string &dirPath)
Get filenames in a directory path.
Definition: Functions.hpp:167
raylib::ExportImage
static bool ExportImage(const Image &image, const std::string &fileName)
Definition: Functions.hpp:236
raylib::ChangeDirectory
static bool ChangeDirectory(const std::string &dir)
Change working directory, return true on success.
Definition: Functions.hpp:178
raylib::SetClipboardText
static void SetClipboardText(const std::string &text)
Set clipboard text content.
Definition: Functions.hpp:66
raylib::GetFileExtension
static std::string GetFileExtension(const std::string &fileName)
Get pointer to extension for a filename string (including point: ".png")
Definition: Functions.hpp:125
raylib::SaveFileText
static bool SaveFileText(const std::string &fileName, const std::string &text)
Save text data to file (write)
Definition: Functions.hpp:97
raylib::LoadFileText
static std::string LoadFileText(const std::string &fileName)
Load text data from file (read)
Definition: Functions.hpp:87
raylib::OpenURL
static void OpenURL(const std::string &url)
Open URL with default system browser (if available)
Definition: Functions.hpp:203
raylib::GetWorkingDirectory
static std::string GetWorkingDirectory()
Get current working directory.
Definition: Functions.hpp:160
raylib::GetClipboardText
static std::string GetClipboardText()
Get clipboard text content.
Definition: Functions.hpp:73