-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUtilities.cpp
More file actions
80 lines (72 loc) · 2.74 KB
/
Utilities.cpp
File metadata and controls
80 lines (72 loc) · 2.74 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
69
70
71
72
73
74
75
76
77
78
79
80
#include "Utilities.h"
#include <string>
#include <map>
namespace SpriteLab
{
std::string SpriteLab::ToolToString(Tools tool) {
static const std::map<Tools, std::string> toolToString = {
{PaintBrush, "PaintBrush"},
{PaintBucket, "PaintBucket"},
{Eraser, "Eraser"},
{EyeDropper, "EyeDropper"},
{Line, "Line"}
};
auto it = toolToString.find(tool);
return (it != toolToString.end()) ? it->second : "Unknown";
}
Tools SpriteLab::StringToTool(const std::string& str) {
static const std::map<std::string, Tools> stringToTool = {
{"PaintBrush", PaintBrush},
{"PaintBucket", PaintBucket},
{"Eraser", Eraser},
{"EyeDropper", EyeDropper},
{"Line", Line}
};
auto it = stringToTool.find(str);
return (it != stringToTool.end()) ? it->second : PaintBrush;
}
bool SpriteLab::CompareColor(SDL_Color color1, SDL_Color color2, bool ignoreAlpha)
{
if (ignoreAlpha) return (color1.r == color2.r && color1.g == color2.g && color1.b == color2.b);
else return (color1.r == color2.r && color1.g == color2.g && color1.b == color2.b && color1.a == color2.a);
return false;
}
void SpriteLab::SetBrushColour(Project* project, Brush* brush, SDL_Color colour)
{
if (colour.a < 10) colour.a = 10;
if (CompareColor(colour, brush->colour, true))
{
if (colour.a != brush->colour.a) brush->colour.a = colour.a;
return;
}
project->recentColours.erase(
std::remove_if(project->recentColours.begin(), project->recentColours.end(),
[&](const SDL_Color& recentColour) {
return CompareColor(colour, recentColour, true);
}),
project->recentColours.end());
if (project->recentColours.size() >= 6)
{
for (int i = 0; i < 5; i++)
project->recentColours[i + 1] = project->recentColours[i];
project->recentColours[0] = colour;
}
else project->recentColours.insert(project->recentColours.begin(), brush->colour);
brush->colour = colour;
}
void SpriteLab::SaveProjectPopup()
{
int result = MessageBox(nullptr, savePopupMessage, L"SpriteLab", MB_YESNOCANCEL | MB_ICONWARNING | MB_SYSTEMMODAL);
switch (result) {
case IDYES:
savePopupButtonClicked = "Yes";
break;
case IDNO:
savePopupButtonClicked = "No";
break;
case IDCANCEL:
savePopupButtonClicked = "Cancel";
break;
}
}
}