mirror of
https://github.com/allankoechke/raylib-cpp.git
synced 2026-11-30 10:59:00 +00:00
Fix Fonts
This commit is contained in:
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [v3.5.0-beta2] - Unreleased
|
||||
### Fixed
|
||||
- `Font.charsPadding` loading
|
||||
### Removed
|
||||
- `DroppedFiles` class replaced with `std::vector<std::string> raylib::GetDroppedFiles()`
|
||||
|
||||
## [v3.5.0-beta1] - 2021-01-02
|
||||
### Added
|
||||
- `Model.Draw()` and `Model.DrawWires()`
|
||||
|
||||
@@ -21,8 +21,7 @@ int main() {
|
||||
|
||||
raylib::Window w(screenWidth, screenHeight, "raylib [core] example - drop files");
|
||||
|
||||
// Create the Dropped Files collection object.
|
||||
raylib::DroppedFiles droppedFiles;
|
||||
std::vector<std::string> droppedFiles;
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
@@ -32,8 +31,8 @@ int main() {
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
if (droppedFiles.IsFileDropped()) {
|
||||
droppedFiles.Get();
|
||||
if (IsFileDropped()) {
|
||||
droppedFiles = raylib::GetDroppedFiles();
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
@@ -68,10 +67,5 @@ int main() {
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
// ClearDroppedFiles(); // Called for us.
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
********************************************************************************************/
|
||||
|
||||
#include <vector>
|
||||
#include <array>
|
||||
|
||||
#include "raylib-cpp.hpp"
|
||||
|
||||
@@ -29,7 +30,7 @@ int main() {
|
||||
raylib::Color textColor(DARKGRAY);
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
raylib::Font fonts[MAX_FONTS] = {
|
||||
std::array<raylib::Font, MAX_FONTS> fonts = {
|
||||
raylib::Font("resources/fonts/alagard.png"),
|
||||
raylib::Font("resources/fonts/pixelplay.png"),
|
||||
raylib::Font("resources/fonts/mecha.png"),
|
||||
@@ -40,22 +41,25 @@ int main() {
|
||||
raylib::Font("resources/fonts/jupiter_crash.png")
|
||||
};
|
||||
|
||||
std::string messages[MAX_FONTS] = { "ALAGARD FONT designed by Hewett Tsoi",
|
||||
"PIXELPLAY FONT designed by Aleksander Shevchuk",
|
||||
"MECHA FONT designed by Captain Falcon",
|
||||
"SETBACK FONT designed by Brian Kent (AEnigma)",
|
||||
"ROMULUS FONT designed by Hewett Tsoi",
|
||||
"PIXANTIQUA FONT designed by Gerhard Grossmann",
|
||||
"ALPHA_BETA FONT designed by Brian Kent (AEnigma)",
|
||||
"JUPITER_CRASH FONT designed by Brian Kent (AEnigma)" };
|
||||
std::array<std::string, MAX_FONTS> messages = {
|
||||
"ALAGARD FONT designed by Hewett Tsoi",
|
||||
"PIXELPLAY FONT designed by Aleksander Shevchuk",
|
||||
"MECHA FONT designed by Captain Falcon",
|
||||
"SETBACK FONT designed by Brian Kent (AEnigma)",
|
||||
"ROMULUS FONT designed by Hewett Tsoi",
|
||||
"PIXANTIQUA FONT designed by Gerhard Grossmann",
|
||||
"ALPHA_BETA FONT designed by Brian Kent (AEnigma)",
|
||||
"JUPITER_CRASH FONT designed by Brian Kent (AEnigma)"
|
||||
};
|
||||
|
||||
const int spacings[MAX_FONTS] = { 2, 4, 8, 4, 3, 4, 4, 1 };
|
||||
std::array<int, MAX_FONTS> spacings = { 2, 4, 8, 4, 3, 4, 4, 1 };
|
||||
|
||||
Vector2 positions[MAX_FONTS];
|
||||
std::array<raylib::Vector2, MAX_FONTS> positions;
|
||||
|
||||
for (int i = 0; i < MAX_FONTS; i++)
|
||||
for (int i = 0; i < fonts.size(); i++)
|
||||
{
|
||||
positions[i].x = screenWidth/2 - MeasureTextEx(fonts[i], messages[i].c_str(), fonts[i].baseSize*2, spacings[i]).x/2;
|
||||
auto size = fonts[i].MeasureText(messages[i], fonts[i].baseSize * 2, spacings[i]);
|
||||
positions[i].x = screenWidth/2 - size.x/2;
|
||||
positions[i].y = 60 + fonts[i].baseSize + 45*i;
|
||||
}
|
||||
|
||||
@@ -64,7 +68,7 @@ int main() {
|
||||
positions[4].y += 2;
|
||||
positions[7].y -= 8;
|
||||
|
||||
raylib::Color colors[MAX_FONTS] = { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD, RED };
|
||||
std::array<raylib::Color, MAX_FONTS> colors = { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD, RED };
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
@@ -84,15 +88,14 @@ int main() {
|
||||
textColor.DrawText("free fonts included with raylib", 250, 20, 20);
|
||||
textColor.DrawLine(220, 50, 590, 50);
|
||||
|
||||
for (int i = 0; i < MAX_FONTS; i++)
|
||||
for (int i = 0; i < fonts.size(); i++)
|
||||
{
|
||||
fonts[i].DrawText(messages[i].c_str(), positions[i], fonts[i].baseSize*2, spacings[i], colors[i]);
|
||||
fonts[i].DrawText(messages[i], positions[i], fonts[i].baseSize*2, spacings[i], colors[i]);
|
||||
}
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ install(FILES
|
||||
Camera2D.hpp
|
||||
Camera3D.hpp
|
||||
Color.hpp
|
||||
DroppedFiles.hpp
|
||||
Functions.hpp
|
||||
Font.hpp
|
||||
Gamepad.hpp
|
||||
|
||||
@@ -98,13 +98,6 @@ class Camera2D : public ::Camera2D {
|
||||
rotation = camera.rotation;
|
||||
zoom = camera.zoom;
|
||||
}
|
||||
|
||||
inline void set(const Camera2D& camera) {
|
||||
offset = camera.offset;
|
||||
target = camera.target;
|
||||
rotation = camera.rotation;
|
||||
zoom = camera.zoom;
|
||||
}
|
||||
};
|
||||
} // namespace raylib
|
||||
|
||||
|
||||
@@ -178,14 +178,6 @@ class Camera3D : public ::Camera3D {
|
||||
fovy = camera.fovy;
|
||||
type = camera.type;
|
||||
}
|
||||
|
||||
inline void set(const Camera3D& camera) {
|
||||
position = camera.position;
|
||||
target = camera.target;
|
||||
up = camera.up;
|
||||
fovy = camera.fovy;
|
||||
type = camera.type;
|
||||
}
|
||||
};
|
||||
|
||||
typedef Camera3D Camera;
|
||||
|
||||
@@ -276,13 +276,6 @@ class Color : public ::Color {
|
||||
b = color.b;
|
||||
a = color.a;
|
||||
}
|
||||
|
||||
inline void set(const Color& color) {
|
||||
r = color.r;
|
||||
g = color.g;
|
||||
b = color.b;
|
||||
a = color.a;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace raylib
|
||||
|
||||
@@ -1,113 +0,0 @@
|
||||
/*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
* raylib-cpp is licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
||||
* BSD-like license that allows static linking with closed source software:
|
||||
*
|
||||
* Copyright (c) 2020 Rob Loach (@RobLoach)
|
||||
*
|
||||
* This software is provided "as-is", without any express or implied warranty. In no event
|
||||
* will the authors be held liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose, including commercial
|
||||
* applications, and to alter it and redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not claim that you
|
||||
* wrote the original software. If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
|
||||
* as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef RAYLIB_CPP_INCLUDE_DROPPEDFILES_HPP_
|
||||
#define RAYLIB_CPP_INCLUDE_DROPPEDFILES_HPP_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "./raylib.hpp"
|
||||
|
||||
namespace raylib {
|
||||
/**
|
||||
* @see raylib::GetDroppedFiles()
|
||||
*/
|
||||
class DroppedFiles {
|
||||
public:
|
||||
DroppedFiles() {
|
||||
Get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the dropped files names.
|
||||
*/
|
||||
DroppedFiles& Get() {
|
||||
m_files = ::GetDroppedFiles(&m_count);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a file has been dropped into window.
|
||||
*/
|
||||
inline bool IsFileDropped() const {
|
||||
return ::IsFileDropped();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear dropped files paths buffer.
|
||||
*/
|
||||
inline DroppedFiles& Clear() {
|
||||
::ClearDroppedFiles();
|
||||
m_count = 0;
|
||||
m_files = NULL;
|
||||
return *this;
|
||||
}
|
||||
|
||||
~DroppedFiles() {
|
||||
Clear();
|
||||
}
|
||||
|
||||
inline std::string operator[](int pos) {
|
||||
return at(pos);
|
||||
}
|
||||
|
||||
inline int Count() const {
|
||||
return m_count;
|
||||
}
|
||||
|
||||
inline int size() const {
|
||||
return m_count;
|
||||
}
|
||||
|
||||
inline bool empty() const {
|
||||
return m_count == 0;
|
||||
}
|
||||
|
||||
inline void clear() {
|
||||
Clear();
|
||||
}
|
||||
|
||||
inline std::string front() const {
|
||||
return at(0);
|
||||
}
|
||||
|
||||
inline std::string back() const {
|
||||
return at(m_count - 1);
|
||||
}
|
||||
|
||||
std::string at(int pos) const {
|
||||
if (m_files != NULL && pos < m_count && pos >= 0) {
|
||||
return std::string(m_files[pos]);
|
||||
}
|
||||
// TODO(RobLoach): Throw exception when out of range.
|
||||
return "";
|
||||
}
|
||||
|
||||
protected:
|
||||
char** m_files;
|
||||
int m_count;
|
||||
};
|
||||
} // namespace raylib
|
||||
|
||||
#endif // RAYLIB_CPP_INCLUDE_DROPPEDFILES_HPP_
|
||||
@@ -79,11 +79,6 @@ class Font : public ::Font {
|
||||
return *this;
|
||||
}
|
||||
|
||||
Font& operator=(const Font& font) {
|
||||
set(font);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Font& DrawText(const std::string& text, ::Vector2 position, float fontSize,
|
||||
float spacing, ::Color tint = WHITE) {
|
||||
::DrawTextEx(*this, text.c_str(), position, fontSize, spacing, tint);
|
||||
@@ -91,19 +86,27 @@ class Font : public ::Font {
|
||||
}
|
||||
|
||||
inline Font& DrawText(const std::string& text, ::Rectangle rec, float fontSize, float spacing,
|
||||
bool wordWrap, ::Color tint = WHITE) {
|
||||
bool wordWrap = false, ::Color tint = WHITE) {
|
||||
::DrawTextRec(*this, text.c_str(), rec, fontSize, spacing, wordWrap, tint);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Font& DrawText(const std::string& text, ::Rectangle rec, float fontSize, float spacing,
|
||||
bool wordWrap, Color tint, int selectStart, int selectLength, ::Color selectText,
|
||||
bool wordWrap, ::Color tint, int selectStart, int selectLength, ::Color selectText,
|
||||
::Color selectBack) {
|
||||
::DrawTextRecEx(*this, text.c_str(), rec, fontSize, spacing, wordWrap, tint,
|
||||
selectStart, selectLength, selectText, selectBack);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw one character (codepoint)
|
||||
*/
|
||||
inline Font& DrawText(int codepoint, ::Vector2 position, float fontSize, ::Color tint = { 255, 255, 255, 255 }) {
|
||||
::DrawTextCodepoint(*this, codepoint, position, fontSize, tint);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Measure string size for Font
|
||||
*/
|
||||
@@ -121,7 +124,7 @@ class Font : public ::Font {
|
||||
/**
|
||||
* Create an image from text (custom sprite font)
|
||||
*/
|
||||
inline Image ImageText(const std::string& text, float fontSize,
|
||||
inline ::Image ImageText(const std::string& text, float fontSize,
|
||||
float spacing, ::Color tint) const {
|
||||
return ::ImageTextEx(*this, text.c_str(), fontSize, spacing, tint);
|
||||
}
|
||||
@@ -130,14 +133,7 @@ class Font : public ::Font {
|
||||
void set(const ::Font& font) {
|
||||
baseSize = font.baseSize;
|
||||
charsCount = font.charsCount;
|
||||
texture = font.texture;
|
||||
recs = font.recs;
|
||||
chars = font.chars;
|
||||
}
|
||||
|
||||
void set(const Font& font) {
|
||||
baseSize = font.baseSize;
|
||||
charsCount = font.charsCount;
|
||||
charsPadding = font.charsPadding;
|
||||
texture = font.texture;
|
||||
recs = font.recs;
|
||||
chars = font.chars;
|
||||
|
||||
@@ -197,6 +197,38 @@ inline void OpenURL(const std::string& url) {
|
||||
return ::OpenURL(url.c_str());
|
||||
}
|
||||
|
||||
inline bool IsGamepadName(int gamepad, const std::string& name) {
|
||||
return ::IsGamepadName(gamepad, name.c_str());
|
||||
}
|
||||
|
||||
inline void UpdateCamera(Camera& camera) {
|
||||
::UpdateCamera(&camera);
|
||||
}
|
||||
|
||||
inline Image LoadImage(const std::string& fileName) {
|
||||
return ::LoadImage(fileName.c_str());
|
||||
}
|
||||
|
||||
inline Image LoadImageRaw(const std::string& fileName, int width, int height, int format, int headerSize) {
|
||||
return ::LoadImageRaw(fileName.c_str(), width, height, format, headerSize);
|
||||
}
|
||||
|
||||
inline Image LoadImageAnim(const std::string& fileName, int *frames) {
|
||||
return ::LoadImageAnim(fileName.c_str(), frames);
|
||||
}
|
||||
|
||||
inline Image LoadImageFromMemory(const std::string& fileType, const unsigned char *fileData, int dataSize) {
|
||||
return ::LoadImageFromMemory(fileType.c_str(), fileData, dataSize);
|
||||
}
|
||||
|
||||
inline bool ExportImage(const Image& image, const std::string& fileName) {
|
||||
return ::ExportImage(image, fileName.c_str());
|
||||
}
|
||||
|
||||
inline bool ExportImageAsCode(const Image& image, const std::string& fileName) {
|
||||
return ::ExportImageAsCode(image, fileName.c_str());
|
||||
}
|
||||
|
||||
} // namespace raylib
|
||||
|
||||
#endif // RAYLIB_CPP_INCLUDE_FUNCTIONS_HPP_
|
||||
|
||||
@@ -73,7 +73,6 @@
|
||||
#include "./Camera2D.hpp"
|
||||
#include "./Camera3D.hpp"
|
||||
#include "./Color.hpp"
|
||||
#include "./DroppedFiles.hpp"
|
||||
#include "./Functions.hpp"
|
||||
#include "./Font.hpp"
|
||||
#include "./Gamepad.hpp"
|
||||
|
||||
Reference in New Issue
Block a user