Skip to content

Commit 1dd2ec0

Browse files
committed
Add "static" to all global raylib-cpp function definitions
Fixes #115
1 parent 263fbe1 commit 1dd2ec0

File tree

6 files changed

+105
-31
lines changed

6 files changed

+105
-31
lines changed

examples/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,9 @@ foreach(example_source ${example_sources})
3838

3939
endforeach()
4040

41+
# Multiple Files Example
42+
add_executable("multiple" multiple/main.cpp multiple/Player.cpp)
43+
target_link_libraries("multiple" PUBLIC raylib-cpp raylib)
44+
4145
# Copy all the resources
4246
file(COPY ${example_resources} DESTINATION "resources/")

examples/multiple/Player.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include "raylib-cpp.hpp"
2+
3+
#include "./Player.hpp"
4+
5+
Player::Player() {
6+
position = Rectangle{
7+
GetScreenWidth() / 2 - 50,
8+
GetScreenHeight() / 2 - 50,
9+
100,
10+
100
11+
};
12+
speed = 3;
13+
}
14+
15+
void Player::Draw() {
16+
position.Draw(RED);
17+
}
18+
19+
void Player::Update() {
20+
if (IsKeyDown(KEY_UP)) {
21+
position.y -= speed;
22+
}
23+
if (IsKeyDown(KEY_DOWN)) {
24+
position.y += speed;
25+
}
26+
if (IsKeyDown(KEY_RIGHT)) {
27+
position.x += speed;
28+
}
29+
if (IsKeyDown(KEY_LEFT)) {
30+
position.x -= speed;
31+
}
32+
}

examples/multiple/Player.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "raylib-cpp.hpp"
2+
3+
class Player {
4+
public:
5+
Player();
6+
raylib::Rectangle position;
7+
int speed;
8+
void Draw();
9+
void Update();
10+
};

examples/multiple/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Multiple Files Example
2+
3+
This provides an example of including raylib-cpp.hpp in multiple files.

examples/multiple/main.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "raylib-cpp.hpp"
2+
3+
#include "./Player.hpp"
4+
5+
int main() {
6+
raylib::Window window(640, 480);
7+
SetTargetFPS(60);
8+
9+
Player player;
10+
while (!window.ShouldClose()) {
11+
window.BeginDrawing();
12+
ClearBackground(SKYBLUE);
13+
player.Update();
14+
player.Draw();
15+
window.EndDrawing();
16+
}
17+
18+
}

include/Functions.hpp

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* LICENSE: zlib/libpng
33
*
44
* 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:
5+
* BSD-like license that allows RLCPPAPI linking with closed source software:
66
*
77
* Copyright (c) 2020 Rob Loach (@RobLoach)
88
*
@@ -30,54 +30,61 @@
3030

3131
#include "./raylib.hpp"
3232

