aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorraysan5 <raysan5@gmail.com>2013-12-27 00:17:39 +0100
committerraysan5 <raysan5@gmail.com>2013-12-27 00:17:39 +0100
commita0d719d95f60d0b2109cebff29603625c3c3cbe1 (patch)
tree1fdf93b234be458b1d25ad372ed7106878c71bf9 /examples
parentcfb42dc251d5cbadb76f5fdab010a389989228d2 (diff)
downloadraylib-a0d719d95f60d0b2109cebff29603625c3c3cbe1.tar.gz
raylib-a0d719d95f60d0b2109cebff29603625c3c3cbe1.zip
Updated examples
Diffstat (limited to 'examples')
-rw-r--r--examples/ex05b_rbmf_fonts.c2
-rw-r--r--examples/ex06a_color_select.c52
-rw-r--r--examples/ex06a_color_select.exebin0 -> 332782 bytes
-rw-r--r--examples/ex06a_color_select.pngbin3913 -> 14328 bytes
-rw-r--r--examples/ex06c_font_select.c100
-rw-r--r--examples/ex06c_font_select.exebin0 -> 334317 bytes
-rw-r--r--examples/ex06c_font_select.pngbin3913 -> 3097 bytes
7 files changed, 146 insertions, 8 deletions
diff --git a/examples/ex05b_rbmf_fonts.c b/examples/ex05b_rbmf_fonts.c
index bc7fc852..71853d5f 100644
--- a/examples/ex05b_rbmf_fonts.c
+++ b/examples/ex05b_rbmf_fonts.c
@@ -9,7 +9,7 @@
*
********************************************************************************************/
-#include "../raylib.h"
+#include "raylib.h"
int main()
{
diff --git a/examples/ex06a_color_select.c b/examples/ex06a_color_select.c
index 3a243e8f..febec407 100644
--- a/examples/ex06a_color_select.c
+++ b/examples/ex06a_color_select.c
@@ -16,9 +16,30 @@ int main()
// Initialization
//--------------------------------------------------------------------------------------
int screenWidth = 800;
- int screenHeight = 450;
+ int screenHeight = 400;
- InitWindow(screenWidth, screenHeight, "raylib example 06a - color selection");
+ Color colors[21] = { DARKGRAY, MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, DARKBROWN,
+ GRAY, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK, YELLOW,
+ GREEN, SKYBLUE, PURPLE, BEIGE };
+
+ Rectangle recs[21]; // Rectangles array
+
+ // Fills recs data (for every rectangle)
+ for (int i = 0; i < 21; i++)
+ {
+ recs[i].x = 20 + 100*(i%7) + 10*(i%7);
+ recs[i].y = 40 + 100*(i/7) + 10*(i/7);
+ recs[i].width = 100;
+ recs[i].height = 100;
+ }
+
+ bool selected[21] = { false }; // Selected rectangles indicator
+
+ Vector2 mousePoint;
+
+ InitWindowEx(screenWidth, screenHeight, "raylib example 06a - color selection", false, "resources/mouse.png");
+
+ SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop
@@ -26,7 +47,18 @@ int main()
{
// Update
//----------------------------------------------------------------------------------
- // TODO: Update your variables here
+ mousePoint = GetMousePosition();
+
+ for (int i = 0; i < 21; i++) // Iterate along all the rectangles
+ {
+ if (CheckCollisionPointRec(mousePoint, recs[i]))
+ {
+ colors[i].a = 120;
+
+ if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) selected[i] = !selected[i];
+ }
+ else colors[i].a = 255;
+ }
//----------------------------------------------------------------------------------
// Draw
@@ -35,7 +67,19 @@ int main()
ClearBackground(RAYWHITE);
- // TODO: Comming soon...
+ for (int i = 0; i < 21; i++) // Draw all rectangles
+ {
+ DrawRectangleRec(recs[i], colors[i]);
+
+ // Draw four rectangles around selected rectangle
+ if (selected[i])
+ {
+ DrawRectangle(recs[i].x, recs[i].y, 100, 10, RAYWHITE); // Square top rectangle
+ DrawRectangle(recs[i].x, recs[i].y, 10, 100, RAYWHITE); // Square left rectangle
+ DrawRectangle(recs[i].x + 90, recs[i].y, 10, 100, RAYWHITE); // Square right rectangle
+ DrawRectangle(recs[i].x, recs[i].y + 90, 100, 10, RAYWHITE); // Square bottom rectangle
+ }
+ }
EndDrawing();
//----------------------------------------------------------------------------------
diff --git a/examples/ex06a_color_select.exe b/examples/ex06a_color_select.exe
new file mode 100644
index 00000000..07b57afe
--- /dev/null
+++ b/examples/ex06a_color_select.exe
Binary files differ
diff --git a/examples/ex06a_color_select.png b/examples/ex06a_color_select.png
index f18ae044..93ab83ae 100644
--- a/examples/ex06a_color_select.png
+++ b/examples/ex06a_color_select.png
Binary files differ
diff --git a/examples/ex06c_font_select.c b/examples/ex06c_font_select.c
index bf13b67b..71a04ef0 100644
--- a/examples/ex06c_font_select.c
+++ b/examples/ex06c_font_select.c
@@ -16,9 +16,43 @@ int main()
// Initialization
//--------------------------------------------------------------------------------------
int screenWidth = 800;
- int screenHeight = 450;
+ int screenHeight = 150;
InitWindow(screenWidth, screenHeight, "raylib example 06c - font selection");
+
+ // 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, GetFontBaseSize(fonts[currentFont])*3, 1);
+
+ Vector2 mousePoint;
+
+ Rectangle btnNextRec = { 673, 18, 109, 44 }; // Button rectangle (useful for collision)
+
+ Color btnNextOutColor = DARKBLUE; // Button color (outside line)
+ Color btnNextInColor = SKYBLUE; // Button color (inside)
+
+ int framesCounter = 0; // Useful to count frames button is 'active' = clicked
+
+ SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop
@@ -26,7 +60,54 @@ int main()
{
// Update
//----------------------------------------------------------------------------------
- // TODO: Update your variables here
+
+ // Keyboard-based font selection (easy)
+ if (IsKeyPressed(KEY_RIGHT))
+ {
+ if (currentFont < 7) currentFont++;
+ }
+
+ if (IsKeyPressed(KEY_LEFT))
+ {
+ if (currentFont > 0) currentFont--;
+ }
+
+ // 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 (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
+ {
+ framesCounter = 20; // Frames button is 'active'
+ btnNextOutColor = MAROON;
+ btnNextInColor = RED;
+ }
+ }
+ else
+ {
+ // Mouse not hover button
+ btnNextOutColor = DARKBLUE;
+ btnNextInColor = SKYBLUE;
+ }
+
+ if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON) && (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, GetFontBaseSize(fonts[currentFont])*3, 1);
//----------------------------------------------------------------------------------
// Draw
@@ -35,7 +116,18 @@ int main()
ClearBackground(RAYWHITE);
- // TODO: Comming soon...
+ DrawRectangle(18, 18, 644, 44, DARKGRAY);
+ DrawRectangle(20, 20, 640, 40, LIGHTGRAY);
+ DrawText(fontNames[currentFont], 30, 31, 20, BLACK);
+ DrawText("< >", 610, 26, 30, BLACK);
+
+ DrawRectangleRec(btnNextRec, btnNextOutColor);
+ DrawRectangle(675, 20, 105, 40, btnNextInColor);
+ DrawText("NEXT", 700, 31, 20, btnNextOutColor);
+
+ DrawTextEx(fonts[currentFont], text, (Vector2){ screenWidth/2 - textSize.x/2,
+ 75 + (70 - textSize.y)/2 }, GetFontBaseSize(fonts[currentFont])*3,
+ 1, colors[currentFont]);
EndDrawing();
//----------------------------------------------------------------------------------
@@ -43,6 +135,8 @@ int main()
// De-Initialization
//--------------------------------------------------------------------------------------
+ for (int i = 0; i < 8; i++) UnloadSpriteFont(fonts[i]); // SpriteFont(s) unloading
+
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
diff --git a/examples/ex06c_font_select.exe b/examples/ex06c_font_select.exe
new file mode 100644
index 00000000..a2919726
--- /dev/null
+++ b/examples/ex06c_font_select.exe
Binary files differ
diff --git a/examples/ex06c_font_select.png b/examples/ex06c_font_select.png
index f18ae044..27bf9432 100644
--- a/examples/ex06c_font_select.png
+++ b/examples/ex06c_font_select.png
Binary files differ