-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiscUtils.cpp
More file actions
68 lines (58 loc) · 1.15 KB
/
Copy pathMiscUtils.cpp
File metadata and controls
68 lines (58 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "MiscUtils.h"
std::vector<std::string> MiscUtils::explode(std::string str, std::string delim)
{
std::vector<std::string> fragments;
size_t found = 0;
size_t delim_sz = delim.size();
while((found = str.find(delim)) != std::string::npos)
{
fragments.push_back(str.substr(0, found));
str = str.substr(found+delim_sz);
}
fragments.push_back(str);
return fragments;
}
bool MiscUtils::is_flag_set(int flag, int& bits)
{
return (bits & (1 << flag)) != 0;
}
void MiscUtils::set_flag(int flag, int& bits)
{
bits |= 1 << flag;
}
void MiscUtils::unset_flag(int flag, int& bits)
{
bits &= ~(1 << flag);
}
int MiscUtils::max(int n1, int n2)
{
if(n1 >= n2)
{
return n1;
}
else
{
return n2;
}
}
int MiscUtils::min(int n1, int n2)
{
if(n1 <= n2)
{
return n1;
}
else
{
return n2;
}
}
void MiscUtils::fill_rect(sf::Image& img, const sf::FloatRect& rect, sf::Color color)
{
for(unsigned int x = (unsigned int) rect.left; x < rect.left + rect.width; x++)
{
for(unsigned int y = (unsigned int) rect.top; y< rect.top + rect.width; y++)
{
img.setPixel(x,y, color);
}
}
}