Otclient  14/8/2020
uiparticles.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 OTClient <https://github.com/edubart/otclient>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 #include "uiparticles.h"
25 
27 {
28  m_referencePos = PointF(-1,-1);
29 }
30 
32 {
33  if(drawPane & Fw::ForegroundPane) {
34  if(drawPane != Fw::BothPanes) {
35  glDisable(GL_BLEND);
38  glEnable(GL_BLEND);
39  }
40  }
41 
42  if(drawPane & Fw::BackgroundPane) {
47 
48  if(m_referencePos.x < 0 && m_referencePos.y < 0)
50  else
51  g_painter->translate(m_rect.x() + m_referencePos.x * m_rect.width(), m_rect.y() + m_referencePos.y * m_rect.height());
52 
53  for(auto &effect: m_effects)
54  effect->render();
56  }
57 }
58 
59 void UIParticles::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
60 {
61  UIWidget::onStyleApply(styleName, styleNode);
62 
63  for(const OTMLNodePtr& node : styleNode->children()) {
64  if(node->tag() == "effect")
65  addEffect(node->value());
66  else if(node->tag() == "reference-pos")
67  setReferencePos(node->value<PointF>());
68  }
69 }
70 
71 void UIParticles::addEffect(const std::string& name)
72 {
74  if(effect)
75  m_effects.push_back(effect);
76 }
Painter::setColor
virtual void setColor(const Color &color)
Definition: painter.h:77
UIWidget::getPaddingRect
Rect getPaddingRect()
Definition: uiwidget.cpp:1054
Painter::restoreSavedState
virtual void restoreSavedState()=0
UIParticles::drawSelf
void drawSelf(Fw::DrawPane drawPane)
Definition: uiparticles.cpp:31
PointF
TPoint< float > PointF
Definition: point.h:87
UIParticles::UIParticles
UIParticles()
Definition: uiparticles.cpp:26
TPoint::y
T y
Definition: point.h:83
Painter::saveAndResetState
virtual void saveAndResetState()=0
TRect::x
T x() const
Definition: rect.h:58
UIWidget::onStyleApply
virtual void onStyleApply(const std::string &styleName, const OTMLNodePtr &styleNode)
Definition: uiwidget.cpp:1461
ParticleManager::createEffect
ParticleEffectPtr createEffect(const std::string &name)
Definition: particlemanager.cpp:54
UIWidget::drawSelf
virtual void drawSelf(Fw::DrawPane drawPane)
Definition: uiwidget.cpp:88
OTMLNode::children
OTMLNodeList children()
Definition: otmlnode.cpp:170
Fw::BackgroundPane
@ BackgroundPane
Definition: const.h:287
particlemanager.h
UIWidget::m_rect
Rect m_rect
Definition: uiwidget.h:62
UIParticles::onStyleApply
void onStyleApply(const std::string &styleName, const OTMLNodePtr &styleNode)
Definition: uiparticles.cpp:59
UIParticles::addEffect
void addEffect(const std::string &name)
Definition: uiparticles.cpp:71
Fw::BothPanes
@ BothPanes
Definition: const.h:288
g_particles
ParticleManager g_particles
Definition: particlemanager.cpp:27
uiparticles.h
Color::white
static const Color white
Definition: color.h:101
TRect::y
T y() const
Definition: rect.h:59
TPoint::x
T x
Definition: point.h:83
Painter::translate
virtual void translate(float x, float y)=0
Painter::setClipRect
virtual void setClipRect(const Rect &clipRect)=0
Color::alpha
static const Color alpha
Definition: color.h:100
Fw::DrawPane
DrawPane
Definition: const.h:285
stdext::shared_object_ptr< OTMLNode >
Fw::ForegroundPane
@ ForegroundPane
Definition: const.h:286
g_painter
Painter * g_painter
Definition: painter.cpp:28
TRect::height
T height() const
Definition: rect.h:70
TPoint< float >
Painter::drawFilledRect
virtual void drawFilledRect(const Rect &dest)=0
TRect::width
T width() const
Definition: rect.h:69
TRect::center
TPoint< T > center() const
Definition: rect.h:68
UIParticles::setReferencePos
void setReferencePos(const PointF &point)
Definition: uiparticles.h:40