33+
#ifndef RLCPPAPI
34+
/**
35+
* Allow changing the declare type for all raylib-cpp global functions. Defaults to static.
36+
*/
37+
#define RLCPPAPI static
38+
#endif
39+
3340
namespace raylib {
3441

3542
/**
3643
* Initialize window and OpenGL context
3744
*/
38-
inline void InitWindow(int width, int height, const std::string& title) {
45+
RLCPPAPI inline void InitWindow(int width, int height, const std::string& title = "") {
3946
::InitWindow(width, height, title.c_str());
4047
}
4148

4249
/**
4350
* Set title for window
4451
*/
45-
inline void SetWindowTitle(const std::string& title) {
52+
RLCPPAPI inline void SetWindowTitle(const std::string& title) {
4653
::SetWindowTitle(title.c_str());
4754
}
4855

4956
/**
5057
* Get the human-readable, UTF-8 encoded name of the primary monitor
5158
*/
52-
inline std::string GetMonitorName(int monitor) {
59+
RLCPPAPI inline std::string GetMonitorName(int monitor = 0) {
5360
return ::GetMonitorName(monitor);
5461
}
5562

5663
/**
5764
* Set clipboard text content
5865
*/
59-
inline void SetClipboardText(const std::string& text) {
66+
RLCPPAPI inline void SetClipboardText(const std::string& text) {
6067
::SetClipboardText(text.c_str());
6168
}
6269

6370
/**
6471
* Get clipboard text content
6572
*/
66-
inline std::string GetClipboardText() {
73+
RLCPPAPI inline std::string GetClipboardText() {
6774
return ::GetClipboardText();
6875
}
6976

7077
/**
7178
* Takes a screenshot of current screen (saved a .png)
7279
*/
73-
inline void TakeScreenshot(const std::string& fileName) {
80+
RLCPPAPI inline void TakeScreenshot(const std::string& fileName) {
7481
::TakeScreenshot(fileName.c_str());
7582
}
7683

7784
/**
7885
* Load text data from file (read)
7986
*/
80-
std::string LoadFileText(const std::string& fileName) {
87+
RLCPPAPI std::string LoadFileText(const std::string& fileName) {
8188
char* text = ::LoadFileText(fileName.c_str());
8289
std::string output(text);
8390
::UnloadFileText((unsigned char*)text);
@@ -87,77 +94,77 @@ std::string LoadFileText(const std::string& fileName) {
8794
/**
8895
* Save text data to file (write)
8996
*/
90-
inline bool SaveFileText(const std::string& fileName, const std::string& text) {
97+
RLCPPAPI inline bool SaveFileText(const std::string& fileName, const std::string& text) {
9198
return ::SaveFileText(fileName.c_str(), const_cast<char*>(text.c_str()));
9299
}
93100

94101
/**
95102
* Check if file exists
96103
*/
97-
inline bool FileExists(const std::string& fileName) {
104+
RLCPPAPI inline bool FileExists(const std::string& fileName) {
98105
return ::FileExists(fileName.c_str());
99106
}
100107

101108
/**
102109
* Check if directory path exists
103110
*/
104-
inline bool DirectoryExists(const std::string& dirPath) {
111+
RLCPPAPI inline bool DirectoryExists(const std::string& dirPath) {
105112
return ::DirectoryExists(dirPath.c_str());
106113
}
107114

108115
/**
109116
* Check file extension (including point: .png, .wav)
110117
*/
111-
inline bool IsFileExtension(const std::string& fileName, const std::string& ext) {
118+
RLCPPAPI inline bool IsFileExtension(const std::string& fileName, const std::string& ext) {
112119
return ::IsFileExtension(fileName.c_str(), ext.c_str());
113120
}
114121

115122
/**
116123
* Get pointer to extension for a filename string (including point: ".png")
117124
*/
118-
inline std::string GetFileExtension(const std::string& fileName) {
125+
RLCPPAPI inline std::string GetFileExtension(const std::string& fileName) {
119126
return ::GetFileExtension(fileName.c_str());
120127
}
121128

122129
/**
123130
* Get pointer to filename for a path string
124131
*/
125-
inline std::string GetFileName(const std::string& filePath) {
132+
RLCPPAPI inline std::string GetFileName(const std::string& filePath) {
126133
return ::GetFileName(filePath.c_str());
127134
}
128135

129136
/**
130137
* Get filename string without extension
131138
*/
132-
inline std::string GetFileNameWithoutExt(const std::string& filePath) {
139+
RLCPPAPI inline std::string GetFileNameWithoutExt(const std::string& filePath) {
133140
return ::GetFileNameWithoutExt(filePath.c_str());
134141
}
135142

136143
/**
137144
* Get full path for a given fileName with path
138145
*/
139-
inline std::string GetDirectoryPath(const std::string& filePath) {
146+
RLCPPAPI inline std::string GetDirectoryPath(const std::string& filePath) {
140147
return ::GetDirectoryPath(filePath.c_str());
141148
}
142149

143150
/**
144151
* Get previous directory path for a given path
145152
*/
146-
inline std::string GetPrevDirectoryPath(const std::string& dirPath) {
153+
RLCPPAPI inline std::string GetPrevDirectoryPath(const std::string& dirPath) {
147154
return ::GetPrevDirectoryPath(dirPath.c_str());
148155
}
149156

150157
/**
151158
* Get current working directory
152159
*/
153-
inline std::string GetWorkingDirectory() {
160+
RLCPPAPI inline std::string GetWorkingDirectory() {
154161
return ::GetWorkingDirectory();
155162
}
156163

157164
/**
158165
* Get filenames in a directory path
159166
*/
160-
std::vector<std::string> GetDirectoryFiles(const std::string& dirPath) {
167+
RLCPPAPI std::vector<std::string> GetDirectoryFiles(const std::string& dirPath) {
161168
int count;
162169
char** files = ::GetDirectoryFiles(dirPath.c_str(), &count);
163170
std::vector<std::string> output(files, files + count);
@@ -168,14 +175,14 @@ std::vector<std::string> GetDirectoryFiles(const std::string& dirPath) {
168175
/**
169176
* Change working directory, return true on success
170177
*/
171-
inline bool ChangeDirectory(const std::string& dir) {
178+
RLCPPAPI inline bool ChangeDirectory(const std::string& dir) {
172179
return ::ChangeDirectory(dir.c_str());
173180
}
174181

175182
/**
176183
* Get dropped files names
177184
*/
178-
std::vector<std::string> GetDroppedFiles() {
185+
RLCPPAPI std::vector<std::string> GetDroppedFiles() {
179186
int count;
180187
char** files = ::GetDroppedFiles(&count);
181188
std::vector<std::string> output(files, files + count);
@@ -186,51 +193,51 @@ std::vector<std::string> GetDroppedFiles() {
186193
/**
187194
* Get file modification time (last write time)
188195
*/
189-
inline long GetFileModTime(const std::string& fileName) { // NOLINT
196+
RLCPPAPI inline long GetFileModTime(const std::string& fileName) { // NOLINT
190197
return ::GetFileModTime(fileName.c_str());
191198
}
192199

193200
/**
194201
* Open URL with default system browser (if available)
195202
*/
196-
inline void OpenURL(const std::string& url) {
203+
RLCPPAPI inline void OpenURL(const std::string& url) {
197204
return ::OpenURL(url.c_str());
198205
}
199206

200-
inline bool IsGamepadName(int gamepad, const std::string& name) {
207+
RLCPPAPI inline bool IsGamepadName(int gamepad, const std::string& name) {
201208
return ::IsGamepadName(gamepad, name.c_str());
202209
}
203210

204-
inline void UpdateCamera(const ::Camera& camera) {
211+
RLCPPAPI inline void UpdateCamera(const ::Camera& camera) {
205212
::Camera* cameraPointer = (::Camera*)&camera;
206213
::UpdateCamera(cameraPointer);
207214
}
208215

209-
inline ::Image LoadImage(const std::string& fileName) {
216+
RLCPPAPI inline ::Image LoadImage(const std::string& fileName) {
210217
return ::LoadImage(fileName.c_str());
211218
}
212219

213-
inline ::Image LoadImageRaw(const std::string& fileName,
220+
RLCPPAPI inline ::Image LoadImageRaw(const std::string& fileName,
214221
int width, int height,
215222
int format, int headerSize) {
216223
return ::LoadImageRaw(fileName.c_str(), width, height, format, headerSize);
217224
}
218225

219-
inline ::Image LoadImageAnim(const std::string& fileName, int *frames) {
226+
RLCPPAPI inline ::Image LoadImageAnim(const std::string& fileName, int *frames) {
220227
return ::LoadImageAnim(fileName.c_str(), frames);
221228
}
222229

223-
inline ::Image LoadImageFromMemory(const std::string& fileType,
230+
RLCPPAPI inline ::Image LoadImageFromMemory(const std::string& fileType,
224231
const unsigned char *fileData,
225232
int dataSize) {
226233
return ::LoadImageFromMemory(fileType.c_str(), fileData, dataSize);
227234
}
228235

229-
inline bool ExportImage(const Image& image, const std::string& fileName) {
236+
RLCPPAPI inline bool ExportImage(const Image& image, const std::string& fileName) {
230237
return ::ExportImage(image, fileName.c_str());
231238
}
232239

233-
inline bool ExportImageAsCode(const Image& image, const std::string& fileName) {
240+
RLCPPAPI inline bool ExportImageAsCode(const Image& image, const std::string& fileName) {
234241
return ::ExportImageAsCode(image, fileName.c_str());
235242
}
236243

0 commit comments

Comments
 (0)