Skip to content

Commit 03d170d

Browse files
committed
Fix Fonts
1 parent bb5758f commit 03d170d

File tree

11 files changed

+73
-179
lines changed

11 files changed

+73
-179
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [v3.5.0-beta2] - Unreleased
8+
### Fixed
9+
- `Font.charsPadding` loading
10+
### Removed
11+
- `DroppedFiles` class replaced with `std::vector<std::string> raylib::GetDroppedFiles()`
12+
713
## [v3.5.0-beta1] - 2021-01-02
814
### Added
915
- `Model.Draw()` and `Model.DrawWires()`

examples/core/core_drop_files.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ int main() {
2121

2222
raylib::Window w(screenWidth, screenHeight, "raylib [core] example - drop files");
2323

24-
// Create the Dropped Files collection object.
25-
raylib::DroppedFiles droppedFiles;
24+
std::vector<std::string> droppedFiles;
2625

2726
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
2827
//--------------------------------------------------------------------------------------
@@ -32,8 +31,8 @@ int main() {
3231
{
3332
// Update
3433
//----------------------------------------------------------------------------------
35-
if (droppedFiles.IsFileDropped()) {
36-
droppedFiles.Get();
34+
if (IsFileDropped()) {
35+
droppedFiles = raylib::GetDroppedFiles();
3736
}
3837
//----------------------------------------------------------------------------------
3938

@@ -68,10 +67,5 @@ int main() {
6867
//----------------------------------------------------------------------------------
6968
}
7069

71-
// De-Initialization
72-
//--------------------------------------------------------------------------------------
73-
// ClearDroppedFiles(); // Called for us.
74-
//--------------------------------------------------------------------------------------
75-
7670
return 0;
7771
}

examples/text/text_raylib_fonts.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
********************************************************************************************/
1414

1515
#include <vector>
16+
#include <array>
1617

1718
#include "raylib-cpp.hpp"
1819

@@ -29,7 +30,7 @@ int main() {
2930
raylib::Color textColor(DARKGRAY);
3031

3132
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
32-
raylib::Font fonts[MAX_FONTS] = {
33+
std::array<raylib::Font, MAX_FONTS> fonts = {
3334
raylib::Font("resources/fonts/alagard.png"),
3435
raylib::Font("resources/fonts/pixelplay.png"),
3536
raylib::Font("resources/fonts/mecha.png"),
@@ -40,22 +41,25 @@ int main() {
4041
raylib::Font("resources/fonts/jupiter_crash.png")
4142
};
4243

43-
std::string messages[MAX_FONTS] = { "ALAGARD FONT designed by Hewett Tsoi",
44-
"PIXELPLAY FONT designed by Aleksander Shevchuk",
45-
"MECHA FONT designed by Captain Falcon",
46-
"SETBACK FONT designed by Brian Kent (AEnigma)",
47-
"ROMULUS FONT designed by Hewett Tsoi",
48-
"PIXANTIQUA FONT designed by Gerhard Grossmann",
49-
"ALPHA_BETA FONT designed by Brian Kent (AEnigma)",
50-
"JUPITER_CRASH FONT designed by Brian Kent (AEnigma)" };
44+
std::array<std::string, MAX_FONTS> messages = {
45+
"ALAGARD FONT designed by Hewett Tsoi",
46+
"PIXELPLAY FONT designed by Aleksander Shevchuk",
47+
"MECHA FONT designed by Captain Falcon",
48+
"SETBACK FONT designed by Brian Kent (AEnigma)",
49+
"ROMULUS FONT designed by Hewett Tsoi",
50+
"PIXANTIQUA FONT designed by Gerhard Grossmann",
51+
"ALPHA_BETA FONT designed by Brian Kent (AEnigma)",
52+
"JUPITER_CRASH FONT designed by Brian Kent (AEnigma)"
53+
};
5154

52-
const int spacings[MAX_FONTS] = { 2, 4, 8, 4, 3, 4, 4, 1 };
55+
std::array<int, MAX_FONTS> spacings = { 2, 4, 8, 4, 3, 4, 4, 1 };
5356

54-
Vector2 positions[MAX_FONTS];
57+
std::array<raylib::Vector2, MAX_FONTS> positions;
5558

56-
for (int i = 0; i < MAX_FONTS; i++)
59+
for (int i = 0; i < fonts.size(); i++)
5760
{
58-
positions[i].x = screenWidth/2 - MeasureTextEx(fonts[i], messages[i].c_str(), fonts[i].baseSize*2, spacings[i]).x/2;
61+
auto size = fonts[i].MeasureText(messages[i], fonts[i].baseSize * 2, spacings[i]);
62+
positions[i].x = screenWidth/2 - size.x/2;
5963
positions[i].y = 60 + fonts[i].baseSize + 45*i;
6064
}
6165

@@ -64,7 +68,7 @@ int main() {
6468
positions[4].y += 2;
6569
positions[7].y -= 8;
6670

67-
raylib::Color colors[MAX_FONTS] = { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD, RED };
71+
std::array<raylib::Color, MAX_FONTS> colors = { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD, RED };
6872
//--------------------------------------------------------------------------------------
6973

7074
// Main game loop
@@ -84,15 +88,14 @@ int main() {
8488
textColor.DrawText("free fonts included with raylib", 250, 20, 20);
8589
textColor.DrawLine(220, 50, 590, 50);
8690

87-
for (int i = 0; i < MAX_FONTS; i++)
91+
for (int i = 0; i < fonts.size(); i++)
8892
{
89-
fonts[i].DrawText(messages[i].c_str(), positions[i], fonts[i].baseSize*2, spacings[i], colors[i]);
93+
fonts[i].DrawText(messages[i], positions[i], fonts[i].baseSize*2, spacings[i], colors[i]);
9094
}
9195

9296
EndDrawing();
9397
//----------------------------------------------------------------------------------
9498
}
95-
//--------------------------------------------------------------------------------------
9699

97100
return 0;
98101
}

include/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ install(FILES
1111
Camera2D.hpp
1212
Camera3D.hpp
1313
Color.hpp
14-
DroppedFiles.hpp
1514
Functions.hpp
1615
Font.hpp
1716
Gamepad.hpp

include/Camera2D.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,6 @@ class Camera2D : public ::Camera2D {
9898
rotation = camera.rotation;
9999
zoom = camera.zoom;
100100
}
101-
102-
inline void set(const Camera2D& camera) {
103-
offset = camera.offset;
104-
target = camera.target;
105-
rotation = camera.rotation;
106-
zoom = camera.zoom;
107-
}
108101
};
109102
} // namespace raylib
110103

include/Camera3D.hpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,6 @@ class Camera3D : public ::Camera3D {
178178
fovy = camera.fovy;
179179
type = camera.type;
180180
}
181-
182-
inline void set(const Camera3D& camera) {
183-
position = camera.position;
184-
target = camera.target;
185-
up = camera.up;
186-
fovy = camera.fovy;
187-
type = camera.type;
188-
}
189181
};
190182

191183
typedef Camera3D Camera;

include/Color.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,6 @@ class Color : public ::Color {
276276
b = color.b;
277277
a = color.a;
278278
}
279-
280-
inline void set(const Color& color) {
281-
r = color.r;
282-
g = color.g;
283-
b = color.b;
284-
a = color.a;
285-
}
286279
};
287280

288281
} // namespace raylib

include/DroppedFiles.hpp

Lines changed: 0 additions & 113 deletions
This file was deleted.

include/Font.hpp

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,31 +79,34 @@ class Font : public ::Font {
7979
return *this;
8080
}
8181

82-
Font& operator=(const Font& font) {
83-
set(font);
84-
return *this;
85-
}
86-
8782
inline Font& DrawText(const std::string& text, ::Vector2 position, float fontSize,
8883
float spacing, ::Color tint = WHITE) {
8984
::DrawTextEx(*this, text.c_str(), position, fontSize, spacing, tint);
9085
return *this;
9186
}
9287

9388
inline Font& DrawText(const std::string& text, ::Rectangle rec, float fontSize, float spacing,
94-
bool wordWrap, ::Color tint = WHITE) {
89+
bool wordWrap = false, ::Color tint = WHITE) {
9590
::DrawTextRec(*this, text.c_str(), rec, fontSize, spacing, wordWrap, tint);
9691
return *this;
9792
}
9893

9994
inline Font& DrawText(const std::string& text, ::Rectangle rec, float fontSize, float spacing,
100-
bool wordWrap, Color tint, int selectStart, int selectLength, ::Color selectText,
95+
bool wordWrap, ::Color tint, int selectStart, int selectLength, ::Color selectText,
10196
::Color selectBack) {
10297
::DrawTextRecEx(*this, text.c_str(), rec, fontSize, spacing, wordWrap, tint,
10398
selectStart, selectLength, selectText, selectBack);
10499
return *this;
105100
}
106101

102+
/**
103+
* Draw one character (codepoint)
104+
*/
105+
inline Font& DrawText(int codepoint, ::Vector2 position, float fontSize, ::Color tint = { 255, 255, 255, 255 }) {
106+
::DrawTextCodepoint(*this, codepoint, position, fontSize, tint);
107+
return *this;
108+
}
109+
107110
/**
108111
* Measure string size for Font
109112
*/
@@ -121,7 +124,7 @@ class Font : public ::Font {
121124
/**
122125
* Create an image from text (custom sprite font)
123126
*/
124-
inline Image ImageText(const std::string& text, float fontSize,
127+
inline ::Image ImageText(const std::string& text, float fontSize,
125128
float spacing, ::Color tint) const {
126129
return ::ImageTextEx(*this, text.c_str(), fontSize, spacing, tint);
127130
}
@@ -130,14 +133,7 @@ class Font : public ::Font {
130133
void set(const ::Font& font) {
131134
baseSize = font.baseSize;
132135
charsCount = font.charsCount;
133-
texture = font.texture;
134-
recs = font.recs;
135-
chars = font.chars;
136-
}
137-
138-
void set(const Font& font) {
139-
baseSize = font.baseSize;
140-
charsCount = font.charsCount;
136+
charsPadding = font.charsPadding;
141137
texture = font.texture;
142138
recs = font.recs;
143139
chars = font.chars;

include/Functions.hpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,38 @@ inline void OpenURL(const std::string& url) {
197197
return ::OpenURL(url.c_str());
198198
}
199199

200+
inline bool IsGamepadName(int gamepad, const std::string& name) {
201+
return ::IsGamepadName(gamepad, name.c_str());
202+
}
203+
204+
inline void UpdateCamera(Camera& camera) {
205+
::UpdateCamera(&camera);
206+
}
207+
208+
inline Image LoadImage(const std::string& fileName) {
209+
return ::LoadImage(fileName.c_str());
210+
}
211+
212+
inline Image LoadImageRaw(const std::string& fileName, int width, int height, int format, int headerSize) {
213+
return ::LoadImageRaw(fileName.c_str(), width, height, format, headerSize);
214+
}
215+
216+
inline Image LoadImageAnim(const std::string& fileName, int *frames) {
217+
return ::LoadImageAnim(fileName.c_str(), frames);
218+
}
219+
220+
inline Image LoadImageFromMemory(const std::string& fileType, const unsigned char *fileData, int dataSize) {
221+
return ::LoadImageFromMemory(fileType.c_str(), fileData, dataSize);
222+
}
223+
224+
inline bool ExportImage(const Image& image, const std::string& fileName) {
225+
return ::ExportImage(image, fileName.c_str());
226+
}
227+
228+
inline bool ExportImageAsCode(const Image& image, const std::string& fileName) {
229+
return ::ExportImageAsCode(image, fileName.c_str());
230+
}
231+
200232
} // namespace raylib
201233

202234
#endif // RAYLIB_CPP_INCLUDE_FUNCTIONS_HPP_

0 commit comments

Comments
 (0)