Windows time crashes were caused by unsupported %r parameter. Added

timeFormat attribute to the reloadableText layout element, with a default of
%H:%M (<24 hour>:<minutes>).
This commit is contained in:
Pieter Hulshoff
2016-06-03 10:07:10 +02:00
parent 382edc61f8
commit 4b05992a19
3 changed files with 12 additions and 4 deletions

View File

@@ -24,7 +24,7 @@
#include <iostream> #include <iostream>
#include <time.h> #include <time.h>
ReloadableText::ReloadableText(std::string type, Page &page, Configuration &config, Font *font, std::string layoutKey, float scaleX, float scaleY) ReloadableText::ReloadableText(std::string type, Page &page, Configuration &config, Font *font, std::string layoutKey, std::string timeFormat, float scaleX, float scaleY)
: Component(page) : Component(page)
, config_(config) , config_(config)
, imageInst_(NULL) , imageInst_(NULL)
@@ -33,6 +33,7 @@ ReloadableText::ReloadableText(std::string type, Page &page, Configuration &conf
, reloadRequested_(false) , reloadRequested_(false)
, firstLoad_(true) , firstLoad_(true)
, fontInst_(font) , fontInst_(font)
, timeFormat_(timeFormat)
, scaleX_(scaleX) , scaleX_(scaleX)
, scaleY_(scaleY) , scaleY_(scaleY)
{ {
@@ -118,7 +119,7 @@ void ReloadableText::ReloadTexture()
struct tm tstruct; struct tm tstruct;
char buf[80]; char buf[80];
tstruct = *localtime(&now); tstruct = *localtime(&now);
strftime(buf, sizeof(buf), "%r", &tstruct); strftime(buf, sizeof(buf), timeFormat_.c_str(), &tstruct);
ss << buf; ss << buf;
} }
if (type_ == "numberButtons") if (type_ == "numberButtons")

View File

@@ -25,7 +25,7 @@
class ReloadableText : public Component class ReloadableText : public Component
{ {
public: public:
ReloadableText(std::string type, Page &page, Configuration &config, Font *font, std::string layoutKey, float scaleX, float scaleY); ReloadableText(std::string type, Page &page, Configuration &config, Font *font, std::string layoutKey, std::string timeFormat, float scaleX, float scaleY);
virtual ~ReloadableText(); virtual ~ReloadableText();
void update(float dt); void update(float dt);
void draw(); void draw();
@@ -44,6 +44,7 @@ private:
bool reloadRequested_; bool reloadRequested_;
bool firstLoad_; bool firstLoad_;
Font *fontInst_; Font *fontInst_;
std::string timeFormat_;
float scaleX_; float scaleX_;
float scaleY_; float scaleY_;

View File

@@ -403,6 +403,7 @@ void PageBuilder::loadReloadableImages(xml_node<> *layout, std::string tagName,
std::string reloadableVideoPath; std::string reloadableVideoPath;
xml_attribute<> *type = componentXml->first_attribute("type"); xml_attribute<> *type = componentXml->first_attribute("type");
xml_attribute<> *mode = componentXml->first_attribute("mode"); xml_attribute<> *mode = componentXml->first_attribute("mode");
xml_attribute<> *timeFormatXml = componentXml->first_attribute("timeFormat");
xml_attribute<> *selectedOffsetXml = componentXml->first_attribute("selectedOffset"); xml_attribute<> *selectedOffsetXml = componentXml->first_attribute("selectedOffset");
bool systemMode = false; bool systemMode = false;
int selectedOffset = 0; int selectedOffset = 0;
@@ -446,7 +447,12 @@ void PageBuilder::loadReloadableImages(xml_node<> *layout, std::string tagName,
if(type) if(type)
{ {
Font *font = addFont(componentXml, NULL); Font *font = addFont(componentXml, NULL);
c = new ReloadableText(type->value(), *page, config_, font, layoutKey, scaleX_, scaleY_); std::string timeFormat = "%H:%M";
if (timeFormatXml)
{
timeFormat = timeFormatXml->value();
}
c = new ReloadableText(type->value(), *page, config_, font, layoutKey, timeFormat, scaleX_, scaleY_);
} }
} }
else else