You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
3.2 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib [core] example - Windows drop files
  4. *
  5. * NOTE: This example only works on platforms that support drag & drop (Windows, Linux, OSX, Html5?)
  6. *
  7. * Example originally created with raylib 1.3, last time updated with raylib 4.2
  8. *
  9. * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
  10. * BSD-like license that allows static linking with closed source software
  11. *
  12. * Copyright (c) 2015-2023 Ramon Santamaria (@raysan5)
  13. *
  14. ********************************************************************************************/
  15. #include "raylib.h"
  16. //------------------------------------------------------------------------------------
  17. // Program main entry point
  18. //------------------------------------------------------------------------------------
  19. int main(void)
  20. {
  21. // Initialization
  22. //--------------------------------------------------------------------------------------
  23. const int screenWidth = 800;
  24. const int screenHeight = 450;
  25. InitWindow(screenWidth, screenHeight, "raylib [core] example - drop files");
  26. FilePathList droppedFiles = { 0 };
  27. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  28. //--------------------------------------------------------------------------------------
  29. // Main game loop
  30. while (!WindowShouldClose()) // Detect window close button or ESC key
  31. {
  32. // Update
  33. //----------------------------------------------------------------------------------
  34. if (IsFileDropped())
  35. {
  36. // Is some files have been previously loaded, unload them
  37. if (droppedFiles.count > 0) UnloadDroppedFiles(droppedFiles);
  38. // Load new dropped files
  39. droppedFiles = LoadDroppedFiles();
  40. }
  41. //----------------------------------------------------------------------------------
  42. // Draw
  43. //----------------------------------------------------------------------------------
  44. BeginDrawing();
  45. ClearBackground(RAYWHITE);
  46. if (droppedFiles.count == 0) DrawText("Drop your files to this window!", 100, 40, 20, DARKGRAY);
  47. else
  48. {
  49. DrawText("Dropped files:", 100, 40, 20, DARKGRAY);
  50. for (int i = 0; i < droppedFiles.count; i++)
  51. {
  52. if (i%2 == 0) DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.5f));
  53. else DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.3f));
  54. DrawText(droppedFiles.paths[i], 120, 100 + 40*i, 10, GRAY);
  55. }
  56. DrawText("Drop new files...", 100, 110 + 40*droppedFiles.count, 20, DARKGRAY);
  57. }
  58. EndDrawing();
  59. //----------------------------------------------------------------------------------
  60. }
  61. // De-Initialization
  62. //--------------------------------------------------------------------------------------
  63. UnloadDroppedFiles(droppedFiles); // Unload files memory
  64. CloseWindow(); // Close window and OpenGL context
  65. //--------------------------------------------------------------------------------------
  66. return 0;
  67. }