msvc min/max fixes

This commit is contained in:
jacob1 2017-04-23 12:30:27 -04:00
parent f9b512a502
commit 6d6a615a37
10 changed files with 56 additions and 11 deletions

View File

@ -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;

View File

@ -1,3 +1,4 @@
#include "common/tpt-minmax.h"
#include <iostream>
#include <sstream>
#include <cmath>

36
src/common/tpt-minmax.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#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 <algorithm>
#define NOMINMAX
#endif
#else
// not using visual studio, std::min and std::max are normal
#include <algorithm>
#endif
#endif

View File

@ -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));

View File

@ -1,4 +1,5 @@
#include "ContextMenu.h"
#include "common/tpt-minmax.h"
using namespace ui;

View File

@ -1,4 +1,5 @@
#include "ProgressBar.h"
#include "common/tpt-minmax.h"
#include "gui/Style.h"
using namespace ui;

View File

@ -1,5 +1,6 @@
#include <iostream>
#include "ScrollPanel.h"
#include "common/tpt-minmax.h"
using namespace ui;

View File

@ -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()

View File

@ -3,6 +3,7 @@
#include <vector>
#include <string>
#include "common/tpt-minmax.h"
#include "common/tpt-thread.h"
#include <cmath>
#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; }

View File

@ -1,4 +1,5 @@
#include <sstream>
#include "common/tpt-minmax.h"
#include "gui/interface/Label.h"
#include "TaskWindow.h"
#include "gui/dialogues/ErrorMessage.h"