/* the code to retrieve the keymap direction and cache it * is taken from GDK: * gdk/x11/gdkkeys-x11.c */ static PangoDirection get_direction (XkbDescPtr xkb, int group) { int rtl_minus_ltr = 0; /* total number of RTL keysyms minus LTR ones */ int code; for (code = xkb->min_key_code; code <= xkb->max_key_code; code += 1) { int level = 0; KeySym sym = XkbKeySymEntry (xkb, code, level, group); PangoDirection dir = pango_unichar_direction (clutter_keysym_to_unicode (sym)); switch (dir) { case PANGO_DIRECTION_RTL: rtl_minus_ltr++; break; case PANGO_DIRECTION_LTR: rtl_minus_ltr--; break; default: break; } } if (rtl_minus_ltr > 0) return PANGO_DIRECTION_RTL; return PANGO_DIRECTION_LTR; }
static VALUE rg_s_unichar_direction(G_GNUC_UNUSED VALUE self, VALUE ch) { return PANGODIRECTION2RVAL(pango_unichar_direction(NUM2UINT(ch))); }
static VALUE rpango_unichar_direction(VALUE self, VALUE ch) { return GENUM2RVAL(pango_unichar_direction(NUM2UINT(ch)), PANGO_TYPE_DIRECTION); }
static GooCanvasItem *wordsgame_create_item(GooCanvasItem *parent) { LettersItem *item; gchar *word = gc_wordlist_random_word_get(gc_wordlist, gcomprisBoard->level); GtkAnchorType direction_anchor = GTK_ANCHOR_NW; if(!word) /* Should display the dialog box here */ return NULL; if (uppercase_only) { gchar *old = word; word = g_utf8_strup(old, -1); g_free(old); } // create and init item item = g_new(LettersItem,1); item->word = word; item->overword=g_strdup(""); item->count=0; item->letter=g_utf8_strndup(item->word,1); item->pos=g_utf8_find_next_char(item->word,NULL); if (pango_unichar_direction(g_utf8_get_char(item->word))) direction_anchor = GTK_ANCHOR_NE; item->rootitem = goo_canvas_group_new (parent, NULL); goo_canvas_item_translate(item->rootitem, 0, -12); /* To 'erase' words, I create 2 times the text item. One is empty now */ /* It will be filled each time the user enters the right key */ goo_canvas_text_new (item->rootitem, item->word, (double) 0, (double) 0, -1, direction_anchor, "font", gc_skin_font_board_huge_bold, "fill_color_rgba", 0x3e2587FF, NULL); item->overwriteItem = \ goo_canvas_text_new (item->rootitem, item->overword, (double) 0, (double) 0, -1, direction_anchor, "font", gc_skin_font_board_huge_bold, "fill-color_rgba", 0xff0000ff, NULL); /*set right x position */ GooCanvasBounds bounds; goo_canvas_item_get_bounds (item->rootitem, &bounds); if(direction_anchor == GTK_ANCHOR_NW) goo_canvas_item_translate (item->rootitem, (g_random_int()%(BOARDWIDTH-(gint)(bounds.x2))), 0); else { double new_x = (double)( g_random_int()%BOARDWIDTH); if ( new_x < -bounds.x1 ) new_x -= bounds.x1; goo_canvas_item_translate (item->rootitem, new_x ,(double) 0); } #if GLIB_CHECK_VERSION(2, 31, 0) g_mutex_lock (&items_lock); #else g_static_mutex_lock (&items_lock); #endif g_ptr_array_add(items, item); #if GLIB_CHECK_VERSION(2, 31, 0) g_mutex_unlock (&items_lock); #else g_static_mutex_unlock (&items_lock); #endif return (item->rootitem); }