core_drop_files.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. --char **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 droppedFiles = GetDroppedFiles(count) end
  27. ---------------------------------------------------------------------------------------
  28. -- Draw
  29. ---------------------------------------------------------------------------------------
  30. BeginDrawing()
  31. ClearBackground(RAYWHITE)
  32. if (count == 0) then DrawText("Drop your files to this window!", 100, 40, 20, DARKGRAY)
  33. else
  34. DrawText("Dropped files:", 100, 40, 20, DARKGRAY)
  35. for i = 0, count do
  36. if (i%2 == 0) then DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.5))
  37. else DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.3)) end
  38. DrawText(droppedFiles[i], 120, 100 + 40*i, 10, GRAY)
  39. end
  40. DrawText("Drop new files...", 100, 110 + 40*count, 20, DARKGRAY)
  41. end
  42. EndDrawing()
  43. ---------------------------------------------------------------------------------------
  44. end
  45. -- De-Initialization
  46. -------------------------------------------------------------------------------------------
  47. ClearDroppedFiles() -- Clear internal buffers
  48. CloseWindow() -- Close window and OpenGL context
  49. -------------------------------------------------------------------------------------------