@@ -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-
0 commit comments