Initial support for text input/edit events
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
#include <ui/Mouse.h>
|
||||
#include <ui/MouseCursor.h>
|
||||
#include <ui/MouseEvent.h>
|
||||
#include <ui/TextEvent.h>
|
||||
#include <ui/TouchEvent.h>
|
||||
#include <ui/Window.h>
|
||||
#include <ui/WindowEvent.h>
|
||||
@@ -763,6 +764,15 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_text_event_manager_register (value callback, value eventObject) {
|
||||
|
||||
TextEvent::callback = new AutoGCRoot (callback);
|
||||
TextEvent::eventObject = new AutoGCRoot (eventObject);
|
||||
return alloc_null ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void lime_text_layout_destroy (value textHandle) {
|
||||
|
||||
#ifdef LIME_HARFBUZZ
|
||||
@@ -885,6 +895,14 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_window_get_enable_text_events (value window) {
|
||||
|
||||
Window* targetWindow = (Window*)(intptr_t)val_float (window);
|
||||
return alloc_bool (targetWindow->GetEnableTextEvents ());
|
||||
|
||||
}
|
||||
|
||||
|
||||
value lime_window_get_height (value window) {
|
||||
|
||||
Window* targetWindow = (Window*)(intptr_t)val_float (window);
|
||||
@@ -935,6 +953,15 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_window_set_enable_text_events (value window, value enabled) {
|
||||
|
||||
Window* targetWindow = (Window*)(intptr_t)val_float (window);
|
||||
targetWindow->SetEnableTextEvents (val_bool (enabled));
|
||||
return alloc_null ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
value lime_window_set_fullscreen (value window, value fullscreen) {
|
||||
|
||||
Window* targetWindow = (Window*)(intptr_t)val_float (window);
|
||||
@@ -1018,6 +1045,7 @@ namespace lime {
|
||||
DEFINE_PRIM (lime_render_event_manager_register, 2);
|
||||
DEFINE_PRIM (lime_system_get_directory, 3);
|
||||
DEFINE_PRIM (lime_system_get_timer, 0);
|
||||
DEFINE_PRIM (lime_text_event_manager_register, 2);
|
||||
DEFINE_PRIM (lime_text_layout_create, 3);
|
||||
DEFINE_PRIM (lime_text_layout_position, 5);
|
||||
DEFINE_PRIM (lime_text_layout_set_direction, 2);
|
||||
@@ -1028,12 +1056,14 @@ namespace lime {
|
||||
DEFINE_PRIM (lime_window_close, 1);
|
||||
DEFINE_PRIM (lime_window_create, 5);
|
||||
DEFINE_PRIM (lime_window_event_manager_register, 2);
|
||||
DEFINE_PRIM (lime_window_get_enable_text_events, 1);
|
||||
DEFINE_PRIM (lime_window_get_height, 1);
|
||||
DEFINE_PRIM (lime_window_get_width, 1);
|
||||
DEFINE_PRIM (lime_window_get_x, 1);
|
||||
DEFINE_PRIM (lime_window_get_y, 1);
|
||||
DEFINE_PRIM (lime_window_move, 3);
|
||||
DEFINE_PRIM (lime_window_resize, 3);
|
||||
DEFINE_PRIM (lime_window_set_enable_text_events, 2);
|
||||
DEFINE_PRIM (lime_window_set_fullscreen, 2);
|
||||
DEFINE_PRIM (lime_window_set_icon, 2);
|
||||
DEFINE_PRIM (lime_window_set_minimized, 2);
|
||||
|
||||
@@ -41,6 +41,7 @@ namespace lime {
|
||||
KeyEvent keyEvent;
|
||||
MouseEvent mouseEvent;
|
||||
RenderEvent renderEvent;
|
||||
TextEvent textEvent;
|
||||
TouchEvent touchEvent;
|
||||
UpdateEvent updateEvent;
|
||||
WindowEvent windowEvent;
|
||||
@@ -145,6 +146,12 @@ namespace lime {
|
||||
ProcessMouseEvent (event);
|
||||
break;
|
||||
|
||||
case SDL_TEXTINPUT:
|
||||
case SDL_TEXTEDITING:
|
||||
|
||||
ProcessTextEvent (event);
|
||||
break;
|
||||
|
||||
case SDL_WINDOWEVENT:
|
||||
|
||||
switch (event->window.event) {
|
||||
@@ -337,6 +344,35 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
void SDLApplication::ProcessTextEvent (SDL_Event* event) {
|
||||
|
||||
if (TextEvent::callback) {
|
||||
|
||||
switch (event->type) {
|
||||
|
||||
case SDL_TEXTINPUT:
|
||||
|
||||
textEvent.type = TEXT_INPUT;
|
||||
break;
|
||||
|
||||
case SDL_TEXTEDITING:
|
||||
|
||||
textEvent.type = TEXT_EDIT;
|
||||
textEvent.start = event->edit.start;
|
||||
textEvent.length = event->edit.length;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
strcpy (textEvent.text, event->text.text);
|
||||
|
||||
TextEvent::Dispatch (&textEvent);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SDLApplication::ProcessTouchEvent (SDL_Event* event) {
|
||||
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <ui/GamepadEvent.h>
|
||||
#include <ui/KeyEvent.h>
|
||||
#include <ui/MouseEvent.h>
|
||||
#include <ui/TextEvent.h>
|
||||
#include <ui/TouchEvent.h>
|
||||
#include <ui/WindowEvent.h>
|
||||
#include "SDLWindow.h"
|
||||
@@ -37,6 +38,7 @@ namespace lime {
|
||||
void ProcessGamepadEvent (SDL_Event* event);
|
||||
void ProcessKeyEvent (SDL_Event* event);
|
||||
void ProcessMouseEvent (SDL_Event* event);
|
||||
void ProcessTextEvent (SDL_Event* event);
|
||||
void ProcessTouchEvent (SDL_Event* event);
|
||||
void ProcessWindowEvent (SDL_Event* event);
|
||||
|
||||
@@ -54,6 +56,7 @@ namespace lime {
|
||||
MouseEvent mouseEvent;
|
||||
double nextUpdate;
|
||||
RenderEvent renderEvent;
|
||||
TextEvent textEvent;
|
||||
TouchEvent touchEvent;
|
||||
UpdateEvent updateEvent;
|
||||
WindowEvent windowEvent;
|
||||
|
||||
@@ -115,6 +115,13 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
bool SDLWindow::GetEnableTextEvents () {
|
||||
|
||||
return SDL_IsTextInputActive ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
int SDLWindow::GetHeight () {
|
||||
|
||||
int width;
|
||||
@@ -177,6 +184,21 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
void SDLWindow::SetEnableTextEvents (bool enabled) {
|
||||
|
||||
if (enabled) {
|
||||
|
||||
SDL_StartTextInput ();
|
||||
|
||||
} else {
|
||||
|
||||
SDL_StopTextInput ();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool SDLWindow::SetFullscreen (bool fullscreen) {
|
||||
|
||||
if (fullscreen) {
|
||||
|
||||
@@ -18,12 +18,14 @@ namespace lime {
|
||||
~SDLWindow ();
|
||||
|
||||
virtual void Close ();
|
||||
virtual bool GetEnableTextEvents ();
|
||||
virtual int GetHeight ();
|
||||
virtual int GetWidth ();
|
||||
virtual int GetX ();
|
||||
virtual int GetY ();
|
||||
virtual void Move (int x, int y);
|
||||
virtual void Resize (int width, int height);
|
||||
virtual void SetEnableTextEvents (bool enabled);
|
||||
virtual bool SetFullscreen (bool fullscreen);
|
||||
virtual void SetIcon (ImageBuffer *imageBuffer);
|
||||
virtual bool SetMinimized (bool minimized);
|
||||
|
||||
59
project/src/ui/TextEvent.cpp
Normal file
59
project/src/ui/TextEvent.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#include <hx/CFFI.h>
|
||||
#include <ui/TextEvent.h>
|
||||
|
||||
|
||||
namespace lime {
|
||||
|
||||
|
||||
AutoGCRoot* TextEvent::callback = 0;
|
||||
AutoGCRoot* TextEvent::eventObject = 0;
|
||||
|
||||
static int id_length;
|
||||
static int id_start;
|
||||
static int id_text;
|
||||
static int id_type;
|
||||
static bool init = false;
|
||||
|
||||
|
||||
TextEvent::TextEvent () {
|
||||
|
||||
length = 0;
|
||||
start = 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TextEvent::Dispatch (TextEvent* event) {
|
||||
|
||||
if (TextEvent::callback) {
|
||||
|
||||
if (!init) {
|
||||
|
||||
id_length = val_id ("length");
|
||||
id_start = val_id ("start");
|
||||
id_text = val_id ("text");
|
||||
id_type = val_id ("type");
|
||||
init = true;
|
||||
|
||||
}
|
||||
|
||||
value object = (TextEvent::eventObject ? TextEvent::eventObject->get () : alloc_empty_object ());
|
||||
|
||||
if (event->type != TEXT_INPUT) {
|
||||
|
||||
alloc_field (object, id_length, alloc_int (event->length));
|
||||
alloc_field (object, id_start, alloc_int (event->start));
|
||||
|
||||
}
|
||||
|
||||
alloc_field (object, id_text, alloc_string (event->text));
|
||||
alloc_field (object, id_type, alloc_int (event->type));
|
||||
|
||||
val_call0 (TextEvent::callback->get ());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user