Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef _DEBUG
Toshihiro Shimizu 890ddd
#define _STLP_DEBUG 1
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
#include "DeformationSelector.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace ToonzExt;
Toshihiro Shimizu 890ddd
using namespace std;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
DeformationSelector::DeformationSelector()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
DeformationSelector::~DeformationSelector()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
DeformationSelector *
Toshihiro Shimizu 890ddd
DeformationSelector::instance()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	static DeformationSelector singleton;
Toshihiro Shimizu 890ddd
	return &singleton;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void DeformationSelector::add(StrokeDeformationImpl *deformation,
Toshihiro Shimizu 890ddd
							  int priority)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(deformation && "Not deformation available!!!");
Toshihiro Shimizu 890ddd
	if (!deformation)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	Deformation val(deformation, priority);
Toshihiro Shimizu 890ddd
	ref_.push_back(val);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
StrokeDeformationImpl *
Toshihiro Shimizu 890ddd
DeformationSelector::getDeformation(const ContextStatus *status)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(status && "Not status available!!!");
Toshihiro Shimizu 890ddd
	if (!status)
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	Deformation candidate((StrokeDeformationImpl *)0, -1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// by default lower deformator is selected
Toshihiro Shimizu 890ddd
	Deformation default_def((StrokeDeformationImpl *)0, -1);
Toshihiro Shimizu 890ddd
	if (!ref_.empty())
Toshihiro Shimizu 890ddd
		default_def = ref_[0];
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	vector<deformation>::iterator</deformation>
Toshihiro Shimizu 890ddd
		it,
Toshihiro Shimizu 890ddd
		end = ref_.end();
Toshihiro Shimizu 890ddd
	for (it = ref_.begin();
Toshihiro Shimizu 890ddd
		 it != end;
Toshihiro Shimizu 890ddd
		 ++it) {
Toshihiro Shimizu 890ddd
		StrokeDeformationImpl
Toshihiro Shimizu 890ddd
			*tmp = it->first;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (tmp->check(status)) {
Toshihiro Shimizu 890ddd
			if (it->second >
Toshihiro Shimizu 890ddd
				candidate.second) {
Toshihiro Shimizu 890ddd
				candidate = *it;
Toshihiro Shimizu 890ddd
				if (it->second < default_def.second)
Toshihiro Shimizu 890ddd
					default_def = *it;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		if (tmp->getShortcutKey() ==
Toshihiro Shimizu 890ddd
			status->key_event_) {
Toshihiro Shimizu 890ddd
			return tmp;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// if there is a good candidate return it
Toshihiro Shimizu 890ddd
	if (candidate.first)
Toshihiro Shimizu 890ddd
		return candidate.first;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// else select a lower deformator (smooth)
Toshihiro Shimizu 890ddd
	return default_def.first;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
//  End Of File
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------