GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/progressindicator.cpp Lines: 24 32 75.0 %
Date: 2017-11-29 Branches: 15 32 46.9 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2010  The Mana Developers
4
 *  Copyright (C) 2011-2017  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
22
#include "gui/widgets/progressindicator.h"
23
24
#include "gui/gui.h"
25
26
#include "resources/imageset.h"
27
28
#include "resources/animation/animation.h"
29
#include "resources/animation/simpleanimation.h"
30
31
#include "utils/delete2.h"
32
33
#include "debug.h"
34
35
2
ProgressIndicator::ProgressIndicator(const Widget2 *const widget) :
36
    Widget(widget),
37
2
    mIndicator(nullptr)
38
{
39
8
    ImageSet *const images = Theme::getImageSetFromTheme(
40
2
        "progress-indicator.png", 32, 32);
41
42
2
    if (images != nullptr)
43
    {
44

8
        Animation *const anim = new Animation("progress indicator");
45
20
        for (ImageSet::size_type i = 0, fsz = images->size();
46
18
             i < fsz;
47
             ++i)
48
        {
49
16
            anim->addFrame(images->get(i), 100, 0, 0, 100);
50
        }
51

2
        mIndicator = new SimpleAnimation(anim);
52
2
        images->decRef();
53
    }
54
55
2
    setSize(32, 32);
56
2
}
57
58
6
ProgressIndicator::~ProgressIndicator()
59
{
60
2
    if (gui != nullptr)
61
2
        gui->removeDragged(this);
62
63
2
    delete2(mIndicator);
64
4
}
65
66
void ProgressIndicator::logic()
67
{
68
    BLOCK_START("ProgressIndicator::logic")
69
    if (mIndicator != nullptr)
70
        mIndicator->update(10);
71
    BLOCK_END("ProgressIndicator::logic")
72
}
73
74
2
void ProgressIndicator::draw(Graphics *const graphics)
75
{
76
    BLOCK_START("ProgressIndicator::draw")
77
2
    if (mIndicator != nullptr)
78
    {
79
        // Draw the indicator centered on the widget
80
2
        const int x = (mDimension.width - 32) / 2;
81
2
        const int y = (mDimension.height - 32) / 2;
82
2
        mIndicator->draw(graphics, x, y);
83
    }
84
    BLOCK_END("ProgressIndicator::draw")
85
2
}
86
87
void ProgressIndicator::safeDraw(Graphics *const graphics)
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
}