]> git.sur5r.net Git - glabels/blobdiff - src/label-line.c
Imported Upstream version 3.0.0
[glabels] / src / label-line.c
index b3eae407df7ba7dc72dfe0f51dedc5f79e0f455e..c88e2ed352ca4396fe1155f979ca4aea044e5fb9 100644 (file)
@@ -1,35 +1,31 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
-
 /*
- *  (GLABELS) Label and Business Card Creation program for GNOME
- *
- *  label_line.c:  GLabels label line object
+ *  label-line.c
+ *  Copyright (C) 2001-2009  Jim Evins <evins@snaught.com>.
  *
- *  Copyright (C) 2001-2007  Jim Evins <evins@snaught.com>.
+ *  This file is part of gLabels.
  *
- *  This program is free software; you can redistribute it and/or modify
+ *  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 2 of the License, or
+ *  the Free Software Foundation, either version 3 of the License, or
  *  (at your option) any later version.
  *
- *  This program is distributed in the hope that it will be useful,
+ *  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 this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include "label-line.h"
 
-#include <glib/gmem.h>
-#include <glib/gstrfuncs.h>
-#include <glib/gmessages.h>
+#include <glib/gi18n.h>
+#include <glib.h>
 
 #include "debug.h"
 
+
 /*========================================================*/
 /* Private types.                                         */
 /*========================================================*/
@@ -39,28 +35,32 @@ struct _glLabelLinePrivate {
        glColorNode     *line_color_node;
 };
 
+
 /*========================================================*/
 /* Private globals.                                       */
 /*========================================================*/
 
+
 /*========================================================*/
 /* Private function prototypes.                           */
 /*========================================================*/
 
-static void    gl_label_line_finalize      (GObject          *object);
+static void    gl_label_line_finalize     (GObject           *object);
 
-static void    copy                        (glLabelObject    *dst_object,
-                                           glLabelObject    *src_object);
+static void    copy                       (glLabelObject     *dst_object,
+                                          glLabelObject     *src_object);
 
-static void    set_line_color              (glLabelObject    *object,
-                                           glColorNode      *line_color_node);
+static void    set_line_color             (glLabelObject     *object,
+                                          glColorNode       *line_color_node,
+                                           gboolean           checkpoint);
 
-static void    set_line_width              (glLabelObject    *object,
-                                           gdouble           line_width);
+static void    set_line_width             (glLabelObject     *object,
+                                          gdouble            line_width,
+                                           gboolean           checkpoint);
 
-static glColorNode   *get_line_color       (glLabelObject    *object);
+static glColorNode   *get_line_color      (glLabelObject     *object);
 
-static gdouble get_line_width              (glLabelObject    *object);
+static gdouble get_line_width             (glLabelObject     *object);
 
 static void    draw_object                (glLabelObject     *object,
                                            cairo_t           *cr,
@@ -72,12 +72,17 @@ static void    draw_shadow                (glLabelObject     *object,
                                            gboolean           screen_flag,
                                            glMergeRecord     *record);
 
+static gboolean object_at                 (glLabelObject     *object,
+                                           cairo_t           *cr,
+                                           gdouble            x_pixels,
+                                           gdouble            y_pixels);
+
 
-\f
 /*****************************************************************************/
 /* Boilerplate object stuff.                                                 */
 /*****************************************************************************/
-G_DEFINE_TYPE (glLabelLine, gl_label_line, GL_TYPE_LABEL_OBJECT);
+G_DEFINE_TYPE (glLabelLine, gl_label_line, GL_TYPE_LABEL_OBJECT)
+
 
 static void
 gl_label_line_class_init (glLabelLineClass *class)
@@ -94,17 +99,21 @@ gl_label_line_class_init (glLabelLineClass *class)
        label_object_class->get_line_width = get_line_width;
         label_object_class->draw_object    = draw_object;
         label_object_class->draw_shadow    = draw_shadow;
+       label_object_class->draw_handles   = gl_label_object_draw_handles_line;
+        label_object_class->object_at      = object_at;
+       label_object_class->handle_at      = gl_label_object_line_handle_at;
 
        object_class->finalize = gl_label_line_finalize;
 }
 
+
 static void
 gl_label_line_init (glLabelLine *lline)
 {
        lline->priv = g_new0 (glLabelLinePrivate, 1);
-       lline->priv->line_color_node = gl_color_node_new_default ();
 }
 
+
 static void
 gl_label_line_finalize (GObject *object)
 {
@@ -118,21 +127,41 @@ gl_label_line_finalize (GObject *object)
        G_OBJECT_CLASS (gl_label_line_parent_class)->finalize (object);
 }
 
+
 /*****************************************************************************/
 /* NEW label "line" object.                                               */
 /*****************************************************************************/
 GObject *
