/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#+
#+     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
#+
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

//	Oct 26, 2022

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

#define SLASH '/'

//--------------------------------------------
//      spikes1 / spikes3 (circles)
//--------------------------------------------

void    on_spikes1_toggled (GtkWidget *b) {

	spikes1_handler(b);

	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(spikes1))) {
		}

	else {
		}

	}


void    spikes1_handler(GtkWidget *b) {

	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(b))) {

		if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(above_bars)))
			gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(above_bars), TRUE);

		show_spikes1 = 1;

		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(traces), FALSE);
//                gtk_spin_button_set_value (GTK_SPIN_BUTTON(barWidth), 3.0);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(meters), TRUE);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(circular), FALSE);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(tower), FALSE);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(bullseye), FALSE);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(spikes), FALSE);
//                gtk_spin_button_set_value (GTK_SPIN_BUTTON(barWidth), 2.0);
//                GRAPH_BAR_WIDTH = 2.0;
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(connectGraph), FALSE);

		}
	else {
		show_spikes1 = 0;
		on_meters_toggled(GTK_BUTTON(meters));
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(connectGraph), TRUE);
		}
	}

//-----------------------------------
//      spikes / spikes2 (radial)
//-----------------------------------

void    on_spikes_toggled (GtkWidget *b) {

	spikes_handler(b);

	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(spikes))) {
		}

	else {
		}

	}


void    spikes_handler(GtkWidget *b) {

	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(b)) ) {

		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(above_bars), TRUE);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(meters), TRUE);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(circular), FALSE);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(spikes1), FALSE);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(tower), FALSE);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(bullseye), FALSE);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(connectGraph), FALSE);

		show_spikes = 1;
		return;
		}

	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(connectGraph)) )
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(connectGraph), FALSE);

	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(traces)) )
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(traces), FALSE);

	on_meters_toggled(GTK_BUTTON(meters));
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(connectGraph), TRUE);
	show_spikes = 0;
	}

void    on_antenna_toggled(GtkWidget *b) {
	return;
	}


void    on_tower_toggled(GtkWidget *b) {

	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(b)) ) {

		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(randColors), FALSE);
		gtk_adjustment_set_value (GTK_ADJUSTMENT(adjustment49), 10.); // ray rotate
		gtk_adjustment_set_value (GTK_ADJUSTMENT(adjustment45), 3.); // bar density

//------------------------------------------------
//              'meters' is the spectrum checkbox
//------------------------------------------------

		if (! gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(meters))) {

//---------------------------------------------------------
//                      adjust density for amplitude data
//---------------------------------------------------------

			gtk_spin_button_set_value (GTK_SPIN_BUTTON(rayCount), 1.0);
			}

//                gtk_spin_button_set_value (GTK_SPIN_BUTTON(barWidth), 7.0);

		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(meters), TRUE);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(above_bars), FALSE);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(circular), FALSE);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(spikes1), FALSE);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(spikes), FALSE);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(bullseye), FALSE);
//                gtk_spin_button_set_value (GTK_SPIN_BUTTON(barWidth), 3.0);
//                GRAPH_BAR_WIDTH = 3.0;

		return;
		}

//        gtk_spin_button_set_value (GTK_SPIN_BUTTON(barWidth), 3.0);
	on_meters_toggled(GTK_BUTTON(meters));
	show_spikes = 0;

	}



void    on_randColors_toggled (GtkWidget *b) {

	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(b))) {
		rand_colors = 1;
		}

	else {
		rand_colors = 0;
		}
	}


void    on_meters_toggled (GtkButton *b) {

	meters_handler(b);

	}


void    meters_handler(GtkButton *b) {

	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(b)) ) { // spectrum on

		if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(spec20))) {
			style = WIDE_SPECTRUM;
			}

		if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(spec12))) {
			style = NARROW_SPECTRUM;
			}

		if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(spec7))) {
			style = VERY_NARROW_SPECTRUM;
			}

		graph_type = SPECTRUM;
		for (int i=0; i<100; i++) rchan[i] = lchan[i] = 0;
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(displayBars), TRUE);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(above_bars), FALSE);
		return;
		}

	graph_type = GAIN;
	for (int i=0; i<100; i++) rchan[i] = lchan[i] = 0;

	gtk_spin_button_set_value (GTK_SPIN_BUTTON(rayCount), 1.0);
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(tower), FALSE);
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(bullseye), FALSE);
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(spikes), FALSE);
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(spikes1), FALSE);
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(randColors), FALSE);
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(connectGraph), FALSE);
	return;
	}


