CanadianMachines / CanadianExperienceLib / MachineDrawable.cpp
MachineDrawable.cpp
Raw
/**
 * @file MachineDrawable.cpp
 * @author sriram
 */

#include "pch.h"
#include "MachineDrawable.h"
#include "Drawable.h"
#include <machine-api.h>

/**
 *
 * @param name drawable name
 * @param resourcesDir resources
 * @param audioEngine
 * @param num  machine number
 * @param startTime
 * @param endTime
 */
MachineDrawable::MachineDrawable(const std::wstring& name,std::wstring resourcesDir,
								 ma_engine* audioEngine,int num, int startTime, int endTime):
								Drawable(name),mStartTime(startTime),mEndTime(endTime)
{
	MachineSystemFactory factory(resourcesDir, audioEngine);
	mMachine = factory.CreateMachineSystem();
	mMachine->SetMachineNumber(num);
}

/**
 * draws machine system
 * @param graphics
 */
void MachineDrawable::Draw(std::shared_ptr<wxGraphicsContext> graphics)
{

	double scale = 0.5f;

	graphics->PushState();
	graphics->Translate(mPlacedPosition.x, mPlacedPosition.y);
	graphics->Scale(scale, scale);
	mMachine->SetLocation(GetPosition());
	mMachine->DrawMachine(graphics);
	graphics->PopState();

	if (mTimeline!=nullptr)
	{
		auto currFrame = mTimeline->GetCurrentFrame();
		if(mStartTime <= currFrame && currFrame <= mEndTime)
		{
			mMachine->SetMachineFrame(currFrame-mStartTime);
		}
	}
}

/**
 * setter for timeline
 * @param timeline
 */
void MachineDrawable::SetTimeline(Timeline *timeline)
{
	Drawable::SetTimeline(timeline);
	mTimeline=timeline;
	mMachine->SetFrameRate(mTimeline->GetFrameRate());
}

/**
 * setter for machine number
 * @param mainFrame
 */
void MachineDrawable::SetMachineNumber(wxWindow* mainFrame)
{
	MachineDialog dlg(mainFrame, mMachine);
	if (dlg.ShowModal() == wxID_OK)
	{

	}
}