core_drop_files.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. -------------------------------------------------------------------------------------------
  2. --
  3. -- raylib [core] example - Windows drop files
  4. --
  5. -- This example only works on platforms that support drag & drop (Windows, Linux, OSX)
  6. --
  7. -- This example has been created using raylib 1.6 (www.raylib.com)
  8. -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  9. --
  10. -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
  11. --
  12. -------------------------------------------------------------------------------------------
  13. -- Initialization
  14. -------------------------------------------------------------------------------------------
  15. local screenWidth = 800
  16. local screenHeight = 450
  17. InitWindow(screenWidth, screenHeight, "raylib [core] example - drop files")
  18. local count = 0
  19. local droppedFiles = {}
  20. SetTargetFPS(60)
  21. -------------------------------------------------------------------------------------------
  22. -- Main game loop
  23. while not WindowShouldClose() do -- Detect window close button or ESC key
  24. -- Update
  25. ---------------------------------------------------------------------------------------
  26. if (IsFileDropped()) then
  27. droppedFiles = GetDroppedFiles()
  28. count = #droppedFiles
  29. end
  30. ---------------------------------------------------------------------------------------
  31. -- Draw
  32. ---------------------------------------------------------------------------------------
  33. BeginDrawing()
  34. ClearBackground(RAYWHITE)
  35. if (count == 0) then DrawText("Drop your files to this window!", 100, 40, 20, DARKGRAY)
  36. else
  37. DrawText("Dropped files:", 100, 40, 20, DARKGRAY)
  38. for i = 0, count-1 do
  39. if (i%2 == 0) then DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.5))
  40. else DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.3)) end
  41. DrawText(droppedFiles[i+1], 120, 100 + 40*i, 10, GRAY)
  42. end
  43. DrawText("Drop new files...", 100, 110 + 40*count, 20, DARKGRAY)
  44. end
  45. EndDrawing()
  46. ---------------------------------------------------------------------------------------
  47. end
  48. -- De-Initialization
  49. -------------------------------------------------------------------------------------------
  50. ClearDroppedFiles() -- Clear internal buffers
  51. CloseWindow() -- Close window and OpenGL context
  52. -------------------------------------------------------------------------------------------