Clutter Learning (3): Add a clutter container to the GTK container -- stage widget example

Source: Internet
Author: User

See materials:

Http://www.openismus.com/documents/clutter_tutorial/0.9/docs/tutorial/html/sec-stage-widget.html

This time we need to use the clutter-GTK development kit. Simple compilation is as follows. Note that the PKG-config quotation marks are not ['], but [']. ^ _ ^. Do not make a mistake.


Gcc-wall-G example. C-o example 'pkg-config clutter-1.0 clutter-gtk-0.10 -- cflags -- libs'

  

The source file is staget_widget.c. We directly add the relevant script in the previous makefile, as shown in the following figure. Add some other colors. We make makefile more suitable for projects with multiple *. c files, as long as we add the file names we need to compile in obj2. Here we add the development kit that uses the cluter-gtk-0.10, we need to add the relevant header file path and Lib, using the PKG-config method to add.


Cc = gcc

#

-Wall indicates that all warning messages are output,-G indicates that the warning messages are compiled into the debug version, and-O indicates that the warning messages are optimized during compilation.

Cflags + =-wall-G 'pkg-config clutter-1.0 clutter-gtk-0.10 -- cflags'

Libs + =-wall-G 'pkg-config clutter-1.0 clutter-gtk-0.10 -- libs'


Target = stage
Obj2 = stage_widget.o

TARGET2 = stage_widget

# In makefile, $ <: the first dependent file in the dependency file list

# In makefile, $ @: list of target files under the current rule
% O: % C

$ (CC) $ (cflags)-C $ <-o $ @

Stage:

Gcc-wall-g stage. C-O Stage 'pkg-config clutter-1.0 -- cflags -- libs'

Stage_widget: $ (obj2)

$ (CC) $ (libs)-o $ (TARGET2) $ (obj2)

ALL: stage stage_widget

Clean:

Rm $ (target) $ (TARGET2) *. o

Gtkclutterembed widgets: "I think widgets are more abuse than gadget. Please do not confuse them with small apps on the Internet. In image interface development, this refers to the essence of the widget. It allows a clutterstage to be added to a GTK + window. Other GTK widgets in this GTK + window can interact with this clutter widget.

The following is a small example. Many of his code and Clutter's callback are displayed in the previous clutter stage example.

# Include <clutter/clutter. h>
# Include <clutter-GTK/clutter-gtk.h>

# Include <stdlib. h>

Clutteractor * stage = NULL;

/* This is the callback function of the last stage. The coordinates of the mouse clicks are given. We will omit it here to avoid too many codes */

Static gboolean on_stage_button_press (clutterstage * stage, clutterevent * event, gpointer user_data)

{

... ...

}

/* This is the processing after the button is pressed. When the GTK + button is triggered, the color of the clutter stage is changed. Can be skipped quickly. */

Static gboolean on_button_clicked (gtkbutton * button, gpointer user_data)

{

Static gboolean already_changed = false;

If (already_changed ){

Cluttercolor stage_color = {0x00,0x00,0x00, 0xff };

Clutter_stage_set_color (clutter_stage (stage), & stage_color );

} Else {

Cluttercolor stage_color = {0x20, 0x20, 0xa0, 0xff };

Clutter_stage_set_color (clutter_stage (stage), & stage_color );

}

Already_changed =! Already_changed;

Return true;

}

Int main (INT argc, char * argv [])

{

Cluttercolor stage_color = {0x00,0x00,0x00, 0xff };

/* This applet allows clutter and GTK to be used together and will use resources of clutter-GTK.

* Therefore, there is a difference between initialization and pure clutter. It contains gtk_init */

Gtk_clutter_init (& argc, & argv );

/* Create the window and some child widgets :*/

/** Create a window and learn about GTK. It turns out that walking must climb.

* Create a window container first, and then create a vbox sub-container. You can vertically place buttons and other widgets in it, or place clutter widgets */

Gtkwidget * window = gtk_window_new (gtk_window_toplevel );
/** Create a container that can store sub-parts vertically

Gtkbox

: Vbox, put it in the GTK window, and set it to visual mode */

Gtkwidget * vbox = gtk_vbox_new (false, 6 );

Gtk_container_add (gtk_container (window), vbox );

Gtk_widget_show (vbox );

/** Create a GTK button, add it to the bottom of the vbox, and set it to visual mode, and add a button to trigger the callback function */

Gtkwidget * button = gtk_button_new_with_label ("change color ");

Gtk_box_pack_end (gtk_box (vbox), button, false, false, 0 );

Gtk_widget_show (button );

G_signal_connect (button, "clicked", g_callback (on_button_clicked), null );
/* Pay attention to the callback function of the window. If this function is not available, the program does not exit when the window is closed. */

G_signal_connect (window, "hide", g_callback (gtk_main_quit), null );

/** The clutter widget has finally arrived.

* Generate a clutter widget that can be loaded in GTK and put it in the GTK container vbox. Set it to the visual mode and set the size of the widget */

Gtkwidget * clutter_widget =Gtk_clutter_embed_new

();

Gtk_box_pack_start (gtk_box (vbox), clutter_widget, true, true, 0 );

Gtk_widget_show (clutter_widget );

Gtk_widget_set_size_request (clutter_widget, 200,200 );
/** For all clutter, we should have at least one clutterstage (derived from clutteraction ),

* This example is obtained from the gtkclutterembed part added with GTK, and the remaining operations are shown in the previous stage example */

Stage =Gtk_clutter_embed_get_stage

(Gtk_clutter_embed (clutter_widget ));

Clutter_stage_set_color (clutter_stage (stage), & stage_color );

G_signal_connect (stage, "button-press-Event", g_callback (on_stage_button_press), null );

Gtk_widget_show (gtk_widget (window ));

Clutter_actor_show (stage );

/* The main window is a GTK window. The main loop of GKT is used to replace the main loop of clutter. Start the main loop, so we can respond to events :*/

Gtk_main ();

Return exit_success;

}


Some problems running on the moblin machine:

If you run the command on worker N,Note the sequence of gtk_widget_show (window) and clutter_actor_show (stage ).

, You must put gtk_widget_show (window) in front. Otherwise, the program is unstable, which may cause crashes. We have not found the order in which the two data are required, and there is no such order in the desktop. This is a strange phenomenon. Pay special attention to it during development.

  

In addition, moblin reports:


Do_wait: drmwaitvblank returned-1, irqs don't seem to be working correctly.

Try adjusting the vblank_mode configuration parameter.

  

We tried to fix this problem,

You cannot set vblank_mode to eliminate it,

In fact, this problem does not have any impact, but the error may not seem pleasing to the eye, which may be related to moblin's integration of clutter UI (suspect ing ). The process records are as follows:


Install the RPM package of driconf,

The dirconf file is as follows:


<Driconf>

<Device screen = "0" driver = "i915">

<Application name = "default">

<Option name = "force_s3tc_enable" value = "false"/>

<Option name = "no_rast" value = "false"/>

<Option name = "fthrottle_mode" value = "2"/>

<Option name = "always_flush_cache" value = "false"/>

<Option name = "always_flush_batch" value = "false"/>

<Option name = "bo_reuse" value = "1"/>

<Option name = "vblank_mode" value = "0"/>

<Option name = "allow_large_textures" value = "2"/>

</Application>

</Device>

</Driconf>

Set vblank_mode to 0, 1, 2, and 3, respectively, and restart and try again. The same error is reported:

Do_wait: drmwaitvblank returned-1, irqs don't seem to be working correctly.

Try adjusting the vblank_mode configuration parameter.

Related links:

My clutter blog

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.