1 /*
2  * tiled.h
3  * Copyright 2013, Thorbjørn Lindeijer <thorbjorn@lindeijer.nl>
4  *
5  * This file is part of libtiled.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  *    1. Redistributions of source code must retain the above copyright notice,
11  *       this list of conditions and the following disclaimer.
12  *
13  *    2. Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in the
15  *       documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
20  * EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #pragma once
30 
31 #include "tiled_global.h"
32 
33 #include <QColor>
34 #include <QMetaType>
35 #include <QRectF>
36 #include <QString>
37 #include <QUrl>
38 
39 class QDir;
40 
41 namespace Tiled {
42 
43 enum FlipDirection {
44     FlipHorizontally,
45     FlipVertically
46 };
47 
48 enum RotateDirection {
49     RotateLeft,
50     RotateRight
51 };
52 
53 enum Alignment {
54     Unspecified,
55     TopLeft,
56     Top,
57     TopRight,
58     Left,
59     Center,
60     Right,
61     BottomLeft,
62     Bottom,
63     BottomRight
64 };
65 
66 enum LoadingStatus {
67     LoadingPending,
68     LoadingReady,
69     LoadingInProgress,
70     LoadingError
71 };
72 
73 const int CHUNK_SIZE = 16;
74 const int CHUNK_BITS = 4;
75 const int CHUNK_SIZE_MIN = 4;
76 const int CHUNK_MASK = CHUNK_SIZE - 1;
77 
78 static const char TILES_MIMETYPE[] = "application/vnd.tile.list";
79 static const char FRAMES_MIMETYPE[] = "application/vnd.frame.list";
80 static const char LAYERS_MIMETYPE[] = "application/vnd.layer.list";
81 static const char PROPERTIES_MIMETYPE[] = "application/vnd.properties.list";
82 
83 TILEDSHARED_EXPORT QPointF alignmentOffset(const QRectF &r, Alignment alignment);
84 
85 TILEDSHARED_EXPORT QString toFileReference(const QUrl &url, const QDir &dir);
86 TILEDSHARED_EXPORT QUrl toUrl(const QString &filePathOrUrl, const QDir &dir);
87 TILEDSHARED_EXPORT QUrl toUrl(const QString &filePathOrUrl);
88 TILEDSHARED_EXPORT QString urlToLocalFileOrQrc(const QUrl &url);
89 
colorToString(const QColor & color)90 inline QString colorToString(const QColor &color)
91 {
92     if (color.alpha() != 255)
93         return color.name(QColor::HexArgb);
94     return color.name();
95 }
96 
maxMargins(const QMargins & a,const QMargins & b)97 inline QMargins maxMargins(const QMargins &a,
98                            const QMargins &b)
99 {
100 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
101     return QMargins(qMax(a.left(), b.left()),
102                     qMax(a.top(), b.top()),
103                     qMax(a.right(), b.right()),
104                     qMax(a.bottom(), b.bottom()));
105 #else
106     return a | b;
107 #endif
108 }
109 
110 TILEDSHARED_EXPORT QString alignmentToString(Alignment);
111 TILEDSHARED_EXPORT Alignment alignmentFromString(const QString &);
112 
113 } // namespace Tiled
114 
115 Q_DECLARE_METATYPE(Tiled::Alignment);
116