mirror of
https://github.com/raysan5/raylib.git
synced 2025-11-03 17:24:25 +00:00
EXAMPLES: Format tweaks
This commit is contained in:
@@ -47,7 +47,7 @@ int main ()
|
||||
//----------------------------------------------------------------------------------
|
||||
if (IsKeyPressed(KEY_ONE)) zoomMode = 0;
|
||||
else if (IsKeyPressed(KEY_TWO)) zoomMode = 1;
|
||||
|
||||
|
||||
// Translate based on mouse right click
|
||||
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT))
|
||||
{
|
||||
@@ -68,7 +68,7 @@ int main ()
|
||||
// Set the offset to where the mouse is
|
||||
camera.offset = GetMousePosition();
|
||||
|
||||
// Set the target to match, so that the camera maps the world space point
|
||||
// Set the target to match, so that the camera maps the world space point
|
||||
// under the cursor to the screen space point under the cursor at any zoom
|
||||
camera.target = mouseWorldPos;
|
||||
|
||||
@@ -89,7 +89,7 @@ int main ()
|
||||
// Set the offset to where the mouse is
|
||||
camera.offset = GetMousePosition();
|
||||
|
||||
// Set the target to match, so that the camera maps the world space point
|
||||
// Set the target to match, so that the camera maps the world space point
|
||||
// under the cursor to the screen space point under the cursor at any zoom
|
||||
camera.target = mouseWorldPos;
|
||||
}
|
||||
@@ -111,7 +111,7 @@ int main ()
|
||||
|
||||
BeginMode2D(camera);
|
||||
|
||||
// Draw the 3d grid, rotated 90 degrees and centered around 0,0
|
||||
// Draw the 3d grid, rotated 90 degrees and centered around 0,0
|
||||
// just so we have something in the XY plane
|
||||
rlPushMatrix();
|
||||
rlTranslatef(0, 25*50, 0);
|
||||
@@ -121,19 +121,19 @@ int main ()
|
||||
|
||||
// Draw a reference circle
|
||||
DrawCircle(GetScreenWidth()/2, GetScreenHeight()/2, 50, MAROON);
|
||||
|
||||
|
||||
EndMode2D();
|
||||
|
||||
|
||||
// Draw mouse reference
|
||||
//Vector2 mousePos = GetWorldToScreen2D(GetMousePosition(), camera)
|
||||
DrawCircleV(GetMousePosition(), 4, DARKGRAY);
|
||||
DrawTextEx(GetFontDefault(), TextFormat("[%i, %i]", GetMouseX(), GetMouseY()),
|
||||
DrawTextEx(GetFontDefault(), TextFormat("[%i, %i]", GetMouseX(), GetMouseY()),
|
||||
Vector2Add(GetMousePosition(), (Vector2){ -44, -24 }), 20, 2, BLACK);
|
||||
|
||||
DrawText("[1][2] Select mouse zoom mode (Wheel or Move)", 20, 20, 20, DARKGRAY);
|
||||
if (zoomMode == 0) DrawText("Mouse left button drag to move, mouse wheel to zoom", 20, 50, 20, DARKGRAY);
|
||||
else DrawText("Mouse left button drag to move, mouse press and move to zoom", 20, 50, 20, DARKGRAY);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ int main(void)
|
||||
|
||||
Rectangle playerRect = { player.position.x - 20, player.position.y - 40, 40.0f, 40.0f };
|
||||
DrawRectangleRec(playerRect, RED);
|
||||
|
||||
|
||||
DrawCircleV(player.position, 5.0f, GOLD);
|
||||
|
||||
EndMode2D();
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* Example complexity rating: [★★★★] 4/4
|
||||
*
|
||||
* Addapted from the core_3d_camera_split_screen example:
|
||||
* Addapted from the core_3d_camera_split_screen example:
|
||||
* https://github.com/raysan5/raylib/blob/master/examples/core/core_3d_camera_split_screen.c
|
||||
*
|
||||
* Example originally created with raylib 4.5, last time updated with raylib 4.5
|
||||
@@ -81,9 +81,9 @@ int main(void)
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginTextureMode(screenCamera1);
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginMode2D(camera1);
|
||||
|
||||
|
||||
// Draw full scene with first camera
|
||||
for (int i = 0; i < screenWidth/PLAYER_SIZE + 1; i++)
|
||||
{
|
||||
@@ -106,17 +106,17 @@ int main(void)
|
||||
DrawRectangleRec(player1, RED);
|
||||
DrawRectangleRec(player2, BLUE);
|
||||
EndMode2D();
|
||||
|
||||
|
||||
DrawRectangle(0, 0, GetScreenWidth()/2, 30, Fade(RAYWHITE, 0.6f));
|
||||
DrawText("PLAYER1: W/S/A/D to move", 10, 10, 10, MAROON);
|
||||
|
||||
|
||||
EndTextureMode();
|
||||
|
||||
BeginTextureMode(screenCamera2);
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginMode2D(camera2);
|
||||
|
||||
|
||||
// Draw full scene with second camera
|
||||
for (int i = 0; i < screenWidth/PLAYER_SIZE + 1; i++)
|
||||
{
|
||||
@@ -138,21 +138,21 @@ int main(void)
|
||||
|
||||
DrawRectangleRec(player1, RED);
|
||||
DrawRectangleRec(player2, BLUE);
|
||||
|
||||
|
||||
EndMode2D();
|
||||
|
||||
|
||||
DrawRectangle(0, 0, GetScreenWidth()/2, 30, Fade(RAYWHITE, 0.6f));
|
||||
DrawText("PLAYER2: UP/DOWN/LEFT/RIGHT to move", 10, 10, 10, DARKBLUE);
|
||||
|
||||
|
||||
EndTextureMode();
|
||||
|
||||
// Draw both views render textures to the screen side by side
|
||||
BeginDrawing();
|
||||
ClearBackground(BLACK);
|
||||
|
||||
|
||||
DrawTextureRec(screenCamera1.texture, splitScreenRect, (Vector2){ 0, 0 }, WHITE);
|
||||
DrawTextureRec(screenCamera2.texture, splitScreenRect, (Vector2){ screenWidth/2.0f, 0 }, WHITE);
|
||||
|
||||
|
||||
DrawRectangle(GetScreenWidth()/2 - 2, 0, 4, GetScreenHeight(), LIGHTGRAY);
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ int main(void)
|
||||
UpdateCameraPro(&camera,
|
||||
(Vector3){
|
||||
(IsKeyDown(KEY_W) || IsKeyDown(KEY_UP))*0.1f - // Move forward-backward
|
||||
(IsKeyDown(KEY_S) || IsKeyDown(KEY_DOWN))*0.1f,
|
||||
(IsKeyDown(KEY_S) || IsKeyDown(KEY_DOWN))*0.1f,
|
||||
(IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT))*0.1f - // Move right-left
|
||||
(IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT))*0.1f,
|
||||
0.0f // Move up-down
|
||||
|
||||
@@ -51,7 +51,7 @@ int main(void)
|
||||
|
||||
// Build a flipped rectangle the size of the split view to use for drawing later
|
||||
Rectangle splitScreenRect = { 0.0f, 0.0f, (float)screenPlayer1.texture.width, (float)-screenPlayer1.texture.height };
|
||||
|
||||
|
||||
// Grid data
|
||||
int count = 5;
|
||||
float spacing = 4;
|
||||
@@ -98,9 +98,9 @@ int main(void)
|
||||
// Draw Player1 view to the render texture
|
||||
BeginTextureMode(screenPlayer1);
|
||||
ClearBackground(SKYBLUE);
|
||||
|
||||
|
||||
BeginMode3D(cameraPlayer1);
|
||||
|
||||
|
||||
// Draw scene: grid of cube trees on a plane to make a "world"
|
||||
DrawPlane((Vector3){ 0, 0, 0 }, (Vector2){ 50, 50 }, BEIGE); // Simple world plane
|
||||
|
||||
@@ -116,20 +116,20 @@ int main(void)
|
||||
// Draw a cube at each player's position
|
||||
DrawCube(cameraPlayer1.position, 1, 1, 1, RED);
|
||||
DrawCube(cameraPlayer2.position, 1, 1, 1, BLUE);
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
DrawRectangle(0, 0, GetScreenWidth()/2, 40, Fade(RAYWHITE, 0.8f));
|
||||
DrawText("PLAYER1: W/S to move", 10, 10, 20, MAROON);
|
||||
|
||||
|
||||
EndTextureMode();
|
||||
|
||||
// Draw Player2 view to the render texture
|
||||
BeginTextureMode(screenPlayer2);
|
||||
ClearBackground(SKYBLUE);
|
||||
|
||||
|
||||
BeginMode3D(cameraPlayer2);
|
||||
|
||||
|
||||
// Draw scene: grid of cube trees on a plane to make a "world"
|
||||
DrawPlane((Vector3){ 0, 0, 0 }, (Vector2){ 50, 50 }, BEIGE); // Simple world plane
|
||||
|
||||
@@ -145,21 +145,21 @@ int main(void)
|
||||
// Draw a cube at each player's position
|
||||
DrawCube(cameraPlayer1.position, 1, 1, 1, RED);
|
||||
DrawCube(cameraPlayer2.position, 1, 1, 1, BLUE);
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
DrawRectangle(0, 0, GetScreenWidth()/2, 40, Fade(RAYWHITE, 0.8f));
|
||||
DrawText("PLAYER2: UP/DOWN to move", 10, 10, 20, DARKBLUE);
|
||||
|
||||
|
||||
EndTextureMode();
|
||||
|
||||
// Draw both views render textures to the screen side by side
|
||||
BeginDrawing();
|
||||
ClearBackground(BLACK);
|
||||
|
||||
|
||||
DrawTextureRec(screenPlayer1.texture, splitScreenRect, (Vector2){ 0, 0 }, WHITE);
|
||||
DrawTextureRec(screenPlayer2.texture, splitScreenRect, (Vector2){ screenWidth/2.0f, 0 }, WHITE);
|
||||
|
||||
|
||||
DrawRectangle(GetScreenWidth()/2 - 2, 0, 4, GetScreenHeight(), LIGHTGRAY);
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ int main(void)
|
||||
player.position = (Vector2){ 400, 280 };
|
||||
player.speed = 0;
|
||||
player.canJump = false;
|
||||
|
||||
|
||||
// Define environment elements (platforms)
|
||||
EnvElement envElements[MAX_ENVIRONMENT_ELEMENTS] = {
|
||||
{{ 0, 0, 1000, 400 }, 0, LIGHTGRAY },
|
||||
@@ -70,13 +70,13 @@ int main(void)
|
||||
camera.offset = (Vector2){ screenWidth/2.0f, screenHeight/2.0f };
|
||||
camera.rotation = 0.0f;
|
||||
camera.zoom = 1.0f;
|
||||
|
||||
|
||||
// Automation events
|
||||
AutomationEventList aelist = LoadAutomationEventList(0); // Initialize list of automation events to record new events
|
||||
SetAutomationEventList(&aelist);
|
||||
bool eventRecording = false;
|
||||
bool eventPlaying = false;
|
||||
|
||||
|
||||
unsigned int frameCounter = 0;
|
||||
unsigned int playFrameCounter = 0;
|
||||
unsigned int currentPlayFrame = 0;
|
||||
@@ -90,7 +90,7 @@ int main(void)
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
float deltaTime = 0.015f;//GetFrameTime();
|
||||
|
||||
|
||||
// Dropped files logic
|
||||
//----------------------------------------------------------------------------------
|
||||
if (IsFileDropped())
|
||||
@@ -102,14 +102,14 @@ int main(void)
|
||||
{
|
||||
UnloadAutomationEventList(aelist);
|
||||
aelist = LoadAutomationEventList(droppedFiles.paths[0]);
|
||||
|
||||
|
||||
eventRecording = false;
|
||||
|
||||
|
||||
// Reset scene state to play
|
||||
eventPlaying = true;
|
||||
playFrameCounter = 0;
|
||||
currentPlayFrame = 0;
|
||||
|
||||
|
||||
player.position = (Vector2){ 400, 280 };
|
||||
player.speed = 0;
|
||||
player.canJump = false;
|
||||
@@ -174,7 +174,7 @@ int main(void)
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Events playing
|
||||
// NOTE: Logic must be before Camera update because it depends on mouse-wheel value,
|
||||
// NOTE: Logic must be before Camera update because it depends on mouse-wheel value,
|
||||
// that can be set by the played event... but some other inputs could be affected
|
||||
//----------------------------------------------------------------------------------
|
||||
if (eventPlaying)
|
||||
@@ -228,7 +228,7 @@ int main(void)
|
||||
if (min.x > 0) camera.offset.x = screenWidth/2 - min.x;
|
||||
if (min.y > 0) camera.offset.y = screenHeight/2 - min.y;
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Events management
|
||||
if (IsKeyPressed(KEY_S)) // Toggle events recording
|
||||
{
|
||||
@@ -238,12 +238,12 @@ int main(void)
|
||||
{
|
||||
StopAutomationEventRecording();
|
||||
eventRecording = false;
|
||||
|
||||
|
||||
ExportAutomationEventList(aelist, "automation.rae");
|
||||
|
||||
|
||||
TraceLog(LOG_INFO, "RECORDED FRAMES: %i", aelist.count);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
SetAutomationEventBaseFrame(180);
|
||||
StartAutomationEventRecording();
|
||||
@@ -293,7 +293,7 @@ int main(void)
|
||||
DrawRectangleRec((Rectangle){ player.position.x - 20, player.position.y - 40, 40, 40 }, RED);
|
||||
|
||||
EndMode2D();
|
||||
|
||||
|
||||
// Draw game controls
|
||||
DrawRectangle(10, 10, 290, 145, Fade(SKYBLUE, 0.5f));
|
||||
DrawRectangleLines(10, 10, 290, 145, Fade(BLUE, 0.8f));
|
||||
@@ -323,7 +323,7 @@ int main(void)
|
||||
|
||||
if (((frameCounter/15)%2) == 1) DrawText(TextFormat("PLAYING RECORDED EVENTS... [%i]", currentPlayFrame), 50, 170, 10, DARKGREEN);
|
||||
}
|
||||
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
@@ -39,7 +39,7 @@ int main(void)
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - custom frame control");
|
||||
|
||||
// Custom timming variables
|
||||
@@ -48,11 +48,11 @@ int main(void)
|
||||
double updateDrawTime = 0.0; // Update + Draw time
|
||||
double waitTime = 0.0; // Wait time (if target fps required)
|
||||
float deltaTime = 0.0f; // Frame time (Update + Draw + Wait time)
|
||||
|
||||
|
||||
float timeCounter = 0.0f; // Accumulative time counter (seconds)
|
||||
float position = 0.0f; // Circle position
|
||||
bool pause = false; // Pause control flag
|
||||
|
||||
|
||||
int targetFPS = 60; // Our initial target fps
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
@@ -64,12 +64,12 @@ int main(void)
|
||||
#ifndef PLATFORM_WEB // NOTE: On non web platforms the PollInputEvents just works before the inputs checks
|
||||
PollInputEvents(); // Poll input events (SUPPORT_CUSTOM_FRAME_CONTROL)
|
||||
#endif
|
||||
|
||||
|
||||
if (IsKeyPressed(KEY_SPACE)) pause = !pause;
|
||||
|
||||
|
||||
if (IsKeyPressed(KEY_UP)) targetFPS += 20;
|
||||
else if (IsKeyPressed(KEY_DOWN)) targetFPS -= 20;
|
||||
|
||||
|
||||
if (targetFPS < 0) targetFPS = 0;
|
||||
|
||||
if (!pause)
|
||||
@@ -91,12 +91,12 @@ int main(void)
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
for (int i = 0; i < GetScreenWidth()/200; i++) DrawRectangle(200*i, 0, 1, GetScreenHeight(), SKYBLUE);
|
||||
|
||||
|
||||
DrawCircle((int)position, GetScreenHeight()/2 - 25, 50, RED);
|
||||
|
||||
|
||||
DrawText(TextFormat("%03.0f ms", timeCounter*1000.0f), (int)position - 40, GetScreenHeight()/2 - 100, 20, MAROON);
|
||||
DrawText(TextFormat("PosX: %03.0f", position), (int)position - 50, GetScreenHeight()/2 + 40, 20, BLACK);
|
||||
|
||||
|
||||
DrawText("Circle is moving at a constant 200 pixels/sec,\nindependently of the frame rate.", 10, 10, 20, DARKGRAY);
|
||||
DrawText("PRESS SPACE to PAUSE MOVEMENT", 10, GetScreenHeight() - 60, 20, GRAY);
|
||||
DrawText("PRESS UP | DOWN to CHANGE TARGET FPS", 10, GetScreenHeight() - 30, 20, GRAY);
|
||||
@@ -108,18 +108,18 @@ int main(void)
|
||||
|
||||
EndDrawing();
|
||||
|
||||
// NOTE: In case raylib is configured to SUPPORT_CUSTOM_FRAME_CONTROL,
|
||||
// NOTE: In case raylib is configured to SUPPORT_CUSTOM_FRAME_CONTROL,
|
||||
// Events polling, screen buffer swap and frame time control must be managed by the user
|
||||
|
||||
SwapScreenBuffer(); // Flip the back buffer to screen (front buffer)
|
||||
|
||||
|
||||
currentTime = GetTime();
|
||||
updateDrawTime = currentTime - previousTime;
|
||||
|
||||
|
||||
if (targetFPS > 0) // We want a fixed frame rate
|
||||
{
|
||||
waitTime = (1.0f/(float)targetFPS) - updateDrawTime;
|
||||
if (waitTime > 0.0)
|
||||
if (waitTime > 0.0)
|
||||
{
|
||||
WaitTime((float)waitTime);
|
||||
currentTime = GetTime();
|
||||
|
||||
@@ -13,12 +13,10 @@
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
static void DrawTextCenter(const char *text, int x, int y, int fontSize, Color color)
|
||||
{
|
||||
Vector2 size = MeasureTextEx(GetFontDefault(), text, (float)fontSize, 3);
|
||||
Vector2 pos = (Vector2){x - size.x/2, y - size.y/2 };
|
||||
DrawTextEx(GetFontDefault(), text, pos, (float)fontSize, 3, color);
|
||||
}
|
||||
//------------------------------------------------------------------------------------
|
||||
// Module functions declaration
|
||||
//------------------------------------------------------------------------------------
|
||||
static void DrawTextCenter(const char *text, int x, int y, int fontSize, Color color);
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Program main entry point
|
||||
@@ -31,10 +29,20 @@ int main(void)
|
||||
const int screenHeight = 450;
|
||||
|
||||
SetConfigFlags(FLAG_WINDOW_HIGHDPI | FLAG_WINDOW_RESIZABLE);
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - highdpi");
|
||||
SetWindowMinSize(450, 450);
|
||||
|
||||
int logicalGridDescY = 120;
|
||||
int logicalGridLabelY = logicalGridDescY + 30;
|
||||
int logicalGridTop = logicalGridLabelY + 30;
|
||||
int logicalGridBottom = logicalGridTop + 80;
|
||||
int pixelGridTop = logicalGridBottom - 20;
|
||||
int pixelGridBottom = pixelGridTop + 80;
|
||||
int pixelGridLabelY = pixelGridBottom + 30;
|
||||
int pixelGridDescY = pixelGridLabelY + 30;
|
||||
int cellSize = 50;
|
||||
float cellSizePx = (float)cellSize;
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
@@ -44,67 +52,60 @@ int main(void)
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
int monitorCount = GetMonitorCount();
|
||||
if (monitorCount > 1 && IsKeyPressed(KEY_N)) {
|
||||
SetWindowMonitor((GetCurrentMonitor() + 1) % monitorCount);
|
||||
|
||||
if ((monitorCount > 1) && IsKeyPressed(KEY_N))
|
||||
{
|
||||
SetWindowMonitor((GetCurrentMonitor() + 1)%monitorCount);
|
||||
}
|
||||
|
||||
int currentMonitor = GetCurrentMonitor();
|
||||
Vector2 dpiScale = GetWindowScaleDPI();
|
||||
cellSizePx = ((float)cellSize)/dpiScale.x;
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
Vector2 dpiScale = GetWindowScaleDPI();
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
int windowCenter = GetScreenWidth() / 2;
|
||||
int windowCenter = GetScreenWidth()/2;
|
||||
DrawTextCenter(TextFormat("Dpi Scale: %f", dpiScale.x), windowCenter, 30, 40, DARKGRAY);
|
||||
DrawTextCenter(TextFormat("Monitor: %d/%d ([N] next monitor)", currentMonitor+1, monitorCount), windowCenter, 70, 16, LIGHTGRAY);
|
||||
|
||||
const int logicalGridDescY = 120;
|
||||
const int logicalGridLabelY = logicalGridDescY + 30;
|
||||
const int logicalGridTop = logicalGridLabelY + 30;
|
||||
const int logicalGridBottom = logicalGridTop + 80;
|
||||
const int pixelGridTop = logicalGridBottom - 20;
|
||||
const int pixelGridBottom = pixelGridTop + 80;
|
||||
const int pixelGridLabelY = pixelGridBottom + 30;
|
||||
const int pixelGridDescY = pixelGridLabelY + 30;
|
||||
|
||||
const int cellSize = 50;
|
||||
const float cellSizePx = ((float)cellSize) / dpiScale.x;
|
||||
|
||||
DrawTextCenter(TextFormat("Monitor: %d/%d ([N] next monitor)", currentMonitor+1, monitorCount), windowCenter, 70, 20, LIGHTGRAY);
|
||||
DrawTextCenter(TextFormat("Window is %d \"logical points\" wide", GetScreenWidth()), windowCenter, logicalGridDescY, 20, ORANGE);
|
||||
|
||||
bool odd = true;
|
||||
for (int i = cellSize; i < GetScreenWidth(); i += cellSize, odd = !odd) {
|
||||
if (odd) {
|
||||
DrawRectangle(i, logicalGridTop, cellSize, logicalGridBottom-logicalGridTop, ORANGE);
|
||||
}
|
||||
DrawTextCenter(TextFormat("%d", i), i, logicalGridLabelY, 12, LIGHTGRAY);
|
||||
for (int i = cellSize; i < GetScreenWidth(); i += cellSize, odd = !odd)
|
||||
{
|
||||
if (odd) DrawRectangle(i, logicalGridTop, cellSize, logicalGridBottom-logicalGridTop, ORANGE);
|
||||
|
||||
DrawTextCenter(TextFormat("%d", i), i, logicalGridLabelY, 10, LIGHTGRAY);
|
||||
DrawLine(i, logicalGridLabelY + 10, i, logicalGridBottom, GRAY);
|
||||
}
|
||||
|
||||
odd = true;
|
||||
const int minTextSpace = 30;
|
||||
int last_text_x = -minTextSpace;
|
||||
for (int i = cellSize; i < GetRenderWidth(); i += cellSize, odd = !odd) {
|
||||
int x = (int)(((float)i) / dpiScale.x);
|
||||
if (odd) {
|
||||
DrawRectangle(x, pixelGridTop, (int)cellSizePx, pixelGridBottom-pixelGridTop, CLITERAL(Color){ 0, 121, 241, 100 });
|
||||
}
|
||||
int lastTextX = -minTextSpace;
|
||||
for (int i = cellSize; i < GetRenderWidth(); i += cellSize, odd = !odd)
|
||||
{
|
||||
int x = (int)(((float)i)/dpiScale.x);
|
||||
if (odd) DrawRectangle(x, pixelGridTop, (int)cellSizePx, pixelGridBottom - pixelGridTop, CLITERAL(Color){ 0, 121, 241, 100 });
|
||||
|
||||
DrawLine(x, pixelGridTop, (int)(((float)i) / dpiScale.x), pixelGridLabelY - 10, GRAY);
|
||||
if (x - last_text_x >= minTextSpace) {
|
||||
DrawTextCenter(TextFormat("%d", i), x, pixelGridLabelY, 12, LIGHTGRAY);
|
||||
last_text_x = x;
|
||||
|
||||
if ((x - lastTextX) >= minTextSpace)
|
||||
{
|
||||
DrawTextCenter(TextFormat("%d", i), x, pixelGridLabelY, 10, LIGHTGRAY);
|
||||
lastTextX = x;
|
||||
}
|
||||
}
|
||||
|
||||
DrawTextCenter(TextFormat("Window is %d \"physical pixels\" wide", GetRenderWidth()), windowCenter, pixelGridDescY, 20, BLUE);
|
||||
|
||||
{
|
||||
const char *text = "Can you see this?";
|
||||
Vector2 size = MeasureTextEx(GetFontDefault(), text, 16, 3);
|
||||
Vector2 pos = (Vector2){GetScreenWidth() - size.x - 5, GetScreenHeight() - size.y - 5};
|
||||
DrawTextEx(GetFontDefault(), text, pos, 16, 3, LIGHTGRAY);
|
||||
}
|
||||
const char *text = "Can you see this?";
|
||||
Vector2 size = MeasureTextEx(GetFontDefault(), text, 20, 3);
|
||||
Vector2 pos = (Vector2){ GetScreenWidth() - size.x - 5, GetScreenHeight() - size.y - 5 };
|
||||
DrawTextEx(GetFontDefault(), text, pos, 20, 3, LIGHTGRAY);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
@@ -117,3 +118,13 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Module functions definition
|
||||
//------------------------------------------------------------------------------------
|
||||
static void DrawTextCenter(const char *text, int x, int y, int fontSize, Color color)
|
||||
{
|
||||
Vector2 size = MeasureTextEx(GetFontDefault(), text, (float)fontSize, 3);
|
||||
Vector2 pos = (Vector2){ x - size.x/2, y - size.y/2 };
|
||||
DrawTextEx(GetFontDefault(), text, pos, (float)fontSize, 3, color);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ int main(void)
|
||||
isCursorHidden = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ballPosition = GetMousePosition();
|
||||
|
||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) ballColor = MAROON;
|
||||
|
||||
@@ -54,7 +54,7 @@ int main(void)
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
for (int i = 0; i < tCount; ++i)
|
||||
{
|
||||
// Make sure point is not (0, 0) as this means there is no touch for it
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* Example originally created with raylib 5.0, last time updated with raylib 5.0
|
||||
*
|
||||
* Example create by GreenSnakeLinux (@GreenSnakeLinux),
|
||||
* lighter by oblerion (@oblerion) and
|
||||
* lighter by oblerion (@oblerion) and
|
||||
* reviewed by Ramon Santamaria (@raysan5) and
|
||||
* improved by danilwhale (@danilwhale)
|
||||
*
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* Example complexity rating: [★★★☆] 3/4
|
||||
*
|
||||
* NOTE: This example requires linking with pthreads library on MinGW,
|
||||
* NOTE: This example requires linking with pthreads library on MinGW,
|
||||
* it can be accomplished passing -static parameter to compiler
|
||||
*
|
||||
* Example originally created with raylib 2.5, last time updated with raylib 3.0
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [core] example - Generates a random sequence
|
||||
* raylib [core] example - generate random sequence
|
||||
*
|
||||
* Example complexity rating: [★☆☆☆] 1/4
|
||||
*
|
||||
@@ -43,7 +43,7 @@ int main(void)
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - Generates a random sequence");
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - generate random sequence");
|
||||
|
||||
int rectCount = 20;
|
||||
float rectSize = (float)screenWidth/rectCount;
|
||||
@@ -118,8 +118,8 @@ int main(void)
|
||||
//------------------------------------------------------------------------------------
|
||||
static Color GenerateRandomColor()
|
||||
{
|
||||
Color color = {
|
||||
GetRandomValue(0, 255),
|
||||
Color color = {
|
||||
GetRandomValue(0, 255),
|
||||
GetRandomValue(0, 255),
|
||||
GetRandomValue(0, 255),
|
||||
255
|
||||
@@ -138,20 +138,20 @@ static ColorRect *GenerateRandomColorRectSequence(float rectCount, float rectWid
|
||||
for (int i = 0; i < rectCount; i++)
|
||||
{
|
||||
int rectHeight = (int)Remap((float)seq[i], 0, rectCount - 1, 0, screenHeight);
|
||||
|
||||
|
||||
rectangles[i].c = GenerateRandomColor();
|
||||
rectangles[i].r = CLITERAL(Rectangle){ startX + i*rectWidth, screenHeight - rectHeight, rectWidth, (float)rectHeight };
|
||||
}
|
||||
|
||||
|
||||
UnloadRandomSequence(seq);
|
||||
|
||||
|
||||
return rectangles;
|
||||
}
|
||||
|
||||
static void ShuffleColorRectSequence(ColorRect *rectangles, int rectCount)
|
||||
{
|
||||
int *seq = LoadRandomSequence(rectCount, 0, rectCount - 1);
|
||||
|
||||
|
||||
for (int i1 = 0; i1 < rectCount; i1++)
|
||||
{
|
||||
ColorRect *r1 = &rectangles[i1];
|
||||
@@ -166,16 +166,16 @@ static void ShuffleColorRectSequence(ColorRect *rectangles, int rectCount)
|
||||
r2->r.height = tmp.r.height;
|
||||
r2->r.y = tmp.r.y;
|
||||
}
|
||||
|
||||
|
||||
UnloadRandomSequence(seq);
|
||||
}
|
||||
|
||||
static void DrawTextCenterKeyHelp(const char *key, const char *text, int posX, int posY, int fontSize, Color color)
|
||||
{
|
||||
int spaceSize = MeasureText(" ", fontSize);
|
||||
int pressSize = MeasureText("Press", fontSize);
|
||||
int keySize = MeasureText(key, fontSize);
|
||||
int textSize = MeasureText(text, fontSize);
|
||||
int spaceSize = MeasureText(" ", fontSize);
|
||||
int pressSize = MeasureText("Press", fontSize);
|
||||
int keySize = MeasureText(key, fontSize);
|
||||
int textSize = MeasureText(text, fontSize);
|
||||
int textSizeCurrent = 0;
|
||||
|
||||
DrawText("Press", posX, posY, fontSize, color);
|
||||
|
||||
@@ -30,9 +30,9 @@ int main(void)
|
||||
// SetRandomSeed(0xaabbccff); // Set a custom random seed if desired, by default: "time(NULL)"
|
||||
|
||||
int randValue = GetRandomValue(-8, 5); // Get a random integer number between -8 and 5 (both included)
|
||||
|
||||
|
||||
unsigned int framesCounter = 0; // Variable used to count frames
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Example complexity rating: [★★★☆] 3/4
|
||||
*
|
||||
* Example originally created with raylib 3.7, last time updated with raylib 4.0
|
||||
*
|
||||
*
|
||||
* Example contributed by Giancamillo Alessandroni (@NotManyIdeasDev) and
|
||||
* reviewed by Ramon Santamaria (@raysan5)
|
||||
*
|
||||
|
||||
@@ -127,7 +127,7 @@ int main(void)
|
||||
EndMode3D();
|
||||
EndVrStereoMode();
|
||||
EndTextureMode();
|
||||
|
||||
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
BeginShaderMode(distortion);
|
||||
|
||||
@@ -86,7 +86,7 @@ int main(void)
|
||||
DrawText(TextFormat("Default Mouse: [%i , %i]", (int)mouse.x, (int)mouse.y), 350, 25, 20, GREEN);
|
||||
DrawText(TextFormat("Virtual Mouse: [%i , %i]", (int)virtualMouse.x, (int)virtualMouse.y), 350, 55, 20, YELLOW);
|
||||
EndTextureMode();
|
||||
|
||||
|
||||
BeginDrawing();
|
||||
ClearBackground(BLACK); // Clear screen background
|
||||
|
||||
|
||||
@@ -26,9 +26,9 @@ int main()
|
||||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - window should close");
|
||||
|
||||
|
||||
SetExitKey(KEY_NULL); // Disable KEY_ESCAPE to close window, X-button still works
|
||||
|
||||
|
||||
bool exitWindowRequested = false; // Flag to request window to exit
|
||||
bool exitWindow = false; // Flag to set window to exit
|
||||
|
||||
@@ -42,12 +42,12 @@ int main()
|
||||
//----------------------------------------------------------------------------------
|
||||
// Detect if X-button or KEY_ESCAPE have been pressed to close window
|
||||
if (WindowShouldClose() || IsKeyPressed(KEY_ESCAPE)) exitWindowRequested = true;
|
||||
|
||||
|
||||
if (exitWindowRequested)
|
||||
{
|
||||
// A request for close window has been issued, we can save data before closing
|
||||
// or just show a message asking for confirmation
|
||||
|
||||
|
||||
if (IsKeyPressed(KEY_Y)) exitWindow = true;
|
||||
else if (IsKeyPressed(KEY_N)) exitWindowRequested = false;
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ int main(void)
|
||||
EndMode3D();
|
||||
|
||||
DrawText("Enemy: 100 / 100", (int)cubeScreenPosition.x - MeasureText("Enemy: 100/100", 20)/2, (int)cubeScreenPosition.y, 20, BLACK);
|
||||
|
||||
|
||||
DrawText(TextFormat("Cube position in screen space coordinates: [%i, %i]", (int)cubeScreenPosition.x, (int)cubeScreenPosition.y), 10, 10, 20, LIME);
|
||||
DrawText("Text 2d should be always on top of the cube", 10, 40, 20, GRAY);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user