49945e
49945e
f278a5
#include <tpixelutils.h></tpixelutils.h>
49945e
#include <tools inputmanager.h=""></tools>
49945e
c3c215
// TnzCore includes
c3c215
#include <tgl.h></tgl.h>
c3c215
49945e
49945e
//*****************************************************************************************
49945e
//    static members
49945e
//*****************************************************************************************
49945e
9f0c16
static const bool debugInputManager = false;
49945e
TInputState::TouchId TInputManager::m_lastTouchId = 0;
49945e
49945e
49945e
//*****************************************************************************************
49945e
//    TInputModifier implementation
49945e
//*****************************************************************************************
49945e
49945e
49945e
void
49945e
TInputModifier::setManager(TInputManager *manager) {
49945e
  if (m_manager != manager)
49945e
    { m_manager = manager; onSetManager(); }
49945e
}
49945e
49945e
49945e
void
7e9eb1
TInputModifier::modifyTrack(
c3c215
  const TTrack &track,
7e9eb1
  TTrackList &outTracks )
7e9eb1
{
c3c215
  if (!track.handler) {
c3c215
      track.handler = new TTrackHandler(track);
c3c215
      track.handler->tracks.push_back(
7e9eb1
        new TTrack(
c3c215
          new TTrackModifier(*track.handler) ));
7e9eb1
  }
7e9eb1
7e9eb1
  outTracks.insert(
7e9eb1
    outTracks.end(),
c3c215
    track.handler->tracks.begin(),
c3c215
    track.handler->tracks.end() );
c3c215
  if (!track.changed())
7e9eb1
    return;
7e9eb1
00337d
  int start = std::max(0, track.size() - track.pointsAdded);
c3c215
  for(TTrackList::const_iterator ti = track.handler->tracks.begin(); ti != track.handler->tracks.end(); ++ti) {
7e9eb1
    TTrack &subTrack = **ti;
00337d
    subTrack.truncate(start);
c3c215
    for(int i = start; i < track.size(); ++i)
f278a5
      subTrack.push_back( subTrack.modifier->calcPoint(i), false );
f278a5
    subTrack.fix_to(track.fixedSize());
7e9eb1
  }
00337d
  track.resetChanges();
7e9eb1
}
7e9eb1
7e9eb1
7e9eb1
void
49945e
TInputModifier::modifyTracks(
49945e
    const TTrackList &tracks,
49945e
    TTrackList &outTracks )
49945e
{
49945e
  for(TTrackList::const_iterator i = tracks.begin(); i != tracks.end(); ++i)
f278a5
    modifyTrack(**i, outTracks);
49945e
}
49945e
49945e
49945e
void
7e9eb1
TInputModifier::modifyHover(
7e9eb1
  const TPointD &hover,
7e9eb1
  THoverList &outHovers )
7e9eb1
{
7e9eb1
  outHovers.push_back(hover);
7e9eb1
}
7e9eb1
7e9eb1
7e9eb1
void
49945e
TInputModifier::modifyHovers(
49945e
  const THoverList &hovers,
49945e
  THoverList &outHovers )
