[Gtk-sharp-list] Best way to build a zoom effect?
Crucius, Wesley
WCrucius at sandc.com
Fri Mar 17 00:12:41 EST 2006
Here's pretty much everything you'll need... Enjoy!
Wes
<method variables>
private System.Xml.XmlDocument _xmlDoc;
<initialization>
_xmlDoc = new System.Xml.XmlDocument();
_xmlDoc.Load(SVGFileName);
<Called from the SizeAllocated event for the Gtk.ScrolledWin that contains the passed in Gtk.EventBox>
private void RenderSVG(ref System.Xml.XmlDocument xmlDoc, ref Gtk.EventBox eventBox)
{
XmlNode nodeElem;
int width, height;
Gdk.Pixmap pixmap, pixmap_mask;
Gdk.Pixbuf pixbuf;
// get the "available" width and height
width = eventBox.Allocation.Width;
height = eventBox.Allocation.Height;
try
{
nodeElem = xmlDoc.SelectSingleNode("//*[@id='svgRoot']"); // xpath search for the root element by id
nodeElem.Attributes.GetNamedItem("width").Value = width.ToString();
nodeElem.Attributes.GetNamedItem("height").Value = height.ToString();
}
catch(Exception ex)
{
Console.WriteLine("Error updating SVG size properties: ");
Console.WriteLine(" " + ex.Message );
}
// render the SVG into a pixbuf
System.IO.MemoryStream streamSVG = new System.IO.MemoryStream();
xmlDoc.Save(streamSVG); // put the XML doc in a Stream
streamSVG.Position = 0; // reset the stream once written, this is IMPORTANT!
pixbuf = new Gdk.Pixbuf(streamSVG);
pixbuf.RenderPixmapAndMask(out pixmap, out pixmap_mask, 0 );
eventBox.GdkWindow.SetBackPixmap( pixmap, false );
}
-----Original Message-----
From: gtk-sharp-list-bounces at lists.ximian.com on behalf of Julien Sobrier
Sent: Thu 3/16/2006 10:36 PM
Cc: gtk-sharp-list at lists.ximian.com
Subject: Re: [Gtk-sharp-list] Best way to build a zoom effect?
Crucius, Wesley wrote:
> I'd suggest using Inkscape to draw the text and save it as an SVG
> document and then use Gdk.Pixbuf to load and render to a bitmap. If the
> text is static you can just use the ".svg file load with scaling
> version" of the constructor, otherwise, load the svg into an XML DOM
> doc, manipulate the width & height attributes of the SVG within the DOM
> (to scale it), save it as an XMLStream, and then use the stream version
> of the Pixbuf constructor.
>
> I've done it both ways, so I know either one will work, however it is a
> bit CPU intensive.
>
> Wes
Thanks. I'll try that. And I guess I still need to modify the picture
size every x milliseconds.
I'm not familiar with the XML library of Mon, and I can't find the "XML
DOM doc". I guess it should be in the class System.XML, but I don't know
in which class.
Thank you
Julien
_______________________________________________
Gtk-sharp-list maillist - Gtk-sharp-list at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/gtk-sharp-list/attachments/20060316/d9080283/attachment.html
More information about the Gtk-sharp-list
mailing list