diff options
| author | Ray <[email protected]> | 2017-04-08 23:31:58 +0200 |
|---|---|---|
| committer | Ray <[email protected]> | 2017-04-08 23:31:58 +0200 |
| commit | 20d205cae5bf78d00fb03c266999c33488cbd2c8 (patch) | |
| tree | 8aafb630d19f3a2a827bf212e16c531a0c672d41 /examples/text | |
| parent | 5fd83708cf860db358d843cb30f99a88aaf3bd2c (diff) | |
| download | raylib-20d205cae5bf78d00fb03c266999c33488cbd2c8.tar.gz raylib-20d205cae5bf78d00fb03c266999c33488cbd2c8.zip | |
Working on examples...
Diffstat (limited to 'examples/text')
| -rw-r--r-- | examples/text/resources/KAISG.ttf (renamed from examples/text/resources/fonts/KAISG.ttf) | bin | 79912 -> 79912 bytes | |||
| -rw-r--r-- | examples/text/resources/bmfont.fnt (renamed from examples/text/resources/fonts/bmfont.fnt) | 0 | ||||
| -rw-r--r-- | examples/text/resources/bmfont.png (renamed from examples/text/resources/fonts/bmfont.png) | bin | 14471 -> 14471 bytes | |||
| -rw-r--r-- | examples/text/resources/custom_alagard.png (renamed from examples/text/resources/fonts/custom_alagard.png) | bin | 37935 -> 37935 bytes | |||
| -rw-r--r-- | examples/text/resources/custom_jupiter_crash.png (renamed from examples/text/resources/fonts/custom_jupiter_crash.png) | bin | 23596 -> 23596 bytes | |||
| -rw-r--r-- | examples/text/resources/custom_mecha.png (renamed from examples/text/resources/fonts/custom_mecha.png) | bin | 26597 -> 26597 bytes | |||
| -rw-r--r-- | examples/text/resources/pixantiqua.ttf (renamed from examples/text/resources/fonts/pixantiqua.ttf) | bin | 35408 -> 35408 bytes | |||
| -rw-r--r-- | examples/text/resources/pixantiqua_0.png (renamed from examples/text/resources/fonts/pixantiqua_0.png) | bin | 4531 -> 4531 bytes | |||
| -rw-r--r-- | examples/text/text_bmfont_ttf.c | 4 | ||||
| -rw-r--r-- | examples/text/text_bmfont_unordered.c | 2 | ||||
| -rw-r--r-- | examples/text/text_font_select.c | 158 | ||||
| -rw-r--r-- | examples/text/text_font_select.png | bin | 16261 -> 0 bytes | |||
| -rw-r--r-- | examples/text/text_rbmf_fonts.c | 7 | ||||
| -rw-r--r-- | examples/text/text_sprite_fonts.c | 6 | ||||
| -rw-r--r-- | examples/text/text_ttf_loading.c | 2 |
15 files changed, 10 insertions, 169 deletions
diff --git a/examples/text/resources/fonts/KAISG.ttf b/examples/text/resources/KAISG.ttf Binary files differindex 04478b25..04478b25 100644 --- a/examples/text/resources/fonts/KAISG.ttf +++ b/examples/text/resources/KAISG.ttf diff --git a/examples/text/resources/fonts/bmfont.fnt b/examples/text/resources/bmfont.fnt index 372c2c88..372c2c88 100644 --- a/examples/text/resources/fonts/bmfont.fnt +++ b/examples/text/resources/bmfont.fnt diff --git a/examples/text/resources/fonts/bmfont.png b/examples/text/resources/bmfont.png Binary files differindex 9d621594..9d621594 100644 --- a/examples/text/resources/fonts/bmfont.png +++ b/examples/text/resources/bmfont.png diff --git a/examples/text/resources/fonts/custom_alagard.png b/examples/text/resources/custom_alagard.png Binary files differindex c3eb63b7..c3eb63b7 100644 --- a/examples/text/resources/fonts/custom_alagard.png +++ b/examples/text/resources/custom_alagard.png diff --git a/examples/text/resources/fonts/custom_jupiter_crash.png b/examples/text/resources/custom_jupiter_crash.png Binary files differindex 451b591f..451b591f 100644 --- a/examples/text/resources/fonts/custom_jupiter_crash.png +++ b/examples/text/resources/custom_jupiter_crash.png diff --git a/examples/text/resources/fonts/custom_mecha.png b/examples/text/resources/custom_mecha.png Binary files differindex 59caab2c..59caab2c 100644 --- a/examples/text/resources/fonts/custom_mecha.png +++ b/examples/text/resources/custom_mecha.png diff --git a/examples/text/resources/fonts/pixantiqua.ttf b/examples/text/resources/pixantiqua.ttf Binary files differindex e012875d..e012875d 100644 --- a/examples/text/resources/fonts/pixantiqua.ttf +++ b/examples/text/resources/pixantiqua.ttf diff --git a/examples/text/resources/fonts/pixantiqua_0.png b/examples/text/resources/pixantiqua_0.png Binary files differindex 2aa2870f..2aa2870f 100644 --- a/examples/text/resources/fonts/pixantiqua_0.png +++ b/examples/text/resources/pixantiqua_0.png diff --git a/examples/text/text_bmfont_ttf.c b/examples/text/text_bmfont_ttf.c index 4d060915..0778fd11 100644 --- a/examples/text/text_bmfont_ttf.c +++ b/examples/text/text_bmfont_ttf.c @@ -24,8 +24,8 @@ int main() const char msgTtf[64] = "THIS SPRITE FONT has been GENERATED from a TTF"; // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required) - SpriteFont fontBm = LoadSpriteFont("resources/fonts/bmfont.fnt"); // BMFont (AngelCode) - SpriteFont fontTtf = LoadSpriteFont("resources/fonts/pixantiqua.ttf"); // TTF font + SpriteFont fontBm = LoadSpriteFont("resources/bmfont.fnt"); // BMFont (AngelCode) + SpriteFont fontTtf = LoadSpriteFont("resources/pixantiqua.ttf"); // TTF font Vector2 fontPosition; diff --git a/examples/text/text_bmfont_unordered.c b/examples/text/text_bmfont_unordered.c index 6fec3256..01561bec 100644 --- a/examples/text/text_bmfont_unordered.c +++ b/examples/text/text_bmfont_unordered.c @@ -25,7 +25,7 @@ int main() const char msg[256] = "ASCII extended characters:\n¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆ\nÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæ\nçèéêëìíîïðñòóôõö÷øùúûüýþÿ"; // NOTE: Loaded font has an unordered list of characters (chars in the range 32..255) - SpriteFont font = LoadSpriteFont("resources/fonts/pixantiqua.fnt"); // BMFont (AngelCode) + SpriteFont font = LoadSpriteFont("resources/pixantiqua.fnt"); // BMFont (AngelCode) SetTargetFPS(60); //-------------------------------------------------------------------------------------- diff --git a/examples/text/text_font_select.c b/examples/text/text_font_select.c deleted file mode 100644 index 5891bef7..00000000 --- a/examples/text/text_font_select.c +++ /dev/null @@ -1,158 +0,0 @@ -/******************************************************************************************* -* -* raylib [text] example - Font selector -* -* This example has been created using raylib 1.3 (www.raylib.com) -* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) -* -* Copyright (c) 2015 Ramon Santamaria (@raysan5) -* -********************************************************************************************/ - -#include "raylib.h" - -int main() -{ - // Initialization - //-------------------------------------------------------------------------------------- - int screenWidth = 800; - int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [text] example - font selector"); - - // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) - SpriteFont fonts[8]; // SpriteFont array - - fonts[0] = LoadSpriteFont("resources/fonts/alagard.rbmf"); // SpriteFont loading - fonts[1] = LoadSpriteFont("resources/fonts/pixelplay.rbmf"); // SpriteFont loading - fonts[2] = LoadSpriteFont("resources/fonts/mecha.rbmf"); // SpriteFont loading - fonts[3] = LoadSpriteFont("resources/fonts/setback.rbmf"); // SpriteFont loading - fonts[4] = LoadSpriteFont("resources/fonts/romulus.rbmf"); // SpriteFont loading - fonts[5] = LoadSpriteFont("resources/fonts/pixantiqua.rbmf"); // SpriteFont loading - fonts[6] = LoadSpriteFont("resources/fonts/alpha_beta.rbmf"); // SpriteFont loading - fonts[7] = LoadSpriteFont("resources/fonts/jupiter_crash.rbmf"); // SpriteFont loading - - int currentFont = 0; // Selected font - - Color colors[8] = { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD, RED }; - - const char fontNames[8][20] = { "[0] Alagard", "[1] PixelPlay", "[2] MECHA", "[3] Setback", - "[4] Romulus", "[5] PixAntiqua", "[6] Alpha Beta", "[7] Jupiter Crash" }; - - const char text[50] = "THIS is THE FONT you SELECTED!"; // Main text - - Vector2 textSize = MeasureTextEx(fonts[currentFont], text, fonts[currentFont].baseSize*3, 1); - - Vector2 mousePoint; - - Color btnNextOutColor = DARKBLUE; // Button color (outside line) - Color btnNextInColor = SKYBLUE; // Button color (inside) - - int framesCounter = 0; // Useful to count frames button is 'active' = clicked - - int positionY = 180; // Text selector and button Y position - - Rectangle btnNextRec = { 673, positionY, 109, 44 }; // Button rectangle (useful for collision) - - SetTargetFPS(60); // Set our game to run at 60 frames-per-second - //-------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key - { - // Update - //---------------------------------------------------------------------------------- - - // Keyboard-based font selection (easy) - if (IsKeyPressed(KEY_RIGHT)) - { - if (currentFont < 7) currentFont++; - } - - if (IsKeyPressed(KEY_LEFT)) - { - if (currentFont > 0) currentFont--; - } - - if (IsKeyPressed('0')) currentFont = 0; - else if (IsKeyPressed('1')) currentFont = 1; - else if (IsKeyPressed('2')) currentFont = 2; - else if (IsKeyPressed('3')) currentFont = 3; - else if (IsKeyPressed('4')) currentFont = 4; - else if (IsKeyPressed('5')) currentFont = 5; - else if (IsKeyPressed('6')) currentFont = 6; - else if (IsKeyPressed('7')) currentFont = 7; - - // Mouse-based font selection (NEXT button logic) - mousePoint = GetMousePosition(); - - if (CheckCollisionPointRec(mousePoint, btnNextRec)) - { - // Mouse hover button logic - if (framesCounter == 0) - { - btnNextOutColor = DARKPURPLE; - btnNextInColor = PURPLE; - } - - if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) - { - framesCounter = 20; // Frames button is 'active' - btnNextOutColor = MAROON; - btnNextInColor = RED; - } - } - else - { - // Mouse not hover button - btnNextOutColor = DARKBLUE; - btnNextInColor = SKYBLUE; - } - - if (framesCounter > 0) framesCounter--; - - if (framesCounter == 1) // We change font on frame 1 - { - currentFont++; - if (currentFont > 7) currentFont = 0; - } - - // Text measurement for better positioning on screen - textSize = MeasureTextEx(fonts[currentFont], text, fonts[currentFont].baseSize*3, 1); - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - DrawText("font selector - use arroys, button or numbers", 160, 80, 20, DARKGRAY); - DrawLine(120, 120, 680, 120, DARKGRAY); - - DrawRectangle(18, positionY, 644, 44, DARKGRAY); - DrawRectangle(20, positionY + 2, 640, 40, LIGHTGRAY); - DrawText(fontNames[currentFont], 30, positionY + 13, 20, BLACK); - DrawText("< >", 610, positionY + 8, 30, BLACK); - - DrawRectangleRec(btnNextRec, btnNextOutColor); - DrawRectangle(675, positionY + 2, 105, 40, btnNextInColor); - DrawText("NEXT", 700, positionY + 13, 20, btnNextOutColor); - - DrawTextEx(fonts[currentFont], text, (Vector2){ screenWidth/2 - textSize.x/2, - 260 + (70 - textSize.y)/2 }, fonts[currentFont].baseSize*3, - 1, colors[currentFont]); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - for (int i = 0; i < 8; i++) UnloadSpriteFont(fonts[i]); // SpriteFont(s) unloading - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -}
\ No newline at end of file diff --git a/examples/text/text_font_select.png b/examples/text/text_font_select.png Binary files differdeleted file mode 100644 index 65040df6..00000000 --- a/examples/text/text_font_select.png +++ /dev/null diff --git a/examples/text/text_rbmf_fonts.c b/examples/text/text_rbmf_fonts.c index cd5da1fe..f4778b45 100644 --- a/examples/text/text_rbmf_fonts.c +++ b/examples/text/text_rbmf_fonts.c @@ -85,10 +85,9 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - for (int i = 0; i < 8; i++) - { - UnloadSpriteFont(fonts[i]); // SpriteFont unloading - } + + // SpriteFonts unloading + for (int i = 0; i < 8; i++) UnloadSpriteFont(fonts[i]); CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/text/text_sprite_fonts.c b/examples/text/text_sprite_fonts.c index bded266e..aefbfd1f 100644 --- a/examples/text/text_sprite_fonts.c +++ b/examples/text/text_sprite_fonts.c @@ -25,9 +25,9 @@ int main() const char msg3[50] = "...and a THIRD one! GREAT! :D"; // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required) - SpriteFont font1 = LoadSpriteFont("resources/fonts/custom_mecha.png"); // SpriteFont loading - SpriteFont font2 = LoadSpriteFont("resources/fonts/custom_alagard.png"); // SpriteFont loading - SpriteFont font3 = LoadSpriteFont("resources/fonts/custom_jupiter_crash.png"); // SpriteFont loading + SpriteFont font1 = LoadSpriteFont("resources/custom_mecha.png"); // SpriteFont loading + SpriteFont font2 = LoadSpriteFont("resources/custom_alagard.png"); // SpriteFont loading + SpriteFont font3 = LoadSpriteFont("resources/custom_jupiter_crash.png"); // SpriteFont loading Vector2 fontPosition1, fontPosition2, fontPosition3; diff --git a/examples/text/text_ttf_loading.c b/examples/text/text_ttf_loading.c index 4aa0bef4..4e490399 100644 --- a/examples/text/text_ttf_loading.c +++ b/examples/text/text_ttf_loading.c @@ -25,7 +25,7 @@ int main() // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required) // TTF SpriteFont loading with custom generation parameters - SpriteFont font = LoadSpriteFontTTF("resources/fonts/KAISG.ttf", 96, 0, 0); + SpriteFont font = LoadSpriteFontTTF("resources/KAISG.ttf", 96, 0, 0); // Generate mipmap levels to use trilinear filtering // NOTE: On 2D drawing it won't be noticeable, it looks like FILTER_BILINEAR |
