-
Notifications
You must be signed in to change notification settings - Fork 0
/
texture_atlas.h
64 lines (47 loc) · 1.23 KB
/
texture_atlas.h
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
/*
* homm3-wallpaper, live HOMM3 wallpaper
* Copyright (C) 2022 i.Dark_Templar <[email protected]>
*
* Subject to terms and condition provided in LICENSE.txt
*
*/
#pragma once
#include <stddef.h>
#include <list>
#include <map>
#include <string>
#include <utility>
#include <QtCore/QRect>
#define tile_size 32
struct TextureItem
{
std::string name;
int group = 0;
int frame = 0;
int special = -1; // player color or ground frame
TextureItem() = default;
explicit TextureItem(const std::string &l_name, int l_group = 0, int l_frame = 0, int l_special = -1);
bool operator<(const TextureItem &other) const;
};
class TextureAtlas
{
public:
TextureAtlas();
void insertItem(const TextureItem &item, const QSize &size);
bool itemIsPresent(const TextureItem &item) const;
QRect findItem(const TextureItem &item) const;
size_t getSize() const;
std::pair<std::map<TextureItem, QRect>::const_iterator, std::map<TextureItem, QRect>::const_iterator> getAllItems() const;
void clear();
private:
struct Line
{
size_t line_height = 0;
size_t line_y = 0;
size_t current_width = 0;
};
size_t m_size;
size_t m_current_height;
std::list<Line> m_current_lines;
std::map<TextureItem, QRect> m_texture_items;
};