49945e
{
49945e
  for(THoverList::const_iterator i = hovers.begin(); i != hovers.end(); ++i)
49945e
    modifyHover(*i, outHovers);
49945e
}
49945e
49945e
c3c215
TRectD
c3c215
TInputModifier::calcDrawBounds(const TTrackList &tracks, const THoverList &hovers) {
c3c215
  TRectD bounds;
c3c215
  for(TTrackList::const_iterator i = tracks.begin(); i != tracks.end(); ++i)
c3c215
    bounds += calcDrawBoundsTrack(**i);
c3c215
  for(std::vector<tpointd>::const_iterator i = hovers.begin(); i != hovers.end(); ++i)</tpointd>
c3c215
    bounds += calcDrawBoundsHover(*i);
c3c215
  return bounds;
c3c215
}
c3c215
c3c215
49945e
void
9cf8be
TInputModifier::drawTracks(const TTrackList &tracks) {
49945e
  for(TTrackList::const_iterator i = tracks.begin(); i != tracks.end(); ++i)
c3c215
    drawTrack(**i);
9cf8be
}
9cf8be
9cf8be
9cf8be
void
9cf8be
TInputModifier::drawHovers(const std::vector<tpointd> &hovers) {</tpointd>
9cf8be
  for(std::vector<tpointd>::const_iterator i = hovers.begin(); i != hovers.end(); ++i)</tpointd>
49945e
    drawHover(*i);
49945e
}
49945e
49945e
9cf8be
void
9cf8be
TInputModifier::draw(const TTrackList &tracks, const std::vector<tpointd> &hovers) {</tpointd>
9cf8be
  drawTracks(tracks);
9cf8be
  drawHovers(hovers);
9cf8be
}
9cf8be
9cf8be
49945e
//*****************************************************************************************
49945e
//    TInputHandler implementation
49945e
//*****************************************************************************************
49945e
49945e
49945e
bool
49945e
TInputHandler::inputKeyEvent(
49945e
  bool press,
f278a5
  TInputState::Key,
49945e
  QKeyEvent *event,
f278a5
  const TInputManager& )
49945e
{
d8eddc
  return press && event && inputKeyDown(event);
49945e
}
49945e
49945e
49945e
void
49945e
TInputHandler::inputButtonEvent(
49945e
  bool press,
f278a5
  TInputState::DeviceId,
49945e
  TInputState::Button button,
49945e
  const TInputManager &manager )
49945e
{
49945e
  if (press && button == Qt::RightButton && !manager.getOutputHovers().empty())
49945e
    inputRightButtonDown(manager.getOutputHovers().front(), manager.state);
49945e
}
49945e
49945e
49945e
void
49945e
TInputHandler::inputHoverEvent(const TInputManager &manager) {
49945e
  if (!manager.getOutputHovers().empty())
49945e
    inputMouseMove(manager.getOutputHovers().front(), manager.state);
49945e
}
49945e
49945e
49945e
void
f278a5
TInputHandler::inputPaintTrackPoint(const TTrackPoint &point, const TTrack &track, bool firstTrack, bool preview) {
f278a5
  if (firstTrack && !preview) {
49945e
    if (track.pointsAdded == track.size())
49945e
      inputLeftButtonDown(point, track);
49945e
    else
49945e
    if (point.final)
49945e
      inputLeftButtonUp(point, track);
49945e
    else
49945e
      inputLeftButtonDrag(point, track);
f278a5
  }
49945e
}
49945e
49945e
49945e
void
49945e
TInputHandler::inputPaintTracks(const TTrackList &tracks) {
f278a5
  // prepare tracks counters
f278a5
  for(TTrackList::const_iterator i = tracks.begin(); i != tracks.end(); ++i) {
f278a5
    (*i)->pointsAdded = (*i)->fixedPointsAdded + (*i)->previewSize();
f278a5
    (*i)->resetRemoved();
f278a5
  }
f278a5
  
f278a5
  // begin paint
f278a5
  bool preview = false;
f278a5
  bool paintStarted = false;
f278a5
49945e
  // paint track points in chronological order
49945e
  while(true) {
f278a5
    // find earlier not painted point
49945e
    TTrackP track;
49945e
    TTimerTicks minTicks = 0;
49945e
    double minTimeOffset = 0.0;
49945e
    for(TTrackList::const_iterator i = tracks.begin(); i != tracks.end(); ++i) {
49945e
      const TTrack &t = **i;
49945e
      if (t.pointsAdded > 0) {
49945e
        TTimerTicks ticks = t.ticks();
49945e
        double timeOffset = t.timeOffset() + t.current().time;
49945e
        if (!track || (ticks - minTicks)*TToolTimer::frequency + timeOffset - minTimeOffset < 0.0) {
49945e
          track = *i;
49945e
          minTicks = ticks;
49945e
          minTimeOffset = timeOffset;
49945e
        }
49945e
      }
49945e
    }
f278a5
    
f278a5
    if (!track)
f278a5
      break; // all tracks are painted
f278a5
    
f278a5
    if (track->pointsAdded <= track->previewSize())
f278a5
      preview = true;
f278a5
    if (!paintStarted)
f278a5
      { inputPaintTracksBegin(); paintStarted = true; }
f278a5
    inputPaintTrackPoint(track->current(), *track, track == tracks.front(), preview);
f278a5
    
f278a5
    // update counters
49945e
    --track->pointsAdded;
f278a5
    if (!preview) {
f278a5
      assert(track->fixedPointsAdded > 0);
f278a5
      --track->fixedPointsAdded;
f278a5
    }
49945e
  }
f278a5
f278a5
  // end paint
f278a5
  if (paintStarted)
f278a5
    inputPaintTracksEnd();
49945e
}
49945e
49945e
49945e
//*****************************************************************************************
49945e
//    TInputManager implementation
49945e
//*****************************************************************************************
49945e
49945e
49945e
TInputManager::TInputManager():
d8eddc
  m_lastTicks(TToolTimer::ticks()),
