ManaPlus
progressindicator.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2010 The Mana Developers
4  * Copyright (C) 2011-2018 The ManaPlus Developers
5  *
6  * This file is part of The ManaPlus Client.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
23 
24 #include "gui/gui.h"
25 
26 #include "resources/imageset.h"
27 
30 
31 #include "utils/delete2.h"
32 
33 #include "debug.h"
34 
36  Widget(widget),
37  mIndicator(nullptr)
38 {
39  ImageSet *const images = Theme::getImageSetFromTheme(
40  "progress-indicator.png", 32, 32);
41 
42  if (images != nullptr)
43  {
44  Animation *const anim = new Animation("progress indicator");
45  for (ImageSet::size_type i = 0, fsz = images->size();
46  i < fsz;
47  ++i)
48  {
49  anim->addFrame(images->get(i), 100, 0, 0, 100);
50  }
51  mIndicator = new SimpleAnimation(anim);
52  images->decRef();
53  }
54 
55  setSize(32, 32);
56 }
57 
59 {
60  if (gui != nullptr)
61  gui->removeDragged(this);
62 
64 }
65 
67 {
68  BLOCK_START("ProgressIndicator::logic")
69  if (mIndicator != nullptr)
70  mIndicator->update(10);
71  BLOCK_END("ProgressIndicator::logic")
72 }
73 
74 void ProgressIndicator::draw(Graphics *const graphics)
75 {
76  BLOCK_START("ProgressIndicator::draw")
77  if (mIndicator != nullptr)
78  {
79  // Draw the indicator centered on the widget
80  const int x = (mDimension.width - 32) / 2;
81  const int y = (mDimension.height - 32) / 2;
82  mIndicator->draw(graphics, x, y);
83  }
84  BLOCK_END("ProgressIndicator::draw")
85 }
86 
88 {
89  BLOCK_START("ProgressIndicator::draw")
90  if (mIndicator != nullptr)
91  {
92  // Draw the indicator centered on the widget
93  const int x = (mDimension.width - 32) / 2;
94  const int y = (mDimension.height - 32) / 2;
95  mIndicator->draw(graphics, x, y);
96  }
97  BLOCK_END("ProgressIndicator::draw")
98 }
void setSize(const int width, const int height)
Definition: widget.cpp:366
ProgressIndicator(const Widget2 *const widget)
int width
Definition: rect.h:218
Image * get(const size_type i) const
Definition: imageset.cpp:66
Gui * gui
Definition: gui.cpp:110
virtual void decRef()
Definition: resource.cpp:49
#define BLOCK_START(name)
Definition: perfomance.h:78
#define BLOCK_END(name)
Definition: perfomance.h:79
#define delete2(var)
Definition: delete2.h:24
static ImageSet * getImageSetFromTheme(const std::string &path, const int w, const int h)
Definition: theme.cpp:659
size_type size() const
Definition: imageset.h:72
bool update(const int timePassed)
void draw(Graphics *const graphics, const int posX, const int posY) const
#define nullptr
Definition: localconsts.h:44
int height
Definition: rect.h:223
void draw(Graphics *const graphics)
std::vector< Image * >::size_type size_type
Definition: imageset.h:68
void safeDraw(Graphics *const graphics)
void removeDragged(const Widget *const widget)
Definition: gui.cpp:1161
Definition: widget.h:97
void addFrame(Image *const image, const int delay, const int offsetX, const int offsetY, const int rand)
Definition: animation.cpp:45
SimpleAnimation * mIndicator
Rect mDimension
Definition: widget.h:1100