1 /*
2 * This file is part of EasyRPG Player.
3 *
4 * EasyRPG Player is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * EasyRPG Player is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifndef EP_DRAWABLE_H
19 #define EP_DRAWABLE_H
20
21 #include <cstdint>
22 #include <memory>
23
24 class Bitmap;
25 class Drawable;
26
27 template <typename T>
28 static constexpr bool IsDrawable = std::is_base_of<Drawable,T>::value;
29
30 enum Priority {
31 Priority_Background = 5 << 24,
32 Priority_TilesetBelow = 10 << 24,
33 Priority_EventsBelow = 15 << 24,
34 Priority_Player = 20 << 24, // In Map, shared with "same as hero" events
35 Priority_Battler = 20 << 24, // In Battle (includes animations)
36 Priority_TilesetAbove = 25 << 24,
37 Priority_EventsAbove = 30 << 24,
38 Priority_EventsFlying = 35 << 24,
39 Priority_Weather = 36 << 24,
40 Priority_Screen = 40 << 24,
41 Priority_PictureNew = 45 << 24, // Pictures in RPG2k Value! and RPG2k3 >=1.05, shared
42 Priority_BattleAnimation = 50 << 24,
43 Priority_PictureOld = 55 << 24, // Picture in RPG2k <1.5 and RPG2k3 <1.05, shared
44 Priority_Window = 60 << 24,
45 Priority_Timer = 65 << 24,
46 Priority_Frame = 70 << 24,
47 Priority_Transition = 75 << 24,
48 Priority_Overlay = 80 << 24,
49 Priority_Maximum = 100 << 24
50 };
51
52 /**
53 * Drawable virtual
54 */
55 class Drawable {
56 public:
57 /** Flags with dictate certain attributes of drawables */
58 enum class Flags : uint32_t {
59 /** No flags */
60 None = 0,
61 /** This is a global drawable which will appear in all scenes */
62 Global = 1,
63 /** This is a shared drawable which will appear in all scenes that use shared drawables */
64 Shared = 2,
65 /** This flag indicates the drawable should not be drawn */
66 Invisible = 4,
67 /** The default flag set */
68 Default = None
69 };
70
71 Drawable(int z, Flags flags = Flags::Default);
72
73 Drawable(const Drawable&) = delete;
74 Drawable& operator=(const Drawable&) = delete;
75
76 virtual ~Drawable();
77
78 virtual void Draw(Bitmap& dst) = 0;
79
80 int GetZ() const;
81
82 void SetZ(int z);
83
84 /* @return true if this drawable should appear in all scenes */
85 bool IsGlobal() const;
86
87 /* @return true if this drawable should appear in all scenes that use shared drawables */
88 bool IsShared() const;
89
90 /* @return true if the drawable is currently visible */
91 bool IsVisible() const;
92
93 /**
94 * Set if the drawable should be visisble
95 *
96 * @param value whether is visible or not.
97 */
98 void SetVisible(bool value);
99
100 /**
101 * Converts a RPG Maker map layer value into a EasyRPG priority value.
102 *
103 * @return Priority or 0 when not found
104 */
105 static int GetPriorityForMapLayer(int which);
106
107 /**
108 * Converts a RPG Maker battle layer value into a EasyRPG priority value.
109 *
110 * @return Priority or 0 when not found
111 */
112 static int GetPriorityForBattleLayer(int which);
113 private:
114 int32_t _z = 0;
115 Flags _flags = Flags::Default;
116 };
117
118 inline Drawable::Flags operator|(Drawable::Flags l, Drawable::Flags r) {
119 return static_cast<Drawable::Flags>(static_cast<unsigned>(l) | static_cast<unsigned>(r));
120 }
121
122 inline Drawable::Flags operator&(Drawable::Flags l, Drawable::Flags r) {
123 return static_cast<Drawable::Flags>(static_cast<unsigned>(l) & static_cast<unsigned>(r));
124 }
125
126 inline Drawable::Flags operator^(Drawable::Flags l, Drawable::Flags r) {
127 return static_cast<Drawable::Flags>(static_cast<unsigned>(l) ^ static_cast<unsigned>(r));
128 }
129
130 inline Drawable::Flags operator~(Drawable::Flags f) {
131 return static_cast<Drawable::Flags>(~static_cast<unsigned>(f));
132 }
133
Drawable(int z,Flags flags)134 inline Drawable::Drawable(int z, Flags flags)
135 : _z(z),
136 _flags(flags)
137 {
138 }
139
GetZ()140 inline int Drawable::GetZ() const {
141 return _z;
142 }
143
IsGlobal()144 inline bool Drawable::IsGlobal() const {
145 return static_cast<bool>(_flags & Flags::Global);
146 }
147
IsShared()148 inline bool Drawable::IsShared() const {
149 return static_cast<bool>(_flags & Flags::Shared);
150 }
151
IsVisible()152 inline bool Drawable::IsVisible() const {
153 return !static_cast<bool>(_flags & Flags::Invisible);
154 }
155
SetVisible(bool value)156 inline void Drawable::SetVisible(bool value) {
157 _flags = value ? _flags & ~Flags::Invisible : _flags | Flags::Invisible;
158 }
159
160 #endif
161