30 #ifndef __SFTOOLS_LOOPFRAMESTREAM_HPP__
31 #define __SFTOOLS_LOOPFRAMESTREAM_HPP__
33 #include <SFML/System/Time.hpp>
176 : m_count(stream.m_count)
177 , m_frameTime(stream.m_frameTime)
178 , m_loop(stream.m_loop)
179 , m_frames(stream.m_frames)
202 sf::Vector2i frameSize,
203 sf::Vector2u frameCount,
208 create(texture, frameSize, frameCount, frameTime, loop, settings);
219 m_count = rhs.m_count;
220 m_frameTime = rhs.m_frameTime;
222 m_frames = rhs.m_frames;
241 sf::Vector2i frameSize,
242 sf::Vector2u frameCount,
248 if (frameCount == sf::Vector2u(0, 0))
throw std::invalid_argument(
"frameCount can't be 0");
249 if (frameTime == sf::Time::Zero)
throw std::invalid_argument(
"frameTime can't be 0");
252 m_count = frameCount.x * frameCount.y;
253 m_frameTime = frameTime;
258 m_frames.reserve(m_count);
263 int const initX = settings.horizontalPolicy ==
FromLeft ? 0 : texture.getSize().x - frameSize.x;
264 int const initY = settings.verticalPolicy ==
FromTop ? 0 : texture.getSize().y - frameSize.y;
265 int const stepX = settings.horizontalPolicy ==
FromLeft ? frameSize.x : -frameSize.x;
266 int const stepY = settings.verticalPolicy ==
FromTop ? frameSize.y : -frameSize.y;
267 int const endX = initX + frameCount.x * stepX;
268 int const endY = initY + frameCount.y * stepY;
277 int const& init1st = settings.precedencePolicy ==
HorizontalFirst ? initX : initY;
278 int const& init2nd = settings.precedencePolicy ==
HorizontalFirst ? initY : initX;
279 int const step1st = settings.precedencePolicy ==
HorizontalFirst ? stepX : stepY;
280 int const step2nd = settings.precedencePolicy ==
HorizontalFirst ? stepY : stepX;
281 int const end1st = settings.precedencePolicy ==
HorizontalFirst ? endX : endY;
282 int const end2nd = settings.precedencePolicy ==
HorizontalFirst ? endY : endX;
285 for (first = init1st; first < end1st; first += step1st)
287 for (second = init2nd; second < end2nd; second += step2nd)
289 sf::Vector2i point(x, y);
290 sf::IntRect area(point, frameSize);
291 m_frames.push_back(
Frame(texture, area));
310 if (m_count == 0)
throw std::runtime_error(
"the stream was not properly initialized");
312 unsigned int frameIndex = time.asMilliseconds() / m_frameTime.asMilliseconds();
314 if (m_loop) frameIndex %= m_count;
315 else frameIndex = std::min(frameIndex, m_count - 1);
317 return m_frames[frameIndex];
322 unsigned int m_count;
323 sf::Time m_frameTime;
327 std::vector<Frame> m_frames;
332 #endif // __SFTOOLS_LOOPFRAMESTREAM_HPP__