void DFS(int i) {
	for (int m = 0; m < n; m++)
	{
		visited[m] = 0;
	}
	int counter = 0;
	StackInit();
	visited[i] = 1;
	Stackpush(i);
	fprintf(fout,"%d ->", i);
	counter++;
	i = getTop();
	while (top != 0)
	{
		for (int w = 0; w < n; w++)
		{
			if ((!visited[w]) && adj_mat[i][w])
			{
				Stackpush(w);
				visited[w] = 1;
				counter++;
				fprintf(fout,"%d ", w);
				if (counter<n)
					fprintf(fout," -> ");
				i = getTop();
				w = 0;
			}
		}
		Stackpop();
		i = getTop();
	}
}
Exemple #2
0
void Gui::draw()
{
    mGraphics->pushClipArea(getTop()->getDimension());
    getTop()->draw(mGraphics);

    int mouseX, mouseY;
    Uint8 button = SDL_GetMouseState(&mouseX, &mouseY);

    mouseX /= graphics->getScale();
    mouseY /= graphics->getScale();

    if ((Client::hasMouseFocus() || button & SDL_BUTTON(1))
            && mCustomCursor
            && mMouseCursorAlpha > 0.0f)
    {
        Image *mouseCursor = mMouseCursors->get(mCursorType);
        mouseCursor->setAlpha(mMouseCursorAlpha);

        static_cast<Graphics*>(mGraphics)->drawImage(
                mouseCursor,
                mouseX - 15,
                mouseY - 17);
    }

    mGraphics->popClipArea();
}
Exemple #3
0
	void Interpreter::pushUserType(void *data, const std::string& type)
	{
		int top = getTop();
		tolua_pushusertype(luastate,data,type.c_str());
		if (getTop() == top)
			throw LuaException(std::string("Failed to push user type ") + type);
	}
Exemple #4
0
void TopWindow::processEvent( EvtMotion &rEvtMotion )
{
    // New control hit by the mouse
    CtrlGeneric *pNewHitControl =
        findHitControl( rEvtMotion.getXPos() - getLeft(),
                        rEvtMotion.getYPos() - getTop() );

    setLastHit( pNewHitControl );

    /// Update the help text
    VarManager *pVarManager = VarManager::instance( getIntf() );
    if( pNewHitControl )
    {
        pVarManager->getHelpText().set( pNewHitControl->getHelpText() );
    }

    // Send a motion event to the hit control, or to the control
    // that captured the mouse, if any
    CtrlGeneric *pActiveControl = pNewHitControl;
    if( m_pCapturingControl )
    {
        pActiveControl = m_pCapturingControl;
    }
    if( pActiveControl )
    {
        // Compute the coordinates relative to the window
        int xPos = rEvtMotion.getXPos() - getLeft();
        int yPos = rEvtMotion.getYPos() - getTop();
        // Send a motion event
        EvtMotion evt( getIntf(), xPos, yPos );
        pActiveControl->handleEvent( evt );
    }
}
Exemple #5
0
	void Interpreter::pop(const int num)
	{
		if (num > getTop()) {
			std::cout << "woah... num " << num << " top " << getTop() << ", stack:\n" << getStack();
			throw LuaException("Attempt to pop more than what is on the stack\n" + getStack());
		}
		lua_pop(luastate, num);
	}
