[glabels/vala] Implemented box creation mode.



commit 13e370308344f073880a7f4d581e89a667393936
Author: Jim Evins <evins snaught com>
Date:   Mon Mar 5 23:59:40 2012 -0500

    Implemented box creation mode.

 configure.ac                       |    1 +
 glabels/Makefile.am                |    5 +++
 glabels/cursor.vapi                |   17 +++++++++
 glabels/cursors/Makefile.am        |   26 +++++++++++++
 glabels/cursors/cursor_barcode.png |  Bin 0 -> 198 bytes
 glabels/cursors/cursor_box.png     |  Bin 0 -> 200 bytes
 glabels/cursors/cursor_ellipse.png |  Bin 0 -> 243 bytes
 glabels/cursors/cursor_image.png   |  Bin 0 -> 247 bytes
 glabels/cursors/cursor_line.png    |  Bin 0 -> 198 bytes
 glabels/cursors/cursor_text.png    |  Bin 0 -> 210 bytes
 glabels/label_object.vala          |   16 +++++++-
 glabels/ui.vala                    |    7 +---
 glabels/view.vala                  |   71 +++++++++++++++++++++---------------
 13 files changed, 106 insertions(+), 37 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 6e39130..3ced90f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -31,6 +31,7 @@ AC_PROG_LIBTOOL
 
 GNOME_DOC_INIT
 
+AC_PATH_PROG(GDK_PIXBUF_CSOURCE,      gdk-pixbuf-csource)
 AC_PATH_PROG(GTK_UPDATE_ICON_CACHE,   gtk-update-icon-cache)
 
 dnl ---------------------------------------------------------------------------
diff --git a/glabels/Makefile.am b/glabels/Makefile.am
index e7ed4cf..1942e61 100644
--- a/glabels/Makefile.am
+++ b/glabels/Makefile.am
@@ -1,5 +1,9 @@
 NULL = 
 
+SUBDIRS = \
+	cursors \
+	$(NULL)
+
 bin_PROGRAMS = glabels-4
 
 glabels_4_SOURCES = \
@@ -12,6 +16,7 @@ glabels_4_SOURCES = \
 	color_menu_item.vala \
 	color_node.vala \
 	color_swatch.vala \
+	cursor.vapi \
 	enum_util.vala \
 	file.vala \
 	file_util.vala \
diff --git a/glabels/cursor.vapi b/glabels/cursor.vapi
new file mode 100644
index 0000000..fcd8f7b
--- /dev/null
+++ b/glabels/cursor.vapi
@@ -0,0 +1,17 @@
+namespace glabels
+{
+
+	[CCode (prefix = "", lower_case_cprefix = "cursor_", cheader_filename = "cursors/cursor_pixdata.h")]
+	namespace Cursor
+	{
+
+		public Gdk.Pixdata barcode_pixdata;
+		public Gdk.Pixdata box_pixdata;
+		public Gdk.Pixdata ellipse_pixdata;
+		public Gdk.Pixdata image_pixdata;
+		public Gdk.Pixdata line_pixdata;
+		public Gdk.Pixdata text_pixdata;
+
+	}
+
+}
diff --git a/glabels/cursors/Makefile.am b/glabels/cursors/Makefile.am
new file mode 100644
index 0000000..6a01d8e
--- /dev/null
+++ b/glabels/cursors/Makefile.am
@@ -0,0 +1,26 @@
+
+CURSOR_IMAGES =	 			\
+	cursor_barcode.png		\
+	cursor_box.png			\
+	cursor_ellipse.png		\
+	cursor_image.png		\
+	cursor_line.png			\
+	cursor_text.png
+
+VARIABLES1 = \
+	cursor_barcode_pixdata	$(srcdir)/cursor_barcode.png	\
+	cursor_box_pixdata	$(srcdir)/cursor_box.png	\
+	cursor_ellipse_pixdata	$(srcdir)/cursor_ellipse.png	\
+	cursor_image_pixdata	$(srcdir)/cursor_image.png	\
+	cursor_line_pixdata	$(srcdir)/cursor_line.png	\
+	cursor_text_pixdata	$(srcdir)/cursor_text.png
+
+noinst_DATA = cursor_pixdata.h
+CLEANFILES = $(noinst_DATA)
+
+cursor_pixdata.h: $(CURSOR_IMAGES)
+	$(AM_V_GEN) $(GDK_PIXBUF_CSOURCE) \
+	   --struct --build-list $(VARIABLES1) > $(srcdir)/cursor_pixdata.h || \
+           ( rm -f $(srcdir)/cursor_pixdata.h && false )
+
+EXTRA_DIST = $(CURSOR_IMAGES) cursor_pixdata.h
diff --git a/glabels/cursors/cursor_barcode.png b/glabels/cursors/cursor_barcode.png
new file mode 100644
index 0000000..59ba928
Binary files /dev/null and b/glabels/cursors/cursor_barcode.png differ
diff --git a/glabels/cursors/cursor_box.png b/glabels/cursors/cursor_box.png
new file mode 100644
index 0000000..c30c0d4
Binary files /dev/null and b/glabels/cursors/cursor_box.png differ
diff --git a/glabels/cursors/cursor_ellipse.png b/glabels/cursors/cursor_ellipse.png
new file mode 100644
index 0000000..40924af
Binary files /dev/null and b/glabels/cursors/cursor_ellipse.png differ
diff --git a/glabels/cursors/cursor_image.png b/glabels/cursors/cursor_image.png
new file mode 100644
index 0000000..e5b4781
Binary files /dev/null and b/glabels/cursors/cursor_image.png differ
diff --git a/glabels/cursors/cursor_line.png b/glabels/cursors/cursor_line.png
new file mode 100644
index 0000000..31d8c6e
Binary files /dev/null and b/glabels/cursors/cursor_line.png differ
diff --git a/glabels/cursors/cursor_text.png b/glabels/cursors/cursor_text.png
new file mode 100644
index 0000000..cda6b21
Binary files /dev/null and b/glabels/cursors/cursor_text.png differ
diff --git a/glabels/label_object.vala b/glabels/label_object.vala
index 51fce90..7b78618 100644
--- a/glabels/label_object.vala
+++ b/glabels/label_object.vala
@@ -39,7 +39,7 @@ namespace glabels
 		/**
 		 * Parent label
 		 */
