@@ -34,7 +34,8 @@ public enum CanvasPointType {
3434 CONTROL,
3535 SELECTOR ;
3636
37- /* Returns the string version of this type */
37+ // -------------------------------------------------------------
38+ // Returns the string version of this type.
3839 public string to_string () {
3940 switch ( this ) {
4041 case RESIZER0 : return ( " resizer0" );
@@ -51,7 +52,26 @@ public enum CanvasPointType {
5152 }
5253 }
5354
54- /* Returns the hidden/shown version of the current type */
55+ // -------------------------------------------------------------
56+ // Parses the given string and returns its CanvasPointType value.
57+ public static CanvasPointType parse ( string value ) {
58+ switch ( value ) {
59+ case " resizer0" : return ( RESIZER0 );
60+ case " resizer1" : return ( RESIZER1 );
61+ case " resizer2" : return ( RESIZER2 );
62+ case " resizer3" : return ( RESIZER3 );
63+ case " hidden0" : return ( HIDDEN0 );
64+ case " hidden1" : return ( HIDDEN1 );
65+ case " hidden2" : return ( HIDDEN2 );
66+ case " hidden3" : return ( HIDDEN3 );
67+ case " control" : return ( CONTROL );
68+ case " selector" : return ( SELECTOR );
69+ default : return ( NONE );
70+ }
71+ }
72+
73+ // -------------------------------------------------------------
74+ // Returns the hidden/shown version of the current type.
5575 public CanvasPointType version ( bool hide ) {
5676 switch ( this ) {
5777 case RESIZER0 : return ( hide ? HIDDEN0 : RESIZER0 );
@@ -66,12 +86,14 @@ public enum CanvasPointType {
6686 }
6787 }
6888
69- /* Returns true if this point should be drawn */
89+ // -------------------------------------------------------------
90+ // Returns true if this point should be drawn.
7091 public bool draw () {
7192 return ( (this == RESIZER0 ) || (this == RESIZER1 ) || (this == RESIZER2 ) || (this == RESIZER3 ) || (this == CONTROL ) || (this == SELECTOR ) );
7293 }
7394
74- /* Returns the color to draw the given point */
95+ // -------------------------------------------------------------
96+ // Returns the color to draw the given point.
7597 public Gdk .RGBA color () {
7698 switch ( this ) {
7799 case SELECTOR :
@@ -88,7 +110,8 @@ public enum CanvasPointType {
88110 }
89111 }
90112
91- /* Returns true if the kind is hidden */
113+ // -------------------------------------------------------------
114+ // Returns true if the kind is hidden.
92115 public bool is_hidden () {
93116 return ( (this == HIDDEN0 ) || (this == HIDDEN1 ) || (this == HIDDEN2 ) || (this == HIDDEN3 ) );
94117 }
@@ -101,57 +124,97 @@ public class CanvasPoint {
101124 public double y { get ; set ; default = 0.0 ; }
102125 public CanvasPointType kind { get ; private set ; default = CanvasPointType . NONE ; }
103126
104- /* Constructor */
127+ // -------------------------------------------------------------
128+ // Constructor.
105129 public CanvasPoint ( CanvasPointType kind = CanvasPointType .NONE ) {
106130 this . kind = kind;
107131 }
108132
109- /* Copy constructor */
133+ // -------------------------------------------------------------
134+ // Copy constructor
110135 public CanvasPoint.from_point ( CanvasPoint point ) {
111136 copy( point );
112137 }
113138
114- /* Constructor */
139+ // -------------------------------------------------------------
140+ // Constructor.
115141 public CanvasPoint.from_coords ( double x , double y , CanvasPointType kind = CanvasPointType .NONE ) {
116142 copy_coords( x, y );
117143 this . kind = kind;
118144 }
119145
120- /* Copies the point information to this instance */
146+ // -------------------------------------------------------------
147+ // Copies the point information to this instance.
121148 public void copy ( CanvasPoint point ) {
122149 this . x = point. x;
123150 this . y = point. y;
124151 this . kind = point. kind;
125152 }
126153
127- /* Copies the x,y coordinates to this instance */
154+ // -------------------------------------------------------------
155+ // Copies the x,y coordinates to this instance.
128156 public void copy_coords ( double x , double y ) {
129157 this . x = x;
130158 this . y = y;
131159 }
132160
133- /* Adjust the point by the given amounts */
161+ // -------------------------------------------------------------
162+ // Adjust the point by the given amounts.
134163 public void adjust ( double diffx , double diffy ) {
135164 this . x + = diffx;
136165 this . y + = diffy;
137166 }
138167
139- /* Resets the visual aspect of this point to non-hidden state */
168+ // -------------------------------------------------------------
169+ // Resets the visual aspect of this point to non-hidden state.
140170 public void reset_visual () {
141171 kind = kind. version( false );
142172 }
143173
144- /* Updates the visual status of this point kind */
174+ // -------------------------------------------------------------
175+ // Updates the visual status of this point kind.
145176 public void set_visual ( CanvasPointType point_kind , bool hide ) {
146177 if ( point_kind != kind ) {
147178 kind = kind. version( hide );
148179 }
149180 }
150181
151- /* Returns a printable version of this point */
182+ // -------------------------------------------------------------
183+ // Returns a printable version of this point.
152184 public string to_string () {
153185 return ( " x: %g , y: %g , kind: %s " . printf( x, y, kind. to_string() ) );
154186 }
155187
188+ // -------------------------------------------------------------
189+ // Saves the contents of this point in XML format.
190+ public Xml .Node * save () {
191+ Xml . Node * node = new Xml .Node ( null , " point" );
192+ node- > set_prop( " x" , x. to_string() );
193+ node- > set_prop( " y" , y. to_string() );
194+ node- > set_prop( " kind" , kind. to_string() );
195+ return ( node );
196+ }
197+
198+ // -------------------------------------------------------------
199+ // Loads the contents of this point
200+ public void load ( Xml .Node * node ) {
201+
202+ var x = node- > get_prop( " x" );
203+ if ( x != null ) {
204+ this . x = double . parse( x );
205+ }
206+
207+ var y = node- > get_prop( " y" );
208+ if ( y != null ) {
209+ this . y = double . parse( y );
210+ }
211+
212+ var k = node- > get_prop( " kind" );
213+ if ( k != null ) {
214+ this . kind = CanvasPointType . parse( k );
215+ }
216+
217+ }
218+
156219}
157220
0 commit comments