/*  Copyright (C) 2008--2010 Joshua Judson Rosen <rozzin@geekspace.com>.

    This program is free software: you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    version 3 as published by the Free Software Foundation.

    This program 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; see the file COPYING. If not, see
    <http://www.gnu.org/licenses/> or write to:

        The Free Software Foundation, inc.
        51 Franklin Street, Fifth Floor
        Boston, MA 02110-1301
        USA
*/

#include <stdlib.h>

#include <math.h>
#include <cairo.h>

#include <glib-object.h>
#include "graphics.h"
#include "metashape.h"
#include "path.h"


struct _VisualID_PathClass {
  VisualID_MetashapeClass parent_class;
};

G_DEFINE_TYPE (VisualID_Path, visualid_path, VISUALID_TYPE_METASHAPE)

enum {
  PROP_ARC_LENGTH = 1
};

static void
path_get_property (GObject *object,
                   guint property_id,
                   GValue *value,
                   GParamSpec *pspec)
{
  VisualID_Metashape *self = VISUALID_METASHAPE (object);

  switch (property_id)
    {
    case PROP_ARC_LENGTH:
      g_value_set_double (value, self->max_angle);
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
    }
}

static void
path_set_property (GObject *object,
                   guint property_id,
                   const GValue *value,
                   GParamSpec *pspec)
{
  VisualID_Metashape *self = VISUALID_METASHAPE (object);

  switch (property_id)
    {
    case PROP_ARC_LENGTH:
      self->max_angle = g_value_get_double (value);
      synth_wave (self);
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
    }
}

static void
visualid_path_init (VisualID_Path *self)
{
  self->max_angle = 0.7;
}

static void
visualid_path_class_init (VisualID_PathClass *class)
{
  GObjectClass *gobject_class = G_OBJECT_CLASS (class);

  VISUALID_GLYPH_CLASS (class)->render =
    (visualid_render_fn *) visualid_metashape_exec;
  VISUALID_GLYPH_CLASS (class)->complexity_fn =
    (visualid_complexity_fn *) visualid_metashape_complexity;

  gobject_class->get_property = path_get_property;
  gobject_class->set_property = path_set_property;

  g_object_class_install_property
    (gobject_class, PROP_ARC_LENGTH,
     g_param_spec_double ("arc-length",
                          "Arch length",
                          "Angle subtended by the arc forming the basis of this path",
                          0, M_PI*2, 0.7,
                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
}

