GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/progressindicator.cpp Lines: 24 32 75.0 %
Date: 2021-03-17 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-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
23
#include "gui/widgets/progressindicator.h"
24
25
#include "gui/gui.h"
26
27
#include "resources/imageset.h"
28
29
#include "resources/animation/animation.h"
30
#include "resources/animation/simpleanimation.h"
31
32
#include "utils/delete2.h"
33
34
#include "debug.h"
35
36
1
ProgressIndicator::ProgressIndicator(const Widget2 *const widget) :
37
    Widget(widget),
38
1
    mIndicator(nullptr)
39
{
40
3
    ImageSet *const images = Theme::getImageSetFromTheme(
41
1
        "progress-indicator.png", 32, 32);
42
43
1
    if (images != nullptr)
44
    {
45

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

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