[glabels/vala] Box and ellipse subclassed to shape object.



commit cc8c2ad404c90a4005e8487aa2173c73e6103835
Author: Jim Evins <evins snaught com>
Date:   Sun Aug 5 11:43:58 2012 -0400

    Box and ellipse subclassed to shape object.

 glabels/Makefile.am               |    2 +
 glabels/label_object.vala         |   63 +-----------------
 glabels/label_object_box.vala     |   36 +----------
 glabels/label_object_ellipse.vala |   35 +----------
 glabels/label_object_shape.vala   |  124 +++++++++++++++++++++++++++++++++++++
 glabels/object_editor.vala        |   12 ++++
 glabels/ui.vala                   |    7 +--
 glabels/view.vala                 |   28 ++++++++-
 glabels/xml_label.vala            |   91 +++++++++++++++++++++++++++-
 9 files changed, 263 insertions(+), 135 deletions(-)
---
diff --git a/glabels/Makefile.am b/glabels/Makefile.am
index c0ff975..906ec55 100644
--- a/glabels/Makefile.am
+++ b/glabels/Makefile.am
@@ -33,6 +33,8 @@ glabels_4_SOURCES = \
 	label.vala \
 	label_object.vala \
 	label_object_box.vala \
+	label_object_ellipse.vala \
+	label_object_shape.vala \
 	label_object_text.vala \
 	label_region.vala \
 	label_state.vala \
diff --git a/glabels/label_object.vala b/glabels/label_object.vala
index ab11eee..0cf6849 100644
--- a/glabels/label_object.vala
+++ b/glabels/label_object.vala
@@ -156,60 +156,11 @@ namespace glabels
 
 
 		/**
-		 * Line width
+		 * Shape parameters interface
 		 */
