Move drop file event to Window, handle mouse capture automatically

This commit is contained in:
Joshua Granick
2016-03-01 10:45:33 -08:00
parent 85ec75fd59
commit 78bf85b766
22 changed files with 218 additions and 189 deletions

View File

@@ -116,6 +116,13 @@ class FlashWindow {
}
public function setMaximized (value:Bool):Bool {
return false;
}
public function setMinimized (value:Bool):Bool {
return false;

View File

@@ -687,6 +687,13 @@ class HTML5Window {
}
public function setMaximized (value:Bool):Bool {
return false;
}
public function setMinimized (value:Bool):Bool {
return false;

View File

@@ -42,10 +42,10 @@ class NativeApplication {
private var applicationEventInfo = new ApplicationEventInfo (UPDATE);
private var currentTouches = new Map<Int, Touch> ();
private var dropEventInfo = new DropEventInfo ();
private var gamepadEventInfo = new GamepadEventInfo ();
private var joystickEventInfo = new JoystickEventInfo ();
private var keyEventInfo = new KeyEventInfo ();
private var dropEventInfo = new DropEventInfo();
private var mouseEventInfo = new MouseEventInfo ();
private var renderEventInfo = new RenderEventInfo (RENDER);
private var sensorEventInfo = new SensorEventInfo ();
@@ -88,10 +88,10 @@ class NativeApplication {
#if !macro
lime_application_event_manager_register (handleApplicationEvent, applicationEventInfo);
lime_drop_event_manager_register (handleDropEvent, dropEventInfo);
lime_gamepad_event_manager_register (handleGamepadEvent, gamepadEventInfo);
lime_joystick_event_manager_register (handleJoystickEvent, joystickEventInfo);
lime_key_event_manager_register (handleKeyEvent, keyEventInfo);
lime_drop_event_manager_register(handleDropEvent, dropEventInfo);
lime_mouse_event_manager_register (handleMouseEvent, mouseEventInfo);
lime_render_event_manager_register (handleRenderEvent, renderEventInfo);
lime_text_event_manager_register (handleTextEvent, textEventInfo);
@@ -177,6 +177,17 @@ class NativeApplication {
}
private function handleDropEvent ():Void {
for (window in parent.windows) {
window.onDropFile.dispatch (dropEventInfo.file);
}
}
private function handleGamepadEvent ():Void {
switch (gamepadEventInfo.type) {
@@ -250,10 +261,6 @@ class NativeApplication {
}
private function handleDropEvent():Void
{
parent.onDropFile.dispatch(dropEventInfo.file);
}
private function handleKeyEvent ():Void {
@@ -624,10 +631,10 @@ class NativeApplication {
@:cffi private static function lime_application_quit (handle:Dynamic):Int;
@:cffi private static function lime_application_set_frame_rate (handle:Dynamic, value:Float):Void;
@:cffi private static function lime_application_update (handle:Dynamic):Bool;
@:cffi private static function lime_drop_event_manager_register (callback:Dynamic, eventObject:Dynamic):Void;
@:cffi private static function lime_gamepad_event_manager_register (callback:Dynamic, eventObject:Dynamic):Void;
@:cffi private static function lime_joystick_event_manager_register (callback:Dynamic, eventObject:Dynamic):Void;
@:cffi private static function lime_key_event_manager_register (callback:Dynamic, eventObject:Dynamic):Void;
@:cffi private static function lime_drop_event_manager_register (callback:Dynamic, eventObject:Dynamic):Void;
@:cffi private static function lime_mouse_event_manager_register (callback:Dynamic, eventObject:Dynamic):Void;
@:cffi private static function lime_render_event_manager_register (callback:Dynamic, eventObject:Dynamic):Void;
@:cffi private static function lime_sensor_event_manager_register (callback:Dynamic, eventObject:Dynamic):Void;
@@ -639,27 +646,6 @@ class NativeApplication {
}
@:enum private abstract DropEventType(Int)
{
var DROP_FILE = 0;
}
private class DropEventInfo
{
public var type:DropEventType;
public var file:String;
public function new (type:DropEventType = null, file:String = null)
{
this.file = file;
this.type = type;
}
public function clone():DropEventInfo
{
return new DropEventInfo(type, file);
}
}
private class ApplicationEventInfo {
@@ -694,6 +680,38 @@ private class ApplicationEventInfo {
}
private class DropEventInfo {
public var file:String;
public var type:DropEventType;
public function new (type:DropEventType = null, file:String = null) {
this.type = type;
this.file = file;
}
public function clone ():DropEventInfo {
return new DropEventInfo (type, file);
}
}
@:enum private abstract DropEventType(Int) {
var DROP_FILE = 0;
}
private class GamepadEventInfo {

View File

@@ -17,7 +17,6 @@ class NativeMouse {
private static var __cursor:MouseCursor;
private static var __hidden:Bool;
private static var __lock:Bool;
private static var __captureMode:Bool;
public static function hide ():Void {
@@ -64,22 +63,7 @@ class NativeMouse {
// Get & Set Methods
public static function get_captureMode():Bool
{
return __captureMode;
}
public static function set_captureMode(v:Bool):Bool
{
if (v != __captureMode)
{
#if !macro
lime_mouse_set_capture_mode(v);
#end
__captureMode = v;
}
return v;
}
public static function get_cursor ():MouseCursor {
@@ -165,7 +149,6 @@ class NativeMouse {
@:cffi private static function lime_mouse_set_lock (lock:Bool):Void;
@:cffi private static function lime_mouse_show ():Void;
@:cffi private static function lime_mouse_warp (x:Int, y:Int, window:Dynamic):Void;
@:cffi private static function lime_mouse_set_capture_mode (capture:Bool):Void;
#end

View File

@@ -249,16 +249,20 @@ class NativeWindow {
}
public function setMaximized (value:Bool):Bool
{
if (handle != null)
{
#if !macro
return lime_window_set_maximized(handle, value);
#end
}
return value;
}
public function setMaximized (value:Bool):Bool {
if (handle != null) {
#if !macro
return lime_window_set_maximized (handle, value);
#end
}
return value;
}
public function setMinimized (value:Bool):Bool {
@@ -327,9 +331,9 @@ class NativeWindow {
@:cffi private static function lime_window_set_enable_text_events (handle:Dynamic, enabled:Bool):Void;
@:cffi private static function lime_window_set_fullscreen (handle:Dynamic, fullscreen:Bool):Bool;
@:cffi private static function lime_window_set_icon (handle:Dynamic, buffer:Dynamic):Void;
@:cffi private static function lime_window_set_maximized (handle:Dynamic, maximized:Bool):Bool;
@:cffi private static function lime_window_set_minimized (handle:Dynamic, minimized:Bool):Bool;
@:cffi private static function lime_window_set_resizable (handle:Dynamic, resizable:Bool):Bool;
@:cffi private static function lime_window_set_maximized (handle:Dynamic, maximized:Bool):Bool;
@:cffi private static function lime_window_set_title (handle:Dynamic, title:String):Dynamic;
#end

View File

@@ -34,7 +34,6 @@ class Application extends Module {
* Update events are dispatched each frame (usually just before rendering)
*/
public var onUpdate = new Event<Int->Void> ();
public var onDropFile = new Event<String->Void> ();
public var renderer (get, null):Renderer;
public var renderers (default, null):Array<Renderer>;
@@ -174,6 +173,7 @@ class Application extends Module {
window.onClose.add (onWindowClose.bind (window));
window.onCreate.add (onWindowCreate.bind (window));
window.onDeactivate.add (onWindowDeactivate.bind (window));
window.onDropFile.add (onWindowDropFile.bind (window));
window.onEnter.add (onWindowEnter.bind (window));
window.onFocusIn.add (onWindowFocusIn.bind (window));
window.onFocusOut.add (onWindowFocusOut.bind (window));
@@ -591,6 +591,17 @@ class Application extends Module {
}
public override function onWindowDropFile (window:Window, file:String):Void {
for (module in modules) {
module.onWindowDropFile (window, file);
}
}
public override function onWindowEnter (window:Window):Void {
for (module in modules) {

View File

@@ -58,11 +58,6 @@ class Event<T> {
}
public function stopPropagation():Void
{
interrupt = true;
}
#if macro
private static function build () {
@@ -236,17 +231,17 @@ class Event<T> {
//
//$ethis.remove (listeners[i]);
//
// } else {
//} else {
//
//i++;
//
// }
//}
//
// }
//}
//
// }
//}
//
// }
//}
public function has (listener:T):Bool {

View File

@@ -282,6 +282,13 @@ interface IModule {
public function onWindowDeactivate (window:Window):Void;
/**
* Called when a window drop file event is fired
* @param window The window dispatching the event
*/
public function onWindowDropFile (window:Window, file:String):Void;
/**
* Called when a window enter event is fired
* @param window The window dispatching the event

View File

@@ -299,6 +299,13 @@ class Module implements IModule {
public function onWindowDeactivate (window:Window):Void { }
/**
* Called when a window drop file event is fired
* @param window The window dispatching the event
*/
public function onWindowDropFile (window:Window, file:String):Void { }
/**
* Called when a window enter event is fired
* @param window The window dispatching the event

View File

@@ -6,17 +6,6 @@ class Mouse {
public static var cursor (get, set):MouseCursor;
public static var lock (get, set):Bool;
public static var captureMode(get, set):Bool;
private static function set_captureMode(v:Bool):Bool
{
return MouseBackend.set_captureMode(v);
}
private static function get_captureMode():Bool
{
return MouseBackend.get_captureMode();
}
public static function hide ():Void {

View File

@@ -28,12 +28,13 @@ class Window {
public var fullscreen (get, set):Bool;
public var height (get, set):Int;
public var id (default, null):Int;
public var minimized (get, set):Bool;
public var maximized (get, set):Bool;
public var minimized (get, set):Bool;
public var onActivate = new Event<Void->Void> ();
public var onClose = new Event<Void->Void> ();
public var onCreate = new Event<Void->Void> ();
public var onDeactivate = new Event<Void->Void> ();
public var onDropFile = new Event<String->Void> ();
public var onEnter = new Event<Void->Void> ();
public var onFocusIn = new Event<Void->Void> ();
public var onFocusOut = new Event<Void->Void> ();
@@ -65,12 +66,9 @@ class Window {
@:noCompletion private var __borderless:Bool;
@:noCompletion private var __fullscreen:Bool;
@:noCompletion private var __height:Int;
@:noCompletion private var __minimized:Bool;
<<<<<<< HEAD
@:noCompletion private var __resizable:Bool;
=======
@:noCompletion private var __maximized:Bool;
>>>>>>> 7cee614... Drag&Drop support; SDL_CaptureMode support; Maximize window support; Interrupting Event spread;
@:noCompletion private var __minimized:Bool;
@:noCompletion private var __resizable:Bool;
@:noCompletion private var __scale:Float;
@:noCompletion private var __title:String;
@:noCompletion private var __width:Int;
@@ -383,16 +381,20 @@ class Window {
}
private inline function get_maximized():Bool
{
return __maximized;
}
@:noCompletion private inline function get_maximized ():Bool {
return __maximized;
}
@:noCompletion private inline function set_maximized (value:Bool):Bool {
__minimized = false;
return __maximized = backend.setMaximized (value);
}
private inline function set_maximized(value:Bool):Bool
{
__minimized = false;
return __maximized = backend.setMaximized(value);
}
@:noCompletion private inline function get_minimized ():Bool {
@@ -400,9 +402,10 @@ class Window {
}
@:noCompletion private function set_minimized (value:Bool):Bool {
__maximized = false;
__maximized = false;
return __minimized = backend.setMinimized (value);
}

View File

@@ -3,7 +3,6 @@
<set name="PLATFORM" value="android-9" if="android" />
<set name="PLATFORM" value="android-14" if="HXCPP_X86" />
<set name="HXCPP_CPP11" value="1" />
<!--<set name="HXCPP_WINXP_COMPAT" value="1" />-->
<include name="${HXCPP}/build-tool/BuildCommon.xml" />
@@ -228,10 +227,10 @@
<file name="src/system/CFFIPointer.cpp" />
<file name="src/system/JNI.cpp" if="android" />
<file name="src/system/SensorEvent.cpp" />
<file name="src/ui/DropEvent.cpp" />
<file name="src/ui/GamepadEvent.cpp" />
<file name="src/ui/JoystickEvent.cpp" />
<file name="src/ui/KeyEvent.cpp" />
<file name="src/ui/DropEvent.cpp" />
<file name="src/ui/MouseEvent.cpp" />
<file name="src/ui/TextEvent.cpp" />
<file name="src/ui/TouchEvent.cpp" />

View File

@@ -3,7 +3,6 @@
#include <hx/CFFI.h>
#include <stdint.h>
namespace lime {

View File

@@ -18,7 +18,6 @@ namespace lime {
static void Hide ();
static void SetCursor (MouseCursor cursor);
static void SetLock (bool lock);
static void SetCaptureMode(bool capture);
static void Show ();
static void Warp (int x, int y, Window* window);

View File

@@ -35,9 +35,9 @@ namespace lime {
virtual void SetEnableTextEvents (bool enable) = 0;
virtual bool SetFullscreen (bool fullscreen) = 0;
virtual void SetIcon (ImageBuffer *imageBuffer) = 0;
virtual bool SetMaximized (bool minimized) = 0;
virtual bool SetMinimized (bool minimized) = 0;
virtual bool SetResizable (bool resizable) = 0;
virtual bool SetMaximized (bool minimized) = 0;
virtual const char* SetTitle (const char* title) = 0;
Application* currentApplication;

View File

@@ -28,13 +28,13 @@
#include <system/System.h>
#include <text/Font.h>
#include <text/TextLayout.h>
#include <ui/DropEvent.h>
#include <ui/FileDialog.h>
#include <ui/Gamepad.h>
#include <ui/GamepadEvent.h>
#include <ui/Joystick.h>
#include <ui/JoystickEvent.h>
#include <ui/KeyEvent.h>
#include <ui/DropEvent.h>
#include <ui/Mouse.h>
#include <ui/MouseCursor.h>
#include <ui/MouseEvent.h>
@@ -265,6 +265,14 @@ namespace lime {
}
void lime_drop_event_manager_register (value callback, value eventObject) {
DropEvent::callback = new AutoGCRoot (callback);
DropEvent::eventObject = new AutoGCRoot (eventObject);
}
value lime_file_dialog_open_directory (HxString filter, HxString defaultPath) {
#ifdef LIME_NFD
@@ -910,11 +918,6 @@ namespace lime {
}
void lime_drop_event_manager_register(value callback, value eventObject)
{
DropEvent::callback = new AutoGCRoot(callback);
DropEvent::eventObject = new AutoGCRoot(eventObject);
}
value lime_lzma_decode (value buffer) {
@@ -969,10 +972,6 @@ namespace lime {
}
void lime_mouse_set_capture_mode(bool capture)
{
Mouse::SetCaptureMode(capture);
}
void lime_mouse_set_lock (bool lock) {
@@ -1415,18 +1414,21 @@ namespace lime {
}
bool lime_window_set_minimized (value window, bool fullscreen) {
bool lime_window_set_maximized (value window, bool maximized) {
Window* targetWindow = (Window*)val_data (window);
return targetWindow->SetMinimized (fullscreen);
Window* targetWindow = (Window*)val_data(window);
return targetWindow->SetMaximized (maximized);
}
bool lime_window_set_minimized (value window, bool minimized) {
Window* targetWindow = (Window*)val_data (window);
return targetWindow->SetMinimized (minimized);
}
bool lime_window_set_maximized (value window, bool fullscreen)
{
Window* targetWindow = (Window*)val_data(window);
return targetWindow->SetMaximized(fullscreen);
}
bool lime_window_set_resizable (value window, bool resizable) {
@@ -1460,6 +1462,7 @@ namespace lime {
DEFINE_PRIME1 (lime_cffi_set_finalizer);
DEFINE_PRIME0 (lime_clipboard_get_text);
DEFINE_PRIME1v (lime_clipboard_set_text);
DEFINE_PRIME2v (lime_drop_event_manager_register);
DEFINE_PRIME2 (lime_file_dialog_open_directory);
DEFINE_PRIME2 (lime_file_dialog_open_file);
DEFINE_PRIME2 (lime_file_dialog_open_files);
@@ -1510,14 +1513,12 @@ namespace lime {
DEFINE_PRIME2 (lime_jpeg_decode_bytes);
DEFINE_PRIME2 (lime_jpeg_decode_file);
DEFINE_PRIME2v (lime_key_event_manager_register);
DEFINE_PRIME2v (lime_drop_event_manager_register);
DEFINE_PRIME1 (lime_lzma_decode);
DEFINE_PRIME1 (lime_lzma_encode);
DEFINE_PRIME2v (lime_mouse_event_manager_register);
DEFINE_PRIME0v (lime_mouse_hide);
DEFINE_PRIME1v (lime_mouse_set_cursor);
DEFINE_PRIME1v (lime_mouse_set_lock);
DEFINE_PRIME1v (lime_mouse_set_capture_mode);
DEFINE_PRIME0v (lime_mouse_show);
DEFINE_PRIME3v (lime_mouse_warp);
DEFINE_PRIME1v (lime_neko_execute);
@@ -1565,9 +1566,9 @@ namespace lime {
DEFINE_PRIME2v (lime_window_set_enable_text_events);
DEFINE_PRIME2 (lime_window_set_fullscreen);
DEFINE_PRIME2v (lime_window_set_icon);
DEFINE_PRIME2 (lime_window_set_maximized);
DEFINE_PRIME2 (lime_window_set_minimized);
DEFINE_PRIME2 (lime_window_set_resizable);
DEFINE_PRIME2 (lime_window_set_maximized);
DEFINE_PRIME2 (lime_window_set_title);

View File

@@ -29,8 +29,6 @@ namespace lime {
}
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
SDL_LogSetPriority (SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN);
currentApplication = this;
@@ -48,10 +46,10 @@ namespace lime {
nextUpdate = 0;
ApplicationEvent applicationEvent;
DropEvent dropEvent;
GamepadEvent gamepadEvent;
JoystickEvent joystickEvent;
KeyEvent keyEvent;
DropEvent dropEvent;
MouseEvent mouseEvent;
RenderEvent renderEvent;
SensorEvent sensorEvent;
@@ -59,6 +57,7 @@ namespace lime {
TouchEvent touchEvent;
WindowEvent windowEvent;
SDL_EventState (SDL_DROPFILE, SDL_ENABLE);
SDLJoystick::Init ();
#ifdef HX_MACOS
@@ -151,6 +150,11 @@ namespace lime {
ProcessGamepadEvent (event);
break;
case SDL_DROPFILE:
ProcessDropEvent (event);
break;
case SDL_FINGERMOTION:
case SDL_FINGERDOWN:
case SDL_FINGERUP:
@@ -204,11 +208,6 @@ namespace lime {
ProcessTextEvent (event);
break;
case SDL_DROPFILE:
ProcessDropEvent (event);
break;
case SDL_WINDOWEVENT:
switch (event->window.event) {
@@ -265,6 +264,21 @@ namespace lime {
}
void SDLApplication::ProcessDropEvent (SDL_Event* event) {
if (DropEvent::callback) {
dropEvent.type = DROP_FILE;
dropEvent.file = event->drop.file;
DropEvent::Dispatch (&dropEvent);
SDL_free (dropEvent.file);
}
}
void SDLApplication::ProcessGamepadEvent (SDL_Event* event) {
if (GamepadEvent::callback) {
@@ -462,17 +476,6 @@ namespace lime {
}
void SDLApplication::ProcessDropEvent (SDL_Event* event)
{
if (DropEvent::callback)
{
dropEvent.type = DROP_FILE;
dropEvent.file = event->drop.file;
DropEvent::Dispatch(&dropEvent);
SDL_free(dropEvent.file);
}
}
void SDLApplication::ProcessKeyEvent (SDL_Event* event) {
@@ -513,6 +516,8 @@ namespace lime {
case SDL_MOUSEBUTTONDOWN:
SDL_CaptureMouse (SDL_TRUE);
mouseEvent.type = MOUSE_DOWN;
mouseEvent.button = event->button.button - 1;
mouseEvent.x = event->button.x;
@@ -521,6 +526,8 @@ namespace lime {
case SDL_MOUSEBUTTONUP:
SDL_CaptureMouse (SDL_FALSE);
mouseEvent.type = MOUSE_UP;
mouseEvent.button = event->button.button - 1;
mouseEvent.x = event->button.x;

View File

@@ -7,11 +7,11 @@
#include <app/ApplicationEvent.h>
#include <graphics/RenderEvent.h>
#include <system/SensorEvent.h>
#include <ui/DropEvent.h>
#include <ui/GamepadEvent.h>
#include <ui/JoystickEvent.h>
#include <ui/KeyEvent.h>
#include <ui/MouseEvent.h>
#include <ui/DropEvent.h>
#include <ui/TextEvent.h>
#include <ui/TouchEvent.h>
#include <ui/WindowEvent.h>
@@ -39,10 +39,10 @@ namespace lime {
private:
void HandleEvent (SDL_Event* event);
void ProcessDropEvent (SDL_Event* event);
void ProcessGamepadEvent (SDL_Event* event);
void ProcessJoystickEvent (SDL_Event* event);
void ProcessKeyEvent (SDL_Event* event);
void ProcessDropEvent (SDL_Event* event);
void ProcessMouseEvent (SDL_Event* event);
void ProcessSensorEvent (SDL_Event* event);
void ProcessTextEvent (SDL_Event* event);
@@ -59,10 +59,10 @@ namespace lime {
ApplicationEvent applicationEvent;
Uint32 currentUpdate;
double framePeriod;
DropEvent dropEvent;
GamepadEvent gamepadEvent;
JoystickEvent joystickEvent;
KeyEvent keyEvent;
DropEvent dropEvent;
Uint32 lastUpdate;
MouseEvent mouseEvent;
double nextUpdate;

View File

@@ -177,17 +177,6 @@ namespace lime {
}
void Mouse::SetCaptureMode(bool capture)
{
if (capture)
{
SDL_CaptureMouse(SDL_TRUE);
}
else
{
SDL_CaptureMouse(SDL_FALSE);
}
}
void Mouse::Show () {

View File

@@ -324,20 +324,23 @@ namespace lime {
}
bool SDLWindow::SetMaximized (bool maximized)
{
if (maximized)
{
SDL_MaximizeWindow(sdlWindow);
}
else
{
SDL_RestoreWindow(sdlWindow);
}
bool SDLWindow::SetMaximized (bool maximized) {
if (maximized) {
SDL_MaximizeWindow (sdlWindow);
} else {
SDL_RestoreWindow (sdlWindow);
}
return maximized;
}
return maximized;
}
bool SDLWindow::SetMinimized (bool minimized) {

View File

@@ -33,9 +33,9 @@ namespace lime {
virtual void SetEnableTextEvents (bool enabled);
virtual bool SetFullscreen (bool fullscreen);
virtual void SetIcon (ImageBuffer *imageBuffer);
virtual bool SetMaximized (bool maximized);
virtual bool SetMinimized (bool minimized);
virtual bool SetResizable (bool resizable);
virtual bool SetMaximized (bool minimized);
virtual const char* SetTitle (const char* title);
SDL_Window* sdlWindow;

View File

@@ -15,27 +15,28 @@ namespace lime {
DropEvent::DropEvent () {
type = DROP_FILE;
file = 0;
type = DROP_FILE;
}
void DropEvent::Dispatch (DropEvent* event) {
if (DropEvent::callback)
{
if (DropEvent::callback) {
if (!init)
{
id_file = val_id("file");
id_type = val_id("type");
init = true;
}
if (!init) {
value object = (DropEvent::eventObject ? DropEvent::eventObject->get() : alloc_empty_object());
id_file = val_id ("file");
id_type = val_id ("type");
init = true;
alloc_field(object, id_file, alloc_string(event->file));
alloc_field(object, id_type, alloc_int (event->type));
}
value object = (DropEvent::eventObject ? DropEvent::eventObject->get () : alloc_empty_object ());
alloc_field (object, id_file, alloc_string (event->file));
alloc_field (object, id_type, alloc_int (event->type));
val_call0 (DropEvent::callback->get ());