Skip to content

Commit 65800ec

Browse files
committed
Fixing more save/load issues with Annotator export.
1 parent 6f4adfe commit 65800ec

12 files changed

+301
-140
lines changed

src/CanvasItem.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ public class CanvasItem {
415415
/****************************************************************************/
416416

417417
/* Saves the item in XML format */
418-
public virtual Xml.Node* save( int id, string? image_dir = null ) {
418+
public virtual Xml.Node* save( int id, string image_dir ) {
419419
Xml.Node* node = new Xml.Node( null, "item" );
420420
node->set_prop( "type", itype.to_string() );
421421
node->set_prop( "x", bbox.x.to_string() );

src/CanvasPoint.vala

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,10 @@ public class CanvasPoint {
187187

188188
//-------------------------------------------------------------
189189
// Saves the contents of this point in XML format.
190-
public Xml.Node* save() {
191-
Xml.Node* node = new Xml.Node( null, "point" );
190+
public Xml.Node* save( string name ) {
191+
Xml.Node* node = new Xml.Node( null, name );
192192
node->set_prop( "x", x.to_string() );
193193
node->set_prop( "y", y.to_string() );
194-
node->set_prop( "kind", kind.to_string() );
195194
return( node );
196195
}
197196

@@ -209,11 +208,6 @@ public class CanvasPoint {
209208
this.y = double.parse( y );
210209
}
211210

212-
var k = node->get_prop( "kind" );
213-
if( k != null ) {
214-
this.kind = CanvasPointType.parse( k );
215-
}
216-
217211
}
218212

219213
}

src/canvas_items/CanvasItemArrow.vala

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,27 @@ public class CanvasItemArrow : CanvasItem {
2929
UPPER_LEFT,
3030
UPPER_RIGHT,
3131
LOWER_LEFT,
32-
LOWER_RIGHT
32+
LOWER_RIGHT;
33+
34+
public string to_string() {
35+
switch( this ) {
36+
case UPPER_LEFT : return( "ul" );
37+
case UPPER_RIGHT : return( "ur" );
38+
case LOWER_LEFT : return( "ll" );
39+
case LOWER_RIGHT : return( "lr" );
40+
default : assert_not_reached();
41+
}
42+
}
43+
44+
public static ArrowHeadDirection parse( string val ) {
45+
switch( val ) {
46+
case "ul" : return( UPPER_LEFT );
47+
case "ur" : return( UPPER_RIGHT );
48+
case "ll" : return( LOWER_LEFT );
49+
case "lr" : return( LOWER_RIGHT );
50+
default : return( UPPER_LEFT );
51+
}
52+
}
3353
}
3454

3555
private enum PType {
@@ -48,14 +68,16 @@ public class CanvasItemArrow : CanvasItem {
4868
private ArrowHeadDirection _dir = ArrowHeadDirection.UPPER_LEFT;
4969
private Cursor _sel_cursor;
5070

51-
/* Constructor */
71+
//-------------------------------------------------------------
72+
// Constructor
5273
public CanvasItemArrow( Canvas canvas, CanvasItemProperties props ) {
5374
base( CanvasItemType.ARROW, canvas, props );
5475
create_points();
5576
_sel_cursor = new Cursor.from_name( "crosshair", null );
5677
}
5778

58-
/* Creates the selection points */
79+
//-------------------------------------------------------------
80+
// Creates the selection points.
5981
private void create_points() {
6082
points.append_val( new CanvasPoint( CanvasPointType.RESIZER0 ) );
6183
points.append_val( new CanvasPoint( CanvasPointType.RESIZER0 ) );
@@ -65,7 +87,8 @@ public class CanvasItemArrow : CanvasItem {
6587
points.append_val( new CanvasPoint() );
6688
}
6789

68-
/* Copies the given arrow item properties to this one */
90+
//-------------------------------------------------------------
91+
// Copies the given arrow item properties to this one.
6992
public override void copy( CanvasItem item ) {
7093
base.copy( item );
7194
var arrow_item = (CanvasItemArrow)item;
@@ -74,17 +97,20 @@ public class CanvasItemArrow : CanvasItem {
7497
_peak_c = arrow_item._peak_c;
7598
_valley_a = arrow_item._valley_a;
7699
_valley_c = arrow_item._valley_c;
100+
_dir = arrow_item._dir;
77101
}
78102
}
79103

80-
/* Creates a duplicate of this item and returns it */
104+
//-------------------------------------------------------------
105+
// Creates a duplicate of this item and returns it.
81106
public override CanvasItem duplicate() {
82107
var item = new CanvasItemArrow( canvas, props );
83108
item.copy( this );
84109
return( item );
85110
}
86111

87-
/* Updates the selection boxes whenever the bounding box changes */
112+
//-------------------------------------------------------------
113+
// Updates the selection boxes whenever the bounding box changes.
88114
protected override void bbox_changed() {
89115

90116
double pvw, pvh, ppw, pph;
@@ -133,7 +159,9 @@ public class CanvasItemArrow : CanvasItem {
133159

134160
}
135161

136-
/* Calculates the width and height values for a peak/valley which are used in adjusting the selector */
162+
//-------------------------------------------------------------
163+
// Calculates the width and height values for a peak/valley
164+
// which are used in adjusting the selector.
137165
private void calc_flight_point( double a, double c, bool primary, out double width, out double height ) {
138166

139167
var spine_a = Math.atan( bbox.height / bbox.width );
@@ -143,7 +171,9 @@ public class CanvasItemArrow : CanvasItem {
143171

144172
}
145173

146-
/* Adjusts the valley/peak length and angle based on the placement of the associated selector */
174+
//-------------------------------------------------------------
175+
// Adjusts the valley/peak length and angle based on the
176+
// placement of the associated selector.
147177
private void adjust_flight_point( int selector_index, ref double a, ref double c ) {
148178

149179
var point = points.index( selector_index );
@@ -170,7 +200,8 @@ public class CanvasItemArrow : CanvasItem {
170200

171201
}
172202

173-
/* Adjusts the bounding box */
203+
//-------------------------------------------------------------
204+
// Adjusts the bounding box.
174205
public override void move_selector( int index, double diffx, double diffy, bool shift ) {
175206

176207
double w = 0, h = 0;
@@ -242,22 +273,27 @@ public class CanvasItemArrow : CanvasItem {
242273

243274
}
244275

245-
/* Provides cursor to display when mouse cursor is hovering over the given selector */
276+
//-------------------------------------------------------------
277+
// Provides cursor to display when mouse cursor is hovering
278+
// over the given selector.
246279
public override Cursor? get_selector_cursor( int index ) {
247280
return( _sel_cursor );
248281
}
249282

250-
/* Saves this item as XML */
251-
public override Xml.Node* save( int id, string? image_dir ) {
283+
//-------------------------------------------------------------
284+
// Saves this item as XML.
285+
public override Xml.Node* save( int id, string image_dir ) {
252286
Xml.Node* node = base.save( id, image_dir );
253287
node->set_prop( "peak-angle", _peak_a.to_string() );
254288
node->set_prop( "peak-length", _peak_c.to_string() );
255289
node->set_prop( "valley-angle", _valley_a.to_string() );
256290
node->set_prop( "valley-length", _valley_c.to_string() );
291+
node->set_prop( "dir", _dir.to_string() );
257292
return( node );
258293
}
259294

260-
/* Loads this item from XML */
295+
//-------------------------------------------------------------
296+
// Loads this item from XML.
261297
public override void load( Xml.Node* node ) {
262298
var pa = node->get_prop( "peak-angle" );
263299
if( pa != null ) {
@@ -275,10 +311,15 @@ public class CanvasItemArrow : CanvasItem {
275311
if( vc != null ) {
276312
_valley_c = double.parse( vc );
277313
}
314+
var d = node->get_prop( "dir" );
315+
if( d != null ) {
316+
_dir = ArrowHeadDirection.parse( d );
317+
}
278318
base.load( node );
279319
}
280320

281-
/* Draw the rectangle */
321+
//-------------------------------------------------------------
322+
// Draw the rectangle.
282323
public override void draw_item( Context ctx, CanvasItemColor color ) {
283324

284325
var alpha = mode.alpha( props.alpha );
@@ -308,5 +349,3 @@ public class CanvasItemArrow : CanvasItem {
308349
}
309350

310351
}
311-
312-

src/canvas_items/CanvasItemBlur.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public class CanvasItemBlur : CanvasItem {
130130

131131
//-------------------------------------------------------------
132132
// Saves the description of this blur item in XML format.
133-
public override Xml.Node* save( int id, string? image_dir ) {
133+
public override Xml.Node* save( int id, string image_dir ) {
134134
Xml.Node* node = base.save( id, image_dir );
135135
node->set_prop( "radius", blur_radius.to_string() );
136136
return( node );

src/canvas_items/CanvasItemBubble.vala

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public class CanvasItemBubble : CanvasItem {
5858
private Cursor[] _sel_cursors;
5959
private CanvasBubbleType _type;
6060
private bool _point_moved = false;
61-
private bool _base_moved = false;
6261
private double _radius = 40.0;
6362

6463
/* Constructor */
@@ -97,7 +96,6 @@ public class CanvasItemBubble : CanvasItem {
9796
if( bubble_item != null ) {
9897
_type = bubble_item._type;
9998
_point_moved = bubble_item._point_moved;
100-
_base_moved = bubble_item._base_moved;
10199
}
102100
}
103101

@@ -161,9 +159,10 @@ public class CanvasItemBubble : CanvasItem {
161159

162160
//-------------------------------------------------------------
163161
// Saves the description of this item in XML format.
164-
public override Xml.Node* save( int id, string? image_dir ) {
162+
public override Xml.Node* save( int id, string image_dir ) {
165163
Xml.Node* node = base.save( id, image_dir );
166164
node->set_prop( "type", _type.to_string() );
165+
node->add_child( points.index( 8 ).save( "talk-point" ) );
167166
return( node );
168167
}
169168

@@ -174,10 +173,18 @@ public class CanvasItemBubble : CanvasItem {
174173
if( t != null ) {
175174
_type = CanvasBubbleType.parse( t );
176175
}
176+
for( Xml.Node* it=node->children; it!=null; it=it->next ) {
177+
if( (it->type == Xml.ElementType.ELEMENT_NODE) && (it->name == "talk-point") ) {
178+
points.index( 8 ).load( it );
179+
_point_moved = true;
180+
}
181+
}
177182
base.load( node );
178183
}
179184

180-
/* Helper function that finds the two tangential points on a circle to a given point */
185+
//-------------------------------------------------------------
186+
// Helper function that finds the two tangential points on a
187+
// circle to a given point.
181188
private bool find_tangents( CanvasPoint center, double radius, CanvasPoint external, CanvasPoint pt1, CanvasPoint pt2 ) {
182189

183190
var dx = center.x - external.x;
@@ -193,7 +200,9 @@ public class CanvasItemBubble : CanvasItem {
193200

194201
}
195202

196-
/* Helper function that finds the two points where two circles intersect */
203+
//-------------------------------------------------------------
204+
// Helper function that finds the two points where two circles
205+
// intersect.
197206
private bool find_circle_circle_intersections( CanvasPoint c0, double r0, CanvasPoint c1, double r1, CanvasPoint pt1, CanvasPoint pt2 ) {
198207

199208
var dx = c0.x - c1.x;

src/canvas_items/CanvasItemImage.vala

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,24 @@ public class CanvasItemImage : CanvasItem {
3030
private Pixbuf? _buf = null;
3131
private Cursor _sel_cursor;
3232

33-
/* Constructor */
33+
//-------------------------------------------------------------
34+
// Constructor.
3435
public CanvasItemImage( Canvas canvas, string? name, bool file, CanvasItemProperties props ) {
3536
base( (file ? CanvasItemType.IMAGE : CanvasItemType.STICKER), canvas, props );
3637
create_points();
3738
create_image( name, file, (file ? 300 : 64) );
3839
_sel_cursor = new Cursor.from_name( "se-resize", null );
3940
}
4041

41-
/* Creates the item points */
42+
//-------------------------------------------------------------
43+
// Creates the item points.
4244
private void create_points() {
4345
points.append_val( new CanvasPoint( CanvasPointType.RESIZER0 ) ); // Resizer
4446
}
4547

46-
/* Creates a pixbuf from the given filename or resource at full size */
48+
//-------------------------------------------------------------
49+
// Creates a pixbuf from the given filename or resource at full
50+
// size.
4751
private void create_image( string? name, bool file, int width ) {
4852
if( name == null ) return;
4953
try {
@@ -61,14 +65,16 @@ public class CanvasItemImage : CanvasItem {
6165
}
6266
}
6367

64-
/* Creates an image from the specified filename */
68+
//-------------------------------------------------------------
69+
// Creates an image from the specified filename.
6570
private void resize_image( int width = 0 ) {
6671
if( (_buf != null) && (width != 0) ) {
6772
create_image( _name, _file, width );
6873
}
6974
}
7075

71-
/* Copies the contents of the given item to ourselves */
76+
//-------------------------------------------------------------
77+
// Copies the contents of the given item to ourselves.
7278
public override void copy( CanvasItem item ) {
7379
base.copy( item );
7480
var img_item = (CanvasItemImage)item;
@@ -80,14 +86,16 @@ public class CanvasItemImage : CanvasItem {
8086
}
8187
}
8288

83-
/* Returns a copy of this item */
89+
//-------------------------------------------------------------
90+
// Returns a copy of this item.
8491
public override CanvasItem duplicate() {
8592
var item = new CanvasItemImage( canvas, _name, _file, props );
8693
item.copy( this );
8794
return( item );
8895
}
8996

90-
/* Updates the selection boxes whenever the bounding box changes */
97+
//-------------------------------------------------------------
98+
// Updates the selection boxes whenever the bounding box changes.
9199
protected override void bbox_changed() {
92100

93101
points.index( 0 ).copy_coords( bbox.x2(), bbox.y2() );
@@ -98,7 +106,8 @@ public class CanvasItemImage : CanvasItem {
98106

99107
}
100108

101-
/* Adjusts the bounding box */
109+
//-------------------------------------------------------------
110+
// Adjusts the bounding box.
102111
public override void move_selector( int index, double diffx, double diffy, bool shift ) {
103112

104113
var box = new CanvasRect.from_rect( bbox );
@@ -113,14 +122,16 @@ public class CanvasItemImage : CanvasItem {
113122

114123
}
115124

116-
/* Provides cursor to display when mouse cursor is hovering over the given selector */
125+
//-------------------------------------------------------------
126+
// Provides cursor to display when mouse cursor is hovering over
127+
// the given selector.
117128
public override Cursor? get_selector_cursor( int index ) {
118129
return( _sel_cursor );
119130
}
120131

121132
//-------------------------------------------------------------
122133
// Saves this item as XML.
123-
public override Xml.Node* save( int id, string? image_dir ) {
134+
public override Xml.Node* save( int id, string image_dir ) {
124135
Xml.Node* node = base.save( id, image_dir );
125136
if( (image_dir != null) && _file ) {
126137
string[] options = { "compression" };
@@ -140,7 +151,8 @@ public class CanvasItemImage : CanvasItem {
140151
return( node );
141152
}
142153

143-
/* Loads this item from XML */
154+
//-------------------------------------------------------------
155+
// Loads this item from XML.
144156
public override void load( Xml.Node* node ) {
145157
var n = node->get_prop( "name" );
146158
if( n != null ) {
@@ -154,7 +166,8 @@ public class CanvasItemImage : CanvasItem {
154166
base.load( node );
155167
}
156168

157-
/* Draw the rectangle */
169+
//-------------------------------------------------------------
170+
// Draw the rectangle.
158171
public override void draw_item( Context ctx, CanvasItemColor color ) {
159172

160173
ctx.set_line_width( 0 );

0 commit comments

Comments
 (0)