Implemented BlackBerry main (initial version)

git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@1648 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
dcnieho 2014-01-24 10:25:47 +00:00
parent 1357eb9fcf
commit 7b34b7be39
4 changed files with 344 additions and 375 deletions

View File

@ -33,6 +33,7 @@
/* BlackBerry OpenGL ES is accessed through EGL */ /* BlackBerry OpenGL ES is accessed through EGL */
#include "egl/fg_internal_egl.h" #include "egl/fg_internal_egl.h"
#include <screen/screen.h> #include <screen/screen.h>
#include <bps/event.h>
/* -- GLOBAL TYPE DEFINITIONS ---------------------------------------------- */ /* -- GLOBAL TYPE DEFINITIONS ---------------------------------------------- */
/* The structure used by display initialization in freeglut_init.c */ /* The structure used by display initialization in freeglut_init.c */
@ -49,6 +50,7 @@ struct tagSFG_PlatformContext
{ {
struct tagSFG_PlatformContextEGL egl; struct tagSFG_PlatformContextEGL egl;
screen_context_t screenContext; screen_context_t screenContext;
bps_event_t* event;
}; };

View File

@ -35,6 +35,11 @@
#define LOGI(...) ((void)slog2fa(NULL, 1337, SLOG2_INFO, __VA_ARGS__)) #define LOGI(...) ((void)slog2fa(NULL, 1337, SLOG2_INFO, __VA_ARGS__))
#define LOGW(...) ((void)slog2fa(NULL, 1337, SLOG2_WARNING, __VA_ARGS__)) #define LOGW(...) ((void)slog2fa(NULL, 1337, SLOG2_WARNING, __VA_ARGS__))
#include <sys/keycodes.h> #include <sys/keycodes.h>
#include <input/screen_helpers.h>
#include <bps/bps.h>
#include <bps/event.h>
#include <bps/screen.h>
#include <bps/navigator.h>
extern void fghOnReshapeNotify(SFG_Window *window, int width, int height, GLboolean forceNotify); extern void fghOnReshapeNotify(SFG_Window *window, int width, int height, GLboolean forceNotify);
extern void fghOnPositionNotify(SFG_Window *window, int x, int y, GLboolean forceNotify); extern void fghOnPositionNotify(SFG_Window *window, int x, int y, GLboolean forceNotify);
@ -48,414 +53,375 @@ extern void fgPlatformIconifyWindow( SFG_Window *window );
extern void fgPlatformShowWindow( SFG_Window *window ); extern void fgPlatformShowWindow( SFG_Window *window );
static struct touchscreen touchscreen; static struct touchscreen touchscreen;
static unsigned char key_a2fg[256];
/** unsigned int key_special(int qnxKeycode)
* Initialize BlackBerry keycode to GLUT keycode mapping {
*/ switch(qnxKeycode) {
static void key_init() { case KEYCODE_F1:
memset(key_a2fg, 0, sizeof(key_a2fg)); return GLUT_KEY_F1;
case KEYCODE_F2:
//XXX Any others? return GLUT_KEY_F2;
case KEYCODE_F3:
key_a2fg[KEYCODE_F1] = GLUT_KEY_F1; return GLUT_KEY_F3;
key_a2fg[KEYCODE_F2] = GLUT_KEY_F2; case KEYCODE_F4:
key_a2fg[KEYCODE_F3] = GLUT_KEY_F3; return GLUT_KEY_F4;
key_a2fg[KEYCODE_F4] = GLUT_KEY_F4; case KEYCODE_F5:
key_a2fg[KEYCODE_F5] = GLUT_KEY_F5; return GLUT_KEY_F5;
key_a2fg[KEYCODE_F6] = GLUT_KEY_F6; case KEYCODE_F6:
key_a2fg[KEYCODE_F7] = GLUT_KEY_F7; return GLUT_KEY_F6;
key_a2fg[KEYCODE_F8] = GLUT_KEY_F8; case KEYCODE_F7:
key_a2fg[KEYCODE_F9] = GLUT_KEY_F9; return GLUT_KEY_F7;
key_a2fg[KEYCODE_F10] = GLUT_KEY_F10; case KEYCODE_F8:
key_a2fg[KEYCODE_F11] = GLUT_KEY_F11; return GLUT_KEY_F8;
key_a2fg[KEYCODE_F12] = GLUT_KEY_F12; case KEYCODE_F9:
return GLUT_KEY_F9;
key_a2fg[KEYCODE_PG_UP] = GLUT_KEY_PAGE_UP; case KEYCODE_F10:
key_a2fg[KEYCODE_PG_DOWN] = GLUT_KEY_PAGE_DOWN; return GLUT_KEY_F10;
key_a2fg[KEYCODE_HOME] = GLUT_KEY_HOME; case KEYCODE_F11:
key_a2fg[KEYCODE_END] = GLUT_KEY_END; return GLUT_KEY_F11;
key_a2fg[KEYCODE_INSERT] = GLUT_KEY_INSERT; case KEYCODE_F12:
return GLUT_KEY_F12;
key_a2fg[KEYCODE_UP] = GLUT_KEY_UP; case KEYCODE_PG_UP:
key_a2fg[KEYCODE_DOWN] = GLUT_KEY_DOWN; return GLUT_KEY_PAGE_UP;
key_a2fg[KEYCODE_LEFT] = GLUT_KEY_LEFT; case KEYCODE_PG_DOWN:
key_a2fg[KEYCODE_RIGHT] = GLUT_KEY_RIGHT; return GLUT_KEY_PAGE_DOWN;
case KEYCODE_HOME:
key_a2fg[KEYCODE_LEFT_ALT] = GLUT_KEY_ALT_L; return GLUT_KEY_HOME;
key_a2fg[KEYCODE_RIGHT_ALT] = GLUT_KEY_ALT_R; case KEYCODE_END:
key_a2fg[KEYCODE_LEFT_SHIFT] = GLUT_KEY_SHIFT_L; return GLUT_KEY_END;
key_a2fg[KEYCODE_RIGHT_SHIFT] = GLUT_KEY_SHIFT_R; case KEYCODE_INSERT:
key_a2fg[KEYCODE_LEFT_CTRL] = GLUT_KEY_CTRL_L; return GLUT_KEY_INSERT;
key_a2fg[KEYCODE_RIGHT_CTRL] = GLUT_KEY_CTRL_R; case KEYCODE_UP:
} //case KEYCODE_KP_UP:
return GLUT_KEY_UP;
//XXX case KEYCODE_DOWN:
/* * //case KEYCODE_KP_DOWN:
* Convert an Android key event to ASCII. return GLUT_KEY_DOWN;
* / case KEYCODE_LEFT:
static unsigned char key_ascii(struct android_app* app, AInputEvent* event) { //case KEYCODE_KP_LEFT:
int32_t code = AKeyEvent_getKeyCode(event); return GLUT_KEY_LEFT;
case KEYCODE_RIGHT:
/* Handle a few special cases: * / //case KEYCODE_KP_RIGHT:
switch (code) { return GLUT_KEY_RIGHT;
case AKEYCODE_DEL: case KEYCODE_NUM_LOCK:
return 8; return GLUT_KEY_NUM_LOCK;
case AKEYCODE_FORWARD_DEL: case KEYCODE_LEFT_ALT:
return 127; return GLUT_KEY_ALT_L;
case AKEYCODE_ESCAPE: case KEYCODE_RIGHT_ALT:
return 27; return GLUT_KEY_ALT_R;
case KEYCODE_LEFT_SHIFT:
return GLUT_KEY_SHIFT_L;
case KEYCODE_RIGHT_SHIFT:
return GLUT_KEY_SHIFT_R;
case KEYCODE_LEFT_CTRL:
return GLUT_KEY_CTRL_L;
case KEYCODE_RIGHT_CTRL:
return GLUT_KEY_CTRL_R;
} }
return 0;
/* Get usable JNI context * / }
JNIEnv* env = app->activity->env;
JavaVM* vm = app->activity->vm; unsigned char key_ascii(int qnxKeycode)
(*vm)->AttachCurrentThread(vm, &env, NULL); {
if (qnxKeycode >= KEYCODE_PC_KEYS && qnxKeycode <= UNICODE_PRIVATE_USE_AREA_LAST) {
jclass KeyEventClass = (*env)->FindClass(env, "android/view/KeyEvent"); switch (qnxKeycode) {
jmethodID KeyEventConstructor = (*env)->GetMethodID(env, KeyEventClass, "<init>", "(II)V"); case KEYCODE_BACKSPACE:
jobject keyEvent = (*env)->NewObject(env, KeyEventClass, KeyEventConstructor, return 0x0008;
AKeyEvent_getAction(event), AKeyEvent_getKeyCode(event)); case KEYCODE_TAB:
jmethodID KeyEvent_getUnicodeChar = (*env)->GetMethodID(env, KeyEventClass, "getUnicodeChar", "(I)I"); return 0x0009;
int ascii = (*env)->CallIntMethod(env, keyEvent, KeyEvent_getUnicodeChar, AKeyEvent_getMetaState(event)); case KEYCODE_KP_ENTER:
case KEYCODE_RETURN:
/* LOGI("getUnicodeChar(%d) = %d ('%c')", AKeyEvent_getKeyCode(event), ascii, ascii); * / return 0x000A;
(*vm)->DetachCurrentThread(vm); case KEYCODE_ESCAPE:
return 0x001B;
return ascii; }
}
return qnxKeycode;
} }
*/
uint64_t fgPlatformSystemTime ( void ) uint64_t fgPlatformSystemTime ( void )
{ {
struct timeval now; struct timespec now;
gettimeofday( &now, NULL ); clock_gettime(CLOCK_REALTIME, &now);
return now.tv_usec / 1000 + now.tv_sec * 1000; return (1000 * now.tv_sec) + (now.tv_nsec / 1000000);
} }
/* /*
* Does the magic required to relinquish the CPU until something interesting * Does the magic required to relinquish the CPU until something interesting
* happens. * happens.
*/ */
void fgPlatformSleepForEvents( long msec ) void fgPlatformSleepForEvents( uint64_t msec )
{ {
//TODO //XXX: Is this right? Is there a more direct way to access the context?
if(bps_get_event(&fgStructure.CurrentWindow->Window.pContext.event, (int)msec) != BPS_SUCCESS) {
LOGW("BPS couldn't get event");
}
} }
/* * void handle_left_mouse(int x, int y, int height, int eventType, SFG_Window* window)
* Process the next input event. {
* / bool handled = false;
int32_t handle_input(struct android_app* app, AInputEvent* event) { /* Virtual arrows PAD */
SFG_Window* window = fgWindowByHandle(app->window); /* Don't interfere with existing mouse move event */
if (window == NULL) if (!touchscreen.in_mmotion) {
return EVENT_NOT_HANDLED; struct vpad_state prev_vpad = touchscreen.vpad;
touchscreen.vpad.left = touchscreen.vpad.right = touchscreen.vpad.up = touchscreen.vpad.down = false;
/* FIXME: in Android, when a key is repeated, down if (eventType == SCREEN_EVENT_MTOUCH_TOUCH || eventType == SCREEN_EVENT_MTOUCH_MOVE) {
and up events happen most often at the exact same time. This if ((x > 0 && x < 100) && (y > (height - 100) && y < height))
makes it impossible to animate based on key press time. * / {
/* e.g. down/up/wait/down/up rather than down/wait/down/wait/up * / touchscreen.vpad.left = true;
/* This looks like a bug in the Android virtual keyboard system :/ }
Real buttons such as the Back button appear to work correctly if ((x > 200 && x < 300) && (y > (height - 100) && y < height))
(series of down events with proper getRepeatCount value). * / {
touchscreen.vpad.right = true;
}
if ((x > 100 && x < 200) && (y > (height - 100) && y < height))
{
touchscreen.vpad.down = true;
}
if ((x > 100 && x < 200) && (y > (height - 200) && y < (height - 100)))
{
touchscreen.vpad.up = true;
}
}
if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_KEY) { if (eventType == SCREEN_EVENT_MTOUCH_TOUCH &&
/* LOGI("action: %d", AKeyEvent_getAction(event)); */ (touchscreen.vpad.left || touchscreen.vpad.right || touchscreen.vpad.down || touchscreen.vpad.up)) {
/* LOGI("keycode: %d", code); * / touchscreen.vpad.on = true;
int32_t code = AKeyEvent_getKeyCode(event); }
if (eventType == SCREEN_EVENT_MTOUCH_RELEASE) {
touchscreen.vpad.on = false;
}
if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_DOWN) { if (prev_vpad.left != touchscreen.vpad.left
int32_t keypress = 0; || prev_vpad.right != touchscreen.vpad.right
unsigned char ascii = 0; || prev_vpad.up != touchscreen.vpad.up
if ((keypress = key_a2fg[code]) && FETCH_WCB(*window, Special)) { || prev_vpad.down != touchscreen.vpad.down
INVOKE_WCB(*window, Special, (keypress, window->State.MouseX, window->State.MouseY)); || prev_vpad.on != touchscreen.vpad.on) {
return EVENT_HANDLED; if (FETCH_WCB(*window, Special)) {
} else if ((ascii = key_ascii(app, event)) && FETCH_WCB(*window, Keyboard)) { if (prev_vpad.left == false && touchscreen.vpad.left == true) {
INVOKE_WCB(*window, Keyboard, (ascii, window->State.MouseX, window->State.MouseY)); INVOKE_WCB(*window, Special, (GLUT_KEY_LEFT, x, y));
return EVENT_HANDLED; }
} else if (prev_vpad.right == false && touchscreen.vpad.right == true) {
} INVOKE_WCB(*window, Special, (GLUT_KEY_RIGHT, x, y));
else if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_UP) { }
int32_t keypress = 0; else if (prev_vpad.up == false && touchscreen.vpad.up == true) {
unsigned char ascii = 0; INVOKE_WCB(*window, Special, (GLUT_KEY_UP, x, y));
if ((keypress = key_a2fg[code]) && FETCH_WCB(*window, Special)) { }
INVOKE_WCB(*window, SpecialUp, (keypress, window->State.MouseX, window->State.MouseY)); else if (prev_vpad.down == false && touchscreen.vpad.down == true) {
return EVENT_HANDLED; INVOKE_WCB(*window, Special, (GLUT_KEY_DOWN, x, y));
} else if ((ascii = key_ascii(app, event)) && FETCH_WCB(*window, Keyboard)) { }
INVOKE_WCB(*window, KeyboardUp, (ascii, window->State.MouseX, window->State.MouseY)); }
return EVENT_HANDLED; if (FETCH_WCB(*window, SpecialUp)) {
} if (prev_vpad.left == true && touchscreen.vpad.left == false) {
} INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_LEFT, x, y));
} }
if (prev_vpad.right == true && touchscreen.vpad.right == false) {
int32_t source = AInputEvent_getSource(event); INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_RIGHT, x, y));
if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION }
&& source == AINPUT_SOURCE_TOUCHSCREEN) { if (prev_vpad.up == true && touchscreen.vpad.up == false) {
int32_t action = AMotionEvent_getAction(event) & AMOTION_EVENT_ACTION_MASK; INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_UP, x, y));
/* Pointer ID for clicks * / }
int32_t pidx = AMotionEvent_getAction(event) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; if (prev_vpad.down == true && touchscreen.vpad.down == false) {
/* TODO: Handle multi-touch; also handle multiple sources/devices */ INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_DOWN, x, y));
/* cf. http://sourceforge.net/mailarchive/forum.php?thread_name=20120518071314.GA28061%40perso.beuc.net&forum_name=freeglut-developer * / }
if (0) { }
LOGI("motion action=%d index=%d source=%d", action, pidx, source); handled = true;
int count = AMotionEvent_getPointerCount(event); }
int i;
for (i = 0; i < count; i++) {
LOGI("multi(%d): %.01f,%.01f",
AMotionEvent_getPointerId(event, i),
AMotionEvent_getX(event, i), AMotionEvent_getY(event, i));
}
}
float x = AMotionEvent_getX(event, 0);
float y = AMotionEvent_getY(event, 0);
/* Virtual arrows PAD */
/* Don't interfere with existing mouse move event * /
if (!touchscreen.in_mmotion) {
struct vpad_state prev_vpad = touchscreen.vpad;
touchscreen.vpad.left = touchscreen.vpad.right
= touchscreen.vpad.up = touchscreen.vpad.down = false;
/* int32_t width = ANativeWindow_getWidth(window->Window.Handle); * /
int32_t height = ANativeWindow_getHeight(window->Window.Handle);
if (action == AMOTION_EVENT_ACTION_DOWN || action == AMOTION_EVENT_ACTION_MOVE) {
if ((x > 0 && x < 100) && (y > (height - 100) && y < height))
touchscreen.vpad.left = true;
if ((x > 200 && x < 300) && (y > (height - 100) && y < height))
touchscreen.vpad.right = true;
if ((x > 100 && x < 200) && (y > (height - 100) && y < height))
touchscreen.vpad.down = true;
if ((x > 100 && x < 200) && (y > (height - 200) && y < (height - 100)))
touchscreen.vpad.up = true;
}
if (action == AMOTION_EVENT_ACTION_DOWN &&
(touchscreen.vpad.left || touchscreen.vpad.right || touchscreen.vpad.down || touchscreen.vpad.up))
touchscreen.vpad.on = true;
if (action == AMOTION_EVENT_ACTION_UP)
touchscreen.vpad.on = false;
if (prev_vpad.left != touchscreen.vpad.left
|| prev_vpad.right != touchscreen.vpad.right
|| prev_vpad.up != touchscreen.vpad.up
|| prev_vpad.down != touchscreen.vpad.down
|| prev_vpad.on != touchscreen.vpad.on) {
if (FETCH_WCB(*window, Special)) {
if (prev_vpad.left == false && touchscreen.vpad.left == true)
INVOKE_WCB(*window, Special, (GLUT_KEY_LEFT, x, y));
else if (prev_vpad.right == false && touchscreen.vpad.right == true)
INVOKE_WCB(*window, Special, (GLUT_KEY_RIGHT, x, y));
else if (prev_vpad.up == false && touchscreen.vpad.up == true)
INVOKE_WCB(*window, Special, (GLUT_KEY_UP, x, y));
else if (prev_vpad.down == false && touchscreen.vpad.down == true)
INVOKE_WCB(*window, Special, (GLUT_KEY_DOWN, x, y));
} }
if (FETCH_WCB(*window, SpecialUp)) {
if (prev_vpad.left == true && touchscreen.vpad.left == false) /* Normal mouse events */
INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_LEFT, x, y)); if (!handled && !touchscreen.vpad.on) {
if (prev_vpad.right == true && touchscreen.vpad.right == false) window->State.MouseX = x;
INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_RIGHT, x, y)); window->State.MouseY = y;
if (prev_vpad.up == true && touchscreen.vpad.up == false)
INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_UP, x, y)); if(eventType == SCREEN_EVENT_MTOUCH_MOVE) {
if (prev_vpad.down == true && touchscreen.vpad.down == false) INVOKE_WCB(*window, Motion, (x, y));
INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_DOWN, x, y)); } else if(FETCH_WCB(*window, Mouse)) {
touchscreen.in_mmotion = eventType == SCREEN_EVENT_MTOUCH_TOUCH;
int glutTouchType = eventType == SCREEN_EVENT_MTOUCH_TOUCH ? GLUT_DOWN : GLUT_UP;
INVOKE_WCB(*window, Mouse, (GLUT_LEFT_BUTTON, glutTouchType, x, y));
}
} }
return EVENT_HANDLED;
}
}
/* Normal mouse events * /
if (!touchscreen.vpad.on) {
window->State.MouseX = x;
window->State.MouseY = y;
if (action == AMOTION_EVENT_ACTION_DOWN && FETCH_WCB(*window, Mouse)) {
touchscreen.in_mmotion = true;
INVOKE_WCB(*window, Mouse, (GLUT_LEFT_BUTTON, GLUT_DOWN, x, y));
} else if (action == AMOTION_EVENT_ACTION_UP && FETCH_WCB(*window, Mouse)) {
touchscreen.in_mmotion = false;
INVOKE_WCB(*window, Mouse, (GLUT_LEFT_BUTTON, GLUT_UP, x, y));
} else if (action == AMOTION_EVENT_ACTION_MOVE && FETCH_WCB(*window, Motion)) {
INVOKE_WCB(*window, Motion, (x, y));
}
}
return EVENT_HANDLED;
}
/* Let Android handle other events (e.g. Back and Menu buttons) * /
return EVENT_NOT_HANDLED;
} }
*/
/* *
* Process the next main command.
* /
void handle_cmd(struct android_app* app, int32_t cmd) {
SFG_Window* window = fgWindowByHandle(app->window); /* may be NULL * /
switch (cmd) {
/* App life cycle, in that order: * /
case APP_CMD_START:
LOGI("handle_cmd: APP_CMD_START");
break;
case APP_CMD_RESUME:
LOGI("handle_cmd: APP_CMD_RESUME");
/* Cf. fgPlatformProcessSingleEvent * /
break;
case APP_CMD_INIT_WINDOW: /* surfaceCreated * /
/* The window is being shown, get it ready. * /
LOGI("handle_cmd: APP_CMD_INIT_WINDOW %p", app->window);
fgDisplay.pDisplay.single_native_window = app->window;
/* start|resume: glPlatformOpenWindow was waiting for Handle to be
defined and will now continue processing * /
break;
case APP_CMD_GAINED_FOCUS:
LOGI("handle_cmd: APP_CMD_GAINED_FOCUS");
break;
case APP_CMD_WINDOW_RESIZED:
LOGI("handle_cmd: APP_CMD_WINDOW_RESIZED");
if (window->Window.pContext.egl.Surface != EGL_NO_SURFACE)
/* Make ProcessSingleEvent detect the new size, only available
after the next SwapBuffer * /
glutPostRedisplay();
break;
case APP_CMD_SAVE_STATE: /* onSaveInstanceState */
/* The system has asked us to save our current state, when it
pauses the application without destroying it right after. * /
app->savedState = strdup("Detect me as non-NULL on next android_main");
app->savedStateSize = strlen(app->savedState) + 1;
LOGI("handle_cmd: APP_CMD_SAVE_STATE");
break;
case APP_CMD_PAUSE:
LOGI("handle_cmd: APP_CMD_PAUSE");
/* Cf. fgPlatformProcessSingleEvent * /
break;
case APP_CMD_LOST_FOCUS:
LOGI("handle_cmd: APP_CMD_LOST_FOCUS");
break;
case APP_CMD_TERM_WINDOW: /* surfaceDestroyed * /
/* The application is being hidden, but may be restored * /
LOGI("handle_cmd: APP_CMD_TERM_WINDOW");
fghPlatformCloseWindowEGL(window);
fgDisplay.pDisplay.single_native_window = NULL;
break;
case APP_CMD_STOP:
LOGI("handle_cmd: APP_CMD_STOP");
break;
case APP_CMD_DESTROY: /* Activity.onDestroy * /
LOGI("handle_cmd: APP_CMD_DESTROY");
/* User closed the application for good, let's kill the window * /
{
/* Can't use fgWindowByHandle as app->window is NULL * /
SFG_Window* window = fgStructure.CurrentWindow;
if (window != NULL) {
fgDestroyWindow(window);
} else {
LOGI("APP_CMD_DESTROY: No current window");
}
}
/* glue has already set android_app->destroyRequested=1 * /
break;
case APP_CMD_CONFIG_CHANGED:
/* Handle rotation / orientation change * /
LOGI("handle_cmd: APP_CMD_CONFIG_CHANGED");
break;
case APP_CMD_LOW_MEMORY:
LOGI("handle_cmd: APP_CMD_LOW_MEMORY");
break;
default:
LOGI("handle_cmd: unhandled cmd=%d", cmd);
}
}
*/
void fgPlatformOpenWindow( SFG_Window* window, const char* title,
GLboolean positionUse, int x, int y,
GLboolean sizeUse, int w, int h,
GLboolean gameMode, GLboolean isSubWindow );
void fgPlatformProcessSingleEvent ( void ) void fgPlatformProcessSingleEvent ( void )
{ {
//TODO int domain;
//-------------------------------- bps_event_t** eventPtr = &fgStructure.CurrentWindow->Window.pContext.event; //XXX Is there a more direct way to access the context?
/* When the screen is resized, the window handle still points to the bps_event_t* event;
old window until the next SwapBuffer, while it's crucial to set do
the size (onShape) correctly before the next onDisplay callback. {
Plus we don't know if the next SwapBuffer already occurred at the if(*eventPtr != NULL) {
time we process the event (e.g. during onDisplay). * / SFG_Window* window = fgStructure.CurrentWindow;
/* So we do the check each time rather than on event. * / if (window != NULL && window->Window.Handle != NULL) {
/* Interestingly, on a Samsung Galaxy S/PowerVR SGX540 GPU/Android int size[2];
2.3, that next SwapBuffer is fake (but still necessary to get the screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size);
new size). * / fghOnReshapeNotify(window,size[0],size[1],GL_FALSE);
SFG_Window* window = fgStructure.CurrentWindow; }
if (window != NULL && window->Window.Handle != NULL) {
int32_t width = ANativeWindow_getWidth(window->Window.Handle);
int32_t height = ANativeWindow_getHeight(window->Window.Handle);
fghOnReshapeNotify(window,width,height,GL_FALSE);
}
/* Read pending event. * / event = *eventPtr;
int ident; domain = bps_event_get_domain(event);
int events; if (domain == screen_get_domain()) {
struct android_poll_source* source; int eventType;
/* This is called "ProcessSingleEvent" but this means we'd only screen_event_t screenEvent = screen_event_get_event(event);
process ~60 (screen Hz) mouse events per second, plus other ports screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_TYPE, &eventType);
are processing all events already. So let's process all pending switch (eventType) {
events. */
/* if ((ident=ALooper_pollOnce(0, NULL, &events, (void**)&source)) >= 0) { * /
while ((ident=ALooper_pollAll(0, NULL, &events, (void**)&source)) >= 0) {
/* Process this event. * /
if (source != NULL) {
source->process(source->app, source);
}
}
/* If we're not in RESUME state, Android paused us, so wait * / //Mostly from fg_main_android
struct android_app* app = fgDisplay.pDisplay.app; case SCREEN_EVENT_MTOUCH_TOUCH:
if (app->destroyRequested != 1 && app->activityState != APP_CMD_RESUME) { case SCREEN_EVENT_MTOUCH_RELEASE:
INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_PAUSE)); case SCREEN_EVENT_MTOUCH_MOVE:
{
mtouch_event_t touchEvent;
screen_get_mtouch_event(screenEvent, &touchEvent, 0);
if(touchEvent.contact_id == 0) { //XXX Only support one contact for now
int size[2];
screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size);
handle_left_mouse(touchEvent.x, touchEvent.y, size[1], eventType, window);
}
break;
}
int FOREVER = -1; case SCREEN_EVENT_POINTER:
while (app->destroyRequested != 1 && (app->activityState != APP_CMD_RESUME)) { {
if ((ident=ALooper_pollOnce(FOREVER, NULL, &events, (void**)&source)) >= 0) { //Based off/part taken from GamePlay3d PlatformBlackBerry
/* Process this event. * / static int mouse_pressed = 0;
if (source != NULL) { int buttons;
source->process(source->app, source); int position[2];
} // A move event will be fired unless a button state changed.
} bool move = true;
} bool left_move = false;
/* Coming back from a pause: * / // This is a mouse move event, it is applicable to a device with a usb mouse or simulator.
/* - Recreate window context and surface */ screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_BUTTONS, &buttons);
/* - Call user-defined hook to restore resources (textures...) * / screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_SOURCE_POSITION, position);
/* - Exit pause loop * / int size[2];
if (app->destroyRequested != 1) { screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size);
/* Android is full-screen only, simplified call.. * /
/* Ideally we'd have a fgPlatformReopenWindow() * /
/* If we're hidden by a non-fullscreen or translucent activity,
we'll be paused but not stopped, and keep the current
surface; in which case fgPlatformOpenWindow will no-op. * /
fgPlatformOpenWindow(window, "", GL_FALSE, 0, 0, GL_FALSE, 0, 0, GL_FALSE, GL_FALSE);
/* TODO: should there be a whole GLUT_INIT_WORK forced? probably... // Handle left mouse. Interpret as touch if the left mouse event is not consumed.
* Could queue that up in APP_CMD_TERM_WINDOW handler, but it'll if (buttons & SCREEN_LEFT_MOUSE_BUTTON) {
* be not possible to ensure InitContext CB gets called before if (mouse_pressed & SCREEN_LEFT_MOUSE_BUTTON) {
* Resume CB like that.. so maybe just force calling initContext CB left_move = true;
* here is best. Or we could force work on the window in question.. } else {
* 1) save old work mask, 2) set mask to init only, 3) call fgProcessWork directly move = false;
* 4) set work mask back to the one saved in step 1. mouse_pressed |= SCREEN_LEFT_MOUSE_BUTTON;
/ handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_TOUCH, window);
if (!FETCH_WCB(*window, InitContext)) }
fgWarning("Resuming application, but no callback to reload context resources (glutInitContextFunc)"); } else if (mouse_pressed & SCREEN_LEFT_MOUSE_BUTTON) {
} move = false;
mouse_pressed &= ~SCREEN_LEFT_MOUSE_BUTTON;
handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_RELEASE, window);
}
INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_RESUME)); // Handle right mouse.
} if (buttons & SCREEN_RIGHT_MOUSE_BUTTON) {
*/ if ((mouse_pressed & SCREEN_RIGHT_MOUSE_BUTTON) == 0) {
move = false;
mouse_pressed |= SCREEN_RIGHT_MOUSE_BUTTON;
INVOKE_WCB(*window, Mouse, (GLUT_RIGHT_BUTTON, GLUT_DOWN, position[0], position[1]));
}
} else if (mouse_pressed & SCREEN_RIGHT_MOUSE_BUTTON) {
move = false;
mouse_pressed &= ~SCREEN_RIGHT_MOUSE_BUTTON;
INVOKE_WCB(*window, Mouse, (GLUT_RIGHT_BUTTON, GLUT_UP, position[0], position[1]));
}
// Handle middle mouse.
if (buttons & SCREEN_MIDDLE_MOUSE_BUTTON) {
if ((mouse_pressed & SCREEN_MIDDLE_MOUSE_BUTTON) == 0) {
move = false;
mouse_pressed |= SCREEN_MIDDLE_MOUSE_BUTTON;
INVOKE_WCB(*window, Mouse, (GLUT_MIDDLE_BUTTON, GLUT_DOWN, position[0], position[1]));
}
} else if (mouse_pressed & SCREEN_MIDDLE_MOUSE_BUTTON) {
move = false;
mouse_pressed &= ~SCREEN_MIDDLE_MOUSE_BUTTON;
INVOKE_WCB(*window, Mouse, (GLUT_MIDDLE_BUTTON, GLUT_UP, position[0], position[1]));
}
// Fire a move event if none of the buttons changed.
if (left_move || move) {
handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_MOVE, window);
}
break;
}
//Based off fg_main_android
case SCREEN_EVENT_KEYBOARD:
{
int flags;
int value;
screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_FLAGS, &flags);
screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_SYM, &value);
LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_KEYBOARD. Flags: 0x%X, Sym: 0x%X", SLOG2_FA_SIGNED(flags), SLOG2_FA_SIGNED(value), SLOG2_FA_END);
// Suppress key repeats if desired
if (!fgStructure.CurrentWindow->State.IgnoreKeyRepeat && (flags & KEY_REPEAT) == 0) {
unsigned int keypress = 0;
unsigned char ascii = 0;
if ((keypress = key_special(value))) {
if(flags & KEY_DOWN) {
INVOKE_WCB(*window, Special, (keypress, window->State.MouseX, window->State.MouseY));
} else {
INVOKE_WCB(*window, SpecialUp, (keypress, window->State.MouseX, window->State.MouseY));
}
} else if((flags & KEY_SYM_VALID) && (ascii = key_ascii(value))) {
if(flags & KEY_DOWN) {
INVOKE_WCB(*window, Keyboard, (ascii, window->State.MouseX, window->State.MouseY));
} else {
INVOKE_WCB(*window, KeyboardUp, (ascii, window->State.MouseX, window->State.MouseY));
}
}
}
break;
}
}
} else if (domain == navigator_get_domain()) {
switch (bps_event_get_code(event)) {
case NAVIGATOR_WINDOW_STATE:
{
LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE", SLOG2_FA_END);
navigator_window_state_t state = navigator_event_get_window_state(event);
switch (state)
{
case NAVIGATOR_WINDOW_FULLSCREEN:
LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_FULLSCREEN", SLOG2_FA_END);
INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_RESUME));
break;
case NAVIGATOR_WINDOW_THUMBNAIL:
case NAVIGATOR_WINDOW_INVISIBLE:
LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_THUMBNAIL/NAVIGATOR_WINDOW_INVISIBLE", SLOG2_FA_END);
INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_PAUSE));
break;
}
break;
}
case NAVIGATOR_EXIT:
LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_EXIT", SLOG2_FA_END);
/* User closed the application for good, let's kill the window */
{
SFG_Window* window = fgStructure.CurrentWindow;
if (window != NULL) {
fgDestroyWindow(window);
} else {
LOGI("NAVIGATOR_EXIT: No current window", SLOG2_FA_END);
}
}
break;
}
}
}
} while(bps_get_event(eventPtr, 1) == BPS_SUCCESS && *eventPtr != NULL);
/* Reset event to reduce chances of triggering something */
*eventPtr = NULL;
} }
void fgPlatformMainLoopPreliminaryWork ( void ) void fgPlatformMainLoopPreliminaryWork ( void )
{ {
LOGI("fgPlatformMainLoopPreliminaryWork\n", SLOG2_FA_END); LOGI("fgPlatformMainLoopPreliminaryWork\n", SLOG2_FA_END);
key_init();
} }

View File

@ -31,7 +31,7 @@
extern void fgPlatformProcessSingleEvent(void); extern void fgPlatformProcessSingleEvent(void);
extern uint64_t fgPlatformSystemTime(void); extern uint64_t fgPlatformSystemTime(void);
extern void fgPlatformSleepForEvents(long msec); extern void fgPlatformSleepForEvents(uint64_t msec);
extern void fgPlatformMainLoopPreliminaryWork(void); extern void fgPlatformMainLoopPreliminaryWork(void);
#endif #endif

View File

@ -48,6 +48,7 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title,
fgWarning("You can't have more than one window on BlackBerry"); fgWarning("You can't have more than one window on BlackBerry");
return; return;
} }
window->Window.pContext.event = NULL; //XXX Should probably be done elsewhere. Done here so there is no event at the moment
/* Create window */ /* Create window */
if (screen_create_context(&window->Window.pContext.screenContext, 0)) { if (screen_create_context(&window->Window.pContext.screenContext, 0)) {