-		public double line_width
-		{
-			get { return _line_width; }
-
-			set
-			{
-				if ( _line_width != value )
-				{
-					_line_width = value;
-					changed();
-				}
-			}
-		}
-		private double _line_width;
-
-
-		/**
-		 * Line color node
-		 */
-		public ColorNode line_color_node
-		{
-			get { return _line_color_node; }
-
-			set
-			{
-				if ( _line_color_node != value )
-				{
-					_line_color_node = value;
-					changed();
-				}
-			}
-		}
-		private ColorNode _line_color_node;
-
-
-		/**
-		 * Fill color node
-		 */
-		public ColorNode fill_color_node
-		{
-			get { return _fill_color_node; }
-
-			set
-			{
-				if ( _fill_color_node != value )
-				{
-					_fill_color_node = value;
-					changed();
-				}
-			}
-		}
-		private ColorNode _fill_color_node;
+		public virtual double          line_width          { get; set; }
+		public virtual ColorNode       line_color_node     { get; set; }
+		public virtual ColorNode       fill_color_node     { get; set; }
 
 
 		/**
@@ -327,12 +278,6 @@ namespace glabels
 			_y0 = 0;
 			_matrix = Cairo.Matrix.identity();
 
-			Prefs prefs = new Prefs();
-
-			_line_width              = prefs.default_line_width;
-			_line_color_node         = ColorNode.from_color( prefs.default_line_color );
-			_fill_color_node         = ColorNode.from_color( prefs.default_fill_color );
-
 			_shadow_state            = false;
 			_shadow_x                = 3.6;
 			_shadow_y                = 3.6;
diff --git a/glabels/label_object_box.vala b/glabels/label_object_box.vala
index 661dc59..af1ca2f 100644
--- a/glabels/label_object_box.vala
+++ b/glabels/label_object_box.vala
@@ -1,6 +1,6 @@
 /*  label_object_box.vala
  *
- *  Copyright (C) 2011  Jim Evins <evins snaught com>
+ *  Copyright (C) 2012  Jim Evins <evins snaught com>
  *
  *  This file is part of gLabels.
  *
@@ -24,38 +24,9 @@ using GLib;
 namespace glabels
 {
 
-	public class LabelObjectBox : LabelObject
+	public class LabelObjectBox : LabelObjectShape
 	{
 
-		public LabelObjectBox()
-		{
-			handles.append( new HandleSouthEast( this ) );
-			handles.append( new HandleSouthWest( this ) );
-			handles.append( new HandleNorthEast( this ) );
-			handles.append( new HandleNorthWest( this ) );
-			handles.append( new HandleEast( this ) );
-			handles.append( new HandleSouth( this ) );
-			handles.append( new HandleWest( this ) );
-			handles.append( new HandleNorth( this ) );
-		}
-
-
-		public override bool can_fill()
-		{
-			return true;
-		}
-
-		public override bool can_line_color()
-		{
-			return true;
-		}
-
-		public override bool can_line_width()
-		{
-			return true;
-		}
-
-
 		public override LabelObject dup()
 		{
 			LabelObjectBox copy = new LabelObjectBox();
@@ -170,9 +141,6 @@ namespace glabels
 		}
 
 
-		// TODO: get_handle_at method.
-
-
 	}
 
 }
diff --git a/glabels/label_object_ellipse.vala b/glabels/label_object_ellipse.vala
index 4dee05c..7a21ed0 100644
--- a/glabels/label_object_ellipse.vala
+++ b/glabels/label_object_ellipse.vala
@@ -24,38 +24,10 @@ using GLib;
 namespace glabels
 {
 
-	public class LabelObjectEllipse : LabelObject
+	public class LabelObjectEllipse : LabelObjectShape
 	{
-		private const int ARC_FINE = 2;
-
-
-		public LabelObjectEllipse()
-		{
-			handles.append( new HandleSouthEast( this ) );
-			handles.append( new HandleSouthWest( this ) );
-			handles.append( new HandleNorthEast( this ) );
-			handles.append( new HandleNorthWest( this ) );
-			handles.append( new HandleEast( this ) );
-			handles.append( new HandleSouth( this ) );
-			handles.append( new HandleWest( this ) );
-			handles.append( new HandleNorth( this ) );
-		}
-
-
-		public override bool can_fill()
-		{
-			return true;
-		}
 
-		public override bool can_line_color()
-		{
-			return true;
-		}
-
-		public override bool can_line_width()
-		{
-			return true;
-		}
+		private const int ARC_FINE = 2;
 
 
 		public override LabelObject dup()
@@ -197,9 +169,6 @@ namespace glabels
 		}
 
 
-		// TODO: get_handle_at method.
-
-
 	}
 
 }
diff --git a/glabels/label_object_shape.vala b/glabels/label_object_shape.vala
new file mode 100644
index 0000000..e818659
--- /dev/null
+++ b/glabels/label_object_shape.vala
@@ -0,0 +1,124 @@
+/*  label_object_shape.vala
+ *
+ *  Copyright (C) 2012  Jim Evins <evins snaught com>
+ *
+ *  This file is part of gLabels.
+ *
+ *  gLabels is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  gLabels is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+using GLib;
+
+namespace glabels
+{
+
+	public abstract class LabelObjectShape : LabelObject
+	{
+
+		/**
+		 * Line width
+		 */
+		public override double line_width
+		{
+			get { return _line_width; }
+
+			set
+			{
+				if ( _line_width != value )
+				{
+					_line_width = value;
+					changed();
+				}
+			}
+		}
+		private double _line_width;
+
+
+		/**
+		 * Line color node
+		 */
+		public override ColorNode line_color_node
+		{
+			get { return _line_color_node; }
+
+			set
+			{
+				if ( _line_color_node != value )
+				{
+					_line_color_node = value;
+					changed();
+				}
+			}
+		}
+		private ColorNode _line_color_node;
+
+
+		/**
+		 * Fill color node
+		 */
+		public override ColorNode fill_color_node
+		{
+			get { return _fill_color_node; }
+
+			set
+			{
+				if ( _fill_color_node != value )
+				{
+					_fill_color_node = value;
+					changed();
+				}
+			}
+		}
+		private ColorNode _fill_color_node;
+
+
+		public LabelObjectShape()
+		{
+			handles.append( new HandleSouthEast( this ) );
+			handles.append( new HandleSouthWest( this ) );
+			handles.append( new HandleNorthEast( this ) );
+			handles.append( new HandleNorthWest( this ) );
+			handles.append( new HandleEast( this ) );
+			handles.append( new HandleSouth( this ) );
+			handles.append( new HandleWest( this ) );
+			handles.append( new HandleNorth( this ) );
+
+			Prefs prefs = new Prefs();
+
+			_line_width              = prefs.default_line_width;
+			_line_color_node         = ColorNode.from_color( prefs.default_line_color );
+			_fill_color_node         = ColorNode.from_color( prefs.default_fill_color );
+		}
+
+
+		public override bool can_fill()
+		{
+			return true;
+		}
+
+		public override bool can_line_color()
+		{
+			return true;
+		}
+
+		public override bool can_line_width()
+		{
+			return true;
+		}
+
+
+	}
+
+}
diff --git a/glabels/object_editor.vala b/glabels/object_editor.vala
index bee6328..77d0639 100644
--- a/glabels/object_editor.vala
+++ b/glabels/object_editor.vala
@@ -394,6 +394,18 @@ namespace glabels
 
 					size_reset_image_button.hide();
 				}
