diff --git a/src/Misc.cpp b/src/Misc.cpp index dee14ac57..ec3e3fba6 100644 --- a/src/Misc.cpp +++ b/src/Misc.cpp @@ -6,6 +6,7 @@ #include "Config.h" #include "Misc.h" #include "icondoc.h" +#include "common/tpt-minmax.h" //Signum function int isign(float i) //TODO: INline or macro @@ -252,10 +253,10 @@ void RGB_to_HSV(int r,int g,int b,int *h,int *s,int *v)//convert 0-255 RGB value rr = r/255.0f;//normalize values gg = g/255.0f; bb = b/255.0f; - a = fmin(rr,gg); - a = fmin(a,bb); - x = fmax(rr,gg); - x = fmax(x,bb); + a = std::min(rr,gg); + a = std::min(a,bb); + x = std::max(rr,gg); + x = std::max(x,bb); if (a==x)//greyscale { *h = 0; diff --git a/src/client/GameSave.cpp b/src/client/GameSave.cpp index 80461eee8..9959c34bb 100644 --- a/src/client/GameSave.cpp +++ b/src/client/GameSave.cpp @@ -1,3 +1,4 @@ +#include "common/tpt-minmax.h" #include #include #include diff --git a/src/common/tpt-minmax.h b/src/common/tpt-minmax.h new file mode 100644 index 000000000..cda40535a --- /dev/null +++ b/src/common/tpt-minmax.h @@ -0,0 +1,36 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef TPT_MINMAX_H +#define TPT_MINMAX_H + +#ifdef _MSC_VER +// less than VS2013. Untested since I don't use VS2012 anymore +#if _MSC_VER < 1800 +#define fmin min +#define fminf min +#define fmax max +#define fmaxf max +#else +// >= VS2013 +#include +#define NOMINMAX +#endif +#else +// not using visual studio, std::min and std::max are normal +#include +#endif + +#endif diff --git a/src/gui/game/GameModel.cpp b/src/gui/game/GameModel.cpp index dc67f0b35..56af988a0 100644 --- a/src/gui/game/GameModel.cpp +++ b/src/gui/game/GameModel.cpp @@ -13,6 +13,7 @@ #include "client/Client.h" #include "client/GameSave.h" #include "client/SaveFile.h" +#include "common/tpt-minmax.h" #include "gui/game/DecorationTool.h" #include "QuickOptions.h" #include "GameModelException.h" @@ -119,10 +120,10 @@ GameModel::GameModel(): } //Set default decoration colour - unsigned char colourR = min(Client::Ref().GetPrefInteger("Decoration.Red", 200), 255); - unsigned char colourG = min(Client::Ref().GetPrefInteger("Decoration.Green", 100), 255); - unsigned char colourB = min(Client::Ref().GetPrefInteger("Decoration.Blue", 50), 255); - unsigned char colourA = min(Client::Ref().GetPrefInteger("Decoration.Alpha", 255), 255); + unsigned char colourR = std::min(Client::Ref().GetPrefInteger("Decoration.Red", 200), 255); + unsigned char colourG = std::min(Client::Ref().GetPrefInteger("Decoration.Green", 100), 255); + unsigned char colourB = std::min(Client::Ref().GetPrefInteger("Decoration.Blue", 50), 255); + unsigned char colourA = std::min(Client::Ref().GetPrefInteger("Decoration.Alpha", 255), 255); SetColourSelectorColour(ui::Colour(colourR, colourG, colourB, colourA)); diff --git a/src/gui/interface/ContextMenu.cpp b/src/gui/interface/ContextMenu.cpp index 61833cfee..9efd4834c 100644 --- a/src/gui/interface/ContextMenu.cpp +++ b/src/gui/interface/ContextMenu.cpp @@ -1,4 +1,5 @@ #include "ContextMenu.h" +#include "common/tpt-minmax.h" using namespace ui; diff --git a/src/gui/interface/ProgressBar.cpp b/src/gui/interface/ProgressBar.cpp index e94c1b02a..7b29609b2 100644 --- a/src/gui/interface/ProgressBar.cpp +++ b/src/gui/interface/ProgressBar.cpp @@ -1,4 +1,5 @@ #include "ProgressBar.h" +#include "common/tpt-minmax.h" #include "gui/Style.h" using namespace ui; diff --git a/src/gui/interface/ScrollPanel.cpp b/src/gui/interface/ScrollPanel.cpp index 46c9f39f3..5aa803133 100644 --- a/src/gui/interface/ScrollPanel.cpp +++ b/src/gui/interface/ScrollPanel.cpp @@ -1,5 +1,6 @@ #include #include "ScrollPanel.h" +#include "common/tpt-minmax.h" using namespace ui; diff --git a/src/gui/preview/PreviewModel.cpp b/src/gui/preview/PreviewModel.cpp index f4b95986e..e98f785d5 100644 --- a/src/gui/preview/PreviewModel.cpp +++ b/src/gui/preview/PreviewModel.cpp @@ -3,6 +3,7 @@ #include "Format.h" #include "client/Client.h" #include "client/GameSave.h" +#include "common/tpt-minmax.h" #include "gui/dialogues/ErrorMessage.h" #include "PreviewModelException.h" @@ -124,7 +125,7 @@ int PreviewModel::GetCommentsPageNum() int PreviewModel::GetCommentsPageCount() { - return max(1, (int)(ceil(commentsTotal/20.0f))); + return std::max(1, (int)(ceil(commentsTotal/20.0f))); } bool PreviewModel::GetCommentsLoaded() diff --git a/src/gui/search/SearchModel.h b/src/gui/search/SearchModel.h index bd3b52981..52dc6b0da 100644 --- a/src/gui/search/SearchModel.h +++ b/src/gui/search/SearchModel.h @@ -3,6 +3,7 @@ #include #include +#include "common/tpt-minmax.h" #include "common/tpt-thread.h" #include #include "client/SaveInfo.h" @@ -63,9 +64,9 @@ public: int GetPageCount() { if (!showOwn && !showFavourite && currentSort == "best" && lastQuery == "") - return max(1, (int)(ceil(resultCount/20.0f))+1); //add one for front page (front page saves are repeated twice) + return std::max(1, (int)(ceil(resultCount/20.0f))+1); //add one for front page (front page saves are repeated twice) else - return max(1, (int)(ceil(resultCount/20.0f))); + return std::max(1, (int)(ceil(resultCount/20.0f))); } int GetPageNum() { return currentPage; } std::string GetLastQuery() { return lastQuery; } diff --git a/src/tasks/TaskWindow.cpp b/src/tasks/TaskWindow.cpp index 1e6ce56d5..91ba9e94c 100644 --- a/src/tasks/TaskWindow.cpp +++ b/src/tasks/TaskWindow.cpp @@ -1,4 +1,5 @@ #include +#include "common/tpt-minmax.h" #include "gui/interface/Label.h" #include "TaskWindow.h" #include "gui/dialogues/ErrorMessage.h"