示例#1
0
int checkColPlayerDown(int x, int y, int level, int offset) {
	int i;
	int count = 0;
	// First, we check the pixels directly below the player...
	for (i = 1; i < 8; i++) { // I don't know why, but if you start at 0, you can jump 1px into the wall.
								// Because Bob is only 7px wide...

								// And it has to be "< 8", we don't want to forget the pixel at the very right of Bob...
		if (getPixel((x + i), (y + 8)) != 0) {
			count++;
		}
	}
	if (count == 0) {
		return 0; // All pixels below the player are white. There is nothing!
	}

	if (count > 0) {
		y = translatepixelval(y, &count) + 1; // Remember: Below!
		x = translatepixelval((x + offset), &count);
		colY = y;
		colX = x;
		if (isBlock(level, x, y) != 0) {
			return 1;
		}
		if (count > 1) { // Player is 7px wide...
			// We are off...
			if (isBlock(level, (x + 1), y) != 0) {
				colX++;
				return 4;
			}
		}
		if (isBox(level, x, y) != 0) {
			return 2;
		}
		if (count > 1) {
			if (isBox(level, (x + 1), y) != 0) {
				colX++;
				return 5;
			}
		}
		if (isCoin(level, x, y) != 0) {
			return 3;
		}
		if (count > 1) {
			if (isCoin(level, (x + 1), y) != 0) {
				colX++;
				return 6;
			}
		}
		for (i = 0; i < HOWMANYENEMYS; i++) {
			if (isEnemy(level, x, y, i) != 0) {
				return 7;
			}
			if (isEnemy(level, (x + 1), y, i) != 0) {
				colX++;
				return 8;
			}
		}
	}
}
示例#2
0
int checkColPlayerUp(int x, int y, int level, int offset) {
	int i;
	int count = 0;
	// First, we check the pixels directly above the player...
	for (i = 1; i < 7; i++) {
		if (getPixel((x + i), (y - 1))) {
			count++;
		}
	}
	if (count == 0) {
		return 0; // All pixels above the player are white. There is nothing!
	}

	if (count > 0) {
		y = translatepixelval(y, &count);
		x = translatepixelval((x + offset), &count);
		colY = y;
		colX = x;
		if (isBlock(level, x, y) != 0) {
			return 1;
		}
		if (count > 1) { // Player is 7px wide...
			// We are off...
			if (isBlock(level, (x + 1), y) != 0) {
				colX++;
				return 4;
			}
		}
		if (isBox(level, x, y) != 0) {
			return 2;
		}
		if (count > 1) {
			if (isBox(level, (x + 1), y) != 0) {
				colX++;
				return 5;
			}
		}
		if (isCoin(level, x, y) != 0) {
			return 3;
		}
		if (count > 1) {
			if (isCoin(level, (x + 1), y) != 0) {
				colX++;
				return 6;
			}
		}
		for (i = 0; i < HOWMANYENEMYS; i++) {
			if (isEnemy(level, x, y, i) != 0) {
				return 7;
			}
			if (isEnemy(level, (x + 1), y, i) != 0) {
				colX++;
				return 8;
			}
		}
	}
}
示例#3
0
int checkColPlayerLeft(int x, int y, int level, int offset) {
	int i;
	int count = 0;
	for (i = 0; i < 8; i++) {
		if (getPixel((x - 1), (y + i)) != 0) {
			count++;
		}
	}
	if (count == 0) {
		return 0;
	}
	if (count > 0) {
		x = translatepixelval((x + offset), &count);
		y = translatepixelval(y, &count);
		colY = y;
		colX = x;
		if (isBlock(level, x, y) != 0) {
			return 1;
		}
		if (count > 0) {
			if (isBlock(level, x, (y + 1)) != 0) {
				colY++;
				return 4;
			}
		}
		if (isBox(level, x, y) != 0) {
			return 2;
		}
		if (count > 0) {
			if (isBox(level, x, (y + 1)) != 0) {
				colY++;
				return 5;
			}
		}
		if (isCoin(level, x, y) != 0) {
			return 3;
		}
		if (count > 0) {
			if (isBox(level, x, (y + 1)) != 0) {
				colY++;
				return 6;
			}
		}
		for (i = 0; i < HOWMANYENEMYS; i++) {
			if (isEnemy(level, x, y, i) != 0) {
				return 7;
			}
			if (isEnemy(level, x, (y + 1), i) != 0) {
				colY++;
				return 8;
			}
		}
	}
}
示例#4
0
void Tile::updateCurrent(sf::Time dt, CommandQueue& commands)
{
	// Entity has been destroyed: Possibly drop pickup, mark for removal
	if (isDestroyed())
	{
		checkPickupDrop(commands);
		mExplosion.update(dt);
		// Play explosion sound only once
		if (!mExplosionBegan)
		{
			// Play sound effect
			SoundEffect::ID soundEffect = (randomInt(2) == 0) ? SoundEffect::Explosion1 : SoundEffect::Explosion2;
			playLocalSound(commands, soundEffect);

			// Emit network game action for explosions
			if (isBlock())
			{
				sf::Vector2f position = getWorldPosition();

				Command command;
				command.category = Category::Network;
				command.action = derivedAction<NetworkNode>([position] (NetworkNode& node, sf::Time)
															{
																node.notifyGameAction(GameActions::EnemyExplode, position);
															});

				commands.push(command);
				mExplosionBegan = true;
			}
		}
		return;
	}

	Entity::updateCurrent(dt, commands);
}
示例#5
0
void Ground::calc(float cx, float cy) {
    b2Filter collisionDisabled;
    b2Filter collisionEnabled;
    collisionDisabled.maskBits =  0;
    collisionEnabled.maskBits  = ~0;

    count = 0;
    int e = 1;
    for(int y=-sy/2; y<=sy/2+1*e; y+=e) {
        for(int x=-sx/2; x<=sx/2+1*e; x+=e) {
            float bx = cx + x;
            float by = cy + y;
            int bxi = e*floor(bx/e);
            int byi = e*floor(by/e);


            if( isBlock(bxi,byi) ) {
                //bodies[bxi+byi*sy].body->GetFixtureList()[0].SetFilterData(collisionEnabled);
                //drawCube(bxi,byi);
                bodies[count].body->SetTransform(b2Vec2(bxi,byi),0.0f);
                ++count;
            }
            //else
            //	bodies[bxi+byi*sy].body->GetFixtureList()[0].SetFilterData(collisionDisabled);
        }
    }
    for(int i=0; i<count; ++i)
        bodies[i].body->GetFixtureList()[0].SetFilterData(collisionEnabled);
    for(int i=count; i<sx*sy; ++i)
        bodies[i].body->GetFixtureList()[0].SetFilterData(collisionDisabled);
}
示例#6
0
int Map::getNFree(){
	int count = 0;
	for (int i = 0; i < _mapWidth; i++)
		for (int j = 0; j < _mapHeight; j++)
			if (isBlock(pair<int, int>(i, j)) == false)
				count++;
	return count;
}
示例#7
0
void Tile::checkPickupDrop(CommandQueue& commands)
{
	// Drop pickup, if enemy airplane, with probability 1/4, if pickup not yet dropped
	// and if not in network mode (where pickups are dropped via packets)
	if (isBlock() && randomInt(5) == 0 && !mSpawnedPickup && mPickupsEnabled){
		commands.push(mDropPickupCommand);
	}
	mSpawnedPickup = true;
}
示例#8
0
文件: game.cpp 项目: elemel/crust
 void Game::removeBlocks(Box2 const &box)
 {
     for (ActorIterator i = actors_.begin(); i != actors_.end(); ++i) {
         Actor *actor = &*i;
         if (isBlock(actor)) {
             BlockPhysicsComponent *physicsComponent = convert(actor->getPhysicsComponent());
             b2Vec2 position = physicsComponent->getBody()->GetPosition();
             if (box.containsPoint(Vector2(position.x, position.y))) {
                 int j = i - actors_.begin();
                 removeActor(actor);
                 i = actors_.begin() + j - 1;
             }
         }
     }
 }
