PHP-GTK2 Newsletter

PHP-GTK2 Tips & Techniques
FREE Newsletter
by kksou



Sample Code 417: How to place a background image in GtkWindow - Part 2 - tiled background image?
Written by kksou   
Thursday, 24 January 2008
Problem

You have seen how to place a background image in a GtkWindow as shown in the article How to place a background image in GtkWindow?

Suppose instead of a single background image, you want to have a tiled background image in a GtkWindow as shown below:

How to place a background image in GtkWindow - Part 2 - tiled background image?


Solution
  • In PHP-GTK2 (actually it's the underlying GTK), background images are always displayed in tiles.
  • So if your background image size is smaller than your application window size, you will find that the background image will always be displayed in tiles — repeating itself in the x- and y- directions.

Sample Code

Note: The following image file is required by the sample code below. Please save a copy of the image files and put them in the same directory where you store the sample code.

 sample6_150a.png

1   
2   
3   
4   
5   
6   
7   
8   
9   
10   
11   
12   
13   
14   
15   
16   
17   
18   
19   
<?php
$window = new GtkWindow();
$window->set_size_request(480, 240);
$window->connect_simple('destroy', array('Gtk','main_quit'));
$window->add($vbox = new GtkVBox());

// display title
$title = new GtkLabel("Place a background image in GtkWindow\n".
"        Part 2 - tiled background image");
$title->modify_font(new PangoFontDescription("Times New Roman Bold Italic 10"));
$title->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse("#0000ff"));
$title->set_size_request(-1, 40);
$vbox->pack_start($title, 0);
$vbox->pack_start(new GtkLabel(), 0);
$vbox->pack_start(new GtkLabel("Notice the background image is tiled!"));
$vbox->pack_start(new GtkLabel("It'll keep repeating in the x and y directions."));

// set background image
$pixbuf=GdkPixbuf::new_from_file("sample6_150.png");
  • 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

The sample code above is exactly the same as that of the article How to place a background image in GtkWindow? (The only diffference is the background image.)

Pleaes refer to the article for explanations.


Related Links

User reviews   Average user ratings:    5.0   (from 1 user)
  1. Vydaman
    May 22, 2008 5:49pm

Note: You have to be a registered member to leave a comment. Free registration here.

 
< Prev   Next >

Copyright © 2006-2008. kksou.com. All Rights Reserved