Ejemplo n.º 1
0
bool
BasicTerminalBuffer::Find(const char* _pattern, const TermPos& start,
	bool forward, bool caseSensitive, bool matchWord, TermPos& _matchStart,
	TermPos& _matchEnd) const
{
//debug_printf("BasicTerminalBuffer::Find(\"%s\", (%ld, %ld), forward: %d, case: %d, "
//"word: %d)\n", _pattern, start.x, start.y, forward, caseSensitive, matchWord);
	// normalize pos, so that _NextChar() and _PreviousChar() are happy
	TermPos pos(start);
	TerminalLine* lineBuffer = ALLOC_LINE_ON_STACK(fWidth);
	TerminalLine* line = _HistoryLineAt(pos.y, lineBuffer);
	if (line != NULL) {
		if (forward) {
			while (line != NULL && pos.x >= line->length && line->softBreak) {
				pos.x = 0;
				pos.y++;
				line = _HistoryLineAt(pos.y, lineBuffer);
			}
		} else {
			if (pos.x > line->length)
				pos.x = line->length;
		}
	}

	int32 patternByteLen = strlen(_pattern);

	// convert pattern to UTF8Char array
	BStackOrHeapArray<UTF8Char, 64> pattern(patternByteLen);
	int32 patternLen = 0;
	while (*_pattern != '\0') {
		int32 charLen = UTF8Char::ByteCount(*_pattern);
		if (charLen > 0) {
			pattern[patternLen].SetTo(_pattern, charLen);

			// if not case sensitive, convert to lower case
			if (!caseSensitive && charLen == 1)
				pattern[patternLen] = pattern[patternLen].ToLower();

			patternLen++;
			_pattern += charLen;
		} else
			_pattern++;
	}
//debug_printf("  pattern byte len: %ld, pattern len: %ld\n", patternByteLen, patternLen);

	if (patternLen == 0)
		return false;

	// reverse pattern, if searching backward
	if (!forward) {
		for (int32 i = 0; i < patternLen / 2; i++)
			std::swap(pattern[i], pattern[patternLen - i - 1]);
	}

	// search loop
	int32 matchIndex = 0;
	TermPos matchStart;
	while (true) {
//debug_printf("    (%ld, %ld): matchIndex: %ld\n", pos.x, pos.y, matchIndex);
		TermPos previousPos(pos);
		UTF8Char c;
		if (!(forward ? _NextChar(pos, c) : _PreviousChar(pos, c)))
			return false;

		if (caseSensitive ? (c == pattern[matchIndex])
				: (c.ToLower() == pattern[matchIndex])) {
			if (matchIndex == 0)
				matchStart = previousPos;

			matchIndex++;

			if (matchIndex == patternLen) {
//debug_printf("      match!\n");
				// compute the match range
				TermPos matchEnd(pos);
				if (!forward)
					std::swap(matchStart, matchEnd);

				// check word match
				if (matchWord) {
					TermPos tempPos(matchStart);
					if ((_PreviousChar(tempPos, c) && !c.IsSpace())
						|| (_NextChar(tempPos = matchEnd, c) && !c.IsSpace())) {
//debug_printf("      but no word match!\n");
						continue;
					}
				}

				_matchStart = matchStart;
				_matchEnd = matchEnd;
//debug_printf("  -> (%ld, %ld) - (%ld, %ld)\n", matchStart.x, matchStart.y,
//matchEnd.x, matchEnd.y);
				return true;
			}
		} else if (matchIndex > 0) {
			// continue after the position where we started matching
			pos = matchStart;
			if (forward)
				_NextChar(pos, c);
			else
				_PreviousChar(pos, c);
			matchIndex = 0;
		}
	}
}
Ejemplo n.º 2
0
void PanGestureProcessor::EmitPanSignal( Actor* actor,
        const GestureDetectorContainer& gestureDetectors,
        const Integration::PanGestureEvent& panEvent,
        Vector2 localCurrent,
        Gesture::State state,
        Dali::RenderTask renderTask )
{
    if ( actor && !gestureDetectors.empty() )
    {
        PanGesture pan(state);
        pan.time = panEvent.time;

        pan.numberOfTouches = panEvent.numberOfTouches;
        pan.screenPosition = panEvent.currentPosition;
        pan.position = localCurrent;

        RenderTask& renderTaskImpl( GetImplementation( renderTask ) );

        Vector2 localPrevious;
        actor->ScreenToLocal( renderTaskImpl, localPrevious.x, localPrevious.y, panEvent.previousPosition.x, panEvent.previousPosition.y );

        pan.displacement = localCurrent - localPrevious;
        Vector2 previousPos( panEvent.previousPosition );
        if ( state == Gesture::Started )
        {
            previousPos = mPossiblePanPosition;
        }

        pan.screenDisplacement = panEvent.currentPosition - previousPos;

        // Avoid dividing by 0
        if ( panEvent.timeDelta > 0 )
        {
            pan.velocity.x = pan.displacement.x / panEvent.timeDelta;
            pan.velocity.y = pan.displacement.y / panEvent.timeDelta;

            pan.screenVelocity.x = pan.screenDisplacement.x / panEvent.timeDelta;
            pan.screenVelocity.y = pan.screenDisplacement.y / panEvent.timeDelta;
        }

        // When the gesture ends, we may incorrectly get a ZERO velocity (as we have lifted our finger without any movement)
        // so we should use the last recorded velocity instead in this scenario.
        if ( ( state == Gesture::Finished ) && ( pan.screenVelocity == Vector2::ZERO ) &&
                ( panEvent.timeDelta < MAXIMUM_TIME_WITH_VALID_LAST_VELOCITY ) )
        {
            pan.velocity = mLastVelocity;
            pan.screenVelocity = mLastScreenVelocity;
        }
        else
        {
            // Store the current velocity for future iterations.
            mLastVelocity = pan.velocity;
            mLastScreenVelocity = pan.screenVelocity;
        }

        if ( mSceneObject )
        {
            // We update the scene object directly rather than sending a message.
            // Sending a message could cause unnecessary delays, the scene object ensure thread safe behaviour.
            mSceneObject->AddGesture( pan );
        }

        Dali::Actor actorHandle( actor );
        const GestureDetectorContainer::const_iterator endIter = gestureDetectors.end();
        for ( GestureDetectorContainer::const_iterator iter = gestureDetectors.begin(); iter != endIter; ++iter )
        {
            static_cast< PanGestureDetector* >( *iter )->EmitPanGestureSignal( actorHandle, pan );
        }
    }
}