aboutsummaryrefslogtreecommitdiff
path: root/examples/text/text_draw_inside_rectangle.c
diff options
context:
space:
mode:
authorRay <raysan5@gmail.com>2019-05-14 15:34:23 +0200
committerRay <raysan5@gmail.com>2019-05-14 15:34:23 +0200
commit424d3ca8d9c5d612606444b2a2099cfad37f1888 (patch)
tree873e8ec9dbd5965d828ed450a8c12feafe714597 /examples/text/text_draw_inside_rectangle.c
parent2edec8ae288ba70630021b330fe61c9005bc03d9 (diff)
downloadraylib-424d3ca8d9c5d612606444b2a2099cfad37f1888.tar.gz
raylib-424d3ca8d9c5d612606444b2a2099cfad37f1888.zip
examples review
Redesigns, deletes and renames Also noted authors propertly on contributed examples
Diffstat (limited to 'examples/text/text_draw_inside_rectangle.c')
-rw-r--r--examples/text/text_draw_inside_rectangle.c120
1 files changed, 0 insertions, 120 deletions
diff --git a/examples/text/text_draw_inside_rectangle.c b/examples/text/text_draw_inside_rectangle.c
deleted file mode 100644
index e60fa5e5..00000000
--- a/examples/text/text_draw_inside_rectangle.c
+++ /dev/null
@@ -1,120 +0,0 @@
-/*******************************************************************************************
-*
-* raylib [text] example - Draw text inside a rectangle
-*
-* This example has been created using raylib 2.3 (www.raylib.com)
-* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
-*
-* Copyright (c) 2018 Vlad Adrian (@demizdor)
-*
-********************************************************************************************/
-
-#include "raylib.h"
-
-int main()
-{
- // Initialization
- //--------------------------------------------------------------------------------------
- int screenWidth = 800;
- int screenHeight = 450;
-
- InitWindow(screenWidth, screenHeight, "raylib [text] example - draw text inside a rectangle");
-
- char text[] = "Text cannot escape\tthis container\t...word wrap also works when active so here's\
- a long text for testing.\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod\
- tempor incididunt ut labore et dolore magna aliqua. Nec ullamcorper sit amet risus nullam eget felis eget.";
-
- bool resizing = false;
- bool wordWrap = true;
-
- Rectangle container = { 25, 25, screenWidth - 50, screenHeight - 250};
- Rectangle resizer = { container.x + container.width - 17, container.y + container.height - 17, 14, 14 };
-
- // Minimum width and heigh for the container rectangle
- const int minWidth = 60;
- const int minHeight = 60;
- const int maxWidth = screenWidth - 50;
- const int maxHeight = screenHeight - 160;
-
- Vector2 lastMouse = { 0, 0 }; // Stores last mouse coordinates
-
- Color borderColor = MAROON; // Container border color
-
- Font font = GetFontDefault(); // Get default system font
-
- SetTargetFPS(60);
- //--------------------------------------------------------------------------------------
-
- // Main game loop
- while (!WindowShouldClose()) // Detect window close button or ESC key
- {
- // 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 (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
- {
- // 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
- //----------------------------------------------------------------------------------
-
- // Draw
- //----------------------------------------------------------------------------------
- BeginDrawing();
-
- 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 },
- 20.0f, 2.0f, wordWrap, GRAY);
-
- DrawRectangleRec(resizer, borderColor); // Draw the resize box
-
- // Draw info
- DrawText("Word Wrap: ", 313, screenHeight-115, 20, BLACK);
- if (wordWrap) DrawText("ON", 447, screenHeight - 115, 20, RED);
- else DrawText("OFF", 447, screenHeight - 115, 20, BLACK);
- DrawText("Press [SPACE] to toggle word wrap", 218, screenHeight - 91, 20, GRAY);
-
- 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();
- //----------------------------------------------------------------------------------
- }
-
- // De-Initialization
- //--------------------------------------------------------------------------------------
- CloseWindow(); // Close window and OpenGL context
- //--------------------------------------------------------------------------------------
-
- return 0;
-} \ No newline at end of file