-gl_label_line_new (glLabel *label)
+gl_label_line_new (glLabel *label,
+                   gboolean checkpoint)
 {
-       glLabelLine *lline;
+       glLabelLine         *lline;
+       glColorNode         *line_color_node;
 
        lline = g_object_new (gl_label_line_get_type(), NULL);
 
-       gl_label_object_set_parent (GL_LABEL_OBJECT(lline), label);
+        if (label != NULL)
+        {
+                if ( checkpoint )
+                {
+                        gl_label_checkpoint (label, _("Create line object"));
+                }
+
+                line_color_node = gl_color_node_new_default ();
+
+                line_color_node->color = gl_label_get_default_line_color(label);
+
+                lline->priv->line_width      = gl_label_get_default_line_width(label);
+                lline->priv->line_color_node = line_color_node;
+
+                gl_label_add_object (label, GL_LABEL_OBJECT (lline));
+                gl_label_object_set_parent (GL_LABEL_OBJECT (lline), label);
+        }
 
        return G_OBJECT (lline);
 }
 
+
 /*****************************************************************************/
 /* Copy object contents.                                                     */
 /*****************************************************************************/
@@ -153,8 +182,8 @@ copy (glLabelObject *dst_object,
        line_width = get_line_width (src_object);
        line_color_node = get_line_color (src_object);
 
-       set_line_width (dst_object, line_width);
-       set_line_color (dst_object, line_color_node);
+       set_line_width (dst_object, line_width, FALSE);
+       set_line_color (dst_object, line_color_node, FALSE);
 
        gl_color_node_free (&line_color_node);
        
@@ -167,14 +196,22 @@ copy (glLabelObject *dst_object,
 /*---------------------------------------------------------------------------*/
 static void
 set_line_color (glLabelObject *object,
-               glColorNode   *line_color_node)
+               glColorNode   *line_color_node,
+                gboolean       checkpoint)
 {
        glLabelLine *lline = (glLabelLine *)object;
+        glLabel     *label;
 
        g_return_if_fail (lline && GL_IS_LABEL_LINE (lline));
 
-       if ( !gl_color_node_equal (lline->priv->line_color_node, line_color_node)) {
-               
+       if ( !gl_color_node_equal (lline->priv->line_color_node, line_color_node))
+        {
+                if ( checkpoint )
+                {
+                        label = gl_label_object_get_parent (GL_LABEL_OBJECT (lline));
+                        gl_label_checkpoint (label, _("Line color"));
+                }
+
                gl_color_node_free (&(lline->priv->line_color_node ));
                lline->priv->line_color_node = gl_color_node_dup (line_color_node);
                
@@ -182,18 +219,28 @@ set_line_color (glLabelObject *object,
        }
 }
 
+
 /*---------------------------------------------------------------------------*/
 /* PRIVATE.  Set line width method.                                          */
 /*---------------------------------------------------------------------------*/
 static void
 set_line_width (glLabelObject *object,
-               gdouble        line_width)
+               gdouble        line_width,
+                gboolean       checkpoint)
 {
        glLabelLine *lline = (glLabelLine *)object;
+        glLabel     *label;
 
        g_return_if_fail (lline && GL_IS_LABEL_LINE (lline));
 
-       if ( lline->priv->line_width != line_width ) {
+       if ( lline->priv->line_width != line_width )
+        {
+                if ( checkpoint )
+                {
+                        label = gl_label_object_get_parent (GL_LABEL_OBJECT (lline));
+                        gl_label_checkpoint (label, _("Line width"));
+                }
+
                lline->priv->line_width = line_width;
                gl_label_object_emit_changed (GL_LABEL_OBJECT(lline));
        }
@@ -213,6 +260,7 @@ get_line_width (glLabelObject *object)
        return lline->priv->line_width;
 }
 
+
 /*---------------------------------------------------------------------------*/
 /* PRIVATE.  Get line width method.                                          */
 /*---------------------------------------------------------------------------*/
@@ -226,6 +274,7 @@ get_line_color (glLabelObject *object)
        return gl_color_node_dup (lline->priv->line_color_node);
 }
 
+
 /*****************************************************************************/
 /* Draw object method.                                                       */
 /*****************************************************************************/
@@ -268,6 +317,7 @@ draw_object (glLabelObject *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /*****************************************************************************/
 /* Draw shadow method.                                                       */
 /*****************************************************************************/
@@ -321,3 +371,43 @@ draw_shadow (glLabelObject *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
+/*****************************************************************************/
+/* Is object at coordinates?                                                 */
+/*****************************************************************************/
+static gboolean
+object_at (glLabelObject *object,
+           cairo_t       *cr,
+           gdouble        x,
+           gdouble        y)
+{
+        gdouble           w, h;
+        gdouble           line_width;
+
+        gl_label_object_get_size (object, &w, &h);
+
+        cairo_new_path (cr);
+        cairo_move_to (cr, 0, 0);
+        cairo_line_to (cr, w, h);
+
+        line_width = gl_label_object_get_line_width (object);
+        cairo_set_line_width (cr, line_width);
+        if (cairo_in_stroke (cr, x, y))
+        {
+                return TRUE;
+        }
+
+        return FALSE;
+}
+
+
+
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */