1 |
|
|
/* |
2 |
|
|
* The ManaPlus Client |
3 |
|
|
* Copyright (C) 2006-2009 The Mana World Development Team |
4 |
|
|
* Copyright (C) 2009-2010 The Mana Developers |
5 |
|
|
* Copyright (C) 2011-2019 The ManaPlus Developers |
6 |
|
|
* Copyright (C) 2019-2021 Andrei Karas |
7 |
|
|
* |
8 |
|
|
* This file is part of The ManaPlus Client. |
9 |
|
|
* |
10 |
|
|
* This program is free software; you can redistribute it and/or modify |
11 |
|
|
* it under the terms of the GNU General Public License as published by |
12 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
13 |
|
|
* any later version. |
14 |
|
|
* |
15 |
|
|
* This program is distributed in the hope that it will be useful, |
16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
|
|
* GNU General Public License for more details. |
19 |
|
|
* |
20 |
|
|
* You should have received a copy of the GNU General Public License |
21 |
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
22 |
|
|
*/ |
23 |
|
|
|
24 |
|
|
#include "particle/imageparticle.h" |
25 |
|
|
|
26 |
|
|
#include "render/graphics.h" |
27 |
|
|
|
28 |
|
|
#include "resources/image/image.h" |
29 |
|
|
|
30 |
|
|
#include "debug.h" |
31 |
|
|
|
32 |
|
1 |
StringIntMap ImageParticle::imageParticleCountByName; |
33 |
|
|
|
34 |
|
|
ImageParticle::ImageParticle(Image *restrict const image) : |
35 |
|
|
Particle() |
36 |
|
|
{ |
37 |
|
|
mType = ParticleType::Image; |
38 |
|
|
mImage = image; |
39 |
|
|
if (mImage != nullptr) |
40 |
|
|
{ |
41 |
|
|
mImage->incRef(); |
42 |
|
|
|
43 |
|
|
const std::string &restrict name = mImage->mIdPath; |
44 |
|
|
StringIntMapIter it |
45 |
|
|
= ImageParticle::imageParticleCountByName.find(name); |
46 |
|
|
if (it == ImageParticle::imageParticleCountByName.end()) |
47 |
|
|
ImageParticle::imageParticleCountByName[name] = 1; |
48 |
|
|
else |
49 |
|
|
(*it).second ++; |
50 |
|
|
} |
51 |
|
|
} |
52 |
|
|
|
53 |
|
|
void ImageParticle::draw(Graphics *restrict const graphics, |
54 |
|
|
const int offsetX, |
55 |
|
|
const int offsetY) const restrict2 |
56 |
|
|
{ |
57 |
|
|
FUNC_BLOCK("ImageParticle::draw", 1) |
58 |
|
|
if (mAlive != AliveStatus::ALIVE || (mImage == nullptr)) |
59 |
|
|
return; |
60 |
|
|
|
61 |
|
|
const int w = mImage->mBounds.w; |
62 |
|
|
const int h = mImage->mBounds.h; |
63 |
|
|
const int screenX = CAST_S32(mPos.x) |
64 |
|
|
+ offsetX - w / 2; |
65 |
|
|
const int screenY = CAST_S32(mPos.y) - CAST_S32(mPos.z) |
66 |
|
|
+ offsetY - h / 2; |
67 |
|
|
|
68 |
|
|
// Check if on screen |
69 |
|
|
if (screenX + w < 0 || |
70 |
|
|
screenX > graphics->mWidth || |
71 |
|
|
screenY + h < 0 || |
72 |
|
|
screenY > graphics->mHeight) |
73 |
|
|
{ |
74 |
|
|
return; |
75 |
|
|
} |
76 |
|
|
|
77 |
|
|
float alphafactor = mAlpha; |
78 |
|
|
|
79 |
|
|
if ((mFadeOut != 0) && mLifetimeLeft > -1 && mLifetimeLeft < mFadeOut) |
80 |
|
|
{ |
81 |
|
|
alphafactor *= static_cast<float>(mLifetimeLeft) |
82 |
|
|
/ static_cast<float>(mFadeOut); |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
if ((mFadeIn != 0) && mLifetimePast < mFadeIn) |
86 |
|
|
{ |
87 |
|
|
alphafactor *= static_cast<float>(mLifetimePast) |
88 |
|
|
/ static_cast<float>(mFadeIn); |
89 |
|
|
} |
90 |
|
|
|
91 |
|
|
mImage->setAlpha(alphafactor); |
92 |
|
|
graphics->drawImage(mImage, screenX, screenY); |
93 |
✓✗✓✗
|
3 |
} |