Sample Code 440: How to set up a round GtkWindow? |
|
Written by kksou
|
|
Thursday, 21 February 2008 |
|
Problem This is in response to Shin's post titled 'Styled Window'.
He would like to have a round GtkWindow as shown below:

Solution
- We use exactly the same technique as outlined in How to create a round button - Part 1?. Instead of GtkEventBox, we use GtkWindow.
- Note that php-gtk simply masked out the alpha channel (i.e. the transparent area) in your image. If there are any text or images in those areas, they will be masked out too.
- To hide the title bar, use GtkWindow::set_decorated(false). If you don't, your application window will look like this:

Sometimes this is desirable, though, if the user wants to be able to move the application window easily with the mouse.
Sample Code Note: The following image file is required by the sample code below. Please save a copy of the image file and put it in the same directory where you store the sample code.
 | round200a.png |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| <?php $window = new GtkWindow(); $window->set_size_request(200, 200); $window->connect_simple('destroy', array('Gtk','main_quit')); $window->add($vbox = new GtkVBox());
$vbox->pack_start(new GtkLabel('this is line abcdefghijk.1'), 0); $vbox->pack_start(new GtkLabel('this is line abcdefghijk.2'), 0); $vbox->pack_start(new GtkLabel('this is line abcdefghijk.3'), 0); $vbox->pack_start(new GtkLabel('this is line abcdefghijk.4'), 0); $vbox->pack_start(new GtkLabel('this is line abcdefghijk.5'), 0); $vbox->pack_start(new GtkLabel('this is line abcdefghijk.6'), 0);
$pixbuf = GdkPixbuf::new_from_file("round200a.png"); // note 1
list($pixmap,$mask) = $pixbuf->render_pixmap_and_mask(255); // note 2
|
- Note that this is only 70% of the sample code. You have to be a registered member to see the entire sample code. Please login or register.
- Registration is free and immediate.
- Have some doubt about the registration? Please read this forum article.
Explanation
- Load the image.
- Get the mask.
- Mask out the transparent areas.
- Hide the title bar.
Related Links
|