49945e
  m_handler(),
49945e
  m_tracks(1),
49945e
  m_hovers(1),
7a5892
  m_started(),
dba7b5
  drawPreview()
49945e
{ }
49945e
49945e
49945e
void
f278a5
TInputManager::paintTracks() {
f278a5
  // run modifiers
f278a5
  for(int i = 0; i < (int)m_modifiers.size(); ++i) {
f278a5
    m_tracks[i+1].clear();
f278a5
    m_modifiers[i]->modifyTracks(m_tracks[i], m_tracks[i+1]);
49945e
  }
f278a5
  TTrackList &subTracks = m_tracks.back();
49945e
f278a5
  
f278a5
  // begin painting if need
f278a5
  bool changed = false;
f278a5
  for(TTrackList::const_iterator i = subTracks.begin(); i != subTracks.end(); ++i)
f278a5
    if ((*i)->changed())
f278a5
      { changed = true; break; }
f278a5
  if (!m_started && changed) {
f278a5
    m_started = true;
f278a5
    if (m_handler) m_handler->inputSetBusy(true);
49945e
  }
49945e
f278a5
  
f278a5
  // paint tracks
f278a5
  if (changed && m_handler)
f278a5
    m_handler->inputPaintTracks(subTracks);
f278a5
  
f278a5
  
f278a5
  // end painting if all tracks are finished
49945e
  bool allFinished = true;
49945e
  for(TTrackList::const_iterator i = m_tracks.front().begin(); i != m_tracks.front().end(); ++i)
f278a5
    if (!(*i)->fixedFinished())
49945e
      { allFinished = false; break; }
f278a5
  if (allFinished)
49945e
    for(TTrackList::const_iterator i = subTracks.begin(); i != subTracks.end(); ++i)
f278a5
      if (!(*i)->fixedFinished())
f278a5
        { allFinished = false; break; }
f278a5
        
f278a5
  if (allFinished) {
f278a5
    if (m_started) {
f278a5
      if (m_handler) m_handler->inputSetBusy(false);
f278a5
      m_started = false;
49945e
    }
f278a5
    for(int i = 0; i < (int)m_tracks.size(); ++i)
f278a5
      m_tracks[i].clear();
49945e
  }
49945e
}
49945e
49945e
49945e
int
49945e
TInputManager::trackCompare(
49945e
  const TTrack &track,
49945e
  TInputState::DeviceId deviceId,
d8eddc
  TInputState::TouchId touchId ) const
