Exemplo n.º 1
0
Interruptible * ActionStack::getNext(Interruptible * previous, int type, int state, int display)
{
    int n = getNextIndex(previous, type, state, display);
    if (n == -1)
        return NULL;
    return ((Interruptible *) mObjects[n]);
}
Exemplo n.º 2
0
unsigned int
MinimumDiameter::findMaxPerpDistance(const CoordinateSequence *pts,
		LineSegment* seg, unsigned int startIndex)
{
	double maxPerpDistance=seg->distancePerpendicular(pts->getAt(startIndex));
	double nextPerpDistance = maxPerpDistance;
	unsigned int maxIndex = startIndex;
	unsigned int nextIndex = maxIndex;
	while (nextPerpDistance >= maxPerpDistance) {
		maxPerpDistance = nextPerpDistance;
		maxIndex=nextIndex;
		nextIndex=getNextIndex(pts, maxIndex);
		nextPerpDistance = seg->distancePerpendicular(pts->getAt(nextIndex));
	}

	// found maximum width for this segment - update global min dist if appropriate
	if (maxPerpDistance < minWidth) {
		minPtIndex = maxIndex;
		minWidth = maxPerpDistance;
		delete minWidthPt; 
		minWidthPt = new Coordinate(pts->getAt(minPtIndex));
		delete minBaseSeg;
		minBaseSeg = new LineSegment(*seg);
//      System.out.println(minBaseSeg);
//      System.out.println(minWidth);
	}
	return maxIndex;
}
Exemplo n.º 3
0
void GlTraceListModel::addGlTraceErrorItem(const QString & text)
{
    layoutAboutToBeChanged();
    int idx = getNextIndex();
    m_pData[idx].setIconType(GlTraceListItem::IT_ERROR);
    layoutChanged();
}
Exemplo n.º 4
0
    void Menu::selectNextItem() {
        if(getItemCount() > 1) {
            int startingPoint = getSelectedIndex();
            int nextIndex = getNextIndex(startingPoint);

            while(nextIndex != startingPoint) {
                if(items.at(nextIndex)->isEnabled()) {
                    setSelectedIndex(nextIndex);
                    break;
                }

                nextIndex = getNextIndex(nextIndex);
            }
        }

        // Don't do anything if there is only 1 or 0 items
    }
