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