+				else if ( object is LabelObjectEllipse  )
+				{
+					title_image.set_from_icon_name( "glabels-ellipse", Gtk.IconSize.LARGE_TOOLBAR );
+					title_label.set_text( "<b>%s</b>".printf( _("Ellipse object properties") ) );
+
+					text_page_box.hide();
+					line_fill_page_box.show_all();
+					pos_size_page_box.show_all();
+					shadow_page_box.show_all();
+
+					size_reset_image_button.hide();
+				}
 				else
 				{
 					assert_not_reached();
diff --git a/glabels/ui.vala b/glabels/ui.vala
index d2037a2..3aec5f8 100644
--- a/glabels/ui.vala
+++ b/glabels/ui.vala
@@ -1175,12 +1175,7 @@ namespace glabels
 
 		private void on_objects_create_ellipse( Gtk.Action action )
 		{
-			/*
-			if (window->view != NULL) {
-				gl_view_object_create_mode (GL_VIEW(window->view),
-				                            GL_LABEL_OBJECT_ELLIPSE);
-			}
-			*/
+			window.view.create_ellipse_mode();
 		}
 
 
diff --git a/glabels/view.vala b/glabels/view.vala
index 55f568f..d9515c2 100644
--- a/glabels/view.vala
+++ b/glabels/view.vala
@@ -385,6 +385,28 @@ namespace glabels
 		}
 
 
+		public void create_ellipse_mode()
+		{
+			Gdk.Window window = canvas.get_window();
+
+			try
+			{
+				Gdk.Pixbuf pixbuf = Gdk.Pixbuf.from_pixdata( Cursor.ellipse_pixdata, false );
+				Gdk.Cursor cursor = new Gdk.Cursor.from_pixbuf( Gdk.Display.get_default(),
+				                                                pixbuf, CURSOR_X_HOTSPOT, CURSOR_Y_HOTSPOT );
+				window.set_cursor( cursor );
+			}
+			catch ( Error err )
+			{
+				error( "%s\n", err.message );
+			}
+
+			in_object_create_mode = true;
+			create_object_type    = CreateType.ELLIPSE;
+			state                 = State.IDLE;
+		}
+
+
 		public void create_text_mode()
 		{
 			Gdk.Window window = canvas.get_window();
@@ -857,7 +879,9 @@ namespace glabels
 						                        double.max( y, create_y0 ) - double.min( y, create_y0 ) );
 						break;
 					case CreateType.ELLIPSE:
-						/* TODO */
+						create_object.set_position( double.min( x, create_x0 ), double.min( y, create_y0 ) );
+						create_object.set_size( double.max( x, create_x0 ) - double.min( x, create_x0 ),
+						                        double.max( y, create_y0 ) - double.min( y, create_y0 ) );
 						break;
 					case CreateType.LINE: 
 						/* TODO */
@@ -985,7 +1009,7 @@ namespace glabels
 							create_object = new LabelObjectBox() as LabelObject;
 							break;
 						case CreateType.ELLIPSE:
-							/* TODO */
+							create_object = new LabelObjectEllipse() as LabelObject;
 							break;
 						case CreateType.LINE: 
 							/* TODO */