49945e
{
49945e
  if (track.deviceId < deviceId) return -1;
49945e
  if (deviceId < track.deviceId) return  1;
49945e
  if (track.touchId < touchId) return -1;
49945e
  if (touchId < track.touchId) return 1;
49945e
  return 0;
49945e
}
49945e
49945e
49945e
const TTrackP&
49945e
TInputManager::createTrack(
49945e
  int index,
49945e
  TInputState::DeviceId deviceId,
49945e
  TInputState::TouchId touchId,
49945e
  TTimerTicks ticks,
49945e
  bool hasPressure,
49945e
  bool hasTilt )
49945e
{
49945e
  TTrackP track = new TTrack(
49945e
    deviceId,
49945e
    touchId,
49945e
    state.keyHistoryHolder(ticks),
49945e
    state.buttonHistoryHolder(deviceId, ticks),
49945e
    hasPressure,
49945e
    hasTilt );
49945e
  return *m_tracks.front().insert(m_tracks[0].begin() + index, track);
49945e
}
49945e
49945e
49945e
const TTrackP&
49945e
TInputManager::getTrack(
49945e
  TInputState::DeviceId deviceId,
49945e
  TInputState::TouchId touchId,
49945e
  TTimerTicks ticks,
49945e
  bool hasPressure,
49945e
  bool hasTilt )
49945e
{
49945e
  TTrackList &origTracks = m_tracks.front();
49945e
  if (origTracks.empty())
49945e
    return createTrack(0, deviceId, touchId, ticks, hasPressure, hasTilt);
49945e
  int cmp;
49945e
49945e
  int a = 0;
49945e
  cmp = trackCompare(*origTracks[a], deviceId, touchId);
49945e
  if (cmp == 0) return origTracks[a];
49945e
  if (cmp < 0) return createTrack(a, deviceId, touchId, ticks, hasPressure, hasTilt);
49945e
49945e
  int b = (int)origTracks.size() - 1;
49945e
  cmp = trackCompare(*origTracks[b], deviceId, touchId);
49945e
  if (cmp == 0) return origTracks[b];
49945e
  if (cmp > 0) return createTrack(b+1, deviceId, touchId, ticks, hasPressure, hasTilt);
49945e
49945e
  // binary search: tracks[a] < tracks[c] < tracks[b]
49945e
  while(true) {
49945e
    int c = (a + b)/2;
49945e
    if (a == c) break;
49945e
    cmp = trackCompare(*origTracks[c], deviceId, touchId);
49945e
    if (cmp < 0) b = c; else
49945e
      if (cmp > 0) a = c; else
49945e
        return origTracks[c];
49945e
  }
49945e
  return createTrack(b, deviceId, touchId, ticks, hasPressure, hasTilt);
49945e
}
49945e
49945e
49945e
void
49945e
TInputManager::addTrackPoint(
49945e
  const TTrackP& track,
49945e
  const TPointD &position,
49945e
  double pressure,
49945e
  const TPointD &tilt,
49945e
  double time,
49945e
  bool final )
