core_drop_files.c 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #include "raylib.h"
  14. int main(void)
  15. {
  16. // Initialization
  17. //--------------------------------------------------------------------------------------
  18. const int screenWidth = 800;
  19. const int screenHeight = 450;
  20. InitWindow(screenWidth, screenHeight, "raylib [core] example - drop files");
  21. FilePathList droppedFiles = { 0 };
  22. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  23. //--------------------------------------------------------------------------------------
  24. // Main game loop
  25. while (!WindowShouldClose()) // Detect window close button or ESC key
  26. {
  27. // Update
  28. //----------------------------------------------------------------------------------
  29. if (IsFileDropped())
  30. {
  31. // Is some files have been previously loaded, unload them
  32. if (droppedFiles.count > 0) UnloadDroppedFiles(droppedFiles);
  33. // Load new dropped files
  34. droppedFiles = LoadDroppedFiles();
  35. }
  36. //----------------------------------------------------------------------------------
  37. // Draw
  38. //----------------------------------------------------------------------------------
  39. BeginDrawing();
  40. ClearBackground(RAYWHITE);
  41. if (droppedFiles.count == 0) DrawText("Drop your files to this window!", 100, 40, 20, DARKGRAY);
  42. else
  43. {
  44. DrawText("Dropped files:", 100, 40, 20, DARKGRAY);
  45. for (int i = 0; i < droppedFiles.count; i++)
  46. {
  47. if (i%2 == 0) DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.5f));
  48. else DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.3f));
  49. DrawText(droppedFiles.paths[i], 120, 100 + 40*i, 10, GRAY);
  50. }
  51. DrawText("Drop new files...", 100, 110 + 40*droppedFiles.count, 20, DARKGRAY);
  52. }
  53. EndDrawing();
  54. //----------------------------------------------------------------------------------
  55. }
  56. // De-Initialization
  57. //--------------------------------------------------------------------------------------
  58. UnloadDroppedFiles(droppedFiles); // Unload files memory
  59. CloseWindow(); // Close window and OpenGL context
  60. //--------------------------------------------------------------------------------------
  61. return 0;
  62. }