EXAMPLES: Format tweaks

This commit is contained in:
Ray 2025-08-07 17:08:22 +02:00
commit f0889a74fe
91 changed files with 409 additions and 397 deletions

View file

@ -1,6 +1,6 @@
/******************************************************************************************* /*******************************************************************************************
* *
* raylib [audio] example - Mixed audio processing * raylib [audio] example - mixed audio processing
* *
* Example complexity rating: [★★★★] 4/4 * Example complexity rating: [★★★★] 4/4
* *

View file

@ -1,6 +1,6 @@
/******************************************************************************************* /*******************************************************************************************
* *
* raylib [audio] example - Playing spatialized 3D sound * raylib [audio] example - spatialized 3D sound
* *
* Example complexity rating: [★★☆☆] 2/4 * Example complexity rating: [★★☆☆] 2/4
* *
@ -32,7 +32,7 @@ int main(void)
const int screenWidth = 800; const int screenWidth = 800;
const int screenHeight = 450; const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [audio] example - Playing spatialized 3D sound"); InitWindow(screenWidth, screenHeight, "raylib [audio] example - spatialized 3D sound");
InitAudioDevice(); InitAudioDevice();

View file

@ -13,12 +13,10 @@
#include "raylib.h" #include "raylib.h"
static void DrawTextCenter(const char *text, int x, int y, int fontSize, Color color) //------------------------------------------------------------------------------------
{ // Module functions declaration
Vector2 size = MeasureTextEx(GetFontDefault(), text, (float)fontSize, 3); //------------------------------------------------------------------------------------
Vector2 pos = (Vector2){x - size.x/2, y - size.y/2 }; static void DrawTextCenter(const char *text, int x, int y, int fontSize, Color color);
DrawTextEx(GetFontDefault(), text, pos, (float)fontSize, 3, color);
}
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Program main entry point // Program main entry point
@ -31,10 +29,20 @@ int main(void)
const int screenHeight = 450; const int screenHeight = 450;
SetConfigFlags(FLAG_WINDOW_HIGHDPI | FLAG_WINDOW_RESIZABLE); SetConfigFlags(FLAG_WINDOW_HIGHDPI | FLAG_WINDOW_RESIZABLE);
InitWindow(screenWidth, screenHeight, "raylib [core] example - highdpi"); InitWindow(screenWidth, screenHeight, "raylib [core] example - highdpi");
SetWindowMinSize(450, 450); 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 SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -44,67 +52,60 @@ int main(void)
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
int monitorCount = GetMonitorCount(); 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(); int currentMonitor = GetCurrentMonitor();
Vector2 dpiScale = GetWindowScaleDPI();
cellSizePx = ((float)cellSize)/dpiScale.x;
//----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
Vector2 dpiScale = GetWindowScaleDPI();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
int windowCenter = GetScreenWidth() / 2; int windowCenter = GetScreenWidth()/2;
DrawTextCenter(TextFormat("Dpi Scale: %f", dpiScale.x), windowCenter, 30, 40, DARKGRAY); 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); DrawTextCenter(TextFormat("Monitor: %d/%d ([N] next monitor)", currentMonitor+1, monitorCount), windowCenter, 70, 20, 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("Window is %d \"logical points\" wide", GetScreenWidth()), windowCenter, logicalGridDescY, 20, ORANGE); DrawTextCenter(TextFormat("Window is %d \"logical points\" wide", GetScreenWidth()), windowCenter, logicalGridDescY, 20, ORANGE);
bool odd = true; bool odd = true;
for (int i = cellSize; i < GetScreenWidth(); i += cellSize, odd = !odd) { for (int i = cellSize; i < GetScreenWidth(); i += cellSize, odd = !odd)
if (odd) { {
DrawRectangle(i, logicalGridTop, cellSize, logicalGridBottom-logicalGridTop, ORANGE); if (odd) DrawRectangle(i, logicalGridTop, cellSize, logicalGridBottom-logicalGridTop, ORANGE);
}
DrawTextCenter(TextFormat("%d", i), i, logicalGridLabelY, 12, LIGHTGRAY); DrawTextCenter(TextFormat("%d", i), i, logicalGridLabelY, 10, LIGHTGRAY);
DrawLine(i, logicalGridLabelY + 10, i, logicalGridBottom, GRAY); DrawLine(i, logicalGridLabelY + 10, i, logicalGridBottom, GRAY);
} }
odd = true; odd = true;
const int minTextSpace = 30; const int minTextSpace = 30;
int last_text_x = -minTextSpace; int lastTextX = -minTextSpace;
for (int i = cellSize; i < GetRenderWidth(); i += cellSize, odd = !odd) { for (int i = cellSize; i < GetRenderWidth(); i += cellSize, odd = !odd)
int x = (int)(((float)i) / dpiScale.x); {
if (odd) { int x = (int)(((float)i)/dpiScale.x);
DrawRectangle(x, pixelGridTop, (int)cellSizePx, pixelGridBottom-pixelGridTop, CLITERAL(Color){ 0, 121, 241, 100 }); 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); 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); if ((x - lastTextX) >= minTextSpace)
last_text_x = x; {
DrawTextCenter(TextFormat("%d", i), x, pixelGridLabelY, 10, LIGHTGRAY);
lastTextX = x;
} }
} }
DrawTextCenter(TextFormat("Window is %d \"physical pixels\" wide", GetRenderWidth()), windowCenter, pixelGridDescY, 20, BLUE); DrawTextCenter(TextFormat("Window is %d \"physical pixels\" wide", GetRenderWidth()), windowCenter, pixelGridDescY, 20, BLUE);
{ const char *text = "Can you see this?";
const char *text = "Can you see this?"; Vector2 size = MeasureTextEx(GetFontDefault(), text, 20, 3);
Vector2 size = MeasureTextEx(GetFontDefault(), text, 16, 3); Vector2 pos = (Vector2){ GetScreenWidth() - size.x - 5, GetScreenHeight() - size.y - 5 };
Vector2 pos = (Vector2){GetScreenWidth() - size.x - 5, GetScreenHeight() - size.y - 5}; DrawTextEx(GetFontDefault(), text, pos, 20, 3, LIGHTGRAY);
DrawTextEx(GetFontDefault(), text, pos, 16, 3, LIGHTGRAY);
}
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -117,3 +118,13 @@ int main(void)
return 0; 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);
}

View file

@ -1,6 +1,6 @@
/******************************************************************************************* /*******************************************************************************************
* *
* raylib [core] example - Generates a random sequence * raylib [core] example - generate random sequence
* *
* Example complexity rating: [★☆☆☆] 1/4 * Example complexity rating: [★☆☆☆] 1/4
* *
@ -43,7 +43,7 @@ int main(void)
const int screenWidth = 800; const int screenWidth = 800;
const int screenHeight = 450; 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; int rectCount = 20;
float rectSize = (float)screenWidth/rectCount; float rectSize = (float)screenWidth/rectCount;

Some files were not shown because too many files have changed in this diff Show more