mirror of
https://github.com/raysan5/raylib.git
synced 2025-12-06 06:13:10 +00:00
REVIEWED: Formatting to follow raylib conventions
This commit is contained in:
parent
6c3ef8d9b4
commit
727a90c5d1
@ -148,7 +148,7 @@ int main(void)
|
|||||||
CaptureFrame(&fft, audioSamples);
|
CaptureFrame(&fft, audioSamples);
|
||||||
RenderFrame(&fft, &fftImage);
|
RenderFrame(&fft, &fftImage);
|
||||||
UpdateTexture(fftTexture, fftImage.data);
|
UpdateTexture(fftTexture, fftImage.data);
|
||||||
//------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
@ -269,7 +269,7 @@ static void CaptureFrame(FFTData *fftData, const float *audioSamples)
|
|||||||
|
|
||||||
fftData->lastFftTime = GetTime();
|
fftData->lastFftTime = GetTime();
|
||||||
memcpy(fftData->fftHistory[fftData->historyPos], smoothedSpectrum, sizeof(smoothedSpectrum));
|
memcpy(fftData->fftHistory[fftData->historyPos], smoothedSpectrum, sizeof(smoothedSpectrum));
|
||||||
fftData->historyPos = (fftData->historyPos + 1) % fftData->fftHistoryLen;
|
fftData->historyPos = (fftData->historyPos + 1)%fftData->fftHistoryLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void RenderFrame(const FFTData *fftData, Image *fftImage)
|
static void RenderFrame(const FFTData *fftData, Image *fftImage)
|
||||||
@ -277,12 +277,9 @@ static void RenderFrame(const FFTData *fftData, Image *fftImage)
|
|||||||
double framesSinceTapback = floor(fftData->tapbackPos/WINDOW_TIME);
|
double framesSinceTapback = floor(fftData->tapbackPos/WINDOW_TIME);
|
||||||
framesSinceTapback = Clamp(framesSinceTapback, 0.0, fftData->fftHistoryLen - 1);
|
framesSinceTapback = Clamp(framesSinceTapback, 0.0, fftData->fftHistoryLen - 1);
|
||||||
|
|
||||||
int historyPosition = (fftData->historyPos - 1 - (int)framesSinceTapback) % fftData->fftHistoryLen;
|
int historyPosition = (fftData->historyPos - 1 - (int)framesSinceTapback)%fftData->fftHistoryLen;
|
||||||
if (historyPosition < 0)
|
if (historyPosition < 0) historyPosition += fftData->fftHistoryLen;
|
||||||
historyPosition += fftData->fftHistoryLen;
|
|
||||||
|
|
||||||
const float *amplitude = fftData->fftHistory[historyPosition];
|
const float *amplitude = fftData->fftHistory[historyPosition];
|
||||||
for (int bin = 0; bin < BUFFER_SIZE; bin++) {
|
for (int bin = 0; bin < BUFFER_SIZE; bin++) ImageDrawPixel(fftImage, bin, FFT_ROW, ColorFromNormalized((Vector4){ amplitude[bin], UNUSED_CHANNEL, UNUSED_CHANNEL, UNUSED_CHANNEL }));
|
||||||
ImageDrawPixel(fftImage, bin, FFT_ROW, ColorFromNormalized((Vector4){ amplitude[bin], UNUSED_CHANNEL, UNUSED_CHANNEL, UNUSED_CHANNEL }));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -35,10 +35,10 @@ int main(void)
|
|||||||
|
|
||||||
float timePlayed = 0.0f; // Time played normalized [0.0f..1.0f]
|
float timePlayed = 0.0f; // Time played normalized [0.0f..1.0f]
|
||||||
bool pause = false; // Music playing paused
|
bool pause = false; // Music playing paused
|
||||||
|
|
||||||
float pan = 0.0f; // Default audio pan center [-1.0f..1.0f]
|
float pan = 0.0f; // Default audio pan center [-1.0f..1.0f]
|
||||||
SetMusicPan(music, pan);
|
SetMusicPan(music, pan);
|
||||||
|
|
||||||
float volume = 0.8f; // Default audio volume [0.0f..1.0f]
|
float volume = 0.8f; // Default audio volume [0.0f..1.0f]
|
||||||
SetMusicVolume(music, volume);
|
SetMusicVolume(music, volume);
|
||||||
|
|
||||||
@ -67,29 +67,29 @@ int main(void)
|
|||||||
if (pause) PauseMusicStream(music);
|
if (pause) PauseMusicStream(music);
|
||||||
else ResumeMusicStream(music);
|
else ResumeMusicStream(music);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set audio pan
|
// Set audio pan
|
||||||
if (IsKeyDown(KEY_LEFT))
|
if (IsKeyDown(KEY_LEFT))
|
||||||
{
|
{
|
||||||
pan -= 0.05f;
|
pan -= 0.05f;
|
||||||
if (pan < -1.0f) pan = -1.0f;
|
if (pan < -1.0f) pan = -1.0f;
|
||||||
SetMusicPan(music, pan);
|
SetMusicPan(music, pan);
|
||||||
}
|
}
|
||||||
else if (IsKeyDown(KEY_RIGHT))
|
else if (IsKeyDown(KEY_RIGHT))
|
||||||
{
|
{
|
||||||
pan += 0.05f;
|
pan += 0.05f;
|
||||||
if (pan > 1.0f) pan = 1.0f;
|
if (pan > 1.0f) pan = 1.0f;
|
||||||
SetMusicPan(music, pan);
|
SetMusicPan(music, pan);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set audio volume
|
// Set audio volume
|
||||||
if (IsKeyDown(KEY_DOWN))
|
if (IsKeyDown(KEY_DOWN))
|
||||||
{
|
{
|
||||||
volume -= 0.05f;
|
volume -= 0.05f;
|
||||||
if (volume < 0.0f) volume = 0.0f;
|
if (volume < 0.0f) volume = 0.0f;
|
||||||
SetMusicVolume(music, volume);
|
SetMusicVolume(music, volume);
|
||||||
}
|
}
|
||||||
else if (IsKeyDown(KEY_UP))
|
else if (IsKeyDown(KEY_UP))
|
||||||
{
|
{
|
||||||
volume += 0.05f;
|
volume += 0.05f;
|
||||||
if (volume > 1.0f) volume = 1.0f;
|
if (volume > 1.0f) volume = 1.0f;
|
||||||
@ -109,7 +109,7 @@ int main(void)
|
|||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
DrawText("MUSIC SHOULD BE PLAYING!", 255, 150, 20, LIGHTGRAY);
|
DrawText("MUSIC SHOULD BE PLAYING!", 255, 150, 20, LIGHTGRAY);
|
||||||
|
|
||||||
DrawText("LEFT-RIGHT for PAN CONTROL", 320, 74, 10, DARKBLUE);
|
DrawText("LEFT-RIGHT for PAN CONTROL", 320, 74, 10, DARKBLUE);
|
||||||
DrawRectangle(300, 100, 200, 12, LIGHTGRAY);
|
DrawRectangle(300, 100, 200, 12, LIGHTGRAY);
|
||||||
DrawRectangleLines(300, 100, 200, 12, GRAY);
|
DrawRectangleLines(300, 100, 200, 12, GRAY);
|
||||||
@ -121,7 +121,7 @@ int main(void)
|
|||||||
|
|
||||||
DrawText("PRESS SPACE TO RESTART MUSIC", 215, 250, 20, LIGHTGRAY);
|
DrawText("PRESS SPACE TO RESTART MUSIC", 215, 250, 20, LIGHTGRAY);
|
||||||
DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 280, 20, LIGHTGRAY);
|
DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 280, 20, LIGHTGRAY);
|
||||||
|
|
||||||
DrawText("UP-DOWN for VOLUME CONTROL", 320, 334, 10, DARKGREEN);
|
DrawText("UP-DOWN for VOLUME CONTROL", 320, 334, 10, DARKGREEN);
|
||||||
DrawRectangle(300, 360, 200, 12, LIGHTGRAY);
|
DrawRectangle(300, 360, 200, 12, LIGHTGRAY);
|
||||||
DrawRectangleLines(300, 360, 200, 12, GRAY);
|
DrawRectangleLines(300, 360, 200, 12, GRAY);
|
||||||
|
|||||||
@ -166,7 +166,7 @@ int main(void)
|
|||||||
memcpy(writeBuf + writeCursor, data + readCursor, writeLength*sizeof(short));
|
memcpy(writeBuf + writeCursor, data + readCursor, writeLength*sizeof(short));
|
||||||
|
|
||||||
// Update cursors and loop audio
|
// Update cursors and loop audio
|
||||||
readCursor = (readCursor + writeLength) % waveLength;
|
readCursor = (readCursor + writeLength)%waveLength;
|
||||||
|
|
||||||
writeCursor += writeLength;
|
writeCursor += writeLength;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -95,7 +95,7 @@ int main(void)
|
|||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -27,9 +27,10 @@ int main(void)
|
|||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
SetConfigFlags(FLAG_WINDOW_HIGHDPI | FLAG_WINDOW_RESIZABLE);
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - highdpi testbed");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - highdpi testbed");
|
||||||
|
|
||||||
// TODO: Load resources / Initialize variables at this point
|
int gridSpacing = 40; // Grid spacing in pixels
|
||||||
|
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
@ -48,11 +49,12 @@ int main(void)
|
|||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
// TODO: Draw everything that requires to be drawn at this point
|
// Draw grid
|
||||||
|
for (int h = 0; h < 20; h++) DrawLine(0, h*gridSpacing, GetRenderWidth(), h*gridSpacing, LIGHTGRAY);
|
||||||
|
for (int v = 0; v < 40; v++) DrawLine(v*gridSpacing, 0, v*gridSpacing, GetScreenHeight(), LIGHTGRAY);
|
||||||
|
|
||||||
DrawLineEx((Vector2){ 0, 0 }, (Vector2){ screenWidth, screenHeight }, 2.0f, RED);
|
// Draw UI info
|
||||||
DrawLineEx((Vector2){ 0, screenHeight }, (Vector2){ screenWidth, 0 }, 2.0f, RED);
|
DrawText(TextFormat("SCREEN SIZE: %ix%i", GetScreenWidth(), GetScreenHeight()), 10, 10, 20, BLACK);
|
||||||
DrawText("example base code template", 260, 400, 20, LIGHTGRAY);
|
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|||||||
@ -202,7 +202,7 @@ int main(void)
|
|||||||
DrawText("Log", (int)gestureLogPosition.x, (int)gestureLogPosition.y, 20, BLACK);
|
DrawText("Log", (int)gestureLogPosition.x, (int)gestureLogPosition.y, 20, BLACK);
|
||||||
|
|
||||||
// Loop in both directions to print the gesture log array in the inverted order (and looping around if the index started somewhere in the middle)
|
// Loop in both directions to print the gesture log array in the inverted order (and looping around if the index started somewhere in the middle)
|
||||||
for (i = 0, ii = gestureLogIndex; i < GESTURE_LOG_SIZE; i++, ii = (ii + 1) % GESTURE_LOG_SIZE) DrawText(gestureLog[ii], (int)gestureLogPosition.x, (int)gestureLogPosition.y + 410 - i*20, 20, (i == 0 ? gestureColor : LIGHTGRAY));
|
for (i = 0, ii = gestureLogIndex; i < GESTURE_LOG_SIZE; i++, ii = (ii + 1)%GESTURE_LOG_SIZE) DrawText(gestureLog[ii], (int)gestureLogPosition.x, (int)gestureLogPosition.y + 410 - i*20, 20, (i == 0 ? gestureColor : LIGHTGRAY));
|
||||||
Color logButton1Color, logButton2Color;
|
Color logButton1Color, logButton2Color;
|
||||||
switch (logMode)
|
switch (logMode)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -46,7 +46,7 @@ int main(void)
|
|||||||
// Clamp touch points available ( set the maximum touch points allowed )
|
// Clamp touch points available ( set the maximum touch points allowed )
|
||||||
if (tCount > MAX_TOUCH_POINTS) tCount = MAX_TOUCH_POINTS;
|
if (tCount > MAX_TOUCH_POINTS) tCount = MAX_TOUCH_POINTS;
|
||||||
// Get touch points positions
|
// Get touch points positions
|
||||||
for (int i = 0; i < tCount; ++i) touchPositions[i] = GetTouchPosition(i);
|
for (int i = 0; i < tCount; i++) touchPositions[i] = GetTouchPosition(i);
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
@ -55,7 +55,7 @@ int main(void)
|
|||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
for (int i = 0; i < tCount; ++i)
|
for (int i = 0; i < tCount; i++)
|
||||||
{
|
{
|
||||||
// Make sure point is not (0, 0) as this means there is no touch for it
|
// Make sure point is not (0, 0) as this means there is no touch for it
|
||||||
if ((touchPositions[i].x > 0) && (touchPositions[i].y > 0))
|
if ((touchPositions[i].x > 0) && (touchPositions[i].y > 0))
|
||||||
|
|||||||
@ -142,7 +142,7 @@ int main(void)
|
|||||||
Vector2 windowPosition = (Vector2){ (GetWindowPosition().x + monitorOffsetX)*monitorScale + 140, GetWindowPosition().y*monitorScale + 80 };
|
Vector2 windowPosition = (Vector2){ (GetWindowPosition().x + monitorOffsetX)*monitorScale + 140, GetWindowPosition().y*monitorScale + 80 };
|
||||||
|
|
||||||
// Draw window position based on monitors
|
// Draw window position based on monitors
|
||||||
DrawRectangleV(windowPosition, (Vector2){screenWidth * monitorScale, screenHeight * monitorScale}, Fade(GREEN, 0.5));
|
DrawRectangleV(windowPosition, (Vector2){screenWidth*monitorScale, screenHeight*monitorScale}, Fade(GREEN, 0.5));
|
||||||
}
|
}
|
||||||
else DrawRectangleLinesEx(rec, 5, GRAY);
|
else DrawRectangleLinesEx(rec, 5, GRAY);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -187,7 +187,7 @@ int main(void)
|
|||||||
if (lastUndoIndex > firstUndoIndex)
|
if (lastUndoIndex > firstUndoIndex)
|
||||||
{
|
{
|
||||||
for (int i = firstUndoIndex; i < currentUndoIndex; i++)
|
for (int i = firstUndoIndex; i < currentUndoIndex; i++)
|
||||||
DrawRectangleRec((Rectangle){gridPosition.x + states[i].cell.x * GRID_CELL_SIZE, gridPosition.y + states[i].cell.y * GRID_CELL_SIZE,
|
DrawRectangleRec((Rectangle){gridPosition.x + states[i].cell.x*GRID_CELL_SIZE, gridPosition.y + states[i].cell.y*GRID_CELL_SIZE,
|
||||||
GRID_CELL_SIZE, GRID_CELL_SIZE }, LIGHTGRAY);
|
GRID_CELL_SIZE, GRID_CELL_SIZE }, LIGHTGRAY);
|
||||||
}
|
}
|
||||||
else if (firstUndoIndex > lastUndoIndex)
|
else if (firstUndoIndex > lastUndoIndex)
|
||||||
@ -195,7 +195,7 @@ int main(void)
|
|||||||
if ((currentUndoIndex < MAX_UNDO_STATES) && (currentUndoIndex > lastUndoIndex))
|
if ((currentUndoIndex < MAX_UNDO_STATES) && (currentUndoIndex > lastUndoIndex))
|
||||||
{
|
{
|
||||||
for (int i = firstUndoIndex; i < currentUndoIndex; i++)
|
for (int i = firstUndoIndex; i < currentUndoIndex; i++)
|
||||||
DrawRectangleRec((Rectangle) { gridPosition.x + states[i].cell.x * GRID_CELL_SIZE, gridPosition.y + states[i].cell.y * GRID_CELL_SIZE,
|
DrawRectangleRec((Rectangle) { gridPosition.x + states[i].cell.x*GRID_CELL_SIZE, gridPosition.y + states[i].cell.y*GRID_CELL_SIZE,
|
||||||
GRID_CELL_SIZE, GRID_CELL_SIZE }, LIGHTGRAY);
|
GRID_CELL_SIZE, GRID_CELL_SIZE }, LIGHTGRAY);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@ -17,11 +17,9 @@
|
|||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
// For itteration purposes and teaching example
|
#define RESOLUTION_COUNT 4 // For iteration purposes and teaching example
|
||||||
#define RESOLUTION_COUNT 4
|
|
||||||
|
|
||||||
enum ViewportType
|
typedef enum {
|
||||||
{
|
|
||||||
// Only upscale, useful for pixel art
|
// Only upscale, useful for pixel art
|
||||||
KEEP_ASPECT_INTEGER,
|
KEEP_ASPECT_INTEGER,
|
||||||
KEEP_HEIGHT_INTEGER,
|
KEEP_HEIGHT_INTEGER,
|
||||||
@ -32,24 +30,28 @@ enum ViewportType
|
|||||||
KEEP_WIDTH,
|
KEEP_WIDTH,
|
||||||
// For itteration purposes and as a teaching example
|
// For itteration purposes and as a teaching example
|
||||||
VIEWPORT_TYPE_COUNT,
|
VIEWPORT_TYPE_COUNT,
|
||||||
|
} ViewportType;
|
||||||
|
|
||||||
|
// For displaying on GUI
|
||||||
|
const char *ViewportTypeNames[VIEWPORT_TYPE_COUNT] = {
|
||||||
|
"KEEP_ASPECT_INTEGER",
|
||||||
|
"KEEP_HEIGHT_INTEGER",
|
||||||
|
"KEEP_WIDTH_INTEGER",
|
||||||
|
"KEEP_ASPECT",
|
||||||
|
"KEEP_HEIGHT",
|
||||||
|
"KEEP_WIDTH",
|
||||||
};
|
};
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
// Module Functions Declaration
|
// Module Functions Declaration
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
static void KeepAspectCenteredInteger(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect);
|
static void KeepAspectCenteredInteger(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect);
|
||||||
|
|
||||||
static void KeepHeightCenteredInteger(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect);
|
static void KeepHeightCenteredInteger(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect);
|
||||||
|
|
||||||
static void KeepWidthCenteredInteger(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect);
|
static void KeepWidthCenteredInteger(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect);
|
||||||
|
|
||||||
static void KeepAspectCentered(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect);
|
static void KeepAspectCentered(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect);
|
||||||
|
|
||||||
static void KeepHeightCentered(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect);
|
static void KeepHeightCentered(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect);
|
||||||
|
|
||||||
static void KeepWidthCentered(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect);
|
static void KeepWidthCentered(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect);
|
||||||
|
static void ResizeRenderSize(ViewportType viewportType, int *screenWidth, int *screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect, RenderTexture2D *target);
|
||||||
static void ResizeRenderSize(enum ViewportType viewportType, int *screenWidth, int *screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect, RenderTexture2D *target);
|
|
||||||
|
|
||||||
// Example how to calculate position on RenderTexture
|
// Example how to calculate position on RenderTexture
|
||||||
static Vector2 Screen2RenderTexturePosition(Vector2 point, Rectangle *textureRect, Rectangle *scaledRect);
|
static Vector2 Screen2RenderTexturePosition(Vector2 point, Rectangle *textureRect, Rectangle *scaledRect);
|
||||||
@ -61,91 +63,89 @@ int main(void)
|
|||||||
{
|
{
|
||||||
// Initialization
|
// Initialization
|
||||||
//---------------------------------------------------------
|
//---------------------------------------------------------
|
||||||
// Preset resolutions that could be created by subdividing screen resolution
|
|
||||||
Vector2 resolutionList[RESOLUTION_COUNT] = {
|
|
||||||
(Vector2){64, 64},
|
|
||||||
(Vector2){256, 240},
|
|
||||||
(Vector2){320, 180},
|
|
||||||
// 4K doesn't work with integer scaling but included for example purposes with non-integer scaling
|
|
||||||
(Vector2){3840, 2160},
|
|
||||||
};
|
|
||||||
int resolutionIndex = 0;
|
|
||||||
|
|
||||||
int screenWidth = 800;
|
int screenWidth = 800;
|
||||||
int screenHeight = 450;
|
int screenHeight = 450;
|
||||||
int gameWidth = 64;
|
|
||||||
int gameHeight = 64;
|
|
||||||
|
|
||||||
RenderTexture2D target = (RenderTexture2D){0};
|
|
||||||
Rectangle sourceRect = (Rectangle){0};
|
|
||||||
Rectangle destRect = (Rectangle){0};
|
|
||||||
|
|
||||||
// For displaying on GUI
|
|
||||||
const char *ViewportTypeNames[VIEWPORT_TYPE_COUNT] = {
|
|
||||||
"KEEP_ASPECT_INTEGER",
|
|
||||||
"KEEP_HEIGHT_INTEGER",
|
|
||||||
"KEEP_WIDTH_INTEGER",
|
|
||||||
"KEEP_ASPECT",
|
|
||||||
"KEEP_HEIGHT",
|
|
||||||
"KEEP_WIDTH",
|
|
||||||
};
|
|
||||||
enum ViewportType viewportType = KEEP_ASPECT_INTEGER;
|
|
||||||
|
|
||||||
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - viewport scaling");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - viewport scaling");
|
||||||
|
|
||||||
|
// Preset resolutions that could be created by subdividing screen resolution
|
||||||
|
Vector2 resolutionList[RESOLUTION_COUNT] = {
|
||||||
|
(Vector2){ 64, 64 },
|
||||||
|
(Vector2){ 256, 240 },
|
||||||
|
(Vector2){ 320, 180 },
|
||||||
|
// 4K doesn't work with integer scaling but included for example purposes with non-integer scaling
|
||||||
|
(Vector2){ 3840, 2160 },
|
||||||
|
};
|
||||||
|
|
||||||
|
int resolutionIndex = 0;
|
||||||
|
int gameWidth = 64;
|
||||||
|
int gameHeight = 64;
|
||||||
|
|
||||||
|
RenderTexture2D target = (RenderTexture2D){ 0 };
|
||||||
|
Rectangle sourceRect = (Rectangle){ 0 };
|
||||||
|
Rectangle destRect = (Rectangle){ 0 };
|
||||||
|
|
||||||
|
ViewportType viewportType = KEEP_ASPECT_INTEGER;
|
||||||
ResizeRenderSize(viewportType, &screenWidth, &screenHeight, gameWidth, gameHeight, &sourceRect, &destRect, &target);
|
ResizeRenderSize(viewportType, &screenWidth, &screenHeight, gameWidth, gameHeight, &sourceRect, &destRect, &target);
|
||||||
|
|
||||||
|
// Button rectangles
|
||||||
|
Rectangle decreaseResolutionButton = (Rectangle){ 200, 30, 10, 10 };
|
||||||
|
Rectangle increaseResolutionButton = (Rectangle){ 215, 30, 10, 10 };
|
||||||
|
Rectangle decreaseTypeButton = (Rectangle){ 200, 45, 10, 10 };
|
||||||
|
Rectangle increaseTypeButton = (Rectangle){ 215, 45, 10, 10 };
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//----------------------------------------------------------
|
//----------------------------------------------------------
|
||||||
|
|
||||||
// Button rectangles
|
|
||||||
Rectangle decreaseResolutionButton = (Rectangle){200, 30, 10, 10};
|
|
||||||
Rectangle increaseResolutionButton = (Rectangle){215, 30, 10, 10};
|
|
||||||
Rectangle decreaseTypeButton = (Rectangle){200, 45, 10, 10};
|
|
||||||
Rectangle increaseTypeButton = (Rectangle){215, 45, 10, 10};
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//-----------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
if (IsWindowResized()){
|
if (IsWindowResized()) ResizeRenderSize(viewportType, &screenWidth, &screenHeight, gameWidth, gameHeight, &sourceRect, &destRect, &target);
|
||||||
ResizeRenderSize(viewportType, &screenWidth, &screenHeight, gameWidth, gameHeight, &sourceRect, &destRect, &target);
|
|
||||||
}
|
|
||||||
Vector2 mousePosition = GetMousePosition();
|
Vector2 mousePosition = GetMousePosition();
|
||||||
bool mousePressed = IsMouseButtonPressed(MOUSE_BUTTON_LEFT);
|
bool mousePressed = IsMouseButtonPressed(MOUSE_BUTTON_LEFT);
|
||||||
|
|
||||||
// Check buttons and rescale
|
// Check buttons and rescale
|
||||||
if (CheckCollisionPointRec(mousePosition, decreaseResolutionButton) && mousePressed){
|
if (CheckCollisionPointRec(mousePosition, decreaseResolutionButton) && mousePressed)
|
||||||
resolutionIndex = (resolutionIndex + RESOLUTION_COUNT - 1) % RESOLUTION_COUNT;
|
{
|
||||||
|
resolutionIndex = (resolutionIndex + RESOLUTION_COUNT - 1)%RESOLUTION_COUNT;
|
||||||
gameWidth = resolutionList[resolutionIndex].x;
|
gameWidth = resolutionList[resolutionIndex].x;
|
||||||
gameHeight = resolutionList[resolutionIndex].y;
|
gameHeight = resolutionList[resolutionIndex].y;
|
||||||
ResizeRenderSize(viewportType, &screenWidth, &screenHeight, gameWidth, gameHeight, &sourceRect, &destRect, &target);
|
ResizeRenderSize(viewportType, &screenWidth, &screenHeight, gameWidth, gameHeight, &sourceRect, &destRect, &target);
|
||||||
}
|
}
|
||||||
if (CheckCollisionPointRec(mousePosition, increaseResolutionButton) && mousePressed){
|
|
||||||
resolutionIndex = (resolutionIndex + 1) % RESOLUTION_COUNT;
|
if (CheckCollisionPointRec(mousePosition, increaseResolutionButton) && mousePressed)
|
||||||
|
{
|
||||||
|
resolutionIndex = (resolutionIndex + 1)%RESOLUTION_COUNT;
|
||||||
gameWidth = resolutionList[resolutionIndex].x;
|
gameWidth = resolutionList[resolutionIndex].x;
|
||||||
gameHeight = resolutionList[resolutionIndex].y;
|
gameHeight = resolutionList[resolutionIndex].y;
|
||||||
ResizeRenderSize(viewportType, &screenWidth, &screenHeight, gameWidth, gameHeight, &sourceRect, &destRect, &target);
|
ResizeRenderSize(viewportType, &screenWidth, &screenHeight, gameWidth, gameHeight, &sourceRect, &destRect, &target);
|
||||||
}
|
}
|
||||||
if (CheckCollisionPointRec(mousePosition, decreaseTypeButton) && mousePressed){
|
|
||||||
viewportType = (viewportType + VIEWPORT_TYPE_COUNT - 1) % VIEWPORT_TYPE_COUNT;
|
if (CheckCollisionPointRec(mousePosition, decreaseTypeButton) && mousePressed)
|
||||||
|
{
|
||||||
|
viewportType = (viewportType + VIEWPORT_TYPE_COUNT - 1)%VIEWPORT_TYPE_COUNT;
|
||||||
ResizeRenderSize(viewportType, &screenWidth, &screenHeight, gameWidth, gameHeight, &sourceRect, &destRect, &target);
|
ResizeRenderSize(viewportType, &screenWidth, &screenHeight, gameWidth, gameHeight, &sourceRect, &destRect, &target);
|
||||||
}
|
}
|
||||||
if (CheckCollisionPointRec(mousePosition, increaseTypeButton) && mousePressed){
|
|
||||||
viewportType = (viewportType + 1) % VIEWPORT_TYPE_COUNT;
|
if (CheckCollisionPointRec(mousePosition, increaseTypeButton) && mousePressed)
|
||||||
|
{
|
||||||
|
viewportType = (viewportType + 1)%VIEWPORT_TYPE_COUNT;
|
||||||
ResizeRenderSize(viewportType, &screenWidth, &screenHeight, gameWidth, gameHeight, &sourceRect, &destRect, &target);
|
ResizeRenderSize(viewportType, &screenWidth, &screenHeight, gameWidth, gameHeight, &sourceRect, &destRect, &target);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 textureMousePosition = Screen2RenderTexturePosition(mousePosition, &sourceRect, &destRect);
|
Vector2 textureMousePosition = Screen2RenderTexturePosition(mousePosition, &sourceRect, &destRect);
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
//-----------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Draw our scene to the render texture
|
// Draw our scene to the render texture
|
||||||
BeginTextureMode(target);
|
BeginTextureMode(target);
|
||||||
ClearBackground(WHITE);
|
ClearBackground(WHITE);
|
||||||
DrawCircle(textureMousePosition.x, textureMousePosition.y, 20.f, LIME);
|
DrawCircle(textureMousePosition.x, textureMousePosition.y, 20.0f, LIME);
|
||||||
|
|
||||||
|
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
|
|
||||||
// Draw render texture to main framebuffer
|
// Draw render texture to main framebuffer
|
||||||
@ -153,9 +153,7 @@ int main(void)
|
|||||||
ClearBackground(BLACK);
|
ClearBackground(BLACK);
|
||||||
|
|
||||||
// Draw our render texture with rotation applied
|
// Draw our render texture with rotation applied
|
||||||
const Vector2 ORIGIN_POSITION = (Vector2){ 0.0f, 0.0f };
|
DrawTexturePro(target.texture, sourceRect, destRect, (Vector2){ 0.0f, 0.0f }, 0.0f, WHITE);
|
||||||
const float ROTATION = 0.f;
|
|
||||||
DrawTexturePro(target.texture, sourceRect, destRect, ORIGIN_POSITION, ROTATION, WHITE);
|
|
||||||
|
|
||||||
// Draw Native resolution (GUI or anything)
|
// Draw Native resolution (GUI or anything)
|
||||||
// Draw info box
|
// Draw info box
|
||||||
@ -167,15 +165,10 @@ int main(void)
|
|||||||
DrawText(TextFormat("Game Resolution: %d x %d", gameWidth, gameHeight), 15, 30, 10, BLACK);
|
DrawText(TextFormat("Game Resolution: %d x %d", gameWidth, gameHeight), 15, 30, 10, BLACK);
|
||||||
|
|
||||||
DrawText(TextFormat("Type: %s", ViewportTypeNames[viewportType]), 15, 45, 10, BLACK);
|
DrawText(TextFormat("Type: %s", ViewportTypeNames[viewportType]), 15, 45, 10, BLACK);
|
||||||
Vector2 scaleRatio = (Vector2){destRect.width / sourceRect.width, destRect.height / -sourceRect.height};
|
Vector2 scaleRatio = (Vector2){destRect.width/sourceRect.width, -destRect.height/sourceRect.height};
|
||||||
if (scaleRatio.x < 0.001f || scaleRatio.y < 0.001f)
|
if (scaleRatio.x < 0.001f || scaleRatio.y < 0.001f) DrawText(TextFormat("Scale ratio: INVALID"), 15, 60, 10, BLACK);
|
||||||
{
|
else DrawText(TextFormat("Scale ratio: %.2f x %.2f", scaleRatio.x, scaleRatio.y), 15, 60, 10, BLACK);
|
||||||
DrawText(TextFormat("Scale ratio: INVALID"), 15, 60, 10, BLACK);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DrawText(TextFormat("Scale ratio: %.2f x %.2f", scaleRatio.x, scaleRatio.y), 15, 60, 10, BLACK);
|
|
||||||
}
|
|
||||||
DrawText(TextFormat("Source size: %.2f x %.2f", sourceRect.width, -sourceRect.height), 15, 75, 10, BLACK);
|
DrawText(TextFormat("Source size: %.2f x %.2f", sourceRect.width, -sourceRect.height), 15, 75, 10, BLACK);
|
||||||
DrawText(TextFormat("Destination size: %.2f x %.2f", destRect.width, destRect.height), 15, 90, 10, BLACK);
|
DrawText(TextFormat("Destination size: %.2f x %.2f", destRect.width, destRect.height), 15, 90, 10, BLACK);
|
||||||
|
|
||||||
@ -190,13 +183,13 @@ int main(void)
|
|||||||
DrawText(">", increaseResolutionButton.x + 3, increaseResolutionButton.y + 1, 10, BLACK);
|
DrawText(">", increaseResolutionButton.x + 3, increaseResolutionButton.y + 1, 10, BLACK);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//-----------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
|
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//---------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//----------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -206,54 +199,54 @@ int main(void)
|
|||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
static void KeepAspectCenteredInteger(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect)
|
static void KeepAspectCenteredInteger(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect)
|
||||||
{
|
{
|
||||||
sourceRect->x = 0.f;
|
sourceRect->x = 0.0f;
|
||||||
sourceRect->y = (float)gameHeight;
|
sourceRect->y = (float)gameHeight;
|
||||||
sourceRect->width = (float)gameWidth;
|
sourceRect->width = (float)gameWidth;
|
||||||
sourceRect->height = (float)-gameHeight;
|
sourceRect->height = (float)-gameHeight;
|
||||||
|
|
||||||
const int ratio_x = (screenWidth/gameWidth);
|
const int ratio_x = (screenWidth/gameWidth);
|
||||||
const int ratio_y = (screenHeight/gameHeight);
|
const int ratio_y = (screenHeight/gameHeight);
|
||||||
const float resizeRatio = (float)(ratio_x < ratio_y ? ratio_x : ratio_y);
|
const float resizeRatio = (float)((ratio_x < ratio_y)? ratio_x : ratio_y);
|
||||||
|
|
||||||
destRect->x = (float)(int)((screenWidth - (gameWidth * resizeRatio)) * 0.5);
|
destRect->x = (float)(int)((screenWidth - (gameWidth*resizeRatio))*0.5f);
|
||||||
destRect->y = (float)(int)((screenHeight - (gameHeight * resizeRatio)) * 0.5);
|
destRect->y = (float)(int)((screenHeight - (gameHeight*resizeRatio))*0.5f);
|
||||||
destRect->width = (float)(int)(gameWidth * resizeRatio);
|
destRect->width = (float)(int)(gameWidth*resizeRatio);
|
||||||
destRect->height = (float)(int)(gameHeight * resizeRatio);
|
destRect->height = (float)(int)(gameHeight*resizeRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void KeepHeightCenteredInteger(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect)
|
static void KeepHeightCenteredInteger(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect)
|
||||||
{
|
{
|
||||||
const float resizeRatio = (float)(screenHeight/gameHeight);
|
const float resizeRatio = (float)(screenHeight/gameHeight);
|
||||||
sourceRect->x = 0.f;
|
sourceRect->x = 0.0f;
|
||||||
sourceRect->y = 0.f;
|
sourceRect->y = 0.0f;
|
||||||
sourceRect->width = (float)(int)(screenWidth / resizeRatio);
|
sourceRect->width = (float)(int)(screenWidth/resizeRatio);
|
||||||
sourceRect->height = (float)-gameHeight;
|
sourceRect->height = (float)-gameHeight;
|
||||||
|
|
||||||
destRect->x = (float)(int)((screenWidth - (sourceRect->width * resizeRatio)) * 0.5);
|
destRect->x = (float)(int)((screenWidth - (sourceRect->width*resizeRatio))*0.5f);
|
||||||
destRect->y = (float)(int)((screenHeight - (gameHeight * resizeRatio)) * 0.5);
|
destRect->y = (float)(int)((screenHeight - (gameHeight*resizeRatio))*0.5f);
|
||||||
destRect->width = (float)(int)(sourceRect->width * resizeRatio);
|
destRect->width = (float)(int)(sourceRect->width*resizeRatio);
|
||||||
destRect->height = (float)(int)(gameHeight * resizeRatio);
|
destRect->height = (float)(int)(gameHeight*resizeRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void KeepWidthCenteredInteger(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect)
|
static void KeepWidthCenteredInteger(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect)
|
||||||
{
|
{
|
||||||
const float resizeRatio = (float)(screenWidth/gameWidth);
|
const float resizeRatio = (float)(screenWidth/gameWidth);
|
||||||
sourceRect->x = 0.f;
|
sourceRect->x = 0.0f;
|
||||||
sourceRect->y = 0.f;
|
sourceRect->y = 0.0f;
|
||||||
sourceRect->width = (float)gameWidth;
|
sourceRect->width = (float)gameWidth;
|
||||||
sourceRect->height = (float)(int)(screenHeight / resizeRatio);
|
sourceRect->height = (float)(int)(screenHeight/resizeRatio);
|
||||||
|
|
||||||
destRect->x = (float)(int)((screenWidth - (gameWidth * resizeRatio)) * 0.5);
|
destRect->x = (float)(int)((screenWidth - (gameWidth*resizeRatio))*0.5f);
|
||||||
destRect->y = (float)(int)((screenHeight - (sourceRect->height * resizeRatio)) * 0.5);
|
destRect->y = (float)(int)((screenHeight - (sourceRect->height*resizeRatio))*0.5f);
|
||||||
destRect->width = (float)(int)(gameWidth * resizeRatio);
|
destRect->width = (float)(int)(gameWidth*resizeRatio);
|
||||||
destRect->height = (float)(int)(sourceRect->height * resizeRatio);
|
destRect->height = (float)(int)(sourceRect->height*resizeRatio);
|
||||||
|
|
||||||
sourceRect->height *= -1.f;
|
sourceRect->height *= -1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void KeepAspectCentered(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect)
|
static void KeepAspectCentered(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect)
|
||||||
{
|
{
|
||||||
sourceRect->x = 0.f;
|
sourceRect->x = 0.0f;
|
||||||
sourceRect->y = (float)gameHeight;
|
sourceRect->y = (float)gameHeight;
|
||||||
sourceRect->width = (float)gameWidth;
|
sourceRect->width = (float)gameWidth;
|
||||||
sourceRect->height = (float)-gameHeight;
|
sourceRect->height = (float)-gameHeight;
|
||||||
@ -262,81 +255,58 @@ static void KeepAspectCentered(int screenWidth, int screenHeight, int gameWidth,
|
|||||||
const float ratio_y = ((float)screenHeight/(float)gameHeight);
|
const float ratio_y = ((float)screenHeight/(float)gameHeight);
|
||||||
const float resizeRatio = (ratio_x < ratio_y ? ratio_x : ratio_y);
|
const float resizeRatio = (ratio_x < ratio_y ? ratio_x : ratio_y);
|
||||||
|
|
||||||
destRect->x = (float)(int)((screenWidth - (gameWidth * resizeRatio)) * 0.5);
|
destRect->x = (float)(int)((screenWidth - (gameWidth*resizeRatio))*0.5f);
|
||||||
destRect->y = (float)(int)((screenHeight - (gameHeight * resizeRatio)) * 0.5);
|
destRect->y = (float)(int)((screenHeight - (gameHeight*resizeRatio))*0.5f);
|
||||||
destRect->width = (float)(int)(gameWidth * resizeRatio);
|
destRect->width = (float)(int)(gameWidth*resizeRatio);
|
||||||
destRect->height = (float)(int)(gameHeight * resizeRatio);
|
destRect->height = (float)(int)(gameHeight*resizeRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void KeepHeightCentered(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect)
|
static void KeepHeightCentered(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect)
|
||||||
{
|
{
|
||||||
const float resizeRatio = ((float)screenHeight/(float)gameHeight);
|
const float resizeRatio = ((float)screenHeight/(float)gameHeight);
|
||||||
sourceRect->x = 0.f;
|
sourceRect->x = 0.0f;
|
||||||
sourceRect->y = 0.f;
|
sourceRect->y = 0.0f;
|
||||||
sourceRect->width = (float)(int)((float)screenWidth / resizeRatio);
|
sourceRect->width = (float)(int)((float)screenWidth/resizeRatio);
|
||||||
sourceRect->height = (float)-gameHeight;
|
sourceRect->height = (float)-gameHeight;
|
||||||
|
|
||||||
destRect->x = (float)(int)((screenWidth - (sourceRect->width * resizeRatio)) * 0.5);
|
destRect->x = (float)(int)((screenWidth - (sourceRect->width*resizeRatio))*0.5f);
|
||||||
destRect->y = (float)(int)((screenHeight - (gameHeight * resizeRatio)) * 0.5);
|
destRect->y = (float)(int)((screenHeight - (gameHeight*resizeRatio))*0.5f);
|
||||||
destRect->width = (float)(int)(sourceRect->width * resizeRatio);
|
destRect->width = (float)(int)(sourceRect->width*resizeRatio);
|
||||||
destRect->height = (float)(int)(gameHeight * resizeRatio);
|
destRect->height = (float)(int)(gameHeight*resizeRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void KeepWidthCentered(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect)
|
static void KeepWidthCentered(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect)
|
||||||
{
|
{
|
||||||
const float resizeRatio = ((float)screenWidth/(float)gameWidth);
|
const float resizeRatio = ((float)screenWidth/(float)gameWidth);
|
||||||
sourceRect->x = 0.f;
|
sourceRect->x = 0.0f;
|
||||||
sourceRect->y = 0.f;
|
sourceRect->y = 0.0f;
|
||||||
sourceRect->width = (float)gameWidth;
|
sourceRect->width = (float)gameWidth;
|
||||||
sourceRect->height = (float)(int)((float)screenHeight / resizeRatio);
|
sourceRect->height = (float)(int)((float)screenHeight/resizeRatio);
|
||||||
|
|
||||||
destRect->x = (float)(int)((screenWidth - (gameWidth * resizeRatio)) * 0.5);
|
destRect->x = (float)(int)((screenWidth - (gameWidth*resizeRatio))*0.5f);
|
||||||
destRect->y = (float)(int)((screenHeight - (sourceRect->height * resizeRatio)) * 0.5);
|
destRect->y = (float)(int)((screenHeight - (sourceRect->height*resizeRatio))*0.5f);
|
||||||
destRect->width = (float)(int)(gameWidth * resizeRatio);
|
destRect->width = (float)(int)(gameWidth*resizeRatio);
|
||||||
destRect->height = (float)(int)(sourceRect->height * resizeRatio);
|
destRect->height = (float)(int)(sourceRect->height*resizeRatio);
|
||||||
|
|
||||||
sourceRect->height *= -1.f;
|
sourceRect->height *= -1.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ResizeRenderSize(enum ViewportType viewportType, int *screenWidth, int *screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect, RenderTexture2D *target)
|
static void ResizeRenderSize(ViewportType viewportType, int *screenWidth, int *screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect, RenderTexture2D *target)
|
||||||
{
|
{
|
||||||
*screenWidth = GetScreenWidth();
|
*screenWidth = GetScreenWidth();
|
||||||
*screenHeight = GetScreenHeight();
|
*screenHeight = GetScreenHeight();
|
||||||
|
|
||||||
switch(viewportType)
|
switch(viewportType)
|
||||||
{
|
{
|
||||||
case KEEP_ASPECT_INTEGER:
|
case KEEP_ASPECT_INTEGER: KeepAspectCenteredInteger(*screenWidth, *screenHeight, gameWidth, gameHeight, sourceRect, destRect); break;
|
||||||
{
|
case KEEP_HEIGHT_INTEGER: KeepHeightCenteredInteger(*screenWidth, *screenHeight, gameWidth, gameHeight, sourceRect, destRect); break;
|
||||||
KeepAspectCenteredInteger(*screenWidth, *screenHeight, gameWidth, gameHeight, sourceRect, destRect);
|
case KEEP_WIDTH_INTEGER: KeepWidthCenteredInteger(*screenWidth, *screenHeight, gameWidth, gameHeight, sourceRect, destRect); break;
|
||||||
break;
|
case KEEP_ASPECT: KeepAspectCentered(*screenWidth, *screenHeight, gameWidth, gameHeight, sourceRect, destRect); break;
|
||||||
}
|
case KEEP_HEIGHT: KeepHeightCentered(*screenWidth, *screenHeight, gameWidth, gameHeight, sourceRect, destRect); break;
|
||||||
case KEEP_HEIGHT_INTEGER:
|
case KEEP_WIDTH: KeepWidthCentered(*screenWidth, *screenHeight, gameWidth, gameHeight, sourceRect, destRect); break;
|
||||||
{
|
default: break;
|
||||||
KeepHeightCenteredInteger(*screenWidth, *screenHeight, gameWidth, gameHeight, sourceRect, destRect);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case KEEP_WIDTH_INTEGER:
|
|
||||||
{
|
|
||||||
KeepWidthCenteredInteger(*screenWidth, *screenHeight, gameWidth, gameHeight, sourceRect, destRect);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case KEEP_ASPECT:
|
|
||||||
{
|
|
||||||
KeepAspectCentered(*screenWidth, *screenHeight, gameWidth, gameHeight, sourceRect, destRect);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case KEEP_HEIGHT:
|
|
||||||
{
|
|
||||||
KeepHeightCentered(*screenWidth, *screenHeight, gameWidth, gameHeight, sourceRect, destRect);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case KEEP_WIDTH:
|
|
||||||
{
|
|
||||||
KeepWidthCentered(*screenWidth, *screenHeight, gameWidth, gameHeight, sourceRect, destRect);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UnloadRenderTexture(*target);
|
UnloadRenderTexture(*target);
|
||||||
*target = LoadRenderTexture(sourceRect->width, -sourceRect->height);
|
*target = LoadRenderTexture(sourceRect->width, -sourceRect->height);
|
||||||
}
|
}
|
||||||
@ -345,7 +315,7 @@ static void ResizeRenderSize(enum ViewportType viewportType, int *screenWidth, i
|
|||||||
static Vector2 Screen2RenderTexturePosition(Vector2 point, Rectangle *textureRect, Rectangle *scaledRect)
|
static Vector2 Screen2RenderTexturePosition(Vector2 point, Rectangle *textureRect, Rectangle *scaledRect)
|
||||||
{
|
{
|
||||||
Vector2 relativePosition = {point.x - scaledRect->x, point.y - scaledRect->y};
|
Vector2 relativePosition = {point.x - scaledRect->x, point.y - scaledRect->y};
|
||||||
Vector2 ratio = {textureRect->width / scaledRect->width, -textureRect->height / scaledRect->height};
|
Vector2 ratio = {textureRect->width/scaledRect->width, -textureRect->height/scaledRect->height};
|
||||||
|
|
||||||
return (Vector2){relativePosition.x * ratio.x, relativePosition.y * ratio.x};
|
return (Vector2){relativePosition.x*ratio.x, relativePosition.y*ratio.x};
|
||||||
}
|
}
|
||||||
@ -97,7 +97,8 @@ int main(void)
|
|||||||
if (IsWindowState(FLAG_WINDOW_MINIMIZED))
|
if (IsWindowState(FLAG_WINDOW_MINIMIZED))
|
||||||
{
|
{
|
||||||
framesCounter++;
|
framesCounter++;
|
||||||
if (framesCounter >= 240) {
|
if (framesCounter >= 240)
|
||||||
|
{
|
||||||
RestoreWindow(); // Restore window after 3 seconds
|
RestoreWindow(); // Restore window after 3 seconds
|
||||||
framesCounter = 0;
|
framesCounter = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -138,7 +138,7 @@ int main(void)
|
|||||||
GetMouseWheelMove()*-2.0f); // Move to target (zoom)
|
GetMouseWheelMove()*-2.0f); // Move to target (zoom)
|
||||||
|
|
||||||
// Cycle between models on mouse click
|
// Cycle between models on mouse click
|
||||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) currentModel = (currentModel + 1) % MAX_VOX_FILES;
|
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) currentModel = (currentModel + 1)%MAX_VOX_FILES;
|
||||||
|
|
||||||
// Update the shader with the camera view vector (points towards { 0.0f, 0.0f, 0.0f })
|
// Update the shader with the camera view vector (points towards { 0.0f, 0.0f, 0.0f })
|
||||||
float cameraPos[3] = { camera.position.x, camera.position.y, camera.position.z };
|
float cameraPos[3] = { camera.position.x, camera.position.y, camera.position.z };
|
||||||
|
|||||||
@ -254,9 +254,9 @@ int main(void)
|
|||||||
{
|
{
|
||||||
Color lightColor = (Color){
|
Color lightColor = (Color){
|
||||||
(unsigned char)(lights[i].color[0]*255),
|
(unsigned char)(lights[i].color[0]*255),
|
||||||
(unsigned char)(lights[i].color[1] * 255),
|
(unsigned char)(lights[i].color[1]*255),
|
||||||
(unsigned char)(lights[i].color[2] * 255),
|
(unsigned char)(lights[i].color[2]*255),
|
||||||
(unsigned char)(lights[i].color[3] * 255) };
|
(unsigned char)(lights[i].color[3]*255) };
|
||||||
|
|
||||||
if (lights[i].enabled) DrawSphereEx(lights[i].position, 0.2f, 8, 8, lightColor);
|
if (lights[i].enabled) DrawSphereEx(lights[i].position, 0.2f, 8, 8, lightColor);
|
||||||
else DrawSphereWires(lights[i].position, 0.2f, 8, 8, ColorAlpha(lightColor, 0.3f));
|
else DrawSphereWires(lights[i].position, 0.2f, 8, 8, ColorAlpha(lightColor, 0.3f));
|
||||||
|
|||||||
@ -138,7 +138,7 @@ int main(void)
|
|||||||
|
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
for (int i = 0; i < MAX_TEXTURES; ++i) UnloadTexture(texture[i]);
|
for (int i = 0; i < MAX_TEXTURES; i++) UnloadTexture(texture[i]);
|
||||||
UnloadShader(shdrColorCorrection);
|
UnloadShader(shdrColorCorrection);
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
|||||||
@ -138,7 +138,7 @@ int main(void)
|
|||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
DrawTextureRec(target.texture, (Rectangle) { 0, 0, (float)screenWidth, (float)-screenHeight }, (Vector2) { 0, 0 }, WHITE);
|
DrawTextureRec(target.texture, (Rectangle) { 0, 0, (float)screenWidth, (float)-screenHeight }, (Vector2) { 0, 0 }, WHITE);
|
||||||
|
|
||||||
DrawFPS(10, 10);
|
DrawFPS(10, 10);
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|||||||
@ -107,7 +107,7 @@ int main(void)
|
|||||||
|
|
||||||
float bulletDirection = baseDirection + (degreesPerRow*row);
|
float bulletDirection = baseDirection + (degreesPerRow*row);
|
||||||
|
|
||||||
// Bullet speed * bullet direction, this will determine how much pixels will be incremented/decremented
|
// Bullet speed*bullet direction, this will determine how much pixels will be incremented/decremented
|
||||||
// from the bullet position every frame. Since the bullets doesn't change its direction and speed,
|
// from the bullet position every frame. Since the bullets doesn't change its direction and speed,
|
||||||
// only need to calculate it at the spawning time
|
// only need to calculate it at the spawning time
|
||||||
// 0 degrees = right, 90 degrees = down, 180 degrees = left and 270 degrees = up, basically clockwise
|
// 0 degrees = right, 90 degrees = down, 180 degrees = left and 270 degrees = up, basically clockwise
|
||||||
|
|||||||
@ -14,9 +14,6 @@
|
|||||||
* Copyright (c) 2025 JP Mortiboys (@themushroompirates)
|
* Copyright (c) 2025 JP Mortiboys (@themushroompirates)
|
||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
#if defined(WIN32)
|
|
||||||
#define _CRT_SECURE_NO_WARNINGS
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
@ -63,24 +60,16 @@ int main(void)
|
|||||||
/* 8 */ { TL,HH,HH,TR, /* */ VV,TL,TR,VV,/* */ VV,BL,BR,VV,/* */ VV,TL,TR,VV,/* */ VV,BL,BR,VV,/* */ BL,HH,HH,BR },
|
/* 8 */ { TL,HH,HH,TR, /* */ VV,TL,TR,VV,/* */ VV,BL,BR,VV,/* */ VV,TL,TR,VV,/* */ VV,BL,BR,VV,/* */ BL,HH,HH,BR },
|
||||||
/* 9 */ { TL,HH,HH,TR, /* */ VV,TL,TR,VV,/* */ VV,BL,BR,VV,/* */ BL,HH,TR,VV,/* */ TL,HH,BR,VV,/* */ BL,HH,HH,BR },
|
/* 9 */ { TL,HH,HH,TR, /* */ VV,TL,TR,VV,/* */ VV,BL,BR,VV,/* */ BL,HH,TR,VV,/* */ TL,HH,BR,VV,/* */ BL,HH,HH,BR },
|
||||||
};
|
};
|
||||||
|
|
||||||
// Time for the hands to move to the new position (in seconds); this must be <1s
|
// Time for the hands to move to the new position (in seconds); this must be <1s
|
||||||
const float handsMoveDuration = .5f;
|
const float handsMoveDuration = 0.5f;
|
||||||
|
|
||||||
// We store the previous seconds value so we can see if the time has changed
|
|
||||||
int prevSeconds = -1;
|
int prevSeconds = -1;
|
||||||
|
|
||||||
// This represents the real position where the hands are right now
|
|
||||||
Vector2 currentAngles[6][24] = { 0 };
|
Vector2 currentAngles[6][24] = { 0 };
|
||||||
|
|
||||||
// This is the position where the hands were moving from
|
|
||||||
Vector2 srcAngles[6][24] = { 0 };
|
Vector2 srcAngles[6][24] = { 0 };
|
||||||
// This is the position where the hands are moving to
|
|
||||||
Vector2 dstAngles[6][24] = { 0 };
|
Vector2 dstAngles[6][24] = { 0 };
|
||||||
|
|
||||||
// Current animation timer
|
|
||||||
float handsMoveTimer = 0.0f;
|
float handsMoveTimer = 0.0f;
|
||||||
|
|
||||||
// 12 or 24 hour mode
|
|
||||||
int hourMode = 24;
|
int hourMode = 24;
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
@ -91,7 +80,6 @@ int main(void)
|
|||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Get the current time
|
// Get the current time
|
||||||
time_t rawtime;
|
time_t rawtime;
|
||||||
struct tm *timeinfo;
|
struct tm *timeinfo;
|
||||||
@ -99,30 +87,26 @@ int main(void)
|
|||||||
time(&rawtime);
|
time(&rawtime);
|
||||||
timeinfo = localtime(&rawtime);
|
timeinfo = localtime(&rawtime);
|
||||||
|
|
||||||
if (timeinfo->tm_sec != prevSeconds) {
|
if (timeinfo->tm_sec != prevSeconds)
|
||||||
|
{
|
||||||
// The time has changed, so we need to move the hands to the new positions
|
// The time has changed, so we need to move the hands to the new positions
|
||||||
prevSeconds = timeinfo->tm_sec;
|
prevSeconds = timeinfo->tm_sec;
|
||||||
|
|
||||||
// Format the current time so we can access the individual digits
|
// Format the current time so we can access the individual digits
|
||||||
const char *clockDigits = TextFormat("%02d%02d%02d", timeinfo->tm_hour % hourMode, timeinfo->tm_min, timeinfo->tm_sec);
|
const char *clockDigits = TextFormat("%02d%02d%02d", timeinfo->tm_hour%hourMode, timeinfo->tm_min, timeinfo->tm_sec);
|
||||||
|
|
||||||
// Fetch where we want all the hands to be
|
// Fetch where we want all the hands to be
|
||||||
for (int digit = 0; digit < 6; digit++) {
|
for (int digit = 0; digit < 6; digit++)
|
||||||
for (int cell = 0; cell < 24; cell++) {
|
{
|
||||||
|
for (int cell = 0; cell < 24; cell++)
|
||||||
|
{
|
||||||
srcAngles[digit][cell] = currentAngles[digit][cell];
|
srcAngles[digit][cell] = currentAngles[digit][cell];
|
||||||
dstAngles[digit][cell] = digitAngles[ clockDigits[digit] - '0' ][cell];
|
dstAngles[digit][cell] = digitAngles[clockDigits[digit] - '0'][cell];
|
||||||
|
|
||||||
// Quick exception for 12h mode
|
// Quick exception for 12h mode
|
||||||
if (digit == 0 && hourMode == 12 && clockDigits[0] == '0') {
|
if ((digit == 0) && (hourMode == 12) && (clockDigits[0] == '0')) dstAngles[digit][cell] = ZZ;
|
||||||
dstAngles[digit][cell] = ZZ;
|
if (srcAngles[digit][cell].x > dstAngles[digit][cell].x) srcAngles[digit][cell].x -= 360.0f;
|
||||||
}
|
if (srcAngles[digit][cell].y > dstAngles[digit][cell].y) srcAngles[digit][cell].y -= 360.0f;
|
||||||
|
|
||||||
if (srcAngles[digit][cell].x > dstAngles[digit][cell].x) {
|
|
||||||
srcAngles[digit][cell].x -= 360.0f;
|
|
||||||
}
|
|
||||||
if (srcAngles[digit][cell].y > dstAngles[digit][cell].y) {
|
|
||||||
srcAngles[digit][cell].y -= 360.0f;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,37 +115,29 @@ int main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now let's animate all the hands if we need to
|
// Now let's animate all the hands if we need to
|
||||||
if (handsMoveTimer < handsMoveDuration) {
|
if (handsMoveTimer < handsMoveDuration)
|
||||||
|
{
|
||||||
// Increase the timer but don't go above the maximum
|
// Increase the timer but don't go above the maximum
|
||||||
handsMoveTimer = Clamp(handsMoveTimer + GetFrameTime(), 0, handsMoveDuration);
|
handsMoveTimer = Clamp(handsMoveTimer + GetFrameTime(), 0, handsMoveDuration);
|
||||||
|
|
||||||
// Calculate the % completion of the animation
|
// Calculate the%completion of the animation
|
||||||
float t = handsMoveTimer / handsMoveDuration;
|
float t = handsMoveTimer/handsMoveDuration;
|
||||||
|
|
||||||
// A little cheeky smoothstep
|
// A little cheeky smoothstep
|
||||||
t = t * t * (3.0f - 2.0f * t);
|
t = t*t*(3.0f - 2.0f*t);
|
||||||
|
|
||||||
for (int digit = 0; digit < 6; digit++) {
|
for (int digit = 0; digit < 6; digit++)
|
||||||
for (int cell = 0; cell < 24; cell++) {
|
{
|
||||||
|
for (int cell = 0; cell < 24; cell++)
|
||||||
|
{
|
||||||
currentAngles[digit][cell].x = Lerp(srcAngles[digit][cell].x, dstAngles[digit][cell].x, t);
|
currentAngles[digit][cell].x = Lerp(srcAngles[digit][cell].x, dstAngles[digit][cell].x, t);
|
||||||
currentAngles[digit][cell].y = Lerp(srcAngles[digit][cell].y, dstAngles[digit][cell].y, t);
|
currentAngles[digit][cell].y = Lerp(srcAngles[digit][cell].y, dstAngles[digit][cell].y, t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handsMoveTimer == handsMoveDuration) {
|
|
||||||
// The animation has now finished
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle input
|
// Handle input
|
||||||
|
if (IsKeyPressed(KEY_SPACE)) hourMode = 36 - hourMode; // Toggle between 12 and 24 hour mode with space
|
||||||
// Toggle between 12 and 24 hour mode with space
|
|
||||||
if (IsKeyPressed(KEY_SPACE)) {
|
|
||||||
hourMode = 36 - hourMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
@ -174,19 +150,22 @@ int main(void)
|
|||||||
|
|
||||||
float xOffset = 4.0f;
|
float xOffset = 4.0f;
|
||||||
|
|
||||||
for (int digit = 0; digit < 6; digit++) {
|
for (int digit = 0; digit < 6; digit++)
|
||||||
|
{
|
||||||
for (int row = 0; row < 6; row++) {
|
for (int row = 0; row < 6; row++)
|
||||||
for (int col = 0; col < 4; col++) {
|
{
|
||||||
|
for (int col = 0; col < 4; col++)
|
||||||
|
{
|
||||||
Vector2 centre = (Vector2){
|
Vector2 centre = (Vector2){
|
||||||
xOffset + col*(clockFaceSize+clockFaceSpacing) + clockFaceSize * .5f,
|
xOffset + col*(clockFaceSize+clockFaceSpacing) + clockFaceSize*0.5f,
|
||||||
100 + row*(clockFaceSize+clockFaceSpacing) + clockFaceSize * .5f
|
100 + row*(clockFaceSize+clockFaceSpacing) + clockFaceSize*0.5f
|
||||||
};
|
};
|
||||||
DrawRing(centre, clockFaceSize * 0.5f - 2.0f, clockFaceSize * 0.5f, 0, 360, 24, DARKGRAY);
|
|
||||||
|
DrawRing(centre, clockFaceSize*0.5f - 2.0f, clockFaceSize*0.5f, 0, 360, 24, DARKGRAY);
|
||||||
|
|
||||||
// Big hand
|
// Big hand
|
||||||
DrawRectanglePro(
|
DrawRectanglePro(
|
||||||
(Rectangle){centre.x, centre.y, clockFaceSize*.5f+4.0f, 4.0f},
|
(Rectangle){centre.x, centre.y, clockFaceSize*0.5f+4.0f, 4.0f},
|
||||||
(Vector2){ 2.0f, 2.0f },
|
(Vector2){ 2.0f, 2.0f },
|
||||||
currentAngles[digit][row*4+col].x,
|
currentAngles[digit][row*4+col].x,
|
||||||
handsColor
|
handsColor
|
||||||
@ -194,7 +173,7 @@ int main(void)
|
|||||||
|
|
||||||
// Little hand
|
// Little hand
|
||||||
DrawRectanglePro(
|
DrawRectanglePro(
|
||||||
(Rectangle){centre.x, centre.y, clockFaceSize*.5f+2.0f, 4.0f},
|
(Rectangle){centre.x, centre.y, clockFaceSize*0.5f+2.0f, 4.0f},
|
||||||
(Vector2){ 2.0f, 2.0f },
|
(Vector2){ 2.0f, 2.0f },
|
||||||
currentAngles[digit][row*4+col].y,
|
currentAngles[digit][row*4+col].y,
|
||||||
handsColor
|
handsColor
|
||||||
@ -202,27 +181,23 @@ int main(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
xOffset += (clockFaceSize+clockFaceSpacing) * 4;
|
xOffset += (clockFaceSize+clockFaceSpacing)*4;
|
||||||
if (digit % 2 == 1) {
|
if (digit%2 == 1)
|
||||||
|
{
|
||||||
DrawRing((Vector2){xOffset + 4.0f, 160.0f}, 6.0f, 8.0f, 0.0f, 360.0f, 24, handsColor);
|
DrawRing((Vector2){xOffset + 4.0f, 160.0f}, 6.0f, 8.0f, 0.0f, 360.0f, 24, handsColor);
|
||||||
DrawRing((Vector2){xOffset + 4.0f, 225.0f}, 6.0f, 8.0f, 0.0f, 360.0f, 24, handsColor);
|
DrawRing((Vector2){xOffset + 4.0f, 225.0f}, 6.0f, 8.0f, 0.0f, 360.0f, 24, handsColor);
|
||||||
|
|
||||||
xOffset += sectionSpacing;
|
xOffset += sectionSpacing;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawFPS(10, 10);
|
DrawFPS(10, 10);
|
||||||
|
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
|
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@ -76,7 +76,7 @@ int main(void)
|
|||||||
float step = dt/SIMULATION_STEPS, step2 = step*step;
|
float step = dt/SIMULATION_STEPS, step2 = step*step;
|
||||||
|
|
||||||
// Update Physics - larger steps = better approximation
|
// Update Physics - larger steps = better approximation
|
||||||
for (int i = 0; i < SIMULATION_STEPS; ++i)
|
for (int i = 0; i < SIMULATION_STEPS; i++)
|
||||||
{
|
{
|
||||||
float delta = theta1 - theta2;
|
float delta = theta1 - theta2;
|
||||||
float sinD = sinf(delta), cosD = cosf(delta), cos2D = cosf(2*delta);
|
float sinD = sinf(delta), cosD = cosf(delta), cos2D = cosf(2*delta);
|
||||||
|
|||||||
@ -31,7 +31,7 @@ int main(void)
|
|||||||
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - math angle rotation");
|
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - math angle rotation");
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
|
|
||||||
Vector2 center = { screenWidth / 2.0f, screenHeight / 2.0f };
|
Vector2 center = { screenWidth/2.0f, screenHeight/2.0f };
|
||||||
const float lineLength = 150.0f;
|
const float lineLength = 150.0f;
|
||||||
|
|
||||||
// Predefined angles for fixed lines
|
// Predefined angles for fixed lines
|
||||||
@ -60,9 +60,9 @@ int main(void)
|
|||||||
// Draw fixed-angle lines with colorful gradient
|
// Draw fixed-angle lines with colorful gradient
|
||||||
for (int i = 0; i < numAngles; i++)
|
for (int i = 0; i < numAngles; i++)
|
||||||
{
|
{
|
||||||
float rad = angles[i] * DEG2RAD;
|
float rad = angles[i]*DEG2RAD;
|
||||||
Vector2 end = { center.x + cosf(rad) * lineLength,
|
Vector2 end = { center.x + cosf(rad)*lineLength,
|
||||||
center.y + sinf(rad) * lineLength };
|
center.y + sinf(rad)*lineLength };
|
||||||
|
|
||||||
// Gradient color from green → cyan → blue → magenta
|
// Gradient color from green → cyan → blue → magenta
|
||||||
Color col;
|
Color col;
|
||||||
@ -78,15 +78,15 @@ int main(void)
|
|||||||
DrawLineEx(center, end, 5.0f, col);
|
DrawLineEx(center, end, 5.0f, col);
|
||||||
|
|
||||||
// Draw angle label slightly offset along the line
|
// Draw angle label slightly offset along the line
|
||||||
Vector2 textPos = { center.x + cosf(rad) * (lineLength + 20),
|
Vector2 textPos = { center.x + cosf(rad)*(lineLength + 20),
|
||||||
center.y + sinf(rad) * (lineLength + 20) };
|
center.y + sinf(rad)*(lineLength + 20) };
|
||||||
DrawText(TextFormat("%d°", angles[i]), (int)textPos.x, (int)textPos.y, 20, col);
|
DrawText(TextFormat("%d°", angles[i]), (int)textPos.x, (int)textPos.y, 20, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw animated rotating line with changing color
|
// Draw animated rotating line with changing color
|
||||||
float animRad = totalAngle * DEG2RAD;
|
float animRad = totalAngle*DEG2RAD;
|
||||||
Vector2 animEnd = { center.x + cosf(animRad) * lineLength,
|
Vector2 animEnd = { center.x + cosf(animRad)*lineLength,
|
||||||
center.y + sinf(animRad) * lineLength };
|
center.y + sinf(animRad)*lineLength };
|
||||||
|
|
||||||
// Cycle through HSV colors for animated line
|
// Cycle through HSV colors for animated line
|
||||||
Color animCol = ColorFromHSV(fmodf(totalAngle, 360.0f), 0.8f, 0.9f);
|
Color animCol = ColorFromHSV(fmodf(totalAngle, 360.0f), 0.8f, 0.9f);
|
||||||
|
|||||||
@ -40,8 +40,8 @@ int main(void)
|
|||||||
|
|
||||||
Vector2 sinePoints[WAVE_POINTS];
|
Vector2 sinePoints[WAVE_POINTS];
|
||||||
Vector2 cosPoints[WAVE_POINTS];
|
Vector2 cosPoints[WAVE_POINTS];
|
||||||
Vector2 center = { (screenWidth/2.0f) - 30.f, screenHeight/2.0f };
|
Vector2 center = { (screenWidth/2.0f) - 30.0f, screenHeight/2.0f };
|
||||||
Rectangle start = { 20.f, screenHeight - 120.f , 200.0f, 100.0f};
|
Rectangle start = { 20.0f, screenHeight - 120.f , 200.0f, 100.0f};
|
||||||
float radius = 130.0f;
|
float radius = 130.0f;
|
||||||
float angle = 0.0f;
|
float angle = 0.0f;
|
||||||
bool pause = false;
|
bool pause = false;
|
||||||
@ -98,7 +98,7 @@ int main(void)
|
|||||||
// Base circle and axes
|
// Base circle and axes
|
||||||
DrawCircleLinesV(center, radius, GRAY);
|
DrawCircleLinesV(center, radius, GRAY);
|
||||||
DrawLineEx((Vector2){ center.x, limitMin.y }, (Vector2){ center.x, limitMax.y }, 1.0f, GRAY);
|
DrawLineEx((Vector2){ center.x, limitMin.y }, (Vector2){ center.x, limitMax.y }, 1.0f, GRAY);
|
||||||
DrawLineEx((Vector2){ limitMin.x, center.y }, (Vector2){ limitMax.x, center.y }, 1.f, GRAY);
|
DrawLineEx((Vector2){ limitMin.x, center.y }, (Vector2){ limitMax.x, center.y }, 1.0f, GRAY);
|
||||||
|
|
||||||
// Wave graph axes
|
// Wave graph axes
|
||||||
DrawLineEx((Vector2){ start.x , start.y }, (Vector2){ start.x , start.y + start.height }, 2.0f, GRAY);
|
DrawLineEx((Vector2){ start.x , start.y }, (Vector2){ start.x , start.y + start.height }, 2.0f, GRAY);
|
||||||
@ -135,19 +135,19 @@ int main(void)
|
|||||||
DrawText(TextFormat("Cotangent %.2f", cotangent), 640, 250, 6, ORANGE);
|
DrawText(TextFormat("Cotangent %.2f", cotangent), 640, 250, 6, ORANGE);
|
||||||
|
|
||||||
// Complementary angle (beige)
|
// Complementary angle (beige)
|
||||||
DrawCircleSectorLines(center, radius*0.6f , -angle, -90.f , 36.0f, BEIGE);
|
DrawCircleSectorLines(center, radius*0.6f , -angle, -90.0f , 36.0f, BEIGE);
|
||||||
DrawText(TextFormat("Complementary %0.f°",complementary), 640, 150, 6, BEIGE);
|
DrawText(TextFormat("Complementary %0.f°",complementary), 640, 150, 6, BEIGE);
|
||||||
|
|
||||||
// Supplementary angle (darkblue)
|
// Supplementary angle (darkblue)
|
||||||
DrawCircleSectorLines(center, radius*0.5f , -angle, -180.f , 36.0f, DARKBLUE);
|
DrawCircleSectorLines(center, radius*0.5f , -angle, -180.0f , 36.0f, DARKBLUE);
|
||||||
DrawText(TextFormat("Supplementary %0.f°",supplementary), 640, 130, 6, DARKBLUE);
|
DrawText(TextFormat("Supplementary %0.f°",supplementary), 640, 130, 6, DARKBLUE);
|
||||||
|
|
||||||
// Explementary angle (pink)
|
// Explementary angle (pink)
|
||||||
DrawCircleSectorLines(center, radius*0.4f , -angle, -360.f , 36.0f, PINK);
|
DrawCircleSectorLines(center, radius*0.4f , -angle, -360.0f , 36.0f, PINK);
|
||||||
DrawText(TextFormat("Explementary %0.f°",explementary), 640, 170, 6, PINK);
|
DrawText(TextFormat("Explementary %0.f°",explementary), 640, 170, 6, PINK);
|
||||||
|
|
||||||
// Current angle - arc (lime), radius (black), endpoint (black)
|
// Current angle - arc (lime), radius (black), endpoint (black)
|
||||||
DrawCircleSectorLines(center, radius*0.7f , -angle, 0.f, 36.0f, LIME);
|
DrawCircleSectorLines(center, radius*0.7f , -angle, 0.0f, 36.0f, LIME);
|
||||||
DrawLineEx((Vector2){ center.x , center.y }, point, 2.0f, BLACK);
|
DrawLineEx((Vector2){ center.x , center.y }, point, 2.0f, BLACK);
|
||||||
DrawCircleV(point, 4.0f, BLACK);
|
DrawCircleV(point, 4.0f, BLACK);
|
||||||
|
|
||||||
@ -156,11 +156,12 @@ int main(void)
|
|||||||
GuiSetStyle(LABEL, TEXT_COLOR_NORMAL, ColorToInt(GRAY));
|
GuiSetStyle(LABEL, TEXT_COLOR_NORMAL, ColorToInt(GRAY));
|
||||||
GuiToggle((Rectangle){ 640, 70, 120, 20}, TextFormat("Pause"), &pause);
|
GuiToggle((Rectangle){ 640, 70, 120, 20}, TextFormat("Pause"), &pause);
|
||||||
GuiSetStyle(LABEL, TEXT_COLOR_NORMAL, ColorToInt(LIME));
|
GuiSetStyle(LABEL, TEXT_COLOR_NORMAL, ColorToInt(LIME));
|
||||||
GuiSliderBar((Rectangle){ 640, 40, 120, 20}, "Angle", TextFormat("%.0f°", angle), &angle, 0.0f, 360.f);
|
GuiSliderBar((Rectangle){ 640, 40, 120, 20}, "Angle", TextFormat("%.0f°", angle), &angle, 0.0f, 360.0f);
|
||||||
|
|
||||||
// Angle values panel
|
// Angle values panel
|
||||||
GuiGroupBox((Rectangle){ 620, 110, 140, 170}, "Angle Values");
|
GuiGroupBox((Rectangle){ 620, 110, 140, 170}, "Angle Values");
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
DrawFPS(10, 10);
|
DrawFPS(10, 10);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
|||||||
@ -71,7 +71,7 @@ int main(void)
|
|||||||
if ((trailPositions[i].x != 0.0f) || (trailPositions[i].y != 0.0f))
|
if ((trailPositions[i].x != 0.0f) || (trailPositions[i].y != 0.0f))
|
||||||
{
|
{
|
||||||
// Calculate relative trail strength (ratio is near 1.0 for new, near 0.0 for old)
|
// Calculate relative trail strength (ratio is near 1.0 for new, near 0.0 for old)
|
||||||
float ratio = (float)(MAX_TRAIL_LENGTH - i) / MAX_TRAIL_LENGTH;
|
float ratio = (float)(MAX_TRAIL_LENGTH - i)/MAX_TRAIL_LENGTH;
|
||||||
|
|
||||||
// Fade effect: oldest positions are more transparent
|
// Fade effect: oldest positions are more transparent
|
||||||
// Fade (color, alpha) - alpha is 0.5 to 1.0 based on ratio
|
// Fade (color, alpha) - alpha is 0.5 to 1.0 based on ratio
|
||||||
|
|||||||
@ -184,7 +184,7 @@ static void DrawRectangleRoundedGradientH(Rectangle rec, float roundnessLeft, fl
|
|||||||
}
|
}
|
||||||
|
|
||||||
// End one even segments
|
// End one even segments
|
||||||
if ( segments % 2)
|
if ( segments%2)
|
||||||
{
|
{
|
||||||
rlTexCoord2f(shapeRect.x/texShapes.width, shapeRect.y/texShapes.height);
|
rlTexCoord2f(shapeRect.x/texShapes.width, shapeRect.y/texShapes.height);
|
||||||
rlVertex2f(center.x, center.y);
|
rlVertex2f(center.x, center.y);
|
||||||
|
|||||||
@ -112,7 +112,7 @@ int main(void)
|
|||||||
GuiSliderBar((Rectangle){ 640, 40, 120, 20}, "Angle", TextFormat("%.0f", angle), &angle, 0, 180);
|
GuiSliderBar((Rectangle){ 640, 40, 120, 20}, "Angle", TextFormat("%.0f", angle), &angle, 0, 180);
|
||||||
GuiSliderBar((Rectangle){ 640, 70, 120, 20 }, "Length", TextFormat("%.0f", length), &length, 12.0f, 240.0f);
|
GuiSliderBar((Rectangle){ 640, 70, 120, 20 }, "Length", TextFormat("%.0f", length), &length, 12.0f, 240.0f);
|
||||||
GuiSliderBar((Rectangle){ 640, 100, 120, 20}, "Decay", TextFormat("%.2f", branchDecay), &branchDecay, 0.1f, 0.78f);
|
GuiSliderBar((Rectangle){ 640, 100, 120, 20}, "Decay", TextFormat("%.2f", branchDecay), &branchDecay, 0.1f, 0.78f);
|
||||||
GuiSliderBar((Rectangle){ 640, 130, 120, 20 }, "Depth", TextFormat("%.0f", treeDepth), &treeDepth, 1.0f, 10.f);
|
GuiSliderBar((Rectangle){ 640, 130, 120, 20 }, "Depth", TextFormat("%.0f", treeDepth), &treeDepth, 1.0f, 10.0f);
|
||||||
GuiSliderBar((Rectangle){ 640, 160, 120, 20}, "Thick", TextFormat("%.0f", thick), &thick, 1, 8);
|
GuiSliderBar((Rectangle){ 640, 160, 120, 20}, "Thick", TextFormat("%.0f", thick), &thick, 1, 8);
|
||||||
GuiCheckBox((Rectangle){ 640, 190, 20, 20 }, "Bezier", &bezier);
|
GuiCheckBox((Rectangle){ 640, 190, 20, 20 }, "Bezier", &bezier);
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|||||||
@ -122,11 +122,11 @@ int main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
float distance = Vector2Distance(center, circlePosition)/pointScale;
|
float distance = Vector2Distance(center, circlePosition)/pointScale;
|
||||||
float angle = ((Vector2Angle((Vector2){ 0.0f, -pointScale }, Vector2Subtract(center, circlePosition))/PI + 1.0f) / 2.0f);
|
float angle = ((Vector2Angle((Vector2){ 0.0f, -pointScale }, Vector2Subtract(center, circlePosition))/PI + 1.0f)/2.0f);
|
||||||
|
|
||||||
if (distance > 1.0f)
|
if (distance > 1.0f)
|
||||||
{
|
{
|
||||||
circlePosition = Vector2Add((Vector2){ sinf(angle*(PI * 2.0f)) * pointScale, -cosf(angle*(PI*2.0f))*pointScale }, center);
|
circlePosition = Vector2Add((Vector2){ sinf(angle*(PI*2.0f))*pointScale, -cosf(angle*(PI*2.0f))*pointScale }, center);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,21 +152,15 @@ int main(void)
|
|||||||
// If the slider or the wheel was clicked, update the current color
|
// If the slider or the wheel was clicked, update the current color
|
||||||
if (settingColor || sliderClicked)
|
if (settingColor || sliderClicked)
|
||||||
{
|
{
|
||||||
if (settingColor) {
|
if (settingColor) circlePosition = GetMousePosition();
|
||||||
circlePosition = GetMousePosition();
|
|
||||||
}
|
|
||||||
|
|
||||||
float distance = Vector2Distance(center, circlePosition) / pointScale;
|
float distance = Vector2Distance(center, circlePosition)/pointScale;
|
||||||
|
|
||||||
float angle = ((Vector2Angle((Vector2){ 0.0f, -pointScale }, Vector2Subtract(center, circlePosition))/PI + 1.0f)/2.0f);
|
float angle = ((Vector2Angle((Vector2){ 0.0f, -pointScale }, Vector2Subtract(center, circlePosition))/PI + 1.0f)/2.0f);
|
||||||
if (settingColor && distance > 1.0f) {
|
if (settingColor && distance > 1.0f) circlePosition = Vector2Add((Vector2){ sinf(angle*(PI*2.0f))*pointScale, -cosf(angle*(PI* 2.0f))*pointScale }, center);
|
||||||
circlePosition = Vector2Add((Vector2){ sinf(angle*(PI*2.0f))*pointScale, -cosf(angle*(PI* 2.0f))*pointScale }, center);
|
|
||||||
}
|
|
||||||
|
|
||||||
float angle360 = angle*360.0f;
|
float angle360 = angle*360.0f;
|
||||||
|
|
||||||
float valueActual = Clamp(distance, 0.0f, 1.0f);
|
float valueActual = Clamp(distance, 0.0f, 1.0f);
|
||||||
|
|
||||||
color = ColorLerp((Color){ (int)(value*255.0f), (int)(value*255.0f), (int)(value*255.0f), 255 }, ColorFromHSV(angle360, Clamp(distance, 0.0f, 1.0f), 1.0f), valueActual);
|
color = ColorLerp((Color){ (int)(value*255.0f), (int)(value*255.0f), (int)(value*255.0f), 255 }, ColorFromHSV(angle360, Clamp(distance, 0.0f, 1.0f), 1.0f), valueActual);
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|||||||
@ -95,7 +95,7 @@ int main(void)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (int i = 0; i <= emissionRate; ++i) EmitParticle(&circularBuffer, emitterPosition, currentType);
|
for (int i = 0; i <= emissionRate; i++) EmitParticle(&circularBuffer, emitterPosition, currentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the parameters of each particle
|
// Update the parameters of each particle
|
||||||
|
|||||||
@ -34,7 +34,7 @@ int main(void)
|
|||||||
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - triangle strip");
|
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - triangle strip");
|
||||||
|
|
||||||
Vector2 points[122] = { 0 };
|
Vector2 points[122] = { 0 };
|
||||||
Vector2 center = { (screenWidth/2.0f) - 125.f, screenHeight/2.0f };
|
Vector2 center = { (screenWidth/2.0f) - 125.0f, screenHeight/2.0f };
|
||||||
float segments = 6.0f;
|
float segments = 6.0f;
|
||||||
float insideRadius = 100.0f;
|
float insideRadius = 100.0f;
|
||||||
float outsideRadius = 150.0f;
|
float outsideRadius = 150.0f;
|
||||||
@ -92,7 +92,7 @@ int main(void)
|
|||||||
|
|
||||||
// Draw GUI controls
|
// Draw GUI controls
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
GuiSliderBar((Rectangle){ 640, 40, 120, 20}, "Segments", TextFormat("%.0f", segments), &segments, 6.0f, 60.f);
|
GuiSliderBar((Rectangle){ 640, 40, 120, 20}, "Segments", TextFormat("%.0f", segments), &segments, 6.0f, 60.0f);
|
||||||
GuiCheckBox((Rectangle){ 640, 70, 20, 20 }, "Outline", &outline);
|
GuiCheckBox((Rectangle){ 640, 70, 20, 20 }, "Outline", &outline);
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@ -231,7 +231,7 @@ int main(void)
|
|||||||
if (multicolor)
|
if (multicolor)
|
||||||
{
|
{
|
||||||
// Fill color array with random colors
|
// Fill color array with random colors
|
||||||
for (int i = 0; i < TEXT_MAX_LAYERS; ++i)
|
for (int i = 0; i < TEXT_MAX_LAYERS; i++)
|
||||||
{
|
{
|
||||||
multi[i] = GenerateRandomColor(0.5f, 0.8f);
|
multi[i] = GenerateRandomColor(0.5f, 0.8f);
|
||||||
multi[i].a = GetRandomValue(0, 255);
|
multi[i].a = GetRandomValue(0, 255);
|
||||||
@ -296,7 +296,7 @@ int main(void)
|
|||||||
rlRotatef(90.0f, 1.0f, 0.0f, 0.0f);
|
rlRotatef(90.0f, 1.0f, 0.0f, 0.0f);
|
||||||
rlRotatef(90.0f, 0.0f, 0.0f, -1.0f);
|
rlRotatef(90.0f, 0.0f, 0.0f, -1.0f);
|
||||||
|
|
||||||
for (int i = 0; i < layers; ++i)
|
for (int i = 0; i < layers; i++)
|
||||||
{
|
{
|
||||||
Color clr = light;
|
Color clr = light;
|
||||||
if (multicolor) clr = multi[i];
|
if (multicolor) clr = multi[i];
|
||||||
|
|||||||
@ -186,7 +186,7 @@ static void DrawTextStyled(Font font, const char *text, Vector2 position, float
|
|||||||
else increaseX += ((float)font.glyphs[index].advanceX*scaleFactor + spacing);
|
else increaseX += ((float)font.glyphs[index].advanceX*scaleFactor + spacing);
|
||||||
|
|
||||||
// Draw background rectangle color (if required)
|
// Draw background rectangle color (if required)
|
||||||
if (colBack.a > 0) DrawRectangleRec((Rectangle) { position.x + textOffsetX, position.y + textOffsetY - backRecPadding, increaseX, fontSize + 2 * backRecPadding }, colBack);
|
if (colBack.a > 0) DrawRectangleRec((Rectangle) { position.x + textOffsetX, position.y + textOffsetY - backRecPadding, increaseX, fontSize + 2*backRecPadding }, colBack);
|
||||||
|
|
||||||
if ((codepoint != ' ') && (codepoint != '\t'))
|
if ((codepoint != ' ') && (codepoint != '\t'))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -210,7 +210,7 @@ int main(void)
|
|||||||
|
|
||||||
// Draw random emojis in the background
|
// Draw random emojis in the background
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
for (int i = 0; i < SIZEOF(emoji); ++i)
|
for (int i = 0; i < SIZEOF(emoji); i++)
|
||||||
{
|
{
|
||||||
const char *txt = &emojiCodepoints[emoji[i].index];
|
const char *txt = &emojiCodepoints[emoji[i].index];
|
||||||
Rectangle emojiRect = { position.x, position.y, (float)fontEmoji.baseSize, (float)fontEmoji.baseSize };
|
Rectangle emojiRect = { position.x, position.y, (float)fontEmoji.baseSize, (float)fontEmoji.baseSize };
|
||||||
@ -316,7 +316,7 @@ static void RandomizeEmoji(void)
|
|||||||
hovered = selected = -1;
|
hovered = selected = -1;
|
||||||
int start = GetRandomValue(45, 360);
|
int start = GetRandomValue(45, 360);
|
||||||
|
|
||||||
for (int i = 0; i < SIZEOF(emoji); ++i)
|
for (int i = 0; i < SIZEOF(emoji); i++)
|
||||||
{
|
{
|
||||||
// 0-179 emoji codepoints (from emoji char array) each 4bytes + null char
|
// 0-179 emoji codepoints (from emoji char array) each 4bytes + null char
|
||||||
emoji[i].index = GetRandomValue(0, 179)*5;
|
emoji[i].index = GetRandomValue(0, 179)*5;
|
||||||
|
|||||||
@ -70,27 +70,32 @@ int main(void)
|
|||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
if (IsKeyPressed(KEY_LEFT))
|
||||||
if (IsKeyPressed(KEY_LEFT)) {
|
{
|
||||||
hAlign = hAlign - 1;
|
hAlign = hAlign - 1;
|
||||||
if (hAlign < 0) hAlign = 0;
|
if (hAlign < 0) hAlign = 0;
|
||||||
}
|
}
|
||||||
if (IsKeyPressed(KEY_RIGHT)) {
|
|
||||||
|
if (IsKeyPressed(KEY_RIGHT))
|
||||||
|
{
|
||||||
hAlign = hAlign + 1;
|
hAlign = hAlign + 1;
|
||||||
if (hAlign > 2) hAlign = 2;
|
if (hAlign > 2) hAlign = 2;
|
||||||
}
|
}
|
||||||
if (IsKeyPressed(KEY_UP)) {
|
|
||||||
|
if (IsKeyPressed(KEY_UP))
|
||||||
|
{
|
||||||
vAlign = vAlign - 1;
|
vAlign = vAlign - 1;
|
||||||
if (vAlign < 0) vAlign = 0;
|
if (vAlign < 0) vAlign = 0;
|
||||||
}
|
}
|
||||||
if (IsKeyPressed(KEY_DOWN)) {
|
|
||||||
|
if (IsKeyPressed(KEY_DOWN))
|
||||||
|
{
|
||||||
vAlign = vAlign + 1;
|
vAlign = vAlign + 1;
|
||||||
if (vAlign > 2) vAlign = 2;
|
if (vAlign > 2) vAlign = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// One word per second
|
// One word per second
|
||||||
wordIndex = (int)GetTime() % wordCount;
|
wordIndex = (int)GetTime()%wordCount;
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
@ -108,9 +113,9 @@ int main(void)
|
|||||||
Vector2 textSize = MeasureTextEx(font, words[wordIndex], fontSize, fontSize*.1f);
|
Vector2 textSize = MeasureTextEx(font, words[wordIndex], fontSize, fontSize*.1f);
|
||||||
|
|
||||||
// Calculate the top-left text position based on the rectangle and alignment
|
// Calculate the top-left text position based on the rectangle and alignment
|
||||||
Vector2 textPos = (Vector2) {
|
Vector2 textPos = (Vector2){
|
||||||
textContainerRect.x + Lerp(0.0f, textContainerRect.width - textSize.x, ((float)hAlign) * 0.5f),
|
textContainerRect.x + Lerp(0.0f, textContainerRect.width - textSize.x, ((float)hAlign)*0.5f),
|
||||||
textContainerRect.y + Lerp(0.0f, textContainerRect.height - textSize.y, ((float)vAlign) * 0.5f)
|
textContainerRect.y + Lerp(0.0f, textContainerRect.height - textSize.y, ((float)vAlign)*0.5f)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Draw the text
|
// Draw the text
|
||||||
|
|||||||
@ -179,7 +179,7 @@ int main(void)
|
|||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
// NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
|
// NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
|
||||||
DrawTextureRec(target.texture, (Rectangle) { 0, 0, (float)target.texture.width, (float)-target.texture.height }, (Vector2) { 0, 0 }, WHITE);
|
DrawTextureRec(target.texture, (Rectangle){ 0, 0, (float)target.texture.width, (float)-target.texture.height }, (Vector2) { 0, 0 }, WHITE);
|
||||||
|
|
||||||
// Draw drawing circle for reference
|
// Draw drawing circle for reference
|
||||||
if (mousePos.y > 50)
|
if (mousePos.y > 50)
|
||||||
|
|||||||
@ -56,7 +56,7 @@ int main(void)
|
|||||||
// Add a positive/negative offset to spin right/left at different speeds
|
// Add a positive/negative offset to spin right/left at different speeds
|
||||||
if (IsKeyDown(KEY_LEFT) || IsKeyDown(KEY_A)) rotationSpeed -= speedChange;
|
if (IsKeyDown(KEY_LEFT) || IsKeyDown(KEY_A)) rotationSpeed -= speedChange;
|
||||||
if (IsKeyDown(KEY_RIGHT) || IsKeyDown(KEY_D)) rotationSpeed += speedChange;
|
if (IsKeyDown(KEY_RIGHT) || IsKeyDown(KEY_D)) rotationSpeed += speedChange;
|
||||||
|
|
||||||
rotation += rotationSpeed*GetFrameTime();
|
rotation += rotationSpeed*GetFrameTime();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@ -100,7 +100,7 @@ int main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check to see which color was clicked and set it as the active color
|
// Check to see which color was clicked and set it as the active color
|
||||||
for (int i = 0; i < MAX_COLORS; ++i)
|
for (int i = 0; i < MAX_COLORS; i++)
|
||||||
{
|
{
|
||||||
if (CheckCollisionPointRec(mouse, colorRec[i]))
|
if (CheckCollisionPointRec(mouse, colorRec[i]))
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user