openclonk/src/gui/C4UpperBoard.cpp

75 lines
2.9 KiB
C++
Raw Normal View History

2009-05-08 13:28:41 +00:00
/*
* OpenClonk, http://www.openclonk.org
*
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
2016-04-03 18:18:29 +00:00
* Copyright (c) 2009-2016, The OpenClonk Team and contributors
2009-05-08 13:28:41 +00:00
*
* Distributed under the terms of the ISC license; see accompanying file
* "COPYING" for details.
2009-05-08 13:28:41 +00:00
*
* "Clonk" is a registered trademark of Matthes Bender, used with permission.
* See accompanying file "TRADEMARK" for details.
2009-05-08 13:28:41 +00:00
*
* To redistribute this file separately, substitute the full license texts
* for the above references.
2009-05-08 13:28:41 +00:00
*/
#include "C4Include.h"
#include "gui/C4UpperBoard.h"
2009-05-08 13:28:41 +00:00
#include "graphics/C4Draw.h"
#include "graphics/C4GraphicsResource.h"
2009-05-08 13:28:41 +00:00
C4UpperBoard::C4UpperBoard() = default;
2009-05-08 13:28:41 +00:00
C4UpperBoard::~C4UpperBoard() = default;
2009-05-08 13:28:41 +00:00
void C4UpperBoard::Execute()
2010-03-28 18:58:01 +00:00
{
if (!Config.Graphics.UpperBoard) return;
2009-05-08 13:28:41 +00:00
// Make the time strings
sprintf(cTimeString,"%02d:%02d:%02d", Game.Time/3600,(Game.Time%3600)/60,Game.Time%60);
time_t t = time(nullptr); strftime(cTimeString2, sizeof(cTimeString2), "[%H:%M:%S]", localtime(&t));
2009-05-08 13:28:41 +00:00
Draw(Output);
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4UpperBoard::Draw(C4Facet &cgo)
2010-03-28 18:58:01 +00:00
{
if (!cgo.Surface) return;
2009-05-08 13:28:41 +00:00
// Background
pDraw->BlitSurfaceTile(::GraphicsResource.fctUpperBoard.Surface,Output.Surface,0,0,Output.Wdt,Output.Hgt,0,0,nullptr);
// Logo
2009-05-08 13:28:41 +00:00
C4Facet cgo2;
float fLogoZoom = 1.0f;
cgo2.Set(cgo.Surface, (int32_t)(cgo.Wdt/2-(::GraphicsResource.fctLogo.Wdt/2)*fLogoZoom), 0,
2010-03-28 18:58:01 +00:00
(int32_t)(::GraphicsResource.fctLogo.Wdt*fLogoZoom), (int32_t)(::GraphicsResource.fctLogo.Hgt*fLogoZoom));
::GraphicsResource.fctLogo.Draw(cgo2);
2009-05-08 13:28:41 +00:00
// Right text sections
int32_t iRightOff = 1;
// Playing time
2011-10-03 14:30:18 +00:00
pDraw->TextOut(cTimeString, ::GraphicsResource.FontRegular, 1.0, cgo.Surface, C4GUI::GetScreenWdt() - (iRightOff++) * TextWidth - 10, TextYPosition, 0xFFFFFFFF);
2009-05-08 13:28:41 +00:00
// Clock
if (Config.Graphics.ShowClock)
2011-10-03 14:30:18 +00:00
pDraw->TextOut(cTimeString2, ::GraphicsResource.FontRegular, 1.0, cgo.Surface, C4GUI::GetScreenWdt() - (iRightOff++) * TextWidth - 30, TextYPosition, 0xFFFFFFFF);
2009-05-08 13:28:41 +00:00
// FPS
if (Config.General.FPS)
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
sprintf(cTimeString, "%d FPS", Game.FPS);
2011-10-03 14:30:18 +00:00
pDraw->TextOut(cTimeString, ::GraphicsResource.FontRegular, 1.0, cgo.Surface, C4GUI::GetScreenWdt() - (iRightOff++) * TextWidth - 30, TextYPosition, 0xFFFFFFFF);
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// Scenario title
2011-10-03 14:30:18 +00:00
pDraw->TextOut(Game.ScenarioTitle.getData(), ::GraphicsResource.FontRegular, 1.0, cgo.Surface, 10, cgo.Hgt / 2 - ::GraphicsResource.FontRegular.GetLineHeight() / 2, 0xFFFFFFFF);
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4UpperBoard::Init(C4Facet &cgo)
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// Save facet
Output = cgo;
if (!::GraphicsResource.fctUpperBoard.Surface) return;
2009-05-08 13:28:41 +00:00
// in newgfx, the upperboard may be larger and overlap the scene
Output.Hgt = std::max(Output.Hgt, ::GraphicsResource.fctUpperBoard.Hgt);
2009-05-08 13:28:41 +00:00
// Generate textposition
sprintf(cTimeString,"%02d:%02d:%02d", Game.Time/3600,(Game.Time%3600)/60,Game.Time%60);
TextWidth = ::GraphicsResource.FontRegular.GetTextWidth(cTimeString);
TextYPosition = cgo.Hgt / 2 - ::GraphicsResource.FontRegular.GetLineHeight() / 2;
2009-05-08 13:28:41 +00:00
}