mirror of
https://github.com/fltk/fltk.git
synced 2026-05-30 13:05:35 +08:00
Add Android Touch events.
"test/button" works now. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11353 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
@@ -24,6 +24,7 @@ LOCAL_MODULE := native-activity
|
|||||||
LOCAL_C_INCLUDES := $(TOP_PATH)
|
LOCAL_C_INCLUDES := $(TOP_PATH)
|
||||||
|
|
||||||
LOCAL_SRC_FILES := \
|
LOCAL_SRC_FILES := \
|
||||||
|
test/button.cxx \
|
||||||
src/flstring.c \
|
src/flstring.c \
|
||||||
src/scandir.c \
|
src/scandir.c \
|
||||||
src/numericsort.c \
|
src/numericsort.c \
|
||||||
@@ -190,8 +191,7 @@ LOCAL_SRC_FILES := \
|
|||||||
src/drivers/PicoAndroid/Fl_PicoAndroid_Window_Driver.cxx \
|
src/drivers/PicoAndroid/Fl_PicoAndroid_Window_Driver.cxx \
|
||||||
src/drivers/PicoAndroid/Fl_PicoAndroid_Graphics_Driver.cxx \
|
src/drivers/PicoAndroid/Fl_PicoAndroid_Graphics_Driver.cxx \
|
||||||
src/drivers/PicoAndroid/Fl_PicoAndroid_Copy_Surface.cxx \
|
src/drivers/PicoAndroid/Fl_PicoAndroid_Copy_Surface.cxx \
|
||||||
src/drivers/PicoAndroid/Fl_PicoAndroid_Image_Surface.cxx \
|
src/drivers/PicoAndroid/Fl_PicoAndroid_Image_Surface.cxx
|
||||||
test/hello.cxx
|
|
||||||
|
|
||||||
#Android/jni/main.c
|
#Android/jni/main.c
|
||||||
|
|
||||||
|
|||||||
@@ -233,15 +233,15 @@ static const char *font_data[128] = {
|
|||||||
/* */0, /*!*/"\31\34\100\35\36", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
/* */0, /*!*/"\31\34\100\35\36", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, /*B*/"\43\54\45\15\11\41\52\43\13", 0, 0, /*E*/"\51\11\15\55\100\13\43", 0, 0,
|
||||||
/*H*/"\11\15\100\61\65\100\13\63", 0, 0, 0, 0, 0, 0, 0,
|
/*H*/"\11\15\100\61\65\100\13\63", 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, /*T*/"\11\71\100\41\45", 0, 0, /*W*/"\01\15\33\55\61",
|
0, 0, 0, 0, /*T*/"\11\71\100\41\45", 0, 0, /*W*/"\01\15\33\55\61",
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
/*X*/"\15\51\100\11\55", 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
|
||||||
0, 0, 0, 0, /*d*/"\64\55\55\25\14\13\22\52\63\100\61\65", /*e*/"\55\25\14\13\22\52\63\64\14", 0, 0,
|
0, 0, 0, 0, /*d*/"\64\55\55\25\14\13\22\52\63\100\61\65", /*e*/"\55\25\14\13\22\52\63\64\14", 0, 0,
|
||||||
0, 0, 0, 0, /*l*/"\31\34\45", 0, 0, /*o*/"\55\25\14\13\22\52\63\64\55",
|
0, /*i*/"\31\32\100\23\33\35\100\25\45", 0, 0, /*l*/"\31\34\45", 0, /*n*/"\15\12\100\13\22\42\53\55", /*o*/"\55\25\14\13\22\52\63\64\55",
|
||||||
0, 0, /*r*/"\25\22\100\23\32\52", /*s*/"\62\22\13\64\55\15", /*t*/"\41\44\55\65\100\22\62", 0, 0, 0,
|
/*p*/"\17\12\42\53\54\45\15", 0, /*r*/"\25\22\100\23\32\52", /*s*/"\62\22\13\64\55\15", /*t*/"\41\44\55\65\100\22\62", 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
/*x*/"\15\52\100\12\55", 0, 0, 0, 0, 0, 0, 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,8 @@
|
|||||||
#include "../../config_lib.h"
|
#include "../../config_lib.h"
|
||||||
#include "Fl_PicoAndroid_Screen_Driver.H"
|
#include "Fl_PicoAndroid_Screen_Driver.H"
|
||||||
|
|
||||||
|
#include <android/window.h>
|
||||||
|
|
||||||
#include <FL/x.H>
|
#include <FL/x.H>
|
||||||
#include <FL/Fl.H>
|
#include <FL/Fl.H>
|
||||||
#include <FL/Fl_Window.H>
|
#include <FL/Fl_Window.H>
|
||||||
@@ -36,6 +38,7 @@
|
|||||||
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "native-activity", __VA_ARGS__))
|
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "native-activity", __VA_ARGS__))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Fl_PicoAndroid_Screen_Driver::initDisplay()
|
void Fl_PicoAndroid_Screen_Driver::initDisplay()
|
||||||
{
|
{
|
||||||
// initialize OpenGL ES and EGL
|
// initialize OpenGL ES and EGL
|
||||||
@@ -159,6 +162,9 @@ void Fl_PicoAndroid_Screen_Driver::handleAppCmd(struct android_app* app, int32_t
|
|||||||
case APP_CMD_INIT_WINDOW:
|
case APP_CMD_INIT_WINDOW:
|
||||||
// The window is being shown, get it ready.
|
// The window is being shown, get it ready.
|
||||||
if (pApp->window != NULL) {
|
if (pApp->window != NULL) {
|
||||||
|
// the flag below allow for easy development and should be removed when
|
||||||
|
// distributing a final app
|
||||||
|
ANativeActivity_setWindowFlags(pApp->activity, AWINDOW_FLAG_KEEP_SCREEN_ON, 0);
|
||||||
initDisplay();
|
initDisplay();
|
||||||
drawFrame();
|
drawFrame();
|
||||||
}
|
}
|
||||||
@@ -202,15 +208,145 @@ int32_t Fl_PicoAndroid_Screen_Driver::handleInputEventCB(struct android_app* app
|
|||||||
int32_t Fl_PicoAndroid_Screen_Driver::handleInputEvent(struct android_app* app, AInputEvent* event)
|
int32_t Fl_PicoAndroid_Screen_Driver::handleInputEvent(struct android_app* app, AInputEvent* event)
|
||||||
{
|
{
|
||||||
if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) {
|
if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) {
|
||||||
|
// fl_lock_function();
|
||||||
int x = AMotionEvent_getX(event, 0);
|
int x = AMotionEvent_getX(event, 0);
|
||||||
int y = AMotionEvent_getY(event, 0);
|
int y = AMotionEvent_getY(event, 0);
|
||||||
|
int action = AKeyEvent_getAction(event);
|
||||||
|
Fl_Window *window = Fl::first_window();
|
||||||
|
switch (action) {
|
||||||
|
case AMOTION_EVENT_ACTION_DOWN:
|
||||||
|
Fl::e_is_click = 1;
|
||||||
|
Fl::e_x = Fl::e_x_root = x/3;
|
||||||
|
Fl::e_y = (y-100)/3;
|
||||||
|
if (!window) break;
|
||||||
|
Fl::e_keysym = FL_Button+FL_LEFT_MOUSE;
|
||||||
|
Fl::e_state = FL_BUTTON1;
|
||||||
|
Fl::handle(FL_PUSH, window);
|
||||||
|
break;
|
||||||
|
case AMOTION_EVENT_ACTION_MOVE:
|
||||||
|
Fl::e_is_click = 1;
|
||||||
|
Fl::e_x = Fl::e_x_root = x/3;
|
||||||
|
Fl::e_y = (y-100)/3;
|
||||||
|
if (!window) break;
|
||||||
|
Fl::e_keysym = FL_Button+FL_LEFT_MOUSE;
|
||||||
|
Fl::e_state = FL_BUTTON1;
|
||||||
|
Fl::handle(FL_DRAG, window);
|
||||||
|
break;
|
||||||
|
case AMOTION_EVENT_ACTION_UP:
|
||||||
|
case AMOTION_EVENT_ACTION_CANCEL:
|
||||||
|
Fl::e_is_click = 1;
|
||||||
|
Fl::e_x = Fl::e_x_root = x/3;
|
||||||
|
Fl::e_y = (y-100)/3;
|
||||||
|
if (!window) break;
|
||||||
|
Fl::e_keysym = FL_Button+FL_LEFT_MOUSE;
|
||||||
|
Fl::e_state = 0;
|
||||||
|
Fl::handle(FL_RELEASE, window);
|
||||||
|
break;
|
||||||
|
// case AMOTION_EVENT_ACTION_HOVER_MOVE:
|
||||||
|
// Fl::e_is_click = 1;
|
||||||
|
// Fl::e_x = Fl::e_x_root = x/3;
|
||||||
|
// Fl::e_y = (y-100)/3;
|
||||||
|
// if (!window) break;
|
||||||
|
// Fl::e_keysym = 0;
|
||||||
|
// Fl::e_state = 0;
|
||||||
|
// Fl::handle(FL_MOVE, window);
|
||||||
|
// break;
|
||||||
|
}
|
||||||
|
// AMOTION_EVENT_ACTION_MASK
|
||||||
LOGI("Motion at %d, %d", x, y);
|
LOGI("Motion at %d, %d", x, y);
|
||||||
|
// fl_unlock_function();
|
||||||
Fl_X::first->w->redraw();
|
Fl_X::first->w->redraw();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
static int keysym[] = { 0, FL_Button+1, FL_Button+3, FL_Button+2 };
|
||||||
|
static int px, py;
|
||||||
|
static char suppressed = 0;
|
||||||
|
|
||||||
|
fl_lock_function();
|
||||||
|
|
||||||
|
Fl_Window *window = (Fl_Window*)[(FLWindow*)[theEvent window] getFl_Window];
|
||||||
|
if ( !window->shown() ) {
|
||||||
|
fl_unlock_function();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Fl_Window *first = Fl::first_window();
|
||||||
|
if (first != window && !(first->modal() || first->non_modal())) Fl::first_window(window);
|
||||||
|
NSPoint pos = [theEvent locationInWindow];
|
||||||
|
pos.y = window->h() - pos.y;
|
||||||
|
NSInteger btn = [theEvent buttonNumber] + 1;
|
||||||
|
NSUInteger mods = [theEvent modifierFlags];
|
||||||
|
int sendEvent = 0;
|
||||||
|
|
||||||
|
NSEventType etype = [theEvent type];
|
||||||
|
if (etype == NSLeftMouseDown || etype == NSRightMouseDown || etype == NSOtherMouseDown) {
|
||||||
|
if (btn == 1) Fl::e_state |= FL_BUTTON1;
|
||||||
|
else if (btn == 3) Fl::e_state |= FL_BUTTON2;
|
||||||
|
else if (btn == 2) Fl::e_state |= FL_BUTTON3;
|
||||||
|
}
|
||||||
|
else if (etype == NSLeftMouseUp || etype == NSRightMouseUp || etype == NSOtherMouseUp) {
|
||||||
|
if (btn == 1) Fl::e_state &= ~FL_BUTTON1;
|
||||||
|
else if (btn == 3) Fl::e_state &= ~FL_BUTTON2;
|
||||||
|
else if (btn == 2) Fl::e_state &= ~FL_BUTTON3;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ( etype ) {
|
||||||
|
case NSLeftMouseDown:
|
||||||
|
case NSRightMouseDown:
|
||||||
|
case NSOtherMouseDown:
|
||||||
|
suppressed = 0;
|
||||||
|
sendEvent = FL_PUSH;
|
||||||
|
Fl::e_is_click = 1;
|
||||||
|
px = (int)pos.x; py = (int)pos.y;
|
||||||
|
if ([theEvent clickCount] > 1)
|
||||||
|
Fl::e_clicks++;
|
||||||
|
else
|
||||||
|
Fl::e_clicks = 0;
|
||||||
|
// fall through
|
||||||
|
case NSLeftMouseUp:
|
||||||
|
case NSRightMouseUp:
|
||||||
|
case NSOtherMouseUp:
|
||||||
|
if (suppressed) {
|
||||||
|
suppressed = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ( !window ) break;
|
||||||
|
if ( !sendEvent ) {
|
||||||
|
sendEvent = FL_RELEASE;
|
||||||
|
}
|
||||||
|
Fl::e_keysym = keysym[ btn ];
|
||||||
|
// fall through
|
||||||
|
case NSMouseMoved:
|
||||||
|
suppressed = 0;
|
||||||
|
if ( !sendEvent ) {
|
||||||
|
sendEvent = FL_MOVE;
|
||||||
|
}
|
||||||
|
// fall through
|
||||||
|
case NSLeftMouseDragged:
|
||||||
|
case NSRightMouseDragged:
|
||||||
|
case NSOtherMouseDragged: {
|
||||||
|
if (suppressed) break;
|
||||||
|
if ( !sendEvent ) {
|
||||||
|
sendEvent = FL_MOVE; // Fl::handle will convert into FL_DRAG
|
||||||
|
if (fabs(pos.x-px)>5 || fabs(pos.y-py)>5)
|
||||||
|
Fl::e_is_click = 0;
|
||||||
|
}
|
||||||
|
mods_to_e_state( mods );
|
||||||
|
update_e_xy_and_e_xy_root([theEvent window]);
|
||||||
|
Fl::handle( sendEvent, window );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
fl_unlock_function();
|
||||||
|
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
|
|
||||||
extern int main(int argc, const char **argv);
|
extern int main(int argc, const char **argv);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user