-		public Label parent { get; set; }
+		public weak Label parent { get; set; }
 
 
 		/**
@@ -444,7 +444,19 @@ namespace glabels
 			_y0 = 0;
 			_matrix = Cairo.Matrix.identity();
 
-			_line_width = 0;
+			Prefs prefs = new Prefs();
+
+			_font_family             = prefs.default_font_family;
+			_font_size               = prefs.default_font_size;
+			_font_weight             = prefs.default_font_weight;
+			_font_italic_flag        = prefs.default_font_italic_flag;
+			_text_color_node         = ColorNode.from_color( prefs.default_text_color );
+			_text_alignment          = prefs.default_text_alignment;
+			_text_line_spacing       = prefs.default_text_line_spacing;
+
+			_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;
diff --git a/glabels/ui.vala b/glabels/ui.vala
index 7cfefa3..9905f8d 100644
--- a/glabels/ui.vala
+++ b/glabels/ui.vala
@@ -1209,12 +1209,7 @@ namespace glabels
 
 		private void on_objects_create_box( Gtk.Action action )
 		{
-			/*
-			if (window->view != NULL) {
-				gl_view_object_create_mode (GL_VIEW(window->view),
-				                            GL_LABEL_OBJECT_BOX);
-			}
-			*/
+			window.view.create_box_mode();
 		}
 
 
diff --git a/glabels/view.vala b/glabels/view.vala
index 2bc3ac9..7bc2d53 100644
--- a/glabels/view.vala
+++ b/glabels/view.vala
@@ -43,6 +43,9 @@ namespace glabels
 		private const double OUTLINE_WIDTH_PIXELS     = 1;
 		private const double SELECT_LINE_WIDTH_PIXELS = 3;
 
+		private const int CURSOR_X_HOTSPOT = 7;
+		private const int CURSOR_Y_HOTSPOT = 7;
+
 		private const int ZOOMTOFIT_PAD = 16;
 		private const int SHADOW_OFFSET_PIXELS = ZOOMTOFIT_PAD/4;
 
@@ -94,7 +97,8 @@ namespace glabels
 		/* CREATE_DRAG state */
 		private CreateType   create_object_type;
 		private LabelObject? create_object;
-
+		private double       create_x0;
+		private double       create_y0;
 
 
 		public Label  label        { get; private set; }
@@ -344,6 +348,28 @@ namespace glabels
 		}
 
 
+		public void create_box_mode()
+		{
+			Gdk.Window window = canvas.get_window();
+
+			try
+			{
+				Gdk.Pixbuf pixbuf = Gdk.Pixbuf.from_pixdata( Cursor.box_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.BOX;
+			state                 = State.IDLE;
+		}
+
+
 		private void on_prefs_changed()
 		{
 			grid_spacing = UnitsUtil.get_grid_size( prefs.units );
@@ -786,7 +812,9 @@ namespace glabels
 					switch ( create_object_type )
 					{
 					case CreateType.BOX:
-						/* 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.ELLIPSE:
 						/* TODO */
@@ -907,12 +935,14 @@ namespace glabels
 				else
 				{
 
-					if ( state != State.IDLE )
+					if ( state == State.IDLE )
 					{
+						LabelObject object;
+
 						switch ( create_object_type )
 						{
 						case CreateType.BOX:
-							/* TODO */
+							create_object = new LabelObjectBox() as LabelObject;
 							break;
 						case CreateType.ELLIPSE:
 							/* TODO */
@@ -934,6 +964,13 @@ namespace glabels
 							break;
 						}
 
+						create_object.set_position( x, y );
+						create_object.set_size( 0, 0 );
+						label.add_object( create_object );
+
+						create_x0 = x;
+						create_y0 = y;
+
 						state = State.CREATE_DRAG;
 
 						return_value = true;
@@ -1018,34 +1055,10 @@ namespace glabels
 				else
 				{
 
-					switch ( create_object_type )
-					{
-					case CreateType.BOX:
-						/* TODO */
-						break;
-					case CreateType.ELLIPSE:
-						/* TODO */
-						break;
-					case CreateType.LINE: 
-						/* TODO */
-						break;
-					case CreateType.IMAGE:
-						/* TODO */
-						break;
-					case CreateType.TEXT:
-						/* TODO */
-						break;
-					case CreateType.BARCODE:
-						/* TODO */
-						break;
-					default:
-						warning( "Invalid create type." );   /* Should not happen! */
-						break;
-					}
-
 					Gdk.Cursor cursor = new Gdk.Cursor( Gdk.CursorType.LEFT_PTR );
 					window.set_cursor( cursor );
 
+					label.unselect_all();
 					label.select_object( create_object );
 
 					in_object_create_mode = false;



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