示例#9
0
文件: game.cpp 项目: elemel/crust
 void Game::step(float dt)
 {
     inputManager_->step(dt);
     controlService_->step(dt);
     physicsManager_->step(dt);
     handleCollisions();
     for (ActorIterator i = actors_.begin(); i != actors_.end(); ++i) {
         Actor *actor = &*i;
         if (isBlock(actor)) {
             b2Body *body = static_cast<BlockPhysicsComponent *>(actor->getPhysicsComponent())->getBody();
             if (body->GetType() != b2_staticBody && !body->IsAwake()) {
                 body->SetType(b2_staticBody);
             }
         }
     }
     graphicsManager_->step(dt);
 }
示例#10
0
// *****************************************************************************
void PodNode::syncBlock()
{
    if (!isBlock()) return;

    //
    // We need to remove any PodNode*s from this block if they are
    // already parented to some other node.  If we don't they can 
    // get double-deleted if this node is deleted during the thrown
    // exeception, which will cause a segfault.
    //
    // Because of this, we collect all the errors found and throw
    // them at once after cleaning things up.
    //
    std::ostringstream err;
    PodNodeDeque& block = asBlock();
    PodNodeDeque::iterator iter = block.begin();
    while (iter != block.end())
    {
        PodNode* child = (*iter);
        if (!child)
        {
            err << "Invalid NULL pointer in block." << std::endl;
            block.erase(iter);
            iter = block.begin();  // erase() invalidates iter, so start over
        }
        else if (child->m_parent && child->m_parent != this)
        {
            err << child->repr() << " is already a child of " 
                << child->m_parent->repr() << std::endl;
            block.erase(iter);
            iter = block.begin();  // erase() invalidates iter, so start over
        }
        else
        {
            child->m_parent = this;
            child->syncBlock();
            ++iter;
        }
    }
    if (!err.str().empty())
    {
        throw PodIntegrityError(this, err.str());
    }
}
示例#11
0
// *****************************************************************************
void PodNode::dump(std::ostream& output, int indent)
{
    for (int i = 0; i < indent; ++i) output << "\t";

    output << "PodNode('" << m_podName << "'";
    if (!m_podType.empty())
    {
        output << ", type='" << m_podType << "'";
    }

    if (m_value)
    {
        output << ", value=" << *m_value;
    }
    else
    {
        output << ", value=NULL";
    }

    output << ", parent='" << (m_parent ? m_parent->podName() : "NULL") << "'";


    if (const EmbedPodValue* embed = dynamic_cast<const EmbedPodValue*>(m_value))
    {
        output << ", lang='" << embed->language() << "'";
    }
    else if (isBlock())
    {
        const PodNodeDeque& children = asBlock();

        output << std::endl;
        for (PodNodeDeque::const_iterator iter = asBlock().begin();
                iter != asBlock().end(); ++iter)
        {
            assert(*iter);
            (*iter)->dump(output, indent+1);
        }
        for (int i = 0; i < indent; ++i) output << "\t";
    }
    output << " [defined in '" << m_sourcefile << "', line " << m_sourceline << "]";
    output << ")" << std::endl;
}
示例#12
0
vector<Text_token> Tokenizer::scan() {
	FILE *file = fopen(path.c_str(), "r");
    if (file == NULL) {
        cout << "error, wrong path" << endl;
        exit(1);
    }
    char tmp;
    string str;
    int pos = 0;
    while ((tmp = fgetc(file)) != EOF) {
        if (isAQL && tmp == '/') {
            str = "";
            tokens.push_back(Text_token("/", pos-1, pos));
            pos++;
            while ((tmp = fgetc(file)) != '/') {
                str += tmp;
                pos++;
            }
        }
        text += tmp;
        if (isBlock(tmp)) {
            if (str.length() != 0) {
                tokens.push_back(Text_token(str, pos-(int)str.length(), pos));
                str = "";
            }
            if (!(tmp == ' ' || tmp == '\n'
                || tmp == '\t' || tmp == '\r')) {
                str += tmp;
                tokens.push_back(Text_token(str, pos, pos+1));
                str = "";
            }
        } else {
            str += tmp;
        }
        
        pos++;
    }
    return tokens;
}
示例#13
0
void VisibleSelection::setStartAndEndFromBaseAndExtentRespectingGranularity(TextGranularity granularity)
{
    if (m_baseIsFirst) {
        m_start = m_base;
        m_end = m_extent;
    } else {
        m_start = m_extent;
        m_end = m_base;
    }

    switch (granularity) {
        case CharacterGranularity:
            // Don't do any expansion.
            break;
        case WordGranularity: {
            // General case: Select the word the caret is positioned inside of, or at the start of (RightWordIfOnBoundary).
            // Edge case: If the caret is after the last word in a soft-wrapped line or the last word in
            // the document, select that last word (LeftWordIfOnBoundary).
            // Edge case: If the caret is after the last word in a paragraph, select from the the end of the
            // last word to the line break (also RightWordIfOnBoundary);
            VisiblePosition start = VisiblePosition(m_start, m_affinity);
            VisiblePosition originalEnd(m_end, m_affinity);
            EWordSide side = RightWordIfOnBoundary;
            if (isEndOfEditableOrNonEditableContent(start) || (isEndOfLine(start) && !isStartOfLine(start) && !isEndOfParagraph(start)))
                side = LeftWordIfOnBoundary;
            m_start = startOfWord(start, side).deepEquivalent();
            side = RightWordIfOnBoundary;
            if (isEndOfEditableOrNonEditableContent(originalEnd) || (isEndOfLine(originalEnd) && !isStartOfLine(originalEnd) && !isEndOfParagraph(originalEnd)))
                side = LeftWordIfOnBoundary;
                
            VisiblePosition wordEnd(endOfWord(originalEnd, side));
            VisiblePosition end(wordEnd);
            
            if (isEndOfParagraph(originalEnd) && !isEmptyTableCell(m_start.deprecatedNode())) {
                // Select the paragraph break (the space from the end of a paragraph to the start of 
                // the next one) to match TextEdit.
                end = wordEnd.next();
                
                if (Node* table = isFirstPositionAfterTable(end)) {
                    // The paragraph break after the last paragraph in the last cell of a block table ends
                    // at the start of the paragraph after the table.
                    if (isBlock(table))
                        end = end.next(CannotCrossEditingBoundary);
                    else
                        end = wordEnd;
                }
                
                if (end.isNull())
                    end = wordEnd;
                    
            }
                
            m_end = end.deepEquivalent();
            // End must not be before start.
            if (m_start.deprecatedNode() == m_end.deprecatedNode() && m_start.deprecatedEditingOffset() > m_end.deprecatedEditingOffset()) {
                Position swap(m_start);
                m_start = m_end;    
                m_end = swap;    
            }
            break;
        }
        case SentenceGranularity: {
            m_start = startOfSentence(VisiblePosition(m_start, m_affinity)).deepEquivalent();
            m_end = endOfSentence(VisiblePosition(m_end, m_affinity)).deepEquivalent();
            break;
        }
        case LineGranularity: {
            m_start = startOfLine(VisiblePosition(m_start, m_affinity)).deepEquivalent();
            VisiblePosition end = endOfLine(VisiblePosition(m_end, m_affinity));
            // If the end of this line is at the end of a paragraph, include the space 
            // after the end of the line in the selection.
            if (isEndOfParagraph(end)) {
                VisiblePosition next = end.next();
                if (next.isNotNull())
                    end = next;
            }
            m_end = end.deepEquivalent();
            break;
        }
        case LineBoundary:
            m_start = startOfLine(VisiblePosition(m_start, m_affinity)).deepEquivalent();
            m_end = endOfLine(VisiblePosition(m_end, m_affinity)).deepEquivalent();
            break;
        case ParagraphGranularity: {
            VisiblePosition pos(m_start, m_affinity);
            if (isStartOfLine(pos) && isEndOfEditableOrNonEditableContent(pos))
                pos = pos.previous();
            m_start = startOfParagraph(pos).deepEquivalent();
            VisiblePosition visibleParagraphEnd = endOfParagraph(VisiblePosition(m_end, m_affinity));
            
            // Include the "paragraph break" (the space from the end of this paragraph to the start
            // of the next one) in the selection.
            VisiblePosition end(visibleParagraphEnd.next());
             
            if (Node* table = isFirstPositionAfterTable(end)) {
                // The paragraph break after the last paragraph in the last cell of a block table ends
                // at the start of the paragraph after the table, not at the position just after the table.
                if (isBlock(table))
                    end = end.next(CannotCrossEditingBoundary);
                // There is no parargraph break after the last paragraph in the last cell of an inline table.
                else
                    end = visibleParagraphEnd;
            }
             
            if (end.isNull())
                end = visibleParagraphEnd;
                
            m_end = end.deepEquivalent();
            break;
        }
        case DocumentBoundary:
            m_start = startOfDocument(VisiblePosition(m_start, m_affinity)).deepEquivalent();
            m_end = endOfDocument(VisiblePosition(m_end, m_affinity)).deepEquivalent();
            break;
        case ParagraphBoundary:
            m_start = startOfParagraph(VisiblePosition(m_start, m_affinity)).deepEquivalent();
            m_end = endOfParagraph(VisiblePosition(m_end, m_affinity)).deepEquivalent();
            break;
        case SentenceBoundary:
            m_start = startOfSentence(VisiblePosition(m_start, m_affinity)).deepEquivalent();
            m_end = endOfSentence(VisiblePosition(m_end, m_affinity)).deepEquivalent();
            break;
        case DocumentGranularity:
            ASSERT_NOT_REACHED();
            break;
    }
    
    // Make sure we do not have a dangling start or end.
    if (m_start.isNull())
        m_start = m_end;
    if (m_end.isNull())
        m_end = m_start;
}
void VisibleSelection::setStartAndEndFromBaseAndExtentRespectingGranularity(TextGranularity granularity)
{
    if (m_baseIsFirst) {
        m_start = m_base;
        m_end = m_extent;
    } else {
        m_start = m_extent;
        m_end = m_base;
    }

    switch (granularity) {
        case CharacterGranularity:
            // Don't do any expansion.
            break;
        case WordGranularity: {
            // General case: Select the word the caret is positioned inside of, or at the start of (RightWordIfOnBoundary).
            // Edge case: If the caret is after the last word in a soft-wrapped line or the last word in
            // the document, select that last word (LeftWordIfOnBoundary).
            // Edge case: If the caret is after the last word in a paragraph, select from the the end of the
            // last word to the line break (also RightWordIfOnBoundary);
            VisiblePosition start = VisiblePosition(m_start, m_affinity);
            VisiblePosition originalEnd(m_end, m_affinity);
            EWordSide side = RightWordIfOnBoundary;

			//SAMSUNG - Text Selection >>
			Document *doc = NULL;
			if (m_start.anchorNode())
				doc = m_start.anchorNode()->document();
			if (doc && doc->settings() && doc->settings()->advancedSelectionEnabled()) 
			{
				bool endOfDocument;
				if ( (endOfDocument = isEndOfDocument(start)) || ( (isEndOfLine(start) || isStartOfSpace(start)) && !isStartOfLine(start))) 
				{
					side = LeftWordIfOnBoundary;
					if (!endOfDocument && isEndOfParagraph(start)) 
					{
						originalEnd = start;
					}
				}
				m_start = startOfWord(start, side).deepEquivalent();
				side = RightWordIfOnBoundary;

				if (isStartOfSpace(start)) 
				{
					side = LeftWordIfOnBoundary;
				}

				if (isEndOfDocument(originalEnd) || (isEndOfLine(originalEnd) && !isStartOfLine(originalEnd)))
				side = LeftWordIfOnBoundary;

				VisiblePosition wordEnd(endOfWord(originalEnd, side));
				VisiblePosition end(wordEnd);
				m_end = end.deepEquivalent();
			} 
			else 
			{			
				//SAMSUNG - Text Selection <<

            if (isEndOfDocument(start) || (isEndOfLine(start) && !isStartOfLine(start) && !isEndOfParagraph(start)))
                side = LeftWordIfOnBoundary;
            m_start = startOfWord(start, side).deepEquivalent();
            side = RightWordIfOnBoundary;
            if (isEndOfDocument(originalEnd) || (isEndOfLine(originalEnd) && !isStartOfLine(originalEnd) && !isEndOfParagraph(originalEnd)))
                side = LeftWordIfOnBoundary;
                
            VisiblePosition wordEnd(endOfWord(originalEnd, side));
            VisiblePosition end(wordEnd);
            
            if (isEndOfParagraph(originalEnd) && !isEmptyTableCell(m_start.deprecatedNode())) {
                // Select the paragraph break (the space from the end of a paragraph to the start of 
                // the next one) to match TextEdit.
                end = wordEnd.next();
                
                if (Node* table = isFirstPositionAfterTable(end)) {
                    // The paragraph break after the last paragraph in the last cell of a block table ends
                    // at the start of the paragraph after the table.
                    if (isBlock(table))
                        end = end.next(CannotCrossEditingBoundary);
                    else
                        end = wordEnd;
                }
                
                if (end.isNull())
                    end = wordEnd;
                    
            }
                
            m_end = end.deepEquivalent();
//SAMSUNG - Text Selection >>		
			}
//SAMSUNG - Text Selection <<			
            break;
        }
        case SentenceGranularity: {
            m_start = startOfSentence(VisiblePosition(m_start, m_affinity)).deepEquivalent();
            m_end = endOfSentence(VisiblePosition(m_end, m_affinity)).deepEquivalent();
            break;
        }
        case LineGranularity: {
            m_start = startOfLine(VisiblePosition(m_start, m_affinity)).deepEquivalent();
            VisiblePosition end = endOfLine(VisiblePosition(m_end, m_affinity));
            // If the end of this line is at the end of a paragraph, include the space 
            // after the end of the line in the selection.
            if (isEndOfParagraph(end)) {
                VisiblePosition next = end.next();
                if (next.isNotNull())
                    end = next;
            }
            m_end = end.deepEquivalent();
            break;
        }
        case LineBoundary:
            m_start = startOfLine(VisiblePosition(m_start, m_affinity)).deepEquivalent();
            m_end = endOfLine(VisiblePosition(m_end, m_affinity)).deepEquivalent();
            break;
        case ParagraphGranularity: {
            VisiblePosition pos(m_start, m_affinity);
            if (isStartOfLine(pos) && isEndOfDocument(pos))
                pos = pos.previous();
            m_start = startOfParagraph(pos).deepEquivalent();
            VisiblePosition visibleParagraphEnd = endOfParagraph(VisiblePosition(m_end, m_affinity));
            
            // Include the "paragraph break" (the space from the end of this paragraph to the start
            // of the next one) in the selection.
	//SAMSUNG - Text Selection >>
            // Here it tries to extend the end point from current paragraph to beginning of next paragraph. So somehow it is 
            // selecting the next paragraph also and it looks wrong when we do backward paragraph selection.
            // Even though user is trying to extend selection in backward direction, because of this condition it extends selection
            // in both directions. So commented the below code to avoid wrong backward text selection
            // WAS: VisiblePosition end(visibleParagraphEnd.next());
            VisiblePosition end(visibleParagraphEnd);
	//SAMSUNG - Text Selection <<

             
            if (Node* table = isFirstPositionAfterTable(end)) {
                // The paragraph break after the last paragraph in the last cell of a block table ends
                // at the start of the paragraph after the table, not at the position just after the table.
                if (isBlock(table))
                    end = end.next(CannotCrossEditingBoundary);
                // There is no parargraph break after the last paragraph in the last cell of an inline table.
                else
                    end = visibleParagraphEnd;
            }
             
            if (end.isNull())
                end = visibleParagraphEnd;
                
            m_end = end.deepEquivalent();
            break;
        }
        case DocumentBoundary:
            m_start = startOfDocument(VisiblePosition(m_start, m_affinity)).deepEquivalent();
            m_end = endOfDocument(VisiblePosition(m_end, m_affinity)).deepEquivalent();
            break;
        case ParagraphBoundary:
            m_start = startOfParagraph(VisiblePosition(m_start, m_affinity)).deepEquivalent();
            m_end = endOfParagraph(VisiblePosition(m_end, m_affinity)).deepEquivalent();
            break;
        case SentenceBoundary:
            m_start = startOfSentence(VisiblePosition(m_start, m_affinity)).deepEquivalent();
            m_end = endOfSentence(VisiblePosition(m_end, m_affinity)).deepEquivalent();
            break;
        case WebKitVisualWordGranularity:
            break;
    }
    
    // Make sure we do not have a dangling start or end.
    if (m_start.isNull())
        m_start = m_end;
    if (m_end.isNull())
        m_end = m_start;
}
示例#15
0
void Selection::validate()
{
    // Move the selection to rendered positions, if possible.
    bool baseAndExtentEqual = m_base == m_extent;
    if (m_base.isNotNull()) {
        m_base = VisiblePosition(m_base, m_affinity).deepEquivalent();
        if (baseAndExtentEqual)
            m_extent = m_base;
    }
    if (m_extent.isNotNull() && !baseAndExtentEqual)
        m_extent = VisiblePosition(m_extent, m_affinity).deepEquivalent();

    // Make sure we do not have a dangling base or extent.
    if (m_base.isNull() && m_extent.isNull())
        m_baseIsFirst = true;
    else if (m_base.isNull()) {
        m_base = m_extent;
        m_baseIsFirst = true;
    } else if (m_extent.isNull()) {
        m_extent = m_base;
        m_baseIsFirst = true;
    } else {
        m_baseIsFirst = comparePositions(m_base, m_extent) <= 0;
    }

    if (m_baseIsFirst) {
        m_start = m_base;
        m_end = m_extent;
    } else {
        m_start = m_extent;
        m_end = m_base;
    }

    // Expand the selection if requested.
    switch (m_granularity) {
        case CharacterGranularity:
            // Don't do any expansion.
            break;
        case WordGranularity: {
            // General case: Select the word the caret is positioned inside of, or at the start of (RightWordIfOnBoundary).
            // Edge case: If the caret is after the last word in a soft-wrapped line or the last word in
            // the document, select that last word (LeftWordIfOnBoundary).
            // Edge case: If the caret is after the last word in a paragraph, select from the the end of the
            // last word to the line break (also RightWordIfOnBoundary);
            VisiblePosition start = VisiblePosition(m_start, m_affinity);
            VisiblePosition originalEnd(m_end, m_affinity);
            EWordSide side = RightWordIfOnBoundary;
            if (isEndOfDocument(start) || (isEndOfLine(start) && !isStartOfLine(start) && !isEndOfParagraph(start)))
                side = LeftWordIfOnBoundary;
            m_start = startOfWord(start, side).deepEquivalent();
            side = RightWordIfOnBoundary;
            if (isEndOfDocument(originalEnd) || (isEndOfLine(originalEnd) && !isStartOfLine(originalEnd) && !isEndOfParagraph(originalEnd)))
                side = LeftWordIfOnBoundary;
                
            VisiblePosition wordEnd(endOfWord(originalEnd, side));
            VisiblePosition end(wordEnd);
            
            if (isEndOfParagraph(originalEnd)) {
                // Select the paragraph break (the space from the end of a paragraph to the start of 
                // the next one) to match TextEdit.
                end = wordEnd.next();
                
                if (Node* table = isFirstPositionAfterTable(end)) {
                    // The paragraph break after the last paragraph in the last cell of a block table ends
                    // at the start of the paragraph after the table.
                    if (isBlock(table))
                        end = end.next(true);
                    else
                        end = wordEnd;
                }
                
                if (end.isNull())
                    end = wordEnd;
                    
            }
                
            m_end = end.deepEquivalent();
            break;
        }
        case SentenceGranularity: {
            m_start = startOfSentence(VisiblePosition(m_start, m_affinity)).deepEquivalent();
            m_end = endOfSentence(VisiblePosition(m_end, m_affinity)).deepEquivalent();
            break;
        }
        case LineGranularity: {
            m_start = startOfLine(VisiblePosition(m_start, m_affinity)).deepEquivalent();
            VisiblePosition end = endOfLine(VisiblePosition(m_end, m_affinity));
            // If the end of this line is at the end of a paragraph, include the space 
            // after the end of the line in the selection.
            if (isEndOfParagraph(end)) {
                VisiblePosition next = end.next();
                if (next.isNotNull())
                    end = next;
            }
            m_end = end.deepEquivalent();
            break;
        }
        case LineBoundary:
            m_start = startOfLine(VisiblePosition(m_start, m_affinity)).deepEquivalent();
            m_end = endOfLine(VisiblePosition(m_end, m_affinity)).deepEquivalent();
            break;
        case ParagraphGranularity: {
            VisiblePosition pos(m_start, m_affinity);
            if (isStartOfLine(pos) && isEndOfDocument(pos))
                pos = pos.previous();
            m_start = startOfParagraph(pos).deepEquivalent();
            VisiblePosition visibleParagraphEnd = endOfParagraph(VisiblePosition(m_end, m_affinity));
            
            // Include the "paragraph break" (the space from the end of this paragraph to the start
            // of the next one) in the selection.
            VisiblePosition end(visibleParagraphEnd.next());
             
            if (Node* table = isFirstPositionAfterTable(end)) {
                // The paragraph break after the last paragraph in the last cell of a block table ends
                // at the start of the paragraph after the table, not at the position just after the table.
                if (isBlock(table))
                    end = end.next(true);
                // There is no parargraph break after the last paragraph in the last cell of an inline table.
                else
                    end = visibleParagraphEnd;
            }
             
            if (end.isNull())
                end = visibleParagraphEnd;
                
            m_end = end.deepEquivalent();
            break;
        }
        case DocumentBoundary:
            m_start = startOfDocument(VisiblePosition(m_start, m_affinity)).deepEquivalent();
            m_end = endOfDocument(VisiblePosition(m_end, m_affinity)).deepEquivalent();
            break;
        case ParagraphBoundary:
            m_start = startOfParagraph(VisiblePosition(m_start, m_affinity)).deepEquivalent();
            m_end = endOfParagraph(VisiblePosition(m_end, m_affinity)).deepEquivalent();
            break;
        case SentenceBoundary:
            m_start = startOfSentence(VisiblePosition(m_start, m_affinity)).deepEquivalent();
            m_end = endOfSentence(VisiblePosition(m_end, m_affinity)).deepEquivalent();
            break;
    }
    
    // Make sure we do not have a dangling start or end.
    if (m_start.isNull())
        m_start = m_end;
    if (m_end.isNull())
        m_end = m_start;
    
    adjustForEditableContent();

    // adjust the state
    if (m_start.isNull()) {
        ASSERT(m_end.isNull());
        m_state = NONE;

        // enforce downstream affinity if not caret, as affinity only
        // makes sense for caret
        m_affinity = DOWNSTREAM;
    } else if (m_start == m_end || m_start.upstream() == m_end.upstream()) {
        m_state = CARET;
    } else {
        m_state = RANGE;

        // enforce downstream affinity if not caret, as affinity only
        // makes sense for caret
        m_affinity = DOWNSTREAM;

        // "Constrain" the selection to be the smallest equivalent range of nodes.
        // This is a somewhat arbitrary choice, but experience shows that it is
        // useful to make to make the selection "canonical" (if only for
        // purposes of comparing selections). This is an ideal point of the code
        // to do this operation, since all selection changes that result in a RANGE 
        // come through here before anyone uses it.
        m_start = m_start.downstream();
        m_end = m_end.upstream();
    }
}
示例#16
0
文件: switch.hpp 项目: abduld/cena
 SwitchNode(const int &row, const int &col, const int &endrow,
            const int &endcol, const string &raw)
     : Node(row, col, endrow, endcol, raw) {
   isBlock(true);
 }