Exemple #6
0
// dieses Rect relativ zum anderen...
eTouchType Rect::getTouchType(const Rect& rect) const
{
	if(!isTouched(rect)) {
		return TOUCHES_NO_TOUCH;
	}

	// ist 'rect' innerhalb dieses Rects?
	if(isRectInside(rect)) {
		return TOUCHES_IS_COMPLETELY_INSIDE;
	} else if(isTopLeftCornerInside(rect.getTopLeft()) && isBottomLeftCornerInside(rect.getBottomLeft())) {
		return TOUCHES_CROSSES_RIGHT_BORDER;
	} else if(isTopLeftCornerInside(rect.getTopLeft()) && isTopRightCornerInside(rect.getTopRight())) {
		return TOUCHES_CROSSES_LOWER_BORDER;
	} else if(isTopRightCornerInside(rect.getTopRight()) && isBottomRightCornerInside(rect.getBottomRight())) {
		return TOUCHES_CROSSES_LEFT_BORDER;
	} else if(isBottomRightCornerInside(rect.getBottomRight()) && isBottomLeftCornerInside(rect.getBottomLeft())) {
		return TOUCHES_CROSSES_UPPER_BORDER;
	} else if(isTopLeftCornerInside(rect.getTopLeft())) {
		return TOUCHES_CROSSES_BOTTOM_RIGHT_CORNER;
	} else if(isTopRightCornerInside(rect.getTopRight())) {
		return TOUCHES_CROSSES_BOTTOM_LEFT_CORNER;
	} else if(isBottomRightCornerInside(rect.getBottomRight())) {
		return TOUCHES_CROSSES_TOP_LEFT_CORNER;
	} else if(isBottomLeftCornerInside(rect.getBottomLeft())) {
		return TOUCHES_CROSSES_TOP_RIGHT_CORNER;
	}

	else if((rect.getLeft() < getLeft()) && (rect.getRight() > getRight()) && (rect.getTop() >= getTop()) && (rect.getBottom() <= getBottom())) { // ? = 
		return TOUCHES_CROSSES_LEFT_AND_RIGHT_BORDER;
	} else if((rect.getTop() < getTop()) && (rect.getBottom() > getBottom()) && (rect.getLeft() >= getLeft()) && (rect.getRight() <= getRight())) {
		return TOUCHES_CROSSES_TOP_AND_BOTTOM_BORDER;
	}

	else if((rect.getLeft() == getRight()) && (rect.getTop() == getTop()) && (rect.getBottom() == getBottom())) {
		return TOUCHES_RIGHT_BORDER;
	} else if((rect.getTop() == getBottom()) && (rect.getLeft() == getLeft()) && (rect.getRight() == getRight())) {
		return TOUCHES_LOWER_BORDER;
	} else if((rect.getRight() == getLeft()) && (rect.getTop() == getTop()) && (rect.getBottom() == getBottom())) {
		return TOUCHES_LEFT_BORDER;
	} else if((rect.getBottom() == getTop()) && (rect.getLeft() == getLeft()) && (rect.getRight() == getRight())) {
		return TOUCHES_UPPER_BORDER;
	}

	else if((rect.isTopLeftCornerInside(getTopLeft())) && (rect.isTopRightCornerInside(getTopRight())) && (!rect.isBottomRightCornerInside(getBottomRight())) && (!rect.isBottomLeftCornerInside(getBottomLeft()))) {
		return TOUCHES_CROSSES_UPPER_AREA;
	} else if((!rect.isTopLeftCornerInside(getTopLeft())) && (rect.isTopRightCornerInside(getTopRight())) && (rect.isBottomRightCornerInside(getBottomRight())) && (!rect.isBottomLeftCornerInside(getBottomLeft()))) {
		return TOUCHES_CROSSES_RIGHT_AREA;
	} else if((!rect.isTopLeftCornerInside(getTopLeft())) && (!rect.isTopRightCornerInside(getTopRight())) && (rect.isBottomRightCornerInside(getBottomRight())) && (rect.isBottomLeftCornerInside(getBottomLeft()))) {
		return TOUCHES_CROSSES_LOWER_AREA;
	} else if((rect.isTopLeftCornerInside(getTopLeft())) && (!rect.isTopRightCornerInside(getTopRight())) && (!rect.isBottomRightCornerInside(getBottomRight())) && (rect.isBottomLeftCornerInside(getBottomLeft()))) {
		return TOUCHES_CROSSES_LEFT_AREA;
	}

	else { 
		return TOUCHES_NO_TOUCH;
	}
}
Exemple #7
0
/*
 * 中缀转后缀
 * 算法
 * 1)检查输入的下一元素。
 * 2)假如是个操作数,输出。
 * 3)假如是个开括号,将其压栈。
 * 4)假如是个运算符,则
 *       i) 假如栈为空,将此运算符压栈。
 *      ii) 假如栈顶是开括号,将此运算符压栈。
 *     iii) 假如此运算符比栈顶运算符优先级高,将此运算符压入栈中。
 *      iv) 否则栈顶运算符出栈并输出,重复步骤4。
 * 5)假如是个闭括号,栈中运算符逐个出栈并输出,直到遇到开括号。开括号出栈并丢弃。
 * 6)假如输入还未完毕,跳转到步骤1。
 * 7)假如输入完毕,栈中剩余的所有操作符出栈并输出它们。
 */
