///////////////////////////////////////////////////////////////////////////////////////////
// Authors: Eva Bunodiere, Yasmin Kossak
// ZoomSettingsDialog.cpp
// ZoomSettingsDialog Class Function Definitions
// JPC36 Wx-View 
// July 25th 2000
// Technical Advisor : Carlos Moreno
///////////////////////////////////////////////////////////////////////////////////////////

#include "ZoomSettingsDialog.h"

#include "wx-view.h"

#include <sstream>
#include <cmath>
using namespace std;

/******************************************************************************************
	Function: ZoomSettingsDialog::ZoomSettingsDialog
	Receives: N/A (constructor)
	Returns: N/A (constructor)
	Description: 
		Calls the wxDialog constructor to create a new zoom settings dialog for the application.
		Creates a new wxRadioBox for the zoom type choice, and a wxTextCtrl for the zoom factor.
		Resizes the Dialog after placing the controls to ensure correct positioning. Adds Cancel
		and OK buttons to dismiss the dialog.
*******************************************************************************************/
ZoomSettingsDialog::ZoomSettingsDialog(wxWindow * parent, wxWindowID id, const wxString &title, double saved_zoom_factor, bool saved_zoom_type)
    : wxDialog (parent, id, title, wxDefaultPosition, wxSize(275, 150))
{
    const int margin = 20;

    wxString Choices [] = {translation["Stretching"], translation["Interpolation"]};

    zoom_choices = new wxRadioBox(this, -1, translation["Zoom Choices"], wxPoint(margin, margin), wxDefaultSize,
		                         WXSIZEOF(Choices), Choices, 1, wxRA_SPECIFY_COLS,
		                         wxDefaultValidator, translation["Zoom Choices"]);
    zoom_choices->SetSelection(saved_zoom_type);
	
	// Place all controls in positions relative to the previously created controls
    
	const int x_ok = zoom_choices->GetRect().GetRight() + 20;
    ok = new wxButton(this, wxID_OK, translation["OK"], wxPoint(x_ok, margin));
    const int y_cancel = ok->GetRect().GetBottom() + 15;
	cancel = new wxButton(this, wxID_CANCEL, translation["Cancel"], wxPoint(x_ok, y_cancel));
	
	const int y_label = zoom_choices->GetRect().GetBottom() + 15;
	zoom_factor_label = new wxStaticText(this, -1, translation["Zoom Factor"], wxPoint(margin, y_label));
	const int y_text = zoom_factor_label->GetRect().GetBottom() + 3;
	zoom_factor_choice = new wxTextCtrl (this, -1, "", wxPoint(margin, y_text));
	
    ostringstream buffer;
    buffer << saved_zoom_factor;
    string temp = buffer.str();
	zoom_factor_choice->SetValue(temp.c_str());
	
	int w, h, client_w, client_h;
	GetSize (&w, &h);
	GetClientSize (&client_w, &client_h);
	
	const int dx = w - client_w;
	const int dy = h - client_h;
	
	const int width = ok->GetRect().GetRight() + margin + dx;
	const int height = zoom_factor_choice->GetRect().GetBottom() + margin + dy;
	
	SetSize (width, height);
	CentreOnParent(wxBOTH);
}

/******************************************************************************************
	Function: ZoomSettingsDialog::zoom_factor()
	Receives: N/A
	Returns: double
	Description:
		Returns the input of the user from the text control and converts the result to a
		double.
*******************************************************************************************/
double ZoomSettingsDialog::zoom_factor() const
{
    return atof(zoom_factor_choice->GetValue().c_str());

}

/******************************************************************************************
	Function: ZoomSettingsDialog::zoom_by_interpollation
	Receives: N/A
	Returns: bool
	Description:
		Returns the zoom type selected by the user, true if interpolation selected, false
		if stretching selected.
*******************************************************************************************/
bool ZoomSettingsDialog::zoom_by_interpolation() const
{
    return zoom_choices->GetSelection() == 1;
}