void    on_shadow_offset_value_changed(GtkSpinButton *s, GtkScrollType scr) {
	SHADOW = gtk_spin_button_get_value(s);
	}

void    on_ray_rotate_value_changed(GtkSpinButton *s, GtkScrollType scr) {
	rayRotate = gtk_spin_button_get_value(s) / 10.;
	}


void    on_rayCount_value_changed(GtkSpinButton *s, GtkScrollType scr) {
	ray_count = gtk_spin_button_get_value(s);
	}


void    on_barWidth_value_changed(GtkSpinButton *s, GtkScrollType scr) {
	GRAPH_BAR_WIDTH = gtk_spin_button_get_value(s);
	if (GRAPH_BAR_WIDTH < 1) GRAPH_BAR_WIDTH = 1;
	}


void    on_radial_start_value_changed(GtkSpinButton *s, GtkScrollType scr) {
	radialStart  = gtk_spin_button_get_value (s);
	}


void    on_radial_decay_value_changed(GtkSpinButton *s, GtkScrollType scr) {
	radialDecay  = gtk_spin_button_get_value (s);
	}


void    on_tower_circles_toggled(GtkWidget *b) {

	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(b)))  { // active
		return;
		}

	}

void    on_tower_rays_toggled(GtkWidget *b) {

	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(b)))  { // active
		return;
		}


	}


//-----------------------------------------------
//      circular/circular1 (cocentric circles)
//-----------------------------------------------


void    on_circular_toggled (GtkWidget *b) {

	circular_handler(b);

	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(circular))) {
		}
	else {
		}
	}



void    circular_handler(GtkWidget *b) {

	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(b))) {

		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(above_bars), TRUE);

		circular_graph = 1;
//                gtk_spin_button_set_value (GTK_SPIN_BUTTON(barWidth), 2.0);

		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(traces), FALSE);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(meters), TRUE);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(tower), FALSE);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(connectGraph), FALSE);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(bullseye), FALSE);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(spikes), FALSE);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(spikes1), FALSE);
//                gtk_spin_button_set_value (GTK_SPIN_BUTTON(barWidth), 2.0);
//                GRAPH_BAR_WIDTH = 2.0;
		}
	else {
		circular_graph = 0;
		on_meters_toggled(GTK_BUTTON(meters));
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(connectGraph), TRUE);
		}
	}

//------------------------------------------
//      bullseye (circle)
//------------------------------------------

void    on_bullseye_toggled (GtkWidget *b) {

	bullseye2_handler(b);

	}


void    bullseye2_handler(GtkWidget *b) {

	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(b))) {

		bulls_eye = 1;

		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(traces), FALSE);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(above_bars), TRUE);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(tower), FALSE);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(meters), TRUE);         // spectrum
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(spikes1), FALSE);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(circular), FALSE);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(spikes), FALSE);
		return;
		}

	bulls_eye = 0;
	on_meters_toggled(GTK_BUTTON(meters));
	return;

	}



void    on_above_bars_toggled (GtkButton *b) {
	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b))) {
		super_bars = 1;
		}
	else {
		super_bars = 0;
		}
	}


void    on_traces_toggled (GtkWidget *b) {
	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(b))) {
		bar_spots = 1;
		}
	else {
		bar_spots = 0;
		}
	}


void    on_connectGraph_toggled (GtkWidget *b) {
	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(b))) {
		connect_graph = 1;
		}
	else {
		connect_graph = 0;
		}
	}



void    on_displayBars_toggled (GtkWidget *b) {
	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(b))) {
		display_bars = 1;
		}
	else {
		display_bars = 0;
		}
	}


void    on_decorations_toggled (GtkWidget *b) {
	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(decorations))) {
		gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
		gtk_window_resize(GTK_WINDOW(window), 400,400);
		return;
		}
	gtk_window_set_decorated(GTK_WINDOW(window), TRUE);
	}

