gnope php gtk gui gnope.org  

Tiling an Image

 
Post new topic   Reply to topic    gnope.org Forum Index -> PHP GTK2 Beginners
View previous topic :: View next topic  
Author Message
ron_t



Joined: 11 Dec 2005
Posts: 78
Location: Gatineau, Quebec

PostPosted: Wed Jan 04, 2006 11:09 pm    Post subject: Tiling an Image Reply with quote

Hi all,

Does anyone know how to tile an image as a background in a widget? I'm thinking it has something to do with GdkFill types (such as GDK_TILED) but I can't find any example code in any language. In fact, I'm not at all clear on how to use a GdkFill type at all. Any suggestions, anyone?

-Ron T.
Back to top
cweiske



Joined: 08 Dec 2005
Posts: 454
Location: Leipzig/Germany

PostPosted: Thu Jan 05, 2006 9:44 am    Post subject: Re: Tiling an Image Reply with quote

ron_t wrote:
Does anyone know how to tile an image as a background in a widget?

Did you already try GtkStyle? it has a background image or background pixmap property, and the image is tiled automatically if the widget is too large.
Back to top
ron_t



Joined: 11 Dec 2005
Posts: 78
Location: Gatineau, Quebec

PostPosted: Thu Jan 05, 2006 1:46 pm    Post subject: Re: Tiling an Image Reply with quote

cweiske wrote:

Did you already try GtkStyle? it has a background image or background pixmap property, and the image is tiled automatically if the widget is too large.


Yes, I took a long look at that. Unfortunately, it didn't make a lot of sense to me. The php-gtk2 docs are still a bit skimpy (I know they're a work a progress, so I'm not complaining) and the docs for version 1 don't seem to apply any longer.

What I did come up with is this, and it works quite well (even if it's not 100% kosher):

Code:

<?php

/*
 * Make sure we have the libraries loaded.
 */
if (!class_exists('gtk'))
{
   die('Please load the php-gtk2 module in your php.ini' . "\r\n");
}


/*
 * do a JIT load of any classes we've overlooked.
 */
function __autoload($class_name)
{
   require_once '../include/' . $class_name . '.inc';
}

/*
 * forces a redraw of simple child widgets
 */
function exposure($adj, $layout)
{
   $layout->queue_draw();
} // exposure()

//////////////////////////////////////////
// SAMPLE STARTS HERE : SAMPLE STARTS HERE
//////////////////////////////////////////

// Use this with any image with a width/height matching the
// cellWidth/cellHeight below.

// an array to hold GtkImages and their positions in the display
$corks = array();
$cellWidth = 340;
$cellHeight = 220;

// This will be the "corkboard"
$layout = new GtkLayout();


// fill in the array of cork images
for($i = 0; $i < 5; $i++)
{
   for($j = 0; $j < 7; $j++)
   {
      $corks[$i][$j][0] = new GtkImage();      // create image
      $corks[$i][$j][0]->set_from_file("../images/cork.png");   // load from file
      $corks[$i][$j][1] = $cellWidth * $i;   // x position
      $corks[$i][$j][2] = $cellHeight * $j;   // y position

      // put image in place
      $layout->put($corks[$i][$j][0], $corks[$i][$j][1], $corks[$i][$j][2]);
   }
}

// the "corkboard" size is a multiple of the image tile's width and height
$layout->set_size($cellWidth * 5, $cellHeight * 7);


/*
 * main window
 */
$window = new GtkWindow();

// NOTE: This is depricated, but it's the only way I've found to
// get the window in more or less the position I want it with win2k.
$window->set_uposition(1, 1);

$window->set_title('Tiled Image Background');
$window->set_size_request(1275, 965);
$window->show();
$window->connect_simple('destroy', array('gtk', 'main_quit'));


$vbox = new GtkVBox();
$window->add($vbox);
$scrolledwindow = new GtkScrolledWindow();
$vbox->add($scrolledwindow);
$scrolledwindow->add($layout);
$window->show_all();


gtk::main();


?>



-Ron T.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    gnope.org Forum Index -> PHP GTK2 Beginners All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Templates enhanced by DigiWiki. Hosting by Tradebit.