49945e
{
f278a5
  track->push_back(
f278a5
    TTrackPoint(
f278a5
      position,
f278a5
      pressure,
f278a5
      tilt,
f278a5
      (double)track->size(),
f278a5
      time,
f278a5
      0.0, // length will calculated inside of TTrack::push_back
f278a5
      final ),
f278a5
    true );
49945e
}
49945e
49945e
49945e
void
49945e
TInputManager::touchTracks(bool finish) {
49945e
  for(TTrackList::const_iterator i = m_tracks.front().begin(); i != m_tracks.front().end(); ++i) {
49945e
    if (!(*i)->finished() && (*i)->size() > 0) {
49945e
      const TTrackPoint &p = (*i)->back();
d8eddc
      addTrackPoint(*i, p.position, p.pressure, p.tilt, fixTicks(m_lastTicks)*TToolTimer::step, finish);
49945e
    }
49945e
  }
49945e
}
49945e
49945e
49945e
void
49945e
TInputManager::modifierActivate(const TInputModifierP &modifier) {
49945e
  modifier->setManager(this);
49945e
  modifier->activate();
49945e
}
49945e
49945e
49945e
void
49945e
TInputManager::modifierDeactivate(const TInputModifierP &modifier) {
49945e
  modifier->deactivate();
49945e
  modifier->setManager(NULL);
49945e
}
49945e
49945e
49945e
void
c3c215
TInputManager::processTracks() {
c3c215
  paintTracks();
9e42bc
  if (m_handler) {
9e42bc
    TRectD bounds = calcDrawBounds();
9e42bc
    if (!bounds.isEmpty()) {
9e42bc
      m_handler->inputInvalidateRect(m_prevBounds + bounds);
9e42bc
      m_nextBounds += bounds;
9e42bc
    }
7a5892
  }
c3c215
}
49945e
49945e
49945e
void
49945e
TInputManager::finishTracks() {
49945e
  touchTracks(true);
49945e
  processTracks();
49945e
}
49945e
49945e
49945e
void
49945e
TInputManager::reset() {
f278a5
  // forget about handler busy state
49945e
  // assuime it was already reset by outside
7a5892
  m_started = false;
49945e
49945e
  // reset tracks
49945e
  for(int i = 0; i < (int)m_tracks.size(); ++i)
49945e
    m_tracks[i].clear();
49945e
}
49945e
49945e
49945e
void
49945e
TInputManager::setHandler(TInputHandler *handler) {
d8eddc
  if (m_handler == handler) return;
d8eddc
  finishTracks();
49945e
  m_handler = handler;
49945e
}
49945e
49945e
49945e
int
49945e
TInputManager::findModifier(const TInputModifierP &modifier) const {
49945e
  for(int i = 0; i < getModifiersCount(); ++i)
49945e
    if (getModifier(i) == modifier)
49945e
      return i;
49945e
  return -1;
49945e
}
49945e
49945e
49945e
void
49945e
TInputManager::insertModifier(int index, const TInputModifierP &modifier) {
49945e
  if (findModifier(modifier) >= 0) return;
49945e
  finishTracks();
49945e
  m_modifiers.insert(m_modifiers.begin() + index, modifier);
49945e
  m_tracks.insert(m_tracks.begin() + index + 1, TTrackList());
49945e
  m_hovers.insert(m_hovers.begin() + index + 1, THoverList());
49945e
  modifierActivate(modifier);
49945e
}
49945e
49945e
49945e
void
49945e
TInputManager::removeModifier(int index) {
49945e
  if (index >= 0 && index < getModifiersCount()) {
49945e
    finishTracks();
49945e
    modifierDeactivate(m_modifiers[index]);
49945e
    m_modifiers.erase(m_modifiers.begin() + index);
49945e
    m_tracks.erase(m_tracks.begin() + index + 1);
49945e
    m_hovers.erase(m_hovers.begin() + index + 1);
49945e
  }
49945e
}
49945e
49945e
49945e
void
49945e
TInputManager::clearModifiers() {
49945e
  while(getModifiersCount() > 0)
49945e
    removeModifier(getModifiersCount() - 1);
49945e
}
49945e
49945e
49945e
void
49945e
TInputManager::trackEvent(
49945e
  TInputState::DeviceId deviceId,
49945e
  TInputState::TouchId touchId,
49945e
  const TPointD &position,
49945e
  const double *pressure,
49945e
  const TPointD *tilt,
49945e
  bool final,
49945e
  TTimerTicks ticks )
