Clutter Learning (4): Stage widgets with scroll bars

Source: Internet
Author: User
Tags gtk

We know that moblin in V2
In beta, clutter is used to create the UI. Clutter has received more and more OSV attention as a UI. Although I personally think Clutter's dependency on the graphics card driver and general graphics card driver VESA are not very well supported, however, clutter does provide brilliant dynamic effects and is compatible with GTK, QT, and so on. This prevents us from considering the impact on the system too much for Clutter selection, for example, whether other Linux applications, OpenOffice, and Firefox are affected, you can choose to add the clutter stage to the GTK container conservatively.
Widget.

The following example shows the source of learning materials:

Http://www.openismus.com/documents/clutter_tutorial/0.9/docs/tutorial/html/actor-scrolling.html

, But we did a litte
More. Because I am not a developer of GTK, I will do more experiments on some GTK. In fact, I usually try my best to avoid participating in interface development. In addition to the development of some Console software in Java, there is also a VC, but the tools are put there.

This is a small example of viewing images. You can use the scroll bar to view images that are not in the display area. Therefore, we need a large image file to work with the experiment. To solve the limited visible space through the scroll bar, we can useGtkScrolledWindow

But this method cannot be used in gtkclutterembed, Because clutter obtains from the display hardware and does not use the Drawing System (Drawing
System). It can also explain why clutter is responding as slowly as it is driven by Vesa. This requires the use of gtkclutterviewport, which does not provide automatic loading of the scroll bar, the use of gtkadjustment using gtksrcollbar
Widget.

  

These graphic interfaces are developed as one container and another container. First, we will analyze the layout of the example below the pipeline. In this example, we retemperature how to add the clutter widget in the GTK container.

 

 

Create a Windows part of GTK and add the layout part table (2 × 2). The last example used the vertical placement of vbox. The image is placed in the (0, 0) area, and the horizontal and vertical scroll bars are placed in the (0, 1) and (1, 0) areas respectively. (1, 1) No widgets are placed in the area.

We use clutter to display images. To add a clutter to the gtk container, we need to add a clutterwidget to the location where the layout is needed, indicating that the clutter container will be used here, And clutterstage is required for any clutter. Therefore, we obtain an embed from the clutterwidget.
Stage. The remaining operations are standard clutter operations. To display an image, we need to use viewport and place the image that breaks through texture (obtained from the specified file path) in the display area.

In this example, a callback function is added to adjust the image adaptation when the window size is detected to change.

# Include <clutter/clutter. h>

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

# Include <stdlib. h>

Clutteractor * viewport = NULL;

/*
Trigger function for component size change: refit the viewport size according to the actual size of the component (stage */

