コード例 #1
0
 // Implements steps according to the current speed
 // You must call this at least once per step
 // returns true if a step occurred
 boolean EightAccelStepper::runSpeed()
 {
     unsigned long time = millis();
     
     if (time > getLastStepTime() + getStepInterval())
     {
         if (getSpeed() > 0)
         {
             // Clockwise
             setCurrentPos(getCurrentPos() + 1);
         }
         else if (getSpeed() < 0)
         {
             // Anticlockwise
             setCurrentPos(getCurrentPos() - 1);            
         }
         if (getPins() == 8) {
             step(getCurrentPos() & 0x7); // Bottom 3 bits (same as mod 8, but works with + and - numbers)                 
         } else {
             step(getCurrentPos() & 0x3); // Bottom 2 bits (same as mod 4, but works with + and - numbers) 
         }
         
         setLastStepTime(time);
         return true;
     }
     else
         return false;
 }
コード例 #2
0
ファイル: Scrollbar.cpp プロジェクト: achellies/WinCEWebKit
bool Scrollbar::scroll(ScrollDirection direction, ScrollGranularity granularity, float multiplier)
{
#if HAVE(ACCESSIBILITY)
    if (AXObjectCache::accessibilityEnabled()) {
        if (parent() && parent()->isFrameView()) {
            Document* document = static_cast<FrameView*>(parent())->frame()->document();
            AXObjectCache* cache = document->axObjectCache();
            AccessibilityScrollbar* axObject = static_cast<AccessibilityScrollbar*>(cache->getOrCreate(ScrollBarRole));
            axObject->setScrollbar(this);
            cache->postNotification(axObject, document, AXObjectCache::AXValueChanged, true);
        }
    }
#endif

    // Ignore perpendicular scrolls.
    if ((m_orientation == HorizontalScrollbar) ? (direction == ScrollUp || direction == ScrollDown) : (direction == ScrollLeft || direction == ScrollRight))
        return false;
    float step = 0;
    switch (granularity) {
    case ScrollByLine:     step = m_lineStep;  break;
    case ScrollByPage:     step = m_pageStep;  break;
    case ScrollByDocument: step = m_totalSize; break;
    case ScrollByPixel:    step = m_pixelStep; break;
    }
    if (direction == ScrollUp || direction == ScrollLeft)
        multiplier = -multiplier;
    if (client())
        return client()->scroll(m_orientation, granularity, step, multiplier);

    return setCurrentPos(max(min(m_currentPos + (step * multiplier), static_cast<float>(m_totalSize - m_visibleSize)), 0.0f), NotFromScrollAnimator);
}
コード例 #3
0
ファイル: Scrollbar.cpp プロジェクト: achellies/WinCEWebKit
bool Scrollbar::setValue(int v, ScrollSource source)
{
    v = max(min(v, m_totalSize - m_visibleSize), 0);
    if (value() == v)
        return false; // Our value stayed the same.
    setCurrentPos(v, source);
    return true;
}
コード例 #4
0
ファイル: streamreader.cpp プロジェクト: KDE/phonon-vlc
bool StreamReader::read(quint64 pos, int *length, char *buffer)
{
    QMutexLocker lock(&m_mutex);
    DEBUG_BLOCK;
    bool ret = true;

    if (m_unlocked) {
        return ret;
    }

    if (currentPos() != pos) {
        if (!streamSeekable()) {
            return false;
        }
        setCurrentPos(pos);
    }

    if (m_buffer.capacity() < *length) {
        m_buffer.reserve(*length);
    }

    while (currentBufferSize() < static_cast<unsigned int>(*length)) {
        quint64 oldSize = currentBufferSize();
        needData();

        m_waitingForData.wait(&m_mutex);

        if (oldSize == currentBufferSize()) {
            if (m_eos && m_buffer.isEmpty()) {
                return false;
            }
            // We didn't get any more data
            *length = static_cast<int>(oldSize);
            // If we have some data to return, why tell to reader that we failed?
            // Remember that length argument is more like maxSize not requiredSize
            ret = true;
        }
    }

    if (m_mediaObject->state() != Phonon::BufferingState &&
        m_mediaObject->state() != Phonon::LoadingState) {
        enoughData();
    }

    memcpy(buffer, m_buffer.data(), *length);
    m_pos += *length;
    // trim the buffer by the amount read
    m_buffer = m_buffer.mid(*length);

    return ret;
}
コード例 #5
0
ファイル: Scrollbar.cpp プロジェクト: achellies/WinCEWebKit
void Scrollbar::moveThumb(int pos)
{
    // Drag the thumb.
    int thumbPos = theme()->thumbPosition(this);
    int thumbLen = theme()->thumbLength(this);
    int trackLen = theme()->trackLength(this);
    int maxPos = trackLen - thumbLen;
    int delta = pos - m_pressedPos;
    if (delta > 0)
        delta = min(maxPos - thumbPos, delta);
    else if (delta < 0)
        delta = max(-thumbPos, delta);
    if (delta)
        setCurrentPos(static_cast<float>(thumbPos + delta) * maximum() / (trackLen - thumbLen), NotFromScrollAnimator);
}
コード例 #6
0
ファイル: iodevicereader.cpp プロジェクト: FilipBE/qtextended
              HRESULT read(LONGLONG pos, LONG length, BYTE *buffer, LONG *actual)
              {
                  QMutexLocker locker(&m_mutexRead);

                  if (m_mediaGraph->isStopping()) {
                      return VFW_E_WRONG_STATE;
                  }

                  if(streamSize() != 1 && pos + length > streamSize()) {
                      //it tries to read outside of the boundaries
                      return E_FAIL;
                  }

                  if (currentPos() - currentBufferSize() != pos) {
                      if (!streamSeekable()) {
                          return S_FALSE;
                      }
                      setCurrentPos(pos);
                  }

                  int oldSize = currentBufferSize();
                  while (currentBufferSize() < int(length)) {
                      needData();
                      if (m_mediaGraph->isStopping()) {
                          return VFW_E_WRONG_STATE;
                      }

                      if (oldSize == currentBufferSize()) {
                          break; //we didn't get any data
                      }
                      oldSize = currentBufferSize();
                  }

                  DWORD bytesRead = qMin(currentBufferSize(), int(length));
                  {
                      QWriteLocker locker(&m_lock);
                      qMemCopy(buffer, m_buffer.data(), bytesRead);
                      //truncate the buffer
                      m_buffer = m_buffer.mid(bytesRead);
                  }

                  if (actual) {
                      *actual = bytesRead; //initialization
                  }

                  return bytesRead == length ? S_OK : S_FALSE;
              }
