summaryrefslogtreecommitdiff
path: root/examples/script-file/main.c
blob: 936916fb3c0a5db38192c15bd33e8a2b2fdfdb15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/***************************************************************
  SVGC EXAMPLE: EMBEDDED ECMASCRIPT

  The file change-color.js contains only JavaScript source
  text. Interactive script execution requires opening the SVG
  as a document.
 ***************************************************************/

#include <stdio.h>
#include <svgc.h>


int
main( void )
{
   struct __svg_sheet *sheet;
   struct __svg_scene *scene;
   struct __svg_node  *circle;

   sheet = (struct __svg_sheet *)__svg_new_sheet( 520, 220, 16, 16, 16, 16 );
   if( !sheet ) return( 1 );

   if( __svg_sheet_add_script_file( sheet, "change-color.js" ) != 1 )
   {
      __svg_free_node( sheet );
      fprintf( stderr, "Cannot add change-color.js to the SVG sheet\n" );
      return( 1 );
   }

   scene = __svg_new_scene( sheet );
   if( !scene )
   {
      __svg_free_node( sheet );
      return( 1 );
   }

   circle = __svg_new_circle( 260, 110, 72 );
   if( !circle ||
       __svg_set_fill( circle, "red" ) != 1 ||
       __svg_scene_add_node( scene, circle ) != 1 )
   {
      if( circle ) __svg_free_node( circle );
      __svg_free_scene( scene );
      return( 1 );
   }

   __svg_paint_scene( scene, 0, "example.svg" );
   __svg_free_scene( scene );
   return( 0 );
}