/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#+
#+     Internet Radio Automation & Encoding Toolkit
#+
#+     Copyright (C) 2018, 2019, 2020, 2021 by Kevin C. O'Kane
#+
#+     Kevin C. O'Kane
#+     kc.okane@gmail.com
#+     https://www.cs.uni.edu/~okane
#+     https://threadsafebooks.com/
#+
#+ This program 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
#+ (at your option) any later version.
#+
#+ 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; if not, write to the Free Software
#+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#+
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

//	Nov 4, 2022

#include "includes.h"
#include "common-externs.h"

#define SLASH '/'

void    spots(cairo_t *cr, double hor, double ver, double len, double z) {

	double x,y,x1,y1,lw;

	cairo_arc (cr, hor, ver, len + SHADOW, -M_PI, -M_PI + z);   // further point

	cairo_get_current_point (cr, &x, &y);

	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sprinkleDamp)))
		cairo_arc (cr, hor, ver, 0.0, -M_PI, -M_PI + z);       // nearer point

	else cairo_arc (cr, hor, ver, len, -M_PI, -M_PI + z);       // nearer point

	cairo_get_current_point (cr, &x1, &y1);

	cairo_new_path (cr);
	cairo_move_to(cr, x, y);
	cairo_line_to (cr, x1, y1 );
	cairo_stroke (cr);
	}

//---------------------------
//	vertical sprinkles
//---------------------------

void    spots2(cairo_t *cr, int i, double len, double max, int lower, int panel) {

	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sprinkleDamp))) {

		double avg;

		avg = (lastR1[i] +
		       lastR2[i] +
		       lastR3[i] +
		       lastR4[i] +
		       lastR5[i] +
		       lastR6[i] +
		       lastR7[i] +
		       lastR8[i] +
		       lastR9[i] +
		       lastRA[i])/(10.0 + (i==0 ? 4.0 : (10.0/(i+1) ) ) );

		spots3(cr, i, avg, max, lower, panel);

		return;
		}

	if(lastR1[i]>len) {
		spots3(cr, i, lastR1[i], max, lower, panel);
		}

	if (sprinkleCount < 2) return;

	if(lastR2[i]>len) {
		spots3(cr, i, lastR2[i], max, lower, panel);
		}

	if (sprinkleCount < 3) return;

	if(lastR3[i]>len) {
		spots3(cr, i, lastR3[i], max, lower, panel);
		}

	if (sprinkleCount < 4) return;

	if(lastR4[i]>len) {
		spots3(cr, i, lastR4[i], max, lower, panel);
		}

	if (sprinkleCount < 5) return;

	if(lastR5[i]>len) {
		spots3(cr, i, lastR5[i], max, lower, panel);
		}

	if (sprinkleCount < 6) return;

	if(lastR6[i]>len) {
		spots3(cr, i, lastR6[i], max, lower, panel);
		}

	if (sprinkleCount < 7) return;

	if(lastR7[i]>len) {
		spots3(cr, i, lastR7[i], max, lower, panel);
		}

	if (sprinkleCount < 8) return;

	if(lastR8[i]>len) {
		spots3(cr, i, lastR8[i], max, lower, panel);
		}

	if (sprinkleCount < 9) return;

	if(lastR9[i]>len) {
		spots3(cr, i, lastR9[i], max, lower, panel);
		}

	if (sprinkleCount < 10) return;

	if(lastRA[i]>len) {
		spots3(cr, i, lastRA[i], max, lower, panel);
		}
	}

void    spots3(cairo_t *cr, int i, double len, double max, int lower, int panel) {

#define GAP 2.0

	if (panel == SMALL_PANEL) {
		if (len > 200.0) len = 200.0;
		}
	else {
		if (len > 500.0) len = 500.0;
		}

	cairo_set_line_cap  (cr, CAIRO_LINE_CAP_BUTT);

	if (lower == LOWER) {

		if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sprinkleDamp)))  {
			cairo_move_to (cr, i * bar_space + G_OFF, max  ); // horizontal, vertical
			cairo_line_to (cr, i * bar_space + G_OFF, max + len); // baseline line
			}
		else {
			cairo_move_to (cr, i * bar_space + G_OFF, max + len  ); // horizontal, vertical
			cairo_line_to (cr, i * bar_space + G_OFF, max + len + SHADOW ); // baseline line
			}

		cairo_stroke (cr);
		}
	else {
		if (len < 4.0) return;

		if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sprinkleDamp))) {
			cairo_move_to (cr, i * bar_space + G_OFF, max); // horizontal, vertical
			cairo_line_to (cr, i * bar_space + G_OFF, max - (len) ); // baseline line
			}
		else {
			cairo_move_to (cr, i * bar_space + G_OFF, max - len  ); // horizontal, vertical
			cairo_line_to (cr, i * bar_space + G_OFF, max - (len + SHADOW) ); // baseline line
			}

		cairo_stroke (cr);
		}

	cairo_set_line_cap  (cr, CAIRO_LINE_CAP_ROUND);
	}
