mirror of
https://github.com/raysan5/raylib.git
synced 2025-11-13 13:58:46 +00:00
Review example formating
This commit is contained in:
@@ -16,7 +16,8 @@
|
|||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
#include "raymath.h" // For Lerp
|
|
||||||
|
#include "raymath.h" // Required for: Lerp()
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Program main entry point
|
// Program main entry point
|
||||||
@@ -38,15 +39,15 @@ int main(void)
|
|||||||
.zoom = 1
|
.zoom = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
// Loading file from resources/text_file.txt
|
// Loading text file from resources/text_file.txt
|
||||||
const char *fileName = "resources/text_file.txt";
|
const char *fileName = "resources/text_file.txt";
|
||||||
char *fileData = LoadFileText(fileName);
|
char *text = LoadFileText(fileName);
|
||||||
|
|
||||||
// Loading all the lines
|
// Loading all the text lines
|
||||||
int lineCount = 0;
|
int lineCount = 0;
|
||||||
char **lines = LoadTextLines(fileData, &lineCount);
|
char **lines = LoadTextLines(text, &lineCount);
|
||||||
|
|
||||||
// Just sylistic choise
|
// Stylistic choises
|
||||||
int fontSize = 20;
|
int fontSize = 20;
|
||||||
int textTop = 25 + fontSize; // Top of the screen from where the text is rendered
|
int textTop = 25 + fontSize; // Top of the screen from where the text is rendered
|
||||||
int wrapWidth = screenWidth - 20;
|
int wrapWidth = screenWidth - 20;
|
||||||
@@ -99,7 +100,6 @@ int main(void)
|
|||||||
.height = screenHeight*100/(textHeight - screenHeight) // Scrollbar height is just a percentage
|
.height = screenHeight*100/(textHeight - screenHeight) // Scrollbar height is just a percentage
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -109,16 +109,17 @@ int main(void)
|
|||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
float scroll = GetMouseWheelMove();
|
float scroll = GetMouseWheelMove();
|
||||||
cam.target.y -= scroll * fontSize * 1.5; // Choosing an arbitrary speed for scroll
|
cam.target.y -= scroll*fontSize*1.5f; // Choosing an arbitrary speed for scroll
|
||||||
|
|
||||||
if(cam.target.y < 0) // Snapping to 0 if we go too far back
|
if (cam.target.y < 0) cam.target.y = 0; // Snapping to 0 if we go too far back
|
||||||
cam.target.y = 0;
|
|
||||||
|
|
||||||
if(cam.target.y > textHeight - screenHeight + textTop) // Ensuring that the camera does not scroll past all text
|
// Ensuring that the camera does not scroll past all text
|
||||||
|
if (cam.target.y > textHeight - screenHeight + textTop)
|
||||||
cam.target.y = textHeight - screenHeight + textTop;
|
cam.target.y = textHeight - screenHeight + textTop;
|
||||||
|
|
||||||
// Computing the position of the scrollBar depending on the percentage of text covered.
|
// Computing the position of the scrollBar depending on the percentage of text covered
|
||||||
scrollBar.y = Lerp(textTop, screenHeight - scrollBar.height, (cam.target.y - textTop)/(textHeight - screenHeight));
|
scrollBar.y = Lerp(textTop, screenHeight - scrollBar.height, (cam.target.y - textTop)/(textHeight - screenHeight));
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
@@ -127,17 +128,16 @@ int main(void)
|
|||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
BeginMode2D(cam);
|
BeginMode2D(cam);
|
||||||
|
|
||||||
Font defaultFont = GetFontDefault();
|
|
||||||
|
|
||||||
// Going through all the read lines
|
// Going through all the read lines
|
||||||
for (int i = 0, t = textTop; i < lineCount; i++)
|
for (int i = 0, t = textTop; i < lineCount; i++)
|
||||||
{
|
{
|
||||||
// Each time we go through and calculate the height of the text to move the cursor appropriately
|
// Each time we go through and calculate the height of the text to move the cursor appropriately
|
||||||
Vector2 size = MeasureTextEx(defaultFont, lines[i], fontSize, 2);
|
Vector2 size = MeasureTextEx(GetFontDefault(), lines[i], fontSize, 2);
|
||||||
|
|
||||||
DrawText(lines[i], 10, t, fontSize, RED);
|
DrawText(lines[i], 10, t, fontSize, RED);
|
||||||
|
|
||||||
// Inserting extra space for real newlines, wrapped lines are rendered closer together
|
// Inserting extra space for real newlines,
|
||||||
|
// wrapped lines are rendered closer together
|
||||||
t += size.y + 10;
|
t += size.y + 10;
|
||||||
}
|
}
|
||||||
EndMode2D();
|
EndMode2D();
|
||||||
@@ -155,7 +155,7 @@ int main(void)
|
|||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
UnloadTextLines(lines, lineCount);
|
UnloadTextLines(lines, lineCount);
|
||||||
UnloadFileText(fileData);
|
UnloadFileText(text);
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user