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 std::string GetMonitorName(int monitor) {
39  return ::GetMonitorName(monitor);
40 }
41 
45 inline void SetClipboardText(const std::string& text) {
46  ::SetClipboardText(text.c_str());
47 }
48 
52 inline std::string GetClipboardText() {
53  return ::GetClipboardText();
54 }
55 
59 inline void TakeScreenshot(const std::string& fileName) {
60  ::TakeScreenshot(fileName.c_str());
61 }
62 
66 std::string LoadFileText(const std::string& fileName) {
67  char* text = ::LoadFileText(fileName.c_str());
68  std::string output(text);
69  ::UnloadFileText((unsigned char*)text);
70  return output;
71 }
72 
76 inline bool SaveFileText(const std::string& fileName, const std::string& text) {
77  return ::SaveFileText(fileName.c_str(), const_cast<char*>(text.c_str()));
78 }
79 
83 inline bool FileExists(const std::string& fileName) {
84  return ::FileExists(fileName.c_str());
85 }
86 
90 inline bool DirectoryExists(const std::string& dirPath) {
91  return ::DirectoryExists(dirPath.c_str());
92 }
93 
97 inline bool IsFileExtension(const std::string& fileName, const std::string& ext) {
98  return ::IsFileExtension(fileName.c_str(), ext.c_str());
99 }
100 
104 inline std::string GetFileExtension(const std::string& fileName) {
105  return ::GetFileExtension(fileName.c_str());
106 }
107 
111 inline std::string GetFileName(const std::string& filePath) {
112  return ::GetFileName(filePath.c_str());
113 }
114 
118 inline std::string GetFileNameWithoutExt(const std::string& filePath) {
119  return ::GetFileNameWithoutExt(filePath.c_str());
120 }
121 
125 inline std::string GetDirectoryPath(const std::string& filePath) {
126  return ::GetDirectoryPath(filePath.c_str());
127 }
128 
132 inline std::string GetPrevDirectoryPath(const std::string& dirPath) {
133  return ::GetPrevDirectoryPath(dirPath.c_str());
134 }
135 
139 inline std::string GetWorkingDirectory() {
140  return ::GetWorkingDirectory();
141 }
142 
146 std::vector<std::string> GetDirectoryFiles(const std::string& dirPath) {
147  int count;
148  char** files = ::GetDirectoryFiles(dirPath.c_str(), &count);
149  std::vector<std::string> output(files, files + count);
150  ::ClearDirectoryFiles();
151  return output;
152 }
153 
157 inline bool ChangeDirectory(const std::string& dir) {
158  return ::ChangeDirectory(dir.c_str());
159 }
160 
164 std::vector<std::string> GetDroppedFiles() {
165  int count;
166  char** files = ::GetDroppedFiles(&count);
167  std::vector<std::string> output(files, files + count);
168  ::ClearDroppedFiles();
169  return output;
170 }
171 
175 inline long GetFileModTime(const std::string& fileName) { // NOLINT
176  return ::GetFileModTime(fileName.c_str());
177 }
178 
182 inline void OpenURL(const std::string& url) {
183  return ::OpenURL(url.c_str());
184 }
185 
186 } // namespace raylib
187 
188 #endif // RAYLIB_CPP_INCLUDE_FUNCTIONS_HPP_
raylib
Provides all the classes associated with raylib-cpp.
Definition: AudioDevice.hpp:31
raylib::GetDirectoryFiles
std::vector< std::string > GetDirectoryFiles(const std::string &dirPath)
Get filenames in a directory path.
Definition: Functions.hpp:146
raylib::ChangeDirectory
bool ChangeDirectory(const std::string &dir)
Change working directory, return true on success.
Definition: Functions.hpp:157
raylib::DirectoryExists
bool DirectoryExists(const std::string &dirPath)
Check if directory path exists.
Definition: Functions.hpp:90
raylib::GetClipboardText
std::string GetClipboardText()
Get clipboard text content.
Definition: Functions.hpp:52
raylib::FileExists
bool FileExists(const std::string &fileName)
Check if file exists.
Definition: Functions.hpp:83
raylib::GetDroppedFiles
std::vector< std::string > GetDroppedFiles()
Get dropped files names.
Definition: Functions.hpp:164
raylib::GetMonitorName
std::string GetMonitorName(int monitor)
Get the human-readable, UTF-8 encoded name of the primary monitor.
Definition: Functions.hpp:38
raylib::GetFileModTime
long GetFileModTime(const std::string &fileName)
Get file modification time (last write time)
Definition: Functions.hpp:175
raylib::GetFileNameWithoutExt
std::string GetFileNameWithoutExt(const std::string &filePath)
Get filename string without extension.
Definition: Functions.hpp:118
raylib::OpenURL
void OpenURL(const std::string &url)
Open URL with default system browser (if available)
Definition: Functions.hpp:182
raylib::LoadFileText
std::string LoadFileText(const std::string &fileName)
Load text data from file (read)
Definition: Functions.hpp:66
raylib::GetFileExtension
std::string GetFileExtension(const std::string &fileName)
Get pointer to extension for a filename string (including point: ".png")
Definition: Functions.hpp:104
raylib::GetPrevDirectoryPath
std::string GetPrevDirectoryPath(const std::string &dirPath)
Get previous directory path for a given path.
Definition: Functions.hpp:132
raylib::GetWorkingDirectory
std::string GetWorkingDirectory()
Get current working directory.
Definition: Functions.hpp:139
raylib::IsFileExtension
bool IsFileExtension(const std::string &fileName, const std::string &ext)
Check file extension (including point: .png, .wav)
Definition: Functions.hpp:97
raylib::GetFileName
std::string GetFileName(const std::string &filePath)
Get pointer to filename for a path string.
Definition: Functions.hpp:111
raylib::TakeScreenshot
void TakeScreenshot(const std::string &fileName)
Takes a screenshot of current screen (saved a .png)
Definition: Functions.hpp:59
raylib::GetDirectoryPath
std::string GetDirectoryPath(const std::string &filePath)
Get full path for a given fileName with path.
Definition: Functions.hpp:125
raylib::SaveFileText
bool SaveFileText(const std::string &fileName, const std::string &text)
Save text data to file (write)
Definition: Functions.hpp:76
raylib::SetClipboardText
void SetClipboardText(const std::string &text)
Set clipboard text content.
Definition: Functions.hpp:45