1

我曾尝试使用 clutter-gtk。我编写了一小段代码来创建一个 gtk 窗口,其中包含一个杂乱的阶段。我尝试在舞台上获得鼠标按钮按下事件,但什么也没有。

这是代码:

#include <clutter/clutter.h>
#include <clutter-gtk/clutter-gtk.h>
#include <glib.h>
#include <stdlib.h>
#include <stdio.h>
/*gcc 3_clutter_app_clickable_text_in_gtk.c -o 3_clutter_app_clickable_text_in_gtk `pkg-config clutter-1.0 clutter-gtk-1.0 glib --cflags --libs`*/

/*mouse clic handler*/
void on_stage_button_press( ClutterStage *stage, ClutterEvent *event, gpointer data) 
{
  printf("ok\n");
}


int main(int argc, char *argv[])
{
  if (gtk_clutter_init(&argc, &argv) != CLUTTER_INIT_SUCCESS)
    return EXIT_FAILURE;

   /*create the window*/
   GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_window_set_default_size (GTK_WINDOW (window), 640, 480);

   /*destroy from window close all*/
   g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);    
   /*vertical box, 0 spacing*/
   GtkWidget * box = gtk_box_new(GTK_ORIENTATION_VERTICAL,0);
   /*add box in the window*/
   gtk_container_add(GTK_CONTAINER(window), box);

   /*create the cutter widget*/
   GtkWidget *clutter_widget = gtk_clutter_embed_new ();
   gtk_widget_set_size_request (clutter_widget, 200, 200);

   ClutterActor *stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED(clutter_widget));
   clutter_stage_set_use_alpha(CLUTTER_STAGE(stage), TRUE);
   ClutterColor stage_color ;
   GString * bg_color = g_string_new("#555753ff");
   clutter_color_from_string(&stage_color,bg_color->str);
   clutter_actor_set_background_color(stage, &stage_color);

   /*add the cutter widget in the box expand and fill are TRUE and spacing is 0*/
   gtk_box_pack_start (GTK_BOX (box), clutter_widget, TRUE, TRUE, 0);

   /*create line text*/
   ClutterColor text_color;
   GString * fg_color = g_string_new("#00000055");
   clutter_color_from_string(&text_color, fg_color->str);
   ClutterActor *some_text = clutter_text_new_full("Sans 24", "Hello, world", &text_color);
   clutter_actor_set_size(some_text, 256, 128);
   clutter_actor_set_position(some_text, 128, 128);
   clutter_actor_add_child(CLUTTER_ACTOR(stage), some_text);
   clutter_text_set_editable(CLUTTER_TEXT(some_text), TRUE);    
   /*define clic event*/
   g_signal_connect(stage, "button-press-event", G_CALLBACK(on_stage_button_press), NULL);

   /* Show the window and all its widgets: */
   gtk_widget_show_all (GTK_WIDGET (window));

   /* Start the main loop, so we can respond to events: */
   gtk_main ();

   return EXIT_SUCCESS;
}

当我点击舞台时没有任何反应。我做了一些测试,我可以在主窗口上处理点击事件,在 clutter_widget 但不能直接在混乱阶段。

此代码是从http://www.openismus.com/documents/clutter_tutorial/0.9/docs/tutorial/html/sec-stage-widget.html修改的。在这篇文章中,作者将信号直接连接到舞台上,但此示例适用于 clutter 0.9,并且不再使用 clutter v > 1.0 进行编译。

关于我做错了什么的任何想法?

编辑

我已经用处理过的“按键事件”进行了一些测试。所以问题似乎来自舞台的事件面具。

有谁知道如何更改舞台的事件掩码以强制舞台对鼠标事件做出反应?

4

2 回答 2

0

I close this question because :

  1. clutter-gtk is just a proof of concept
  2. clutter-gtk will not be used in the future

see https://mail.gnome.org/archives/clutter-list/2013-February/msg00059.html

so I don't want to loose more time with this.

For information,the same example using juste clutter works as expected.

于 2013-05-16T19:03:21.893 回答
0

CLUTTER_BACKEND=gdk ./yourexecutable

于 2014-03-28T06:14:26.483 回答