From c69c3788e02670c8cf52fa4ac16525f9f3d83124 Mon Sep 17 00:00:00 2001 From: ExMix Date: Tue, 23 Apr 2013 15:58:13 +0300 Subject: [PATCH] From this moment we will set and reset state for overlay element instead of cloning element with new transformation --- graphics/circle_element.cpp | 12 +++--------- graphics/circle_element.hpp | 3 +-- graphics/overlay_element.cpp | 17 ++++++++++++++++- graphics/overlay_element.hpp | 14 ++++++++++++-- graphics/path_text_element.cpp | 15 +++++---------- graphics/path_text_element.hpp | 4 +--- graphics/straight_text_element.cpp | 28 ++++++++++------------------ graphics/straight_text_element.hpp | 3 +-- graphics/symbol_element.cpp | 13 +++---------- graphics/symbol_element.hpp | 5 ++--- gui/element.cpp | 8 +++----- gui/element.hpp | 2 +- 12 files changed, 58 insertions(+), 66 deletions(-) diff --git a/graphics/circle_element.cpp b/graphics/circle_element.cpp index 8fbf9ac3d0..c7421bb356 100644 --- a/graphics/circle_element.cpp +++ b/graphics/circle_element.cpp @@ -13,13 +13,6 @@ namespace graphics m_ci(p.m_ci) {} - CircleElement::CircleElement(CircleElement const & ce, math::Matrix const & m) - : base_t(ce), - m_ci(ce.m_ci) - { - setPivot(ce.pivot() * m); - } - vector const & CircleElement::boundRects() const { if (isDirtyRect()) @@ -72,8 +65,9 @@ namespace graphics res->m_pipelineID); } - OverlayElement * CircleElement::clone(math::Matrix const & m) const + void CircleElement::setTransformation(const math::Matrix & m) { - return new CircleElement(*this, m); + setPivot(pivot() * getResetMatrix() * m); + base_t::setTransformation(m); } } diff --git a/graphics/circle_element.hpp b/graphics/circle_element.hpp index aa32a24d02..289214a88b 100644 --- a/graphics/circle_element.hpp +++ b/graphics/circle_element.hpp @@ -26,12 +26,11 @@ namespace graphics }; CircleElement(Params const & p); - CircleElement(CircleElement const & ce, math::Matrix const & m); vector const & boundRects() const; void draw(OverlayRenderer * s, math::Matrix const & m) const; - OverlayElement * clone(math::Matrix const & m) const; + void setTransformation(const math::Matrix & m); }; } diff --git a/graphics/overlay_element.cpp b/graphics/overlay_element.cpp index ec6d5e5937..2594f2d62c 100644 --- a/graphics/overlay_element.cpp +++ b/graphics/overlay_element.cpp @@ -24,7 +24,8 @@ namespace graphics m_isDirtyRect(true), m_isDirtyLayout(true), m_isDirtyRoughRect(true), - m_userInfo(p.m_userInfo) + m_userInfo(p.m_userInfo), + m_inverseMatrix(math::Identity()) {} m2::PointD const OverlayElement::computeTopLeft(m2::PointD const & sz, @@ -229,4 +230,18 @@ namespace graphics return m_depth; } + math::Matrix const & OverlayElement::getResetMatrix() const + { + return m_inverseMatrix; + } + + void OverlayElement::setTransformation(const math::Matrix & m) + { + m_inverseMatrix = math::Inverse(m); + } + + void OverlayElement::resetTransformation() + { + setTransformation(math::Identity()); + } } diff --git a/graphics/overlay_element.hpp b/graphics/overlay_element.hpp index 6b0c695e35..e8471a2627 100644 --- a/graphics/overlay_element.hpp +++ b/graphics/overlay_element.hpp @@ -43,6 +43,11 @@ namespace graphics mutable bool m_isDirtyRoughRect; mutable m2::RectD m_roughBoundRect; + math::Matrix m_inverseMatrix; + + protected: + math::Matrix const & getResetMatrix() const; + public: UserInfo m_userInfo; @@ -62,11 +67,16 @@ namespace graphics OverlayElement(Params const & p); virtual ~OverlayElement(); - virtual OverlayElement * clone(math::Matrix const & m) const = 0; - /// PLEASE, REMEMBER THE REFERENCE!!! virtual vector const & boundRects() const = 0; virtual void draw(OverlayRenderer * r, math::Matrix const & m) const = 0; + /// Set new transformation ! RELATIVE TO INIT STATE ! for drawing and safe information for reseting + /// Need to call base class method + virtual void setTransformation(math::Matrix const & m) = 0; + /// This method reset transformation to initial state. + /// Geometry stored in coordinates relative to the tile. + /// Need to call base class method + virtual void resetTransformation(); virtual double priority() const; diff --git a/graphics/path_text_element.cpp b/graphics/path_text_element.cpp index a2ccb1c571..a2b20d912c 100644 --- a/graphics/path_text_element.cpp +++ b/graphics/path_text_element.cpp @@ -27,14 +27,6 @@ namespace graphics setIsValid((m_glyphLayout.firstVisible() == 0) && (m_glyphLayout.lastVisible() == visText().size())); } - PathTextElement::PathTextElement(PathTextElement const & src, math::Matrix const & m) - : TextElement(src), - m_glyphLayout(src.m_glyphLayout, m) - { - setPivot(m_glyphLayout.pivot()); - setIsValid((m_glyphLayout.firstVisible() == 0) && (m_glyphLayout.lastVisible() == visText().size())); - } - vector const & PathTextElement::boundRects() const { if (isDirtyRect()) @@ -92,8 +84,11 @@ namespace graphics m_glyphLayout.setPivot(pivot); } - OverlayElement * PathTextElement::clone(math::Matrix const & m) const + void PathTextElement::setTransformation(const math::Matrix & m) { - return new PathTextElement(*this, m); + m_glyphLayout = GlyphLayout(m_glyphLayout, getResetMatrix() * m); + TextElement::setPivot(m_glyphLayout.pivot()); + setIsValid((m_glyphLayout.firstVisible() == 0) && (m_glyphLayout.lastVisible() == visText().size())); + TextElement::setTransformation(m); } } diff --git a/graphics/path_text_element.hpp b/graphics/path_text_element.hpp index c165dbe55a..ab14d8d66c 100644 --- a/graphics/path_text_element.hpp +++ b/graphics/path_text_element.hpp @@ -23,14 +23,12 @@ namespace graphics }; PathTextElement(Params const & p); - PathTextElement(PathTextElement const & src, math::Matrix const & m); vector const & boundRects() const; void draw(OverlayRenderer * r, math::Matrix const & m) const; void setPivot(m2::PointD const & pivot); - - OverlayElement * clone(math::Matrix const & m) const; + void setTransformation(const math::Matrix & m); }; } diff --git a/graphics/straight_text_element.cpp b/graphics/straight_text_element.cpp index 83717130dc..ae4913a4b5 100644 --- a/graphics/straight_text_element.cpp +++ b/graphics/straight_text_element.cpp @@ -178,22 +178,6 @@ namespace graphics m_offset(0, 0) {} - StraightTextElement::StraightTextElement(StraightTextElement const & src, - math::Matrix const & m) - : TextElement(src), - m_glyphLayouts(src.m_glyphLayouts) - { - m_offsets = src.m_offsets; - - setPivot(pivot() * m); - - for (unsigned i = 0; i < m_glyphLayouts.size(); ++i) - { - m_glyphLayouts[i].setPivot(pivot()); - m_glyphLayouts[i].setOffset(m_offsets[i]); - } - } - vector const & StraightTextElement::boundRects() const { if (isDirtyRect()) @@ -262,9 +246,17 @@ namespace graphics m_glyphLayouts[i].setPivot(m_glyphLayouts[i].pivot() + offs); } - OverlayElement * StraightTextElement::clone(math::Matrix const & m) const + void StraightTextElement::setTransformation(const math::Matrix & m) { - return new StraightTextElement(*this, m); + setPivot(pivot() * getResetMatrix() * m); + + for (unsigned i = 0; i < m_glyphLayouts.size(); ++i) + { + m_glyphLayouts[i].setPivot(pivot()); + m_glyphLayouts[i].setOffset(m_offsets[i]); + } + + TextElement::setTransformation(m); } bool StraightTextElement::hasSharpGeometry() const diff --git a/graphics/straight_text_element.hpp b/graphics/straight_text_element.hpp index d33f18e3d9..9d42c095fa 100644 --- a/graphics/straight_text_element.hpp +++ b/graphics/straight_text_element.hpp @@ -28,7 +28,6 @@ namespace graphics }; StraightTextElement(Params const & p); - StraightTextElement(StraightTextElement const & src, math::Matrix const & m); vector const & boundRects() const; @@ -36,7 +35,7 @@ namespace graphics void setPivot(m2::PointD const & pv); - OverlayElement * clone(math::Matrix const & m) const; + void setTransformation(const math::Matrix & m); bool hasSharpGeometry() const; }; diff --git a/graphics/symbol_element.cpp b/graphics/symbol_element.cpp index 1eb21e353c..2fefa5ca84 100644 --- a/graphics/symbol_element.cpp +++ b/graphics/symbol_element.cpp @@ -30,14 +30,6 @@ namespace graphics m_symbolRect = res->m_texRect; } - SymbolElement::SymbolElement(SymbolElement const & se, math::Matrix const & m) - : base_t(se), - m_info(se.m_info), - m_symbolRect(se.m_symbolRect) - { - setPivot(se.pivot() * m); - } - vector const & SymbolElement::boundRects() const { if (isDirtyRect()) @@ -101,9 +93,10 @@ namespace graphics res->m_pipelineID); } - OverlayElement * SymbolElement::clone(math::Matrix const & m) const + void SymbolElement::setTransformation(const math::Matrix & m) { - return new SymbolElement(*this, m); + setPivot(pivot() * getResetMatrix() * m); + base_t::setTransformation(m); } bool SymbolElement::hasSharpGeometry() const diff --git a/graphics/symbol_element.hpp b/graphics/symbol_element.hpp index 4960c06148..49f58b517a 100644 --- a/graphics/symbol_element.hpp +++ b/graphics/symbol_element.hpp @@ -31,15 +31,14 @@ namespace graphics }; SymbolElement(Params const & p); - SymbolElement(SymbolElement const & se, math::Matrix const & m); vector const & boundRects() const; void draw(OverlayRenderer * s, math::Matrix const & m) const; uint32_t resID() const; - OverlayElement * clone(math::Matrix const & m) const; - bool hasSharpGeometry() const; + + void setTransformation(const math::Matrix & m); }; } diff --git a/gui/element.cpp b/gui/element.cpp index e20b615e89..9c464652ed 100644 --- a/gui/element.cpp +++ b/gui/element.cpp @@ -84,11 +84,6 @@ namespace gui } } - graphics::OverlayElement * Element::clone(math::Matrix const & m) const - { - return 0; - } - void Element::draw(graphics::OverlayRenderer *r, math::Matrix const & m) const { for (unsigned i = 0; i < boundRects().size(); ++i) @@ -125,4 +120,7 @@ namespace gui m_controller = controller; } + void Element::setTransformation(const math::Matrix & /*m*/) + { + } } diff --git a/gui/element.hpp b/gui/element.hpp index 4d8adfd1ed..11124360f6 100644 --- a/gui/element.hpp +++ b/gui/element.hpp @@ -86,9 +86,9 @@ namespace gui /// check if the layout of element is dirty and re-layout element if needed. void checkDirtyLayout() const; - graphics::OverlayElement * clone(math::Matrix const & m) const; void draw(graphics::OverlayRenderer * r, math::Matrix const & m) const; double priority() const; + void setTransformation(const math::Matrix & m); }; }