diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Format.cpp | 35 | ||||
| -rw-r--r-- | src/Format.h | 23 | ||||
| -rw-r--r-- | src/Misc.h | 14 | ||||
| -rw-r--r-- | src/game/GameView.cpp | 17 | ||||
| -rw-r--r-- | src/preview/PreviewView.cpp | 3 |
5 files changed, 69 insertions, 23 deletions
diff --git a/src/Format.cpp b/src/Format.cpp new file mode 100644 index 0000000..71a0e9e --- /dev/null +++ b/src/Format.cpp @@ -0,0 +1,35 @@ + +#include <time.h> +#include <string> +#include "Format.h" + +std::string format::UnixtimeToDate(time_t unixtime, std::string dateFormat) +{ + struct tm * timeData; + char buffer[128]; + + timeData = localtime(&unixtime); + + strftime(buffer, 128, dateFormat.c_str(), timeData); + return std::string(buffer); +} + +std::string format::UnixtimeToDateMini(time_t unixtime) +{ + time_t currentTime = time(NULL); + struct tm currentTimeData = *localtime(¤tTime); + struct tm timeData = *localtime(&unixtime); + + if(currentTimeData.tm_year != timeData.tm_year) + { + return UnixtimeToDate(unixtime, "%b %Y"); + } + else if(currentTimeData.tm_mon != timeData.tm_mon || currentTimeData.tm_mday != timeData.tm_mday) + { + return UnixtimeToDate(unixtime, "%d %B"); + } + else + { + return UnixtimeToDate(unixtime, "%H:%M:%S"); + } +} diff --git a/src/Format.h b/src/Format.h new file mode 100644 index 0000000..1df883f --- /dev/null +++ b/src/Format.h @@ -0,0 +1,23 @@ +#pragma once + +#include <sstream> + +namespace format +{ + template <typename T> std::string NumberToString(T number) + { + std::stringstream ss; + ss << number; + return ss.str(); + } + + template <typename T> T StringToNumber(const std::string & text) + { + std::stringstream ss(text); + T number; + return (ss >> number)?number:0; + } + + std::string UnixtimeToDate(time_t unixtime, std::string dateFomat = "%d %b %Y"); + std::string UnixtimeToDateMini(time_t unixtime); +}
\ No newline at end of file @@ -83,20 +83,6 @@ void RGB_to_HSV(int r,int g,int b,int *h,int *s,int *v); void OpenURI(std::string uri); -template <typename T> std::string NumberToString(T number) -{ - std::stringstream ss; - ss << number; - return ss.str(); -} - -template <typename T> T StringToNumber(const std::string & text) -{ - std::stringstream ss(text); - T number; - return (ss >> number)?number:0; -} - void membwand(void * dest, void * src, size_t destsize, size_t srcsize); // a b // c d diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index b0736b4..838f733 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -12,6 +12,7 @@ #include "interface/Slider.h" #include "search/Thumbnail.h" #include "simulation/SaveRenderer.h" +#include "Format.h" #include "QuickOption.h" GameView::GameView(): @@ -603,10 +604,10 @@ void GameView::NotifyColourSelectorColourChanged(GameModel * sender) { std::string intR, intG, intB, intA; - intR = NumberToString<int>(sender->GetColourSelectorColour().Red); - intG = NumberToString<int>(sender->GetColourSelectorColour().Green); - intB = NumberToString<int>(sender->GetColourSelectorColour().Blue); - intA = NumberToString<int>(sender->GetColourSelectorColour().Alpha); + intR = format::NumberToString<int>(sender->GetColourSelectorColour().Red); + intG = format::NumberToString<int>(sender->GetColourSelectorColour().Green); + intB = format::NumberToString<int>(sender->GetColourSelectorColour().Blue); + intA = format::NumberToString<int>(sender->GetColourSelectorColour().Alpha); colourRSlider->SetValue(sender->GetColourSelectorColour().Red); colourRSlider->SetColour(ui::Colour(0, 0, 0), ui::Colour(255, 0, 0)); @@ -1318,10 +1319,10 @@ void GameView::changeColourSlider() void GameView::changeColourText() { c->SetColour(ui::Colour( - std::min(255U, StringToNumber<unsigned int>(colourRValue->GetText())), - std::min(255U, StringToNumber<unsigned int>(colourGValue->GetText())), - std::min(255U, StringToNumber<unsigned int>(colourBValue->GetText())), - std::min(255U, StringToNumber<unsigned int>(colourAValue->GetText()))) + std::min(255U, format::StringToNumber<unsigned int>(colourRValue->GetText())), + std::min(255U, format::StringToNumber<unsigned int>(colourGValue->GetText())), + std::min(255U, format::StringToNumber<unsigned int>(colourBValue->GetText())), + std::min(255U, format::StringToNumber<unsigned int>(colourAValue->GetText()))) ); } diff --git a/src/preview/PreviewView.cpp b/src/preview/PreviewView.cpp index f6c74b4..d134568 100644 --- a/src/preview/PreviewView.cpp +++ b/src/preview/PreviewView.cpp @@ -15,6 +15,7 @@ #include "interface/Window.h" #include "interface/Textbox.h" #include "Style.h" +#include "Format.h" #include "search/Thumbnail.h" #include "client/Client.h" #include "interface/ScrollPanel.h" @@ -316,7 +317,7 @@ void PreviewView::NotifySaveChanged(PreviewModel * sender) votesUp = save->votesUp; votesDown = save->votesDown; saveNameLabel->SetText(save->name); - authorDateLabel->SetText("\bgAuthor:\bw " + save->userName + " \bgDate:\bw "); + authorDateLabel->SetText("\bgAuthor:\bw " + save->userName + " \bgDate:\bw " + format::UnixtimeToDateMini(save->date)); saveDescriptionLabel->SetText(save->Description); if(save->Favourite) favButton->Enabled = false; |
