Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add copy and move constructor for Font #108

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/core/core_3d_camera_first_person.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ int main() {
const int screenWidth = 800;
const int screenHeight = 450;

raylib::Window w(screenWidth, screenHeight, "raylib [core] example - 3d camera first person");
raylib::Color background(RAYWHITE);
raylib::Window window(screenWidth, screenHeight, "raylib [core] example - 3d camera first person");
raylib::Color background = RAYWHITE;

// Define the camera to look into our 3d world (position, target, up vector)
raylib::Camera camera(
Expand Down Expand Up @@ -48,7 +48,7 @@ int main() {
//--------------------------------------------------------------------------------------

// Main game loop
while (!w.ShouldClose()) // Detect window close button or ESC key
while (!window.ShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions examples/core/core_basic_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ int main() {
//--------------------------------------------------------------------------------------
int screenWidth = 800;
int screenHeight = 450;
raylib::Color textColor(LIGHTGRAY);
raylib::Window w(screenWidth, screenHeight, "raylib [core] example - basic window");
raylib::Color textColor = LIGHTGRAY;
raylib::Window window(screenWidth, screenHeight, "raylib [core] example - basic window");

SetTargetFPS(60);
//--------------------------------------------------------------------------------------

// Main game loop
while (!w.ShouldClose()) // Detect window close button or ESC key
while (!window.ShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions examples/core/core_drop_files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ int main() {
const int screenWidth = 800;
const int screenHeight = 450;

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

// Create the Dropped Files collection object.
raylib::DroppedFiles droppedFiles;
Expand All @@ -28,7 +28,7 @@ int main() {
//--------------------------------------------------------------------------------------

// Main game loop
while (!w.ShouldClose()) // Detect window close button or ESC key
while (!window.ShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions examples/core/core_input_mouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int main() {
const int screenWidth = 800;
const int screenHeight = 450;

raylib::Window w(screenWidth, screenHeight, "raylib [core] example - mouse input");
raylib::Window window(screenWidth, screenHeight, "raylib [core] example - mouse input");

raylib::Vector2 ballPosition(-100.0f, -100.0f);
raylib::Color background(RAYWHITE);
Expand All @@ -28,7 +28,7 @@ int main() {
//---------------------------------------------------------------------------------------

// Main game loop
while (!w.ShouldClose()) // Detect window close button or ESC key
while (!window.ShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions examples/core/core_random_values.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int main() {
const int screenWidth = 800;
const int screenHeight = 450;

raylib::Window w(screenWidth, screenHeight, "raylib [core] example - generate random values");
raylib::Window window(screenWidth, screenHeight, "raylib [core] example - generate random values");

int framesCounter = 0; // Variable used to count frames

Expand All @@ -27,7 +27,7 @@ int main() {
//--------------------------------------------------------------------------------------

// Main game loop
while (!w.ShouldClose()) // Detect window close button or ESC key
while (!window.ShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions examples/core/core_world_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int main() {
const int screenWidth = 800;
const int screenHeight = 450;

raylib::Window w(screenWidth, screenHeight, "raylib [core] example - 3d camera free");
raylib::Window window(screenWidth, screenHeight, "raylib [core] example - 3d camera free");

// Define the camera to look into our 3d world
raylib::Camera camera(
Expand All @@ -36,7 +36,7 @@ int main() {
//--------------------------------------------------------------------------------------

// Main game loop
while (!w.ShouldClose()) // Detect window close button or ESC key
while (!window.ShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
Expand Down
Binary file modified examples/text/resources/fonts/alagard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/text/resources/fonts/alpha_beta.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/text/resources/fonts/jupiter_crash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/text/resources/fonts/mecha.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/text/resources/fonts/pixantiqua.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/text/resources/fonts/pixelplay.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/text/resources/fonts/romulus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/text/resources/fonts/setback.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions examples/text/text_font_loading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int main() {
const int screenWidth = 800;
const int screenHeight = 450;

raylib::Window w(screenWidth, screenHeight, "raylib [text] example - font loading");
raylib::Window window(screenWidth, screenHeight, "raylib [text] example - font loading");

// Define characters to draw
// NOTE: raylib supports UTF-8 encoding, following list is actually codified as UTF8 internally
Expand All @@ -44,11 +44,11 @@ int main() {

bool useTtf = false;

w.SetTargetFPS(60); // Set our game to run at 60 frames-per-second
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------

// Main game loop
while (!w.ShouldClose()) // Detect window close button or ESC key
while (!window.ShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
Expand All @@ -58,7 +58,7 @@ int main() {

// Draw
//----------------------------------------------------------------------------------
w.BeginDrawing();
BeginDrawing();

ClearBackground(RAYWHITE);

Expand Down
6 changes: 3 additions & 3 deletions examples/text/text_font_spritefont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ int main(void)
raylib::Font font2("resources/custom_alagard.png"); // Font loading
raylib::Font font3("resources/custom_jupiter_crash.png"); // Font loading

raylib::Vector2 fontPosition1(screenWidth/2 - MeasureTextEx(font1, msg1.c_str(), font1.baseSize, -3).x/2,
raylib::Vector2 fontPosition1(screenWidth/2 - font1.MeasureText(msg1, font1.baseSize, -3).x/2,
screenHeight/2 - font1.baseSize/2 - 80);

raylib::Vector2 fontPosition2(screenWidth/2 - MeasureTextEx(font2, msg2.c_str(), font2.baseSize, -2).x/2,
raylib::Vector2 fontPosition2(screenWidth/2 - font2.MeasureText(msg2, font2.baseSize, -2).x/2,
screenHeight/2 - font2.baseSize/2 - 10);

raylib::Vector2 fontPosition3(screenWidth/2 - MeasureTextEx(font3, msg3.c_str(), font3.baseSize, 2).x/2,
raylib::Vector2 fontPosition3(screenWidth/2 - font3.MeasureText(msg3, font3.baseSize, 2).x/2,
screenHeight/2 - font3.baseSize/2 + 50);

SetTargetFPS(60); // Set our game to run at 60 frames-per-second
Expand Down
122 changes: 86 additions & 36 deletions examples/text/text_raylib_fonts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,63 +12,104 @@
*
********************************************************************************************/

#include <vector>
#include <string>
#include <array>

#include "raylib-cpp.hpp"

#define MAX_FONTS 8

int main() {
int main(void)
{
// Initialization
//--------------------------------------------------------------------------------------
int screenWidth = 800;
int screenHeight = 450;
const int screenWidth = 800;
const int screenHeight = 450;

raylib::Window w(screenWidth, screenHeight, "raylib [text] example - raylib fonts");
raylib::Color background(RAYWHITE);
raylib::Color textColor(DARKGRAY);
raylib::Window window(screenWidth, screenHeight, "raylib [text] example - raylib fonts");

// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
raylib::Font fonts[MAX_FONTS] = {
raylib::Font("resources/fonts/alagard.png"),
raylib::Font("resources/fonts/pixelplay.png"),
raylib::Font("resources/fonts/mecha.png"),
raylib::Font("resources/fonts/setback.png"),
raylib::Font("resources/fonts/romulus.png"),
raylib::Font("resources/fonts/pixantiqua.png"),
raylib::Font("resources/fonts/alpha_beta.png"),
raylib::Font("resources/fonts/jupiter_crash.png")
// Font fonts[MAX_FONTS] = { 0 };

// fonts[0] = LoadFont("resources/fonts/alagard.png");
// fonts[1] = LoadFont("resources/fonts/pixelplay.png");
// fonts[2] = LoadFont("resources/fonts/mecha.png");
// fonts[3] = LoadFont("resources/fonts/setback.png");
// fonts[4] = LoadFont("resources/fonts/romulus.png");
// fonts[5] = LoadFont("resources/fonts/pixantiqua.png");
// fonts[6] = LoadFont("resources/fonts/alpha_beta.png");
// fonts[7] = LoadFont("resources/fonts/jupiter_crash.png");

// Vector
std::vector<raylib::Font> fonts;
fonts.emplace_back("resources/fonts/alagard.png");
fonts.emplace_back("resources/fonts/pixelplay.png");
fonts.emplace_back("resources/fonts/mecha.png");
fonts.emplace_back("resources/fonts/setback.png");
fonts.emplace_back("resources/fonts/romulus.png");
fonts.emplace_back("resources/fonts/pixantiqua.png");
fonts.emplace_back("resources/fonts/alpha_beta.png");
fonts.emplace_back("resources/fonts/jupiter_crash.png");

// Normal Array
// raylib::Font fonts[MAX_FONTS] = {
// raylib::Font("resources/fonts/alagard.png"),
// raylib::Font("resources/fonts/pixelplay.png"),
// raylib::Font("resources/fonts/mecha.png"),
// raylib::Font("resources/fonts/setback.png"),
// raylib::Font("resources/fonts/romulus.png"),
// raylib::Font("resources/fonts/pixantiqua.png"),
// raylib::Font("resources/fonts/alpha_beta.png"),
// raylib::Font("resources/fonts/jupiter_crash.png")
// };

// Array
// 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"),
// raylib::Font("resources/fonts/setback.png"),
// raylib::Font("resources/fonts/romulus.png"),
// raylib::Font("resources/fonts/pixantiqua.png"),
// raylib::Font("resources/fonts/alpha_beta.png"),
// raylib::Font("resources/fonts/jupiter_crash.png")
// };

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)"
};

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<const int, MAX_FONTS> spacings = { 2, 4, 8, 4, 3, 4, 4, 1 };

const int spacings[MAX_FONTS] = { 2, 4, 8, 4, 3, 4, 4, 1 };
std::array<raylib::Vector2, MAX_FONTS> positions;

Vector2 positions[MAX_FONTS];

for (int i = 0; i < MAX_FONTS; i++)
for (int i = 0; i < positions.size(); i++)
{
positions[i].x = screenWidth/2 - MeasureTextEx(fonts[i], messages[i].c_str(), fonts[i].baseSize*2, spacings[i]).x/2;
positions[i].y = 60 + fonts[i].baseSize + 45*i;
const raylib::Vector2 size = fonts[i].MeasureText(messages[i], fonts[i].baseSize*2, spacings[i]);
//const raylib::Vector2 size = MeasureTextEx(fonts[i], messages[i].c_str(), fonts[i].baseSize*2, spacings[i]);
positions[i].x = screenWidth / 2 - size.x / 2;
positions[i].y = 60 + fonts[i].baseSize + 45 * i;
}

// Small Y position corrections
positions[3].y += 8;
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 };

SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------

// Main game loop
while (!w.ShouldClose()) // Detect window close button or ESC key
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
Expand All @@ -79,19 +120,28 @@ int main() {
//----------------------------------------------------------------------------------
BeginDrawing();

background.ClearBackground();
ClearBackground(RAYWHITE);

textColor.DrawText("free fonts included with raylib", 250, 20, 20);
textColor.DrawLine(220, 50, 590, 50);
DrawText("free fonts included with raylib", 250, 20, 20, DARKGRAY);
DrawLine(220, 50, 590, 50, DARKGRAY);

for (int i = 0; i < MAX_FONTS; i++)
{
fonts[i].DrawText(messages[i].c_str(), positions[i], fonts[i].baseSize*2, spacings[i], colors[i]);
//DrawTextEx(fonts[i], 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();
//----------------------------------------------------------------------------------
}

// De-Initialization
//--------------------------------------------------------------------------------------

// Fonts unloading
//for (int i = 0; i < MAX_FONTS; i++) UnloadFont(fonts[i]);

//CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------

return 0;
Expand Down
4 changes: 2 additions & 2 deletions examples/textures/textures_bunnymark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int main(void)
const int screenWidth = 800;
const int screenHeight = 450;

raylib::Window w(screenWidth, screenHeight, "raylib [textures] example - bunnymark");
raylib::Window window(screenWidth, screenHeight, "raylib [textures] example - bunnymark");

// Load bunny texture
raylib::Texture2D texBunny("resources/wabbit_alpha.png");
Expand All @@ -64,7 +64,7 @@ int main(void)
//--------------------------------------------------------------------------------------

// Main game loop
while (!w.ShouldClose()) // Detect window close button or ESC key
while (!window.ShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions examples/textures/textures_image_drawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ int main(void)
const int screenWidth = 800;
const int screenHeight = 450;

raylib::Window w(screenWidth, screenHeight, "raylib [textures] example - image drawing");
raylib::Window window(screenWidth, screenHeight, "raylib [textures] example - image drawing");
raylib::Color background(RAYWHITE);
raylib::Color darkGray(DARKGRAY);

Expand Down Expand Up @@ -51,7 +51,7 @@ int main(void)
//---------------------------------------------------------------------------------------

// Main game loop
while (!w.ShouldClose()) // Detect window close button or ESC key
while (!window.ShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
Expand All @@ -60,7 +60,7 @@ int main(void)

// Draw
//----------------------------------------------------------------------------------
w.BeginDrawing();
window.BeginDrawing();

background.ClearBackground();

Expand All @@ -70,7 +70,7 @@ int main(void)
darkGray.DrawText("We are drawing only one texture from various images composed!", 240, 350, 10);
darkGray.DrawText("Source images have been cropped, scaled, flipped and copied one over the other.", 190, 370, 10);

w.EndDrawing();
window.EndDrawing();
//----------------------------------------------------------------------------------
}

Expand Down
4 changes: 2 additions & 2 deletions examples/textures/textures_image_loading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ int main() {
int screenWidth = 800;
int screenHeight = 450;

raylib::Window w(screenWidth, screenHeight, "raylib [textures] example - image loading");
raylib::Window window(screenWidth, screenHeight, "raylib [textures] example - image loading");
raylib::Texture texture("resources/raylib_logo.png");
raylib::Color background(RAYWHITE);
raylib::Color textColor(LIGHTGRAY);

// Main game loop
while (!w.ShouldClose()) // Detect window close button or ESC key
while (!window.ShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
Expand Down
Loading