void EditLineWidget::Render()
{
	WidgetBase::Render();
	LabelWidget::Render();

	Vec2 worldPos = GetWorldPosition();
	float textOpacity = GetTextOpacity();

	RGBA cursorColor;
	GetPropertyForCurrentState("text color", cursorColor);
	cursorColor.a() = static_cast<unsigned char>(cursorColor.a() * textOpacity);

	float textScale;
	GetPropertyForCurrentState("text scale", textScale);

	double time;
	GetPropertyForCurrentState("blink time", time);

	if ((m_currentBlinkTimeSeconds >= time) && m_canType) {
		Vec2 cursorSize = Vec2(1.f, textScale * 5.f);
		if (m_cursorIndex == 0) {
			RenderBackground(worldPos, cursorSize, cursorColor);
		}
		else {
			std::string leftOfCursor = m_fullText.substr(m_leftmostCharacterIndex, m_cursorIndex - m_leftmostCharacterIndex);
			float cursorOffset = m_fontRenderer->CalcTextWidth(leftOfCursor, cursorSize.y());
			RenderBackground(Vec2(worldPos.x() + cursorOffset, worldPos.y()), cursorSize, cursorColor);
		}
	}
	if (m_currentBlinkTimeSeconds >= (time * 2)) {
		m_currentBlinkTimeSeconds = 0.0;
	}
}
void ProgressBarWidget::Render()
{
	Vec2 worldPos = GetWorldPosition();
	float progress;

	Vec2 size;
	GetPropertyForCurrentState("size", size);

	float borderSize;
	GetPropertyForCurrentState("border size", borderSize);

	float opacity = GetOpacity();

	RGBA backgroundColor;
	RGBA innerColor;
	GetPropertyForCurrentState("color", backgroundColor);
	GetPropertyForCurrentState("inner color", innerColor);

	backgroundColor.a() *= static_cast<unsigned char>(backgroundColor.a() * opacity);
	innerColor.a() = static_cast<unsigned char>(innerColor.a() * opacity);


	RenderBackground(worldPos, size, backgroundColor);
	GetPropertyForCurrentState("progress", progress);

	CardinalDir dir;
	GetPropertyForCurrentState("direction", dir);
	switch (dir) {
	case C_DIRECTION_EAST:
		RenderBackground(worldPos, Vec2(size.x() * progress, size.y()), innerColor);
		break;
	case C_DIRECTION_WEST: {
		Vec2 fillSize = Vec2(size.x() * progress, size.y());
		Vec2 leftEnd = Vec2(worldPos.x() + size.x() - fillSize.x(), worldPos.y());
		RenderBackground(leftEnd, fillSize, innerColor);
		break;
	}
	case C_DIRECTION_SOUTH: {
		Vec2 fillSize = Vec2(size.x(), size.y()  * progress);
		Vec2 top = Vec2(worldPos.x(), worldPos.y() + size.y() - fillSize.y());
		RenderBackground(top, fillSize, innerColor);
		break;
	}
	case C_DIRECTION_NORTH:
		RenderBackground(worldPos, Vec2(size.x(), size.y()  * progress), innerColor);
		break;
	}

	RenderOutline(worldPos, size, borderSize);

	WidgetBase::ProcessRenderEvent();
	/*
	RenderBackground(worldPos + (size * 0.25f), size * 0.5f, innerColor);
	RenderOutline(worldPos, size, borderSize);
	*/
}
Exemple #3
0
int RenderList(PWINDOW_LIST pList)
{
	int i;
	int nColumValid = -1,nRowValid = 0;
	RECT rAbsoluteScroll;
	int xCurrent = pList->wBasic.nOutLineWidth;
	int yCurrent = pList->wBasic.nOutLineWidth * 2 + pList->nHeaderHeight + pList->nRowsHeight;

	SetColorFoucus((PWINDOW)pList);

	RenderBackground(pList->wBasic.rAbsolute);

	RenderBonder(pList->wBasic.rAbsolute,pList->wBasic.nOutLineWidth);

	DrawLineWithWidth(pList->wBasic.rAbsolute.nLeft,
		pList->wBasic.rAbsolute.nTop + pList->wBasic.nOutLineWidth + pList->nHeaderHeight,
		pList->wBasic.rAbsolute.nWidth,pList->wBasic.nOutLineWidth);

	for(i=0;i<pList->nColums;++i){
		xCurrent += pList->nColumsWidth[i];
		if(xCurrent > pList->wBasic.rAbsolute.nWidth){
			nColumValid = xCurrent + 1;
		}
		DrawLineWithWidth(pList->wBasic.rAbsolute.nLeft+xCurrent,pList->wBasic.rAbsolute.nTop,
			pList->nInnerLineWidth,pList->wBasic.rAbsolute.nHeight);
		xCurrent += pList->nInnerLineWidth;
	}

	if(nColumValid == -1 ){
		nColumValid = pList->nColums;
	}

	while(yCurrent < pList->wBasic.rAbsolute.nHeight){
		DrawLineWithWidth(pList->wBasic.rAbsolute.nLeft,pList->wBasic.rAbsolute.nTop+yCurrent,
			pList->wBasic.rAbsolute.nWidth- pList->nScrollWidth ,pList->nInnerLineWidth);
		yCurrent += pList->nInnerLineWidth;
		yCurrent += pList->nRowsHeight;
		nRowValid ++;
	}

	rAbsoluteScroll.nLeft 	= pList->wBasic.rAbsolute.nLeft + pList->wBasic.rAbsolute.nWidth - pList->nScrollWidth;
	rAbsoluteScroll.nTop 	= pList->wBasic.rAbsolute.nTop  + pList->wBasic.nOutLineWidth + pList->nHeaderHeight;
	rAbsoluteScroll.nWidth  = pList->nScrollWidth;
	rAbsoluteScroll.nHeight = pList->wBasic.rAbsolute.nHeight - ( pList->wBasic.nOutLineWidth + pList->nHeaderHeight );

	RenderBackground(rAbsoluteScroll);

	RenderBonder(rAbsoluteScroll,pList->wBasic.nOutLineWidth);

	return 1;
}
/*
============================
idAutoRender::RenderFrame
============================
*/
void idAutoRender::RenderFrame()
{
	// values are 0 to 1
	float loadingIconPosX = 0.5f;
	float loadingIconPosY = 0.6f;
	float loadingIconScale = 0.025f;
	float loadingIconSpeed = 0.095f;
	
	if( autoRenderIcon == AUTORENDER_HELLICON )
	{
		loadingIconPosX = 0.85f;
		loadingIconPosY = 0.85f;
		loadingIconScale = 0.1f;
		loadingIconSpeed = 0.095f;
	}
	else if( autoRenderIcon == AUTORENDER_DIALOGICON )
	{
		loadingIconPosY = 0.73f;
	}
	
	
	GL_SetDefaultState();
	
	GL_Cull( CT_TWO_SIDED );
	
	const bool stereoRender = false;
	
	const int width = renderSystem->GetWidth();
	const int height = renderSystem->GetHeight();
	const int guardBand = height / 24;
	
	if( stereoRender )
	{
		for( int viewNum = 0 ; viewNum < 2; viewNum++ )
		{
			GL_ViewportAndScissor( 0, viewNum * ( height + guardBand ), width, height );
			RenderBackground();
			RenderLoadingIcon( loadingIconPosX, loadingIconPosY, loadingIconScale, loadingIconSpeed );
		}
	}
	else
	{
		GL_ViewportAndScissor( 0, 0, width, height );
		RenderBackground();
		RenderLoadingIcon( loadingIconPosX, loadingIconPosY, loadingIconScale, loadingIconSpeed );
	}
	
}
//RenderGame(TetrisGame* game) - depending on the game state, render the game 
void RenderGame(TetrisGame* game)
{
	if(game->state != TITLE_SCREEN)
	{
		//we are in main game mode, or a version of it - render from back to front
		RenderBackground(game);

		RenderBoard(game);

		//if the block is falling render it 
		if(game->state == BLOCK_FALLING)
		{
			RenderBlock(game,game->currentBlockPos[0] * BLOCK_SIZE + GAME_BOARD_TOP_LEFT_X,
						game->currentBlockPos[1] * BLOCK_SIZE + GAME_BOARD_TOP_LEFT_Y,game->currentBlock,true);
		}

		//render the score and level display etc
		RenderHUD(game);

		//if game over, render the game over sign
		if(game->state == GAME_OVER && game->GameOverImageBool)
		{
			RenderImage(game,200,200,D3DXCOLOR(1.0f,1.0f,1.0f,1.0f),&(game->gameOverImage));
		}
	}
	else
	{
		//otherwise, we are in title screen mode, so render the main title,
		//the levels to choose from and the transparent cursor
		int xOffset = 230 + (game->Level + 4) % 5 * 35;
		int yOffset = 310 + (game->Level / 6) * 35;
		RenderImage(game,0,0,D3DXCOLOR(1.0f,1.0f,1.0f,1.0f),&(game->titleScreen));
		RenderImage(game,xOffset,yOffset,D3DXCOLOR(1.0f,1.0f,1.0f,game->transparency),&(game->cursorImg));
	}
}
Exemple #6
0
int RenderShowBox(PWINDOW_SHOW_BOX pShowBox){

//	return 0;
	RenderBackground(pShowBox->wBasic.rAbsolute);

	if(pShowBox->bCentered){
		RenderStringInRectCenter(
			pShowBox->szBuffer,
			pShowBox->nFrontSize,
			pShowBox->bUseHZK,
			pShowBox->wBasic.rAbsolute.nLeft,
			pShowBox->wBasic.rAbsolute.nTop ,
			pShowBox->wBasic.rAbsolute.nWidth ,
			pShowBox->wBasic.rAbsolute.nHeight
			);
	}else{
		RenderStringInRectNormal(
			pShowBox->szBuffer,
			pShowBox->nFrontSize,
			pShowBox->bUseHZK,
			pShowBox->wBasic.rAbsolute.nLeft,
			pShowBox->wBasic.rAbsolute.nTop ,
			// 100,
			// 100
			pShowBox->wBasic.rAbsolute.nWidth ,
			pShowBox->wBasic.rAbsolute.nHeight
			);
			//rectangle(500,400,100,100);¿ÉÒÔÖ´Ðе½´Ë
	}

	return 1;
}
//--------------------------------------------------------------------------------------
// Name: Render()
// Desc: Render the console to the screen
//--------------------------------------------------------------------------------------
VOID Console::Render()
{
    // Give GPU control back to us
    if( m_bSuspendFlag )
        m_pd3dDevice->Resume();

    m_bSuspendFlag = TRUE;

    // Render the background
    RenderBackground( m_colBackColor, m_colBackColor );

    // The top line
    UINT nTextLine = ( m_nCurLine - m_cScreenHeight + m_cScreenHeightVirtual - m_nScrollOffset + 1 )
        % m_cScreenHeightVirtual;


    m_Font.Begin();

    for( UINT nScreenLine = 0; nScreenLine < m_cScreenHeight; nScreenLine++ )
    {
        m_Font.DrawText( ( FLOAT )( m_cxSafeAreaOffset ),
                         ( FLOAT )( m_cySafeAreaOffset + m_fLineHeight * nScreenLine ),
                         m_colTextColor, m_Lines[nTextLine] );

        nTextLine = ( nTextLine + 1 ) % m_cScreenHeightVirtual;
    }

    m_Font.End();

    // Present the scene
    m_pd3dDevice->Present( NULL, NULL, NULL, NULL );

    // Take away GPU control so that the Guide can be rendered
    m_pd3dDevice->Suspend();
}
Exemple #8
0
int RenderDropList(PWINDOW_DROP_LIST pDropList)
{
	int i;

	SetColorFoucus((PWINDOW)pDropList);

	RenderBackground(pDropList->wBasic.rAbsolute);

	RenderBonder(pDropList->wBasic.rAbsolute,pDropList->wBasic.nOutLineWidth);

	DrawLineWithWidth(
		pDropList->wBasic.rAbsolute.nLeft+pDropList->nTitleAreaWidth+
		pDropList->wBasic.nOutLineWidth,
		pDropList->wBasic.rAbsolute.nTop,
		pDropList->wBasic.nOutLineWidth,
		pDropList->wBasic.rAbsolute.nHeight
		);

	RenderStringInRectCenter(
		pDropList->szDropData[pDropList->nSelected],
		pDropList->nFrontSize,
		1,
		pDropList->wBasic.rAbsolute.nLeft+pDropList->wBasic.nOutLineWidth,
		pDropList->wBasic.rAbsolute.nTop +pDropList->wBasic.nOutLineWidth,
		pDropList->nTitleAreaWidth,
		pDropList->wBasic.rRectOffset.nHeight - 2*pDropList->wBasic.nOutLineWidth
		);

	return 1;
}
Exemple #9
0
int RenderEdit(PWINDOW_EDIT pEdit)
{
	int i;

	SetColorFoucus((PWINDOW)pEdit);

	RenderBackground(pEdit->wBasic.rAbsolute);

	RenderBonder(pEdit->wBasic.rAbsolute,pEdit->wBasic.nOutLineWidth);

	DrawLineWithWidth(
		pEdit->wBasic.rAbsolute.nLeft+pEdit->nTitleAreaWidth+
		pEdit->wBasic.nOutLineWidth,
		pEdit->wBasic.rAbsolute.nTop,
		pEdit->wBasic.nOutLineWidth,
		pEdit->wBasic.rAbsolute.nHeight
		);

	RenderStringInRectCenter(
		pEdit->szTitle,
		pEdit->nFrontSize,
		1,
		pEdit->wBasic.rAbsolute.nLeft+pEdit->wBasic.nOutLineWidth,
		pEdit->wBasic.rAbsolute.nTop +pEdit->wBasic.nOutLineWidth,
		pEdit->nTitleAreaWidth,
		pEdit->wBasic.rRectOffset.nHeight - 2*pEdit->wBasic.nOutLineWidth
		);

	return 1;
}
Exemple #10
0
void FadeLabel::paintEvent(QPaintEvent* /*event*/)
{
	QRectF r( rect() );
	r.adjust(1, 1, -1, -1);
	
	QPainter painter(this);
	painter.setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing);
	
	QColor penColor( palette().color(QPalette::Button) );
	if(penColor.alpha() > 0)
		painter.setPen( QPen(penColor,2) );
	else
		painter.setPen(Qt::NoPen);
	painter.setBrush( palette().color(QPalette::Window) );
	RenderBackground(painter, r);
	
	sImage &img = m_Images[m_ImageIndex];
	if( !img.pixmap.isNull() )
	{
		painter.drawPixmap(	r.x() + qRound((r.width()-img.pixmap.width())*0.5),
						   r.y() + qRound((r.height()-img.pixmap.height())*0.5),
						   img.pixmap );
	}
	
	QColor textColor( palette().color(QPalette::ButtonText) );
	if( !isEnabled() )
		textColor = textColor.darker(150);
	
	if( !text().isEmpty() )
	{
		if( m_Label.isEmpty() )
		{
			// just text centered
			painter.setPen(textColor);
			painter.drawText(r, Qt::AlignCenter|Qt::TextWordWrap, text());
		}
		else
		{
			// both text and label text
			QRectF textRect;
			painter.setPen(textColor);
			painter.drawText(r, Qt::AlignCenter|Qt::TextWordWrap|Qt::TextDontPrint, text(), &textRect);
			
			QRectF labelRect;
			painter.drawText(r, Qt::AlignCenter|Qt::TextWordWrap|Qt::TextDontPrint, m_Label, &labelRect);
			
			qreal h = (r.height() * 0.5 * (textRect.height()/labelRect.height()));
			painter.drawText(QRectF(r.x(),r.y(),r.width(),h), Qt::AlignCenter|Qt::TextWordWrap, text());
			painter.drawText(QRectF(r.x(),r.y()+h,r.width(),r.height()-h), Qt::AlignCenter|Qt::TextWordWrap, m_Label);
		}
	}
	else if( !m_Label.isEmpty() )
	{
		// just label text centered
		painter.setPen(textColor);
		painter.drawText(r, Qt::AlignCenter|Qt::TextWordWrap, m_Label);
	}
}
Exemple #11
0
void CMenus::RenderLoading()
{
	static int64 LastLoadRender = 0;
	float Percent = m_LoadCurrent++/(float)m_LoadTotal;

	// make sure that we don't render for each little thing we load
	// because that will slow down loading if we have vsync
	if(time_get()-LastLoadRender < time_freq()/60)
		return;
		
	LastLoadRender = time_get();
	
	// need up date this here to get correct
	vec3 Rgb = HslToRgb(vec3(g_Config.m_UiColorHue/255.0f, g_Config.m_UiColorSat/255.0f, g_Config.m_UiColorLht/255.0f));
	ms_GuiColor = vec4(Rgb.r, Rgb.g, Rgb.b, g_Config.m_UiColorAlpha/255.0f);
	
    CUIRect Screen = *UI()->Screen();
	Graphics()->MapScreen(Screen.x, Screen.y, Screen.w, Screen.h);

	RenderBackground();

	float tw;

	float w = 700;
	float h = 200;
	float x = Screen.w/2-w/2;
	float y = Screen.h/2-h/2;

	Graphics()->BlendNormal();

	Graphics()->TextureSet(-1);
	Graphics()->QuadsBegin();
	Graphics()->SetColor(0,0,0,0.50f);
	RenderTools()->DrawRoundRect(x, y, w, h, 40.0f);
	Graphics()->QuadsEnd();


	const char *pCaption = Localize("Loading");

	tw = TextRender()->TextWidth(0, 48.0f, pCaption, -1);
	CUIRect r;
	r.x = x;
	r.y = y+20;
	r.w = w;
	r.h = h;
	UI()->DoLabel(&r, pCaption, 48.0f, 0, -1);

	Graphics()->TextureSet(-1);
	Graphics()->QuadsBegin();
	Graphics()->SetColor(1,1,1,0.75f);
	RenderTools()->DrawRoundRect(x+40, y+h-75, (w-80)*Percent, 25, 5.0f);
	Graphics()->QuadsEnd();

	Graphics()->Swap();
}
Exemple #12
0
void Scene::Render() const {
	Renderer::Instance().Clear(backr, backg, backb);
    Renderer::Instance().SetOrigin(GetCamera().GetX(), GetCamera().GetY());
	if ( backgroundImg ) Renderer::Instance().DrawImage(backgroundImg, 0, 0);
	Renderer::Instance().SetOrigin(0, 0);
	RenderBackground();
    Renderer::Instance().SetOrigin(GetCamera().GetX(), GetCamera().GetY());
	RenderAfterBackground();	
	for ( int i = 0; i < LAYER_COUNT; i++ ) {
		RenderSprites((Layer)i);
		RenderEmitters((Layer)i);
	}
}
Exemple #13
0
int RenderIMEWindow(PWINDOW_IME pIME){
	PWINDOW_SHOW_BOX pShowBox;

	pShowBox = (PWINDOW_SHOW_BOX)pIME->wBasic.wChildrenHead;

	RenderBackground(pIME->wBasic.rAbsolute);

	pShowBox -> szBuffer = pIME ->bShowHZ == 1 ? pIME ->szHz : pIME -> szKeys;
	pShowBox -> bUseHZK	 = (pIME ->bShowHZ == 1);

	if(pIME -> bShow){
	//rectangle(500,400,100,100);¿ÉÒÔÖ´Ðе½´Ë
		RenderBonder(pIME->wBasic.rAbsolute,pIME->wBasic.nOutLineWidth);
	}
	return pIME -> bShow;
	//return 0;
}
Exemple #14
0
int RenderRichEdit(PWINDOW_RICHEDIT pRichEdit)
{
	int nxShowArea,nyShowArea,nShowAreaWidth,nShowAreaHeight;

	SetColorFoucus((PWINDOW)pRichEdit);

	RenderBackground(pRichEdit->wBasic.rAbsolute);

	RenderBonder(pRichEdit->wBasic.rAbsolute,pRichEdit->wBasic.nOutLineWidth);

	DrawLineWithWidth(
		pRichEdit->wBasic.rAbsolute.nLeft,
		pRichEdit->wBasic.rAbsolute.nTop+pRichEdit->wBasic.nOutLineWidth+pRichEdit->nTitleHeight,
		pRichEdit->wBasic.rAbsolute.nWidth,
		pRichEdit->wBasic.nOutLineWidth
		);

	nxShowArea 		= pRichEdit->wBasic.rAbsolute.nLeft + pRichEdit->wBasic.nOutLineWidth;
	nyShowArea 		= pRichEdit->wBasic.rAbsolute.nTop  + pRichEdit->wBasic.nOutLineWidth * 2 + pRichEdit->nTitleHeight;
	nShowAreaWidth	= pRichEdit->wBasic.rAbsolute.nWidth - 2 * pRichEdit->wBasic.nOutLineWidth;
	nShowAreaHeight	= pRichEdit->wBasic.rAbsolute.nHeight- 3 * pRichEdit->wBasic.nOutLineWidth - pRichEdit->nTitleHeight;

	RenderStringInRectCenter(
		pRichEdit->szTitle,
		pRichEdit->nFrontSize,
		1,
		pRichEdit->wBasic.rAbsolute.nLeft+pRichEdit->wBasic.nOutLineWidth,
		pRichEdit->wBasic.rAbsolute.nTop +pRichEdit->wBasic.nOutLineWidth,
		pRichEdit->wBasic.rRectOffset.nWidth - 2*pRichEdit->wBasic.nOutLineWidth,
		pRichEdit->nTitleHeight
		);

	RenderStringInRectNormal(
		pRichEdit -> szData,
		pRichEdit -> nFrontSize,
		1,
		nxShowArea,
		nyShowArea,
		nShowAreaWidth,
		nShowAreaHeight
		);

	return 1;
}
Exemple #15
0
void WidgetBase::Render()
{
	Vec2 worldPos = GetWorldPosition();

	float opacity = GetOpacity();

	RGBA backgroundColor;
	GetPropertyForCurrentState("color", backgroundColor);
	backgroundColor.a() = static_cast<unsigned char>(backgroundColor.a() * opacity);

	Vec2 size;
	GetPropertyForCurrentState("size", size);

	float borderSize;
	GetPropertyForCurrentState("border size", borderSize);

	RenderBackground(worldPos, size, backgroundColor);
	RenderOutline(worldPos, size, borderSize);
}
Exemple #16
0
int RenderButton(PWINDOW_BUTTON pButton)
{
	SetColorFoucus((PWINDOW)pButton);

	RenderBackground(pButton->wBasic.rAbsolute);

	RenderBonder(pButton->wBasic.rAbsolute,pButton->wBasic.nOutLineWidth);

	RenderStringInRectCenter(
		pButton->szTitle,
		pButton->nFrontSize,
		1,
		pButton->wBasic.rAbsolute.nLeft+pButton->wBasic.nOutLineWidth,
		pButton->wBasic.rAbsolute.nTop +pButton->wBasic.nOutLineWidth,
		pButton->wBasic.rRectOffset.nWidth - 2*pButton->wBasic.nOutLineWidth,
		pButton->wBasic.rRectOffset.nHeight - 2*pButton->wBasic.nOutLineWidth
		);

	return 1;
}
Exemple #17
0
// ----------------------------------------------------------------------------
//  Name: Render
//
//  Desc: Renders the scene.
// ----------------------------------------------------------------------------
HRESULT CGame::Render()
{
	// Clear the backbuffer.
	m_pDevice->Clear( 0, NULL, (D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER), 0, 1.0f, 0 );

	// Attempt to begin the scene.
	if( SUCCEEDED( m_pDevice->BeginScene() ) )
	{
		// See RenderBackground function below.
		RenderBackground();

		// What state are we in? Render appropriately.
		switch( m_CurrentState )
		{
		case TitleScreen:
			RenderTitleScreen();
			break;

		case GameScreen:
			RenderGameScreen();
			break;

		default:
			break;
		}

		// We are done rendering, end the scene.
		m_pDevice->EndScene();
	}
	else
	{
		DbgPrint( "For some reason we didn't succeed in beginning the scene..." );
	}

	// Present the backbuffer to the display.
	m_pDevice->Present( NULL, NULL, NULL, NULL );

	return D3D_OK;
}
void UpdateGraphics(void)
{
	RenderBackground();

	RenderPixel(401, 300, 0x0000000F);
	RenderPixel(402, 300, 0x0000000F);
	RenderPixel(403, 300, 0x0000000F);
	RenderPixel(404, 300, 0x0000000F);

	RenderPixel(401, 301, 0x0000000F);
	RenderPixel(402, 301, 0x0000000F);
	RenderPixel(403, 301, 0x0000000F);
	RenderPixel(404, 301, 0x0000000F);

	RenderPixel(401, 302, 0x0000000F);
	RenderPixel(402, 302, 0x0000000F);
	RenderPixel(403, 302, 0x0000000F);
	RenderPixel(404, 302, 0x0000000F);

	RenderPixel(401, 303, 0x0000000F);
	RenderPixel(402, 303, 0x0000000F);
	RenderPixel(403, 303, 0x0000000F);
	RenderPixel(404, 303, 0x0000000F);	
}
//-----------------------------------------------------------------------------
// The following function displays the current time. 
//-----------------------------------------------------------------------------
void MapBackground::Render()
{
	RenderBackground();
}
void StateCredits::Draw(StateHandler* stateHandler)
{
	RenderBackground();
	RenderNames();
	theView->SwapBuffers();
}
Exemple #21
0
void Game::Loop(){

srand (time(NULL));

player = new Player(renderer,WIDTH/2 ,HEIGHT/2,1,PLAYER,&information);
gameObjects.push_back(player);


for(int i=1;i<=5;i++)
{
        int AsteroidX = rand() % 600 + 150;
        int AsteroidY = rand() % 300 + 150;
        if(player->CheckIfCanSpawnAsteroid(AsteroidX,AsteroidY))
            {
                asteroid = new Asteroids(renderer,AsteroidX,AsteroidY,&information);
                gameObjects.push_back(asteroid);
            }
        else i--;
}


while(!quit && mainEvent.type != SDL_QUIT)
    {
        timer = SDL_GetTicks();
        CheckIfGameIsEnded();



        while(SDL_PollEvent(&mainEvent))
        {
            if(mainEvent.type == SDL_KEYDOWN)
            {
                    if(mainEvent.key.keysym.sym == SDLK_q)
                    {
                        //ADDING NEW ASTEROIDS
                        //asteroid = new Asteroids(renderer,rand() % 600 + 150 ,rand() % 300 + 150,&information);
                        //gameObjects.push_back(asteroid);


                    }

                    if(mainEvent.key.keysym.sym == SDLK_SPACE)
                    {
                        //ADDING NEW ASTEROIDS
                         bullet = new Bullet(renderer,player->points[1].x,player->points[1].y,5,BULLET,player->GetAngle(),&information);
                        gameObjects.push_back(bullet);

                    }
            }

        }

        SpawnAsteroids();

/////////////////COLLISION DETECTION ////////////

        CollisionDetection();

///////////////////////////////////////////////////////

        //UPDATE GAMEOBJECTS
        for(int i = 0; i < gameObjects.size(); i++){
        gameObjects[i]->Update();
        }



////////////////////////////////////////////////////////

        //DELETE DEAD OBJECTS
        DeleteUnusedOrDeadObjects();

//////////////////////////////////////////////////////




//////////////////////////////////////////////////////

        //DRAW Background
       RenderBackground();

//////////////////////////////////////////////////////



       //DRAW things



        ///////RENDER

        for(int i = 0; i < gameObjects.size(); i++){
        gameObjects[i]->Render();
        }

        ShowScore(information);
////////////////////////////////////////////////////////



///////////////FPS//////////////
        SDL_RenderPresent(renderer);
        if(1000/FPS > SDL_GetTicks() - timer)
        SDL_Delay(1000/FPS - (SDL_GetTicks() - timer));

////////////////////////////////////////////////////////


    }

}
Exemple #22
0
int CMenus::Render()
{
    CUIRect Screen = *UI()->Screen();
	Graphics()->MapScreen(Screen.x, Screen.y, Screen.w, Screen.h);

	static bool s_First = true;
	if(s_First)
	{
		if(g_Config.m_UiPage == PAGE_INTERNET)
			ServerBrowser()->Refresh(IServerBrowser::TYPE_INTERNET);
		else if(g_Config.m_UiPage == PAGE_LAN)
			ServerBrowser()->Refresh(IServerBrowser::TYPE_LAN);
		else if(g_Config.m_UiPage == PAGE_FAVORITES)
			ServerBrowser()->Refresh(IServerBrowser::TYPE_FAVORITES);
		s_First = false;
	}
	
	if(Client()->State() == IClient::STATE_ONLINE)
	{
		ms_ColorTabbarInactive = ms_ColorTabbarInactiveIngame;
		ms_ColorTabbarActive = ms_ColorTabbarActiveIngame;
	}
	else
	{
		RenderBackground();
		ms_ColorTabbarInactive = ms_ColorTabbarInactiveOutgame;
		ms_ColorTabbarActive = ms_ColorTabbarActiveOutgame;
	}
	
	CUIRect TabBar;
	CUIRect MainView;

	// some margin around the screen
	Screen.Margin(10.0f, &Screen);
	
	if(m_Popup == POPUP_NONE)
	{
		// do tab bar
		Screen.HSplitTop(24.0f, &TabBar, &MainView);
		TabBar.VMargin(20.0f, &TabBar);
		RenderMenubar(TabBar);
		
		// news is not implemented yet
		if(g_Config.m_UiPage <= PAGE_NEWS || g_Config.m_UiPage > PAGE_SETTINGS || (Client()->State() == IClient::STATE_OFFLINE && g_Config.m_UiPage >= PAGE_GAME && g_Config.m_UiPage <= PAGE_CALLVOTE))
		{
			ServerBrowser()->Refresh(IServerBrowser::TYPE_INTERNET);
			g_Config.m_UiPage = PAGE_INTERNET;
		}
		
		// render current page
		if(Client()->State() != IClient::STATE_OFFLINE)
		{
			if(m_GamePage == PAGE_GAME)
				RenderGame(MainView);
			else if(m_GamePage == PAGE_SERVER_INFO)
				RenderServerInfo(MainView);
			else if(m_GamePage == PAGE_CALLVOTE)
				RenderServerControl(MainView);
			else if(m_GamePage == PAGE_SETTINGS)
				RenderSettings(MainView);
		}
		else if(g_Config.m_UiPage == PAGE_NEWS)
			RenderNews(MainView);
		else if(g_Config.m_UiPage == PAGE_INTERNET)
			RenderServerbrowser(MainView);
		else if(g_Config.m_UiPage == PAGE_LAN)
			RenderServerbrowser(MainView);
		else if(g_Config.m_UiPage == PAGE_DEMOS)
			RenderDemoList(MainView);
		else if(g_Config.m_UiPage == PAGE_FAVORITES)
			RenderServerbrowser(MainView);
		else if(g_Config.m_UiPage == PAGE_SETTINGS)
			RenderSettings(MainView);
	}
	else
	{
		// make sure that other windows doesn't do anything funnay!
		//UI()->SetHotItem(0);
		//UI()->SetActiveItem(0);
		char aBuf[128];
		const char *pTitle = "";
		const char *pExtraText = "";
		const char *pButtonText = "";
		int ExtraAlign = 0;
		
		if(m_Popup == POPUP_MESSAGE)
		{
			pTitle = m_aMessageTopic;
			pExtraText = m_aMessageBody;
			pButtonText = m_aMessageButton;
		}
		else if(m_Popup == POPUP_CONNECTING)
		{
			pTitle = Localize("Connecting to");
			pExtraText = g_Config.m_UiServerAddress;  // TODO: query the client about the address
			pButtonText = Localize("Abort");
			if(Client()->MapDownloadTotalsize() > 0)
			{
				pTitle = Localize("Downloading map");
				str_format(aBuf, sizeof(aBuf), "%d/%d KiB", Client()->MapDownloadAmount()/1024, Client()->MapDownloadTotalsize()/1024);
				pExtraText = aBuf;
			}
		}
		else if(m_Popup == POPUP_DISCONNECTED)
		{
			pTitle = Localize("Disconnected");
			pExtraText = Client()->ErrorString();
			pButtonText = Localize("Ok");
			ExtraAlign = -1;
		}
		else if(m_Popup == POPUP_PURE)
		{
			pTitle = Localize("Disconnected");
			pExtraText = Localize("The server is running a non-standard tuning on a pure game type.");
			pButtonText = Localize("Ok");
			ExtraAlign = -1;
		}
		else if(m_Popup == POPUP_PASSWORD)
		{
			pTitle = Localize("Password incorrect");
			pExtraText = Client()->ErrorString();
			pButtonText = Localize("Try again");
		}
		else if(m_Popup == POPUP_QUIT)
		{
			pTitle = Localize("Quit");
			pExtraText = Localize("Are you sure that you want to quit?");
		}
		else if(m_Popup == POPUP_FIRST_LAUNCH)
		{
			pTitle = Localize("Welcome to Teeworlds");
			pExtraText = Localize("As this is the first time you launch the game, please enter your nick name below. It's recommended that you check the settings to adjust them to your liking before joining a server.");
			pButtonText = Localize("Ok");
			ExtraAlign = -1;
		}
		
		CUIRect Box, Part;
		Box = Screen;
		Box.VMargin(150.0f, &Box);
		Box.HMargin(150.0f, &Box);
		
		// render the box
		RenderTools()->DrawUIRect(&Box, vec4(0,0,0,0.5f), CUI::CORNER_ALL, 15.0f);
		 
		Box.HSplitTop(20.f, &Part, &Box);
		Box.HSplitTop(24.f, &Part, &Box);
		UI()->DoLabel(&Part, pTitle, 24.f, 0);
		Box.HSplitTop(20.f, &Part, &Box);
		Box.HSplitTop(24.f, &Part, &Box);
		Part.VMargin(20.f, &Part);
		
		if(ExtraAlign == -1)
			UI()->DoLabel(&Part, pExtraText, 20.f, -1, (int)Part.w);
		else
			UI()->DoLabel(&Part, pExtraText, 20.f, 0, -1);

		if(m_Popup == POPUP_QUIT)
		{
			CUIRect Yes, No;
			Box.HSplitBottom(20.f, &Box, &Part);
			Box.HSplitBottom(24.f, &Box, &Part);
			Part.VMargin(80.0f, &Part);
			
			Part.VSplitMid(&No, &Yes);
			
			Yes.VMargin(20.0f, &Yes);
			No.VMargin(20.0f, &No);

			static int s_ButtonAbort = 0;
			if(DoButton_Menu(&s_ButtonAbort, Localize("No"), 0, &No) || m_EscapePressed)
				m_Popup = POPUP_NONE;

			static int s_ButtonTryAgain = 0;
			if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || m_EnterPressed)
				Client()->Quit();
		}
		else if(m_Popup == POPUP_PASSWORD)
		{
			CUIRect Label, TextBox, TryAgain, Abort;
			
			Box.HSplitBottom(20.f, &Box, &Part);
			Box.HSplitBottom(24.f, &Box, &Part);
			Part.VMargin(80.0f, &Part);
			
			Part.VSplitMid(&Abort, &TryAgain);
			
			TryAgain.VMargin(20.0f, &TryAgain);
			Abort.VMargin(20.0f, &Abort);
			
			static int s_ButtonAbort = 0;
			if(DoButton_Menu(&s_ButtonAbort, Localize("Abort"), 0, &Abort) || m_EscapePressed)
				m_Popup = POPUP_NONE;

			static int s_ButtonTryAgain = 0;
			if(DoButton_Menu(&s_ButtonTryAgain, Localize("Try again"), 0, &TryAgain) || m_EnterPressed)
			{
				Client()->Connect(g_Config.m_UiServerAddress);
			}
			
			Box.HSplitBottom(60.f, &Box, &Part);
			Box.HSplitBottom(24.f, &Box, &Part);
			
			Part.VSplitLeft(60.0f, 0, &Label);
			Label.VSplitLeft(100.0f, 0, &TextBox);
			TextBox.VSplitLeft(20.0f, 0, &TextBox);
			TextBox.VSplitRight(60.0f, &TextBox, 0);
			UI()->DoLabel(&Label, Localize("Password"), 18.0f, -1);
			static float Offset = 0.0f;
			DoEditBox(&g_Config.m_Password, &TextBox, g_Config.m_Password, sizeof(g_Config.m_Password), 12.0f, &Offset, true);
		}
		else if(m_Popup == POPUP_FIRST_LAUNCH)
		{
			CUIRect Label, TextBox;
			
			Box.HSplitBottom(20.f, &Box, &Part);
			Box.HSplitBottom(24.f, &Box, &Part);
			Part.VMargin(80.0f, &Part);
			
			static int s_EnterButton = 0;
			if(DoButton_Menu(&s_EnterButton, Localize("Enter"), 0, &Part) || m_EnterPressed)
				m_Popup = POPUP_NONE;
			
			Box.HSplitBottom(40.f, &Box, &Part);
			Box.HSplitBottom(24.f, &Box, &Part);
			
			Part.VSplitLeft(60.0f, 0, &Label);
			Label.VSplitLeft(100.0f, 0, &TextBox);
			TextBox.VSplitLeft(20.0f, 0, &TextBox);
			TextBox.VSplitRight(60.0f, &TextBox, 0);
			UI()->DoLabel(&Label, Localize("Nickname"), 18.0f, -1);
			static float Offset = 0.0f;
			DoEditBox(&g_Config.m_PlayerName, &TextBox, g_Config.m_PlayerName, sizeof(g_Config.m_PlayerName), 12.0f, &Offset);
		}
		else
		{
			Box.HSplitBottom(20.f, &Box, &Part);
			Box.HSplitBottom(24.f, &Box, &Part);
			Part.VMargin(120.0f, &Part);

			static int s_Button = 0;
			if(DoButton_Menu(&s_Button, pButtonText, 0, &Part) || m_EscapePressed || m_EnterPressed)
			{
				if(m_Popup == POPUP_CONNECTING)
					Client()->Disconnect();
				m_Popup = POPUP_NONE;
			}
		}
	}
	
	return 0;
}
Exemple #23
0
int CMenus::Render()
{
    CUIRect Screen = *UI()->Screen();
	Graphics()->MapScreen(Screen.x, Screen.y, Screen.w, Screen.h);

	static bool s_First = true;
	if(s_First)
	{
		if(g_Config.m_UiPage == PAGE_INTERNET)
			ServerBrowser()->Refresh(IServerBrowser::TYPE_INTERNET);
		else if(g_Config.m_UiPage == PAGE_LAN)
			ServerBrowser()->Refresh(IServerBrowser::TYPE_LAN);
		else if(g_Config.m_UiPage == PAGE_FAVORITES)
			ServerBrowser()->Refresh(IServerBrowser::TYPE_FAVORITES);
		s_First = false;
	}
	
	if(Client()->State() == IClient::STATE_ONLINE)
	{
		ms_ColorTabbarInactive = ms_ColorTabbarInactiveIngame;
		ms_ColorTabbarActive = ms_ColorTabbarActiveIngame;
	}
	else
	{
		RenderBackground();
		ms_ColorTabbarInactive = ms_ColorTabbarInactiveOutgame;
		ms_ColorTabbarActive = ms_ColorTabbarActiveOutgame;
	}
	
	CUIRect TabBar;
	CUIRect MainView;

	// some margin around the screen
	Screen.Margin(10.0f, &Screen);
	
	static bool s_SoundCheck = false;
	if(!s_SoundCheck && m_Popup == POPUP_NONE)
	{
		if(Client()->SoundInitFailed())
			m_Popup = POPUP_SOUNDERROR;
		s_SoundCheck = true;
	}

	if(m_Popup == POPUP_NONE)
	{
		// do tab bar
		Screen.HSplitTop(24.0f, &TabBar, &MainView);
		TabBar.VMargin(20.0f, &TabBar);
		RenderMenubar(TabBar);
		
		// news is not implemented yet
		if(g_Config.m_UiPage <= PAGE_NEWS || g_Config.m_UiPage > PAGE_SETTINGS || (Client()->State() == IClient::STATE_OFFLINE && g_Config.m_UiPage >= PAGE_GAME && g_Config.m_UiPage <= PAGE_CALLVOTE))
		{
			ServerBrowser()->Refresh(IServerBrowser::TYPE_INTERNET);
			g_Config.m_UiPage = PAGE_INTERNET;
		}
		
		// render current page
		if(Client()->State() != IClient::STATE_OFFLINE)
		{
			if(m_GamePage == PAGE_GAME)
				RenderGame(MainView);
			else if(m_GamePage == PAGE_PLAYERS)
				RenderPlayers(MainView);
			else if(m_GamePage == PAGE_SERVER_INFO)
				RenderServerInfo(MainView);
			else if(m_GamePage == PAGE_CALLVOTE)
				RenderServerControl(MainView);
			else if(m_GamePage == PAGE_SETTINGS)
				RenderSettings(MainView);
		}
		else if(g_Config.m_UiPage == PAGE_NEWS)
			RenderNews(MainView);
		else if(g_Config.m_UiPage == PAGE_INTERNET)
			RenderServerbrowser(MainView);
		else if(g_Config.m_UiPage == PAGE_LAN)
			RenderServerbrowser(MainView);
		else if(g_Config.m_UiPage == PAGE_DEMOS)
			RenderDemoList(MainView);
		else if(g_Config.m_UiPage == PAGE_FAVORITES)
			RenderServerbrowser(MainView);
		else if(g_Config.m_UiPage == PAGE_SETTINGS)
			RenderSettings(MainView);
	}
	else
	{
		// make sure that other windows doesn't do anything funnay!
		//UI()->SetHotItem(0);
		//UI()->SetActiveItem(0);
		char aBuf[128];
		const char *pTitle = "";
		const char *pExtraText = "";
		const char *pButtonText = "";
		int ExtraAlign = 0;
		
		if(m_Popup == POPUP_MESSAGE)
		{
			pTitle = m_aMessageTopic;
			pExtraText = m_aMessageBody;
			pButtonText = m_aMessageButton;
		}
		else if(m_Popup == POPUP_CONNECTING)
		{
			pTitle = Localize("Connecting to");
			pExtraText = g_Config.m_UiServerAddress;  // TODO: query the client about the address
			pButtonText = Localize("Abort");
			if(Client()->MapDownloadTotalsize() > 0)
			{
				pTitle = Localize("Downloading map");
				pExtraText = "";
			}
		}
		else if(m_Popup == POPUP_DISCONNECTED)
		{
			pTitle = Localize("Disconnected");
			pExtraText = Client()->ErrorString();
			pButtonText = Localize("Ok");
			ExtraAlign = -1;
		}
		else if(m_Popup == POPUP_PURE)
		{
			pTitle = Localize("Disconnected");
			pExtraText = Localize("The server is running a non-standard tuning on a pure game type.");
			pButtonText = Localize("Ok");
			ExtraAlign = -1;
		}
		else if(m_Popup == POPUP_DELETE_DEMO)
		{
			pTitle = Localize("Delete demo");
			pExtraText = Localize("Are you sure that you want to delete the demo?");
			ExtraAlign = -1;
		}
		else if(m_Popup == POPUP_RENAME_DEMO)
		{
			pTitle = Localize("Rename demo");
			pExtraText = "";
			ExtraAlign = -1;
		}
		else if(m_Popup == POPUP_REMOVE_FRIEND)
		{
			pTitle = Localize("Remove friend");
			pExtraText = Localize("Are you sure that you want to remove the player from your friends list?");
			ExtraAlign = -1;
		}
		else if(m_Popup == POPUP_SOUNDERROR)
		{
			pTitle = Localize("Sound error");
			pExtraText = Localize("The audio device couldn't be initialised.");
			pButtonText = Localize("Ok");
			ExtraAlign = -1;
		}
		else if(m_Popup == POPUP_PASSWORD)
		{
			pTitle = Localize("Password incorrect");
			pExtraText = "";
			pButtonText = Localize("Try again");
		}
		else if(m_Popup == POPUP_QUIT)
		{
			pTitle = Localize("Quit");
			pExtraText = Localize("Are you sure that you want to quit?");
			ExtraAlign = -1;
		}
		else if(m_Popup == POPUP_FIRST_LAUNCH)
		{
			pTitle = Localize("Welcome to Teeworlds");
			pExtraText = Localize("As this is the first time you launch the game, please enter your nick name below. It's recommended that you check the settings to adjust them to your liking before joining a server.");
			pButtonText = Localize("Ok");
			ExtraAlign = -1;
		}
		
		CUIRect Box, Part;
		Box = Screen;
		Box.VMargin(150.0f/UI()->Scale(), &Box);
		Box.HMargin(150.0f/UI()->Scale(), &Box);
		
		// render the box
		RenderTools()->DrawUIRect(&Box, vec4(0,0,0,0.5f), CUI::CORNER_ALL, 15.0f);
		 
		Box.HSplitTop(20.f/UI()->Scale(), &Part, &Box);
		Box.HSplitTop(24.f/UI()->Scale(), &Part, &Box);
		UI()->DoLabelScaled(&Part, pTitle, 24.f, 0);
		Box.HSplitTop(20.f/UI()->Scale(), &Part, &Box);
		Box.HSplitTop(24.f/UI()->Scale(), &Part, &Box);
		Part.VMargin(20.f/UI()->Scale(), &Part);
		
		if(ExtraAlign == -1)
			UI()->DoLabelScaled(&Part, pExtraText, 20.f, -1, (int)Part.w);
		else
			UI()->DoLabelScaled(&Part, pExtraText, 20.f, 0, -1);

		if(m_Popup == POPUP_QUIT)
		{
			CUIRect Yes, No;
			Box.HSplitBottom(20.f, &Box, &Part);
			Box.HSplitBottom(24.f, &Box, &Part);

			// additional info
			Box.HSplitTop(10.0f, 0, &Box);
			Box.VMargin(20.f/UI()->Scale(), &Box);
			if(m_pClient->Editor()->HasUnsavedData())
			{
				char aBuf[128];
				str_format(aBuf, sizeof(aBuf), "%s\n%s", Localize("There's an unsaved map in the editor, you might want to save it before you quit the game."), Localize("Quit anyway?"));
				UI()->DoLabelScaled(&Box, aBuf, 20.f, -1, Part.w-20.0f);
			}

			// buttons
			Part.VMargin(80.0f, &Part);
			Part.VSplitMid(&No, &Yes);
			Yes.VMargin(20.0f, &Yes);
			No.VMargin(20.0f, &No);

			static int s_ButtonAbort = 0;
			if(DoButton_Menu(&s_ButtonAbort, Localize("No"), 0, &No) || m_EscapePressed)
				m_Popup = POPUP_NONE;

			static int s_ButtonTryAgain = 0;
			if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || m_EnterPressed)
				Client()->Quit();
		}
		else if(m_Popup == POPUP_PASSWORD)
		{
			CUIRect Label, TextBox, TryAgain, Abort;
			
			Box.HSplitBottom(20.f, &Box, &Part);
			Box.HSplitBottom(24.f, &Box, &Part);
			Part.VMargin(80.0f, &Part);
			
			Part.VSplitMid(&Abort, &TryAgain);
			
			TryAgain.VMargin(20.0f, &TryAgain);
			Abort.VMargin(20.0f, &Abort);
			
			static int s_ButtonAbort = 0;
			if(DoButton_Menu(&s_ButtonAbort, Localize("Abort"), 0, &Abort) || m_EscapePressed)
				m_Popup = POPUP_NONE;

			static int s_ButtonTryAgain = 0;
			if(DoButton_Menu(&s_ButtonTryAgain, Localize("Try again"), 0, &TryAgain) || m_EnterPressed)
			{
				Client()->Connect(g_Config.m_UiServerAddress);
			}
			
			Box.HSplitBottom(60.f, &Box, &Part);
			Box.HSplitBottom(24.f, &Box, &Part);
			
			Part.VSplitLeft(60.0f, 0, &Label);
			Label.VSplitLeft(100.0f, 0, &TextBox);
			TextBox.VSplitLeft(20.0f, 0, &TextBox);
			TextBox.VSplitRight(60.0f, &TextBox, 0);
			UI()->DoLabel(&Label, Localize("Password"), 18.0f, -1);
			static float Offset = 0.0f;
			DoEditBox(&g_Config.m_Password, &TextBox, g_Config.m_Password, sizeof(g_Config.m_Password), 12.0f, &Offset, true);
		}
		else if(m_Popup == POPUP_CONNECTING)
		{
			Box = Screen;
			Box.VMargin(150.0f, &Box);
			Box.HMargin(150.0f, &Box);
			Box.HSplitBottom(20.f, &Box, &Part);
			Box.HSplitBottom(24.f, &Box, &Part);
			Part.VMargin(120.0f, &Part);

			static int s_Button = 0;
			if(DoButton_Menu(&s_Button, pButtonText, 0, &Part) || m_EscapePressed || m_EnterPressed)
			{
				Client()->Disconnect();
				m_Popup = POPUP_NONE;
			}

			if(Client()->MapDownloadTotalsize() > 0)
			{
				int64 Now = time_get();
				if(Now-m_DownloadLastCheckTime >= time_freq())
				{
					if(m_DownloadLastCheckSize > Client()->MapDownloadAmount())
					{
						// map downloaded restarted
						m_DownloadLastCheckSize = 0;
					}

					// update download speed
					float Diff = (Client()->MapDownloadAmount()-m_DownloadLastCheckSize)/1024.0f;
					m_DownloadSpeed = absolute((m_DownloadSpeed*(1.0f-(1.0f/m_DownloadSpeed))) + (Diff*(1.0f/m_DownloadSpeed)));
					m_DownloadLastCheckTime = Now;
					m_DownloadLastCheckSize = Client()->MapDownloadAmount();
				}

				Box.HSplitTop(64.f, 0, &Box);
				Box.HSplitTop(24.f, &Part, &Box);
				str_format(aBuf, sizeof(aBuf), "%d/%d KiB (%.1f KiB/s)", Client()->MapDownloadAmount()/1024, Client()->MapDownloadTotalsize()/1024,	m_DownloadSpeed);
				UI()->DoLabel(&Part, aBuf, 20.f, 0, -1);
				
				// time left
				const char *pTimeLeftString;
				int TimeLeft = (Client()->MapDownloadTotalsize()-Client()->MapDownloadAmount())/(m_DownloadSpeed*1024)+1;
				if(TimeLeft >= 60)
				{
					TimeLeft /= 60;
					pTimeLeftString = TimeLeft == 1 ? Localize("%i minute left") : Localize("%i minutes left");
				}
				else
					pTimeLeftString = TimeLeft == 1 ? Localize("%i second left") : Localize("%i seconds left");
				Box.HSplitTop(20.f, 0, &Box);
				Box.HSplitTop(24.f, &Part, &Box);
				str_format(aBuf, sizeof(aBuf), pTimeLeftString, TimeLeft);
				UI()->DoLabel(&Part, aBuf, 20.f, 0, -1);

				// progress bar
				Box.HSplitTop(20.f, 0, &Box);
				Box.HSplitTop(24.f, &Part, &Box);
				Part.VMargin(40.0f, &Part);
				RenderTools()->DrawUIRect(&Part, vec4(1.0f, 1.0f, 1.0f, 0.25f), CUI::CORNER_ALL, 5.0f);
				Part.w = max(10.0f, (Part.w*Client()->MapDownloadAmount())/Client()->MapDownloadTotalsize());
				RenderTools()->DrawUIRect(&Part, vec4(1.0f, 1.0f, 1.0f, 0.5f), CUI::CORNER_ALL, 5.0f);
			}
		}
		else if(m_Popup == POPUP_LANGUAGE)
		{
			Box = Screen;
			Box.VMargin(150.0f, &Box);
			Box.HMargin(150.0f, &Box);
			Box.HSplitTop(20.f, &Part, &Box);
			Box.HSplitBottom(20.f, &Box, &Part);
			Box.HSplitBottom(24.f, &Box, &Part);
			Box.HSplitBottom(20.f, &Box, 0);
			Box.VMargin(20.0f, &Box);
			RenderLanguageSelection(Box);
			Part.VMargin(120.0f, &Part);

			static int s_Button = 0;
			if(DoButton_Menu(&s_Button, Localize("Ok"), 0, &Part) || m_EscapePressed || m_EnterPressed)
				m_Popup = POPUP_FIRST_LAUNCH;
		}
		else if(m_Popup == POPUP_DELETE_DEMO)
		{
			CUIRect Yes, No;
			Box.HSplitBottom(20.f, &Box, &Part);
			Box.HSplitBottom(24.f, &Box, &Part);
			Part.VMargin(80.0f, &Part);
			
			Part.VSplitMid(&No, &Yes);
			
			Yes.VMargin(20.0f, &Yes);
			No.VMargin(20.0f, &No);

			static int s_ButtonAbort = 0;
			if(DoButton_Menu(&s_ButtonAbort, Localize("No"), 0, &No) || m_EscapePressed)
				m_Popup = POPUP_NONE;

			static int s_ButtonTryAgain = 0;
			if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || m_EnterPressed)
			{
				m_Popup = POPUP_NONE;
				// delete demo
				if(m_DemolistSelectedIndex >= 0 && !m_DemolistSelectedIsDir)
				{
					char aBuf[512];
					str_format(aBuf, sizeof(aBuf), "%s/%s", m_aCurrentDemoFolder, m_lDemos[m_DemolistSelectedIndex].m_aFilename);
					if(Storage()->RemoveFile(aBuf, m_lDemos[m_DemolistSelectedIndex].m_StorageType))
					{
						DemolistPopulate();
						DemolistOnUpdate(false);
					}
					else
						PopupMessage(Localize("Error"), Localize("Unable to delete the demo"), Localize("Ok"));
				}
			}
		}
		else if(m_Popup == POPUP_RENAME_DEMO)
		{
			CUIRect Label, TextBox, Ok, Abort;
			
			Box.HSplitBottom(20.f, &Box, &Part);
			Box.HSplitBottom(24.f, &Box, &Part);
			Part.VMargin(80.0f, &Part);
			
			Part.VSplitMid(&Abort, &Ok);
			
			Ok.VMargin(20.0f, &Ok);
			Abort.VMargin(20.0f, &Abort);
			
			static int s_ButtonAbort = 0;
			if(DoButton_Menu(&s_ButtonAbort, Localize("Abort"), 0, &Abort) || m_EscapePressed)
				m_Popup = POPUP_NONE;

			static int s_ButtonOk = 0;
			if(DoButton_Menu(&s_ButtonOk, Localize("Ok"), 0, &Ok) || m_EnterPressed)
			{
				m_Popup = POPUP_NONE;
				// rename demo
				if(m_DemolistSelectedIndex >= 0 && !m_DemolistSelectedIsDir)
				{
					char aBufOld[512];
					str_format(aBufOld, sizeof(aBufOld), "%s/%s", m_aCurrentDemoFolder, m_lDemos[m_DemolistSelectedIndex].m_aFilename);
					int Length = str_length(m_aCurrentDemoFile);
					char aBufNew[512];
					if(Length <= 4 || m_aCurrentDemoFile[Length-5] != '.' || str_comp_nocase(m_aCurrentDemoFile+Length-4, "demo"))
						str_format(aBufNew, sizeof(aBufNew), "%s/%s.demo", m_aCurrentDemoFolder, m_aCurrentDemoFile);
					else
						str_format(aBufNew, sizeof(aBufNew), "%s/%s", m_aCurrentDemoFolder, m_aCurrentDemoFile);
					if(Storage()->RenameFile(aBufOld, aBufNew, m_lDemos[m_DemolistSelectedIndex].m_StorageType))
					{
						DemolistPopulate();
						DemolistOnUpdate(false);
					}
					else
						PopupMessage(Localize("Error"), Localize("Unable to rename the demo"), Localize("Ok"));
				}
			}
			
			Box.HSplitBottom(60.f, &Box, &Part);
			Box.HSplitBottom(24.f, &Box, &Part);
			
			Part.VSplitLeft(60.0f, 0, &Label);
			Label.VSplitLeft(120.0f, 0, &TextBox);
			TextBox.VSplitLeft(20.0f, 0, &TextBox);
			TextBox.VSplitRight(60.0f, &TextBox, 0);
			UI()->DoLabel(&Label, Localize("New name:"), 18.0f, -1);
			static float Offset = 0.0f;
			DoEditBox(&Offset, &TextBox, m_aCurrentDemoFile, sizeof(m_aCurrentDemoFile), 12.0f, &Offset);
		}
		else if(m_Popup == POPUP_REMOVE_FRIEND)
		{
			CUIRect Yes, No;
			Box.HSplitBottom(20.f, &Box, &Part);
			Box.HSplitBottom(24.f, &Box, &Part);
			Part.VMargin(80.0f, &Part);
			
			Part.VSplitMid(&No, &Yes);
			
			Yes.VMargin(20.0f, &Yes);
			No.VMargin(20.0f, &No);

			static int s_ButtonAbort = 0;
			if(DoButton_Menu(&s_ButtonAbort, Localize("No"), 0, &No) || m_EscapePressed)
				m_Popup = POPUP_NONE;

			static int s_ButtonTryAgain = 0;
			if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || m_EnterPressed)
			{
				m_Popup = POPUP_NONE;
				// remove friend
				if(m_FriendlistSelectedIndex >= 0)
				{
					m_pClient->Friends()->RemoveFriend(m_FriendlistSelectedIndex);
					Client()->ServerBrowserUpdate();
				}
			}
		}
		else if(m_Popup == POPUP_FIRST_LAUNCH)
		{
			CUIRect Label, TextBox;
			
			Box.HSplitBottom(20.f, &Box, &Part);
			Box.HSplitBottom(24.f, &Box, &Part);
			Part.VMargin(80.0f, &Part);
			
			static int s_EnterButton = 0;
			if(DoButton_Menu(&s_EnterButton, Localize("Enter"), 0, &Part) || m_EnterPressed)
				m_Popup = POPUP_NONE;
			
			Box.HSplitBottom(40.f, &Box, &Part);
			Box.HSplitBottom(24.f, &Box, &Part);
			
			Part.VSplitLeft(60.0f, 0, &Label);
			Label.VSplitLeft(100.0f, 0, &TextBox);
			TextBox.VSplitLeft(20.0f, 0, &TextBox);
			TextBox.VSplitRight(60.0f, &TextBox, 0);
			UI()->DoLabel(&Label, Localize("Nickname"), 18.0f, -1);
			static float Offset = 0.0f;
			DoEditBox(&g_Config.m_PlayerName, &TextBox, g_Config.m_PlayerName, sizeof(g_Config.m_PlayerName), 12.0f, &Offset);
		}
		else
		{
			Box.HSplitBottom(20.f, &Box, &Part);
			Box.HSplitBottom(24.f, &Box, &Part);
			Part.VMargin(120.0f, &Part);

			static int s_Button = 0;
			if(DoButton_Menu(&s_Button, pButtonText, 0, &Part) || m_EscapePressed || m_EnterPressed)
				m_Popup = POPUP_NONE;
		}
	}
	
	return 0;
}
Exemple #24
0
void DeckMenu::Render()
{
    JRenderer * renderer = JRenderer::GetInstance();
    float height = mHeight;

    if (!menuInitialized)
    {
        initMenuItems();
        stars->Fire();
        timeOpen = 0;
        menuInitialized = true;
    }
    
    if (timeOpen < 1) height *= timeOpen > 0 ? timeOpen : -timeOpen;
    
    for (int i = startId; i < startId + maxItems; i++)
    {
        if (i > mCount - 1) break;        
        DeckMenuItem *currentMenuItem = static_cast<DeckMenuItem*> (mObjects[i]);
        if (currentMenuItem->getY() - DeckMenuConst::kLineHeight * startId < mY + height - DeckMenuConst::kLineHeight + 7)
        {
            // only load stats for visible items in the list
			DeckMetaData* metaData = currentMenuItem->getMetaData();
            if (metaData && !metaData->mStatsLoaded)
            {
                metaData->LoadStats();
			}

            if (currentMenuItem->hasFocus())
            {
                mSelectedDeck = metaData;
                WFont *descriptionFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);

                // display the "more info" button if special condition is met
                if (showDetailsScreen())
                {                    
                    dismissButton->setIsSelectionValid(true);
                    dismissButton->Render();
                }
                else
                {
                    dismissButton->setIsSelectionValid(false);
                }
                // display the avatar image
                string currentAvatarImageName = currentMenuItem->getImageFilename();
                if (currentAvatarImageName.size() > 0)
                {
                    JQuadPtr quad = WResourceManager::Instance()->RetrieveTempQuad(currentAvatarImageName, TEXTURE_SUB_AVATAR);
                    if(quad.get())
                    {
                        quad->mWidth = 35.f;
                        quad->mHeight = 50.f;
                        if (currentMenuItem->getText() == "Evil Twin")
                        {
                            JQuad * evil = quad.get();
                            evil->SetHFlip(true);
                            renderer->RenderQuad(quad.get(), avatarX, avatarY);
                            evil = NULL;
                        }
                        else
                            renderer->RenderQuad(quad.get(), avatarX, avatarY);
                    }
                }
                
                // fill in the description part of the screen
				string text = wordWrap(_(currentMenuItem->getDescription()), descWidth, descriptionFont->mFontID );
                descriptionFont->SetColor(ARGB(255,255,255,255));
                descriptionFont->DrawString(text.c_str(), descX, descY);
                
                // fill in the statistical portion
                if (currentMenuItem->hasMetaData())
                {
                    ostringstream oss;
                    oss << _("Deck: ") << currentMenuItem->getDeckName() << endl;
                    oss << currentMenuItem->getDeckStatsSummary();
                    descriptionFont->SetColor(ARGB(255,255,255,255));
                    descriptionFont->DrawString(oss.str(), statsX, statsY);
                }
                
                // change the font color of the current menu item
                mFont->SetColor(ARGB(255,255,255,255));
            }
            else // reset the font color to be slightly muted
                mFont->SetColor(ARGB(150,255,255,255));
            currentMenuItem->RenderWithOffset(-DeckMenuConst::kLineHeight * startId);
        }
    }
    
	if (!title.empty())
    {
        mFont->SetColor(ARGB(255,255,255,255));
        mFont->DrawString(title.c_str(), titleX, titleY, JGETEXT_CENTER);
    }

    mScroller->Render();
	RenderBackground();
    RenderDeckManaColors();
    
    renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE);
	stars->Render();
	renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);

}
Exemple #25
0
bool CapApp::onInit(int argc, char* argv[])
{
	(void)argc;
	(void)argv;

	// Load settings...
	if(!iniRead()) {
		iniWrite(); // create settings file...
	}

	cellSysmoduleLoadModule(CELL_SYSMODULE_FS);

	cellSysmoduleLoadModule(CELL_SYSMODULE_SYSUTIL_SCREENSHOT);
	cellScreenShotEnable();

	InputInit();

	while(!videoOutIsReady())
	{
		// ...
	}


	PSGLinitOptions options = 
	{
		enable:					PSGL_INIT_MAX_SPUS | PSGL_INIT_INITIALIZE_SPUS,
		maxSPUs:				1,
		initializeSPUs:			GL_FALSE,
		persistentMemorySize:	0,
		transientMemorySize:	0,
		errorConsole:			0,
		fifoSize:				0,  
		hostMemorySize:			128* 1024*1024,  // 128 mbs for host memory 
	};

#if CELL_SDK_VERSION < 0x340000
	options.enable |=	PSGL_INIT_HOST_MEMORY_SIZE;
#endif

	// Initialize 6 SPUs but reserve 1 SPU as a raw SPU for PSGL
	sys_spu_initialize(6, 1);
	psglInit(&options);

	const unsigned int resolutions[] = { 
		CELL_VIDEO_OUT_RESOLUTION_1080, 
		CELL_VIDEO_OUT_RESOLUTION_960x1080, 
		CELL_VIDEO_OUT_RESOLUTION_720, 
		CELL_VIDEO_OUT_RESOLUTION_480 
	};

	const int numResolutions = sizeof(resolutions) / sizeof(resolutions[0]);

	int bestResolution = chooseBestResolution(resolutions,numResolutions);

	getResolutionWidthHeight(bestResolution, deviceWidth, deviceHeight);

	if(bestResolution)
	{
		PSGLdeviceParameters params;

		params.enable				= PSGL_DEVICE_PARAMETERS_COLOR_FORMAT |
									  PSGL_DEVICE_PARAMETERS_DEPTH_FORMAT |
									  PSGL_DEVICE_PARAMETERS_MULTISAMPLING_MODE;
		params.colorFormat			= GL_ARGB_SCE;
		params.depthFormat			= GL_NONE;
		params.multisamplingMode	= GL_MULTISAMPLING_NONE_SCE;
		params.enable				|= PSGL_DEVICE_PARAMETERS_WIDTH_HEIGHT;
		params.width				= deviceWidth;
		params.height				= deviceHeight;

		device						= psglCreateDeviceExtended(&params);
		context						= psglCreateContext();

		psglMakeCurrent(context, device);
		psglResetCurrentContext();

		initGraphics(device);

		if( cellSysutilRegisterCallback( 0, callback_sysutil_exit, NULL ) < 0 ) {
			//...
		}

		dbgFontInit();

		fbaRL = new c_fbaRL();

		while(bRun)
		{
			onRender();
			onUpdate();
			cellSysutilCheckCallback();
		}

	} else {
		// resolution error...
	}

	onShutdown();

	return false;
}

