@@ -118,7 +118,8 @@ public class Canvas : DrawingArea {
118118 set_cursor( cursor );
119119 }
120120
121- /* Opens a new image and displays it in the drawing area */
121+ // -------------------------------------------------------------
122+ // Opens a new image and displays it in the drawing area.
122123 public bool open_image ( string filename ) {
123124
124125 try {
@@ -376,7 +377,7 @@ public class Canvas : DrawingArea {
376377
377378 var retval = grab_focus();
378379 if ( image. cropping ) {
379- if ( image. cursor_pressed( x, y , n_press ) ) {
380+ if ( image. cursor_pressed( ex, ey , n_press ) ) {
380381 queue_draw();
381382 }
382383 } else if ( items. cursor_pressed( x, y, n_press ) ) {
@@ -400,7 +401,7 @@ public class Canvas : DrawingArea {
400401 _last_y = y;
401402
402403 if ( image. cropping || image. picking ) {
403- if ( image. cursor_moved( x, y ) ) {
404+ if ( image. cursor_moved( ex, ey ) ) {
404405 queue_draw();
405406 }
406407 } else if ( items. cursor_moved( x, y ) ) {
@@ -416,7 +417,7 @@ public class Canvas : DrawingArea {
416417 var y = scale_y( ey );
417418
418419 if ( image. cropping || image. picking ) {
419- if ( image. cursor_released( x, y ) ) {
420+ if ( image. cursor_released( ex, ey ) ) {
420421 queue_draw();
421422 }
422423 } else if ( items. cursor_released( x, y ) ) {
@@ -494,6 +495,42 @@ public class Canvas : DrawingArea {
494495
495496 }
496497
498+ /* ***************************************************************************/
499+ // SAVE/LOAD
500+ /* ***************************************************************************/
501+
502+ // -------------------------------------------------------------
503+ // Saves this canvas and all canvas items in XML format.
504+ public Xml . Node * save( string image_dir, int compression ) {
505+
506+ Xml . Node * node = new Xml .Node ( null , " canvas" );
507+
508+ node- > add_child( image. save( image_dir, compression ) );
509+ node- > add_child( items. save( image_dir ) );
510+
511+ return ( node );
512+
513+ }
514+
515+ // -------------------------------------------------------------
516+ // Loads this canvas and the canvas items from XML format.
517+ public bool load( Xml . Node * node ) {
518+
519+ bool image_loaded = false ;
520+
521+ for ( Xml . Node * it= node- > children; it!= null ; it= it- > next ) {
522+ if ( it- > type == Xml . ElementType . ELEMENT_NODE ) {
523+ switch ( it- > name ) {
524+ case " image" : image_loaded = image. load( it ); break ;
525+ case " items" : items. load( it ); break ;
526+ }
527+ }
528+ }
529+
530+ return ( image_loaded );
531+
532+ }
533+
497534 /* ***************************************************************************/
498535 // DRAWING FUNCTIONS
499536 /* ***************************************************************************/
0 commit comments