blob: 11c8fb96bd473b0f2e20197e9d2b3350d16fdfc3 (
plain)
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
81
82
83
84
|
#include "stdafx.h"
#include "Stitcher.h"
#include "Texture.h"
#include "..\Minecraft.World\StringHelpers.h"
#include "TextureHolder.h"
TextureHolder::TextureHolder(Texture *texture)
{
scale = 1.0f;
this->texture = texture;
this->width = texture->getWidth();
this->height = texture->getHeight();
this->rotated = smallestFittingMinTexel(height) > smallestFittingMinTexel(width);
}
Texture *TextureHolder::getTexture()
{
return texture;
}
int TextureHolder::getWidth() const
{
return rotated ? smallestFittingMinTexel(static_cast<int>(height * scale)) : smallestFittingMinTexel(static_cast<int>(width * scale));
}
int TextureHolder::getHeight() const
{
return rotated ? smallestFittingMinTexel(static_cast<int>(width * scale)) : smallestFittingMinTexel(static_cast<int>(height * scale));
}
void TextureHolder::rotate()
{
rotated = !rotated;
}
bool TextureHolder::isRotated()
{
return rotated;
}
int TextureHolder::smallestFittingMinTexel(int input) const
{
return ((input >> Stitcher::MAX_MIPLEVEL) + ((input & (Stitcher::MIN_TEXEL - 1)) == 0 ? 0 : 1)) << Stitcher::MAX_MIPLEVEL;
}
void TextureHolder::setForcedScale(int targetSize)
{
if (width <= targetSize || height <= targetSize)
{
return;
}
scale = static_cast<float>(targetSize) / min(width, height);
}
//@Override
wstring TextureHolder::toString()
{
return L"TextureHolder{width=" + std::to_wstring(width) + L", height=" + std::to_wstring(height) + L'}';
}
int TextureHolder::compareTo(const TextureHolder *other) const
{
int result = 0;
if (this->getHeight() == other->getHeight())
{
if (this->getWidth() == other->getWidth())
{
if (texture->getName().empty())
{
return other->texture->getName().empty() ? 0 : -1;
}
return texture->getName().compare(other->texture->getName());
}
result = this->getWidth() < other->getWidth() ? 1 : -1;
}
else
{
result = this->getHeight() < other->getHeight() ? 1 : -1;
}
return result;
}
|