Skip to content

Commit 08cafd5

Browse files
drop files example
1 parent 17f033c commit 08cafd5

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

examples/core/core_drop_files.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
import pyray
14+
from raylib.colors import (
15+
RAYWHITE,
16+
DARKGRAY,
17+
LIGHTGRAY,
18+
GRAY
19+
)
20+
21+
screenWidth = 800
22+
screenHeight = 450
23+
24+
pyray.init_window(screenWidth, screenHeight,
25+
'raylib [core] example - drop files')
26+
pyray.set_target_fps(60) # Set our game to run at 60 frames-per-second
27+
28+
29+
count_pointer = pyray.ffi.new("int *", 0)
30+
count = 0
31+
32+
while not pyray.window_should_close():
33+
34+
if pyray.is_file_dropped():
35+
droppedFiles_pointer = pyray.get_dropped_files(count_pointer)
36+
count = count_pointer[0]
37+
droppedFiles = pyray.ffi.unpack(droppedFiles_pointer, count)
38+
39+
pyray.begin_drawing()
40+
41+
pyray.clear_background(RAYWHITE)
42+
43+
if count == 0:
44+
pyray.draw_text("Drop your files to this window!", 100, 40, 20, DARKGRAY)
45+
else:
46+
pyray.draw_text("Dropped files:", 100, 40, 20, DARKGRAY);
47+
48+
for i in range(0, count):
49+
if i % 2 == 0:
50+
pyray.draw_rectangle(0, 85 + 40*i, screenWidth, 40, pyray.fade(LIGHTGRAY, 0.5))
51+
else:
52+
pyray.draw_rectangle(0, 85 + 40*i, screenWidth, 40, pyray.fade(LIGHTGRAY, 0.3))
53+
filename = pyray.ffi.string(droppedFiles[i]).decode('utf-8')
54+
pyray.draw_text(filename, 120, 100 + 40*i, 10, GRAY)
55+
56+
pyray.draw_text("Drop new files...", 100, 110 + 40*count, 20, DARKGRAY);
57+
pyray.end_drawing()
58+
59+
# De-Initialization
60+
pyray.clear_dropped_files()
61+
pyray.close_window() # Close window and OpenGL context

0 commit comments

Comments
 (0)