cvs: php-gtk-doc /en/tutorials pixmaps.xml

From: Date: Sun, 01 Aug 2004 07:10:02 +0000
Subject: cvs: php-gtk-doc /en/tutorials pixmaps.xml
Groups: php.gtk.doc 
Request: Send a blank email to php-gtk-doc+get-1008@lists.php.net to get a copy of this message
cweiske Sun Aug 1 03:10:02 2004 EDT Modified files: /php-gtk-doc/en/tutorials pixmaps.xml Log: Gave the tutorial a big example http://cvs.php.net/diff.php/php-gtk-doc/en/tutorials/pixmaps.xml?r1=1.1&r2=1.2&ty=u Index: php-gtk-doc/en/tutorials/pixmaps.xml diff -u php-gtk-doc/en/tutorials/pixmaps.xml:1.1 php-gtk-doc/en/tutorials/pixmaps.xml:1.2 --- php-gtk-doc/en/tutorials/pixmaps.xml:1.1 Sat Jul 31 05:56:49 2004 +++ php-gtk-doc/en/tutorials/pixmaps.xml Sun Aug 1 03:10:01 2004 @@ -195,6 +195,8 @@ <![CDATA[ $colTransparent = &new GdkColor(0, 0, 0);]]> </programlisting> + It doesn't seem to work with php-gtk, so you have to use the <literal>None</literal> color + in the pixmap definition. </para> <simpara> The third parameter is the name of the image file (<literal>pixmap_create_from_xpm</literal>), @@ -202,15 +204,197 @@ (<literal>pixmap_create_from_xpm</literal>). </simpara> <!-- </section>--> + + + +<!-- <section> + <title>Examples</title>--> + <simpara> + The following example shows how to create a pixmap from an array, + creating a button and attaching the pixmap along with the label + to the button. It also uses the <literal>enter</literal> and <literal>leave</literal> + signals to change the pixmap when the button is hovered by the mouse. + The icon of the window is set, too - but this won't work on Windows. + </simpara> + <example> + <title>Pixmap button &amp; highlighting example</title> + <programlisting role="php"> +<![CDATA[ +<?php +if( !extension_loaded('gtk')) { + dl( 'php_gtk.' . PHP_SHLIB_SUFFIX); +} + +$arXPMs['ok'] = array( +"32 32 7 1", +" c None", +". c #005F00", "+ c #008A00", "@ c #00BB00", +"# c #00E000", "$ c #00F709", "% c #4BE24A", +" ", +" ", +" ", +" ", +" @@", +" +@++", +"+@ +@+@+ ", +"+++ @+@++. ", +"+@++ ++@%++. ", +" +%++ +++%%@+ ", +" +%@++ +++%%%++ ", +" +@##++ +++%$$%++ ", +" +$$%++ +++@$$$$++ ", +" +#$$@+. +++@$$$$%++ ", +" +@$$$#+.+.+@$$$$$#+. ", +" .+$$$$@+.@#$$$$$@+. ", +" +##$$$####$$$$++. ", +" .@$#####$$###@.. ", +" .+##########+.. ", +" .#########+.. ", +" .@##@#@#@.. ", +" .+@##@#@+. ", +" ..#@@#@.. ", +" .@@@@.. ", +" .+@+.. ", +" .++.. ", +" ... ", +" .. ", +" ", +" ", +" ", +" "); + +$arXPMs['inbox'] = array( +"16 16 6 1", +" c None" , ". c #028800", "+ c #995700", +"@ c #82E61D", "# c #FFBE58", "$ c #FCEF8E", +" ", +" .... ", +" .$$$$. ", +" .@@@@. ", +" .@@@@. ", +" ..@@@@.. ", +" .@@@@@@@@. ", +" .@@@@@@. ", +" .@.@@. ", +" ..@. ", +"+++ .. +++", +"+$$+ +$$+", +"+$$++++++++++$$+", +"+$#$$$$$$$$$$$#+", +"+$#############+", +"++++++++++++++++" +); + +$window = &new GtkWindow(); +$window->set_title( 'pixmaps'); +$window->set_default_size( 200, 100); +$window->connect_object('destroy', array('gtk', 'main_quit')); +$window->realize(); + +$clTransparentTest = &new GdkColor( '#000000'); + +$arPxTest = gdk::pixmap_create_from_xpm_d($window->window, $clTransparentTest, $arXPMs['ok']); + +$btnTest = &new GtkButton(); +$pxmTest = &new GtkPixmap( $arPxTest[0], $arPxTest[1]); +$lblTest = &new GtkLabel( 'Button with icon'); +$hboxTest = &new GtkHBox(); +$hboxTest->pack_start( $pxmTest); +$hboxTest->pack_end( $lblTest); +$btnTest->add( $hboxTest); + +//hovering the button changes the image +//to a highlighted version of itself +function changePixmap( $btnTest, $strAction, &$pixmap) { + $hbox = $btnTest->child; + $arChildren = $hbox->children(); + $hbox->remove( $arChildren[0]); + $hbox->pack_start( $pixmap); + $pixmap->show(); + //underline the label + $lblTest = $arChildren[1]; + $strPattern = ''; + if( $strAction == 'enter') { + $strPattern = '________________'; + } + $lblTest->set_pattern( $strPattern); +} + +//generate a highlighted picture from the original +$arXPMs['high'] = $arXPMs['ok']; +$arData = explode( ' ', $arXPMs['high'][0]); +$nColors = $arData[2]; + +//change all colors | we know the first color is transparent +for( $nA = 2; $nA < $nColors + 1; $nA++) { + $arData = explode( ' #', $arXPMs['high'][$nA]); + //the following code is taken from PEAR::Image_Color + $degree = 40; + $color[] = hexdec( substr( $arData[1], 0, 2 ) ); + $color[] = hexdec( substr( $arData[1], 2, 2 ) ); + $color[] = hexdec( substr( $arData[1], 4, 2 ) ); + for ( $x = 0; $x < 3; $x++ ) { + if ( ( $color[$x] + $degree ) < 256 ) { + if ( ( $color1[$x] + $degree ) > -1 ) { + $color[$x] += $degree; + } else { + $color[$x] = 0; + } + } else { + $color[$x] = 255; + } + } + $arData[1] = sprintf( '%02X%02X%02X', $color[0], $color[1], $color[2]); + $arXPMs['high'][$nA] = implode( ' #', $arData); +} + +$arPxTestH = gdk::pixmap_create_from_xpm_d($window->window, null, $arXPMs['high']); +$pxmTestHigh = &new GtkPixmap( $arPxTestH[0], $arPxTestH[1]); + +$btnTest->connect( 'enter', 'changePixmap', 'enter', $pxmTestHigh); +$btnTest->connect( 'leave', 'changePixmap', 'leave', $pxmTest); + +$alBtn = &new GtkAlignment( 0.5, 0.5, 0, 0); +$alBtn->add( $btnTest); + + +list( $pxWindow, $maskWindow) = gdk::pixmap_create_from_xpm_d($window->window, null, $arXPMs['inbox']); +$gdkwindow = $window->window; +$gdkwindow->set_icon( $gdkwindow, $pxWindow, $maskWindow); + +$window->add( $alBtn); +$window->show_all(); + +gtk::main(); +?> +]]> + </programlisting> + </example> +<!-- </section>--> + + + +<!-- <section> + <title>Other things you can do with pixmaps</title>--> + <simpara> + Another nice thing you can do with a pixmap or better a pixmask is + defining your own shape for widgets or whole windows. This means you + can have can have a button with rounded corners or a window with "holes" + in it by using the + <link linked="gtk.gtkwidget.method.shape_combine_mask">shape_combine_mask</link> + method of <classname>GtkWidget</classname>. + </simpara> + + +<!-- </section>--> <!-- TODO: -- example -- set_icon -- shaped buttons and windows - other xpm functions - symbolic names, changing during runtime -- additional transparency checking +- displaying jpg/png/whatever by transforming them before with gd + +- additional transparency checking | doesn't seem to work --> </chapter>

« previous php.gtk.doc (#1008) next »