static void gletters_move_item(GooCanvasItem *item) { GooCanvasBounds bounds; goo_canvas_item_translate(item, 0, 2.0); goo_canvas_item_get_bounds (item, &bounds); if(bounds.y1>BOARDHEIGHT) { item2del_list = g_list_append (item2del_list, item); player_loose(); } }
/* Called with items_lock locked */ static void wordsgame_move_item(LettersItem *item) { GooCanvasBounds bounds; goo_canvas_item_translate(item->rootitem, 0, 2.0); goo_canvas_item_get_bounds (item->rootitem, &bounds); if(bounds.y1>BOARDHEIGHT) { if (item == item_on_focus) item_on_focus = NULL; g_ptr_array_remove (items, item); g_ptr_array_add (items2del, item); g_timeout_add (100,(GSourceFunc) wordsgame_delete_items, NULL); player_loose(); } }
static gint key_press(guint keyval, gchar *commit_str, gchar *preedit_str) { gchar *letter; gint i; LettersItem *item; gchar *str; gunichar unichar_letter; gint retval = TRUE; if(!gcomprisBoard) return FALSE; if (keyval){ g_warning("keyval %d", keyval); return TRUE; } if (preedit_str){ g_warning("preedit_str %s", preedit_str); /* show the preedit string on bottom of the window */ GcomprisProperties *properties = gc_prop_get (); gchar *text; PangoAttrList *attrs; gint cursor_pos; gtk_im_context_get_preedit_string (properties->context, &text, &attrs, &cursor_pos); if (!preedit_text) preedit_text = \ goo_canvas_text_new (goo_canvas_get_root_item(gcomprisBoard->canvas), "", BOARDWIDTH/2, BOARDHEIGHT - 100, -1, GTK_ANCHOR_N, "font", gc_skin_font_board_huge_bold, //"fill_color_rgba", 0xba00ffff, NULL); g_object_set (preedit_text, "text", text, "attributes", attrs, NULL); return TRUE; } /* commit str */ g_warning("commit_str %s", commit_str); str = commit_str; #if GLIB_CHECK_VERSION(2, 31, 0) g_mutex_lock (&items_lock); #else g_static_mutex_lock (&items_lock); #endif for (i=0; i < g_utf8_strlen(commit_str,-1); i++){ unichar_letter = g_utf8_get_char(str); str = g_utf8_next_char(str); if(!g_unichar_isalnum (unichar_letter)){ player_loose(); retval = FALSE; break; } letter = g_new0(gchar,6); g_unichar_to_utf8 (unichar_letter, letter); /* Force entered letter to the casing we expect * Children is to small to manage the caps lock key for now */ if (uppercase_only) { gchar *old = letter; letter = g_utf8_strup(old, -1); g_free(old); } else { gchar *old = letter; letter = g_utf8_strdown(old, -1); g_free(old); } if(item_on_focus==NULL) { for (i=0;i<items->len;i++) { item=g_ptr_array_index(items,i); g_assert (item!=NULL); if (strcmp(item->letter,letter)==0) { item_on_focus=item; break; } } } if(item_on_focus!=NULL) { if(strcmp(item_on_focus->letter, letter)==0) { gchar *tmpstr; item_on_focus->count++; g_free(item_on_focus->overword); tmpstr = g_utf8_strndup(item_on_focus->word, item_on_focus->count); /* Add the ZERO WIDTH JOINER to force joined char in Arabic and Hangul * http://en.wikipedia.org/wiki/Zero-width_joiner */ item_on_focus->overword = g_strdup_printf("%s%lc", tmpstr, 0x200D); g_free(tmpstr); g_object_set (item_on_focus->overwriteItem, "text", item_on_focus->overword, NULL); if (item_on_focus->count<g_utf8_strlen(item_on_focus->word,-1)) { g_free(item_on_focus->letter); item_on_focus->letter=g_utf8_strndup(item_on_focus->pos,1); item_on_focus->pos=g_utf8_find_next_char(item_on_focus->pos,NULL); } else { player_win(item_on_focus); item_on_focus=NULL; } } else { /* It is a loose : unselect the word and defocus */ g_free(item_on_focus->overword); item_on_focus->overword=g_strdup(" "); item_on_focus->count=0; g_free(item_on_focus->letter); item_on_focus->letter=g_utf8_strndup(item_on_focus->word,1); item_on_focus->pos=g_utf8_find_next_char(item_on_focus->word,NULL); g_object_set (item_on_focus->overwriteItem, "text", item_on_focus->overword, NULL); item_on_focus=NULL; g_free(letter); player_loose(); break; } } else { /* Anyway kid you clicked on the wrong key */ player_loose(); g_free(letter); break; } g_free(letter); } #if GLIB_CHECK_VERSION(2, 31, 0) g_mutex_unlock (&items_lock); #else g_static_mutex_unlock (&items_lock); #endif return retval; }