mirror of
https://github.com/raylib-cs/raylib-cs
synced 2025-06-30 19:03:42 -04:00
Fixed trailing whitespace
- Removed trailing whitespace from bindings and examples.
This commit is contained in:
@ -13,32 +13,32 @@ public partial class text_bmfont_ttf
|
||||
* Copyright (c) 2016 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [text] example - bmfont and ttf sprite fonts loading");
|
||||
|
||||
|
||||
string msgBm = "THIS IS AN AngelCode SPRITE FONT";
|
||||
string msgTtf = "THIS SPRITE FONT has been GENERATED from a TTF";
|
||||
|
||||
|
||||
// NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
|
||||
Font fontBm = LoadFont("resources/bmfont.fnt"); // BMFont (AngelCode)
|
||||
Font fontTtf = LoadFont("resources/pixantiqua.ttf"); // TTF font
|
||||
|
||||
|
||||
Vector2 fontPosition;
|
||||
|
||||
|
||||
fontPosition.x = screenWidth/2 - MeasureTextEx(fontBm, msgBm, fontBm.baseSize, 0).x/2;
|
||||
fontPosition.y = screenHeight/2 - fontBm.baseSize/2 - 80;
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -46,28 +46,28 @@ public partial class text_bmfont_ttf
|
||||
//----------------------------------------------------------------------------------
|
||||
// TODO: Update variables here...
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawTextEx(fontBm, msgBm, fontPosition, fontBm.baseSize, 0, MAROON);
|
||||
DrawTextEx(fontTtf, msgTtf, new Vector2( 75.0f, 240.0f ), fontTtf.baseSize*0.8f, 2, LIME);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadFont(fontBm); // AngelCode Font unloading
|
||||
UnloadFont(fontTtf); // TTF Font unloading
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ public partial class text_bmfont_unordered
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
DrawText("Font name: PixAntiqua", 40, 50, 20, GRAY);
|
||||
//TODO: Uncomment this code when FormatText is fixed.
|
||||
//TODO: Uncomment this code when FormatText is fixed.
|
||||
// DrawText(FormatText("Font base size: %i", font.baseSize), 40, 80, 20, GRAY);
|
||||
// DrawText(FormatText("Font chars number: %i", font.charsCount), 40, 110, 20, GRAY);
|
||||
|
||||
|
@ -14,21 +14,21 @@ public partial class text_font_sdf
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [text] example - SDF fonts");
|
||||
|
||||
|
||||
// NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
|
||||
|
||||
|
||||
string msg = "Signed Distance Fields";
|
||||
|
||||
|
||||
// Default font generation from TTF font
|
||||
Font fontDefault = new Font();
|
||||
fontDefault.baseSize = 16;
|
||||
@ -40,7 +40,7 @@ public partial class text_font_sdf
|
||||
//Image atlas = GenImageFontAtlas(fontDefault.chars, 95, 16, 4, 0);
|
||||
//fontDefault.texture = LoadTextureFromImage(atlas);
|
||||
//UnloadImage(atlas);
|
||||
|
||||
|
||||
// SDF font generation from TTF font
|
||||
// NOTE: SDF chars data is generated with LoadFontData(), it's just a bool option
|
||||
Font fontSDF = new Font();
|
||||
@ -54,82 +54,82 @@ public partial class text_font_sdf
|
||||
//atlas = GenImageFontAtlas(fontSDF.chars, 95, 16, 0, 1);
|
||||
//fontSDF.texture = LoadTextureFromImage(atlas);
|
||||
//UnloadImage(atlas);
|
||||
|
||||
|
||||
// Load SDF required shader (we use default vertex shader)
|
||||
Shader shader = LoadShader(null, "resources/shaders/sdf.fs");
|
||||
SetTextureFilter(fontSDF.texture, (int)FILTER_BILINEAR); // Required for SDF font
|
||||
|
||||
|
||||
Vector2 fontPosition = new Vector2( 40, screenHeight/2 - 50 );
|
||||
Vector2 textSize = new Vector2( 0.0f );
|
||||
float fontSize = 16.0f;
|
||||
int currentFont = 0; // 0 - fontDefault, 1 - fontSDF
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
fontSize += GetMouseWheelMove()*8.0f;
|
||||
|
||||
|
||||
if (fontSize < 6) fontSize = 6;
|
||||
|
||||
|
||||
if (IsKeyDown(KEY_SPACE)) currentFont = 1;
|
||||
else currentFont = 0;
|
||||
|
||||
|
||||
if (currentFont == 0) textSize = MeasureTextEx(fontDefault, msg, fontSize, 0);
|
||||
else textSize = MeasureTextEx(fontSDF, msg, fontSize, 0);
|
||||
|
||||
|
||||
fontPosition.x = GetScreenWidth()/2 - textSize.x/2;
|
||||
fontPosition.y = GetScreenHeight()/2 - textSize.y/2 + 80;
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
if (currentFont == 1)
|
||||
{
|
||||
// NOTE: SDF fonts require a custom SDf shader to compute fragment color
|
||||
BeginShaderMode(shader); // Activate SDF font shader
|
||||
DrawTextEx(fontSDF, msg, fontPosition, fontSize, 0, BLACK);
|
||||
EndShaderMode(); // Activate our default shader for next drawings
|
||||
|
||||
|
||||
DrawTexture(fontSDF.texture, 10, 10, BLACK);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
DrawTextEx(fontDefault, msg, fontPosition, fontSize, 0, BLACK);
|
||||
DrawTexture(fontDefault.texture, 10, 10, BLACK);
|
||||
}
|
||||
|
||||
|
||||
if (currentFont == 1) DrawText("SDF!", 320, 20, 80, RED);
|
||||
else DrawText("default font", 315, 40, 30, GRAY);
|
||||
|
||||
|
||||
DrawText("FONT SIZE: 16.0", GetScreenWidth() - 240, 20, 20, DARKGRAY);
|
||||
DrawText(FormatText("RENDER SIZE: %02.02f", fontSize), GetScreenWidth() - 240, 50, 20, DARKGRAY);
|
||||
DrawText("Use MOUSE WHEEL to SCALE TEXT!", GetScreenWidth() - 240, 90, 10, DARKGRAY);
|
||||
|
||||
|
||||
DrawText("PRESS SPACE to USE SDF FONT VERSION!", 340, GetScreenHeight() - 30, 20, MAROON);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadFont(fontDefault); // Default font unloading
|
||||
UnloadFont(fontSDF); // SDF font unloading
|
||||
|
||||
|
||||
UnloadShader(shader); // Unload SDF shader
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,24 +13,24 @@ public partial class text_format_text
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [text] example - text formatting");
|
||||
|
||||
|
||||
int score = 100020;
|
||||
int hiscore = 200450;
|
||||
int lives = 5;
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -38,30 +38,30 @@ public partial class text_format_text
|
||||
//----------------------------------------------------------------------------------
|
||||
// TODO: Update your variables here
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawText(FormatText("Score: %08i", score), 200, 80, 20, RED);
|
||||
|
||||
|
||||
DrawText(FormatText("HiScore: %08i", hiscore), 200, 120, 20, GREEN);
|
||||
|
||||
|
||||
DrawText(FormatText("Lives: %02i", lives), 200, 160, 40, BLUE);
|
||||
|
||||
|
||||
DrawText(FormatText("Elapsed Time: %02.02f ms", GetFrameTime()*1000), 200, 220, 20, BLACK);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,30 +14,30 @@ public partial class text_input_box
|
||||
* Copyright (c) 2017 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public const int MAX_INPUT_CHARS = 9;
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [text] example - input box");
|
||||
|
||||
StringBuilder name = new StringBuilder(' ', MAX_INPUT_CHARS + 1); // NOTE: One extra space required for line ending char '\0'
|
||||
int letterCount = 0;
|
||||
|
||||
|
||||
Rectangle textBox = new Rectangle( screenWidth/2 - 100, 180, 225, 50 );
|
||||
bool mouseOnText = false;
|
||||
|
||||
|
||||
int framesCounter = 0;
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -45,47 +45,47 @@ public partial class text_input_box
|
||||
//----------------------------------------------------------------------------------
|
||||
if (CheckCollisionPointRec(GetMousePosition(), textBox)) mouseOnText = true;
|
||||
else mouseOnText = false;
|
||||
|
||||
|
||||
if (mouseOnText)
|
||||
{
|
||||
int key = GetKeyPressed();
|
||||
|
||||
|
||||
// NOTE: Only allow keys in range [32..125]
|
||||
if ((key >= 32) && (key <= 125) && (letterCount < MAX_INPUT_CHARS))
|
||||
{
|
||||
name[letterCount] = (char)key;
|
||||
letterCount++;
|
||||
}
|
||||
|
||||
|
||||
if (IsKeyPressed(KEY_BACKSPACE))
|
||||
{
|
||||
letterCount--;
|
||||
name[letterCount] = '\0';
|
||||
|
||||
|
||||
if (letterCount < 0) letterCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (mouseOnText) framesCounter++;
|
||||
else framesCounter = 0;
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawText("PLACE MOUSE OVER INPUT BOX!", 240, 140, 20, GRAY);
|
||||
|
||||
|
||||
DrawRectangleRec(textBox, LIGHTGRAY);
|
||||
if (mouseOnText) DrawRectangleLines((int)textBox.x, (int)textBox.y, (int)textBox.width, (int)textBox.height, RED);
|
||||
else DrawRectangleLines((int)textBox.x, (int)textBox.y, (int)textBox.width, (int)textBox.height, DARKGRAY);
|
||||
|
||||
|
||||
DrawText(name.ToString(), (int)textBox.x + 5, (int)textBox.y + 8, 40, MAROON);
|
||||
|
||||
|
||||
DrawText(FormatText("INPUT CHARS: %i/%i", letterCount, MAX_INPUT_CHARS), 315, 250, 20, DARKGRAY);
|
||||
|
||||
|
||||
if (mouseOnText)
|
||||
{
|
||||
if (letterCount < MAX_INPUT_CHARS)
|
||||
@ -95,28 +95,28 @@ public partial class text_input_box
|
||||
}
|
||||
else DrawText("Press BACKSPACE to delete chars...", 230, 300, 20, GRAY);
|
||||
}
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Check if any key is pressed
|
||||
// NOTE: We limit keys check to keys between 32 (KEY_SPACE) and 126
|
||||
bool IsAnyKeyPressed()
|
||||
{
|
||||
bool keyPressed = false;
|
||||
int key = GetKeyPressed();
|
||||
|
||||
|
||||
if ((key >= 32) && (key <= 126)) keyPressed = true;
|
||||
|
||||
|
||||
return keyPressed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,22 +16,22 @@ public partial class text_raylib_fonts
|
||||
* Copyright (c) 2017 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public const int MAX_FONTS = 8;
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [text] example - raylib fonts");
|
||||
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
Font[] fonts = new Font[MAX_FONTS];
|
||||
|
||||
|
||||
fonts[0] = LoadFont("resources/fonts/alagard.png");
|
||||
fonts[1] = LoadFont("resources/fonts/pixelplay.png");
|
||||
fonts[2] = LoadFont("resources/fonts/mecha.png");
|
||||
@ -40,34 +40,34 @@ public partial class text_raylib_fonts
|
||||
fonts[5] = LoadFont("resources/fonts/pixantiqua.png");
|
||||
fonts[6] = LoadFont("resources/fonts/alpha_beta.png");
|
||||
fonts[7] = LoadFont("resources/fonts/jupiter_crash.png");
|
||||
|
||||
string[] messages = new string[MAX_FONTS] { "ALAGARD FONT designed by Hewett Tsoi",
|
||||
|
||||
string[] messages = new string[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",
|
||||
"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)" };
|
||||
|
||||
|
||||
int[] spacings = new int[MAX_FONTS]{ 2, 4, 8, 4, 3, 4, 4, 1 };
|
||||
|
||||
|
||||
Vector2[] positions = new Vector2[MAX_FONTS];
|
||||
|
||||
|
||||
for (int i = 0; i < MAX_FONTS; i++)
|
||||
{
|
||||
positions[i].x = screenWidth/2 - MeasureTextEx(fonts[i], messages[i], fonts[i].baseSize*2, spacings[i]).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;
|
||||
|
||||
|
||||
Color[] colors = new Color[MAX_FONTS] { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD, RED };
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -75,34 +75,34 @@ public partial class text_raylib_fonts
|
||||
//----------------------------------------------------------------------------------
|
||||
// TODO: Update your variables here
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawText("free fonts included with raylib", 250, 20, 20, DARKGRAY);
|
||||
DrawLine(220, 50, 590, 50, DARKGRAY);
|
||||
|
||||
|
||||
for (int i = 0; i < MAX_FONTS; i++)
|
||||
{
|
||||
DrawTextEx(fonts[i], 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,39 +13,39 @@ public partial class text_sprite_fonts
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [text] example - sprite fonts usage");
|
||||
|
||||
|
||||
string msg1 = "THIS IS A custom SPRITE FONT...";
|
||||
string msg2 = "...and this is ANOTHER CUSTOM font...";
|
||||
string msg3 = "...and a THIRD one! GREAT! :D";
|
||||
|
||||
|
||||
// NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
|
||||
Font font1 = LoadFont("resources/custom_mecha.png"); // Font loading
|
||||
Font font2 = LoadFont("resources/custom_alagard.png"); // Font loading
|
||||
Font font3 = LoadFont("resources/custom_jupiter_crash.png"); // Font loading
|
||||
|
||||
|
||||
Vector2 fontPosition1, fontPosition2, fontPosition3;
|
||||
|
||||
|
||||
fontPosition1.x = screenWidth/2 - MeasureTextEx(font1, msg1, font1.baseSize, -3).x/2;
|
||||
fontPosition1.y = screenHeight/2 - font1.baseSize/2 - 80;
|
||||
|
||||
|
||||
fontPosition2.x = screenWidth/2 - MeasureTextEx(font2, msg2, font2.baseSize, -2).x/2;
|
||||
fontPosition2.y = screenHeight/2 - font2.baseSize/2 - 10;
|
||||
|
||||
|
||||
fontPosition3.x = screenWidth/2 - MeasureTextEx(font3, msg3, font3.baseSize, 2).x/2;
|
||||
fontPosition3.y = screenHeight/2 - font3.baseSize/2 + 50;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -53,30 +53,30 @@ public partial class text_sprite_fonts
|
||||
//----------------------------------------------------------------------------------
|
||||
// TODO: Update variables here...
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawTextEx(font1, msg1, fontPosition1, font1.baseSize, -3, WHITE);
|
||||
DrawTextEx(font2, msg2, fontPosition2, font2.baseSize, -2, WHITE);
|
||||
DrawTextEx(font3, msg3, fontPosition3, font3.baseSize, 2, WHITE);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadFont(font1); // Font unloading
|
||||
UnloadFont(font2); // Font unloading
|
||||
UnloadFont(font3); // Font unloading
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,49 +14,49 @@ public partial class text_ttf_loading
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [text] example - ttf loading");
|
||||
|
||||
|
||||
string msg = "TTF Font";
|
||||
|
||||
|
||||
// NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
|
||||
|
||||
|
||||
// TTF Font loading with custom generation parameters
|
||||
Font font = LoadFontEx("resources/KAISG.ttf", 96, 0, null);
|
||||
|
||||
|
||||
// Generate mipmap levels to use trilinear filtering
|
||||
// NOTE: On 2D drawing it won't be noticeable, it looks like FILTER_BILINEAR
|
||||
GenTextureMipmaps(ref font.texture);
|
||||
|
||||
|
||||
float fontSize = font.baseSize;
|
||||
Vector2 fontPosition = new Vector2( 40, screenHeight/2 - 80 );
|
||||
Vector2 textSize;
|
||||
|
||||
|
||||
SetTextureFilter(font.texture, (int)FILTER_POINT);
|
||||
int currentFontFilter = 0; // FILTER_POINT
|
||||
|
||||
|
||||
// NOTE: Drag and drop support only available for desktop platforms: Windows, Linux, OSX
|
||||
int count = 0;
|
||||
string[] droppedFiles;
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
fontSize += GetMouseWheelMove()*4.0f;
|
||||
|
||||
|
||||
// Choose font texture filter method
|
||||
if (IsKeyPressed(KEY_ONE))
|
||||
{
|
||||
@ -74,17 +74,17 @@ public partial class text_ttf_loading
|
||||
SetTextureFilter(font.texture, (int)FILTER_TRILINEAR);
|
||||
currentFontFilter = 2;
|
||||
}
|
||||
|
||||
|
||||
textSize = MeasureTextEx(font, msg, fontSize, 0);
|
||||
|
||||
|
||||
if (IsKeyDown(KEY_LEFT)) fontPosition.x -= 10;
|
||||
else if (IsKeyDown(KEY_RIGHT)) fontPosition.x += 10;
|
||||
|
||||
|
||||
// Load a dropped TTF file dynamically (at current fontSize)
|
||||
if (IsFileDropped())
|
||||
{
|
||||
droppedFiles = GetDroppedFiles(ref count);
|
||||
|
||||
|
||||
if (count == 1) // Only support one ttf file dropped
|
||||
{
|
||||
UnloadFont(font);
|
||||
@ -93,44 +93,44 @@ public partial class text_ttf_loading
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawText("Use mouse wheel to change font size", 20, 20, 10, GRAY);
|
||||
DrawText("Use KEY_RIGHT and KEY_LEFT to move text", 20, 40, 10, GRAY);
|
||||
DrawText("Use 1, 2, 3 to change texture filter", 20, 60, 10, GRAY);
|
||||
DrawText("Drop a new TTF font for dynamic loading", 20, 80, 10, DARKGRAY);
|
||||
|
||||
|
||||
DrawTextEx(font, msg, fontPosition, fontSize, 0, BLACK);
|
||||
|
||||
|
||||
// TODO: It seems texSize measurement is not accurate due to chars offsets...
|
||||
//DrawRectangleLines(fontPosition.x, fontPosition.y, textSize.x, textSize.y, RED);
|
||||
|
||||
|
||||
DrawRectangle(0, screenHeight - 80, screenWidth, 80, LIGHTGRAY);
|
||||
DrawText(FormatText("Font size: %02.02f", fontSize), 20, screenHeight - 50, 10, DARKGRAY);
|
||||
DrawText(FormatText("Text size: [%02.02f, %02.02f]", textSize.x, textSize.y), 20, screenHeight - 30, 10, DARKGRAY);
|
||||
DrawText("CURRENT TEXTURE FILTER:", 250, 400, 20, GRAY);
|
||||
|
||||
|
||||
if (currentFontFilter == 0) DrawText("POINT", 570, 400, 20, BLACK);
|
||||
else if (currentFontFilter == 1) DrawText("BILINEAR", 570, 400, 20, BLACK);
|
||||
else if (currentFontFilter == 2) DrawText("TRILINEAR", 570, 400, 20, BLACK);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
ClearDroppedFiles(); // Clear internal buffers
|
||||
UnloadFont(font); // Font unloading
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,24 +13,24 @@ public partial class text_writing_anim
|
||||
* Copyright (c) 2016 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [text] example - text writing anim");
|
||||
|
||||
|
||||
string message = "This sample illustrates a text writing\nanimation effect! Check it out! ;)";
|
||||
|
||||
|
||||
int framesCounter = 0;
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -38,30 +38,30 @@ public partial class text_writing_anim
|
||||
//----------------------------------------------------------------------------------
|
||||
if (IsKeyDown(KEY_SPACE)) framesCounter += 8;
|
||||
else framesCounter++;
|
||||
|
||||
|
||||
if (IsKeyPressed(KEY_ENTER)) framesCounter = 0;
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawText(SubText(message, 0, framesCounter/10), 210, 160, 20, MAROON);
|
||||
|
||||
|
||||
DrawText("PRESS [ENTER] to RESTART!", 240, 260, 20, LIGHTGRAY);
|
||||
DrawText("PRESS [SPACE] to SPEED UP!", 239, 300, 20, LIGHTGRAY);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user