Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions libs/sdl/sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ typedef enum {
JoystickButtonUp,
JoystickAdded,
JoystickRemoved,
DropStart = 400,
DropFile,
DropText,
DropEnd,
} event_type;

typedef enum {
Expand Down Expand Up @@ -91,6 +95,7 @@ typedef struct {
int value;
int fingerId;
int joystick;
vbyte* dropFile;
} event_data;

HL_PRIM bool HL_NAME(init_once)() {
Expand Down Expand Up @@ -329,6 +334,19 @@ HL_PRIM bool HL_NAME(event_loop)( event_data *event ) {
event->type = JoystickRemoved;
event->joystick = e.jdevice.which;
break;
case SDL_DROPBEGIN:
event->type = DropStart;
break;
case SDL_DROPFILE: case SDL_DROPTEXT: {
vbyte* bytes = hl_copy_bytes(e.drop.file, (int)strlen(e.drop.file) + 1);
SDL_free(e.drop.file);
event->type = e.type == SDL_DROPFILE ? DropFile : DropText;
event->dropFile = bytes;
break;
}
case SDL_DROPCOMPLETE:
event->type = DropEnd;
break;
default:
//printf("Unknown event type 0x%X\\n", e.type);
continue;
Expand Down Expand Up @@ -836,6 +854,14 @@ HL_PRIM char* HL_NAME(get_clipboard_text)() {
return bytes;
}

HL_PRIM void HL_NAME(set_drag_and_drop_enabled)( bool enabled ) {
SDL_EventState(SDL_DROPFILE, enabled ? SDL_ENABLE : SDL_DISABLE);
}

HL_PRIM bool HL_NAME(get_drag_and_drop_enabled)() {
return SDL_EventState(SDL_DROPFILE, SDL_QUERY);
}

HL_PRIM varray* HL_NAME(get_displays)() {
int n = SDL_GetNumVideoDisplays();
if (n < 0)
Expand Down Expand Up @@ -916,6 +942,8 @@ DEFINE_PRIM(_VOID, free_cursor, _CURSOR);
DEFINE_PRIM(_VOID, set_cursor, _CURSOR);
DEFINE_PRIM(_BOOL, set_clipboard_text, _BYTES);
DEFINE_PRIM(_BYTES, get_clipboard_text, _NO_ARG);
DEFINE_PRIM(_VOID, set_drag_and_drop_enabled, _BOOL);
DEFINE_PRIM(_BOOL, get_drag_and_drop_enabled, _NO_ARG);
DEFINE_PRIM(_ARR, get_displays, _NO_ARG);
DEFINE_PRIM(_ARR, get_display_modes, _I32);
DEFINE_PRIM(_DYN, get_current_display_mode, _I32 _BOOL);
Expand Down
5 changes: 5 additions & 0 deletions libs/sdl/sdl/Event.hx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package sdl;
public var value : Int;
public var fingerId : Int;
public var joystick : Int;
public var dropFile: hl.Bytes;
public function new() {
}
}
Expand Down Expand Up @@ -46,6 +47,10 @@ enum abstract EventType(Int) {
var JoystickButtonUp = 304;
var JoystickAdded = 305;
var JoystickRemoved = 306;
var DropStart = 400;
var DropFile = 401;
var DropText = 402;
var DropEnd = 403;
}

enum abstract WindowStateChange(Int) {
Expand Down
9 changes: 9 additions & 0 deletions libs/sdl/sdl/Sdl.hx
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,15 @@ class Sdl {
private static function _getClipboardText() : hl.Bytes {
return null;
}

@:hlNative("?sdl", "set_drag_and_drop_enabled")
public static function setDragAndDropEnabled( v : Bool ): Void {
}

@:hlNative("?sdl", "get_drag_and_drop_enabled")
public static function getDragAndDropEnabled(): Bool {
return false;
}
}

enum abstract SDLHint(String) from String to String {
Expand Down