Drag&Drop support; SDL_CaptureMode support; Maximize window support;
This commit is contained in:
committed by
Joshua Granick
parent
3a7d8b80e5
commit
85ec75fd59
@@ -45,6 +45,7 @@ class NativeApplication {
|
||||
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 ();
|
||||
@@ -90,6 +91,7 @@ class NativeApplication {
|
||||
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);
|
||||
@@ -248,6 +250,10 @@ class NativeApplication {
|
||||
|
||||
}
|
||||
|
||||
private function handleDropEvent():Void
|
||||
{
|
||||
parent.onDropFile.dispatch(dropEventInfo.file);
|
||||
}
|
||||
|
||||
private function handleKeyEvent ():Void {
|
||||
|
||||
@@ -621,6 +627,7 @@ class NativeApplication {
|
||||
@: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;
|
||||
@@ -632,6 +639,27 @@ 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 {
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ 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 {
|
||||
@@ -63,7 +64,22 @@ 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 {
|
||||
|
||||
@@ -149,6 +165,7 @@ 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
|
||||
|
||||
|
||||
|
||||
@@ -249,6 +249,17 @@ 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 setMinimized (value:Bool):Bool {
|
||||
|
||||
if (handle != null) {
|
||||
@@ -318,6 +329,7 @@ class NativeWindow {
|
||||
@:cffi private static function lime_window_set_icon (handle:Dynamic, buffer:Dynamic):Void;
|
||||
@: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
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ 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>;
|
||||
|
||||
@@ -57,6 +57,11 @@ class Event<T> {
|
||||
#end
|
||||
|
||||
}
|
||||
|
||||
public function stopPropagation():Void
|
||||
{
|
||||
interrupt = true;
|
||||
}
|
||||
|
||||
|
||||
#if macro
|
||||
@@ -231,17 +236,17 @@ class Event<T> {
|
||||
//
|
||||
//$ethis.remove (listeners[i]);
|
||||
//
|
||||
//} else {
|
||||
// } else {
|
||||
//
|
||||
//i++;
|
||||
//
|
||||
//}
|
||||
// }
|
||||
//
|
||||
//}
|
||||
// }
|
||||
//
|
||||
//}
|
||||
// }
|
||||
//
|
||||
//}
|
||||
// }
|
||||
|
||||
|
||||
public function has (listener:T):Bool {
|
||||
|
||||
@@ -6,6 +6,17 @@ 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 {
|
||||
|
||||
@@ -29,6 +29,7 @@ class Window {
|
||||
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 onActivate = new Event<Void->Void> ();
|
||||
public var onClose = new Event<Void->Void> ();
|
||||
public var onCreate = new Event<Void->Void> ();
|
||||
@@ -65,7 +66,11 @@ class Window {
|
||||
@: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 __scale:Float;
|
||||
@:noCompletion private var __title:String;
|
||||
@:noCompletion private var __width:Int;
|
||||
@@ -378,15 +383,26 @@ class Window {
|
||||
}
|
||||
|
||||
|
||||
private inline function get_maximized():Bool
|
||||
{
|
||||
return __maximized;
|
||||
}
|
||||
|
||||
private inline function set_maximized(value:Bool):Bool
|
||||
{
|
||||
__minimized = false;
|
||||
return __maximized = backend.setMaximized(value);
|
||||
}
|
||||
|
||||
@:noCompletion private inline function get_minimized ():Bool {
|
||||
|
||||
return __minimized;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@:noCompletion private function set_minimized (value:Bool):Bool {
|
||||
|
||||
__maximized = false;
|
||||
return __minimized = backend.setMinimized (value);
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
<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" />
|
||||
|
||||
@@ -230,6 +231,7 @@
|
||||
<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" />
|
||||
|
||||
39
project/include/ui/DropEvent.h
Normal file
39
project/include/ui/DropEvent.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef LIME_UI_DROP_EVENT_H
|
||||
#define LIME_UI_DROP_EVENT_H
|
||||
|
||||
|
||||
#include <hx/CFFI.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
namespace lime {
|
||||
|
||||
|
||||
enum DropEventType {
|
||||
|
||||
DROP_FILE
|
||||
|
||||
};
|
||||
|
||||
|
||||
class DropEvent {
|
||||
|
||||
public:
|
||||
|
||||
static AutoGCRoot* callback;
|
||||
static AutoGCRoot* eventObject;
|
||||
|
||||
DropEvent ();
|
||||
|
||||
static void Dispatch (DropEvent* event);
|
||||
|
||||
char* file;
|
||||
DropEventType type;
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -18,6 +18,7 @@ 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);
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ namespace lime {
|
||||
virtual void SetIcon (ImageBuffer *imageBuffer) = 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;
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#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>
|
||||
@@ -909,6 +910,11 @@ 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) {
|
||||
|
||||
@@ -963,7 +969,11 @@ namespace lime {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void lime_mouse_set_capture_mode(bool capture)
|
||||
{
|
||||
Mouse::SetCaptureMode(capture);
|
||||
}
|
||||
|
||||
void lime_mouse_set_lock (bool lock) {
|
||||
|
||||
Mouse::SetLock (lock);
|
||||
@@ -1412,6 +1422,11 @@ namespace lime {
|
||||
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
@@ -1495,12 +1510,14 @@ 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);
|
||||
@@ -1550,6 +1567,7 @@ namespace lime {
|
||||
DEFINE_PRIME2v (lime_window_set_icon);
|
||||
DEFINE_PRIME2 (lime_window_set_minimized);
|
||||
DEFINE_PRIME2 (lime_window_set_resizable);
|
||||
DEFINE_PRIME2 (lime_window_set_maximized);
|
||||
DEFINE_PRIME2 (lime_window_set_title);
|
||||
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@ namespace lime {
|
||||
printf ("Could not initialize SDL: %s.\n", SDL_GetError ());
|
||||
|
||||
}
|
||||
|
||||
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
|
||||
|
||||
SDL_LogSetPriority (SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN);
|
||||
|
||||
@@ -49,6 +51,7 @@ namespace lime {
|
||||
GamepadEvent gamepadEvent;
|
||||
JoystickEvent joystickEvent;
|
||||
KeyEvent keyEvent;
|
||||
DropEvent dropEvent;
|
||||
MouseEvent mouseEvent;
|
||||
RenderEvent renderEvent;
|
||||
SensorEvent sensorEvent;
|
||||
@@ -201,6 +204,11 @@ namespace lime {
|
||||
ProcessTextEvent (event);
|
||||
break;
|
||||
|
||||
case SDL_DROPFILE:
|
||||
|
||||
ProcessDropEvent (event);
|
||||
break;
|
||||
|
||||
case SDL_WINDOWEVENT:
|
||||
|
||||
switch (event->window.event) {
|
||||
@@ -454,6 +462,17 @@ 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) {
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#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>
|
||||
@@ -41,6 +42,7 @@ namespace lime {
|
||||
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);
|
||||
@@ -60,6 +62,7 @@ namespace lime {
|
||||
GamepadEvent gamepadEvent;
|
||||
JoystickEvent joystickEvent;
|
||||
KeyEvent keyEvent;
|
||||
DropEvent dropEvent;
|
||||
Uint32 lastUpdate;
|
||||
MouseEvent mouseEvent;
|
||||
double nextUpdate;
|
||||
|
||||
@@ -176,8 +176,19 @@ namespace lime {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Mouse::SetCaptureMode(bool capture)
|
||||
{
|
||||
if (capture)
|
||||
{
|
||||
SDL_CaptureMouse(SDL_TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_CaptureMouse(SDL_FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
void Mouse::Show () {
|
||||
|
||||
SDL_ShowCursor (SDL_ENABLE);
|
||||
|
||||
@@ -324,6 +324,20 @@ namespace lime {
|
||||
|
||||
}
|
||||
|
||||
bool SDLWindow::SetMaximized (bool maximized)
|
||||
{
|
||||
if (maximized)
|
||||
{
|
||||
SDL_MaximizeWindow(sdlWindow);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_RestoreWindow(sdlWindow);
|
||||
}
|
||||
|
||||
return maximized;
|
||||
}
|
||||
|
||||
bool SDLWindow::SetMinimized (bool minimized) {
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace lime {
|
||||
virtual void SetIcon (ImageBuffer *imageBuffer);
|
||||
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;
|
||||
|
||||
47
project/src/ui/DropEvent.cpp
Normal file
47
project/src/ui/DropEvent.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include <hx/CFFI.h>
|
||||
#include <ui/DropEvent.h>
|
||||
|
||||
|
||||
namespace lime {
|
||||
|
||||
|
||||
AutoGCRoot* DropEvent::callback = 0;
|
||||
AutoGCRoot* DropEvent::eventObject = 0;
|
||||
|
||||
static int id_file;
|
||||
static int id_type;
|
||||
static bool init = false;
|
||||
|
||||
|
||||
DropEvent::DropEvent () {
|
||||
|
||||
type = DROP_FILE;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void DropEvent::Dispatch (DropEvent* event) {
|
||||
|
||||
if (DropEvent::callback)
|
||||
{
|
||||
|
||||
if (!init)
|
||||
{
|
||||
id_file = val_id("file");
|
||||
id_type = val_id("type");
|
||||
init = true;
|
||||
}
|
||||
|
||||
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 ());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user