char *infix_to_suffix(const char *exp)
{
    int i, j;
    char *suffix, top;
    StackNode *stack = NULL;
    suffix = (char *)calloc(1, strlen(exp) + 1);
    assert(suffix != NULL);

    for (i = j = 0; exp[i] != '\0'; i++)
    {
        if (isupper(exp[i]))
            suffix[j++] = exp[i];
        else if (exp[i] == '(')
            push(&stack, exp[i]);
        else if (isoperator(exp[i]))
        {
            while (1)
            {
                if (isEmpty(stack) || getTop(stack) == '(')
                {
                    push(&stack, exp[i]);
                    break;
                }
                else
                {
                    top = getTop(stack);
                    if (priority(exp[i]) > priority(top) || (exp[i] == '!' && top == '!'))
                    {
                        push(&stack, exp[i]);
                        break;
                    }
                    else
                    {
                        suffix[j++] = getTop(stack);
                        pop(&stack);
                    }
                }
            }
        }
        else if (exp[i] == ')')
        {
            while (!isEmpty(stack) && (top = getTop(stack)) != '(')
            {
                suffix[j++] = top;
                pop(&stack);
            }
            pop(&stack);
        }
    }

    while (!isEmpty(stack))
    {
        suffix[j++] = getTop(stack);
        pop(&stack);
    }
    return suffix;
}
Exemple #8
0
void ScreenManager::enter(Screen* screen)
{
	if (getTop() != 0)
	{
		myScreenToExit = getTop();
	}

	myStack.push_back(screen);
}
Exemple #9
0
void Button::draw()
{
	COLOUR farg1, farg2, farg3, farg4;
	if ( getStatus() == Pressed || getStatus() == Active)
	{
		farg1 = WHITE;
		farg2 = BLACK;
		farg3 = DARKGREY;
		farg4 = LIGHTGREY;
	}
	else {
		farg1 = BLACK;
		farg2 = WHITE;
		farg3 = LIGHTGREY;
		farg4 = DARKGREY;
	}
//Bakgrund
	rectfill(bmp, getLeft(), getTop(), getRight(), getBottom(), GREY);
//Texten
	textout(bmp, font, getText(), getTextPosX(), getTextPosY(), getTextColor());
//Yttre boxen
	line(bmp, getLeft(), getBottom(), getRight(), getBottom(), farg1);
	line(bmp, getRight(), getBottom(), getRight(), getTop(), farg1);
	line(bmp, getLeft(), getBottom()-1, getLeft(), getTop(), farg2);
	line(bmp, getLeft(), getTop(), getRight()-1, getTop(), farg2);
//Inre boxen
	line(bmp, getLeft()+1, getBottom()-1, getLeft()+1, getTop()+1, farg3);
	line(bmp, getLeft()+1, getTop()+1, getRight()-1, getTop()+1, farg3);
	line(bmp, getRight()-1, getBottom()-1, getRight()-1, getTop()+1, farg4);
	line(bmp, getLeft()+1, getBottom()-1, getRight()-1, getBottom()-1, farg4);
}
Int32 FBOViewport::getPixelTop(void) const
{
    // >1: pixel
    if(getTop() > 1)
        return Int32(getTop());
 
    if(getFrameBufferObject() == NULL)
        return Int32(getTop());
   
    // <=1: partial screen, use 1 less to not overlap other windows
    return Int32(getFrameBufferObject()->getHeight() * getTop() - 1);
}
void Radiolist::genericFunc3(int x, int y, bool arg)
{
	if (getVisible())
	{
		for (int i = 0; i < lines.size(); i++)
		{
			if ((x >= lines[i].getLeft() - getLeft()) && (x <= (lines[i].getLeft() - getLeft() + lines[i].getMaxWidth())))
			if (y >= lines[i].getTop() - getTop() && y <= (lines[i].getTop() - getTop() + lines[i].getHight()))
			{
				lines[i].genericFunc1();
			}
		}
	}
}
Exemple #12
0
Int32 StagedViewport::getPixelTop(void) const
{
    if(!getFrameBufferObject())
    {   // => behave like normal viewport
        return Viewport::calcPixelTop();
    }
    else
    {   // => behave like FBOViewport
        if(getTop() > 1)
            return Int32(getTop());

        // <=1: partial screen, use 1 less to not overlap other windows
        return Int32(getFrameBufferObject()->getHeight() * getTop() - 1);
    }
}
void StickOnCollision::handleEvent(const CollisionEvent& e)
 {

	GameObject obj = e.getOtherObject();
	if (obj.getType() == GameObject::Type::TILE)
	{
		hookPoint = obj.getPos();
		PhysicsComponent * hookPhysics = owner_.getComponent<PhysicsComponent>();
		hookPhysics->setVelX(0);
		hookPhysics->setVelY(0);
		
		auto tileCollider = e.getOtherCollider();
		auto hookCollider = owner_.getComponent<ColliderComponent>();

		float hookBot = hookCollider->getBottom();
		float tileBot = tileCollider.getBottom();
		float tileTop = tileCollider.getTop();

		if (hookBot == tileTop)
		{
			isConnected = false;
		}
		else
		{
			isConnected = true;
		}
		//LOG("INFO") << "Hook is connected at " << hookPoint;
		
	}
}
Exemple #14
0
Rect GUI::getCommandLineArea(const Window& window)
{
    auto worldViewport = getWorldViewport(window);
    auto questionArea = getQuestionArea(window);
    return Rect(worldViewport.getLeft() + spacing.x, worldViewport.getTop() + spacing.y,
                worldViewport.getWidth() - spacing.x * 2, questionArea.getHeight());
}
Exemple #15
0
void
LuaParser::getTop(unsigned int& output) const
{
  double d;
  getTop(d);
  output = unsigned(d);
}
Exemple #16
0
void
LuaParser::getTop(int& output) const
{
  double d;
  getTop(d);
  output = (int)d;
}
Exemple #17
0
void
LuaParser::getTop(float& output) const
{
  double d;
  getTop(d);
  output = float(d);
}
Exemple #18
0
// Technically, this is incorrect. This is a intersect
bool Rect::contains(const Rect &rect) const
{
	return getLeft() < rect.getRight() &&
		getRight() > rect.getLeft() &&
		getTop() < rect.getBottom() &&
		getBottom() > rect.getTop();
}
Exemple #19
0
bool Recti::contains(const Vector2i &pt) const
{
	return getLeft() < pt.x &&
		getTop() < pt.y &&
		getRight() > pt.x &&
		getBottom() > pt.y;
}
Exemple #20
0
void CX3DCylinderNode::print(int indent)
{
	FILE *fp = CX3DParser::getDebugLogFp();

	char *nodeName = getNodeName();
	if (nodeName)
	{
		CX3DParser::printIndent(indent);
		fprintf(fp, "%s (%s)\n", nodeName, CX3DNode::getNodeTypeString(getNodeType()));

		CX3DParser::printIndent(indent+1);
		fprintf(fp, "solid : %s\n", getSolid()->getValue() ? "TRUE" : "FALSE");

		CX3DParser::printIndent(indent+1);
		fprintf(fp, "radius : (%f)\n", getRadius()->getValue());

		CX3DParser::printIndent(indent+1);
		fprintf(fp, "height : (%f)\n", getHeight()->getValue());

		CX3DParser::printIndent(indent+1);
		fprintf(fp, "bottom : %s\n", getBottom()->getValue() ? "TRUE" : "FALSE");

		CX3DParser::printIndent(indent+1);
		fprintf(fp, "side : %s\n", getSide()->getValue() ? "TRUE" : "FALSE");

		CX3DParser::printIndent(indent+1);
		fprintf(fp, "top : %s\n", getTop()->getValue() ? "TRUE" : "FALSE");
	}
}
Exemple #21
0
// returns false if the bitmap is empty or has wrong color space.
bool
BoundsCalculator::getValidRect(BBitmap *bitmap, RECT *rect)
{
	enum {
		kRectIsInvalid = false,
		kRectIsEmpty = false,
		kRectIsValid = true
	};
	
	switch (bitmap->ColorSpace()) {
		case B_RGB32:
		case B_RGB32_BIG:
			break;
		default:
			return kRectIsInvalid;
			break;
	};

	// initialize member variables
	fBits = (uchar*)bitmap->Bits();
	fBPR  = bitmap->BytesPerRow();
	
	fLeft   = rect->left;	
	fRight  = rect->right;
	fTop    = rect->top;
	fBottom = rect->bottom;
	
	fWidth = fRight - fLeft + 1;

	// get top bound
	fTop = getTop();
	if (fTop > fBottom) {
		return kRectIsEmpty;
	}
	
	// get bottom bound
	fBottom = getBottom();
	
	// calculate left and right bounds
	fLeftBound = fRight + 1;
	fRightBound = fLeft - 1;
	
	const uchar *row = getRow(fLeft, fTop);
	for (int y = fTop; y <= fBottom; y ++) {
		updateLeftBound((const rgb_color*)row);
		updateRightBound((const rgb_color*)row);
		if (fLeft == fLeftBound && fRight == fRightBound) {
			break;
		}
		row += fBPR;
	}
	
	// return bounds in rectangle
	rect->left = fLeftBound;
	rect->right = fRightBound; 
	rect->top = fTop;
	rect->bottom = fBottom;
		
	return kRectIsValid;
}
Exemple #22
0
//----------------------------------------------------------
//	isActive används när man vill skriva till TextFältet
//----------------------------------------------------------
void TextField::isActive()
{
	bool stop = false;
	while(!stop)
	{
		gotoxy(getLeft(), getTop());
		this->draw();
		char key=getch();
	/*Special*/
		if(key==0)
		{
			char key=getch();
			switch(key)
			{
/*Pil VÄNSTER*/	case CHLEFT: TextObjekt::left(); break;
	/*Pil HÖGER*/	case CHRIGHT: TextObjekt::right(); break;
	/*Del*/			case CHDEL: TextObjekt::del(); break;
	/*ANNAN*/		default: break;
			}
		}
		switch(key)
		{
/*Baksteg*/		case 8: this->baksteg(); break;
/*TAB <-->*/	case 9: for(int i=0; i<4; ++i)
							{	this->putIn(' ');	}
					break;
	/*Esc*/		case CHESC: stop = true; break;
	/*Enter*/	case ENTER: stop = true; break;
/*Tecken a-z*/	default: this->putIn(key); break;
		}
	}
}
Exemple #23
0
	bool Rectangle::overlapping(const Rectangle &rectangle)
	{
		return (rectangle.getLeft() < getRight()) &&
				(rectangle.getRight() > getLeft()) &&
				(rectangle.getTop() > getBottom()) &&
				(rectangle.getBottom() < getTop());
	}
