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.

75 lines
2.7 KiB

  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. int count = 0;
  22. char **droppedFiles = { 0 };
  23. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  24. //--------------------------------------------------------------------------------------
  25. // Main game loop
  26. while (!WindowShouldClose()) // Detect window close button or ESC key
  27. {
  28. // Update
  29. //----------------------------------------------------------------------------------
  30. if (IsFileDropped())
  31. {
  32. droppedFiles = GetDroppedFiles(&count);
  33. }
  34. //----------------------------------------------------------------------------------
  35. // Draw
  36. //----------------------------------------------------------------------------------
  37. BeginDrawing();
  38. ClearBackground(RAYWHITE);
  39. if (count == 0) DrawText("Drop your files to this window!", 100, 40, 20, DARKGRAY);
  40. else
  41. {
  42. DrawText("Dropped files:", 100, 40, 20, DARKGRAY);
  43. for (int i = 0; i < count; i++)
  44. {
  45. if (i%2 == 0) DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.5f));
  46. else DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.3f));
  47. DrawText(droppedFiles[i], 120, 100 + 40*i, 10, GRAY);
  48. }
  49. DrawText("Drop new files...", 100, 110 + 40*count, 20, DARKGRAY);
  50. }
  51. EndDrawing();
  52. //----------------------------------------------------------------------------------
  53. }
  54. // De-Initialization
  55. //--------------------------------------------------------------------------------------
  56. ClearDroppedFiles(); // Clear internal buffers
  57. CloseWindow(); // Close window and OpenGL context
  58. //--------------------------------------------------------------------------------------
  59. return 0;
  60. }