Static gboolean
On_win_resize (clutterstage * widget, clutterevent * event, gpointer
User_data ){

Float W = 0, H = 0;

Clutteractor * stage =
(Clutteractor *) user_data;

Clutter_actor_get_size (stage, & W,
& H );

Printf ("[configure-event]: Stage size is %. 0f * %. 0f, reset
Viewport./N ", W, H );

Clutter_actor_set_size (viewport, (INT) W, (INT)
H );

Return true;

}

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

Cluttercolor
Stage_color = {0x61, 0x64, 0x8c, 0xff };

/** G_error will interrupt the application (abort
Therefore, we do not need to add exit (-1 ),

* At the same time, we need to be cautious when using g_error to determine whether to end the process. */

If (argc! = 2)

G_error ("Usage: stage_scroll
<Image File> ");

If (gtk_clutter_init (& argc, & argv )! =
Clutter_init_success)

G_error ("unable to init GTK-clutter ");

/** Create GTK
Window acts as the main container of the main window, and provides processing for closing the window */

Gtkwidget * window =
Gtk_window_new (gtk_window_toplevel );

Gtk_window_set_default_size
(Gtk_window (Windows), 640,480 );


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

/** Put the layout gtktable in the gtk windows container

And set table to display mode.
*/

Gtkwidget * Table = gtk_table_new (2,
2, false );

Gtk_container_add (gtk_container (window), table );


Gtk_widget_show (table );

/*
Insert the clutter embedded widget into the table (0, 0) position, and put the stage into the widget as the clutter container */


Gtkwidget * clutter_widget =Gtk_clutter_embed_new

();


Gtk_table_attach

(Gtk_table (table), clutter_widget, 0,
1, 0, 1,

Gtk_expand | gtk_fill, gtk_expand | gtk_fill, 0, 0 );


Gtk_widget_show (clutter_widget );

Clutteractor * stage =
Gtk_clutter_embed_get_stage

(Gtk_clutter_embed (clutter_widget ));


Clutter_stage_set_color (clutter_stage (stage), & stage_color );


Clutter_actor_set_size (stage, 640,480 );


Clutter_actor_show (stage );

/*
Create a viewport clutteractor and put it into the stage container, allowing scroll.

* By passing null it
Will create new gtkadjustments. The viewport will contian the image.


* Gtk_clutter_viewport_new add third Param z_adjust in version 0.10
*/

Viewport =Gtk_clutter_viewport_new

(Null,
Null, null );


Clutter_container_add_actor (

Clutter_container (stage), viewport );

/** Put an image in

Viewport

.
*/

Clutteractor * texture =
Clutter_texture_new_from_file

(Argv [1], null );


If (texture = NULL ){

G_print ("[Error]: The file is not
Existed! /N ");

Exit (-1 );

}

/*
Texture is automatically placed in the viewport from 0 to 0, and does not need to be set to postition. */


Clutter_container_add_actor

(Clutter_container (viewport ),
Texture );

// Clutter_actor_set_position (texture, 0, 0 );


Float W = 0, H = 0;

Clutter_actor_get_size (viewport, & W,
& H );

Printf ("[info]: viewport size is %. 0f *
%. 0f./N ", W, H );

Clutter_actor_get_size (stage, & W, & H );


Printf ("[info]: Stage size is %. 0f * %. 0f./N", W, H );

/*
We have added the GTK size event detection. We do not need to automatically adapt the image size here (so that the scroll bar can work effectively) and perform it in the callback function */


// Clutter_actor_set_size (viewport, 640,480 );

/* Create scrollbars and connect
Them To viewport :*/

Gtkadjustment

* H_adjustment =
NULL;

Gtkadjustment

* V_adjustment = NULL;


Gtk_clutter_scrollable_get_adjustments

(Gtk_clutter_scrollable (viewport ),


& H_adjustment, & v_adjustment );

Gtkwidget * scrollbar =
Gtk_vscrollbar_new

(V_adjustment );


Gtk_table_attach

(Gtk_table (table ),
Scrollbar, 0, gtk_expand | gtk_fill );

Gtk_widget_show
(Scrollbar );

Scrollbar = gtk_hscrollbar_new (h_adjustment );


Gtk_table_attach (gtk_table (table), scrollbar, 0, 1, 2, gtk_expand |
Gtk_fill, 0, 0 );

Gtk_widget_show (scrollbar );

/*
Configure_event: this event will be generated when we change the widget size, including when the window is created. */


G_signal_connect (clutter_widget, "configure_event ",
G_callback (on_win_resize), stage );


Gtk_widget_show (gtk_widget (window ));

Gtk_main ();

Return
Exit_success;

}

 

Actions of the GTK component or events sent by the X server can be associated with the following events. For details, refer to the famous GTK + 2.0 document.

Button_press_event // press the button

Button_release_event // click to release

Motion_policy_event // move the mouse

Delete_event // close with Window Manager

Destroy_event // close

Expose_event // exposure

Key_press_event // press the key

Key_release_event // press the button to release

Enter_policy_event // enter the component with the mouse pointer

Leave_policy_event // move the mouse pointer away from the component

Configure_event // attribute change

Focus_in_event // obtain the focus

Focus_out_event // lose focus

Map_event // ing

Unmap_event // disappears

Property_policy_event // attribute change

Selection_clear_event // select clear

Selection_request_event // select the request

Selection_policy_event // select notification

Proximity_in_event // close

Proximity_out_event // exit

Drag_begin_event // drag start

Drag_request_event // drag request

Drag_end_event // drag the end

Drop_enter_event // enter

Drop_leave_event // exit

Drop_data_available_event // data available

 

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.