3
* Copyright (C) 2006-2009 The Mana World Development Team
4
* Copyright (C) 2009-2010 The Mana Developers
5
* Copyright (C) 2011-2013 The ManaPlus Developers
7
* This file is part of The ManaPlus Client.
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
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.
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/>.
23
#include "imageparticle.h"
28
#include "resources/image.h"
32
std::map<std::string, int> ImageParticle::imageParticleCountByName;
34
ImageParticle::ImageParticle(Map *const map, Image *const image):
42
const std::string &name = mImage->getIdPath();
43
std::map<std::string, int>::iterator it
44
= ImageParticle::imageParticleCountByName.find(name);
45
if (it == ImageParticle::imageParticleCountByName.end())
46
ImageParticle::imageParticleCountByName[name] = 1;
52
ImageParticle::~ImageParticle()
56
const std::string &name = mImage->getIdPath();
57
std::map<std::string, int>::iterator it
58
= ImageParticle::imageParticleCountByName.find(name);
59
if (it != ImageParticle::imageParticleCountByName.end())
61
int &cnt = (*it).second;
72
bool ImageParticle::draw(Graphics *const graphics,
73
const int offsetX, const int offsetY) const
75
FUNC_BLOCK("ImageParticle::draw", 1)
76
if (mAlive != ALIVE || !mImage)
79
const int screenX = static_cast<int>(mPos.x)
80
+ offsetX - mImage->mBounds.w / 2;
81
const int screenY = static_cast<int>(mPos.y) - static_cast<int>(mPos.z)
82
+ offsetY - mImage->mBounds.h / 2;
85
if (screenX + mImage->mBounds.w < 0 ||
86
screenX > graphics->mWidth ||
87
screenY + mImage->mBounds.h < 0 ||
88
screenY > graphics->mHeight)
93
float alphafactor = mAlpha;
95
if (mFadeOut && mLifetimeLeft > -1 && mLifetimeLeft < mFadeOut)
97
alphafactor *= static_cast<float>(mLifetimeLeft)
98
/ static_cast<float>(mFadeOut);
101
if (mFadeIn && mLifetimePast < mFadeIn)
103
alphafactor *= static_cast<float>(mLifetimePast)
104
/ static_cast<float>(mFadeIn);
107
mImage->setAlpha(alphafactor);
108
return graphics->drawImage(mImage, screenX, screenY);