49945e
{
d8eddc
  ticks = fixTicks(ticks);
49945e
  TTrackP track = getTrack(deviceId, touchId, ticks, (bool)pressure, (bool)tilt);
49945e
  if (!track->finished()) {
d8eddc
    ticks = fixTicks(ticks);
49945e
    double time = (double)(ticks - track->ticks())*TToolTimer::step - track->timeOffset();
49945e
    addTrackPoint(
49945e
      track,
49945e
      position,
49945e
      pressure ? *pressure : 0.5,
49945e
      tilt ? *tilt : TPointD(),
49945e
      time,
49945e
      final );
49945e
  }
49945e
}
49945e
49945e
49945e
bool
49945e
TInputManager::keyEvent(
49945e
  bool press,
49945e
  TInputState::Key key,
49945e
  TTimerTicks ticks,
49945e
  QKeyEvent *event )
49945e
{
9f0c16
  bool wasPressed = state.isKeyPressed(key);
d8eddc
  ticks = fixTicks(ticks);
49945e
  state.keyEvent(press, key, ticks);
49945e
  processTracks();
49945e
  bool result = m_handler && m_handler->inputKeyEvent(press, key, event, *this);
9f0c16
  if (wasPressed != press) {
9f0c16
    touchTracks();
9f0c16
    processTracks();
9f0c16
    //hoverEvent(getInputHovers());
9f0c16
  }
49945e
  return result;
49945e
}
49945e
49945e
49945e
void
49945e
TInputManager::buttonEvent(
49945e
  bool press,
49945e
  TInputState::DeviceId deviceId,
49945e
  TInputState::Button button,
49945e
  TTimerTicks ticks )
