Skip to content

Commit 3e729ec

Browse files
drop files alt example
1 parent 0703645 commit 3e729ec

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

examples/core/core_drop_files2.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
droppedFiles = []
29+
30+
def get_dropped_files():
31+
count_pointer = pyray.ffi.new("int *", 0)
32+
droppedFiles_pointer = pyray.get_dropped_files(count_pointer)
33+
d = []
34+
for i in range(0, count_pointer[0]):
35+
d.append(pyray.ffi.string(droppedFiles_pointer[i]).decode('utf-8'))
36+
return d
37+
38+
39+
while not pyray.window_should_close():
40+
41+
if pyray.is_file_dropped():
42+
droppedFiles = get_dropped_files()
43+
44+
pyray.begin_drawing()
45+
46+
pyray.clear_background(RAYWHITE)
47+
48+
if len(droppedFiles) == 0:
49+
pyray.draw_text("Drop your files to this window!", 100, 40, 20, DARKGRAY)
50+
else:
51+
pyray.draw_text("Dropped files:", 100, 40, 20, DARKGRAY);
52+
53+
for i in range(0, len(droppedFiles)):
54+
if i % 2 == 0:
55+
pyray.draw_rectangle(0, 85 + 40*i, screenWidth, 40, pyray.fade(LIGHTGRAY, 0.5))
56+
else:
57+
pyray.draw_rectangle(0, 85 + 40*i, screenWidth, 40, pyray.fade(LIGHTGRAY, 0.3))
58+
pyray.draw_text(droppedFiles[i], 120, 100 + 40*i, 10, GRAY)
59+
60+
pyray.draw_text("Drop new files...", 100, 110 + 40*len(droppedFiles), 20, DARKGRAY);
61+
pyray.end_drawing()
62+
63+
# De-Initialization
64+
pyray.clear_dropped_files()
65+
pyray.close_window() # Close window and OpenGL context

0 commit comments

Comments
 (0)