示例#17
0
	double getTexcoordX(item item, ubyte side) {
		if (isBlock(item)) //如果为方块
			return (getTextureIndex(item, side) & 7) / 8.0;
		else
			return NULLBLOCK;
	}
示例#18
0
文件: markup.cpp 项目: domenic/mojo
Node* StyledMarkupAccumulator::traverseNodesForSerialization(Node* startNode, Node* pastEnd, NodeTraversalMode traversalMode)
{
    const bool shouldEmit = traversalMode == EmitString;
    Vector<RawPtr<ContainerNode> > ancestorsToClose;
    Node* next;
    Node* lastClosed = 0;
    for (Node* n = startNode; n != pastEnd; n = next) {
        // According to <rdar://problem/5730668>, it is possible for n to blow
        // past pastEnd and become null here. This shouldn't be possible.
        // This null check will prevent crashes (but create too much markup)
        // and the ASSERT will hopefully lead us to understanding the problem.
        ASSERT(n);
        if (!n)
            break;

        next = NodeTraversal::next(*n);
        bool openedTag = false;

        if (isBlock(n) && canHaveChildrenForEditing(n) && next == pastEnd)
            // Don't write out empty block containers that aren't fully selected.
            continue;

        if (!n->renderer() && m_shouldAnnotate != AnnotateForNavigationTransition) {
            next = NodeTraversal::nextSkippingChildren(*n);
            // Don't skip over pastEnd.
            if (pastEnd && pastEnd->isDescendantOf(n))
                next = pastEnd;
        } else {
            // Add the node to the markup if we're not skipping the descendants
            if (shouldEmit)
                appendStartTag(*n);

            // If node has no children, close the tag now.
            if (n->isContainerNode() && toContainerNode(n)->hasChildren()) {
                openedTag = true;
                ancestorsToClose.append(toContainerNode(n));
            } else {
                if (shouldEmit && n->isElementNode())
                    appendEndTag(toElement(*n));
                lastClosed = n;
            }
        }

        // If we didn't insert open tag and there's no more siblings or we're at the end of the traversal, take care of ancestors.
        // FIXME: What happens if we just inserted open tag and reached the end?
        if (!openedTag && (!n->nextSibling() || next == pastEnd)) {
            // Close up the ancestors.
            while (!ancestorsToClose.isEmpty()) {
                ContainerNode* ancestor = ancestorsToClose.last();
                ASSERT(ancestor);
                if (next != pastEnd && next->isDescendantOf(ancestor))
                    break;
                // Not at the end of the range, close ancestors up to sibling of next node.
                if (shouldEmit && ancestor->isElementNode())
                    appendEndTag(toElement(*ancestor));
                lastClosed = ancestor;
                ancestorsToClose.removeLast();
            }

            // Surround the currently accumulated markup with markup for ancestors we never opened as we leave the subtree(s) rooted at those ancestors.
            ContainerNode* nextParent = next ? next->parentNode() : 0;
            if (next != pastEnd && n != nextParent) {
                Node* lastAncestorClosedOrSelf = n->isDescendantOf(lastClosed) ? lastClosed : n;
                for (ContainerNode* parent = lastAncestorClosedOrSelf->parentNode(); parent && parent != nextParent; parent = parent->parentNode()) {
                    // All ancestors that aren't in the ancestorsToClose list should either be a) unrendered:
                    if (!parent->renderer())
                        continue;
                    // or b) ancestors that we never encountered during a pre-order traversal starting at startNode:
                    ASSERT(startNode->isDescendantOf(parent));
                    if (shouldEmit)
                        wrapWithNode(*parent);
                    lastClosed = parent;
                }
            }
        }
    }

    return lastClosed;
}
示例#19
0
 bool MapCollideMgr::isBlock( MapElement *elem ) {
     return isBlock(elem->getBoundingBox());
 }
