-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathShelfPacker.cpp
More file actions
46 lines (39 loc) · 965 Bytes
/
Copy pathShelfPacker.cpp
File metadata and controls
46 lines (39 loc) · 965 Bytes
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
#include "ShelfPacker.h"
namespace sh::render
{
ShelfPacker::ShelfPacker(int texW, int texH, int padding)
{
this->texW = texW; this->texH = texH;
this->padding = padding;
cursorX = 0;
cursorY = 0;
shelfH = 0;
}
SH_RENDER_API void ShelfPacker::Reset()
{
cursorX = 0;
cursorY = 0;
shelfH = 0;
}
SH_RENDER_API auto ShelfPacker::Alloc(int w, int h, int& outX, int& outY) -> bool
{
w += padding * 2;
h += padding * 2;
if (w > texW || h > texH)
return false;
if (cursorX + w > texW)
{
cursorX = 0;
cursorY += shelfH;
shelfH = 0;
}
if (cursorY + h > texH)
return false;
outX = cursorX + padding;
outY = cursorY + padding;
cursorX += w;
if (h > shelfH)
shelfH = h;
return true;
}
}//namespace