Turtles all the way down
[ipdf/code.git] / src / view.cpp
index 9ad633c..53511d2 100644 (file)
@@ -24,7 +24,7 @@ using namespace std;
  * @param bounds - Initial bounds of the View
  * @param colour - Colour to use for rendering this view. TODO: Make sure this actually works, or just remove it
  */
-View::View(Document & document, Screen & screen, const Rect & bounds, const Colour & colour)
+View::View(Document & document, Screen & screen, const VRect & bounds, const Colour & colour)
        : m_use_gpu_transform(USE_GPU_TRANSFORM), m_use_gpu_rendering(USE_GPU_RENDERING), m_bounds_dirty(true), m_buffer_dirty(true), 
                m_render_dirty(true), m_document(document), m_screen(screen), m_cached_display(), m_bounds(bounds), m_colour(colour), m_bounds_ubo(), 
                m_objbounds_vbo(), m_object_renderers(NUMBER_OF_OBJECT_TYPES), m_cpu_rendering_pixels(NULL),
@@ -96,10 +96,8 @@ void View::Translate(Real x, Real y)
                #endif
        m_document.TranslateObjects(-x, -y, type);
        #endif
-       x *= m_bounds.w;
-       y *= m_bounds.h;
-       m_bounds.x += x;
-       m_bounds.y += y;
+       m_bounds.x += m_bounds.w*VReal(x);
+       m_bounds.y += m_bounds.h*VReal(y);
        //Debug("View Bounds => %s", m_bounds.Str().c_str());
 
        
@@ -143,19 +141,19 @@ void View::ScaleAroundPoint(Real x, Real y, Real scale_amount)
        #endif
        m_document.ScaleObjectsAboutPoint(x, y, scale_amount, type);
        #endif
-       x *= m_bounds.w;
-       y *= m_bounds.h;
-       x += m_bounds.x;
-       y += m_bounds.y;
+       VReal vx = m_bounds.w * VReal(x);
+       VReal vy = m_bounds.h * VReal(y);
+       vx += m_bounds.x;
+       vy += m_bounds.y;
        
-       Real top = y - m_bounds.y;
-       Real left = x - m_bounds.x;
+       VReal top = vy - m_bounds.y;
+       VReal left = vx - m_bounds.x;
        
        top *= scale_amount;
        left *= scale_amount;
        
-       m_bounds.x = x - left;
-       m_bounds.y = y - top;
+       m_bounds.x = vx - left;
+       m_bounds.y = vy - top;
        m_bounds.w *= scale_amount;
        m_bounds.h *= scale_amount;
        //Debug("Scale at {%s, %s} by %s View Bounds => %s", x.Str().c_str(), y.Str().c_str(), scale_amount.Str().c_str(), m_bounds.Str().c_str());
@@ -174,7 +172,7 @@ Rect View::TransformToViewCoords(const Rect& inp) const
        #ifdef TRANSFORM_OBJECTS_NOT_VIEW
                return inp;
        #endif