void VisibleSelection::setStartAndEndFromBaseAndExtentRespectingGranularity(TextGranularity granularity)
{
    if (m_baseIsFirst) {
        m_start = m_base;
        m_end = m_extent;
    } else {
        m_start = m_extent;
        m_end = m_base;
    }

    switch (granularity) {
        case CharacterGranularity:
            // Don't do any expansion.
            break;
        case WordGranularity: {
            // General case: Select the word the caret is positioned inside of, or at the start of (RightWordIfOnBoundary).
            // Edge case: If the caret is after the last word in a soft-wrapped line or the last word in
            // the document, select that last word (LeftWordIfOnBoundary).
            // Edge case: If the caret is after the last word in a paragraph, select from the the end of the
            // last word to the line break (also RightWordIfOnBoundary);
            VisiblePosition start = VisiblePosition(m_start, m_affinity);
            VisiblePosition originalEnd(m_end, m_affinity);
            EWordSide side = RightWordIfOnBoundary;
            if (isEndOfDocument(start) || (isEndOfLine(start) && !isStartOfLine(start) && !isEndOfParagraph(start)))
                side = LeftWordIfOnBoundary;
            m_start = startOfWord(start, side).deepEquivalent();
            side = RightWordIfOnBoundary;
            if (isEndOfDocument(originalEnd) || (isEndOfLine(originalEnd) && !isStartOfLine(originalEnd) && !isEndOfParagraph(originalEnd)))
                side = LeftWordIfOnBoundary;
                
            VisiblePosition wordEnd(endOfWord(originalEnd, side));
            VisiblePosition end(wordEnd);
            
            if (isEndOfParagraph(originalEnd) && !isEmptyTableCell(m_start.deprecatedNode())) {
                // Select the paragraph break (the space from the end of a paragraph to the start of 
                // the next one) to match TextEdit.
                end = wordEnd.next();
                
                if (Node* table = isFirstPositionAfterTable(end)) {
                    // The paragraph break after the last paragraph in the last cell of a block table ends
                    // at the start of the paragraph after the table.
                    if (isBlock(table))
                        end = end.next(CannotCrossEditingBoundary);
                    else
                        end = wordEnd;
                }
                
                if (end.isNull())
                    end = wordEnd;
                    
            }
                
            m_end = end.deepEquivalent();
		
            //added this to select only letters for dictionary viewing
            if( m_selectOnlyLetters && m_start.anchorNode()->isTextNode() && m_end.anchorNode()->isTextNode() ) {

                CharacterData* startText = static_cast<CharacterData*>(m_start.anchorNode());
                String startStr = startText->data();
                CharacterData* endText = static_cast<CharacterData*>(m_end.anchorNode());
                String endStr = endText->data();

                int n1 = m_start.offsetInContainerNode();
                int n2 = m_end.offsetInContainerNode() - 1;

                //unhandled corner case: at beginning of sentence, m_start may refer
                //to the Node of the last sentence, this causes the space at the beginning
                //of a sentence to be part of the selection. Assigning m_end to m_start and
                //adjusting the offset does not fix this. 		

                QChar c1 = startStr[n1];
                QChar c2 = endStr[n2];

                while(!c1.isLetter() && n1 <= n2) {
                    c1 = startStr[++n1];
                    m_start = m_start.next(Character);
                }

                while(!c2.isLetter() && n2 >= n1) {
                    c2 = endStr[--n2];
                    m_end = m_end.previous(Character);
                }
            }
            break;
        }
        case SentenceGranularity: {
            m_start = startOfSentence(VisiblePosition(m_start, m_affinity)).deepEquivalent();
            m_end = endOfSentence(VisiblePosition(m_end, m_affinity)).deepEquivalent();
            break;
        }
        case LineGranularity: {
            m_start = startOfLine(VisiblePosition(m_start, m_affinity)).deepEquivalent();
            VisiblePosition end = endOfLine(VisiblePosition(m_end, m_affinity));
            // If the end of this line is at the end of a paragraph, include the space 
            // after the end of the line in the selection.
            if (isEndOfParagraph(end)) {
                VisiblePosition next = end.next();
                if (next.isNotNull())
                    end = next;
            }
            m_end = end.deepEquivalent();
            break;
        }
        case LineBoundary:
            m_start = startOfLine(VisiblePosition(m_start, m_affinity)).deepEquivalent();
            m_end = endOfLine(VisiblePosition(m_end, m_affinity)).deepEquivalent();
            break;
        case ParagraphGranularity: {
            VisiblePosition pos(m_start, m_affinity);
            if (isStartOfLine(pos) && isEndOfDocument(pos))
                pos = pos.previous();
            m_start = startOfParagraph(pos).deepEquivalent();
            VisiblePosition visibleParagraphEnd = endOfParagraph(VisiblePosition(m_end, m_affinity));
            
            // Include the "paragraph break" (the space from the end of this paragraph to the start
            // of the next one) in the selection.
            VisiblePosition end(visibleParagraphEnd.next());
             
            if (Node* table = isFirstPositionAfterTable(end)) {
                // The paragraph break after the last paragraph in the last cell of a block table ends
                // at the start of the paragraph after the table, not at the position just after the table.
                if (isBlock(table))
                    end = end.next(CannotCrossEditingBoundary);
                // There is no parargraph break after the last paragraph in the last cell of an inline table.
                else
                    end = visibleParagraphEnd;
            }
             
            if (end.isNull())
                end = visibleParagraphEnd;
                
            m_end = end.deepEquivalent();
            break;
        }
        case DocumentBoundary:
            m_start = startOfDocument(VisiblePosition(m_start, m_affinity)).deepEquivalent();
            m_end = endOfDocument(VisiblePosition(m_end, m_affinity)).deepEquivalent();
            break;
        case ParagraphBoundary:
            m_start = startOfParagraph(VisiblePosition(m_start, m_affinity)).deepEquivalent();
            m_end = endOfParagraph(VisiblePosition(m_end, m_affinity)).deepEquivalent();
            break;
        case SentenceBoundary:
            m_start = startOfSentence(VisiblePosition(m_start, m_affinity)).deepEquivalent();
            m_end = endOfSentence(VisiblePosition(m_end, m_affinity)).deepEquivalent();
            break;
        case WebKitVisualWordGranularity:
            break;
    }
    
    // Make sure we do not have a dangling start or end.
    if (m_start.isNull())
        m_start = m_end;
    if (m_end.isNull())
        m_end = m_start;
}
示例#21
0
文件: block.hpp 项目: abduld/cena
 BlockNode(const int &row, const int &col, const int &endrow,
           const int &endcol, const string &raw, const shared_ptr<Node> &nd)
     : CompoundNode(row, col, endrow, endcol, raw) {
   isBlock(true);
   push_back(nd);
 }
