/******************************************************************************/
/* Copyright 1996 MBARI                                                       */
/******************************************************************************/
/* Summary  : Video overlay functions for Icon class                          */
/* Filename : Icon.c                                                          */
/* Author   : Janice Tarrant                                                  */
/* Project  : Tiburon                                                         */
/* Version  : Version 1.0                                                     */
/* Created  : 10/02/96                                                        */
/* Modified :                                                                 */
/* Archived :                                                                 */
/******************************************************************************/
/* Modification History :                                                     */
/* $Header$
 * $Log$
 *
 */
/******************************************************************************/

#include "dmvideo.h"                    /* data manager definitions           */
#include <types.h>                      /* MBARI style guide type declarations*/
#include "OVtypes.h"                    /* video overlay type definitions     */
#include "dy4std.h"                     /* DY4 standard definitions           */
#include "video.h"                      /* DY4 video definitions              */
#include "mygraphics.h"                 /* graphics alignment definitions     */
#include "dy4driver.h"                 	/* DY4 driver definitions             */
#include "Icon.h" 			/* definitions for Icon class         */

#define NUM_CORNERS      4		/* number of corners of square icon   */
#define SQUARE_ICON_SIDE 5.0		/* square icon side length            */
#define NUM_LINE_ENDS    3		/* number of line ends for crosshair  */
#define CROSSHAIR_LENGTH 20.0		/* crosshair length                   */


/******************************************************************************/
/* Function : Square_Icon_Display                                             */
/* Purpose  : Displays a square icon on the overlay.                          */
/* Inputs   : Square icon Item pointer.                                       */
/* Outputs  : None.                                                           */
/******************************************************************************/
    Void
Square_Icon_Display(OV_alignment *alignment, OV_Item *p_item)
{
    Nat32 x[NUM_CORNERS];		/* x corner coordinates (pixels)      */
    Nat32 y[NUM_CORNERS];		/* y corner coordinates (pixels)      */
    Flt32 x_point[NUM_CORNERS];		/* x corner coordinates (mm)          */
    Flt32 y_point[NUM_CORNERS];		/* y corner coordinates (mm)          */
    Flt32 xorg, yorg;			/* coords of axes' origin (mm)        */

    if (strcmp(p_item->value, "on") == 0)
    {
/* draw an icon at the current position                                       */
    	x_point[0] = p_item->x;
    	y_point[0] = p_item->y;
    	x_point[1] = x_point[0] + SQUARE_ICON_SIDE;
    	y_point[1] = y_point[0];
    	x_point[2] = x_point[1];
    	y_point[2] = y_point[0] - SQUARE_ICON_SIDE;
    	x_point[3] = x_point[0];
    	y_point[3] = y_point[2];

	My_mov_point(alignment, x_point[0], y_point[0]);
	My_get_point(alignment, &x[0], &y[0]);
	My_mov_point(alignment, x_point[1], y_point[1]);
	My_get_point(alignment, &x[1], &y[1]);
	Draw_line(x[0], y[0], x[1]-1, y[1]);

	My_mov_point(alignment, x_point[2], y_point[2]);
	My_get_point(alignment, &x[2], &y[2]);
	Draw_line(x[1], y[1], x[2], y[2]-1);

	My_mov_point(alignment, x_point[3], y_point[3]);
	My_get_point(alignment, &x[3], &y[3]);
	Draw_line(x[2], y[2], x[3]+1, y[3]);

	Draw_line(x[3], y[3], x[0], y[0]+1);
    }

}  /* Square_Icon_Display */


/******************************************************************************/
/* Function : Square_Icon_SetValue                                            */
/* Purpose  : Sets a square icon value to "on" or "off".                      */
/* Inputs   : Square icon Item pointer and value.                             */
/* Outputs  : None.                                                           */
/******************************************************************************/
    Void
Square_Icon_SetValue(OV_Item *p_item, OV_char *value)
{
    Int16 intValue;				/* integer item value         */
    Int16 nb_char;				/* number of chars            */
    MBool boolValue;				/* boolean item value         */

/* convert value to Boolean                                                   */
    intValue = atoi(value);
    boolValue = (MBool) intValue;

/* set icon value to "on" or "off"                                            */
    if (boolValue)
    {
	nb_char = strlen("on") + 1;
	p_item->value = (char *) malloc (nb_char);
	strcpy(p_item->value, "on");
    }
    else
    {
	nb_char = strlen("off") + 1;
	p_item->value = (char *) malloc (nb_char);
	strcpy(p_item->value, "off");
    }

}  /* Square_Icon_SetValue */


/******************************************************************************/
/* Function : Croshair_Icon_Display                                           */
/* Purpose  : Displays a crosshair on the overlay.                            */
/* Inputs   : Crosshair icon Item pointer.                                    */
/* Outputs  : None.                                                           */
/******************************************************************************/
    Void
Crosshair_Icon_Display(OV_alignment *alignment, OV_Item *p_item)
{
    Nat32 x[NUM_LINE_ENDS];		/* x line end coordinates (pixels)    */
    Nat32 y[NUM_LINE_ENDS];		/* y line end coordinates (pixels)    */

    if (strcmp(p_item->value, "on") == 0)
    {
    	My_mov_point(alignment, p_item->x - CROSSHAIR_LENGTH, p_item->y);
    	My_wri_line(alignment, p_item->x + CROSSHAIR_LENGTH, p_item->y);

    	My_mov_point(alignment, p_item->x, p_item->y + CROSSHAIR_LENGTH);
	My_get_point(alignment, &x[0], &y[0]);
	My_mov_point(alignment, p_item->x, p_item->y);
	My_get_point(alignment, &x[1], &y[1]);
	Draw_line(x[0], y[0], x[1], y[1]-1);

    	My_mov_point(alignment, p_item->x, p_item->y - CROSSHAIR_LENGTH);
	My_get_point(alignment, &x[2], &y[2]);
	Draw_line(x[1], y[1]+1, x[2], y[2]);
    }

}  /* Crosshair_Icon_Display */


/******************************************************************************/
/* Function : Crosshair_Icon_SetValue                                         */
/* Purpose  : Sets a crosshair icon value to "on" or "off".                   */
/* Inputs   : Crosshair icon Item pointer and value.                          */
/* Outputs  : None.                                                           */
/******************************************************************************/
    Void
Crosshair_Icon_SetValue(OV_Item *p_item, OV_char *value)
{
    Int16 intValue;				/* integer item value         */
    Int16 nb_char;				/* number of chars            */
    MBool boolValue;				/* boolean item value         */

/* convert value to Boolean                                                   */
    intValue = atoi(value);
    boolValue = (MBool) intValue;

/* set icon value to "on" or "off"                                            */
    if (boolValue)
    {
	nb_char = strlen("on") + 1;
	p_item->value = (char *) malloc (nb_char);
	strcpy(p_item->value, "on");
    }
    else
    {
	nb_char = strlen("off") + 1;
	p_item->value = (char *) malloc (nb_char);
	strcpy(p_item->value, "off");
    }

}  /* Crosshair_Icon_SetValue */