49945e
{
9f0c16
  bool wasPressed = state.isButtonPressed(deviceId, button);
d8eddc
  ticks = fixTicks(ticks);
49945e
  state.buttonEvent(press, deviceId, button, ticks);
49945e
  processTracks();
49945e
  if (m_handler) m_handler->inputButtonEvent(press, deviceId, button, *this);
9f0c16
  if (wasPressed != press) {
9f0c16
    touchTracks();
9f0c16
    processTracks();
9f0c16
    //hoverEvent(getInputHovers());
9f0c16
  }
49945e
}
49945e
49945e
49945e
void
49945e
TInputManager::hoverEvent(const THoverList &hovers) {
49945e
  if (&m_hovers[0] != &hovers)
49945e
    m_hovers[0] = hovers;
49945e
  for(int i = 0; i < (int)m_modifiers.size(); ++i) {
49945e
    m_hovers[i+1].clear();
49945e
    m_modifiers[i]->modifyHovers(m_hovers[i], m_hovers[i+1]);
49945e
  }
362052
  if (m_handler) {
362052
    TRectD bounds = calcDrawBounds();
7a5892
    if (!bounds.isEmpty()) {
7a5892
      m_handler->inputInvalidateRect(m_prevBounds + bounds);
7a5892
      m_nextBounds += bounds;
7a5892
    }
362052
    m_handler->inputHoverEvent(*this);
362052
  }
49945e
}
49945e
49945e
c3c215
TRectD
c3c215
TInputManager::calcDrawBounds() {
9f0c16
  if (debugInputManager)
9f0c16
    return TConsts::infiniteRectD;
9f0c16
c3c215
  TRectD bounds;
c3c215
  for(int i = 0; i < (int)m_modifiers.size(); ++i)
c3c215
    bounds += m_modifiers[i]->calcDrawBounds(m_tracks[i], m_hovers[i]);
c3c215
f278a5
  if (drawPreview) {
c3c215
    for(TTrackList::const_iterator ti = getOutputTracks().begin(); ti != getOutputTracks().end(); ++ti) {
c3c215
      TTrack &track = **ti;
f278a5
      int start = std::max(0, track.fixedSize() - track.fixedPointsAdded);
f278a5
      if (start + 1 < track.size())
f278a5
        for(int i = start + 1; i < track.size(); ++i)
f278a5
          bounds += boundingBox(track[i-1].position, track[i].position);
c3c215
    }
c3c215
  }
c3c215
c3c215
  if (!bounds.isEmpty())
362052
    bounds.enlarge(4.0);
c3c215
  
c3c215
  return bounds;
c3c215
}
c3c215
c3c215
49945e
void
49945e
TInputManager::draw() {
7a5892
  m_prevBounds = m_nextBounds;
7a5892
  m_nextBounds = TRectD();
7a5892
  
f278a5
  // paint not fixed parts of tracks
f278a5
  if (drawPreview) {
c3c215
    glPushAttrib(GL_ALL_ATTRIB_BITS);
c3c215
    tglEnableBlending();
dba7b5
    tglEnableLineSmooth(true, 1.0);
37c008
    double pixelSize = sqrt(tglGetPixelSize2());
f278a5
    double colorBlack[4] = { 0.0, 0.0, 0.0, 0.5 };
f278a5
    double colorWhite[4] = { 1.0, 1.0, 1.0, 0.5 };
c3c215
    for(TTrackList::const_iterator ti = getOutputTracks().begin(); ti != getOutputTracks().end(); ++ti) {
c3c215
      TTrack &track = **ti;
f278a5
      int start = std::max(0, track.fixedSize() - track.fixedPointsAdded);
f278a5
      const TPointD *a = &track[start].position;
f278a5
      for(int i = start + 1; i < track.size(); ++i) {
f278a5
        const TPointD *b = &track[i].position;
f278a5
        TPointD d = *b - *a;
f278a5
        double k = norm2(d);
f278a5
        if (k > TConsts::epsilon*TConsts::epsilon) {
f278a5
          k = 0.5*pixelSize/sqrt(k);
f278a5
          d = TPointD(-k*d.y, k*d.x);
f278a5
          glColor4dv(colorWhite);
f278a5
          tglDrawSegment(*a - d, *b - d);
f278a5
          glColor4dv(colorBlack);
f278a5
          tglDrawSegment(*a + d, *b + d);
f278a5
          a = b;
f278a5
        }
f278a5
      }
f278a5
    }
f278a5
    glPopAttrib();
f278a5
  }
f278a5
  
f278a5
  // paint all tracks modifications for debug
f278a5
  if (debugInputManager) {
f278a5
    double pixelSize = sqrt(tglGetPixelSize2());
f278a5
    double color[4] = { 0.0, 0.0, 0.0, 0.5 };
f278a5
    int cnt = m_tracks.size();
f278a5
    for(int li = 0; li < cnt; ++li) {
f278a5
      HSV2RGB(240 + li*120.0/(cnt-1), 1, 1, &color[0], &color[1], &color[2]);
f278a5
      glColor4dv(color);
f278a5
      for(TTrackList::const_iterator ti = m_tracks[li].begin(); ti != m_tracks[li].end(); ++ti) {
f278a5
        assert(*ti);
f278a5
        const TTrack &track = **ti;
f278a5
        int radius = 0;
f278a5
        const TPointD *a = &track[0].position;
f278a5
        for(int i = 0; i < track.size(); ++i) {
f278a5
          const TPointD *b = &track[i].position;
f278a5
          
f278a5
          if (i) {
f278a5
            TPointD d = *b - *a;
37c008
            double k = norm2(d);
f278a5
            if (k > 4*pixelSize*pixelSize) {
f278a5
              tglDrawSegment(*a, *b);
f278a5
              radius = 0;
f278a5
              a = b;
9f0c16
            } else {
f278a5
              ++radius;
49945e
            }
49945e
          }
f278a5
          
f278a5
          if (radius && li == 0)
f278a5
            tglDrawCircle(*b, radius*pixelSize*3);
49945e
        }
49945e
      }
49945e
    }
49945e
  }
49945e
49945e
  // paint modifiers
49945e
  for(int i = 0; i < (int)m_modifiers.size(); ++i)
49945e
    m_modifiers[i]->draw(m_tracks[i], m_hovers[i]);
49945e
}
49945e
49945e
TInputState::TouchId
49945e
TInputManager::genTouchId()
49945e
  { return ++m_lastTouchId; }