示例#22
0
void FindSeeds(int targetCount, int *candidates, int candidatesNum)
{
	int i, j, top1;
	int topk = seedNumber;
	int *seedSet = malloc(seedNumber * sizeof(int));
	bool best = true;
	double diffusionTime, time_spent;
	extern clock_t begin, end;

	double **distToTargets = malloc(targetCount * sizeof(double *));	// create a 2D array distToTargets[eachTarget][totalvertices]
	double *firstRound = malloc(candidatesNum * sizeof(double));		// store max time of each candidate to targets
	double *targets = malloc(targetCount * sizeof(double));				// the minimum time to arrive each target
	double *eachReduce = malloc(candidatesNum * sizeof(double));		// store each candidate to target causes the diffusion time less

	/*	initialize targets array, distToTargets array, firstRound array, eachReduce array and seedSet */
	for(i = 0 ; i < targetCount ; i++){
		targets[i] = DBL_MAX;
		distToTargets[i] = malloc(totalvertices * sizeof(double));
		for(j = 0 ; j < totalvertices ; j++)
			distToTargets[i][j] = -1;
	}
	for(i = 0 ; i < candidatesNum ; i++){
		firstRound[i] = -1;
		eachReduce[i] = 0;
	}
	memset(seedSet, -1, seedNumber * sizeof(int));

	FILE *f = write_file("result");
	if(f == NULL) err("Couldn't open file.\n");
	fprintf(f, "number of candidates : %d\n", candidatesNum);
	fprintf(f, "number of targets : %d\n", targetCount);

	/* Get the first seed. Then get the next seed by recording the marginal gain of each candidate. */
	int count = 0;
	while(topk > 0){
		InitializeEachReduce(eachReduce, candidatesNum);
		best = true;														// check the diffusion time has improved or not

		for(i = 0 ; i < targetCount ; i++){
			distToTargets[i] = BoundDist[i];								// the time of each node to the target
			for(j = 0 ; j < candidatesNum ; j++){
				if(count == 0){
					firstRound[j] = MAX(firstRound[j], distToTargets[i][candidates[j]]);
//					printf("node %d to node %d : %f\n", candidates[j], targetUsers[i], distToTargets[i][candidates[j]]);
					best = false;
				}
				/* check the candidate is blocked by seed or not. */
				else if(isBlock(targetUsers[i], candidates[j], seedSet)){
					continue;
				}
				/* if node has contribution of diffusion time, then store it into "eachReduce" to get the most one. */
				else if(!isInclude(candidates[j], seedSet) && distToTargets[i][candidates[j]]<targets[i]){
					eachReduce[j] += targets[i]-distToTargets[i][candidates[j]];
					best = false;
//					printf("\ncandidates %d has contribution!\n\n", candidates[j]);
				}
			}
		}

		// if there is no node has contribution , then quit the algorithm.
		if(best){
			printf("No more seeds !!\nIt's the shortest diffusion time !!\n");
			break;
		}
		if(count == 0)
			top1 = BubbleSort(firstRound, false, candidatesNum);
		else
			top1 = BubbleSort(eachReduce, true, candidatesNum);

		top1 = candidates[top1];
		seedSet[count++] = top1;											// store top1 to seed set
		diffusionTime = 0.0;
//		printf("top %d is %d\n", count, top1);
		for(i = 0 ; i < targetCount ; i++){
			if(distToTargets[i][top1] < targets[i])
				targets[i] = distToTargets[i][top1];
			diffusionTime = MAX(diffusionTime, targets[i]);
//			printf("top %d to node %d is : %f\n\n", count, targetUsers[i], targets[i]);
		}

		topk--;

		fprintf(f, "top%d", count);
		fprintf(f, "\nseed set are : \n\t");
		for(i = 0 ; i < count ; i++)
			fprintf(f, "%d ", seedSet[i]);
		fprintf(f, "\nDiffusion Time is %lf\n", diffusionTime);

		end = clock();
		time_spent = (double)(end-begin) / CLOCKS_PER_SEC;
		fprintf(f, "execution time : %f\n", time_spent);
	}

	printf("targets are : \n");
	for(i = 0 ; i < targetCount ; i++)
		printf("%d ", targetUsers[i]);
	printf("number of targets : %d\n", targetCount);
	printf("\nseed set are : \n");
	for(i = 0 ; i < count ; i++)
		printf("%d ", seedSet[i]);
	printf("\nDiffusion Time is %lf\n", diffusionTime);

	fclose(f);
}
示例#23
0
文件: block.hpp 项目: abduld/cena
 BlockNode(const int &row, const int &col, const int &endrow,
           const int &endcol, const string &raw)
     : CompoundNode(row, col, endrow, endcol, raw) {
   isBlock(true);
 }