-       return TransformRectCoordinates(m_bounds, inp);
+       return TransformRectCoordinates(m_bounds.Convert<Real>(), inp);
 }
 
 /**
@@ -211,7 +209,7 @@ void View::Render(int width, int height)
 #ifndef QUADTREE_DISABLED
        if (m_bounds_dirty || !m_lazy_rendering)
        {
-               if ( (m_bounds.x > 1.0 || m_bounds.x < 0.0 || m_bounds.y > 1.0 || m_bounds.y < 0.0 || m_bounds.w > 1.0 || m_bounds.h > 1.0))
+               if ( m_bounds.w > 1.0 || m_bounds.h > 1.0)
                {
                        //TODO: Generate a new parent node.
                        if (m_document.GetQuadTree().nodes[m_current_quadtree_node].parent != QUADTREE_EMPTY)
@@ -220,6 +218,32 @@ void View::Render(int width, int height)
                                m_current_quadtree_node = m_document.GetQuadTree().nodes[m_current_quadtree_node].parent;
                        }
                }
+
+               // TODO: Support generating new parent nodes.
+               if (false && m_document.GetQuadTree().nodes[m_current_quadtree_node].parent != QUADTREE_EMPTY)
+               {
+                       if (m_bounds.x < -0.5)
+                       {
+                               m_bounds = Rect(m_bounds.x + 1, m_bounds.y, m_bounds.w, m_bounds.h);
+                               m_current_quadtree_node = m_document.GetQuadTree().GetNeighbour(m_current_quadtree_node, -1, 0, &m_document);
+                       }
+                       if (m_bounds.y < -0.5)
+                       {
+                               m_bounds = Rect(m_bounds.x, m_bounds.y + 1, m_bounds.w, m_bounds.h);
+                               m_current_quadtree_node = m_document.GetQuadTree().GetNeighbour(m_current_quadtree_node, 0, -1, &m_document);
+                       }
+                       if (m_bounds.w + m_bounds.x > 0.5)
+                       {
+                               m_bounds = Rect(m_bounds.x - 1, m_bounds.y, m_bounds.w, m_bounds.h);
+                               m_current_quadtree_node = m_document.GetQuadTree().GetNeighbour(m_current_quadtree_node, 1, 0, &m_document);
+                       }
+                       if (m_bounds.h + m_bounds.y > 0.5)
+                       {
+                               m_bounds = Rect(m_bounds.x, m_bounds.y - 1, m_bounds.w, m_bounds.h);
+                               m_current_quadtree_node = m_document.GetQuadTree().GetNeighbour(m_current_quadtree_node, 0, 1, &m_document);
+                       }
+               }
+
                if (ContainedInQuadChild(m_bounds, QTC_TOP_LEFT))
                {
                        if (m_document.GetQuadTree().nodes[m_current_quadtree_node].top_left == QUADTREE_EMPTY)
@@ -342,49 +366,56 @@ void View::RenderQuadtreeNode(int width, int height, QuadTreeIndex node, int rem
        {
                m_bounds = Rect(m_bounds.x - 1, m_bounds.y - 1, m_bounds.w, m_bounds.h);
                m_bounds_dirty = true;
-               RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, -1, -1), remaining_depth - 1);
+               RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, -1, -1, &m_document), remaining_depth - 1);
        }
+       m_bounds = old_bounds;
        if (m_bounds.Intersects(Rect(-1,0,1,1)))
        {
                m_bounds = Rect(m_bounds.x - 1, m_bounds.y, m_bounds.w, m_bounds.h);
                m_bounds_dirty = true;
-               RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, -1, 0), remaining_depth - 1);
+               RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, -1, 0, &m_document), remaining_depth - 1);
        }
+       m_bounds = old_bounds;
        if (m_bounds.Intersects(Rect(-1,1,1,1)))
        {
                m_bounds = Rect(m_bounds.x - 1, m_bounds.y + 1, m_bounds.w, m_bounds.h);
                m_bounds_dirty = true;
-               RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, -1, 1), remaining_depth - 1);
+               RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, -1, 1, &m_document), remaining_depth - 1);
        }
+       m_bounds = old_bounds;
        if (m_bounds.Intersects(Rect(0,-1,1,1)))
        {
                m_bounds = Rect(m_bounds.x, m_bounds.y - 1, m_bounds.w, m_bounds.h);
                m_bounds_dirty = true;
-               RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, 0, -1), remaining_depth - 1);
+               RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, 0, -1, &m_document), remaining_depth - 1);
        }
+       m_bounds = old_bounds;
        if (m_bounds.Intersects(Rect(0,1,1,1)))
        {
                m_bounds = Rect(m_bounds.x, m_bounds.y + 1, m_bounds.w, m_bounds.h);
                m_bounds_dirty = true;
-               RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, 0, 1), remaining_depth - 1);
+               RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, 0, 1, &m_document), remaining_depth - 1);
        }
+       m_bounds = old_bounds;
        if (m_bounds.Intersects(Rect(1,-1,1,1)))
        {
                m_bounds = Rect(m_bounds.x + 1, m_bounds.y - 1, m_bounds.w, m_bounds.h);
                m_bounds_dirty = true;
-               RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, 1, -1), remaining_depth - 1);
+               RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, 1, -1, &m_document), remaining_depth - 1);
        }
+       m_bounds = old_bounds;
        if (m_bounds.Intersects(Rect(1,0,1,1)))
        {
                m_bounds = Rect(m_bounds.x + 1, m_bounds.y, m_bounds.w, m_bounds.h);
                m_bounds_dirty = true;
-               RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, 1, 0), remaining_depth - 1);
+               RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, 1, 0, &m_document), remaining_depth - 1);
        }
+       m_bounds = old_bounds;
        if (m_bounds.Intersects(Rect(1,1,1,1)))
        {
                m_bounds = Rect(m_bounds.x + 1, m_bounds.y + 1, m_bounds.w, m_bounds.h);
                m_bounds_dirty = true;
-               RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, 1, 1), remaining_depth - 1);
+               RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, 1, 1, &m_document), remaining_depth - 1);
        }
        m_bounds = old_bounds;
        m_bounds_dirty = true;

UCC git Repository :: git.ucc.asn.au