summaryrefslogtreecommitdiffhomepage
path: root/examples/web/text/text_rectangle_bounds.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/web/text/text_rectangle_bounds.c')
-rw-r--r--examples/web/text/text_rectangle_bounds.c50
1 files changed, 25 insertions, 25 deletions
diff --git a/examples/web/text/text_rectangle_bounds.c b/examples/web/text/text_rectangle_bounds.c
index 90a3c7e..ffe7f2c 100644
--- a/examples/web/text/text_rectangle_bounds.c
+++ b/examples/web/text/text_rectangle_bounds.c
@@ -20,8 +20,8 @@
//----------------------------------------------------------------------------------
// Global Variables Definition
//----------------------------------------------------------------------------------
-int screenWidth = 800;
-int screenHeight = 450;
+const int screenWidth = 800;
+const int screenHeight = 450;
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
@@ -32,12 +32,12 @@ tempor incididunt ut labore et dolore magna aliqua. Nec ullamcorper sit amet ris
bool resizing = false;
bool wordWrap = true;
-Rectangle container;
-Rectangle resizer;
+Rectangle container = { 0 };
+Rectangle resizer = { 0 };
// Minimum width and heigh for the container rectangle
int minWidth = 60;
-int minHeight = 60;
+int minHeight = 60;
int maxWidth = 0;
int maxHeight = 0;
@@ -51,9 +51,9 @@ Font font = { 0 };
void UpdateDrawFrame(void); // Update and Draw one frame
//----------------------------------------------------------------------------------
-// Main Enry Point
+// Program Main Entry Point
//----------------------------------------------------------------------------------
-int main()
+int main(void)
{
// Initialization
//--------------------------------------------------------------------------------------
@@ -61,18 +61,18 @@ int main()
container = (Rectangle){ 25, 25, screenWidth - 50, screenHeight - 250};
resizer = (Rectangle){ container.x + container.width - 17, container.y + container.height - 17, 14, 14 };
-
+
maxWidth = screenWidth - 50;
maxHeight = screenHeight - 160;
font = GetFontDefault(); // Get default system font
-
+
#if defined(PLATFORM_WEB)
emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
#else
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
-
+
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
@@ -81,7 +81,7 @@ int main()
#endif
// De-Initialization
- //--------------------------------------------------------------------------------------
+ //--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
@@ -96,34 +96,34 @@ void UpdateDrawFrame(void)
// Update
//----------------------------------------------------------------------------------
if (IsKeyPressed(KEY_SPACE)) wordWrap = !wordWrap;
-
+
Vector2 mouse = GetMousePosition();
-
+
// Check if the mouse is inside the container and toggle border color
if (CheckCollisionPointRec(mouse, container)) borderColor = Fade(MAROON, 0.4f);
else if (!resizing) borderColor = MAROON;
-
+
// Container resizing logic
- if (resizing)
+ if (resizing)
{
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) resizing = false;
-
+
int width = container.width + (mouse.x - lastMouse.x);
container.width = (width > minWidth)? ((width < maxWidth)? width : maxWidth) : minWidth;
-
+
int height = container.height + (mouse.y - lastMouse.y);
container.height = (height > minHeight)? ((height < maxHeight)? height : maxHeight) : minHeight;
- }
- else
+ }
+ else
{
// Check if we're resizing
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON) && CheckCollisionPointRec(mouse, resizer)) resizing = true;
}
-
+
// Move resizer rectangle properly
resizer.x = container.x + container.width - 17;
resizer.y = container.y + container.height - 17;
-
+
lastMouse = mouse; // Update mouse
//----------------------------------------------------------------------------------
@@ -134,10 +134,10 @@ void UpdateDrawFrame(void)
ClearBackground(RAYWHITE);
DrawRectangleLinesEx(container, 3, borderColor); // Draw container border
-
+
// Draw text in container (add some padding)
- DrawTextRec(font, text,
- (Rectangle){ container.x + 4, container.y + 4, container.width - 4, container.height - 4 },
+ DrawTextRec(font, text,
+ (Rectangle){ container.x + 4, container.y + 4, container.width - 4, container.height - 4 },
20.0f, 2.0f, wordWrap, GRAY);
DrawRectangleRec(resizer, borderColor); // Draw the resize box
@@ -151,7 +151,7 @@ void UpdateDrawFrame(void)
DrawRectangle(0, screenHeight - 54, screenWidth, 54, GRAY);
DrawText("Click hold & drag the to resize the container", 155, screenHeight - 38, 20, RAYWHITE);
DrawRectangleRec((Rectangle){ 382, screenHeight - 34, 12, 12 }, MAROON);
-
+
EndDrawing();
//----------------------------------------------------------------------------------
}