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
Shinya Kitaoka 120a6e
DeformationSelector::DeformationSelector() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
DeformationSelector::~DeformationSelector() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
DeformationSelector *DeformationSelector::instance() {
Shinya Kitaoka 120a6e
  static DeformationSelector singleton;
Shinya Kitaoka 120a6e
  return &singleton;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void DeformationSelector::add(StrokeDeformationImpl *deformation,
Shinya Kitaoka 120a6e
                              int priority) {
Shinya Kitaoka 120a6e
  assert(deformation && "Not deformation available!!!");
Shinya Kitaoka 120a6e
  if (!deformation) return;
Shinya Kitaoka 120a6e
  Deformation val(deformation, priority);
Shinya Kitaoka 120a6e
  ref_.push_back(val);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
StrokeDeformationImpl *DeformationSelector::getDeformation(
Shinya Kitaoka 120a6e
    const ContextStatus *status) {
Shinya Kitaoka 120a6e
  assert(status && "Not status available!!!");
Shinya Kitaoka 120a6e
  if (!status) return 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  Deformation candidate((StrokeDeformationImpl *)0, -1);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // by default lower deformator is selected
Shinya Kitaoka 120a6e
  Deformation default_def((StrokeDeformationImpl *)0, -1);
Shinya Kitaoka 120a6e
  if (!ref_.empty()) default_def = ref_[0];
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  vector<deformation>::iterator it, end = ref_.end();</deformation>
Shinya Kitaoka 120a6e
  for (it = ref_.begin(); it != end; ++it) {
Shinya Kitaoka 120a6e
    StrokeDeformationImpl *tmp = it->first;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (tmp->check(status)) {
Shinya Kitaoka 120a6e
      if (it->second > candidate.second) {
Shinya Kitaoka 120a6e
        candidate                                        = *it;
Shinya Kitaoka 120a6e
        if (it->second < default_def.second) default_def = *it;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    if (tmp->getShortcutKey() == status->key_event_) {
Shinya Kitaoka 120a6e
      return tmp;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // if there is a good candidate return it
Shinya Kitaoka 120a6e
  if (candidate.first) return candidate.first;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // else select a lower deformator (smooth)
Shinya Kitaoka 120a6e
  return default_def.first;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
//  End Of File
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------