mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-29 19:38:27 +02:00
utilities: Replace min/max functions by the versions from STL.
This commit is contained in:
parent
40c510a28a
commit
aea1c44020
@ -3,6 +3,7 @@
|
|||||||
#include "surface.h"
|
#include "surface.h"
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
@ -115,7 +116,7 @@ int ASFont::getTextWidth(const char *text) {
|
|||||||
while (char ch = *text++) {
|
while (char ch = *text++) {
|
||||||
if (ch == '\n') {
|
if (ch == '\n') {
|
||||||
// New line.
|
// New line.
|
||||||
maxWidth = max(width, maxWidth);
|
maxWidth = std::max(width, maxWidth);
|
||||||
width = 0;
|
width = 0;
|
||||||
} else {
|
} else {
|
||||||
std::string::size_type pos;
|
std::string::size_type pos;
|
||||||
@ -133,7 +134,7 @@ int ASFont::getTextWidth(const char *text) {
|
|||||||
width += charpos[pos * 2 + 2] - charpos[pos * 2 + 1];
|
width += charpos[pos * 2 + 2] - charpos[pos * 2 + 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return max(width, maxWidth);
|
return std::max(width, maxWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ASFont::getTextWidth(const std::string& text) {
|
int ASFont::getTextWidth(const std::string& text) {
|
||||||
|
@ -1541,7 +1541,8 @@ void GMenu2X::contextMenu() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool close = false;
|
bool close = false;
|
||||||
uint i, sel=0, fadeAlpha=0;
|
uint i, fadeAlpha=0;
|
||||||
|
int sel = 0;
|
||||||
|
|
||||||
int h = font->getHeight();
|
int h = font->getHeight();
|
||||||
SDL_Rect box;
|
SDL_Rect box;
|
||||||
@ -1624,10 +1625,10 @@ void GMenu2X::contextMenu() {
|
|||||||
close = true;
|
close = true;
|
||||||
break;
|
break;
|
||||||
case InputManager::UP:
|
case InputManager::UP:
|
||||||
sel = max(0, sel-1);
|
sel = std::max(0, sel-1);
|
||||||
break;
|
break;
|
||||||
case InputManager::DOWN:
|
case InputManager::DOWN:
|
||||||
sel = min((int)voices.size()-1, sel+1);
|
sel = std::min((int)voices.size()-1, sel+1);
|
||||||
break;
|
break;
|
||||||
case InputManager::ACCEPT:
|
case InputManager::ACCEPT:
|
||||||
voices[sel].action();
|
voices[sel].action();
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <SDL_gfxPrimitives.h>
|
#include <SDL_gfxPrimitives.h>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
//for browsing the filesystem
|
//for browsing the filesystem
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -102,8 +103,11 @@ int Selector::exec(int startSelection) {
|
|||||||
//Screenshot
|
//Screenshot
|
||||||
if (selected-fl.dirCount()<screens.size() && screens[selected-fl.dirCount()]!="") {
|
if (selected-fl.dirCount()<screens.size() && screens[selected-fl.dirCount()]!="") {
|
||||||
curTick = SDL_GetTicks();
|
curTick = SDL_GetTicks();
|
||||||
if (curTick-selTick>200)
|
if (curTick - selTick > 200) {
|
||||||
gmenu2x->sc[screens[selected-fl.dirCount()]]->blitRight(gmenu2x->s, 311, 42, 160, 160, min((curTick-selTick-200)/3,255));
|
gmenu2x->sc[screens[selected-fl.dirCount()]]->blitRight(
|
||||||
|
gmenu2x->s, 311, 42, 160, 160,
|
||||||
|
min((curTick - selTick - 200) / 3, 255u));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Files & Dirs
|
//Files & Dirs
|
||||||
|
@ -138,7 +138,7 @@ void TextDialog::exec() {
|
|||||||
if (firstRow + rowsPerPage*2 -1 < text->size()) {
|
if (firstRow + rowsPerPage*2 -1 < text->size()) {
|
||||||
firstRow += rowsPerPage-1;
|
firstRow += rowsPerPage-1;
|
||||||
} else {
|
} else {
|
||||||
firstRow = max(0, text->size() - rowsPerPage);
|
firstRow = max(0u, text->size() - rowsPerPage);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case InputManager::SETTINGS:
|
case InputManager::SETTINGS:
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include "gmenu2x.h"
|
#include "gmenu2x.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@ -131,7 +132,7 @@ void TextManualDialog::exec() {
|
|||||||
break;
|
break;
|
||||||
case InputManager::ALTRIGHT:
|
case InputManager::ALTRIGHT:
|
||||||
if (firstRow + rowsPerPage*2 -1 < pages[page].text.size()) firstRow += rowsPerPage-1;
|
if (firstRow + rowsPerPage*2 -1 < pages[page].text.size()) firstRow += rowsPerPage-1;
|
||||||
else firstRow = max(0, pages[page].text.size() - rowsPerPage);
|
else firstRow = max(0u, pages[page].text.size() - rowsPerPage);
|
||||||
break;
|
break;
|
||||||
case InputManager::CANCEL:
|
case InputManager::CANCEL:
|
||||||
case InputManager::SETTINGS:
|
case InputManager::SETTINGS:
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
//for browsing the filesystem
|
//for browsing the filesystem
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -86,14 +87,8 @@ bool rmtree(string path) {
|
|||||||
return rmdir(path.c_str())==0;
|
return rmdir(path.c_str())==0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int max (int a, int b) {
|
int constrain(int x, int imin, int imax) {
|
||||||
return a>b ? a : b;
|
return min(imax, max(imin, x));
|
||||||
}
|
|
||||||
int min (int a, int b) {
|
|
||||||
return a<b ? a : b;
|
|
||||||
}
|
|
||||||
int constrain (int x, int imin, int imax) {
|
|
||||||
return min( imax, max(imin,x) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Configuration parsing utilities
|
//Configuration parsing utilities
|
||||||
|
@ -36,8 +36,6 @@ std::string cmdclean(std::string cmdline);
|
|||||||
bool fileExists(const std::string &file);
|
bool fileExists(const std::string &file);
|
||||||
bool rmtree(std::string path);
|
bool rmtree(std::string path);
|
||||||
|
|
||||||
int max(int a, int b);
|
|
||||||
int min(int a, int b);
|
|
||||||
int constrain(int x, int imin, int imax);
|
int constrain(int x, int imin, int imax);
|
||||||
|
|
||||||
int evalIntConf(int val, int def, int imin, int imax);
|
int evalIntConf(int val, int def, int imin, int imax);
|
||||||
|
Loading…
Reference in New Issue
Block a user