/*
    lsclock is small fltk date/time displayer.
    Copyright (C) 2009  sterling pickens

    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 3 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, see <http://www.gnu.org/licenses/>.
*/


#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <sys/time.h>
#include <unistd.h>
#include <FL/Fl.H>

#include <FL/Fl_Button.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Scrollbar.H>
#include <FL/Fl_Scroll.H>
#include <FL/Fl_Output.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_utf8.h>
#include <FL/Fl_Box.H>
//#include <GL/glut.h>
//#include <GL/gl.h>
#include <FL/Fl_Clock.H>
#include <FL/Fl_Round_Clock.H>
#include <FL/Fl_Widget.H>
#include <FL/fl_draw.H>
#include <FL/x.H>





Fl_Input *title1[10];
//Fl_Line *line[10];

struct tm *local; 
time_t t;
Fl_Double_Window *win = 0;
Fl_Button *a = 0;
Fl_Button *b = 0;

struct city_struct
{
	char city[15];
	int change;
};
struct city_struct city_names[10];


void clock_update(void*) {


	char date[30];
	time_t time_tmp;
	int i;

//	printf("before while\n");

       	t = time(NULL);
	//time_tmp = t;
	
	for(i=0; i<9; i++) {
		time_tmp = t;
		time_tmp = time_tmp + (city_names[i].change*60*60);
       		local = localtime(&time_tmp);
		memset ((void*) date, '\0', sizeof (date));
		strcpy(date, " ");
		strcat(date, asctime(local));
		date[strlen(date)-1]='\0';
		title1[i]->value(date);
	}




//	printf("new time: %s\n", date);
	//title1[0]->value(date);
	 win->redraw();
	Fl::repeat_timeout(1.0, clock_update);

}



int main(int argc, char **argv) {
        			// width, height  385
        win = new Fl_Double_Window(425,225,"lsclock v0.0.1");



strcpy( city_names[0].city, "Local" );   
strcpy( city_names[1].city, "New York" );
strcpy( city_names[2].city, "UTC" );   
strcpy( city_names[3].city, "London" );   
strcpy( city_names[4].city, "Frankfurt" );
strcpy( city_names[5].city, "Moscow" );   
strcpy( city_names[6].city, "Shanghai" ); 
strcpy( city_names[7].city, "Tokyo" );   
strcpy( city_names[8].city, "Sydney" );


city_names[0].change=0;
city_names[1].change=3;
city_names[2].change=7;
city_names[3].change=8;
city_names[4].change=9; 
city_names[5].change=11;
city_names[6].change=15;
city_names[7].change=16;
city_names[8].change=17;





	//fltk::line_style(0)
	Fl::background2(0, 0, 0);
	Fl::background(0, 0, 0);
	int down;
	int count1=0;
	int color=2;

	for (down = 0; down < 250; down=down+25) {

        	title1[count1] = new Fl_Input(75, down, 360, 25, city_names[count1].city);
        	//title1[0]->align(FL_ALIGN_BOTTOM);
        	title1[count1]->value("");
		title1[count1]->labelcolor((Fl_Color)color);
        	title1[count1]->textsize(24);
        	title1[count1]->textcolor((Fl_Color)color);
        	title1[count1]->box(FL_BORDER_BOX);
		//fl_line_style(0, 385, FL_SOLID)
		//bla = new fl_line(0, down, 385, down);
		count1++;


		//fl_color (m_MrkColour);
		//fl_line_style(0)
		//fl_color(1);
		//fl_line(0, down, 385, down);
		//line[count1] = new Fl_Line(0, down, 385, down);
		if(color==2){color=4;}else{color=2;}

	}
//fl_color(50);
//        fl_line(x1, y1, x2, y2);

/*
fl_line_style(255, 0, 0);

    fl_begin_line();
    fl_vertex(0, 250);
    fl_vertex(300,250 );
    //fl_vertex(, );
    //fl_vertex(, );
    fl_end_line();
    // you must reset the line type when done:
    fl_line_style(FL_SOLID);
    fl_color(FL_RED);
*/

//fl_color(50);



//fl_rect(10,10,50,50);


//fl_line (10, 250, 300, 250);


//  fl_begin_line();

//  fl_vertex(0, 250);

//  fl_vertex(300, 250); 
//  fl_vertex(-40, 35);
//  fl_vertex(35, 2);

//  fl_end_line();






//draw_line->value(0);
//draw_line(0, 250, 300, 250);

//fl_line(5, 5, 30, 30, 2, 2);


	Fl::add_timeout(1.0, clock_update);

        win->resizable(win);
        
        win->end();
        win->show();
        //Scrollbar_CB(0,0);                  // show scrollbar's initial position
        return(Fl::run());
}


