From 2624827ee680b0a721c408da690721b28e8f2427 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sun, 27 Jan 2013 09:26:52 +1000 Subject: Get the new camera actually working. Still some bugs to be ironed out. --- ClientHamr/extantz/extantz.c | 121 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 110 insertions(+), 11 deletions(-) (limited to 'ClientHamr/extantz/extantz.c') diff --git a/ClientHamr/extantz/extantz.c b/ClientHamr/extantz/extantz.c index fb15019..46dc8a3 100644 --- a/ClientHamr/extantz/extantz.c +++ b/ClientHamr/extantz/extantz.c @@ -329,6 +329,107 @@ load_shader(GLData *gld, GLenum type, const char *shader_src) return shader; } +static void _cb_mouse_down_GL(void *data, Evas *evas, Evas_Object *obj, void *event_info) +{ + GLData *gld = data; + Evas_Event_Mouse_Down *ev = event_info; + + if (1 == ev->button) + { + gld->camFocus = 1; + printf("Background GL object focused.\n"); + } +} + +static void _cb_mouse_down_elm(void *data, Evas *evas, Evas_Object *obj, void *event_info) +{ + GLData *gld = data; + Evas_Event_Mouse_Down *ev = event_info; + + if (1 == ev->button) + { + gld->camFocus = 0; + // TODO - Yes we really DO need to figure out what was clicked on and set focus to it. sigh + // For now, we only got one window, focus on it's box. + elm_object_focus_set(gld->bx, EINA_TRUE); + printf("ELM object focused.\n"); + } +} + +static Eina_Bool _on_camera_input(void *data, Evas_Object *obj, Evas_Object *src, Evas_Callback_Type type, void *event_info) +{ + GLData *gld = data; + + if (gld->camFocus) + { + if (gld->move) + { + // TODO - Careful, gld->move MIGHT be read at the other end by another thread. MIGHT, coz I really don't now at what point the camera animate routine is actually called. + Evas_Event_Key_Down *ev = event_info; + + // Yes, we are dealing with the horrid Evas keyboard handling FUCKING STRING COMPARES! Soooo ... + // TODO - make this a hash lookup dammit. + // TODO - these are not working, coz Elm is grabbing the Left, Right, Up, and Down KEY_DOWNs. + if (EVAS_CALLBACK_KEY_DOWN == type) + { + if (0 == strcmp(ev->keyname, "Escape")) + { + } + else if (0 == strcmp(ev->key, "Left")) + gld->move->y = 1.0; + else if (0 == strcmp(ev->key, "Right")) + gld->move->y = -1.0; + else if (0 == strcmp(ev->key, "Up")) + gld->move->x = 1.0; + else if (0 == strcmp(ev->key, "Down")) + gld->move->x = -1.0; + else if (0 == strcmp(ev->key, "Prior")) + gld->move->x = 1.0; + else if (0 == strcmp(ev->key, "Next")) + gld->move->x = -1.0; + else if (0 == strcmp(ev->key, "Home")) + gld->move->y = 1.0; + else if (0 == strcmp(ev->key, "End")) + gld->move->y = -1.0; + else if (0 == strcmp(ev->key, "space")) + gld->move->jump = 1.0; + else + printf("Unexpected down keystroke - %s\n", ev->key); + } + else if (EVAS_CALLBACK_KEY_UP == type) + { + if (0 == strcmp(ev->keyname, "Escape")) + { + } + else if (0 == strcmp(ev->key, "Left")) + gld->move->y = 0.0; + else if (0 == strcmp(ev->key, "Right")) + gld->move->y = 0.0; + else if (0 == strcmp(ev->key, "Up")) + gld->move->x = 0.0; + else if (0 == strcmp(ev->key, "Down")) + gld->move->x = 0.0; + else if (0 == strcmp(ev->key, "Prior")) + gld->move->x = 0.0; + else if (0 == strcmp(ev->key, "Next")) + gld->move->x = 0.0; + else if (0 == strcmp(ev->key, "Home")) + gld->move->y = 0.0; + else if (0 == strcmp(ev->key, "End")) + gld->move->y = 0.0; + else if (0 == strcmp(ev->key, "space")) + gld->move->jump = 0.0; + else + printf("Unexpected up keystroke - %s\n", ev->key); + } + } + else + printf("Camera input not ready\n"); + } + + return EINA_FALSE; // TRUE = event was processed here, don't propagate. FALSE = propagate event, not processed here. +} + static void _resize(GLData *gld) { Evas_GL_API *gl = gld->glapi; @@ -441,6 +542,7 @@ on_del(void *data, Evas *e, Evas_Object *obj, void *event_info) if (!gld) return; Evas_GL_API *gl = gld->glapi; + elm_object_event_callback_del(gld->r1, _on_camera_input, gld); ecore_animator_del(gld->animator); if (gld->useEGL) @@ -635,6 +737,11 @@ static void init_evas_gl(GLData *gld, int w, int h) // ecore_animator_frametime_set(1.0); gld->animator = ecore_animator_add(doFrame, gld); // This animator will be called every frame tick, which defaults to 1/30 seconds. + // In this code, we are making our own camera, so grab it's input when we are focused. + elm_object_event_callback_add(gld->win, _on_camera_input, gld); + evas_object_event_callback_add(gld->r1, EVAS_CALLBACK_MOUSE_DOWN, _cb_mouse_down_GL, gld); + gld->camFocus = 1; // Start with the GL camera focused. + return; } @@ -752,7 +859,8 @@ static void _grid_sel_cb(void *data, Evas_Object *obj, void *event_info) // sprintf(buf, "dillo -f -g '%dx%d+%d+%d' %s &", w - (w / 5), h - 30, w / 5, y, thisGrid->splashPage); sprintf(buf, "uzbl -g '%dx%d+%d+%d' -u %s &", w - (w / 5), h - 30, w / 5, y, thisGrid->splashPage); printf("%s ### genlist obj [%p], item pointer [%p]\n", buf, obj, event_info); - system(buf); +// comment this out for now, busy dealing with input stuff, don't want to trigger this multiple times. +// system(buf); } static void @@ -902,15 +1010,6 @@ fill(Evas_Object *win) evas_object_show(bx); } - -static void -cb_mouse_down(void *data, Evas *evas, Evas_Object *obj, void *event_info) -{ - Evas_Event_Mouse_Down *ev = event_info; - - if (ev->button == 1) elm_object_focus_set(obj, EINA_TRUE); -} - static void cb_mouse_move(void *data, Evas *evas, Evas_Object *obj, void *event_info) { @@ -1043,7 +1142,7 @@ EAPI_MAIN int elm_main(int argc, char **argv) win3 = elm_win_add(gld->win, "inlined", ELM_WIN_INLINED_IMAGE); elm_win_title_set(win3, "world manager"); - evas_object_event_callback_add(elm_win_inlined_image_object_get(win3), EVAS_CALLBACK_MOUSE_DOWN, cb_mouse_down, NULL); + evas_object_event_callback_add(elm_win_inlined_image_object_get(win3), EVAS_CALLBACK_MOUSE_DOWN, _cb_mouse_down_elm, gld); elm_win_alpha_set(win3, EINA_TRUE); fill(win3); // Odd, it needs to be resized twice? -- cgit v1.1