...
 
Commits (2)
  • Dmitry Kargin's avatar
    AnyUnitSize merge: refactoring and cleaning up · 8e00eefe
    Dmitry Kargin authored
    These are small scale fixes I've made in AnyUnitSize branch:
    
     - Removed global Quit method. Event manager exits its event loop more gracefully.
     - Moved utlities like pcx, unifonts, tinyxml to appropriate folder
     - Global `cUniFont font;` has ben moved to static field inside cUniFont.
     - removed `#include "gameversion.h"` from netmessage2.h. It caused massive rebuilds after every git change.
     - updated paths to tinyxml2.h. It will not collide with system-wide version.
    8e00eefe
  • Bernd Kosmahl's avatar
    Merge branch 'develop' into 'develop' · f1623a30
    Bernd Kosmahl authored
    AnyUnitSize merge: refactoring and cleaning up
    
    See merge request !15
    f1623a30
......@@ -38,18 +38,28 @@ cEventManager& cEventManager::getInstance()
return instance;
}
bool cEventManager::shouldExit() const
{
return isDone;
}
//------------------------------------------------------------------------------
void cEventManager::run()
{
SDL_Event event;
while (SDL_PollEvent (&event))
{
handleSdlEvent (event);
if(!handleSdlEvent (event))
{
isDone = true;
break;
}
}
SDL_Delay(1);
}
//------------------------------------------------------------------------------
void cEventManager::handleSdlEvent (const SDL_Event& event)
bool cEventManager::handleSdlEvent (const SDL_Event& event)
{
switch (event.type)
{
......@@ -70,7 +80,7 @@ void cEventManager::handleSdlEvent (const SDL_Event& event)
mouseWheelEvent (cEventMouseWheel (event.wheel));
break;
case SDL_QUIT:
Quit();
return false;
break;
case SDL_MOUSEMOTION:
mouseMotionEvent (cEventMouseMotion (event.motion));
......@@ -80,4 +90,6 @@ void cEventManager::handleSdlEvent (const SDL_Event& event)
break;
default: break;
}
// Everything is OK, continue the cycle
return true;
}
......@@ -62,12 +62,15 @@ public:
cSignal<void (const cKeyboardEvent&)> keyboardEvent;
cSignal<void (const cTextInputEvent&)> textInputEvent;
bool shouldExit() const;
private:
cEventManager();
cEventManager (const cEventManager& other) MAXR_DELETE_FUNCTION;
cEventManager& operator= (const cEventManager& other) MAXR_DELETE_FUNCTION;
void handleSdlEvent (const SDL_Event& event);
bool handleSdlEvent (const SDL_Event& event);
bool isDone = false;
};
#endif // events_eventmanagerH
......@@ -18,8 +18,8 @@
***************************************************************************/
#include <vector>
#include "extendedtinyxml.h"
#include "utility/log.h"
#include "tinyxml2.h"
using namespace tinyxml2;
using namespace std;
......
......@@ -20,7 +20,7 @@
#ifndef EXTENDEDTINYXML_H
#define EXTENDEDTINYXML_H
#include "tinyxml2.h"
#include "utility/tinyxml2.h"
#include <stdarg.h>
#include <string>
......
......@@ -27,7 +27,7 @@
#include "utility/autosurface.h"
#include "defines.h"
#include "t_2.h"
#include "utility/t_2.h"
#include "utility/position.h"
#include "utility/signal/signal.h"
#include "game/data/gamesettings.h"
......
......@@ -22,7 +22,7 @@
#include <string>
#include "tinyxml2.h"
#include "utility/tinyxml2.h"
class cModel;
class cSaveGameInfo;
......
......@@ -24,13 +24,14 @@
#include "utility/listhelpers.h"
#include "game/logic/fxeffects.h"
#include "main.h"
#include "pcx.h"
//#include "pcx.h"
#include "netmessage2.h"
#include "game/data/player/player.h"
#include "settings.h"
#include "game/logic/upgradecalculator.h"
#include "game/data/units/vehicle.h"
#include "video.h"
#include "unifonts.h"
#include "utility/unifonts.h"
#include "game/data/report/savedreportsimple.h"
#include "game/data/report/special/savedreportresourcechanged.h"
#include "utility/random.h"
......@@ -194,6 +195,7 @@ cBuilding::~cBuilding()
//----------------------------------------------------
string cBuilding::getStatusStr (const cPlayer* whoWantsToKnow, const cUnitsData& unitsData) const
{
auto font = cUnicodeFont::font.get();
if (isDisabled())
{
string sText;
......@@ -1283,8 +1285,8 @@ sBuildingUIData& sBuildingUIData::operator= (sBuildingUIData && other)
hasOverlay = other.hasOverlay;
buildUpGraphic = other.buildUpGraphic;
powerOnGraphic = other.powerOnGraphic;
isAnimated = isAnimated;
isConnectorGraphic = isConnectorGraphic;
isAnimated = other.isAnimated;
isConnectorGraphic = other.isConnectorGraphic;
hasFrames = other.hasFrames;
return *this;
......
......@@ -20,7 +20,7 @@
#include <algorithm>
#include "unitdata.h"
#include "tinyxml2.h"
#include "utility/tinyxml2.h"
#include "game/data/player/clans.h"
#include "utility/log.h"
#include "utility/language.h"
......
......@@ -28,12 +28,11 @@
#include "game/logic/fxeffects.h"
#include "utility/log.h"
#include "game/data/map/map.h"
#include "pcx.h"
#include "game/data/player/player.h"
#include "settings.h"
#include "video.h"
#include "sound.h"
#include "unifonts.h"
#include "utility/unifonts.h"
#include "input/mouse/mouse.h"
#include "output/sound/sounddevice.h"
#include "output/sound/soundchannel.h"
......@@ -236,7 +235,9 @@ void cVehicle::render_simple (SDL_Surface* surface, const SDL_Rect& dest, float
// draw player color
if (owner)
{
SDL_BlitSurface (owner->getColor().getTexture(), nullptr, GraphicsData.gfx_tmp.get(), nullptr);
SDL_Surface* src = owner->getColor().getTexture();
SDL_Surface* dst = GraphicsData.gfx_tmp.get();
SDL_BlitSurface(src, nullptr, dst, nullptr);
}
// read the size:
......@@ -454,6 +455,7 @@ bool cVehicle::refreshData()
//-----------------------------------------------------------------------------
string cVehicle::getStatusStr(const cPlayer* player, const cUnitsData& unitsData) const
{
auto font = cUnicodeFont::font.get();
if (isDisabled())
{
string sText;
......
......@@ -23,7 +23,7 @@
#include "game/data/units/unitdata.h"
#include "utility/log.h"
#include "tinyxml2.h"
#include "utility/tinyxml2.h"
#include "game/data/units/unit.h"
#include "game/data/player/player.h"
......
......@@ -17,7 +17,7 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "tinyxml2.h"
#include "utility/tinyxml2.h"
#include "keys.h"
#include "utility/files.h"
......
......@@ -44,11 +44,11 @@
#include "keys.h"
#include "utility/log.h"
#include "main.h"
#include "pcx.h"
#include "utility/pcx.h"
#include "settings.h"
#include "sound.h"
#include "tinyxml2.h"
#include "unifonts.h"
#include "utility/tinyxml2.h"
#include "utility/unifonts.h"
#include "game/data/units/vehicle.h"
#include "video.h"
#include "debug.h"
......@@ -149,8 +149,8 @@ int LoadData (void* data)
return 0;
}
font = new cUnicodeFont; // init ascii fonts
font->setTargetSurface (cVideo::buffer);
cUnicodeFont::font.reset(new cUnicodeFont()); // init ascii fonts
cUnicodeFont::font->setTargetSurface (cVideo::buffer);
Log.mark();
}
......@@ -347,6 +347,7 @@ int LoadData (void* data)
cout << sTxt << endl;
return;
}
const auto& font = cUnicodeFont::font.get();
const SDL_Rect rDest = {22, 152, 228, Uint16 (font->getFontHeight (FONT_LATIN_BIG_GOLD)) };
const SDL_Rect rDest2 = {250, 152, 230, Uint16 (font->getFontHeight (FONT_LATIN_BIG_GOLD)) };
......
......@@ -43,11 +43,9 @@
#include "game/data/map/map.h"
#include "mveplayer.h"
#include "network.h"
#include "pcx.h"
#include "game/data/player/player.h"
#include "settings.h"
#include "sound.h"
#include "unifonts.h"
#include "game/data/units/vehicle.h"
#include "video.h"
#include "maxrversion.h"
......@@ -64,16 +62,32 @@
using namespace std;
static int initNet();
static int initSDL();
static int initSDL(bool headless);
static int initSound();
static void logMAXRVersion();
static void showIntro();
struct AtExit
{
~AtExit()
{
//unload files here
cSoundDevice::getInstance().close();
SDLNet_Quit();
Video.clearMemory();
SDL_Quit();
Log.write ("EOF");;
}
};
int main (int argc, char* argv[])
{
AtExit exitGuard; // Will clean data global data in its destructor
bool headless = DEDICATED_SERVER;
if (!cSettings::getInstance().isInitialized())
{
Quit();
return -1;
}
......@@ -81,14 +95,14 @@ int main (int argc, char* argv[])
// stop on error during init of SDL basics. WARNINGS will be ignored!
if (initSDL() == -1) return -1;
if (initSDL(headless) == -1) return -1;
// call it once to initialize
is_main_thread();
logMAXRVersion();
if (!DEDICATED_SERVER)
if (!headless)
{
Video.init();
Video.showSplashScreen(); // show splashscreen
......@@ -107,11 +121,11 @@ int main (int argc, char* argv[])
{
Log.write ("Error while loading data!", cLog::eLOG_TYPE_ERROR);
SDL_WaitThread (dataThread, nullptr);
Quit();
return -1;
}
while (SDL_PollEvent (&event))
{
if (!DEDICATED_SERVER
if (!headless
&& event.type == SDL_WINDOWEVENT
&& event.window.event == SDL_WINDOWEVENT_EXPOSED)
{
......@@ -119,14 +133,14 @@ int main (int argc, char* argv[])
}
}
SDL_Delay (100);
if (!DEDICATED_SERVER)
if (!headless)
{
// The draw may be conditionned when screen has changed.
Video.draw();
}
}
if (!DEDICATED_SERVER)
if (!headless)
{
// play intro if we're supposed to and the file exists
if (cSettings::getInstance().shouldShowIntro())
......@@ -141,7 +155,7 @@ int main (int argc, char* argv[])
SDL_WaitThread (dataThread, nullptr);
if (DEDICATED_SERVER)
if (headless)
{
cDedicatedServer::instance().run();
}
......@@ -166,7 +180,6 @@ int main (int argc, char* argv[])
application.execute();
}
Quit();
return 0;
}
......@@ -175,10 +188,10 @@ int main (int argc, char* argv[])
*@author beko
*@return -1 on error<br>0 on success<br>1 with warnings
*/
static int initSDL()
static int initSDL(bool headless)
{
int sdlInitResult = -1;
if (DEDICATED_SERVER)
if (headless)
sdlInitResult = SDL_Init (SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE); // start SDL basics without video
else
sdlInitResult = SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE); // start SDL basics
......@@ -311,23 +324,6 @@ bool is_main_thread()
return main_thread_id == SDL_ThreadID();
}
/**
*Terminates app
*@author beko
*/
void Quit()
{
delete font;
//unload files here
cSoundDevice::getInstance().close();
SDLNet_Quit();
Video.clearMemory();
SDL_Quit();
Log.write ("EOF");
exit (0);
}
string iToStr (int x)
{
stringstream strStream;
......
......@@ -331,6 +331,4 @@ int Round (float num);
std::string getHexValue(unsigned char byte);
unsigned char getByteValue(const std::string& str, int index);
void Quit();
#endif
......@@ -28,6 +28,7 @@
#include "utility/serialization/serialization.h"
#include "ui/graphical/menu/control/menuevents.h"
#include "game/logic/turntimeclock.h"
#include "maxrversion.h"
std::unique_ptr<cNetMessage2> cNetMessage2::createFromBuffer(const unsigned char* data, int length)
{
......@@ -102,6 +103,30 @@ std::unique_ptr<cNetMessage2> cNetMessage2::clone() const
return cNetMessage2::createFromBuffer(serialMessage.data(), serialMessage.size());
}
//------------------------------------------------------------------------------
cNetMessageTcpHello::cNetMessageTcpHello():
cNetMessage2(eNetMessageType::TCP_HELLO),
packageVersion(PACKAGE_VERSION),
packageRev(PACKAGE_REV)
{}
//------------------------------------------------------------------------------
cNetMessageTcpWantConnect::cNetMessageTcpWantConnect():
cNetMessage2(eNetMessageType::TCP_WANT_CONNECT),
ready(false),
packageVersion(PACKAGE_VERSION),
packageRev(PACKAGE_REV),
socket(nullptr)
{}
//------------------------------------------------------------------------------
cNetMessageTcpConnected::cNetMessageTcpConnected(int playerNr) :
cNetMessage2(eNetMessageType::TCP_CONNECTED),
playerNr(playerNr),
packageVersion(PACKAGE_VERSION),
packageRev(PACKAGE_REV)
{}
//------------------------------------------------------------------------------
std::string enumToString(eNetMessageType value)
{
......
......@@ -30,7 +30,6 @@
#include "game/data/report/savedreport.h"
#include "ui/graphical/game/gameguistate.h"
#include "utility/color.h"
#include "maxrversion.h"
#include "mapdownload.h"
#include "game/data/player/playerbasicdata.h"
#include "main.h"
......@@ -364,11 +363,7 @@ private:
class cNetMessageTcpHello : public cNetMessage2
{
public:
cNetMessageTcpHello() :
cNetMessage2(eNetMessageType::TCP_HELLO),
packageVersion(PACKAGE_VERSION),
packageRev(PACKAGE_REV)
{};
cNetMessageTcpHello();
cNetMessageTcpHello(cBinaryArchiveOut& archive) :
cNetMessage2(eNetMessageType::TCP_HELLO)
{
......@@ -395,13 +390,7 @@ private:
class cNetMessageTcpWantConnect : public cNetMessage2
{
public:
cNetMessageTcpWantConnect() :
cNetMessage2(eNetMessageType::TCP_WANT_CONNECT),
ready(false),
packageVersion(PACKAGE_VERSION),
packageRev(PACKAGE_REV),
socket(nullptr)
{};
cNetMessageTcpWantConnect();
cNetMessageTcpWantConnect(cBinaryArchiveOut& archive) :
cNetMessage2(eNetMessageType::TCP_WANT_CONNECT)
{
......@@ -436,12 +425,7 @@ private:
class cNetMessageTcpConnected : public cNetMessage2
{
public:
cNetMessageTcpConnected(int playerNr) :
cNetMessage2(eNetMessageType::TCP_CONNECTED),
playerNr(playerNr),
packageVersion(PACKAGE_VERSION),
packageRev(PACKAGE_REV)
{};
cNetMessageTcpConnected(int playerNr);
cNetMessageTcpConnected(cBinaryArchiveOut& archive) :
cNetMessage2(eNetMessageType::TCP_CONNECTED)
{
......
......@@ -36,7 +36,7 @@
#include "utility/files.h"
#include "utility/log.h"
#include "main.h"
#include "tinyxml2.h"
#include "utility/tinyxml2.h"
#include "video.h"
#include "utility/string/tolower.h"
#include "game/data/player/playercolor.h"
......
......@@ -21,7 +21,7 @@
#include <string>
#include <SDL.h>
#include "tinyxml2.h"
#include "utility/tinyxml2.h"
#include "utility/thread/mutex.h"
#include "utility/signal/signal.h"
#include "utility/color.h"
......
......@@ -25,7 +25,8 @@
#include "settings.h"
#include "video.h"
#include "main.h"
#include "unifonts.h"
#include "utility/unifonts.h"
#include "netmessage2.h"
#include "game/startup/game.h"
#include "utility/runnable.h"
......@@ -70,16 +71,26 @@ cApplication::cApplication() :
//------------------------------------------------------------------------------
cApplication::~cApplication()
{}
{
// Move it to temporary container.
// It allows to break all shared_ptr cross-references broken before
// cApplication is destroyed
{
auto runnables_tmp = std::move(runnables);
}
}
//------------------------------------------------------------------------------
void cApplication::execute()
{
cWindow* lastActiveWindow = nullptr;
bool lastClosed = false;
while (!modalWindows.empty())
cEventManager& eventManager = cEventManager::getInstance();
while (!modalWindows.empty() && !eventManager.shouldExit())
{
cEventManager::getInstance().run();
eventManager.run();
for (auto i = runnables.begin(); i != runnables.end(); /*erase in loop*/)
{
......@@ -235,12 +246,12 @@ void cApplication::addRunnable (std::shared_ptr<cRunnable> runnable)
}
//------------------------------------------------------------------------------
std::shared_ptr<cRunnable> cApplication::removeRunnable (const cRunnable& runnable)
std::shared_ptr<cRunnable> cApplication::removeRunnable(std::shared_ptr<cRunnable> runnable)
{
std::shared_ptr<cRunnable> result;
for (auto i = runnables.begin(); i != runnables.end();)
{
if (i->get() == &runnable)
if (*i == runnable)
{
result = std::move (*i);
i = runnables.erase (i);
......@@ -495,5 +506,6 @@ void cApplication::drawFramesPerSecond (unsigned int fps, bool draw)
{
SDL_Rect dest = {0, 0, 55, 10};
SDL_FillRect (cVideo::buffer, &dest, 0);
if (draw) font->showText (0, 0, "FPS: " + iToStr (fps));
if (draw)
cUnicodeFont::font->showText (0, 0, "FPS: " + iToStr (fps));
}
......@@ -77,7 +77,7 @@ public:
bool hasKeyFocus() const;
void addRunnable (std::shared_ptr<cRunnable> runnable);
std::shared_ptr<cRunnable> removeRunnable (const cRunnable& runnable);
std::shared_ptr<cRunnable> removeRunnable (std::shared_ptr<cRunnable> runnable);
cShortcut* addShortcut (std::unique_ptr<cShortcut> shortcut);
......
......@@ -152,7 +152,7 @@ cGameGuiController::cGameGuiController (cApplication& application_, std::shared_
//------------------------------------------------------------------------------
cGameGuiController::~cGameGuiController()
{
application.removeRunnable (*animationTimer);
application.removeRunnable (animationTimer);
}
//------------------------------------------------------------------------------
......
......@@ -96,6 +96,7 @@ cGameGui::cGameGui (std::shared_ptr<const cStaticMap> staticMap_, std::shared_pt
hudPanels = addChild (std::make_unique<cHudPanels> (getPosition(), getSize().y(), animationTimer));
auto font = cUnicodeFont::font.get();
primiaryInfoLabel = addChild (std::make_unique<cLabel> (cBox<cPosition> (cPosition (cHud::panelLeftWidth, 235), cPosition (getEndPosition().x() - cHud::panelRightWidth, 235 + font->getFontHeight (FONT_LATIN_BIG))), "", FONT_LATIN_BIG, toEnumFlag (eAlignmentType::CenterHorizontal) | eAlignmentType::Top));
primiaryInfoLabel->disable();
primiaryInfoLabel->hide();
......@@ -867,6 +868,8 @@ void cGameGui::handleResolutionChange()
resize (hud->getSize());
auto font = cUnicodeFont::font.get();
// TODO: remove duplication of widget areas with the ones during initialization
hudPanels->resize (cPosition (hudPanels->getSize().x(), getSize().y()));
......
......@@ -24,7 +24,7 @@
#include "utility/serialization/serialization.h"
#include "utility/position.h"
#include "tinyxml2.h"
#include "utility/tinyxml2.h"
class cUnitSelection;
class cUnitLockList;
......
......@@ -33,7 +33,7 @@
#include "defines.h"
#include "settings.h"
#include "video.h"
#include "pcx.h"
#include "utility/pcx.h"
#include "main.h"
#include "game/data/units/unit.h"
#include "keys.h"
......
......@@ -93,7 +93,7 @@ cChatBox<ChatListItemType, PlayerListItemType>::cChatBox (const cBox<cPosition>&
chatList->disableSelectable();
chatList->setBeginMargin (cPosition (2, 2));
chatList->setEndMargin (cPosition (2, 2));
chatList->setScrollOffset (font->getFontHeight() + 3);
chatList->setScrollOffset (cUnicodeFont::font->getFontHeight() + 3);
chatLineEdit = addChild (std::make_unique<cLineEdit> (cBox<cPosition> (cPosition (getPosition().x() + 2, getEndPosition().y() - 12), cPosition (getEndPosition().x() - 164, getEndPosition().y() - 2))));
signalConnectionManager.connect (chatLineEdit->returnPressed, std::bind (&cChatBox::sendCommand, this));
......
......@@ -25,7 +25,7 @@
#include "game/logic/client.h"
#include "game/logic/server2.h"
#include "video.h"
#include "unifonts.h"
#include "utility/unifonts.h"
#include "game/data/units/building.h"
#include "game/data/units/vehicle.h"
#include "utility/string/toString.h"
......@@ -142,10 +142,12 @@ void cDebugOutputWidget::draw (SDL_Surface& destination, const cBox<cPosition>&
if (!client) return;
auto font = cUnicodeFont::font.get();
const cPlayer& player = client->getActivePlayer();
setPrintPosition(cPosition(getEndPosition().x() - 200, getPosition().y()));
if (debugPlayers)
{
print("Players: " + toString(client->model.getPlayerList().size()));
......@@ -363,8 +365,8 @@ void cDebugOutputWidget::setPrintPosition(cPosition position)
//------------------------------------------------------------------------------
void cDebugOutputWidget::print(const std::string& text, eUnicodeFontType font_ /*= FONT_LATIN_SMALL_WHITE*/)
{
font->showText(drawPosition.x(), drawPosition.y(), text, font_);
drawPosition.y() += font->getFontHeight(font_);
cUnicodeFont::font->showText(drawPosition.x(), drawPosition.y(), text, font_);
drawPosition.y() += cUnicodeFont::font->getFontHeight(font_);
}
//------------------------------------------------------------------------------
......@@ -408,6 +410,8 @@ void cDebugOutputWidget::traceVehicle (const cVehicle& vehicle, cPosition& drawP
{
std::string tmpString;
auto font = cUnicodeFont::font.get();
tmpString = "name: \"" + vehicle.getDisplayName() + "\" id: \"" + iToStr (vehicle.iID) + "\" owner: \"" + vehicle.getOwner()->getName() + "\" posX: +" + iToStr (vehicle.getPosition().x()) + " posY: " + iToStr (vehicle.getPosition().y()) + " offX: " + iToStr (vehicle.getMovementOffset().x()) + " offY: " + iToStr (vehicle.getMovementOffset().y());
font->showText (drawPosition, tmpString, FONT_LATIN_SMALL_WHITE);
drawPosition.y() += 8;
......@@ -472,6 +476,8 @@ void cDebugOutputWidget::traceBuilding (const cBuilding& building, cPosition& dr
{
std::string tmpString;
auto font = cUnicodeFont::font.get();
tmpString = "name: \"" + building.getDisplayName() + "\" id: \"" + iToStr (building.iID) + "\" owner: \"" + (building.getOwner() ? building.getOwner()->getName() : "<null>") + "\" posX: +" + iToStr (building.getPosition().x()) + " posY: " + iToStr (building.getPosition().y());
font->showText (drawPosition, tmpString, FONT_LATIN_SMALL_WHITE);
drawPosition.y() += 8;
......@@ -540,12 +546,14 @@ void cDebugOutputWidget::drawDetectedByPlayerList()
const auto tileDrawingRange = gameMap->computeTileDrawingRange();
const auto zoomedStartTilePixelOffset = gameMap->getZoomedStartTilePixelOffset();
auto font = cUnicodeFont::font.get();
for (auto i = makeIndexIterator(tileDrawingRange.first, tileDrawingRange.second); i.hasMore(); i.next())
{
auto& mapField = map.getField(*i);
auto building = mapField.getBuilding();
if (building == nullptr) continue;
auto drawDestination = gameMap->computeTileDrawingArea (zoomedTileSize, zoomedStartTilePixelOffset, tileDrawingRange.first, building->getPosition());
drawDestination.x += 4;
drawDestination.y += 4;
......@@ -599,6 +607,8 @@ void cDebugOutputWidget::drawDetectionMaps()
const auto tileDrawingRange = gameMap->computeTileDrawingRange();
const auto zoomedStartTilePixelOffset = gameMap->getZoomedStartTilePixelOffset();
auto font = cUnicodeFont::font.get();
for (auto i = makeIndexIterator(tileDrawingRange.first, tileDrawingRange.second); i.hasMore(); i.next())
{
auto drawDestination = gameMap->computeTileDrawingArea(zoomedTileSize, zoomedStartTilePixelOffset, tileDrawingRange.first, *i);
......
......@@ -21,7 +21,7 @@
#define ui_graphical_game_widgets_debugoutputidgetH
#include "ui/graphical/widget.h"
#include "unifonts.h"
#include "utility/unifonts.h"
class cClient;
class cServer2;
......
......@@ -102,6 +102,7 @@ void cUnitRenameWidget::setUnit (const cUnit* unit, const cUnitsData& unitsData)
selectedUnitNameEdit->enable();
auto font = cUnicodeFont::font.get();
const auto xPosition = selectedUnitNamePrefixLabel->getPosition().x() + font->getTextWide (selectedUnitNamePrefixLabel->getText() + " ", FONT_LATIN_SMALL_GREEN);
const cPosition moveOffset (xPosition - selectedUnitNameEdit->getPosition().x(), 0);
selectedUnitNameEdit->move (moveOffset);
......@@ -133,4 +134,4 @@ const std::string& cUnitRenameWidget::getUnitName() const
bool cUnitRenameWidget::isAt (const cPosition& position) const
{
return selectedUnitNameEdit->isAt (position);
}
\ No newline at end of file
}
......@@ -32,6 +32,7 @@
#include "game/startup/network/client/networkclientgamenew.h"
#include "game/startup/network/client/networkclientgamereconnection.h"
#include "game/startup/network/client/networkclientgamesaved.h"
#include "maxrversion.h"
#include "main.h"
#include "game/data/map/map.h"
#include "game/data/player/player.h"
......@@ -96,7 +97,7 @@ void cMenuControllerMultiplayerClient::reset()
windowLandingPositionSelection = nullptr;
playersLandingStatus.clear();
newGame = nullptr;
application.removeRunnable (*this);
application.removeRunnable (shared_from_this());
}
//------------------------------------------------------------------------------
......
......@@ -34,6 +34,7 @@
#include "ui/graphical/menu/dialogs/dialogyesno.h"
#include "game/startup/network/host/networkhostgamenew.h"
#include "game/startup/network/host/networkhostgamesaved.h"
#include "maxrversion.h"
#include "main.h"
#include "game/data/map/map.h"
#include "game/data/player/player.h"
......@@ -132,7 +133,7 @@ void cMenuControllerMultiplayerHost::reset()
windowNetworkLobby = nullptr;
windowLandingPositionSelection = nullptr;
newGame = nullptr;
application.removeRunnable (*this);
application.removeRunnable (shared_from_this());
}
//------------------------------------------------------------------------------
......
......@@ -26,13 +26,15 @@
#include "ui/graphical/menu/widgets/image.h"
#include "ui/graphical/menu/widgets/lineedit.h"
#include "ui/graphical/menu/widgets/tools/validatorint.h"
#include "pcx.h"
#include "utility/pcx.h"
#include "main.h"
//------------------------------------------------------------------------------
cDialogColorPicker::cDialogColorPicker (const cRgbColor& color, eWindowBackgrounds backgroundType) :
cWindow (LoadPCX (GFXOD_DIALOG2), backgroundType)
{
auto* font = cUnicodeFont::font.get();
colorPicker = addChild (std::make_unique<cRgbColorPicker> (cBox<cPosition> (getPosition() + cPosition (35, 35), getPosition() + cPosition (35 + 160, 35 + 135)), color));
selectedColorImage = addChild (std::make_unique<cImage> (getPosition() + cPosition (210, 35)));
......@@ -143,4 +145,4 @@ AutoSurface cDialogColorPicker::createSelectedColorSurface()
SDL_FillRect (surface.get(), nullptr, colorPicker->getSelectedColor().toMappedSdlRGBAColor (surface->format));
return surface;
}
\ No newline at end of file
}
......@@ -23,7 +23,7 @@
#include "ui/graphical/menu/widgets/label.h"
#include "ui/graphical/menu/widgets/pushbutton.h"
#include "pcx.h"
#include "utility/pcx.h"
#include "main.h"
//------------------------------------------------------------------------------
......@@ -32,6 +32,8 @@ cDialogLicense::cDialogLicense() :
currentPage (0),
maxPage (3)
{
auto* font = cUnicodeFont::font.get();
addChild (std::make_unique<cLabel> (cBox<cPosition> (getPosition() + cPosition (35, 30), getPosition() + cPosition (35 + 232, 30 + font->getFontHeight())), "\"M.A.X.R.\"", FONT_LATIN_NORMAL, eAlignmentType::CenterHorizontal));
headerLabel = addChild (std::make_unique<cLabel> (cBox<cPosition> (getPosition() + cPosition (35, 30 + font->getFontHeight()), getPosition() + cPosition (35 + 232, 30 + font->getFontHeight() * 2)), "", FONT_LATIN_NORMAL, eAlignmentType::CenterHorizontal));
......
......@@ -21,7 +21,7 @@
#include "ui/graphical/menu/widgets/label.h"
#include "ui/graphical/menu/widgets/pushbutton.h"
#include "pcx.h"
#include "utility/pcx.h"
#include "main.h"
//------------------------------------------------------------------------------
......
......@@ -30,7 +30,7 @@
#include "ui/graphical/menu/widgets/lineedit.h"
#include "ui/graphical/menu/widgets/combobox.h"
#include "ui/graphical/menu/widgets/special/textlistviewitem.h"
#include "pcx.h"
#include "utility/pcx.h"
#include "main.h"
#include "settings.h"
#include "video.h"
......
......@@ -22,7 +22,7 @@
#include "ui/graphical/menu/widgets/pushbutton.h"
#include "ui/graphical/menu/widgets/slider.h"
#include "ui/graphical/menu/widgets/image.h"
#include "pcx.h"
#include "utility/pcx.h"
#include "main.h"
#include "game/data/player/player.h"
#include "video.h"
......
......@@ -23,7 +23,7 @@
#include "ui/graphical/menu/widgets/pushbutton.h"
#include "ui/graphical/menu/widgets/special/protectionglass.h"
#include "ui/graphical/application.h"
#include "pcx.h"
#include "utility/pcx.h"
#include "main.h"
#include "game/data/units/unit.h"
......
......@@ -24,7 +24,8 @@
#include "ui/graphical/menu/widgets/pushbutton.h"
#include "ui/graphical/menu/widgets/image.h"
#include "ui/graphical/application.h"
#include "pcx.h"
#include "utility/pcx.h"
#include "utility/drawing.h"
#include "main.h"
#include "game/data/units/unit.h"
#include "game/data/units/building.h"
......
......@@ -21,7 +21,7 @@
#include "ui/graphical/menu/widgets/label.h"
#include "ui/graphical/menu/widgets/pushbutton.h"
#include "pcx.h"
#include "utility/pcx.h"
#include "main.h"
//------------------------------------------------------------------------------
......
......@@ -60,6 +60,8 @@ cCheckBox::cCheckBox (const cPosition& position, const std::string& text_, eUnic
//------------------------------------------------------------------------------
void cCheckBox::draw (SDL_Surface& destination, const cBox<cPosition>& clipRect)
{
auto font = cUnicodeFont::font.get();
auto position = getArea().toSdlRect();
int textDestx = -1;
int textDesty = -1;
......@@ -213,6 +215,7 @@ void cCheckBox::renewSurface()
{
cPosition size;
SDL_Rect src = {0, 0, 0, 0};
auto font = cUnicodeFont::font.get();
if (type >= eCheckBoxType::HudIndex_00 && type <= eCheckBoxType::HudIndex_22)
{
......
......@@ -23,7 +23,7 @@
#include "ui/graphical/menu/widgets/clickablewidget.h"
#include "utility/autosurface.h"
#include "unifonts.h"
#include "utility/unifonts.h"
#include "sound.h"
#include "utility/signal/signal.h"
......
......@@ -30,6 +30,8 @@ cComboBox::cComboBox (const cBox<cPosition>& area) :
cWidget (area),
maxVisibleItems (5)
{
auto font = cUnicodeFont::font.get();
const cBox<cPosition> listViewArea (cPosition (area.getMinCorner().x(), area.getMaxCorner().y() - 1), cPosition (area.getMaxCorner().x() - 3, area.getMaxCorner().y() + 5));
listView = addChild (std::make_unique<cListView<cTextListViewItem>> (listViewArea, eScrollBarStyle::Modern));
listView->setBeginMargin (cPosition (2, 2));
......@@ -119,7 +121,7 @@ void cComboBox::updateListViewSize()
{
const auto visibleItems = static_cast<int> (std::min (maxVisibleItems, listView->getItemsCount()));
const auto itemHeight = font->getFontHeight (FONT_LATIN_NORMAL) + 1;
const auto itemHeight = cUnicodeFont::font->getFontHeight (FONT_LATIN_NORMAL) + 1;
const auto requiredSize = listView->getBeginMargin().y() + listView->getEndMargin().y() + itemHeight * visibleItems + (visibleItems > 0 ? (listView->getItemDistance() * (visibleItems - 1)) : 0) + 1;
......
......@@ -93,13 +93,14 @@ void cLabel::setWordWrap (bool wordWrap_)
//------------------------------------------------------------------------------
void cLabel::resizeToTextHeight()
{
const auto textHeight = drawLines.size() * font->getFontHeight (fontType);
const auto textHeight = drawLines.size() * cUnicodeFont::font->getFontHeight (fontType);
resize (cPosition (getSize().x(), textHeight));
}
//------------------------------------------------------------------------------
void cLabel::breakText (const std::string& text, std::vector<std::string>& lines, int maximalWidth, eUnicodeFontType fontType) const
{
auto font = cUnicodeFont::font.get();
// NOTE: better would be not to copy each line into the vector
// but use something like "string_view". We could simulate this by using
// a pair of iterators (like a range) but non of other methods would support such a
......@@ -167,8 +168,8 @@ void cLabel::breakText (const std::string& text, std::vector<std::string>& lines
}
int increase;
auto unicodeCharacter = font->encodeUTF8Char (& (*it), increase);
currentWordLength += font->getUnicodeCharacterWidth (unicodeCharacter, fontType);
auto unicodeCharacter = cUnicodeFont::font->encodeUTF8Char (& (*it), increase);
currentWordLength += cUnicodeFont::font->getUnicodeCharacterWidth (unicodeCharacter, fontType);
it += increase;
}
......@@ -179,6 +180,8 @@ void cLabel::updateDisplayInformation()
{
if (surface == nullptr) return;
auto font = cUnicodeFont::font.get();
drawLines.clear();
if (wordWrap)
......@@ -192,7 +195,7 @@ void cLabel::updateDisplayInformation()
SDL_FillRect (surface.get(), nullptr, 0xFF00FF);
const auto height = font->getFontHeight (fontType) * drawLines.size();
const auto height = cUnicodeFont::font->getFontHeight (fontType) * drawLines.size();
int drawPositionY;
if (alignment & eAlignmentType::Bottom)
......@@ -209,7 +212,8 @@ void cLabel::updateDisplayInformation()
}
auto originalTargetSurface = font->getTargetSurface();
auto fontTargetSurfaceResetter = makeScopedOperation ([originalTargetSurface]() { font->setTargetSurface (originalTargetSurface); });
auto fontTargetSurfaceResetter = makeScopedOperation(
[originalTargetSurface, font]() { font->setTargetSurface (originalTargetSurface); });
font->setTargetSurface (surface.get());
for (size_t i = 0; i < drawLines.size(); ++i)
{
......@@ -272,4 +276,4 @@ bool cLabel::handleClicked (cApplication& application, cMouse& mouse, eMouseButt
clicked ();
return true;
}
\ No newline at end of file
}
......@@ -26,7 +26,7 @@
#include "maxrconfig.h"
#include "ui/graphical/menu/widgets/clickablewidget.h"
#include "ui/graphical/alignment.h"
#include "unifonts.h"
#include "utility/unifonts.h"
class cLabel : public cClickableWidget
{
......
......@@ -130,6 +130,8 @@ void cLineEdit::draw (SDL_Surface& destination, const cBox<cPosition>& clipRect)
SDL_BlitSurface (surface.get(), nullptr, &destination, &position);
}
auto font = cUnicodeFont::font.get();
const auto offsetRect = getTextDrawOffset();
const auto cursorXOffset = font->getFontSize (fontType) == FONT_SIZE_SMALL ? -1 : 0;
......@@ -166,6 +168,7 @@ bool cLineEdit::handleGetKeyFocus (cApplication& application)
if (!hadKeyFocus)
{
auto font = cUnicodeFont::font.get();
cursorPos = (int)text.length();
while (cursorPos > endOffset) doPosIncrease (endOffset, endOffset);
while (font->getTextWide (text.substr (startOffset, endOffset - startOffset), fontType) > getSize().x() - getBorderSize()) doPosIncrease (startOffset, startOffset);
......@@ -193,6 +196,7 @@ bool cLineEdit::handleClicked (cApplication& application, cMouse& mouse, eMouseB
if (readOnly) return false;
auto font = cUnicodeFont::font.get();
int x = mouse.getPosition().x() - (getPosition().x() + getTextDrawOffset().x());
int cursor = startOffset;
while (font->getTextWide (text.substr (startOffset, cursor - startOffset), fontType) < x)
......@@ -257,6 +261,8 @@ void cLineEdit::resetTextPosition()
startOffset = 0;
endOffset = (int)text.length();
cursorPos = endOffset;
auto font = cUnicodeFont::font.get();
while (font->getTextWide (text.substr (startOffset, endOffset - startOffset), fontType) > getSize().x() - getBorderSize()) doPosDecrease (endOffset);
}
......@@ -305,6 +311,8 @@ void cLineEdit::scrollLeft (bool changeCursor)
// makes the cursor go left
if (changeCursor && cursorPos > 0) doPosDecrease (cursorPos);
auto font = cUnicodeFont::font.get();
if (cursorPos > 0) while (cursorPos - 1 < startOffset) doPosDecrease (startOffset);
else while (cursorPos < startOffset) doPosDecrease (startOffset);
......@@ -321,6 +329,8 @@ void cLineEdit::scrollRight()
// makes the cursor go right
if (cursorPos < (int)text.length()) doPosIncrease (cursorPos, cursorPos);
assert (cursorPos <= (int)text.length());
auto font = cUnicodeFont::font.get();
while (cursorPos > endOffset) doPosIncrease (endOffset, endOffset);
while (font->getTextWide (text.substr (startOffset, endOffset - startOffset), fontType) > getSize().x() - getBorderSize()) doPosIncrease (startOffset, startOffset);
}
......@@ -370,6 +380,8 @@ bool cLineEdit::handleKeyPressed (cApplication& application, cKeyboard& keyboard
{
if (readOnly || !hasKeyFocus) return false;
auto font = cUnicodeFont::font.get();
switch (key)
{
case SDLK_ESCAPE:
......@@ -458,6 +470,8 @@ void cLineEdit::handleTextEntered (cApplication& application, cKeyboard& keyboar
text.insert (cursorPos, inputText);
auto font = cUnicodeFont::font.get();
if (validator)
{
const auto state = validator->validate (text);
......
......@@ -27,7 +27,7 @@
#include "maxrconfig.h"
#include "ui/graphical/menu/widgets/clickablewidget.h"
#include "ui/graphical/menu/widgets/tools/validatorstate.h"
#include "unifonts.h"
#include "utility/unifonts.h"
#include "utility/autosurface.h"
#include "utility/signal/signal.h"
......
......@@ -440,7 +440,7 @@ int cPlot<T, U>::toPixelY (U y)
template<typename T, typename U>
void cPlot<T, U>::draw (SDL_Surface& destination, const cBox<cPosition>& clipRect)
{
auto* font = cUnicodeFont::font.get();
const cPosition origin (graphBeginMargin.x(), getSize().y() - graphBeginMargin.y());
const auto xPixelWidth = getSize().x() - graphBeginMargin.x() - graphEndMargin.x();
......
......@@ -23,7 +23,7 @@
#include "settings.h"
#include "video.h"
#include "unifonts.h"
#include "utility/unifonts.h"
#include "main.h"
#include "input/mouse/mouse.h"
#include "output/sound/sounddevice.h"
......@@ -109,6 +109,7 @@ void cPushButton::draw (SDL_Surface& destination, const cBox<cPosition>& clipRec
if (!text.empty())
{
auto font = cUnicodeFont::font.get();
if (buttonType >= ePushButtonType::HudNext && buttonType <= ePushButtonType::HudFiles)
{
if (isPressed || isLocked) font->showTextCentered (position.x + position.w / 2, position.y + getTextYOffset(), text, FONT_LATIN_SMALL_GREEN);
......@@ -367,7 +368,7 @@ void cPushButton::renewSurface()
SDL_BlitSurface (srcSurface, &src, surface.get(), nullptr);
text = font->shortenStringToSize (text, size.x() - getBordersSize(), fontType);
text = cUnicodeFont::font->shortenStringToSize (text, size.x() - getBordersSize(), fontType);
}
//------------------------------------------------------------------------------
......
......@@ -26,7 +26,7 @@
#include "ui/graphical/menu/widgets/clickablewidget.h"
#include "utility/autosurface.h"
#include "utility/signal/signal.h"
#include "unifonts.h"
#include "utility/unifonts.h"
#include "sound.h"
enum class ePushButtonType
......
......@@ -44,6 +44,7 @@ cLobbyChatBoxListViewItem::cLobbyChatBoxListViewItem (const std::string& prefix,
cAbstractListViewItem (cPosition (50, 0))
{
int prefixTextWidth;
auto font = cUnicodeFont::font.get();
if (!prefix.empty ())
{
const auto prefixText = addColon ? prefix + lngPack.i18n ("Text~Punctuation~Colon") : prefix;
......@@ -108,4 +109,4 @@ void cLobbyChatBoxListViewItem::setDesiredPrefixLabelWidth (int width)
messageLabel->setConsumeClick (false);
fitToChildren ();
}
\ No newline at end of file
}
......@@ -34,6 +34,8 @@ cReportDisadvantagesListViewItem::cReportDisadvantagesListViewItem (const cStati
unitId (data.ID),
disadvantages (disadvantages_)
{
auto font = cUnicodeFont::font.get();
const auto totalHeight = std::max (unitImageHeight, (int) (disadvantages.size() / maxItemsInRow + 1) * font->getFontHeight());
AutoSurface unitSurface (SDL_CreateRGBSurface (0, unitImageWidth, unitImageHeight, Video.getColDepth(), 0, 0, 0, 0));
......
......@@ -23,9 +23,9 @@
//------------------------------------------------------------------------------
cTextListViewItem::cTextListViewItem (const std::string& text) :
cAbstractListViewItem (cPosition (50, font->getFontHeight (FONT_LATIN_NORMAL)))
cAbstractListViewItem (cPosition (50, cUnicodeFont::font->getFontHeight (FONT_LATIN_NORMAL)))
{
label = addChild (std::make_unique<cLabel> (cBox<cPosition> (cPosition (0, 0), cPosition (getSize().x() - 1, font->getFontHeight (FONT_LATIN_NORMAL))), text));
label = addChild (std::make_unique<cLabel> (cBox<cPosition> (cPosition (0, 0), cPosition (getSize().x() - 1, cUnicodeFont::font->getFontHeight (FONT_LATIN_NORMAL))), text));
label->setConsumeClick (false);
}
......
......@@ -26,7 +26,7 @@
#include "ui/graphical/menu/dialogs/dialogok.h"
#include "ui/graphical/game/widgets/turntimeclockwidget.h"
#include "ui/graphical/application.h"
#include "pcx.h"
#include "utility/pcx.h"
#include "game/data/units/vehicle.h"
#include "game/data/player/player.h"
#include "game/data/units/unitdata.h"
......
......@@ -28,7 +28,7 @@
#include "ui/graphical/menu/dialogs/dialogok.h"
#include "ui/graphical/game/widgets/turntimeclockwidget.h"
#include "ui/graphical/application.h"
#include "pcx.h"
#include "utility/pcx.h"
#include "game/data/units/building.h"
#include "game/data/player/player.h"
#include "game/data/map/mapview.h"
......
......@@ -19,7 +19,7 @@
#include "ui/graphical/menu/windows/windowclanselection/windowclanselection.h"
#include "main.h"
#include "pcx.h"
#include "utility/pcx.h"
#include "game/data/player/clans.h"
#include "ui/graphical/menu/widgets/label.h"
#include "ui/graphical/menu/widgets/pushbutton.h"
......
......@@ -20,7 +20,7 @@
#include "ui/graphical/menu/windows/windowgamesettings/windowgamesettings.h"
#include "game/data/gamesettings.h"
#include "main.h"
#include "pcx.h"
#include "utility/pcx.h"
#include "ui/graphical/application.h"
#include "ui/graphical/menu/widgets/label.h"
#include "ui/graphical/menu/widgets/pushbutton.h"
......
......@@ -191,7 +191,7 @@ void cWindowLandingPositionSelection::handleActivated (cApplication& application
//------------------------------------------------------------------------------
void cWindowLandingPositionSelection::handleDeactivated (cApplication& application, bool removed)
{
application.removeRunnable (*animationTimer);
application.removeRunnable (animationTimer);
cWindow::handleDeactivated (application, removed);
if (removed) closed();
}
......
......@@ -19,7 +19,7 @@
#include "ui/graphical/menu/windows/windowlandingunitselection/windowlandingunitselection.h"
#include "main.h"
#include "pcx.h"
#include "utility/pcx.h"
#include "game/data/player/player.h"
#include "game/data/units/landingunit.h"
#include "ui/graphical/menu/widgets/label.h"
......
......@@ -24,7 +24,7 @@
#include "ui/graphical/game/widgets/turntimeclockwidget.h"
#include "ui/graphical/application.h"
#include "ui/graphical/menu/dialogs/dialogok.h"
#include "pcx.h"
#include "utility/pcx.h"
#include "main.h"
#include "utility/log.h"
#include "utility/files.h"
......
......@@ -20,7 +20,7 @@
#include <functional>
#include "ui/graphical/menu/windows/windowmain.h"
#include "pcx.h"
#include "utility/pcx.h"
#include "main.h"
#include "game/data/units/building.h"
#include "game/data/units/vehicle.h"
......
......@@ -19,7 +19,7 @@
#include "ui/graphical/menu/windows/windowmapselection/windowmapselection.h"
#include "main.h"
#include "pcx.h"
#include "utility/pcx.h"
#include "utility/files.h"
#include "game/data/map/map.h"
#include "utility/autosurface.h"
......@@ -140,6 +140,7 @@ void cWindowMapSelection::updateUpDownLocked()
//------------------------------------------------------------------------------
void cWindowMapSelection::updateMaps()
{
auto* font = cUnicodeFont::font.get();
for (size_t i = 0; i < mapCount; ++i)
{
const auto mapIndex = page * mapCount + i;
......
......@@ -29,7 +29,7 @@
#include "ui/graphical/menu/widgets/tools/validatorint.h"
#include "ui/graphical/menu/dialogs/dialogcolorpicker.h"
#include "game/data/player/player.h"
#include "pcx.h"
#include "utility/pcx.h"
#include "main.h"
#include "game/data/map/map.h"
#include "video.h"
......@@ -58,7 +58,7 @@ cWindowNetworkLobby::cWindowNetworkLobby (const std::string title, bool disableI
chatList->disableSelectable();
chatList->setBeginMargin (cPosition (12, 12));
chatList->setEndMargin (cPosition (10, 10));
chatList->setScrollOffset (font->getFontHeight() + 3);
chatList->setScrollOffset (cUnicodeFont::font->getFontHeight() + 3);
addChild (std::make_unique<cLabel> (cBox<cPosition> (getPosition() + cPosition (20, 245), getPosition() + cPosition (20 + 170, 245 + 10)), lngPack.i18n ("Text~Title~IP"), FONT_LATIN_NORMAL, eAlignmentType::Left));
addChild (std::make_unique<cLabel> (cBox<cPosition> (getPosition() + cPosition (228, 245), getPosition() + cPosition (228 + 90, 245 + 10)), lngPack.i18n ("Text~Title~Port"), FONT_LATIN_NORMAL, eAlignmentType::Left));
......@@ -206,9 +206,9 @@ void cWindowNetworkLobby::updateMap()
auto mapName = staticMap->getName();
const auto size = staticMap->getSize();
if (font->getTextWide (">" + mapName.substr (0, mapName.length() - 4) + " (" + iToStr (size.x()) + "x" + iToStr (size.y()) + ")<") > 140)
if (cUnicodeFont::font->getTextWide (">" + mapName.substr (0, mapName.length() - 4) + " (" + iToStr (size.x()) + "x" + iToStr (size.y()) + ")<") > 140)
{
while (font->getTextWide (">" + mapName + "... (" + iToStr (size.x()) + "x" + iToStr (size.y()) + ")<") > 140)
while (cUnicodeFont::font->getTextWide (">" + mapName + "... (" + iToStr (size.x()) + "x" + iToStr (size.y()) + ")<") > 140)
{
mapName.erase (mapName.length() - 1, mapName.length());
}
......
......@@ -25,7 +25,7 @@
#include "ui/graphical/menu/widgets/label.h"
#include "ui/graphical/menu/widgets/pushbutton.h"
#include "ui/graphical/menu/widgets/image.h"
#include "pcx.h"
#include "utility/pcx.h"
#include "defines.h"
#include "video.h"
#include "main.h" // lngPack
......
......@@ -31,7 +31,7 @@
#include "ui/graphical/menu/widgets/special/reportunitlistviewitem.h"
#include "ui/graphical/menu/widgets/special/reportdisadvantageslistviewitem.h"
#include "ui/graphical/menu/widgets/special/reportmessagelistviewitem.h"
#include "pcx.h"
#include "utility/pcx.h"
#include "main.h"
#include "game/data/player/player.h"
#include "game/data/units/vehicle.h"
......@@ -74,6 +74,8 @@ cWindowReports::cWindowReports (std::vector<std::shared_ptr<const cPlayer>> play
disadvantagesListDirty (true),
reportsListDirty (true)
{
auto* font = cUnicodeFont::font.get();
auto turnTimeClockWidget = addChild (std::make_unique<cTurnTimeClockWidget> (cBox<cPosition> (cPosition (527, 17), cPosition (527 + 57, 17 + 10))));
turnTimeClockWidget->setTurnTimeClock (std::move (turnTimeClock));
......
......@@ -18,7 +18,7 @@
***************************************************************************/
#include "ui/graphical/menu/windows/windowresourcedistribution/windowresourcedistribution.h"
#include "pcx.h"
#include "utility/pcx.h"
#include "main.h"
#include "game/data/base/base.h"
#include "ui/graphical/menu/widgets/label.h"
......
......@@ -18,7 +18,7 @@
***************************************************************************/
#include "ui/graphical/menu/windows/windowstorage/windowstorage.h"
#include "pcx.h"
#include "utility/pcx.h"
#include "main.h"
#include "video.h"
#include "game/data/units/unit.h"
......
......@@ -22,7 +22,7 @@
#include "ui/graphical/menu/widgets/label.h"
#include "ui/graphical/menu/widgets/pushbutton.h"
#include "ui/graphical/menu/widgets/special/unitdetails.h"
#include "pcx.h"
#include "utility/pcx.h"
#include "game/data/units/vehicle.h"
#include "game/data/units/building.h"
......
......@@ -23,7 +23,7 @@
#include "ui/graphical/menu/widgets/pushbutton.h"
#include "ui/graphical/menu/widgets/special/resourcebar.h"
#include "ui/graphical/game/widgets/turntimeclockwidget.h"
#include "pcx.h"
#include "utility/pcx.h"
#include "main.h"
#include "game/data/player/player.h"
......
......@@ -39,6 +39,8 @@ struct SdlSurfaceDeleter
}
typedef std::unique_ptr<SDL_Surface, detail::SdlSurfaceDeleter> AutoSurface;
typedef std::unique_ptr<SDL_Surface, detail::SdlSurfaceDeleter> SurfaceUPtr;
typedef std::shared_ptr<SDL_Surface> SurfacePtr;
/* Prevent accidentally freeing the SDL_Surface owned by an AutoSurface */
void SDL_FreeSurface (const AutoSurface&) MAXR_DELETE_FUNCTION;
......
......@@ -37,6 +37,8 @@ public:
cBox();
cBox (const PointType& minCorner, const PointType& maxCorner);
void set(const PointType& minCorner, const PointType& maxCorner);
PointType& getMinCorner();
PointType& getMaxCorner();
......@@ -46,6 +48,12 @@ public:
PointType getSize() const;
void resize (const PointType& newSize);
/**
* Expands a box in all directions
* @param lower - additional size for 'lower' sides
* @param upper - additional size for 'upper' sides
*/
void expand(const PointType& lower, const PointType& upper);
void add (const PointType& point);
void add (const cBox<PointType>& box);
......@@ -99,6 +107,14 @@ cBox<PointType>::cBox (const PointType& minCorner_, const PointType& maxCorner_)
maxCorner (maxCorner_)
{}
//------------------------------------------------------------------------------
template<typename PointType>
void cBox<PointType>::set(const PointType& minCorner_, const PointType& maxCorner_)
{
minCorner = minCorner_;
maxCorner = maxCorner_;
}
//------------------------------------------------------------------------------
template<typename PointType>
PointType& cBox<PointType>::getMinCorner()
......@@ -245,4 +261,16 @@ void cBox<PointType>::fromSdlRect (const SDL_Rect& rect)
maxCorner[1] = rect.y + rect.h - 1;
}
template<typename PointType>
void cBox<PointType>::expand(const PointType &lower, const PointType &upper)
{
auto& min = getMinCorner();
auto& max = getMaxCorner();
for (size_t d = 0; d < PointType::const_size::value; ++d)
{
min[d] -= fabs(lower[d]);
max[d] += fabs(upper[d]);
}