/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#+
#+     Internet Radio Automation & Encoding Toolkit
#+
#+     Copyright (C) 2018 - 2025 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
#+
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

//	Sept 17, 2025

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

#define SLASH '/'

void	 drawS (GtkDrawingArea *widget, cairo_t *cr, int panel) {

//---------------------------------------------------------
//	called to draw cocentric, circles, bullseye, etc.
//	not called for tower.
//	called twice if graphics panel is visible.
//---------------------------------------------------------

	double hor, ver, len;
	double z, r, g, b, x, y, x1, y1, clip ;
	int i;
	double red, blue, green;

	double cAdj = 95.0; // fill out circle  adjustment

	cairo_set_line_cap  (cr, CAIRO_LINE_CAP_ROUND);

	clip = ClipLevel;

	if (panel == SMALL_PANEL) {

		draw_mode = DRAWS;

		if (bulls_eye || bulls_eye1) {
			x1 = hor = 200.;
			y1 = ver = 130.;
			}
		else {
			x1 = hor = 195.;
			if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(noBackPic)))
				y1 = ver = 220.;
			else y1 = ver = 150.;
			}
		}

	else {
		draw_mode = DRAWS1;

		if (bulls_eye || bulls_eye1 || circular_graph) {
			x1 = hor = 340.;
			x1 = hor = 322.;
			y1 = ver = 250.;
			}
		else if (show_spikes) {  // radial
			x1 = hor = 342.;
			x1 = hor = 322.;
			y1 = ver = 550.;
			y1 = ver = 470.;
			}
		else {
			x1 = hor = 342.;
			x1 = hor = 322.;
			y1 = ver = 355.;
			y1 = ver = 470.;
			}
		}

	spectrum(); 	// scaling is done in spectrum()

	cairo_set_line_width(cr, GRAPH_BAR_WIDTH);

#define BMAX 100.0

	for (int i = 0; i < BMAX; i = i + ray_count) { // resolution

		if (! show_spikes)
			color_generator(cr, i, &red, &green, &blue);

		if (bar_spots) {

			z = i / cAdj * M_PI;
			if (z > M_PI) z = M_PI;

			if (panel == SMALL_PANEL) {
				if (z < M_PI_4 || z > 3.0 * M_PI_4) if (len > 200.) len = 200.0;
				}

			else { // large panel
				if (z < M_PI/3.0 || z > 2.0 * M_PI/3.0) if (len > 220.) len = len / 500.0 * 250.0;
				}

			sprinkles(cr, z, len, i, hor,  ver);
			}

		if (bulls_eye1) {


			if (panel == SMALL_PANEL) len = (slchan[i]  + srchan[i]) / 2.0;
			else len = (slchan[i]  + srchan[i]) / 5.0;

			if (len > clip) len = clip;

			cairo_rectangle (cr, hor, ver, -len, -len);
			cairo_rectangle (cr, hor, ver, len, len);
			cairo_rectangle (cr, hor, ver, -len, len);
			cairo_rectangle (cr, hor, ver, len, -len);

			cairo_fill(cr); // fill in arc
			cairo_stroke (cr);

			continue; // done
			}

		if (bulls_eye) {

			if (panel == SMALL_PANEL) len = (slchan[i] + srchan[i]) / 2.0;
			else len = (slchan[i] + srchan[i]) / 5.0;

			if (len > clip) len = clip;
			cairo_arc (cr, hor, ver, len, - M_PI, 2.0 *  M_PI );
			cairo_fill(cr); // fill in arc
			cairo_stroke (cr);
			continue; // done
			}

		if (show_spikes) { // radial

			if (panel == SMALL_PANEL) len = (slchan[i] + srchan[i] ) / 1.2;
			else len = (slchan[i] + srchan[i] ) / 1.5;

			len = (slchan[i] + srchan[i] ) / 1.5;

			cairo_new_path (cr);

			z = i / cAdj * M_PI;
			if (z > M_PI) z = M_PI;

//--------------------------------------------------------------
//	limit extent of rays depending on panel size and angle
//--------------------------------------------------------------

			if (panel == SMALL_PANEL) {
				if (z < M_PI_4 || z > 3.0 * M_PI_4)
					if (len > 200.) len = 200.0;
				}
			else { // large panel
				if (z < M_PI / 3.0 || z > 2.0 * M_PI / 3.0)
					if (len > 300.) len = 330.;
				}

			cairo_arc (cr, hor, ver, len, - M_PI, - M_PI + z);
			cairo_get_current_point (cr, &x, &y);
			cairo_new_path(cr);


			if (display_bars) { // show radial bars

				color_generator(cr, i, &red, &green, &blue);
				cairo_set_source_rgba(cr, red, green, blue, .5);  // tranparancy

				if (panel == SMALL_PANEL)
					cairo_arc (cr, hor, ver, 300., - M_PI, - M_PI + z);

				else
					cairo_arc (cr, hor, ver, 330., - M_PI, - M_PI + z);

				cairo_get_current_point (cr, &x, &y);
				cairo_new_path(cr);
				cairo_move_to(cr, hor, ver);
				cairo_line_to (cr, x, y);
				cairo_stroke (cr);

				cairo_set_source_rgba(cr, red, green, blue, 1.0);
				cairo_arc (cr, hor, ver, len, - M_PI, - M_PI + z);
				cairo_get_current_point (cr, &x, &y);
				cairo_new_path(cr);
				cairo_move_to(cr, hor, ver);
				cairo_line_to (cr, x, y );
				cairo_stroke (cr);

				}

			if (connect_graph) { // connect bar end points

				color_generator(cr, i, &red, &green, &blue);
				cairo_move_to(cr, x1, y1);
				cairo_line_to (cr, x, y );
				cairo_stroke (cr);
				x1 = x;
				y1 = y;
				}
			}

		len = (slchan[i]  + srchan[i]) / 2.0;

		if (panel == SMALL_PANEL) {
			if (show_spikes1) {
				z = M_PI;
				cairo_set_source_rgba(cr, red, green, blue, len/50.0);  // tranparancy
				}
			else z = (len / 225.0 ) * (1.0 * M_PI);
			}
		else {
			if (show_spikes1) { // horizon arcs
				z = M_PI;
				cairo_set_source_rgba(cr, red, green, blue, len/150.0);  // tranparancy
				}
			else z = (len / 225.0 ) * (1.0 * M_PI);
			}

//--------------------------
//	concentric
//--------------------------

		if (circular_graph || show_spikes1) {
			if (show_spikes1) cairo_arc (cr, hor, ver, i * 3., - M_PI, - M_PI + z);
			else cairo_arc(cr, hor, ver, i * 2.1, - M_PI, - M_PI + z);
			cairo_move_to(cr, x1, y1);
			cairo_line_to (cr, hor, ver );
			cairo_stroke (cr);
			}
		}
	}
