0
我想開發一個遊戲,可以採取多種語言輸入,包括CJK字符。是否有可能有一個GtkDrawingArea填充整個窗口,並有一個GtkEntry浮動「頂部」?也有可能使GtkEntry的背景和邊框透明嗎?謝謝你的幫助。透明浮動GtkEntry
我想開發一個遊戲,可以採取多種語言輸入,包括CJK字符。是否有可能有一個GtkDrawingArea填充整個窗口,並有一個GtkEntry浮動「頂部」?也有可能使GtkEntry的背景和邊框透明嗎?謝謝你的幫助。透明浮動GtkEntry
這裏是我做到了在my application,具有功能彈出一個GtkEntry
包含一些文本,在父控件的頂部,在座標(X,Y)相對於父控件的左上角:
GtkWidget *
popup_edit_window(GtkWidget *parent, gint x, gint y, const gchar *text)
{
gint px, py;
gdk_window_get_origin(gtk_widget_get_window(parent), &px, &py);
GtkWidget *edit_popup = gtk_window_new(GTK_WINDOW_TOPLEVEL);
/* stackoverflow.com/questions/1925568/how-to-give-keyboard-focus-to-a-pop-up-gtk-window */
GTK_WIDGET_SET_FLAGS(edit_popup, GTK_CAN_FOCUS);
gtk_window_set_decorated(GTK_WINDOW(edit_popup), FALSE);
gtk_window_set_has_frame(GTK_WINDOW(edit_popup), FALSE);
gtk_window_set_type_hint(GTK_WINDOW(edit_popup), GDK_WINDOW_TYPE_HINT_POPUP_MENU);
gtk_window_set_transient_for(GTK_WINDOW(edit_popup), GTK_WINDOW(parent));
gtk_window_set_gravity(GTK_WINDOW(edit_popup), GDK_GRAVITY_CENTER);
GtkWidget *entry = gtk_entry_new();
gtk_widget_add_events(entry, GDK_FOCUS_CHANGE_MASK);
gtk_entry_set_text(GTK_ENTRY(entry), text);
gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
gtk_container_add(GTK_CONTAINER(edit_popup), entry);
g_signal_connect_swapped(entry, "focus-out-event", G_CALLBACK(gtk_widget_destroy), edit_popup);
g_signal_connect(entry, "key-press-event", G_CALLBACK(on_edit_popup_key_press), edit_popup);
gtk_widget_show_all(edit_popup);
gtk_window_move(GTK_WINDOW(edit_popup), x + px, y + py);
/* GDK_GRAVITY_CENTER seems to have no effect? */
gtk_widget_grab_focus(entry);
gtk_window_present(GTK_WINDOW(edit_popup));
return edit_popup;
}
gboolean
on_edit_popup_key_press(GtkWidget *entry, GdkEventKey *event, GtkWidget *edit_popup)
{
switch(event->keyval) {
case GDK_Escape:
gtk_widget_destroy(edit_popup);
return TRUE;
case GDK_Return:
case GDK_KP_Enter:
/* here, do whatever you need to do when finished editing */
gtk_widget_destroy(edit_popup);
return TRUE;
}
return FALSE; /* event not handled */
}
要使其透明的,你應該能夠做到:
gtk_window_set_opacity(GTK_WINDOW(edit_popup), 0.5);
但要知道,你的窗口管理器可能不支持,或者可以選擇忽略它。
但是,您是否認爲GTK具有相關的輸入法庫,以便用戶可以選擇他們想要輸入CJK字符的任何輸入法?沒有必要重新發明輪子。