#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Input.H>
#include <FL/Fl_Float_Input.H>
#include <FL/Fl_Int_Input.H>
#include <FL/Fl_Secret_Input.H>
#include <FL/Fl_Multiline_Input.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Toggle_Button.H>
#include <FL/Fl_Color_Chooser.H>
#include <FL/fl_utf8.h>
#include <FL/Fl_Scrollbar.H>
#include <FL/Fl_Scroll.H>
#include "comp.h"
//#include "tiers.h"

int test1;
//double number1, number2, number3, number4, number5, number6, number7, number8;
//double number9, number10;

double numarray[25];
float float1;
char varstring[50];
char title[1024];

int when = 0;
//Fl_Input *input[36];
//Fl_Input *output[73];
//Fl_Float_Input float1;
//float1;
//Fl_Input float1;

Fl_Window *window;
Fl_Input *titleinput=(Fl_Input *)1;

Fl_Input *input1=(Fl_Input *)0;
Fl_Input *input2=(Fl_Input *)0;
Fl_Input *input3=(Fl_Input *)0;
Fl_Input *input4=(Fl_Input *)0;
Fl_Input *input5=(Fl_Input *)0;
Fl_Input *input6=(Fl_Input *)0;
Fl_Input *input7=(Fl_Input *)0;
Fl_Input *input8=(Fl_Input *)0;
Fl_Input *input9=(Fl_Input *)0;
Fl_Input *input10=(Fl_Input *)0;
Fl_Input *input11=(Fl_Input *)0;
Fl_Input *input12=(Fl_Input *)0;
Fl_Input *input13=(Fl_Input *)0;
Fl_Input *input14=(Fl_Input *)0;

/*
input6->value("-100");
input7->value("0");
input8->value("100");
input9->value("200");
*/

Fl_Input *output1=(Fl_Input *)0;
Fl_Input *output2=(Fl_Input *)0;
Fl_Input *output3=(Fl_Input *)0;
Fl_Input *output4=(Fl_Input *)0;
Fl_Input *output5=(Fl_Input *)0;
Fl_Input *output6=(Fl_Input *)0;
Fl_Input *output7=(Fl_Input *)0;
Fl_Input *output8=(Fl_Input *)0;
Fl_Input *output9=(Fl_Input *)0;
Fl_Input *output10=(Fl_Input *)0;

//Fl_Scroll* scroll1;
//Fl_Scroll *thescroll;
FL_Scroll *scroll1=(int x, int y, int w, int h, const char *label = 0);
//Fl_Scrollbar     *scrollbar = 0;
//FLscroll


void button1_cb(Fl_Widget *,void *) {

	//printf("number: %f\n", input1->value());	

	numarray[1] = atof(input1->value());
        numarray[2] = atof(input2->value());
        numarray[3] = atof(input3->value());

	//number1 = number1*2;

	numarray[4] = comp(numarray[1], numarray[2], numarray[3]);
	
	test1 = sprintf(varstring, "%.05lf", numarray[4]);
	output1->value( varstring );
}

double tiers(double price1, double shares1, double change)
{
	double tiers;
	tiers=((shares1*price1)+change)/shares1;
        return tiers;
}



void button2_cb(Fl_Widget *,void *) {

       //printf("number: %s\n", input6->value());

        numarray[1] = atof(input4->value());
        numarray[2] = atof(input5->value());

        numarray[3] = atof(input6->value());
        numarray[4] = atof(input7->value());
        numarray[5] = atof(input8->value());
        numarray[6] = atof(input9->value());
	numarray[7] = atof(input10->value());
	numarray[8] = atof(input11->value());
	numarray[9] = atof(input12->value());
	numarray[10] = atof(input13->value());
	numarray[11] = atof(input14->value());


	numarray[12] = tiers(numarray[2], numarray[1], numarray[3]);
	test1 = sprintf(varstring, "%.05lf", numarray[12]);
	output2->value( varstring );

        numarray[13] = tiers(numarray[2], numarray[1], numarray[4]);
        test1 = sprintf(varstring, "%.05lf", numarray[13]);
        output3->value( varstring );

        numarray[14] = tiers(numarray[2], numarray[1], numarray[5]);
        test1 = sprintf(varstring, "%.05lf", numarray[14]);
        output4->value( varstring );

        numarray[15] = tiers(numarray[2], numarray[1], numarray[6]);
        test1 = sprintf(varstring, "%.05lf", numarray[15]);
        output5->value( varstring );

        numarray[16] = tiers(numarray[2], numarray[1], numarray[7]);
        test1 = sprintf(varstring, "%.05lf", numarray[16]);
        output6->value( varstring );

        numarray[17] = tiers(numarray[2], numarray[1], numarray[8]);
        test1 = sprintf(varstring, "%.05lf", numarray[17]);
        output7->value( varstring );

        numarray[18] = tiers(numarray[2], numarray[1], numarray[9]);
        test1 = sprintf(varstring, "%.05lf", numarray[18]);
        output8->value( varstring );

        numarray[19] = tiers(numarray[2], numarray[1], numarray[10]);
        test1 = sprintf(varstring, "%.05lf", numarray[19]);
        output9->value( varstring );

        numarray[20] = tiers(numarray[2], numarray[1], numarray[11]);
        test1 = sprintf(varstring, "%.05lf", numarray[20]);
        output10->value( varstring );


}



