Drag&Drop support; SDL_CaptureMode support; Maximize window support;

This commit is contained in:
Yanrishatum
2015-10-18 00:15:05 +03:00
committed by Joshua Granick
parent 3a7d8b80e5
commit 85ec75fd59
18 changed files with 256 additions and 10 deletions

View File

@@ -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" />

View 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

View File

@@ -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);

View File

@@ -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;

View File

@@ -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);

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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);

View File

@@ -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) {

View File

@@ -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;

View 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 ());
}
}
}