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 namespace raylib {
34 
38 inline void InitWindow(int width, int height, const std::string& title) {
39  ::InitWindow(width, height, title.c_str());
40 }
41 
45 inline void SetWindowTitle(const std::string& title) {
46  ::SetWindowTitle(title.c_str());
47 }
48 
52 inline std::string GetMonitorName(int monitor) {
53  return ::GetMonitorName(monitor);
54 }
55 
59 inline void SetClipboardText(const std::string& text) {
60  ::SetClipboardText(text.c_str());
61 }
62 
66 inline std::string GetClipboardText() {
67  return ::GetClipboardText();
68 }
69 
73 inline void TakeScreenshot(const std::string& fileName) {
74  ::TakeScreenshot(fileName.c_str());
75 }
76 
80 std::string LoadFileText(const std::string& fileName) {
81  char* text = ::LoadFileText(fileName.c_str());
82  std::string output(text);
83  ::UnloadFileText((unsigned char*)text);
84  return output;
85 }
86 
90 inline bool SaveFileText(const std::string& fileName, const std::string& text) {
91  return ::SaveFileText(fileName.c_str(), const_cast<char*>(text.c_str()));
92 }
93 
97 inline bool FileExists(const std::string& fileName) {
98  return ::FileExists(fileName.c_str());
99 }
100 
104 inline bool DirectoryExists(const std::string& dirPath) {
105  return ::DirectoryExists(dirPath.c_str());
106 }
107 
111 inline bool IsFileExtension(const std::string& fileName, const std::string& ext) {
112  return ::IsFileExtension(fileName.c_str(), ext.c_str());
113 }
114 
118 inline std::string GetFileExtension(const std::string& fileName) {
119  return ::GetFileExtension(fileName.c_str());
120 }
121 
125 inline std::string GetFileName(const std::string& filePath) {
126  return ::GetFileName(filePath.c_str());
127 }
128 
132 inline std::string GetFileNameWithoutExt(const std::string& filePath) {
133  return ::GetFileNameWithoutExt(filePath.c_str());
134 }
135 
139 inline std::string GetDirectoryPath(const std::string& filePath) {
140  return ::GetDirectoryPath(filePath.c_str());
141 }
142 
146 inline std::string GetPrevDirectoryPath(const std::string& dirPath) {
147  return ::GetPrevDirectoryPath(dirPath.c_str());
148 }
149 
153 inline std::string GetWorkingDirectory() {
154  return ::GetWorkingDirectory();
155 }
156 
160 std::vector<std::string> GetDirectoryFiles(const std::string& dirPath) {
161  int count;
162  char** files = ::GetDirectoryFiles(dirPath.c_str(), &count);
163  std::vector<std::string> output(files, files + count);
164  ::ClearDirectoryFiles();
165  return output;
166 }
167 
171 inline bool ChangeDirectory(const std::string& dir) {
172  return ::ChangeDirectory(dir.c_str());
173 }
174 
178 std::vector<std::string> GetDroppedFiles() {
179  int count;
180  char** files = ::GetDroppedFiles(&count);
181  std::vector<std::string> output(files, files + count);
182  ::ClearDroppedFiles();
183  return output;
184 }
185 
189 inline long GetFileModTime(const std::string& fileName) { // NOLINT
190  return ::GetFileModTime(fileName.c_str());
191 }
192 
196 inline void OpenURL(const std::string& url) {
197  return ::OpenURL(url.c_str());
198 }
199 
200 inline bool IsGamepadName(int gamepad, const std::string& name) {
201  return ::IsGamepadName(gamepad, name.c_str());
202 }
203 
204 inline void UpdateCamera(const ::Camera& camera) {
205  ::Camera* cameraPointer = (::Camera*)&camera;
206  ::UpdateCamera(cameraPointer);
207 }
208 
209 inline ::Image LoadImage(const std::string& fileName) {
210  return ::LoadImage(fileName.c_str());
211 }
212 
213 inline ::Image LoadImageRaw(const std::string& fileName,
214  int width, int height,
215  int format, int headerSize) {
216  return ::LoadImageRaw(fileName.c_str(), width, height, format, headerSize);
217 }
218 
219 inline ::Image LoadImageAnim(const std::string& fileName, int *frames) {
220  return ::LoadImageAnim(fileName.c_str(), frames);
221 }
222 
223 inline ::Image LoadImageFromMemory(const std::string& fileType,
224  const unsigned char *fileData,
225  int dataSize) {
226  return ::LoadImageFromMemory(fileType.c_str(), fileData, dataSize);
227 }
228 
229 inline bool ExportImage(const Image& image, const std::string& fileName) {
230  return ::ExportImage(image, fileName.c_str());
231 }
232 
233 inline bool ExportImageAsCode(const Image& image, const std::string& fileName) {
234  return ::ExportImageAsCode(image, fileName.c_str());
235 }
236 
237 } // namespace raylib
238 
239 #endif // RAYLIB_CPP_INCLUDE_FUNCTIONS_HPP_
raylib::ExportImageAsCode
bool ExportImageAsCode(const Image &image, const std::string &fileName)
Definition: Functions.hpp:233
raylib
Provides all the classes associated with raylib-cpp.
Definition: AudioDevice.hpp:31
raylib::InitWindow
void InitWindow(int width, int height, const std::string &title)
Initialize window and OpenGL context.
Definition: Functions.hpp:38
raylib::GetDirectoryFiles
std::vector< std::string > GetDirectoryFiles(const std::string &dirPath)
Get filenames in a directory path.
Definition: Functions.hpp:160
raylib::ChangeDirectory
bool ChangeDirectory(const std::string &dir)
Change working directory, return true on success.
Definition: Functions.hpp:171
raylib::DirectoryExists
bool DirectoryExists(const std::string &dirPath)
Check if directory path exists.
Definition: Functions.hpp:104
raylib::GetClipboardText
std::string GetClipboardText()
Get clipboard text content.
Definition: Functions.hpp:66
raylib::FileExists
bool FileExists(const std::string &fileName)
Check if file exists.
Definition: Functions.hpp:97
raylib::Image
Definition: Image.hpp:34
raylib::GetDroppedFiles
std::vector< std::string > GetDroppedFiles()
Get dropped files names.
Definition: Functions.hpp:178
raylib::GetMonitorName
std::string GetMonitorName(int monitor)
Get the human-readable, UTF-8 encoded name of the primary monitor.
Definition: Functions.hpp:52
raylib::GetFileModTime
long GetFileModTime(const std::string &fileName)
Get file modification time (last write time)
Definition: Functions.hpp:189
raylib::SetWindowTitle
void SetWindowTitle(const std::string &title)
Set title for window.
Definition: Functions.hpp:45
raylib::LoadImageFromMemory
inline ::Image LoadImageFromMemory(const std::string &fileType, const unsigned char *fileData, int dataSize)
Definition: Functions.hpp:223
raylib::GetFileNameWithoutExt
std::string GetFileNameWithoutExt(const std::string &filePath)
Get filename string without extension.
Definition: Functions.hpp:132
raylib::OpenURL
void OpenURL(const std::string &url)
Open URL with default system browser (if available)
Definition: Functions.hpp:196
raylib::LoadFileText
std::string LoadFileText(const std::string &fileName)
Load text data from file (read)
Definition: Functions.hpp:80
raylib::GetFileExtension
std::string GetFileExtension(const std::string &fileName)
Get pointer to extension for a filename string (including point: ".png")
Definition: Functions.hpp:118
raylib::Camera3D
Definition: Camera3D.hpp:33
raylib::GetPrevDirectoryPath
std::string GetPrevDirectoryPath(const std::string &dirPath)
Get previous directory path for a given path.
Definition: Functions.hpp:146
raylib::GetWorkingDirectory
std::string GetWorkingDirectory()
Get current working directory.
Definition: Functions.hpp:153
raylib::IsFileExtension
bool IsFileExtension(const std::string &fileName, const std::string &ext)
Check file extension (including point: .png, .wav)
Definition: Functions.hpp:111
raylib::LoadImageRaw
inline ::Image LoadImageRaw(const std::string &fileName, int width, int height, int format, int headerSize)
Definition: Functions.hpp:213
raylib::ExportImage
bool ExportImage(const Image &image, const std::string &fileName)
Definition: Functions.hpp:229
raylib::GetFileName
std::string GetFileName(const std::string &filePath)
Get pointer to filename for a path string.
Definition: Functions.hpp:125
raylib::TakeScreenshot
void TakeScreenshot(const std::string &fileName)
Takes a screenshot of current screen (saved a .png)
Definition: Functions.hpp:73
raylib::GetDirectoryPath
std::string GetDirectoryPath(const std::string &filePath)
Get full path for a given fileName with path.
Definition: Functions.hpp:139
raylib::LoadImage
inline ::Image LoadImage(const std::string &fileName)
Definition: Functions.hpp:209
raylib::IsGamepadName
bool IsGamepadName(int gamepad, const std::string &name)
Definition: Functions.hpp:200
raylib::SaveFileText
bool SaveFileText(const std::string &fileName, const std::string &text)
Save text data to file (write)
Definition: Functions.hpp:90
raylib::UpdateCamera
void UpdateCamera(const ::Camera &camera)
Definition: Functions.hpp:204
raylib::SetClipboardText
void SetClipboardText(const std::string &text)
Set clipboard text content.
Definition: Functions.hpp:59
raylib::LoadImageAnim
inline ::Image LoadImageAnim(const std::string &fileName, int *frames)
Definition: Functions.hpp:219