// scaleVe.cpp : implementation file
//

#include "stdafx.h"
#include "megatune.h"
#include "scaleVe.h"
#include "msDatabase.h"
#include "veconst.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//------------------------------------------------------------------------------

extern msDatabase mdb;

/////////////////////////////////////////////////////////////////////////////
// scaleVe dialog


scaleVe::scaleVe(CWnd* pParent /*=NULL*/)
	: CDialog(scaleVe::IDD, pParent)
{
	//{{AFX_DATA_INIT(scaleVe)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void scaleVe::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(scaleVe)
	DDX_Control(pDX, IDC_NEW_REQ_FUEL, m_newReqFuel);
	DDX_Control(pDX, IDC_OLD_REQ_FUEL, m_oldReqFuel);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(scaleVe, CDialog)
	//{{AFX_MSG_MAP(scaleVe)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// scaleVe message handlers

void scaleVe::OnOK() 
{
   char txt[20];

   m_oldReqFuel.GetWindowText(txt, sizeof(txt));
   double oldReqFuel = strtod(txt, NULL);
   if (oldReqFuel < 0.1 || oldReqFuel > 25.5) {
      MessageBox("Old ReqFuel must be between 0.1 and 25.5", "Scale VE");
      return;
   }
   
   m_newReqFuel.GetWindowText(txt, sizeof(txt));
   double newReqFuel = strtod(txt, NULL);
   if (newReqFuel < 0.1 || newReqFuel > 25.5) {
      MessageBox("New ReqFuel must be between 0.1 and 25.5", "Scale VE");
      return;
   }

   double scale = oldReqFuel / newReqFuel;
   for (int i = 0; i < 64; i++) {
      mdb.putConstByte(Dve+i, int(scale * mdb.Const(Dve+i) + 0.5));
   }
   
	CDialog::OnOK();
}