void CapApp::onRender()
{
	if(fbaRL) fbaRL->DlgDisplayFrame();

	// get render target buffer dimensions and set viewport	
	psglGetRenderBufferDimensions(device,&renderWidth,&renderHeight);

	glViewport(0, 0, renderWidth, renderHeight);

	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	RenderBackground();
	if(fbaRL) fbaRL->DisplayFrame();
	dbgFontDraw();

	psglSwap();
}

bool CapApp::onUpdate()
{
	if(!mFrame) mFrame = 0;
	mFrame++;

	InputFrameStart();
	if(fbaRL) fbaRL->InputFrame();
	InputFrameEnd();	

	return true;
}

void CapApp::onShutdown()
{
	iniWrite(); // save settings

	if(context) psglDestroyContext(context);
	if(device) psglDestroyDevice(device);

	InputExit();
	psglExit();
}
void StateAGDevOptions::Draw(StateHandler * stateHandler)
{
	RenderBackground();
	RenderButtons();
	theView->SwapBuffers();
}
Exemple #27
0
void displayCallback()
{
	akj::ResetCubeDrawCount();
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	glClear(  GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	
	if(gUseFBO)
	{
		if(gWidth != gPostFXFrameBuffer->mWidth || gHeight != gPostFXFrameBuffer->mHeight)
		{
			gPostFXFrameBuffer->InitBuffers(gWidth, gHeight, GL_SRGB8_ALPHA8);
			//rebind to the normal back buffer
			glBindFramebuffer(GL_FRAMEBUFFER, 0);
		}
		glEnable(GL_BLEND);
		glBlendEquation(GL_FUNC_ADD);
		glBlendFuncSeparate (GL_ONE, GL_ZERO, GL_ONE, GL_ZERO);
		RenderBackground();
		glBlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);

		//flame effects need to know about the time 
		gCompositingShader->BindUniformToFloat("my_time", gTime);

		glPolygonMode(GL_FRONT, GL_FILL);
		gCompositingShader->Use();
		// clear the color buffer
		// set up camera: we want a quad matched up to the viewport
		glMatrixMode( GL_PROJECTION );
		glLoadIdentity();
		glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
		glMatrixMode( GL_MODELVIEW );
		glLoadIdentity();
		//drawcube gives a -0.5 - 0.5 range, so mult by 2
		glScalef(2.0, 2.0, 1.0);
		glTranslatef( 0.0, 0.0, -0.8);
		akj::glDrawRect2D();
		akj::glCheckAllErrors(__FILE__,__LINE__);
		glClear( GL_DEPTH_BUFFER_BIT );
	}
	else
	{
		RenderBackground();
	}
	glClear( GL_DEPTH_BUFFER_BIT );
	glDisable(GL_BLEND);
	SetupCamera();
	RenderRabbit();

	if(gUseFBO)
	{
		if(gClearFBO)
		{
			glClear(  GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
			gClearFBO = false;
		}
		glActiveTexture(GL_TEXTURE0 + gPostFXFrameBuffer->GetBoundTextureUnit());
		glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, gWidth, gHeight);

	}

	glutSwapBuffers();
	if (gDump) {               // save images to file
		dumpPPM();
	}
	//printf("number of cubes this frame = %d\n", akj::GetCubeDrawCount());
	
}