summaryrefslogtreecommitdiff
path: root/src/player/RectNode.cpp
diff options
context:
space:
mode:
authorDimitri John Ledkov <dimitri.ledkov@canonical.com>2014-02-20 16:10:52 +0000
committerDimitri John Ledkov <dimitri.ledkov@canonical.com>2014-02-20 19:15:57 +0000
commitd20f4a64eba38690337ac914a04a113de7caf125 (patch)
tree6828990e93ca5d8847b8cde2f2febb6566b0d53f /src/player/RectNode.cpp
parent28161e9209f21be1a600f637565ecede94855a36 (diff)
New upstream release. Closes: #721047debian/1.8.0-1
Drop all patches, none are needed with this new upstream release. Port to dh. Specify foreign in configure.ac.
Diffstat (limited to 'src/player/RectNode.cpp')
-rw-r--r--src/player/RectNode.cpp137
1 files changed, 76 insertions, 61 deletions
diff --git a/src/player/RectNode.cpp b/src/player/RectNode.cpp
index d7387df..980a957 100644
--- a/src/player/RectNode.cpp
+++ b/src/player/RectNode.cpp
@@ -1,6 +1,6 @@
//
// libavg - Media Playback Engine.
-// Copyright (C) 2003-2011 Ulrich von Zadow
+// Copyright (C) 2003-2014 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
@@ -21,7 +21,7 @@
#include "RectNode.h"
-#include "NodeDefinition.h"
+#include "TypeDefinition.h"
#include "../graphics/VertexArray.h"
#include "../base/Exception.h"
@@ -34,63 +34,66 @@ using namespace std;
namespace avg {
-NodeDefinition RectNode::createDefinition()
+void RectNode::registerType()
{
- double texCoords[] = {0, 0.25, 0.5, 0.75, 1};
- return NodeDefinition("rect", Node::buildNode<RectNode>)
- .extendDefinition(FilledVectorNode::createDefinition())
- .addArg(Arg<DPoint>("pos", DPoint(0,0), false, offsetof(RectNode, m_Rect.tl)))
- .addArg(Arg<DPoint>("size", DPoint(0,0)))
- .addArg(Arg<double>("angle", 0.0, false, offsetof(RectNode, m_Angle)))
- .addArg(Arg<vector<double> >("texcoords", vectorFromCArray(5, texCoords), false,
+ float texCoords[] = {0, 0.25f, 0.5f, 0.75f, 1};
+ TypeDefinition def = TypeDefinition("rect", "filledvectornode",
+ ExportedObject::buildObject<RectNode>)
+ .addArg(Arg<glm::vec2>("pos", glm::vec2(0,0), false,
+ offsetof(RectNode, m_Rect.tl)))
+ .addArg(Arg<glm::vec2>("size", glm::vec2(0,0)))
+ .addArg(Arg<float>("angle", 0.0f, false, offsetof(RectNode, m_Angle)))
+ .addArg(Arg<vector<float> >("texcoords", vectorFromCArray(5, texCoords), false,
offsetof(RectNode, m_TexCoords)))
;
+ TypeRegistry::get()->registerType(def);
}
RectNode::RectNode(const ArgList& args)
: FilledVectorNode(args)
{
args.setMembers(this);
- setSize(args.getArgVal<DPoint>("size"));
+ setSize(args.getArgVal<glm::vec2>("size"));
}
RectNode::~RectNode()
{
}
-const DPoint& RectNode::getPos() const
+const glm::vec2& RectNode::getPos() const
{
return m_Rect.tl;
}
-void RectNode::setPos(const DPoint& pt)
+void RectNode::setPos(const glm::vec2& pt)
{
- double w = m_Rect.width();
- double h = m_Rect.height();
+ float w = m_Rect.width();
+ float h = m_Rect.height();
m_Rect.tl = pt;
m_Rect.setWidth(w);
m_Rect.setHeight(h);
setDrawNeeded();
}
-DPoint RectNode::getSize() const
+glm::vec2 RectNode::getSize() const
{
return m_Rect.size();
}
-void RectNode::setSize(const DPoint& pt)
+void RectNode::setSize(const glm::vec2& pt)
{
m_Rect.setWidth(pt.x);
m_Rect.setHeight(pt.y);
+ notifySubscribers("SIZE_CHANGED", m_Rect.size());
setDrawNeeded();
}
-const vector<double>& RectNode::getTexCoords() const
+const vector<float>& RectNode::getTexCoords() const
{
return m_TexCoords;
}
-void RectNode::setTexCoords(const vector<double>& coords)
+void RectNode::setTexCoords(const vector<float>& coords)
{
if (coords.size() != 5) {
throw(Exception(AVG_ERR_OUT_OF_RANGE,
@@ -100,64 +103,76 @@ void RectNode::setTexCoords(const vector<double>& coords)
setDrawNeeded();
}
-double RectNode::getAngle() const
+float RectNode::getAngle() const
{
return m_Angle;
}
-void RectNode::setAngle(double angle)
+void RectNode::setAngle(float angle)
{
- m_Angle = fmod(angle, 2*M_PI);
+ m_Angle = fmod(angle, 2*PI);
setDrawNeeded();
}
-void RectNode::getElementsByPos(const DPoint& pos, vector<NodeWeakPtr>& pElements)
+glm::vec2 RectNode::toLocal(const glm::vec2& globalPos) const
{
- DPoint pivot = m_Rect.tl+m_Rect.size()/2;
- DPoint rpos = pos.getRotatedPivot(m_Angle, pivot);
- if (rpos.x >= m_Rect.tl.x && rpos.y >= m_Rect.tl.y && rpos.x < m_Rect.br.x &&
- rpos.y < m_Rect.br.y && reactsToMouseEvents())
+ glm::vec2 localPos = globalPos - m_Rect.tl;
+ glm::vec2 pivot = m_Rect.size()/2.f;
+ return getRotatedPivot(localPos, -m_Angle, pivot);
+}
+
+glm::vec2 RectNode::toGlobal(const glm::vec2& localPos) const
+{
+ glm::vec2 pivot = m_Rect.tl + m_Rect.size()/2.f;
+ glm::vec2 globalPos = getRotatedPivot(localPos, m_Angle, pivot);
+ return globalPos + m_Rect.tl;
+}
+
+void RectNode::getElementsByPos(const glm::vec2& pos, vector<NodePtr>& pElements)
+{
+ if (pos.x >= 0 && pos.y >= 0 && pos.x < m_Rect.size().x && pos.y < m_Rect.size().y
+ && reactsToMouseEvents())
{
- pElements.push_back(shared_from_this());
+ pElements.push_back(getSharedThis());
}
}
-void RectNode::calcVertexes(VertexArrayPtr& pVertexArray, Pixel32 color)
+void RectNode::calcVertexes(const VertexDataPtr& pVertexData, Pixel32 color)
{
- DPoint pivot = m_Rect.tl+m_Rect.size()/2;
+ glm::vec2 pivot = m_Rect.tl+m_Rect.size()/2.f;
- DPoint p1 = m_Rect.tl;
- DPoint p2(m_Rect.tl.x, m_Rect.br.y);
- DPoint p3 = m_Rect.br;
- DPoint p4(m_Rect.br.x, m_Rect.tl.y);
+ glm::vec2 p1 = m_Rect.tl;
+ glm::vec2 p2(m_Rect.tl.x, m_Rect.br.y);
+ glm::vec2 p3 = m_Rect.br;
+ glm::vec2 p4(m_Rect.br.x, m_Rect.tl.y);
- vector<DPoint> pts;
- pts.push_back(p1.getRotatedPivot(m_Angle, pivot));
- pts.push_back(p2.getRotatedPivot(m_Angle, pivot));
- pts.push_back(p3.getRotatedPivot(m_Angle, pivot));
- pts.push_back(p4.getRotatedPivot(m_Angle, pivot));
- calcPolyLine(pts, m_TexCoords, true, LJ_MITER, pVertexArray, color);
-}
-
-void RectNode::calcFillVertexes(VertexArrayPtr& pVertexArray, Pixel32 color)
-{
- DPoint pivot = m_Rect.tl+m_Rect.size()/2;
-
- DPoint p1 = m_Rect.tl;
- DPoint p2(m_Rect.tl.x, m_Rect.br.y);
- DPoint p3 = m_Rect.br;
- DPoint p4(m_Rect.br.x, m_Rect.tl.y);
- DPoint rp1 = p1.getRotatedPivot(m_Angle, pivot);
- DPoint rp2 = p2.getRotatedPivot(m_Angle, pivot);
- DPoint rp3 = p3.getRotatedPivot(m_Angle, pivot);
- DPoint rp4 = p4.getRotatedPivot(m_Angle, pivot);
- pVertexArray->appendPos(rp1, getFillTexCoord1(), color);
- DPoint blTexCoord = DPoint(getFillTexCoord1().x, getFillTexCoord2().y);
- pVertexArray->appendPos(rp2, blTexCoord, color);
- pVertexArray->appendPos(rp3, getFillTexCoord2(), color);
- DPoint trTexCoord = DPoint(getFillTexCoord2().x, getFillTexCoord1().y);
- pVertexArray->appendPos(rp4, trTexCoord, color);
- pVertexArray->appendQuadIndexes(1, 0, 2, 3);
+ vector<glm::vec2> pts;
+ pts.push_back(getRotatedPivot(p1, m_Angle, pivot));
+ pts.push_back(getRotatedPivot(p2, m_Angle, pivot));
+ pts.push_back(getRotatedPivot(p3, m_Angle, pivot));
+ pts.push_back(getRotatedPivot(p4, m_Angle, pivot));
+ calcPolyLine(pts, m_TexCoords, true, LJ_MITER, pVertexData, color);
+}
+
+void RectNode::calcFillVertexes(const VertexDataPtr& pVertexData, Pixel32 color)
+{
+ glm::vec2 pivot = m_Rect.tl+m_Rect.size()/2.f;
+
+ glm::vec2 p1 = m_Rect.tl;
+ glm::vec2 p2(m_Rect.tl.x, m_Rect.br.y);
+ glm::vec2 p3 = m_Rect.br;
+ glm::vec2 p4(m_Rect.br.x, m_Rect.tl.y);
+ glm::vec2 rp1 = getRotatedPivot(p1, m_Angle, pivot);
+ glm::vec2 rp2 = getRotatedPivot(p2, m_Angle, pivot);
+ glm::vec2 rp3 = getRotatedPivot(p3, m_Angle, pivot);
+ glm::vec2 rp4 = getRotatedPivot(p4, m_Angle, pivot);
+ pVertexData->appendPos(rp1, getFillTexCoord1(), color);
+ glm::vec2 blTexCoord = glm::vec2(getFillTexCoord1().x, getFillTexCoord2().y);
+ pVertexData->appendPos(rp2, blTexCoord, color);
+ pVertexData->appendPos(rp3, getFillTexCoord2(), color);
+ glm::vec2 trTexCoord = glm::vec2(getFillTexCoord2().x, getFillTexCoord1().y);
+ pVertexData->appendPos(rp4, trTexCoord, color);
+ pVertexData->appendQuadIndexes(1, 0, 2, 3);
}
}