Skip to content

Commit

Permalink
msvc min/max fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob1 committed Apr 23, 2017
1 parent f9b512a commit 6d6a615
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 11 deletions.
9 changes: 5 additions & 4 deletions src/Misc.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/client/GameSave.cpp
@@ -1,3 +1,4 @@
#include "common/tpt-minmax.h"
#include <iostream>
#include <sstream>
#include <cmath>
Expand Down
36 changes: 36 additions & 0 deletions 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 <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
9 changes: 5 additions & 4 deletions src/gui/game/GameModel.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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));

Expand Down
1 change: 1 addition & 0 deletions src/gui/interface/ContextMenu.cpp
@@ -1,4 +1,5 @@
#include "ContextMenu.h"
#include "common/tpt-minmax.h"

using namespace ui;

Expand Down
1 change: 1 addition & 0 deletions src/gui/interface/ProgressBar.cpp
@@ -1,4 +1,5 @@
#include "ProgressBar.h"
#include "common/tpt-minmax.h"
#include "gui/Style.h"

using namespace ui;
Expand Down
1 change: 1 addition & 0 deletions src/gui/interface/ScrollPanel.cpp
@@ -1,5 +1,6 @@
#include <iostream>
#include "ScrollPanel.h"
#include "common/tpt-minmax.h"

using namespace ui;

Expand Down
3 changes: 2 additions & 1 deletion src/gui/preview/PreviewModel.cpp
Expand Up @@ -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"

Expand Down Expand Up @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions src/gui/search/SearchModel.h
Expand Up @@ -3,6 +3,7 @@

#include <vector>
#include <string>
#include "common/tpt-minmax.h"
#include "common/tpt-thread.h"
#include <cmath>
#include "client/SaveInfo.h"
Expand Down Expand Up @@ -63,9 +64,9 @@ class SearchModel
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; }
Expand Down
1 change: 1 addition & 0 deletions src/tasks/TaskWindow.cpp
@@ -1,4 +1,5 @@
#include <sstream>
#include "common/tpt-minmax.h"
#include "gui/interface/Label.h"
#include "TaskWindow.h"
#include "gui/dialogues/ErrorMessage.h"
Expand Down

0 comments on commit 6d6a615

Please sign in to comment.