Exemple #24
0
void TopWindow::processEvent( EvtDragDrop &rEvtDragDrop )
{
    // Get the control hit by the mouse
    int xPos = rEvtDragDrop.getXPos() - getLeft();
    int yPos = rEvtDragDrop.getYPos() - getTop();

    CtrlGeneric *pHitControl = findHitControl( xPos, yPos );
    if( pHitControl && pHitControl->getType() == "tree" )
    {
        // Send a dragDrop event
        EvtDragDrop evt( getIntf(), xPos, yPos, rEvtDragDrop.getFiles() );
        pHitControl->handleEvent( evt );
    }
    else
    {
        list<string> files = rEvtDragDrop.getFiles();
        list<string>::const_iterator it = files.begin();
        for( bool first = true; it != files.end(); ++it, first = false )
        {
            bool playOnDrop = m_playOnDrop && first;
            CmdAddItem( getIntf(), it->c_str(), playOnDrop ).execute();
        }
    }
    m_pDragControl = NULL;
}
Exemple #25
0
Gui::~Gui()
{
    config.removeListeners(mConfigListener);
    delete2(mConfigListener);

    if (mMouseCursors)
    {
        mMouseCursors->decRef();
        mMouseCursors = nullptr;
    }

    if (windowContainer)
        windowContainer->slowLogic();
    delete getTop();

    delete2(mGuiFont);
    delete2(boldFont);
    delete2(mHelpFont);
    delete2(mSecureFont);
    delete2(mInfoParticleFont);
    delete2(mNpcFont);

    delete2(guiInput);

    delete2(theme);

    if (Widget::widgetExists(mTop))
        setTop(nullptr);

    delete2(mFocusHandler);
}
Exemple #26
0
int Position::getBottom() const
{
    if( m_yKeepRatio )
    {
        // Ratio mode
        // The height of the control being constant, we can use the result of
        // getTop() (this will avoid rounding issues).
        return getTop() + m_bottom - m_top;
    }
    else
    {
        switch( m_refRighBottom )
        {
            case kLeftTop:
            case kRightTop:
                return m_bottom;
                break;
            case kLeftBottom:
            case kRightBottom:
                return m_rBox.getHeight() + m_bottom - 1;
                break;
        }
        // Avoid a warning
        return 0;
    }
}
Exemple #27
0
inline Box<float>::operator Box<int>() const
{
	Box<int> box;
	box.setCoords(static_cast<int>(roundf(getLeft())), static_cast<int>(roundf(getTop())), 
			static_cast<int>(roundf(getRight())), static_cast<int>(roundf(getBottom())));
	return box;
}
Exemple #28
0
inline Box<double>::operator Box<long>() const
{
	Box<long> box;
	box.setCoords(static_cast<long>(round(getLeft())), static_cast<long>(round(getTop())), 
			static_cast<long>(round(getRight())), static_cast<long>(round(getBottom())));
	return box;
}
Exemple #29
0
inline void Box<int>::scale(double xScale, double yScale)
{
	int x = static_cast<int>(round(xScale * getLeft()));
	int y = static_cast<int>(round(yScale * getTop()));
	int x2 = static_cast<int>(round(xScale * getRight()));
	int y2 = static_cast<int>(round(yScale * getBottom()));
	setCoords(x, y, x2, y2);
}
Exemple #30
0
inline void Box<long>::scale(double xScale, double yScale)
{
	long x = static_cast<long>(round(xScale * getLeft()));
	long y = static_cast<long>(round(yScale * getTop()));
	long x2 = static_cast<long>(round(xScale * getRight()));
	long y2 = static_cast<long>(round(yScale * getBottom()));
	setCoords(x, y, x2, y2);
}