コード例 #7
0
ファイル: tokenizer.cpp プロジェクト: 03050903/Torque3D
bool Tokenizer::findToken(U32 start, const char* pCmp)
{
   // Move to the start
   setCurrentPos(start);

   // In case the first token is what we are looking for
   if (tokenICmp(pCmp))
      return true;

   // Loop through the file and see if the token exists
   while (advanceToken(true))
   {
      if (tokenICmp(pCmp))
         return true;
   }

   return false;
}
コード例 #8
0
bool Scrollbar::scroll(ScrollDirection direction, ScrollGranularity granularity, float multiplier)
{
    float step = 0;
    if ((direction == ScrollUp && m_orientation == VerticalScrollbar) || (direction == ScrollLeft && m_orientation == HorizontalScrollbar))
        step = -1;
    else if ((direction == ScrollDown && m_orientation == VerticalScrollbar) || (direction == ScrollRight && m_orientation == HorizontalScrollbar)) 
        step = 1;
    
    if (granularity == ScrollByLine)
        step *= m_lineStep;
    else if (granularity == ScrollByPage)
        step *= m_pageStep;
    else if (granularity == ScrollByDocument)
        step *= m_totalSize;
    else if (granularity == ScrollByPixel)
        step *= m_pixelStep;
        
    float newPos = m_currentPos + step * multiplier;
    float maxPos = m_totalSize - m_visibleSize;
    return setCurrentPos(max(min(newPos, maxPos), 0.0f));
}
コード例 #9
0
ファイル: Scrollbar.cpp プロジェクト: achellies/WinCEWebKit
bool Scrollbar::mouseMoved(const PlatformMouseEvent& evt)
{
    if (m_pressedPart == ThumbPart) {
        if (theme()->shouldSnapBackToDragOrigin(this, evt))
            setCurrentPos(m_dragOrigin, NotFromScrollAnimator);
        else {
            moveThumb(m_orientation == HorizontalScrollbar ? 
                      convertFromContainingWindow(evt.pos()).x() :
                      convertFromContainingWindow(evt.pos()).y());
        }
        return true;
    }

    if (m_pressedPart != NoPart)
        m_pressedPos = (orientation() == HorizontalScrollbar ? convertFromContainingWindow(evt.pos()).x() : convertFromContainingWindow(evt.pos()).y());

    ScrollbarPart part = theme()->hitTest(this, evt);    
    if (part != m_hoveredPart) {
        if (m_pressedPart != NoPart) {
            if (part == m_pressedPart) {
                // The mouse is moving back over the pressed part.  We
                // need to start up the timer action again.
                startTimerIfNeeded(theme()->autoscrollTimerDelay());
                theme()->invalidatePart(this, m_pressedPart);
            } else if (m_hoveredPart == m_pressedPart) {
                // The mouse is leaving the pressed part.  Kill our timer
                // if needed.
                stopTimerIfNeeded();
                theme()->invalidatePart(this, m_pressedPart);
            }
        } 
        
        setHoveredPart(part);
    } 

    return true;
}