From 63ff5690ff7a1feb80c4ea2467004c2caa38a08b Mon Sep 17 00:00:00 2001 From: penguindark <57967770+penguindark@users.noreply.github.com> Date: Wed, 1 Sep 2021 08:21:27 +0200 Subject: [PATCH] sokol.sapp,gg: add support for drag & drop events (#11359) --- vlib/gg/gg.c.v | 4 ++++ vlib/gg/gg.v | 4 ++++ vlib/sokol/sapp/enums.v | 1 + vlib/sokol/sapp/sapp.c.v | 12 ++++++++++++ vlib/sokol/sapp/sapp_funcs.c.v | 6 ++++++ 5 files changed, 27 insertions(+) diff --git a/vlib/gg/gg.c.v b/vlib/gg/gg.c.v index f6956e60ef..c9869d676f 100644 --- a/vlib/gg/gg.c.v +++ b/vlib/gg/gg.c.v @@ -194,6 +194,10 @@ pub fn new_context(cfg Config) &Context { high_dpi: true fullscreen: cfg.fullscreen __v_native_render: cfg.native_rendering + // drag&drop + enable_dragndrop: cfg.enable_dragndrop + max_dropped_files: cfg.max_dropped_files + max_dropped_file_path_length: cfg.max_dropped_file_path_length } g.window = window return g diff --git a/vlib/gg/gg.v b/vlib/gg/gg.v index d1dbaa4507..d6c466370b 100644 --- a/vlib/gg/gg.v +++ b/vlib/gg/gg.v @@ -77,6 +77,10 @@ pub: font_bytes_mono []byte font_bytes_italic []byte native_rendering bool // Cocoa on macOS/iOS, GDI+ on Windows + // drag&drop + enable_dragndrop bool // enable file dropping (drag'n'drop), default is false + max_dropped_files int = 1 // max number of dropped files to process (default: 1) + max_dropped_file_path_length int = 2048 // max length in bytes of a dropped UTF-8 file path (default: 2048) } pub struct PenConfig { diff --git a/vlib/sokol/sapp/enums.v b/vlib/sokol/sapp/enums.v index 8e0efd796d..14f2d4c6f3 100644 --- a/vlib/sokol/sapp/enums.v +++ b/vlib/sokol/sapp/enums.v @@ -23,6 +23,7 @@ pub enum EventType { update_cursor quit_requested clipboard_pasted + files_droped num } diff --git a/vlib/sokol/sapp/sapp.c.v b/vlib/sokol/sapp/sapp.c.v index 28b756248f..fc8d00f286 100644 --- a/vlib/sokol/sapp/sapp.c.v +++ b/vlib/sokol/sapp/sapp.c.v @@ -245,3 +245,15 @@ pub fn toggle_fullscreen() { pub fn is_fullscreen() bool { return C.sapp_is_fullscreen() } + +[inline] +pub fn get_num_dropped_files() int { + return C.sapp_get_num_dropped_files() +} + +[inline] +pub fn get_dropped_file_path(index int) string { + unsafe { + return cstring_to_vstring(C.sapp_get_dropped_file_path(index)) + } +} diff --git a/vlib/sokol/sapp/sapp_funcs.c.v b/vlib/sokol/sapp/sapp_funcs.c.v index 3d177bda33..85531a6135 100644 --- a/vlib/sokol/sapp/sapp_funcs.c.v +++ b/vlib/sokol/sapp/sapp_funcs.c.v @@ -109,3 +109,9 @@ fn C.sapp_toggle_fullscreen() // Check if full screen rendering fn C.sapp_is_fullscreen() bool + +// Get number of droped files +fn C.sapp_get_num_dropped_files() int + +// Get the file path of the droped file +fn C.sapp_get_dropped_file_path(int) &byte