Exemplo n.º 5
0
void GlTraceListModel::addGlTraceItem(const  GlTraceListItem::IconType type, const QString & text)
{
    layoutAboutToBeChanged();
    int idx = getNextIndex();
    m_pData[idx].setIconType(type);
    m_pData[idx].setText(text);
    layoutChanged();
}
void GlTraceListModel::addGlTraceWarningItem(const QString & text)
{
    int idx = getNextIndex();

    m_pData[idx].setIconType(GlTraceListItem::IT_WARNING);

    layoutChanged();
}
Exemplo n.º 7
0
bool PicManager::nextPic()
{
    if(!hasFile() || list.size() < 1) return false; //

    currentIndex = getNextIndex(currentIndex);
    readFile(currentIndex);

    preReadingNextPic();
    return true;
}
void MaskFrame::findGhostPointIfCloseTo(int absoluteX, int absoluteY){
    int maskFrameX = absoluteX - this->getX();
    int maskFrameY = absoluteY - this->getY();
    this->hasAGhostPoint = false;
    for(int i = 0; i < maskPoints.size(); i++){
        int nextIndex = getNextIndex(i, maskPoints.size());
        this->hasAGhostPoint = getIntersection(maskFrameX, maskFrameY, maskPoints[i], maskPoints[nextIndex], &ghostPoint);
        if(this->hasAGhostPoint){
            ghostPointIndex = nextIndex;
            transposeToLiveCanvas();
            break;
        }
    }
}
static bool createElement(int counter, int myIndex, int myDirection, Element& elem, QSet<QPair<int, int> >& visitedFaces, const QVector<QVector<int> >& orientedEdgeGroups) {
    if (myIndex < 0) return false; // we have come to dead end
    if (counter == 4) return true; // we have the face

    elem.setP(myDirection, myIndex);

    int nextIndex = myIndex;
    int nextDirection = myDirection;
    getNextIndex(&nextIndex, &nextDirection, orientedEdgeGroups);

    QPair<int, int> pair = qMakePair(myIndex, nextIndex);
    if (visitedFaces.contains(pair)) return false; // we already have this element created
    visitedFaces.insert(pair);

    counter++;
    return createElement(counter, nextIndex, nextDirection, elem,  visitedFaces, orientedEdgeGroups);
}
Exemplo n.º 10
0
int ActionStack::getNextIndex(Interruptible * previous, int type, int state, int display)
{
    int found = 0;
    if (!previous)
        found = 1;
    for (size_t i = 0; i < mObjects.size(); i++)
    {
        Interruptible * current = (Interruptible *) mObjects[i];
        if (found && (type == 0 || current->type == type) && (state == 0 || current->state == state) && (display
                == -1 || current->display == display))
        {
            return i;
        }
        if (current == previous)
            found = 1;
    }
    if (!found)
        return getNextIndex(NULL, type, state, display);
    return -1;
}
void MaskFrame::drawDesign(){
    ofPushMatrix();
    ofTranslate(this->designPosition.x, this->designPosition.y);
    
    bool hasHighlightedDragHandle = this->hasHighlightedDragHandle();
    bool hasHighlightedMaskPoint = this->hasHighlightedMaskPoint();
    
    if((highlighted || hasHighlightedDragHandle || getTransformState() == Scaling) && !hasHighlightedMaskPoint){
        ofSetColor(highlightedColor);
    }else{
        ofSetColor(notHighlightedColor);   
    }
    ofRect(0, 0, this->designWidth, this->designHeight);
    
    if((highlighted || hasHighlightedDragHandle) && !hasHighlightedMaskPoint){
        for(int i = 0; i < dragHandles.size(); i++){
            dragHandles[i]->drawDesign();
        }
    }
    
    if(maskPoints.size() > 1){
        ofSetColor(maskLineColor);
        for(int i = 0; i < maskPoints.size(); i++){
            int nextIndex = getNextIndex(i, maskPoints.size());
            ofLine(maskPoints[i]->getX(), maskPoints[i]->getY(), maskPoints[nextIndex]->getX(), maskPoints[nextIndex]->getY());
        }
    }
    
    if(this->hasAGhostPoint){
        ghostPoint.drawDesign();
    }
    
    for(int i = 0; i < maskPoints.size(); i++){
        maskPoints[i]->drawDesign();
    }
    
    ofPopMatrix();
}
Exemplo n.º 12
0
void MainFrm::navigateThroughTabs(const bool bNext, const int idx)
{
    int curIdx=tabWidget->currentIndex();

    tabWidget->blockSignals(true);//lets block the signals to prevent entering the next again...

    int newIndex=-1;
/*
    bool bEnable=!vTabs.at(idx)->getSample()->bLogBook;
    for (int i=JUMP+1; i < JUMP+STEP; ++i)
        tabWidget->setTabEnabled(i,bEnable);

    if (!bEnable){
        vTabs.at(idx)->getSample()->cellId=-1;
        vTabs.at(idx)->getSample()->vesselTypeId=-1;
    }
*/
    if (bNext){
        if (!getNextIndex(idx,vTabs.at(curIdx)->getSample()->bLogBook,newIndex)){
            displayError(tr("Could not navigate to the next tab!"),false);
            return;
        }

    }else{
        if (!getPrevIndex(curIdx,vTabs.at(curIdx)->getSample()->bLogBook,newIndex)){
            displayError(tr("Could not navigate to the next tab!"),false);
            return;
        }

    }

    tabWidget->setTabEnabled(newIndex,true);
    tabWidget->setCurrentIndex(newIndex);

    tabWidget->blockSignals(false);//and unblock...
}
Exemplo n.º 13
0
bool ActionStack::CheckUserInput(JButton inputKey)
{
    JButton key = inputKey;
    JButton trigger = (options[Options::REVERSETRIGGERS].number ? JGE_BTN_NEXT : JGE_BTN_PREV);
    if (mode == ACTIONSTACK_STANDARD)
    {
        if (askIfWishesToInterrupt)
        {
            int x,y;
            if(observer->getInput()->GetLeftClickCoordinates(x, y))
            {
                key = handleInterruptRequest(inputKey, x, y);
            }

            if (JGE_BTN_SEC == key && gModRules.game.canInterrupt())
            {
                setIsInterrupting(askIfWishesToInterrupt);
                return true;
            }
            else if ((JGE_BTN_OK == key) || (trigger == key))
            {
                cancelInterruptOffer();
                return true;
            }
            else if ((JGE_BTN_PRI == key))
            {
                cancelInterruptOffer(DONT_INTERRUPT_ALL);
                return true;
            }
            return true;
        }
        else if (observer->isInterrupting)
        {
            if (JGE_BTN_SEC == key)
            {
                if(observer->mExtraPayment)
                {
                    observer->mExtraPayment->action->CheckUserInput(JGE_BTN_SEC);
                    observer->mExtraPayment = NULL;
                }
                endOfInterruption();
                return true;
            }
        }
    }
    else if (mode == ACTIONSTACK_TARGET)
    {
        if (modal)
        {
            if (JGE_BTN_UP == key)
            {
                if (mObjects[mCurr])
                {
                    int n = getPreviousIndex(((Interruptible *) mObjects[mCurr]), 0, 0, 1);
                    if (n != -1 && n != mCurr && mObjects[mCurr]->Leaving(JGE_BTN_UP))
                    {
                        mCurr = n;
                        mObjects[mCurr]->Entering();
                        DebugTrace("ACTIONSTACK UP TO mCurr = " << mCurr);
                    }
                }
                return true;
            }
            else if (JGE_BTN_DOWN == key)
            {
                if( mObjects[mCurr])
                {
                    int n = getNextIndex(((Interruptible *) mObjects[mCurr]), 0, 0, 1);
                    if (n!= -1 && n != mCurr && mObjects[mCurr]->Leaving(JGE_BTN_DOWN))
                    {
                        mCurr = n;
                        mObjects[mCurr]->Entering();
                        DebugTrace("ACTIONSTACK DOWN TO mCurr " << mCurr);
                    }
                }
                return true;
            }
            else if (JGE_BTN_OK == key)
            {
                DebugTrace("ACTIONSTACK CLICKED mCurr = " << mCurr);

                observer->stackObjectClicked(((Interruptible *) mObjects[mCurr]));
                return true;
            }
            return true; //Steal the input to other layers if we're visible
        }
        if (JGE_BTN_CANCEL == key)
        {
            if (modal) modal = 0;
            else modal = 1;
            return true;
        }
    }
    return false;
}
Exemplo n.º 14
0
Indexed::Indexed()
    : m_index(getNextIndex())
{}
Exemplo n.º 15
0
void TableViewTabKey::setNextIndex(){
    QModelIndex nextIndex = getNextIndex();
    this->setCurrentIndex(nextIndex);
    this->edit(nextIndex);
}
Exemplo n.º 16
0
ROEdge*
RODFEdgeBuilder::buildEdge(const std::string& name, RONode* from, RONode* to, const int priority) {
    return new RODFEdge(name, from, to, getNextIndex(), priority);
}
void MaskFrame::drawLive(DisplayMode mode, StretchMode stretchMode){
    ofPushMatrix();
    ofTranslate(this->livePosition.x, this->livePosition.y);
    
    if(this->canDrawLive()){
        homographyMode = stretchMode == HOMOGRAPHY && maskPoints.size() == 4;
        ofSetColor(ofColor::white);
        
        if(homographyMode) {
            prepareHomography();
            homography.begin(input, output);
            pattern->drawLayer(0, false);
            homography.end();
        } else {
            pattern->beginMask();
            ofPushStyle();
            {
                ofFill();
                ofBackground(ofColor::black);
                ofBeginShape();
                for(int i = 0; i < maskPoints.size(); i++){
                    if(stretchMode == STRETCH_TO_MASKFRAME) {
                        x = ofMap(maskPoints[i]->getLiveX(), 0, getLiveWidth(), 0, pattern->getWidth());
                        y = ofMap(maskPoints[i]->getLiveY(), 0, getLiveHeight(), 0, pattern->getHeight());
                    } else {
                        x = maskPoints[i]->getLiveX();
                        y = maskPoints[i]->getLiveY();
                    }
                    ofVertex(x, y);
                }
                ofEndShape();
            }
            ofPopStyle();
            pattern->endMask();
            
            if(stretchMode == STRETCH_TO_MASKFRAME) {
                pattern->draw(0, 0, getLiveWidth(), getLiveHeight());
            } else {
                pattern->draw();
            }
        }
    }
    
    if(mode != Live){
        
        bool hasHighlightedDragHandle = this->hasHighlightedDragHandle();
        bool hasHighlightedMaskPoint = this->hasHighlightedMaskPoint();

        ofPushStyle();
        {
            if((highlighted || hasHighlightedDragHandle || getTransformState() == Scaling) && !hasHighlightedMaskPoint){
                ofSetColor(highlightedColor);
            }else{
                ofSetColor(notHighlightedColor);
            }
            ofRect(0, 0, this->liveWidth, this->liveHeight);

            if((highlighted || hasHighlightedDragHandle) && !hasHighlightedMaskPoint){
                for(int i = 0; i < dragHandles.size(); i++){
                    dragHandles[i]->drawLive();
                }
            }
        }
        ofPopStyle();
    }
        
    if(mode == Design){
        if(maskPoints.size() > 2){
            ofSetColor(maskLineColor);
            for(int i = 0; i < maskPoints.size(); i++){
                int nextIndex = getNextIndex(i, maskPoints.size());
                ofLine(maskPoints[i]->getLiveX(), maskPoints[i]->getLiveY(), maskPoints[nextIndex]->getLiveX(), maskPoints[nextIndex]->getLiveY());
            }
        }
    }
    
    if(mode != Live){
        
        if(this->hasAGhostPoint){
            ghostPoint.drawLive();
        }
        
        for(int i = 0; i < maskPoints.size(); i++){
            maskPoints[i]->drawLive();
        }
    }
    
    ofPopMatrix();
}
Exemplo n.º 18
0
    std::pair<int, size_t> dp(const int k, const size_t kidx, const std::vector<int>& a, const size_t ai, const std::vector<int>& b, const size_t bi) {
        std::ostringstream ostr;
        ostr << k << ":" << kidx << ":" << ai << ":" << bi << ":";
        if (dpMap.find(ostr.str()) != dpMap.end()) {
            return dpMap[ostr.str()];
        }

        if (ai >= a.size()) {
            saveResult(ostr.str(), std::make_pair(1, getNextIndex(false, k, kidx, b, bi, a.size(), ai)));
            return dpMap[ostr.str()];
        }
        
        if (bi >= b.size()) {
            saveResult(ostr.str(), std::make_pair(0, getNextIndex(true, k, kidx, a, ai, b.size(), bi)));
            return dpMap[ostr.str()];
        }
        
        if (ai >=a.size() && bi >=a.size()) {
            assert(0 == "should not reach here");
        }
        
        const size_t naidx = getNextIndex(true, k, kidx, a, ai, b.size(), bi);
        const size_t nbidx = getNextIndex(false, k, kidx, b, bi, a.size(), ai);
        
        if (a[naidx] > b[nbidx]) {
            saveResult(ostr.str(), std::make_pair(0, naidx));
            return dpMap[ostr.str()];
        } else if (a[naidx] < b[nbidx]) {
            saveResult(ostr.str(),std::make_pair(1, nbidx));
            return dpMap[ostr.str()];
        } else if (kidx == k-1) {
            saveResult(ostr.str(),std::make_pair(0, naidx));
            return dpMap[ostr.str()];
        } else {
            std::vector<std::vector<int> const*> nums;
            nums.reserve(2);
            nums.push_back(&a);
            nums.push_back(&b);
            std::pair<int, size_t> adp;
            std::pair<int, size_t> bdp;
            
            size_t tnaidx = naidx+1;
            size_t tnbidx = nbidx+1;
            size_t depth = 1;
            do {
                adp = dp(k, kidx+depth, a, tnaidx, b, bi);
                bdp = dp(k, kidx+depth, a, ai, b, tnbidx);
                ++tnaidx;
                ++tnbidx;
                ++depth;
            } while ((*nums[adp.first])[adp.second] == (*nums[bdp.first])[bdp.second] &&
                     nums[adp.first]->size()-1 <= adp.second &&
                     nums[bdp.first]->size()-1 <= bdp.second &&
                     depth < k-kidx);
            if ((*nums[adp.first])[adp.second] > (*nums[bdp.first])[bdp.second]) {
                saveResult(ostr.str(),std::make_pair(0, naidx));
                return dpMap[ostr.str()];
            } else if ((*nums[adp.first])[adp.second] < (*nums[bdp.first])[bdp.second]) {
                saveResult(ostr.str(),std::make_pair(1, nbidx));
                return dpMap[ostr.str()];
            } else if (nums[adp.first]->size()-1 > adp.second) {
                saveResult(ostr.str(), std::make_pair(0, naidx));
                return dpMap[ostr.str()];
            } else if (nums[bdp.first]->size()-1 > bdp.second) {
                saveResult(ostr.str(),std::make_pair(1, nbidx));
                return dpMap[ostr.str()];
            }
        }
        assert(0 == "Should never reach here");
    }