void button3_cb(Fl_Widget *,void *) {

        //title = titleinput->value();
	window->label(titleinput->value());
        //test1 = sprintf(varstring, "%.05lf", numarray[4]);
        //output1->value( varstring );
}




/*
void box_cb(Fl_Widget* o, void*) {
  thescroll->box(((Fl_Button*)o)->value() ? FL_DOWN_FRAME : FL_NO_BOX);
  thescroll->redraw();
}
  
void type_cb(Fl_Widget*, void* v) {
  thescroll->type((uchar)((long)v));
  thescroll->redraw();
}

*/




//tiers(double price1, double shares1, double change)

//window->label(title);

int main(int argc, char **argv) {
	Fl::args(argc, argv);
	Fl::get_system_colors();
	window = new Fl_Window(800,800, title);
scroll1 = new FL_Scroll(800, 800);
//scrollbar = new Fl_Scrollbar(800,0,800,25,"Scrollbar");
//scrollbar->type(FL_BOTH);
//scrollbar->slider_size(.1);

//Fl_Scroll *scroll1(800,0,800,600);
//	Fl_Scroll *scroll1 = new Fl_Scroll(800,0,800,700);
	//Fl_Scroll *scroll2 = new Fl_Scroll(0,800,700,700);


	int x = 160;
	int y = 10;

titleinput = new Fl_Input(600, 50, 200, 25, "window title:");
//titleinput->type(1);
titleinput->align(FL_ALIGN_TOP);
titleinput->value("lscomp");
titleinput->box(FL_BORDER_BOX);

        Fl_Button *d;

        d = new Fl_Button(700,75,100,25,"Change");
        d->callback(button3_cb);





Fl_Box* title1 = new Fl_Box(1, 1, 600, 50, "Compounds Needed for Goal");
title1->box(FL_BORDER_BOX);
Fl_Box* title2 = new Fl_Box(1, 51, 50, 105, "Input");y += 50;
title2->box(FL_BORDER_BOX);
	//input1 = new Fl_Float_Input(70,y,300,30, "Float:"); y += 35;
	input1 = new Fl_Input(x+50, y, 150, 25, "Starting Principle:"); y += 35;
	input1->type(1);
	input1->value("1000");
	input1->box(FL_BORDER_BOX);

        input2 = new Fl_Input(x+50, y, 150, 25, "rate:"); y += 35;
        input2->type(1);
	input2->value("1.5");
	input2->box(FL_BORDER_BOX);

        input3 = new Fl_Input(x+50, y, 150, 25, "ending principle:"); y += 70;
        input3->type(1);
	input3->value("1200");
	input3->box(FL_BORDER_BOX);




//	output1 = new Fl_Input(160, y, 155, 25, "# of times:"); y += 35;
//	output1->type(1);


  	//float1->tooltip("Input field for floating-point number (F1)");

	//input[1]->when(0); input[1]->callback(cb);


Fl_Box* title3 = new Fl_Box(1, 156, 50, 105, "Output");
title3->box(FL_BORDER_BOX);
        output1 = new Fl_Input(x+50, y, 155, 25, "# of times:"); y += 70;
        output1->type(1);
	output1->box(FL_BORDER_BOX);


        Fl_Button *b;
        
        b = new Fl_Button(400,156,155,25,"Calculate"); y += 35;
        b->callback(button1_cb);









//				//
//	START OF TIERS WIDGETS  //
//				//

Fl_Box* title4 = new Fl_Box(1, 261, 600, 50, "Share Price tiers for $ change");
title4->box(FL_BORDER_BOX);
	x = 210;

Fl_Box* title5 = new Fl_Box(1, 311, 50, 175, "Input");
title5->box(FL_BORDER_BOX);

	y = 346;
        input4 = new Fl_Input(x, y, 150, 25, "# of Shares:"); y += 35;
        input4->type(1);
	input4->value("100");
	input4->box(FL_BORDER_BOX);

        input5 = new Fl_Input(x, y, 150, 25, "Share Price:");
        input5->type(1);
	input5->value("20"); 
	input5->box(FL_BORDER_BOX);	

	y += 70;
	x = 85;

new Fl_Box(x, y-35, 65, 25, "Change:");
        input6 = new Fl_Input(x, y, 65, 25, ""); x += 70;
        input6->type(1);
	input6->value("-200");
	input6->box(FL_BORDER_BOX);
new Fl_Box(x, y-35, 65, 25, "Change:");
        input7 = new Fl_Input(x, y, 65, 25, ""); x += 70;
        input7->type(1);
	input7->value("-150");
	input7->box(FL_BORDER_BOX);
new Fl_Box(x, y-35, 65, 25, "Change:");
        input8 = new Fl_Input(x, y, 65, 25, ""); x += 70;
        input8->type(1);
	input8->value("-100");
	input8->box(FL_BORDER_BOX);
new Fl_Box(x, y-35, 65, 25, "Change:");
        input9 = new Fl_Input(x, y, 65, 25, ""); x += 70;
        input9->type(1);
	input9->value("-50");
	input9->box(FL_BORDER_BOX);

new Fl_Box(x, y-35, 65, 25, "Change:");
        input10 = new Fl_Input(x, y, 65, 25, ""); x += 70;
        input10->type(1);
	input10->value("0");
        input10->box(FL_BORDER_BOX);
new Fl_Box(x, y-35, 65, 25, "Change:");
        input11 = new Fl_Input(x, y, 65, 25, ""); x += 70;
        input11->type(1);
	input11->value("50");
        input11->box(FL_BORDER_BOX);
new Fl_Box(x, y-35, 65, 25, "Change:");
        input12 = new Fl_Input(x, y, 65, 25, ""); x += 70;
        input12->type(1);
	input12->value("100");
        input12->box(FL_BORDER_BOX);
new Fl_Box(x, y-35, 65, 25, "Change:");
        input13 = new Fl_Input(x, y, 65, 25, ""); x += 70;
        input13->type(1);
	input13->value("150");
        input13->box(FL_BORDER_BOX);
new Fl_Box(x, y-35, 65, 25, "Change:");
        input14 = new Fl_Input(x, y, 65, 25, ""); x += 70;
        input14->type(1);
	input14->value("200");
        input14->box(FL_BORDER_BOX);


	y += 105;
	x = 85;


Fl_Box* title6 = new Fl_Box(1, 486, 50, 140, "Output");
title6->box(FL_BORDER_BOX);

new Fl_Box(x, y-35, 65, 25, "Price:");
        output2 = new Fl_Input(x, y, 65, 25, ""); x += 70;
        output2->type(1);
	output2->box(FL_BORDER_BOX);
new Fl_Box(x, y-35, 65, 25, "Price:");
        output3 = new Fl_Input(x, y, 65, 25, ""); x += 70;
        output3->type(1);
	output3->box(FL_BORDER_BOX);
new Fl_Box(x, y-35, 65, 25, "Price:");
        output4 = new Fl_Input(x, y, 65, 25, ""); x += 70;
        output4->type(1);
	output4->box(FL_BORDER_BOX);
new Fl_Box(x, y-35, 65, 25, "Price:");
        output5 = new Fl_Input(x, y, 65, 25, ""); x += 70;
        output5->type(1);
	output5->box(FL_BORDER_BOX);

new Fl_Box(x, y-35, 65, 25, "Price:");
        output6 = new Fl_Input(x, y, 65, 25, ""); x += 70;
        output6->type(1);
        output6->box(FL_BORDER_BOX);
new Fl_Box(x, y-35, 65, 25, "Price:");
        output7 = new Fl_Input(x, y, 65, 25, ""); x += 70;
        output7->type(1);
        output7->box(FL_BORDER_BOX);
new Fl_Box(x, y-35, 65, 25, "Price:");
        output8 = new Fl_Input(x, y, 65, 25, ""); x += 70;
        output8->type(1);
        output8->box(FL_BORDER_BOX);
new Fl_Box(x, y-35, 65, 25, "Price:");
        output9 = new Fl_Input(x, y, 65, 25, ""); x += 70;
        output9->type(1);
        output9->box(FL_BORDER_BOX);
new Fl_Box(x, y-35, 65, 25, "Price:");
        output10 = new Fl_Input(x, y, 65, 25, ""); x += 70;
        output10->type(1);
        output10->box(FL_BORDER_BOX);




        //y += 35;
        //x = 10;

        Fl_Button *c;

        c = new Fl_Button(400,490,155,25,"Calculate");
        c->callback(button2_cb);

/*
     Fl_Scrollbar* scroll1 = new Fl_Scrollbar(775, 0, 25, 775);
     scroll1->type(1);
     scroll1->align(FL_ALIGN_LEFT);
     //scroll1->callback(cb_scroll1);

//Fl_Scrollbar* o 

     Fl_Scrollbar* scroll2 = new Fl_Scrollbar(0, 775, 800, 25);
      scroll2->type(1);
      scroll2->align(FL_ALIGN_LEFT);
      //scroll2->callback(cb_scroll2);

// Fl_Scrollbar* o
*/


//xposition() yposition()
  //scroll.end();


	
//	scroll1->end();
//	scroll2->end();
//window->resizable(scroll1);	
//window->resizable(scroll2);

window->resizable(window);
//thescroll = &scroll1;
scroll1->end();
//FLscrollEnd;
	window->end();
	window->show(argc,argv);
	return Fl::run();
}
