C-Sharp Interface For ASV
From Svg wiki
I've been working on C#/Adobe SVG 3.0 and have uploaded a demo at
http://groups.yahoo.com/group/svg-developers/files/whack_em.zip
The readme document follows:
This application demonstrates interaction between C# and ADOBE's SVG Viewer 3.0, Build 76.
Description, resources and issues are discussed below.
DESCRIPTION:
This application includes an SVG file, whack_em.svg, which randomly shows one of five faces. Clicking on a face with the mouse, "whacks" it into hiding, but another face shows up to replace it.
The game runs for a specified number of seconds and keeps score.
C# loads the SVG file, allows the user to set the time limit for the game and starts the game on command.
SVG randomly shows a face, handles the "onclick" events, watches the timer and keeps score.
C# calls ASV functions in the SVG object to provide a running score and show the time remaining.
C# also handles "click" events, displays the ID name of the face selected and keeps separate score.
When the time expires, C# displays its score in a message box. The score should match the score kept by the SVG object.
RESOURCES:
The following resources were helpful in developing this demo:
http://groups.yahoo.com/group/svg-developers/files/svg.zip which demonsrates handling SVG events in C++
http://www.oreilly.com/catalog/svgess/ Chapter 11 in SVG Essentials has an excellent example on interaction between HTML and SVG.
ISSUES:
1. C# can easily call ASV functions. However, I was not able to determine how to get ASV to call a C# method. When SVG is hosted in a browser container, ASV can call a Javascript function in the HTML page (see SVG Essentials above).
2. C# can listen for a click and a few other events. I was not able to determine how an ASV function could raise an event that would be recognized by C#.
This application works around both issues by using a polling thread to periodically call the appropriate ASV functions to report the score and time remaining. This seems acceptable in a client application, especially if the SVG encapsulates its functionality and only needs infrequent interaction with C# (which feels like good design practice to me). However, there are other situations where the ability to call methods or raise event handlers in C# would be helpful.
3. This example reads a static SVG file. In most cases, I will be dynamically creating SVG files from XML/XSL transforms, etc. I have been able to create and render and SVG image using Adobe's parseXML method, but have not been able to access the included ASV functions. Clearly the setSRC method that normally loads SVG documents makes the appropriate connections between ASV scripts and the windows object that holds both ASV and SVG elements. It may be that parseXML doesn't make similar connections.
As a workaround, I generate the SVG documents through the appropriate transforms, write them to a temporary file, "foo", and use setSRC( "foo" ) to render the document.
jlongson
teamatics.com