/**
	This static method reads an obj file, whose name is sent in as a parameter, and returns a pointer to a GLMesh object that it created based on the file information.
	This method throws errors if the file doesn't exist, is not an obj file, etc.
*/
GLMesh* OBJReader::loadOBJFile(const char* fileName){
	if (fileName == NULL)
		throwError("fileName is NULL.");
	
//	Logger::out()<< "Loading mesh: " << fileName <<std::endl;

	FILE* f = fopen(fileName, "r");
	if (f == NULL)
		throwError("Cannot open file \'%s\'.", fileName);

	GLMesh* result = new GLMesh();

	result->setOriginalFilename( fileName );

	//have a temporary buffer used to read the file line by line...
	char buffer[200];

	//and this is an array of texture coordinates - the Point3d is a simple data type so I can use the DynamicArray
	DynamicArray<Point3d> texCoordinates;


	//this variable will keep getting populated with face information
	GLIndexedPoly temporaryPolygon;

	//this is where it happens.
	while (!feof(f)){
		//get a line from the file...
		fgets(buffer, 200, f);
		//see what line it is...
		int lineType = getLineType(buffer);
		if (lineType == VERTEX_INFO){
			//we need to read in the three coordinates - skip over the v
			Point3d vertexCoords = readCoordinates(buffer + 1);
			result->addVertex(vertexCoords);
		}

		if (lineType == TEXTURE_INFO){
			Point3d texCoords = readCoordinates(buffer + 2);
			texCoordinates.push_back(texCoords);
		}

		if (lineType == FACE_INFO){
			temporaryPolygon.indexes.clear();
			int vIndex, tIndex;
			int flag;
			char* tmpPointer = buffer+1;
			while (tmpPointer = getNextIndex(tmpPointer, vIndex, tIndex, flag)){
				temporaryPolygon.indexes.push_back(vIndex-1);
				if (flag & READ_TEXTCOORD_INDEX){
					if (tIndex<0)
						result->setVertexTexCoordinates(vIndex, texCoordinates[texCoordinates.size()+tIndex]);
					else
						result->setVertexTexCoordinates(vIndex, texCoordinates[tIndex]);
				}
			}
			if (temporaryPolygon.indexes.size() == 0)
				tprintf("Found a polygon with zero vertices.\n");
			else
				result->addPoly(temporaryPolygon);
		}

	}

	fclose(f);
	return result;
}
Exemplo n.º 20
0
void CollisionDetector::addCollisionsBetween(Entity* e1, Entity* e2, std::vector<CollisionEvent*>* events, float timeLeft)
{
	if (Entity::areWrapperPartners(e1, e2))
	{
		Debug::warn(std::string(__PRETTY_FUNCTION__) + ": between collision partners");
	}

	const GameRect wrapper1 = e1->getWrapper(0.f); // TODO make getWrapper more beautiful
	const GameRect wrapper2 = e2->getWrapper(0.f);

	const float posX1 = e1->getPosition().x;
	const float posY1 = e1->getPosition().y;
	const float sizeX1 = wrapper1.getSize().x;
	const float sizeY1 = wrapper1.getSize().y;

	const float posX2 = e2->getPosition().x;
	const float posY2 = e2->getPosition().y;
	const float sizeX2 = wrapper2.getSize().x;
	const float sizeY2 = wrapper2.getSize().y;

	// speed subtraction
	const float speedX = e1->getSpeed().x - e2->getSpeed().x;
	const float speedY = e1->getSpeed().y - e2->getSpeed().y;

	// getestet
	CollisionStatus xCol, yCol;
	const float right1 = wrapper1.getRight();
	const float right2 = wrapper2.getRight();

	const float left1 = wrapper1.getLeft();
	const float left2 = wrapper2.getLeft();

	const float bot1 = wrapper1.getBot();
	const float bot2 = wrapper2.getBot();

	const float top1 = wrapper1.getTop();
	const float top2 = wrapper2.getTop();

	if ((right1 > left2) && (right2 > left1)) // Wenn die Entities sich auf der xAchse schneiden
	{
		xCol = CollisionStatus::IN;
	}
	else if ((right1 == left2) || (right2 == left1)) // Wenn die Entities sich auf der xAchse berühren
	{
		xCol = CollisionStatus::BORDER;
	}
	else // sonst OUT
	{
		xCol = CollisionStatus::OUT;
	}

	if ((bot1 > top2) && (bot2 > top1))
	{
		yCol = CollisionStatus::IN;
	}
	else if ((bot1 == top2) || (bot2 == top1))
	{
		yCol = CollisionStatus::BORDER;
	}
	else
	{
		yCol = CollisionStatus::OUT;
	}

	CollisionStatus oldStatus = std::max(xCol, yCol);

	if (oldStatus < CollisionStatus::OUT)
	{
		CollisionEvent* ev = new CollisionEvent(e1, e2, timeLeft);
		addEvent(events, ev);
	}

	std::pair<std::vector<float>, std::vector<bool>> pair = getPair(posX1, posY1, sizeX1, sizeY1, speedX, speedY, posX2, posY2, sizeX2, sizeY2, timeLeft);
	std::vector<float> floats = pair.first;
	std::vector<bool> bools = pair.second;

	while (floats.size() > 0)
	{
		int index = getNextIndex(floats);
		float time = floats[index];

		if (bools[index])
		{
			if (xCol == CollisionStatus::IN)
			{
				xCol = CollisionStatus::OUT;
			}
			else if (xCol == CollisionStatus::OUT)
			{
				xCol = CollisionStatus::IN;
			}
			else
			{
				// linke entity schneller:
				if (speedX == 0) Debug::error("CollisionDetector::addCollisionsBetweenEvenRects(): logical issue here (x)");
				if ((speedX > 0) == (posX1 < posX2))
				{
					xCol = CollisionStatus::IN;
				}
				else
				{
					xCol = CollisionStatus::OUT;
				}
			}
		}
		else
		{
			if (yCol == CollisionStatus::IN)
			{
				yCol = CollisionStatus::OUT;
			}
			else if (yCol == CollisionStatus::OUT)
			{
				yCol = CollisionStatus::IN;
			}
			else
			{
				// obere entity schneller:
				if (speedY == 0) Debug::error("CollisionDetector::addCollisionsBetweenEvenRects(): logical issue here (y)");
				if ((speedY > 0) == (posY1 < posY2))
				{
					yCol = CollisionStatus::IN;
				}
				else
				{
					yCol = CollisionStatus::OUT;
				}
			}
		}

		floats.erase(floats.begin() + index);
		bools.erase(bools.begin() + index);

		if (oldStatus != std::max(xCol, yCol))
		{
			oldStatus = std::max(xCol, yCol);
			CollisionEvent* ev = new CollisionEvent(e1, e2, timeLeft-time);
			addEvent(events, ev);
		}
	}
}