1 | /******************************************************************************************* |
2 | * |
3 | * raylib [core] example - Windows drop files |
4 | * |
5 | * This example only works on platforms that support drag & drop (Windows, Linux, OSX, Html5?) |
6 | * |
7 | * This example has been created using raylib 1.3 (www.raylib.com) |
8 | * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) |
9 | * |
10 | * Copyright (c) 2015 Ramon Santamaria (@raysan5) |
11 | * |
12 | ********************************************************************************************/ |
13 | |
14 | #include "raylib.h" |
15 | |
16 | int main(void) |
17 | { |
18 | // Initialization |
19 | //-------------------------------------------------------------------------------------- |
20 | const int screenWidth = 800; |
21 | const int screenHeight = 450; |
22 | |
23 | InitWindow(screenWidth, screenHeight, "raylib [core] example - drop files" ); |
24 | |
25 | int count = 0; |
26 | char **droppedFiles = { 0 }; |
27 | |
28 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second |
29 | //-------------------------------------------------------------------------------------- |
30 | |
31 | // Main game loop |
32 | while (!WindowShouldClose()) // Detect window close button or ESC key |
33 | { |
34 | // Update |
35 | //---------------------------------------------------------------------------------- |
36 | if (IsFileDropped()) |
37 | { |
38 | droppedFiles = GetDroppedFiles(&count); |
39 | } |
40 | //---------------------------------------------------------------------------------- |
41 | |
42 | // Draw |
43 | //---------------------------------------------------------------------------------- |
44 | BeginDrawing(); |
45 | |
46 | ClearBackground(RAYWHITE); |
47 | |
48 | if (count == 0) DrawText("Drop your files to this window!" , 100, 40, 20, DARKGRAY); |
49 | else |
50 | { |
51 | DrawText("Dropped files:" , 100, 40, 20, DARKGRAY); |
52 | |
53 | for (int i = 0; i < count; i++) |
54 | { |
55 | if (i%2 == 0) DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.5f)); |
56 | else DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.3f)); |
57 | |
58 | DrawText(droppedFiles[i], 120, 100 + 40*i, 10, GRAY); |
59 | } |
60 | |
61 | DrawText("Drop new files..." , 100, 110 + 40*count, 20, DARKGRAY); |
62 | } |
63 | |
64 | EndDrawing(); |
65 | //---------------------------------------------------------------------------------- |
66 | } |
67 | |
68 | // De-Initialization |
69 | //-------------------------------------------------------------------------------------- |
70 | ClearDroppedFiles(); // Clear internal buffers |
71 | |
72 | CloseWindow(); // Close window and OpenGL context |
73 | //-------------------------------------------------------------------------------------- |
74 | |
75 | return 0; |
76 | } |