/* The routines in this file are copyright (c) 1987 by Helene (Lee) Taran.
 * Permission is granted for use and free distribution as long as the
 * original author's name is included with the code.
 */

/*
 * Reformatted, and modified to compile without warnings and errors
 * under SAS/C -6.5x by gduncan@philips.oz.au (GMD). This included
 * proto generation, renaming of some literals to avoid name collisions,
 * and Amiga Version string (also displayed in Title bar).
 * No original version number, this version arbitrarily named 1.1. 
 * - otherwise no functional changes.
 * GMD - Sep 94
 */

#include "all.h"

#define VERSION "1.1 "__AMIGADATE__

/*
 * Version string (GMD)
 */
static char A_vers[] = "\0$VER: spline\t" VERSION;

DLIST_ELEMENT Control_Points;

main ()
{

  /*
   * append Version string to TitleBar (GMD)
   */

  strcat (TitleBar, VERSION);
  OpenLibraries ();
  SetupEnvironment ();
  Init_List (&Control_Points);
  Create_ControlPoints ();
  Init_GValues ();		/* sets up the Gvalues for interpolating splines */



  while (1)			/* Main Loop */
    {
      INTUIMESSAGE *message;
      INTUIMESSAGE mcopy;

      /* Wait until something happens and then respond to it */

      Wait (1 << Window->UserPort->mp_SigBit);

      /* Now, one or more input events have arrived. Respond to ALL */
      while (message = (INTUIMESSAGE *) GetMsg (Window->UserPort))
	{
	  mcopy = *message;	/* make a copy of the message */
	  ReplyMsg ((MESSAGE *) message);	/* reply to it immediately */
	  ProcessMessage (&mcopy);	/* react to the message */
	}
    }
}


/* ProcessMessage processes an input event given */

void
ProcessMessage (msg)
     INTUIMESSAGE *msg;
{
  switch (msg->Class)
    {
    case CLOSEWINDOW:
      close_things ();
      exit (0);
    case MOUSEBUTTONS:
      if (msg->Code == SELECTDOWN)
	{
	  DLISTPTR p, Select_ControlPoint ();
	  if (p = Select_ControlPoint (msg->MouseX, msg->MouseY))
	    Edit_ControlPoint (Window, p);
	  else
	    Edit_CurveStyle (Window);
	}
      break;
    }
}

void
Create_ControlPoints ()
{
  DLISTPTR p;
  REAL_POINT *c;

  p = (DLISTPTR) calloc (1, sizeof (DLIST_ELEMENT));
  c = (REAL_POINT *) calloc (1, sizeof (REAL_POINT));
  c->x = 300;
  c->y = 200;
  p->contents = c;
  INSERT_FIRST (p, &Control_Points);

  p = (DLISTPTR) calloc (1, sizeof (DLIST_ELEMENT));
  c = (REAL_POINT *) calloc (1, sizeof (REAL_POINT));
  c->x = 155;
  c->y = 30;
  p->contents = c;
  INSERT_FIRST (p, &Control_Points);

  p = (DLISTPTR) calloc (1, sizeof (DLIST_ELEMENT));
  c = (REAL_POINT *) calloc (1, sizeof (REAL_POINT));
  c->x = 20;
  c->y = 175;
  p->contents = c;
  INSERT_FIRST (p, &Control_Points);

  Draw_ControlPoints (Window);
  Draw_Natural_Bspline (Window, &Control_Points);
}
/*--*/
