Canvas SVG parser: Difference between revisions

m
Line 3: Line 3:
== Basic example ==
== Basic example ==


For loading a SVG file onto a Canvas we first need to create a Canvas instance (See [[Howto:Add_a_2D_canvas_instrument_to_your_aircraft]]). Afterwards we can load a SVG by just using the function ''canvas.parsesvg'' from the Canvas API:
For loading a SVG file onto a Canvas we first need to create a Canvas instance (See [[Howto:Add_a_2D_canvas_instrument_to_your_aircraft]]). Afterwards we can load a SVG by just using the function ''canvas.parsesvg'' from the Canvas API, also the API now supports retrieving elements by id which enables the following simple code snippet for changing the text and color in an instrument:


<syntaxhighlight lang="php">
<syntaxhighlight lang="php">
Line 21: Line 21:
</syntaxhighlight>
</syntaxhighlight>


Also the API now supports retrieving elements by id which enables the following simple code snippet for changing the text and color in an instrument:
You can lookup any type of element you want and modify them how you want (Add transformations, change colors/texts/coordinates etc.). You can also lookup an parent element and afterwards some of is child elements. By this you can use the same id multiple times but are still able to get access to every element (eg. Engine 1/Dial N1, Engine 2/Dial N1, etc.).
You can lookup any type of element you want and modify them how you want (Add transformations, change colors/texts/coordinates etc.). You can also lookup an parent element and afterwards some of is child elements. By this you can use the same id multiple times but are still able to get access to every element (eg. Engine 1/Dial N1, Engine 2/Dial N1, etc.).