diff options
author | Dmitrijs Ledkovs <xnox@debian.org> | 2013-09-24 09:14:03 +0100 |
---|---|---|
committer | Dmitrijs Ledkovs <xnox@debian.org> | 2013-09-24 09:14:03 +0100 |
commit | 28161e9209f21be1a600f637565ecede94855a36 (patch) | |
tree | 5a82eaf04f3d680b0b4486f6d738bd3620d01f75 /src/player/FilledVectorNode.cpp |
libavg (1.7.1-4) unstable; urgency=low
* Drop automake1.10 dependency in favor of automake. Closes: #724398.
# imported from the archive
Diffstat (limited to 'src/player/FilledVectorNode.cpp')
-rw-r--r-- | src/player/FilledVectorNode.cpp | 214 |
1 files changed, 214 insertions, 0 deletions
diff --git a/src/player/FilledVectorNode.cpp b/src/player/FilledVectorNode.cpp new file mode 100644 index 0000000..69d833b --- /dev/null +++ b/src/player/FilledVectorNode.cpp @@ -0,0 +1,214 @@ +// +// libavg - Media Playback Engine. +// Copyright (C) 2003-2011 Ulrich von Zadow +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// Current versions can be found at www.libavg.de +// + +#include "FilledVectorNode.h" + +#include "NodeDefinition.h" +#include "Image.h" +#include "DivNode.h" + +#include "../base/ScopeTimer.h" +#include "../base/Logger.h" +#include "../base/Exception.h" + +using namespace std; +using namespace boost; + +namespace avg { + +NodeDefinition FilledVectorNode::createDefinition() +{ + return NodeDefinition("filledvector") + .extendDefinition(VectorNode::createDefinition()) + .addArg(Arg<UTF8String>("filltexhref", "", false, + offsetof(FilledVectorNode, m_FillTexHRef))) + .addArg(Arg<double>("fillopacity", 0, false, + offsetof(FilledVectorNode, m_FillOpacity))) + .addArg(Arg<string>("fillcolor", "FFFFFF", false, + offsetof(FilledVectorNode, m_sFillColorName))) + .addArg(Arg<DPoint>("filltexcoord1", DPoint(0,0), false, + offsetof(FilledVectorNode, m_FillTexCoord1))) + .addArg(Arg<DPoint>("filltexcoord2", DPoint(1,1), false, + offsetof(FilledVectorNode, m_FillTexCoord2))) + ; +} + +FilledVectorNode::FilledVectorNode(const ArgList& args) + : VectorNode(args), + m_pFillShape(new Shape(MaterialInfo(GL_REPEAT, GL_REPEAT, false))) +{ + m_FillTexHRef = args.getArgVal<UTF8String>("filltexhref"); + setFillTexHRef(m_FillTexHRef); + m_sFillColorName = args.getArgVal<string>("fillcolor"); + m_FillColor = colorStringToColor(m_sFillColorName); +} + +FilledVectorNode::~FilledVectorNode() +{ +} + +void FilledVectorNode::connectDisplay() +{ + VectorNode::connectDisplay(); + m_FillColor = colorStringToColor(m_sFillColorName); + m_pFillShape->moveToGPU(); + m_OldOpacity = -1; +} + +void FilledVectorNode::disconnect(bool bKill) +{ + if (bKill) { + m_pFillShape->discard(); + } else { + m_pFillShape->moveToCPU(); + } + VectorNode::disconnect(bKill); +} + +void FilledVectorNode::checkReload() +{ + Node::checkReload(m_FillTexHRef, m_pFillShape->getImage()); + if (getState() == Node::NS_CANRENDER) { + m_pFillShape->moveToGPU(); + setDrawNeeded(); + } + VectorNode::checkReload(); +} + +const UTF8String& FilledVectorNode::getFillTexHRef() const +{ + return m_FillTexHRef; +} + +void FilledVectorNode::setFillTexHRef(const UTF8String& href) +{ + m_FillTexHRef = href; + checkReload(); + setDrawNeeded(); +} + +void FilledVectorNode::setFillBitmap(BitmapPtr pBmp) +{ + m_FillTexHRef = ""; + m_pFillShape->setBitmap(pBmp); + setDrawNeeded(); +} + +const DPoint& FilledVectorNode::getFillTexCoord1() const +{ + return m_FillTexCoord1; +} + +void FilledVectorNode::setFillTexCoord1(const DPoint& pt) +{ + m_FillTexCoord1 = pt; + setDrawNeeded(); +} + +const DPoint& FilledVectorNode::getFillTexCoord2() const +{ + return m_FillTexCoord2; +} + +void FilledVectorNode::setFillTexCoord2(const DPoint& pt) +{ + m_FillTexCoord2 = pt; + setDrawNeeded(); +} + +double FilledVectorNode::getFillOpacity() const +{ + return m_FillOpacity; +} + +void FilledVectorNode::setFillOpacity(double opacity) +{ + m_FillOpacity = opacity; + setDrawNeeded(); +} + +void FilledVectorNode::preRender() +{ + Node::preRender(); + double curOpacity = getParent()->getEffectiveOpacity()*m_FillOpacity; + VertexArrayPtr pFillVA; + pFillVA = m_pFillShape->getVertexArray(); + if (isDrawNeeded() || curOpacity != m_OldOpacity) { + pFillVA->reset(); + Pixel32 color = getFillColorVal(); + color.setA((unsigned char)(curOpacity*255)); + calcFillVertexes(pFillVA, color); + pFillVA->update(); + m_OldOpacity = curOpacity; + } + VectorNode::preRender(); +} + +static ProfilingZoneID RenderProfilingZone("FilledVectorNode::render"); + +void FilledVectorNode::render(const DRect& rect) +{ + ScopeTimer Timer(RenderProfilingZone); + double curOpacity = getParent()->getEffectiveOpacity()*m_FillOpacity; + if (curOpacity > 0.01) { + glColor4d(1.0, 1.0, 1.0, curOpacity); + m_pFillShape->draw(); + } + VectorNode::render(rect); +} + +void FilledVectorNode::setFillColor(const string& sColor) +{ + if (m_sFillColorName != sColor) { + m_sFillColorName = sColor; + m_FillColor = colorStringToColor(m_sFillColorName); + setDrawNeeded(); + } +} + +const string& FilledVectorNode::getFillColor() const +{ + return m_sFillColorName; +} + +Pixel32 FilledVectorNode::getFillColorVal() const +{ + return m_FillColor; +} + +DPoint FilledVectorNode::calcFillTexCoord(const DPoint& pt, const DPoint& minPt, + const DPoint& maxPt) +{ + DPoint texPt; + texPt.x = (m_FillTexCoord2.x-m_FillTexCoord1.x)*(pt.x-minPt.x)/(maxPt.x-minPt.x) + +m_FillTexCoord1.x; + texPt.y = (m_FillTexCoord2.y-m_FillTexCoord1.y)*(pt.y-minPt.y)/(maxPt.y-minPt.y) + +m_FillTexCoord1.y; + return texPt; +} + +bool FilledVectorNode::isVisible() const +{ + return getActive() && (getEffectiveOpacity() > 0.01 || + getParent()->getEffectiveOpacity()*m_FillOpacity > 0.01); +} + +} |