diff --git a/glabels/xml_label.vala b/glabels/xml_label.vala
index fad305b..f882558 100644
--- a/glabels/xml_label.vala
+++ b/glabels/xml_label.vala
@@ -190,7 +190,7 @@ namespace glabels
 					break;
 
 				case "Object-ellipse":
-					/* TODO. */
+					parse_object_ellipse_node( child, label );
 					break;
 
 				case "Object-line":
@@ -263,6 +263,48 @@ namespace glabels
 		}
 
 
+		private void parse_object_ellipse_node( Xml.Node node,
+		                                        Label    label )
+		{
+			LabelObjectEllipse object = new LabelObjectEllipse();
+
+		
+			/* position attrs */
+			object.x0 = XmlUtil.get_prop_length( node, "x", 0.0 );
+			object.y0 = XmlUtil.get_prop_length( node, "y", 0.0 );
+
+			/* size attrs */
+			object.w = XmlUtil.get_prop_length( node, "w", 0 );
+			object.h = XmlUtil.get_prop_length( node, "h", 0 );
+
+			/* line attrs */
+			object.line_width = XmlUtil.get_prop_length( node, "line_width", 1.0 );
+	
+			{
+				string key        = XmlUtil.get_prop_string( node, "line_color_field", null );
+				bool   field_flag = key != null;
+				Color  color      = Color.from_legacy_color( XmlUtil.get_prop_uint( node, "line_color", 0 ) );
+				object.line_color_node = ColorNode( field_flag, color, key );
+			}
+
+			/* fill attrs */
+			{
+				string key        = XmlUtil.get_prop_string( node, "fill_color_field", null );
+				bool   field_flag = key != null;
+				Color  color      = Color.from_legacy_color( XmlUtil.get_prop_uint( node, "fill_color", 0 ) );
+				object.fill_color_node = ColorNode( field_flag, color, key );
+			}
+	
+			/* affine attrs */
+			parse_affine_attrs( node, object );
+
+			/* shadow attrs */
+			parse_shadow_attrs( node, object );
+
+			label.add_object( object );
+		}
+
+
 		private void parse_object_text_node( Xml.Node node,
 		                                     Label    label )
 		{
@@ -512,6 +554,10 @@ namespace glabels
 				{
 					create_object_box_node( node, ns, (LabelObjectBox)object );
 				}
+				else if ( object is LabelObjectEllipse )
+				{
+					create_object_ellipse_node( node, ns, (LabelObjectEllipse)object );
+				}
 				else if ( object is LabelObjectText )
 				{
 					create_object_text_node( node, ns, (LabelObjectText)object );
@@ -567,6 +613,49 @@ namespace glabels
 		}
 
 
+		private void create_object_ellipse_node( Xml.Node           parent,
+		                                         Xml.Ns             ns,
+		                                         LabelObjectEllipse object )
+		{
+			unowned Xml.Node *node = parent.new_child( ns, "Object-ellipse" );
+
+			/* position attrs */
+			XmlUtil.set_prop_length( node, "x", object.x0 );
+			XmlUtil.set_prop_length( node, "y", object.y0 );
+
+			/* size attrs */
+			XmlUtil.set_prop_length( node, "w", object.w );
+			XmlUtil.set_prop_length( node, "h", object.h );
+
+			/* line attrs */
+			XmlUtil.set_prop_length( node, "line_width", object.line_width );
+			if ( object.line_color_node.field_flag )
+			{
+				XmlUtil.set_prop_string( node, "line_color_field", object.line_color_node.key );
+			}
+			else
+			{
+				XmlUtil.set_prop_uint_hex( node, "line_color", object.line_color_node.color.to_legacy_color() );
+			}
+
+			/* fill attrs */
+			if ( object.fill_color_node.field_flag )
+			{
+				XmlUtil.set_prop_string( node, "fill_color_field", object.fill_color_node.key );
+			}
+			else
+			{
+				XmlUtil.set_prop_uint_hex( node, "fill_color", object.fill_color_node.color.to_legacy_color() );
+			}
+
+			/* affine attrs */
+			create_affine_attrs( node, object );
+
+			/* shadow attrs */
+			create_shadow_attrs( node, object );
+		}
+
+
 		private void create_object_text_node( Xml.Node        parent,
 		                                      Xml.Ns          ns,
 		                                      LabelObjectText object )



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]