mirror of
https://github.com/edubart/otclient.git
synced 2025-04-30 09:39:21 +02:00

* Replaced push_back calls with emplace_back where applicable. * Replaced size() == 0 and size() != 0 with empty() and !empty(). * Replaced C style loops for range for loops where applicable. * Fixed mismatching arg names between function declarations and definitions. * Replaced NULL and 0 (in the context of pointers) with nullptr. * Remove unnecessary calls to string::c_str() where applicable. * Replaced deprecated C headers with proper C++ headers. * Removed unnecessary null pointer checks when deleting pointers (deleting a null pointer has no effect). * Fixed a potential memory leak in apngloader.cpp file. * Replaced unsafe strcpy with strncpy in the demangle_name function.
77 lines
2.7 KiB
C++
77 lines
2.7 KiB
C++
/*
|
|
* Copyright (c) 2010-2017 OTClient <https://github.com/edubart/otclient>
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
* THE SOFTWARE.
|
|
*/
|
|
|
|
#include "uiparticles.h"
|
|
#include <framework/graphics/particlemanager.h>
|
|
|
|
UIParticles::UIParticles()
|
|
{
|
|
m_referencePos = PointF(-1,-1);
|
|
}
|
|
|
|
void UIParticles::drawSelf(Fw::DrawPane drawPane)
|
|
{
|
|
if(drawPane & Fw::ForegroundPane) {
|
|
if(drawPane != Fw::BothPanes) {
|
|
glDisable(GL_BLEND);
|
|
g_painter->setColor(Color::alpha);
|
|
g_painter->drawFilledRect(m_rect);
|
|
glEnable(GL_BLEND);
|
|
}
|
|
}
|
|
|
|
if(drawPane & Fw::BackgroundPane) {
|
|
UIWidget::drawSelf(Fw::ForegroundPane);
|
|
g_painter->saveAndResetState();
|
|
g_painter->setColor(Color::white);
|
|
g_painter->setClipRect(getPaddingRect());
|
|
|
|
if(m_referencePos.x < 0 && m_referencePos.y < 0)
|
|
g_painter->translate(m_rect.center());
|
|
else
|
|
g_painter->translate(m_rect.x() + m_referencePos.x * m_rect.width(), m_rect.y() + m_referencePos.y * m_rect.height());
|
|
|
|
for(auto &effect: m_effects)
|
|
effect->render();
|
|
g_painter->restoreSavedState();
|
|
}
|
|
}
|
|
|
|
void UIParticles::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
|
|
{
|
|
UIWidget::onStyleApply(styleName, styleNode);
|
|
|
|
for(const OTMLNodePtr& node : styleNode->children()) {
|
|
if(node->tag() == "effect")
|
|
addEffect(node->value());
|
|
else if(node->tag() == "reference-pos")
|
|
setReferencePos(node->value<PointF>());
|
|
}
|
|
}
|
|
|
|
void UIParticles::addEffect(const std::string& name)
|
|
{
|
|
ParticleEffectPtr effect = g_particles.createEffect(name);
|
|
if(effect)
|
|
m_effects.push_back(effect);
|
|
}
|