summaryrefslogtreecommitdiff
path: root/src/compoundsprite.cpp
blob: a9a521ef9718b14303d01ada8c9c3cefe5212788 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
 *  The Mana Client
 *  Copyright (C) 2010  The Mana Developers
 *
 *  This file is part of The Mana Client.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "compoundsprite.h"

#include "utils/dtor.h"

CompoundSprite::CompoundSprite()
{
    mAlpha = 1.0f;
}

CompoundSprite::~CompoundSprite()
{
    SpriteIterator it, it_end;
    for (it = begin(), it_end = end(); it != it_end; it++)
        delete (*it);

    clear();
}

void CompoundSprite::reset()
{
    SpriteIterator it, it_end;
    for (it = begin(), it_end = end(); it != it_end; it++)
        if (*it)
            (*it)->reset();
}

void CompoundSprite::play(SpriteAction action)
{
    SpriteIterator it, it_end;
    for (it = begin(), it_end = end(); it != it_end; it++)
        if (*it)
            (*it)->play(action);
}

void CompoundSprite::update(int time)
{
    SpriteIterator it, it_end;
    for (it = begin(), it_end = end(); it != it_end; it++)
        if (*it)
            (*it)->update(time);
}

bool CompoundSprite::draw(Graphics* graphics, int posX, int posY) const
{
    SpriteConstIterator it, it_end;
    for (it = begin(), it_end = end(); it != it_end; it++)
    {
        if (*it)
        {
            if ((*it)->getAlpha() != mAlpha)
                (*it)->setAlpha(mAlpha);
            (*it)->draw(graphics, posX, posY);
        }
    }

    return true;
}

int CompoundSprite::getWidth() const
{
    Sprite *base = NULL;

    SpriteConstIterator it, it_end;
    for (it = begin(), it_end = end(); it != it_end; it++)
        if ((base = (*it)))
            break;

    if (base)
        return base->getWidth();

    return 0;
}

int CompoundSprite::getHeight() const
{
    Sprite *base = NULL;

    SpriteConstIterator it, it_end;
    for (it = begin(), it_end = end(); it != it_end; it++)
        if ((base = (*it)))
            break;

    if (base)
        return base->getHeight();

    return 0;
}

Image* CompoundSprite::getImage() const
{
    // TODO http://bugs.manasource.org/view.php?id=24
    return NULL;
}

void CompoundSprite::setDirection(SpriteDirection direction)
{
    SpriteIterator it, it_end;
    for (it = begin(), it_end = end(); it != it_end; it++)
        if (*it)
            (*it)->setDirection(direction);
}