Otclient  14/8/2020
animatedtexture.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 OTClient <https://github.com/edubart/otclient>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 #include "animatedtexture.h"
24 #include "graphics.h"
25 
27 
28 AnimatedTexture::AnimatedTexture(const Size& size, std::vector<ImagePtr> frames, std::vector<int> framesDelay, bool buildMipmaps, bool compress)
29 {
30  if(!setupSize(size, buildMipmaps))
31  return;
32 
33  for(const auto &frame: frames) {
34  m_frames.push_back(new Texture(frame, buildMipmaps, compress));
35  }
36 
37  m_framesDelay = framesDelay;
38  m_hasMipmaps = buildMipmaps;
39  m_id = m_frames[0]->getId();
40  m_currentFrame = 0;
41  m_animTimer.restart();
42 }
43 
45 {
46 
47 }
48 
50 {
52  return false;
53  for(const TexturePtr& frame : m_frames)
54  frame->buildHardwareMipmaps();
55  m_hasMipmaps = true;
56  return true;
57 }
58 
59 void AnimatedTexture::setSmooth(bool smooth)
60 {
61  for(const TexturePtr& frame : m_frames)
62  frame->setSmooth(smooth);
63  m_smooth = smooth;
64 }
65 
66 void AnimatedTexture::setRepeat(bool repeat)
67 {
68  for(const TexturePtr& frame : m_frames)
69  frame->setRepeat(repeat);
70  m_repeat = repeat;
71 }
72 
74 {
75  if(m_animTimer.ticksElapsed() < m_framesDelay[m_currentFrame])
76  return;
77 
78  m_animTimer.restart();
79  m_currentFrame++;
80  if(m_currentFrame >= m_frames.size())
81  m_currentFrame = 0;
82  m_id = m_frames[m_currentFrame]->getId();
83 }
eventdispatcher.h
graphics.h
AnimatedTexture::AnimatedTexture
AnimatedTexture(const Size &size, std::vector< ImagePtr > frames, std::vector< int > framesDelay, bool buildMipmaps=false, bool compress=false)
Definition: animatedtexture.cpp:28
Timer::ticksElapsed
ticks_t ticksElapsed()
Definition: timer.cpp:33
animatedtexture.h
Texture::m_id
uint m_id
Definition: texture.h:66
Texture::Texture
Texture()
Definition: texture.cpp:30
AnimatedTexture::setRepeat
virtual void setRepeat(bool repeat)
Definition: animatedtexture.cpp:66
Texture::setupSize
bool setupSize(const Size &size, bool forcePowerOfTwo=false)
Definition: texture.cpp:164
Texture::m_hasMipmaps
stdext::boolean< false > m_hasMipmaps
Definition: texture.h:71
Graphics::canUseHardwareMipmaps
bool canUseHardwareMipmaps()
Definition: graphics.cpp:349
Timer::restart
void restart()
Definition: timer.cpp:27
g_graphics
Graphics g_graphics
Definition: graphics.cpp:44
Texture::m_repeat
stdext::boolean< false > m_repeat
Definition: texture.h:74
AnimatedTexture::setSmooth
virtual void setSmooth(bool smooth)
Definition: animatedtexture.cpp:59
AnimatedTexture::updateAnimation
void updateAnimation()
Definition: animatedtexture.cpp:73
stdext::shared_object_ptr< Texture >
Texture::m_smooth
stdext::boolean< false > m_smooth
Definition: texture.h:72
AnimatedTexture::~AnimatedTexture
virtual ~AnimatedTexture()
Definition: animatedtexture.cpp:44
TSize< int >
AnimatedTexture::buildHardwareMipmaps
virtual bool buildHardwareMipmaps()
Definition: animatedtexture.cpp:49