Groups are a thing and sort of have a bounding box now
authorSam Moore <[email protected]>
Thu, 14 Aug 2014 04:34:55 +0000 (12:34 +0800)
committerSam Moore <[email protected]>
Thu, 14 Aug 2014 04:34:55 +0000 (12:34 +0800)
That was what I forgot in the last commit; I added "GROUP".

So, the idea is that GROUP can be used to shade a path.
Maybe. Eventually.

Or, it could just be used to make quad tree magic easier (?)

Or it could do both! (Since you can pretty easily just turn off the shading...
 but we're getting ahead of ourselves a bit there)

Or, if it gets given a name, then it can be used to implement the <use> SVG tag.
And then we can allow recursion (which regular SVG doesn't support).

Wouldn't it be nice...

src/document.cpp
src/objectrenderer.cpp

index 65a07ec..6754faa 100644 (file)
@@ -272,8 +272,26 @@ void Document::Load(const string & filename)
 
 unsigned Document::AddGroup(unsigned start_index, unsigned end_index)
 {
-       //TODO: Set bounds rect?
-       unsigned result = Add(GROUP, Rect(0,0,1,1),0);
+       Real xmin = 0; Real ymin = 0; 
+       Real xmax = 0; Real ymax = 0;
+       
+       for (unsigned i = start_index; i <= end_index; ++i)
+       {
+               Rect & objb = m_objects.bounds[i];
+               
+               if (i == start_index || objb.x < xmin)
+                       xmin = objb.x;
+               if (i == start_index || (objb.x+objb.w) > xmax)
+                       xmax = (objb.x+objb.w);
+                       
+               if (i == start_index || objb.y < ymin)
+                       ymin = objb.y;
+               if (i == start_index || (objb.y+objb.h) > ymax)
+                       ymax = objb.y;
+       }
+       
+       Rect bounds(xmin,ymin, xmax-xmin, ymax-ymin);
+       unsigned result = Add(GROUP, bounds,0);
        m_objects.groups[m_count-1].first = start_index;
        m_objects.groups[m_count-1].second = end_index;
        return result;
index 4b77f00..23d09c3 100644 (file)
@@ -229,8 +229,8 @@ void BezierRenderer::RenderUsingCPU(const Objects & objects, const View & view,
                // Draw a rectangle around the bezier for debugging the bounds rectangle calculations
                ObjectRenderer::RenderLineOnCPU(pix_bounds.x, pix_bounds.y, pix_bounds.x+pix_bounds.w, pix_bounds.y, target, Colour(1,0,0,1));
                ObjectRenderer::RenderLineOnCPU(pix_bounds.x, pix_bounds.y+pix_bounds.h, pix_bounds.x+pix_bounds.w, pix_bounds.y+pix_bounds.h, target, Colour(0,1,0,1));
-               ObjectRenderer::RenderLineOnCPU(pix_bounds.x, pix_bounds.y, pix_bounds.x, pix_bounds.y+pix_bounds.h, target, Colour(0,0,1,1));
-               ObjectRenderer::RenderLineOnCPU(pix_bounds.x+pix_bounds.w, pix_bounds.y, pix_bounds.x+pix_bounds.w, pix_bounds.y+pix_bounds.h, target, Colour(1,0,1,1));
+               ObjectRenderer::RenderLineOnCPU(pix_bounds.x, pix_bounds.y, pix_bounds.x, pix_bounds.y+pix_bounds.h, target, Colour(1,0,0,1));
+               ObjectRenderer::RenderLineOnCPU(pix_bounds.x+pix_bounds.w, pix_bounds.y, pix_bounds.x+pix_bounds.w, pix_bounds.y+pix_bounds.h, target, Colour(0,1,0,1));
        
                // Draw lines between the control points for debugging
                //ObjectRenderer::RenderLineOnCPU((int64_t)control.x0, (int64_t)control.y0, (int64_t)control.x1, (int64_t)control.y1,target);
@@ -341,7 +341,15 @@ void GroupRenderer::RenderUsingCPU(const Objects & objects, const View & view, c
                if (m_indexes[i] < first_obj_id) continue;
                if (m_indexes[i] >= last_obj_id) continue;
                
-               //pair<unsigned, unsigned> range = objects.groups[m_indexes[i]];
+               Rect bounds(CPURenderBounds(objects.bounds[m_indexes[i]], view, target));
+               PixelBounds pix_bounds(bounds);
+       
+
+               Colour c(0.5,0.5,1,1);
+               ObjectRenderer::RenderLineOnCPU(pix_bounds.x, pix_bounds.y, pix_bounds.x+pix_bounds.w, pix_bounds.y, target, c);
+               ObjectRenderer::RenderLineOnCPU(pix_bounds.x, pix_bounds.y+pix_bounds.h, pix_bounds.x+pix_bounds.w, pix_bounds.y+pix_bounds.h, target, c);
+               ObjectRenderer::RenderLineOnCPU(pix_bounds.x, pix_bounds.y, pix_bounds.x, pix_bounds.y+pix_bounds.h, target, c);
+               ObjectRenderer::RenderLineOnCPU(pix_bounds.x+pix_bounds.w, pix_bounds.y, pix_bounds.x+pix_bounds.w, pix_bounds.y+pix_bounds.h, target, c);
                
        
        }       

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