/***********************************************************************************************

 Author:		Muhammad Zulfiqar		JPC36
 School;		John Abbott College, Montreal, Canada.
 File:			slide_show.cpp
 Date:			August 08, 2000.

 ************************************************************************************************/

#include "slide_show.h"
#include "canvas.h"

#include <wx/wx.h>
#include <wx/dc.h>
#include "wx/file.h"
#include <wx/filedlg.h>
#include "wx/dirdlg.h"
#include <wx/string.h>
#include "wx/timer.h"

using namespace std;

/******************************************************************************************

BEGIN_EVENT_TABLE(MySlideShow, wxFrame)
receives: 	pointer to MyslideShow and wxFrame
Return:		N/A
Description;	Handles the user specified timer-interval

********************************************************************************************/

BEGIN_EVENT_TABLE(Slide_show, wxFrame)

    //Timer which will trigger slideshow
    EVT_TIMER(ID_Slide_Show_Timer, Slide_show::on_timer)

END_EVENT_TABLE()

//---------------------------------------------------------------------------------------------

/*********************************************************************************************

Function:	 Slide_show::Slide_show
receives: 	N/A
Return:		N/A
Description;	Configures frame application with Canvas.h

************************************************************************************************/

//constructor
Slide_show::Slide_show(Canvas * canvas_pointer)
{		
  	m_canvas = canvas_pointer;  	  	
}

/*********************************************************************************************

Function:		Slide_show::on_timer	
receives: 		timer event
Return:			N/A
Description;	The timer will send one image at a time to display on canvas

************************************************************************************************/


void Slide_show::on_timer(wxTimerEvent& event)
{
	//The timer will call this function after a user specified interval
	send_to_display_image();    	
}

//--------------------------------------------------------------------------------------------------------

/*********************************************************************************************

Function:		Slide_show::on_slide_show
receives: 	    N/A
Return:		    N/A
Description;	A list of images is loaded in a vector of wxArrayString type

************************************************************************************************/


/*void Slide_show::on_slide_show ()
{		
	
	//user will select a number of files to display slide show
	
	wxFileDialog dialog(this, "Select Images for Slide Show.",
                        "", "", wxFileSelectorDefaultWildcardStr,
                        wxMULTIPLE);
	
    if (dialog.ShowModal() == wxID_OK)
    {

        dialog.GetPaths(image_list);
        dialog.GetFilenames(image_names);
    }

} */

/*********************************************************************************************

Function:		Slide_show::start_slide_show
receives: 	    N/A
Return:		    N/A
Description;	timer is triggered.

************************************************************************************************/


void Slide_show::start_slide_show(long user_interval, vector <wxString> & list)
{
	
	//The function will start the timer to start the slide show
	
	image_list = list;
	slide_show_timer = new wxTimer (this, ID_Slide_Show_Timer);
	slide_show_timer->Start(user_interval);
	
}

/*********************************************************************************************

Function:		Slide_show::send_to_load_file
receives: 	    N/A
Return:		    N/A
Description;	The timer calls this function which sends one file at a time to display the image

************************************************************************************************/


//	The timer will call this function which will send one image at  a time to showImage()

void Slide_show::send_to_display_image()
{

    size_t count = image_list.size();

    static size_t num_of_images = 0;                       // timer will start from the 2nd element

    if (num_of_images == count)
    {
    		slide_show_timer->Stop();
    		num_of_images = 0;
    		m_canvas->load_file(image_list[0]);           	//reset the count to the first element in the vector of paths[].
    }
    else
    {
        wxString path = image_list[num_of_images].c_str();
    //    wxString file_name = image_names[num_of_images].c_str();
       m_canvas->load_file(path);

       num_of_images++;
    }


    	
}
//--------------------------------------------------------------------------------------------------------
