Skip to content

Commit 2c5e7f8

Browse files
committed
REVIEWED: example: textures_clipboard_image
1 parent 8596c94 commit 2c5e7f8

1 file changed

Lines changed: 21 additions & 36 deletions

File tree

examples/textures/textures_clipboard_image.c

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,25 @@
44
*
55
* Example complexity rating: [★☆☆☆] 1/4
66
*
7-
* Example originally created with raylib 5.5, last time updated with raylib 5.6
7+
* Example originally created with raylib 6.0, last time updated with raylib 6.0
88
*
99
* Example contributed by Maicon Santana (@maiconpintoabreu) and reviewed by Ramon Santamaria (@raysan5)
1010
*
1111
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
1212
* BSD-like license that allows static linking with closed source software
1313
*
14-
* Copyright (c) 2026-2026 Maicon Santana (@maiconpintoabreu)
14+
* Copyright (c) 2026 Maicon Santana (@maiconpintoabreu)
1515
*
1616
********************************************************************************************/
1717

18-
#define RCORE_PLATFORM_RGFW
1918
#include "raylib.h"
2019

21-
#define MAX_IAMGE_COLLECTION_AMOUNT 1000
20+
#define MAX_TEXTURE_COLLECTION 20
2221

23-
typedef struct ImageCollection {
22+
typedef struct TextureCollection {
2423
Texture2D texture;
2524
Vector2 position;
26-
} ImageCollection;
25+
} TextureCollection;
2726

2827
//------------------------------------------------------------------------------------
2928
// Program main entry point
@@ -37,7 +36,7 @@ int main(void)
3736

3837
InitWindow(screenWidth, screenHeight, "raylib [textures] example - clipboard_image");
3938

40-
ImageCollection collection[MAX_IAMGE_COLLECTION_AMOUNT] = {0};
39+
TextureCollection collection[MAX_TEXTURE_COLLECTION] = { 0 };
4140
int currentCollectionIndex = 0;
4241

4342
SetTargetFPS(60);
@@ -48,55 +47,45 @@ int main(void)
4847
{
4948
// Update
5049
//----------------------------------------------------------------------------------
51-
// TODO: Update variables / Implement example logic at this point
52-
//----------------------------------------------------------------------------------
53-
54-
if(IsKeyPressed(KEY_R))
50+
if (IsKeyPressed(KEY_R)) // Reset image collection
5551
{
52+
// Unload textures to avoid memory leaks
53+
for (int i = 0; i < MAX_TEXTURE_COLLECTION; i++) UnloadTexture(collection[i].texture);
54+
5655
currentCollectionIndex = 0;
57-
58-
// Unload Texture to avoid Memory leak
59-
for (int i=0;i<MAX_IAMGE_COLLECTION_AMOUNT;i++)
60-
{
61-
if (IsTextureValid(collection[i].texture))
62-
{
63-
UnloadTexture(collection[i].texture);
64-
}
65-
}
6656
}
6757

68-
if (currentCollectionIndex < MAX_IAMGE_COLLECTION_AMOUNT && IsKeyDown(KEY_LEFT_CONTROL) && IsKeyPressed(KEY_V))
58+
if (IsKeyDown(KEY_LEFT_CONTROL) && IsKeyPressed(KEY_V) &&
59+
(currentCollectionIndex < MAX_TEXTURE_COLLECTION))
6960
{
7061
Image image = GetClipboardImage();
62+
7163
if (IsImageValid(image))
7264
{
7365
collection[currentCollectionIndex].texture = LoadTextureFromImage(image);
7466
collection[currentCollectionIndex].position = GetMousePosition();
7567
currentCollectionIndex++;
7668
UnloadImage(image);
7769
}
78-
else
79-
{
80-
TraceLog(LOG_INFO, "Nothing to paste here");
81-
}
70+
else TraceLog(LOG_INFO, "IMAGE: Could not retrieve image from clipboard");
8271
}
72+
//----------------------------------------------------------------------------------
8373

8474
// Draw
8575
//----------------------------------------------------------------------------------
8676
BeginDrawing();
8777

8878
ClearBackground(RAYWHITE);
89-
for (int i=0;i<currentCollectionIndex;i++)
79+
80+
for (int i = 0; i < currentCollectionIndex; i++)
9081
{
9182
if (IsTextureValid(collection[i].texture))
9283
{
93-
DrawTexturePro(
94-
collection[i].texture,
84+
DrawTexturePro(collection[i].texture,
9585
(Rectangle){0,0,collection[i].texture.width, collection[i].texture.height},
9686
(Rectangle){collection[i].position.x,collection[i].position.y,collection[i].texture.width, collection[i].texture.height},
9787
(Vector2){collection[i].texture.width*0.5f, collection[i].texture.height*0.5f},
98-
0.0f,
99-
WHITE);
88+
0.0f, WHITE);
10089
}
10190
}
10291

@@ -109,13 +98,9 @@ int main(void)
10998

11099
// De-Initialization
111100
//--------------------------------------------------------------------------------------
112-
113-
for (int i=0;i<MAX_IAMGE_COLLECTION_AMOUNT;i++)
101+
for (int i = 0; i < MAX_TEXTURE_COLLECTION;i ++)
114102
{
115-
if (IsTextureValid(collection[i].texture))
116-
{
117-
UnloadTexture(collection[i].texture);
118-
}
103+
UnloadTexture(collection[i].texture);
119104
}
120105

121106
CloseWindow(); // Close window and OpenGL context

0 commit comments

Comments
 (0)